1 17 package org.openbravo.erpCommon.ad_forms; 18 19 import org.openbravo.base.secureApp.VariablesSecureApp; 20 import java.math.*; 21 import java.util.*; 22 import javax.servlet.*; 23 import org.apache.log4j.Logger ; 24 import org.openbravo.database.ConnectionProvider; 26 import java.sql.Connection ; 27 import org.openbravo.data.FieldProvider; 28 29 30 31 public class DocOrder extends AcctServer { 32 static Logger log4jDocOrder = Logger.getLogger(DocOrder.class); 33 34 35 public DocTax[] m_taxes = null; 36 37 38 42 public DocOrder(String AD_Client_ID){ 43 super(AD_Client_ID); 44 } 45 46 47 public void loadObjectFieldProvider(ConnectionProvider conn, String AD_Client_ID, String Id) throws ServletException{ 48 setObjectFieldProvider(DocOrderData.selectRegistro(conn, AD_Client_ID, Id)); 49 } 50 51 56 public boolean loadDocumentDetails (FieldProvider [] data,ConnectionProvider conn){ 57 DateDoc = data[0].getField("DateOrdered"); 58 TaxIncluded = data[0].getField("IsTaxIncluded"); 59 60 Amounts[AcctServer.AMTTYPE_Gross] = data[0].getField("GrandTotal"); 62 if (Amounts[AcctServer.AMTTYPE_Gross] == null) 63 Amounts[AcctServer.AMTTYPE_Gross] = ZERO.toString(); 64 Amounts[AcctServer.AMTTYPE_Net] = data[0].getField("TotalLines"); 65 if (Amounts[AcctServer.AMTTYPE_Net] == null) 66 Amounts[AcctServer.AMTTYPE_Net] = ZERO.toString(); 67 Amounts[AcctServer.AMTTYPE_Charge] = data[0].getField("ChargeAmt"); 68 if (Amounts[AcctServer.AMTTYPE_Charge] == null) 69 Amounts[AcctServer.AMTTYPE_Charge] = ZERO.toString(); 70 loadDocumentType(); p_lines = loadLines(conn); 73 m_taxes = loadTaxes(conn); 74 return true; 76 } 78 79 83 public DocLine[] loadLines(ConnectionProvider conn){ 84 ArrayList<Object > list = new ArrayList<Object >(); 85 DocLineOrderData [] data = null; 86 try{ 87 data = DocLineOrderData.select(conn, Record_ID); 88 } 89 catch (ServletException e){ 90 log4jDocOrder.warn(e); 91 } 92 for(int i=0;i<data.length;i++){ 94 String Line_ID = data[i].getField("cOrderlineId"); 95 DocLine docLine = new DocLine (DocumentType, Record_ID, Line_ID); 96 docLine.loadAttributes(data[i], this); 97 String Qty = data[i].getField("qtyordered"); 98 docLine.setQty(Qty); 99 String LineNetAmt = data[i].getField("linenetamt"); 100 docLine.setAmount (LineNetAmt); 102 list.add(docLine); 103 } 104 106 DocLine[] dl = new DocLine[list.size()]; 108 list.toArray(dl); 109 return dl; 110 } 112 116 public DocTax[] loadTaxes(ConnectionProvider conn){ 117 ArrayList<Object > list = new ArrayList<Object >(); 118 119 DocOrderData [] data = null; 120 try{ 121 data = DocOrderData.select(conn, Record_ID); 122 } 123 catch (ServletException e){ 124 log4jDocOrder.warn(e); 125 } 126 127 for(int i=0; i<data.length; i++){ 129 String C_Tax_ID = data[i].getField("cTaxId"); 130 String name = data[i].getField("name"); 131 String rate = data[i].getField("rate"); 132 String taxBaseAmt = data[i].getField("taxbaseamt"); 133 String amount = data[i].getField("taxamt"); 134 DocTax taxLine = new DocTax(C_Tax_ID, name, rate, taxBaseAmt, amount); 136 list.add(taxLine); 137 } 138 139 DocTax[] tl = new DocTax[list.size()]; 141 list.toArray(tl); 142 return tl; 143 } 145 149 public BigDecimal getBalance(){ 150 BigDecimal retValue = new BigDecimal("0"); 151 StringBuffer sb = new StringBuffer (" ["); 152 retValue = retValue.add(new BigDecimal(getAmount(AcctServer.AMTTYPE_Gross))); 154 sb.append(getAmount(AcctServer.AMTTYPE_Gross)); 155 retValue = retValue.subtract(new BigDecimal(getAmount(AcctServer.AMTTYPE_Charge))); 157 sb.append("-").append(getAmount(AcctServer.AMTTYPE_Charge)); 158 if (m_taxes != null){ 160 for (int i = 0; i < m_taxes.length; i++){ 161 retValue = retValue.subtract(new BigDecimal(m_taxes[i].getAmount())); 162 sb.append("-").append(m_taxes[i].getAmount()); 163 } 164 } 165 if (p_lines != null){ 167 for (int i = 0; i < p_lines.length; i++){ 168 retValue = retValue.subtract(new BigDecimal(p_lines[i].getAmount())); 169 sb.append("-").append(p_lines[i].getAmount()); 170 } 171 sb.append("]"); 172 } 173 log4jDocOrder.debug(" Balance=" + retValue + sb.toString()); 175 return retValue; 176 } 178 186 public Fact createFact (AcctSchema as,ConnectionProvider conn,Connection con,VariablesSecureApp vars) throws ServletException{ 187 if (DocumentType.equals(AcctServer.DOCTYPE_POrder)) 189 updateProductInfo(as.getC_AcctSchema_ID(), conn, con); 190 191 Fact fact = new Fact(this, as, Fact.POST_Actual); 193 return fact; 194 } 196 202 private void updateProductInfo (String C_AcctSchema_ID,ConnectionProvider conn,Connection con){ 203 log4jDocOrder.debug("updateProductInfo - C_Order_ID=" + Record_ID); 204 205 207 208 209 try{ 210 int no = DocOrderData.updateProductPO(con, conn, Record_ID); 214 log4jDocOrder.debug("M_Product_PO - Updated=" + no); 215 216 no = DocOrderData.updateProductCosting(con, conn, C_AcctSchema_ID, Record_ID); 220 log4jDocOrder.debug("M_Product_Costing - Updated=" + no); 221 } 222 catch (ServletException e){ 223 log4jDocOrder.warn(e); 224 } 225 226 } 228 232 public boolean getDocumentConfirmation(ConnectionProvider conn, String strRecordId) { 233 return true; 234 } 235 236 public String getServletInfo() { 237 return "Servlet for the accounting"; 238 } } 240 | Popular Tags |