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_Inventory extends Doc 33 { 34 38 public Doc_Inventory (int AD_Client_ID) 39 { 40 super (AD_Client_ID); 41 } 43 47 public int getAD_Table_ID() 48 { 49 return 321; 50 } 52 56 public String getTableName() 57 { 58 return "M_Inventory"; 59 } 61 66 protected boolean loadDocumentDetails(ResultSet rs) 67 { 68 p_vo.DocumentType = DocVO.DOCTYPE_MatInventory; 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_InventoryLine WHERE M_Inventory_ID=? ORDER BY Line"; 93 try 94 { 95 PreparedStatement pstmt = DB.prepareStatement(sql); 96 pstmt.setInt(1, p_vo.Record_ID); 97 ResultSet rs = pstmt.executeQuery(); 98 while (rs.next()) 100 { 101 int Line_ID = rs.getInt("M_InventoryLine_ID"); 102 DocLine_Material docLine = new DocLine_Material (p_vo.DocumentType, p_vo.Record_ID, Line_ID); 103 docLine.loadAttributes(rs, p_vo); 104 BigDecimal QtyBook = rs.getBigDecimal("QtyBook"); 105 BigDecimal QtyCount = rs.getBigDecimal("QtyCount"); 106 docLine.setQty (QtyCount.subtract(QtyBook)); 107 docLine.setM_Locator_ID (rs.getInt("M_Locator_ID")); 108 if (!"C".equals(rs.getString("InventoryType"))) 110 docLine.setC_Charge_ID (0); 111 log.debug(docLine.toString()); 113 list.add (docLine); 114 } 115 rs.close(); 117 pstmt.close(); 118 } 119 catch (SQLException e) 120 { 121 log.error ("loadLines", e); 122 } 123 124 DocLine[] dl = new DocLine[list.size()]; 126 list.toArray(dl); 127 return dl; 128 } 130 134 public BigDecimal getBalance() 135 { 136 BigDecimal retValue = Env.ZERO; 137 return retValue; 138 } 140 151 public Fact createFact(AcctSchema as) 152 { 153 p_vo.C_Currency_ID = as.getC_Currency_ID(); 155 Fact fact = new Fact(this, as, Fact.POST_Actual); 157 158 FactLine dr = null; 160 FactLine cr = null; 161 162 for (int i = 0; i < p_lines.length; i++) 163 { 164 DocLine_Material line = (DocLine_Material)p_lines[i]; 165 BigDecimal costs = line.getProductCosts(as); 166 dr = fact.createLine(line, 168 line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as), 169 as.getC_Currency_ID(), costs); 170 if (dr == null) 172 continue; 173 dr.setM_Locator_ID(line.getM_Locator_ID()); 174 175 Account invDiff = line.getChargeAccount(as, costs.negate()); 178 if (invDiff == null) 179 invDiff = getAccount(Doc.ACCTTYPE_InvDifferences, as); 180 cr = fact.createLine(line, invDiff, 181 as.getC_Currency_ID(), costs.negate()); 182 cr.setM_Locator_ID(line.getM_Locator_ID()); 183 } 184 return fact; 185 } 187 } | Popular Tags |