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 DocMovement extends AcctServer { 32 static Logger log4jDocMovement = Logger.getLogger(DocMovement.class); 33 34 private String SeqNo = "0"; 35 36 40 public DocMovement(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(DocMovementData.select(conn, AD_Client_ID, Id)); 46 } 47 48 53 public boolean loadDocumentDetails(FieldProvider [] data,ConnectionProvider conn){ 54 DocumentType = AcctServer.DOCTYPE_MatMovement; 55 C_Currency_ID = NO_CURRENCY; 56 DateDoc = data[0].getField("MovementDate"); 57 58 loadDocumentType(); p_lines = loadLines(conn); 61 log4jDocMovement.debug("Lines=" + p_lines.length); 62 return true; 63 } 65 69 public DocLine[] loadLines(ConnectionProvider conn){ 70 ArrayList<Object > list = new ArrayList<Object >(); 71 DocLineMovementData [] data = null; 72 try{ 73 data = DocLineMovementData.select(conn, Record_ID); 74 } 75 catch (ServletException e){ 76 log4jDocMovement.warn(e); 77 } 78 for(int i=0; i<data.length;i++){ 80 String Line_ID = data[i].getField("mMovementlineId"); 81 DocLine_Material docLine = new DocLine_Material (DocumentType, Record_ID, Line_ID); 82 docLine.loadAttributes(data[i], this); 83 docLine.setQty(data[i].getField("MovementQty"),conn); 84 docLine.m_M_Locator_ID = data[i].getField("M_Locator_ID"); 85 docLine.m_M_LocatorTo_ID = data[i].getField("M_LocatorTo_ID"); 86 log4jDocMovement.debug("Movement line: " + Line_ID + " loaded."); 88 list.add (docLine); 89 } 90 91 DocLine[] dl = new DocLine[list.size()]; 93 list.toArray(dl); 94 return dl; 95 } 97 101 public BigDecimal getBalance(){ 102 BigDecimal retValue = ZERO; 103 return retValue; 104 } 106 117 public Fact createFact(AcctSchema as,ConnectionProvider conn,Connection con,VariablesSecureApp vars) throws ServletException{ 118 C_Currency_ID = as.getC_Currency_ID(); 119 Fact fact = new Fact(this, as, Fact.POST_Actual); 121 String Fact_Acct_Group_ID = SequenceIdData.getSequence(conn, "Fact_Acct_Group", vars.getClient()); 122 123 FactLine dr = null; 125 FactLine cr = null; 126 log4jDocMovement.debug("DocMovement - Before the loop"); 127 for (int i=0; i < p_lines.length; i++){ 128 DocLine_Material line = (DocLine_Material)p_lines[i]; 129 log4jDocMovement.debug("DocMovement - Before calculating the costs for line i = " + i); 130 String costs = line.getProductCosts(as, conn, con); 131 BigDecimal b_Costs = new BigDecimal(costs); 132 dr = fact.createLine(line,line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),as.getC_Currency_ID(), (b_Costs.negate()).toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn); dr.setM_Locator_ID(line.m_M_Locator_ID); 135 cr = fact.createLine(line,line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),as.getC_Currency_ID(), costs, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn); cr.setM_Locator_ID(line.m_M_LocatorTo_ID); 138 } 139 log4jDocMovement.debug("DocMovement - After the loop"); 140 SeqNo = "0"; 141 return fact; 142 } 144 public String nextSeqNo(String oldSeqNo){ 145 log4jDocMovement.debug("DocMovement - oldSeqNo = " + oldSeqNo); 146 BigDecimal seqNo = new BigDecimal(oldSeqNo); 147 SeqNo = (seqNo.add(new BigDecimal("10"))).toString(); 148 log4jDocMovement.debug("DocMovement - nextSeqNo = " + SeqNo); 149 return SeqNo; 150 } 151 152 156 public boolean getDocumentConfirmation(ConnectionProvider conn, String strRecordId) { 157 return true; 158 } 159 160 public String getServletInfo() { 161 return "Servlet for accounting"; 162 } } 164 | Popular Tags |