public ActionResult <string> StorePDF([FromForm] PDFData formData) { string Base64 = formData.Base64; byte[] byteArray = Convert.FromBase64String(Base64); //Calculating Bill profit after dedcution of Discount % int Accurateprofit = formData.Billprofit - formData.Deduction; BillsDatasTE Billdata = new BillsDatasTE() { Billnumber = formData.Billnumber, Billamount = formData.Billamount, Deduction = formData.Deduction, Payableamount = formData.Payableamount, Billprofit = Accurateprofit, Billbytearray = byteArray, Billdate = DateTime.Now, Ispaid = false, Customerid = formData.Customerid }; _context.Add(Billdata); _context.SaveChanges(); BillsPendingTE billPending = new BillsPendingTE() { Pendingamount = formData.Payableamount, Billnumber = formData.Billnumber, Iscompleted = false, Customerid = formData.Customerid, }; _context.Add(billPending); _context.SaveChanges(); int maxID = _context.billscollections.Max(x => x.Id); byte[] byteArray2 = _context.billscollections.Single(x => x.Id == maxID).Billbytearray; string Base642 = Convert.ToBase64String(byteArray); return(Ok(Base642)); }
public ActionResult <CustwithOrder> GetBillData([FromForm] BillsPendingTE billsPending) { CustwithOrder CustWithBillAmount = new CustwithOrder(); var BillData = _context.billspending.SingleOrDefault(x => x.Billnumber == billsPending.Billnumber); if (BillData != null) { var CustData = _context.customers.SingleOrDefault(x => x.CustomerId == BillData.Customerid.ToString()); CustWithBillAmount.customer = CustData; CustWithBillAmount.Totalcost = BillData.Pendingamount; } else { CustWithBillAmount.customer = null; CustWithBillAmount.Totalcost = 0; } return(Ok(CustWithBillAmount)); }
public ActionResult <string> StorePayment([FromForm] CustomerTxHistoryTE bills) { string result = ""; BillsPendingTE BillData = _context.billspending .Single(x => x.Billnumber == bills.Billnumber && x.Customerid == bills.Customerid); if (BillData != null) { if (bills.Paymentmode == "ACCOUNT") { var CustAccountData = _context.customeraccounts.Single(x => Convert.ToInt32(x.Customerid) == bills.Customerid); if (CustAccountData != null) { CustAccountData.Availableamount -= bills.Paidamount; _context.Entry(CustAccountData).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); } else { result = "Customer Account Data Not Found - Server Side"; } } else if (bills.Paymentmode == "CASH") { bool isDataAvailable = _context.cashposition.Any(); if (isDataAvailable) { int Id = _context.cashposition.Max(x => x.Id); var CashPositionData = _context.cashposition.Single(x => x.Id == Id); CashPositionData.Globalcash += bills.Paidamount; _context.Entry(CashPositionData).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); } else { CashPositionTE cashPosition = new CashPositionTE() { Globalcash = bills.Paidamount }; _context.Add(cashPosition); _context.SaveChanges(); } } BillData.Pendingamount = BillData.Pendingamount - bills.Paidamount; if (BillData.Pendingamount == 0) { BillData.Iscompleted = true; } _context.Entry(BillData).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); CustomerTxHistoryTE customer = new CustomerTxHistoryTE() { Billnumber = bills.Billnumber, Paidamount = bills.Paidamount, Paiddate = DateTime.Now.Date, Paymentmode = bills.Paymentmode, Customerid = bills.Customerid }; _context.Add(customer); _context.SaveChanges(); result = "Done!"; } else { result = "Please check your Bill Number!"; } return(Ok(result)); }