1 19 package org.openbravo.erpCommon.ad_callouts; 20 21 import org.openbravo.base.secureApp.HttpSecureAppServlet; 22 import org.openbravo.base.secureApp.VariablesSecureApp; 23 import org.openbravo.xmlEngine.XmlDocument; 24 import org.openbravo.utils.FormatUtilities; 25 import org.openbravo.erpCommon.utility.*; 26 import org.openbravo.data.FieldProvider; 27 import java.io.*; 28 import java.math.BigDecimal ; 29 import javax.servlet.*; 30 import javax.servlet.http.*; 31 32 import org.openbravo.erpCommon.utility.DateTimeData; 33 34 35 public class SL_Payment_Amounts extends HttpSecureAppServlet { 36 37 static final BigDecimal ZERO = new BigDecimal (0.0); 38 39 public void init (ServletConfig config) { 40 super.init(config); 41 boolHist = false; 42 } 43 44 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 45 VariablesSecureApp vars = new VariablesSecureApp(request); 46 if (vars.commandIn("DEFAULT")) { 47 String strChanged = vars.getStringParameter("inpLastFieldChanged"); 48 if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged); 49 String strIsOverUnderPayment = vars.getStringParameter("inpisoverunderpayment"); 50 String strPayamt = vars.getStringParameter("inppayamt"); 51 String strDiscountamt = vars.getStringParameter("inpdiscountamt"); 52 String strWriteoffamt = vars.getStringParameter("inpwriteoffamt"); 53 String strOverunderamt = vars.getStringParameter("inpoverunderamt"); 54 String strcCurrencyId = vars.getStringParameter("inpcCurrencyId"); 55 String strcPaymentId = vars.getStringParameter("inpcPaymentId"); 56 String strcInvoiceId = vars.getStringParameter("inpcInvoiceId"); 57 String strTabId = vars.getStringParameter("inpTabId"); 58 try { 59 printPage(response, vars, strChanged, strIsOverUnderPayment, strPayamt, strDiscountamt, strWriteoffamt, strOverunderamt, strcCurrencyId, strcPaymentId, strcInvoiceId, strTabId); 60 } catch (ServletException ex) { 61 pageErrorCallOut(response); 62 } 63 64 } else pageError(response); 65 } 66 67 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strChanged, String strIsOverUnderPayment, String strPayamt, String strDiscountamt, String strWriteoffamt, String strOverunderamt, String strcCurrencyId, String strcPaymentId, String strcInvoiceId, String strTabId) throws IOException, ServletException { 68 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 69 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 70 71 BigDecimal payamt, discountamt, writeoffamt, overunderamt, cpaymentid, convert, cCurrencyIdBi, invtotamt; 72 int cCurrencyId; 73 74 payamt = new BigDecimal (strPayamt); 75 if (payamt == null) payamt = ZERO; 76 discountamt = new BigDecimal (strDiscountamt); 77 if (discountamt == null) discountamt = ZERO; 78 writeoffamt = new BigDecimal (strWriteoffamt); 79 if (writeoffamt == null) writeoffamt = ZERO; 80 overunderamt = new BigDecimal (strOverunderamt); 81 if (overunderamt == null) overunderamt = ZERO; 82 83 StringBuffer resultado = new StringBuffer (); 84 resultado.append("var calloutName='SL_Payment_Amounts';\n\n"); 85 resultado.append("var respuesta = new Array("); 86 if (strChanged.equals("inpisoverunderpayment")){ 87 overunderamt = new BigDecimal (strOverunderamt); 88 if (overunderamt == null) overunderamt = ZERO; 89 resultado.append("new Array(\"inpoverunderamt\", \"" + overunderamt.toString() + "\")"); 90 } 91 92 else if (strChanged.equals("inpcCurrencyId")){ 93 94 String strCurrency = vars.getSessionValue("Last.Currency"); 95 if (log4j.isDebugEnabled()) log4j.debug("LAST CURRENCY: "+strCurrency); 96 if (strCurrency.equals("")){ 97 vars.setSessionValue("Last.Currency", strcCurrencyId); 98 } 99 else{ 100 101 if (strCurrency.equals(strcCurrencyId)){ 102 } 103 else{ 104 String strconvert = SLPaymentAmountsData.selectConversion(this, strCurrency, strcCurrencyId, DateTimeData.today(this), null, vars.getClient(), vars.getOrg()); 105 if (strconvert.equals("")){ 106 resultado.append("new Array('MESSAGE', \"" + FormatUtilities.replaceJS(Utility.messageBD(this, "NoCurrencyConversion", vars.getLanguage())) + "\"),"); 107 FieldProvider [] tdd = null; 108 try { 109 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "C_Currency", "ID", Utility.getContext(this, vars, "#User_Org", "SLPaymentAmounts"), Utility.getContext(this, vars, "#User_Client", "SLPaymentAmounts"), 0); 110 Utility.fillSQLParameters(this, vars, null, comboTableData, "SLPaymentAmounts", ""); 111 tdd = comboTableData.select(false); 112 comboTableData = null; 113 } catch (Exception ex) { 114 throw new ServletException(ex); 115 } 116 117 resultado.append("new Array(\"inpcCurrencyId\", "); 118 if (tdd!=null && tdd.length>0) { 119 resultado.append("new Array("); 120 for (int i=0;i<tdd.length;i++) { 121 resultado.append("new Array(\"" + tdd[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tdd[i].getField("name")) + "\", \"" + (tdd[i].getField("id").equalsIgnoreCase(strCurrency)?"true":"false") + "\")"); 122 if (i<tdd.length-1) resultado.append(",\n"); 123 } 124 resultado.append("\n)"); 125 } else resultado.append("null"); 126 resultado.append("\n)"); 127 } 128 else { 129 convert = new BigDecimal (strconvert); 130 payamt = payamt.multiply(convert).setScale(2,4); 131 resultado.append("new Array(\"inppayamt\", \"" + payamt.toString() + "\"),"); 132 discountamt = discountamt.multiply(convert).setScale(2,4); 133 resultado.append("new Array(\"inpdiscountamt\", \"" + discountamt.toString() + "\"),"); 134 writeoffamt = writeoffamt.multiply(convert).setScale(2,4); 135 resultado.append("new Array(\"inpwriteoffamt\", \"" + writeoffamt.toString() + "\"),"); 136 overunderamt = overunderamt.multiply(convert).setScale(2,4); 137 resultado.append("new Array(\"inpoverunderamt\", \"" + overunderamt.toString() + "\")"); 138 vars.setSessionValue("Last.Currency", strcCurrencyId); 139 } 140 141 } 142 143 } 144 145 } 146 else if (strChanged.equals("inppayamt")){ 147 SLPaymentAmountsData[] data= SLPaymentAmountsData.select(this, strcInvoiceId); 148 if (log4j.isDebugEnabled()) log4j.debug("PAYMENT: "+data[0].grand+"CURRENCYID: "+data[0].currencyid); 149 invtotamt = new BigDecimal (data[0].grand); 150 if (invtotamt == null) invtotamt = ZERO; 151 if (strcCurrencyId.equals(data[0].currencyid)){ 152 } 153 else { 154 String strconvert = SLPaymentAmountsData.selectConversion(this, data[0].currencyid, strcCurrencyId, DateTimeData.today(this), null, vars.getClient(), vars.getOrg()); 155 convert = new BigDecimal (strconvert); 156 invtotamt = invtotamt.multiply(convert).setScale(2,4); 157 } 158 writeoffamt = (invtotamt).subtract(payamt).subtract(discountamt).subtract(overunderamt); 159 resultado.append("new Array(\"inpwriteoffamt\", \"" + writeoffamt.toString() + "\")"); 160 } 161 else if (strChanged.equals("inpdiscountamt")){ 162 String strCurrency = vars.getSessionValue("Last.Currency"); 163 SLPaymentAmountsData[] data= SLPaymentAmountsData.select(this, strcInvoiceId); 164 invtotamt = new BigDecimal (data[0].grand); 165 if (invtotamt == null) invtotamt = ZERO; 166 if (strcCurrencyId.equals(data[0].currencyid)){ 167 } 168 else { 169 String strconvert = SLPaymentAmountsData.selectConversion(this, data[0].currencyid, strcCurrencyId, DateTimeData.today(this), null, vars.getClient(), vars.getOrg()); 170 convert = new BigDecimal (strconvert); 171 invtotamt = invtotamt.multiply(convert).setScale(2,4); 172 } 173 invtotamt = invtotamt.subtract(discountamt).subtract(writeoffamt).subtract(overunderamt); 174 resultado.append("new Array(\"inppayamt\", \"" + invtotamt.toString() + "\")"); 175 } 176 else if (strChanged.equals("inpwriteoffamt")){ 177 String strCurrency = vars.getSessionValue("Last.Currency"); 178 SLPaymentAmountsData[] data= SLPaymentAmountsData.select(this, strcInvoiceId); 179 invtotamt = new BigDecimal (data[0].grand); 180 if (invtotamt == null) invtotamt = ZERO; 181 if (strcCurrencyId.equals(data[0].currencyid)){ 182 } 183 else { 184 String strconvert = SLPaymentAmountsData.selectConversion(this, data[0].currencyid, strcCurrencyId, DateTimeData.today(this), null, vars.getClient(), vars.getOrg()); 185 convert = new BigDecimal (strconvert); 186 invtotamt = invtotamt.multiply(convert).setScale(2,4); 187 } 188 invtotamt = invtotamt.subtract(writeoffamt).subtract(discountamt).subtract(overunderamt); 189 resultado.append("new Array(\"inppayamt\", \"" + invtotamt.toString() + "\")"); 190 } 191 else if (strChanged.equals("inpoverunderamt")){ 192 String strCurrency = vars.getSessionValue("Last.Currency"); 193 SLPaymentAmountsData[] data= SLPaymentAmountsData.select(this, strcInvoiceId); 194 invtotamt = new BigDecimal (data[0].grand); 195 if (invtotamt == null) invtotamt = ZERO; 196 invtotamt = invtotamt.subtract(overunderamt).subtract(writeoffamt).subtract(discountamt); 197 resultado.append("new Array(\"inppayamt\", \"" + invtotamt.toString() + "\")"); 198 } 199 resultado.append(");"); 200 xmlDocument.setParameter("array", resultado.toString()); 201 xmlDocument.setParameter("frameName", "frameAplicacion"); 202 response.setContentType("text/html; charset=UTF-8"); 203 PrintWriter out = response.getWriter(); 204 out.println(xmlDocument.print()); 205 out.close(); 206 207 } 208 } 209 | Popular Tags |