public JsonResult GetAmount(string id) { Getamtclass ob = new Getamtclass(); int jobid = (from j in db.JobGenerations where j.JobCode == id select j.JobID).FirstOrDefault(); int invid = (from c in db.JInvoices where c.JobID == jobid select c.InvoiceID).FirstOrDefault(); decimal invamt = (from c in db.JInvoices where c.InvoiceID == invid select c.SalesHome).FirstOrDefault().Value; decimal recamt = (from r in db.RecPayDetails where r.InvoiceID == invid select r.Amount).FirstOrDefault().Value; ob.invoiceamt = invamt; ob.recamt = recamt; return(Json(ob, JsonRequestBehavior.AllowGet)); }
public JsonResult GetAmountByinvono(int invno, bool IsTrading) { Getamtclass ob = new Getamtclass(); ob.invoiceamt = 0; ob.recamt = 0; if (IsTrading == false) { //int jobid = (from j in db.JobGenerations where j.JobCode == invno select j.JobID).FirstOrDefault(); //int invid = (from c in db.JInvoices where c.JobID == jobid select c.InvoiceID).FirstOrDefault(); //decimal invamt = (from c in db.JInvoices where c.InvoiceID == invid select c.SalesHome).FirstOrDefault().Value; //decimal recamt = (from r in db.RecPayDetails where r.InvoiceID == invid select r.Amount).FirstOrDefault().Value; //ob.invoiceamt = invamt; //ob.recamt = recamt; } else { var sinvoice = (from d in db.CustomerInvoices where d.CustomerInvoiceID == invno select d).FirstOrDefault(); var sinDetails = (from c in db.CustomerInvoiceDetails where c.CustomerInvoiceID == sinvoice.CustomerInvoiceID select c).ToList(); List <int?> pinvoiceids = sinDetails.Select(d => (int?)d.CustomerInvoiceDetailID).ToList(); ob.invoiceamt = Convert.ToDecimal(sinDetails.Sum(d => d.NetValue)); var recpay = (from x in db.RecPayDetails where pinvoiceids.Contains(x.InvoiceID) select x).ToList(); if (recpay.Count > 0) { ob.recamt = Convert.ToDecimal(Math.Abs(recpay.Sum(s => s.Amount.Value))); } } return(Json(ob, JsonRequestBehavior.AllowGet)); }