Exemple #1
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"));
            }
        }
        public ActionResult Create(RevenueUpdateMasterVM vm)
        {
            ViewBag.Title = "Revenue Update - Create";
            int userId = Convert.ToInt32(Session["UserID"].ToString());

            ViewBag.employee = db.EmployeeMasters.ToList();

            ViewBag.PaymentType = db.tblPaymentModes.ToList();
            ViewBag.Currency    = db.CurrencyMasters.ToList();
            ViewBag.Consignment = db.InScanMasters.ToList();
            List <VoucherTypeVM> lsttype = new List <VoucherTypeVM>();

            //lsttype.Add(new VoucherTypeVM { TypeName = "All" });
            lsttype.Add(new VoucherTypeVM {
                TypeName = "Shipper"
            });
            lsttype.Add(new VoucherTypeVM {
                TypeName = "Consignee"
            });

            ViewBag.InvoiceTo = lsttype;
            int branchid          = Convert.ToInt32(Session["CurrentBranchID"].ToString());
            int fyearid           = Convert.ToInt32(Session["fyearid"].ToString());
            RevenueUpdateMaster v = new RevenueUpdateMaster();
            bool duplicatecost    = false;

            for (int i = 0; i < vm.DetailVM.Count; i++)
            {
                if (vm.DetailVM[i].IsDeleted != true)
                {
                    for (int j = i + 1; j < vm.DetailVM.Count; j++)
                    {
                        if (vm.DetailVM[i].RevenueCostMasterID == vm.DetailVM[j].RevenueCostMasterID && vm.DetailVM[j].IsDeleted != true)
                        {
                            duplicatecost = true;

                            TempData["ErrorMsg"]           = "Revenue Component should not be Duplicated!";
                            Session["CreateRevenueUpdate"] = vm;
                            ViewBag.Title = "Revenue Update - Modify";

                            return(View(vm));
                        }
                    }
                }
            }
            if (vm.ID == 0)
            {
                ViewBag.Title = "Revenue Update - Create";

                v.EntryDate         = vm.EntryDate;
                v.EmployeeID        = vm.EmployeeID;
                v.InScanID          = vm.InScanID;
                v.BranchID          = branchid;
                v.AcFinancialYearID = fyearid;
                v.CreatedBy         = userId;
                v.CreatedDate       = CommanFunctions.GetCurrentDateTime();
                v.ModifiedBy        = userId;
                v.ModifiedDate      = CommanFunctions.GetCurrentDateTime();
                db.RevenueUpdateMasters.Add(v);
                db.SaveChanges();
            }
            else
            {
                ViewBag.Title       = "Revenue Update - Modify";
                v                   = db.RevenueUpdateMasters.Find(vm.ID);
                v.EntryDate         = vm.EntryDate;
                v.EmployeeID        = vm.EmployeeID;
                v.InScanID          = vm.InScanID;
                v.BranchID          = branchid;
                v.AcFinancialYearID = fyearid;
                v.ModifiedBy        = userId;
                v.ModifiedDate      = CommanFunctions.GetCurrentDateTime();
                db.Entry(v).State   = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            for (int i = 0; i < vm.DetailVM.Count; i++)
            {
                if (vm.DetailVM[i].IsDeleted != true)
                {
                    if (vm.DetailVM[i].ID == 0)
                    {
                        RevenueUpdateDetail detail = new RevenueUpdateDetail();
                        detail.MasterID            = v.ID;
                        detail.RevenueCostMasterID = vm.DetailVM[i].RevenueCostMasterID;
                        detail.AcHeadCreditId      = vm.DetailVM[i].AcHeadCreditId;
                        detail.AcHeadDebitId       = vm.DetailVM[i].AcHeadDebitId;
                        detail.Amount        = vm.DetailVM[i].Amount;
                        detail.CurrencyId    = vm.DetailVM[i].CurrencyId;
                        detail.CustomerId    = vm.DetailVM[i].CustomerId;
                        detail.ExchangeRate  = vm.DetailVM[i].ExchangeRate;
                        detail.TaxPercent    = vm.DetailVM[i].TaxPercent;
                        detail.TaxAmount     = vm.DetailVM[i].TaxAmount;
                        detail.TotalCharge   = vm.DetailVM[i].TotalCharge;
                        detail.PaymentModeId = vm.DetailVM[i].PaymentModeId;
                        detail.InvoiceTo     = vm.DetailVM[i].InvoiceTo;

                        db.RevenueUpdateDetails.Add(detail);
                        db.SaveChanges();
                    }
                    else
                    {
                        RevenueUpdateDetail detail = db.RevenueUpdateDetails.Find(vm.DetailVM[i].ID);
                        if (detail != null)
                        {
                            detail.MasterID            = v.ID;
                            detail.RevenueCostMasterID = vm.DetailVM[i].RevenueCostMasterID;
                            detail.AcHeadCreditId      = vm.DetailVM[i].AcHeadCreditId;
                            detail.AcHeadDebitId       = vm.DetailVM[i].AcHeadDebitId;
                            detail.Amount        = vm.DetailVM[i].Amount;
                            detail.CurrencyId    = vm.DetailVM[i].CurrencyId;
                            detail.CustomerId    = vm.DetailVM[i].CustomerId;
                            detail.ExchangeRate  = vm.DetailVM[i].ExchangeRate;
                            detail.PaymentModeId = vm.DetailVM[i].PaymentModeId;
                            detail.InvoiceTo     = vm.DetailVM[i].InvoiceTo;

                            db.Entry(detail).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    if (vm.DetailVM[i].ID > 0)
                    {
                        RevenueUpdateDetail detail = db.RevenueUpdateDetails.Find(vm.DetailVM[i].ID);
                        db.RevenueUpdateDetails.Remove(detail);
                        db.SaveChanges();
                    }
                }
            }


            //update inscan revenue update status
            var inscan = db.InScanMasters.Find(vm.InScanID);

            inscan.Remarks         = vm.Remarks;
            inscan.RevenueUpdate   = true;
            db.Entry(inscan).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            PickupRequestDAO _dao = new PickupRequestDAO();

            _dao.GenerateRevenueUpdatePosting(v.ID);
            Session["CreateRevenueUpdate"] = null;
            TempData["SuccessMsg"]         = "Revenue of Consignment Updated Successfully!";
            return(RedirectToAction("Index"));
            //ViewBag.Title = "Revenue Update - Create";
            //ViewBag.employee = db.EmployeeMasters.ToList();
            //List<VoucherTypeVM> lsttype = new List<VoucherTypeVM>();
            //lsttype.Add(new VoucherTypeVM { TypeName = "Pickup Cash" });
            //lsttype.Add(new VoucherTypeVM { TypeName = "Customer" });
            //lsttype.Add(new VoucherTypeVM { TypeName = "Shipper" });

            //ViewBag.PaymentType = lsttype;
            //ViewBag.Currency = db.CurrencyMasters.ToList();
            //return View();
        }