KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MOrder


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.model;
15
16 import java.util.*;
17 import java.sql.*;
18 import java.math.*;
19 import java.io.Serializable JavaDoc;
20
21 import org.compiere.process.*;
22 import org.compiere.util.DB;
23 import org.compiere.util.Env;
24 import org.compiere.util.Log;
25
26 /**
27  * Order Model
28  *
29  * @author Jorg Janke
30  * @version $Id: MOrder.java,v 1.25 2003/10/31 05:28:34 jjanke Exp $
31  */

32 public class MOrder extends X_C_Order
33 {
34     /**
35      * Default Constructor
36      * @param ctx context
37      * @param C_Order_ID order to load, (0 create new order)
38      */

39     public MOrder(Properties ctx, int C_Order_ID)
40     {
41         super (ctx, C_Order_ID);
42         // New
43
if (C_Order_ID == 0)
44         {
45             setDocStatus(DOCSTATUS_Drafted);
46             setDocAction (DOCACTION_Process);
47             //
48
setDeliveryRule (DELIVERYRULE_Availability);
49             setFreightCostRule (FREIGHTCOSTRULE_FreightIncluded);
50             setInvoiceRule (INVOICERULE_Immediate);
51             setPaymentRule(PAYMENTRULE_OnCredit);
52             setPriorityRule (PRIORITYRULE_Medium);
53             setDeliveryViaRule (DELIVERYVIARULE_Pickup);
54             //
55
setIsDiscountPrinted (false);
56             setIsSelected (false);
57             setIsTaxIncluded (false);
58             setIsSOTrx (true);
59             setSendEMail (false);
60             //
61
setIsApproved(false);
62             setIsPrinted(false);
63             setIsCreditApproved(false);
64             setIsDelivered(false);
65             setIsInvoiced(false);
66             setIsTransferred(false);
67             setIsSelfService(false);
68             //
69
setProcessed(false);
70             setPosted(false);
71
72             setDateAcct (new Timestamp(System.currentTimeMillis()));
73             setDatePromised (new Timestamp(System.currentTimeMillis()));
74             setDateOrdered (new Timestamp(System.currentTimeMillis()));
75
76             setFreightAmt (Env.ZERO);
77             setChargeAmt (Env.ZERO);
78             setTotalLines (Env.ZERO);
79             setGrandTotal (Env.ZERO);
80         }
81     } // MOrder
82

83     /**
84      * Project Constructor
85      * @param project Project to create Order from
86      * @param DocSubTypeSO DocType Target (default DocSubTypeSO_OnCredit)
87      */

88     public MOrder (MProject project, String JavaDoc DocSubTypeSO)
89     {
90         this (project.getCtx(), 0);
91         setAD_Client_ID(project.getAD_Client_ID());
92         setAD_Org_ID(project.getAD_Org_ID());
93         setC_Campaign_ID(project.getC_Campaign_ID());
94         setSalesRep_ID(project.getSalesRep_ID());
95         //
96
setC_Project_ID(getC_Project_ID());
97         setDescription(project.getName());
98         Timestamp ts = project.getDateContract();
99         if (ts != null)
100             setDateOrdered (ts);
101         ts = project.getDateFinish();
102         if (ts != null)
103             setDatePromised (ts);
104         //
105
setC_BPartner_ID(project.getC_BPartner_ID());
106         setC_BPartner_Location_ID(project.getC_BPartner_Location_ID());
107         setBillTo_ID(project.getC_BPartner_Location_ID());
108         setAD_User_ID(project.getAD_User_ID());
109         //
110
setM_Warehouse_ID(project.getM_Warehouse_ID());
111         setM_PriceList_ID(project.getM_PriceList_ID());
112         setC_PaymentTerm_ID(project.getC_PaymentTerm_ID());
113         //
114
if (DocSubTypeSO == null || DocSubTypeSO.length() == 0)
115             setC_DocTypeTarget_ID(DocSubTypeSO_OnCredit);
116         else
117             setC_DocTypeTarget_ID(DocSubTypeSO);
118     } // MOrder
119

120     /**
121      * Load Constructor
122      * @param ctx context
123      * @param rs result set record
124      */

125     public MOrder (Properties ctx, ResultSet rs)
126     {
127         super (ctx, rs);
128     } // MOrder
129

130     /**
131      * Overwrite Client/Org if required
132      * @param AD_Client_ID client
133      * @param AD_Org_ID org
134      */

135     public void setClientOrg (int AD_Client_ID, int AD_Org_ID)
136     {
137         super.setClientOrg(AD_Client_ID, AD_Org_ID);
138     } // setClientOrg
139

140     /*************************************************************************/
141
142     public static final String JavaDoc DocSubTypeSO_Standard = "SO";
143     public static final String JavaDoc DocSubTypeSO_Quotation = "OB";
144     public static final String JavaDoc DocSubTypeSO_Proposal = "ON";
145     public static final String JavaDoc DocSubTypeSO_Prepay = "PR";
146     public static final String JavaDoc DocSubTypeSO_POS = "WR";
147     public static final String JavaDoc DocSubTypeSO_Warehouse = "WP";
148     public static final String JavaDoc DocSubTypeSO_OnCredit = "WI";
149     public static final String JavaDoc DocSubTypeSO_RMA = "RM";
150
151     /**
152      * Set Target Document Type
153      * @param DocSubTypeSO_x SO sub type - see DocSubTypeSO_*
154      */

155     public void setC_DocTypeTarget_ID (String JavaDoc DocSubTypeSO_x)
156     {
157         String JavaDoc sql = "SELECT C_DocType_ID FROM C_DocType WHERE AD_Client_ID=? AND DocSubTypeSO=?";
158         int C_DocType_ID = DB.getSQLValue(sql, getAD_Client_ID(), DocSubTypeSO_x);
159         if (C_DocType_ID <= 0)
160             log.error ("setC_DocTypeTarget_ID - Not found for AD_Client_ID=" + getAD_Client_ID () + ", SubType=" + DocSubTypeSO_x);
161         else
162         {
163             log.debug("setC_DocTypeTarget_ID - " + DocSubTypeSO_x);
164             setC_DocTypeTarget_ID (C_DocType_ID);
165             setIsSOTrx(true);
166         }
167     } // setC_DocTypeTarget_ID
168

169     /**
170      * Set Target Document Type.
171      * Standard Order or PO
172      */

173     public void setC_DocTypeTarget_ID ()
174     {
175         if (isSOTrx()) // SO = Std Order
176
{
177             setC_DocTypeTarget_ID(DocSubTypeSO_Standard);
178             return;
179         }
180         // PO
181
String JavaDoc sql = "SELECT C_DocType_ID FROM C_DocType WHERE AD_Client_ID=? AND DocBaseType='POO'";
182         int C_DocType_ID = DB.getSQLValue(sql, getAD_Client_ID());
183         if (C_DocType_ID <= 0)
184             log.error ("setC_DocTypeTarget_ID - No POO found for AD_Client_ID=" + getAD_Client_ID ());
185         else
186         {
187             log.debug("setC_DocTypeTarget_ID (PO) - " + C_DocType_ID);
188             setC_DocTypeTarget_ID (C_DocType_ID);
189         }
190     } // setC_DocTypeTarget_ID
191

192
193     /**
194      * Set Doc No explicitly
195      * @param DocumentNo doc no
196      */

197     public void setDocumentNo (String JavaDoc DocumentNo)
198     {
199         super.setDocumentNo(DocumentNo);
200     } // setDocumentNo
201

202
203     /**
204      * Set Business Partner Defaults & Details.
205      * SOTrx should be set.
206      * @param bp business partner
207      */

208     public void setBPartner (MBPartner bp)
209     {
210         if (bp == null)
211             return;
212
213         setC_BPartner_ID(bp.getC_BPartner_ID());
214         // Defaults Payment Term
215
int ii = 0;
216         if (isSOTrx())
217             ii = bp.getC_PaymentTerm_ID();
218         else
219             ii = bp.getPO_PaymentTerm_ID();
220         if (ii != 0)
221             setC_PaymentTerm_ID(ii);
222         // Default Price List
223
if (isSOTrx())
224             ii = bp.getM_PriceList_ID();
225         else
226             ii = bp.getPO_PriceList_ID();
227         if (ii != 0)
228             setM_PriceList_ID(ii);
229         // Default Delivery/Via Rule
230
String JavaDoc ss = bp.getDeliveryRule();
231         if (ss != null)
232             setDeliveryRule(ss);
233         ss = bp.getDeliveryViaRule();
234         if (ss != null)
235             setDeliveryViaRule(ss);
236         // Default Invoice/Payment Rule
237
ss = bp.getInvoiceRule();
238         if (ss != null)
239             setInvoiceRule(ss);
240         ss = bp.getPaymentRule();
241         if (ss != null)
242             setPaymentRule(ss);
243
244
245         // Set Locations
246
MBPartner_Location[] locs = bp.getLocations();
247         if (locs != null)
248         {
249             for (int i = 0; i < locs.length; i++)
250             {
251                 if (locs[i].isBillTo())
252                     setBillTo_ID(locs[i].getC_BPartner_Location_ID());
253                 if (locs[i].isShipTo())
254                     setC_BPartner_Location_ID(locs[i].getC_BPartner_Location_ID());
255             }
256             // set to first
257
if (getBillTo_ID() == 0 && locs.length > 0)
258                 setBillTo_ID(locs[0].getC_BPartner_Location_ID());
259             if (getC_BPartner_Location_ID() == 0 && locs.length > 0)
260                 setC_BPartner_Location_ID(locs[0].getC_BPartner_Location_ID());
261         }
262         if (getBillTo_ID() == 0)
263             log.error("MOrder.setBPartner - Has no Bill To Address: " + bp);
264         if (getC_BPartner_Location_ID() == 0)
265             log.error("MOrder.setBPartner - Has no Ship To Address: " + bp);
266
267         // Set Contact
268
MUser[] contacts = bp.getContacts();
269         if (contacts != null && contacts.length == 1)
270             setAD_User_ID(contacts[0].getAD_User_ID());
271     } // setBPartner
272

273     /**
274      * Set Defaults for mandatory values where not set yet
275      */

276     private void setDefaults ()
277     {
278         int AD_Client_ID = getAD_Client_ID();
279         int AD_Org_ID = getAD_Org_ID();
280         log.debug("setDefaults - " + "Client/Org=" + AD_Client_ID + "/" + AD_Org_ID);
281
282         // No Partner Info - set Template
283
if (getC_BPartner_ID() == 0)
284             setBPartner(MBPartner.getTemplate(getCtx(), getAD_Client_ID()));
285         if (getC_BPartner_Location_ID() == 0 || getBillTo_ID() == 0)
286             setBPartner(new MBPartner(getCtx(), getC_BPartner_ID()));
287
288         // Price List
289
if (getM_PriceList_ID() == 0)
290         {
291             int ii = Env.getContextAsInt(getCtx(), "#M_PriceList_ID");
292             if (ii != 0)
293                 setM_PriceList_ID(ii);
294             else
295             {
296                 String JavaDoc sql = "SELECT M_PriceList_ID FROM M_PriceList WHERE AD_Client_ID=? AND IsDefault='Y'";
297                 ii = DB.getSQLValue (sql, AD_Client_ID);
298                 if (ii != 0)
299                     setM_PriceList_ID (ii);
300             }
301         }
302         // Currency
303
if (getC_Currency_ID() == 0)
304         {
305             String JavaDoc sql = "SELECT C_Currency_ID FROM M_PriceList WHERE M_PriceList_ID=?";
306             int ii = DB.getSQLValue (sql, getM_PriceList_ID());
307             if (ii != 0)
308                 setC_Currency_ID (ii);
309             else
310                 setC_Currency_ID(Env.getContextAsInt(getCtx(), "#C_Currency_ID"));
311         }
312
313         // Sales Rep
314
if (getSalesRep_ID() == 0)
315         {
316             int ii = Env.getContextAsInt(getCtx(), "#SalesRep_ID");
317             if (ii != 0)
318                 setSalesRep_ID (ii);
319         }
320
321         // Document Type
322
if (getC_DocType_ID() == 0)
323             setC_DocType_ID (0); // make sure it's set to 0
324
if (getC_DocTypeTarget_ID() == 0)
325             setC_DocTypeTarget_ID(DocSubTypeSO_Standard);
326
327         // Payment Term
328
if (getC_PaymentTerm_ID() == 0)
329         {
330             int ii = Env.getContextAsInt(getCtx(), "#C_PaymentTerm_ID");
331             if (ii != 0)
332                 setC_PaymentTerm_ID(ii);
333             else
334             {
335                 String JavaDoc sql = "SELECT C_PaymentTerm_ID FROM C_PaymentTerm WHERE AD_Client_ID=? AND IsDefault='Y'";
336                 ii = DB.getSQLValue(sql, AD_Client_ID);
337                 if (ii != 0)
338                     setC_PaymentTerm_ID (ii);
339             }
340         }
341         if (getM_Warehouse_ID() == 0)
342         {
343             int ii = Env.getContextAsInt(getCtx(), "#M_Warehouse_ID");
344             if (ii != 0)
345                 setM_Warehouse_ID(ii);
346         }
347     } // setDefaults
348

349     /**
350      * Copy Lines From other Order
351      * @param order order
352      * @return number of lines copied
353      */

354     public int copyLinesFrom (MOrder order)
355     {
356         if (isProcessed() || isPosted() || order == null)
357             return 0;
358         MOrderLine[] fromLines = order.getLines();
359         int count = 0;
360         for (int i = 0; i < fromLines.length; i++)
361         {
362             MOrderLine line = new MOrderLine (this);
363             PO.copyValues(fromLines[i], line, getAD_Client_ID(), getAD_Org_ID());
364             line.setC_Order_ID(getC_Order_ID());
365             line.setOrder(order);
366             line.setC_OrderLine_ID(0);
367             //
368
line.setQtyDelivered(Env.ZERO);
369             line.setQtyInvoiced(Env.ZERO);
370             line.setDateDelivered(null);
371             line.setDateInvoiced(null);
372             line.setRef_OrderLine_ID(0);
373             line.setTax();
374             if (line.save())
375                 count++;
376         }
377         if (fromLines.length != count)
378             log.error("copyLinesFrom - Line difference - From=" + fromLines.length + " <> Saved=" + count);
379         return count;
380     } // copyLinesFrom
381

382     /*************************************************************************/
383
384     /**
385      * String Representation
386      * @return info
387      */

388     public String JavaDoc toString ()
389     {
390         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ("MOrder[")
391             .append(getID()).append("-").append(getDocumentNo())
392             .append ("]");
393         return sb.toString ();
394     } // toString
395

396     /**
397      * Save Order
398      * @return true if saved
399      */

400     public boolean save ()
401     {
402         log.debug ("save");
403         setDefaults();
404         if (getDocumentNo() == null)
405         {
406             String JavaDoc DocumentNo = DB.getDocumentNo (getAD_Client_ID(), getC_DocTypeTarget_ID());
407             if (DocumentNo == null || DocumentNo.length() == 0)
408                 DocumentNo = DB.getDocumentNo(getAD_Client_ID(), "N", "C_Order");
409             setDocumentNo (DocumentNo);
410         }
411         return super.save ();
412     } // save
413

414     /*************************************************************************/
415
416     /**
417      * Process Order
418      * @param docAction doc action
419      * @return true if no error
420      */

421     public boolean process (String JavaDoc docAction)
422     {
423         setDocAction(docAction);
424         return process();
425     } // process
426

427     /**
428      * Process Order
429      * @return true if no error
430      */

431     public boolean process ()
432     {
433         save();
434         log.debug ("process - " + getDocAction());
435         int AD_Process_ID = 104; // C_Order_Post
436
MProcess pp = new MProcess (getCtx(), AD_Process_ID);
437         boolean ok = pp.process(getC_Order_ID()).isOK();
438         load(); // reload
439
log.debug("process - ok=" + ok + " - GrandTotal=" + getGrandTotal());
440         return ok;
441     } // process
442

443     /**
444      * Set Price List (and Currency) when valid
445      * @param M_PriceList_ID price list
446      */

447     public void setM_PriceList_ID (int M_PriceList_ID)
448     {
449         String JavaDoc sql = "SELECT M_PriceList_ID, C_Currency_ID "
450             + "FROM M_PriceList WHERE M_PriceList_ID=?";
451         PreparedStatement pstmt = null;
452         try
453         {
454             pstmt = DB.prepareStatement(sql);
455             pstmt.setInt(1, M_PriceList_ID);
456             ResultSet rs = pstmt.executeQuery();
457             if (rs.next())
458             {
459                 super.setM_PriceList_ID(rs.getInt(1));
460                 setC_Currency_ID (rs.getInt(2));
461             }
462             rs.close();
463             pstmt.close();
464             pstmt = null;
465         }
466         catch (Exception JavaDoc e)
467         {
468             log.error("MOrder.setM_PriceList_ID", e);
469         }
470         finally
471         {
472             try
473             {
474                 if (pstmt != null)
475                     pstmt.close ();
476             }
477             catch (Exception JavaDoc e)
478             {}
479             pstmt = null;
480         }
481     } // setM_PriceList_ID
482

483     /*************************************************************************/
484
485     /**
486      * Get Invoices of Order
487      * @return invoices
488      */

489     public MOrderLine[] getLines()
490     {
491         return getLines (getC_Order_ID());
492     }
493
494     /**
495      * Get Invoices of Order
496      * @param C_Order_ID id
497      * @return invoices
498      */

499     public MOrderLine[] getLines(int C_Order_ID)
500     {
501         ArrayList list = new ArrayList();
502         String JavaDoc sql = "SELECT * FROM C_OrderLine WHERE C_Order_ID=? ORDER BY Line DESC";
503         PreparedStatement pstmt = null;
504         try
505         {
506             pstmt = DB.prepareStatement(sql);
507             pstmt.setInt(1, C_Order_ID);
508             ResultSet rs = pstmt.executeQuery();
509             while (rs.next())
510             {
511                 list.add(new MOrderLine(getCtx(), rs));
512             }
513             rs.close();
514             pstmt.close();
515             pstmt = null;
516         }
517         catch (Exception JavaDoc e)
518         {
519             log.error("getLines", e);
520         }
521         finally
522         {
523             try
524             {
525                 if (pstmt != null)
526                     pstmt.close ();
527             }
528             catch (Exception JavaDoc e)
529             {}
530             pstmt = null;
531         }
532         //
533
MOrderLine[] retValue = new MOrderLine[list.size()];
534         list.toArray(retValue);
535         return retValue;
536     } // getLines
537

538
539     /**
540      * Get Invoices of Order
541      * @return invoices
542      */

543     public MInvoice[] getInvoices()
544     {
545         ArrayList list = new ArrayList();
546         String JavaDoc sql = "SELECT * FROM C_Invoice WHERE C_Order_ID=? ORDER BY Created DESC";
547         PreparedStatement pstmt = null;
548         try
549         {
550             pstmt = DB.prepareStatement(sql);
551             pstmt.setInt(1, getC_Order_ID());
552             ResultSet rs = pstmt.executeQuery();
553             while (rs.next())
554             {
555                 list.add(new MInvoice(getCtx(), rs));
556             }
557             rs.close();
558             pstmt.close();
559             pstmt = null;
560         }
561         catch (Exception JavaDoc e)
562         {
563             log.error("getInvoices", e);
564         }
565         finally
566         {
567             try
568             {
569                 if (pstmt != null)
570                     pstmt.close ();
571             }
572             catch (Exception JavaDoc e)
573             {}
574             pstmt = null;
575         }
576         //
577
MInvoice[] retValue = new MInvoice[list.size()];
578         list.toArray(retValue);
579         return retValue;
580     } // getInvoices
581

582     /**
583      * Get latest Invoice of Order
584      * @return invoice id or 0
585      */

586     public int getC_Invoice_ID()
587     {
588         int C_Invoice_ID = 0;
589         ArrayList list = new ArrayList();
590         String JavaDoc sql = "SELECT C_Invoice_ID FROM C_Invoice "
591             + "WHERE C_Order_ID=? AND DocStatus IN ('CO','CL') "
592             + "ORDER BY Created DESC";
593         PreparedStatement pstmt = null;
594         try
595         {
596             pstmt = DB.prepareStatement(sql);
597             pstmt.setInt(1, getC_Order_ID());
598             ResultSet rs = pstmt.executeQuery();
599             if (rs.next())
600                 C_Invoice_ID = rs.getInt(1);
601             rs.close();
602             pstmt.close();
603             pstmt = null;
604         }
605         catch (Exception JavaDoc e)
606         {
607             log.error("getC_Invoice_ID", e);
608         }
609         finally
610         {
611             try
612             {
613                 if (pstmt != null)
614                     pstmt.close ();
615             }
616             catch (Exception JavaDoc e)
617             {}
618             pstmt = null;
619         }
620         return C_Invoice_ID;
621     } // getC_Invoice_ID
622

623
624     /**
625      * Get Shipments of Order
626      * @return shipments
627      */

628     public MInOut[] getShipments()
629     {
630         ArrayList list = new ArrayList();
631         String JavaDoc sql = "SELECT * FROM M_InOut WHERE C_Order_ID=? ORDER BY Created DESC";
632         PreparedStatement pstmt = null;
633         try
634         {
635             pstmt = DB.prepareStatement(sql);
636             pstmt.setInt(1, getC_Order_ID());
637             ResultSet rs = pstmt.executeQuery();
638             while (rs.next())
639             {
640                 list.add(new MInOut(getCtx(), rs));
641             }
642             rs.close();
643             pstmt.close();
644             pstmt = null;
645         }
646         catch (Exception JavaDoc e)
647         {
648             log.error("getShipments", e);
649         }
650         finally
651         {
652             try
653             {
654                 if (pstmt != null)
655                     pstmt.close ();
656             }
657             catch (Exception JavaDoc e)
658             {}
659             pstmt = null;
660         }
661         //
662
MInOut[] retValue = new MInOut[list.size()];
663         list.toArray(retValue);
664         return retValue;
665     } // getShipments
666

667     /**
668      * Get ISO Code of Currency
669      * @return Currency ISO
670      */

671     public String JavaDoc getCurrencyISO()
672     {
673         return MCurrency.getISO_Code (getCtx(), getC_Currency_ID());
674     } // getCurrencyISO
675

676     /**
677      * Get Document Status
678      * @return Document Status Clear Text
679      */

680     public String JavaDoc getDocStatusName()
681     {
682         return MRef_List.getListName(getCtx(), 131, getDocStatus());
683     } // getDocStatusName
684

685
686     /**
687      * Create new Order by copying
688      * @param ctx context
689      * @param C_Order_ID invoice
690      * @param dateDoc date of the document date
691      * @return Order
692      */

693     public static MOrder copyFrom (Properties ctx, int C_Order_ID, Timestamp dateDoc)
694     {
695         MOrder from = new MOrder (ctx, C_Order_ID);
696         if (from.getC_Order_ID() == 0)
697             throw new IllegalArgumentException JavaDoc ("From Invoice not found C_Invoice_ID=" + C_Order_ID);
698         //
699
MOrder to = new MOrder (ctx, 0);
700         PO.copyValues(from, to, from.getAD_Client_ID(), from.getAD_Org_ID());
701         to.setC_Order_ID(0);
702         to.setValueNoCheck ("DocumentNo", null);
703         //
704
to.setDocStatus (DOCSTATUS_Drafted); // Draft
705
to.setDocAction(DOCACTION_Process);
706         to.setC_DocTypeTarget_ID(to.getC_DocType_ID());
707         to.setC_DocType_ID(0);
708         to.setIsSelected (false);
709         to.setDateOrdered (dateDoc);
710         to.setDateAcct (dateDoc);
711         to.setDatePromised (dateDoc);
712         //
713
to.setIsApproved (false);
714         to.setIsCreditApproved(false);
715         to.setC_Payment_ID(0);
716         to.setC_CashLine_ID(0);
717         // Amounts are updated by trigger when adding lines
718
to.setGrandTotal(Env.ZERO);
719         to.setTotalLines(Env.ZERO);
720         //
721
to.setIsDelivered(false);
722         to.setIsInvoiced(false);
723         to.setIsSelfService(false);
724         to.setDatePrinted(null);
725         to.setIsPrinted (false);
726         to.setIsTransferred (false);
727         to.setPosted (false);
728         to.setProcessed (false);
729         //
730
if (!to.save())
731             throw new IllegalStateException JavaDoc("Could not create Order");
732
733         if (to.copyLinesFrom(from) == 0)
734             throw new IllegalStateException JavaDoc("Could not create Order Lines");
735
736         return to;
737     } // copyFrom
738

739 } // MOrder
740
Popular Tags