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; ...@@ -9,5 +9,7 @@ import ibase.webitm.util.gst.HSNSerializer;
@JsonSerialize(using = HSNSerializer.class) @JsonSerialize(using = HSNSerializer.class)
public class HSN extends BaseData public class HSN extends BaseData
{ {
public String recType;
public List<HSNDetails> hsnDetails; public List<HSNDetails> hsnDetails;
} }
...@@ -16,4 +16,14 @@ public class InvLineItem { ...@@ -16,4 +16,14 @@ public class InvLineItem {
public double samt; public double samt;
public double csamt; 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 ...@@ -567,6 +567,10 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
summaryDataJsonStr += getGstr1Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn); summaryDataJsonStr += getGstr1Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn);
retXML = "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>"; 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 ...@@ -964,11 +968,12 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
@Override @Override
public String handleRequest(HashMap<String, String> reqParamMap, UserInfoBean userInfo) throws ITMException public String handleRequest(HashMap<String, String> reqParamMap, UserInfoBean userInfo) throws ITMException
{ {
String retResponseXML = "", action = ""; String retResponseXML = "", action = "", dataAction = "", errorCode = "", dataErrMsg = "";
String sql = ""; String sql = "";
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
boolean isDataError = false;
try try
{ {
action = reqParamMap.get("action"); action = reqParamMap.get("action");
...@@ -976,7 +981,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -976,7 +981,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
if("GENERATE_OTP".equalsIgnoreCase(action)) 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 responseId = "", responseJsonStr = "", callStatus = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", ""); String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
long timeStamp = new Timestamp().getDateTime(); long timeStamp = new Timestamp().getDateTime();
...@@ -992,20 +997,253 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -992,20 +997,253 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
gstinNo = reqParamMap.get("gstin_no"); gstinNo = reqParamMap.get("gstin_no");
periodCode = reqParamMap.get("period_code"); periodCode = reqParamMap.get("period_code");
siteCode = reqParamMap.get("site_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"; recType = "1";
} }
else if("GSTR2".equalsIgnoreCase(reqParamMap.get("rec_type"))) else if("GSTR2".equalsIgnoreCase(recordType))
{ {
recType = "2"; recType = "2";
} }
else if("GSTR3".equalsIgnoreCase(reqParamMap.get("rec_type"))) else if("GSTR3".equalsIgnoreCase(recordType))
{ {
recType = "3"; recType = "3";
} }
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;
}
}
if(!isDataError)
{
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo; gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey); gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
...@@ -1085,6 +1323,30 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1085,6 +1323,30 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
gstCommonUtil.updateAPICallLogHistory(apiCallData, null); 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)) else if ("ITEM_CHANGE".equalsIgnoreCase(action))
{ {
String currColumn = "", currFieldData = "", siteDescr = "", gstinNo = "", userName = "", stateCode = "", stateDescr = "", grossTurnover = ""; String currColumn = "", currFieldData = "", siteDescr = "", gstinNo = "", userName = "", stateCode = "", stateDescr = "", grossTurnover = "";
...@@ -1147,7 +1409,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1147,7 +1409,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
{ {
System.out.println("GSTDataSubmitWizEJB.handleRequest()["+e.getMessage()+"]"); System.out.println("GSTDataSubmitWizEJB.handleRequest()["+e.getMessage()+"]");
e.printStackTrace(); e.printStackTrace();
retResponseXML = "<root><message><![CDATA[Message : Error occured!]]></message></root>"; retResponseXML = "<root><message><![CDATA[Message :"+e.getMessage()+"]]></message></root>";
} }
finally finally
{ {
......
...@@ -44,6 +44,7 @@ import ibase.webitm.bean.gst.APICallData; ...@@ -44,6 +44,7 @@ import ibase.webitm.bean.gst.APICallData;
import ibase.webitm.bean.gst.AT; import ibase.webitm.bean.gst.AT;
import ibase.webitm.bean.gst.ATA; import ibase.webitm.bean.gst.ATA;
import ibase.webitm.bean.gst.B2B; import ibase.webitm.bean.gst.B2B;
import ibase.webitm.bean.gst.B2BUR;
import ibase.webitm.bean.gst.B2CL; import ibase.webitm.bean.gst.B2CL;
import ibase.webitm.bean.gst.B2CLA; import ibase.webitm.bean.gst.B2CLA;
import ibase.webitm.bean.gst.B2CS; import ibase.webitm.bean.gst.B2CS;
...@@ -56,6 +57,7 @@ import ibase.webitm.bean.gst.DocDetails; ...@@ -56,6 +57,7 @@ import ibase.webitm.bean.gst.DocDetails;
import ibase.webitm.bean.gst.DocIssued; import ibase.webitm.bean.gst.DocIssued;
import ibase.webitm.bean.gst.EXP; import ibase.webitm.bean.gst.EXP;
import ibase.webitm.bean.gst.GSTR1; import ibase.webitm.bean.gst.GSTR1;
import ibase.webitm.bean.gst.GSTR2;
import ibase.webitm.bean.gst.HSN; import ibase.webitm.bean.gst.HSN;
import ibase.webitm.bean.gst.HSNDetails; import ibase.webitm.bean.gst.HSNDetails;
import ibase.webitm.bean.gst.InvLineItem; import ibase.webitm.bean.gst.InvLineItem;
...@@ -477,10 +479,13 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -477,10 +479,13 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
retString = downloadGstr2AData(authToken, stateCode, userName, gstin, periodCode, siteCode, authSEK, xtraParams, conn); retString = downloadGstr2AData(authToken, stateCode, userName, gstin, periodCode, siteCode, authSEK, xtraParams, conn);
} }
} }
} else if("GSTR2".equalsIgnoreCase(returnsType))
else
{ {
if("SAVE".equalsIgnoreCase(action))
{
retString = saveGstr2(authToken, siteCode, stateCode, userName, gstin, periodCode, grossTurnover, currentYearTurnover, authSEK, xtraParams, conn);
}
}
} }
} }
catch(Exception e) catch(Exception e)
...@@ -571,7 +576,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -571,7 +576,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
posStateCode = checkNullandTrim(rs.getString("GST_CODE")); posStateCode = checkNullandTrim(rs.getString("GST_CODE"));
tranIdRef = checkNullandTrim(rs.getString("TRAN_ID__REF")); 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>(); invoices = new ArrayList<Invoice>();
invoice = new Invoice(); invoice = new Invoice();
...@@ -1192,6 +1197,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1192,6 +1197,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
if(hsnList.size() > 0) if(hsnList.size() > 0)
{ {
hsn = new HSN(); hsn = new HSN();
hsn.recType = "1";
hsn.hsnDetails = hsnList; hsn.hsnDetails = hsnList;
} }
...@@ -1284,6 +1290,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1284,6 +1290,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
} }
String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = ""; String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
APICallData apiRetStatsCallData = null;
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm"); chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
...@@ -1349,12 +1356,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1349,12 +1356,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr1Rek = gstr1RespObj.getString("rek"); gstr1Rek = gstr1RespObj.getString("rek");
byte[] apiEKGstr1 = aesEncryption.decrypt(gstr1Rek, authSek); 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)); JSONObject gstr1TransIdRespObj = new JSONObject(new String(gstr1RespJsonInBytes));
String transId = Gstr1RespObj.getString("reference_id"); String transId = gstr1TransIdRespObj.getString("reference_id");
responseId = transId; responseId = transId;
...@@ -1479,22 +1486,20 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1479,22 +1486,20 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
isRetStatusError = true; isRetStatusError = true;
} }
APICallData apiCallData = new APICallData(); apiRetStatsCallData = new APICallData();
apiCallData.setPeriodCode(periodCode); apiRetStatsCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date()); apiRetStatsCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode); apiRetStatsCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode); apiRetStatsCallData.setUserId(loginCode);
apiCallData.setCallType("RETSTATUS"); apiRetStatsCallData.setCallType("RETSTATUS");
apiCallData.setRecType("1"); apiRetStatsCallData.setRecType("1");
apiCallData.setNoOfRecords(0); apiRetStatsCallData.setNoOfRecords(0);
apiCallData.setCallStatus(retStatusCallStatus); apiRetStatsCallData.setCallStatus(retStatusCallStatus);
apiCallData.setResponseId(""); apiRetStatsCallData.setResponseId("");
apiCallData.setResponseJsonStr(retStatusResponseJsonStr); apiRetStatsCallData.setResponseJsonStr(retStatusResponseJsonStr);
apiCallData.setChgUser(loginCode); apiRetStatsCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date()); apiRetStatsCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm); apiRetStatsCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
if(isRetStatusError) if(isRetStatusError)
{ {
...@@ -1543,6 +1548,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1543,6 +1548,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
apiCallData.setChgTerm(chgTerm); apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null); gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
gstCommonUtil.updateAPICallLogHistory(apiRetStatsCallData, null);
} }
} }
catch (Exception e) catch (Exception e)
...@@ -1553,6 +1559,154 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1553,6 +1559,154 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
} }
return retString; 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 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 = ""; String retString = "";
...@@ -1888,51 +2042,31 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1888,51 +2042,31 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
} }
return retString; 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
private String submitGstr1(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, String xtraParams,Connection conn) throws ITMException
{ {
String retString = ""; String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "";
String[] gstr2Section = {"B2B","CDN"};
String transactionId = UUID.randomUUID().toString().replaceAll("-", ""); String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "", responseId = ""; String loginCode = "", chgTerm = "", callStatus = "", responseJsonStr = "", responseId = "";
String sql = "";
PreparedStatement pstmt = null;
int updateCnt = 0;
try try
{ {
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm"); chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
String json = "{\"gstin\":\""+gstin+"\",\"ret_period\":\""+periodCode+"\"}"; for(String action : gstr2Section)
{
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes()); System.out.println("calling for ["+action+"]");
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(); long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin; gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey); gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
System.out.println("RETSUBMIT request url ["+String.format("%s%s", GSP_API_URL, GSTR1_URL_V3)+"]"); HttpRequest getGstr2InvoicesReq = Unirest.get(String.format("%s%s", GSP_API_URL, GSTR2A_URL_V3))
.queryString("action", action)
HttpResponse<JsonNode> gstr1SubmitResp = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR1_URL_V3)) .queryString("gstin", gstin)
.queryString("ret_period", periodCode)
.header("Content-Type", APPLICATION_JSON) .header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT")
.header("state-cd", stateCode) .header("state-cd", stateCode)
.header("clientid", clientId) .header("clientid", clientId)
.header("client-secret", clientSecret) .header("client-secret", clientSecret)
...@@ -1944,124 +2078,565 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1944,124 +2078,565 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
.header("gstin", gstin) .header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString) .header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature) .header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(reqBody.toString())) .getHttpRequest();
.asJson();
System.out.println(String.format("gstr1SubmitResp Request : Status[%s] Response[%s]", gstr1SubmitResp.getStatus(), gstr1SubmitResp.getBody())); 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()+"]");
if (gstr1SubmitResp.getStatus() == 200) 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 gstr1SubmitRespObj = gstr1SubmitResp.getBody().getObject(); JSONObject getGstr2InvoicesRespObj = getGstr2InvoicesResp.getBody().getObject();
if(gstr1SubmitRespObj.has("data") && gstr1SubmitRespObj.has("rek")) if(getGstr2InvoicesRespObj.has("data") && getGstr2InvoicesRespObj.has("rek"))
{ {
callStatus = "1"; callStatus = "1";
String gstr1Submitdata = gstr1SubmitRespObj.getString("data"); String gstr2InvoicesData = getGstr2InvoicesRespObj.getString("data");
String gstr1Submitrek = gstr1SubmitRespObj.getString("rek"); String gstr2InvoicesRek = getGstr2InvoicesRespObj.getString("rek");
byte[] apiEK = aesEncryption.decrypt(gstr1Submitrek, authSEK); byte[] apiEK = aesEncryption.decrypt(gstr2InvoicesRek, authSEK);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr1Submitdata, apiEK)); String respJsoninBase64 = new String(aesEncryption.decrypt(gstr2InvoicesData, apiEK));
byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64); byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64);
JSONObject gstr1SubmitObj = new JSONObject(new String(respJsonInBytes)); JSONObject gstr2InvoiceJsonObj = 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(); System.out.println("respJsonInBytes["+new String(respJsonInBytes)+"]");
if(pstmt!=null) if("B2B".equalsIgnoreCase(action))
{ {
pstmt.close(); insertB2BInvoiceData(stateCode, periodCode, siteCode, gstr2InvoiceJsonObj, xtraParams, conn);
pstmt = null;
} }
else if("CDN".equalsIgnoreCase(action))
System.out.println("submit status updated of ["+siteCode+"] for ["+periodCode+"] update count ["+updateCnt+"]"); {
insertCDNData(stateCode, periodCode, siteCode, gstr2InvoiceJsonObj, xtraParams, conn);
}
}
else
{
callStatus = "2";
JSONObject errorJSON = getGstr2InvoicesResp.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(getGstr2InvoicesResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+getGstr2InvoicesResp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = getGstr2InvoicesResp.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("GET_"+action);
apiCallData.setRecType("2");
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.getGstr2Invoices()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
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);
} }
else if(pstmt != null)
{ {
callStatus = "2"; pstmt.close();
JSONObject errorJSON = gstr1SubmitResp.getBody().getObject().getJSONObject("error"); pstmt = null;
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
} }
else if(gstr1SubmitResp.getStatus() == 500) if(rs != null)
{ {
callStatus = "2"; rs.close();
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstr1SubmitResp.getStatus(); rs = null;
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
} }
else
if(hsnList.size() > 0)
{ {
callStatus = "2"; hsn = new HSN();
JSONObject errorJSON = gstr1SubmitResp.getBody().getObject().getJSONObject("error"); hsn.recType = "2";
responseJsonStr = errorJSON.toString(); hsn.hsnDetails = hsnList;
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
} }
APICallData apiCallData = new APICallData(); gstr2 = new GSTR2();
apiCallData.setPeriodCode(periodCode); gstr2.gstin = gstin;
apiCallData.setCallDate(new Date()); gstr2.financialPeriod = periodCode;
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); if(b2bInvoiceList.size() > 0)
{
gstr2.b2b = b2bInvoiceList;
} }
catch(Exception e) if(b2burInvoiceList.size() > 0)
{ {
System.out.println("GSTDataSubmitWizPos.submitGstr1()["+e.getMessage()+"]"); gstr2.b2bur = b2burInvoiceList;
e.printStackTrace();
throw new ITMException(e);
} }
return retString; if(cdnrList.size() > 0)
{
gstr2.cdnr = cdnrList;
} }
if(hsn != null)
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 = ""; gstr2.hsn = hsn;
String errMsg = "", gspAuthString = "", gspAuthSignature = ""; }
String[] gstr2Section = {"B2B","CDN"};
String transactionId = UUID.randomUUID().toString().replaceAll("-", ""); String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
String loginCode = "", chgTerm = "", callStatus = "", responseJsonStr = "", responseId = ""; APICallData apiRetStatsCallData = null;
try
{
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm"); chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
for(String action : gstr2Section) ObjectMapper objectMapper = new ObjectMapper();
{
System.out.println("calling for ["+action+"]"); 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(); long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin; gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey); gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest getGstr2InvoicesReq = Unirest.get(String.format("%s%s", GSP_API_URL, GSTR2A_URL_V3)) HttpRequest saveGstr2Req = Unirest.put(String.format("%s%s", GSP_API_URL, GSTR2_URL_V3))
.queryString("action", action) .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("gstin", gstin)
.queryString("ret_period", periodCode) .queryString("ret_period", periodCode)
.queryString("ref_id",transId)
.header("Content-Type", APPLICATION_JSON) .header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode) .header("state-cd", stateCode)
.header("clientid", clientId) .header("clientid", clientId)
...@@ -2072,65 +2647,143 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2072,65 +2647,143 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
.header("txn", transactionId) .header("txn", transactionId)
.header("ret_period", periodCode) .header("ret_period", periodCode)
.header("gstin", gstin) .header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString) .header("X-Asp-Auth-Token", gspAuthStringRet)
.header("X-Asp-Auth-Signature", gspAuthSignature) .header("X-Asp-Auth-Signature", gspAuthSignatureRet)
.getHttpRequest(); .getHttpRequest();
System.out.println("get GSTR2A ["+action+"] invoices url["+getGstr2InvoicesReq.getUrl()+"]"); System.out.println("RETSTATUS url["+retStatusReq.getUrl()+"]");
System.out.println("get GSTR2A ["+action+"] invoices method["+getGstr2InvoicesReq.getHttpMethod()+"]"); System.out.println("RETSTATUS method["+retStatusReq.getHttpMethod()+"]");
System.out.println("get GSTR2A ["+action+"] invoices request header["+getGstr2InvoicesReq.getHeaders()+"]"); System.out.println("RETSTATUS request header["+retStatusReq.getHeaders()+"]");
HttpResponse<JsonNode> getGstr2InvoicesResp = getGstr2InvoicesReq.asJson(); HttpResponse<JsonNode> retStatusResp = retStatusReq.asJson();
System.out.println(String.format("getGstr2InvoicesResp Request : Status[%s] Response[%s]", getGstr2InvoicesResp.getStatus(), getGstr2InvoicesResp.getBody())); System.out.println(String.format("retStatusResp Request : Status[%s] Response[%s]", retStatusResp.getStatus(), retStatusResp.getBody()));
if (getGstr2InvoicesResp.getStatus() == 200) if (retStatusResp.getStatus() == 200)
{ {
JSONObject getGstr2InvoicesRespObj = getGstr2InvoicesResp.getBody().getObject(); JSONObject retStatsRespObj = retStatusResp.getBody().getObject();
if(getGstr2InvoicesRespObj.has("data") && getGstr2InvoicesRespObj.has("rek")) if(retStatsRespObj.has("data") && retStatsRespObj.has("rek"))
{ {
callStatus = "1"; retStatsData = retStatsRespObj.getString("data");
String gstr2InvoicesData = getGstr2InvoicesRespObj.getString("data"); retStatsRek = retStatsRespObj.getString("rek");
String gstr2InvoicesRek = getGstr2InvoicesRespObj.getString("rek");
byte[] apiEK = aesEncryption.decrypt(gstr2InvoicesRek, authSEK); byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSek);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr2InvoicesData, apiEK));
byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64); String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats));
JSONObject gstr2InvoiceJsonObj = new JSONObject(new String(respJsonInBytes)); byte[] retStatsRespJsonInBytes = aesEncryption.decodeBase64StringTOByte(retStatsRespJsoninBase64);
System.out.println("respJsonInBytes["+new String(respJsonInBytes)+"]"); JSONObject retStatsJsonData = new JSONObject(new String(retStatsRespJsonInBytes));
System.out.println( "retStatsJsonData["+retStatsJsonData+"]");
if("B2B".equalsIgnoreCase(action)) if("IP".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{ {
insertB2BInvoiceData(stateCode, periodCode, siteCode, gstr2InvoiceJsonObj, xtraParams, conn); retStatusCallStatus = "0";
continue;
} }
else if("CDN".equalsIgnoreCase(action)) else if("P".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{ {
insertCDNData(stateCode, periodCode, siteCode, gstr2InvoiceJsonObj, xtraParams, conn); 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 else
{ {
callStatus = "2"; callStatus = "2";
JSONObject errorJSON = getGstr2InvoicesResp.getBody().getObject().getJSONObject("error"); JSONObject errorJSON = gstr2Resp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString(); responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd"); errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn); retString = getError(errMsg, "GSTAPIERR", conn);
} }
} }
else if(getGstr2InvoicesResp.getStatus() == 500) else if(gstr2Resp.getStatus() == 500)
{ {
callStatus = "2"; callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+getGstr2InvoicesResp.getStatus(); errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstr2Resp.getStatus();
responseJsonStr = errMsg; responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn); retString = getError(errMsg, "GSTAPIERR", conn);
} }
else else
{ {
callStatus = "2"; callStatus = "2";
JSONObject errorJSON = getGstr2InvoicesResp.getBody().getObject().getJSONObject("error"); JSONObject errorJSON = gstr2Resp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString(); responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd"); errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn); retString = getError(errMsg, "GSTAPIERR", conn);
...@@ -2141,9 +2794,9 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2141,9 +2794,9 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
apiCallData.setCallDate(new Date()); apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode); apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode); apiCallData.setUserId(loginCode);
apiCallData.setCallType("GET_"+action); apiCallData.setCallType("RETSAVE");
apiCallData.setRecType("2"); apiCallData.setRecType("2");
apiCallData.setNoOfRecords(0); apiCallData.setNoOfRecords(noOfRecords);
apiCallData.setCallStatus(callStatus); apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId); apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr); apiCallData.setResponseJsonStr(responseJsonStr);
...@@ -2152,17 +2805,20 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2152,17 +2805,20 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
apiCallData.setChgTerm(chgTerm); apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null); gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
gstCommonUtil.updateAPICallLogHistory(apiRetStatsCallData, null);
} }
} }
catch(Exception e) catch(Exception e)
{ {
System.out.println("GSTDataSubmitWizPos.getGstr2Invoices()["+e.getMessage()+"]"); System.out.println("GSTDataSubmitWizPos.saveGstr2()["+e.getMessage()+"]");
e.printStackTrace(); e.printStackTrace();
throw new ITMException(e); throw new ITMException(e);
} }
return retString; return retString;
} }
private void insertB2BInvoiceData(String stateCode, String periodCode, String siteCode, JSONObject gstr2InvoiceJsonObj, String xtraParams, Connection conn) throws ITMException private void insertB2BInvoiceData(String stateCode, String periodCode, String siteCode, JSONObject gstr2InvoiceJsonObj, String xtraParams, Connection conn) throws ITMException
{ {
JSONArray b2bInvArry = new JSONArray(); JSONArray b2bInvArry = new JSONArray();
......
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> ...@@ -143,6 +143,20 @@ abstract class BaseSerializer<T extends BaseData> extends JsonSerializer<T>
json.writeEndObject(); 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(); json.writeEndObject();
} }
catch (Exception e) catch (Exception e)
......
...@@ -115,6 +115,20 @@ public class CDNRSerializer extends JsonSerializer<CDNR> ...@@ -115,6 +115,20 @@ public class CDNRSerializer extends JsonSerializer<CDNR>
} }
json.writeEndObject(); 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(); json.writeEndObject();
} }
catch (Exception e) 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> ...@@ -16,7 +16,14 @@ public class HSNSerializer extends BaseSerializer<HSN>
{ {
json.writeStartObject(); json.writeStartObject();
if("1".equalsIgnoreCase(hsn.recType))
{
json.writeFieldName("data"); json.writeFieldName("data");
}
else if("2".equalsIgnoreCase(hsn.recType))
{
json.writeFieldName("det");
}
json.writeStartArray(); json.writeStartArray();
for(HSNDetails hsnDetails : hsn.hsnDetails) for(HSNDetails hsnDetails : hsn.hsnDetails)
...@@ -40,26 +47,17 @@ public class HSNSerializer extends BaseSerializer<HSN> ...@@ -40,26 +47,17 @@ public class HSNSerializer extends BaseSerializer<HSN>
{ {
json.writeStringField("desc", hsnDetails.description); json.writeStringField("desc", hsnDetails.description);
} }
if(hsnDetails.unitOfMeasure != null && hsnDetails.unitOfMeasure.trim().length()>0)
{
json.writeStringField("uqc", hsnDetails.unitOfMeasure); json.writeStringField("uqc", hsnDetails.unitOfMeasure);
}
json.writeNumberField("qty", hsnDetails.quantity); json.writeNumberField("qty", hsnDetails.quantity);
json.writeNumberField("val", hsnDetails.totalAmount); json.writeNumberField("val", hsnDetails.totalAmount);
json.writeNumberField("txval", hsnDetails.totalTaxableAmount); json.writeNumberField("txval", hsnDetails.totalTaxableAmount);
if(hsnDetails.totalIGSTAmount > 0)
{
json.writeNumberField("iamt", hsnDetails.totalIGSTAmount); json.writeNumberField("iamt", hsnDetails.totalIGSTAmount);
}
if(hsnDetails.totalCGSTAmount > 0)
{
json.writeNumberField("camt", hsnDetails.totalCGSTAmount); json.writeNumberField("camt", hsnDetails.totalCGSTAmount);
}
if(hsnDetails.totalSGSTAmount > 0)
{
json.writeNumberField("samt", hsnDetails.totalSGSTAmount); json.writeNumberField("samt", hsnDetails.totalSGSTAmount);
}
if(hsnDetails.totalCESSAmount > 0)
{
json.writeNumberField("csamt", hsnDetails.totalCESSAmount); json.writeNumberField("csamt", hsnDetails.totalCESSAmount);
}
json.writeEndObject(); 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