Commit fc15cd83 authored by steurwadkar's avatar steurwadkar

F17ABAS001 source code commit


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@44090 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 1f450bed
package ibase.webitm.bean.gst;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.ATSearializer;
@JsonSerialize(using = ATSearializer.class)
public class AT extends BaseData
{
public String typ;
public String cpty;
public String stateCode;
public String docNum;
public Date docDt;
public List<InvLineItem> itms;
}
package ibase.webitm.bean.gst;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.B2BSerializer;
@JsonSerialize(using = B2BSerializer.class)
public class B2B extends BaseData
{
public String ctin;
}
package ibase.webitm.bean.gst;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.B2BASerializer;
@JsonSerialize(using = B2BASerializer.class)
public class B2BA extends BaseData
{
public String ctin;
}
package ibase.webitm.bean.gst;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.B2CLSerializer;
@JsonSerialize(using = B2CLSerializer.class)
public class B2CL extends BaseData
{
public String stateCode;
}
package ibase.webitm.bean.gst;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.B2CLASerializer;
@JsonSerialize(using = B2CLASerializer.class)
public class B2CLA extends BaseData
{
public String stateCode;
}
package ibase.webitm.bean.gst;
import java.util.Date;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.B2CSSerializer;
@JsonSerialize(using = B2CSSerializer.class)
public class B2CS extends BaseData
{
public String stateCode;
public String ty;
public String itemOrServiceCode;
public double txval;
public double irt;
public double iamt;
public double crt;
public double camt;
public double srt;
public double samt;
public double csrt;
public double csamt;
public boolean prs;
public String od_num;
public Date od_dt;
public String etin;
public String typ;
}
package ibase.webitm.bean.gst;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.B2CSASerializer;
@JsonSerialize(using = B2CSASerializer.class)
public class B2CSA extends B2CS
{
public String orgPeriodCode;
public String orgType;
public String orgItemOrServiceCode;
public String orgStateCode;
}
package ibase.webitm.bean.gst;
import java.util.List;
public abstract class BaseData
{
public boolean isReverseCharge;
public List<Invoice> invoices;
}
package ibase.webitm.bean.gst;
import java.util.Date;
public class CDNDetails
{
public String cdnNoteType;
public String cdNoteNumber;
public Date cdNoteDate;
public String orgCDNoteNumber;
public Date orgCDNoteDate;
public String reason;
public String invoiceNumber;
public Date invoiceDate;
public boolean rchrg;
public double val;
public double irt;
public double iamt;
public double crt;
public double camt;
public double srt;
public double samt;
public double csrt;
public double csamt;
public String etin;
}
package ibase.webitm.bean.gst;
import java.util.List;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.CDNRSerializer;
@JsonSerialize(using = CDNRSerializer.class)
public class CDNR extends BaseData
{
public String ctin;
public List<CDNDetails> cdnDetails;
}
package ibase.webitm.bean.gst;
import java.util.List;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.CDNRASerializer;
@JsonSerialize(using = CDNRASerializer.class)
public class CDNRA extends CDNR
{
public String ctin;
public List<CDNDetails> cdnDetails;
}
package ibase.webitm.bean.gst;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.GSTR1Serailizer;
@JsonSerialize(using = GSTR1Serailizer.class)
public class GSTR1 {
@JsonProperty("gstin")
public String gstin;
@JsonProperty("fp")
public String financialPeriod;
@JsonProperty("gt")
public double grossTurnOver;
@JsonProperty("b2b")
public List<B2B> b2b;
@JsonProperty("b2ba")
public List<B2BA> b2ba;
@JsonProperty("b2cl")
public List<B2CL> b2cl;
@JsonProperty("b2cla")
public List<B2CLA> b2cla;
@JsonProperty("b2cs")
public List<B2CS> b2cs;
@JsonProperty("b2csa")
public List<B2CSA> b2csa;
@JsonProperty("cdnr")
public List<CDNR> cdnr;
@JsonProperty("cdnra")
public List<CDNRA> cdnra;
}
package ibase.webitm.bean.gst;
public class InvLineItem {
public int num;
public String ty;
public String hsn_sc;
public double taxval;
public double irt;
public double iamt;
public double crt;
public double camt;
public double srt;
public double samt;
public double csrt;
public double csamt;
}
package ibase.webitm.bean.gst;
import java.util.Date;
import java.util.List;
public class Invoice
{
public String flag;
public String inum;
public String oinum;
public Date idt;
public Date oidt;
public String cname;
public double val;
public String pos;
public boolean rchrg;
public boolean prs;
public String od_num;
public Date od_dt;
public String etin;
public String checksum;
public List<InvLineItem> items;
}
package ibase.webitm.ejb.gst;
import java.io.InputStream;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
import javax.annotation.PostConstruct;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.util.gst.AESEncryption;
import ibase.webitm.util.gst.PubKeyEncryption;
import ibase.webitm.utility.ITMException;
@javax.ejb.Stateless
public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWizEJBLocal, GSTDataSubmitWizEJBRemote
{
private String GST_API_URL = "";
private String GST_AUTH_URL = "";
private String appKey = "";
InetAddress ipAddress = null;
private byte[] appKeyInBytes = null;
private String appKeyEncryptedAndCoded = "";
private String clientId = "";
private String clientSecret = "";
AESEncryption aesEncryption = null;
PubKeyEncryption pubKeyEncryption = null;
Connection conn = null;
@PostConstruct
public void postConstruct()
{
String sql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
System.out.println("GSTDataSubmitWizEJB PostConstruct called!");
InputStream pubKeyInpStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("ibase/webitm/resources/gst/GSTN_Public_Key.cer");
conn = getConnection();
FinCommon finCommon = new FinCommon();
clientId = finCommon.getFinparams("999999", "GST_CLIENT_ID", conn);
clientSecret = finCommon.getFinparams("999999", "GST_CLIENT_SECRET", conn);
aesEncryption = new AESEncryption();
pubKeyEncryption = new PubKeyEncryption(pubKeyInpStream);
ipAddress = Inet4Address.getLocalHost();
System.out.println("host ipAddress["+ipAddress.getHostAddress()+"]");
sql = "SELECT SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = 'gst_base_url' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
GST_API_URL = checkNull(rs.getString("SERVICE_URI"));
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
sql = "SELECT SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = 'gstr_auth_url' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
GST_AUTH_URL = checkNull(rs.getString("SERVICE_URI"));
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
}
catch (Exception e)
{
System.out.println("GSTDataSubmitWizEJB.postConstruct()["+e.getMessage()+"]");
e.printStackTrace();
}
finally
{
try
{
if(conn!= null && !conn.isClosed())
{
conn.close();
conn = null;
}
}
catch(SQLException se)
{
System.out.println("GSTDataSubmitWizEJB.postConstruct()["+se.getMessage()+"]");
se.printStackTrace();
}
}
}
@Override
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String retString = null;
E12GenericUtility genericUtility = new E12GenericUtility();
try
{
if (xmlString != null && xmlString.trim().length()!=0)
{
dom = genericUtility.parseString(xmlString);
}
if (xmlString1 != null && xmlString1.trim().length()!=0)
{
dom1 = genericUtility.parseString(xmlString1);
}
if (xmlString2 != null && xmlString2.trim().length()!=0)
{
dom2 = genericUtility.parseString(xmlString2);
}
retString = itemChanged( dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams );
}
catch (Exception e)
{
System.out.println ( "Exception :GSTDataSubmitWizEJB :itemChanged(String,String):" + e.getMessage() + ":" );
e.printStackTrace();
}
System.out.println ( "Return String from GSTDataSubmitWizEJB ["+retString+"]" );
return retString;
}
@Override
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
E12GenericUtility e12genericUtility = new E12GenericUtility();
StringBuffer valueXmlString = new StringBuffer();
int currentFormNo = 0;
String sql = "", siteCode = "", siteDescr = "", gstinNo = "", userName = "", stateCode = "", stateDescr = "", grossTurnover = "";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
System.out.println("Inside GSTDataSubmitWizEJB itemchanged");
conn = getConnection();
siteCode = e12genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
if( objContext != null && objContext.trim().length() > 0 )
{
currentFormNo = Integer.parseInt( objContext );
}
System.out.println("currentColumn["+currentColumn+"] currentFormNo["+currentFormNo+"]" );
valueXmlString = new StringBuffer( "<?xml version=\"1.0\"?><Root><Header><editFlag>" );
valueXmlString.append( editFlag ).append( "</editFlag></Header>" );
switch(currentFormNo)
{
case 1:
{
System.out.println(" -------- Inside itemchange case 1111111 ------------ ");
if( currentColumn.trim().equalsIgnoreCase( "itm_default" ))
{
appKey = aesEncryption.generateSecureKey();
appKeyInBytes = aesEncryption.decodeBase64StringTOByte(appKey);
appKeyEncryptedAndCoded = pubKeyEncryption.encrypt(appKeyInBytes);
sql = " SELECT S.SITE_CODE, S.SH_DESCR, ST.GST_CODE, ST.DESCR, SR.REF_CODE, SR.REG_NO FROM SITE S, SITEREGNO SR, STATE ST"
+ " WHERE S.SITE_CODE = SR.SITE_CODE AND S.FIN_ENTITY = SR.FIN_ENTITY AND S.STATE_CODE = ST.STATE_CODE AND SR.REF_CODE IN ('GSTIN_NO','GST_UNAME','GST_GT')"
+ " AND SR.SITE_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
rs = pstmt.executeQuery();
while(rs.next())
{
siteDescr = checkNull(rs.getString("SH_DESCR"));
if("GSTIN_NO".equalsIgnoreCase(checkNull(rs.getString("REF_CODE"))))
{
gstinNo = checkNull(rs.getString("REG_NO"));
}
if("GST_UNAME".equalsIgnoreCase(checkNull(rs.getString("REF_CODE"))))
{
userName = checkNull(rs.getString("REG_NO"));
}
if("GST_GT".equalsIgnoreCase(checkNull(rs.getString("REF_CODE"))))
{
grossTurnover = checkNull(rs.getString("REG_NO"));
}
stateCode = checkNull(rs.getString("GST_CODE"));
stateDescr = checkNull(rs.getString("DESCR"));
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<Detail1 domID='1'>");
valueXmlString.append("<period_code><![CDATA[]]></period_code>");
valueXmlString.append("<site_code><![CDATA[").append(siteCode).append( "]]></site_code>");
valueXmlString.append("<site_descr><![CDATA[").append(siteDescr).append( "]]></site_descr>");
valueXmlString.append("<gstin><![CDATA[" ).append(gstinNo).append( "]]></gstin>");
valueXmlString.append("<username><![CDATA[").append(userName).append( "]]></username>");
valueXmlString.append("<state_code><![CDATA[").append(stateCode).append( "]]></state_code>");
valueXmlString.append("<state_descr><![CDATA[").append(stateDescr).append( "]]></state_descr>");
valueXmlString.append("<gross_turnover><![CDATA[").append(grossTurnover).append( "]]></gross_turnover>");
valueXmlString.append("<otp><![CDATA[]]></otp>");
valueXmlString.append("<app_key><![CDATA["+appKey+"]]></app_key>");
valueXmlString.append("<returns_type><![CDATA[]]></returns_type>");
valueXmlString.append("</Detail1>" );
}
break;
}
/*case 2:
{
System.out.println(" -------- Inside itemchange case 2222222 ------------ ");
if( currentColumn.trim().equalsIgnoreCase( "itm_default" ))
{
valueXmlString.append("<Detail2 domID='1'>");
valueXmlString.append("<gstin><![CDATA[" ).append("33GSPTN2071G1ZC").append( "]]></gstin>");
valueXmlString.append("<invoice_id><![CDATA[").append("INV0000001").append( "]]></invoice_id>");
valueXmlString.append("<invoice_date><![CDATA[12-03-2017]]></invoice_date>");
valueXmlString.append("</Detail2>" );
}
break;
}*/
}
valueXmlString.append( "</Root>" );
}
catch (Exception e)
{
System.out.println("GSTDataSubmitWizEJB.itemChanged()["+e.getMessage()+"]");
e.printStackTrace();
}
finally
{
try
{
if(!conn.isClosed() && conn != null)
{
conn.close();
conn = null;
}
}
catch(SQLException se)
{
System.out.println("GSTDataSubmitWizEJB.itemChanged():finally block["+se.getMessage()+"]");
se.printStackTrace();
}
}
return valueXmlString.toString();
}
@Override
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext,String editFlag, String xtraParams) throws RemoteException, ITMException
{
String errString = "";
Document dom = null;
Document dom1 = null;
Document dom2 = null;
System.out.println("GSTDataSubmitWiz.wfValData()");
System.out.println("xmlString :"+xmlString);
System.out.println("xmlString1 :"+xmlString1);
System.out.println("xmlString2 :"+xmlString2);
System.out.println("objContext :"+objContext);
System.out.println("editFlag :"+editFlag);
System.out.println("xtraParams :"+xtraParams);
try
{
if (xmlString != null && xmlString.trim().length() > 0)
{
dom = parseString(xmlString);
}
if (xmlString1 != null && xmlString1.trim().length() > 0)
{
dom1 = parseString(xmlString1);
}
if (xmlString2 != null && xmlString2.trim().length() > 0)
{
dom2 = parseString(xmlString2);
}
System.out.println("Before calling function wfvalData****");
errString = wfValData(dom, dom1, dom2, objContext, editFlag, xtraParams);
System.out.println("After calling method wfVAlData Error String===="+errString);
}
catch (Exception e)
{
System.out.println("Exception : [GSTDataSubmitWiz][wfValData( String, String )] :==>\n" + e.getMessage());
throw new ITMException(e);
}
return errString;
}
@Override
public String wfValData(Document currFormDataDom, Document hdrDataDom, Document allFormDataDom, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException
{
String errString = "", userId = "";
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
int currentFormNo = 0;
String sql = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String errorType = "", errCode = "";
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
E12GenericUtility e12GenericUtility = new E12GenericUtility();
try
{
userId = e12GenericUtility.getValueFromXTRA_PARAMS( xtraParams, "loginCode" );
if (objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
System.out.println("currentFormNo ["+currentFormNo+"]");
}
conn = getConnection();
switch (currentFormNo)
{
case 1:
{
NodeList parentList = null, childList = null;
Node childNode = null;
String childNodeName = "", columnValue = "";
int noOfChilds = 0;
parentList = currFormDataDom.getElementsByTagName( "Detail" + currentFormNo );
childList = parentList.item( 0 ).getChildNodes();
noOfChilds = childList.getLength();
for (int ctr = 0; ctr < noOfChilds; ctr++)
{
childNode = childList.item( ctr );
childNodeName = childNode.getNodeName();
if ( childNode != null && childNode.getFirstChild() != null )
{
columnValue = childNode.getFirstChild().getNodeValue();
}
System.out.println(" columnName [" + childNodeName + "] columnValue [" + columnValue + "]");
if("period_code".equalsIgnoreCase(childNodeName))
{
sql = "SELECT COUNT(*) AS CNT FROM PERIOD WHERE TO_CHAR(TO_DATE(CODE,'yyyymm'),'mmyyyy') = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, columnValue);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") == 0)
{
errList.add( "VTMONATD10" );
errFields.add( childNodeName.toLowerCase() );
}
}
}
if("site_code".equalsIgnoreCase(childNodeName))
{
sql = "SELECT COUNT(*) AS CNT FROM SITE WHERE SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, columnValue);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") == 0)
{
errList.add( "INVDSITECD" );
errFields.add( childNodeName.toLowerCase() );
}
}
}
}
break;
}
/*case 2:
{
break;
}*/
}
int errListSize = errList.size();
String errFldName = null;
if ( errList != null && errListSize > 0 )
{
for (int i = 0; i < errListSize; i++ )
{
errCode = (String)errList.get(i);
errFldName = (String)errFields.get(i);
System.out.println("errCode .........."+errCode);
errString = getErrorString( errFldName, errCode, userId );
errorType = errorType( conn , errCode );
if ( errString.length() > 0)
{
String bifurErrString = errString.substring( errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
bifurErrString =bifurErrString+errString.substring( errString.indexOf("</trace>") + 8,errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
System.out.println("errStringXml .........."+errStringXml);
errString = "";
}
if ( errorType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errList = null;
errFields.clear();
errFields = null;
errStringXml.append("</Errors></Root>\r\n");
}
else
{
errStringXml = new StringBuffer( "" );
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizEJB.wfValData()["+e.getMessage()+"]");
e.printStackTrace();
}
return errStringXml.toString();
}
@Override
public String handleRequest(HashMap<String, String> reqParamMap)
{
String retResponseXML = "", action = "";
String sql = "";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
action = reqParamMap.get("action");
conn = getConnection();
if("GENERATE_OTP".equalsIgnoreCase(action))
{
String userName = "", stateCode = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
if("NULLFOUND".equalsIgnoreCase(clientId) || "NULLFOUND".equalsIgnoreCase(clientSecret))
{
retResponseXML = "<root><message><![CDATA[Client ID/Client secret API configuration is missing.]]></message></root>";
return retResponseXML;
}
userName = reqParamMap.get("user_name");
stateCode = reqParamMap.get("state_code");
JSONObject otpRequest = new JSONObject();
otpRequest.put("action", "OTPREQUEST");
otpRequest.put("app_key", appKeyEncryptedAndCoded);
otpRequest.put("username", userName);
HttpResponse<JsonNode> otpResp = Unirest.post(String.format("%s%s", GST_API_URL,GST_AUTH_URL))
.header("Content-Type", "application/json")
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("state-cd", stateCode)
.header("ip-usr", ipAddress.getHostAddress())
.header("username", userName)
.header("txn", transactionId)
.header("app_key", appKeyEncryptedAndCoded)
.body(new JsonNode(otpRequest.toString()))
.asJson();
System.out.println(String.format("OTP Request : Status[%s] Response[%s]", otpResp.getStatus(), otpResp.getBody()));
if (otpResp.getStatus() == 200)
{
JSONObject object = otpResp.getBody().getObject();
if( object.has("status_cd") && "1".equalsIgnoreCase(object.getString("status_cd")))
{
retResponseXML = "<root><message><![CDATA[OTP generated successfuly!]]></message></root>";
}
else
{
JSONObject errorJSON = otpResp.getBody().getObject().getJSONObject("error");
retResponseXML = "<root><message><![CDATA[Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd")+"]]></message></root>";
}
}
else
{
JSONObject errorJSON = otpResp.getBody().getObject().getJSONObject("error");
retResponseXML = "<root><message><![CDATA[Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd")+"]]></message></root>";
}
}
else if ("ITEM_CHANGE".equalsIgnoreCase(action))
{
String currColumn = "", currFieldData = "", siteDescr = "", gstinNo = "", userName = "", stateCode = "", stateDescr = "", grossTurnover = "";
currColumn = reqParamMap.get("focused_column");
currFieldData = reqParamMap.get("data_value");
System.out.println("custom itemchange logic for ["+currColumn+"] and data["+currFieldData+"]");
if("SITE_CODE".equalsIgnoreCase(currColumn))
{
sql = " SELECT S.SITE_CODE, S.SH_DESCR, ST.GST_CODE, ST.DESCR, SR.REF_CODE, SR.REG_NO FROM SITE S, SITEREGNO SR, STATE ST"
+ " WHERE S.SITE_CODE = SR.SITE_CODE AND S.FIN_ENTITY = SR.FIN_ENTITY AND S.STATE_CODE = ST.STATE_CODE AND SR.REF_CODE IN ('GSTIN_NO','GST_UNAME','GST_GT')"
+ " AND SR.SITE_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, currFieldData);
rs = pstmt.executeQuery();
while(rs.next())
{
siteDescr = checkNull(rs.getString("SH_DESCR"));
if("GSTIN_NO".equalsIgnoreCase(checkNull(rs.getString("REF_CODE"))))
{
gstinNo = checkNull(rs.getString("REG_NO"));
}
if("GST_UNAME".equalsIgnoreCase(checkNull(rs.getString("REF_CODE"))))
{
userName = checkNull(rs.getString("REG_NO"));
}
if("GST_GT".equalsIgnoreCase(checkNull(rs.getString("REF_CODE"))))
{
grossTurnover = checkNull(rs.getString("REG_NO"));
}
stateCode = checkNull(rs.getString("GST_CODE"));
stateDescr = checkNull(rs.getString("DESCR"));
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
retResponseXML = "<root><Detail1>"
+ "<site_descr><![CDATA["+siteDescr+"]]></site_descr>"
+ "<gstin><![CDATA["+gstinNo+"]]></gstin>"
+ "<username><![CDATA["+userName+"]]></username>"
+ "<state_code><![CDATA["+stateCode+"]]></state_code>"
+ "<state_descr><![CDATA["+stateDescr+"]]></state_descr>"
+ "<gross_turnover><![CDATA["+grossTurnover+"]]></gross_turnover>"
+ "</Detail1></root>";
}
}
}
catch (Exception e)
{
System.out.println("GSTDataSubmitWizEJB.handleRequest()["+e.getMessage()+"]");
e.printStackTrace();
}
finally
{
try
{
if(!conn.isClosed() && conn != null)
{
conn.close();
conn = null;
}
}
catch(SQLException se)
{
System.out.println("GSTDataSubmitWizEJB.handleRequest():finally block["+se.getMessage()+"]");
se.printStackTrace();
}
}
System.out.println("final retResonseXML ["+retResponseXML+"]");
return retResponseXML;
}
private String checkNull(String input)
{
if (input==null)
{
input="";
}
return input.trim();
}
private String errorType( Connection conn , String errorCode )
{
String msgType = "";
PreparedStatement pstmt = null ;
ResultSet rs = null;
try
{
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement( sql );
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
if( rs.next() )
{
msgType = rs.getString("MSG_TYPE");
}
}
catch (Exception ex)
{
System.out.println("GSTDataSubmitWizEJB.errorType()["+ex.getMessage()+"]");
ex.printStackTrace();
}
finally
{
try
{
if ( rs != null )
{
rs.close();
rs = null;
}
if ( pstmt != null )
{
pstmt.close();
pstmt = null;
}
}
catch ( Exception e )
{
e.printStackTrace();
}
}
return msgType;
}
}
package ibase.webitm.ejb.gst;
import java.rmi.RemoteException;
import java.util.HashMap;
import javax.ejb.Local;
import org.w3c.dom.Document;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
@Local
public interface GSTDataSubmitWizEJBLocal extends ValidatorLocal
{
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext,String editFlag, String xtraParams) throws RemoteException, ITMException;
public String wfValData(Document currFormDataDom, Document hdrDataDom, Document allFormDataDom, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String handleRequest(HashMap<String, String> reqParamMap);
}
package ibase.webitm.ejb.gst;
import java.rmi.RemoteException;
import java.util.HashMap;
import javax.ejb.Remote;
import org.w3c.dom.Document;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
@Remote
public interface GSTDataSubmitWizEJBRemote extends ValidatorRemote
{
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext,String editFlag, String xtraParams) throws RemoteException, ITMException;
public String wfValData(Document currFormDataDom, Document hdrDataDom, Document allFormDataDom, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String handleRequest(HashMap<String, String> reqParamMap);
}
package ibase.webitm.ejb.gst;
import java.io.InputStream;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import javax.annotation.PostConstruct;
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.crypto.macs.HMac;
import org.bouncycastle.crypto.params.KeyParameter;
import org.json.JSONArray;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import ibase.utility.E12GenericUtility;
import ibase.webitm.bean.gst.B2B;
import ibase.webitm.bean.gst.B2BA;
import ibase.webitm.bean.gst.B2CL;
import ibase.webitm.bean.gst.B2CLA;
import ibase.webitm.bean.gst.B2CS;
import ibase.webitm.bean.gst.B2CSA;
import ibase.webitm.bean.gst.CDNDetails;
import ibase.webitm.bean.gst.CDNR;
import ibase.webitm.bean.gst.CDNRA;
import ibase.webitm.bean.gst.GSTR1;
import ibase.webitm.bean.gst.InvLineItem;
import ibase.webitm.bean.gst.Invoice;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.util.gst.AESEncryption;
import ibase.webitm.util.gst.PubKeyEncryption;
import ibase.webitm.utility.ITMException;
@javax.ejb.Stateless
public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWizPosLocal, GSTDataSubmitWizPosRemote
{
private String GST_API_URL = "";
private String GSTR1_URL = "";
private String GSTR2_URL = "";
private final String APPLICATION_JSON = "application/json";
private String appKey = "";
InetAddress ipAddress = null;
private byte[] appKeyInBytes = null;
private String appKeyEncryptedAndCoded = "";
private String clientId = "";
private String clientSecret = "";
AESEncryption aesEncryption = null;
PubKeyEncryption pubKeyEncryption = null;
Connection conn = null;
E12GenericUtility e12GeneticUitlity = null;
@PostConstruct
public void postConstruct()
{
String sql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
System.out.println("GSTDataSubmitWizPos PostConstruct called!");
InputStream pubKeyInpStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("ibase/webitm/resources/gst/GSTN_Public_Key.cer");
conn = getConnection();
e12GeneticUitlity = new E12GenericUtility();
FinCommon finCommon = new FinCommon();
clientId = finCommon.getFinparams("999999", "GST_CLIENT_ID", conn);
clientSecret = finCommon.getFinparams("999999", "GST_CLIENT_SECRET", conn);
aesEncryption = new AESEncryption();
pubKeyEncryption = new PubKeyEncryption(pubKeyInpStream);
ipAddress = Inet4Address.getLocalHost();
System.out.println("host ipAddress["+ipAddress.getHostAddress()+"]");
sql = "SELECT SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = 'gst_base_url' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
GST_API_URL = checkNullandTrim(rs.getString("SERVICE_URI"));
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
sql = "SELECT SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = 'gstr1_url' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
GSTR1_URL = checkNullandTrim(rs.getString("SERVICE_URI"));
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
sql = "SELECT SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = 'gstr2_url' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
GSTR2_URL = checkNullandTrim(rs.getString("SERVICE_URI"));
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
}
catch (Exception e)
{
System.out.println("GSTDataSubmitWizPos.postConstruct()["+e.getMessage()+"]");
e.printStackTrace();
}
finally
{
try
{
if(conn!= null && !conn.isClosed())
{
conn.close();
conn = null;
}
}
catch(SQLException se)
{
System.out.println("GSTDataSubmitWizPos.postConstruct()["+se.getMessage()+"]");
se.printStackTrace();
}
}
}
@Override
public String postSave(String xmlStringAll, String dcrId, String editFlag, String xtraParams, Connection conn) throws RemoteException,ITMException
{
Document allXMLDom = null;
NodeList detail1NList = null, detail1ChildNList = null;
String retString = "", nodeName = "", otp = "", stateCode = "", sek = "", returnsType = "", gstin = "", periodCode = "", grossTurnover = "",
action = "", siteCode = "";
byte[] authSEK = null;
try
{
String userName = "", authToken = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String AUTH_TOKEN_URL = "/taxpayerapi/v0.2/authenticate";
System.out.println("xmlStringAll["+xmlStringAll+"]");
System.out.println("dcrId["+dcrId+"]");
System.out.println("editFlag["+editFlag+"]");
allXMLDom = e12GeneticUitlity.parseString(xmlStringAll);
detail1NList = allXMLDom.getElementsByTagName("Detail1");
detail1ChildNList = detail1NList.item(0).getChildNodes();
for(int i=0; i<detail1ChildNList.getLength();i++)
{
Node eachDetail1Element = detail1ChildNList.item(i);
nodeName = eachDetail1Element.getNodeName();
if(!"#text".equalsIgnoreCase(nodeName) && !"attribute".equals(nodeName))
{
if("username".equalsIgnoreCase(nodeName))
{
userName = eachDetail1Element.getTextContent();
}
else if("state_code".equalsIgnoreCase(nodeName))
{
stateCode = eachDetail1Element.getTextContent();;
}
else if("app_key".equalsIgnoreCase(nodeName))
{
appKey = eachDetail1Element.getTextContent();
}
else if("otp".equalsIgnoreCase(nodeName))
{
otp = eachDetail1Element.getTextContent();
}
else if("returns_type".equalsIgnoreCase(nodeName))
{
returnsType = eachDetail1Element.getTextContent();
}
else if("gstin".equalsIgnoreCase(nodeName))
{
gstin = eachDetail1Element.getTextContent();
}
else if("period_code".equalsIgnoreCase(nodeName))
{
periodCode = eachDetail1Element.getTextContent();
}
else if("gross_turnover".equalsIgnoreCase(nodeName))
{
grossTurnover = eachDetail1Element.getTextContent();
}
else if("action".equalsIgnoreCase(nodeName))
{
action = eachDetail1Element.getTextContent();
}
else if("site_code".equalsIgnoreCase(nodeName))
{
siteCode = eachDetail1Element.getTextContent();
}
}
}
System.out.println("returnsType["+returnsType+"] action ["+action+"]");
appKeyInBytes = aesEncryption.decodeBase64StringTOByte(appKey);
appKeyEncryptedAndCoded = pubKeyEncryption.encrypt(appKeyInBytes);
String encryptedOTP = aesEncryption.encryptEK(otp.getBytes(), appKeyInBytes);
JSONObject authTokenReq = new JSONObject();
authTokenReq.put("action", "AUTHTOKEN");
authTokenReq.put("username", userName);
authTokenReq.put("app_key", appKeyEncryptedAndCoded);
authTokenReq.put("otp", encryptedOTP);
HttpResponse<JsonNode> authTokenResp = Unirest.post(String.format("%s%s", GST_API_URL, AUTH_TOKEN_URL))
.header("Content-Type",APPLICATION_JSON)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("state-cd", stateCode)
.header("ip-usr", ipAddress.getHostAddress())
.header("txn", transactionId)
.header("app_key", appKeyEncryptedAndCoded)
.body(new JsonNode(authTokenReq.toString()))
.asJson();
System.out.println(String.format("authTokenResp Request : Status[%s] Response[%s]", authTokenResp.getStatus(), authTokenResp.getBody()));
if (authTokenResp.getStatus() == 200)
{
JSONObject object = authTokenResp.getBody().getObject();
if (object.has("auth_token") && object.has("sek") && object.has("status_cd") && Objects.equals(object.getString("status_cd"), "1"))
{
authToken = object.getString("auth_token");
sek = object.getString("sek");
authSEK = aesEncryption.decrypt(sek, appKeyInBytes);
System.out.println("AuthSEK = "+ aesEncryption.encodeBase64String(authSEK));
if("GSTR1".equalsIgnoreCase(returnsType))
{
if("SAVE".equalsIgnoreCase(action))
{
retString = saveGstr1(authToken, siteCode, stateCode, userName, gstin, periodCode, grossTurnover, authSEK, conn);
}
else if ("RETSUM".equalsIgnoreCase(action) || "FILE".equalsIgnoreCase(action))
{
retString = getGstr1Summary(authToken, stateCode, userName, gstin, periodCode, authSEK, action, conn);
}
else if ("SUBMIT".equalsIgnoreCase(action))
{
retString = submitGstr1(authToken, stateCode, userName, gstin, periodCode, authSEK, conn);
}
}
else if("GSTR2".equalsIgnoreCase(returnsType))
{
if("GETINV".equalsIgnoreCase(action))
{
retString = getGstr2Invoices(authToken, stateCode, userName, gstin, periodCode, authSEK, conn);
}
}
}
else
{
JSONObject errorJSON = authTokenResp.getBody().getObject().getJSONObject("error");
if("AUTH4033".equalsIgnoreCase(errorJSON.getString("error_cd")))
{
retString = new ITMDBAccessEJB().getErrorString("","VTINVOTP","","",conn);
}
else
{
String errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
}
else
{
JSONObject errorJSON = authTokenResp.getBody().getObject().getJSONObject("error");
String errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.postSave()["+e.getMessage()+"]");
e.printStackTrace();
}
return retString;
}
private String saveGstr1(String authToken, String siteCode, String stateCode, String userName, String gstin, String periodCode, String grossTurnover, byte[] authSek, Connection conn)
{
String retString = "", errMsg = "";
String gstr1Data = "", gstr1Rek = "";
String retStatsData = "", retStatsRek = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String sql = "", lineSql = "", refDataSql = "";
PreparedStatement pstmt = null, linePstmt = null, refDataPstmt = null;
ResultSet rs = null, lineRs = null, refDataRs = null;
String tranId = "", tranType = "", tranIdRef = "", ctin = "", posStateCode = "", posStateCodeStr = "", supplyType = "";
ArrayList<String> tranIdList = new ArrayList<String>();
Map<String, ArrayList<Invoice>> invoicesHMap = new HashMap<String, ArrayList<Invoice>>();
Map<String, Object> invTypObjHMap = new HashMap<String, Object>();
ArrayList<B2B> b2bInvoiceList = new ArrayList<B2B>();
ArrayList<B2BA> b2baInvoiceList = new ArrayList<B2BA>();
ArrayList<B2CL> b2clInvoiceList = new ArrayList<B2CL>();
ArrayList<B2CLA> b2claInvoiceList = new ArrayList<B2CLA>();
ArrayList<B2CS> b2csInvoiceList = new ArrayList<B2CS>();
ArrayList<B2CSA> b2csaInvoiceList = new ArrayList<B2CSA>();
ArrayList<CDNR> cdnrList = new ArrayList<CDNR>();
ArrayList<CDNRA> cdnraList = new ArrayList<CDNRA>();
ArrayList<InvLineItem> invLineItems = null;
ArrayList<Invoice> invoices = null;
ArrayList<CDNDetails> cdnDetailsList = null;
GSTR1 gstr1 = null;
Invoice invoice = null;
InvLineItem invLineItem = null;
B2B b2b = null;
B2BA b2ba = null;
B2CL b2cl = null;
B2CLA b2cla = null;
B2CS b2cs = null;
B2CSA b2csa = null;
CDNR cdnr = null;
CDNRA cdnra = null;
CDNDetails cdnDetails = null;
try
{
gstr1 = new GSTR1();
gstr1.gstin = gstin;
gstr1.financialPeriod = periodCode;
gstr1.grossTurnOver = Double.valueOf(grossTurnover);
sql = "SELECT * FROM GST_DATA_HDR WHERE PRD_CODE = ? AND SITE_CODE = ? AND SUBMIT_STATUS = 'P' AND REC_TYPE ='1'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, periodCode);
pstmt.setString(2, siteCode);
rs = pstmt.executeQuery();
while(rs.next())
{
tranId = checkNullandTrim(rs.getString("TRAN_ID"));
tranType = checkNullandTrim(rs.getString("TRAN_TYPE"));
ctin = checkNullandTrim(rs.getString("TAX_REG_NO"));
posStateCodeStr = checkNullandTrim(rs.getString("STATE_CODE"));
tranIdRef = checkNullandTrim(rs.getString("TRAN_ID__REF"));
System.out.println("tranId["+tranId+"] tranType["+tranType+"] ctin["+ctin+"] posStateCodeStr["+posStateCodeStr+"] tranIdRef["+tranIdRef+"]");
if(posStateCodeStr.length() > 0)
{
lineSql = "SELECT GST_CODE FROM STATE WHERE STATE_CODE = ?";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, posStateCodeStr);
lineRs = linePstmt.executeQuery();
if(lineRs.next())
{
posStateCode = checkNullandTrim(lineRs.getString("GST_CODE")) ;
}
if(linePstmt != null)
{
linePstmt.close();
linePstmt = null;
}
if(lineRs != null)
{
lineRs.close();
lineRs = null;
}
}
invoices = new ArrayList<Invoice>();
invoice = new Invoice();
invLineItems = new ArrayList<InvLineItem>();
cdnDetailsList = new ArrayList<CDNDetails>();
if(invoicesHMap.containsKey(ctin+"~"+tranType))
{
invoices = invoicesHMap.get(ctin+"~"+tranType);
}
//tran_type : 01 = B2B invoices, 02 B2BA invoices
if("01".equalsIgnoreCase(tranType) || "02".equalsIgnoreCase(tranType))
{
if("02".equalsIgnoreCase(tranType))
{
if(tranIdRef.length() > 0)
{
lineSql = "SELECT DOC_NO, DOC_DATE FROM GST_DATA_HDR WHERE TRAN_ID = ?";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranIdRef);
lineRs = linePstmt.executeQuery();
if(lineRs.next())
{
invoice.oinum = checkNullandTrim(lineRs.getString("DOC_NO")) ;
invoice.oidt = lineRs.getDate("DOC_DATE");
}
if(linePstmt != null)
{
linePstmt.close();
linePstmt = null;
}
if(lineRs != null)
{
lineRs.close();
lineRs = null;
}
}
}
lineSql = "SELECT * FROM GST_DATA_DET WHERE TRAN_ID = ? ORDER BY LINE_NO ";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranId);
lineRs = linePstmt.executeQuery();
while(lineRs.next())
{
invLineItem = new InvLineItem();
invLineItem.num = lineRs.getInt("LINE_NO");
invLineItem.ty = lineRs.getString("LINE_TYPE");
invLineItem.hsn_sc = lineRs.getString("GS_CODE");
invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT");
invLineItem.irt = lineRs.getDouble("IGST_PERC");
invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.crt = lineRs.getDouble("CGST_PERC");
invLineItem.camt = lineRs.getDouble("CGST_AMT");
invLineItem.srt = lineRs.getDouble("SGST_PERC");
invLineItem.samt = lineRs.getDouble("SGST_AMT");
invLineItem.csrt = lineRs.getDouble("CESS_PERC");
invLineItem.csamt = lineRs.getDouble("CESS_AMT");
invLineItems.add(invLineItem);
}
if(linePstmt != null)
{
linePstmt.close();
linePstmt = null;
}
if(lineRs != null)
{
lineRs.close();
lineRs = null;
}
invoice.inum = rs.getString("DOC_NO");
invoice.idt = rs.getDate("DOC_DATE");
invoice.val = rs.getDouble("AMOUNT");
invoice.pos = posStateCode;
invoice.rchrg = "Y".equalsIgnoreCase(rs.getString("REVERSE_CHRG"));
invoice.prs = "Y".equalsIgnoreCase(rs.getString("PROV_ASSMNT"));
invoice.od_num = rs.getString("ORDER_NO");
invoice.od_dt = rs.getDate("ORDER_DATE");
invoice.etin = rs.getString("ECOM_REG_NO");
invoice.items = invLineItems;
invoices.add(invoice);
invoicesHMap.put(ctin+"~"+tranType, invoices);
if("01".equalsIgnoreCase(tranType))
{
b2b = new B2B();
if(invTypObjHMap.containsKey(ctin+"~"+tranType))
{
b2b = (B2B)invTypObjHMap.get(ctin+"~"+tranType);
if(b2bInvoiceList.contains(b2b))
{
int index = b2bInvoiceList.indexOf(b2b);
b2bInvoiceList.remove(index);
}
}
b2b.ctin = ctin;
b2b.isReverseCharge = true;
b2b.invoices = invoices;
invTypObjHMap.put(ctin+"~"+tranType, b2b);
b2bInvoiceList.add(b2b);
}
else if("02".equalsIgnoreCase(tranType))
{
b2ba = new B2BA();
if(invTypObjHMap.containsKey(ctin+"~"+tranType))
{
b2ba = (B2BA)invTypObjHMap.get(ctin+"~"+tranType);
if(b2baInvoiceList.contains(b2ba))
{
int index = b2baInvoiceList.indexOf(b2ba);
b2baInvoiceList.remove(index);
}
}
b2ba.ctin = ctin;
b2ba.isReverseCharge = true;
b2ba.invoices = invoices;
invTypObjHMap.put(ctin+"~"+tranType, b2ba);
b2baInvoiceList.add(b2ba);
}
}
//tran_type : 03 = B2CL invoices, 04 B2CLA invoices
if("03".equalsIgnoreCase(tranType) || "04".equalsIgnoreCase(tranType))
{
invoices = new ArrayList<Invoice>();
invoice = new Invoice();
invLineItems = new ArrayList<InvLineItem>();
if("04".equalsIgnoreCase(tranType))
{
tranIdRef = checkNullandTrim(rs.getString("TRAN_ID__REF"));
if(tranIdRef.length() > 0)
{
lineSql = "SELECT DOC_NO, DOC_DATE FROM GST_DATA_HDR WHERE TRAN_ID = ?";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranIdRef);
lineRs = linePstmt.executeQuery();
if(lineRs.next())
{
invoice.oinum = checkNullandTrim(lineRs.getString("DOC_NO")) ;
invoice.oidt = lineRs.getDate("DOC_DATE");
}
if(linePstmt != null)
{
linePstmt.close();
linePstmt = null;
}
if(lineRs != null)
{
lineRs.close();
lineRs = null;
}
}
}
lineSql = "SELECT * FROM GST_DATA_DET WHERE TRAN_ID = ? ORDER BY LINE_NO ";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranId);
lineRs = linePstmt.executeQuery();
while(lineRs.next())
{
invLineItem = new InvLineItem();
invLineItem.num = lineRs.getInt("LINE_NO");
invLineItem.ty = lineRs.getString("LINE_TYPE");
invLineItem.hsn_sc = lineRs.getString("GS_CODE");
invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT");
invLineItem.irt = lineRs.getDouble("IGST_PERC");
invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.crt = lineRs.getDouble("CGST_PERC");
invLineItem.camt = lineRs.getDouble("CGST_AMT");
invLineItem.srt = lineRs.getDouble("SGST_PERC");
invLineItem.samt = lineRs.getDouble("SGST_AMT");
invLineItem.csrt = lineRs.getDouble("CESS_PERC");
invLineItem.csamt = lineRs.getDouble("CESS_AMT");
invLineItems.add(invLineItem);
}
if(linePstmt != null)
{
linePstmt.close();
linePstmt = null;
}
if(lineRs != null)
{
lineRs.close();
lineRs = null;
}
invoice.cname = checkNullandTrim(rs.getString("CUST_NAME"));
invoice.inum = checkNullandTrim(rs.getString("DOC_NO"));
invoice.idt = rs.getDate("DOC_DATE");
invoice.val = rs.getDouble("AMOUNT");
invoice.pos = posStateCode;
invoice.prs = "Y".equalsIgnoreCase(rs.getString("PROV_ASSMNT"));
invoice.od_num = checkNullandTrim(rs.getString("ORDER_NO"));
invoice.od_dt = rs.getDate("ORDER_DATE");
invoice.etin = rs.getString("ECOM_REG_NO");
invoice.items = invLineItems;
invoices.add(invoice);
if("03".equalsIgnoreCase(tranType))
{
b2cl = new B2CL();
b2cl.stateCode = stateCode;
b2cl.isReverseCharge = false;
b2cl.invoices = invoices;
b2clInvoiceList.add(b2cl);
}
else if("04".equalsIgnoreCase(tranType))
{
b2cla = new B2CLA();
b2cla.stateCode = stateCode;
b2cla.isReverseCharge = false;
b2cla.invoices = invoices;
b2claInvoiceList.add(b2cla);
}
}
//tran_type : 05 = B2CS invoices, 06 B2CSA invoices
if("05".equalsIgnoreCase(tranType) || "06".equalsIgnoreCase(tranType))
{
lineSql = "SELECT * FROM GST_DATA_DET WHERE TRAN_ID = ? ORDER BY LINE_NO ";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranId);
lineRs = linePstmt.executeQuery();
while(lineRs.next())
{
if("05".equalsIgnoreCase(tranType))
{
b2cs = new B2CS();
refDataSql = "SELECT DESCR FROM GENCODES WHERE MOD_NAME = 'W_GSTR' AND FLD_NAME = 'SUPPLY_TYPE' AND FLD_VALUE = ?";
refDataPstmt = conn.prepareStatement(refDataSql);
refDataPstmt.setString(1, checkNullandTrim(lineRs.getString("SUPPLY_TYPE")));
refDataRs = refDataPstmt.executeQuery();
if(refDataRs.next())
{
supplyType = checkNullandTrim(refDataRs.getString("DESCR"));
}
if(refDataPstmt != null)
{
refDataPstmt.close();
refDataPstmt = null;
}
if(refDataRs != null)
{
refDataRs.close();
refDataRs = null;
}
b2cs.stateCode = posStateCode;
b2cs.ty = checkNullandTrim(lineRs.getString("LINE_TYPE"));
b2cs.itemOrServiceCode = lineRs.getString("GS_CODE");
b2cs.txval = lineRs.getDouble("TAXABLE_AMT");
b2cs.irt = lineRs.getDouble("IGST_PERC");
b2cs.iamt = lineRs.getDouble("IGST_AMT");
b2cs.crt = lineRs.getDouble("CGST_PERC");
b2cs.camt = lineRs.getDouble("CGST_AMT");
b2cs.srt = lineRs.getDouble("SGST_PERC");
b2cs.samt = lineRs.getDouble("SGST_AMT");
b2cs.csrt = lineRs.getDouble("CESS_PERC");
b2cs.csamt = lineRs.getDouble("CESS_AMT");
b2cs.prs = "Y".equalsIgnoreCase(checkNullandTrim(rs.getString("PROV_ASSMNT")));
b2cs.od_num = rs.getString("ORDER_NO");
b2cs.od_dt = rs.getDate("ORDER_DATE");
b2cs.etin = rs.getString("ECOM_REG_NO");
b2cs.typ = supplyType;
b2csInvoiceList.add(b2cs);
}
if("06".equalsIgnoreCase(tranType))
{
String orgPeriodCode = "", orgType = "", orgItemOrServiceCode="", orgStateCode = "";
b2csa = new B2CSA();
if(tranIdRef.length() > 0)
{
refDataSql = " SELECT GDH.PRD_CODE,S.GST_CODE,GDD.LINE_TYPE,GDD.GS_CODE "
+ " FROM GST_DATA_HDR GDH, GST_DATA_DET GDD, STATE S "
+ " WHERE GDH.TRAN_ID = GDD.TRAN_ID AND GDH.STATE_CODE = S.STATE_CODE "
+ " AND GDH.TRAN_ID = ? AND GDD.LINE_NO = ?";
refDataPstmt = conn.prepareStatement(refDataSql);
refDataPstmt.setString(1, tranIdRef);
refDataPstmt.setString(2, lineRs.getString("SR_NO__OLD"));
refDataRs = refDataPstmt.executeQuery();
if(refDataRs.next())
{
orgPeriodCode = checkNullandTrim(refDataRs.getString("PRD_CODE"));
orgType = checkNullandTrim(refDataRs.getString("LINE_TYPE"));
orgItemOrServiceCode = checkNullandTrim(refDataRs.getString("GS_CODE"));
orgStateCode = checkNullandTrim(refDataRs.getString("GST_CODE"));
}
if(refDataPstmt != null)
{
refDataPstmt.close();
refDataPstmt = null;
}
if(refDataRs != null)
{
refDataRs.close();
refDataRs = null;
}
}
refDataSql = "SELECT DESCR FROM GENCODES WHERE MOD_NAME = 'W_GSTR' AND FLD_NAME = 'SUPPLY_TYPE' AND FLD_VALUE = ?";
refDataPstmt = conn.prepareStatement(refDataSql);
refDataPstmt.setString(1, checkNullandTrim(lineRs.getString("SUPPLY_TYPE")));
refDataRs = refDataPstmt.executeQuery();
if(refDataRs.next())
{
supplyType = checkNullandTrim(refDataRs.getString("DESCR"));
}
if(refDataPstmt != null)
{
refDataPstmt.close();
refDataPstmt = null;
}
if(refDataRs != null)
{
refDataRs.close();
refDataRs = null;
}
b2csa.orgPeriodCode = orgPeriodCode;
b2csa.orgType = orgType;
b2csa.orgItemOrServiceCode = orgItemOrServiceCode;
b2csa.orgStateCode = orgStateCode;
b2csa.stateCode = posStateCode;
b2csa.ty = checkNullandTrim(lineRs.getString("LINE_TYPE"));
b2csa.itemOrServiceCode = lineRs.getString("GS_CODE");
b2csa.txval = lineRs.getDouble("TAXABLE_AMT");
b2csa.irt = lineRs.getDouble("IGST_PERC");
b2csa.iamt = lineRs.getDouble("IGST_AMT");
b2csa.crt = lineRs.getDouble("CGST_PERC");
b2csa.camt = lineRs.getDouble("CGST_AMT");
b2csa.srt = lineRs.getDouble("SGST_PERC");
b2csa.samt = lineRs.getDouble("SGST_AMT");
b2csa.csrt = lineRs.getDouble("CESS_PERC");
b2csa.csamt = lineRs.getDouble("CESS_AMT");
b2csa.prs = "Y".equalsIgnoreCase(checkNullandTrim(rs.getString("PROV_ASSMNT")));
b2csa.od_num = rs.getString("ORDER_NO");
b2csa.od_dt = rs.getDate("ORDER_DATE");
b2csa.etin = rs.getString("ECOM_REG_NO");
b2csa.typ = supplyType;
b2csaInvoiceList.add(b2csa);
}
}
if(linePstmt != null)
{
linePstmt.close();
linePstmt = null;
}
if(lineRs != null)
{
lineRs.close();
lineRs = null;
}
}
//tran_type : 07 = CDNR, 08 CDNRA
if("07".equalsIgnoreCase(tranType) || "08".equalsIgnoreCase(tranType))
{
String reason = "";
refDataSql = "SELECT DESCR FROM GENCODES WHERE MOD_NAME = 'W_GSTR' AND FLD_NAME = 'REAS_CODE' AND FLD_VALUE = ?";
refDataPstmt = conn.prepareStatement(refDataSql);
refDataPstmt.setString(1, checkNullandTrim(rs.getString("REAS_CODE")));
refDataRs = refDataPstmt.executeQuery();
if(refDataRs.next())
{
reason = checkNullandTrim(refDataRs.getString("DESCR"));
}
if(refDataPstmt != null)
{
refDataPstmt.close();
refDataPstmt = null;
}
if(refDataRs != null)
{
refDataRs.close();
refDataRs = null;
}
if("07".equalsIgnoreCase(tranType))
{
cdnr = new CDNR();
cdnr.isReverseCharge = true;
cdnr.ctin = ctin;
lineSql = "SELECT * FROM GST_DATA_DET WHERE TRAN_ID = ? ORDER BY LINE_NO";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranId);
lineRs = linePstmt.executeQuery();
while(lineRs.next())
{
cdnDetails = new CDNDetails();
cdnDetails.cdnNoteType = checkNullandTrim(rs.getString("DOC_TYPE"));
cdnDetails.cdNoteNumber = checkNullandTrim(rs.getString("DOC_NO"));
cdnDetails.cdNoteDate = rs.getDate("DOC_DATE");
cdnDetails.reason = reason;
cdnDetails.invoiceNumber = checkNullandTrim(rs.getString("REF_ID__INV"));
cdnDetails.invoiceDate = rs.getDate("REF_DATE__INV");
cdnDetails.rchrg = "Y".equalsIgnoreCase(rs.getString("REVERSE_CHRG"));
cdnDetails.val = lineRs.getDouble("TAXABLE_AMT");
cdnDetails.irt = lineRs.getDouble("IGST_PERC");
cdnDetails.iamt = lineRs.getDouble("IGST_AMT");
cdnDetails.crt = lineRs.getDouble("CGST_PERC");
cdnDetails.camt = lineRs.getDouble("CGST_AMT");
cdnDetails.srt = lineRs.getDouble("SGST_PERC");
cdnDetails.samt = lineRs.getDouble("SGST_AMT");
cdnDetails.csrt = lineRs.getDouble("CESS_PERC");
cdnDetails.csamt = lineRs.getDouble("CESS_AMT");
cdnDetails.etin = rs.getString("ECOM_REG_NO");
cdnDetailsList.add(cdnDetails);
}
if(linePstmt != null)
{
linePstmt.close();
linePstmt = null;
}
if(lineRs != null)
{
lineRs.close();
lineRs = null;
}
cdnr.cdnDetails = cdnDetailsList;
cdnrList.add(cdnr);
}
if("08".equalsIgnoreCase(tranType))
{
String orgInvoiceNumber = "";
Date orgInvoiceDate = null;
if(tranIdRef.length() > 0)
{
refDataSql = "SELECT DOC_NO, DOC_DATE FROM GST_DATA_HDR WHERE TRAN_ID = ?";
refDataPstmt = conn.prepareStatement(refDataSql);
refDataPstmt.setString(1, tranIdRef);
refDataRs = refDataPstmt.executeQuery();
if(refDataRs.next())
{
orgInvoiceNumber = checkNullandTrim(refDataRs.getString("DOC_NO")) ;
orgInvoiceDate = refDataRs.getDate("DOC_DATE");
}
if(refDataPstmt != null)
{
refDataPstmt.close();
refDataPstmt = null;
}
if(refDataRs != null)
{
refDataRs.close();
refDataRs = null;
}
}
cdnra = new CDNRA();
cdnra.isReverseCharge = true;
cdnra.ctin = ctin;
lineSql = "SELECT * FROM GST_DATA_DET WHERE TRAN_ID = ? ORDER BY LINE_NO";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranId);
lineRs = linePstmt.executeQuery();
while(lineRs.next())
{
cdnDetails = new CDNDetails();
cdnDetails.cdnNoteType = checkNullandTrim(rs.getString("DOC_TYPE"));
cdnDetails.cdNoteNumber = checkNullandTrim(rs.getString("DOC_NO"));
cdnDetails.cdNoteDate = rs.getDate("DOC_DATE");
cdnDetails.orgCDNoteNumber = orgInvoiceNumber;
cdnDetails.orgCDNoteDate = orgInvoiceDate;
cdnDetails.reason = reason;
cdnDetails.invoiceNumber = checkNullandTrim(rs.getString("REF_ID__INV"));
cdnDetails.invoiceDate = rs.getDate("REF_DATE__INV");
cdnDetails.rchrg = "Y".equalsIgnoreCase(rs.getString("REVERSE_CHRG"));
cdnDetails.val = lineRs.getDouble("TAXABLE_AMT");
cdnDetails.irt = lineRs.getDouble("IGST_PERC");
cdnDetails.iamt = lineRs.getDouble("IGST_AMT");
cdnDetails.crt = lineRs.getDouble("CGST_PERC");
cdnDetails.camt = lineRs.getDouble("CGST_AMT");
cdnDetails.srt = lineRs.getDouble("SGST_PERC");
cdnDetails.samt = lineRs.getDouble("SGST_AMT");
cdnDetails.csrt = lineRs.getDouble("CESS_PERC");
cdnDetails.csamt = lineRs.getDouble("CESS_AMT");
cdnDetails.etin = rs.getString("ECOM_REG_NO");
cdnDetailsList.add(cdnDetails);
}
if(linePstmt != null)
{
linePstmt.close();
linePstmt = null;
}
if(lineRs != null)
{
lineRs.close();
lineRs = null;
}
cdnra.cdnDetails = cdnDetailsList;
cdnraList.add(cdnra);
}
}
tranIdList.add(tranId);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(b2bInvoiceList.size() > 0)
{
gstr1.b2b = b2bInvoiceList;
}
if(b2baInvoiceList.size() > 0)
{
gstr1.b2ba = b2baInvoiceList;
}
if(b2clInvoiceList.size() > 0)
{
gstr1.b2cl = b2clInvoiceList;
}
if(b2claInvoiceList.size() > 0)
{
gstr1.b2cla = b2claInvoiceList;
}
if(b2csInvoiceList.size() > 0)
{
gstr1.b2cs = b2csInvoiceList;
}
if(b2csaInvoiceList.size() > 0)
{
gstr1.b2csa = b2csaInvoiceList;
}
if(cdnrList.size() > 0)
{
gstr1.cdnr = cdnrList;
}
if(cdnraList.size() > 0)
{
gstr1.cdnra = cdnraList;
}
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(gstr1);
System.out.println("jsonPayload to SAVE GSTR1["+json+"]");
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
JSONObject gstr1HeaderObj = new JSONObject();
gstr1HeaderObj.put("action", "RETSAVE");
gstr1HeaderObj.put("data", encryptedPayload);
gstr1HeaderObj.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
HttpResponse<JsonNode> gstr1Resp = Unirest.put(String.format("%s/%s", GST_API_URL, GSTR1_URL))
.header("Content-Type", APPLICATION_JSON)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("txn",transactionId)
.header("state-cd", stateCode)
.header("auth-token", authToken)
.header("gstin", gstin)
.header("username", userName)
.header("ret_period", periodCode)
.header("ip-usr", ipAddress.getHostAddress())
.header("app_key", appKeyEncryptedAndCoded)
.body(new JsonNode(gstr1HeaderObj.toString()))
.asJson();
System.out.println(String.format("gstr1Resp Request : Status[%s] Response[%s]", gstr1Resp.getStatus(), gstr1Resp.getBody()));
if (gstr1Resp.getStatus() == 200)
{
JSONObject gstr1RespObj = gstr1Resp.getBody().getObject();
if(gstr1RespObj.has("data") && gstr1RespObj.has("rek"))
{
gstr1Data = gstr1RespObj.getString("data");
gstr1Rek = gstr1RespObj.getString("rek");
byte[] apiEKGstr1 = aesEncryption.decrypt(gstr1Rek, authSek);
String Gstr1RespJsoninBase64 = new String(aesEncryption.decrypt(gstr1Data, apiEKGstr1));
byte[] Gstr1RespJsonInBytes = aesEncryption.decodeBase64StringTOByte(Gstr1RespJsoninBase64);
JSONObject Gstr1RespObj = new JSONObject(new String(Gstr1RespJsonInBytes));
String transId = Gstr1RespObj.getString("reference_id");
System.out.println("transId to getStatus["+transId+"]");
while(true)
{
HttpResponse<JsonNode> retStatusResp = Unirest.get(String.format("%s/%s", GST_API_URL, GSTR1_URL))
.queryString("action","RETSTATUS")
.queryString("gstin", gstin)
.queryString("ret_period", periodCode)
.queryString("trans_id",transId)
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress.getHostAddress())
.header("username", userName)
.header("auth-token", authToken)
.header("app_key", appKeyEncryptedAndCoded)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.asJson();
System.out.println(String.format("retStatusResp Request : Status[%s] Response[%s]", retStatusResp.getStatus(), retStatusResp.getBody()));
if (retStatusResp.getStatus() == 200)
{
JSONObject retStatsRespObj = retStatusResp.getBody().getObject();
if(retStatsRespObj.has("data") && retStatsRespObj.has("rek"))
{
retStatsData = retStatsRespObj.getString("data");
retStatsRek = retStatsRespObj.getString("rek");
byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSek);
String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats));
byte[] retStatsRespJsonInBytes = aesEncryption.decodeBase64StringTOByte(retStatsRespJsoninBase64);
JSONObject retStatsJsonData = new JSONObject(new String(retStatsRespJsonInBytes));
System.out.println( "retStatsJsonData["+retStatsJsonData+"]");
if("IP".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
continue;
}
else if("P".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
break;
}
else if("PE".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
errMsg = getRetStatusErrMsg(retStatsJsonData);
retString = getError(errMsg, "GSTAPIERR", conn);
break;
}
}
else
{
JSONObject errorJSON = retStatusResp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else
{
JSONObject errorJSON = retStatusResp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("desc")+" \nError code : "+errorJSON.getString("code");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
}
else
{
JSONObject errorJSON = gstr1Resp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else
{
JSONObject errorJSON = gstr1Resp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("desc")+" \nError code : "+errorJSON.getString("code");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
catch (Exception e)
{
System.out.println("GSTDataSubmitWizPos.saveGstr1()["+e.getMessage()+"]");
e.printStackTrace();
}
return retString;
}
private String getGstr1Summary(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSek, String action, Connection conn)
{
String retString = "";
String errMsg = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
try
{
HttpResponse<JsonNode> getGstr1SumryResp = Unirest.get(String.format("%s/%s", GST_API_URL, GSTR1_URL))
.queryString("action","RETSUM")
.queryString("gstin", gstin)
.queryString("ret_period", periodCode)
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress.getHostAddress())
.header("username", userName)
.header("auth-token", authToken)
.header("app_key", appKeyEncryptedAndCoded)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.asJson();
System.out.println(String.format("getGstr1SumryResp Request : Status[%s] Response[%s]", getGstr1SumryResp.getStatus(), getGstr1SumryResp.getBody()));
if (getGstr1SumryResp.getStatus() == 200)
{
JSONObject getGstr1SumryRespObj = getGstr1SumryResp.getBody().getObject();
if(getGstr1SumryRespObj.has("data") && getGstr1SumryRespObj.has("rek"))
{
String gstr1Sumrydata = getGstr1SumryRespObj.getString("data");
String gstr1Sumryrek = getGstr1SumryRespObj.getString("rek");
byte[] apiEK = aesEncryption.decrypt(gstr1Sumryrek, authSek);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr1Sumrydata, apiEK));
byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64);
JSONObject gstr1SumryJsonObj = new JSONObject(new String(respJsonInBytes));
//String jsonData = new String(respJsonInBytes);
System.out.println(gstr1SumryJsonObj);
if("FILE".equalsIgnoreCase(action))
{
byte[] jsonBase64 = Base64.getEncoder().encode(gstr1SumryJsonObj.toString().getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
JSONObject fileGstr1DataJsonObj = new JSONObject();
fileGstr1DataJsonObj.put("action", "RETFILE");
fileGstr1DataJsonObj.put("data", encryptedPayload);
fileGstr1DataJsonObj.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
fileGstr1DataJsonObj.put("sign", "asfasfasfu3dsfkj3kjdv=");
fileGstr1DataJsonObj.put("st", "DSC");
fileGstr1DataJsonObj.put("sid", "AMAPT8269L");
HttpResponse<JsonNode> fileGstr1Resp = Unirest.post(String.format("%s/%s", GST_API_URL, GSTR1_URL))
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress.getHostAddress())
.header("username", userName)
.header("auth-token", authToken)
.header("app_key", appKeyEncryptedAndCoded)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.body(new JsonNode(fileGstr1DataJsonObj.toString()))
.asJson();
System.out.println(String.format("fileGstr1Resp Request : Status[%s] Response[%s]", fileGstr1Resp.getStatus(), fileGstr1Resp.getBody()));
if (fileGstr1Resp.getStatus() == 200)
{
JSONObject fileGstr1RespObj = fileGstr1Resp.getBody().getObject();
if(fileGstr1RespObj.has("data") && fileGstr1RespObj.has("rek"))
{
String fileGstr1Data = fileGstr1RespObj.getString("data");
String fileGstr1Rek = fileGstr1RespObj.getString("rek");
byte[] fileGstr1ApiEK = aesEncryption.decrypt(fileGstr1Rek, authSek);
String fileGstr1JsoninBase64 = new String(aesEncryption.decrypt(fileGstr1Data, fileGstr1ApiEK));
byte[] fileGstr1JsonInBytes = aesEncryption.decodeBase64StringTOByte(fileGstr1JsoninBase64);
System.out.println(new String(fileGstr1JsonInBytes));
}
else
{
JSONObject errorJSON = fileGstr1Resp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else
{
JSONObject errorJSON = fileGstr1Resp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
}
else
{
JSONObject errorJSON = getGstr1SumryResp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else
{
JSONObject errorJSON = getGstr1SumryResp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("desc")+" \nError code : "+errorJSON.getString("code");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.getGstr1Summary()["+e.getMessage()+"]");
e.printStackTrace();
}
return retString;
}
private String submitGstr1(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, Connection conn)
{
String retString = "";
String errMsg = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
try
{
String json = "{\"gstin\":\""+gstin+"\",\"ret_period\":\""+periodCode+"\"}";
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
JSONObject reqBody = new JSONObject();
reqBody.put("action", "RETSUBMIT");
reqBody.put("data", encryptedPayload);
reqBody.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
HttpResponse<JsonNode> gstr1SubmitResp = Unirest.post(String.format("%s/%s", GST_API_URL, GSTR1_URL))
.header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT")
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress.getHostAddress())
.header("username", userName)
.header("auth-token", authToken)
.header("app_key", appKeyEncryptedAndCoded)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.body(new JsonNode(reqBody.toString()))
.asJson();
System.out.println(String.format("gstr1SubmitResp Request : Status[%s] Response[%s]", gstr1SubmitResp.getStatus(), gstr1SubmitResp.getBody()));
if (gstr1SubmitResp.getStatus() == 200)
{
JSONObject gstr1SubmitRespObj = gstr1SubmitResp.getBody().getObject();
if(gstr1SubmitRespObj.has("data") && gstr1SubmitRespObj.has("rek"))
{
String gstr1Submitdata = gstr1SubmitRespObj.getString("data");
String gstr1Submitrek = gstr1SubmitRespObj.getString("rek");
byte[] apiEK = aesEncryption.decrypt(gstr1Submitrek, authSEK);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr1Submitdata, apiEK));
byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64);
JSONObject gstr1SubmitObj = new JSONObject(new String(respJsonInBytes));
String transId = gstr1SubmitObj.getString("reference_id");
System.out.println("transId to getStatus after SUBMIT call["+transId+"]");
}
else
{
JSONObject errorJSON = gstr1SubmitResp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else
{
JSONObject errorJSON = gstr1SubmitResp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("desc")+" \nError code : "+errorJSON.getString("code");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.submitGstr1()["+e.getMessage()+"]");
e.printStackTrace();
}
return retString;
}
private String getGstr2Invoices(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, Connection conn)
{
String retString = "";
String errMsg = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
try
{
HttpResponse<JsonNode> getGstr2InvoicesResp = Unirest.get(String.format("%s/%s", GST_API_URL, GSTR2_URL))
.queryString("action", "B2B")
.queryString("gstin", gstin)
.queryString("ret_period", periodCode)
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress.getHostAddress())
.header("username", userName)
.header("auth-token", authToken)
.header("app_key", appKeyEncryptedAndCoded)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.asJson();
System.out.println(String.format("getGstr2InvoicesResp Request : Status[%s] Response[%s]", getGstr2InvoicesResp.getStatus(), getGstr2InvoicesResp.getBody()));
if (getGstr2InvoicesResp.getStatus() == 200)
{
JSONObject getGstr2InvoicesRespObj = getGstr2InvoicesResp.getBody().getObject();
if(getGstr2InvoicesRespObj.has("data") && getGstr2InvoicesRespObj.has("rek"))
{
String gstr2InvoicesData = getGstr2InvoicesRespObj.getString("data");
String gstr2InvoicesRek = getGstr2InvoicesRespObj.getString("rek");
byte[] apiEK = aesEncryption.decrypt(gstr2InvoicesRek, authSEK);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr2InvoicesData, apiEK));
byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64);
JSONObject gstr2InvoiceJsonObj = new JSONObject(new String(respJsonInBytes));
System.out.println("respJsonInBytes["+new String(respJsonInBytes)+"]");
}
else
{
JSONObject errorJSON = getGstr2InvoicesResp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else
{
JSONObject errorJSON = getGstr2InvoicesResp.getBody().getObject().getJSONObject("error");
errMsg = "Message : "+errorJSON.getString("desc")+" \nError code : "+errorJSON.getString("code");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.getGstr2Invoices()["+e.getMessage()+"]");
e.printStackTrace();
}
return retString;
}
private String getError(String errMsg, String Code, Connection conn) throws ITMException, Exception
{
String mainStr ="";
try
{
String errString = "";
errString = new ITMDBAccessEJB().getErrorString("",Code,"","",conn);
String begPart = errString.substring(0,errString.indexOf("</description>"));
String endDesc = errString.substring(errString.indexOf("</description>"),errString.length());
mainStr = checkNullandTrim(begPart) + "<![CDATA[" +errMsg+ " ]]>" + checkNullandTrim(endDesc);
System.out.println("mainStr:::::::::::::::::: "+mainStr);
begPart = null;
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return mainStr;
}
private String getRetStatusErrMsg(JSONObject retStatusJsonObj)
{
String retString = "";
JSONObject errorJsonObj = null;
JSONArray eachInvErrorJsonArry = null;
try
{
errorJsonObj = retStatusJsonObj.getJSONObject("error_report");
if(errorJsonObj.has("b2b"))
{
eachInvErrorJsonArry = errorJsonObj.getJSONArray("b2b");
}
else if(errorJsonObj.has("b2ba"))
{
eachInvErrorJsonArry = errorJsonObj.getJSONArray("b2ba");
}
else if(errorJsonObj.has("b2cl"))
{
eachInvErrorJsonArry = errorJsonObj.getJSONArray("b2cl");
}
else if(errorJsonObj.has("b2cla"))
{
eachInvErrorJsonArry = errorJsonObj.getJSONArray("b2cla");
}
else if(errorJsonObj.has("b2cs"))
{
eachInvErrorJsonArry = errorJsonObj.getJSONArray("b2cs");
}
else if(errorJsonObj.has("b2csa"))
{
eachInvErrorJsonArry = errorJsonObj.getJSONArray("b2csa");
}
else if(errorJsonObj.has("cdnr"))
{
eachInvErrorJsonArry = errorJsonObj.getJSONArray("cdnr");
}
else if(errorJsonObj.has("cdnra"))
{
eachInvErrorJsonArry = errorJsonObj.getJSONArray("cdnra");
}
for(int i=0; i<eachInvErrorJsonArry.length(); i++)
{
JSONObject tempJsonObj = (JSONObject) eachInvErrorJsonArry.get(i);
retString += tempJsonObj.getString("error_msg")+"\n";
if(tempJsonObj.has("ty") && tempJsonObj.has("hsn_sc"))
{
retString += " Line Type : "+tempJsonObj.optString("ty")+ " Item/Service Code : "+tempJsonObj.optString("hsn_sc")+"\n";
}
else if(tempJsonObj.has("nt_num") && tempJsonObj.has("nt_dt"))
{
retString += " Credit/Debit No. : "+tempJsonObj.optString("nt_num")+ " Credit/Debit Dt. : "+tempJsonObj.optString("nt_dt")+"\n";
}
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.getRetStatusErrMsg()["+e.getMessage()+"]");
e.printStackTrace();
}
return retString;
}
private static String checkNullandTrim(String input)
{
if (input==null)
{
input="";
}
return input.trim();
}
}
package ibase.webitm.ejb.gst;
import java.rmi.RemoteException;
import java.sql.Connection;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
@javax.ejb.Local
public interface GSTDataSubmitWizPosLocal extends ValidatorLocal
{
public String postSave(String xmlStringAll, String dcrId, String editFlag, String xtraParams, Connection conn) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.gst;
import java.rmi.RemoteException;
import java.sql.Connection;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
@javax.ejb.Remote
public interface GSTDataSubmitWizPosRemote extends ValidatorLocal
{
public String postSave(String xmlStringAll, String dcrId, String editFlag, String xtraParams, Connection conn) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.gst;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.ejb.Stateless;
import org.apache.log4j.spi.ErrorCode;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Session Bean implementation class GstrIC
*/
@Stateless
public class GstrIC extends ValidatorEJB implements GstrICRemote, GstrICLocal
{
E12GenericUtility genericUtility = new E12GenericUtility();
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag,String xtraParams) throws RemoteException, ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String retString = "";
try
{
System.out.println("*************** Inside wfValData *******************");
if(xmlString != null && xmlString.trim().length()>0)
{
dom = genericUtility.parseString(xmlString);
}
if(xmlString1 != null && xmlString1.trim().length()>0)
{
dom1 = genericUtility.parseString(xmlString1);
}
if(xmlString2 != null && xmlString2.trim().length()>0)
{
dom2 = genericUtility.parseString(xmlString2);
}
retString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
System.out.println("errorString::::::::::"+retString);
}
catch(Exception e)
{
System.out.println(":::" + getClass().getSimpleName() + "::"+ e.getMessage());
e.getMessage();
}
return retString;
}
public String wfValData(Document dom, Document dom1, Document dom2,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{
E12GenericUtility genericUtility = new E12GenericUtility();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null ;
String sql="";
String userId = "";
int currentFormNo = 0;
NodeList parentNodeList = null;
Node parentNode = null;
NodeList childNodeList = null;
Node childNode = null;
int childNodeLength = 0;
int ctr = 0, cnt = 0;
String childNodeName = "";
String errorType = "",errString="";
String errCode = "";
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
String site_code="";
String rec_type="";
String tran_type="";
String submission_type="";
String state_code="";
String prd_code="";
String reco_status="";
String reas_code="";
String cust_name = "",tax_reg_no = "";
StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>");
try
{
conn = getConnection();
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
System.out.println("currentFormNo:::"+currentFormNo);
switch(currentFormNo)
{
case 1:
{
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
System.out.println("childNodeName:::"+childNodeName);
if("site_code".equalsIgnoreCase(childNodeName))
{
site_code = checkNull(genericUtility.getColumnValue("site_code",dom)).trim();
if(site_code != null && site_code.trim().length() > 0)
{
sql = "select count(*) as cnt from site where site_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,site_code);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(cnt==0)
{
errCode = "VTSITEXT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}// end of if block for site_code
else if("prd_code".equalsIgnoreCase(childNodeName))
{
prd_code = checkNull(genericUtility.getColumnValue("prd_code", dom)).trim();
if(prd_code == null || prd_code.trim().length() == 0)
{
errCode = "VPATDPRC01";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else
{
prd_code = checkNull(genericUtility.getColumnValue("prd_code", dom)).trim();
sql = "select count(*) as cnt from period where TO_CHAR(TO_DATE(code,'yyyymm'),'mmyyyy')=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prd_code);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(cnt==0)
{
errCode = "VTMONATD10";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}// end of if block for prd_code
else if("rec_type".equalsIgnoreCase(childNodeName))
{
rec_type = checkNull(genericUtility.getColumnValue("rec_type", dom)).trim();
if(rec_type != null && rec_type.trim().length() > 0)
{
sql = "select count(*) as cnt from gencodes where fld_name='REC_TYPE' and fld_value=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,rec_type);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(cnt==0)
{
errCode = "INVRECTYPE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}//end of if block for rec_type
else if("tran_type".equalsIgnoreCase(childNodeName))
{
tran_type = checkNull(genericUtility.getColumnValue("tran_type", dom)).trim();
if(tran_type == null || tran_type.trim().length() == 0)
{
errCode = "INVTRNTYPE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else
{
tran_type = checkNull(genericUtility.getColumnValue("tran_type", dom)).trim();
sql = "select count(*) as cnt from gencodes where fld_name='TRAN_TYPE' and fld_value=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tran_type);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(cnt==0)
{
errCode = "VMATRNTYPE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}//end of if block for tran_type
else if("cust_name".equalsIgnoreCase(childNodeName))
{
tran_type = checkNull(genericUtility.getColumnValue("tran_type", dom)).trim();
cust_name = checkNull(genericUtility.getColumnValue("cust_name", dom)).trim();
if((tran_type.equalsIgnoreCase("03")) || (tran_type.equalsIgnoreCase("04")) || (tran_type.equalsIgnoreCase("05")) || tran_type.equalsIgnoreCase("06"))
{
if(cust_name == null || cust_name.trim().length() == 0)
{
errCode = "VMATTDET01";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}//end of if block for cust_name
else if("state_code".equalsIgnoreCase(childNodeName))
{
state_code = checkNull(genericUtility.getColumnValue("state_code", dom)).trim();
if(state_code == null || state_code.trim().length() == 0)
{
errCode = "VMSTATE2";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else
{
state_code = checkNull(genericUtility.getColumnValue("state_code", dom)).trim();
sql = "select count(*) as cnt from state where state_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,state_code);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(cnt==0)
{
errCode = "VESTATCD2";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}//end of if block for state_code
else if("reas_code".equalsIgnoreCase(childNodeName))
{
reas_code = checkNull(genericUtility.getColumnValue("reas_code", dom)).trim();
if(reas_code != null && reas_code.trim().length() > 0)
{
sql = "select count(*) as cnt from gencodes where fld_name='REAS_CODE' AND MOD_NAME='W_DRCRRCP_CR' AND fld_value=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,reas_code);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(cnt == 0)
{
errCode = "VMREASCOIN";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}//end of if block for reas_code
else if("reco_status".equalsIgnoreCase(childNodeName))
{
reco_status = checkNull(genericUtility.getColumnValue("reco_status", dom)).trim();
if(reco_status != null && reco_status.trim().length() > 0)
{
sql= "select count(*) as cnt from gencodes where fld_name='RECO_STATUS' and fld_value=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,reco_status);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(cnt == 0)
{
errCode = "INVRECNSTS";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}// end of if block for reco_status
else if("tax_reg_no".equalsIgnoreCase(childNodeName))
{
tran_type = checkNull(genericUtility.getColumnValue("tran_type", dom)).trim();
tax_reg_no = checkNull(genericUtility.getColumnValue("tax_reg_no", dom)).trim();
if(tran_type.equalsIgnoreCase("07") || tran_type.equalsIgnoreCase("08") || tran_type.equalsIgnoreCase("12"))
{
if(tax_reg_no == null || tax_reg_no.trim().length() == 0)
{
errCode = "VMGTINCODE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}// end of if block for tax_reg_no
}//end of for loop
}//end of case1
break;
}
int errListSize = errList.size();
System.out.println("errListSize::::::::::"+errListSize);
int count = 0;
String errFldName = null;
if (errList != null && errListSize > 0)
{
for (count = 0; count < errListSize; count++)
{
errCode = errList.get(count);
errFldName = errFields.get(count);
System.out.println(" testing :errCode .:" + errCode);
errString = getErrorString(errFldName, errCode, userId);
System.out.println("errString>>>>>>>>>"+errString);
errorType = errorType(conn, errCode);
if (errString.length() > 0)
{
String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8, errString.indexOf("<trace>"));
bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8, errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
errString = "";
}
if (errorType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errList = null;
errFields.clear();
errFields = null;
errStringXml.append("</Errors> </Root> \r\n");
}
else
{
errStringXml = new StringBuffer("");
}
}
}//end of try block
catch(Exception e)
{
System.out.println("Exception ::"+e);
e.printStackTrace();
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
conn.close();
}
conn = null;
}
catch (Exception d)
{
d.printStackTrace();
throw new ITMException(d);
}
}
errString = errStringXml.toString();
System.out.println("testing : final errString : " + errString);
return errString;
}
private String checkNull(String input)
{
return input == null ? "" : input;
}
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom=null;
Document domhr=null;
Document domAll=null;
String retString="";
try
{
System.out.println("************** Inside itemChanged method ****************");
if(xmlString != null && xmlString.trim().length()>0)
{
dom = genericUtility.parseString(xmlString);
}
if(xmlString1 != null && xmlString1.trim().length()>0)
{
domhr = genericUtility.parseString(xmlString1);
}
if(xmlString2 != null && xmlString2.trim().length()>0)
{
domAll = genericUtility.parseString(xmlString2);
}
retString = itemChanged(dom,domhr,domAll,objContext,currentColumn,editFlag,xtraParams);
System.out.println("retString::::::::::"+retString);
}
catch(Exception e)
{
System.out.println(":::" + getClass().getSimpleName() + "::"+ e.getMessage());
e.getMessage();
}
return retString;
}
public String itemChanged(Document dom, Document dom1, Document dom2,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null ;
int currentFormNo=0,ctr = 0;
StringBuffer valueXmlString = new StringBuffer();
NodeList parentNodeList = null;
Node parentNode = null;
Node childNode = null;
NodeList childNodeList = null;
int childNodeLength = 0;
String childNodeName = "";
String columnValue="";
int childNodeListLength = 0;
String tran_id__ref="",rec_type="",tran_type="",state_code="",reco_status="",site_code="",cust_code="",cust_name="";
String sql="";
String doc_no="";
String docDateStr="";
double amount=0.0;
String recDescr ="",tranDescr="",stateDescr="",recoDescr="",siteDescr="";
java.util.Date doc_date=null;
String loginSite = "";
SimpleDateFormat sdf;
try
{
conn = getConnection();
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
System.out.println("[GstrIC] [itemChanged] :currentFormNo ....." +currentFormNo);
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
switch(currentFormNo)
{
case 1 :
{
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
valueXmlString.append("<Detail1>");
childNodeListLength = childNodeList.getLength();
System.out.println("currentColumn-------->>[" + currentColumn + "]");
if("itm_default".equalsIgnoreCase(currentColumn.trim()))
{
loginSite = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
valueXmlString.append("<tran_date>").append("<![CDATA[" + sdf.format(new Date())+ "]]>").append("</tran_date>");
//*****************changes for rec_type non-editable fields **************************
sql = "select fld_value,descr from gencodes where fld_name='REC_TYPE' and mod_name='W_GSTR'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next())
{
rec_type = rs.getString("fld_value");
recDescr = rs.getString("descr");
if(rec_type.equalsIgnoreCase("1") && recDescr.equalsIgnoreCase("GSTR1"))
{
valueXmlString.append("<rec_type>").append("<![CDATA["+rec_type+"]]>").append("</rec_type>");
valueXmlString.append("<rec_type_descr>").append("<![CDATA["+recDescr+"]]>").append("</rec_type_descr>");
}
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
//*****************changes for rec_type non-editable fields **************************
}//end of if block for itm_default
else if("itm_defaultedit".equalsIgnoreCase(currentColumn.trim()))
{
tran_id__ref = checkNull(genericUtility.getColumnValue("tran_id__ref", dom));
sql = "select doc_no,doc_date,amount from gst_data_hdr where tran_id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tran_id__ref);
rs = pstmt.executeQuery();
if(rs.next())
{
doc_no = rs.getString("doc_no");
doc_date = rs.getTimestamp("doc_date");
amount = rs.getDouble("amount");
System.out.println("doc_no::"+doc_no +"\t"+"doc_date::"+doc_date+"amount::"+amount);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(doc_date != null)
{
docDateStr=genericUtility.getValidDateString((doc_date).toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
}
else
{
docDateStr = "";
}
valueXmlString.append("<doc_no_old>").append("<![CDATA["+checkNull(doc_no)+"]]>").append("</doc_no_old>");
valueXmlString.append("<doc_date_1>").append("<![CDATA["+checkNull(docDateStr)+"]]>").append("</doc_date_1>");
valueXmlString.append("<amount_1>").append("<![CDATA["+amount+"]]>").append("</amount_1>");
rec_type = genericUtility.getColumnValue("rec_type", dom);
sql = "select descr from gencodes where fld_name='REC_TYPE' and fld_value=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,rec_type);
rs = pstmt.executeQuery();
if(rs.next())
{
recDescr = rs.getString("descr");
System.out.println("recDescr>>"+recDescr);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
valueXmlString.append("<rec_type_descr>").append("<![CDATA["+recDescr+"]]>").append("</rec_type_descr>");
tran_type = checkNull(genericUtility.getColumnValue("tran_type", dom));
sql = "select descr from gencodes where fld_name='TRAN_TYPE' and fld_value=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tran_type);
rs = pstmt.executeQuery();
if(rs.next())
{
tranDescr = rs.getString("descr");
System.out.println("tranDescr>>"+tranDescr);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
valueXmlString.append("<tran_type_descr>").append("<![CDATA["+tranDescr+"]]>").append("</tran_type_descr>");
state_code = checkNull(genericUtility.getColumnValue("state_code", dom));
sql = "select descr from state where state_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,state_code);
rs = pstmt.executeQuery();
if(rs.next())
{
stateDescr = rs.getString("descr");
System.out.println("stateDescr>>"+stateDescr);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
valueXmlString.append("<state_descr>").append("<![CDATA["+stateDescr+"]]>").append("</state_descr>");
reco_status = checkNull(genericUtility.getColumnValue("reco_status", dom));
sql = "select descr from gencodes where fld_name='RECO_STATUS' and fld_value=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,reco_status);
rs = pstmt.executeQuery();
if(rs.next())
{
recoDescr = rs.getString("descr");
System.out.println("recoDescr>>"+recoDescr);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
valueXmlString.append("<reco_status_descr>").append("<![CDATA["+recoDescr+"]]>").append("</reco_status_descr>");
site_code = checkNull(genericUtility.getColumnValue("site_code", dom));
sql = "select descr from site where site_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,site_code);
rs = pstmt.executeQuery();
if(rs.next())
{
siteDescr = rs.getString("descr");
System.out.println("siteDescr>>"+siteDescr);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
valueXmlString.append("<site_code_descr>").append("<![CDATA["+siteDescr+"]]>").append("</site_code_descr>");
}//end of if block for itm_defaultedit
else if ("tran_id__ref".equalsIgnoreCase(currentColumn.trim()))
{
tran_id__ref = checkNull(genericUtility.getColumnValue("tran_id__ref", dom));
sql = "select doc_no,doc_date,amount from gst_data_hdr where tran_id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tran_id__ref);
rs = pstmt.executeQuery();
if(rs.next())
{
doc_no = rs.getString("doc_no");
doc_date = rs.getTimestamp("doc_date");
amount = rs.getDouble("amount");
System.out.println("doc_no::"+doc_no +"\t"+"doc_date::"+doc_date+"amount::"+amount);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(doc_date != null)
{
docDateStr=genericUtility.getValidDateString((doc_date).toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
}
else
{
docDateStr = "";
}
valueXmlString.append("<doc_no_old>").append("<![CDATA["+checkNull(doc_no)+"]]>").append("</doc_no_old>");
valueXmlString.append("<doc_date_1>").append("<![CDATA["+checkNull(docDateStr)+"]]>").append("</doc_date_1>");
valueXmlString.append("<amount_1>").append("<![CDATA["+amount+"]]>").append("</amount_1>");
}//end of if block for tran_id__ref
else if("tran_type".equalsIgnoreCase(currentColumn.trim()))
{
tran_type = checkNull(genericUtility.getColumnValue("tran_type", dom));
sql = "select descr from gencodes where fld_name='TRAN_TYPE' and fld_value=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tran_type);
rs = pstmt.executeQuery();
if(rs.next())
{
tranDescr = rs.getString("descr");
System.out.println("descr>>"+tranDescr);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
valueXmlString.append("<tran_type_descr>").append("<![CDATA["+tranDescr+"]]>").append("</tran_type_descr>");
}//end of if block for tran_type
else if("state_code".equalsIgnoreCase(currentColumn.trim()))
{
state_code = checkNull(genericUtility.getColumnValue("state_code", dom));
sql = "select descr from state where state_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,state_code);
rs = pstmt.executeQuery();
if(rs.next())
{
stateDescr = rs.getString("descr");
System.out.println("descr>>"+stateDescr);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
valueXmlString.append("<state_descr>").append("<![CDATA["+stateDescr+"]]>").append("</state_descr>");
}//end of if block for state_code
else if("reco_status".equalsIgnoreCase(currentColumn.trim()))
{
reco_status = checkNull(genericUtility.getColumnValue("reco_status", dom));
sql = "select descr from gencodes where fld_name='RECO_STATUS' and fld_value=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,reco_status);
rs = pstmt.executeQuery();
if(rs.next())
{
recoDescr = rs.getString("descr");
System.out.println("recoDescr>>"+recoDescr);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
valueXmlString.append("<reco_status_descr>").append("<![CDATA["+recoDescr+"]]>").append("</reco_status_descr>");
}// end of if block for reco_status
else if("site_code".equalsIgnoreCase(currentColumn.trim()))
{
site_code = checkNull(genericUtility.getColumnValue("site_code", dom));
sql = "select descr from site where site_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,site_code);
rs = pstmt.executeQuery();
if(rs.next())
{
siteDescr = rs.getString("descr");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
valueXmlString.append("<site_descr>").append("<![CDATA["+siteDescr+"]]>").append("</site_descr>");
}//end of if block for site_code
else if("cust_code".equalsIgnoreCase(currentColumn.trim()))
{
cust_code = checkNull(genericUtility.getColumnValue("cust_code", dom));
System.out.println("cust_code>>>>"+cust_code);
sql = "select cust_name from customer where cust_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,cust_code);
rs = pstmt.executeQuery();
if(rs.next())
{
cust_name = rs.getString("cust_name");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
valueXmlString.append("<cust_name>").append("<![CDATA["+cust_name+"]]>").append("</cust_name>");
}//end of if block for cust_code
valueXmlString.append("</Detail1>");
break;
}//end of case1
}//end of switch block
valueXmlString.append("</Root>");
}//end of try block
catch(Exception e)
{
System.out.println(":::" + getClass().getSimpleName() + "::"+ e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
conn.close();
}
conn = null;
}
catch (Exception d)
{
d.printStackTrace();
throw new ITMException(d);
}
}
return valueXmlString.toString();
}
private String errorType(Connection conn, String errorCode) throws ITMException
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String sql = "SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
if (rs.next())
{
msgType = rs.getString("MSG_TYPE");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
}
catch (Exception ex)
{
ex.printStackTrace();
throw new ITMException(ex);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return msgType;
}
}
package ibase.webitm.ejb.gst;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.w3c.dom.Document;
@Local
public interface GstrICLocal extends ValidatorLocal
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.gst;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import org.w3c.dom.Document;
@Remote
public interface GstrICRemote extends ValidatorRemote
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.servlet.gst;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.zip.GZIPOutputStream;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ibase.system.config.AppConnectParm;
import ibase.utility.CommonConstants;
import ibase.webitm.ejb.gst.GSTDataSubmitWizEJBRemote;
import ibase.webitm.utility.ITMException;
public class GSTDataSubmitWizServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
InitialContext ctx = null;
public GSTDataSubmitWizServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost( request, response );
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
System.out.println("XXXXXXXXXXXXXXXXXXXXXX[ GSTDataSubmitWizServlet START]XXXXXXXXXXXXXXXXXXXX");
request.setCharacterEncoding(CommonConstants.ENCODING);
String action = "", responseXML = "";
GSTDataSubmitWizEJBRemote gstDataSubmitWizRemote = null;
try
{
action = request.getParameter("action");
System.out.println("GSTDataSubmitWizServlet ACTION ["+action+"]");
if("".equalsIgnoreCase(action))
{
}
else
{
HashMap<String,String> requestParamMap = new HashMap<String,String>();
String paramName = "", paramValue = "";
@SuppressWarnings("unchecked")
Enumeration<String> reqParams = request.getParameterNames();
while(reqParams.hasMoreElements())
{
Object paramObj = reqParams.nextElement();
paramName = (String) paramObj;
paramValue = (String)request.getParameter(paramName);
if(!paramValue.equalsIgnoreCase(""))
requestParamMap.put(paramName,paramValue);
}
System.out.println("Request Parameter map :"+requestParamMap);
ctx=getInitialContext();
gstDataSubmitWizRemote = (ibase.webitm.ejb.gst.GSTDataSubmitWizEJBRemote) ctx.lookup("ibase/GSTDataSubmitWizEJB/remote");
responseXML = gstDataSubmitWizRemote.handleRequest(requestParamMap);
response.setContentType("text/xml");
if(CommonConstants.CONTENT_ENCODING != null && CommonConstants.CONTENT_ENCODING.equalsIgnoreCase("gzip"))
{
response.setHeader("Content-Encoding", "gzip");
GZIPOutputStream gzOutStream = new GZIPOutputStream(response.getOutputStream());
gzOutStream.write(responseXML.getBytes());
gzOutStream.flush();
gzOutStream.close();
}
else
{
response.setHeader("Content-Encoding", "");
OutputStream outStream = response.getOutputStream();
outStream.write(responseXML.getBytes());
outStream.flush();
outStream.close();
}
}
}
catch (Exception e)
{
System.out.println("GSTDataSubmitWizServlet.doPost():doPost"+e.getMessage());
e.printStackTrace();
}
System.out.println("XXXXXXXXXXXXXXXXXXXXXX[ GSTDataSubmitWizServlet END]XXXXXXXXXXXXXXXXXXXX");
}
protected InitialContext getInitialContext()throws ITMException
{
InitialContext ctx = null;
try
{
AppConnectParm appConnect = new AppConnectParm();
ctx = new InitialContext(appConnect.getProperty());
}
catch(ITMException itme)
{
System.out.println("GSTDataSubmitWizServlet.getInitialContext()");
throw itme;
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizServlet.getInitialContext()"+e.getMessage());
throw new ITMException(e);
}
return ctx;
}
}
package ibase.webitm.util.gst;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
public class AESEncryption
{
private final String AES_TRANSFORMATION = "AES/ECB/PKCS5Padding";
private final String AES_ALGORITHM = "AES";
private final int ENC_BITS = 256;
private final String CHARACTER_ENCODING = "UTF-8";
private Cipher ENCRYPT_CIPHER;
private Cipher DECRYPT_CIPHER;
private KeyGenerator KEYGEN;
public AESEncryption() throws Exception
{
ENCRYPT_CIPHER = Cipher.getInstance(AES_TRANSFORMATION);
DECRYPT_CIPHER = Cipher.getInstance(AES_TRANSFORMATION);
KEYGEN = KeyGenerator.getInstance(AES_ALGORITHM);
KEYGEN.init(ENC_BITS);
}
public String encodeBase64String(byte[] bytes)
{
return new String(java.util.Base64.getEncoder().encode(bytes));
}
public byte[] decodeBase64StringTOByte(String stringData) throws Exception
{
return java.util.Base64.getDecoder().decode(stringData.getBytes(CHARACTER_ENCODING));
}
public String generateSecureKey() throws Exception
{
SecretKey secretKey = KEYGEN.generateKey();
return encodeBase64String(secretKey.getEncoded());
}
public String encryptEK(byte[] plainText, byte[] secret) throws Exception
{
SecretKeySpec sk = new SecretKeySpec(secret, AES_ALGORITHM);
ENCRYPT_CIPHER.init(Cipher.ENCRYPT_MODE, sk);
return Base64.encodeBase64String(ENCRYPT_CIPHER.doFinal(plainText));
}
public byte[] decrypt(String plainText, byte[] secret) throws Exception
{
SecretKeySpec sk = new SecretKeySpec(secret, AES_ALGORITHM);
DECRYPT_CIPHER.init(Cipher.DECRYPT_MODE, sk);
return DECRYPT_CIPHER.doFinal(Base64.decodeBase64(plainText));
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import ibase.webitm.bean.gst.AT;
import ibase.webitm.bean.gst.InvLineItem;
public class ATSearializer extends BaseSerializer<AT>
{
@Override
public void serialize(AT at, JsonGenerator json, SerializerProvider serializeProvider) throws IOException, JsonProcessingException
{
json.writeStartObject();
json.writeStringField("typ", at.typ);
json.writeStringField("cpty", at.cpty);
json.writeStringField("state_cd", at.stateCode);
json.writeStringField("doc_num", at.docNum);
json.writeStringField("doc_dt", gstFmt.format(at.docDt));
writeLineItems(at, json);
json.writeEndObject();
}
private void writeLineItems(AT at, JsonGenerator json) throws IOException
{
json.writeFieldName("itms");
json.writeStartArray();
for(InvLineItem li : at.itms)
{
writeLineItem(json, li);
}
json.writeEndArray();
}
private void writeLineItem(JsonGenerator json, InvLineItem li)
{
try
{
json.writeStartObject();
json.writeStringField("ty", li.ty);
json.writeStringField("hsn_sc", li.hsn_sc);
json.writeNumberField("ad_amt", li.taxval);
json.writeNumberField("irt", li.irt);
json.writeNumberField("iamt", li.iamt);
json.writeNumberField("crt", li.crt);
json.writeNumberField("camt", li.camt);
json.writeNumberField("srt", li.srt);
json.writeNumberField("samt", li.samt);
json.writeNumberField("csrt", li.csrt);
json.writeNumberField("csamt", li.csamt);
json.writeEndObject();
}
catch (Exception e)
{
System.out.println("ATSearializer.writeLineItem()["+e.getMessage()+"]");
e.printStackTrace();
}
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import ibase.webitm.bean.gst.B2BA;
public class B2BASerializer extends BaseSerializer<B2BA>
{
@Override
public void serialize(B2BA b2ba, final JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonProcessingException
{
json.writeStartObject();
json.writeStringField("ctin", b2ba.ctin);
writeInvoices(b2ba, json);
json.writeEndObject();
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import ibase.webitm.bean.gst.B2B;
public class B2BSerializer extends BaseSerializer<B2B>
{
@Override
public void serialize(B2B b2B, final JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonProcessingException
{
json.writeStartObject();
json.writeStringField("ctin", b2B.ctin);
writeInvoices(b2B, json);
json.writeEndObject();
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import ibase.webitm.bean.gst.B2CL;
import ibase.webitm.bean.gst.B2CLA;
public class B2CLASerializer extends BaseSerializer<B2CLA> {
@Override
public void serialize(B2CLA b2cla, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonProcessingException
{
json.writeStartObject();
json.writeStringField("state_cd", b2cla.stateCode);
writeInvoices(b2cla, json);
json.writeEndObject();
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import ibase.webitm.bean.gst.B2CL;
public class B2CLSerializer extends BaseSerializer<B2CL> {
@Override
public void serialize(B2CL b2cl, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonProcessingException
{
json.writeStartObject();
json.writeStringField("state_cd", b2cl.stateCode);
writeInvoices(b2cl, json);
json.writeEndObject();
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import ibase.webitm.bean.gst.B2CSA;
public class B2CSASerializer extends BaseSerializer<B2CSA>
{
@Override
public void serialize(B2CSA b2csa, JsonGenerator json, SerializerProvider serializerProvider)throws IOException, JsonProcessingException
{
json.writeStartObject();
json.writeStringField("omon", b2csa.orgPeriodCode);
json.writeStringField("oty", b2csa.orgType);
json.writeStringField("ohsn_sc", b2csa.orgItemOrServiceCode);
json.writeStringField("osupst_cd", b2csa.orgStateCode);
json.writeStringField("state_cd", b2csa.stateCode);
json.writeStringField("ty", b2csa.ty);
json.writeStringField("hsn_sc", b2csa.itemOrServiceCode);
json.writeNumberField("txval", b2csa.txval);
json.writeNumberField("irt", b2csa.irt);
json.writeNumberField("iamt", b2csa.iamt);
json.writeNumberField("crt", b2csa.crt);
json.writeNumberField("camt", b2csa.camt);
json.writeNumberField("srt", b2csa.srt);
json.writeNumberField("samt", b2csa.samt);
json.writeNumberField("csrt", b2csa.csrt);
json.writeNumberField("csamt", b2csa.csamt);
json.writeStringField("prs", b2csa.prs ? "Y" : "N");
if(b2csa.prs)
{
json.writeStringField("od_num", b2csa.od_num);
json.writeStringField("od_dt", gstFmt.format(b2csa.od_dt));
}
if(b2csa.etin!=null)
{
json.writeStringField("etin", b2csa.etin);
}
json.writeStringField("typ", b2csa.typ);
json.writeEndObject();
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import ibase.webitm.bean.gst.B2CS;
public class B2CSSerializer extends BaseSerializer<B2CS>
{
@Override
public void serialize(B2CS b2cs, JsonGenerator json, SerializerProvider serializerProvider)throws IOException, JsonProcessingException
{
json.writeStartObject();
json.writeStringField("state_cd", b2cs.stateCode);
json.writeStringField("ty", b2cs.ty);
json.writeStringField("hsn_sc", b2cs.itemOrServiceCode);
json.writeNumberField("txval", b2cs.txval);
json.writeNumberField("irt", b2cs.irt);
json.writeNumberField("iamt", b2cs.iamt);
json.writeNumberField("crt", b2cs.crt);
json.writeNumberField("camt", b2cs.camt);
json.writeNumberField("srt", b2cs.srt);
json.writeNumberField("samt", b2cs.samt);
json.writeNumberField("csrt", b2cs.csrt);
json.writeNumberField("csamt", b2cs.csamt);
json.writeStringField("prs", b2cs.prs ? "Y" : "N");
if(b2cs.prs)
{
json.writeStringField("od_num", b2cs.od_num);
json.writeStringField("od_dt", gstFmt.format(b2cs.od_dt));
}
if(b2cs.etin!=null)
{
json.writeStringField("etin", b2cs.etin);
}
json.writeStringField("typ", b2cs.typ);
json.writeEndObject();
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import java.text.SimpleDateFormat;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import ibase.webitm.bean.gst.BaseData;
import ibase.webitm.bean.gst.InvLineItem;
import ibase.webitm.bean.gst.Invoice;
abstract class BaseSerializer<T extends BaseData> extends JsonSerializer<T>
{
final SimpleDateFormat gstFmt = new SimpleDateFormat("dd-MM-yyyy");
void writeInvoices(T genericInvoice, JsonGenerator json) throws IOException
{
json.writeFieldName("inv");
json.writeStartArray();
for(Invoice inv : genericInvoice.invoices)
{
writeInvoice(genericInvoice, json, inv);
}
json.writeEndArray();
}
private void writeInvoice(T genericInvoice, JsonGenerator json, Invoice inv)
{
try
{
json.writeStartObject();
if( (inv.flag != null) && ("A".equalsIgnoreCase(inv.flag) || "M".equalsIgnoreCase(inv.flag) || "D".equalsIgnoreCase(inv.flag)) )
{
json.writeStringField("flag", inv.flag);
json.writeStringField("inum", inv.inum);
json.writeStringField("idt", gstFmt.format(inv.idt));
json.writeStringField("chksum", inv.checksum);
}
else
{
if (inv.oinum != null && inv.oidt != null)
{
json.writeStringField("oinum", inv.oinum);
json.writeStringField("oidt", gstFmt.format(inv.oidt));
}
if(inv.cname != null)
{
json.writeStringField("cname", inv.cname);
}
json.writeStringField("inum", inv.inum);
json.writeStringField("idt", gstFmt.format(inv.idt));
json.writeNumberField("val", inv.val);
json.writeStringField("pos", inv.pos);
if(genericInvoice.isReverseCharge)
{
json.writeStringField("rchrg", inv.rchrg ? "Y" : "N");
}
json.writeStringField("prs", inv.prs ? "Y" : "N");
if (inv.prs)
{
json.writeStringField("od_num", inv.od_num);
json.writeStringField("od_dt", gstFmt.format(inv.od_dt));
}
if(inv.etin!=null)
{
json.writeStringField("etin", inv.etin);
}
writeLineItems(genericInvoice, json, inv);
}
json.writeEndObject();
}
catch (Exception e)
{
System.out.println("BaseSerializer.writeInvoice()["+e.getMessage()+"]");
e.printStackTrace();
}
}
private void writeLineItems(T genericInvoice, JsonGenerator json, Invoice inv) throws IOException
{
json.writeFieldName("itms");
json.writeStartArray();
for(InvLineItem li : inv.items)
{
writeLineItem(genericInvoice, json, li);
}
json.writeEndArray();
}
private void writeLineItem(T genericInvoice, JsonGenerator json, InvLineItem li)
{
try
{
json.writeStartObject();
json.writeNumberField("num", li.num);
json.writeFieldName("itm_det");
json.writeStartObject();
json.writeStringField("ty", li.ty);
json.writeStringField("hsn_sc", li.hsn_sc);
json.writeNumberField("txval", li.taxval);
json.writeNumberField("irt", li.irt);
json.writeNumberField("iamt", li.iamt);
json.writeNumberField("crt", li.crt);
json.writeNumberField("camt", li.camt);
json.writeNumberField("srt", li.srt);
json.writeNumberField("samt", li.samt);
json.writeNumberField("csrt", li.csrt);
json.writeNumberField("csamt", li.csamt);
json.writeEndObject();
json.writeEndObject();
}
catch (Exception e)
{
System.out.println("BaseSerializer.writeLineItem()["+e.getMessage()+"]");
e.printStackTrace();
}
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import java.text.SimpleDateFormat;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import ibase.webitm.bean.gst.CDNDetails;
import ibase.webitm.bean.gst.CDNRA;
public class CDNRASerializer extends JsonSerializer<CDNRA>
{
final SimpleDateFormat gstFmt = new SimpleDateFormat("dd-MM-yyyy");
@Override
public void serialize(CDNRA cdnra, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonProcessingException
{
json.writeStartObject();
json.writeStringField("ctin", cdnra.ctin);
json.writeFieldName("nt");
json.writeStartArray();
for(CDNDetails cdnDetails : cdnra.cdnDetails)
{
writeCDNDetails(cdnra, json, cdnDetails);
}
json.writeEndArray();
json.writeEndObject();
}
private void writeCDNDetails(CDNRA cdnra, JsonGenerator json, CDNDetails cdnDetails)
{
try
{
json.writeStartObject();
json.writeStringField("ntty", cdnDetails.cdnNoteType);
json.writeStringField("nt_num", cdnDetails.cdNoteNumber);
json.writeStringField("nt_dt", gstFmt.format(cdnDetails.cdNoteDate));
json.writeStringField("rsn", cdnDetails.reason);
if(cdnDetails.orgCDNoteNumber != null && cdnDetails.orgCDNoteDate != null)
{
json.writeStringField("ont_num", cdnDetails.orgCDNoteNumber);
json.writeStringField("ont_dt", gstFmt.format(cdnDetails.orgCDNoteDate));
}
json.writeStringField("inum", cdnDetails.invoiceNumber);
json.writeStringField("idt", gstFmt.format(cdnDetails.invoiceDate));
if(cdnra.isReverseCharge)
{
json.writeStringField("rchrg", cdnDetails.rchrg ? "Y" : "N");
}
json.writeNumberField("val", cdnDetails.val);
json.writeNumberField("irt", cdnDetails.irt);
json.writeNumberField("iamt", cdnDetails.iamt);
json.writeNumberField("crt", cdnDetails.crt);
json.writeNumberField("camt", cdnDetails.camt);
json.writeNumberField("srt", cdnDetails.srt);
json.writeNumberField("samt", cdnDetails.samt);
json.writeNumberField("csrt", cdnDetails.csrt);
json.writeNumberField("csamt", cdnDetails.csamt);
if(cdnDetails.etin!=null)
{
json.writeStringField("etin", cdnDetails.etin);
}
json.writeEndObject();
}
catch(Exception e)
{
System.out.println("CDNRASerializer.writecdnDetails()["+e.getMessage()+"]");
e.printStackTrace();
}
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import java.text.SimpleDateFormat;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import ibase.webitm.bean.gst.CDNDetails;
import ibase.webitm.bean.gst.CDNR;
public class CDNRSerializer extends JsonSerializer<CDNR>
{
final SimpleDateFormat gstFmt = new SimpleDateFormat("dd-MM-yyyy");
@Override
public void serialize(CDNR cdnr, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonProcessingException
{
json.writeStartObject();
json.writeStringField("ctin", cdnr.ctin);
json.writeFieldName("nt");
json.writeStartArray();
for(CDNDetails cdnDetails : cdnr.cdnDetails)
{
writeCDNDetails(cdnr, json, cdnDetails);
}
json.writeEndArray();
json.writeEndObject();
}
private void writeCDNDetails(CDNR cdnr, JsonGenerator json, CDNDetails cdnDetails)
{
try
{
json.writeStartObject();
json.writeStringField("ntty", cdnDetails.cdnNoteType);
json.writeStringField("nt_num", cdnDetails.cdNoteNumber);
json.writeStringField("nt_dt", gstFmt.format(cdnDetails.cdNoteDate));
json.writeStringField("rsn", cdnDetails.reason);
json.writeStringField("inum", cdnDetails.invoiceNumber);
json.writeStringField("idt", gstFmt.format(cdnDetails.invoiceDate));
if(cdnr.isReverseCharge)
{
json.writeStringField("rchrg", cdnDetails.rchrg ? "Y" : "N");
}
json.writeNumberField("val", cdnDetails.val);
json.writeNumberField("irt", cdnDetails.irt);
json.writeNumberField("iamt", cdnDetails.iamt);
json.writeNumberField("crt", cdnDetails.crt);
json.writeNumberField("camt", cdnDetails.camt);
json.writeNumberField("srt", cdnDetails.srt);
json.writeNumberField("samt", cdnDetails.samt);
json.writeNumberField("csrt", cdnDetails.csrt);
json.writeNumberField("csamt", cdnDetails.csamt);
if(cdnDetails.etin!=null)
{
json.writeStringField("etin", cdnDetails.etin);
}
json.writeEndObject();
}
catch(Exception e)
{
System.out.println("CDNRSerializer.writecdnDetails()["+e.getMessage()+"]");
e.printStackTrace();
}
}
}
package ibase.webitm.util.gst;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import ibase.webitm.bean.gst.GSTR1;
public class GSTR1Serailizer extends JsonSerializer<GSTR1> {
@Override
public void serialize(GSTR1 gstr1, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException
{
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("gstin", gstr1.gstin);
jsonGenerator.writeStringField("fp", gstr1.financialPeriod);
jsonGenerator.writeNumberField("gt", gstr1.grossTurnOver);
if(gstr1.b2b != null)
{
jsonGenerator.writeObjectField("b2b", gstr1.b2b);
}
if(gstr1.b2ba != null)
{
jsonGenerator.writeObjectField("b2ba", gstr1.b2ba);
}
if(gstr1.b2cl != null)
{
jsonGenerator.writeObjectField("b2cl", gstr1.b2cl);
}
if(gstr1.b2cla != null)
{
jsonGenerator.writeObjectField("b2cla", gstr1.b2cla);
}
if(gstr1.b2cs != null)
{
jsonGenerator.writeObjectField("b2cs", gstr1.b2cs);
}
if(gstr1.b2csa != null)
{
jsonGenerator.writeObjectField("b2csa", gstr1.b2csa);
}
if(gstr1.cdnr != null)
{
jsonGenerator.writeObjectField("cdnr", gstr1.cdnr);
}
if(gstr1.cdnra != null)
{
jsonGenerator.writeObjectField("cdnra", gstr1.cdnra);
}
jsonGenerator.writeEndObject();
}
}
package ibase.webitm.util.gst;
import java.io.InputStream;
import java.security.PublicKey;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import javax.crypto.Cipher;
/**
* This class is used to encrypt the string using a
* public publicKey
*/
public class PubKeyEncryption {
private PublicKey publicKey;
public PubKeyEncryption(InputStream pubKeyUrl) throws Exception
{
this.publicKey = readPublicKey(pubKeyUrl);
}
private PublicKey readPublicKey(InputStream fin) throws Exception
{
CertificateFactory f = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate) f.generateCertificate(fin);
return certificate.getPublicKey();
}
/**
* This method is used to encrypt the string , passed to it
* using a public publicKey provided
*
* @param plaintext : Text to encrypt
* @return :encrypted string
*/
public String encrypt(byte[] plaintext) throws Exception
{
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] encryptedByte = cipher.doFinal(plaintext);
return new String(java.util.Base64.getEncoder().encode(encryptedByte));
}
}
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