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_Production extends Doc 33 { 34 38 public Doc_Production (int AD_Client_ID) 39 { 40 super (AD_Client_ID); 41 } 43 47 public int getAD_Table_ID() 48 { 49 return 325; 50 } 52 56 public String getTableName() 57 { 58 return "M_Production"; 59 } 61 66 protected boolean loadDocumentDetails(ResultSet rs) 67 { 68 p_vo.DocumentType = DocVO.DOCTYPE_MatProduction; 69 p_vo.C_Currency_ID = NO_CURRENCY; 70 try 71 { 72 p_vo.DateDoc = rs.getTimestamp("MovementDate"); 73 } 74 catch (SQLException e) 75 { 76 log.error("loadDocumentDetails", e); 77 } 78 loadDocumentType(); p_lines = loadLines(); 81 log.debug("Lines=" + p_lines.length); 82 return true; 83 } 85 89 private DocLine[] loadLines() 90 { 91 ArrayList list = new ArrayList(); 92 String sql = "SELECT * FROM M_ProductionLine pl " 93 + "WHERE EXISTS (SELECT * FROM M_ProductionPlan pp" 94 + " WHERE pl.M_ProductionPlan_ID=pp.M_ProductionPlan_ID" 95 + " AND M_Production_ID=?) " 96 + "ORDER BY pl.M_ProductionPlan_ID, pl.Line"; 97 try 98 { 99 PreparedStatement pstmt = DB.prepareStatement(sql); 100 pstmt.setInt(1, p_vo.Record_ID); 101 ResultSet rs = pstmt.executeQuery(); 102 while (rs.next()) 104 { 105 int Line_ID = rs.getInt("M_ProductionLine_ID"); 106 DocLine_Material docLine = new DocLine_Material (p_vo.DocumentType, p_vo.Record_ID, Line_ID); 107 docLine.loadAttributes(rs, p_vo); 108 docLine.setQty (rs.getBigDecimal("MovementQty")); 109 docLine.setM_Locator_ID (rs.getInt("M_Locator_ID")); 110 log.debug(docLine.toString()); 112 list.add (docLine); 113 } 114 rs.close(); 116 pstmt.close(); 117 } 118 catch (SQLException e) 119 { 120 log.error ("loadLines", e); 121 } 122 DocLine[] dl = new DocLine[list.size()]; 124 list.toArray(dl); 125 return dl; 126 } 128 132 public BigDecimal getBalance() 133 { 134 BigDecimal retValue = Env.ZERO; 135 return retValue; 136 } 138 148 public Fact createFact(AcctSchema as) 149 { 150 p_vo.C_Currency_ID = as.getC_Currency_ID(); 151 Fact fact = new Fact(this, as, Fact.POST_Actual); 153 154 FactLine fl = null; 156 157 BigDecimal bomCost = Env.ZERO; 159 for (int i = 0; i < p_lines.length; i++) 160 { 161 DocLine_Material line = (DocLine_Material)p_lines[i]; 162 if (!line.isBOM()) 163 bomCost = bomCost.add(line.getProductCosts(as)); 164 } 165 166 for (int i = 0; i < p_lines.length; i++) 167 { 168 DocLine_Material line = (DocLine_Material)p_lines[i]; 169 BigDecimal costs = null; 170 if (line.isBOM()) 171 costs = bomCost.negate(); 172 else 173 costs = line.getProductCosts(as); 174 fl = fact.createLine(line, 176 line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as), 177 as.getC_Currency_ID(), costs); 178 fl.setM_Locator_ID(line.getM_Locator_ID()); 179 } 180 return fact; 181 } 183 } | Popular Tags |