1 19 package org.openbravo.erpCommon.ad_actionButton; 20 21 import org.openbravo.erpCommon.utility.SequenceIdData; 23 import org.openbravo.erpCommon.utility.Utility; 24 import org.openbravo.utils.FormatUtilities; 25 import org.openbravo.base.secureApp.HttpSecureAppServlet; 26 import org.openbravo.base.secureApp.VariablesSecureApp; 27 import org.openbravo.xmlEngine.XmlDocument; 28 import java.io.*; 29 import java.math.*; 30 import javax.servlet.*; 31 import javax.servlet.http.*; 32 33 public class CreateCloseFactAcct extends HttpSecureAppServlet { 34 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 44 if (vars.commandIn("DEFAULT")) { 45 String strProcessId = vars.getStringParameter("inpProcessId"); 46 String strWindow = vars.getStringParameter("inpwindowId"); 47 String strTab = vars.getStringParameter("inpTabId"); 48 String strPediodId = vars.getStringParameter("inpcPeriodId", ""); 49 String strKey = vars.getRequiredGlobalVariable("inpcYearId", strWindow + "|C_Year_ID"); 50 printPage(response, vars, strKey, strPediodId, strWindow, strTab, strProcessId); 51 } else if (vars.commandIn("SAVE")) { 52 String strWindow = vars.getStringParameter("inpwindowId"); 53 String strPediodId = vars.getStringParameter("inpcPeriodId", ""); 54 String strKey = vars.getRequiredGlobalVariable("inpcYearId", strWindow + "|C_Year_ID"); 55 String strTab = vars.getStringParameter("inpTabId"); 56 ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab); 57 String strWindowPath="", strTabName=""; 58 if (tab!=null && tab.length!=0) { 59 strTabName = FormatUtilities.replace(tab[0].name); 60 strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html"; 61 } else strWindowPath = strDefaultServlet; 62 String messageResult = processButton(vars, strKey, strPediodId, strWindow); 63 vars.setSessionValue(strWindow + "|" + strTabName + ".message", messageResult); 64 printPageClosePopUp(response, vars, strWindowPath); 65 } else pageErrorPopUp(response); 66 } 67 68 69 String processButton(VariablesSecureApp vars, String strKey, String strPediodId, String windowId) { 70 try { 71 CreateCloseFactAcctData[] asset = CreateCloseFactAcctData.getAmounts(this, strKey, strPediodId, "A"); 72 CreateCloseFactAcctData[] liability = CreateCloseFactAcctData.getAmounts(this, strKey, strPediodId, "L"); 73 BigDecimal AmtCr, AmtDr; 74 BigDecimal assetAmtDr = new BigDecimal("0"); 75 BigDecimal assetAmtCr = new BigDecimal("0"); 76 BigDecimal liabilityAmtDr = new BigDecimal("0"); 77 BigDecimal liabilityAmtCr = new BigDecimal("0"); 78 String strAcctSchema = Utility.getContext(this, vars, "$C_ACCTSCHEMA_ID", windowId);; 79 String Fact_Acct_ID = ""; 80 String Fact_Acct_Group_ID = ""; 81 String newPeriod = ""; 82 if(CreateCloseFactAcctData.getNextPeriod(this, strPediodId, strKey).equals("")) 83 if (CreateCloseFactAcctData.getNextYear(this, strKey).equals(""))return Utility.messageBD(this, "ProcessRunError", vars.getLanguage()); 84 else if (CreateCloseFactAcctData.getFirstPeriod(this, CreateCloseFactAcctData.getNextYear(this, strKey)).equals("")) 85 return Utility.messageBD(this, "ProcessRunError", vars.getLanguage()); 86 else newPeriod = CreateCloseFactAcctData.getFirstPeriod(this, CreateCloseFactAcctData.getNextYear(this, strKey)); 87 else newPeriod = CreateCloseFactAcctData.getNextPeriod(this, strPediodId, strKey); 88 Fact_Acct_Group_ID = SequenceIdData.getSequence(this, "Fact_Acct_Group", vars.getClient()); 89 int i; 90 for (i=0;i<asset.length;i++){ 91 assetAmtDr = assetAmtDr.add(new BigDecimal(asset[i].totalamtdr)); 92 assetAmtCr = assetAmtCr.add(new BigDecimal(asset[i].totalamtcr)); 93 Fact_Acct_ID = SequenceIdData.getSequence(this, "Fact_Acct", vars.getClient()); 94 CreateCloseFactAcctData.insert(this, Fact_Acct_ID, vars.getClient(), vars.getOrg(), vars.getUser(), strAcctSchema, asset[i].accountId, CreateCloseFactAcctData.getEndDate(this, strPediodId), strPediodId, CreateCloseFactAcctData.adTableId(this), "A", CreateCloseFactAcctData.cCurrencyId(this, strAcctSchema),asset[i].totalamtdr,asset[i].totalamtcr,asset[i].totalamtdr,asset[i].totalamtcr , Fact_Acct_Group_ID, Integer.toString((i+3)*10), "C"); 95 } 96 for (int j=0;j<liability.length;j++){ 97 liabilityAmtDr = liabilityAmtDr.add(new BigDecimal(liability[j].totalamtdr)); 98 liabilityAmtCr = liabilityAmtCr.add(new BigDecimal(liability[j].totalamtcr)); 99 Fact_Acct_ID = SequenceIdData.getSequence(this, "Fact_Acct", vars.getClient()); 100 CreateCloseFactAcctData.insert(this, Fact_Acct_ID, vars.getClient(), vars.getOrg(), vars.getUser(), strAcctSchema, liability[j].accountId, CreateCloseFactAcctData.getEndDate(this, strPediodId), strPediodId, CreateCloseFactAcctData.adTableId(this), "A", CreateCloseFactAcctData.cCurrencyId(this, strAcctSchema),liability[j].totalamtdr,liability[j].totalamtcr,liability[j].totalamtdr,liability[j].totalamtcr , Fact_Acct_Group_ID, Integer.toString((i+j+3)*10), "C"); 101 } 102 String Fact_Acct_Group_ID2 = SequenceIdData.getSequence(this, "Fact_Acct_Group", vars.getClient()); 103 i = 0; 104 for (i=0;i<asset.length;i++){ 105 assetAmtDr = assetAmtDr.add(new BigDecimal(asset[i].totalamtdr)); 106 assetAmtCr = assetAmtCr.add(new BigDecimal(asset[i].totalamtcr)); 107 Fact_Acct_ID = SequenceIdData.getSequence(this, "Fact_Acct", vars.getClient()); 108 CreateCloseFactAcctData.insert(this, Fact_Acct_ID, vars.getClient(), vars.getOrg(), vars.getUser(), strAcctSchema, asset[i].accountId, CreateCloseFactAcctData.getStartDate(this, newPeriod), newPeriod, CreateCloseFactAcctData.adTableId(this), "A", CreateCloseFactAcctData.cCurrencyId(this, strAcctSchema),asset[i].totalamtcr,asset[i].totalamtdr,asset[i].totalamtcr,asset[i].totalamtdr , Fact_Acct_Group_ID2, Integer.toString((i+3)*10), "O"); 109 } 110 for (int j=0;j<liability.length;j++){ 111 liabilityAmtDr = liabilityAmtDr.add(new BigDecimal(liability[j].totalamtdr)); 112 liabilityAmtCr = liabilityAmtCr.add(new BigDecimal(liability[j].totalamtcr)); 113 Fact_Acct_ID = SequenceIdData.getSequence(this, "Fact_Acct", vars.getClient()); 114 CreateCloseFactAcctData.insert(this, Fact_Acct_ID, vars.getClient(), vars.getOrg(), vars.getUser(), strAcctSchema, liability[j].accountId, CreateCloseFactAcctData.getStartDate(this, newPeriod), newPeriod, CreateCloseFactAcctData.adTableId(this), "A", CreateCloseFactAcctData.cCurrencyId(this, strAcctSchema),liability[j].totalamtcr,liability[j].totalamtdr,liability[j].totalamtcr,liability[j].totalamtdr, Fact_Acct_Group_ID2, Integer.toString((i+j+3)*10), "O"); 115 } 116 if(CreateCloseFactAcctData.updatePeriods(this, Fact_Acct_Group_ID, strKey, strPediodId)!=0) 117 return Utility.messageBD(this, "ProcessOK", vars.getLanguage()); 118 else return Utility.messageBD(this, "ProcessRunError", vars.getLanguage()); 119 } catch (ServletException e) { 120 log4j.warn(e); 121 return Utility.messageBD(this, "ProcessRunError", vars.getLanguage()); 122 } 123 } 124 125 126 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strPediodId, String windowId, String strTab, String strProcessId) throws IOException, ServletException { 127 if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Create Close Fact Acct"); 128 129 ActionButtonDefaultData[] data = null; 130 String strHelp="", strDescription=""; 131 if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId); 132 else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId); 133 134 if (data!=null && data.length!=0) { 135 strDescription = data[0].description; 136 strHelp = data[0].help; 137 } 138 String [] discard = {""}; 139 if (strHelp.equals("")) discard[0] = new String ("helpDiscard"); 140 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/CreateCloseFactAcct", discard).createXmlDocument(); 141 xmlDocument.setParameter("key", strKey); 142 xmlDocument.setParameter("window", windowId); 143 xmlDocument.setParameter("tab", strTab); 144 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 145 xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage())); 146 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 147 xmlDocument.setParameter("description", strDescription); 148 xmlDocument.setParameter("help", strHelp); 149 150 151 xmlDocument.setData("reportcPeriodId", "liststructure", CreateCloseFactAcctData.select(this,strKey)); 152 153 xmlDocument.setParameter("cPeriodId", strPediodId); 154 155 156 response.setContentType("text/html; charset=UTF-8"); 157 PrintWriter out = response.getWriter(); 158 out.println(xmlDocument.print()); 159 out.close(); 160 } 161 162 public String getServletInfo() { 163 return "Servlet Project close fact acct"; 164 } } 166 167 | Popular Tags |