Merge with FinancialReport

This commit is contained in:
hodianto 2018-05-04 21:09:43 +07:00
commit b62417a620
4 changed files with 2189 additions and 27 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,115 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package andromedia.midsuit.process;
import java.sql.CallableStatement;
import java.util.ArrayList;
import java.util.logging.Level;
import org.adempiere.util.ProcessUtil;
import org.compiere.model.MPInstance;
import org.compiere.model.MProcess;
import org.compiere.process.ProcessInfo;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.report.MReport;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Trx;
/**
* Financial Report Engine
*
* @author Jorg Janke
* @version $Id: FinReport.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
*/
public class MID_FinReportJasper extends MID_FinReport
{
/** Report Definition */
private MReport m_report = null;
/**************************************************************************
* Perform process.
* @return Message to be translated
* @throws Exception
*/
protected String doIt() throws Exception
{
// Call the normal FinReport to fill the T_Report table
String finReportMsg = super.doIt();
// Now invoke the associated jasper report (must report on the T_Report table)
ArrayList<ProcessInfoParameter> list = new ArrayList<ProcessInfoParameter>();
// Copy the list of parameters from the financial report
ProcessInfoParameter oldpara[] = getParameter();
for (int i = 0; i < oldpara.length; i++)
list.add (oldpara[i]);
// and add the T_Report_AD_PInstance_ID parameter
list.add (new ProcessInfoParameter("T_Report_AD_PInstance_ID", new Integer(getAD_PInstance_ID()), null, null, null));
ProcessInfoParameter[] pars = new ProcessInfoParameter[list.size()];
list.toArray(pars);
// Load Report Definition
m_report = new MReport (getCtx(), getRecord_ID(), get_TrxName());
MProcess proc = new MProcess(getCtx(), m_report.getJasperProcess_ID(), get_TrxName());
MPInstance instance = new MPInstance(proc, getRecord_ID());
instance.saveEx();
ProcessInfo poInfo = new ProcessInfo(proc.getName(), proc.getAD_Process_ID());
poInfo.setParameter(pars);
poInfo.setRecord_ID(getRecord_ID());
poInfo.setAD_Process_ID(proc.getAD_Process_ID());
poInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID());
// need to commit in order to allow jasper to view the data
Trx trx = Trx.get(get_TrxName(), true);
trx.commit();
// CarlosRuiz - globalqss - allow procedure preprocess
if (proc.getProcedureName() != null && proc.getProcedureName().length() > 0) {
// execute on this thread/connection
String sql = "{call " + proc.getProcedureName() + "(?)}";
CallableStatement cstmt = null;
try
{
cstmt = DB.prepareCall(sql); // ro??
cstmt.setInt(1, getAD_PInstance_ID());
cstmt.executeUpdate();
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
poInfo.setSummary (Msg.getMsg(Env.getCtx(), "ProcessRunError") + " " + e.getLocalizedMessage());
}
finally
{
DB.close(cstmt);
cstmt = null;
}
}
// TODO - allow java class preprocess if the classname <> ProcessUtil.JASPER_STARTER_CLASS
ProcessUtil.startJavaProcess(getCtx(), poInfo, trx);
return finReportMsg;
} // doIt
} // FinReport

View File

