Commit 523d2825 authored by vkadam's avatar vkadam

Updated source for auto advance adjustment(S16ESUN001)


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@103612 ce508802-f39f-4f6c-b175-0d175dae99d5
parent a0c3aa9d
...@@ -36,7 +36,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -36,7 +36,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
ResultSet rs =null,rs1=null; ResultSet rs =null,rs1=null;
boolean isError = false; boolean isError = false;
String tranId = "";
String sql = null,sql1=null; String sql = null,sql1=null;
double diffAmtExch = 0, adjAmt = 0, netAmt = 0, netAmtBc = 0, vouchAmt = 0, billAmt = 0, taxAmt = 0, totAmt = 0; double diffAmtExch = 0, adjAmt = 0, netAmt = 0, netAmtBc = 0, vouchAmt = 0, billAmt = 0, taxAmt = 0, totAmt = 0;
...@@ -44,6 +44,9 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -44,6 +44,9 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
double netAmtRcp = 0, advAmt = 0, netAmtDet = 0, netAmtBcRcp = 0, taxAmtDet = 0, totAmtDet = 0, netAmtBcDet = 0 ; double netAmtRcp = 0, advAmt = 0, netAmtDet = 0, netAmtBcRcp = 0, taxAmtDet = 0, totAmtDet = 0, netAmtBcDet = 0 ;
double advAmtAdj = 0, taxedAdjAmt = 0, advAmtDet = 0, taxAmtAdv = 0; double advAmtAdj = 0, taxedAdjAmt = 0, advAmtDet = 0, taxAmtAdv = 0;
String hdrVoucherType="",exchRate=""; String hdrVoucherType="",exchRate="";
String tran_id = "", sql = "", exchRate = "", sundryType = "", vouchType = "", advAdjMthd = "", sundryCode = "", siteCode = "";
boolean isAutoAdvAdjustment = false;
int cnt=0,cnt1=0,listCnt=1; int cnt=0,cnt1=0,listCnt=1;
try try
...@@ -52,7 +55,40 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -52,7 +55,40 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
GenericUtility genericUtility = GenericUtility.getInstance(); GenericUtility genericUtility = GenericUtility.getInstance();
dom = genericUtility.parseString(domString); dom = genericUtility.parseString(domString);
tranId = GenericUtility.getInstance().getColumnValue("tran_id",dom); //added by azhar [start](S16ESUN001)
//Read Header Column Values
tran_id = checkNullAndTrim(genericUtility.getColumnValue("tran_id", dom));
sundryType = checkNullAndTrim(genericUtility.getColumnValue("sundry_type", dom));
vouchType = checkNullAndTrim(genericUtility.getColumnValue("vouch_type", dom));
advAdjMthd = genericUtility.getColumnValue("adv_adj_mthd", dom);
totAmt = Double.parseDouble(genericUtility.getColumnValue("supp_bill_amt", dom));
siteCode = checkNullAndTrim(genericUtility.getColumnValue("site_code", dom));
sundryCode = checkNullAndTrim(genericUtility.getColumnValue("sundry_code", dom));
System.out.println("tran id from dom::: " + tran_id);
advAdjMthd = advAdjMthd == null ? "0" : advAdjMthd.trim();
System.out.println();
if("1".equalsIgnoreCase(advAdjMthd) && totAmt > 0){
{
isAutoAdvAdjustment = true;
}
} else {
isAutoAdvAdjustment = false;
}
if(isAutoAdvAdjustment){
insertIntoMiscVouchAdv(tran_id,sundryType,totAmt,siteCode,sundryCode,conn);
}
//added by azhar[end](S16ESUN001)
// Advance Screen Cross Update // Advance Screen Cross Update
sql="select exch_rate from misc_voucher where tran_id=?"; sql="select exch_rate from misc_voucher where tran_id=?";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
...@@ -71,7 +107,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -71,7 +107,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
+ " where tran_id= ? "; + " where tran_id= ? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,exchRate); pstmt.setString(1,exchRate);
pstmt.setString(2,tranId); pstmt.setString(2,tran_id);
cnt1 = pstmt.executeUpdate(); cnt1 = pstmt.executeUpdate();
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
...@@ -84,7 +120,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -84,7 +120,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
//SUM of all diff_amt__exch to update in header //SUM of all diff_amt__exch to update in header
sql="select coalesce(sum(diff_amt__exch),0) from misc_vouchadv where tran_id = ?"; sql="select coalesce(sum(diff_amt__exch),0) from misc_vouchadv where tran_id = ?";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId ); pstmt.setString(1,tran_id );
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
...@@ -97,7 +133,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -97,7 +133,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
sql="select coalesce(sum(adj_amt),0), coalesce(sum(taxed_adj_amt),0), coalesce(sum(tax_amt),0) from misc_vouchadv WHERE tran_id = ? " ; sql="select coalesce(sum(adj_amt),0), coalesce(sum(taxed_adj_amt),0), coalesce(sum(tax_amt),0) from misc_vouchadv WHERE tran_id = ? " ;
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId); pstmt.setString(1,tran_id);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
...@@ -112,7 +148,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -112,7 +148,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
sql="select coalesce((adv_amt__adj + adv_amt__det),0), coalesce((coalesce((adv_amt__adj + adv_amt__det),0) + tot_amt),0), coalesce((coalesce((adv_amt__adj + adv_amt__det),0) + tot_amt),0) + coalesce(exch_rate,0) from misc_voucher WHERE tran_id = ? " ; sql="select coalesce((adv_amt__adj + adv_amt__det),0), coalesce((coalesce((adv_amt__adj + adv_amt__det),0) + tot_amt),0), coalesce((coalesce((adv_amt__adj + adv_amt__det),0) + tot_amt),0) + coalesce(exch_rate,0) from misc_voucher WHERE tran_id = ? " ;
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId ); pstmt.setString(1,tran_id );
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
...@@ -131,7 +167,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -131,7 +167,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
// +" WHERE tran_id = ? "; // +" WHERE tran_id = ? ";
// pstmt = conn.prepareStatement(sql); // pstmt = conn.prepareStatement(sql);
// pstmt.setDouble(1,diffAmtExch ); // pstmt.setDouble(1,diffAmtExch );
// pstmt.setString(2,tranId ); // pstmt.setString(2,tran_id );
// cnt = pstmt.executeUpdate(); // cnt = pstmt.executeUpdate();
// pstmt.close(); // pstmt.close();
// pstmt = null; // pstmt = null;
...@@ -151,7 +187,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -151,7 +187,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
pstmt.setDouble(4,diffAmtExch ); pstmt.setDouble(4,diffAmtExch );
pstmt.setDouble(5,netAmt ); pstmt.setDouble(5,netAmt );
pstmt.setDouble(6,netAmtBc ); pstmt.setDouble(6,netAmtBc );
pstmt.setString(7,tranId ); pstmt.setString(7,tran_id );
cnt = pstmt.executeUpdate(); cnt = pstmt.executeUpdate();
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
...@@ -174,7 +210,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -174,7 +210,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
+ "on mvdet.tran_id = mv.tran_id " + "on mvdet.tran_id = mv.tran_id "
+ "WHERE mvdet.tran_id = ? group by mv.vouch_type" ; + "WHERE mvdet.tran_id = ? group by mv.vouch_type" ;
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId); pstmt.setString(1,tran_id);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
...@@ -191,7 +227,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -191,7 +227,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
sql="select coalesce(adv_amt__adj + adv_amt__det,0) from misc_voucher WHERE tran_id = ? " ; sql="select coalesce(adv_amt__adj + adv_amt__det,0) from misc_voucher WHERE tran_id = ? " ;
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId ); pstmt.setString(1,tran_id );
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
...@@ -209,7 +245,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -209,7 +245,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
sql="select coalesce(? * exch_rate,0) from misc_voucher WHERE tran_id = ? " ; sql="select coalesce(? * exch_rate,0) from misc_voucher WHERE tran_id = ? " ;
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setDouble(1,netAmt ); pstmt.setDouble(1,netAmt );
pstmt.setString(2,tranId ); pstmt.setString(2,tran_id );
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
...@@ -231,7 +267,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -231,7 +267,7 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
pstmt.setDouble(5,totAmt); pstmt.setDouble(5,totAmt);
pstmt.setDouble(6,netAmt); pstmt.setDouble(6,netAmt);
pstmt.setDouble(7,netAmtBc); pstmt.setDouble(7,netAmtBc);
pstmt.setString(8,tranId ); pstmt.setString(8,tran_id );
cnt = pstmt.executeUpdate(); cnt = pstmt.executeUpdate();
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
...@@ -270,4 +306,171 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost ...@@ -270,4 +306,171 @@ public class MiscVoucherPostSave extends ValidatorEJB implements MiscVoucherPost
{ {
return Math.round(round*Math.pow(10, scale))/Math.pow(10, scale); return Math.round(round*Math.pow(10, scale))/Math.pow(10, scale);
}*/ }*/
//added by azhar[start](S16ESUN001)
private void insertIntoMiscVouchAdv(String tran_id, String sundryType, double totAmt,String siteCode, String sundryCode, Connection conn)throws ITMException{
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "", varValue = "";
String tranId = "",refSer = "",refNo = "";
double totAmtPay = 0, adjAmtPay = 0,adjAmt = 0,totAmtTemp = 0;
int lineNo = 1;
try {
sql = "delete from misc_vouchadv where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tran_id);
pstmt.executeUpdate();
totAmtTemp = totAmt;
sql = "select var_value from finparm where var_name = 'ADV_ADJ_ACCT_CODE' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next()){
varValue = rs.getString("var_value");
}
varValue = varValue == null ? "" : varValue.trim();
System.out.println("var value ::: " + varValue);
sql = "select tran_id,tran_ser,ref_no,tot_amt,adj_amt from misc_payables where site_code = ? and sundry_type = ? and sundry_code = ? " +
"and tot_amt <> adj_amt and tot_amt < 0 and acct_code in (" + varValue + ") order by tran_date";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setString(2, sundryType);
pstmt.setString(3, sundryCode);
rs = pstmt.executeQuery();
while(rs.next()){
tranId = checkNullAndTrim(rs.getString("tran_id"));
refSer = checkNullAndTrim(rs.getString("tran_ser"));
refNo = checkNullAndTrim(rs.getString("ref_no"));
totAmtPay = Math.abs(rs.getDouble("tot_amt"));
adjAmtPay = Math.abs(rs.getDouble("adj_amt"));
System.out.println("tran id :: " + tranId + " tran ser::: " + refSer + "ref no::: " + refNo + " ::tot amt " + totAmtPay + "::adj amt pay:: " +adjAmtPay);
adjAmt = totAmtPay - adjAmtPay - getUnconfirmedVouchValue(refNo,siteCode,sundryCode,sundryType,refSer,conn);
System.out.println("adj amt to be set::: " + adjAmt);
if(totAmtTemp>=adjAmt && adjAmt > 0)
{
System.out.println("total amount temp:: " + totAmtTemp);
sql = "Insert into misc_vouchadv(tran_id,ref_ser,ref_no,adj_amt,tot_amt,line_no) values(?,?,?,?,?,?)";//TODO insert
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tran_id);
pstmt.setString(2, refSer);
pstmt.setString(3, refNo);
pstmt.setDouble(4, adjAmt);
pstmt.setDouble(5, totAmt);
pstmt.setInt(6, lineNo);
pstmt.executeUpdate();
lineNo++;
totAmtTemp-=adjAmt;
if(pstmt != null){
pstmt.close();
pstmt = null;
}
}
}
} catch (Exception e) {
System.out.println(":::: " + this.getClass().getSimpleName() + "::: " + e.getMessage());
e.printStackTrace();
}
}
private double getUnconfirmedVouchValue(String refNo, String siteCode ,String sundryCode, String sundryType, String refSer, Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
double unconfirmedAmt = 0,totAmtMVouch1 = 0, totAmtVouch1 = 0;
try {
sql = "select nvl(sum(a.tot_amt),0) from misc_voucher v, misc_vouchadv a where v.tran_id = a.tran_id and v.confirmed = 'N' " +
"and v.sundry_code = ? and v.site_code = ? and v.sundry_type = ? and a.ref_no = ? and a.ref_ser = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, sundryCode);
pstmt.setString(2, siteCode);
pstmt.setString(3,sundryType);
pstmt.setString(4, refNo);
pstmt.setString(5, refSer);
rs = pstmt.executeQuery();
if(rs.next()){
totAmtMVouch1 = Math.abs(rs.getDouble(1));
}
System.out.println("tot amt misc voucher::: " + totAmtMVouch1);
closeResources(pstmt,rs);
sql = "select nvl(sum(a.tot_amt),0) from voucher v, vouchadv a where v.tran_id = a.tran_id and v.confirmed = 'N' " +
"and v.supp_code = ? and v.site_code = ? and a.ref_no = ? and a.ref_ser = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, sundryCode);
pstmt.setString(2, siteCode);
pstmt.setString(3, refNo);
pstmt.setString(4, refSer);
rs = pstmt.executeQuery();
if(rs.next()){
totAmtVouch1 = Math.abs(rs.getDouble(1));
}
System.out.println("tot amt voucher::: " + totAmtVouch1);
closeResources(pstmt,rs);
unconfirmedAmt = totAmtMVouch1 + totAmtVouch1;
} catch (Exception e) {
}
return unconfirmedAmt;
}
//added by azhar[end](S16ESUN001)
private void closeResources(PreparedStatement pstmt, ResultSet rs) {
try{
if(pstmt != null){
pstmt.close();
pstmt = null;
}
if(rs != null){
rs.close();
rs = null;
}
}catch(Exception e){
}
}
private String checkNullAndTrim(String strValue) {
return strValue == null ? "" : strValue.trim();
}
} }
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