public async Task <IActionResult> Edit(int id, [Bind("cid,cdate,person,particular,totalamount,name,mobilenumber,address")] creditnote creditnote)
        {
            if (id != creditnote.cid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    creditnote.cdate = DateTime.UtcNow;
                    _context.Update(creditnote);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!creditnoteExists(creditnote.cid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(View());
            }
            return(View(creditnote));
        }
        public void print(creditnote creditnote)
        {
            Creditnote = creditnote;
            if (!isprintersetup)
            {
                loadPrintsetting();
            }
            if (!isprintersetup)
            {
                return;
            }

            printDocumentScroll.PrinterSettings     = PrinterSettings;
            printDocumentScroll.DefaultPageSettings = new PageSettings()
            {
                PaperSize = new PaperSize("scroll", 280, 83149000)
            };
            printDocumentScroll.Print();
        }
        public async Task <IActionResult> Create([Bind("cid,cdate,person,particular,totalamount,name,mobilenumber,Paid,Balance,address,paymenttype,refno")] creditnote 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.Add(creditnote);
                await _context.SaveChangesAsync();

                var cno = creditnote.cid;
                if (creditnote.person == "customer")
                {
                    var checkcustomer = _context.customerdetails.Where(i => i.Mobilenumber == creditnote.mobilenumber).FirstOrDefault();
                    if (checkcustomer == null)
                    {
                        CustomerDetails cd = new CustomerDetails();
                        cd.Mobilenumber = creditnote.mobilenumber;
                        cd.Customername = creditnote.name;
                        cd.Address      = creditnote.address;
                        cd.Branch       = Branch;
                        cd.Entrydate    = DateTime.UtcNow;
                        cd.Entryby      = Name;
                        _context.customerdetails.Add(cd);
                        _context.SaveChanges();
                    }
                    Creditpaymenthistry cph1 = new Creditpaymenthistry();
                    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.refno   = creditnote.refno;
                    cph1.Branch  = Branch;
                    cph1.total   = creditnote.totalamount;
                    cph1.Balance = creditnote.Balance;
                    cph1.billid  = cno;
                    _context.creditpaymenthistries.Add(cph1);


                    _context.SaveChanges();
                }

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

                    cph1.refno  = creditnote.refno;
                    cph1.Branch = Branch;
                    cph1.total  = creditnote.totalamount;
                    cph1.billid = cno;
                    _context.creditpaymenthistries.Add(cph1);
                    _context.SaveChanges();
                }

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