Commit 6e9b5c1f authored by pchavan's avatar pchavan

Impliment E-wayBill Functionality.

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@213058 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 7afcdfdb
package ibase.webitm.ejb.dis.adv;
import java.util.List;
public class EwayBillJson {
String version;
List<EwayBillValue> billLists;
public EwayBillJson(String version, List<EwayBillValue> billLists) {
super();
this.version = version;
this.billLists = billLists;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public List<EwayBillValue> getBillLists() {
return billLists;
}
public void setBillLists(List<EwayBillValue> billLists) {
this.billLists = billLists;
}
}
package ibase.webitm.ejb.dis.adv;
import java.io.File;
import java.io.FileWriter;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.utility.ITMException;
/*
* This class will holds the values which will represents the EWAY BILL JSON FILE.
* This claas contains the validations for the various fields values of the eway json file.
*/
@JsonPropertyOrder({"userGstin","supplyType","subSupplyType","docType","docNo","docDate","transType","fromGstin","fromTrdName","fromAddr1","fromAddr2","fromPlace","fromPinCode","fromStateCode","actualFromStateCode","toGstin","toTrdName","toAddr1","toAddr2","toPlace","toPincode","toStateCode","actualToStateCode","totalValue","cgstValue","sgstValue","igstValue","cessValue","TotNonAdvolVal","OthValue","totInvValue","transMode","transDistance","transporterName","transporterId","transDocNo","transDocDate","vehicleNo","vehicleType","mainHsnCode","itemList"})
public class EwayBillValue {
private String userGstin;
private String supplyType;
private int subSupplyType;
private String docType;
private String docNo;
private String docDate;
private int transType;
private String fromGstin;
private String fromTrdName;
private String fromAddr1;
private String fromAddr2;
private String fromPlace;
private int fromPinCode;
private int fromStateCode;
private int actualFromStateCode;
private String toGstin;
private String toTrdName;
private String toAddr1;
private String toAddr2;
private String toPlace;
private int toPincode;
private int toStateCode;
private int actualToStateCode;
private double totalValue;
private double cgstValue;
private double sgstValue;
private double igstValue;
private double cessValue;
private int TotNonAdvolVal;
private int OthValue;
private double totInvValue;
private int transMode;
private double transDistance;
private String transporterName;
private String transporterId;
private String transDocNo;
private String transDocDate;
private String vehicleNo;
private String vehicleType;
private int mainHsnCode;
private List<ItemDetails> itemList;
public EwayBillValue(){
}
/* public EwayBillValue(String userGstin, String supplyType, String subSupplyType, String docType, String docNo,
String docDate, String fromGstin, String fromTrdName, String formAddr1, String fromAddr2, String fromPlace,
int frompinCode, String fromstateCode, String actualFromStateCode, String toGstin, String toTrdName,
String toAddr1, String toAddr2, String toPlace, int toPincode, String tostateCode, String actualToStateCode,
String assessable_value, double cgstValue, double sgstValue, double igstValue, double cessValue,
double totalValue) {
super();
this.userGstin = checkNull(userGstin);
this.supplyType = checkNull(supplyType);
this.subSupplyType = checkNull(subSupplyType);
this.docType = checkNull(docType);
this.docNo = checkNull(docNo);
this.docDate = checkNull(docDate);
this.fromGstin = checkNull(fromGstin);
this.fromTrdName = checkNull(fromTrdName);
this.formAddr1 = checkNull(formAddr1);
this.fromAddr2 = checkNull(fromAddr2);
this.fromPlace = checkNull(fromPlace);
this.frompinCode =frompinCode;
this.fromstateCode = checkNull(fromstateCode);
this.actualFromStateCode = checkNull(actualFromStateCode);
this.toGstin = checkNull(toGstin);
this.toTrdName =checkNull(toTrdName);
this.toAddr1 = checkNull(toAddr1);
this.toAddr2 = checkNull(toAddr2);
this.toPlace = checkNull(toPlace);
this.toPincode = toPincode;
this.tostateCode = checkNull(tostateCode);
this.actualToStateCode = checkNull(actualToStateCode);
this.cgstValue = cgstValue;
this.sgstValue = sgstValue;
this.igstValue = igstValue;
this.cessValue = cessValue;
this.totalValue = totalValue;
}*/
public EwayBillValue(String userGstin, String supplyType, int subSupplyType, String docType, String docNo,
String docDate,int transType ,String fromGstin, String fromTrdName, String fromAddr1, String fromAddr2, String fromPlace,
int frompinCode, int fromstateCode, int actualFromStateCode, String toGstin, String toTrdName,
String toAddr1, String toAddr2, String toPlace, int toPincode, int tostateCode, int actualToStateCode,
double totalvalue, double cgstValue, double sgstValue, double igstValue, double cessValue,int TotNonAdvolVal,int OthValue, double totInvValue,
int transMode,double transDistance,String transporterName,String transporterId,String transDocNo,String transDocDate,String sundryType,String vehicleType,String vehicleNo,int mainHsnCode,List<ItemDetails> itemList,String refSer,String tranId) {
super();
this.userGstin = checkNull(userGstin).trim();
this.supplyType = checkNull(supplyType).trim();
this.subSupplyType = subSupplyType;
this.docType = checkNull(docType).trim();
this.docNo = checkNull(docNo).trim();
this.docDate = checkNull(docDate).trim();
this.transType =transType;
this.fromGstin = checkNull(fromGstin).trim();
this.fromTrdName = checkNull(fromTrdName).trim();
this.fromAddr1 = checkNull(fromAddr1).trim();
this.fromAddr2 = checkNull(fromAddr2).trim();
this.fromPlace = checkNull(fromPlace).trim();
this.fromPinCode =frompinCode;
this.fromStateCode = fromstateCode;
this.actualFromStateCode = actualFromStateCode;
this.toGstin = checkNull(toGstin);
this.toTrdName =checkNull(toTrdName).trim();
this.toAddr1 = checkNull(toAddr1).trim();
this.toAddr2 = checkNull(toAddr2).trim();
this.toPlace = checkNull(toPlace).trim();
this.toPincode = toPincode;
this.toStateCode = tostateCode;
this.actualToStateCode = actualToStateCode;
this.totalValue = totalvalue;
this.cgstValue = cgstValue;
this.sgstValue = sgstValue;
this.igstValue = igstValue;
this.cessValue = cessValue;
this.TotNonAdvolVal=TotNonAdvolVal;
this.OthValue=OthValue;
this.totInvValue = totInvValue;
this.transMode=transMode;
this.transDistance=transDistance;
this.transporterName=checkNull(transporterName).trim();
this.transporterId=checkNull(transporterId).trim();
this.vehicleType=checkNull(vehicleType).trim();
this.vehicleNo=checkNull(vehicleNo).trim();
this.transDocDate=checkNull(transDocDate).trim();
this.transDocNo=checkNull(transDocNo).trim();
this.itemList=itemList;
this.mainHsnCode=mainHsnCode;
}
public String getUserGstin() {
return userGstin;
}
public void setUserGstin(String userGstin) {
this.userGstin = userGstin;
}
public String getSupplyType() {
return supplyType;
}
public void setSupplyType(String supplyType) {
this.supplyType = supplyType;
}
public int getSubSupplyType() {
return subSupplyType;
}
public void setSubSupplyType(int subSupplyType) {
this.subSupplyType = subSupplyType;
}
public String getDocType() {
return docType;
}
public void setDocType(String docType) {
this.docType = docType;
}
public String getDocNo() {
return docNo;
}
public void setDocNo(String docNo) {
this.docNo = docNo;
}
public String getDocDate() {
return docDate;
}
public void setDocDate(String docDate) {
this.docDate = docDate;
}
@JsonProperty("transType")
public int gettransType() {
return transType;
}
@JsonProperty("transType")
public void settransType(int transType) {
this.transType = transType;
}
public String getFromGstin() {
return fromGstin;
}
public void setFromGstin(String fromGstin) {
this.fromGstin = fromGstin;
}
public String getFromTrdName() {
return fromTrdName;
}
public void setFromTrdName(String fromTrdName) {
this.fromTrdName = fromTrdName;
}
public String getFromAddr1() {
return fromAddr1;
}
public void setFromAddr1(String fromAddr1) {
this.fromAddr1 = fromAddr1;
}
public String getFromAddr2() {
return fromAddr2;
}
public void setFromAddr2(String fromAddr2) {
this.fromAddr2 = fromAddr2;
}
public String getFromPlace() {
return fromPlace;
}
public void setFromPlace(String fromPlace) {
this.fromPlace = fromPlace;
}
@JsonProperty("fromPinCode")
public int getfromPinCode() {
return fromPinCode;
}
@JsonProperty("fromPinCode")
public void setfromPinCode(int fromPinCode) {
this.fromPinCode = fromPinCode;
}
@JsonProperty("fromStateCode")
public int getfromStateCode() {
return fromStateCode;
}
@JsonProperty("fromStateCode")
public void setfromStateCode(int fromStateCode) {
this.fromStateCode = fromStateCode;
}
public int getActualFromStateCode() {
return actualFromStateCode;
}
public void setActualFromStateCode(int actualFromStateCode) {
this.actualFromStateCode = actualFromStateCode;
}
public String getToGstin() {
return toGstin;
}
public void setToGstin(String toGstin) {
this.toGstin = toGstin;
}
public String getToTrdName() {
return toTrdName;
}
public void setToTrdName(String toTrdName) {
this.toTrdName = toTrdName;
}
public String getToAddr1() {
return toAddr1;
}
public void setToAddr1(String toAddr1) {
this.toAddr1 = toAddr1;
}
public String getToAddr2() {
return toAddr2;
}
public void setToAddr2(String toAddr2) {
this.toAddr2 = toAddr2;
}
public String getToPlace() {
return toPlace;
}
public void setToPlace(String toPlace) {
this.toPlace = toPlace;
}
public int getToPincode() {
return toPincode;
}
public void setToPincode(int toPincode) {
this.toPincode = toPincode;
}
@JsonProperty("toStateCode")
public int getTostateCode() {
return toStateCode;
}
@JsonProperty("toStateCode")
public void setTostateCode(int toStateCode) {
this.toStateCode = toStateCode;
}
public int getActualToStateCode() {
return actualToStateCode;
}
public void setActualToStateCode(int actualToStateCode) {
this.actualToStateCode = actualToStateCode;
}
public double getCgstValue() {
return cgstValue;
}
public void setCgstValue(double cgstValue) {
this.cgstValue = cgstValue;
}
public double getSgstValue() {
return sgstValue;
}
public void setSgstValue(double sgstValue) {
this.sgstValue = sgstValue;
}
public double getIgstValue() {
return igstValue;
}
public void setIgstValue(double igstValue) {
this.igstValue = igstValue;
}
public double getCessValue() {
return cessValue;
}
public void setCessValue(double cessValue) {
this.cessValue = cessValue;
}
@JsonProperty("TotNonAdvolVal")
public int getTotNonAdvolVal() {
return TotNonAdvolVal;
}
@JsonProperty("TotNonAdvolVal")
public void setTotNonAdvolVal(int TotNonAdvolVal) {
this.TotNonAdvolVal = TotNonAdvolVal;
}
@JsonProperty("OthValue")
public int getOthValue() {
return OthValue;
}
@JsonProperty("OthValue")
public void setOthValue(int OthValue) {
this.OthValue = OthValue;
}
public double getTotalValue() {
return totalValue;
}
public void setTotalValue(double totalValue) {
this.totalValue = totalValue;
}
public int getTransMode() {
return transMode;
}
public void setTransMode(int transMode) {
this.transMode = transMode;
}
public String getTransporterName() {
return transporterName;
}
public void setTransporterName(String transporterName) {
this.transporterName = transporterName;
}
public String getTransporterId() {
return transporterId;
}
public void setTransporterId(String transporterId) {
this.transporterId = transporterId;
}
public String getVehicleType() {
return vehicleType;
}
public void setVehicleType(String vehicleType) {
this.vehicleType = vehicleType;
}
public String getVehicleNo() {
return vehicleNo;
}
public void setVehicleNo(String vehicleNo) {
this.vehicleNo = vehicleNo;
}
public String getTransDocNo() {
return transDocNo;
}
public void setTransDocNo(String transDocNo) {
this.transDocNo = transDocNo;
}
public String getTransDocDate() {
return transDocDate;
}
public void setTransDocDate(String transDocDate) {
this.transDocDate = transDocDate;
}
public int getMainHsnCode() {
return mainHsnCode;
}
public void setMainHsnCode(int mainHsnCode) {
this.mainHsnCode = mainHsnCode;
}
public double getTotInvValue() {
return totInvValue;
}
public void setTotInvValue(double totInvValue) {
this.totInvValue = totInvValue;
}
public double getTransDistance() {
return transDistance;
}
public void setTransDistance(double transDistance) {
this.transDistance = transDistance;
}
public List<ItemDetails> getItemList() {
return itemList;
}
public void setItemList(List<ItemDetails> itemList) {
this.itemList = itemList;
}
//add validations for the input values....
public boolean validateFields(String refSer,String tranId,String siteCode){
String errorArray[];
boolean flag=true;
try{
System.out.println("Inside Validation Fields:"+ docType);
if(userGstin.trim().length()<=0){
errorArray=getErrorMessageDescription("VTEW017").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW017-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
if(docType.trim().length()<=0){
errorArray=getErrorMessageDescription("VTEW001").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW001-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
/* if(docNo.trim().length()<=0){
errorArray=getErrorMessageDescription("VTEW002").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW002-"+errorArray[1]+"'");
flag=false;
}
}*/
if(fromGstin.trim().length()<=0){
errorArray=getErrorMessageDescription("VTEW003").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW003-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
if(fromPinCode==0){
errorArray=getErrorMessageDescription("VTEW004").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW004-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
if(fromStateCode==0){
errorArray=getErrorMessageDescription("VTEW005").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW005-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
if(toStateCode==0){
errorArray=getErrorMessageDescription("VTEW006").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW006-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
if(toGstin.trim().length()<=0){
errorArray=getErrorMessageDescription("VTEW007").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW007-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
if(toPincode==0){
errorArray=getErrorMessageDescription("VTEW008").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW008-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
if(transMode==1){
if(transporterId.trim().length()<=0 && vehicleNo.trim().length()<=0 ){
errorArray=getErrorMessageDescription("VTEW009").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW009-"+errorArray[1]+"'",siteCode);
flag=false;
}
errorArray=getErrorMessageDescription("VTEW011").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW011-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
}
if(transMode != 1){
if(transDocDate.trim().length()<=0){
errorArray=getErrorMessageDescription("VTEW010").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW010-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
if(docNo.trim().length()<=0){
errorArray=getErrorMessageDescription("VTEW002").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW002-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
}
/* if(vehicleNo.trim().length()<=0){
errorArray=getErrorMessageDescription("VTEW011").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW011-"+errorArray[1]+"'");
flag=false;
}
}*/
if(transMode==0){
errorArray=getErrorMessageDescription("VTEW014").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW014-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
if(transDistance==0.0){
errorArray=getErrorMessageDescription("VTEW015").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW015-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
if(transDistance>4000.00){
errorArray=getErrorMessageDescription("VTEW016").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW016-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
//checked values from the list where we add items.
Iterator<ItemDetails> itemListIterator=itemList.iterator();
while(itemListIterator.hasNext()){
ItemDetails item=itemListIterator.next();
int value=item.getHsnCode();
System.out.println("hsn value:"+value);
if(value==0){
errorArray=getErrorMessageDescription("VTEW012").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW012-"+errorArray[1]+"'",siteCode);
flag=false;
}
}
/*double taxableAmount=item.getTaxableAmount();
System.out.println("cgstValue:"+cgstValue+" igstValue:"+igstValue+" sgstValue:"+sgstValue+" taxableAmount:"+taxableAmount);
System.out.println("(cgstValue+igstValue+sgstValue+taxableAmount)"+(cgstValue+igstValue+sgstValue+taxableAmount)+" Invoice amount :"+(totInvValue)+"'");
if((cgstValue+igstValue+sgstValue+taxableAmount)<totInvValue)
{
errorArray=getErrorMessageDescription("VTEW013").split(",");
if(errorArray[0].equals("E")){
printLog("EWAY Bill failed","'REF_SER-"+refSer+"','Tran-Id-"+tranId+"','Error-Code-VTEW013-"+errorArray[1]);
flag=false;
}
}*/
}
}
catch(Exception e){
printLog("EWAY Bill failed",e.getMessage(),siteCode);
}
return flag;
}
//printing the log values while validations
private void printLog(String title, String msg,String siteCode)
{
String logFile = "";
String logDir = "";
File logFileDir = null;
FileWriter fileWriter = null;
String logPath="";
DistCommon distCommon = new DistCommon();
Connection conn = null;
try
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB();
String logFileName = "";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
logFileName = "EWAYBILL_"+siteCode+"_"+sdf.format(new Date());
System.out.println("Inside the print log method");
logPath=distCommon.getDisparams("999999", "EWAY_LOG_PATH", conn);
logDir = logPath + File.separator + File.separator + "EWAYBILL";
System.out.println("Log direction: "+logDir);
logFileDir = new File(logDir);
if (!logFileDir.exists())
{
logFileDir.mkdirs();
}
logFile = logDir + File.separator + logFileName + ".log";
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
java.util.Date now = new java.util.Date();
String strDate = sdfDate.format(now);
fileWriter = new FileWriter(logFile, true);
fileWriter.write("\r\n");
fileWriter.write(strDate+" "+"[ERROR] "+msg);
}
catch (Exception ex)
{
ex.printStackTrace();
//printLog("STDERR", ex);
printLog("STDOUT","Inside Exception [getLog]>>" + ex.toString(),siteCode);
}
finally
{
try
{
conn.close();
conn = null;
}
catch(Exception e){}
try
{
if (fileWriter != null)
{
fileWriter.flush();
fileWriter.close();
}
}
catch (Exception e)
{
e.printStackTrace();
//printLog("STDERR", e);
}
}
}
String checkNull(String value){
if(value==null){
value= "";
}
return value;
}
public String getErrorMessageDescription(String errorCode) throws RemoteException, ITMException
{
Statement stmt = null;
ResultSet rs = null;
Connection conn=null;
String msgType="";
String msgString="";
try{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB();
String sqlQuery = "SELECT MSG_TYPE,MSG_STR,MSG_DESCR,MSG_OPT,MSG_TIME,ALARM,ERR_SOURCE FROM MESSAGES WHERE MSG_NO='" + errorCode + "'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sqlQuery);
if (rs.next())
{
msgType = rs.getString("MSG_TYPE");
msgString = rs.getString("MSG_STR");
}
else
{
msgString = "Message Not Defined >>";
msgType = "E";
msgString = "";
}
stmt.close();
stmt=null;
rs.close();
rs=null;
}
catch (SQLException e)
{
//printLog("E-way Bill Failed", "SQL Sytax is Incorrect for Ref-Ser :"+,"ERROR");
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
catch (Exception e)
{
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
finally
{
try
{
conn.close();
conn = null;
}
catch(Exception e){}
}
return msgType+","+msgString;
}
}
package ibase.webitm.ejb.dis.adv;
import java.io.File;
import java.io.FileWriter;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateless;
import org.apache.commons.io.FileUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.fasterxml.jackson.databind.ObjectMapper;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.utility.EMail;
import ibase.utility.MailInfo;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.ejb.dis.DistCommon;
//import ibase.webitm.ejb.dis.adv.ItemDetails;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.TransIDGenerator;
@Stateless
public class EwaybillPrc extends ProcessEJB implements EwaybillPrcLocal,EwaybillPrcRemote {
private String generatedTransactionId="";
private String siteCodes="";
private String loginCode="";
private String logFileNames="", mailLogFileName = "";
private String logDires="";
private List<Transaction> tranIdList=new ArrayList<Transaction>();
SimpleDateFormat sdf=null;
@Override
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams)
throws RemoteException, ITMException {
String rtrStr="";
Document headerDom=null;
Document detailDom=null;
// GenericUtility genericUtility = GenericUtility.getInstance();
System.out.println("Calling getData method......");
try{
E12GenericUtility genericUtility= new E12GenericUtility();
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
Timestamp currDateTs = new Timestamp(System.currentTimeMillis());
if ((xmlString != null) && (xmlString.trim().length() != 0))
{
System.out.println("XML String :" + xmlString);
headerDom = genericUtility.parseString(xmlString);
}
if ((xmlString2 != null) && (xmlString2.trim().length() != 0))
{
System.out.println("XML String :" + xmlString2);
detailDom = genericUtility.parseString(xmlString2);
}
rtrStr = getData(headerDom, detailDom, windowName, xtraParams);
}
catch (Exception e)
{
System.out
.println("Exception :getData(String xmlString, String xmlString2, String windowName, String xtraParams):"
+ e.getMessage() + ":");
rtrStr = e.getMessage();
}
return rtrStr;
}
public String getData(Document dom, Document dom2, String windowName, String xtraParams)
throws RemoteException, ITMException
{
String resultString="";
String sql="",objName="",argumentString="",jrxmlName="",tranSerOld="";
String sqlExpr="",sqlExpr1="",sqlExpr2="",sqlExpr3="",sqlExpr4="",sqlExpr5="",sqlExpr6="",errfilePath="";
String compSql="";
PreparedStatement pstmt = null,pstmt1=null;
ResultSet rs = null,rs1=null ;
String balGroup="EWAY",dateFromString="",dateToString="";
Connection conn = null;
//GenericUtility genericUtility = GenericUtility.getInstance();
E12GenericUtility genericUtility= new E12GenericUtility();
try {
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Timestamp currDateTs = new Timestamp(System.currentTimeMillis());
Timestamp dateFrom = null;
Timestamp dateTo = null;
StringBuffer xmlStringBuffer = new StringBuffer();
//screen retrieval values
String siteCode="",tranSer="",sundryCodeFr="",sundryCodeTo="",tranDateFr="",tranDateTo="",invValue="",supplyType="";
//display screen values
String tranSerRet="",userId="",tranDate = "",tranId="",gpNp="",toPartyDesc="",toPlace="",pincode="",gstnno="",docType="";
String transMode = "",vehicleType = "",transPorterName="";
Timestamp tran_date = null;
double invAmt=0.0d,asseblValue = 0.0d,distance = 0.0d;
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
String errString = "";
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "user_id");
loginCode=genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
siteCode=genericUtility.getColumnValue("site_code", dom2);
siteCodes = siteCode;
tranSer=genericUtility.getColumnValue("tran_ser", dom2);
sundryCodeFr=genericUtility.getColumnValue("sundry_code_fr", dom2);
sundryCodeTo=genericUtility.getColumnValue("sundry_code_to", dom2);
tranDateFr=genericUtility.getColumnValue("tran_date_fr", dom2);
tranDateTo=genericUtility.getColumnValue("tran_date_to", dom2);
invValue=genericUtility.getColumnValue("inv_value", dom2);
supplyType=genericUtility.getColumnValue("state", dom2);
try
{
/*ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB();*/
conn = getConnection();
xmlStringBuffer = new StringBuffer("<?xml version = \"1.0\"?>");
xmlStringBuffer.append("<DocumentRoot>");
xmlStringBuffer.append("<description>").append("Datawindow Root").append("</description>");
xmlStringBuffer.append("<group0>");
xmlStringBuffer.append("<description>").append("Group0 description").append("</description>");
xmlStringBuffer.append("<Header0>");
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
java.util.Date currentDate = new java.util.Date();
String todaysDate=sdf.format(currentDate);
System.out.println("Current date is :"+todaysDate);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getDBDateFormat());
tranDateFr = genericUtility.getValidDateString(tranDateFr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat());
dateFrom = java.sql.Timestamp.valueOf(tranDateFr + " 00:00:00");
dateFromString = simpleDateFormat.format(dateFrom);
tranDateTo = genericUtility.getValidDateString(tranDateTo, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat());
dateTo = java.sql.Timestamp.valueOf(tranDateTo + " 00:00:00");
tranDateTo = simpleDateFormat.format(dateTo);
String[] tranSerArray=tranSer.split(",");
for(int i=0;i<tranSerArray.length;i++){
if(i==tranSerArray.length-1)
{
tranSerOld=tranSerOld+("'"+tranSerArray[i].trim()+"'");
}
else
{
tranSerOld=tranSerOld+("'"+tranSerArray[i].trim()+"',");
}
}
int dataCounter=0;
sql="select line_no,sql_expr,sql_input,sql_expr1,sql_expr2,sql_expr3,sql_expr4,"
+ " sql_expr5,sql_expr6 from tax_bal_grp_det where bal_group=? and ref_ser in ("+tranSerOld.trim()+")";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, balGroup);
rs=pstmt.executeQuery();
while(rs.next()){
sqlExpr= checkNull(rs.getString("sql_expr"));
sqlExpr1= checkNull(rs.getString("sql_expr1"));
sqlExpr2= checkNull(rs.getString("sql_expr2"));
sqlExpr3= checkNull( rs.getString("sql_expr3"));
sqlExpr4= checkNull(rs.getString("sql_expr4"));
sqlExpr5= checkNull(rs.getString("sql_expr5"));
sqlExpr6= checkNull(rs.getString("sql_expr6"));
compSql= sqlExpr+" "+sqlExpr1+" "+sqlExpr2+" "+sqlExpr3+" "+sqlExpr4+" "+sqlExpr5+" "+sqlExpr6;
System.out.println("Combine SQL::::"+compSql);
if(compSql!=null && compSql.trim().length() > 0 )
{
pstmt1=conn.prepareStatement(compSql);
pstmt1.setString(1, siteCode);
pstmt1.setTimestamp(2, dateFrom);
pstmt1.setTimestamp(3, dateTo);
pstmt1.setString(4, sundryCodeFr);
pstmt1.setString(5, sundryCodeTo);
pstmt1.setInt(6, Integer.parseInt(invValue));
pstmt1.setString(7, supplyType);
pstmt1.setString(8,supplyType);
rs1=pstmt1.executeQuery();
while(rs1.next()){
tranSerRet=rs1.getString("tran_ser");
tran_date=rs1.getTimestamp("tran_date");
if(tran_date!=null){
tranDate=genericUtility.getValidDateString(tran_date.toString(), genericUtility.getDBDateFormat(), genericUtility.getApplDateFormat());
}
else{
tranDate="";
}
tranId=rs1.getString("tran_id");
gpNp=rs1.getString("gp_no");
toPartyDesc=rs1.getString("to_party_descr");
invAmt=rs1.getDouble("inv_amt");
asseblValue=rs1.getDouble("assesable_value");
distance=rs1.getDouble("distance");
pincode=rs1.getString("pincode");
gstnno=rs1.getString("gstnno");
/*if(gstnno == null || gstnno.trim().length() == 0 || "null".equalsIgnoreCase(gstnno))
{
continue;
}*/
docType=rs1.getString("doctype");
transMode=rs1.getString("trans_mode");
vehicleType=rs1.getString("vehicle_type");
transPorterName=rs1.getString("transporter_name");
xmlStringBuffer.append("<Detail2>");
xmlStringBuffer.append("<tran_ser>").append("<![CDATA[").append(tranSerRet).append("]]>").append("</tran_ser>");
xmlStringBuffer.append("<tran_date>").append("<![CDATA[").append(tranDate).append("]]>").append("</tran_date>");
xmlStringBuffer.append("<tran_id>").append("<![CDATA[").append(tranId).append("]]>").append("</tran_id>");
xmlStringBuffer.append("<gp_no>").append("<![CDATA[").append(gpNp).append("]]>").append("</gp_no>");
xmlStringBuffer.append("<to_party_descr>").append("<![CDATA[").append(toPartyDesc).append("]]>").append("</to_party_descr>");
//xmlStringBuffer.append("<to_place>").append("<![CDATA[").append(toPlace).append("]]>").append("</to_place>");
xmlStringBuffer.append("<trans_name>").append("<![CDATA[").append("").append("]]>").append("</trans_name>");
xmlStringBuffer.append("<trans_mode>").append("<![CDATA[").append(transMode==null?"R":transMode).append("]]>").append("</trans_mode>");
xmlStringBuffer.append("<trans_doc_id>").append("<![CDATA[").append("").append("]]>").append("</trans_doc_id>");
xmlStringBuffer.append("<trans_doc_date>").append("<![CDATA[").append(todaysDate).append("]]>").append("</trans_doc_date>");
xmlStringBuffer.append("<vehicle_no>").append("<![CDATA[").append("").append("]]>").append("</vehicle_no>");
xmlStringBuffer.append("<distance>").append("<![CDATA[").append(distance).append("]]>").append("</distance>");
xmlStringBuffer.append("<invoice_amt>").append("<![CDATA[").append(invAmt).append("]]>").append("</invoice_amt>");
xmlStringBuffer.append("<assesable_value>").append("<![CDATA[").append(asseblValue).append("]]>").append("</assesable_value>");
xmlStringBuffer.append("<pincode>").append("<![CDATA[").append(pincode).append("]]>").append("</pincode>");
xmlStringBuffer.append("<gstnno>").append("<![CDATA[").append(gstnno).append("]]>").append("</gstnno>");
xmlStringBuffer.append("<doc_type>").append("<![CDATA[").append(docType).append("]]>").append("</doc_type>");
xmlStringBuffer.append("</Detail2>");
dataCounter++;
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
}
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
if(dataCounter==0){
printLog("No Data Found", "Please Enter Valid Query to Return data","ERROR"); //this will write on log file for no data is found
errString = itmDBAccessEJB.getErrorString("","VTNODATA",userId,"",conn);
System.out.println("process completed .."+errString);
return errString;
}
xmlStringBuffer.append("</Header0>");
xmlStringBuffer.append("</group0>");
xmlStringBuffer.append("</DocumentRoot>");
resultString = xmlStringBuffer.toString();
System.out.println("@narendra Final xml string : "+resultString);
}
catch (SQLException e)
{
printLog("E-way Bill Failed", "SQL Sytax is Incorrect for Ref-Ser :"+tranSerOld,"ERROR");
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
catch (Exception e)
{
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
finally
{
try
{
conn.close();
conn = null;
}
catch(Exception e){}
}
return resultString;
}
private String checkNull(String input) {
if (input == null) {
input = "";
}
return input.trim();
}
@Override
public String process(String xmlString, String xmlString1, String windowName, String xtraParams)
throws RemoteException, ITMException {
System.out.println("Inside process method");
// TODO Auto-generated method stub
//calling values inside the test process.... done
//make log file which will shows the log generated while processing the data.... done
//while processing the data insert the data inside the GST_DATA_HDR as well as inside the GST_DATA_DET
//query is already created we just have to use that built in query inside the code..
//json file will be generated using that sql which will be inside the tax bal grp det table
String retStr = "";
Document detailDom = null;
Document headerDom = null;
// GenericUtility genericUtility = GenericUtility.getInstance();
System.out.println(
"below genericUtility--------------->>>>>>>>>");
try {
E12GenericUtility genericUtility= new E12GenericUtility();
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
Timestamp currDateTs = new Timestamp(System.currentTimeMillis());
System.out.println("Process Method xmlString = " + xmlString);
System.out.println("Process Method xmlString1 = " + xmlString1);
if ((xmlString != null) && (xmlString.trim().length() != 0))
{
headerDom = genericUtility.parseString(xmlString);
System.out.println("headerDom === " + headerDom);
}
if ((xmlString1 != null) && (xmlString1.trim().length() != 0))
{
detailDom = genericUtility.parseString(xmlString1);
System.out.println("detailDom === " + detailDom);
}
retStr = process(headerDom, detailDom, windowName, xtraParams);
} catch (Exception e)
{
printLog("E-way Bill Failed", "Error occured during Processing the data","ERROR");
System.out
.println("Exception :process(String xmlString, String xmlString2, String windowName, String xtraParams):"
+ e.getMessage() + ":");
e.printStackTrace();
retStr = e.getMessage();
throw new ITMException(e);
}
return retStr;
}
@Override
public String process(Document dom, Document dom2, String windowName, String xtraParams)
throws RemoteException, ITMException
{
// TODO Auto-generated method stub
// GenericUtility genericUtility = GenericUtility.getInstance();
String errString="";
String errCode="";
Connection conn = null;
String refSer="",tranId="";
try{
E12GenericUtility genericUtility= new E12GenericUtility();
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
Timestamp currDateTs = new Timestamp(System.currentTimeMillis());
/*ConnDriver connDriver = new ConnDriver();
conn=connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);*/
conn = getConnection();
refSer=genericUtility.getColumnValue("tran_ser", dom2);
tranId=genericUtility.getColumnValue("tran_id",dom2);
System.out.println("@ref ser:"+refSer+" @invoiceId:"+tranId);
loginCode=genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
errString=executeGSTHdrAndGSTDetQuery(dom,dom2,xtraParams,conn);
}catch (SQLException e)
{
System.out.println("Exception :BankReconciliationEJB :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
catch (Exception e)
{
System.out.println("Exception :BankReconciliationEJB :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
finally
{
try
{
conn.close();
conn = null;
}
catch(Exception e){}
}
return errString;
}
public String executeGSTHdrAndGSTDetQuery(Document dom,Document dom2,String xtraParams,Connection conn){
String errString="";
Node currDetail = null;
int noOfDetails = 0;
NodeList detailList = null;
NodeList detailNodeList = null;
Node detailNode = null;
int lltrue = 0;
int nodeListLength=0;
String tranId="";
String refSer="";
String distance="";
String transporterName="";
String transId="";
String transMode="";
String transDocNo="";
String transDocDate="";
String vehicleType="";
String vehicleNo="";
//E12GenericUtility genericUtility = E12GenericUtility.getInstance();
ArrayList dataList=new ArrayList();
HashMap<String,String> transDetailMap=new HashMap<String,String>();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
String siteCode="";
File logFilePath=null;
File copyFilePath=null;
File copyLogFilePath=null;
boolean mailSent;
PreparedStatement pstmt = null,pstmt1 = null;
ResultSet rs = null,rs1 = null ;
String sql="";
String emailAddr="";
try{
E12GenericUtility genericUtility= new E12GenericUtility();
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
Timestamp currDateTs = new Timestamp(System.currentTimeMillis());
DistCommon distCommon = new DistCommon();//Modified by Ahmed on 13/06/2019 to set log path
siteCode=genericUtility.getColumnValue("site_code", dom);
siteCodes=siteCode;
setLogFile(conn);//Modified by Ahmed on 13/06/2019 to set log path
detailList = dom2.getElementsByTagName( "Detail2" );
noOfDetails = detailList.getLength();
detailNodeList = dom2.getElementsByTagName("Detail2");
nodeListLength = detailNodeList.getLength();
System.out.println("nodeListLength" + nodeListLength);
for(int n = 0;n < nodeListLength;n++)
{
try
{
detailNode = detailNodeList.item(n);
tranId=genericUtility.getColumnValueFromNode("tran_id", detailNode);
refSer=genericUtility.getColumnValueFromNode("tran_ser", detailNode);
distance=genericUtility.getColumnValueFromNode("distance", detailNode);
transporterName=genericUtility.getColumnValueFromNode("trans_name", detailNode);
transMode=genericUtility.getColumnValueFromNode("trans_mode", detailNode);
transId=genericUtility.getColumnValueFromNode("trans_id", detailNode);
transDocNo=genericUtility.getColumnValueFromNode("trans_doc_id", detailNode);
transDocDate=genericUtility.getColumnValueFromNode("trans_doc_date", detailNode);
vehicleType="R"; //default value for the vehicle is regular holding suffix variable as the 'R'
vehicleNo=genericUtility.getColumnValueFromNode("vehicle_no", detailNode);
transDetailMap.put("distance", distance);
transDetailMap.put("trans_name", transporterName);
transDetailMap.put("trans_mode", transMode);
transDetailMap.put("trans_id", getTransId(transporterName,conn));
transDetailMap.put("trans_doc", transDocNo);
transDetailMap.put("trans_doc_date", transDocDate);
transDetailMap.put("vehicle_type", vehicleType);
transDetailMap.put("vehicle_no", vehicleNo);
dataList.add(transDetailMap);
errString=insertDataInGstHdrAndDetail(tranId,refSer,dataList, conn);
System.out.println(genericUtility.getColumnValueFromNode("tran_id", detailNode));
}
catch(Exception e)
{
e.printStackTrace();
}
}
dataList.clear();
//generating json file eway bill
/*if(errString.indexOf("CONFSUCCES") > -1 || errString.indexOf("Success") > -1 )
{*/
System.out.println("inside after insertion of the data inside HDR and DET");
System.out.println("Generated Transaction List id is:"+generatedTransactionId);
if(tranIdList.size()>0){
errString= generateJSONFileForEway(tranIdList,siteCode,xtraParams,conn);
}
else{
try{
sql="select email_id from users where code= ? ";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, loginCode.trim());
rs=pstmt.executeQuery();
while(rs.next()){
emailAddr=rs.getString("email_id");
}
}
catch(SQLException e){
e.printStackTrace();
}
if(rs!=null){
rs.close();
rs=null;
}
if(pstmt!=null){
pstmt.close();
pstmt=null;
}
System.out.println("Log Dire:"+logDires+" Log File:"+logFileNames);
copyLogFilePath = new File(logDires + File.separator +"temp");
if(!copyLogFilePath.exists()) {
copyLogFilePath.mkdir();
}
else if(copyLogFilePath.exists())
{
try
{
FileUtils.cleanDirectory(copyLogFilePath);
}
catch(Exception exp)
{
exp.printStackTrace();
}
}
logFilePath=new File(logDires+File.separator+logFileNames+".log");
//logFilePath=new File(logDires+File.separator+mailLogFileName+".log");//Modified by Ahmed on 13/06/2019
try
{
FileUtils.copyFileToDirectory(logFilePath, copyLogFilePath);
mailSent= sendMailLog("",copyLogFilePath+File.separator+logFileNames+".log",getDomString(emailAddr),false);
//mailSent= sendMailLog("",copyLogFilePath+File.separator+mailLogFileName+".log",getDomString(emailAddr),false);//Modified by Ahmed on 13/06/2019
if(mailSent)
{
printMailLog("Log file Mail Send succesfully to "+emailAddr +" to Login Code-"+loginCode, "Mail Send Successfully!"+refSer,"SUCCESS");
System.out.println("Succesfully send the mail");
}else
{
printMailLog("Mail Send Failed to "+loginCode, "Mail Send Failed!"+refSer,"FAILED");//GENERATE LOG
System.out.println("failure while sending the mail");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
System.out.println("error message return by the data:"+errString);
if(errString.indexOf("CONFSUCCES") > -1 || errString.indexOf("Success") > -1 )
{
tranIdList.clear();
conn.commit();
errString = itmDBAccessEJB.getErrorString("","VPSUCC1","","",conn);
System.out.println("inside the successfully insertion of the data");
}
else
{
//generatedTransactionId.clear();
//itemList.clear();
conn.rollback();
System.out.println("#####Error String is" + errString);
errString = itmDBAccessEJB.getErrorString("","VTEPFAIL","","",conn);
}
/*}
else
{
//generatedTransactionId.clear();
conn.rollback();
System.out.println("#####Error String is" + errString);
errString = itmDBAccessEJB.getErrorString("","VTEPFAIL","","",conn);
}*/
}
catch (Exception sqx)
{
System.out.println("The SQLException occurs in EWayBillPrc GST HDR detail insertion :"+sqx);
sqx.printStackTrace();
//throw new ITMException(sqx);
}
finally{
try{
}
catch(Exception e){}
}
detailList = dom2.getElementsByTagName( "Detail2" );
noOfDetails = detailList.getLength();
return errString;
}
public String insertDataInGstHdrAndDetail(String tranId,String refSer,ArrayList list,Connection conn)throws RemoteException, ITMException
{
String errString="";
String sql="";
//inserting data query inside GST hdr and GST detail so that we can use that data for JSON formation
PreparedStatement pstmt = null,pstmt1=null,pstmt2=null,pstmt3=null;
ResultSet rs = null,rs1=null,rs3=null ;
String sqlExpr="",sqlExpr1="",sqlExpr2="",sqlExpr3="",sqlExpr4="",sqlExpr5="",sqlExpr6="",errfilePath="";
String compSql="";
String tranID="";//this variable holds the whole transaction id
String windowName="w_ewaybill_prc";
String keyString="",tranSer="",keyCol="";
//GST_DATA_HDR variables...
String tran_id="",tran_id__ref="",site_code="",prd_code="",rec_type="",
tran_type="",cust_code="",cust_name="",submission_type="",doc_checksum="",doc_type="",doc_no="",reverse_chrg="",lr_no="",
reas_code="",ref_id__inv="",prov_assmnt="",order_no="",remarks="",submit_status="",add_user="",
add_term="",chg_user="",chg_term="",tax_reg_no="",reco_status="",ecom_reg_no="",ref_ser="",gst_code="",gst_type="",ref_id="";
double amount=0.0;
Timestamp docDate=null,lr_date=null,ref_date__inv=null,order_date=null,submit_date=null;
Timestamp add_date=null,chg_date=null;
String distance="",transporterName="",transId="",transMode="",transModes="",transDocNo="",transDocDate="",vehicleType="",vehicleNo="";
Timestamp docDates=null;
//GST_DATA_DET variables...
String status="",line_type="",gs_code="",gs_descr="",unit="",supply_type="",itc_type="";
int sr_no__old=0,line_no;
double taxable_amt=0.0,igst_perc=0.0,igst_amt=0.0,cgst_perc=0.0,cgst_amt=0.0,sgst_perc=0.0,sgst_amt=0.0;
double quantity=0.0,cess_perc=0.0,cess_amt=0.0,itc_igst=0.0,itc_cgst=0.0,itc_sgst=0.0,itc_cess=0.0,gst_rate=0.0;
String product_name="",productDesc="",hsnCode="",qtyUnit="";
double prodtQty=0.0,taxableAmount=0.0,cessNonAdvol=1.0;//default value setted for cess non advol
int returnHdr=0,returnData=0;
//GenericUtility genericUtility=GenericUtility.getInstance();
int lineno=0;
Transaction transaction=null;
try
{
E12GenericUtility genericUtility= new E12GenericUtility();
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
Timestamp currDateTs = new Timestamp(System.currentTimeMillis());
SimpleDateFormat sdf = null;
java.util.Date currentDate = new java.util.Date();
sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
SimpleDateFormat sdfBillDate = new SimpleDateFormat(genericUtility.getApplDateFormat());
Timestamp tranDate = java.sql.Timestamp.valueOf( sdf.format(currentDate)+" 00:00:00.0");
System.out.println("Process for Transaction id ::"+tranId+" : "+refSer);
System.out.println(list.size());
HashMap transMap = (HashMap)list.get(0);
Iterator<String> itr = transMap.keySet().iterator();
while (itr.hasNext())
{
String key = itr.next();
String value = (String) transMap.get(key);
System.out.println(key + "=" + value);
}
distance=checkNull((String)transMap.get("distance"));
transporterName=checkNull((String)transMap.get("trans_name"));
transMode=checkNull((String)transMap.get("trans_mode"));
transId=checkNull((String)transMap.get("trans_id"));
transDocNo=checkNull((String)transMap.get("trans_doc"));
transDocDate=checkNull((String)transMap.get("trans_doc_date"));
vehicleType=checkNull((String)transMap.get("vehicle_type"));
vehicleNo=checkNull((String)transMap.get("vehicle_no"));
System.out.println("retrived value of the date for transaction is as:"+new SimpleDateFormat("dd/MM/yy").parse(transDocDate).toString());
//converting value of transaction date into database formate form.
Timestamp transsDocDate=java.sql.Timestamp.valueOf( sdf.format(new SimpleDateFormat("dd/MM/yy").parse(transDocDate))+" 00:00:00.0");
System.out.println("transaction document date:"+transsDocDate);
sql = "SELECT KEY_STRING, TRAN_ID_COL, REF_SER FROM TRANSETUP WHERE TRAN_WINDOW= ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString( 1, windowName );
rs = pstmt.executeQuery();
if (rs.next())
{
keyString = rs.getString("KEY_STRING");
keyCol = rs.getString("TRAN_ID_COL");
tranSer = rs.getString("REF_SER");
}
rs.close();rs = null;
pstmt.close();pstmt = null;
System.out.println("keyString :"+keyString);
System.out.println("keyCol :"+keyCol);
System.out.println("tranSer :"+tranSer);
String xmlValues = "";
xmlValues ="<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
xmlValues = xmlValues + "<Header></Header>";
xmlValues = xmlValues + "<Detail1>";
xmlValues = xmlValues + "<site_code>" +site_code +"</site_code>";
xmlValues = xmlValues + "<tran_date>"+tranDate +"</tran_date>";
xmlValues = xmlValues + "</Detail1></Root>";
System.out.println("xmlValues :["+xmlValues+"]");
TransIDGenerator tg = new TransIDGenerator(xmlValues, "BASE", CommonConstants.DB_NAME);
tranID = tg.generateTranSeqID(tranSer, keyCol, keyString, conn);
generatedTransactionId=tranID;
System.out.println("tranId :"+tranID);
transaction=new Transaction(tranID, refSer);
if(refSer.trim().equals("S-INV")){
lineno=1;
}
if(refSer.trim().equals("D-ISS")){
lineno=2;
}
if(refSer.trim().equals("P-RET")){
lineno=3;
}
if(refSer.trim().equals("C-ISS")){
lineno=4;
}
sql="select line_no,sql_expr,sql_input,sql_expr1,sql_expr2,sql_expr3,sql_expr4,"
+ " sql_expr5,sql_expr6 from tax_bal_grp_det where bal_group=? and ref_ser = '"+refSer+"' and line_no="+lineno+"";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, "EWAYH");
rs=pstmt.executeQuery();
while(rs.next()){
sqlExpr= checkNull(rs.getString("sql_expr"));
sqlExpr1= checkNull(rs.getString("sql_expr1"));
sqlExpr2= checkNull(rs.getString("sql_expr2"));
sqlExpr3= checkNull( rs.getString("sql_expr3"));
sqlExpr4= checkNull(rs.getString("sql_expr4"));
sqlExpr5= checkNull(rs.getString("sql_expr5"));
sqlExpr6= checkNull(rs.getString("sql_expr6"));
compSql= sqlExpr+" "+sqlExpr1+" "+sqlExpr2+" "+sqlExpr3+" "+sqlExpr4+" "+sqlExpr5+" "+sqlExpr6;
System.out.println("Combine SQL GST HDR ::::"+compSql);
if(compSql!=null && compSql.trim().length() > 0 )
{
System.out.println("inside the insert GST HDR details");
pstmt1=conn.prepareStatement(compSql);
pstmt1.setString(1, tranId);
rs1=pstmt1.executeQuery();
while(rs1.next()){
tran_id=rs1.getString("tran_id");
tran_id__ref=rs1.getString("tran_id__ref");
site_code=rs1.getString("site_code");
prd_code=rs1.getString("prd_code");
rec_type=rs1.getString("rec_type");
gst_type=rs1.getString("gst_type");
tran_type=rs1.getString("tran_type");
cust_code=rs1.getString("cust_code");
cust_name=rs1.getString("cust_name");
gst_code=rs1.getString("gst_code");
submission_type=rs1.getString("submission_type");
doc_checksum=rs1.getString("doc_checksum");
doc_type=rs1.getString("doc_type");
doc_no=rs1.getString("doc_no");
amount=rs1.getDouble("amount");
reverse_chrg=rs1.getString("reverse_chrg");
lr_no=rs1.getString("lr_no");
reas_code=rs1.getString("reas_code");
ref_id__inv=rs1.getString("ref_id__inv");
prov_assmnt=rs1.getString("prov_assmnt");
order_no=rs1.getString("order_no");
remarks=rs1.getString("remarks");
ref_id=rs1.getString("ref_id");
submit_status=rs1.getString("submit_status");
add_user=rs1.getString("add_user");
add_term=rs1.getString("add_term");
chg_user=rs1.getString("chg_user");
chg_term=rs1.getString("chg_term");
tax_reg_no=rs1.getString("tax_reg_no");
reco_status=rs1.getString("reco_status");
ecom_reg_no=rs1.getString("ecom_reg_no");
ref_ser=rs1.getString("ref_ser");
docDates=rs1.getTimestamp("doc_date");
//mapping attribute with DocType
sql="select descr from genmst where fld_name=?";
pstmt3 = conn.prepareStatement(sql);
pstmt3.setString(1, doc_type.trim());
rs3=pstmt3.executeQuery();
if(rs3.next()){
doc_type=checkNull(rs3.getString("descr"));
}
pstmt3.close();
pstmt3=null;
rs3.close();
rs3=null;
//mapping attribute with transMode
sql="select descr from genmst where fld_name=? ";
pstmt3 = conn.prepareStatement(sql);
pstmt3.setString(1, transMode.trim());
rs3=pstmt3.executeQuery();
if(rs3.next()){
transModes=checkNull(rs3.getString("descr"));
}
pstmt3.close();
pstmt3=null;
rs3.close();
rs3=null;
//inserting above details inside GST_DATA_HDR tables....
sql="insert into GST_DATA_HDR(tran_id,tran_date,tran_id__ref,site_code,prd_code,rec_type,"
+ "tran_type,cust_code,cust_name,submission_type,doc_checksum,doc_type,doc_no,doc_date,amount,reverse_chrg,lr_no,"
+ "lr_date,reas_code,ref_id__inv,ref_date__inv,prov_assmnt,order_no,order_date,remarks,submit_status,submit_date,add_user,add_date,"
+ "add_term,chg_user,chg_date,chg_term,tax_reg_no,reco_status,ecom_reg_no,ref_ser,gst_code,gst_type,ref_id,distance,trans_code,trans_mode,trans_id,trans_doc_id,vehicle_type,trans_doc_date,vehicle_no"
+ ") values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
System.out.println("insertSql : "+sql);
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, tranID);
pstmt2.setTimestamp(2, tranDate);
pstmt2.setString(3, tran_id__ref);
pstmt2.setString(4, site_code);
pstmt2.setString(5, prd_code);
pstmt2.setString(6, rec_type);
pstmt2.setString(7, tran_type);
pstmt2.setString(8, cust_code);
pstmt2.setString(9, cust_name);
pstmt2.setString(10, submission_type);
pstmt2.setString(11, doc_checksum);
pstmt2.setString(12, doc_type);
pstmt2.setString(13, doc_no);
pstmt2.setTimestamp(14, docDates);
pstmt2.setDouble(15, amount);
pstmt2.setString(16, reverse_chrg);
pstmt2.setString(17, lr_no);
pstmt2.setTimestamp(18, lr_date);
pstmt2.setString(19, reas_code);
pstmt2.setString(20, ref_id__inv);
pstmt2.setTimestamp(21, ref_date__inv);
pstmt2.setString(22, prov_assmnt);
pstmt2.setString(23, order_no);
pstmt2.setTimestamp(24, order_date);
pstmt2.setString(25, remarks);
pstmt2.setString(26, submit_status);
pstmt2.setTimestamp(27, submit_date);
pstmt2.setString(28, add_user);
pstmt2.setTimestamp(29, add_date);//add_term,chg_user,chg_date,chg_term,tax_reg_no,reco_status,ecom_reg_no,ref_ser,gst_code,gst_type,ref_id
pstmt2.setString(30, add_term);
pstmt2.setString(31, chg_user);
pstmt2.setTimestamp(32, chg_date);
pstmt2.setString(33, chg_term);
pstmt2.setString(34, tax_reg_no);
pstmt2.setString(35, reco_status);
pstmt2.setString(36, ecom_reg_no);
pstmt2.setString(37, ref_ser);
pstmt2.setString(38, gst_code);
pstmt2.setString(39, gst_type);
pstmt2.setString(40,ref_id);
pstmt2.setDouble(41, Double.parseDouble(distance));
pstmt2.setString(42,transporterName);
pstmt2.setString(43,checkNull(transModes));
pstmt2.setString(44,transId);
pstmt2.setString(45,transDocNo);
pstmt2.setString(46,vehicleType);
pstmt2.setTimestamp(47, transsDocDate);
pstmt2.setString(48,vehicleNo);
int a= pstmt2.executeUpdate();
if(a==0){
System.out.println("Process failed INSERT into ..................");
errString="VTEPFAIL";
//return errString;
}
else{
System.out.println("Process sucessfully INSERT into ..................");
errString="CONFSUCCES";
}
//closing the prepared statment here for both the insert statement...
pstmt2.close();
pstmt2=null;
returnHdr++;
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
if(returnHdr<=0){
printLog("E-way Bill Failed", "No Data Found for Inserting in GST HEADER details for Transaction Id:"+tranId,"ERROR");
}
}
/*sql="insert into GST_DATA_HDR(tran_id,tran_date,tran_id__ref,site_code,prd_code,rec_type,"
+ "tran_type,cust_code,cust_name,submission_type,doc_checksum,doc_type,doc_no,doc_date,amount,reverse_chrg,lr_no,"
+ "lr_date,reas_code,ref_id__inv,ref_date__inv,prov_assmnt,order_no,order_date,remarks,submit_status,submit_date,add_user,add_date,"
+ "add_term,chg_user,chg_date,chg_term,tax_reg_no,reco_status,ecom_reg_no,ref_ser,gst_code,gst_type,ref_id"
+ ") values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
sql="insert into GST_DATA_DET() values()";*/
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
//DETAIL BLOCKS START FROM HERE....
if(returnHdr>0)
{
sql="select line_no,sql_expr,sql_input,sql_expr1,sql_expr2,sql_expr3,sql_expr4,"
+ " sql_expr5,sql_expr6 from tax_bal_grp_det where bal_group=? and ref_ser = '"+refSer+"' and line_no="+lineno+"";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, "EWAYD");
rs=pstmt.executeQuery();
while(rs.next()){
sqlExpr= checkNull(rs.getString("sql_expr"));
sqlExpr1= checkNull(rs.getString("sql_expr1"));
sqlExpr2= checkNull(rs.getString("sql_expr2"));
sqlExpr3= checkNull( rs.getString("sql_expr3"));
sqlExpr4= checkNull(rs.getString("sql_expr4"));
sqlExpr5= checkNull(rs.getString("sql_expr5"));
sqlExpr6= checkNull(rs.getString("sql_expr6"));
compSql= sqlExpr+" "+sqlExpr1+" "+sqlExpr2+" "+sqlExpr3+" "+sqlExpr4+" "+sqlExpr5+" "+sqlExpr6;
System.out.println("Combine SQL GST DET ::::"+compSql);
if(compSql!=null && compSql.trim().length() > 0 )
{
System.out.println("inside the insert GST DET details");
pstmt1=conn.prepareStatement(compSql);
pstmt1.setString(1, tranId);
rs1=pstmt1.executeQuery();
while(rs1.next()){
tran_id=rs1.getString("tran_id");
line_no=rs1.getInt("line_no");
status=rs1.getString("status");
sr_no__old=rs1.getInt("sr_no__old");
line_type=rs1.getString("line_type");
gs_code=rs1.getString("gs_code");
taxable_amt=rs1.getDouble("taxable_amt");
igst_perc=rs1.getDouble("igst_perc");
igst_amt=rs1.getDouble("igst_amt");
cgst_perc=rs1.getDouble("cgst_perc");
cgst_amt=rs1.getDouble("cgst_amt");
sgst_perc=rs1.getDouble("sgst_perc");
sgst_amt=rs1.getDouble("sgst_amt");
gs_descr=rs1.getString("gs_descr");
unit=rs1.getString("unit");
quantity=rs1.getDouble("quantity");
supply_type=rs1.getString("supply_type");
cess_perc=rs1.getDouble("cess_perc");
cess_amt=rs1.getDouble("cess_amt");
remarks=rs1.getString("remarks");
gst_rate=rs1.getDouble("gst_rate");
product_name=rs1.getString("item_name");
productDesc=rs1.getString("item_name");
hsnCode=rs1.getString("hsn_code");
/*prodtQty=rs1.getDouble("item_quantity");
qtyUnit=rs1.getString("unit");
taxableAmount=rs1.getDouble("taxable_amount");*/
//inserting the value inside GST_DATA_DET table.....
sql="insert into GST_DATA_DET(tran_id,line_no,status,sr_no__old,line_type,gs_code,taxable_amt,igst_perc,igst_amt,cgst_perc,cgst_amt,sgst_perc,sgst_amt,"
+ "gs_descr,unit,quantity,supply_type,cess_perc,cess_amt,remarks,itc_type,itc_igst,itc_cgst,itc_sgst,itc_cess,gst_rate)"
+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt2 = conn.prepareStatement(sql);
System.out.println("insertSql : "+sql);
pstmt2.setString(1, tranID);
pstmt2.setInt(2, line_no);
pstmt2.setString(3, status);
pstmt2.setInt(4, sr_no__old);
pstmt2.setString(5,line_type);
pstmt2.setString(6,gs_code);
pstmt2.setDouble(7,taxable_amt);
pstmt2.setDouble(8,igst_perc);
pstmt2.setDouble(9,igst_amt);
pstmt2.setDouble(10,cgst_perc);
pstmt2.setDouble(11,cgst_amt);
pstmt2.setDouble(12,sgst_perc);
pstmt2.setDouble(13,sgst_amt);
pstmt2.setString(14,gs_descr);
pstmt2.setString(15,unit);
pstmt2.setDouble(16,quantity);
pstmt2.setString(17,supply_type);
pstmt2.setDouble(18,cess_perc);
pstmt2.setDouble(19,cess_amt);
pstmt2.setString(20,remarks);
pstmt2.setString(21,itc_type);
pstmt2.setDouble(22,itc_igst);
pstmt2.setDouble(23,itc_cgst);
pstmt2.setDouble(24,itc_sgst);
pstmt2.setDouble(25,itc_cess);
pstmt2.setDouble(26,gst_rate);
int a= pstmt2.executeUpdate();
if(a==0){
System.out.println("Process failed INSERT into ..................");
errString="VTEPFAIL";
//return errString;
}
else{
System.out.println("Process sucessfully INSERT into ..................");
errString="CONFSUCCES";
}
//closing the prepared statment here for both the insert statement...
pstmt2.close();
pstmt2=null;
returnData++;
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
if(returnData<=0){
printLog("E-way Bill Failed", "No Data Found for Inserting in GST DETAIL details for Transaction Id:"+tranId,"ERROR");
errString="VTEPFAIL";
}
else{
if(validateJSONFileForEway(transaction,site_code,conn)){
tranIdList.add(transaction);
conn.commit();
}
else{
conn.rollback();
}
}
}
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
else{
printLog("E-way Bill Failed", "No Data Found for Inserting in GST DETAIL Detail for Transaction Id:"+tranId,"ERROR");
}
//closing result set and prepared statement
}
catch (SQLException e)
{
printLog("E-way Bill Failed", "SQL Sytax is Incorrect for Ref-Ser :"+refSer,"ERROR");
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
catch (Exception e)
{
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
finally
{
try{
if(errString.equals("VTEPFAIL")){
conn.rollback();
}
}catch(Exception e){
e.printStackTrace();
}
try
{
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)//if codn added by Jiten 19/05/06
{
rs.close();
rs = null;
}
if(pstmt2!=null){
pstmt2.close();
pstmt2 = null;
}
if (rs1 != null)//if codn added by Jiten 19/05/06
{
rs1.close();
rs1 = null;
}
}
catch(Exception e)
{
System.err.println("Exception :DBAccessEJB :getITMVersion :\n"+e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
}
return errString;
}
//generating JSON file for EWAY-BILL
public String generateJSONFileForEway(List<Transaction> tranId,String siteCode,String xtraParams,Connection con)throws RemoteException, ITMException{
PreparedStatement pstmt = null,pstmt1 = null;
ResultSet rs = null,rs1 = null ;
String sql="",refSer="E-WAY",refId="";
String sqlExpr="",sqlExpr1="",sqlExpr2="",sqlExpr3="",sqlExpr4="",sqlExpr5="",sqlExpr6="",errfilePath="";
String compSql="",compSql1="",compSql2="",compSql3="";
//variables which are holding the data for displaying the
String userGstin="",supplyType = "", docType="",docNo="",fromGstin="",toGstin="",fromTrdName="",
fromAddr1="",fromAddr2="",fromPlace="",docDateValue="";
String toTrdName="",toAddr1="",toAddr2="",toPlace="";
Timestamp docDate=null,transDocDate=null;
int frompinCode=0,toPincode=0,transType=0,subSupplyType = 0,actualFromStateCode=0,tostateCode=0,actualToStateCode=0,transMode=0,mainHsnCode=0;
double transDistance=0.0;
String sundryType="",transporterName="",transporterId="",transDocNo="",vehicleNo="",vehicleType="",assesable_value="";
//item details data holder values
int itemNo=0,quantity=0,cessNonAdvol=0,fromstateCode=0;
String productName="",productDescr="",qtyUnit="",hsnCode = "";
double sgstRate=0.0,cgstRate=0.0,igstRate=0.0,cessRate=0.0,taxableAmount=0.0;
double totalAssesableValue=0.0,totalValue=0.0,cgstValue=0.0,sgstValue=0.0,igstValue=0.0,cessValue=0.0,totNonAdvolVal=0.0,othValue=0.0,totInvValue=0,distance=0.0;
String errString="";
//data holder list which will use in creation of the JSON file data
List<EwayBillValue> list=new ArrayList<EwayBillValue>();
int valueCounter=0;
//GenericUtility genericUtility = GenericUtility.getInstance();
int index=0;
String transIdComma="";
String siteCodeArr[] = null;
String parameters = "";
boolean flag=true;
String groupByQuery="";
//lets use some dummy data for getting values inside the json file....
DistCommon distCommon = new DistCommon();
String dateFormat="";
String filePath="";
String logPath="";
String jsonFileVersion="";
String count="";
String transactionDocDate="";
String transporterid="";
File orgFilePath=null;
File logFilePath=null;
File copyFilePath=null;
File copyLogFilePath=null;
String loginCode="";
String transInfo="";
String emailAddr="";
boolean mailSent;
//List<ItemDetails> itemList=new ArrayList<ItemDetails>();
Map<String,Boolean> validatorMap=new HashMap<String,Boolean>();
List<Boolean> validatorList=new ArrayList<Boolean>();
try{
E12GenericUtility genericUtility= new E12GenericUtility();
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
Timestamp currDateTs = new Timestamp(System.currentTimeMillis());
//getting date format for ewaybill
dateFormat=distCommon.getDisparams("999999", "EWAY_DATE_FORM", con);
//getting file path for ewaybill
filePath=distCommon.getDisparams("999999", "EWAY_FILE_PATH", con);
//getting version of the json file
jsonFileVersion=distCommon.getDisparams("999999", "EWAY_JSON_VERSION", con);
setLogFile(con);//Modified by Ahmed on 13/06/2019 to set log path
System.out.println("Ewaybill date Format is:"+dateFormat);
System.out.println("generatedTransactionId:"+tranId);
for(int i=0;i<tranId.size();i++){
if(i==tranId.size()-1)
{
transIdComma=transIdComma+(""+tranId.get(i).getTranId()+"");
}
else
{
transIdComma=transIdComma+(""+tranId.get(i).getTranId()+",");
}
}
//System.out.println("generatedTransactionId:list:"+generatedTransactionId+" "+" "+ generatedTransactionId.size()+" "+ generatedTransactionId.get(index));
StringBuffer siteCodeBuffr = new StringBuffer("(");
int siteCount=0;
if(transIdComma.length()>0){
siteCodeArr = transIdComma.split(",");
for( String userSiteArr : siteCodeArr )
{
siteCount++;
System.out.println("EwayBillPrc:::wfValData:::siteCodeArr is "+userSiteArr);
siteCodeBuffr.append("?,");
}
if(siteCodeBuffr.lastIndexOf(",") == siteCodeBuffr.length() - 1)
{
siteCodeBuffr.deleteCharAt( siteCodeBuffr.length() - 1 );
parameters = siteCodeBuffr.append("").toString();
System.out.println("EwayBillPrc:::parameters:::"+parameters);
}
else
{
parameters = siteCodeBuffr.append("").toString();
}
}
System.out.println("Parameters is:"+parameters);
for(int i=0;i<tranId.size();i++){
try
{
sql="select line_no,sql_expr,sql_input,sql_expr1,sql_expr2,sql_expr3,sql_expr4,"
+ " sql_expr5,sql_expr6 from tax_bal_grp_det where bal_group=? and ref_ser = '"+tranId.get(i).getRefSer()+"'";
pstmt=con.prepareStatement(sql);
pstmt.setString(1, "EWAYJ");
rs=pstmt.executeQuery();
while(rs.next()){
sqlExpr= checkNull(rs.getString("sql_expr"));
sqlExpr1= checkNull(rs.getString("sql_expr1"));
sqlExpr2= checkNull(rs.getString("sql_expr2"));
sqlExpr3= checkNull( rs.getString("sql_expr3"));
sqlExpr4= checkNull(rs.getString("sql_expr4"));
sqlExpr5= checkNull(rs.getString("sql_expr5"));
sqlExpr6= checkNull(rs.getString("sql_expr6"));
compSql= sqlExpr+" "+sqlExpr1+" "+sqlExpr2+" "+sqlExpr3+" "+sqlExpr4+" "+sqlExpr5+" "+sqlExpr6;
//parameters=parameters+groupByQuery();
compSql1=compSql.substring(0, compSql.indexOf("group"));
compSql2=compSql.substring(compSql.indexOf("group"));
compSql=compSql1+(" = '"+tranId.get(i).getTranId())+"'"+compSql2;
System.out.println("Combine SQL JSON FILE::::"+(compSql));
String temp="";
if(compSql != null && compSql.trim().length() > 0 )
{
System.out.println("inside JSON retrieval query"+compSql);
pstmt1=con.prepareStatement(compSql);
//pstmt1.setString(1, tranId.get(0));
/*
int indexi = 1;
if(transIdComma.contains(","))
{
for(String userSiteArr : siteCodeArr)
{
System.out.println("Withhold:::siteCode:::"+userSiteArr);
pstmt1.setString(indexi++, userSiteArr.trim());
}
}
else
{*/
//pstmt1.setString(1, tranId.get(i).getTranId().trim());
rs1 = pstmt1.executeQuery();
List<ItemDetails> itemList=null;
while(rs1.next())
{
//getting data from GST HDR and GST DET tables for generating the JSON file for EWAY
//from detail part
System.out.println("inside the loop of EWAY JSON file");
if(!temp.equalsIgnoreCase(rs1.getString("ref_id"))){
itemList=new ArrayList<ItemDetails>();
valueCounter=0;
}
refSer=rs1.getString("ref_ser");
refId=rs1.getString("ref_id");
userGstin=rs1.getString("from_gstin");
supplyType=rs1.getString("supply_type");
//subSupplyType=rs1.getString("sub_type");
subSupplyType=rs1.getInt("sub_type");
docType=rs1.getString("doc_type");
docNo=rs1.getString("doc_no");
docDate=rs1.getTimestamp("doc_date"); //this will be in date format
transType = rs1.getInt("trans_type");
fromGstin=rs1.getString("from_gstin");
fromTrdName=rs1.getString("from_party_descr");//from party description.
fromAddr1=rs1.getString("from_address1");
fromAddr2=rs1.getString("from_address2");
fromPlace=rs1.getString("from_place");
frompinCode=rs1.getInt("from_pincode");
fromstateCode=rs1.getInt("from_state_code");
actualFromStateCode=rs1.getInt("from_state_code");
//to detail part
toGstin=rs1.getString("to_gstin");
toTrdName=rs1.getString("to_party_descr");
toAddr1=rs1.getString("to_address1");
toAddr2=rs1.getString("to_address2");
toPlace=rs1.getString("to_place");
toPincode=rs1.getInt("to_pin_code");
tostateCode=rs1.getInt("to_state_code");
actualToStateCode=rs1.getInt("to_state_code");
totInvValue=rs1.getDouble("total_invoice_amt");//here taken assessable value as int instead of double
cgstValue=rs1.getDouble("cgst_amt");
sgstValue=rs1.getDouble("sgst_amt");
igstValue=rs1.getDouble("igst_amt");
cessValue=rs1.getDouble("cess_amt");
totalValue=rs1.getDouble("assessable_value");
totalAssesableValue=rs1.getDouble("tot_assessable_value");
transMode=rs1.getInt("trans_mode");
//transporterName=rs1.getString("trans_code");
//transporterName="ABC";
transporterName=(rs1.getString("trans_code")==null || rs1.getString("trans_code").trim().length() == 0) ? "ABC" : rs1.getString("trans_code").trim();
transporterid=rs1.getString("trans_id");
transDocNo=rs1.getString("trans_doc_id");
transDocDate=rs1.getTimestamp("trans_doc_date");
sundryType=rs1.getString("sundry_type");
vehicleType=rs1.getString("vehicle_type");
vehicleNo=rs1.getString("vehicle_no");
mainHsnCode=rs1.getInt("hsn");
transDistance=rs1.getDouble("distance");
cgstRate=rs1.getDouble("cgst_perc");
sgstRate=rs1.getDouble("sgst_perc");
igstRate=rs1.getDouble("igst_perc");
cessRate=rs1.getDouble("cess_perc");
transactionDocDate = genericUtility.getValidDateString(transDocDate.toString(), genericUtility.getDBDateFormat(), dateFormat);
docDateValue=genericUtility.getValidDateString(docDate.toString(), genericUtility.getDBDateFormat(), dateFormat);
valueCounter++;
ItemDetails itemDetails=new ItemDetails(valueCounter,"","", mainHsnCode, 0, "",totalValue,sgstRate,cgstRate, igstRate, cessRate,0.0);
itemList.add(itemDetails);
System.out.println("counter:"+valueCounter+" Size ItemList:"+list.size());
EwayBillValue ewayBillValue=new EwayBillValue(
userGstin, supplyType, subSupplyType, docType, docNo, docDateValue,transType, fromGstin, fromTrdName,
fromAddr1,fromAddr2,fromPlace,frompinCode,fromstateCode,actualFromStateCode,
toGstin,toTrdName,toAddr1,toAddr2,toPlace,toPincode,tostateCode,actualToStateCode,totalAssesableValue,
cgstValue,sgstValue,igstValue,cessValue,0,0,totInvValue,transMode,transDistance,transporterName,transporterid,transDocNo,transactionDocDate,sundryType,vehicleType,vehicleNo,mainHsnCode,itemList,refSer,refId);
if(temp.equalsIgnoreCase(refId))
{
list.remove(list.size()-1);
}
list.add(ewayBillValue);
//validatorList.add(ewayBillValue.validateFields(refSer, refId));
System.out.println("Validation flag is:"+flag);
System.out.println("counter:"+valueCounter+" Size ValueList:"+list.size());
temp=rs1.getString("ref_id");
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
//tranId.clear();
//itemList.clear();
//generatedTransactionId.clear();
}else{
//tranId.clear();
//itemList.clear();
// generatedTransactionId.clear();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
if(rs!=null){
rs.close();
rs=null;
}
if(pstmt!=null){
pstmt.close();
pstmt=null;
}
System.out.println("counter value is :"+valueCounter);
if(valueCounter>0){
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
java.util.Date currentDate = new java.util.Date();
String todaysDate=sdf.format(currentDate);
System.out.println("File date is :"+todaysDate);
Calendar cal = Calendar.getInstance();
count=cal.get(Calendar.YEAR)+""+cal.get(Calendar.DATE)+""+((cal.get(Calendar.MONTH))+1)+""+cal.get(Calendar.HOUR)+""+cal.get(Calendar.MINUTE)
+""+cal.get(Calendar.SECOND);
String filename=siteCode+"_"+count;
ObjectMapper mapper = new ObjectMapper();
File file = new File(filePath+File.separator+filename+".json");//bring this path from disparm value
try{
File fileFolder=new File(filePath+File.separator);
//check for file validation...this will check the provided file path is correct or not
if (! fileFolder.exists()){
errString="VTEPFAIL";
printLog("E-way Bill Failed", "Provided File Path is Incorrect ","ERROR");
con.rollback();
return errString;
}
}
catch(Exception e){
printLog("E-way Bill Failed", "Provided File Path is Incorrect ","ERROR");
}
//check for field validation..flag will returns the false value if any invalid details found
System.out.println("Validation List:"+validatorList);
/* if(validatorList.contains(false)){
errString="VTEPFAIL";
printLog("E-way Bill Failed", "Please Enter Valid Details"+refSer,"ERROR");
con.rollback();
return errString;
}*/
EwayBillJson json=new EwayBillJson(jsonFileVersion, list);
//Modified by Ahmed on 10-08-2019[to display indented json and replace .0 value][start]
//mapper.writeValue(new File(filePath+File.separator+filename+".json"), json);
String jsonString = mapper.writeValueAsString(json);
jsonString = jsonString.replace(".0,", ",");
jsonString = jsonString.replace(".0}", "}");
//Object jsonObject = mapper.readValue(jsonString, Object.class);
//jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
//String jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
//jsonString = jsonString.replace(".0", "");
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(jsonString);
if (fileWriter != null)
{
fileWriter.flush();
fileWriter.close();
}
//Modified by Ahmed on 10-08-2019[end]
errString="CONFSUCCES";
//itemList.clear();
if(errString.equals("CONFSUCCES"))
{
loginCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.println("loginCode:"+loginCode);
//getting email id
try{
sql="select email_id from users where code= ? ";
pstmt=con.prepareStatement(sql);
pstmt.setString(1, loginCode.trim());
rs=pstmt.executeQuery();
while(rs.next()){
emailAddr=rs.getString("email_id");
}
}
catch(SQLException e){
e.printStackTrace();
}
if(rs!=null){
rs.close();
rs=null;
}
if(pstmt!=null){
pstmt.close();
pstmt=null;
}
if(emailAddr!=null && emailAddr.trim().length()>0){
transInfo = getDomString(emailAddr);
copyFilePath = new File(filePath + File.separator +"temp");
if(!copyFilePath.exists()) {
copyFilePath.mkdir();
}
else if(copyFilePath.exists())
{
try
{
FileUtils.cleanDirectory(copyFilePath);
}
catch(Exception exp)
{
exp.printStackTrace();
}
}
//log file
copyLogFilePath = new File(logDires + File.separator +"temp");
if(!copyLogFilePath.exists()) {
copyLogFilePath.mkdir();
}
else if(copyLogFilePath.exists())
{
try
{
FileUtils.cleanDirectory(copyLogFilePath);
}
catch(Exception exp)
{
exp.printStackTrace();
}
}
for(int i=0;i<tranId.size();i++){
printLog("E-way Bill Generated", "E_WAY bill Generated for Id "+tranId.get(i).getTranId()+" Of Ref-Ser:"+tranId.get(i).getRefSer(),"SUCCESS");
}
if(filename != null && filename.trim().length() > 0)
{
orgFilePath=new File(filePath+File.separator+filename+".json");
FileUtils.copyFileToDirectory(orgFilePath, copyFilePath);
/*logFilePath=new File(logDires+File.separator+logFileNames+".log");
FileUtils.copyFileToDirectory(logFilePath, copyLogFilePath);*/
//send JSon File....
mailSent= sendMail("",copyFilePath+File.separator+filename+".json",transInfo,true);
if(mailSent){
printMailLog("JSON file Mail Send succesfully to "+emailAddr, "Mail Send Successfully!"+refSer,"SUCCESS");
System.out.println("Succesfully send the mail");
}else{
printMailLog("Mail Send Failed to "+emailAddr, "Mail Send Failed!"+refSer,"ERROR");//GENERATE LOG
System.out.println("failure while sending the mail");
}
//send Log File....
/*mailSent= sendMailLog("",copyLogFilePath+File.separator+logFileNames+".log",transInfo,true);
if(mailSent){
printMailLog("Log file Mail Send succesfully to "+emailAddr, "Mail Send Successfully!"+refSer,"SUCCESS");
System.out.println("Succesfully send the mail");
}else{
printMailLog("Mail Send Failed to "+emailAddr, "Mail Send Failed!"+refSer,"ERROR");//GENERATE LOG
System.out.println("failure while sending the mail");
}*/
}
else{
printMailLog("File Not Found", "File Not Found for Copying the Files into Destination folder "+refSer,"ERROR");
}
//send mail for log file
logFilePath=new File(logDires+File.separator+logFileNames+".log");
//logFilePath=new File(logDires+File.separator+mailLogFileName+".log");
try{
FileUtils.copyFileToDirectory(logFilePath, copyLogFilePath);
mailSent= sendMailLog("",copyLogFilePath+File.separator+logFileNames+".log",transInfo,false);
//mailSent= sendMailLog("",copyLogFilePath+File.separator+mailLogFileName+".log",transInfo,false);
if(mailSent){
printMailLog("Log file Mail Send succesfully to "+emailAddr +" to Login Code-"+loginCode, "Mail Send Successfully!"+refSer,"SUCCESS");
System.out.println("Succesfully send the mail");
}else{
printMailLog("Mail Send Failed to "+loginCode, "Mail Send Failed!"+refSer,"FAILED");//GENERATE LOG
System.out.println("failure while sending the mail");
}
}
catch(Exception e){
e.printStackTrace();
}
}
else{
printMailLog("Email Id Not Found for Login Id-"+loginCode, "Please Enter the email id for given Login Code!"+refSer,"FAILED");
}
}
/*for(int i=0;i<tranId.size();i++){
printLog("E-way Bill Generated", "E_WAY bill Generated for Id "+tranId.get(i).getTranId()+" Of Ref-Ser:"+tranId.get(i).getRefSer(),"SUCCESS");
}*/
//clear the list
tranId.clear();
}
}
catch (SQLException e)
{
printLog("E-way Bill Failed", "SQL Sytax is Incorrect for Ref-Ser :"+refSer,"ERROR");
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
catch (Exception e)
{
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
finally {
tranId.clear();
}
return errString;
}
public boolean validateJSONFileForEway(Transaction tranId,String siteCode,Connection con)throws RemoteException, ITMException{
PreparedStatement pstmt = null,pstmt1 = null;
ResultSet rs = null,rs1 = null ;
String sql="",refSer="E-WAY",refId="";
String sqlExpr="",sqlExpr1="",sqlExpr2="",sqlExpr3="",sqlExpr4="",sqlExpr5="",sqlExpr6="",errfilePath="";
String compSql="",compSql1="",compSql2="",compSql3="";
//variables which are holding the data for displaying the
String userGstin="",supplyType="",docType="",docNo="",fromGstin="",toGstin="",fromTrdName="",
fromAddr1="",fromAddr2="",fromPlace="",docDateValue="";
String toTrdName="",toAddr1="",toAddr2="",toPlace="";
Timestamp docDate=null,transDocDate=null;
int frompinCode=0,toPincode=0,transType=0,fromstateCode=0,actualFromStateCode=0,tostateCode=0,actualToStateCode=0,mainHsnCode=0,transMode=0;
double transDistance=0.0;
String sundryType="",transporterName="",transporterId="",transDocNo="",vehicleNo="",vehicleType="",assesable_value="";
//item details data holder values
int itemNo=0,quantity=0,cessNonAdvol=0,subSupplyType=0;
String productName="",productDescr="",qtyUnit="",hsnCode = "";
double sgstRate=0.0,cgstRate=0.0,igstRate=0.0,cessRate=0.0,taxableAmount=0.0;
double totalAssesableValue=0.0,totalValue=0.0,cgstValue=0.0,sgstValue=0.0,igstValue=0.0,cessValue=0.0,totNonAdvolVal=0.0,othValue=0.0,totInvValue=0,distance=0.0;
String errString="";
//data holder list which will use in creation of the JSON file data
List<EwayBillValue> list=new ArrayList<EwayBillValue>();
int valueCounter=0;
//GenericUtility genericUtility = GenericUtility.getInstance();
int index=0;
String transIdComma="";
String siteCodeArr[] = null;
String parameters = "";
boolean flag=true;
String groupByQuery="";
//lets use some dummy data for getting values inside the json file....
DistCommon distCommon = new DistCommon();
String dateFormat="";
String filePath="";
String logPath="";
String jsonFileVersion="";
String count="";
String transactionDocDate="";
String transporterid="";
//List<ItemDetails> itemList=new ArrayList<ItemDetails>();
Map<String,Boolean> validatorMap=new HashMap<String,Boolean>();
List<Boolean> validatorList=new ArrayList<Boolean>();
try{
E12GenericUtility genericUtility= new E12GenericUtility();
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
Timestamp currDateTs = new Timestamp(System.currentTimeMillis());
//getting date format for ewaybill
dateFormat=distCommon.getDisparams("999999", "EWAY_DATE_FORM", con);
//getting file path for ewaybill
filePath=distCommon.getDisparams("999999", "EWAY_FILE_PATH", con);
//getting version of the json file
jsonFileVersion=distCommon.getDisparams("999999", "EWAY_JSON_VERSION", con);
System.out.println("Ewaybill date Format is:"+dateFormat);
System.out.println("generatedTransactionId:"+tranId);
/*for(int i=0;i<tranId.size();i++){
if(i==tranId.size()-1)
{
transIdComma=transIdComma+(""+tranId.get(i).getTranId()+"");
}
else
{
transIdComma=transIdComma+(""+tranId.get(i).getTranId()+",");
}
}*/
//System.out.println("generatedTransactionId:list:"+generatedTransactionId+" "+" "+ generatedTransactionId.size()+" "+ generatedTransactionId.get(index));
try
{
sql="select line_no,sql_expr,sql_input,sql_expr1,sql_expr2,sql_expr3,sql_expr4,"
+ " sql_expr5,sql_expr6 from tax_bal_grp_det where bal_group=? and ref_ser = '"+tranId.getRefSer()+"'";
pstmt=con.prepareStatement(sql);
pstmt.setString(1, "EWAYJ");
rs=pstmt.executeQuery();
while(rs.next()){
sqlExpr= checkNull(rs.getString("sql_expr"));
sqlExpr1= checkNull(rs.getString("sql_expr1"));
sqlExpr2= checkNull(rs.getString("sql_expr2"));
sqlExpr3= checkNull( rs.getString("sql_expr3"));
sqlExpr4= checkNull(rs.getString("sql_expr4"));
sqlExpr5= checkNull(rs.getString("sql_expr5"));
sqlExpr6= checkNull(rs.getString("sql_expr6"));
compSql= sqlExpr+" "+sqlExpr1+" "+sqlExpr2+" "+sqlExpr3+" "+sqlExpr4+" "+sqlExpr5+" "+sqlExpr6;
//parameters=parameters+groupByQuery();
compSql1=compSql.substring(0, compSql.indexOf("group"));
compSql2=compSql.substring(compSql.indexOf("group"));
compSql=compSql1+(" = '"+tranId.getTranId())+"'"+compSql2;
System.out.println("Combine SQL JSON FILE::::"+(compSql));
String temp="";
if(compSql != null && compSql.trim().length() > 0 )
{
System.out.println("inside JSON retrieval query"+compSql);
pstmt1=con.prepareStatement(compSql);
//pstmt1.setString(1, tranId.get(0));
/*
int indexi = 1;
if(transIdComma.contains(","))
{
for(String userSiteArr : siteCodeArr)
{
System.out.println("Withhold:::siteCode:::"+userSiteArr);
pstmt1.setString(indexi++, userSiteArr.trim());
}
}
else
{*/
//pstmt1.setString(1, tranId.get(i).getTranId().trim());
rs1 = pstmt1.executeQuery();
List<ItemDetails> itemList=null;
while(rs1.next())
{
//getting data from GST HDR and GST DET tables for generating the JSON file for EWAY
//from detail part
System.out.println("inside the loop of EWAY JSON file");
if(!temp.equalsIgnoreCase(rs1.getString("ref_id"))){
itemList=new ArrayList<ItemDetails>();
valueCounter=0;
}
refSer=rs1.getString("ref_ser");
refId=rs1.getString("ref_id");
userGstin=rs1.getString("from_gstin");
supplyType=rs1.getString("supply_type");
//subSupplyType=rs1.getString("sub_type");
subSupplyType=rs1.getInt("sub_type");
docType=rs1.getString("doc_type");
docNo=rs1.getString("doc_no");
docDate=rs1.getTimestamp("doc_date"); //this will be in date format
transType=rs1.getInt("trans_type");
fromGstin=rs1.getString("from_gstin");
fromTrdName=rs1.getString("from_party_descr");//from party description.
fromAddr1=rs1.getString("from_address1");
fromAddr2=rs1.getString("from_address2");
fromPlace=rs1.getString("from_place");
frompinCode=rs1.getInt("from_pincode");
fromstateCode=rs1.getInt("from_state_code");
actualFromStateCode=rs1.getInt("from_state_code");
//to detail part
toGstin=rs1.getString("to_gstin");
toTrdName=rs1.getString("to_party_descr");
toAddr1=rs1.getString("to_address1");
toAddr2=rs1.getString("to_address2");
toPlace=rs1.getString("to_place");
toPincode=rs1.getInt("to_pin_code");
tostateCode=rs1.getInt("to_state_code");
actualToStateCode=rs1.getInt("to_state_code");
totInvValue=rs1.getDouble("total_invoice_amt");//here taken assessable value as int instead of double
cgstValue=rs1.getDouble("cgst_amt");
sgstValue=rs1.getDouble("sgst_amt");
igstValue=rs1.getDouble("igst_amt");
cessValue=rs1.getDouble("cess_amt");
totalValue=rs1.getDouble("assessable_value");
totalAssesableValue=rs1.getDouble("tot_assessable_value");
transMode=rs1.getInt("trans_mode");
//transporterName=rs1.getString("trans_code");
//transporterName="ABC";
transporterName=(rs1.getString("trans_code")==null || rs1.getString("trans_code").trim().length() == 0) ? "ABC" : rs1.getString("trans_code").trim();
transporterid=rs1.getString("trans_id");
transDocNo=rs1.getString("trans_doc_id");
transDocDate=rs1.getTimestamp("trans_doc_date");
sundryType=rs1.getString("sundry_type");
vehicleType=rs1.getString("vehicle_type");
vehicleNo=rs1.getString("vehicle_no");
mainHsnCode=rs1.getInt("hsn");
transDistance=rs1.getDouble("distance");
cgstRate=rs1.getDouble("cgst_perc");
sgstRate=rs1.getDouble("sgst_perc");
igstRate=rs1.getDouble("igst_perc");
cessRate=rs1.getDouble("cess_perc");
transactionDocDate = genericUtility.getValidDateString(transDocDate.toString(), genericUtility.getDBDateFormat(), dateFormat);
docDateValue=genericUtility.getValidDateString(docDate.toString(), genericUtility.getDBDateFormat(), dateFormat);
valueCounter++;
ItemDetails itemDetails=new ItemDetails(valueCounter,"","", mainHsnCode, 0, "",totalValue,sgstRate,cgstRate, igstRate, cessRate,0.0);
itemList.add(itemDetails);
System.out.println("counter:"+valueCounter+" Size ItemList:"+list.size());
EwayBillValue ewayBillValue=new EwayBillValue(
userGstin, supplyType, subSupplyType, docType, docNo, docDateValue,transType, fromGstin, fromTrdName,
fromAddr1,fromAddr2,fromPlace,frompinCode,fromstateCode,actualFromStateCode,
toGstin,toTrdName,toAddr1,toAddr2,toPlace,toPincode,tostateCode,actualToStateCode,totalAssesableValue,
cgstValue,sgstValue,igstValue,cessValue,0,0,totInvValue,transMode,transDistance,transporterName,transporterid,transDocNo,transactionDocDate,sundryType,vehicleType,vehicleNo,mainHsnCode,itemList,refSer,refId);
if(temp.equalsIgnoreCase(refId)){
list.remove(list.size()-1);
}
list.add(ewayBillValue);
flag=ewayBillValue.validateFields(refSer, refId,siteCode);
System.out.println("Validation flag is:"+flag);
System.out.println("counter:"+valueCounter+" Size ValueList:"+list.size());
temp=rs1.getString("ref_id");
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
//tranId.clear();
//itemList.clear();
//generatedTransactionId.clear();
}else{
//tranId.clear();
//itemList.clear();
// generatedTransactionId.clear();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
catch (SQLException e)
{
printLog("E-way Bill Failed", "SQL Sytax is Incorrect for Ref-Ser :"+refSer,"ERROR");
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
catch (Exception e)
{
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
finally {
list.clear();
}
if(!flag){
System.out.println("inside failed transaction");
printLog("E-way Bill Failed", "Please Check Entered Values for given transaction"+refSer,"ERROR");
}
return flag;
}
class TransModeData{
double distance;
String transporterName;
String transId;
String transMode;
String transDocNo;
String transDocDate;
String vehicleType;
public TransModeData(double distance, String transporterName, String transId, String transMode,
String transDocNo, String transDocDate, String vehicleType) {
super();
this.distance = distance;
this.transporterName = transporterName;
this.transId = transId;
this.transMode = transMode;
this.transDocNo = transDocNo;
this.transDocDate = transDocDate;
this.vehicleType = vehicleType;
}
public double getDistance() {
return distance;
}
public void setDistance(double distance) {
this.distance = distance;
}
public String getTransporterName() {
return transporterName;
}
public void setTransporterName(String transporterName) {
this.transporterName = transporterName;
}
public String getTransId() {
return transId;
}
public void setTransId(String transId) {
this.transId = transId;
}
public String getTransMode() {
return transMode;
}
public void setTransMode(String transMode) {
this.transMode = transMode;
}
public String getTransDocNo() {
return transDocNo;
}
public void setTransDocNo(String transDocNo) {
this.transDocNo = transDocNo;
}
public String getTransDocDate() {
return transDocDate;
}
public void setTransDocDate(String transDocDate) {
this.transDocDate = transDocDate;
}
public String getVehicleType() {
return vehicleType;
}
public void setVehicleType(String vehicleType) {
this.vehicleType = vehicleType;
}
}
private String getTransId(String transCode,Connection conn)throws RemoteException, ITMException
{
String sql="";
PreparedStatement pstmt = null;
ResultSet rs = null ;
String transId="";
int count=0;
try{
sql="select count(*) from transporter where tran_code=? ";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, transCode);
rs=pstmt.executeQuery();
while(rs.next()){
count=rs.getInt(1);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
if(count>0){
sql="select tax_reg_2 from transporter where tran_code=? ";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, transCode);
rs=pstmt.executeQuery();
while(rs.next()){
transId=rs.getString(1);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
else{
transId="";
}
}
catch (SQLException e)
{
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
catch (Exception e)
{
System.out.println("Exception :EwaybillPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
finally
{
try
{
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)//if codn added by Jiten 19/05/06
{
rs.close();
rs = null;
}
}
catch(Exception e)
{
System.err.println("Exception :DBAccessEJB :getITMVersion :\n"+e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
}
return transId;
}
private void setLogFile(Connection conn)
{
try
{
String logPath = "", logDir = "", logFile = "";
File logFileDir = null;
DistCommon distCommon = new DistCommon();
String logFileName = "";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
logFileName = "EWAYBILL_"+siteCodes+"_"+sdf.format(new Date());
System.out.println("Inside the print log method");
logPath=distCommon.getDisparams("999999", "EWAY_LOG_PATH", conn);
logDir = logPath + File.separator + "EWAYBILL";
System.out.println("Log direction: "+logDir);
logFileDir = new File(logDir);
if (!logFileDir.exists())
{
logFileDir.mkdirs();
}
logFile = logDir + File.separator + logFileName + ".log";
logFileNames=logFileName;
logDires=logDir;
}
catch(Exception e)
{
e.printStackTrace();
}
}
//this method will helps to write the log based upon the number of actions taken on the files while processing the eway bill
/**
* @param title
* @param msg
* This method is used for printing the logs in log file
*/
private void printLog(String title, String msg,String text)
{
String logFile = "";
String logDir = "";
File logFileDir = null;
FileWriter fileWriter = null;
String logPath="";
DistCommon distCommon = new DistCommon();
Connection conn = null;
try
{
/*ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB();*/
conn = getConnection();
String logFileName = "";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
logFileName = "EWAYBILL_"+siteCodes+"_"+sdf.format(new Date());
System.out.println("Inside the print log method");
logPath=distCommon.getDisparams("999999", "EWAY_LOG_PATH", conn);
logDir = logPath + File.separator + "EWAYBILL";
System.out.println("Log direction: "+logDir);
logFileDir = new File(logDir);
if (!logFileDir.exists())
{
logFileDir.mkdirs();
}
logFile = logDir + File.separator + logFileName + ".log";
logFileNames=logFileName;
logDires=logDir;
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
java.util.Date now = new java.util.Date();
String strDate = sdfDate.format(now);
fileWriter = new FileWriter(logFile, true);
fileWriter.write("\r\n");
fileWriter.write(strDate+" "+"["+text+"] "+msg);
}
catch (Exception ex)
{
ex.printStackTrace();
//printLog("STDERR", ex);
printLog("STDOUT","Inside Exception [getLog]>>" + ex.toString(),"ERROR");
}
finally
{
try
{
conn.close();
conn = null;
}
catch(Exception e){}
try
{
if (fileWriter != null)
{
fileWriter.flush();
fileWriter.close();
}
}
catch (Exception e)
{
e.printStackTrace();
//printLog("STDERR", e);
}
}
}
//email log file
private void printMailLog(String title, String msg,String text)
{
String logFile = "";
String logDir = "";
File logFileDir = null;
FileWriter fileWriter = null;
String logPath="";
DistCommon distCommon = new DistCommon();
Connection conn = null;
try
{
/*ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB();*/
conn = getConnection();
String logFileName = "";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
logFileName = "EWAYBILL_MAIL_"+siteCodes+"_"+sdf.format(new Date());
mailLogFileName = logFileName;
System.out.println("Inside the print log method");
logPath=distCommon.getDisparams("999999", "EWAY_LOG_PATH", conn);
logDir = logPath + File.separator + "EWAYBILL";
System.out.println("Log direction: "+logDir);
logFileDir = new File(logDir);
if (!logFileDir.exists())
{
logFileDir.mkdirs();
}
logFile = logDir + File.separator + logFileName + ".log";
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
java.util.Date now = new java.util.Date();
String strDate = sdfDate.format(now);
fileWriter = new FileWriter(logFile, true);
fileWriter.write("\r\n");
fileWriter.write(strDate+" "+"["+text+"] "+msg);
}
catch (Exception ex)
{
ex.printStackTrace();
//printLog("STDERR", ex);
printLog("STDOUT","Inside Exception [getEmailLog]>>" + ex.toString(),"ERROR");
}
finally
{
try
{
conn.close();
conn = null;
}
catch(Exception e){}
try
{
if (fileWriter != null)
{
fileWriter.flush();
fileWriter.close();
}
}
catch (Exception e)
{
e.printStackTrace();
//printLog("STDERR", e);
}
}
}
//this class will hold the generated transaction details inside transaction
public class Transaction{
private String tranId;
private String refSer;
public Transaction(String tranId, String refSer) {
super();
this.tranId = tranId;
this.refSer = refSer;
}
public String getTranId() {
return tranId;
}
public void setTranId(String tranId) {
this.tranId = tranId;
}
public String getRefSer() {
return refSer;
}
public void setRefSer(String refSer) {
this.refSer = refSer;
}
}
//send email id option...
private boolean sendMail(String jsonFilePath,String attachment, String transInfo,boolean flag)throws ITMException
{
boolean sentMail = false;
String lineNo = "1";
String emailType = "page";
StringBuffer valueXmlString=null;
String retValue="";
try{
valueXmlString = new StringBuffer("<ROOT>");
/*valueXmlString = new StringBuffer("<ROOT><TRANS_INFO>");
valueXmlString.append("<OBJ_NAME>").append("<![CDATA[" + "" + "]]>").append("</OBJ_NAME>");
valueXmlString.append("<REF_SER>").append("<![CDATA[" + "" + "]]>").append("</REF_SER>");
valueXmlString.append("<REF_ID>").append("<![CDATA[" + "" + "]]>").append("</REF_ID>");
valueXmlString.append("<LINE_NO>").append("<![CDATA[" + lineNo + "]]>").append("</LINE_NO>");
valueXmlString.append("</TRANS_INFO>");
valueXmlString.append("<MAIL>");
valueXmlString.append("<EMAIL_TYPE>").append("<![CDATA[" + emailType + "]]>").append("</EMAIL_TYPE>");
valueXmlString.append("<ENTITY_CODE>").append("<![CDATA[" + "SUN" + "]]>").append("</ENTITY_CODE>");
valueXmlString.append("<ENTITY_TYPE>").append("<![CDATA[" + "" + "]]>").append("</ENTITY_TYPE>");
valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[" + "E" +"]]>").append("</FORMAT_CODE>");
valueXmlString.append("<TO_ADD>").append("<![CDATA[" +mailAddress +"]]>").append("</TO_ADD>");
valueXmlString.append("<CC_ADD>").append("<![CDATA[" + mailAddress+"]]>").append("</CC_ADD>");
valueXmlString.append("<SUBJECT>").append("<![CDATA[" + "Reports" +"]]>").append("</SUBJECT>");
valueXmlString.append("<BODY_TEXT>").append("<![CDATA[" + "PFA of Report(s)" +"]]>").append("</BODY_TEXT>");
valueXmlString.append("<MESSAGE>").append("<![CDATA[" + "PFA of Report(s)" +"]]>").append("</MESSAGE>");
valueXmlString.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" + reportFilePath + "]]>").append("</XML_DATA_FILE_PATH>");
valueXmlString.append("</MAIL>");
valueXmlString.append("</ROOT>");*/
//valueXmlString.append("<ROOT>");
valueXmlString.append("<MAILINFO>");
valueXmlString.append("<EMAIL_TYPE>").append("page").append("</EMAIL_TYPE>");
valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[DOWN_JSON]]>").append("</FORMAT_CODE>");
//commInfo.append("<TO_ADD>").append("<![CDATA[" + emailTo + "]]>").append("</TO_ADD>");
if(flag){
valueXmlString.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" +attachment+"]]>").append("</XML_DATA_FILE_PATH>");
}
else{
valueXmlString.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" + attachment + "]]>").append("</XML_DATA_FILE_PATH>");
}
valueXmlString.append("</MAILINFO>");
valueXmlString.append("<XML_DATA>").append(transInfo).append("</XML_DATA>");
valueXmlString.append("</ROOT>");
String mailDomStr = valueXmlString.toString();
System.out.println("@@## [Generic Report] :sendMail mailDomStr :-->" + mailDomStr);
EMail email = new EMail();
MailInfo info=new MailInfo();
retValue=email.sendMail(mailDomStr, "ITM");
if("S".equalsIgnoreCase(retValue))
{
//printLog("STDOUT","ReportCreationScheduler : sendMail => Mail sent successfully" );
sentMail = true;
}
System.out.println("[JSON] mail delivered successfully" );
}
catch (ITMException itme)
{
System.out.println("@@## ITMException [[Generic Report]] :sendMail :sendMail :sendMail() :==>\n");
throw itme;
}
catch (Exception e)
{
System.out.println("Exception :[[Generic Report]] :sendMail() :==>\n" + e.getMessage());
throw new ITMException(e);
}
return sentMail;
}
//send mail log files...
private boolean sendMailLog(String jsonFilePath,String attachment, String transInfo,boolean flag)throws ITMException
{
boolean sentMail = false;
String lineNo = "1";
String emailType = "page";
StringBuffer valueXmlString=null;
String retValue="";
try{
valueXmlString = new StringBuffer("<ROOT>");
/*valueXmlString = new StringBuffer("<ROOT><TRANS_INFO>");
valueXmlString.append("<OBJ_NAME>").append("<![CDATA[" + "" + "]]>").append("</OBJ_NAME>");
valueXmlString.append("<REF_SER>").append("<![CDATA[" + "" + "]]>").append("</REF_SER>");
valueXmlString.append("<REF_ID>").append("<![CDATA[" + "" + "]]>").append("</REF_ID>");
valueXmlString.append("<LINE_NO>").append("<![CDATA[" + lineNo + "]]>").append("</LINE_NO>");
valueXmlString.append("</TRANS_INFO>");
valueXmlString.append("<MAIL>");
valueXmlString.append("<EMAIL_TYPE>").append("<![CDATA[" + emailType + "]]>").append("</EMAIL_TYPE>");
valueXmlString.append("<ENTITY_CODE>").append("<![CDATA[" + "SUN" + "]]>").append("</ENTITY_CODE>");
valueXmlString.append("<ENTITY_TYPE>").append("<![CDATA[" + "" + "]]>").append("</ENTITY_TYPE>");
valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[" + "E" +"]]>").append("</FORMAT_CODE>");
valueXmlString.append("<TO_ADD>").append("<![CDATA[" +mailAddress +"]]>").append("</TO_ADD>");
valueXmlString.append("<CC_ADD>").append("<![CDATA[" + mailAddress+"]]>").append("</CC_ADD>");
valueXmlString.append("<SUBJECT>").append("<![CDATA[" + "Reports" +"]]>").append("</SUBJECT>");
valueXmlString.append("<BODY_TEXT>").append("<![CDATA[" + "PFA of Report(s)" +"]]>").append("</BODY_TEXT>");
valueXmlString.append("<MESSAGE>").append("<![CDATA[" + "PFA of Report(s)" +"]]>").append("</MESSAGE>");
valueXmlString.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" + reportFilePath + "]]>").append("</XML_DATA_FILE_PATH>");
valueXmlString.append("</MAIL>");
valueXmlString.append("</ROOT>");*/
//valueXmlString.append("<ROOT>");
valueXmlString.append("<MAILINFO>");
valueXmlString.append("<EMAIL_TYPE>").append("page").append("</EMAIL_TYPE>");
valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[DOWN_LOG]]>").append("</FORMAT_CODE>");
//commInfo.append("<TO_ADD>").append("<![CDATA[" + emailTo + "]]>").append("</TO_ADD>");
if(flag){
valueXmlString.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" +attachment+"]]>").append("</XML_DATA_FILE_PATH>");
}
else{
valueXmlString.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" + attachment + "]]>").append("</XML_DATA_FILE_PATH>");
}
valueXmlString.append("</MAILINFO>");
valueXmlString.append("<XML_DATA>").append(transInfo).append("</XML_DATA>");
valueXmlString.append("</ROOT>");
String mailDomStr = valueXmlString.toString();
System.out.println("@@## [Generic Report] :sendMail mailDomStr :-->" + mailDomStr);
EMail email = new EMail();
MailInfo info=new MailInfo();
retValue=email.sendMail(mailDomStr, "ITM");
if("S".equalsIgnoreCase(retValue))
{
//printLog("STDOUT","ReportCreationScheduler : sendMail => Mail sent successfully" );
sentMail = true;
}
System.out.println("[JSON] mail delivered successfully" );
}
catch (ITMException itme)
{
System.out.println("@@## ITMException [[Generic Report]] :sendMail :sendMail :sendMail() :==>\n");
throw itme;
}
catch (Exception e)
{
System.out.println("Exception :[[Generic Report]] :sendMail() :==>\n" + e.getMessage());
throw new ITMException(e);
}
return sentMail;
}
private String getDomString(String emailIdPer) throws ITMException
{
String retString = "";
StringBuffer valueXmlString = new StringBuffer();
try
{
valueXmlString.append("<ROOT>");
valueXmlString.append("<Detail1>");
valueXmlString.append("<email_id>").append("<![CDATA[" + emailIdPer + "]]>").append("</email_id>");
valueXmlString.append("</Detail1>");
valueXmlString.append("</ROOT>");
retString = valueXmlString.toString();
}
catch(Exception e)
{
e.printStackTrace();
printLog("ERROR", "Exception occured while sending an email","");
}
return retString;
}
}
package ibase.webitm.ejb.dis.adv;
import java.rmi.RemoteException;
import javax.ejb.Local;
import ibase.webitm.utility.ITMException;
@Local
public interface EwaybillPrcLocal {
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis.adv;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import ibase.webitm.utility.ITMException;
@Remote
public interface EwaybillPrcRemote {
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis.adv;
public class ItemDetails{
private int counter=1;
private int itemNo=0;
private String productName;
private String productDesc;
private int hsnCode;
private int quantity;
private String qtyUnit;
private double taxableAmount;
private double sgstRate;
private double cgstRate;
private double igstRate;
private double cessRate;
private double cessNonAdvol;
public ItemDetails(int counter,String productName, String productDesc, int hsnCode, int quantity,
String qtyUnit, double taxableAmount, double sgstRate, double cgstRate, double igstRate,
double cessRate, double cessNonAdvol) {
super();
this.itemNo = counter;
this.productName = productName;
this.productDesc = productDesc;
this.hsnCode = hsnCode;
this.quantity = quantity;
this.qtyUnit = qtyUnit;
this.taxableAmount = taxableAmount;
this.sgstRate = sgstRate;
this.cgstRate = cgstRate;
this.igstRate = igstRate;
this.cessRate = cessRate;
this.cessNonAdvol = cessNonAdvol;
}
public int getItemNo() {
return itemNo;
}
public void setItemNo(int itemNo) {
this.itemNo = itemNo;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductDesc() {
return productDesc;
}
public void setProductDesc(String productDesc) {
this.productDesc = productDesc;
}
public int getHsnCode() {
return hsnCode;
}
public void setHsnCode(int hsnCode) {
this.hsnCode = hsnCode;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getQtyUnit() {
return qtyUnit;
}
public void setQtyUnit(String qtyUnit) {
this.qtyUnit = qtyUnit;
}
public double getTaxableAmount() {
return taxableAmount;
}
public void setTaxableAmount(double taxableAmount) {
this.taxableAmount = taxableAmount;
}
public double getSgstRate() {
return sgstRate;
}
public void setSgstRate(double sgstRate) {
this.sgstRate = sgstRate;
}
public double getCgstRate() {
return cgstRate;
}
public void setCgstRate(double cgstRate) {
this.cgstRate = cgstRate;
}
public double getIgstRate() {
return igstRate;
}
public void setIgstRate(double igstRate) {
this.igstRate = igstRate;
}
public double getCessRate() {
return cessRate;
}
public void setCessRate(double cessRate) {
this.cessRate = cessRate;
}
public double getCessNonAdvol() {
return cessNonAdvol;
}
public void setCessNonAdvol(double cessNonAdvol) {
this.cessNonAdvol = cessNonAdvol;
}
}
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