Commit b6e48d19 authored by dkasliwal's avatar dkasliwal

mfg dashboard code commit


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@96912 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 6e829e88
package ibase.dashboard.mfg.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.Date;
import java.util.List;
import java.util.StringTokenizer;
import javax.ejb.Stateless;
import org.json.simple.JSONObject;
/**
* Session Bean implementation class ProfitLossBalSheet
*/
@Stateless
public class ProfitLossBalSheet extends ValidatorEJB implements ProfitLossBalSheetLocal, ProfitLossBalSheetRemote {
/**
* Default constructor.
*/
JSONObject rawDataJson = new JSONObject();
String codes[]=new String[20];
String signs[] =new String[20];
public ProfitLossBalSheet()
{
}
GenericUtility genericUtility = GenericUtility.getInstance();
@SuppressWarnings("unchecked")
public JSONObject generateReport(String siteCode,String prdFrom,String prdTo,String acctPrd, String formatCode,String reportType,String dataSourceName) throws RemoteException, ITMException
{
ResultSet rs=null;
ResultSet rs1 = null;
PreparedStatement pstmt=null;
PreparedStatement pstmt1 = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
String prevPrd="";
String prevPrdCodeFrom="";
String prevPrdCodeTo = "";
String sql="";
String sql1="";
JSONObject rowData = null;
String titleCode="";
String titleDescr="";
String siteDescr="";
String balType="";
String factor="";
String codeString="";
double curGroupTotal,preGroupTotal,printLevel ;
int llCount=0;
Date date = null;
int month=0;
try
{
prevPrd= String.valueOf(Integer.parseInt(acctPrd.substring(0, 4))-1)+"-"+acctPrd.substring(2, 4);
prevPrdCodeFrom= String.valueOf(Integer.parseInt(prdFrom.substring(0, 4))-1)+prdFrom.substring(4, 6);
prevPrdCodeTo=String.valueOf(Integer.parseInt(prdTo.substring(0, 4))-1)+prdTo.substring(4, 6);
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
sql="select descr from SITE where site_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
rs = pstmt.executeQuery();
while (rs.next())
{
siteDescr= rs.getString("descr");
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql =" select PL_FORMAT.TITLE_CODE, PL_FORMAT.DESCR, PL_FORMAT.SCHEDULE_NO, PL_FORMAT.SCHEDULE_NO_NEXT, "
+" PL_FORMAT.TITLE_CODE__PARENT,pl_format.cmp_grp, pl_format.cmp_sgrp,pl_format.cmp_acct, "
+" pl_format.disp_tot,pl_format.disp_type,pl_format.print_level,pl_format.underline, "
+" pl_format.bal_type FROM pl_format where (( PL_FORMAT.TITLE_CODE__PARENT is null ) "
+" or ( PL_FORMAT.FORMAT_CODE = '" + formatCode + "')) and ( pl_format.report_type = '"
+ reportType + "') ORDER BY pl_format.print_level ASC ";
pstmt = conn.prepareStatement(sql);
//pstmt.setString(1, frDate);
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
titleCode=rs.getString("TITLE_CODE");
titleDescr=rs.getString("DESCR");
balType=rs.getString("bal_type");
rowData = new JSONObject();
//rowData.put("as_conversion",factor ); //lc_factor
//rowData.put("site_code",siteCode );
//rowData.put("site_descr",siteDescr );
rowData.put("title_descr",titleDescr );
//rowData.put("schedule_no",rs.getString("SCHEDULE_NO") );
//rowData.put("disp_Type", rs.getString("disp_Type"));
//rowData.put("Print_Level",0 );
//rowData.put("disp_tot", rs.getString("disp_tot"));
//rowData.put("underline",rs.getString("underline") );
//rowData.put("prd_code__from",prdFrom );
//rowData.put("prd_code__to",prdTo );
curGroupTotal = 0.0;
preGroupTotal = 0.0;
printLevel = 0.0;
sql1="SELECT count(*) as total "
+" FROM pl_format "
+" where PL_FORMAT.TITLE_CODE__PARENT = ? "
+" and pl_format.format_code=?";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, titleCode);
pstmt1.setString(2, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
llCount = (rs1.getInt("total"));
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
if(llCount >0)
{
if(populateSubGroup(siteCode,siteDescr,titleCode,curGroupTotal,preGroupTotal, printLevel,acctPrd,prdFrom,prdTo,prevPrd,
prevPrdCodeFrom,prevPrdCodeTo,formatCode,reportType,factor,rawDataJson,dataSourceName))
{
}
}
else
{
/*******************start of group formula******************/
codeString = (rs.getString("cmp_grp"));
codeString="A+B-C+";
if(codeString.trim()!=null && codeString.trim().length() > 0)
{
String tempCode="";
double ldAmount=0.0;
getformula_arys(codeString);
System.out.println("codes:"+codes+"///////signs:"+signs);
for(int llCtr=1;llCtr<=codes.length;llCtr++)
{
tempCode = codes[llCtr-1];
// start of current year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) "
// +" and ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" and ( (acctbal.prd_code between '000000' and '"+prdTo+"' ) ) " ;
//+" AND ( acctsgrp.group_code = '"+tempCode+"' ) )";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prdFrom+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code between '"+prdFrom+"' and '"+prdTo+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//pstmt1.setString(1, titleCode);
//pstmt1.setString(2, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount = checkDoubleNull(rs1.getString("total")); //su)m
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
curGroupTotal = -1 * ldAmount;
}
else
{
curGroupTotal = ldAmount;
}
}
else
{
System.out.println("signs:"+signs.length);
if(signs[llCtr - 1] =="+")
{
curGroupTotal += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
curGroupTotal -= ldAmount;
}
}
System.out.println("curGroupTotal:"+curGroupTotal);
//end of current year
//Start of Previous year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) "
// +"and ( acctbal.acct_prd = '"+ prevPrd +"' ) and "
+" and ( (acctbal.prd_code between '000000' and '"+prevPrdCodeTo+"' )) " ;
// +" AND ( acctsgrp.group_code = '"+tempCode+"' ) )";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrd +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prevPrdCodeFrom+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrd +"' ) and "
+" ( (acctbal.prd_code between '"+prevPrdCodeFrom+"' and '"+prevPrdCodeTo+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//pstmt1.setString(1, titleCode);
//pstmt1.setString(2, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount = (rs1.getInt("total")); //sum
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
preGroupTotal = -1 * ldAmount;
}
else
{
preGroupTotal = ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
preGroupTotal += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
preGroupTotal -= ldAmount;
}
}
System.out.println("preGroupTotal:"+preGroupTotal);
// end of previous year
} // end of for of codes.length //end of group formula
}
System.out.println("end of group formula");
/***********end if of group formula**************/
/***********Start of sub group formula********************/
codeString = (rs.getString("cmp_sgrp"));
codeString="A-B+C+";
if(codeString.trim()!=null && codeString.trim().length() > 0)
{
String tempCode="";
double ldAmount=0.0;
getformula_arys(codeString) ;
for(int llCtr=1;llCtr<=codes.length;llCtr++)
{
tempCode = codes[llCtr-1];
// start of current year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp WHERE site_code IN ('"+siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) "
//+" ( acctbal.acct_prd = '"+acctPrd +"' ) and "
+"and ( (acctbal.prd_code between '000000' and '"+prdTo+"' )) ";
//+" AND ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prdFrom+"' ) AND "
+" ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal,accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code between '"+prdFrom+"' and '"+prdTo+"' ) AND "
+" ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//pstmt1.setString(1, titleCode);
//pstmt1.setString(1, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount = (rs1.getInt("total")); //sum
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
curGroupTotal -= ldAmount;
}
else
{
curGroupTotal += ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
curGroupTotal += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
curGroupTotal -= ldAmount;
}
}
System.out.println("curGroupTotal:"+curGroupTotal);
//end of current year
//start of previous year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
// +" ( acctbal.acct_prd = '"+ prevPrd +"' ) and "
+" ( (acctbal.prd_code between '000000' and '"+prevPrdCodeTo+"' )) " ;
// +"AND ( acctsgrp.group_code = '"+tempCode+"' ) )";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrd +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prevPrdCodeFrom+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrd +"' ) and "
+" ( (acctbal.prd_code between '"+prevPrdCodeFrom+"' and '"+prevPrdCodeTo+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//pstmt1.setString(1, titleCode);
//pstmt1.setString(1, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount = (rs1.getInt("total")); //sum
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
preGroupTotal -= ldAmount;
}
else
{
preGroupTotal += ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
preGroupTotal += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
preGroupTotal -= ldAmount;
}
}
System.out.println("preGroupTotal:"+preGroupTotal);
//end of previous year
}
}
System.out.println("end of sub group formula");
/***********End of sub group formula********************/
/***********Start of a/c group formula********************/
codeString = (rs.getString("cmp_acct"));
codeString="A+B-C-";
if(codeString.trim()!=null && codeString.trim().length() > 0)
{
String tempCode="";
double ldAmount=0.0;
getformula_arys(codeString) ;
for(int llCtr=1;llCtr<=codes.length;llCtr++)
{
tempCode = codes[llCtr-1];
// start of current year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp WHERE site_code IN ('"+siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
// +" ( acctbal.acct_prd = '"+acctPrd +"' ) and "
+" ( (acctbal.prd_code between '000000' and '"+prdTo+"' ) ) ";
//+" AND ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prdFrom+"' ) AND "
+" ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal,accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code between '"+prdFrom+"' and '"+prdTo+"' ) AND "
+" ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//pstmt1.setString(1, titleCode);
//pstmt1.setString(1, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount =( rs1.getInt("total")); //sum
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
curGroupTotal -= ldAmount;
}
else
{
curGroupTotal += ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
curGroupTotal += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
curGroupTotal -= ldAmount;
}
}
System.out.println("curGroupTotal:"+curGroupTotal);
//end of current year
//start of previous year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) "
// +"and ( acctbal.acct_prd = '"+ prevPrd +"' ) "
+" and ( (acctbal.prd_code between '000000' and '"+prevPrdCodeTo+"' ) ) " ;
// +"AND ( acctsgrp.group_code = '"+tempCode+"' ) )";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrd +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prevPrdCodeFrom+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrd +"' ) and "
+" ( (acctbal.prd_code between '"+prevPrdCodeFrom+"' and '"+prevPrdCodeTo+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//.setString(1, titleCode);
//pstmt1.setString(1, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount =( rs1.getInt("total")); //sum
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
preGroupTotal -= ldAmount;
}
else
{
preGroupTotal += ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
preGroupTotal += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
preGroupTotal -= ldAmount;
}
}
System.out.println("preGroupTotal:"+preGroupTotal);
//end of previous year
}
}
System.out.println("end of a/c group formula");
/***********End of a/c group formula********************/
rowData.put("curr_out_val", curGroupTotal);
rowData.put("prev_out_val", preGroupTotal);
rowData.put("curr_in_val", 0);
rowData.put("prev_in_val", 0);
rawDataJson.put(count, rowData);
count++;
} // end of else of llCount >0
}// end of while
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//for current year
String date1 =(Integer.parseInt(prdTo.substring(0, 4))+"-"+Integer.parseInt(prdTo.substring(4, 6))+"-"+ 28);
date =sdf.parse(date1);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
month=cal.get(Calendar.MONTH);
do
{
cal.add(Calendar.DAY_OF_MONTH,1);
date1=sdf.format(cal.getTime());
date =sdf.parse(date1);
}while(month!=cal.get(Calendar.MONTH));
cal.add(Calendar.DAY_OF_MONTH,-1);
date1=sdf.format(cal.getTime());
date =sdf.parse(date1);
//for previous year
date1 =(Integer.parseInt(prevPrdCodeTo.substring(0, 4))+"-"+Integer.parseInt(prevPrdCodeTo.substring(4, 6))+"-"+ 28);
date =sdf.parse(date1);
cal = Calendar.getInstance();
cal.setTime(date);
month=cal.get(Calendar.MONTH);
do
{
cal.add(Calendar.DAY_OF_MONTH,1);
date1=sdf.format(cal.getTime());
date =sdf.parse(date1);
}while(month!=cal.get(Calendar.MONTH));
cal.add(Calendar.DAY_OF_MONTH,-1);
date1=sdf.format(cal.getTime());
date =sdf.parse(date1);
}
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 :RecallDetails:getProductWiseRecallDetails:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataJson;
}
@SuppressWarnings("unchecked")
public boolean populateSubGroup(String siteCode,String siteDescr,String titleCode,double curGroupTotal,double preGroupTotal,
double printLevel,String acctPrd,String prdFrom,String prdTo,String prevPrd,String prevPrdCodeFrom,String prevPrdCodeTo,String formatCode,
String reportType,String factor,JSONObject rawDataJson,String dataSourceName) throws RemoteException, ITMException
{
/////JSONObject rawDataJsonSGrp = new JSONObject();
ResultSet rs=null;
ResultSet rs1 = null;
PreparedStatement pstmt = null;
PreparedStatement pstmt1 = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
String prevPrdSGrp="";
String prevPrdCodeFromSGrp="";
String prevPrdCodeToSGrp = "";
String sql="";
String sql1="";
JSONObject rowData = null;
String titleCodeSGrp="";
String titleDescr="";
String siteDescrSGrp="";
String balType="";
String factorSGrp="";
String codeString="";
String codes[]=new String[20];
String signs[] =new String[20];
int totalCurr[]=new int[10];
int totalPrev[]=new int[10];
double curGroupTotalSGrp=0.0;
double preGroupTotalSGrp=0.0;
double printLevelSGrp=0.0 ;
int llCount=0;
String parentcode="B1010";
try
{
prevPrdSGrp= String.valueOf(Integer.parseInt(acctPrd.substring(0, 4))-1)+"-"+acctPrd.substring(2, 4);
prevPrdCodeFromSGrp= String.valueOf(Integer.parseInt(prdFrom.substring(0, 4))-1)+prdFrom.substring(4, 6);
prevPrdCodeToSGrp=String.valueOf(Integer.parseInt(prdTo.substring(0, 4))-1)+prdTo.substring(4, 6);
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
for(int i=0;i<10;i++)
{
totalCurr[i]=0;
totalPrev[i]=0;
}
sql="select descr from SITE where site_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
rs = pstmt.executeQuery();
while (rs.next())
{
siteDescrSGrp= rs.getString("descr");
}
rs=null;
//rs.close();
pstmt=null;
//pstmt.close();
sql =" select PL_FORMAT.TITLE_CODE, PL_FORMAT.DESCR, PL_FORMAT.SCHEDULE_NO, PL_FORMAT.SCHEDULE_NO_NEXT, "
+" PL_FORMAT.TITLE_CODE__PARENT,pl_format.cmp_grp, pl_format.cmp_sgrp,pl_format.cmp_acct, "
+" pl_format.disp_tot,pl_format.disp_type,pl_format.print_level,pl_format.underline, "
+" pl_format.bal_type FROM pl_format where (( PL_FORMAT.TITLE_CODE__PARENT = '"+parentcode+"' ) "
+" or ( PL_FORMAT.FORMAT_CODE = '" + formatCode + "')) and ( pl_format.report_type = '"
+ reportType + "') ORDER BY pl_format.print_level ASC ";
pstmt = conn.prepareStatement(sql);
//pstmt.setString(1, frDate);
rs = pstmt.executeQuery();
int count = 0;
int printlevel=0;
while (rs.next())
{
printlevel++;
titleCodeSGrp=rs.getString("TITLE_CODE");
titleDescr=rs.getString("DESCR");
balType=rs.getString("bal_type");
rowData = new JSONObject();
// rowData.put("as_conversion",factorSGrp ); //lc_factor
//rowData.put("site_code",siteCode );
//rowData.put("site_descr",siteDescrSGrp );
rowData.put("title_descr",titleDescr );
//rowData.put("schedule_no",rs.getString("SCHEDULE_NO") );
//rowData.put("disp_Type", rs.getString("disp_Type"));
//rowData.put("Print_Level",printlevel );
//rowData.put("disp_tot", rs.getString("disp_tot"));
//rowData.put("underline",rs.getString("underline") );
////rowData.put("prd_code__from",prdFrom );
//rowData.put("prd_code__to",prdTo );
curGroupTotalSGrp = 0.0;
preGroupTotalSGrp = 0.0;
sql1="SELECT count(*) as total "
+" FROM pl_format "
+" where PL_FORMAT.TITLE_CODE__PARENT = ? "
+" and pl_format.format_code=?";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, titleCodeSGrp);
pstmt1.setString(2, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
llCount = rs1.getInt("Total");
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
if(llCount >0)
{
if(populateSubGroup(siteCode,siteDescrSGrp,titleCodeSGrp,curGroupTotalSGrp,preGroupTotalSGrp,
printLevelSGrp,acctPrd,prdFrom,prdTo,prevPrdSGrp,prevPrdCodeFromSGrp,prevPrdCodeToSGrp,formatCode,
reportType,factorSGrp,rawDataJson,dataSourceName))
{
totalCurr[printlevel] = 0;
totalPrev[printlevel]= 0;
printlevel--;
}
}
else
{
/*******************start of group formula******************/
codeString = (rs.getString("cmp_grp"));
if(codeString.trim()!=null && codeString.trim().length() > 0)
{
String tempCode="";
double ldAmount=0.0;
getformula_arys(codeString) ;
for(int llCtr=1;llCtr<=codes.length;llCtr++)
{
tempCode = codes[llCtr-1];
// start of current year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code between '000000' and '"+prdTo+"' ) AND "
+" ( acctsgrp.group_code = '"+tempCode+"' ) )";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prdFrom+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code between '"+prdFrom+"' and '"+prdTo+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//pstmt1.setString(1, titleCodeSGrp);
//pstmt1.setString(1, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount = (rs1.getInt("total")); //su)m
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
curGroupTotalSGrp = -1 * ldAmount;
}
else
{
curGroupTotalSGrp = ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
curGroupTotalSGrp += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
curGroupTotalSGrp -= ldAmount;
}
}
//end of current year
//Start of Previous year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrdSGrp +"' ) and "
+" ( (acctbal.prd_code between '000000' and '"+prevPrdCodeToSGrp+"' ) AND "
+" ( acctsgrp.group_code = '"+tempCode+"' ) )";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrdSGrp +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prevPrdCodeFromSGrp+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrdSGrp +"' ) and "
+" ( (acctbal.prd_code between '"+prevPrdCodeFromSGrp+"' and '"+prevPrdCodeToSGrp+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//pstmt1.setString(1, titleCodeSGrp);
//pstmt1.setString(1, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount = (rs1.getInt("total")); //sum
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
preGroupTotalSGrp = -1 * ldAmount;
}
else
{
preGroupTotalSGrp = ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
preGroupTotalSGrp += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
preGroupTotalSGrp -= ldAmount;
}
}
// end of previous year
} // end of for of codes.length //end of group formula
}
/***********end if of group formula**************/
/***********Start of sub group formula********************/
codeString = (rs.getString("cmp_sgrp"));
if(codeString.trim()!=null && codeString.trim().length() > 0)
{
String tempCode="";
double ldAmount=0.0;
getformula_arys(codeString) ;
for(int llCtr=1;llCtr<=codes.length;llCtr++)
{
tempCode = codes[llCtr-1];
// start of current year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp WHERE site_code IN ('"+siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+acctPrd +"' ) and "
+" ( (acctbal.prd_code between '000000' and '"+prdTo+"' ) AND "
+" ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prdFrom+"' ) AND "
+" ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal,accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code between '"+prdFrom+"' and '"+prdTo+"' ) AND "
+" ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//pstmt1.setString(1, titleCodeSGrp);
//pstmt1.setString(1, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount = checkDoubleNull(rs1.getString("total")); //sum
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
curGroupTotalSGrp -= ldAmount;
}
else
{
curGroupTotalSGrp += ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
curGroupTotalSGrp += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
curGroupTotalSGrp -= ldAmount;
}
}
//end of current year
//start of previous year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrdSGrp +"' ) and "
+" ( (acctbal.prd_code between '000000' and '"+prevPrdCodeToSGrp+"' ) AND "
+" ( acctsgrp.group_code = '"+tempCode+"' ) )";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrdSGrp +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prevPrdCodeFromSGrp+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrdSGrp +"' ) and "
+" ( (acctbal.prd_code between '"+prevPrdCodeFromSGrp+"' and '"+prevPrdCodeToSGrp+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
// pstmt1.setString(1, titleCodeSGrp);
// pstmt1.setString(1, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount = (rs1.getInt("total")); //sum
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
preGroupTotalSGrp -= ldAmount;
}
else
{
preGroupTotalSGrp += ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
preGroupTotalSGrp += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
preGroupTotalSGrp -= ldAmount;
}
}
//end of previous year
}
}
/***********End of sub group formula********************/
/***********Start of a/c group formula********************/
codeString = (rs.getString("cmp_acct"));
if(codeString.trim()!=null && codeString.trim().length() > 0)
{
String tempCode="";
double ldAmount=0.0;
getformula_arys(codeString) ;
for(int llCtr=1;llCtr<=codes.length;llCtr++)
{
tempCode = codes[llCtr-1];
// start of current year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp WHERE site_code IN ('"+siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) "
//+" and ( acctbal.acct_prd = '"+acctPrd +"' ) "
+" and ( (acctbal.prd_code between '000000' and '"+prdTo+"' ) ";
//+" AND ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prdFrom+"' ) AND "
+" ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal,accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ acctPrd +"' ) and "
+" ( (acctbal.prd_code between '"+prdFrom+"' and '"+prdTo+"' ) AND "
+" ( acctsgrp.sgroup_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//pstmt1.setString(1, titleCodeSGrp);
//pstmt1.setString(1, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount = (rs1.getInt("total")); //sum
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
curGroupTotalSGrp -= ldAmount;
}
else
{
curGroupTotalSGrp += ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
curGroupTotalSGrp += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
curGroupTotalSGrp -= ldAmount;
}
}
System.out.println("curGroupTotalSGrp:"+curGroupTotalSGrp);
//end of current year
//start of previous year
if(balType.trim().equals("C"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrdSGrp +"' ) and "
+" ( (acctbal.prd_code between '000000' and '"+prevPrdCodeToSGrp+"' ) AND "
+" ( acctsgrp.group_code = '"+tempCode+"' ) )";
}
else if(balType.trim().equals("O"))
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts, acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrdSGrp +"' ) and "
+" ( (acctbal.prd_code >= '000000' and acctbal.prd_code < '"+prevPrdCodeFromSGrp+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
else
{
sql="SELECT sum(case when accounts.typ_bal = 'D' then acctbal.dr_amt__base - acctbal.cr_amt__base else acctbal.cr_amt__base - acctbal.dr_amt__base end) as total "
+" FROM acctbal, accounts,acctsgrp "
+" WHERE site_code IN ('"+ siteCode + "') AND "
+" ( acctbal.acct_code = accounts.acct_code ) and "
+" ( acctsgrp.sgroup_code = accounts.sgroup_code ) and "
+" ( acctbal.acct_prd = '"+ prevPrdSGrp +"' ) and "
+" ( (acctbal.prd_code between '"+prevPrdCodeFromSGrp+"' and '"+prevPrdCodeToSGrp+"' ) "
+" AND ( acctsgrp.group_code = '"+tempCode+"' ))";
}
pstmt1 = conn.prepareStatement(sql);
//pstmt1.setString(1, titleCodeSGrp);
//pstmt1.setString(1, formatCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
ldAmount =( rs1.getInt("total")); //sum
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
if(llCtr==1)
{
if(codeString.substring(0, 1) == "-")
{
preGroupTotalSGrp -= ldAmount;
}
else
{
preGroupTotalSGrp += ldAmount;
}
}
else
{
if(signs[llCtr - 1] =="+")
{
preGroupTotalSGrp += ldAmount;
}
else if(signs[llCtr - 1] == "-")
{
preGroupTotalSGrp -= ldAmount;
}
}
System.out.println("preGroupTotalSGrp:"+preGroupTotalSGrp);
//end of previous year
}
}
/***********End of a/c group formula********************/
rowData.put("curr_in_val", curGroupTotalSGrp);
rowData.put("prev_in_val", preGroupTotalSGrp);
totalCurr[printlevel] += curGroupTotalSGrp;
totalPrev[printlevel] += preGroupTotalSGrp;
rowData.put("curr_out_val", totalCurr[printlevel]);
rowData.put("prev_out_val", totalPrev[printlevel]);
rawDataJson.put(count, rowData);
count++;
} // end of else of llCount >0
}// end of while
}
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 :RecallDetails:getProductWiseRecallDetails:" + d.getMessage());
throw new ITMException(d);
}
}
return true;
}
@SuppressWarnings("unchecked")
public JSONObject getProfitBalanceSheetDetails(String sitecode, String prdfrom,String prdto,String acctprd,String formatcode,String reporttype,String dataSourceName) throws RemoteException, ITMException
{
JSONObject rawDataMnthDivWiseSalesJson = new JSONObject();
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
String frDate="",toDate="";
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
rawDataMnthDivWiseSalesJson=generateReport(sitecode,prdfrom,prdto,acctprd,formatcode,reporttype,dataSourceName);
System.out.println("getProductWiseRecallDetails data :"+rawDataMnthDivWiseSalesJson);
}
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 :RecallDetails:getProductWiseRecallDetails:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataMnthDivWiseSalesJson;
}
private int checkIntNull(String str)
{
if(str == null || str.trim().length() == 0 )
{
return 0;
}
else
{
return Integer.parseInt(str) ;
}
}
private double checkDoubleNull(String str)
{
if(str == null || str.trim().length() == 0)
{
return 0.0;
}
else
{
return Math.round(Double.parseDouble(str)* Math.pow(10, 2)) / Math.pow(10, 2);
}
}
private void getformula_arys(String codeString)
{
List<String> operatorList = new ArrayList<String>();
List<String> operandList = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(codeString, "+-*/", true);
while (st.hasMoreTokens()) {
String token = st.nextToken();
if ("+-/*".contains(token)) {
operatorList.add(token);
} else {
operandList.add(token);
}
}
codes= operandList.toArray(new String[operandList.size()]);
signs= operatorList.toArray(new String[operatorList.size()]);
// codes= (String[]) operandList.toArray();
// signs = (String[]) operatorList.toArray();
}
}
package ibase.dashboard.mfg.ejb;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.json.simple.JSONObject;
@Local
public interface ProfitLossBalSheetLocal extends ValidatorLocal {
public JSONObject getProfitBalanceSheetDetails(String sitecode, String prdfrom,String prdto,String acctprd,String formatcode,String reporttype,String dataSourceName) throws RemoteException, ITMException;
public JSONObject generateReport(String siteCode,String acctPrd,String prdFrom,String prdTo, String formatCode,String reportType,String dataSourceName) throws RemoteException, ITMException;
public boolean populateSubGroup(String siteCode,String siteDescr,String titleCode,double curGroupTotal,double preGroupTotal,
double printLevel,String acctPrd,String prdFrom,String prdTo,String prevPrd,String prevPrdCodeFrom,String prevPrdCodeTo,String formatCode,
String reportType,String factor,JSONObject rawDataJson,String dataSourceName) throws RemoteException, ITMException;
}
package ibase.dashboard.mfg.ejb;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import org.json.simple.JSONObject;
@Remote
public interface ProfitLossBalSheetRemote extends ValidatorRemote{
public JSONObject getProfitBalanceSheetDetails(String sitecode, String prdfrom,String prdto,String acctprd,String formatcode,String reporttype,String dataSourceName) throws RemoteException, ITMException;
public JSONObject generateReport(String siteCode,String acctPrd,String prdFrom,String prdTo, String formatCode,String reportType,String dataSourceName) throws RemoteException, ITMException;
public boolean populateSubGroup(String siteCode,String siteDescr,String titleCode,double curGroupTotal,double preGroupTotal,
double printLevel,String acctPrd,String prdFrom,String prdTo,String prevPrd,String prevPrdCodeFrom,String prevPrdCodeTo,String formatCode,
String reportType,String factor,JSONObject rawDataJson,String dataSourceName) throws RemoteException, ITMException;
}
package ibase.dashboard.mfg.ejb;
import ibase.dashboard.Report.Utility.DashboardUtility;
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.Calendar;
import java.util.Date;
import javax.ejb.Stateless;
import org.json.simple.JSONObject;
/**
* Session Bean implementation class SalesPersonSales
*/
@Stateless
public class QCSampleCost extends ValidatorEJB implements QCSampleCostLocal, QCSampleCostRemote
{
/**
* Default constructor.
*/
public QCSampleCost()
{
}
@SuppressWarnings("unchecked")
public JSONObject getQCSampleCostData(String dataSourceName, String geoLocation, String lastMonth) throws RemoteException, ITMException
{
JSONObject qcSampleCostDataJson = new JSONObject();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
GenericUtility genericUtility = GenericUtility.getInstance();
Date frmDate = null;
Date toDate = null;
DashboardUtility dashbordUtil = null;
try
{
/*String[] geoLocArray = this.getSplitedStrng(geoLocation);
if (geoLocArray != null)
{
for (int i = 0; i < geoLocArray.length; i++)
{
if (i == geoLocArray.length - 1)
{
modifyGeoLoc = modifyGeoLoc + "'" + geoLocArray[i] + "'";
} else
{
modifyGeoLoc = modifyGeoLoc + "'" + geoLocArray[i] + "',";
}
}
} else
{
modifyGeoLoc="";
}*/
/*monthInInt=Integer.parseInt(lastMonth);
calendar = Calendar.getInstance();
simpleDateFormat = new SimpleDateFormat("dd-MMM-yy");
String toDate = simpleDateFormat.format(calendar.getTime());
//calendar.add(Calendar.MONTH,-monthInInt);
calendar.add(Calendar.MONTH,-6);
String fromDate = simpleDateFormat.format(calendar.getTime());*/
SimpleDateFormat convrtToTimStmDate = new SimpleDateFormat(genericUtility.getDBDateFormat());
dashbordUtil = new DashboardUtility();
geoLocation = dashbordUtil.getCommaSeparated(geoLocation);
if(lastMonth!=null && lastMonth.trim().length()>0 )
{
Calendar cal = Calendar.getInstance();
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
cal.get(Calendar.MONTH + 1);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
int month = cal.get(Calendar.MONTH);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE));
}
System.out.println("From date is =" + frmDate + "and to date is =" + toDate + "and geolocation is ="+geoLocation+" and lastmonth is ="+lastMonth);
if (frmDate != null && toDate != null)
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
sql = " select to_char(tran_date,'MON-YY') as qc_date , to_date('01-' || to_char(tran_date,'MON-YY')),sum(i.quantity * s.rate) as sample_cost" +
" from invtrace i, stock s, site o where o.site_code = i.site_code and s.item_code = i.item_code and s.site_code = i.site_code" +
" and s.loc_code = i.loc_code and s.lot_no = i.lot_no and s.lot_sl = i.lot_sl and i.ref_ser in ('S-ISS','W-QCS') And I.Eff_Qty < 0" + " " +
//" and o.geo_loc in ("+ modifyGeoLoc +")" +
" and tran_date between ? and ?" +
" group by to_char(tran_date,'MON-YY') " + " Order By To_Date('01-' || To_Char(Tran_Date,'MON-YY'))";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
rowData = new JSONObject();
rowData.put("qc_date", checkNull(rs.getString("qc_date")));
rowData.put("sample_cost", checkNull(rs.getString("sample_cost")));
qcSampleCostDataJson.put(count, rowData);
count++;
}
}
System.out.println("json object for QCSampleCost data====" + qcSampleCostDataJson.toString());
} 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 :QCSampleCost: getQCSampleCostData(String dataSourceName, String geoLocation) throws RemoteException, ITMException:" + d.getMessage());
throw new ITMException(d);
}
}
return qcSampleCostDataJson;
}
/*private String[] getSplitedStrng(String year)
{
String[] splitedArray = null;
if (year != null && year.length() > 0)
{
splitedArray = year.split(",");
}
return splitedArray;
}*/
private String checkNull(String str)
{
if (str == null)
{
return "";
} else
{
return str;
}
}
}
package ibase.dashboard.mfg.ejb;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
import org.json.simple.JSONObject;
@Local
public interface QCSampleCostLocal extends ValidatorLocal
{
public JSONObject getQCSampleCostData(String dataSourceName,String geoLocation,String month) throws RemoteException, ITMException;
}
package ibase.dashboard.mfg.ejb;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
import org.json.simple.JSONObject;
@Remote
public interface QCSampleCostRemote extends ValidatorRemote
{
public JSONObject getQCSampleCostData(String dataSourceName,String geoLocation,String month ) throws RemoteException, ITMException;
}
package ibase.dashboard.mfg.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.Calendar;
import java.util.Date;
import javax.ejb.Stateless;
import org.json.simple.JSONObject;
/**
* Session Bean implementation class RecallDetails
*/
@Stateless
public class RecallDetails extends ValidatorEJB implements RecallDetailsRemote, RecallDetailsLocal {
/**
* Default constructor.
*/
public RecallDetails() {
}
GenericUtility genericUtility = GenericUtility.getInstance();
@SuppressWarnings("unchecked")
public JSONObject getMarketWiseRecallDetails(String dataSourceName,String lastMonth) throws RemoteException, ITMException
{
JSONObject rawDataMarketWiseRecallJson = new JSONObject();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
Date frmDate = null;
Date toDate = null;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
SimpleDateFormat convrtToTimStmDate = new SimpleDateFormat(genericUtility.getDBDateFormat());
if(lastMonth!=null && lastMonth.trim().length()>0 )
{
Calendar cal = Calendar.getInstance();
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
cal.get(Calendar.MONTH + 1);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
int month = cal.get(Calendar.MONTH);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE));
}
if (frmDate != null && toDate != null )
{
sql =" select i.market_reg as MARKET_REG ,count(1) as MARKET_RECALL "
+" from item_lot_info l, item i "
+" where i.item_code = l.item_code "
//+" and case when l.STOP_BUSINESS is null then 'N' else l.STOP_BUSINESS end= 'Y' "
//+" and l.stop_business_date between ? and ? "
+" group by i.market_reg ";
pstmt = conn.prepareStatement(sql);
//pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
//pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
rowData = new JSONObject();
rowData.put("market_reg", checkNull(rs.getString("MARKET_REG")));
rowData.put("market_recall", rs.getString("MARKET_RECALL"));
rawDataMarketWiseRecallJson.put(count, rowData);
count++;
}
}
System.out.println("getMarketWiseRecallDetails data :"+rawDataMarketWiseRecallJson);
}
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 :RecallDetails :getPlantWiseRecallDetails:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataMarketWiseRecallJson;
}
@SuppressWarnings("unchecked")
public JSONObject getProductWiseRecallDetails(String dataSourceName,String lastMonth) throws RemoteException, ITMException
{
JSONObject rawDataProductWiseRecallJson = new JSONObject();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
Date frmDate = null;
Date toDate = null;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
SimpleDateFormat convrtToTimStmDate = new SimpleDateFormat(genericUtility.getDBDateFormat());
if(lastMonth!=null && lastMonth.trim().length()>0 )
{
Calendar cal = Calendar.getInstance();
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
cal.get(Calendar.MONTH + 1);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
int month = cal.get(Calendar.MONTH);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE));
}
if (frmDate != null && toDate != null )
{
sql =" select t.unit__form,count(1) as product_recall "
+" from item_lot_info l, item i, item_type t "
+" where i.item_code = l.item_code "
//+" and t.item_type = i.item_type "
// +" and case when l.STOP_BUSINESS is null then 'N' else l.STOP_BUSINESS end = 'Y' "
// +" and l.stop_business_date between ? and ? "
+" group by t.unit__form ";
pstmt = conn.prepareStatement(sql);
//pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
//pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
rowData = new JSONObject();
rowData.put("unit__form", checkNull(rs.getString("unit__form")));
rowData.put("product_recall", rs.getString("product_recall"));
rawDataProductWiseRecallJson.put(count, rowData);
count++;
}
}
System.out.println("getProductWiseRecallDetails data :"+rawDataProductWiseRecallJson);
}
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 :RecallDetails :getProductWiseRecallDetails:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataProductWiseRecallJson;
}
@SuppressWarnings("unchecked")
public JSONObject getPlantWiseRecallDetails(String dataSourceName,String lastMonth) throws RemoteException, ITMException
{
JSONObject rawDataPlantWiseRecallJson = new JSONObject();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
Date frmDate = null;
Date toDate = null;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
SimpleDateFormat convrtToTimStmDate = new SimpleDateFormat(genericUtility.getDBDateFormat());
if(lastMonth!=null && lastMonth.trim().length()>0 )
{
Calendar cal = Calendar.getInstance();
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
cal.get(Calendar.MONTH + 1);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
int month = cal.get(Calendar.MONTH);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE));
}
if (frmDate != null && toDate != null)
{
sql =" select s.geo_loc as geo_loc,g.descr as geodescr,count(1) as product_recall "
+" from item_lot_info l, site s,gencodes g "
+" where g.fld_value = s.geo_loc and g.fld_name = 'GEO_LOC' and g.mod_name = 'X' "
+" and s.geo_loc in(110,120,113,114,404,307,612,628) "
/*+" w.item_code = l.item_code "
+" and w.lot_no = l.lot_no "
+" and s.site_code = w.site_code "
+" and case when l.STOP_BUSINESS is null then 'N' else l.STOP_BUSINESS end= 'Y' "
+" and l.stop_business_date between ? and ? " //dwh_production w,
*/ +" group by s.geo_loc,g.descr ";
pstmt = conn.prepareStatement(sql);
//pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
//pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
rowData = new JSONObject();
rowData.put("geo_loc", checkNull(rs.getString("geodescr")));
rowData.put("product_recall", rs.getString("product_recall"));
rawDataPlantWiseRecallJson.put(count, rowData);
count++;
}
}
System.out.println("getPlantWiseRecallDetails data :"+rawDataPlantWiseRecallJson);
}
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 :RecallDetails :getPlantWiseRecallDetails:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataPlantWiseRecallJson;
}
private String checkNull(String str)
{
if(str == null)
{
return "";
}
else
{
return str ;
}
}
}
\ No newline at end of file
package ibase.dashboard.mfg.ejb;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.json.simple.JSONObject;
@Local
public interface RecallDetailsLocal extends ValidatorLocal {
public JSONObject getMarketWiseRecallDetails(String dataSourceName,String days) throws RemoteException, ITMException;
public JSONObject getProductWiseRecallDetails(String dataSourceName,String days) throws RemoteException, ITMException;
public JSONObject getPlantWiseRecallDetails(String dataSourceName,String days) throws RemoteException, ITMException;
}
package ibase.dashboard.mfg.ejb;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import org.json.simple.JSONObject;
@Remote
public interface RecallDetailsRemote extends ValidatorRemote{
public JSONObject getMarketWiseRecallDetails(String dataSourceName,String days) throws RemoteException, ITMException;
public JSONObject getProductWiseRecallDetails(String dataSourceName,String days) throws RemoteException, ITMException;
public JSONObject getPlantWiseRecallDetails(String dataSourceName,String days) throws RemoteException, ITMException;
}
package ibase.dashboard.mfg.ejb;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.sys.UtilMethods;
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.Calendar;
import java.util.Date;
import ibase.webitm.utility.GenericUtility;
import javax.ejb.Stateless;
import org.json.simple.JSONObject;
/**
* Session Bean implementation class SalesPersonSales
*/
@Stateless
public class SampleRCpDtl extends ValidatorEJB implements SampleRCpDtlRemote, SampleRCpDtlLocal
{
/**
* Default constructor.
*/
public SampleRCpDtl()
{
}
/***
* End of method getProfitGraphData()
*
* @author base
* @param metedata
* as xml file by client side
* @return JSONObject
* @throws RemoteException
* , ITMException @ *
***/
@SuppressWarnings("unchecked")
public JSONObject getSampleRCPDtlData(String dataSourceName, String lastMonth) throws RemoteException, ITMException
{
JSONObject smplRcpDateWiseJson = new JSONObject();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
SimpleDateFormat simpleDateFormat = null;
Calendar calendar = null;
UtilMethods utilMethods = new UtilMethods();
int daysInInt=0;
GenericUtility genericUtility = GenericUtility.getInstance();
Date frmDate = null;
Date toDate = null;
try
{
SimpleDateFormat convrtToTimStmDate = new SimpleDateFormat(genericUtility.getDBDateFormat());
SimpleDateFormat graphDateFormat = new SimpleDateFormat("dd-MMM-yy");
if(lastMonth!=null && lastMonth.trim().length()>0 )
{
Calendar cal = Calendar.getInstance();
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
cal.get(Calendar.MONTH + 1);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
int month = cal.get(Calendar.MONTH);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE));
}
System.out.println("From date is =" + frmDate + "and to date is =" + toDate+ "and to lastMonth is ="+lastMonth);
if (frmDate != null && toDate != null)
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
sql = "select facility_code, curr_date,sum(day_received) as day_received, sum(day_approved) day_approved, sum (day_pending) day_pending from ( select s.facility_code, q.QORDER_DATE as curr_date,count(1) as day_received," + "0 as day_pending, 0 as day_approved from qc_order q, site s Where S.Site_Code = Q.Site_Code " +
" and q.QORDER_DATE between ? and ?"+
" group by s.facility_code, q.QORDER_DATE union all select s.facility_code, " + "q.QORDER_DATE, 0 day_received, count(1) day_pending, 0 day_approved from qc_order q, site s where s.site_code = q.site_code and case when q.status is null then 'U' else q.status end = 'U' " +
" and q.QORDER_DATE between ? and ?"+
" group by s.facility_code, q.QORDER_DATE union all select s.facility_code, q.status_DATE,0 day_received, 0 day_pending, count(1) day_approved from qc_order q, " + "site s where s.site_code = q.site_code and case when q.status is null then 'U' else q.status end = 'A' " +
" and q.QORDER_DATE between ? and ?"+
" group by s.facility_code, q.status_DATE ) Group By Facility_Code, Curr_Date";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(3,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(4,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(5,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(6,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
rowData = new JSONObject();
;
rowData.put("curr_date", String.valueOf(graphDateFormat.format(rs.getDate("CURR_DATE"))).substring(0, 6));
rowData.put("day_received", checkNull(rs.getString("DAY_RECEIVED")));
rowData.put("day_approved", rs.getString("DAY_APPROVED"));
rowData.put("day_pending", rs.getString("DAY_PENDING"));
smplRcpDateWiseJson.put(count, rowData);
count++;
}
}
System.out.println("json object for sample rcp data====" + smplRcpDateWiseJson.toString());
} 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 :SampleRCpDtl: getSampleRCPDtlData(String dataSourceName, String days) :" + d.getMessage());
throw new ITMException(d);
}
}
return smplRcpDateWiseJson;
}
private String checkNull(String str)
{
if (str == null)
{
return "";
} else
{
return str;
}
}
}
package ibase.dashboard.mfg.ejb;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
import org.json.simple.JSONObject;
@Local
public interface SampleRCpDtlLocal extends ValidatorLocal
{
public JSONObject getSampleRCPDtlData(String dataSourceName,String days) throws RemoteException, ITMException;
}
package ibase.dashboard.mfg.ejb;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
import org.json.simple.JSONObject;
@Remote
public interface SampleRCpDtlRemote extends ValidatorRemote
{
public JSONObject getSampleRCPDtlData(String dataSourceName,String days) throws RemoteException, ITMException;
}
package ibase.dashboard.mfg.servlet;
import ibase.dashboard.mfg.ejb.RecallDetailsRemote;
import ibase.system.config.AppConnectParm;
import ibase.webitm.utility.ITMException;
import java.io.IOException;
import java.io.OutputStream;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
@SuppressWarnings("serial")
public class MarketWiseRecallServlet extends HttpServlet
{
//private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
doPost(request, response);
}
@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
RecallDetailsRemote recallDetailsRemote = null;
InitialContext context = null;
AppConnectParm appConnectParm = new AppConnectParm();
String dataSourceName = "";
String lastMonth = "";
try
{
response.setContentType("application/xml");
dataSourceName = request.getParameter("dataSourceName");
lastMonth = request.getParameter("lastMonth");
System.out.println("in doPost" + "lastMonth is =:" + lastMonth+":" );
context = new InitialContext(appConnectParm.getProperty());
recallDetailsRemote = (RecallDetailsRemote) context.lookup("ibase/RecallDetails/remote");
JSONObject jsonObjData = (JSONObject)recallDetailsRemote.getMarketWiseRecallDetails(dataSourceName,lastMonth);
OutputStream outputStream = response.getOutputStream();
outputStream.write(jsonObjData.toString().getBytes());
outputStream.flush();
outputStream.close();
System.out.println(" Final data set for MarketWiseRecallServlet build the Graph is===" + jsonObjData);
} catch (Exception e)
{
System.out.println("Exception : MarketWiseRecallServlet :doPost(HttpServletRequest request, HttpServletResponse response) :" + e);
try
{
throw new ITMException(e);
} catch (ITMException e1)
{
e1.printStackTrace();
}
}
}
}
\ No newline at end of file
package ibase.dashboard.mfg.servlet;
import ibase.dashboard.mfg.ejb.RecallDetailsRemote;
import ibase.system.config.AppConnectParm;
import ibase.webitm.utility.ITMException;
import java.io.IOException;
import java.io.OutputStream;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
@SuppressWarnings("serial")
public class PlantWiseRecallServlet extends HttpServlet
{
//private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
doPost(request, response);
}
@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
RecallDetailsRemote recallDetailsRemote = null;
InitialContext context = null;
AppConnectParm appConnectParm = new AppConnectParm();
String dataSourceName = "";
String lastMonth = "";
try
{
response.setContentType("application/xml");
dataSourceName = request.getParameter("dataSourceName");
lastMonth = request.getParameter("lastMonth");
System.out.println("in doPost lastMonth is ==:" + lastMonth );
context = new InitialContext(appConnectParm.getProperty());
recallDetailsRemote = (RecallDetailsRemote) context.lookup("ibase/RecallDetails/remote");
JSONObject jsonObjData = (JSONObject)recallDetailsRemote.getPlantWiseRecallDetails(dataSourceName,lastMonth);
OutputStream outputStream = response.getOutputStream();
outputStream.write(jsonObjData.toString().getBytes());
outputStream.flush();
outputStream.close();
System.out.println(" Final data set for PlantWiseRecallServlet build the Graph is===" + jsonObjData);
} catch (Exception e)
{
System.out.println("Exception : PlantWiseRecallServlet :doPost(HttpServletRequest request, HttpServletResponse response) :" + e);
try
{
throw new ITMException(e);
} catch (ITMException e1)
{
e1.printStackTrace();
}
}
}
}
\ No newline at end of file
package ibase.dashboard.mfg.servlet;
import ibase.dashboard.mfg.ejb.RecallDetailsRemote;
import ibase.system.config.AppConnectParm;
import ibase.webitm.utility.ITMException;
import java.io.IOException;
import java.io.OutputStream;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
@SuppressWarnings("serial")
public class ProductWiseRecallServlet extends HttpServlet
{
//private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
doPost(request, response);
}
@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
RecallDetailsRemote recallDetailsRemote = null;
InitialContext context = null;
AppConnectParm appConnectParm = new AppConnectParm();
String dataSourceName = "";
String lastMonth = "";
try
{
response.setContentType("application/xml");
dataSourceName = request.getParameter("dataSourceName");
lastMonth = (request.getParameter("lastMonth"));
System.out.println("in doPost" + "lastMonth is ==:" + lastMonth+":" );
context = new InitialContext(appConnectParm.getProperty());
recallDetailsRemote = (RecallDetailsRemote) context.lookup("ibase/RecallDetails/remote");
JSONObject jsonObjData = (JSONObject)recallDetailsRemote.getProductWiseRecallDetails(dataSourceName,lastMonth);
OutputStream outputStream = response.getOutputStream();
outputStream.write(jsonObjData.toString().getBytes());
outputStream.flush();
outputStream.close();
System.out.println(" Final data set for ProductWiseRecallServlet build the Graph is===" + jsonObjData);
} catch (Exception e)
{
System.out.println("Exception : ProductWiseRecallServlet :doPost(HttpServletRequest request, HttpServletResponse response) :" + e);
try
{
throw new ITMException(e);
} catch (ITMException e1)
{
e1.printStackTrace();
}
}
}
}
\ No newline at end of file
package ibase.dashboard.mfg.servlet;
import ibase.dashboard.mfg.ejb.ProfitLossBalSheetRemote;
import ibase.system.config.AppConnectParm;
import ibase.webitm.utility.ITMException;
import java.io.IOException;
import java.io.OutputStream;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
@SuppressWarnings("serial")
public class ProfitLossBalSheetServlet extends HttpServlet
{
//private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
doPost(request, response);
}
@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
ProfitLossBalSheetRemote profitLossBalSheetRemote = null;
InitialContext context = null;
AppConnectParm appConnectParm = new AppConnectParm();
String dataSourceName = "";
String prdfrom = "", acctprd = "",sitecode="",prdto="",formatcode="",reporttype="";
try
{
response.setContentType("application/xml");
sitecode= request.getParameter("sitecode");
prdfrom = request.getParameter("prdfrom");
prdto= request.getParameter("prdto");
acctprd= request.getParameter("acctprd");
formatcode= request.getParameter("formatcode");
reporttype= request.getParameter("reporttype");
dataSourceName = request.getParameter("dataSourceName");
System.out.println("in doPost" );
System.out.println("days is =" + sitecode );
System.out.println("days is =" + prdfrom );
System.out.println("days is =" + prdto );
System.out.println("days is =" + acctprd );
System.out.println("days is =" + formatcode );
System.out.println("days is =" + reporttype );
context = new InitialContext(appConnectParm.getProperty());
profitLossBalSheetRemote = (ProfitLossBalSheetRemote) context.lookup("ibase/ProfitLossBalSheet/remote");
JSONObject jsonObjData = (JSONObject)profitLossBalSheetRemote.getProfitBalanceSheetDetails(sitecode,prdfrom,prdto,acctprd,formatcode,reporttype,dataSourceName);
OutputStream outputStream = response.getOutputStream();
outputStream.write(jsonObjData.toString().getBytes());
outputStream.flush();
outputStream.close();
System.out.println(" Final data set for ProfitLossBalSheetServlet build the Graph is===" + jsonObjData);
} catch (Exception e)
{
System.out.println("Exception : ProfitLossBalSheetServlet :doPost(HttpServletRequest request, HttpServletResponse response) :" + e);
try
{
throw new ITMException(e);
} catch (ITMException e1)
{
e1.printStackTrace();
}
}
}
}
\ No newline at end of file
package ibase.dashboard.mfg.servlet;
import ibase.dashboard.mfg.ejb.QCSampleCostRemote;
import ibase.dashboard.mfg.ejb.SampleRCpDtlRemote;
import ibase.system.config.AppConnectParm;
import ibase.webitm.utility.ITMException;
import java.io.IOException;
import java.io.OutputStream;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
public class QCSampleCostServlet extends HttpServlet
{
// private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
doPost(request, response);
}
@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
QCSampleCostRemote qCSampleCostRemote = null;
InitialContext context = null;
AppConnectParm appConnectParm = new AppConnectParm();
String dataSourceName = "";
String geoLocation = "";
String lastMonth = "";
try
{
response.setContentType("application/xml");
dataSourceName = request.getParameter("dataSourceName");
geoLocation = request.getParameter("geoLocation");
lastMonth = request.getParameter("lastMonth");
context = new InitialContext(appConnectParm.getProperty());
qCSampleCostRemote = (QCSampleCostRemote) context.lookup("ibase/QCSampleCost/remote");
JSONObject jsonObjData = (JSONObject) qCSampleCostRemote.getQCSampleCostData(dataSourceName,geoLocation,lastMonth);
OutputStream outputStream = response.getOutputStream();
outputStream.write(jsonObjData.toString().getBytes());
outputStream.flush();
outputStream.close();
System.out.println(" Final data set for QCSampleCostServlet build the Graph is===" + jsonObjData);
} catch (Exception e)
{
System.out.println("Exception : QCSampleCostServlet :doPost(HttpServletRequest request, HttpServletResponse response) :" + e);
try
{
throw new ITMException(e);
} catch (ITMException e1)
{
e1.printStackTrace();
}
}
}
}
\ No newline at end of file
package ibase.dashboard.mfg.servlet;
import ibase.dashboard.mfg.ejb.SampleRCpDtlRemote;
import ibase.system.config.AppConnectParm;
import ibase.webitm.utility.ITMException;
import java.io.IOException;
import java.io.OutputStream;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
public class SampleRcpDtlServlet extends HttpServlet
{
// private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
doPost(request, response);
}
@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
SampleRCpDtlRemote sampleRCpDtlRemote = null;
InitialContext context = null;
AppConnectParm appConnectParm = new AppConnectParm();
String dataSourceName = "";
String lastMonth = "";
try
{
response.setContentType("application/xml");
dataSourceName = request.getParameter("dataSourceName");
lastMonth = request.getParameter("lastMonth");
context = new InitialContext(appConnectParm.getProperty());
sampleRCpDtlRemote = (SampleRCpDtlRemote) context.lookup("ibase/SampleRCpDtl/remote");
JSONObject jsonObjData = (JSONObject) sampleRCpDtlRemote.getSampleRCPDtlData(dataSourceName,lastMonth);
OutputStream outputStream = response.getOutputStream();
outputStream.write(jsonObjData.toString().getBytes());
outputStream.flush();
outputStream.close();
System.out.println(" Final data set for SampleRcpDtlServlet build the Graph is===" + jsonObjData);
} catch (Exception e)
{
System.out.println("Exception : SampleRcpDtlServlet :doPost(HttpServletRequest request, HttpServletResponse response) :" + e);
try
{
throw new ITMException(e);
} catch (ITMException e1)
{
e1.printStackTrace();
}
}
}
}
\ No newline at end of file
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