1 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 28 public class ProjectGenOrder extends SvrProcess 29 { 30 31 private int m_C_Project_ID = 0; 32 33 36 protected void prepare() 37 { 38 ProcessInfoParameter[] para = getParameter(); 39 for (int i = 0; i < para.length; i++) 40 { 41 String 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 } 50 55 protected String doIt() throws Exception 56 { 57 log.info("doIt - C_Project_ID=" + m_C_Project_ID); 58 if (m_C_Project_ID == 0) 59 throw new IllegalArgumentException ("C_Project_ID == 0"); 60 MProject fromProject = getProject (getCtx(), m_C_Project_ID); 61 62 63 64 MOrder order = new MOrder (fromProject, MOrder.DocSubTypeSO_OnCredit); 65 if (!order.save()) 66 throw new Exception ("Could not create Order"); 67 68 int count = 0; 70 71 if (MProject.PROJECTCATEGORY_ServiceChargeProject.equals(fromProject.getProjectCategory())) 73 { 74 75 76 } 78 else { 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 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 } if (lines.length != count) 98 log.error("doIt - Lines difference - ProjectLines=" + lines.length + " <> Saved=" + count); 99 } 101 return "@C_Order_ID@ " + order.getDocumentNo() + " (" + count + ")"; 102 } 104 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 ("Project not found C_Project_ID=" + C_Project_ID); 115 if (fromProject.getM_PriceList_Version_ID() == 0) 116 throw new IllegalArgumentException ("Project has no Price List"); 117 if (fromProject.getM_Warehouse_ID() == 0) 118 throw new IllegalArgumentException ("Project has no Warehouse"); 119 if (fromProject.getC_BPartner_ID() == 0 || fromProject.getC_BPartner_Location_ID() == 0) 120 throw new IllegalArgumentException ("Project has no Business Partner/Location"); 121 return fromProject; 122 } 124 } | Popular Tags |