@ -0,0 +1,182 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package andromedia.midsuit.process;
import java.sql.Timestamp;
import org.compiere.util.DB;
/**
* Financial Report Periods
*
* @author Jorg Janke
* @version $Id: FinReportPeriod.java,v 1.3 2006/08/03 22:16:52 jjanke Exp $
*/
public class MID_FinReportPeriod
{
/**
* Constructor
* @param C_Period_ID period
* @param Name name
* @param StartDate period start date
* @param EndDate period end date
* @param YearStartDate year start date
*/
public MID_FinReportPeriod (int C_Period_ID, String Name, Timestamp StartDate, Timestamp EndDate,
Timestamp YearStartDate, Timestamp date1, Timestamp date2)
{
m_C_Period_ID = C_Period_ID;
m_Name = Name;
m_StartDate = StartDate;
m_EndDate = EndDate;
m_YearStartDate = YearStartDate;
m_Date1 = date1;
m_Date2 = date2;
} //
private int m_C_Period_ID;
private String m_Name;
private Timestamp m_StartDate;
private Timestamp m_EndDate;
private Timestamp m_YearStartDate;
private Timestamp m_Date1;
private Timestamp m_Date2;
/**
* Get Period Info
* @return BETWEEN start AND end
*/
public String getPeriodWhere ()
{
StringBuilder sql = new StringBuilder ("BETWEEN ");
sql.append(DB.TO_DATE(m_StartDate))
.append(" AND ")
.append(DB.TO_DATE(m_EndDate));
return sql.toString();
} // getPeriodWhere
/**
* Get Year Info
* @return BETWEEN start AND end
*/
public String getYearWhere ()
{
StringBuilder sql = new StringBuilder ("BETWEEN ");
sql.append(DB.TO_DATE(m_YearStartDate))
.append(" AND ")
.append(DB.TO_DATE(m_EndDate));
return sql.toString();
} // getPeriodWhere
/**
* Get Total Info
* @return <= end
*/
public String getTotalWhere ()
{
StringBuilder sql = new StringBuilder ("<= ");
sql.append(DB.TO_DATE(m_EndDate));
return sql.toString();
} // getPeriodWhere
/**
* Is date in period
* @param date date
* @return true if in period
*/
public boolean inPeriod (Timestamp date)
{
if (date == null)
return false;
if (date.before(m_StartDate))
return false;
if (date.after(m_EndDate))
return false;
return true;
} // inPeriod
/**
* Get Name
* @return name
*/
public String getName()
{
return m_Name;
}
/**
* Get C_Period_ID
* @return period
*/
public int getC_Period_ID()
{
return m_C_Period_ID;
}
/**
* Get End Date
* @return end date
*/
public Timestamp getEndDate()
{
return m_EndDate;
}
/**
* Get Start Date
* @return start date
*/
public Timestamp getStartDate()
{
return m_StartDate;
}
/**
* Get Year Start Date
* @return year start date
*/
public Timestamp getYearStartDate()
{
return m_YearStartDate;
}
/**
* Get natural balance dateacct filter
* @param alias table name or alias name
* @return is balance sheet a/c and <= end or BETWEEN start AND end
*/
public String getNaturalWhere(String alias) {
String yearWhere = getYearWhere();
String totalWhere = getTotalWhere();
String bs = " EXISTS (SELECT C_ElementValue_ID FROM C_ElementValue WHERE C_ElementValue_ID = " + alias + ".Account_ID AND AccountType NOT IN ('R', 'E'))";
String full = totalWhere + " AND ( " + bs + " OR TRUNC(" + alias + ".DateAcct) " + yearWhere + " ) ";
return full;
}
public String getDateRangeWhere ()
{
StringBuilder sql = new StringBuilder ("BETWEEN ");
sql.append(DB.TO_DATE(m_Date1))
.append(" AND ")
.append(DB.TO_DATE(m_Date2));
return sql.toString();
}
public Timestamp getM_Date1() {
return m_Date1;
}
public Timestamp getM_Date2() {
return m_Date2;
}
} // FinReportPeriod

View File

