Commit e3adfffb authored by steurwadkar's avatar steurwadkar

F17ABAS001 source code commit


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@106355 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 1f46159a
package ibase.webitm.bean.gst;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ibase.webitm.util.gst.B2BURSerializer;
@JsonSerialize(using = B2BURSerializer.class)
public class B2BUR extends BaseData
{
}
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.GSTR2Serailizer;
@JsonSerialize(using = GSTR2Serailizer.class)
public class GSTR2
{
@JsonProperty("gstin")
public String gstin;
@JsonProperty("fp")
public String financialPeriod;
@JsonProperty("b2b")
public List<B2B> b2b;
@JsonProperty("b2bur")
public List<B2BUR> b2bur;
@JsonProperty("cdn")
public List<CDNR> cdnr;
@JsonProperty("hsnsum")
public HSN hsn;
}
......@@ -9,5 +9,7 @@ import ibase.webitm.util.gst.HSNSerializer;
@JsonSerialize(using = HSNSerializer.class)
public class HSN extends BaseData
{
public String recType;
public List<HSNDetails> hsnDetails;
}
......@@ -16,4 +16,14 @@ public class InvLineItem {
public double samt;
public double csamt;
public String itcType;
public double igstInputTax;
public double cgstInputTax;
public double sgstInputTax;
public double cessInputTax;
}
......@@ -567,6 +567,10 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
summaryDataJsonStr += getGstr1Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn);
retXML = "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>";
}
else if("GETINV".equalsIgnoreCase(action))
{
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
}
}
}
......@@ -964,11 +968,12 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
@Override
public String handleRequest(HashMap<String, String> reqParamMap, UserInfoBean userInfo) throws ITMException
{
String retResponseXML = "", action = "";
String retResponseXML = "", action = "", dataAction = "", errorCode = "", dataErrMsg = "";
String sql = "";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean isDataError = false;
try
{
action = reqParamMap.get("action");
......@@ -976,7 +981,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
if("GENERATE_OTP".equalsIgnoreCase(action))
{
String userName = "", stateCode = "", gspAuthString = "", gspAuthSignature = "", gstinNo = "", periodCode = "", siteCode = "", recType = "";
String userName = "", stateCode = "", gspAuthString = "", gspAuthSignature = "", gstinNo = "", periodCode = "", siteCode = "", recType = "", recordType = "";
String responseId = "", responseJsonStr = "", callStatus = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
long timeStamp = new Timestamp().getDateTime();
......@@ -992,98 +997,355 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
gstinNo = reqParamMap.get("gstin_no");
periodCode = reqParamMap.get("period_code");
siteCode = reqParamMap.get("site_code");
dataAction = reqParamMap.get("data_action");
recordType = reqParamMap.get("rec_type");
if("GSTR1".equalsIgnoreCase(reqParamMap.get("rec_type")))
if("GSTR1".equalsIgnoreCase(recordType))
{
recType = "1";
}
else if("GSTR2".equalsIgnoreCase(reqParamMap.get("rec_type")))
else if("GSTR2".equalsIgnoreCase(recordType))
{
recType = "2";
}
else if("GSTR3".equalsIgnoreCase(reqParamMap.get("rec_type")))
else if("GSTR3".equalsIgnoreCase(recordType))
{
recType = "3";
}
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
if("SAVE".equalsIgnoreCase(dataAction))
{
sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE REC_TYPE = ? AND SUBMIT_STATUS = 'P' AND PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, recType);
pstmt.setString(2, periodCode);
pstmt.setString(3, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") == 0)
{
isDataError = true;
errorCode = "VTNOGSDATA";
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE REC_TYPE = ? AND SUBMIT_STATUS = 'S' AND PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, recType);
pstmt.setString(2, periodCode);
pstmt.setString(3, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") > 0)
{
isDataError = true;
errorCode = "VTSUBALRDY";
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE REC_TYPE = ? AND SUBMIT_STATUS = 'R' AND PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, recType);
pstmt.setString(2, periodCode);
pstmt.setString(3, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") > 0)
{
isDataError = true;
errorCode = "VTFILALRDY";
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
}
if("SUBMIT".equalsIgnoreCase(dataAction))
{
sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE REC_TYPE = ? AND SUBMIT_STATUS = 'S' AND PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, recType);
pstmt.setString(2, periodCode);
pstmt.setString(3, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") > 0)
{
isDataError = true;
errorCode = "VTSUBALRDY";
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE REC_TYPE = ? AND SUBMIT_STATUS = 'T' AND PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, recType);
pstmt.setString(2, periodCode);
pstmt.setString(3, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") == 0)
{
isDataError = true;
errorCode = "VTNORECSAV";
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE REC_TYPE = ? AND SUBMIT_STATUS = 'R' AND PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, recType);
pstmt.setString(2, periodCode);
pstmt.setString(3, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") > 0)
{
isDataError = true;
errorCode = "VTFILALRDY";
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
}
if("FILE".equalsIgnoreCase(dataAction))
{
sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE REC_TYPE = ? AND SUBMIT_STATUS = 'S' AND PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, recType);
pstmt.setString(2, periodCode);
pstmt.setString(3, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") == 0)
{
isDataError = true;
errorCode = "VTGSTSUBPN";
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE REC_TYPE = ? AND SUBMIT_STATUS = 'R' AND PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, recType);
pstmt.setString(2, periodCode);
pstmt.setString(3, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") > 0)
{
isDataError = true;
errorCode = "VTGSTFILE";
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
}
if("GETINV".equalsIgnoreCase(dataAction))
{
sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE REC_TYPE = ? AND SUBMIT_STATUS = 'T' AND PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, recType);
pstmt.setString(2, periodCode);
pstmt.setString(3, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") == 0)
{
isDataError = true;
errorCode = "VTNORECSAV";
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
}
JSONObject otpRequest = new JSONObject();
otpRequest.put("action", "OTPREQUEST");
otpRequest.put("app_key", appKeyEncryptedAndCoded);
otpRequest.put("username", userName);
if(!isDataError)
{
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
JSONObject otpRequest = new JSONObject();
otpRequest.put("action", "OTPREQUEST");
otpRequest.put("app_key", appKeyEncryptedAndCoded);
otpRequest.put("username", userName);
HttpRequest otpReq = Unirest.post(String.format("%s%s", GSP_API_URL,AUTH_TOKEN_URL_V2))
.header("Content-Type", APPLICATION_JSON)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("state-cd", stateCode)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("txn", transactionId)
.header("app_key", appKeyEncryptedAndCoded)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(otpRequest.toString()))
.getHttpRequest();
System.out.println("OTP url["+otpReq.getUrl()+"]");
System.out.println("OTP method["+otpReq.getHttpMethod()+"]");
System.out.println("OTP request header["+otpReq.getHeaders()+"]");
System.out.println("OTP request payload["+IOUtils.toString(otpReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> otpResp = otpReq.asJson();
HttpRequest otpReq = Unirest.post(String.format("%s%s", GSP_API_URL,AUTH_TOKEN_URL_V2))
.header("Content-Type", APPLICATION_JSON)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("state-cd", stateCode)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("txn", transactionId)
.header("app_key", appKeyEncryptedAndCoded)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(otpRequest.toString()))
.getHttpRequest();
System.out.println("OTP url["+otpReq.getUrl()+"]");
System.out.println("OTP method["+otpReq.getHttpMethod()+"]");
System.out.println("OTP request header["+otpReq.getHeaders()+"]");
System.out.println("OTP request payload["+IOUtils.toString(otpReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> otpResp = otpReq.asJson();
System.out.println(String.format("OTP Request : Status[%s] Response[%s]", otpResp.getStatus(), otpResp.getBody()));
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")))
{
callStatus = "1";
retResponseXML = "<root><message><![CDATA["+object.getString("status_cd")+"]]></message></root>";
}
else
{
callStatus = "2";
JSONObject errorJSON = otpResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
retResponseXML = "<root><message><![CDATA[Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd")+"]]></message></root>";
}
}
else if(otpResp.getStatus() == 500)
{
callStatus = "2";
String errMsg = "Message : Error occurred at GSTN server \nResponse code : "+otpResp.getStatus();
responseJsonStr = errMsg;
retResponseXML = "<root><message><![CDATA[Message : "+errMsg+" \nError code : "+otpResp.getStatus()+"]]></message></root>";
}
else
{
callStatus = "2";
JSONObject errorJSON = otpResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
retResponseXML = "<root><message><![CDATA[Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd")+"]]></message></root>";
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(userInfo.getLoginCode());
apiCallData.setCallType("OTPREQUEST");
apiCallData.setRecType(recType);
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(userInfo.getLoginCode());
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(userInfo.getRemoteHost());
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
if (otpResp.getStatus() == 200)
{
JSONObject object = otpResp.getBody().getObject();
if( object.has("status_cd") && "1".equalsIgnoreCase(object.getString("status_cd")))
{
callStatus = "1";
retResponseXML = "<root><message><![CDATA["+object.getString("status_cd")+"]]></message></root>";
}
else
{
callStatus = "2";
JSONObject errorJSON = otpResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
retResponseXML = "<root><message><![CDATA[Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd")+"]]></message></root>";
}
}
else if(otpResp.getStatus() == 500)
{
callStatus = "2";
String errMsg = "Message : Error occurred at GSTN server \nResponse code : "+otpResp.getStatus();
responseJsonStr = errMsg;
retResponseXML = "<root><message><![CDATA[Message : "+errMsg+" \nError code : "+otpResp.getStatus()+"]]></message></root>";
}
else
{
callStatus = "2";
JSONObject errorJSON = otpResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
retResponseXML = "<root><message><![CDATA[Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd")+"]]></message></root>";
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(userInfo.getLoginCode());
apiCallData.setCallType("OTPREQUEST");
apiCallData.setRecType(recType);
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(userInfo.getLoginCode());
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(userInfo.getRemoteHost());
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
}
else
{
sql = "SELECT MSG_DESCR FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
if(rs.next())
{
dataErrMsg = rs.getString("MSG_DESCR");
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
retResponseXML = "<root><message><![CDATA[Message : "+dataErrMsg+"]]></message></root>";
}
}
else if ("ITEM_CHANGE".equalsIgnoreCase(action))
{
......@@ -1147,7 +1409,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
{
System.out.println("GSTDataSubmitWizEJB.handleRequest()["+e.getMessage()+"]");
e.printStackTrace();
retResponseXML = "<root><message><![CDATA[Message : Error occured!]]></message></root>";
retResponseXML = "<root><message><![CDATA[Message :"+e.getMessage()+"]]></message></root>";
}
finally
{
......
......@@ -44,6 +44,7 @@ import ibase.webitm.bean.gst.APICallData;
import ibase.webitm.bean.gst.AT;
import ibase.webitm.bean.gst.ATA;
import ibase.webitm.bean.gst.B2B;
import ibase.webitm.bean.gst.B2BUR;
import ibase.webitm.bean.gst.B2CL;
import ibase.webitm.bean.gst.B2CLA;
import ibase.webitm.bean.gst.B2CS;
......@@ -56,6 +57,7 @@ import ibase.webitm.bean.gst.DocDetails;
import ibase.webitm.bean.gst.DocIssued;
import ibase.webitm.bean.gst.EXP;
import ibase.webitm.bean.gst.GSTR1;
import ibase.webitm.bean.gst.GSTR2;
import ibase.webitm.bean.gst.HSN;
import ibase.webitm.bean.gst.HSNDetails;
import ibase.webitm.bean.gst.InvLineItem;
......@@ -477,10 +479,13 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
retString = downloadGstr2AData(authToken, stateCode, userName, gstin, periodCode, siteCode, authSEK, xtraParams, conn);
}
}
}
else
{
else if("GSTR2".equalsIgnoreCase(returnsType))
{
if("SAVE".equalsIgnoreCase(action))
{
retString = saveGstr2(authToken, siteCode, stateCode, userName, gstin, periodCode, grossTurnover, currentYearTurnover, authSEK, xtraParams, conn);
}
}
}
}
catch(Exception e)
......@@ -560,7 +565,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
pstmt.setString(1, periodCode);
pstmt.setString(2, siteCode);
rs = pstmt.executeQuery();
while(rs.next())
{
++noOfRecords;
......@@ -571,7 +576,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
posStateCode = checkNullandTrim(rs.getString("GST_CODE"));
tranIdRef = checkNullandTrim(rs.getString("TRAN_ID__REF"));
System.out.println("tranId["+tranId+"] tranType["+tranType+"] ctin["+ctin+"] posStateCode["+posStateCode+"] tranIdRef["+tranIdRef+"]");
System.out.println("in saveGstr1 tranId["+tranId+"] tranType["+tranType+"] ctin["+ctin+"] posStateCode["+posStateCode+"] tranIdRef["+tranIdRef+"]");
invoices = new ArrayList<Invoice>();
invoice = new Invoice();
......@@ -1192,6 +1197,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
if(hsnList.size() > 0)
{
hsn = new HSN();
hsn.recType = "1";
hsn.hsnDetails = hsnList;
}
......@@ -1284,6 +1290,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
APICallData apiRetStatsCallData = null;
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
......@@ -1329,12 +1336,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
.body(new JsonNode(gstr1HeaderObj.toString()))
.getHttpRequest();
System.out.println("SAVE GSTR1 url["+saveGstr1Req.getUrl()+"]");
System.out.println("SAVE GSTR1 method["+saveGstr1Req.getHttpMethod()+"]");
System.out.println("SAVE GSTR1 request header["+saveGstr1Req.getHeaders()+"]");
System.out.println("SAVE GSTR1 request payload["+IOUtils.toString(saveGstr1Req.getBody().getEntity().getContent())+"]");
System.out.println("SAVE GSTR1 url["+saveGstr1Req.getUrl()+"]");
System.out.println("SAVE GSTR1 method["+saveGstr1Req.getHttpMethod()+"]");
System.out.println("SAVE GSTR1 request header["+saveGstr1Req.getHeaders()+"]");
System.out.println("SAVE GSTR1 request payload["+IOUtils.toString(saveGstr1Req.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> gstr1Resp = saveGstr1Req.asJson();
HttpResponse<JsonNode> gstr1Resp = saveGstr1Req.asJson();
System.out.println(String.format("gstr1Resp Request : Status[%s] Response[%s]", gstr1Resp.getStatus(), gstr1Resp.getBody()));
......@@ -1349,12 +1356,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr1Rek = gstr1RespObj.getString("rek");
byte[] apiEKGstr1 = aesEncryption.decrypt(gstr1Rek, authSek);
String Gstr1RespJsoninBase64 = new String(aesEncryption.decrypt(gstr1Data, apiEKGstr1));
String gstr1RespJsoninBase64 = new String(aesEncryption.decrypt(gstr1Data, apiEKGstr1));
byte[] Gstr1RespJsonInBytes = aesEncryption.decodeBase64StringTOByte(Gstr1RespJsoninBase64);
byte[] gstr1RespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstr1RespJsoninBase64);
JSONObject Gstr1RespObj = new JSONObject(new String(Gstr1RespJsonInBytes));
String transId = Gstr1RespObj.getString("reference_id");
JSONObject gstr1TransIdRespObj = new JSONObject(new String(gstr1RespJsonInBytes));
String transId = gstr1TransIdRespObj.getString("reference_id");
responseId = transId;
......@@ -1479,22 +1486,20 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
isRetStatusError = true;
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETSTATUS");
apiCallData.setRecType("1");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(retStatusCallStatus);
apiCallData.setResponseId("");
apiCallData.setResponseJsonStr(retStatusResponseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
apiRetStatsCallData = new APICallData();
apiRetStatsCallData.setPeriodCode(periodCode);
apiRetStatsCallData.setCallDate(new Date());
apiRetStatsCallData.setSiteCode(siteCode);
apiRetStatsCallData.setUserId(loginCode);
apiRetStatsCallData.setCallType("RETSTATUS");
apiRetStatsCallData.setRecType("1");
apiRetStatsCallData.setNoOfRecords(0);
apiRetStatsCallData.setCallStatus(retStatusCallStatus);
apiRetStatsCallData.setResponseId("");
apiRetStatsCallData.setResponseJsonStr(retStatusResponseJsonStr);
apiRetStatsCallData.setChgUser(loginCode);
apiRetStatsCallData.setChgDate(new Date());
apiRetStatsCallData.setChgTerm(chgTerm);
if(isRetStatusError)
{
......@@ -1543,6 +1548,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
gstCommonUtil.updateAPICallLogHistory(apiRetStatsCallData, null);
}
}
catch (Exception e)
......@@ -1553,6 +1559,154 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}
private String submitGstr1(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, String xtraParams,Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "", responseId = "";
String sql = "";
PreparedStatement pstmt = null;
int updateCnt = 0;
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
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)));
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
System.out.println("RETSUBMIT request url ["+String.format("%s%s", GSP_API_URL, GSTR1_URL_V3)+"]");
HttpResponse<JsonNode> gstr1SubmitResp = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR1_URL_V3))
.header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT")
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.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"))
{
callStatus = "1";
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");
responseId = transId;
System.out.println("transId to getStatus after SUBMIT call["+transId+"]");
sql = "UPDATE GST_DATA_HDR SET SUBMIT_STATUS = ? AND SUBMIT_DATE = ? WHERE PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "S");
pstmt.setString(2, new SimpleDateFormat(new E12GenericUtility().getApplDateFormat()).format(new Date()));
pstmt.setString(3, periodCode);
pstmt.setString(4, siteCode);
updateCnt = pstmt.executeUpdate();
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
System.out.println("submit status updated of ["+siteCode+"] for ["+periodCode+"] update count ["+updateCnt+"]");
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr1SubmitResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else if(gstr1SubmitResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstr1SubmitResp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr1SubmitResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETSUBMIT");
apiCallData.setRecType("1");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.submitGstr1()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private String fileGstr1(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSek, String summaryData, String signedData, String panNo, String aadhaarNo, String signMethod, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
......@@ -1888,203 +2042,53 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}*/
private String submitGstr1(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, String xtraParams,Connection conn) throws ITMException
private String downloadGstr2AData(String authToken, String stateCode, String userName, String gstin, String periodCode, String siteCode, byte[] authSEK, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
String[] gstr2Section = {"B2B","CDN"};
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "", responseId = "";
String sql = "";
PreparedStatement pstmt = null;
int updateCnt = 0;
String loginCode = "", chgTerm = "", callStatus = "", responseJsonStr = "", responseId = "";
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
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)));
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
System.out.println("RETSUBMIT request url ["+String.format("%s%s", GSP_API_URL, GSTR1_URL_V3)+"]");
HttpResponse<JsonNode> gstr1SubmitResp = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR1_URL_V3))
.header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT")
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.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"))
{
callStatus = "1";
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");
responseId = transId;
System.out.println("transId to getStatus after SUBMIT call["+transId+"]");
sql = "UPDATE GST_DATA_HDR SET SUBMIT_STATUS = ? AND SUBMIT_DATE = ? WHERE PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "S");
pstmt.setString(2, new SimpleDateFormat(new E12GenericUtility().getApplDateFormat()).format(new Date()));
pstmt.setString(3, periodCode);
pstmt.setString(4, siteCode);
updateCnt = pstmt.executeUpdate();
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
System.out.println("submit status updated of ["+siteCode+"] for ["+periodCode+"] update count ["+updateCnt+"]");
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr1SubmitResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else if(gstr1SubmitResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstr1SubmitResp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr1SubmitResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETSUBMIT");
apiCallData.setRecType("1");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.submitGstr1()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private String downloadGstr2AData(String authToken, String stateCode, String userName, String gstin, String periodCode, String siteCode, byte[] authSEK, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
String[] gstr2Section = {"B2B","CDN"};
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", callStatus = "", responseJsonStr = "", responseId = "";
try
{
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
for(String action : gstr2Section)
{
System.out.println("calling for ["+action+"]");
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest getGstr2InvoicesReq = Unirest.get(String.format("%s%s", GSP_API_URL, GSTR2A_URL_V3))
.queryString("action", action)
.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)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.getHttpRequest();
System.out.println("get GSTR2A ["+action+"] invoices url["+getGstr2InvoicesReq.getUrl()+"]");
System.out.println("get GSTR2A ["+action+"] invoices method["+getGstr2InvoicesReq.getHttpMethod()+"]");
System.out.println("get GSTR2A ["+action+"] invoices request header["+getGstr2InvoicesReq.getHeaders()+"]");
HttpResponse<JsonNode> getGstr2InvoicesResp = getGstr2InvoicesReq.asJson();
System.out.println(String.format("getGstr2InvoicesResp Request : Status[%s] Response[%s]", getGstr2InvoicesResp.getStatus(), getGstr2InvoicesResp.getBody()));
if (getGstr2InvoicesResp.getStatus() == 200)
for(String action : gstr2Section)
{
System.out.println("calling for ["+action+"]");
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest getGstr2InvoicesReq = Unirest.get(String.format("%s%s", GSP_API_URL, GSTR2A_URL_V3))
.queryString("action", action)
.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)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.getHttpRequest();
System.out.println("get GSTR2A ["+action+"] invoices url["+getGstr2InvoicesReq.getUrl()+"]");
System.out.println("get GSTR2A ["+action+"] invoices method["+getGstr2InvoicesReq.getHttpMethod()+"]");
System.out.println("get GSTR2A ["+action+"] invoices request header["+getGstr2InvoicesReq.getHeaders()+"]");
HttpResponse<JsonNode> getGstr2InvoicesResp = getGstr2InvoicesReq.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"))
......@@ -2162,6 +2166,658 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}
private String saveGstr2(String authToken, String siteCode, String stateCode, String userName, String gstin, String periodCode, String grossTurnover, String currentYearTurnover, byte[] authSek, String xtraParams, Connection conn) throws ITMException
{
String retString = "", errMsg = "";
String gstr2Data = "", gstr2Rek = "";
String retStatsData = "", retStatsRek = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
int num = 0, noOfRecords = 0;
boolean isDataFound = false;
String udfStr1 = "", udfStr2 = "", udfStr3 = "";
String sql = "", lineSql = "", refDataSql = "";
PreparedStatement pstmt = null, linePstmt = null, refDataPstmt = null;
ResultSet rs = null, lineRs = null, refDataRs = null;
String tranId = "", tranType = "", tranIdRef = "", ctin = "", posStateCode = "";
String loginCode = "", chgTerm = "", callStatus = "", responseId = "", responseJsonStr= "", retStatusCallStatus = "", retStatusResponseJsonStr = "";
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<B2BUR> b2burInvoiceList = new ArrayList<B2BUR>();
ArrayList<CDNR> cdnrList = new ArrayList<CDNR>();
ArrayList<HSNDetails> hsnList = new ArrayList<HSNDetails>();
ArrayList<InvLineItem> invLineItems = null;
ArrayList<Invoice> invoices = null;
ArrayList<CDNDetails> cdnDetailsList = null;
GSTR2 gstr2 = null;
Invoice invoice = null;
InvLineItem invLineItem = null;
B2B b2b = null;
B2BUR b2bur = null;
CDNR cdnr = null;
CDNDetails cdnDetails = null;
HSNDetails hsnDetails = null;
HSN hsn = null;
try
{
sql = "SELECT * FROM GST_DATA_HDR WHERE PRD_CODE = ? AND SITE_CODE = ? AND SUBMIT_STATUS = 'P' AND REC_TYPE ='2'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, periodCode);
pstmt.setString(2, siteCode);
rs = pstmt.executeQuery();
while(rs.next())
{
++noOfRecords;
isDataFound = true;
tranId = checkNullandTrim(rs.getString("TRAN_ID"));
tranType = checkNullandTrim(rs.getString("TRAN_TYPE"));
ctin = checkNullandTrim(rs.getString("TAX_REG_NO"));
posStateCode = checkNullandTrim(rs.getString("GST_CODE"));
tranIdRef = checkNullandTrim(rs.getString("TRAN_ID__REF"));
System.out.println("in saveGstr2 tranId["+tranId+"] tranType["+tranType+"] ctin["+ctin+"] posStateCode["+posStateCode+"] tranIdRef["+tranIdRef+"]");
invoices = new ArrayList<Invoice>();
invoice = new Invoice();
invLineItems = new ArrayList<InvLineItem>();
cdnDetailsList = new ArrayList<CDNDetails>();
lineSql = "SELECT UDF_STR1, UDF_STR2, UDF_STR3 FROM GENCODES WHERE MOD_NAME = 'W_GSTR_PURC' AND FLD_NAME = 'TRAN_TYPE' AND FLD_VALUE = ? ";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranType);
lineRs = linePstmt.executeQuery();
if(lineRs.next())
{
udfStr1 = checkNullandTrim(lineRs.getString("UDF_STR1"));
udfStr2 = checkNullandTrim(lineRs.getString("UDF_STR2"));
udfStr3 = checkNullandTrim(lineRs.getString("UDF_STR3"));
}
if(linePstmt!=null)
{
linePstmt.close();
linePstmt=null;
}
if(lineRs!=null)
{
lineRs.close();
lineRs=null;
}
if(invoicesHMap.containsKey(ctin+"~"+udfStr1))
{
invoices = invoicesHMap.get(ctin+"~"+udfStr1);
}
//tran_type : 01 = B2B invoices
if("B2B".equalsIgnoreCase(udfStr1))
{
lineSql = " SELECT GST_RATE, SUM(TAXABLE_AMT) AS TAXABLE_AMT, SUM(IGST_AMT) AS IGST_AMT, SUM(CGST_AMT) AS CGST_AMT, SUM(SGST_AMT) AS SGST_AMT, SUM(CESS_AMT) AS CESS_AMT "
+ " ITC_TYPE, SUM(ITC_IGST) AS ITC_IGST, SUM(ITC_CGST) AS ITC_CGST, SUM(ITC_SGST) AS ITC_SGST, SUM(ITC_CESS) AS ITC_CESS "
+ " FROM GST_DATA_DET "
+ " WHERE TRAN_ID = ? "
+ " GROUP BY GST_RATE, ITC_TYPE ";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranId);
lineRs = linePstmt.executeQuery();
int lineNum = 0;
while(lineRs.next())
{
invLineItem = new InvLineItem();
invLineItem.num = ++lineNum;
invLineItem.rate = lineRs.getDouble("GST_RATE");
invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT");
invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.camt = lineRs.getDouble("CGST_AMT");
invLineItem.samt = lineRs.getDouble("SGST_AMT");
invLineItem.csamt = lineRs.getDouble("CESS_AMT");
invLineItem.itcType = lineRs.getString("ITC_TYPE");
invLineItem.igstInputTax = lineRs.getDouble("ITC_IGST");
invLineItem.cgstInputTax = lineRs.getDouble("ITC_CGST");
invLineItem.sgstInputTax = lineRs.getDouble("ITC_SGST");
invLineItem.cessInputTax = lineRs.getDouble("ITC_CESS");
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.invoiceType = udfStr2;
invoice.pos = posStateCode;
invoice.rchrg = "Y".equalsIgnoreCase(rs.getString("REVERSE_CHRG"));
invoice.items = invLineItems;
invoices.add(invoice);
invoicesHMap.put(ctin+"~"+udfStr1, invoices);
if("B2B".equalsIgnoreCase(udfStr1))
{
b2b = new B2B();
if(invTypObjHMap.containsKey(ctin+"~"+udfStr1))
{
b2b = (B2B)invTypObjHMap.get(ctin+"~"+udfStr1);
if(b2bInvoiceList.contains(b2b))
{
int index = b2bInvoiceList.indexOf(b2b);
b2bInvoiceList.remove(index);
}
}
b2b.ctin = ctin;
b2b.isReverseCharge = true;
b2b.invoices = invoices;
invTypObjHMap.put(ctin+"~"+udfStr1, b2b);
b2bInvoiceList.add(b2b);
}
}
if("B2BUR".equalsIgnoreCase(udfStr1))
{
invoices = new ArrayList<Invoice>();
invoice = new Invoice();
invLineItems = new ArrayList<InvLineItem>();
lineSql = " SELECT GST_RATE, SUM(TAXABLE_AMT) AS TAXABLE_AMT, SUM(IGST_AMT) AS IGST_AMT, SUM(CGST_AMT) AS CGST_AMT, SUM(SGST_AMT) AS SGST_AMT, SUM(CESS_AMT) AS CESS_AMT "
+ " ITC_TYPE, SUM(ITC_IGST) AS ITC_IGST, SUM(ITC_CGST) AS ITC_CGST, SUM(ITC_SGST) AS ITC_SGST, SUM(ITC_CESS) AS ITC_CESS "
+ " FROM GST_DATA_DET "
+ " WHERE TRAN_ID = ? "
+ " GROUP BY GST_RATE, ITC_TYPE ";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranId);
lineRs = linePstmt.executeQuery();
int lineNum = 0;
while(lineRs.next())
{
invLineItem = new InvLineItem();
invLineItem.num = ++lineNum;
invLineItem.rate = lineRs.getDouble("GST_RATE");
invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT");
invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.camt = lineRs.getDouble("CGST_AMT");
invLineItem.samt = lineRs.getDouble("SGST_AMT");
invLineItem.csamt = lineRs.getDouble("CESS_AMT");
invLineItem.itcType = lineRs.getString("ITC_TYPE");
invLineItem.igstInputTax = lineRs.getDouble("ITC_IGST");
invLineItem.cgstInputTax = lineRs.getDouble("ITC_CGST");
invLineItem.sgstInputTax = lineRs.getDouble("ITC_SGST");
invLineItem.cessInputTax = lineRs.getDouble("ITC_CESS");
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.items = invLineItems;
invoice.supplyType = stateCode.trim().equalsIgnoreCase(posStateCode.trim())?"INTRA":"INTER";
invoices.add(invoice);
if("B2B".equalsIgnoreCase(udfStr1))
{
b2bur = new B2BUR();
b2bur.invoices = invoices;
b2burInvoiceList.add(b2bur);
}
}
if("CDNR".equalsIgnoreCase(udfStr1))
{
Calendar calendar = Calendar.getInstance();
calendar.set(2017, 06, 01);
Date gstStartDate = calendar.getTime();
if("CDNR".equalsIgnoreCase(udfStr1))
{
lineSql = " SELECT GST_RATE, SUM(TAXABLE_AMT) AS TAXABLE_AMT, SUM(IGST_AMT) AS IGST_AMT, SUM(CGST_AMT) AS CGST_AMT, SUM(SGST_AMT) AS SGST_AMT, SUM(CESS_AMT) AS CESS_AMT "
+ " ITC_TYPE, SUM(ITC_IGST) AS ITC_IGST, SUM(ITC_CGST) AS ITC_CGST, SUM(ITC_SGST) AS ITC_SGST, SUM(ITC_CESS) AS ITC_CESS "
+ " FROM GST_DATA_DET "
+ " WHERE TRAN_ID = ? "
+ " GROUP BY GST_RATE, ITC_TYPE ";
linePstmt = conn.prepareStatement(lineSql);
linePstmt.setString(1, tranId);
lineRs = linePstmt.executeQuery();
int lineNum = 0;
while(lineRs.next())
{
invLineItem = new InvLineItem();
invLineItem.num = ++lineNum;
invLineItem.rate = lineRs.getDouble("GST_RATE");
invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT");
invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.camt = lineRs.getDouble("CGST_AMT");
invLineItem.samt = lineRs.getDouble("SGST_AMT");
invLineItem.csamt = lineRs.getDouble("CESS_AMT");
invLineItem.itcType = lineRs.getString("ITC_TYPE");
invLineItem.igstInputTax = lineRs.getDouble("ITC_IGST");
invLineItem.cgstInputTax = lineRs.getDouble("ITC_CGST");
invLineItem.sgstInputTax = lineRs.getDouble("ITC_SGST");
invLineItem.cessInputTax = lineRs.getDouble("ITC_CESS");
invLineItems.add(invLineItem);
}
if(linePstmt != null)
{
linePstmt.close();
linePstmt = null;
}
if(lineRs != null)
{
lineRs.close();
lineRs = null;
}
cdnDetails = new CDNDetails();
cdnDetails.cdnNoteType = udfStr2;
cdnDetails.cdNoteNumber = checkNullandTrim(rs.getString("DOC_NO"));
cdnDetails.cdNoteDate = rs.getDate("DOC_DATE");
cdnDetails.invoiceNumber = checkNullandTrim(rs.getString("REF_ID__INV"));
cdnDetails.invoiceDate = rs.getDate("REF_DATE__INV");
cdnDetails.val = rs.getDouble("AMOUNT");
cdnDetails.reason = checkNullandTrim(rs.getString("REAS_CODE"));
if(rs.getDate("REF_DATE__INV").before(gstStartDate))
{
cdnDetails.isPreGSTInvoice = true;
}
cdnDetails.items = invLineItems;
cdnDetailsList.add(cdnDetails);
cdnr = new CDNR();
cdnr.isReverseCharge = false;
cdnr.ctin = ctin;
cdnr.cdnDetails = cdnDetailsList;
cdnrList.add(cdnr);
}
}
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(isDataFound)
{
//HSN summary data will be sent every time
sql = " SELECT GDD.GS_CODE, GDD.GS_DESCR, GDD.UNIT, SUM(GDD.QUANTITY) AS TOT_QTY, SUM(GDD.TAXABLE_AMT) AS TOT_TAXVAL,"
+ " SUM(GDD.IGST_AMT) AS TOT_IAMT, SUM(CGST_AMT) AS TOT_CAMT, SUM(SGST_AMT) AS TOT_SAMT, SUM(CESS_AMT) AS TOT_CSAMT"
+ " FROM GST_DATA_HDR GDH, GST_DATA_DET GDD"
+ " WHERE GDH.TRAN_ID = GDD.TRAN_ID AND GDD.GS_CODE IS NOT NULL AND GDH.REC_TYPE='2'"
+ " AND GDH.SITE_CODE = ? AND GDH.PRD_CODE = ?"
+ " GROUP BY GDD.GS_CODE, GDD.GS_DESCR, GDD.UNIT";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setString(2, periodCode);
rs = pstmt.executeQuery();
while (rs.next())
{
hsnDetails = new HSNDetails();
hsnDetails.num = ++num;
hsnDetails.itemOrServiceCode = checkNullandTrim(rs.getString("GS_CODE"));
hsnDetails.description = checkNullandTrim(rs.getString("GS_DESCR"));
hsnDetails.unitOfMeasure = checkNullandTrim(rs.getString("UNIT"));
hsnDetails.quantity = rs.getDouble("TOT_QTY");
hsnDetails.totalAmount = rs.getDouble("TOT_TAXVAL");
hsnDetails.totalTaxableAmount = rs.getDouble("TOT_TAXVAL");
hsnDetails.totalIGSTAmount = rs.getDouble("TOT_IAMT");
hsnDetails.totalCGSTAmount = rs.getDouble("TOT_CAMT");
hsnDetails.totalSGSTAmount = rs.getDouble("TOT_SAMT");
hsnDetails.totalCESSAmount = rs.getDouble("TOT_CSAMT");
hsnList.add(hsnDetails);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(hsnList.size() > 0)
{
hsn = new HSN();
hsn.recType = "2";
hsn.hsnDetails = hsnList;
}
gstr2 = new GSTR2();
gstr2.gstin = gstin;
gstr2.financialPeriod = periodCode;
if(b2bInvoiceList.size() > 0)
{
gstr2.b2b = b2bInvoiceList;
}
if(b2burInvoiceList.size() > 0)
{
gstr2.b2bur = b2burInvoiceList;
}
if(cdnrList.size() > 0)
{
gstr2.cdnr = cdnrList;
}
if(hsn != null)
{
gstr2.hsn = hsn;
}
String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
APICallData apiRetStatsCallData = null;
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(gstr2);
System.out.println("jsonPayload to SAVE GSTR2["+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)));
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest saveGstr2Req = Unirest.put(String.format("%s%s", GSP_API_URL, GSTR2_URL_V3))
.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)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(gstr1HeaderObj.toString()))
.getHttpRequest();
System.out.println("SAVE GSTR2 url["+saveGstr2Req.getUrl()+"]");
System.out.println("SAVE GSTR2 method["+saveGstr2Req.getHttpMethod()+"]");
System.out.println("SAVE GSTR2 request header["+saveGstr2Req.getHeaders()+"]");
System.out.println("SAVE GSTR2 request payload["+IOUtils.toString(saveGstr2Req.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> gstr2Resp = saveGstr2Req.asJson();
System.out.println(String.format("gstr2Resp Request : Status[%s] Response[%s]", gstr2Resp.getStatus(), gstr2Resp.getBody()));
if (gstr2Resp.getStatus() == 200)
{
JSONObject gstr2RespObj = gstr2Resp.getBody().getObject();
if(gstr2RespObj.has("data") && gstr2RespObj.has("rek"))
{
callStatus = "1";
gstr2Data = gstr2RespObj.getString("data");
gstr2Rek = gstr2RespObj.getString("rek");
byte[] apiEKGstr2 = aesEncryption.decrypt(gstr2Rek, authSek);
String gstr2RespJsoninBase64 = new String(aesEncryption.decrypt(gstr2Data, apiEKGstr2));
byte[] gstr2RespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstr2RespJsoninBase64);
JSONObject gstr2TransIdRespObj = new JSONObject(new String(gstr2RespJsonInBytes));
String transId = gstr2TransIdRespObj.getString("reference_id");
responseId = transId;
System.out.println("transId to getStatus["+transId+"]");
boolean isRetStatusError = false;
while(true)
{
long timeStampRet = new Timestamp().getDateTime();
gspAuthStringRet = clientId + ":" + transactionId + ":" + timeStampRet + ":" + gstin;
gspAuthSignatureRet = gspSignature.sign(gspAuthStringRet, aspPrivateKey);
HttpRequest retStatusReq = Unirest.get(String.format("%s%s", GSP_API_URL, GSTR_URL_V3))
.queryString("action","RETSTATUS")
.queryString("gstin", gstin)
.queryString("ret_period", periodCode)
.queryString("ref_id",transId)
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthStringRet)
.header("X-Asp-Auth-Signature", gspAuthSignatureRet)
.getHttpRequest();
System.out.println("RETSTATUS url["+retStatusReq.getUrl()+"]");
System.out.println("RETSTATUS method["+retStatusReq.getHttpMethod()+"]");
System.out.println("RETSTATUS request header["+retStatusReq.getHeaders()+"]");
HttpResponse<JsonNode> retStatusResp = retStatusReq.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")))
{
retStatusCallStatus = "0";
continue;
}
else if("P".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
retStatusCallStatus = "1";
if(tranIdList.size() > 0)
{
updateSubmissionStatus(tranIdList, conn);
}
isRetStatusError = true;
}
else if("PE".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
retStatusCallStatus = "2";
errMsg = getRetStatusErrMsg(retStatsJsonData);
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
else if("ER".equalsIgnoreCase(retStatsJsonData.getString("status_cd")))
{
retStatusCallStatus = "2";
if(retStatsJsonData.has("error_report"))
{
JSONObject errorJSON = retStatsJsonData.getJSONObject("error_report");
if(errorJSON.has("error_msg") && errorJSON.has("error_cd"))
{
errMsg = "Message : "+errorJSON.getString("error_msg")+" \nError code : "+errorJSON.getString("error_cd");
}
}
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
}
else
{
retStatusCallStatus = "2";
JSONObject errorJSON = retStatusResp.getBody().getObject().getJSONObject("error");
retStatusResponseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
}
else if(retStatusResp.getStatus() == 500)
{
retStatusCallStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+retStatusResp.getStatus();
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
else
{
retStatusCallStatus = "2";
JSONObject errorJSON = retStatusResp.getBody().getObject().getJSONObject("error");
retStatusResponseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
apiRetStatsCallData = new APICallData();
apiRetStatsCallData.setPeriodCode(periodCode);
apiRetStatsCallData.setCallDate(new Date());
apiRetStatsCallData.setSiteCode(siteCode);
apiRetStatsCallData.setUserId(loginCode);
apiRetStatsCallData.setCallType("RETSTATUS");
apiRetStatsCallData.setRecType("2");
apiRetStatsCallData.setNoOfRecords(0);
apiRetStatsCallData.setCallStatus(retStatusCallStatus);
apiRetStatsCallData.setResponseId("");
apiRetStatsCallData.setResponseJsonStr(retStatusResponseJsonStr);
apiRetStatsCallData.setChgUser(loginCode);
apiRetStatsCallData.setChgDate(new Date());
apiRetStatsCallData.setChgTerm(chgTerm);
if(isRetStatusError)
{
break;
}
}
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr2Resp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else if(gstr2Resp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstr2Resp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr2Resp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETSAVE");
apiCallData.setRecType("2");
apiCallData.setNoOfRecords(noOfRecords);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
gstCommonUtil.updateAPICallLogHistory(apiRetStatsCallData, null);
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.saveGstr2()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private void insertB2BInvoiceData(String stateCode, String periodCode, String siteCode, JSONObject gstr2InvoiceJsonObj, String xtraParams, Connection conn) throws ITMException
{
......
......@@ -97,7 +97,7 @@ public class GSTDataSubmitWizServlet extends HttpServlet
response.setContentType("text/xml");
if(CommonConstants.CONTENT_ENCODING != null && CommonConstants.CONTENT_ENCODING.equalsIgnoreCase("gzip"))
if(CommonConstants.CONTENT_ENCODING != null && CommonConstants.CONTENT_ENCODING.equalsIgnoreCase("gzip"))
{
response.setHeader("Content-Encoding", "gzip");
GZIPOutputStream gzOutStream = new GZIPOutputStream(response.getOutputStream());
......
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.B2BUR;
public class B2BURSerializer extends BaseSerializer<B2BUR>
{
@Override
public void serialize(B2BUR b2bur, final JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonProcessingException
{
json.writeStartObject();
writeInvoices(b2bur, json);
json.writeEndObject();
}
}
......@@ -143,6 +143,20 @@ abstract class BaseSerializer<T extends BaseData> extends JsonSerializer<T>
json.writeEndObject();
}
if(li.itcType != null && (li.igstInputTax > 0.0 || li.cgstInputTax > 0.0 || li.sgstInputTax > 0.0) || li.cessInputTax > 0.0)
{
json.writeFieldName("itc");
json.writeStartObject();
json.writeStringField("elg", li.itcType);
json.writeNumberField("tx_i", li.igstInputTax);
json.writeNumberField("tx_s", li.cgstInputTax);
json.writeNumberField("tx_c", li.sgstInputTax);
json.writeNumberField("tx_cs", li.cessInputTax);
json.writeEndObject();
}
json.writeEndObject();
}
catch (Exception e)
......
......@@ -115,6 +115,20 @@ public class CDNRSerializer extends JsonSerializer<CDNR>
}
json.writeEndObject();
if(li.itcType != null && (li.igstInputTax > 0.0 || li.cgstInputTax > 0.0 || li.sgstInputTax > 0.0) || li.cessInputTax > 0.0)
{
json.writeFieldName("itc");
json.writeStartObject();
json.writeStringField("elg", li.itcType);
json.writeNumberField("tx_i", li.igstInputTax);
json.writeNumberField("tx_s", li.cgstInputTax);
json.writeNumberField("tx_c", li.sgstInputTax);
json.writeNumberField("tx_cs", li.cessInputTax);
json.writeEndObject();
}
json.writeEndObject();
}
catch (Exception e)
......
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.GSTR2;
public class GSTR2Serailizer extends JsonSerializer<GSTR2> {
@Override
public void serialize(GSTR2 gstr2, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException
{
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("gstin", gstr2.gstin);
if(gstr2.b2b != null)
{
jsonGenerator.writeObjectField("b2b", gstr2.b2b);
}
if(gstr2.b2bur != null)
{
jsonGenerator.writeObjectField("b2bur", gstr2.b2bur);
}
if(gstr2.cdnr != null)
{
jsonGenerator.writeObjectField("cdn", gstr2.cdnr);
}
if(gstr2.hsn != null)
{
jsonGenerator.writeObjectField("hsnsum", gstr2.hsn);
}
jsonGenerator.writeEndObject();
}
}
......@@ -16,7 +16,14 @@ public class HSNSerializer extends BaseSerializer<HSN>
{
json.writeStartObject();
json.writeFieldName("data");
if("1".equalsIgnoreCase(hsn.recType))
{
json.writeFieldName("data");
}
else if("2".equalsIgnoreCase(hsn.recType))
{
json.writeFieldName("det");
}
json.writeStartArray();
for(HSNDetails hsnDetails : hsn.hsnDetails)
......@@ -40,26 +47,17 @@ public class HSNSerializer extends BaseSerializer<HSN>
{
json.writeStringField("desc", hsnDetails.description);
}
json.writeStringField("uqc", hsnDetails.unitOfMeasure);
if(hsnDetails.unitOfMeasure != null && hsnDetails.unitOfMeasure.trim().length()>0)
{
json.writeStringField("uqc", hsnDetails.unitOfMeasure);
}
json.writeNumberField("qty", hsnDetails.quantity);
json.writeNumberField("val", hsnDetails.totalAmount);
json.writeNumberField("txval", hsnDetails.totalTaxableAmount);
if(hsnDetails.totalIGSTAmount > 0)
{
json.writeNumberField("iamt", hsnDetails.totalIGSTAmount);
}
if(hsnDetails.totalCGSTAmount > 0)
{
json.writeNumberField("camt", hsnDetails.totalCGSTAmount);
}
if(hsnDetails.totalSGSTAmount > 0)
{
json.writeNumberField("samt", hsnDetails.totalSGSTAmount);
}
if(hsnDetails.totalCESSAmount > 0)
{
json.writeNumberField("csamt", hsnDetails.totalCESSAmount);
}
json.writeNumberField("iamt", hsnDetails.totalIGSTAmount);
json.writeNumberField("camt", hsnDetails.totalCGSTAmount);
json.writeNumberField("samt", hsnDetails.totalSGSTAmount);
json.writeNumberField("csamt", hsnDetails.totalCESSAmount);
json.writeEndObject();
}
......
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