1 14 package org.compiere.process; 15 16 import java.math.*; 17 18 import org.compiere.model.*; 19 import org.compiere.util.*; 20 21 22 28 public class ProjectPhaseGenOrder extends SvrProcess 29 { 30 private int m_C_ProjectPhase_ID = 0; 31 32 35 protected void prepare() 36 { 37 ProcessInfoParameter[] para = getParameter(); 38 for (int i = 0; i < para.length; i++) 39 { 40 String name = para[i].getParameterName(); 41 if (para[i].getParameter() == null) 42 ; 43 else 44 log.error("prepare - Unknown Parameter: " + name); 45 } 46 } 48 53 protected String doIt() throws Exception  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 ("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 ("Could not create Order"); 65 66 if (fromPhase.getM_Product_ID() != 0) 68 { 69 MOrderLine ol = new MOrderLine(order); 70 ol.setLine(fromPhase.getSeqNo()); 71 StringBuffer sb = new StringBuffer (fromPhase.getName()); 72 if (fromPhase.getDescription() != null && fromPhase.getDescription().length() > 0) 73 sb.append(" - ").append(fromPhase.getDescription()); 74 ol.setDescription(sb.toString()); 75 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 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 sb = new StringBuffer (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 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 } 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 } 112 } | Popular Tags |