@ -24,14 +24,14 @@ import java.sql.Timestamp;
import java.util.logging.Level;
import org.adempiere.exceptions.DBException;
import org.compiere.model.MAging;
import org.compiere.model.MRole;
import org.compiere.print.ReportEngine;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
import org.compiere.util.TimeUtil;
import andromedia.midsuit.model.MID_Aging;
/**
* Invoice Aging Report.
* Based on RV_Aging.
@ -56,7 +56,6 @@ public class MID_ProcessRVAging extends SvrProcess
private boolean p_IsListInvoices = false;
/** Number of days between today and statement date */
private int m_statementOffset = 0;
private String m_DocBaseType = null;
/**
* Prepare - e.g., get Parameters.
@ -85,8 +84,6 @@ public class MID_ProcessRVAging extends SvrProcess
p_C_BPartner_ID = ((BigDecimal)para[i].getParameter()).intValue();
else if (name.equals("IsListInvoices"))
p_IsListInvoices = "Y".equals(para[i].getParameter());
else if (name.equals("DocBaseType"))
m_DocBaseType = (String)para[i].getParameterAsString();
else
log.log(Level.SEVERE, "Unknown Parameter: " + name);
}
@ -142,7 +139,6 @@ public class MID_ProcessRVAging extends SvrProcess
}
}
sql.append(",oi.C_Activity_ID,oi.C_Campaign_ID,oi.C_Project_ID,oi.AD_Org_ID "); // 14..17
sql.append(",alo.UnallocatedPayment ");
if (!p_DateAcct)//FR 1933937
{
sql.append(" FROM RV_OpenItem oi");
@ -153,16 +149,6 @@ public class MID_ProcessRVAging extends SvrProcess
}
sql.append(" INNER JOIN C_BPartner bp ON (oi.C_BPartner_ID=bp.C_BPartner_ID) "
+ "LEFT JOIN C_DocType dt ON (dt.C_DocType_ID=oi.C_DocType_ID) "
+ "LEFT JOIN (select c_bpartner_id, " +
"sum(payment) as UnallocatedPayment " +
"FROM " +
"(SELECT p.c_bpartner_id, " +
"p.payamt + (coalesce(sum(al.amount),0)) as payment " +
"FROM C_Payment p " +
"left join c_allocationline al on al.c_payment_id = p.c_payment_id " +
"group by p.c_bpartner_id, payamt) allo " +
"group by c_bpartner_id) alo ON alo.C_BPartner_ID = oi.C_BPartner_ID "
+ "WHERE oi.ISSoTrx=").append(p_IsSOTrx ? "'Y'" : "'N'");
if (p_C_BPartner_ID > 0)
{
@ -181,21 +167,19 @@ public class MID_ProcessRVAging extends SvrProcess
{
sql.append(" AND invoiceOpenToDate(oi.C_Invoice_ID,oi.C_InvoicePaySchedule_ID,"+dateacct+") <> 0 ");
}
if (m_DocBaseType!=null) {
sql.append(" AND dt.DocBaseType='").append(m_DocBaseType).append("'");
}
sql.append(" ORDER BY oi.C_BPartner_ID, oi.C_Currency_ID, oi.C_Invoice_ID");
if (log.isLoggable(Level.FINEST)) log.finest(sql.toString());
String finalSql = MRole.getDefault(getCtx(), false).addAccessSQL(
sql.toString(), "oi", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
// String finalSql = MRole.getDefault(getCtx(), false).addAccessSQL(
// sql.toString(), "oi", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
String finalSql = sql.toString();
log.finer(finalSql);
PreparedStatement pstmt = null;
ResultSet rs = null;
//
MID_Aging aging = null;
MAging aging = null;
int counter = 0;
int rows = 0;
int AD_PInstance_ID = getAD_PInstance_ID();
@ -228,11 +212,8 @@ public class MID_ProcessRVAging extends SvrProcess
int C_Campaign_ID = p_IsListInvoices ? rs.getInt(15) : 0;
int C_Project_ID = p_IsListInvoices ? rs.getInt(16) : 0;
int AD_Org_ID = rs.getInt(17);
BigDecimal UnallocatedPayment = rs.getBigDecimal(18);
rows++;
aging.add (DueDate, DaysDue, GrandTotal, OpenAmt, UnallocatedPayment);
// New Aging Row
if (aging == null // Key
|| AD_PInstance_ID != aging.getAD_PInstance_ID()
@ -246,7 +227,7 @@ public class MID_ProcessRVAging extends SvrProcess
aging.saveEx();
if (log.isLoggable(Level.FINE)) log.fine("#" + ++counter + " - " + aging);
}
aging = new MID_Aging (getCtx(), AD_PInstance_ID, p_StatementDate,
aging = new MAging (getCtx(), AD_PInstance_ID, p_StatementDate,
C_BPartner_ID, C_Currency_ID,
C_Invoice_ID, C_InvoicePaySchedule_ID,
C_BP_Group_ID, AD_Org_ID, DueDate, IsSOTrx, get_TrxName());
@ -256,7 +237,7 @@ public class MID_ProcessRVAging extends SvrProcess
aging.setDateAcct(p_DateAcct);
}
// Fill Buckets
aging.add (DueDate, DaysDue, GrandTotal, OpenAmt);
}
if (aging != null)
{
@ -277,6 +258,7 @@ public class MID_ProcessRVAging extends SvrProcess
//
if (log.isLoggable(Level.INFO)) log.info("#" + counter + " - rows=" + rows);
return "";
} // doIt
} // Aging