KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
18
19 import org.compiere.model.*;
20 import org.compiere.util.*;
21
22 /**
23  * Generate Sales Order from Project.
24  *
25  * @author Jorg Janke
26  * @version $Id: ProjectGenOrder.java,v 1.5 2003/11/06 07:08:06 jjanke Exp $
27  */

28 public class ProjectGenOrder extends SvrProcess
29 {
30     /** Project ID from project directly */
31     private int m_C_Project_ID = 0;
32
33     /**
34      * Prepare - e.g., get Parameters.
35      */

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

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

55     protected String JavaDoc doIt() throws Exception JavaDoc
56     {
57         log.info("doIt - C_Project_ID=" + m_C_Project_ID);
58         if (m_C_Project_ID == 0)
59             throw new IllegalArgumentException JavaDoc("C_Project_ID == 0");
60         MProject fromProject = getProject (getCtx(), m_C_Project_ID);
61
62         /** @todo duplicate invoice prevention */
63
64         MOrder order = new MOrder (fromProject, MOrder.DocSubTypeSO_OnCredit);
65         if (!order.save())
66             throw new Exception JavaDoc("Could not create Order");
67
68         // *** Lines ***
69
int count = 0;
70         
71         // Service Project
72
if (MProject.PROJECTCATEGORY_ServiceChargeProject.equals(fromProject.getProjectCategory()))
73         {
74             /** @todo service project invoicing */
75
76         } // Service Lines
77

78         else // Order Lines
79
{
80             MProjectLine[] lines = fromProject.getLines ();
81             for (int i = 0; i < lines.length; i++)
82             {
83                 MOrderLine ol = new MOrderLine(order);
84                 ol.setLine(lines[i].getLine());
85                 ol.setDescription(lines[i].getDescription());
86                 //
87
ol.setM_Product_ID(lines[i].getM_Product_ID());
88                 ol.setQtyOrdered(lines[i].getInvoicedQty());
89                 ol.setPrice();
90                 if (lines[i].getInvoicedAmt() != null && lines[i].getInvoicedAmt().compareTo(Env.ZERO) != 0)
91                     ol.setPriceActual(lines[i].getInvoicedAmt());
92                 ol.setDiscount();
93                 ol.setTax();
94                 if (ol.save())
95                     count++;
96             } // for all lines
97
if (lines.length != count)
98                 log.error("doIt - Lines difference - ProjectLines=" + lines.length + " <> Saved=" + count);
99         } // Order Lines
100

101         return "@C_Order_ID@ " + order.getDocumentNo() + " (" + count + ")";
102     } // doIt
103

104     /**
105      * Get and validate Project
106      * @param ctx context
107      * @param C_Project_ID id
108      * @return valid project
109      */

110     static protected MProject getProject (Properties ctx, int C_Project_ID)
111     {
112         MProject fromProject = new MProject (ctx, C_Project_ID);
113         if (fromProject.getC_Project_ID() == 0)
114             throw new IllegalArgumentException JavaDoc("Project not found C_Project_ID=" + C_Project_ID);
115         if (fromProject.getM_PriceList_Version_ID() == 0)
116             throw new IllegalArgumentException JavaDoc("Project has no Price List");
117         if (fromProject.getM_Warehouse_ID() == 0)
118             throw new IllegalArgumentException JavaDoc("Project has no Warehouse");
119         if (fromProject.getC_BPartner_ID() == 0 || fromProject.getC_BPartner_Location_ID() == 0)
120             throw new IllegalArgumentException JavaDoc("Project has no Business Partner/Location");
121         return fromProject;
122     } // getProject
123

124 } // ProjectGenOrder
125
Popular Tags