Exemplo n.º 1
0
        public IActionResult UpdateCreditnotepayment(Emipaymenthistry cph)
        {
            ViewBag.data   = HttpContext.Session.GetObject(SD.Sessionname);
            ViewBag.branch = HttpContext.Session.GetObject(SD.Statusbranch);
            var Name   = ViewBag.data;
            var Branch = ViewBag.branch;

            if (cph.Paiddate == null)
            {
                cph.Paiddate = DateTime.UtcNow;
            }
            cph.Recivedby = Name;

            cph.Branch = Branch;


            var     billamount = _context.eminotes.Where(i => i.cid == cph.billid).FirstOrDefault();
            decimal paid       = cph.Payment;
            decimal cal        = cph.Balance;

            cph.total   = billamount.totalamount;
            cph.Payment = cph.Payment;
            var billhis = _context.emipaymenthistries.Add(cph);

            billamount.balance = cal;
            billamount.paid    = billamount.paid + cph.Payment;
            _context.eminotes.Update(billamount);

            _context.SaveChanges();



            return(Json(new { success = true, message = "Save successfull." }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("cid,cdate,balance,paid,person,particular,totalamount,name,mobilenumber,address,paymenttype,refno")] Eminote creditnote)
        {
            if (ModelState.IsValid)
            {
                ViewBag.data = HttpContext.Session.GetObject(SD.Sessionname);
                var Name = ViewBag.data;
                ViewBag.branch = HttpContext.Session.GetObject(SD.Statusbranch);
                string Branch = ViewBag.branch;
                creditnote.addby  = Name;
                creditnote.branch = Branch;
                if (creditnote.cdate == null)
                {
                    creditnote.cdate = DateTime.UtcNow;
                }

                _context.eminotes.Add(creditnote);
                await _context.SaveChangesAsync();

                var cno = creditnote.cid;
                if (creditnote.person == "customer")
                {
                    var checkcustomer = _context.creditcustomers.Where(i => i.Mobilenumber == creditnote.mobilenumber).FirstOrDefault();
                    if (checkcustomer == null)
                    {
                        CreditCustomerDetails cd = new CreditCustomerDetails();
                        cd.Mobilenumber = creditnote.mobilenumber;
                        cd.Customername = creditnote.name;
                        cd.Address      = creditnote.address;
                        cd.Branch       = Branch;
                        cd.Entrydate    = DateTime.UtcNow;
                        cd.Entryby      = Name;
                        _context.creditcustomers.Add(cd);
                        _context.SaveChanges();
                    }
                    Emipaymenthistry cph1 = new Emipaymenthistry();
                    cph1.Mobile       = creditnote.mobilenumber;
                    cph1.Customername = creditnote.name;
                    cph1.Address      = creditnote.address;
                    cph1.paymenttype  = creditnote.paymenttype;
                    cph1.Payment      = creditnote.paid;
                    cph1.Recivedby    = Name;
                    if (creditnote.cdate == null)
                    {
                        cph1.Paiddate = DateTime.UtcNow;
                    }
                    cph1.Paiddate = creditnote.cdate;
                    cph1.Balance  = creditnote.balance;

                    cph1.refno  = creditnote.refno;
                    cph1.Branch = Branch;
                    cph1.total  = creditnote.totalamount;

                    cph1.billid = cno;
                    _context.emipaymenthistries.Add(cph1);


                    _context.SaveChanges();
                }

                if (creditnote.person == "vendor")
                {
                    var checkvendor = _context.creditvendors.Where(i => i.Mobilenumber == creditnote.mobilenumber).FirstOrDefault();
                    if (checkvendor == null)
                    {
                        CreditVendor cd = new CreditVendor();
                        cd.Mobilenumber = creditnote.mobilenumber;
                        cd.Name         = creditnote.name;
                        cd.Address      = creditnote.address;
                        cd.Branch       = Branch;
                        cd.Entrydate    = DateTime.UtcNow;
                        cd.Entryby      = Name;
                        _context.creditvendors.Add(cd);
                        _context.SaveChanges();
                    }
                    Emipaymenthistry cph1 = new Emipaymenthistry();
                    cph1.Mobile       = creditnote.mobilenumber;
                    cph1.Customername = creditnote.name;
                    cph1.Address      = creditnote.address;
                    cph1.paymenttype  = creditnote.paymenttype;
                    cph1.Payment      = creditnote.paid;
                    cph1.Recivedby    = Name;
                    if (creditnote.cdate == null)
                    {
                        cph1.Paiddate = DateTime.UtcNow;
                    }
                    cph1.Paiddate = creditnote.cdate;
                    cph1.Balance  = creditnote.balance;

                    cph1.refno  = creditnote.refno;
                    cph1.Branch = Branch;
                    cph1.total  = creditnote.totalamount;

                    cph1.billid = cno;
                    _context.emipaymenthistries.Add(cph1);

                    _context.SaveChanges();
                }

                if (creditnote.person == "vendor")
                {
                    return(RedirectToAction(nameof(VendorIndex)));
                }
                else
                {
                    return(RedirectToAction(nameof(CustomerIndex)));
                }
            }
            return(View());
        }