1 17 package org.openbravo.erpCommon.ad_forms; 18 19 import org.openbravo.erpCommon.utility.SequenceIdData; 20 import org.openbravo.base.secureApp.VariablesSecureApp; 21 import java.math.*; 22 import java.util.*; 23 import javax.servlet.*; 24 import org.apache.log4j.Logger ; 25 import org.openbravo.database.ConnectionProvider; 27 import java.sql.Connection ; 28 import org.openbravo.data.FieldProvider; 29 30 31 public class DocInventory extends AcctServer { 32 static Logger log4jDocInventory = Logger.getLogger(DocInventory.class); 33 34 private String SeqNo = "0"; 35 36 40 public DocInventory(String AD_Client_ID){ 41 super(AD_Client_ID); 42 } 43 44 public void loadObjectFieldProvider(ConnectionProvider conn, String AD_Client_ID, String Id) throws ServletException{ 45 setObjectFieldProvider(DocInventoryData.select(conn, AD_Client_ID, Id)); 46 } 47 48 53 public boolean loadDocumentDetails(FieldProvider [] data,ConnectionProvider conn){ 54 DocumentType = AcctServer.DOCTYPE_MatInventory; 55 C_Currency_ID = NO_CURRENCY; 56 DateDoc = data[0].getField("MovementDate"); 57 loadDocumentType(); p_lines = loadLines(conn); 60 log4jDocInventory.debug("Lines=" + p_lines.length); 61 return true; 62 } 64 68 private DocLine[] loadLines(ConnectionProvider conn){ 69 ArrayList<Object > list = new ArrayList<Object >(); 70 DocLineInventoryData [] data = null; 71 try{ 72 data = DocLineInventoryData.select(conn,Record_ID); 73 } 74 catch (ServletException e){ 75 log4jDocInventory.warn(e); 76 } 77 for(int i =0; i<data.length;i++){ 78 String Line_ID = data[i].getField("mInventorylineId"); 79 DocLine_Material docLine = new DocLine_Material (DocumentType, Record_ID, Line_ID); 80 docLine.loadAttributes(data[i], this); 81 log4jDocInventory.debug("QtyBook = " + data[i].getField("qtybook") + " - QtyCount = " + data[i].getField("qtycount")); 82 BigDecimal QtyBook = new BigDecimal(data[i].getField("qtybook")); 83 BigDecimal QtyCount = new BigDecimal(data[i].getField("qtycount")); 84 docLine.setQty ((QtyCount.subtract(QtyBook)).toString(),conn); 85 docLine.m_M_Locator_ID = data[i].getField("mLocatorId"); 86 DocInventoryData [] data1 = null; 87 try{ 88 data1= DocInventoryData.selectWarehouse(conn, docLine.m_M_Locator_ID); 89 }catch(ServletException e){ 90 log4jDocInventory.warn(e); 91 } 92 if(data1!=null && data1.length>0) this.M_Warehouse_ID = data1[0].mWarehouseId; 93 if (!"C".equals(data[i].getField("inventorytype"))) 95 docLine.m_C_Charge_ID = ""; 96 list.add (docLine); 98 } 99 DocLine[] dl = new DocLine[list.size()]; 101 list.toArray(dl); 102 return dl; 103 } 105 106 110 public BigDecimal getBalance(){ 111 BigDecimal retValue = ZERO; 112 return retValue; 113 } 115 126 public Fact createFact(AcctSchema as,ConnectionProvider conn,Connection con,VariablesSecureApp vars) throws ServletException{ 127 C_Currency_ID = as.getC_Currency_ID(); 129 Fact fact = new Fact(this, as, Fact.POST_Actual); 131 String Fact_Acct_Group_ID = SequenceIdData.getSequence(conn, "Fact_Acct_Group", vars.getClient()); 132 FactLine dr = null; 134 FactLine cr = null; 135 log4jDocInventory.debug("CreateFact - before loop"); 136 for (int i = 0; i < p_lines.length; i++){ 137 DocLine_Material line = (DocLine_Material)p_lines[i]; 138 String costs = line.getProductCosts(as, conn, con); 139 log4jDocInventory.debug("CreateFact - before DR - Costs: " + costs); 140 dr = fact.createLine(line,line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),as.getC_Currency_ID(), costs, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn); 142 if (dr == null) 144 continue; 145 dr.setM_Locator_ID(line.m_M_Locator_ID); 146 log4jDocInventory.debug("CreateFact - before CR"); 147 BigDecimal b_Costs = new BigDecimal(costs); 149 Account invDiff = line.getChargeAccount(as, b_Costs.negate(), conn); 151 log4jDocInventory.debug("CreateFact - after getChargeAccount"); 152 if (invDiff == null) 153 invDiff = getAccount(AcctServer.ACCTTYPE_InvDifferences, as, conn); 154 log4jDocInventory.debug("CreateFact - after getAccount - invDiff; " + invDiff); 155 cr = fact.createLine(line, invDiff,as.getC_Currency_ID(), (b_Costs.negate()).toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn); 156 cr.setM_Locator_ID(line.m_M_Locator_ID); 157 } 158 log4jDocInventory.debug("CreateFact - after loop"); 159 SeqNo = "0"; 160 return fact; 161 } 163 public String nextSeqNo(String oldSeqNo){ 164 log4jDocInventory.debug("DocInventory - oldSeqNo = " + oldSeqNo); 165 BigDecimal seqNo = new BigDecimal(oldSeqNo); 166 SeqNo = (seqNo.add(new BigDecimal("10"))).toString(); 167 log4jDocInventory.debug("DocInventory - nextSeqNo = " + SeqNo); 168 return SeqNo; 169 } 170 171 175 public boolean getDocumentConfirmation(ConnectionProvider conn, String strRecordId) { 176 return true; 177 } 178 179 public String getServletInfo() { 180 return "Servlet for the accounting"; 181 } } 183 | Popular Tags |