1 14 package org.compiere.process; 15 16 import java.math.*; 17 import java.util.*; 18 import java.sql.*; 19 20 import org.compiere.model.*; 21 import org.compiere.util.*; 22 23 29 public class ProjectIssue extends SvrProcess 30 { 31 32 private int m_C_Project_ID = 0; 33 34 private int m_M_InOut_ID = 0; 35 36 private int m_S_TimeExpense_ID = 0; 37 38 private int m_M_Locator_ID = 0; 39 40 private int m_C_ProjectLine_ID = 0; 41 42 private int m_M_Product_ID = 0; 43 44 private int m_M_AttributeSetInstance_ID = 0; 45 46 private BigDecimal m_MovementQty = null; 47 48 private Timestamp m_MovementDate = null; 49 50 private String m_Description = null; 51 52 53 private MProject m_project = null; 54 55 private MProjectIssue[] m_projectIssues = null; 56 57 58 61 protected void prepare() 62 { 63 ProcessInfoParameter[] para = getParameter(); 64 for (int i = 0; i < para.length; i++) 65 { 66 String name = para[i].getParameterName(); 67 if (para[i].getParameter() == null) 68 ; 69 else if (name.equals("C_Project_ID")) 70 m_C_Project_ID = ((BigDecimal)para[i].getParameter()).intValue(); 71 else if (name.equals("M_InOut_ID")) 72 m_M_InOut_ID = ((BigDecimal)para[i].getParameter()).intValue(); 73 else if (name.equals("S_TimeExpense_ID")) 74 m_S_TimeExpense_ID = ((BigDecimal)para[i].getParameter()).intValue(); 75 else if (name.equals("M_Locator_ID")) 76 m_M_Locator_ID = ((BigDecimal)para[i].getParameter()).intValue(); 77 else if (name.equals("C_ProjectLine_ID")) 78 m_C_ProjectLine_ID = ((BigDecimal)para[i].getParameter()).intValue(); 79 else if (name.equals("M_Product_ID")) 80 m_M_Product_ID = ((BigDecimal)para[i].getParameter()).intValue(); 81 else if (name.equals("M_AttributeSetInstance_ID")) 82 m_M_AttributeSetInstance_ID = ((BigDecimal)para[i].getParameter()).intValue(); 83 else if (name.equals("MovementQty")) 84 m_MovementQty = (BigDecimal)para[i].getParameter(); 85 else if (name.equals("MovementDate")) 86 m_MovementDate = (Timestamp)para[i].getParameter(); 87 else if (name.equals("Description")) 88 m_Description = (String )para[i].getParameter(); 89 else 90 log.error("prepare - Unknown Parameter: " + name); 91 } 92 } 94 99 protected String doIt() throws Exception 100 { 101 m_project = new MProject (getCtx(), m_C_Project_ID); 103 if (!(MProject.PROJECTCATEGORY_WorkOrderJob.equals(m_project.getProjectCategory()) 104 || MProject.PROJECTCATEGORY_AssetProject.equals(m_project.getProjectCategory()))) 105 throw new IllegalArgumentException ("Project not Work Order or Asset =" + m_project.getProjectCategory()); 106 log.info("doIt - " + m_project); 107 if (m_M_InOut_ID != 0) 109 return issueReceipt(); 110 if (m_S_TimeExpense_ID != 0) 111 return issueExpense(); 112 if (m_M_Locator_ID == 0) 113 throw new IllegalArgumentException ("Locator missing"); 114 if (m_C_ProjectLine_ID != 0) 115 return issueProjectLine(); 116 return issueInventory(); 117 } 119 123 private String issueReceipt() 124 { 125 MInOut inOut = new MInOut (getCtx(), m_M_InOut_ID); 126 if (inOut.isSOTrx() || !inOut.isProcessed() 127 || !(MInOut.DOCSTATUS_Completed.equals(inOut.getDocStatus()) || MInOut.DOCSTATUS_Closed.equals(inOut.getDocStatus()))) 128 throw new IllegalArgumentException ("Receipt not valid - " + inOut); 129 log.info("issueReceipt - " + inOut); 130 if (inOut.getC_Project_ID() == 0) 132 { 133 inOut.setC_Project_ID(m_project.getC_Project_ID()); 134 inOut.save(); 135 } 136 else if (inOut.getC_Project_ID() == m_project.getC_Project_ID()) 137 throw new IllegalArgumentException ("Receipt for other Project"); 138 139 MInOutLine[] inOutLines = inOut.getMInOutLines(); 140 int counter = 0; 141 for (int i = 0; i < inOutLines.length; i++) 142 { 143 if (inOutLines[i].getM_Product_ID() == 0) 145 continue; 146 if (inOutLines[i].getMovementQty() == null || inOutLines[i].getMovementQty().compareTo(Env.ZERO) == 0) 148 continue; 149 if (projectIssueHasReceipt(inOutLines[i].getM_InOutLine_ID())) 151 continue; 152 MProjectIssue pi = new MProjectIssue (m_project); 154 pi.setMandatory (inOutLines[i].getM_Locator_ID(), inOutLines[i].getM_Product_ID(), inOutLines[i].getMovementQty()); 155 if (m_MovementDate != null) pi.setMovementDate(m_MovementDate); 157 if (m_Description != null && m_Description.length() > 0) 158 pi.setDescription(m_Description); 159 else if (inOutLines[i].getDescription() != null) 160 pi.setDescription(inOutLines[i].getDescription()); 161 else if (inOut.getDescription() != null) 162 pi.setDescription(inOut.getDescription()); 163 pi.setM_InOutLine_ID(inOutLines[i].getM_InOutLine_ID()); 164 pi.process(); 165 166 MProjectLine pl = null; 168 MProjectLine[] pls = m_project.getLines(); 169 for (int ii = 0; ii < pls.length; ii++) 170 { 171 if (pls[ii].getC_OrderPO_ID() == inOut.getC_Order_ID() 173 && pls[ii].getM_Product_ID() == inOutLines[i].getM_Product_ID() 174 && pls[ii].getC_ProjectIssue_ID() == 0) { 176 pl = pls[ii]; 177 break; 178 } 179 } 180 if (pl == null) 181 pl = new MProjectLine(m_project); 182 pl.setMProjectIssue(pi); pl.save(); 184 addLog(pi.getLine(), pi.getMovementDate(), pi.getMovementQty(), null); 185 counter++; 186 } 188 return "@Created@ " + counter; 189 } 191 192 196 private String issueExpense() 197 { 198 MTimeExpense expense = new MTimeExpense (getCtx(), m_S_TimeExpense_ID); 200 if (!expense.isProcessed()) 201 throw new IllegalArgumentException ("Time+Expense not processed - " + expense); 202 203 MTimeExpenseLine[] expenseLines = expense.getLines(); 205 int counter = 0; 206 for (int i = 0; i < expenseLines.length; i++) 207 { 208 if (expenseLines[i].getM_Product_ID() == 0) 210 continue; 211 if (expenseLines[i].getQty() == null || expenseLines[i].getQty().compareTo(Env.ZERO) == 0) 213 continue; 214 if (expenseLines[i].getC_Project_ID() != m_project.getC_Project_ID()) 216 continue; 217 if (projectIssueHasExpense(expenseLines[i].getS_TimeExpenseLine_ID())) 219 continue; 220 221 int M_Locator_ID = 0; 223 M_Locator_ID = MStorage.getM_Location_ID(expense.getM_Warehouse_ID(), expenseLines[i].getM_Product_ID()); 226 if (M_Locator_ID == 0) M_Locator_ID = expense.getM_Locator_ID(); 228 229 MProjectIssue pi = new MProjectIssue (m_project); 231 pi.setMandatory (M_Locator_ID, expenseLines[i].getM_Product_ID(), expenseLines[i].getQty()); 232 if (m_MovementDate != null) pi.setMovementDate(m_MovementDate); 234 if (m_Description != null && m_Description.length() > 0) 235 pi.setDescription(m_Description); 236 else if (expenseLines[i].getDescription() != null) 237 pi.setDescription(expenseLines[i].getDescription()); 238 pi.setS_TimeExpenseLine_ID(expenseLines[i].getS_TimeExpenseLine_ID()); 239 pi.process(); 240 MProjectLine pl = new MProjectLine(m_project); 242 pl.setMProjectIssue(pi); pl.save(); 244 addLog(pi.getLine(), pi.getMovementDate(), pi.getMovementQty(), null); 245 counter++; 246 } 248 return "@Created@ " + counter; 249 } 251 252 256 private String issueProjectLine() 257 { 258 MProjectLine pl = new MProjectLine(getCtx(), m_C_ProjectLine_ID); 259 if (pl.getM_Product_ID() == 0) 260 throw new IllegalArgumentException ("Projet Line has no Product"); 261 if (pl.getC_ProjectIssue_ID() != 0) 262 throw new IllegalArgumentException ("Projet Line already been issued"); 263 if (m_M_Locator_ID == 0) 264 throw new IllegalArgumentException ("No Locator"); 265 if (pl.getPlannedQty() == null || pl.getPlannedQty().compareTo(Env.ZERO) == 0) 267 pl.setPlannedQty(Env.ONE); 268 MProjectIssue pi = new MProjectIssue (m_project); 270 pi.setMandatory (m_M_Locator_ID, pl.getM_Product_ID(), pl.getPlannedQty()); 271 if (m_MovementDate != null) pi.setMovementDate(m_MovementDate); 273 if (m_Description != null && m_Description.length() > 0) 274 pi.setDescription(m_Description); 275 else if (pl.getDescription() != null) 276 pi.setDescription(pl.getDescription()); 277 pi.process(); 278 279 pl.setMProjectIssue(pi); 281 pl.save(); 282 addLog(pi.getLine(), pi.getMovementDate(), pi.getMovementQty(), null); 283 return "@Created@ 1"; 284 } 286 287 291 private String issueInventory() 292 { 293 if (m_M_Locator_ID == 0) 294 throw new IllegalArgumentException ("No Locator"); 295 if (m_M_Product_ID == 0) 296 throw new IllegalArgumentException ("No Product"); 297 if (m_MovementQty == null || m_MovementQty.compareTo(Env.ZERO) == 0) 299 m_MovementQty = Env.ONE; 300 MProjectIssue pi = new MProjectIssue (m_project); 302 pi.setMandatory (m_M_Locator_ID, m_M_Product_ID, m_MovementQty); 303 if (m_MovementDate != null) pi.setMovementDate(m_MovementDate); 305 if (m_Description != null && m_Description.length() > 0) 306 pi.setDescription(m_Description); 307 pi.process(); 308 309 MProjectLine pl = new MProjectLine(m_project); 311 pl.setMProjectIssue(pi); 312 pl.save(); 313 addLog(pi.getLine(), pi.getMovementDate(), pi.getMovementQty(), null); 314 return "@Created@ 1"; 315 } 317 322 private boolean projectIssueHasExpense (int S_TimeExpenseLine_ID) 323 { 324 if (m_projectIssues == null) 325 m_projectIssues = m_project.getIssues(); 326 for (int i = 0; i < m_projectIssues.length; i++) 327 { 328 if (m_projectIssues[i].getS_TimeExpenseLine_ID() == S_TimeExpenseLine_ID) 329 return true; 330 } 331 return false; 332 } 334 339 private boolean projectIssueHasReceipt (int M_InOutLine_ID) 340 { 341 if (m_projectIssues == null) 342 m_projectIssues = m_project.getIssues(); 343 for (int i = 0; i < m_projectIssues.length; i++) 344 { 345 if (m_projectIssues[i].getM_InOutLine_ID() == M_InOutLine_ID) 346 return true; 347 } 348 return false; 349 } 351 } | Popular Tags |