.getSessionValue("#AD_SqlDateFormat"), strDateFrom, Utility.getContext(this, vars,
"#User_Client", "ReportGeneralLedger"), strOrgFamily);
if (strYearInitialDate.equals(""))
strYearInitialDate = strDateFrom;
ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportGeneralLedger", true, "", "",
"imprimir();return false;", false, "ad_reports", strReplaceWith, false, true);
String strcBpartnerIdAux = strcBpartnerId;
if (!strAll.equals(""))
strcBpartnerId = "";
if (strDateFrom.equals("") && strDateTo.equals("")) {
String discard[] = { "sectionAmount", "sectionPartner" };
xmlDocument = xmlEngine.readXmlTemplate(
"org/openbravo/erpCommon/ad_reports/ReportGeneralLedger", discard).createXmlDocument();
toolbar
.prepareRelationBarTemplate(false, false,
"submitCommandForm('XLS', false, frmMain, 'ReportGeneralLedgerExcel.xls', 'EXCEL');return false;");
data = ReportGeneralLedgerData.set();
} else {
String[] discard = { "discard" };
if (strcBpartnerId.equals("") && strAll.equals(""))
discard[0] = "sectionPartner";
else
discard[0] = "sectionAmount";
BigDecimal previousDebit = BigDecimal.ZERO;
BigDecimal previousCredit = BigDecimal.ZERO;
if (strcelementvaluefrom != null && !strcelementvaluefrom.equals("")) {
if (strcelementvalueto.equals("")) {
strcelementvalueto = strcelementvaluefrom;
}
if (log4j.isDebugEnabled())
log4j.debug("##################### strcelementvaluefrom= " + strcelementvaluefrom);
if (log4j.isDebugEnabled())
log4j.debug("##################### strcelementvalueto= " + strcelementvalueto);
if (strHide.equals(""))
data = ReportGeneralLedgerData.select(this, rowNum, (strcBpartnerId.equals("") && (strAll
.equals(""))) ? "'0' AS C_BPARTNER_ID, '0' AS PARTNER, "
: "FACT_ACCT.C_BPARTNER_ID, C_BPARTNER.NAME AS PARTNER, ", strcelementvaluefrom,
strcelementvalueto, Utility.getContext(this, vars, "#AccessibleOrgTree",
"ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Client",
"ReportGeneralLedger"), strcAcctSchemaId, null, null, null, strDateFrom,
DateTimeData.nDaysAfter(this, strDateTo, "1"), strOrgFamily, strcBpartnerId,
strAmtFrom, strAmtTo, (strcBpartnerId.equals("") && (strAll.equals(""))) ? ""
: "C_BPARTNER.NAME, FACT_ACCT.C_BPARTNER_ID, ", pgLimit, oraLimit1, oraLimit2,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? "" : "PARTNER, ");
else
data = ReportGeneralLedgerData
.selectHiding(
this,
rowNum,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? "'0' AS C_BPARTNER_ID, '0' AS PARTNER, "
: "FACT_ACCT.C_BPARTNER_ID, C_BPARTNER.NAME AS PARTNER, ", strDateFrom,
DateTimeData.nDaysAfter(this, strDateTo, "1"), strcelementvaluefrom,
strcelementvalueto, Utility.getContext(this, vars, "#AccessibleOrgTree",
"ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Client",
"ReportGeneralLedger"), strcAcctSchemaId, null, null, null, strDateFrom,
DateTimeData.nDaysAfter(this, strDateTo, "1"), strOrgFamily, strcBpartnerId,
strAmtFrom, strAmtTo, (strcBpartnerId.equals("") && (strAll.equals(""))) ? ""
: "C_BPARTNER.NAME, FACT_ACCT.C_BPARTNER_ID, ", pgLimit, oraLimit1,
oraLimit2, (strcBpartnerId.equals("") && (strAll.equals(""))) ? "" : "PARTNER, ");
} else {
if (strHide.equals(""))
data = ReportGeneralLedgerData
.selectAll(
this,
rowNum,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? "'0' AS C_BPARTNER_ID, '0' AS PARTNER, "
: "FACT_ACCT.C_BPARTNER_ID, C_BPARTNER.NAME AS PARTNER, ", Utility
.getContext(this, vars, "#AccessibleOrgTree", "ReportGeneralLedger"), Utility
.getContext(this, vars, "#User_Client", "ReportGeneralLedger"),
strcAcctSchemaId, null, null, null, strDateFrom, DateTimeData.nDaysAfter(this,
strDateTo, "1"), strOrgFamily, strcBpartnerId, strAmtFrom, strAmtTo,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? ""
: "C_BPARTNER.NAME, FACT_ACCT.C_BPARTNER_ID, ", pgLimit, oraLimit1,
oraLimit2, (strcBpartnerId.equals("") && (strAll.equals(""))) ? "" : "PARTNER, ");
else
data = ReportGeneralLedgerData
.selectAllHiding(
this,
rowNum,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? "'0' AS C_BPARTNER_ID, '0' AS PARTNER, "
: "FACT_ACCT.C_BPARTNER_ID, C_BPARTNER.NAME AS PARTNER, ", strDateFrom,
DateTimeData.nDaysAfter(this, strDateTo, "1"), Utility.getContext(this, vars,
"#AccessibleOrgTree", "ReportGeneralLedger"), Utility.getContext(this, vars,
"#User_Client", "ReportGeneralLedger"), strcAcctSchemaId, null, null, null,
strDateFrom, DateTimeData.nDaysAfter(this, strDateTo, "1"), strOrgFamily,
strcBpartnerId, strAmtFrom, strAmtTo, (strcBpartnerId.equals("") && (strAll
.equals(""))) ? "" : "C_BPARTNER.NAME, FACT_ACCT.C_BPARTNER_ID, ", pgLimit,
oraLimit1, oraLimit2, (strcBpartnerId.equals("") && (strAll.equals(""))) ? ""
: "PARTNER, ");
}
if (log4j.isDebugEnabled())
log4j.debug("RecordNo: " + initRecordNumber);
// In case this is not the first screen to show, initial balance may need to include amounts
// of previous screen, so same sql -but from the beginning of the fiscal year- is executed
ReportGeneralLedgerData[] dataTotal = null;
if (data.length > 1) {
if (strcelementvaluefrom != null && !strcelementvaluefrom.equals("") && data != null) {
if (strHide.equals(""))
dataTotal = ReportGeneralLedgerData
.select(
this,
rowNum,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? "'0' AS C_BPARTNER_ID, '0' AS PARTNER, "
: "FACT_ACCT.C_BPARTNER_ID, C_BPARTNER.NAME AS PARTNER, ",
strcelementvaluefrom, strcelementvalueto, Utility.getContext(this, vars,
"#AccessibleOrgTree", "ReportGeneralLedger"), Utility.getContext(this,
vars, "#User_Client", "ReportGeneralLedger"), strcAcctSchemaId, data[0].id,
data[0].dateacctnumber + data[0].factAcctGroupId + data[0].factAcctId,
(strcBpartnerId.equals("") && strAll.equals("")) ? null : data[0].cBpartnerId,
strYearInitialDate, DateTimeData.nDaysAfter(this, data[0].dateacct, "1"),
strOrgFamily, strcBpartnerId, strAmtFrom, strAmtTo,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? ""
: "C_BPARTNER.NAME, FACT_ACCT.C_BPARTNER_ID, ", null, null, null,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? "" : "PARTNER, ");
else
dataTotal = ReportGeneralLedgerData.selectHiding(this, rowNum, (strcBpartnerId
.equals("") && (strAll.equals(""))) ? "'0' AS C_BPARTNER_ID, '0' AS PARTNER, "
: "FACT_ACCT.C_BPARTNER_ID, C_BPARTNER.NAME AS PARTNER, ", strDateFrom,
DateTimeData.nDaysAfter(this, strDateTo, "1"), strcelementvaluefrom,
strcelementvalueto, Utility.getContext(this, vars, "#AccessibleOrgTree",
"ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Client",
"ReportGeneralLedger"), strcAcctSchemaId, data[0].id, data[0].dateacctnumber
+ data[0].factAcctGroupId + data[0].factAcctId,
(strcBpartnerId.equals("") && strAll.equals("")) ? null : data[0].cBpartnerId,
strYearInitialDate, DateTimeData.nDaysAfter(this, data[0].dateacct, "1"),
strOrgFamily, strcBpartnerId, strAmtFrom, strAmtTo,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? ""
: "C_BPARTNER.NAME, FACT_ACCT.C_BPARTNER_ID, ", null, null, null,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? "" : "PARTNER, ");
} else {
if (strHide.equals(""))
dataTotal = ReportGeneralLedgerData
.selectAll(
this,
rowNum,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? "'0' AS C_BPARTNER_ID, '0' AS PARTNER, "
: "FACT_ACCT.C_BPARTNER_ID, C_BPARTNER.NAME AS PARTNER, ",
Utility.getContext(this, vars, "#AccessibleOrgTree", "ReportGeneralLedger"),
Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"),
strcAcctSchemaId,
// only account for first record of current page
data[0].id, data[0].dateacctnumber + data[0].factAcctGroupId
+ data[0].factAcctId,
(strcBpartnerId.equals("") && strAll.equals("")) ? null : data[0].cBpartnerId,
strYearInitialDate, DateTimeData.nDaysAfter(this, data[0].dateacct, "1"),
strOrgFamily, strcBpartnerId, strAmtFrom, strAmtTo,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? ""
: "C_BPARTNER.NAME, FACT_ACCT.C_BPARTNER_ID, ", null, null, null,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? "" : "PARTNER, ");
else
dataTotal = ReportGeneralLedgerData.selectAllHiding(this, rowNum, (strcBpartnerId
.equals("") && (strAll.equals(""))) ? "'0' AS C_BPARTNER_ID, '0' AS PARTNER, "
: "FACT_ACCT.C_BPARTNER_ID, C_BPARTNER.NAME AS PARTNER, ", strDateFrom,
DateTimeData.nDaysAfter(this, strDateTo, "1"), Utility.getContext(this, vars,
"#AccessibleOrgTree", "ReportGeneralLedger"), Utility.getContext(this, vars,
"#User_Client", "ReportGeneralLedger"), strcAcctSchemaId, data[0].id,
data[0].dateacctnumber + data[0].factAcctGroupId + data[0].factAcctId,
(strcBpartnerId.equals("") && strAll.equals("")) ? null : data[0].cBpartnerId,
strYearInitialDate, DateTimeData.nDaysAfter(this, data[0].dateacct, "1"),
strOrgFamily, strcBpartnerId, strAmtFrom, strAmtTo,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? ""
: "C_BPARTNER.NAME, FACT_ACCT.C_BPARTNER_ID, ", null, null, null,
(strcBpartnerId.equals("") && (strAll.equals(""))) ? "" : "PARTNER, ");
}
}
// Now dataTotal is covered adding debit and credit amounts
for (int i = 0; dataTotal != null && i < dataTotal.length; i++) {
previousDebit = previousDebit.add(new BigDecimal(dataTotal[i].amtacctdr));
previousCredit = previousCredit.add(new BigDecimal(dataTotal[i].amtacctcr));
}
ArrayList<Object> list = new ArrayList<Object>();
String toDatePlusOne = DateTimeData.nDaysAfter(this, strDateTo, "1");
String strOld = "";
int j = 0;
ReportGeneralLedgerData[] subreportElement = new ReportGeneralLedgerData[1];
for (int i = 0; data != null && i < data.length; i++) {
if (!strOld.equals(((strcBpartnerId.equals("") && strAll.equals("")) ? ""
: data[i].cBpartnerId)
+ data[i].id)) {
subreportElement = new ReportGeneralLedgerData[1];
if (i == 0 && initRecordNumber > 0) {
subreportElement = new ReportGeneralLedgerData[1];
subreportElement[0] = new ReportGeneralLedgerData();
subreportElement[0].totaldr = previousDebit.toPlainString();
subreportElement[0].totalcr = previousCredit.toPlainString();
subreportElement[0].total = previousDebit.subtract(previousCredit).toPlainString();
} else if (strHide.equals(""))
subreportElement = ReportGeneralLedgerData.selectTotal(this,
(strcBpartnerId.equals("") && strAll.equals("")) ? "" : data[i].cBpartnerId,
strcAcctSchemaId, data[i].id, strYearInitialDate, strDateFrom, strOrgFamily);
else
subreportElement = ReportGeneralLedgerData.selectTotalHiding(this, strDateFrom,
toDatePlusOne, (strcBpartnerId.equals("") && strAll.equals("")) ? ""
: data[i].cBpartnerId, strcAcctSchemaId, data[i].id, strYearInitialDate,
strDateFrom, strOrgFamily);
data[i].totalacctdr = subreportElement[0].totaldr;
data[i].totalacctcr = subreportElement[0].totalcr;
data[i].totalacctsub = subreportElement[0].total;
list.add(subreportElement);
j++;
}
data[i].previousdebit = subreportElement[0].totaldr;
data[i].previouscredit = subreportElement[0].totalcr;
data[i].previoustotal = subreportElement[0].total;
strOld = (((strcBpartnerId.equals("") && strAll.equals("")) ? "" : data[i].cBpartnerId) + data[i].id);
}
/*
* subreport = new ReportGeneralLedgerData[j][]; list.toArray(subreport);
*/
list = new ArrayList<Object>();
String strTotal = "";
int g = 0;
subreportElement = new ReportGeneralLedgerData[1];
for (int i = 0; data != null && i < data.length; i++) {
if (!strTotal.equals(((strcBpartnerId.equals("") && strAll.equals("")) ? ""
: data[i].cBpartnerId)
+ data[i].id)) {
subreportElement = new ReportGeneralLedgerData[1];
if (strHide.equals(""))
subreportElement = ReportGeneralLedgerData.selectTotal(this,
(strcBpartnerId.equals("") && strAll.equals("")) ? "" : data[i].cBpartnerId,
strcAcctSchemaId, data[i].id, strYearInitialDate, toDatePlusOne, strOrgFamily);
else
subreportElement = ReportGeneralLedgerData.selectTotalHiding(this, strDateFrom,
toDatePlusOne, (strcBpartnerId.equals("") && strAll.equals("")) ? ""
: data[i].cBpartnerId, strcAcctSchemaId, data[i].id, strYearInitialDate,
toDatePlusOne, strOrgFamily);
g++;
}
data[i].finaldebit = subreportElement[0].totaldr;
data[i].finalcredit = subreportElement[0].totalcr;
data[i].finaltotal = subreportElement[0].total;
strTotal = (((strcBpartnerId.equals("") && strAll.equals("")) ? "" : data[i].cBpartnerId) + data[i].id);
}
/*
* subreport2 = new ReportGeneralLedgerData[g][]; list.toArray(subreport2);
*/
boolean hasPrevious = !(data == null || data.length == 0 || initRecordNumber <= 1);
boolean hasNext = !(data == null || data.length == 0 || data.length < intRecordRange);
toolbar
.prepareRelationBarTemplate(hasPrevious, hasNext,
"submitCommandForm('XLS', true, frmMain, 'ReportGeneralLedgerExcel.xls', 'EXCEL');return false;");
xmlDocument = xmlEngine.readXmlTemplate(
"org/openbravo/erpCommon/ad_reports/ReportGeneralLedger", discard).createXmlDocument();
}
xmlDocument.setParameter("toolbar", toolbar.toString());
try {
WindowTabs tabs = new WindowTabs(this, vars,
"org.openbravo.erpCommon.ad_reports.ReportGeneralLedger");
xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());