1 14 package org.compiere.model; 15 16 import java.sql.*; 17 import java.util.*; 18 import java.math.*; 19 20 import org.compiere.util.*; 21 22 28 public class MProjectIssue extends X_C_ProjectIssue 29 { 30 31 36 public MProjectIssue (Properties ctx, int C_ProjectIssue_ID) 37 { 38 super (ctx, C_ProjectIssue_ID); 39 52 } 54 59 public MProjectIssue (Properties ctx, ResultSet rs) 60 { 61 super (ctx, rs); 62 } 64 68 public MProjectIssue (MProject project) 69 { 70 super (project.getCtx(), 0); 71 setClientOrg(project.getAD_Client_ID(), project.getAD_Org_ID()); 72 setC_Project_ID (project.getC_Project_ID()); setLine (getNextLine()); 75 setM_Locator_ID (0); 77 setM_Product_ID (0); 78 setMovementDate (new Timestamp(System.currentTimeMillis())); 80 setMovementQty (Env.ZERO); 81 setPosted (false); 82 setProcessed (false); 83 } 85 89 private int getNextLine() 90 { 91 return DB.getSQLValue("SELECT COALESCE(MAX(Line),0)+10 FROM C_ProjectIssue WHERE C_Project_ID=?", getC_Project_ID()); 92 } 94 100 public void setMandatory (int M_Locator_ID, int M_Product_ID, BigDecimal MovementQty) 101 { 102 setM_Locator_ID (M_Locator_ID); 103 setM_Product_ID (M_Product_ID); 104 setMovementQty (MovementQty); 105 } 107 108 109 113 public boolean process() 114 { 115 if (!save()) 116 return false; 117 if (getM_Product_ID() == 0) 118 { 119 log.error("process - No Product"); 120 return false; 121 } 122 123 MProduct product = new MProduct (getCtx(), getM_Product_ID()); 124 125 if (MProduct.PRODUCTTYPE_Item.equals(product.getProductType()) && product.isStocked()) 127 { 128 setProcessed(true); 129 return save(); 130 } 131 132 133 134 MTransaction trx = new MTransaction (getCtx(), MTransaction.MOVEMENTTYPE_WorkOrderPlus, 136 getM_Locator_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(), 137 getMovementQty().negate(), getMovementDate()); 138 if (MStorage.add(getCtx(), getM_Locator_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(), 140 getMovementQty().negate(), null, null)) 141 { 142 if (trx.save()) 143 { 144 setProcessed (true); 145 if (save()) 146 return true; 147 else 148 log.error("process - Issue not saved"); } 150 else 151 log.error("process - Transaction not saved"); } 153 else 154 log.error("process - Storage not updated"); return false; 157 } 159 }
| Popular Tags
|