KickJava   Java API By Example, From Geeks To Geeks.

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


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 Smart 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 /**
23  * Generate Order from Project Phase
24  *
25  * @author Jorg Janke
26  * @version $Id: ProjectPhaseGenOrder.java,v 1.4 2003/09/05 04:59:48 jjanke Exp $
27  */

28 public class ProjectPhaseGenOrder extends SvrProcess
29 {
30     private int m_C_ProjectPhase_ID = 0;
31
32     /**
33      * Prepare - e.g., get Parameters.
34      */

35     protected void prepare()
36     {
37         ProcessInfoParameter[] para = getParameter();
38         for (int i = 0; i < para.length; i++)
39         {
40             String JavaDoc name = para[i].getParameterName();
41             if (para[i].getParameter() == null)
42                 ;
43             else
44                 log.error("prepare - Unknown Parameter: " + name);
45         }
46     } // prepare
47

48     /**
49      * Perrform process.
50      * @return Message (clear text)
51      * @throws Exception if not successful
52      */

53     protected String JavaDoc doIt() throws Exception JavaDoc
54     {
55         int m_C_ProjectPhase_ID = getRecord_ID();
56         log.info("doIt - C_ProjectPhase_ID=" + m_C_ProjectPhase_ID);
57         if (m_C_ProjectPhase_ID == 0)
58             throw new IllegalArgumentException JavaDoc("C_ProjectPhase_ID == 0");
59         MProjectPhase fromPhase = new MProjectPhase (getCtx(), m_C_ProjectPhase_ID);
60         MProject fromProject = ProjectGenOrder.getProject (getCtx(), fromPhase.getC_Project_ID());
61         MOrder order = new MOrder (fromProject, MOrder.DocSubTypeSO_OnCredit);
62         order.setDescription(order.getDescription() + " - " + fromPhase.getName());
63         if (!order.save())
64             throw new Exception JavaDoc("Could not create Order");
65
66         // Create an order on Phase Level
67
if (fromPhase.getM_Product_ID() != 0)
68         {
69             MOrderLine ol = new MOrderLine(order);
70             ol.setLine(fromPhase.getSeqNo());
71             StringBuffer JavaDoc sb = new StringBuffer JavaDoc (fromPhase.getName());
72             if (fromPhase.getDescription() != null && fromPhase.getDescription().length() > 0)
73                 sb.append(" - ").append(fromPhase.getDescription());
74             ol.setDescription(sb.toString());
75             //
76
ol.setM_Product_ID(fromPhase.getM_Product_ID());
77             ol.setQtyOrdered(fromPhase.getQty());
78             ol.setPrice();
79             if (fromPhase.getPriceActual() != null && fromPhase.getPriceActual().compareTo(Env.ZERO) != 0)
80                 ol.setPriceActual(fromPhase.getPriceActual());
81             ol.setTax();
82             if (!ol.save())
83                 log.error("doIt - Lines not generated");
84             return "@C_Order_ID@ " + order.getDocumentNo() + " (1)";
85         }
86
87         // Project Tasks
88
int count = 0;
89         MProjectTask[] tasks = fromPhase.getTasks ();
90         for (int i = 0; i < tasks.length; i++)
91         {
92             MOrderLine ol = new MOrderLine(order);
93             ol.setLine(tasks[i].getSeqNo());
94             StringBuffer JavaDoc sb = new StringBuffer JavaDoc (tasks[i].getName());
95             if (tasks[i].getDescription() != null && tasks[i].getDescription().length() > 0)
96                 sb.append(" - ").append(tasks[i].getDescription());
97             ol.setDescription(sb.toString());
98             //
99
ol.setM_Product_ID(tasks[i].getM_Product_ID());
100             ol.setQtyOrdered(tasks[i].getQty());
101             ol.setPrice();
102             ol.setTax();
103             if (ol.save())
104                 count++;
105         } // for all lines
106
if (tasks.length != count)
107             log.error("doIt - Lines difference - ProjectTasks=" + tasks.length + " <> Saved=" + count);
108
109         return "@C_Order_ID@ " + order.getDocumentNo() + " (" + count + ")";
110     } // doIt
111

112 } // ProjectPhaseGenOrder
113
Popular Tags