Commit 62db036c authored by btambade's avatar btambade

F19DBAS003 : Payable Dashboard (Migration From DBR to ang)

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@205103 ce508802-f39f-4f6c-b175-0d175dae99d5
parent b5cd458c
package ibase.dashboard.ssc.ejb;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import javax.ejb.Stateless;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
/**
* Session Bean implementation class CustomerInfoEJB
*/
@Stateless
public class PayableDashboardDAO extends ValidatorEJB {
/**
* Default constructor.
*/
public PayableDashboardDAO() {
}
GenericUtility genericUtility = GenericUtility.getInstance();
SimpleDateFormat gridDateFormat=null;
SimpleDateFormat convrtToTimStmDate=null;
/*Last*/
@SuppressWarnings("unchecked")
public JSONArray getAngPendingPO(String loginCode, String dataSourceName) throws RemoteException, ITMException
{
System.out.println("getAngPendingPO");
JSONArray rawDataPaymentDet = new JSONArray();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
try
{
if(loginCode!=null && loginCode.trim().length()>0)
{
gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat());
System.out.println("gridDateFormat "+ gridDateFormat);
convrtToTimStmDate = new SimpleDateFormat(genericUtility.getDBDateFormat());
System.out.println("convrtToTimStmDate"+ convrtToTimStmDate);
System.out.println(" Inside PayableDashboardDAO for getAngPendingPO Method Data Soruc Name ="+dataSourceName+" loginCode comming from seesion =" + loginCode);
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
int count = 0;
sql = " select m.tran_id,m.tran_date, m.net_amt,m.ref_no,m. bank_code,b.bank_name " +
"from misc_payment m inner join bank b on m.bank_code=b.bank_code " +
" where Rownum <= 5 and m.sundry_type = 'S'and m.net_amt>0 " +
" and m.sundry_code in (select entity_code from entity_contact where entity_type = 'S' " +
" and User_id__portal = '"+loginCode+"' ) "+
" and tran_date >= (select fr_date from acctprd where to_date(sysdate) " +
" between fr_date and to_date) and confirmed = 'Y'order by tran_date desc ";
System.out.println("sql is"+ sql);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
rowData = new JSONObject();
rowData.put("tran_id", checkNull(rs.getString("tran_id")));
String tranDate =checkNull(rs.getString("tran_date"));
if(tranDate.trim().length()>0)
{
rowData.put("tran_date", gridDateFormat.format((convrtToTimStmDate.parse(tranDate))));
}
else
{
rowData.put("tran_date",checkNull(rs.getString("tran_date")));
}
rowData.put("net_amt", checkNull(rs.getString("net_amt")));
rowData.put("cheque_no",checkNull (rs.getString("ref_no")));
rowData.put("bank_code", checkNull(rs.getString("bank_name")));
rawDataPaymentDet.add(rowData);
count++;
System.out.println("after jsonobject adding in JsonArray" +rowData );
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :PayableDashboardDAO for getAngPendingPurcOrder Method :" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataPaymentDet;
}
@SuppressWarnings("unchecked")
public JSONArray getAngPendingPOValue(String loginCode, String dataSourceName) throws RemoteException, ITMException
{
JSONArray rawDataPOValueDet = new JSONArray();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
try
{
System.out.println(" Inside PayableDashboardDAO for getAngPOValueData Method Data Soruc Name ="+dataSourceName+" logincode comming from session =" + loginCode);
if(loginCode!=null && loginCode.trim().length()>0)
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
sql = " select to_char(ORD_DATE, 'MON-YY') as month, sum(tot_amt) as povalue,to_char(ORD_DATE,'MMYY'),count(1) as no_of_po "+
" from porder where ORD_DATE >= (SELECT ADD_MONTHS(SYSDATE,-5) FROM DUAL ) "+
" and case when confirmed is null then 'N' else confirmed end = 'Y' "+
" and case when status is null then 'O' else status end <> 'X' "+
" and supp_code in (select entity_code from entity_contact where entity_type = 'S' " +
" and User_id__portal ='"+loginCode+"')"+
" group by to_char(ORD_DATE, 'MON-YY') ,to_char(ORD_DATE,'MMYY') "+
" order by to_char(ORD_DATE,'MMYY') asc ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
rowData = new JSONObject();
rowData.put("month", (rs.getString("month")));
rowData.put("povalue", (rs.getString("povalue")));
rowData.put("no_of_po", (rs.getString("no_of_po")));
rawDataPOValueDet.add(rowData);
count++;
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :PayableDashboardDAO for getAngPendingPOValue Method :" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataPOValueDet;
}
@SuppressWarnings("unchecked")
public JSONArray getAngPendingInvoice(String loginCode,String fromDate,String toDate, String dataSourceName) throws RemoteException, ITMException
{
JSONArray rawDataPendingInvoice = new JSONArray();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
Calendar calendar=null;
String currentDate="";
String varValue="";
String[] lotNoList=null;
try
{
System.out.println(" Inside PayableDashboardDAO for getAngPendingInvoice Method Data Soruc Name ="+dataSourceName+" logincode is =" + loginCode+"fromDate==="+fromDate+"ToDate==="+toDate);
if(loginCode!=null && loginCode.trim().length()>0)
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
// This is old sql for pending invoice detail.Changes by Birendra Pandey on dated :13/10/2015
sql ="select var_value from disparm where prd_code = '999999' and var_name = 'BILL_STATUS_REAS'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{
varValue = rs.getString("var_value");
}
System.out.println(" Inside PayableDashboardDAO for getAngPendingInvoice Method Data var_value ="+varValue);
rs.close();
rs = null;
pstmt.close();
pstmt = null;
String lotNoIssueTemp = "";
if (varValue != null && varValue.trim().length() > 0)
{
lotNoList = varValue.split(",");
varValue = "";
for(int ctr = 0;ctr < lotNoList.length;ctr++)
{
lotNoIssueTemp = lotNoList[ctr];
if (varValue.trim().length() > 0)
{
varValue = varValue + ",'".concat(lotNoIssueTemp).concat("'");
}
else
{
varValue = varValue + "'".concat(lotNoIssueTemp).concat("'");
}
}
}
System.out.println("varValue after ["+varValue + "]");
if (varValue=="" || varValue==null)
{
varValue ="'Y'";
}
//SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yyyy");
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat());
calendar = Calendar.getInstance();
currentDate = simpleDateFormat.format(calendar.getTime());
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
toDate = simpleDateFormat.format(calendar.getTime());
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = simpleDateFormat.format(calendar.getTime());
System.out.println("get default date ,when user not entering date from GUI:"+"currentDate="+currentDate+"fromDate="+fromDate+"toDate="+toDate);
}
else
{
fromDate = genericUtility.getValidDateString( fromDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() );
toDate = genericUtility.getValidDateString( toDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() );
System.out.println("In PayableDashboardDAO After format :: fromDate:["+fromDate+"] toDate:["+toDate+"]");
}
sql = "SELECT SB.SUPP_CODE , S.SUPP_NAME , SUM(CASE WHEN SB.REAS_CODES IN ("+varValue+") " +
"THEN 1 ELSE 0 END ) AS HARD_COPY_NOT_RECD, " +
"SUM(CASE WHEN SB.STATUS !='Y' And SB.Voucher_No Is Null And SB.Reas_Codes Is Null Then 1 else 0 end) as In_Process, " +
"SUM( case when (select count(1) FROM MISC_PAYDET WHERE TRAN_SER in ('VOUCH','P-IBCA','P-IBC1','P-IBC2','P-IBC3') AND VOUCH_NO = SB.VOUCHER_NO ) = 0 THEN 1 ELSE 0 END ) AS COMPLETE " +
"FROM SUPPLIER_BILL SB INNER JOIN SUPPLIER S ON S.SUPP_CODE = SB.SUPP_CODE " +
"WHERE TO_CHAR(SB.TRAN_DATE,'DD/MM/YY') >= '"+fromDate+"' " +
"AND TO_CHAR(SB.TRAN_DATE,'DD/MM/YY') <= '"+toDate+"' " +
"AND SB.SUPP_CODE IN (SELECT ENTITY_CODE FROM ENTITY_CONTACT WHERE ENTITY_TYPE = 'S' " +
"AND USER_ID__PORTAL = '"+loginCode+"') " +
"GROUP BY SB.SUPP_CODE,S.SUPP_NAME ORDER BY S.SUPP_NAME ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
rowData = new JSONObject();
rowData.put("supplier_code", checkNull (rs.getString("SUPP_CODE")));
rowData.put("supplier_name", checkNull (rs.getString("SUPP_NAME")));
rowData.put("hard_copy_not_recd", checkNull (rs.getString("HARD_COPY_NOT_RECD")));
rowData.put("in_process", checkNull (rs.getString("In_Process")));
rowData.put("complete", checkNull (rs.getString("COMPLETE")));
rawDataPendingInvoice.add(rowData);
count++;
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :PayableDashboardDAO for getAngPendingInvoice Method :" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataPendingInvoice;
}
//POOrderSummary Method
@SuppressWarnings("unchecked")
public JSONArray getAngPendingPOSummary(String loginCode, String dataSourceName) throws RemoteException, ITMException
{
System.out.println("getAngPendingPOSummary ");
JSONArray rawDataPaymentDet = new JSONArray();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
//String processOrder="",completed="",open="";
try
{
gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat());
System.out.println("gridDateFormat is" +gridDateFormat);
convrtToTimStmDate = new SimpleDateFormat(genericUtility.getDBDateFormat());
System.out.println("convrtToTimStmDate is" +convrtToTimStmDate);
if(loginCode!=null && loginCode.trim().length()>0)
{
System.out.println(" Inside PayableDashboardDAO for getAngPendingPOSummary Method Data Soruc Name ="+dataSourceName+" loginCode is =" + loginCode);
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
/*to get P Order summary data */
sql = " select sum(tot_amt) as process_orders,count(1) as no_of_po "
+" from porder where ORD_DATE >= (SELECT ADD_MONTHS(SYSDATE,-5) FROM DUAL ) "
+" and case when confirmed is null then 'N' else confirmed end = 'N' "
+" and case when status is null then 'O' else status end not in ('X','C') "
+" and supp_code in (select entity_code from entity_contact where entity_type = 'S' "
+" and User_id__portal = '"+loginCode+"') ";
System.out.println("getAngPendingPOSummary "+sql);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
rowData = new JSONObject();
rowData.put("status", "In Process ");
rowData.put("process_orders",checkDoubleNull(rs.getString("process_orders")));
rowData.put("no_of_po", rs.getString("no_of_po"));
rawDataPaymentDet.add(rowData);
count++;
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql = " select sum(tot_amt) as completed,count(1) as no_of_po "
+" from porder where ORD_DATE >= (SELECT ADD_MONTHS(SYSDATE,-5) FROM DUAL ) "
+" and case when confirmed is null then 'N' else confirmed end = 'Y' "
+" and case when status is null then 'O' else status end = 'C' "
+" and supp_code in (select entity_code from entity_contact where entity_type = 'S' "
+"and User_id__portal = '"+loginCode+"') ";
System.out.println("2nd getAngPendingPOSummary "+sql);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
rowData = new JSONObject();
rowData.put("status", "Completed");
rowData.put("process_orders", checkDoubleNull(rs.getString("completed")));
rowData.put("no_of_po", rs.getString("no_of_po"));
rawDataPaymentDet.add(rowData);
count++;
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql = " select sum(tot_amt) as open,count(1) as no_of_po "
+" from porder where ORD_DATE >= (SELECT ADD_MONTHS(SYSDATE,-5) FROM DUAL ) "
+" and case when confirmed is null then 'N' else confirmed end = 'Y' "
+" and case when status is null then 'O' else status end not in ('X','C') "
+" and supp_code in (select entity_code from entity_contact where entity_type = 'S'"
+" and User_id__portal = '"+loginCode+"' ) ";
System.out.println("3rd getAngPendingPOSummary "+sql);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
rowData = new JSONObject();
rowData.put("status", "Open");
rowData.put("process_orders",checkDoubleNull(rs.getString("open")));
rowData.put("no_of_po", rs.getString("no_of_po"));
rawDataPaymentDet.add(rowData);
count++;
System.out.println("Array Data "+rowData);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}//close if block
}//close try block
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :PayableDashboardDAO for getAngPendingPOSummary Method :" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataPaymentDet;
}
public JSONArray getAngPaymentEfficiency(String dataSourceName) throws RemoteException, ITMException
{
JSONArray rawDataAcctPayableDtlJson = new JSONArray();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
try
{
System.out.println(" Inside PayableDashboardDAO for getAngPaymentEfficiency Data Soruc Name ="+dataSourceName);
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
int count = 0;
int delayCount = 0;
double delayAmount = 0.0;
int paymentCount = 0;
double totalCount = 0.0;
double paymentAmount = 0.0;
double paidAmount = 0.0;
double delayTotalAmount = 0.0;
double delayDays = 0.0;
double delayIndex = 0.0;
double percntVal = 0.0;
double percntValForAmountPaid = 0.0;
double totalAmount = 0.0;
sql = "select count(1) delay_Invoice , round(sum(d.pay_amt)) delay_Inv_payment " +
"from misc_payment h, misc_paydet d, misc_payables m, period p where d.tran_id = h.tran_id " +
"and m.tran_ser = d.tran_ser and m.ref_no = d.vouch_no and to_date(h.conf_date) > m.due_date " +
"and to_date(h.conf_date) between p.fr_date and p.to_date " +
"and h.confirmed = 'Y'" +
"and to_date(sysdate) between p.fr_date and p.to_date" ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
delayCount = rs.getInt("delay_Invoice");
delayAmount = Double.parseDouble(checkZero(rs.getString("delay_Inv_payment")));
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="select count(1) as paymentcount, round(sum(d.pay_amt)) as paymentamt " +
"from misc_payment h, misc_paydet d, misc_payables m, " +
"period p where d.tran_id = h.tran_id and m.tran_ser = d.tran_ser " +
"and m.ref_no = d.vouch_no and to_date(h.conf_date) <= m.due_date " +
"and to_date(h.conf_date) between p.fr_date and p.to_date " +
"and h.confirmed = 'Y'" +
"and to_date(sysdate) between p.fr_date and p.to_date";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
paymentCount = rs.getInt("paymentcount");
paymentAmount = Double.parseDouble(checkZero(rs.getString("paymentamt")));
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="select sum(d.pay_amt) as paid_amount, sum(m.tot_amt) total_amount, " +
"sum(to_date(h.conf_date) - m.due_date) delayed_days from misc_payment h, " +
"misc_paydet d, misc_payables m, period p where d.tran_id = h.tran_id " +
"and m.tran_ser = d.tran_ser and m.ref_no = d.vouch_no " +
"and to_date(h.conf_date) <= m.due_date and " +
"to_date(h.conf_date) between p.fr_date and p.to_date and " +
"h.confirmed = 'Y'" +
"and to_date(sysdate) between p.fr_date and p.to_date";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
paidAmount = Double.parseDouble(checkZero(rs.getString("paid_amount")));
delayDays = Double.parseDouble(checkZero(rs.getString("delayed_days")));
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="select sum(d.pay_amt) delay_Total_Amount from misc_payment h, misc_paydet d, " +
"misc_payables m, period p where d.tran_id = h.tran_id and m.tran_ser = d.tran_ser " +
"and m.ref_no = d.vouch_no and " +
"to_date(h.conf_date) between p.fr_date and p.to_date and " +
"h.confirmed = 'Y' and to_date(sysdate) between p.fr_date and p.to_date";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
delayTotalAmount = Double.parseDouble(checkZero(rs.getString("delay_Total_Amount")));
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
System.out.println("paymentCount :"+paymentCount + "-- delayCount :"+delayCount);
totalCount = paymentCount + delayCount;
System.out.println("totalCount :"+totalCount);
if(totalCount != 0)
{
percntVal = (((double)paymentCount / totalCount) * 100) ;
}
totalAmount = paymentAmount + delayAmount;
System.out.println("totalAmount :"+totalAmount);
if(totalAmount != 0)
{
percntValForAmountPaid = ((paymentAmount / (paymentAmount+delayAmount)) * 100);
}
System.out.println("twoDecFormat.format percntValForAmountPaid :"+(percntValForAmountPaid));
rowData = new JSONObject();
rowData.put("descr", "No of voucher paid");
rowData.put("percentage", Math.round(percntVal));
rowData.put("spanvalue", Math.round(percntVal)+"%");
rowData.put("ontimeval", paymentCount);
rowData.put("delayval", delayCount );
rowData.put("totalval", (paymentCount + delayCount));
rowData.put("tbldisplay", "style='display: visible;'");
rowData.put("circledisplay", "c100");
rowData.put("data","style='display: none;'");
rawDataAcctPayableDtlJson.add(rowData);
count++;
rowData = new JSONObject();
rowData.put("descr", "Value of payment in (INR)");
rowData.put("percentage", Math.round(percntValForAmountPaid));
rowData.put("spanvalue", Math.round(percntValForAmountPaid)+"%");
rowData.put("ontimeval", paymentAmount);
rowData.put("delayval", delayAmount );
rowData.put("totalval", (paymentAmount+delayAmount));
rowData.put("tbldisplay", "style='display: visible;'");
rowData.put("circledisplay", "c100");
rowData.put("data","style='display: none;'");
rawDataAcctPayableDtlJson.add(rowData);
count++;
System.out.println("paidAmount :"+paidAmount + "-- delayDays :"+delayDays + "delayTotalAmount :"+delayTotalAmount);
if(delayDays <0)
{
delayIndex = (paidAmount * delayDays) *(-1) / delayTotalAmount;
}else
{
delayIndex = (paidAmount * delayDays) / delayTotalAmount;
}
rowData = new JSONObject();
rowData.put("descr", "Delay index");
rowData.put("percentage", "0");
rowData.put("spanvalue", Math.round(delayIndex));
rowData.put("ontimeval", "0");
rowData.put("delayval", "0");
rowData.put("totalval", "0");
rowData.put("tbldisplay", "style='display: none;'");
rowData.put("circledisplay", "circleNotDisplay");
rowData.put("data","style='display: visible;'");
rawDataAcctPayableDtlJson.add(rowData);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :getAngPaymentEfficiency:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataAcctPayableDtlJson;
}
public JSONArray getAngPayableProfit(String dataSourceName) throws RemoteException, ITMException
{
JSONArray rawDataPayableProfitJson = new JSONArray();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
try
{
System.out.println(" Inside AcctPayable for getAngPayableProfit Data Soruc Name ="+dataSourceName);
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
int count = 0;
sql = "select count(1) invoice_number, sum(m.tot_amt - m.adj_amt) invoice_val,'7 Days' as descr "+
" from misc_payables m where m.due_date > to_date(sysdate) and m.due_date - to_date(sysdate) <= 7 "+
" and m.tot_amt - m.adj_amt <> 0 "+
" union all "+
" select count(1) invoice_number, sum(m.tot_amt - m.adj_amt) invoice_val,'15 Days' as descr "+
" from misc_payables m where m.due_date > to_date(sysdate) and m.due_date - to_date(sysdate) <= 15 "+
" and m.tot_amt - m.adj_amt <> 0 "+
" union all "+
" select count(1) invoice_number, sum(m.tot_amt - m.adj_amt) invoice_val,'30 Days' as descr "+
" from misc_payables m where m.due_date > to_date(sysdate) and m.due_date - to_date(sysdate) <= 30 "+
" and m.tot_amt - m.adj_amt <> 0 "+
" union all "+
" select count(1) invoice_number, sum(m.tot_amt - m.adj_amt) invoice_val,'60 Days' as descr "+
" from misc_payables m where m.due_date > to_date(sysdate) and m.due_date - to_date(sysdate) <= 60 "+
" and m.tot_amt - m.adj_amt <> 0";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
boolean isInvoiceNumberAvailable=false;
while (rs.next())
{
String invoice_number=checkZero(rs.getString("invoice_number"));
rowData = new JSONObject();
rowData.put("invoice_number",invoice_number);
rowData.put("invoice_val", checkZero(rs.getString("invoice_val")));
rowData.put("descr", rs.getString("descr"));
rawDataPayableProfitJson.add(rowData);
count++;
if( !"0".equalsIgnoreCase(invoice_number))
{
isInvoiceNumberAvailable =true;
}
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
if( !isInvoiceNumberAvailable )
{
rawDataPayableProfitJson = new JSONArray();
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :getAngPayableProfit:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataPayableProfitJson;
}
public JSONArray getAngSavingOpportunity(String dataSourceName) throws RemoteException, ITMException
{
JSONArray rawDataSavingOpporntyJson = new JSONArray();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
try
{
System.out.println(" Inside PaybleDashboard for getAngSavingOpportunity Data Soruc Name ="+dataSourceName);
SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat());
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat());
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
int count = 0;
sql=" select v.bill_no, s.sh_name, v.net_amt, round(case when c.FCHG_TYPE ='F' " +
" then c.FIN_CHG else (v.net_amt * c.FIN_CHG / 100) end,0) as disc_amt , " +
" v.due_date from voucher v, supplier s, crtermfc c, misc_payables m " +
" where v.supp_code = s.supp_code and v.cr_term = c.cr_term and c.max_day < 0 " +
" and m.tran_ser = 'VOUCH' and m.ref_no = v.tran_id and m.adj_amt = 0 " +
" and m.due_date > to_date(sysdate)" +
" ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
rowData = new JSONObject();
rowData.put("bill_no", checkNull(rs.getString("bill_no")));
rowData.put("sh_name", checkNull(rs.getString("sh_name")));
rowData.put("net_amt", checkNull(rs.getString("net_amt")));
rowData.put("disc_amt", checkNull(rs.getString("disc_amt")));
rowData.put("due_date", gridDateFormat.format(convrtToTimStmDate.parse(rs.getString("due_date"))));
rawDataSavingOpporntyJson.add(rowData);
count++;
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :getAngSavingOpportunity:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataSavingOpporntyJson;
}
public JSONArray getAngEfficiencyTrend(String dataSourceName) throws RemoteException, ITMException
{
JSONArray rawDataEfficiencyTrendJson = new JSONArray();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
try
{
System.out.println(" Inside PayableDashboard for getAngEfficiencyTrend Data Soruc Name ="+dataSourceName);
SimpleDateFormat gridDateFormat = new SimpleDateFormat( "yyyy-MM-dd");
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat());
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
HashMap<String, ArrayList<String>> onTimeMap = new HashMap<String,ArrayList<String>>();
HashMap<String, String> delayTimeMap = new HashMap<String, String>();
ArrayList<String> valueList =null;
TreeMap<String, ArrayList<String>> finalHashMap = new TreeMap<String, ArrayList<String>>();
ArrayList<String> tempList = null;
TreeMap<String, String> onTimeDataMap = new TreeMap<String, String>();
TreeMap<String, String> delayTimeDataMap = new TreeMap<String, String>();
TreeMap<String, String> onTimeDataMapLine1 = new TreeMap<String, String>();
TreeMap<String, String> onTimeDataMapLine2 = new TreeMap<String, String>();
String conf_date = "";
int count = 0;
int sumOfOnTimeInv = 0;
sql=" select to_date(h.conf_date) as conf_date, sum(d.pay_amt) paid_amount, sum(m.tot_amt) total_amount, " +
" sum(to_date(h.conf_date) - m.due_date) delayed_days, count(1) no_inv " +
" from misc_payment h, misc_paydet d, misc_payables m, period p " +
" where d.tran_id = h.tran_id and m.tran_ser = d.tran_ser and m.ref_no = d.vouch_no and h.confirmed = 'Y'" +
" and to_date(h.conf_date) <= m.due_date and " +
"to_date(h.conf_date) between p.fr_date and p.to_date and" +
" to_date(sysdate) between p.fr_date and p.to_date " +
" group by to_date(h.conf_date) order by to_date(h.conf_date) ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
valueList = new ArrayList<String>();
sumOfOnTimeInv = sumOfOnTimeInv + rs.getInt("no_inv");
conf_date = gridDateFormat.format(convrtToTimStmDate.parse(rs.getString("conf_date")));
valueList.add(checkZero(rs.getString("no_inv")));
valueList.add(checkZero(rs.getString("paid_amount")));
valueList.add(checkZero(rs.getString("total_amount")));
onTimeMap.put(conf_date, valueList);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="select to_date(h.conf_date) as conf_date, sum(d.pay_amt) paid_amount, sum(m.tot_amt) total_amount, " +
" sum(to_date(h.conf_date) - m.due_date) delayed_days, count(1) no_inv " +
" from misc_payment h, misc_paydet d, misc_payables m, period p " +
" where d.tran_id = h.tran_id and m.tran_ser = d.tran_ser and m.ref_no = d.vouch_no and h.confirmed = 'Y'" +
" and to_date(h.conf_date) > m.due_date and" +
" to_date(h.conf_date) between p.fr_date and p.to_date and" +
" to_date(sysdate) between p.fr_date and p.to_date" +
" group by to_date(h.conf_date) order by to_date(h.conf_date)";
pstmt = null;
rs = null;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
conf_date = "";
while (rs.next())
{
conf_date = gridDateFormat.format(convrtToTimStmDate.parse(rs.getString("conf_date")));
delayTimeMap.put(conf_date, checkZero(rs.getString("no_inv")));
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
for (Map.Entry<String, String> entry : delayTimeMap.entrySet())
{
if(onTimeMap.containsKey(entry.getKey()))
{
valueList = new ArrayList<String>();
tempList = new ArrayList<String>();
tempList = onTimeMap.get(entry.getKey());
valueList.add(tempList.get(0));
valueList.add(""+delayTimeMap.get(entry.getKey()));
valueList.add(""+((Double.parseDouble(tempList.get(0)))/sumOfOnTimeInv) * 100);
valueList.add(""+((Double.parseDouble(tempList.get(1)))/(Double.parseDouble(tempList.get(2)))) * 100);
finalHashMap.put(entry.getKey(), valueList);
}else if(!onTimeMap.containsKey(entry.getKey()))
{
valueList = new ArrayList<String>();
valueList.add("0");
valueList.add(""+delayTimeMap.get(entry.getKey()));
valueList.add("0");
valueList.add("0");
finalHashMap.put(entry.getKey(), valueList);
}
}
for (Map.Entry<String, ArrayList<String>> entry : onTimeMap.entrySet())
{
if(!finalHashMap.containsKey(entry.getKey()))
{
valueList = new ArrayList<String>();
tempList = new ArrayList<String>();
tempList = onTimeMap.get(entry.getKey());
valueList.add(tempList.get(0));
valueList.add("0");
valueList.add(""+((Double.parseDouble(tempList.get(0)))/sumOfOnTimeInv) * 100);
valueList.add(""+((Double.parseDouble(tempList.get(1)))/(Double.parseDouble(tempList.get(2)))) * 100);
finalHashMap.put(entry.getKey(), valueList);
}
}
System.out.println("finalHashMap :"+finalHashMap);
ArrayList<String> tempData = null;
for (Map.Entry<String, ArrayList<String>> entry : finalHashMap.entrySet())
{
tempData = new ArrayList<String>();
tempData = entry.getValue();
onTimeDataMap.put(entry.getKey(), tempData.get(0));
delayTimeDataMap.put(entry.getKey(), tempData.get(1));
onTimeDataMapLine1.put(entry.getKey(), tempData.get(2));
onTimeDataMapLine2.put(entry.getKey(), tempData.get(3));
rowData = new JSONObject();
rowData.put("conf_date", entry.getKey());
rowData.put("inv_paid_ontime", tempData.get(0));
rowData.put("inv_paid_delay", tempData.get(1));
rowData.put("inv_paid_perc", tempData.get(2));
rowData.put("amt_paid_perc", tempData.get(3));
rawDataEfficiencyTrendJson.add(rowData);
count++;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :getEfficiencyTrend:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataEfficiencyTrendJson;
}
//check null functionality for required component
private double checkDoubleNull(String str)
{
if(str == null || str.trim().length() == 0 || str.trim().equalsIgnoreCase("null"))
{
return 0.0;
}
else
{
return Math.round(Double.parseDouble(str)* Math.pow(10, 2)) / Math.pow(10, 2);
}
}
private String checkNull(String str)
{
if(str == null || str.trim().equalsIgnoreCase("null"))
{
return "";
}
else
{
return str.trim();
}
}
private String checkZero(String str)
{
if (str == null)
{
return "0";
} else
{
return str;
}
}
private String getSiteCode(String sessionUserLevel, String sessionSiteCode)
{
String appendSiteCode = "";
//sessionUserLevel="2";
if(Integer.parseInt(sessionUserLevel)>0)
{
appendSiteCode = " and o.site_code ='"+sessionSiteCode+"' ";
}
System.out.println("In getSiteCode appendSiteCode: " + appendSiteCode);
return appendSiteCode;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment