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.erpCommon.utility.Utility; 25 import java.io.*; 26 import java.math.BigDecimal ; 27 import javax.servlet.*; 28 import javax.servlet.http.*; 29 30 import org.openbravo.erpCommon.utility.DateTimeData; 31 32 public class SL_JournalLineAmt extends HttpSecureAppServlet { 33 34 static final BigDecimal ZERO = new BigDecimal (0.0); 35 36 public void init (ServletConfig config) { 37 super.init(config); 38 boolHist = false; 39 } 40 41 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 42 VariablesSecureApp vars = new VariablesSecureApp(request); 43 if (vars.commandIn("DEFAULT")) { 44 String strChanged = vars.getStringParameter("inpLastFieldChanged"); 45 String strWindowId = vars.getStringParameter("inpWindowId"); 46 if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged); 47 String strGLJournal= vars.getRequiredStringParameter("inpglJournalId"); 48 String strCurrencyRate= vars.getStringParameter("inpcurrencyrate", "1"); 49 String strCurrency = vars.getStringParameter("inpcCurrencyId"); 50 String strDateAcct = vars.getStringParameter("inpdateacct", DateTimeData.today(this)); 51 String strCurrencyRateType = vars.getStringParameter("inpcurrencyratetype", "S"); 52 String strAmtSourceDr = vars.getStringParameter("inpamtsourcedr", "0"); 53 String strAmtSourceCr = vars.getStringParameter("inpamtsourcecr", "0"); 54 String strTabId = vars.getStringParameter("inpTabId"); 55 56 try { 57 printPage(response, vars, strGLJournal, strCurrencyRate, strCurrency, strDateAcct, strCurrencyRateType, strWindowId, strAmtSourceDr, strAmtSourceCr, strTabId); 58 } catch (ServletException ex) { 59 pageErrorCallOut(response); 60 } 61 } else pageError(response); 62 } 63 64 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strGLJournal, String strCurrencyRate, String strCurrency, String strDateAcct, String strCurrencyRateType, String strWindowId, String strAmtSourceDr, String strAmtSourceCr, String strTabId) throws IOException, ServletException { 65 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 66 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 67 String strAcctSchema = Utility.getContext(this, vars, "$C_ACCTSCHEMA_ID", strWindowId); 68 SLJournalLineAmtData[] data = SLJournalLineAmtData.select(this, strAcctSchema); 69 String strPrecision = "2", strTargetCurrencyId=""; 70 if (data!=null && data.length>0) { 71 strPrecision = data[0].stdprecision.equals("")?"2":data[0].stdprecision; 72 strTargetCurrencyId = data[0].cCurrencyId.equals("")?"0":data[0].cCurrencyId; 73 } 74 String CurrencyRate = SLJournalLineAmtData.currencyRate(this, strCurrency, strTargetCurrencyId, strDateAcct, strCurrencyRateType, vars.getClient(), vars.getOrg()); 75 if (CurrencyRate.equals("")) CurrencyRate = SLJournalLineAmtData.currencyRate2(this, strGLJournal, strCurrency, strCurrencyRateType); 76 int StdPrecision = Integer.valueOf(strPrecision).intValue(); 77 78 BigDecimal AmtSourceDr = new BigDecimal (strAmtSourceDr); 79 BigDecimal AmtSourceCr = new BigDecimal (strAmtSourceCr); 80 BigDecimal CurrencyRateValue = new BigDecimal (strCurrencyRate); 81 CurrencyRateValue = CurrencyRateValue.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP); 82 BigDecimal AmtAcctDr, AmtAcctCr; 83 84 AmtAcctDr = (strAmtSourceDr.equals("")?ZERO:AmtSourceDr.multiply(new BigDecimal (CurrencyRate))).setScale(StdPrecision, BigDecimal.ROUND_HALF_UP); 85 AmtAcctCr = (strAmtSourceCr.equals("")?ZERO:AmtSourceCr.multiply(new BigDecimal (CurrencyRate))).setScale(StdPrecision, BigDecimal.ROUND_HALF_UP); 86 87 StringBuffer resultado = new StringBuffer (); 88 resultado.append("var calloutName='SL_JournalLineAmt';\n\n"); 89 resultado.append("var respuesta = new Array("); 90 resultado.append("new Array(\"inpamtacctdr\", \"" + AmtAcctDr.toString() + "\"),"); 91 resultado.append("new Array(\"inpamtacctcr\", \"" + AmtAcctCr.toString() + "\"),"); 92 resultado.append("new Array(\"inpcurrencyrate\", \"" + CurrencyRateValue.toString() + "\"),"); 93 resultado.append("new Array(\"inpcurrencyratetype\", \"" + strCurrencyRateType + "\")"); 94 95 resultado.append(");"); 96 xmlDocument.setParameter("array", resultado.toString()); 97 xmlDocument.setParameter("frameName", "frameAplicacion"); 98 response.setContentType("text/html; charset=UTF-8"); 99 PrintWriter out = response.getWriter(); 100 out.println(xmlDocument.print()); 101 out.close(); 102 } 103 } 104 | Popular Tags |