Commit 04014361 authored by dpawar's avatar dpawar

changes in debit note (Misc. )


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@94079 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 9e93a144
...@@ -20,12 +20,7 @@ import java.sql.SQLException; ...@@ -20,12 +20,7 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
...@@ -103,8 +98,9 @@ public String process(Document dom, Document dom2, String windowName, String xtr ...@@ -103,8 +98,9 @@ public String process(Document dom, Document dom2, String windowName, String xtr
PreparedStatement pstmt=null; PreparedStatement pstmt=null;
ResultSet rs=null; ResultSet rs=null;
int cnt=0; int cnt=0;
String siteCode="",custCodeFrm="",custCodeTo="",invType="",errorString="",errCode="",userId=""; double ExchRate=0;
String sql="",invoiceId="",priceList=""; String siteCode="",custCodeFrm="",custCodeTo="",invType="",errorString="",errCode="",userId="",custCode="";
String sql="",invoiceId="",priceList="",currCode="";
try{ try{
genericUtility = GenericUtility.getInstance(); genericUtility = GenericUtility.getInstance();
itmDBAccessEJB = new ITMDBAccessEJB(); itmDBAccessEJB = new ITMDBAccessEJB();
...@@ -207,9 +203,8 @@ public String process(Document dom, Document dom2, String windowName, String xtr ...@@ -207,9 +203,8 @@ public String process(Document dom, Document dom2, String windowName, String xtr
rs=null; rs=null;
pstmt.close(); pstmt.close();
pstmt=null; pstmt=null;
priceList=podObject.getNameOrDescrForCode(conn, "site", "price_list", "site_code", siteCode);
System.out.println("Size of arrayList inv45dayList----->>["+inv45dayList.size()+"]"); System.out.println("Size of arrayList inv45dayList----->>["+inv45dayList.size()+"]");
podProcessInvIDList=getPendingInvoiceID( conn, inv45dayList); podProcessInvIDList=getDoneInvoiceIdHDR( conn, inv45dayList);
if(podProcessInvIDList.contains("Error")) if(podProcessInvIDList.contains("Error"))
{ {
...@@ -238,12 +233,19 @@ public String process(Document dom, Document dom2, String windowName, String xtr ...@@ -238,12 +233,19 @@ public String process(Document dom, Document dom2, String windowName, String xtr
} }
} }
podProcessInvIDList.clear();
podProcessInvIDList.add("618ID00040");
System.out.println("Final invoice Id ready for debit note---->>["+podProcessInvIDList+"]"); System.out.println("Final invoice Id ready for debit note---->>["+podProcessInvIDList+"]");
priceList=podObject.getNameOrDescrForCode(conn, "site", "price_list", "site_code", siteCode);
priceList=priceList==null ? "" :priceList.trim();
System.out.println("priceList----->>["+priceList+"]");
//Check in invoice_trace if item_code_ord (scheme_code) is available or not.
//if yes then checked in bomdet.if scheme code found then for that particular item scheme is apply.
String str=schemeApply(conn, podProcessInvIDList,priceList,xtraParams,siteCode);
...@@ -270,6 +272,115 @@ public String process(Document dom, Document dom2, String windowName, String xtr ...@@ -270,6 +272,115 @@ public String process(Document dom, Document dom2, String windowName, String xtr
return errorString; return errorString;
} }
private String schemeApply(Connection conn,ArrayList<String> podProcessInvIDListL,String priceListL,String xtraParams,String siteCode)
{
ResultSet rs=null;
PreparedStatement pstmt=null;
ProofOfDelivery pod=null;
ProofOfDeliveryConf podC=null;
String sql="",lotNo="",lotSl="",itemCode="",itemCodeOrd="",itemActive="",detail2xmlString="";
double invRate=0,invQty=0,discount=0,priceListRate=0,detail3Amt=0,detail3AmtT=0,debitNoteAmtDetail=0;
double debitNoteAmtHdr=0;
int lineNotrace=0,lineNo=0;
pod=ProofOfDelivery.getInstance();
podC=ProofOfDeliveryConf.getInstance();
try{
System.out.println("priceListL------>>["+priceListL+"]");
for(String invoiceId :podProcessInvIDListL)
{
sql="select rate,quantity,lot_no,lot_sl,item_code,inv_line_no,discount,item_code__ord " +
"from invoice_trace where invoice_id = ? order by inv_line_no";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, invoiceId);
rs=pstmt.executeQuery();
while(rs.next())
{
invRate=rs.getDouble(1);
invQty=rs.getDouble(2);
lotNo=rs.getString(3);
lotSl=rs.getString(4);
itemCode=rs.getString(5);
lineNotrace=rs.getInt(6);
discount=rs.getDouble(7);
itemCodeOrd=rs.getString(8);
lotNo=lotNo==null ? "" :lotNo.trim();
lotSl=lotSl==null ? "" :lotSl.trim();
itemCode=itemCode==null ? "" :itemCode.trim();
itemCodeOrd=itemCodeOrd==null ? "" :itemCodeOrd.trim();
//Discount need discussion -----------------@@@@@--------
if(discount > 0)
{
invRate=invRate - (invRate * discount/100);
System.out.println("Discount for invoice id--->>["+invoiceId+"]"+"inv Rate-->>["+invRate+"]");
}
//Check if item code Active or not."N" or null then return error message.
itemActive=pod.getColumnDescr(conn,"active","item","item_code",itemCode);
itemActive=itemActive==null ? "" :itemActive.trim();
if(itemActive.equalsIgnoreCase("N") || itemActive.length()<=0)
{
return "ITEMNOTACTIVE"; // item code not active
}
//check if scheme is apply or not
if(isSchemeApply(conn,itemCode))
{
//java code if scheme is apply
System.out.println("-------Scheme is apply -----------");
}
else{
System.out.println("-------Scheme not apply -----------");
if(priceListL.length() <=0)
{
return "PRICELIST"; //priceList not define in site master.
}
else{
java.util.Date tranDate=new Date();
priceListRate=getPriceListRate(priceListL, tranDate,itemCode,lotNo,"", conn);
System.out.println("priceListRate----->>["+priceListRate+"]");
if(priceListRate < 0)
{
// return error messages
}
else
{
debitNoteAmtDetail=podC.getDebitNoteAmount(invRate,invQty);
debitNoteAmtHdr=debitNoteAmtHdr+debitNoteAmtDetail;
detail3Amt= (priceListRate - invRate) * invQty;
System.out.println("Debit note amount-------->>["+detail3Amt+"]");
detail3AmtT=detail3AmtT + detail3Amt;
lineNo++;
//detail2xmlString=detail2xmlString + podC.getDetailsXmlString(invoiceId,lineNotrace,lineNo,invRate,invQty,lotNo,lotSl,itemCode, detail3Amt);
}
} //end priceListL if
} //end isSchemeApply
} //end while invoice trace
System.out.println("Final detail2xmlString----->>["+detail2xmlString+"]");
System.out.println("Final debitNoteAmtHdr---------->> : "+debitNoteAmtHdr);
System.out.println("Final detail3AmtT in debit note table---------->> : "+detail3AmtT);
//errString=genDebitNote(tranId,invoiceId,custCode,siteCode,xtraParams,0,currCode,ExchRate,detail2xmlString,debitNoteAmtHdr,detail3AmtT,conn);
} //end invoice id for loop
}catch(Exception e)
{
System.out.println("Exception : ");
e.printStackTrace();
}
return "";
}
// Return array list whoes invoice id not confirmed in spl_sales_por_hdr table. // Return array list whoes invoice id not confirmed in spl_sales_por_hdr table.
private ArrayList<String> getNotConfirmedInvIdFromHdr(Connection conn) private ArrayList<String> getNotConfirmedInvIdFromHdr(Connection conn)
{ {
...@@ -306,10 +417,10 @@ private ArrayList<String> getNotConfirmedInvIdFromHdr(Connection conn) ...@@ -306,10 +417,10 @@ private ArrayList<String> getNotConfirmedInvIdFromHdr(Connection conn)
} }
private ArrayList<String> getPendingInvoiceID(Connection conn,ArrayList<String> invIdList) private ArrayList<String> getDoneInvoiceIdHDR(Connection conn,ArrayList<String> inv45dayListL)
{ {
System.out.println("--------------checkPODDoneOrNot method------------------"); System.out.println("--------------checkPODDoneOrNot method------------------");
System.out.println("ArrayList invIdList--->>[["+invIdList+"]]"); System.out.println("ArrayList invIdList--->>[["+inv45dayListL+"]]");
ArrayList<String> podDoneInvIDList=new ArrayList<String>(); ArrayList<String> podDoneInvIDList=new ArrayList<String>();
ArrayList<String> podProcessInvIDListL=new ArrayList<String>(); ArrayList<String> podProcessInvIDListL=new ArrayList<String>();
...@@ -338,9 +449,9 @@ private ArrayList<String> getPendingInvoiceID(Connection conn,ArrayList<String> ...@@ -338,9 +449,9 @@ private ArrayList<String> getPendingInvoiceID(Connection conn,ArrayList<String>
rs=null; rs=null;
pstmt.close(); pstmt.close();
pstmt=null; pstmt=null;
if(invIdList.size() > 0 && podDoneInvIDList.size() > 0){ if(inv45dayListL.size() > 0 && podDoneInvIDList.size() > 0){
System.out.println("---both arraylist contains elements-----------"); System.out.println("---both arraylist contains elements-----------");
for (String invId : invIdList) { for (String invId : inv45dayListL) {
if(!(podDoneInvIDList.contains(invId))){ if(!(podDoneInvIDList.contains(invId))){
podProcessInvIDListL.add(invId); podProcessInvIDListL.add(invId);
...@@ -384,6 +495,195 @@ private ArrayList<String> getPendingInvoiceID(Connection conn,ArrayList<String> ...@@ -384,6 +495,195 @@ private ArrayList<String> getPendingInvoiceID(Connection conn,ArrayList<String>
return podProcessInvIDListL; return podProcessInvIDListL;
} }
private boolean isSchemeApply(Connection conn,String itemCodeL)
{
String sql="";
ResultSet rsL=null;
PreparedStatement pstmtL=null;
int countL=0;
try{
sql="select count(*) from bomdet where item_Code = ? ";
pstmtL=conn.prepareStatement(sql);
pstmtL.setString(1, itemCodeL);
rsL=pstmtL.executeQuery();
if(rsL.next()){
countL=rsL.getInt(1);
}
System.out.println("count in isSchemeApply-->>["+countL+"] itemCode--->>["+itemCodeL+"]");
rsL.close();
rsL=null;
pstmtL.close();
pstmtL=null;
if(countL > 0)
return true;
}
catch(Exception e)
{
System.out.println("----Exception : in isSchemeApply method-------");
e.printStackTrace();
}
return false;
}
public double getPriceListRate(String priceList, java.util.Date tranDate, String itemCode, String lotNo, String type, Connection connectionObject) throws RemoteException,ITMException
{
double rate = 0;
String siteCode = "";
String locCode = "";
String lotSl = "";
String errCode = "";
Statement stmt;
ResultSet rs = null;
String sql = "";
//boolean connectionState = false;
try
{
stmt = connectionObject.createStatement();
sql = "SELECT LIST_TYPE FROM PRICELIST WHERE PRICE_LIST = '"+priceList+"'";
rs = stmt.executeQuery(sql);
if (!rs.next())
{
return -1;
}
else
{
type = rs.getString(1);
}
if (type.equalsIgnoreCase("L")) // List Price
{
sql = "SELECT RATE FROM PRICELIST WHERE PRICE_LIST = '"+priceList+"' AND ITEM_CODE = ''"+itemCode+"' AND LIST_TYPE = 'L' AND EFF_FROM <= '"+tranDate+"' AND VALID_UPTO >= '"+tranDate+"'";
rs = stmt.executeQuery(sql);
if (!rs.next())
{
return -1; // Denotes Error
}
else
{
rate = rs.getDouble(1);
}
}
else if (type.equalsIgnoreCase("D")) // Despatch
/* Selecting rate from pricelist for L, if not found picking up from batch */
{
try
{
sql = "SELECT RATE FROM PRICELIST WHERE PRICE_LIST = '"+priceList+"' AND ITEM_CODE = '"+itemCode+"' AND LIST_TYPE = 'L' AND EFF_FROM <= '"+tranDate+"' AND VALID_UPTO >= '"+tranDate+"'";
rs = stmt.executeQuery(sql);
if (!rs.next())
{
rate = 0;
sql = "SELECT RATE FROM PRICELIST WHERE PRICE_LIST = '"+priceList+"' AND ITEM_CODE = '"+itemCode+"' AND LIST_TYPE = 'B' AND LOT_NO__FROM <= '"+lotNo+"' AND LOT_NO__TO >= '"+lotNo+"' AND EFF_FROM <= '"+tranDate+"' AND VALID_UPTO >= '"+tranDate+"'";
rs = stmt.executeQuery(sql);
if (!rs.next())
{
return -1; // Denotes Error
}
else
{
rate = rs.getDouble(1);
}
}
else
{
rate = rs.getDouble(1);
}
}
catch(SQLException ie)
{
System.out.println("Exception: DistDiscountEJB: pickRate: type D: ==>"+ie);
ie.printStackTrace();
return -1;
}
}
else if (type.equalsIgnoreCase("B")) // Batch Price
{
rate = 0;
sql = "SELECT RATE FROM PRICELIST WHERE PRICE_LIST = '"+priceList+"' AND ITEM_CODE = '"+itemCode+"' AND LIST_TYPE = 'B' AND LOT_NO__FROM <= '"+lotNo+"' AND LOT_NO__TO >= '"+lotNo+"' AND EFF_FROM <= sysdate AND VALID_UPTO >= sysdate";
System.out.println("price list sql---->>["+sql+"]");
rs = stmt.executeQuery(sql);
System.out.println("After excution-----------");
if (!rs.next())
{
return -1; // Denotes Error
}
else
{
rate = rs.getDouble(1);
}
}
else if (type.equalsIgnoreCase("M") || type.equalsIgnoreCase("N")) // Discount Price
{
sql = "SELECT RATE FROM PRICELIST WHERE PRICE_LIST = '"+priceList+"' AND ITEM_CODE = '"+itemCode+"' AND LIST_TYPE = '"+type+"' AND EFF_FROM <= '"+tranDate+"' AND VALID_UPTO >= '"+tranDate+"'";
rs = stmt.executeQuery(sql);
if (!rs.next())
{
return -1; // Denotes Error
}
else
{
rate = rs.getDouble(1);
}
}
else if (type.equalsIgnoreCase("I")) // Inventory
{
/* ------------------Code not transferred, it's calling an external function
siteCode =
locCode =
lotNo =
lotSl =
-------------------*/
rate = 0;
// To check is lot no is null or not and fetch accordingly
if (lotSl.trim().length() == 0 || lotSl.length() == 0)
{
sql = "SELECT RATE FROM STOCK WHERE ITEM_CODE = '"+itemCode+"' AND SITE_CODE = '"+siteCode+"' AND LOC_CODE = '"+locCode+"' AND LOT_NO = '"+lotNo+"'";
rs = stmt.executeQuery(sql);
if (!rs.next())
{
return -1;
}
else
{
rate = rs.getDouble(1);
}
}
else
{
sql = "SELECT RATE FROM STOCK WHERE ITEM_CODE = '"+itemCode+"' AND SITE_CODE = '"+siteCode+"' AND LOC_CODE = '"+locCode+"' AND LOT_NO = '"+lotNo+"' AND LOT_SL '"+lotSl+"'";
rs = stmt.executeQuery(sql);
if (rs.next())
{
rate = rs.getDouble(1);
}
else
{
return -1;
}
}
}
if (rs != null)
{
rs.close();
}
}
catch(Exception e)
{
System.out.println("Exception :PODProcess :getPriceListRate:" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
return rate;
}
} }
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