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")); } }
public ActionResult Create(int id = 0) { int userId = Convert.ToInt32(Session["UserID"].ToString()); ViewBag.Title = "Revenue Update - Create"; 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; RevenueUpdateMasterVM vm = new RevenueUpdateMasterVM(); if (id == 0) { vm.ID = 0; vm.DetailVM = new List <RevenueUpdateDetailVM>(); vm.EntryDate = DateTime.Now; var acc = db.AcHeads.Where(cc => cc.AcHead1 == "Un-invoiced Consignment Note").FirstOrDefault(); if (acc != null) { vm.DebitAccountName = acc.AcHead1; vm.DebitAccountId = acc.AcHeadID; } var pacc = db.AcHeads.Where(cc => cc.AcHead1 == "Pickup Cash Control Account").FirstOrDefault(); if (pacc != null) { vm.DebitCashAccountName = pacc.AcHead1; vm.DebitCashAccountId = pacc.AcHeadID; } var customer = db.CustomerMasters.Where(cc => cc.CustomerType == "COD").FirstOrDefault(); if (customer != null) { vm.DebitCODCustomerId = customer.CustomerID; vm.DebitCODCustomer = customer.CustomerName; } var codacc = db.AcHeads.Where(cc => cc.AcHead1 == "Cod Control A/c.").FirstOrDefault(); if (codacc != null) { vm.DebitCODAccountName = codacc.AcHead1; vm.DebitCODAccountId = codacc.AcHeadID; } vm.CurrencyId = Convert.ToInt32(Session["CurrencyId"].ToString()); var emp = db.EmployeeMasters.Where(cc => cc.UserID == userId).FirstOrDefault(); if (emp != null) { vm.EmployeeID = emp.EmployeeID; } ViewBag.EditMode = "false"; } else { ViewBag.Title = "Revenue Update - Modify"; RevenueUpdateMaster v = db.RevenueUpdateMasters.Find(id); vm.ID = v.ID; vm.EntryDate = v.EntryDate; vm.EmployeeID = v.EmployeeID; vm.InScanID = v.InScanID; vm.BranchID = v.BranchID; vm.CurrencyId = Convert.ToInt32(Session["CurrencyId"].ToString()); vm.AcFinancialYearID = v.AcFinancialYearID; var acc = db.AcHeads.Where(cc => cc.AcHead1 == "Un-invoiced Consignment Note").FirstOrDefault(); if (acc != null) { vm.DebitAccountName = acc.AcHead1; vm.DebitAccountId = acc.AcHeadID; } var pacc = db.AcHeads.Where(cc => cc.AcHead1 == "Pickup Cash Control Account").FirstOrDefault(); if (pacc != null) { vm.DebitCashAccountName = pacc.AcHead1; vm.DebitCashAccountId = pacc.AcHeadID; } var codacc = db.AcHeads.Where(cc => cc.AcHead1 == "Cod Control A/c.").FirstOrDefault(); if (codacc != null) { vm.DebitCODAccountName = codacc.AcHead1; vm.DebitCODAccountId = codacc.AcHeadID; } vm.ConsignmentNo = db.InScanMasters.Find(v.InScanID).ConsignmentNo; ViewBag.EditMode = "true"; } //vm.PickupCashHeadId = db.AcHeads.Where(cc => cc.AcHead1 == "Main Cash Account").FirstOrDefault().AcHead1; return(View(vm)); }
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(); }