1 19 package org.openbravo.erpCommon.ad_process; 20 21 22 import org.openbravo.erpCommon.ad_actionButton.*; 23 import org.openbravo.erpCommon.businessUtility.WindowTabs; 24 import org.openbravo.erpCommon.utility.*; 25 26 import org.openbravo.base.secureApp.HttpSecureAppServlet; 27 import org.openbravo.base.secureApp.VariablesSecureApp; 28 import org.openbravo.xmlEngine.XmlDocument; 29 import org.openbravo.utils.*; 30 import java.io.*; 31 import javax.servlet.*; 32 import javax.servlet.http.*; 33 34 import java.math.BigDecimal ; 35 36 import java.sql.Connection ; 38 39 public class CashBankOperations extends HttpSecureAppServlet { 40 41 42 public void init (ServletConfig config) { 43 super.init(config); 44 boolHist = false; 45 } 46 47 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 48 VariablesSecureApp vars = new VariablesSecureApp(request); 49 50 if (!Utility.hasProcessAccess(this, vars, "", "Cash_Bank_Operations")) { 51 bdError(response, "AccessTableNoView", vars.getLanguage()); 52 return; 53 } 54 55 if (vars.commandIn("DEFAULT")) { 56 printPage(response, vars); 57 } else if (vars.commandIn("SAVE")) { 58 String strCashFrom = vars.getStringParameter("inpCCashFromID"); 59 String strCashTo = vars.getStringParameter("inpCCashToID"); 60 String strBankFrom = vars.getStringParameter("inpCBankAccountFromID"); 61 String strBankTo = vars.getStringParameter("inpCBankAccountToID"); 62 String strPaymentRuleFrom = vars.getStringParameter("inppaymentruleFrom"); 63 String strPaymentRuleTo = vars.getStringParameter("inppaymentruleTo"); 64 String strAmount = vars.getStringParameter("inpAmount"); 65 String strMovementDate = vars.getStringParameter("inpmovementdate"); 66 String strDescription = vars.getStringParameter("inpdescription"); 67 process(vars, strCashFrom, strCashTo, strBankFrom, strBankTo, strPaymentRuleFrom, strPaymentRuleTo, strAmount,strMovementDate, strDescription); 68 printPage(response, vars); 69 } else pageErrorPopUp(response); 70 } 71 72 void process(VariablesSecureApp vars, String strCashFrom, String strCashTo, String strBankFrom, String strBankTo, String strPaymentRuleFrom, String strPaymentRuleTo, String strAmount, String strMovementDate, String strDescription)throws ServletException { 73 if (log4j.isDebugEnabled()) log4j.debug("Save: CashBankOperations"); 74 Connection con = null; 75 OBError myMessage = null; 76 String strSettlementDocumentNo=""; 77 try { 78 con = getTransactionConnection(); 79 String msg = ""; 80 String strBPartner = CashBankOperationsData.select(this, vars.getOrg()); 81 String strCashCurrency = CashBankOperationsData.selectCashCurrency(this, strCashFrom.equals("")?strCashTo:strCashFrom); 82 String strBankCurrency = CashBankOperationsData.selectBankCurrency(this, strBankFrom.equals("")?strBankTo:strBankFrom); 83 String strSettlement = SequenceIdData.getSequence(this, "C_Settlement", vars.getClient()); 84 String strDoctypeId = CashBankOperationsData.selectSettlementDoctypeId(this); 85 strSettlementDocumentNo = Utility.getDocumentNo(this, vars, "CashBankOperations", "C_Settlement", "", strDoctypeId, false, true); 86 if (strCashFrom.equals("") && strBankTo.equals("")){ 87 CashBankOperationsData.insertSettlement(con,this, strSettlement, vars.getClient(), vars.getOrg(), vars.getUser(), strSettlementDocumentNo, strMovementDate, strDoctypeId, strCashCurrency); 88 String strDebtPaymentId = SequenceIdData.getSequence(this, "C_Debt_Payment", vars.getClient()); 89 String strCashline = insertCash(vars, strCashTo, strAmount, strMovementDate, strCashCurrency,strDescription,con); 90 CashBankOperationsData.insertDebtpayment(con,this, strDebtPaymentId, vars.getClient(), vars.getOrg(), vars.getUser(), 91 "Y",strSettlement, strDescription + " - " + Utility.messageBD(this, "DebtPaymentFor", vars.getLanguage()) + Utility.messageBD(this, "Cash", vars.getLanguage()) + CashBankOperationsData.selectCashBook(this,strCashTo), strBPartner, strCashCurrency, "","", strCashTo, strPaymentRuleTo, strAmount, strMovementDate, ""); 92 CashBankOperationsData.updateCashLine(con,this, strDebtPaymentId, strCashline); 93 strDebtPaymentId = SequenceIdData.getSequence(this, "C_Debt_Payment", vars.getClient()); 94 CashBankOperationsData.insertDebtpayment(con,this, strDebtPaymentId, vars.getClient(), vars.getOrg(), vars.getUser(), 95 "N",strSettlement, strDescription + " - " + Utility.messageBD(this, "DebtPaymentFor", vars.getLanguage()) + CashBankOperationsData.selectBankAccount(this,strBankFrom), strBPartner, strBankCurrency, "",strBankFrom, "", strPaymentRuleTo, strAmount, strMovementDate, ""); 96 CashBankOperationsData.updateSettlement(con,this, strSettlement); 97 }else if (strCashTo.equals("") && strBankFrom.equals("")){ 98 CashBankOperationsData.insertSettlement(con,this, strSettlement, vars.getClient(), vars.getOrg(), vars.getUser(), strSettlementDocumentNo, strMovementDate, strDoctypeId, strBankCurrency); 99 String strDebtPaymentId = SequenceIdData.getSequence(this, "C_Debt_Payment", vars.getClient()); 100 String strCashline = insertCash(vars, strCashFrom, negate(strAmount), strMovementDate, strCashCurrency,strDescription,con); 101 CashBankOperationsData.insertDebtpayment(con,this, strDebtPaymentId, vars.getClient(), vars.getOrg(), vars.getUser(), 102 "N",strSettlement, strDescription + " - " + Utility.messageBD(this, "DebtPaymentFor", vars.getLanguage()) + Utility.messageBD(this, "Cash", vars.getLanguage()) + CashBankOperationsData.selectCashBook(this,strCashFrom), strBPartner, strCashCurrency, "","", strCashFrom, strPaymentRuleFrom, strAmount, strMovementDate, ""); 103 CashBankOperationsData.updateCashLine(con,this, strDebtPaymentId, strCashline); 104 strDebtPaymentId = SequenceIdData.getSequence(this, "C_Debt_Payment", vars.getClient()); 105 CashBankOperationsData.insertDebtpayment(con,this, strDebtPaymentId, vars.getClient(), vars.getOrg(), vars.getUser(), 106 "Y",strSettlement, strDescription + " - " + Utility.messageBD(this, "DebtPaymentFor", vars.getLanguage()) + CashBankOperationsData.selectBankAccount(this,strBankTo), strBPartner, strBankCurrency, "",strBankTo, "", strPaymentRuleTo, strAmount, strMovementDate, ""); 107 CashBankOperationsData.updateSettlement(con,this, strSettlement); 108 }else if (strBankTo.equals("") && strBankFrom.equals("")){ 109 CashBankOperationsData.insertSettlement(con,this, strSettlement, vars.getClient(), vars.getOrg(), vars.getUser(), strSettlementDocumentNo, strMovementDate, strDoctypeId, strCashCurrency); 110 String strDebtPaymentId = SequenceIdData.getSequence(this, "C_Debt_Payment", vars.getClient()); 111 String strCashline = insertCash(vars, strCashFrom, negate(strAmount), strMovementDate, strCashCurrency,strDescription,con); 112 CashBankOperationsData.insertDebtpayment(con,this, strDebtPaymentId, vars.getClient(), vars.getOrg(), vars.getUser(), 113 "N",strSettlement, strDescription + " - " + Utility.messageBD(this, "DebtPaymentFor", vars.getLanguage()) + Utility.messageBD(this, "Cash", vars.getLanguage()) + CashBankOperationsData.selectCashBook(this,strCashFrom), strBPartner, strCashCurrency, "","", strCashFrom, strPaymentRuleFrom, strAmount, strMovementDate, ""); 114 CashBankOperationsData.updateCashLine(con,this, strDebtPaymentId, strCashline); 115 strDebtPaymentId = SequenceIdData.getSequence(this, "C_Debt_Payment", vars.getClient()); 116 strCashline = insertCash(vars, strCashTo, strAmount, strMovementDate, strCashCurrency,strDescription,con); 117 CashBankOperationsData.insertDebtpayment(con,this, strDebtPaymentId, vars.getClient(), vars.getOrg(), vars.getUser(), 118 "Y",strSettlement, strDescription + " - " + Utility.messageBD(this, "DebtPaymentFor", vars.getLanguage()) + Utility.messageBD(this, "Cash", vars.getLanguage()) + CashBankOperationsData.selectCashBook(this,strCashTo), strBPartner, strCashCurrency, "", "",strCashTo, strPaymentRuleTo, strAmount, strMovementDate, ""); 119 CashBankOperationsData.updateCashLine(con,this, strDebtPaymentId, strCashline); 120 CashBankOperationsData.updateSettlement(con,this, strSettlement); 121 }else if (strCashTo.equals("") && strCashFrom.equals("")){ 122 CashBankOperationsData.insertSettlement(con,this, strSettlement, vars.getClient(), vars.getOrg(), vars.getUser(), strSettlementDocumentNo, strMovementDate, strDoctypeId, strBankCurrency); 123 String strDebtPaymentId = SequenceIdData.getSequence(this, "C_Debt_Payment", vars.getClient()); 124 CashBankOperationsData.insertDebtpayment(con,this, strDebtPaymentId, vars.getClient(), vars.getOrg(), vars.getUser(), 125 "N",strSettlement, strDescription + " - " + Utility.messageBD(this, "DebtPaymentFor", vars.getLanguage()) + CashBankOperationsData.selectBankAccount(this,strBankFrom), strBPartner, strBankCurrency, "", strBankFrom,"", strPaymentRuleFrom, strAmount, strMovementDate, ""); 126 strDebtPaymentId = SequenceIdData.getSequence(this, "C_Debt_Payment", vars.getClient()); 127 CashBankOperationsData.insertDebtpayment(con,this, strDebtPaymentId, vars.getClient(), vars.getOrg(), vars.getUser(), 128 "Y",strSettlement, strDescription + " - " + Utility.messageBD(this, "DebtPaymentFor", vars.getLanguage()) + CashBankOperationsData.selectBankAccount(this,strBankTo), strBPartner, strBankCurrency, "", strBankTo,"", strPaymentRuleTo, strAmount, strMovementDate, ""); 129 CashBankOperationsData.updateSettlement(con,this, strSettlement); 130 } 131 releaseCommitConnection(con); 132 }catch (Exception e){ 135 myMessage = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage()); 136 try { 137 releaseRollbackConnection(con); 138 } catch (Exception ignored) {} 139 log4j.warn(e); 140 return; 141 } 142 143 144 if (myMessage==null) { 145 myMessage = new OBError(); 146 myMessage.setType("Success"); 147 myMessage.setTitle(""); 148 myMessage.setMessage(Utility.messageBD(this, "PaymentsSettlementDocNo", vars.getLanguage()) + "*FT*" + strSettlementDocumentNo); 149 } 150 vars.setMessage("CashBankOperations", myMessage); 151 152 } 153 154 String negate(String amount){ 155 BigDecimal amt = new BigDecimal (amount); 156 amt = amt.multiply(new BigDecimal ("-1.0")); 157 return amt.toString(); 158 } 159 160 String insertCash (VariablesSecureApp vars, String strCashBook, String strAmount, String strDate, String strCurrency, String strDescription, Connection con) throws ServletException{ 161 String strCash = CashBankOperationsData.selectOpenCash(this, strCashBook, strDate); 162 if (strCash.equals("")){ 163 strCash =SequenceIdData.getSequence(this, "C_Cash", vars.getClient()); 164 CashBankOperationsData.insertCash(con,this, strCash, vars.getClient(), vars.getOrg(), vars.getUser(), strCashBook, strDate + " - " + CashBankOperationsData.selectCurrency(this, strCurrency), strDate); 165 } 166 String strCashLine = SequenceIdData.getSequence(this, "C_CashLine", vars.getClient()); 167 CashBankOperationsData.insertCashLine(con,this, strCashLine, vars.getClient(), vars.getOrg(),vars.getUser(),strCash,CashBankOperationsData.selectNextCashLine(this,strCash),strDescription, 168 strAmount,strCurrency); 169 return strCashLine; 170 } 171 172 173 void printPage(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 174 if (log4j.isDebugEnabled()) log4j.debug("Output: process CashBankOperations"); 175 ActionButtonDefaultData[] data = null; 176 String strHelp="", strDescription="", strProcessId="800082"; 177 if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId); 178 else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId); 179 if (data!=null && data.length!=0) { 180 strDescription = data[0].description; 181 strHelp = data[0].help; 182 } 183 String [] discard = {""}; 184 if (strHelp.equals("")) discard[0] = new String ("helpDiscard"); 185 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CashBankOperations").createXmlDocument(); 186 187 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "CashBankOperations", false, "", "", "",false, "ad_process", strReplaceWith, false, true); 188 toolbar.prepareSimpleToolBarTemplate(); 189 xmlDocument.setParameter("toolbar", toolbar.toString()); 190 xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2)); 191 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 192 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 193 xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage())); 194 xmlDocument.setParameter("description", strDescription); 195 xmlDocument.setParameter("help", strHelp); 196 xmlDocument.setParameter("datedisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 197 xmlDocument.setParameter("datesaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 198 try { 199 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_BankAccount_ID", "", "", Utility.getContext(this, vars, "#User_Org", "CashBankOperations"), Utility.getContext(this, vars, "#User_Client", "CashBankOperations"), 0); 200 Utility.fillSQLParameters(this, vars, null, comboTableData, "CashBankOperations", ""); 201 xmlDocument.setData("reportC_BankAccountFrom_ID","liststructure", comboTableData.select(false)); 202 comboTableData = null; 203 } catch (Exception ex) { 204 throw new ServletException(ex); 205 } 206 207 208 try { 209 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_BankAccount_ID", "", "", Utility.getContext(this, vars, "#User_Org", "CashBankOperations"), Utility.getContext(this, vars, "#User_Client", "CashBankOperations"), 0); 210 Utility.fillSQLParameters(this, vars, null, comboTableData, "CashBankOperations", ""); 211 xmlDocument.setData("reportC_BankAccountTo_ID","liststructure", comboTableData.select(false)); 212 comboTableData = null; 213 } catch (Exception ex) { 214 throw new ServletException(ex); 215 } 216 217 218 try { 219 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_CashBook_ID", "", "", Utility.getContext(this, vars, "#User_Org", "CashBankOperations"), Utility.getContext(this, vars, "#User_Client", "CashBankOperations"), 0); 220 Utility.fillSQLParameters(this, vars, null, comboTableData, "CashBankOperations", ""); 221 xmlDocument.setData("reportC_CashFrom_ID","liststructure", comboTableData.select(false)); 222 comboTableData = null; 223 } catch (Exception ex) { 224 throw new ServletException(ex); 225 } 226 227 228 try { 229 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_CashBook_ID", "", "", Utility.getContext(this, vars, "#User_Org", "CashBankOperations"), Utility.getContext(this, vars, "#User_Client", "CashBankOperations"), 0); 230 Utility.fillSQLParameters(this, vars, null, comboTableData, "CashBankOperations", ""); 231 xmlDocument.setData("reportC_CashTo_ID","liststructure", comboTableData.select(false)); 232 comboTableData = null; 233 } catch (Exception ex) { 234 throw new ServletException(ex); 235 } 236 237 238 try { 239 ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "All_Payment Rule", "", Utility.getContext(this, vars, "#User_Org", "CashBankOperations"), Utility.getContext(this, vars, "#User_Client", "CashBankOperations"), 0); 240 Utility.fillSQLParameters(this, vars, null, comboTableData, "CashBankOperations", ""); 241 xmlDocument.setData("reportPaymentRuleFrom","liststructure", comboTableData.select(false)); 242 comboTableData = null; 243 } catch (Exception ex) { 244 throw new ServletException(ex); 245 } 246 247 try { 248 ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "All_Payment Rule", "", Utility.getContext(this, vars, "#User_Org", "CashBankOperations"), Utility.getContext(this, vars, "#User_Client", "CashBankOperations"), 0); 249 Utility.fillSQLParameters(this, vars, null, comboTableData, "CashBankOperations", ""); 250 xmlDocument.setData("reportPaymentRuleTo","liststructure", comboTableData.select(false)); 251 comboTableData = null; 252 } catch (Exception ex) { 253 throw new ServletException(ex); 254 } 255 256 257 String strMessage = vars.getSessionValue("CashBankOperations.message"); 258 if (!strMessage.equals("")) { 259 vars.removeSessionValue("CashBankOperations.message"); 260 strMessage = "alert('" + Replace.replace(strMessage, "'", "\'") + "');"; 261 } 262 xmlDocument.setParameter("body", strMessage); 263 264 265 266 267 try { 268 KeyMap key = new KeyMap(this, vars, "CashBankOperations.html"); 269 xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps()); 270 } catch (Exception ex) { 271 throw new ServletException(ex); 272 } 273 try { 274 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_process.CashBankOperations"); 275 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 276 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 277 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 278 xmlDocument.setParameter("theme", vars.getTheme()); 279 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "CashBankOperations.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 280 xmlDocument.setParameter("navigationBar", nav.toString()); 281 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "CashBankOperations.html", strReplaceWith); 282 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 283 } catch (Exception ex) { 284 throw new ServletException(ex); 285 } 286 { 287 OBError myMessage = vars.getMessage("CashBankOperations"); 288 vars.removeMessage("CashBankOperations"); 289 if (myMessage!=null) { 290 xmlDocument.setParameter("messageType", myMessage.getType()); 291 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 292 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 293 } 294 } 295 296 297 response.setContentType("text/html; charset=UTF-8"); 298 PrintWriter out = response.getWriter(); 299 out.println(xmlDocument.print()); 300 out.close(); 301 } 302 303 public String getServletInfo() { 304 return "Servlet CashBankOperations"; 305 } } 307 308
| Popular Tags
|