java action class:
private String debit_total;
private String credit_total;
public String getVoucherChildList() {
Object[] logInInfo = (Object[]) ActionContext.getContext().getSession().get(sessionVariable.getUserLogInInfo());
String companyNo = logInInfo[4].toString();
String emp_no = logInInfo[1].toString();
showVoucherChildList = accVoucherEntrySQL.getVouChildList(voucherNo);
postingLevelList = accVoucherEntrySQL.getPostingLevelList(companyNo);
getVoucherMasterValue(voucherNo);
debit_total = ((String) ActionContext.getContext().getSession().get("debit_total_amt"));
credit_total = ((String) ActionContext.getContext().getSession().get("credit_total_amt"));
return "getVoucherChildList";
}
sql class:
public List getVouChildList(String voucherNo) {
List showVoucherChildList = new ArrayList<FnVoucherchd>();
boolean fg = true;
con = mdbc.connectDB();
if (con == null) {
fg = false;
}
if (fg) {
try {
st = con.createStatement();
String ckQuery ="SELECT SUM(fn_paymentmodeamt.PAYMENT_AMT) AS DEBIT_AMT, '0' AS CREDIT_AMT FROM fn_paymentmodeamt INNER JOIN fn_vouchermst ON (fn_paymentmodeamt.VOUCHER_NO = fn_vouchermst.VOUCHER_NO) WHERE (fn_paymentmodeamt.VOUCHER_NO = '"+voucherNo+"' ) UNION SELECT '0' AS DEBIT_AMT, SUM(fn_voucherchd.ITEM_QTY*fn_voucherchd.BILL_AMT) AS CREDIT_AMT FROM fn_vouchermst INNER JOIN fn_voucherchd ON (fn_vouchermst.VOUCHER_NO = fn_voucherchd.VOUCHER_NO) WHERE (fn_vouchermst.VOUCHER_NO ='"+voucherNo+"') GROUP BY fn_vouchermst.VOUCHER_NO";
rs=st.executeQuery(ckQuery);
while(rs.next()){
check_debit_amt+=Math.round(Double.valueOf(rs.getString("debit_amt")));
check_credit_amt+=Math.round(Double.valueOf(rs.getString("credit_amt")));
}
if(check_debit_amt!=check_credit_amt){
if(check_debit_amt>check_credit_amt){
String query="SELECT fn_paymentmodeamt.VOUCHER_NO, fn_vouchermst.VOUCHER_DT, case fn_paymentmodeamt.PAYMENT_TYPE when 'CS' then 'Cash in Hand' when 'CQ' then 'Cash at Bank' end,fn_paymentmodeamt.PAYMENT_AMT AS DEBIT_AMT, '0' AS CREDIT_AMT, fn_paymentmodeamt.CQ_NO FROM fn_paymentmodeamt INNER JOIN fn_vouchermst ON (fn_paymentmodeamt.VOUCHER_NO = fn_vouchermst.VOUCHER_NO) WHERE (fn_paymentmodeamt.VOUCHER_NO = '"+voucherNo+"' ) " +
" UNION SELECT fn_voucherchd.VOUCHER_NO, fn_vouchermst.VOUCHER_DT,'' as PAYMENT_TYPE, '0' AS DEBIT_AMT, SUM(fn_voucherchd.ITEM_QTY*fn_voucherchd.BILL_AMT) AS CREDIT_AMT, fn_voucherchd.SERVICE_TYPE FROM fn_vouchermst INNER JOIN fn_voucherchd ON (fn_vouchermst.VOUCHER_NO = fn_voucherchd.VOUCHER_NO) WHERE (fn_vouchermst.VOUCHER_NO ='"+voucherNo+"') GROUP BY fn_vouchermst.VOUCHER_NO " +
" UNION All SELECT fn_voucherchd.VOUCHER_NO, fn_vouchermst.VOUCHER_DT,'VAT' as PAYMENT_TYPE, '0' AS DEBIT_AMT, SUM(fn_voucherchd.VAT_AMT) AS CREDIT_AMT, fn_voucherchd.SERVICE_TYPE FROM fn_vouchermst INNER JOIN fn_voucherchd ON (fn_vouchermst.VOUCHER_NO = fn_voucherchd.VOUCHER_NO) WHERE (fn_vouchermst.VOUCHER_NO ='"+voucherNo+"') GROUP BY fn_vouchermst.VOUCHER_NO";
System.out.println("1st Query : "+query);
rs = st.executeQuery(query);
while (rs.next()) {
FnVoucherchd fnVoucherchd = new FnVoucherchd();
fnVoucherchd.setCheque_no(rs.getString("CQ_NO"));
fnVoucherchd.setVoucher_no(rs.getString("voucher_no"));
fnVoucherchd.setPayment_type(rs.getString(3));
fnVoucherchd.setCredit_amt(String.valueOf(Math.round(Double.valueOf(rs.getString("credit_amt")))));
fnVoucherchd.setDebit_amt(String.valueOf(Math.round(Double.valueOf(rs.getString("debit_amt")))));
credit_total_amt+=Math.round(Double.valueOf(rs.getString("credit_amt")));
debit_total_amt+=Math.round(Double.valueOf(rs.getString("debit_amt")));
showVoucherChildList.add(fnVoucherchd);
}
ActionContext.getContext().getSession().put("debit_total_amt", String.valueOf(debit_total_amt));
ActionContext.getContext().getSession().put("credit_total_amt", String.valueOf(credit_total_amt));
}else{
String query="SELECT fn_paymentmodeamt.VOUCHER_NO, fn_vouchermst.VOUCHER_DT, case fn_paymentmodeamt.PAYMENT_TYPE when 'CS' then 'Cash in Hand' when 'CQ' then 'Cash at Bank' end,fn_paymentmodeamt.PAYMENT_AMT AS DEBIT_AMT, '0' AS CREDIT_AMT, fn_paymentmodeamt.CQ_NO FROM fn_paymentmodeamt INNER JOIN fn_vouchermst ON (fn_paymentmodeamt.VOUCHER_NO = fn_vouchermst.VOUCHER_NO) WHERE (fn_paymentmodeamt.VOUCHER_NO = '"+voucherNo+"' ) " +
" UNION SELECT fn_voucherchd.VOUCHER_NO, fn_vouchermst.VOUCHER_DT,'Discount' as PAYMENT_TYPE, SUM(fn_voucherchd.DISC_AMT) AS DEBIT_AMT,'0' AS CREDIT_AMT, fn_voucherchd.SERVICE_TYPE FROM fn_vouchermst INNER JOIN fn_voucherchd ON (fn_vouchermst.VOUCHER_NO = fn_voucherchd.VOUCHER_NO) WHERE (fn_vouchermst.VOUCHER_NO ='"+voucherNo+"') GROUP BY fn_vouchermst.VOUCHER_NO " +
" UNION All SELECT fn_voucherchd.VOUCHER_NO, fn_vouchermst.VOUCHER_DT,'' as PAYMENT_TYPE, '0' AS DEBIT_AMT, SUM(fn_voucherchd.ITEM_QTY*fn_voucherchd.BILL_AMT) AS CREDIT_AMT, fn_voucherchd.SERVICE_TYPE FROM fn_vouchermst INNER JOIN fn_voucherchd ON (fn_vouchermst.VOUCHER_NO = fn_voucherchd.VOUCHER_NO) WHERE (fn_vouchermst.VOUCHER_NO ='"+voucherNo+"') GROUP BY fn_vouchermst.VOUCHER_NO";
System.out.println("2nd Query : "+query);
rs = st.executeQuery(query);
while (rs.next()) {
FnVoucherchd fnVoucherchd = new FnVoucherchd();
fnVoucherchd.setCheque_no(rs.getString("CQ_NO"));
fnVoucherchd.setVoucher_no(rs.getString("voucher_no"));
fnVoucherchd.setPayment_type(rs.getString(3));
fnVoucherchd.setCredit_amt(String.valueOf(Math.round(Double.valueOf(rs.getString("credit_amt")))));
fnVoucherchd.setDebit_amt(String.valueOf(Math.round(Double.valueOf(rs.getString("debit_amt")))));
credit_total_amt+=Math.round(Double.valueOf(rs.getString("credit_amt")));
debit_total_amt+=Math.round(Double.valueOf(rs.getString("debit_amt")));
showVoucherChildList.add(fnVoucherchd);
}
ActionContext.getContext().getSession().put("debit_total_amt", String.valueOf(debit_total_amt));
ActionContext.getContext().getSession().put("credit_total_amt", String.valueOf(credit_total_amt));
}
}else{
String query="SELECT fn_paymentmodeamt.VOUCHER_NO, fn_vouchermst.VOUCHER_DT, case fn_paymentmodeamt.PAYMENT_TYPE when 'CS' then 'Cash in Hand' when 'CQ' then 'Cash at Bank' end,fn_paymentmodeamt.PAYMENT_AMT AS DEBIT_AMT, '0' AS CREDIT_AMT, fn_paymentmodeamt.CQ_NO FROM fn_paymentmodeamt INNER JOIN fn_vouchermst ON (fn_paymentmodeamt.VOUCHER_NO = fn_vouchermst.VOUCHER_NO) WHERE (fn_paymentmodeamt.VOUCHER_NO = '"+voucherNo+"' ) UNION" +
" SELECT fn_voucherchd.VOUCHER_NO, fn_vouchermst.VOUCHER_DT,'' as PAYMENT_TYPE, '0' AS DEBIT_AMT, SUM(fn_voucherchd.ITEM_QTY*fn_voucherchd.BILL_AMT) AS CREDIT_AMT, fn_voucherchd.SERVICE_TYPE FROM fn_vouchermst INNER JOIN fn_voucherchd ON (fn_vouchermst.VOUCHER_NO = fn_voucherchd.VOUCHER_NO) WHERE (fn_vouchermst.VOUCHER_NO ='"+voucherNo+"') GROUP BY fn_vouchermst.VOUCHER_NO";
System.out.println("3rd Query : "+query);
rs = st.executeQuery(query);
while (rs.next()) {
FnVoucherchd fnVoucherchd = new FnVoucherchd();
fnVoucherchd.setCheque_no(rs.getString("CQ_NO"));
fnVoucherchd.setVoucher_no(rs.getString("voucher_no"));
fnVoucherchd.setPayment_type(rs.getString(3));
fnVoucherchd.setCredit_amt(String.valueOf(Math.round(Double.valueOf(rs.getString("credit_amt")))));
fnVoucherchd.setDebit_amt(String.valueOf(Math.round(Double.valueOf(rs.getString("debit_amt")))));
credit_total_amt+=Math.round(Double.valueOf(rs.getString("credit_amt")));
debit_total_amt+=Math.round(Double.valueOf(rs.getString("debit_amt")));
showVoucherChildList.add(fnVoucherchd);
}
ActionContext.getContext().getSession().put("debit_total_amt", String.valueOf(debit_total_amt));
ActionContext.getContext().getSession().put("credit_total_amt", String.valueOf(credit_total_amt));
}
} catch (Exception ex) {
System.out.println("Voucher Child List Query Exception "
+ ex.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
con.close();
} catch (SQLException sq) {
sq.printStackTrace();
}
}
}
return showVoucherChildList;
}