Commit 7e97cb98 authored by steurwadkar's avatar steurwadkar

Changes made to generate and download data excel file in custom format for GSTR1 and GSTR2

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@179368 ce508802-f39f-4f6c-b175-0d175dae99d5
parent dc322077
......@@ -46,7 +46,6 @@ import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.request.HttpRequest;
import com.sun.jmx.snmp.Timestamp;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
......@@ -5289,6 +5288,587 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
}
}
public Object generateCustomOfflineFile(String periodCode, String siteCode) throws ITMException
{
XSSFWorkbook retDataWorkbook = null;
String gstrWorkBookPath = "";
String sep = File.separator;
String tranId = "", ctin = "", posStateCode = "", docNo = "", docDateStr = "",errorCode = "", dataErrMsg = "", refInvId = "",
refInvDtStr = "", preGST = "", portCode = "", gstDateFormat = "", customerName = "", regUreg = "UNREGISTERED",
siteGSTStCode = "", isRCM = "", tranTypeStr = "", interIntraExp = "", suppGSTStCode = "", crdrType = "";
boolean noDataFound = false;
double amount =0.0, gstRate = 0.0, taxableAmt = 0.0, cessAmt = 0.0;
int outWrdSuppdataRow = 4, inWrdSuppdataRow = 4, crdrPaydataRow = 4, crdrRecdataRow = 4;
double igstAmt = 0.0, cgstAmt = 0.0, sgstAmt = 0.0;
HashMap<String,String> stateCodeHMap = new HashMap<String, String>();
Calendar calendar = Calendar.getInstance();
calendar.set(2017, 06, 01);
Date gstStartDate = calendar.getTime();
String sql = "", hdrSql = "", detSql = "";
Date refInvDate = null , docDate = null;
Connection conn = null;
PreparedStatement pstmt = null, hdrPstmt = null, detPstmt = null;
ResultSet rs = null, hdrRs = null, detRs = null;
FinCommon finCommon = new FinCommon();
try
{
conn = getConnection();
sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE SUBMIT_STATUS = 'P' AND PRD_CODE = ? AND SITE_CODE = ? AND REC_TYPE IN ('1','2')";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, periodCode);
pstmt.setString(2, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") == 0)
{
noDataFound = true;
errorCode = "VTNOGSDATA";
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt=null;
}
if(rs!=null)
{
rs.close();
rs=null;
}
if(noDataFound)
{
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");
}
closeResources(rs, pstmt);
return "<root><message><![CDATA[Message : "+dataErrMsg+"]]></message></root>";
}
else
{
gstrWorkBookPath = CommonConstants.JBOSSHOME + sep + "DOWNLOAD" + sep + "template" + sep + "GSTR_Custom_Format.xlsx";
File gstrExcleFile = new File(gstrWorkBookPath);
if(gstrExcleFile.exists())
{
retDataWorkbook = new XSSFWorkbook(new FileInputStream(gstrExcleFile));
}
gstDateFormat = finCommon.getFinparams("999999", "GST_EXCL_DATE_FORMAT", conn);
CellStyle dateCellStyle = retDataWorkbook.createCellStyle();
CreationHelper createHelper = retDataWorkbook.getCreationHelper();
dateCellStyle.setDataFormat( createHelper.createDataFormat().getFormat(gstDateFormat));
SimpleDateFormat gstDateFormatSdf = new SimpleDateFormat(gstDateFormat);
sql = " SELECT GST_CODE, DESCR FROM STATE WHERE GST_CODE IS NOT NULL ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next())
{
String gstStCode = checkNull(rs.getString("GST_CODE"));
String stateDscr = checkNull(rs.getString("DESCR"));
stateCodeHMap.put(gstStCode, stateDscr);
}
closeResources(rs, pstmt);
sql = " SELECT SUBSTR(REG_NO,0,2) AS GST_CODE FROM SITEREGNO WHERE SITE_CODE = ? AND REF_CODE = 'GSTIN_NO' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
siteGSTStCode = checkNull(rs.getString("GST_CODE"));
}
closeResources(rs, pstmt);
hdrSql = " SELECT GDH.TRAN_ID, GDH.DOC_NO, GDH.DOC_DATE, GDH.CUST_NAME, CASE WHEN GDH.TRAN_TYPE='02' THEN 'YES' ELSE 'NO' END AS RCM, "
+ " GEN.UDF_STR1, GDH.TAX_REG_NO, GDH.GST_CODE, GDH.AMOUNT, GDH.ORDER_NO FROM GST_DATA_HDR GDH, GENCODES GEN "
+ " WHERE GDH.REC_TYPE = ? AND GDH.PRD_CODE = ? AND GDH.SITE_CODE = ? AND GDH.SUBMIT_STATUS = ? "
+ " AND GDH.TRAN_TYPE NOT IN ('29','30','31','32','33','34','35','36') AND GEN.MOD_NAME='W_GSTR' AND GEN.FLD_NAME='TRAN_TYPE' "
+ " AND GDH.TRAN_TYPE=GEN.FLD_VALUE ORDER BY GDH.TRAN_TYPE,GDH.DOC_DATE,GDH.DOC_NO ";
hdrPstmt = conn.prepareStatement(hdrSql);
hdrPstmt.setString(1, "1");
hdrPstmt.setString(2, periodCode);
hdrPstmt.setString(3, siteCode);
hdrPstmt.setString(4, "P");
hdrRs = hdrPstmt.executeQuery();
XSSFSheet outWrdSuppdataSheet = retDataWorkbook.getSheet("Outward_Sale_N_Transfer");
while(hdrRs.next())
{
tranId = hdrRs.getString("TRAN_ID");
docNo = checkNull(hdrRs.getString("DOC_NO"));
docDate = hdrRs.getDate("DOC_DATE");
customerName = checkNull(hdrRs.getString("CUST_NAME"));
isRCM = checkNull(hdrRs.getString("RCM"));
tranTypeStr = checkNull(hdrRs.getString("UDF_STR1"));
ctin = checkNull(hdrRs.getString("TAX_REG_NO"));
posStateCode = checkNull(hdrRs.getString("GST_CODE"));
amount = Double.parseDouble(String.format("%.2f",hdrRs.getDouble("AMOUNT")));
portCode = checkNull(hdrRs.getString("ORDER_NO"));
if(docDate!=null)
{
docDateStr = gstDateFormatSdf.format(docDate);
}
if("EXP".equalsIgnoreCase(tranTypeStr))
{
interIntraExp = "Export";
}
else
{
if(siteGSTStCode.equalsIgnoreCase(posStateCode))
{
interIntraExp = "IntraState";
}
else
{
interIntraExp = "InterState";
}
}
detSql = " SELECT GST_RATE, SUM(IGST_AMT) AS IGST_AMT, SUM(CGST_AMT) AS CGST_AMT, SUM(SGST_AMT) AS SGST_AMT, SUM(CESS_AMT) AS CESS_AMT "
+ " FROM GST_DATA_DET WHERE TRAN_ID = ? GROUP BY GST_RATE ";
detPstmt = conn.prepareStatement(detSql);
detPstmt.setString(1, tranId);
detRs = detPstmt.executeQuery();
while(detRs.next())
{
gstRate = Double.parseDouble(String.format("%.2f",detRs.getDouble("GST_RATE")));
igstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("IGST_AMT")));
cgstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("CGST_AMT")));
sgstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("SGST_AMT")));
cessAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("CESS_AMT")));
double totTaxAmt = igstAmt + cgstAmt + sgstAmt + cessAmt;
totTaxAmt = Double.parseDouble(String.format("%.2f",totTaxAmt));
XSSFRow dataRow = outWrdSuppdataSheet.createRow(outWrdSuppdataRow++);
dataRow.createCell(0).setCellValue(docNo);
XSSFCell docDateCell = dataRow.createCell(1);
if(docDateStr!=null && docDateStr.trim().length()>0)
{
docDateCell.setCellValue(gstDateFormatSdf.parse(docDateStr));
docDateCell.setCellStyle(dateCellStyle);
}
dataRow.createCell(2).setCellValue(customerName);
dataRow.createCell(3).setCellValue(interIntraExp);
dataRow.createCell(4).setCellValue(isRCM);
dataRow.createCell(5).setCellValue(tranTypeStr);
dataRow.createCell(6).setCellValue(ctin);
dataRow.createCell(7).setCellValue(posStateCode+"-"+checkNull(stateCodeHMap.get(posStateCode)));
dataRow.createCell(8).setCellValue(amount);
dataRow.createCell(9).setCellValue(gstRate);
dataRow.createCell(10).setCellValue(igstAmt);
dataRow.createCell(11).setCellValue(cgstAmt);
dataRow.createCell(12).setCellValue(sgstAmt);
dataRow.createCell(13).setCellValue(cessAmt);
dataRow.createCell(14).setCellValue(totTaxAmt);
dataRow.createCell(15).setCellValue(portCode);
}
closeResources(detRs, detPstmt);
}
closeResources(hdrRs, hdrPstmt);
hdrSql = " SELECT GDH.TRAN_ID, GDH.DOC_NO, GDH.DOC_DATE, GDH.CUST_NAME, CASE WHEN GDH.TRAN_TYPE='05' THEN 'YES' ELSE 'NO' END AS RCM, "
+ " GEN.UDF_STR1, GDH.TAX_REG_NO, GDH.GST_CODE, GDH.AMOUNT, GDH.ORDER_NO FROM GST_DATA_HDR GDH, GENCODES GEN "
+ " WHERE GDH.REC_TYPE = ? AND GDH.PRD_CODE = ? AND GDH.SITE_CODE = ? AND GDH.SUBMIT_STATUS = ? "
+ " AND GDH.TRAN_TYPE NOT IN ('10','11','12','13') AND GEN.MOD_NAME='W_GSTR_PURC' AND GEN.FLD_NAME='TRAN_TYPE' "
+ " AND GDH.TRAN_TYPE=GEN.FLD_VALUE ORDER BY GDH.TRAN_TYPE,GDH.DOC_DATE,GDH.DOC_NO ";
hdrPstmt = conn.prepareStatement(hdrSql);
hdrPstmt.setString(1, "2");
hdrPstmt.setString(2, periodCode);
hdrPstmt.setString(3, siteCode);
hdrPstmt.setString(4, "P");
hdrRs = hdrPstmt.executeQuery();
XSSFSheet inWrdSuppdataSheet = retDataWorkbook.getSheet("Inward_Purchase_N_Transfer");
while(hdrRs.next())
{
tranId = hdrRs.getString("TRAN_ID");
docNo = checkNull(hdrRs.getString("DOC_NO"));
docDate = hdrRs.getDate("DOC_DATE");
customerName = checkNull(hdrRs.getString("CUST_NAME"));
isRCM = checkNull(hdrRs.getString("RCM"));
tranTypeStr = checkNull(hdrRs.getString("UDF_STR1"));
ctin = checkNull(hdrRs.getString("TAX_REG_NO"));
posStateCode = checkNull(hdrRs.getString("GST_CODE"));
amount = Double.parseDouble(String.format("%.2f",hdrRs.getDouble("AMOUNT")));
portCode = checkNull(hdrRs.getString("ORDER_NO"));
if(docDate!=null)
{
docDateStr = gstDateFormatSdf.format(docDate);
}
if(ctin.trim().length() > 2)
{
suppGSTStCode = ctin.substring(0, 2);
}
if("IMP_G".equalsIgnoreCase(tranTypeStr))
{
interIntraExp = "Import";
}
else
{
if(suppGSTStCode.equalsIgnoreCase(posStateCode))
{
interIntraExp = "IntraState";
}
else
{
interIntraExp = "InterState";
}
}
detSql = " SELECT GST_RATE, SUM(IGST_AMT) AS IGST_AMT, SUM(CGST_AMT) AS CGST_AMT, SUM(SGST_AMT) AS SGST_AMT, SUM(CESS_AMT) AS CESS_AMT "
+ " FROM GST_DATA_DET WHERE TRAN_ID = ? GROUP BY GST_RATE ";
detPstmt = conn.prepareStatement(detSql);
detPstmt.setString(1, tranId);
detRs = detPstmt.executeQuery();
while(detRs.next())
{
gstRate = Double.parseDouble(String.format("%.2f",detRs.getDouble("GST_RATE")));
igstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("IGST_AMT")));
cgstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("CGST_AMT")));
sgstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("SGST_AMT")));
cessAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("CESS_AMT")));
double totTaxAmt = igstAmt + cgstAmt + sgstAmt + cessAmt;
totTaxAmt = Double.parseDouble(String.format("%.2f",totTaxAmt));
XSSFRow dataRow = inWrdSuppdataSheet.createRow(inWrdSuppdataRow++);
dataRow.createCell(0).setCellValue(docNo);
XSSFCell docDateCell = dataRow.createCell(1);
if(docDateStr!=null && docDateStr.trim().length()>0)
{
docDateCell.setCellValue(gstDateFormatSdf.parse(docDateStr));
docDateCell.setCellStyle(dateCellStyle);
}
dataRow.createCell(2).setCellValue(customerName);
dataRow.createCell(3).setCellValue(interIntraExp);
dataRow.createCell(4).setCellValue(isRCM);
dataRow.createCell(5).setCellValue(tranTypeStr);
dataRow.createCell(6).setCellValue(ctin);
dataRow.createCell(7).setCellValue(posStateCode+"-"+checkNull(stateCodeHMap.get(posStateCode)));
dataRow.createCell(8).setCellValue(""); //TODO need to check with devendra sir
dataRow.createCell(9).setCellValue(""); //TODO need to check with devendra sir
dataRow.createCell(10).setCellValue(amount);
dataRow.createCell(11).setCellValue(gstRate);
dataRow.createCell(12).setCellValue(igstAmt);
dataRow.createCell(13).setCellValue(cgstAmt);
dataRow.createCell(14).setCellValue(sgstAmt);
dataRow.createCell(15).setCellValue(cessAmt);
dataRow.createCell(16).setCellValue(totTaxAmt);
dataRow.createCell(17).setCellValue(portCode);
}
closeResources(detRs, detPstmt);
}
closeResources(hdrRs, hdrPstmt);
hdrSql = " SELECT GDH.TRAN_ID, GDH.DOC_NO, GDH.DOC_DATE, GDH.CUST_NAME, GEN.UDF_STR1, GEN.UDF_STR2, GDH.TAX_REG_NO, "
+ " GDH.GST_CODE, GDH.REF_ID__INV, GDH.REF_DATE__INV, GDH.AMOUNT FROM GST_DATA_HDR GDH, GENCODES GEN "
+ " WHERE GDH.REC_TYPE = ? AND GDH.PRD_CODE = ? AND GDH.SITE_CODE = ? AND GDH.SUBMIT_STATUS = ? "
+ " AND GDH.TRAN_TYPE IN ('29','30','31','32','33','34','35','36') AND GEN.MOD_NAME='W_GSTR' AND GEN.FLD_NAME='TRAN_TYPE' "
+ " AND GDH.TRAN_TYPE=GEN.FLD_VALUE ORDER BY GDH.TRAN_TYPE,GDH.DOC_DATE,GDH.DOC_NO";
hdrPstmt = conn.prepareStatement(hdrSql);
hdrPstmt.setString(1, "1");
hdrPstmt.setString(2, periodCode);
hdrPstmt.setString(3, siteCode);
hdrPstmt.setString(4, "P");
hdrRs = hdrPstmt.executeQuery();
XSSFSheet crdrRecdataSheet = retDataWorkbook.getSheet("Credit_Debit_Note_Receivable");
while(hdrRs.next())
{
tranId = hdrRs.getString("TRAN_ID");
docNo = checkNull(hdrRs.getString("DOC_NO"));
docDate = hdrRs.getDate("DOC_DATE");
customerName = checkNull(hdrRs.getString("CUST_NAME"));
tranTypeStr = checkNull(hdrRs.getString("UDF_STR1"));
crdrType = checkNull(hdrRs.getString("UDF_STR2"));
ctin = checkNull(hdrRs.getString("TAX_REG_NO"));
posStateCode = checkNull(hdrRs.getString("GST_CODE"));
refInvId = checkNull(hdrRs.getString("REF_ID__INV"));
refInvDate = hdrRs.getDate("REF_DATE__INV");
amount = Double.parseDouble(String.format("%.2f",hdrRs.getDouble("AMOUNT")));
if(docDate!=null)
{
docDateStr = gstDateFormatSdf.format(docDate);
}
if(ctin.trim().length() > 0)
{
regUreg = "REGISTERED";
}
if(refInvDate!=null)
{
refInvDtStr = gstDateFormatSdf.format(refInvDate);
}
if(refInvDate!=null)
{
preGST = refInvDate.before(gstStartDate) ? "Y" : "N";
}
else
{
preGST = "";
}
detSql = " 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 "
+ " FROM GST_DATA_DET WHERE TRAN_ID = ? GROUP BY GST_RATE ";
detPstmt = conn.prepareStatement(detSql);
detPstmt.setString(1, tranId);
detRs = detPstmt.executeQuery();
while(detRs.next())
{
taxableAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("TAXABLE_AMT")));
gstRate = Double.parseDouble(String.format("%.2f",detRs.getDouble("GST_RATE")));
igstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("IGST_AMT")));
cgstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("CGST_AMT")));
sgstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("SGST_AMT")));
cessAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("CESS_AMT")));
double totTaxAmt = igstAmt + cgstAmt + sgstAmt + cessAmt;
totTaxAmt = Double.parseDouble(String.format("%.2f",totTaxAmt));
XSSFRow dataRow = crdrRecdataSheet.createRow(crdrRecdataRow++);
dataRow.createCell(0).setCellValue(docNo);
XSSFCell docDateCell = dataRow.createCell(1);
if(docDateStr!=null && docDateStr.trim().length()>0)
{
docDateCell.setCellValue(gstDateFormatSdf.parse(docDateStr));
docDateCell.setCellStyle(dateCellStyle);
}
dataRow.createCell(2).setCellValue(customerName);
dataRow.createCell(3).setCellValue("");//TODO need to check with devendra sir
dataRow.createCell(4).setCellValue(crdrType);
dataRow.createCell(5).setCellValue(regUreg);
dataRow.createCell(6).setCellValue(ctin);
dataRow.createCell(7).setCellValue(posStateCode+"-"+checkNull(stateCodeHMap.get(posStateCode)));
dataRow.createCell(8).setCellValue(refInvId);
XSSFCell refInvDateCell = dataRow.createCell(9);
if(refInvDtStr!=null && refInvDtStr.trim().length()>0)
{
refInvDateCell.setCellValue(gstDateFormatSdf.parse(refInvDtStr));
refInvDateCell.setCellStyle(dateCellStyle);
}
dataRow.createCell(10).setCellValue("Others");
dataRow.createCell(11).setCellValue(amount);
dataRow.createCell(12).setCellValue(gstRate);
dataRow.createCell(13).setCellValue(taxableAmt);
dataRow.createCell(14).setCellValue(igstAmt);
dataRow.createCell(15).setCellValue(cgstAmt);
dataRow.createCell(16).setCellValue(sgstAmt);
dataRow.createCell(17).setCellValue(cessAmt);
dataRow.createCell(18).setCellValue(totTaxAmt);
dataRow.createCell(19).setCellValue(preGST);
}
closeResources(detRs, detPstmt);
}
closeResources(hdrRs, hdrPstmt);
hdrSql = " SELECT GDH.TRAN_ID, GDH.DOC_NO, GDH.DOC_DATE, GDH.CUST_NAME, GEN.UDF_STR1, GEN.UDF_STR2, GDH.TAX_REG_NO, "
+ " GDH.GST_CODE, GDH.REF_ID__INV, GDH.REF_DATE__INV, GDH.AMOUNT FROM GST_DATA_HDR GDH, GENCODES GEN "
+ " WHERE GDH.REC_TYPE = ? AND GDH.PRD_CODE = ? AND GDH.SITE_CODE = ? AND GDH.SUBMIT_STATUS = ? "
+ " AND GDH.TRAN_TYPE IN ('10','11','12','13') AND GEN.MOD_NAME='W_GSTR_PURC' AND GEN.FLD_NAME='TRAN_TYPE' "
+ " AND GDH.TRAN_TYPE=GEN.FLD_VALUE ORDER BY GDH.TRAN_TYPE,GDH.DOC_DATE,GDH.DOC_NO";
hdrPstmt = conn.prepareStatement(hdrSql);
hdrPstmt.setString(1, "2");
hdrPstmt.setString(2, periodCode);
hdrPstmt.setString(3, siteCode);
hdrPstmt.setString(4, "P");
hdrRs = hdrPstmt.executeQuery();
XSSFSheet crdrPaydataSheet = retDataWorkbook.getSheet("Credit_Debit_Note_Payable");
while(hdrRs.next())
{
tranId = hdrRs.getString("TRAN_ID");
docNo = checkNull(hdrRs.getString("DOC_NO"));
docDate = hdrRs.getDate("DOC_DATE");
customerName = checkNull(hdrRs.getString("CUST_NAME"));
tranTypeStr = checkNull(hdrRs.getString("UDF_STR1"));
crdrType = checkNull(hdrRs.getString("UDF_STR2"));
ctin = checkNull(hdrRs.getString("TAX_REG_NO"));
posStateCode = checkNull(hdrRs.getString("GST_CODE"));
refInvId = checkNull(hdrRs.getString("REF_ID__INV"));
refInvDate = hdrRs.getDate("REF_DATE__INV");
amount = Double.parseDouble(String.format("%.2f",hdrRs.getDouble("AMOUNT")));
if(docDate!=null)
{
docDateStr = gstDateFormatSdf.format(docDate);
}
if(ctin.trim().length() > 0)
{
regUreg = "REGISTERED";
}
if(refInvDate!=null)
{
refInvDtStr = gstDateFormatSdf.format(refInvDate);
}
if(refInvDate!=null)
{
preGST = refInvDate.before(gstStartDate) ? "Y" : "N";
}
else
{
preGST = "";
}
detSql = " 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 "
+ " FROM GST_DATA_DET WHERE TRAN_ID = ? GROUP BY GST_RATE ";
detPstmt = conn.prepareStatement(detSql);
detPstmt.setString(1, tranId);
detRs = detPstmt.executeQuery();
while(detRs.next())
{
taxableAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("TAXABLE_AMT")));
gstRate = Double.parseDouble(String.format("%.2f",detRs.getDouble("GST_RATE")));
igstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("IGST_AMT")));
cgstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("CGST_AMT")));
sgstAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("SGST_AMT")));
cessAmt = Double.parseDouble(String.format("%.2f",detRs.getDouble("CESS_AMT")));
double totTaxAmt = igstAmt + cgstAmt + sgstAmt + cessAmt;
totTaxAmt = Double.parseDouble(String.format("%.2f",totTaxAmt));
XSSFRow dataRow = crdrPaydataSheet.createRow(crdrPaydataRow++);
dataRow.createCell(0).setCellValue(docNo);
XSSFCell docDateCell = dataRow.createCell(1);
if(docDateStr!=null && docDateStr.trim().length()>0)
{
docDateCell.setCellValue(gstDateFormatSdf.parse(docDateStr));
docDateCell.setCellStyle(dateCellStyle);
}
dataRow.createCell(2).setCellValue(customerName);
dataRow.createCell(3).setCellValue("");//TODO need to check with devendra sir
dataRow.createCell(4).setCellValue(crdrType);
dataRow.createCell(5).setCellValue(regUreg);
dataRow.createCell(6).setCellValue(ctin);
dataRow.createCell(7).setCellValue(posStateCode+"-"+checkNull(stateCodeHMap.get(posStateCode)));
dataRow.createCell(8).setCellValue(refInvId);
XSSFCell refInvDateCell = dataRow.createCell(9);
if(refInvDtStr!=null && refInvDtStr.trim().length()>0)
{
refInvDateCell.setCellValue(gstDateFormatSdf.parse(refInvDtStr));
refInvDateCell.setCellStyle(dateCellStyle);
}
dataRow.createCell(10).setCellValue("Others");
dataRow.createCell(11).setCellValue(amount);
dataRow.createCell(12).setCellValue(gstRate);
dataRow.createCell(13).setCellValue(taxableAmt);
dataRow.createCell(14).setCellValue(igstAmt);
dataRow.createCell(15).setCellValue(cgstAmt);
dataRow.createCell(16).setCellValue(sgstAmt);
dataRow.createCell(17).setCellValue(cessAmt);
dataRow.createCell(18).setCellValue(totTaxAmt);
dataRow.createCell(19).setCellValue(preGST);
}
closeResources(detRs, detPstmt);
}
closeResources(hdrRs, hdrPstmt);
return retDataWorkbook;
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizEJB.generateCustomOfflineFile()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(pstmt!=null)
{
pstmt.close();
pstmt=null;
}
if(rs!=null)
{
rs.close();
rs=null;
}
if(hdrPstmt!=null)
{
hdrPstmt.close();
hdrPstmt = null;
}
if(hdrRs!=null)
{
hdrRs.close();
hdrRs=null;
}
if(detPstmt!=null)
{
detPstmt.close();
detPstmt = null;
}
if(detRs!=null)
{
detRs.close();
detRs=null;
}
if(conn!=null && !conn.isClosed())
{
conn.close();
conn=null;
}
}
catch(SQLException se)
{
System.out.println("GSTDataSubmitWizEJB.generateOfflineFile()["+se.getMessage()+"]");
se.printStackTrace();
}
}
}
private String checkNull(String input)
{
if (input==null)
......
......@@ -106,7 +106,84 @@ public class GSTDataSubmitWizServlet extends HttpServlet
{
boolean isWorkbook = retObj instanceof Workbook;
System.out.println("isWorkbook : "+ isWorkbook);
request.getSession().setAttribute("GSTR_OFFLINE_FILE:"+siteCode+":"+prdCode+":"+recType+":"+random,"DONE");
//request.getSession().setAttribute("GSTR_OFFLINE_FILE:"+siteCode+":"+prdCode+":"+recType+":"+random,"DONE");
if(retObj instanceof String)
{
response.setContentType( "text/html; charset=UTF8,"+CommonConstants.ENCODING );
responseXML = (String) retObj.toString();
System.out.println("responseXML["+responseXML+"]");
Document errDom = e12GenericUtility.parseString(responseXML);
String errMsg = errDom.getElementsByTagName("message").item(0).getFirstChild().getNodeValue();
String responseStr = "<HTML><HEAD><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><SCRIPT language=JAVASCRIPT>alert('"+errMsg+"');window.location.href = '/ibase/webitm/jsp/GetGSTOfflineFile.jsp'</SCRIPT></HEAD></HTML>";
if(CommonConstants.CONTENT_ENCODING != null && CommonConstants.CONTENT_ENCODING.equalsIgnoreCase("gzip"))
{
response.setHeader("Content-Encoding", "gzip");
GZIPOutputStream gzOutStream = new GZIPOutputStream(response.getOutputStream());
gzOutStream.write(responseStr.getBytes());
gzOutStream.flush();
gzOutStream.close();
}
else
{
response.setHeader("Content-Encoding", "");
OutputStream outStream = response.getOutputStream();
outStream.write(responseStr.getBytes());
outStream.flush();
outStream.close();
}
}
else if(retObj instanceof Workbook)
{
retDataWorkbook = (XSSFWorkbook) retObj;
response.setContentType("application/excel");
if(CommonConstants.CONTENT_ENCODING != null && CommonConstants.CONTENT_ENCODING.equalsIgnoreCase("gzip"))
{
response.setHeader("Content-Encoding", "gzip");
response.setHeader("Content-Disposition","attachment; fileName=\"" + fileName + "\"");
GZIPOutputStream gzOutStream = new GZIPOutputStream(response.getOutputStream());
retDataWorkbook.write(gzOutStream);
gzOutStream.flush();
gzOutStream.close();
}
else
{
response.setHeader("Content-Encoding", "");
response.setHeader("Content-Disposition","attachment; fileName=\"" + fileName + "\"");
OutputStream outStream = response.getOutputStream();
retDataWorkbook.write(outStream);
outStream.flush();
outStream.close();
}
}
}
}
else if("GET_OFFLINE_CUST_FILE".equalsIgnoreCase(action))
{
String fileName = "";
Workbook retDataWorkbook = null;
String prdCode = request.getParameter("prd_code");
String siteCode = request.getParameter("site_code");
String random = request.getParameter("random");
System.out.println("siteCode ["+siteCode+"]");
System.out.println("prdCode ["+prdCode+"]");
System.out.println("random ["+random+"]");
fileName = "GSTR_"+prdCode+"_Custom_Data.xlsx";
GSTDataSubmitWizEJB gstDataSubmitWizEJB = new GSTDataSubmitWizEJB();
Object retObj = gstDataSubmitWizEJB.generateCustomOfflineFile(prdCode, siteCode);
if(retObj != null)
{
boolean isWorkbook = retObj instanceof Workbook;
System.out.println("isWorkbook : "+ isWorkbook);
//request.getSession().setAttribute("GSTR_OFFLINE_CUST_FILE:"+siteCode+":"+prdCode+":"+random,"DONE");
if(retObj instanceof String)
{
......
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="ibase.utility.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.zip.GZIPOutputStream"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.io.*,org.w3c.dom.Document"%>
<%@ page import="ibase.webitm.ejb.gst.GSTDataSubmitWizEJB,ibase.utility.E12GenericUtility"%>
<%@ page import="org.apache.poi.ss.usermodel.Workbook,org.apache.poi.xssf.usermodel.XSSFWorkbook"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
ibase.utility.UserInfoBean userInfo = (ibase.utility.UserInfoBean)session.getAttribute("USER_INFO");
String referer = request.getRequestURL().toString();
referer = referer.substring( referer.indexOf( "ibase" ) - 1 );
String queryString = (String)request.getQueryString();
queryString = (queryString == null) ? "" : queryString;
referer = referer +"?"+queryString;
if( userInfo == null )
{
%>
<jsp:forward page="/jsp/DirectAccess.jsp">
<jsp:param name="REFERER" value="<%=referer%>"/>
</jsp:forward>
<%
}
%>
<%
String siteCode = "";
if(userInfo != null)
{
siteCode = userInfo.getSiteCode();
}
%>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/ibase/webitm/css/Galaxy/galaxy-theme.css" media="screen"/>
<link href="/ibase/webitm/css/htmlWizard.css" rel="stylesheet"/>
<script type="text/javascript" src="/ibase/webitm/js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="/ibase/webitm/js/jquery-ui-1.10.4.custom.min.js"></script>
<script language="Javascript" src="/ibase/webitm/js/date.js"></script>
<style>
.headerDiv
{
font-size: 18px;
color: #5893bf;
padding-left: 20px;
padding-top: 0;
height: 32px;
line-height: 32px;
}
.mainContainer
{
border : 1px solid lightgray !important;
border-top: 2px solid #7bc6ff !important;
-moz-border : 1px solid lightgray !important;
-moz-border-top: 2px solid #7bc6ff !important;
padding-top: 10px;
padding-bottom: 10px;
overflow:auto;
background-color: white;
height: 200px;
}
.inputContainer
{
padding-left: 40px;
padding-top: 20px;
}
.inputDiv
{
display: inline;
}
.inputLable
{
color: #555;
font-size: 16px;
text-align: right;
width:132px;
}
.eachLineFields div
{
display: inline-block;
margin-bottom: 5px;
}
.eachField div
{
display: inline-block;
margin-left: 5px;
float: left;
}
.btnDiv
{
margin-top: 5px;
padding-left: 20px;
}
#buttonreplacement
{
width: 150px;
height: 80px;
background-color: #fff;
margin:0px auto;
text-align: center;
z-index:1005;
display:none;
position: fixed;
top: 40%;
left: 40%;
}
#buttonreplacement>img{
margin-top:15px;
margin-left:50px;
display: table-cell;
}
</style>
<script>
function returnPeriodDropdown()
{
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var monthCode = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
var selectedMonthCode = "";
var curDate = new Date();
var prevMonth = new Date().addMonths(-1);
selectedMonthCode = monthCode[prevMonth.getMonth()]+prevMonth.getFullYear();
var gstStartMonth = 7;
var gstStartYear = 2017;
var curMonth = curDate.getMonth();
var diffMonths = (curDate.getFullYear() - gstStartYear - 1) * 12 + gstStartMonth + curMonth;
var prevdate = curDate.addMonths(-diffMonths);
for(var i=0; i<diffMonths; i++)
{
var nextDate = prevdate.addMonths(1);
$('#yearMonthInput').append($('<option />').val(monthCode[nextDate.getMonth()] + nextDate.getFullYear()).html(months[nextDate.getMonth()] + " " + nextDate.getFullYear()));
if(monthCode[nextDate.getMonth()]+nextDate.getFullYear() == selectedMonthCode)
{
$('#yearMonthInput').val(monthCode[curDate.getMonth()]+""+curDate.getFullYear()).change();
}
prevdate = nextDate;
}
}
function generateFile()
{
var retPeriod = document.getElementById("yearMonthInput").value;
var random = Math.random();
document.getElementById("prdCode").value = retPeriod;
var url ="/ibase/GSTDataSubmitWizServlet?random="+random;
document.getElementById("dataForm").action = url;
document.getElementById("dataForm").submit();
//Commented on 23/10/2017 for Infinispan lock issue
/* var overlay = document.getElementById( "overlay" );
overlay.setAttribute( "style", "position: fixed; top: 0; right: 0; bottom: 0; left: 0; background-color:#000; opacity: .45; z-index:1003; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;");
document.getElementById("buttonreplacement").style.display = "block";
var siteCode = document.getElementById("siteCode").value;
var key = "GSTR_OFFLINE_FILE:"+siteCode+":"+retPeriod+":"+returnType+":"+random;
hideWaitImg(key); */
}
function hideWaitImg(key)
{
$.ajax({
url : "/ibase/GSTDataSubmitWizServlet",
type : "POST",
data : {
key : key,
action : "CHECK_HIDE_IMAGE"
},
dataType: "text/plain",
complete: function(xhr,status){
document.getElementById("buttonreplacement").style.display = "none";
var overlay = document.getElementById( "overlay" );
overlay.removeAttribute( "style");
}
});
}
</script>
</head>
<body onload="returnPeriodDropdown();">
<div id="overlay"></div>
<form method="post" action="" id="dataForm">
<div class="bodyContainer">
<div class="headerDiv">
<span>Download custom data file</span>
</div>
<div class="mainContainer">
<div class="inputContainer">
<div class="eachLineFields">
<div class="eachField">
<div class="inputLable">
Month :
</div>
<div class="inputBox">
<select id="yearMonthInput" class="input_editable">
</select>
</div>
</div>
</div>
</div>
<input type="hidden" id="siteCode" name="site_code" value="<%=siteCode %>"/>
<input type="hidden" id="prdCode" name="prd_code"/>
<input type="hidden" id="action" name="action" value="GET_OFFLINE_CUST_FILE"/>
</div>
<div class="btnDiv">
<input type="button" class="button" value="Generate & download file" onclick="generateFile();"/>
</div>
<div id="buttonreplacement">
<img src="/ibase/images/preload.gif" alt="Please wait" ></img>
<span>Please wait......</span>
</div>
</div>
</form>
</body>
</html>
\ No newline at end of file
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