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_MatchPO extends Doc 33 { 34 38 protected Doc_MatchPO(int AD_Client_ID) 39 { 40 super(AD_Client_ID); 41 } 43 private int m_C_OrderLine_ID = 0; 44 private int m_M_InOutLine_ID = 0; 45 private int m_C_InvoiceLine_ID = 0; 46 private ProductInfo m_pi; 47 48 52 public String getTableName() 53 { 54 return "M_MatchPO"; 55 } 57 61 public int getAD_Table_ID() 62 { 63 return 473; 64 } 66 71 protected boolean loadDocumentDetails (ResultSet rs) 72 { 73 p_vo.DocumentType = DocVO.DOCTYPE_MatMatchPO; 74 try 75 { 76 p_vo.DateDoc = rs.getTimestamp("DateTrx"); 77 p_vo.M_Product_ID = rs.getInt("M_Product_ID"); 78 p_vo.Qty = rs.getBigDecimal("Qty"); 79 m_C_OrderLine_ID = rs.getInt("C_OrderLine_ID"); 80 m_M_InOutLine_ID = rs.getInt("M_InOutLine_ID"); 81 m_C_InvoiceLine_ID = rs.getInt("C_InvoiceLine_ID"); 82 m_pi = new ProductInfo (p_vo.M_Product_ID); 84 m_pi.setQty(p_vo.Qty); 85 } 86 catch (SQLException e) 87 { 88 log.error("loadDocumentDetails", e); 89 } 90 p_vo.C_Currency_ID = Doc.NO_CURRENCY; 91 return false; 92 } 94 95 96 100 public BigDecimal getBalance() 101 { 102 return Env.ZERO; 103 } 105 115 public Fact createFact (AcctSchema as) 116 { 117 Fact fact = new Fact(this, as, Fact.POST_Actual); 119 if (p_vo.M_Product_ID == 0) 121 return fact; 122 if (m_M_InOutLine_ID == 0) 124 return fact; 125 p_vo.C_Currency_ID = as.getC_Currency_ID(); 127 BigDecimal difference = loadInfo(as); if (difference == null) 129 { 130 p_vo.Error = "No PPV Difference"; 131 log.error("createFact - " + p_vo.Error); 132 return null; 133 } 134 135 FactLine cr = fact.createLine(null, 137 m_pi.getAccount(ProductInfo.ACCTTYPE_P_PPV, as), 138 as.getC_Currency_ID(), difference); 139 FactLine dr = fact.createLine(null, 141 getAccount(Doc.ACCTTYPE_PPVOffset, as), 142 as.getC_Currency_ID(), difference.negate()); 143 144 return fact; 145 } 147 153 private BigDecimal loadInfo(AcctSchema as) 154 { 155 BigDecimal difference = null; 156 String sql = "SELECT PriceActual from C_OrderLine WHERE C_OrderLine_ID=?"; 158 try 159 { 160 PreparedStatement pstmt = DB.prepareStatement(sql); 161 pstmt.setInt(1, m_C_OrderLine_ID); 162 ResultSet rs = pstmt.executeQuery(); 163 if (rs.next()) 164 { 165 difference = rs.getBigDecimal(1); 166 } 167 rs.close(); 168 pstmt.close(); 169 } 170 catch (SQLException e) 171 { 172 log.error("loadInfo", e); 173 } 174 if (difference == null) 175 return null; 176 177 difference.subtract(m_pi.getProductItemCost(as, AcctSchema.COSTING_STANDARD)); 180 181 return difference.multiply(p_vo.Qty); 182 } 184 189 private void updateProductInfo (int C_AcctSchema_ID) 190 { 191 log.debug("updateProductInfo - M_MatchPO_ID=" + p_vo.Record_ID); 192 193 StringBuffer sql = new StringBuffer ( 196 "UPDATE M_Product_Costing pc " 197 + "SET (CostStandardPOQty,CostStandardPOAmt) = " 198 + "(SELECT CostStandardPOQty + m.Qty," 199 + " CostStandardPOAmt + C_Currency_Convert(ol.PriceActual,ol.C_Currency_ID,a.C_Currency_ID,ol.DateOrdered,null,ol.AD_Client_ID,ol.AD_Org_ID)*m.Qty " 200 + "FROM M_MatchPO m, C_OrderLine ol, C_AcctSchema a " 201 + "WHERE m.C_OrderLine_ID=ol.C_OrderLine_ID" 202 + " AND pc.M_Product_ID=ol.M_Product_ID" 203 + " AND pc.C_AcctSchema_ID=a.C_AcctSchema_ID" 204 + "AND m.M_MatchPO_ID=").append(p_vo.Record_ID).append(") ") 205 .append("WHERE pc.C_AcctSchema_ID=").append(C_AcctSchema_ID) 206 .append(" AND pc.M_Product_ID=").append(p_vo.M_Product_ID); 207 int no = DB.executeUpdate(sql.toString()); 208 log.debug("M_Product_Costing - Updated=" + no); 209 } 211 } | Popular Tags |