コード例 #1
0
        public ActionResult Edit(CustomerInvoiceVM model)
        {
            var userid = Convert.ToInt32(Session["UserID"]);

            if (model.CustomerInvoiceID > 0)
            {
                CustomerInvoice _custinvoice = new CustomerInvoice();
                _custinvoice                 = db.CustomerInvoices.Find(model.CustomerInvoiceID);
                _custinvoice.InvoiceDate     = model.InvoiceDate;
                _custinvoice.TaxPercent      = model.TaxPercent;
                _custinvoice.InvoiceTotal    = model.InvoiceTotal;
                _custinvoice.Remarks         = model.Remarks;
                _custinvoice.ModifiedBy      = userid;
                _custinvoice.ModifiedDate    = CommanFunctions.GetCurrentDateTime();
                db.Entry(_custinvoice).State = EntityState.Modified;
                db.SaveChanges();

                List <CustomerInvoiceDetailVM> e_Details = model.CustomerInvoiceDetailsVM; //  Session["InvoiceListing"] as List<CustomerInvoiceDetailVM>;

                model.CustomerInvoiceDetailsVM = e_Details;

                if (model.CustomerInvoiceDetailsVM != null)
                {
                    foreach (var e_details in model.CustomerInvoiceDetailsVM)
                    {
                        if (e_details.CustomerInvoiceDetailID == 0 && e_details.AWBChecked)
                        {
                            CustomerInvoiceDetail _detail = new CustomerInvoiceDetail();
                            _detail.CustomerInvoiceDetailID = db.CustomerInvoiceDetails.Select(x => x.CustomerInvoiceDetailID).DefaultIfEmpty(0).Max() + 1;
                            _detail.CustomerInvoiceID       = _custinvoice.CustomerInvoiceID;
                            _detail.ConsignmentNo           = e_details.ConsignmentNo;
                            _detail.InScanID = e_details.InScanID;
                            //_detail.StatusPaymentMode = e_details.StatusPaymentMode;
                            _detail.FreightCharge = e_details.FreightCharge;
                            _detail.CustomsCharge = e_details.CustomsCharge;
                            _detail.DocCharge     = e_details.DocCharge;
                            _detail.OtherCharge   = e_details.OtherCharge;
                            db.CustomerInvoiceDetails.Add(_detail);
                            db.SaveChanges();

                            //inscan invoice modified
                            InScanMaster _inscan = db.InScanMasters.Find(e_details.InScanID);
                            _inscan.InvoiceID       = _custinvoice.CustomerInvoiceID;
                            db.Entry(_inscan).State = EntityState.Modified;
                            db.SaveChanges();

                            RevenueUpdateMaster _revenueupdate = db.RevenueUpdateMasters.Where(cc => cc.InScanID == e_details.InScanID).FirstOrDefault();
                            _revenueupdate.InvoiceId       = _custinvoice.CustomerInvoiceID;
                            db.Entry(_revenueupdate).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        else if (e_details.CustomerInvoiceDetailID == 0 && e_details.AWBChecked == false)
                        {
                            //CustomerInvoiceDetail _detail = new CustomerInvoiceDetail();
                            //_detail = db.CustomerInvoiceDetails.Find(e_details.CustomerInvoiceID);
                            //_detail.CourierCharge = e_details.CourierCharge;
                            //_detail.CustomCharge = e_details.CustomCharge;
                            //_detail.OtherCharge = e_details.OtherCharge;
                            //db.CustomerInvoiceDetails.Add(_detail);
                            //db.SaveChanges();

                            ////inscan invoice modified
                            //InScanMaster _inscan = db.InScanMasters.Find(e_details.InscanID);
                            //_inscan.InvoiceID = _custinvoice.CustomerInvoiceID;
                            //db.Entry(_inscan).State = System.Data.EntityState.Modified;
                            //db.SaveChanges();
                        }
                        else if (e_details.CustomerInvoiceDetailID > 0 && e_details.AWBChecked == false)
                        {
                            CustomerInvoiceDetail _detail = new CustomerInvoiceDetail();
                            _detail = db.CustomerInvoiceDetails.Find(e_details.CustomerInvoiceDetailID);
                            db.CustomerInvoiceDetails.Remove(_detail);
                            db.SaveChanges();
                            ////inscan invoice modified
                            InScanMaster _inscan = db.InScanMasters.Find(e_details.InScanID);
                            _inscan.InvoiceID       = null;
                            db.Entry(_inscan).State = EntityState.Modified;
                            db.SaveChanges();

                            RevenueUpdateMaster        _revenueupdate       = db.RevenueUpdateMasters.Where(cc => cc.InScanID == e_details.InScanID).FirstOrDefault();
                            List <RevenueUpdateDetail> revenueUpdateDetails = db.RevenueUpdateDetails.Where(cc => cc.MasterID == _revenueupdate.ID).ToList();
                            foreach (RevenueUpdateDetail item in revenueUpdateDetails)
                            {
                                item.InvoiceId       = null;
                                db.Entry(item).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                            //_revenueupdate.InvoiceId = null;
                            //db.Entry(_revenueupdate).State = EntityState.Modified;
                            //db.SaveChanges();
                        }
                    }
                }
                //Accounts Posting
                PickupRequestDAO _dao = new PickupRequestDAO();
                _dao.GenerateInvoicePosting(_custinvoice.CustomerInvoiceID);

                TempData["SuccessMsg"] = "You have successfully Updated the Customer Invoice";
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
コード例 #2
0
        public ActionResult Create(CustomerInvoiceVM model)
        {
            int branchid  = Convert.ToInt32(Session["CurrentBranchID"].ToString());
            int companyId = Convert.ToInt32(Session["CurrentCompanyID"].ToString());
            var userid    = Convert.ToInt32(Session["UserID"]);
            int yearid    = Convert.ToInt32(Session["fyearid"].ToString());

            if (model.CustomerInvoiceID == 0)
            {
                CustomerInvoice _custinvoice = new CustomerInvoice();
                var             max          = db.CustomerInvoices.Select(x => x.CustomerInvoiceID).DefaultIfEmpty(0).Max() + 1;
                _custinvoice.CustomerInvoiceID = max;
                _custinvoice.CustomerInvoiceNo = model.CustomerInvoiceNo;
                _custinvoice.InvoiceDate       = model.InvoiceDate;
                _custinvoice.CustomerID        = model.CustomerID;
                //_custinvoice.CustomerInvoiceTax = model.CustomerInvoiceTax;
                //_custinvoice.ChargeableWT = model.ChargeableWT;
                //_custinvoice.AdminPer = model.AdminPer;
                //_custinvoice.AdminAmt = model.AdminAmt;
                //_custinvoice.FuelPer = model.FuelPer;
                //_custinvoice.FuelAmt = model.FuelAmt;
                //_custinvoice.OtherCharge = model.OtherCharge;
                _custinvoice.InvoiceTotal      = model.InvoiceTotal;
                _custinvoice.AcFinancialYearID = yearid;
                _custinvoice.AcCompanyID       = companyId;
                _custinvoice.BranchID          = branchid;
                _custinvoice.Remarks           = model.Remarks;
                _custinvoice.CreatedBy         = userid;
                _custinvoice.CreatedDate       = CommanFunctions.GetCurrentDateTime();
                _custinvoice.ModifiedBy        = userid;
                _custinvoice.ModifiedDate      = CommanFunctions.GetCurrentDateTime();
                db.CustomerInvoices.Add(_custinvoice);
                db.SaveChanges();

                List <CustomerInvoiceDetailVM> e_Details = model.CustomerInvoiceDetailsVM; //  Session["InvoiceListing"] as List<CustomerInvoiceDetailVM>;

                model.CustomerInvoiceDetailsVM = e_Details;

                if (model.CustomerInvoiceDetailsVM != null)
                {
                    foreach (var e_details in model.CustomerInvoiceDetailsVM)
                    {
                        if (e_details.CustomerInvoiceDetailID == 0 && e_details.AWBChecked)
                        {
                            CustomerInvoiceDetail _detail = new CustomerInvoiceDetail();
                            _detail.CustomerInvoiceDetailID = db.CustomerInvoiceDetails.Select(x => x.CustomerInvoiceDetailID).DefaultIfEmpty(0).Max() + 1;
                            _detail.CustomerInvoiceID       = _custinvoice.CustomerInvoiceID;
                            _detail.ConsignmentNo           = e_details.ConsignmentNo;
                            _detail.InScanID = e_details.InScanID;
                            //_detail.StatusPaymentMode = e_details.StatusPaymentMode;
                            _detail.FreightCharge = e_details.FreightCharge;
                            _detail.CustomsCharge = e_details.CustomsCharge;
                            _detail.OtherCharge   = e_details.OtherCharge;
                            _detail.DocCharge     = e_details.DocCharge;
                            _detail.NetValue      = e_details.TotalCharges;
                            db.CustomerInvoiceDetails.Add(_detail);
                            db.SaveChanges();

                            //inscan invoice modified
                            InScanMaster _inscan = db.InScanMasters.Find(e_details.InScanID);
                            _inscan.InvoiceID       = _custinvoice.CustomerInvoiceID;
                            db.Entry(_inscan).State = EntityState.Modified;
                            db.SaveChanges();

                            RevenueUpdateMaster _revenueupdate = db.RevenueUpdateMasters.Where(cc => cc.InScanID == e_details.InScanID).FirstOrDefault();
                            var revenuedetails = db.RevenueUpdateDetails.Where(cc => cc.MasterID == _revenueupdate.ID && cc.InvoiceId == null).ToList();
                            foreach (var revdetail in revenuedetails)
                            {
                                revdetail.InvoiceId       = _custinvoice.CustomerInvoiceID;
                                db.Entry(revdetail).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                            _revenueupdate.InvoiceId       = _custinvoice.CustomerInvoiceID;
                            db.Entry(_revenueupdate).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }

                //Accounts Posting
                PickupRequestDAO _dao = new PickupRequestDAO();
                _dao.GenerateInvoicePosting(_custinvoice.CustomerInvoiceID);

                TempData["SuccessMsg"] = "You have successfully Saved the Customer Invoice";
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }