KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > compiere > custom > XXVisit


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 com.compiere.custom;
15
16 import java.math.*;
17 import org.compiere.model.*;
18 import org.compiere.process.*;
19
20 /**
21  * Example Process
22  *
23  * @author Jorg Janke
24  * @version $Id: XXVisit.java,v 1.2 2003/09/29 04:07:49 jjanke Exp $
25  */

26 public class XXVisit extends SvrProcess
27 {
28     // Local (Parameter) Variable
29
private int m_XX_Visit_ID;
30
31     /**
32      * Preparation
33      * @see org.compiere.process.SvrProcess#prepare()
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         m_XX_Visit_ID = getRecord_ID();
47     }
48
49     /**
50      * The Worker Process
51      * @see org.compiere.process.SvrProcess#doIt()
52      */

53     protected String JavaDoc doIt() throws Exception JavaDoc
54     {
55         // Test Parameter
56
if (m_XX_Visit_ID == 0)
57             throw new IllegalArgumentException JavaDoc("No Visit");
58         // Load Data
59
X_XX_Visit visit = new X_XX_Visit(getCtx(), m_XX_Visit_ID);
60         if (visit.getXX_Visit_ID() == 0)
61             throw new IllegalArgumentException JavaDoc("Visit does not exist");
62         // Create Header
63
MInvoice invoice = new MInvoice(getCtx(), 0);
64         invoice.setC_BPartner_ID(visit.getC_BPartner_ID());
65         invoice.setC_BPartner_Location_ID(visit.getC_BPartner_Location_ID());
66         invoice.save();
67         // Create Lines
68
MInvoiceLine line = new MInvoiceLine(invoice);
69         line.setDescription(visit.getDescription());
70         line.setQtyInvoiced(new BigDecimal(visit.getMinutes()));
71         line.setPriceActual(new BigDecimal(5)); // harcoded price
72
// No need for product
73
// The proper way would to have a product and price list;
74
// The method line.setPrice() then sets the correct price
75
line.save();
76         //
77
/**
78          * You should add a field "Processed CHAR(1) DEFAULTS 'N'"
79          * to the table and set the window type to Transaction.
80         visit.setProcessed (true);
81         visit.save();
82          */

83         
84         return "@C_Invoice_ID@ " + invoice.getDocumentNo();
85     } // doIt
86

87 } // XXVisit
88
Popular Tags