1 14 package org.compiere.process; 15 16 import java.math.*; 17 18 import org.compiere.model.*; 19 import org.compiere.util.*; 20 21 27 public class OrderRePrice extends SvrProcess 28 { 29 30 private int p_C_Order_ID = 0; 31 32 private int p_C_Invoice_ID = 0; 33 34 37 protected void prepare() 38 { 39 ProcessInfoParameter[] para = getParameter(); 40 for (int i = 0; i < para.length; i++) 41 { 42 String name = para[i].getParameterName(); 43 if (para[i].getParameter() == null) 44 ; 45 else if (name.equals("C_Order_ID")) 46 p_C_Order_ID = ((BigDecimal)para[i].getParameter()).intValue(); 47 else if (name.equals("C_Invoice_ID")) 48 p_C_Invoice_ID = ((BigDecimal)para[i].getParameter()).intValue(); 49 else 50 log.error("prepare - Unknown Parameter: " + name); 51 } 52 } 54 59 protected String doIt() throws Exception 60 { 61 log.info("doIt - C_Order_ID=" + p_C_Order_ID + ", C_Invoice_ID=" + p_C_Invoice_ID); 62 if (p_C_Order_ID == 0 && p_C_Invoice_ID == 0) 63 throw new IllegalArgumentException ("Nothing to do"); 64 65 String retValue = ""; 66 if (p_C_Order_ID != 0) 67 { 68 MOrder order = new MOrder (getCtx(), p_C_Order_ID); 69 BigDecimal oldPrice = order.getGrandTotal(); 70 MOrderLine[] lines = order.getLines(); 71 for (int i = 0; i < lines.length; i++) 72 { 73 lines[i].setPrice(); 74 lines[i].save(); 75 } 76 order = new MOrder (getCtx(), p_C_Order_ID); 77 BigDecimal newPrice = order.getGrandTotal(); 78 retValue = order.getDocumentNo() + ": " + oldPrice + " -> " + newPrice; 79 } 80 if (p_C_Invoice_ID != 0) 81 { 82 MInvoice invoice = new MInvoice (getCtx(), p_C_Invoice_ID); 83 BigDecimal oldPrice = invoice.getGrandTotal(); 84 MInvoiceLine[] lines = invoice.getLines(); 85 for (int i = 0; i < lines.length; i++) 86 { 87 lines[i].setPrice(); 88 lines[i].save(); 89 } 90 invoice = new MInvoice (getCtx(), p_C_Invoice_ID); 91 BigDecimal newPrice = invoice.getGrandTotal(); 92 if (retValue.length() > 0) 93 retValue += Env.NL; 94 retValue += invoice.getDocumentNo() + ": " + oldPrice + " -> " + newPrice; 95 } 96 return retValue; 98 } 100 } | Popular Tags |