KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > process > OrderRePrice


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.process;
15
16 import java.math.*;
17
18 import org.compiere.model.*;
19 import org.compiere.util.*;
20
21 /**
22  * Re-Price Order or Invoice
23  *
24  * @author Jorg Janke
25  * @version $Id: OrderRePrice.java,v 1.1 2003/10/04 23:39:26 jjanke Exp $
26  */

27 public class OrderRePrice extends SvrProcess
28 {
29     /** Order to re-price */
30     private int p_C_Order_ID = 0;
31     /** Invoice to re-price */
32     private int p_C_Invoice_ID = 0;
33     
34     /**
35      * Prepare - e.g., get Parameters.
36      */

37     protected void prepare()
38     {
39         ProcessInfoParameter[] para = getParameter();
40         for (int i = 0; i < para.length; i++)
41         {
42             String JavaDoc 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     } // prepare
53

54     /**
55      * Perrform process.
56      * @return Message (clear text)
57      * @throws Exception if not successful
58      */

59     protected String JavaDoc doIt() throws Exception JavaDoc
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 JavaDoc("Nothing to do");
64
65         String JavaDoc 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         //
97
return retValue;
98     } // doIt
99

100 } // OrderRePrice
101
Popular Tags