KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.sql.*;
18
19 import org.compiere.model.*;
20
21 /**
22  * Copy Order and optionally close
23  *
24  * @author Jorg Janke
25  * @version $Id: CopyOrder.java,v 1.1 2003/10/04 23:39:26 jjanke Exp $
26  */

27 public class CopyOrder extends SvrProcess
28 {
29     /** Order to Copy */
30     private int p_C_Order_ID = 0;
31     /** Document Type of new Order */
32     private int p_C_DocType_ID = 0;
33     /** New Doc Date */
34     private Timestamp p_DateDoc = null;
35     /** Close/Process Old Order */
36     private boolean p_IsCloseDocument = false;
37     
38     /**
39      * Prepare - e.g., get Parameters.
40      */

41     protected void prepare()
42     {
43         ProcessInfoParameter[] para = getParameter();
44         for (int i = 0; i < para.length; i++)
45         {
46             String JavaDoc name = para[i].getParameterName();
47             if (para[i].getParameter() == null)
48                 ;
49             else if (name.equals("C_Order_ID"))
50                 p_C_Order_ID = ((BigDecimal)para[i].getParameter()).intValue();
51             else if (name.equals("C_DocType_ID"))
52                 p_C_DocType_ID = ((BigDecimal)para[i].getParameter()).intValue();
53             else if (name.equals("DateDoc"))
54                 p_DateDoc = (Timestamp)para[i].getParameter();
55             else if (name.equals("IsCloseDocument"))
56                 p_IsCloseDocument = "Y".equals(para[i].getParameter());
57             else
58                 log.error("prepare - Unknown Parameter: " + name);
59         }
60     } // prepare
61

62     /**
63      * Perrform process.
64      * @return Message (clear text)
65      * @throws Exception if not successful
66      */

67     protected String JavaDoc doIt() throws Exception JavaDoc
68     {
69         log.info("doIt - C_Order_ID=" + p_C_Order_ID + ", C_DocType_ID=" + p_C_DocType_ID + ", CloseDocument" + p_IsCloseDocument);
70         if (p_C_Order_ID == 0)
71             throw new IllegalArgumentException JavaDoc("No Order");
72         if (p_C_DocType_ID == 0)
73             throw new IllegalArgumentException JavaDoc("No DocType");
74         if (p_DateDoc == null)
75             p_DateDoc = new Timestamp (System.currentTimeMillis());
76         //
77
MOrder newOrder = MOrder.copyFrom(getCtx(), p_C_Order_ID, p_DateDoc);
78         newOrder.setC_DocTypeTarget_ID(p_C_DocType_ID);
79         boolean OK = newOrder.save();
80         if (!OK)
81             throw new IllegalStateException JavaDoc("Could not create new Order");
82         //
83
if (p_IsCloseDocument)
84         {
85             MOrder original = new MOrder (getCtx(), p_C_Order_ID);
86             original.process(MOrder.DOCACTION_Complete);
87             original.save();
88         }
89         //
90
return "@C_Order_ID@ " + newOrder.getDocumentNo();
91     } // doIt
92

93 } // CopyOrder
94
Popular Tags