Dear Sir
I have tried all the way but unable to get error and also i need save the JSON confirm dialog. Please help me out.
protected void btnJson_Click(object sender, EventArgs e)
{
List<Root> Details = new List<Root>();
DataTable dt = GetData("SELECT DISTINCT BRANCH_GSTIN FROM GST_SUMMARY_VW WHERE BRANCH_GSTIN='" + ddlGSTINNo.SelectedValue + "' AND BILL_MONTH='" + drpMonth.SelectedValue + "' ");
for (int i = 0; i < dt.Rows.Count; i++)
{
Root DWBDetail = new Root
{
gstin = Convert.ToString(dt.Rows[i]["BRANCH_GSTIN"]),
fp = Convert.ToString(drpMonth.SelectedValue),
version = "GST3.1.2",
hash = "hash",
b2b = CustomerGSTINNumber(Convert.ToString(dt.Rows[i]["BRANCH_GSTIN"]))
};
Details.Add(DWBDetail);
}
Root root = new Root();
root = Details;
var json = new JavaScriptSerializer().Serialize(root);
System.IO.File.WriteAllText(Server.MapPath("~/json.json"), json);
}
public List<B2b> CustomerGSTINNumber(string BranchGstin)
{
List<B2b> CustomerGstin = new List<B2b>();
DataTable dt = GetData(string.Format("SELECT DISTINCT CUST_GSTIN FROM GST_SUMMARY_VW WHERE BRANCH_GSTIN='{0}' AND BILL_MONTH='" + drpMonth.SelectedValue + "' ORDER BY CUST_GSTIN ", BranchGstin));
for (int i = 0; i < dt.Rows.Count; i++)
{
CustomerGstin.Add(new B2b
{
ctin = Convert.ToString(dt.Rows[i]["CUST_GSTIN"]),
inv = CustomerInvNo(BranchGstin,Convert.ToString(dt.Rows[i]["CUST_GSTIN"]))
});
}
return CustomerGstin;
}
public List<Inv> CustomerInvNo(string BranchGst,string CustomerGst)
{
List<Inv> CustomerInvoices = new List<Inv>();
DataTable dt = GetData(string.Format("SELECT BILL_NO,TO_DATE(BILL_DATE,'DD-MM-YYYY')BILL_DATE,(SUBSTR(CUST_GSTIN,0,2))POS,CGST_RATE,SGST_RATE,IGST_RATE,CGST,SGST,IGST,BILL_FREIGHT,NET_AMNT FROM GST_SUMMARY_VW WHERE BRANCH_GSTIN='{0}' AND CUST_GSTIN='{1}' AND BILL_MONTH='" + drpMonth.SelectedValue + "' ORDER BY BILL_NO ", BranchGst,CustomerGst));
for (int i = 0; i < dt.Rows.Count; i++)
{
CustomerInvoices.Add(new Inv
{
inum = Convert.ToString(dt.Rows[i]["BILL_NO"]),
idt = Convert.ToString(dt.Rows[i]["BILL_DATE"]).Replace("00:00:00",""),
val = Convert.ToDouble(dt.Rows[i]["NET_AMNT"]),
pos = Convert.ToString(dt.Rows[i]["POS"]),
rchrg ="N",
inv_typ ="R",
itms = CustomerInvNoItem(BranchGst, CustomerGst, Convert.ToString(dt.Rows[i]["BILL_NO"]))
});
}
return CustomerInvoices;
}
public List<Itm> CustomerItm()
{
List<Itm> CustomerItm = new List<Itm>();
DataTable dt = GetData(string.Format("SELECT BILL_NO,TO_DATE(BILL_DATE,'DD-MM-YYYY')BILL_DATE,(SUBSTR(CUST_GSTIN,0,2))POS,CGST_RATE,SGST_RATE,IGST_RATE,CGST,SGST,IGST,BILL_FREIGHT,NET_AMNT FROM GST_SUMMARY_VW WHERE BRANCH_GSTIN='{0}' AND CUST_GSTIN='{1}' AND BILL_MONTH='" + drpMonth.SelectedValue + "' ORDER BY BILL_NO ", BranchGst, CustomerGst));
for (int i = 0; i < dt.Rows.Count; i++)
{
CustomerItm.Add(new Inv
{
inum = Convert.ToString(dt.Rows[i]["BILL_NO"]),
idt = Convert.ToString(dt.Rows[i]["BILL_DATE"]).Replace("00:00:00", ""),
val = Convert.ToDouble(dt.Rows[i]["NET_AMNT"]),
pos = Convert.ToString(dt.Rows[i]["POS"]),
rchrg = "N",
inv_typ = "R",
itms = CustomerInvNoItem(BranchGst, CustomerGst, Convert.ToString(dt.Rows[i]["BILL_NO"]))
});
}
return CustomerItm;
}
public List<ItmDet> CustomerInvNoItem(string BranchGst, string CustomerGst,string InvNo)
{
List<ItmDet> CustomerInvoitem = new List<ItmDet>();
DataTable dt = GetData(string.Format("SELECT BILL_DATE,(SUBSTR(CUST_GSTIN,0,2))POS,(CGST_RATE+SGST_RATE+IGST_RATE)RATE,CGST,SGST,IGST,BILL_FREIGHT,NET_AMNT FROM GST_SUMMARY_VW WHERE BRANCH_GSTIN='{0}' AND CUST_GSTIN='{1}' AND BILL_NO='{2}' ORDER BY BILL_NO ", BranchGst, CustomerGst, InvNo));
for (int i = 0; i < dt.Rows.Count; i++)
{
CustomerInvoitem.Add(new ItmDet
{
txval = Convert.ToDouble(dt.Rows[i]["BILL_FREIGHT"]),
rt = Convert.ToInt32(dt.Rows[i]["RATE"]),
camt = Convert.ToDouble(dt.Rows[i]["CGST"]),
samt = Convert.ToDouble(dt.Rows[i]["SGST"]),
csamt = Convert.ToInt32(dt.Rows[i]["IGST"])
});
}
return CustomerInvoitem;
}
private DataTable GetData(string query)
{
OracleCommand cmd = new OracleCommand(query);
using (OracleConnection con = new OracleConnection(oper.ConnectionString))
{
using (OracleDataAdapter sda = new OracleDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
public class ItmDet
{
public double txval { get; set; }
public int rt { get; set; }
public double camt { get; set; }
public double samt { get; set; }
public int csamt { get; set; }
public double? iamt { get; set; }
}
public class Itm
{
public int num { get; set; }
public ItmDet itm_det { get; set; }
}
public class Inv
{
public string inum { get; set; }
public string idt { get; set; }
public double val { get; set; }
public string pos { get; set; }
public string rchrg { get; set; }
public string inv_typ { get; set; }
public List<Itm> itms { get; set; }
public string sply_ty { get; set; }
public int expt_amt { get; set; }
public int nil_amt { get; set; }
public int ngsup_amt { get; set; }
}
public class B2b
{
public string ctin { get; set; }
public List<Inv> inv { get; set; }
}
public class B2cs
{
public string sply_ty { get; set; }
public int rt { get; set; }
public string typ { get; set; }
public string pos { get; set; }
public double txval { get; set; }
public double camt { get; set; }
public double samt { get; set; }
public int csamt { get; set; }
}
public class Nil
{
public List<Inv> inv { get; set; }
}
public class Root
{
public string gstin { get; set; }
public string fp { get; set; }
public string version { get; set; }
public string hash { get; set; }
public List<B2b> b2b { get; set; }
public List<B2cs> b2cs { get; set; }
public Nil nil { get; set; }
}