1 14 package org.compiere.acct; 15 16 import java.math.*; 17 import java.util.*; 18 import java.sql.*; 19 20 import org.compiere.util.*; 21 import org.compiere.model.*; 22 23 32 public class Doc_ProjectIssue extends Doc 33 { 34 35 public static final int AD_TABLE_ID = 623; 36 37 public static final String DOCUMENTTYPE = "PJI"; 38 39 43 public Doc_ProjectIssue (int AD_Client_ID) 44 { 45 super (AD_Client_ID); 46 p_vo.DocumentType = DOCUMENTTYPE; 47 } 49 50 private boolean m_assetProject = false; 51 52 private DocLine_Material m_line = null; 53 54 private int m_S_TimeExpenseLine_ID = 0; 55 56 private int m_M_InOutLine_ID = 0; 57 58 59 63 public int getAD_Table_ID() 64 { 65 return AD_TABLE_ID; 66 } 68 72 public String getTableName() 73 { 74 return "C_ProjectIssue"; 75 } 77 82 protected boolean loadDocumentDetails(ResultSet rs) 83 { 84 p_vo.C_Currency_ID = NO_CURRENCY; 85 try 86 { 87 p_vo.DateDoc = rs.getTimestamp("MovementDate"); 88 m_M_InOutLine_ID = rs.getInt("M_InOutLine_ID"); 89 m_S_TimeExpenseLine_ID = rs.getInt("S_TimeExpenseLine_ID"); 90 91 m_line = new DocLine_Material (p_vo.DocumentType, p_vo.Record_ID, p_vo.Record_ID); 93 m_line.loadAttributes(rs, p_vo); 94 m_line.setQty (rs.getBigDecimal("MovementQty")); m_line.setM_Locator_ID (rs.getInt("M_Locator_ID")); 96 } 97 catch (SQLException e) 98 { 99 log.error("loadDocumentDetails", e); 100 } 101 102 if (m_line.getM_Product_ID() == 0) 104 log.warn(m_line.toString() + " - No Product"); 105 log.debug(m_line.toString()); 106 107 loadProjectCategory(); 109 return true; 110 } 112 115 private void loadProjectCategory() 116 { 117 String sql = "SELECT pj.ProjectCategory FROM C_ProjectType pj" 118 + " INNER JOIN C_Project p ON (p.C_ProjectType_ID=pj.C_ProjectType_ID) " 119 + "WHERE C_Project_ID=?"; 120 PreparedStatement pstmt = null; 121 try 122 { 123 pstmt = DB.prepareCall(sql); 124 pstmt.setInt(1, p_vo.C_Project_ID); 125 ResultSet rs = pstmt.executeQuery(); 126 if (rs.next()) 127 { 128 String pc = rs.getString(1); 129 if (MProjectType.PROJECTCATEGORY_AssetProject.equals(pc)) 130 m_assetProject = true; 131 } 132 else 133 log.warn("loadProjectCategory - Not found for C_Project_ID=" + p_vo.C_Project_ID); 134 rs.close(); 135 pstmt.close(); 136 pstmt = null; 137 } 138 catch (Exception e) 139 { 140 log.error("loadProjectCategory", e); 141 } 142 try 143 { 144 if (pstmt != null) 145 pstmt.close(); 146 pstmt = null; 147 } 148 catch (Exception e) 149 { 150 pstmt = null; 151 } 152 } 154 158 public BigDecimal getBalance() 159 { 160 BigDecimal retValue = Env.ZERO; 161 return retValue; 162 } 164 176 public Fact createFact(AcctSchema as) 177 { 178 p_vo.C_Currency_ID = as.getC_Currency_ID(); 179 Fact fact = new Fact(this, as, Fact.POST_Actual); 181 182 FactLine dr = null; 184 FactLine cr = null; 185 186 BigDecimal cost = null; 188 if (m_M_InOutLine_ID != 0) 189 cost = getPOCost(as); 190 else if (m_S_TimeExpenseLine_ID != 0) 191 cost = getLaborCost(as); 192 if (cost == null) cost = m_line.getProductCosts(as); 194 dr = fact.createLine(m_line, 196 getAccount(m_assetProject ? ACCTTYPE_ProjectAsset : ACCTTYPE_ProjectWIP, as), 197 as.getC_Currency_ID(), cost, null); 198 cr = fact.createLine(m_line, 200 m_line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as), 201 as.getC_Currency_ID(), null, cost); 202 cr.setM_Locator_ID(m_line.getM_Locator_ID()); 203 cr.setLocationFromLocator(m_line.getM_Locator_ID(), true); return fact; 205 } 207 212 private BigDecimal getPOCost(AcctSchema as) 213 { 214 BigDecimal retValue = null; 215 String sql = "SELECT C_Currency_Convert(ol.PriceActual, o.C_Currency_ID, ?, o.DateOrdered, 'S', ?, ?) " 217 + "FROM C_OrderLine ol" 218 + " INNER JOIN M_InOutLine iol ON (iol.C_OrderLine_ID=ol.C_OrderLine_ID)" 219 + " INNER JOIN C_Order o ON (o.C_Order_ID=ol.C_Order_ID) " 220 + "WHERE iol.M_InOutLine_ID=?"; 221 PreparedStatement pstmt = null; 222 try 223 { 224 pstmt = DB.prepareCall(sql); 225 pstmt.setInt(1, as.getC_Currency_ID()); 226 pstmt.setInt(2, p_vo.AD_Client_ID); 227 pstmt.setInt(3, p_vo.AD_Org_ID); 228 pstmt.setInt(4, m_M_InOutLine_ID); 229 ResultSet rs = pstmt.executeQuery(); 230 if (rs.next()) 231 { 232 retValue = rs.getBigDecimal(1); 233 log.debug("getPOCost = " + retValue); 234 } 235 else 236 log.warn("getPOCost - Not found for M_InOutLine_ID=" + m_M_InOutLine_ID); 237 rs.close(); 238 pstmt.close(); 239 pstmt = null; 240 } 241 catch (Exception e) 242 { 243 log.error("getPOCost", e); 244 } 245 try 246 { 247 if (pstmt != null) 248 pstmt.close(); 249 pstmt = null; 250 } 251 catch (Exception e) 252 { 253 pstmt = null; 254 } 255 return retValue; 256 } 258 263 private BigDecimal getLaborCost(AcctSchema as) 264 { 265 BigDecimal retValue = null; 266 267 return retValue; 268 } 270 } 272 | Popular Tags |