// GET: /PurchaseOrderSettingMaster/Create public ActionResult Create(int id)//DocTypeId { List <string> UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"]; if (!UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } var DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; var SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; //PrepareViewBag(); var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(id, DivisionId, SiteId); if (settings == null) { PurchaseOrderSettingsViewModel vm = new PurchaseOrderSettingsViewModel(); vm.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; vm.SiteId = SiteId; vm.DivisionId = DivisionId; vm.DocTypeId = id; return(View("Create", vm)); } else { PurchaseOrderSettingsViewModel temp = AutoMapper.Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); temp.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; return(View("Create", temp)); } }
// GET: /PurchaseOrderCancelHeaderMaster/Create public ActionResult Create(int id)//DocumentTypeId { PrepareViewBag(id); PurchaseOrderCancelHeaderViewModel vm = new PurchaseOrderCancelHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; vm.CreatedDate = DateTime.Now; //Getting Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(id, vm.DivisionId, vm.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("CreatePurchaseOrderCancel", "PurchaseOrderSetting", new { id = id }).Warning("Please create Purchase Order Cancel settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } vm.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); vm.DocDate = DateTime.Now; vm.DocTypeId = id; vm.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".PurchaseOrderCancelHeaders", vm.DocTypeId, vm.DocDate, vm.DivisionId, vm.SiteId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
private void NotifyUser(int Id, ActivityTypeContants ActivityType) { PurchaseOrderCancelHeader Header = new PurchaseOrderCancelHeaderService(_unitOfWork).Find(Id); PurchaseOrderSetting PurchaseOrderCancelSettings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); DocEmailContent DocEmailContentSettings = new DocEmailContentService(_unitOfWork).GetDocEmailContentForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId, ActivityType); DocNotificationContent DocNotificationContentSettings = new DocNotificationContentService(_unitOfWork).GetDocNotificationContentForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId, ActivityType); DocSmsContent DocSmsContentSettings = new DocSmsContentService(_unitOfWork).GetDocSmsContentForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId, ActivityType); new NotifyUserController(_unitOfWork).SendEmailMessage(Id, ActivityType, DocEmailContentSettings, PurchaseOrderCancelSettings.SqlProcDocumentPrint); new NotifyUserController(_unitOfWork).SendNotificationMessage(Id, ActivityType, DocNotificationContentSettings, User.Identity.Name); new NotifyUserController(_unitOfWork).SendSmsMessage(Id, ActivityType, DocSmsContentSettings); }
public ActionResult _Detail(int id) { PurchaseOrderCancelLineViewModel temp = _PurchaseOrderCancelLineService.GetPurchaseOrderCancelLine(id); PurchaseOrderCancelHeader H = new PurchaseOrderCancelHeaderService(_unitOfWork).Find(temp.PurchaseOrderCancelHeaderId); //Getting Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId); temp.PurchOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); if (temp == null) { return(HttpNotFound()); } return(PartialView("_Create", temp)); }
public ActionResult _Create(int Id, int sid) //Id ==>Sale Order Header Id { PurchaseOrderCancelHeader H = new PurchaseOrderCancelHeaderService(_unitOfWork).Find(Id); PurchaseOrderCancelLineViewModel svm = new PurchaseOrderCancelLineViewModel(); //Getting Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId); svm.PurchOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); svm.PurchaseOrderCancelHeaderId = Id; svm.SupplierId = sid; ViewBag.LineMode = "Create"; return(PartialView("_Create", svm)); }
public ActionResult _Create(int Id, int?sid) //Id ==>Sale Order Header Id { PurchaseOrderAmendmentHeader header = new PurchaseOrderAmendmentHeaderService(db).Find(Id); PurchaseOrderRateAmendmentLineViewModel svm = new PurchaseOrderRateAmendmentLineViewModel(); //Getting Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(header.DocTypeId, header.DivisionId, header.SiteId); svm.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); svm.DocTypeId = header.DocTypeId; svm.DivisionId = header.DivisionId; svm.SiteId = header.SiteId; ViewBag.LineMode = "Create"; svm.PurchaseOrderAmendmentHeaderId = Id; return(PartialView("_Create", svm)); }
public ActionResult Create(int id)//DocumentTypeId { PrepareViewBag(id); PurchaseOrderAmendmentHeaderViewModel vm = new PurchaseOrderAmendmentHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; //Getting Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(id, vm.DivisionId, vm.SiteId); vm.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); vm.DocTypeId = id; vm.DocDate = DateTime.Now; vm.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".PurchaseOrderAmendmentHeaders", vm.DocTypeId, vm.DocDate, vm.DivisionId, vm.SiteId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
private ActionResult _Delete(int id) { var line = _PurchaseOrderCancelLineService.GetPurchaseOrderCancelLine(id); if (line == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocumentLine(new DocumentUniqueId { LockReason = line.LockReason }, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXCL"] += ExceptionMsg; } #endregion if ((TimePlanValidation || Continue)) { ViewBag.LineMode = "Delete"; } PurchaseOrderCancelHeader H = new PurchaseOrderCancelHeaderService(_unitOfWork).Find(line.PurchaseOrderCancelHeaderId); //Getting Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId); line.PurchOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); return(PartialView("_Create", line)); }
private ActionResult _Delete(int id) { PurchaseOrderRateAmendmentLineViewModel temp = _PurchaseOrderRateAmendmentLineService.GetPurchaseOrderRateAmendmentLine(id); if (temp == null) { return(HttpNotFound()); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocumentLine(new DocumentUniqueId { LockReason = temp.LockReason }, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXCL"] += ExceptionMsg; } #endregion if ((TimePlanValidation || Continue)) { ViewBag.LineMode = "Delete"; } PurchaseOrderAmendmentHeader header = new PurchaseOrderAmendmentHeaderService(db).Find(temp.PurchaseOrderAmendmentHeaderId); //Getting Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(header.DocTypeId, header.DivisionId, header.SiteId); temp.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); return(PartialView("_Create", temp)); }
public ActionResult Report(int id) { DocumentType Dt = new DocumentType(); Dt = new DocumentTypeService(_unitOfWork).Find(id); PurchaseOrderSetting SEttings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(Dt.DocumentTypeId, (int)System.Web.HttpContext.Current.Session["DivisionId"], (int)System.Web.HttpContext.Current.Session["SiteId"]); Dictionary <int, string> DefaultValue = new Dictionary <int, string>(); if (!Dt.ReportMenuId.HasValue) { throw new Exception("Report Menu not configured in document types"); } Model.Models.Menu menu = new MenuService(_unitOfWork).Find(Dt.ReportMenuId ?? 0); if (menu != null) { ReportHeader header = new ReportHeaderService(_unitOfWork).GetReportHeaderByName(menu.MenuName); ReportLine Line = new ReportLineService(_unitOfWork).GetReportLineByName("DocumentType", header.ReportHeaderId); if (Line != null) { DefaultValue.Add(Line.ReportLineId, id.ToString()); } ReportLine Site = new ReportLineService(_unitOfWork).GetReportLineByName("Site", header.ReportHeaderId); if (Site != null) { DefaultValue.Add(Site.ReportLineId, ((int)System.Web.HttpContext.Current.Session["SiteId"]).ToString()); } ReportLine Division = new ReportLineService(_unitOfWork).GetReportLineByName("Division", header.ReportHeaderId); if (Division != null) { DefaultValue.Add(Division.ReportLineId, ((int)System.Web.HttpContext.Current.Session["DivisionId"]).ToString()); } } TempData["ReportLayoutDefaultValues"] = DefaultValue; return(Redirect((string)System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/Report_ReportPrint/ReportPrint/?MenuId=" + Dt.ReportMenuId)); }
public ActionResult Detail(int id, string IndexType, string transactionType) { ViewBag.transactionType = transactionType; ViewBag.IndexStatus = IndexType; PurchaseOrderCancelHeader pt = _PurchaseOrderCancelHeaderService.Find(id); PurchaseOrderCancelHeaderViewModel temp = AutoMapper.Mapper.Map <PurchaseOrderCancelHeader, PurchaseOrderCancelHeaderViewModel>(pt); //Job Order Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("CreatePurchaseOrderCancel", "PurchaseOrderSetting", new { id = pt.DocTypeId }).Warning("Please create Purchase Order Cancel settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } temp.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); PrepareViewBag(pt.DocTypeId); if (pt == null) { return(HttpNotFound()); } if (String.IsNullOrEmpty(transactionType) || transactionType == "detail") { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.PurchaseOrderCancelHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); } return(View("Create", temp)); }
public ActionResult RateAmendtmentWizard(int id)//DocumentTypeId { PrepareViewBag(id); PurchaseOrderAmendmentHeaderViewModel vm = new PurchaseOrderAmendmentHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; //Getting Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(id, vm.DivisionId, vm.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("CreatePurchaseOrderAmendment", "PurchaseOrderSettings", new { id = id }).Warning("Please create Purchase amendment settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } return(View()); }
public ActionResult OrderCancelWizard(int id)//DocumentTypeId { PrepareViewBag(id); PurchaseOrderCancelHeaderViewModel vm = new PurchaseOrderCancelHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; ViewBag.ReasonList = new ReasonService(_unitOfWork).GetReasonList(TransactionDocCategoryConstants.PurchaseOrderCancel).ToList(); //Getting Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(id, vm.DivisionId, vm.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("CreatePurchaseOrderCancel", "PurchaseOrderSettings", new { id = id }).Warning("Please create Purchase order cancel settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } return(View()); }
public ActionResult Detail(int id, string IndexType, string transactionType) { //var UManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db)); //var UserRoles = UManager.GetRoles(User.Identity.GetUserId()); ViewBag.transactionType = transactionType; ViewBag.IndexStatus = IndexType; PurchaseOrderAmendmentHeader pt = _PurchaseOrderAmendmentHeaderService.Find(id); PurchaseOrderAmendmentHeaderViewModel temp = AutoMapper.Mapper.Map <PurchaseOrderAmendmentHeader, PurchaseOrderAmendmentHeaderViewModel>(pt); //Getting Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId); temp.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); PrepareViewBag(pt.DocTypeId); if (pt == null) { return(HttpNotFound()); } if (String.IsNullOrEmpty(transactionType) || transactionType == "detail") { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.PurchaseOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); } return(View("Create", temp)); }
public ActionResult Post(PurchaseOrderAmendmentHeaderViewModel vm) { bool BeforeSave = true; int Serial = 1; Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); PurchaseOrderAmendmentHeader pt = AutoMapper.Mapper.Map <PurchaseOrderAmendmentHeaderViewModel, PurchaseOrderAmendmentHeader>(vm); try { BeforeSave = PurchaseOrderAmendmentDocEvents.beforeWizardSaveEvent(this, new PurchaseEventArgs(vm.PurchaseOrderAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before save"; } int Cnt = 0; int Sr = 0; List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>(); List <LineChargeViewModel> LineCharges = new List <LineChargeViewModel>(); int pk = 0; bool HeaderChargeEdit = false; PurchaseOrderSetting Settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(vm.DocTypeId, vm.DivisionId, vm.SiteId); int?MaxLineId = 0; int PersonCount = 0; if (!Settings.CalculationId.HasValue) { throw new Exception("Calculation not configured in Purchase order settings"); } int CalculationId = Settings.CalculationId ?? 0; List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>(); if (ModelState.IsValid && BeforeSave && !EventException) { pt.Status = (int)StatusConstants.Drafted; _PurchaseOrderAmendmentHeaderService.Create(pt, User.Identity.Name); var SelectedPurchaseOrders = (List <PurchaseOrderAmendmentWizardViewModel>)System.Web.HttpContext.Current.Session["RateAmendmentWizardOrders"]; var PurchaseOrderLineIds = SelectedPurchaseOrders.Select(m => m.PurchaseOrderLineId).ToArray(); var PurchaseOrderBalanceRecords = (from p in db.ViewPurchaseOrderBalanceForInvoice where PurchaseOrderLineIds.Contains(p.PurchaseOrderLineId) select p).AsNoTracking().ToList(); var PurchaseOrderRecords = (from p in db.PurchaseOrderLine where PurchaseOrderLineIds.Contains(p.PurchaseOrderLineId) select p).AsNoTracking().ToList(); foreach (var item in SelectedPurchaseOrders) { PurchaseOrderLine orderline = PurchaseOrderRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault(); var balorderline = PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault(); if (item.Rate - PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault().Rate != 0) { PurchaseOrderRateAmendmentLine line = new PurchaseOrderRateAmendmentLine(); line.PurchaseOrderAmendmentHeaderId = pt.PurchaseOrderAmendmentHeaderId; line.PurchaseOrderLineId = item.PurchaseOrderLineId; line.Qty = PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault().BalanceQty; line.AmendedRate = item.Rate; line.Rate = line.AmendedRate - balorderline.Rate; line.Amount = balorderline.BalanceQty * orderline.UnitConversionMultiplier * line.Rate; line.PurchaseOrderRate = balorderline.Rate; line.Sr = Serial++; line.PurchaseOrderRateAmendmentLineId = pk; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; LineStatus.Add(line.PurchaseOrderLineId, line.Rate); line.ObjectState = Model.ObjectState.Added; db.PurchaseOrderRateAmendmentLine.Add(line); if (Settings.CalculationId.HasValue) { LineList.Add(new LineDetailListViewModel { Amount = line.Amount, Rate = line.Rate, LineTableId = line.PurchaseOrderRateAmendmentLineId, HeaderTableId = pt.PurchaseOrderAmendmentHeaderId, PersonID = pt.SupplierId, DealQty = orderline.DealQty }); } pk++; Cnt = Cnt + 1; } } new PurchaseOrderLineStatusService(_unitOfWork).UpdatePurchaseRateOnAmendmentMultiple(LineStatus, pt.DocDate, ref db); new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, pt.PurchaseOrderAmendmentHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.PurchaseOrderAmendmentHeaderCharges", "Web.PurchaseOrderRateAmendmentLineCharges", out PersonCount, pt.DocTypeId, pt.SiteId, pt.DivisionId); //Saving Charges foreach (var item in LineCharges) { PurchaseOrderRateAmendmentLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, PurchaseOrderRateAmendmentLineCharge>(item); PoLineCharge.ObjectState = Model.ObjectState.Added; db.PurchaseOrderRateAmendmentLineCharge.Add(PoLineCharge); } //Saving Header charges for (int i = 0; i < HeaderCharges.Count(); i++) { if (!HeaderChargeEdit) { PurchaseOrderAmendmentHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, PurchaseOrderAmendmentHeaderCharge>(HeaderCharges[i]); POHeaderCharge.HeaderTableId = pt.PurchaseOrderAmendmentHeaderId; POHeaderCharge.PersonID = pt.SupplierId; POHeaderCharge.ObjectState = Model.ObjectState.Added; db.PurchaseOrderAmendmentHeaderCharges.Add(POHeaderCharge); } else { var footercharge = new PurchaseOrderAmendmentHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id); footercharge.Rate = HeaderCharges[i].Rate; footercharge.Amount = HeaderCharges[i].Amount; footercharge.ObjectState = Model.ObjectState.Modified; db.PurchaseOrderAmendmentHeaderCharges.Add(footercharge); } } try { PurchaseOrderAmendmentDocEvents.onWizardSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); } try { PurchaseOrderAmendmentDocEvents.afterWizardSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.PurchaseOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.WizardCreate, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); Session.Remove("RateAmendmentWizardOrders"); return(RedirectToAction("Index", "PurchaseOrderAmendmentHeader", new { id = pt.DocTypeId }).Success("Data saved Successfully")); } PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
public ActionResult _ResultsPost(PurchaseOrderAmendmentMasterDetailModel vm) { List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>(); List <LineChargeViewModel> LineCharges = new List <LineChargeViewModel>(); int pk = 0; int Serial = _PurchaseOrderRateAmendmentLineService.GetMaxSr(vm.PurchaseOrderRateAmendmentLineViewModel.FirstOrDefault().PurchaseOrderAmendmentHeaderId); bool HeaderChargeEdit = false; var Header = new PurchaseOrderAmendmentHeaderService(db).Find(vm.PurchaseOrderRateAmendmentLineViewModel.FirstOrDefault().PurchaseOrderAmendmentHeaderId); PurchaseOrderSetting Settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); int?MaxLineId = new PurchaseOrderRateAmendmentLineChargeService(_unitOfWork).GetMaxProductCharge(Header.PurchaseOrderAmendmentHeaderId, "Web.PurchaseOrderRateAmendmentLines", "PurchaseOrderAmendmentHeaderId", "PurchaseOrderRateAmendmentLineId"); int PersonCount = 0; if (!Settings.CalculationId.HasValue) { throw new Exception("Calculation not configured in purchase order settings"); } int CalculationId = Settings.CalculationId ?? 0; List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>(); Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); #region BeforeSave bool BeforeSave = true; try { BeforeSave = PurchaseOrderAmendmentDocEvents.beforeLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseOrderRateAmendmentLineViewModel.FirstOrDefault().PurchaseOrderAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } if (!BeforeSave) { ModelState.AddModelError("", "Validation failed before save"); } #endregion if (ModelState.IsValid && BeforeSave && !EventException) { foreach (var item in vm.PurchaseOrderRateAmendmentLineViewModel.Where(m => (m.AmendedRate - m.PurchaseOrderRate) != 0 && m.AAmended == false)) { PurchaseOrderRateAmendmentLine line = new PurchaseOrderRateAmendmentLine(); line.PurchaseOrderAmendmentHeaderId = item.PurchaseOrderAmendmentHeaderId; line.PurchaseOrderLineId = item.PurchaseOrderLineId; line.Qty = item.Qty; line.AmendedRate = item.AmendedRate; line.Rate = item.AmendedRate - item.PurchaseOrderRate; line.Amount = item.DealQty * line.Rate; line.PurchaseOrderRate = item.PurchaseOrderRate; line.Sr = Serial++; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.Remark = item.Remark; LineStatus.Add(line.PurchaseOrderLineId, line.Rate); line.ObjectState = Model.ObjectState.Added; db.PurchaseOrderRateAmendmentLine.Add(line); LineList.Add(new LineDetailListViewModel { Amount = line.Amount, Rate = line.Rate, LineTableId = line.PurchaseOrderRateAmendmentLineId, HeaderTableId = item.PurchaseOrderAmendmentHeaderId, PersonID = Header.SupplierId, DealQty = item.DealQty }); pk++; } new PurchaseOrderLineStatusService(_unitOfWork).UpdatePurchaseRateOnAmendmentMultiple(LineStatus, Header.DocDate, ref db); new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, vm.PurchaseOrderRateAmendmentLineViewModel.FirstOrDefault().PurchaseOrderAmendmentHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.PurchaseOrderAmendmentHeaderCharges", "Web.PurchaseOrderRateAmendmentLineCharges", out PersonCount, Header.DocTypeId, Header.SiteId, Header.DivisionId); //Saving Charges foreach (var item in LineCharges) { PurchaseOrderRateAmendmentLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, PurchaseOrderRateAmendmentLineCharge>(item); PoLineCharge.ObjectState = Model.ObjectState.Added; //new PurchaseOrderLineChargeService(_unitOfWork).Create(PoLineCharge); db.PurchaseOrderRateAmendmentLineCharge.Add(PoLineCharge); } //Saving Header charges for (int i = 0; i < HeaderCharges.Count(); i++) { if (!HeaderChargeEdit) { PurchaseOrderAmendmentHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, PurchaseOrderAmendmentHeaderCharge>(HeaderCharges[i]); POHeaderCharge.HeaderTableId = vm.PurchaseOrderRateAmendmentLineViewModel.FirstOrDefault().PurchaseOrderAmendmentHeaderId; POHeaderCharge.PersonID = Header.SupplierId; POHeaderCharge.ObjectState = Model.ObjectState.Added; //new PurchaseOrderHeaderChargeService(_unitOfWork).Create(POHeaderCharge); db.PurchaseOrderAmendmentHeaderCharges.Add(POHeaderCharge); } else { var footercharge = new PurchaseOrderAmendmentHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id); footercharge.Rate = HeaderCharges[i].Rate; footercharge.Amount = HeaderCharges[i].Amount; footercharge.ObjectState = Model.ObjectState.Modified; //new PurchaseOrderHeaderChargeService(_unitOfWork).Update(footercharge); db.PurchaseOrderAmendmentHeaderCharges.Add(footercharge); } } try { PurchaseOrderAmendmentDocEvents.onLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseOrderRateAmendmentLineViewModel.FirstOrDefault().PurchaseOrderAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; return(PartialView("_Results", vm)); } try { PurchaseOrderAmendmentDocEvents.afterLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseOrderRateAmendmentLineViewModel.FirstOrDefault().PurchaseOrderAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = Header.DocTypeId, DocId = Header.PurchaseOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.MultipleCreate, DocNo = Header.DocNo, DocDate = Header.DocDate, DocStatus = Header.Status, })); return(Json(new { success = true })); } return(PartialView("_Results", vm)); }
public ActionResult ConfirmedPurchaseOrders(List <PurchaseOrderAmendmentWizardViewModel> ConfirmedList, int DocTypeId, string UserRemark) { //System.Web.HttpContext.Current.Session["RateAmendmentWizardOrders"] = ConfirmedList; //return Json(new { Success = "URL", Data = "/PurchaseOrderRateAmendmentWizard/Create/" + DocTypeId }, JsonRequestBehavior.AllowGet); if (ConfirmedList.Count() > 0 && ConfirmedList.GroupBy(m => m.SupplierId).Count() > 1) { return(Json(new { Success = false, Data = " Multiple Headers are selected. " }, JsonRequestBehavior.AllowGet)); } else if (ConfirmedList.Count() == 0) { return(Json(new { Success = false, Data = " No Records are selected. " }, JsonRequestBehavior.AllowGet)); } else { int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; bool BeforeSave = true; int Serial = 1; Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); try { BeforeSave = PurchaseOrderAmendmentDocEvents.beforeWizardSaveEvent(this, new PurchaseEventArgs(0), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); return(Json(new { Success = false, Data = message }, JsonRequestBehavior.AllowGet)); } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before save"; } int Cnt = 0; int Sr = 0; List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>(); List <LineChargeViewModel> LineCharges = new List <LineChargeViewModel>(); int pk = 0; bool HeaderChargeEdit = false; PurchaseOrderSetting Settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(DocTypeId, DivisionId, SiteId); int?MaxLineId = 0; int PersonCount = 0; if (!Settings.CalculationId.HasValue) { throw new Exception("Calculation not configured in Purchase order settings"); } int CalculationId = Settings.CalculationId ?? 0; List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>(); if (ModelState.IsValid && BeforeSave && !EventException) { PurchaseOrderAmendmentHeader pt = new PurchaseOrderAmendmentHeader(); //Getting Settings pt.SiteId = SiteId; pt.SupplierId = ConfirmedList.FirstOrDefault().SupplierId; pt.DivisionId = DivisionId; pt.DocTypeId = DocTypeId; pt.DocDate = DateTime.Now; pt.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".PurchaseOrderAmendmentHeaders", pt.DocTypeId, pt.DocDate, pt.DivisionId, pt.SiteId); pt.Status = (int)StatusConstants.Drafted; _PurchaseOrderAmendmentHeaderService.Create(pt, User.Identity.Name); var SelectedPurchaseOrders = ConfirmedList; var PurchaseOrderLineIds = SelectedPurchaseOrders.Select(m => m.PurchaseOrderLineId).ToArray(); var PurchaseOrderBalanceRecords = (from p in db.ViewPurchaseOrderBalanceForInvoice where PurchaseOrderLineIds.Contains(p.PurchaseOrderLineId) select p).AsNoTracking().ToList(); var PurchaseOrderRecords = (from p in db.PurchaseOrderLine where PurchaseOrderLineIds.Contains(p.PurchaseOrderLineId) select p).AsNoTracking().ToList(); foreach (var item in SelectedPurchaseOrders) { PurchaseOrderLine orderline = PurchaseOrderRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault(); var balorderline = PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault(); if (item.Rate - PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault().Rate != 0) { PurchaseOrderRateAmendmentLine line = new PurchaseOrderRateAmendmentLine(); line.PurchaseOrderAmendmentHeaderId = pt.PurchaseOrderAmendmentHeaderId; line.PurchaseOrderLineId = item.PurchaseOrderLineId; line.Qty = PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault().BalanceQty; line.AmendedRate = item.Rate; line.Rate = line.AmendedRate - balorderline.Rate; line.Amount = balorderline.BalanceQty * orderline.UnitConversionMultiplier * line.Rate; line.PurchaseOrderRate = balorderline.Rate; line.Sr = Serial++; line.PurchaseOrderRateAmendmentLineId = pk; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; LineStatus.Add(line.PurchaseOrderLineId, line.Rate); line.ObjectState = Model.ObjectState.Added; db.PurchaseOrderRateAmendmentLine.Add(line); if (Settings.CalculationId.HasValue) { LineList.Add(new LineDetailListViewModel { Amount = line.Amount, Rate = line.Rate, LineTableId = line.PurchaseOrderRateAmendmentLineId, HeaderTableId = pt.PurchaseOrderAmendmentHeaderId, PersonID = pt.SupplierId, DealQty = orderline.DealQty }); } pk++; Cnt = Cnt + 1; } } new PurchaseOrderLineStatusService(_unitOfWork).UpdatePurchaseRateOnAmendmentMultiple(LineStatus, pt.DocDate, ref db); new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, pt.PurchaseOrderAmendmentHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.PurchaseOrderAmendmentHeaderCharges", "Web.PurchaseOrderRateAmendmentLineCharges", out PersonCount, pt.DocTypeId, pt.SiteId, pt.DivisionId); //Saving Charges foreach (var item in LineCharges) { PurchaseOrderRateAmendmentLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, PurchaseOrderRateAmendmentLineCharge>(item); PoLineCharge.ObjectState = Model.ObjectState.Added; db.PurchaseOrderRateAmendmentLineCharge.Add(PoLineCharge); } //Saving Header charges for (int i = 0; i < HeaderCharges.Count(); i++) { if (!HeaderChargeEdit) { PurchaseOrderAmendmentHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, PurchaseOrderAmendmentHeaderCharge>(HeaderCharges[i]); POHeaderCharge.HeaderTableId = pt.PurchaseOrderAmendmentHeaderId; POHeaderCharge.PersonID = pt.SupplierId; POHeaderCharge.ObjectState = Model.ObjectState.Added; db.PurchaseOrderAmendmentHeaderCharges.Add(POHeaderCharge); } else { var footercharge = new PurchaseOrderAmendmentHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id); footercharge.Rate = HeaderCharges[i].Rate; footercharge.Amount = HeaderCharges[i].Amount; footercharge.ObjectState = Model.ObjectState.Modified; db.PurchaseOrderAmendmentHeaderCharges.Add(footercharge); } } try { PurchaseOrderAmendmentDocEvents.onWizardSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); return(Json(new { Success = false, Data = message }, JsonRequestBehavior.AllowGet)); } try { PurchaseOrderAmendmentDocEvents.afterWizardSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.PurchaseOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.WizardCreate, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); return(Json(new { Success = "URL", Data = "/PurchaseOrderAmendmentHeader/Submit/" + pt.PurchaseOrderAmendmentHeaderId }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Success = false, Data = "ModelState is Invalid" }, JsonRequestBehavior.AllowGet)); } } }
// here we simulate SQL search, sorting and paging operations private IQueryable <PurchaseOrderAmendmentWizardViewModel> FilterData(int DocType, DateTime?FromDate, DateTime?ToDate, string PurchaseOrderHeaderId, string SupplierId, string ProductId, string Dimension1Id, string Dimension2Id, string ProductGroupId, string ProductCategoryId, decimal?Rate, decimal NewRate, decimal?MultiplierGT, decimal?MultiplierLT, string Sample) { List <int> PurchaseOrderHeaderIds = new List <int>(); if (!string.IsNullOrEmpty(PurchaseOrderHeaderId)) { foreach (var item in PurchaseOrderHeaderId.Split(',')) { PurchaseOrderHeaderIds.Add(Convert.ToInt32(item)); } } List <int> SupplierIds = new List <int>(); if (!string.IsNullOrEmpty(SupplierId)) { foreach (var item in SupplierId.Split(',')) { SupplierIds.Add(Convert.ToInt32(item)); } } //List<int> ProductIds = new List<int>(); //if (!string.IsNullOrEmpty(ProductId)) // foreach (var item in ProductId.Split(',')) // ProductIds.Add(Convert.ToInt32(item)); List <int> Dimension1Ids = new List <int>(); if (!string.IsNullOrEmpty(Dimension1Id)) { foreach (var item in Dimension1Id.Split(',')) { Dimension1Ids.Add(Convert.ToInt32(item)); } } List <int> Dimension2Ids = new List <int>(); if (!string.IsNullOrEmpty(Dimension2Id)) { foreach (var item in Dimension2Id.Split(',')) { Dimension2Ids.Add(Convert.ToInt32(item)); } } //List<int> ProductGroupIds = new List<int>(); //if (!string.IsNullOrEmpty(ProductGroupId)) // foreach (var item in ProductGroupId.Split(',')) // ProductGroupIds.Add(Convert.ToInt32(item)); int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; var Settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(DocType, DivisionId, SiteId); string[] contraDocTypes = null; if (!string.IsNullOrEmpty(Settings.filterContraDocTypes)) { contraDocTypes = Settings.filterContraDocTypes.Split(",".ToCharArray()); } else { contraDocTypes = new string[] { "NA" }; } IQueryable <PurchaseOrderAmendmentWizardViewModel> _data = from p in db.ViewPurchaseOrderBalanceForInvoice join t in db.PurchaseOrderLine on p.PurchaseOrderLineId equals t.PurchaseOrderLineId join jw in db.Persons on p.SupplierId equals jw.PersonID into jwtable from jwtab in jwtable.DefaultIfEmpty() join prod in db.FinishedProduct on p.ProductId equals prod.ProductId into prodtable from prodtab in prodtable.DefaultIfEmpty() join dim1 in db.Dimension1 on p.Dimension1Id equals dim1.Dimension1Id into dimtable from dimtab in dimtable.DefaultIfEmpty() join dim2 in db.Dimension2 on p.Dimension2Id equals dim2.Dimension2Id into dim2table from dim2tab in dim2table.DefaultIfEmpty() join pg in db.ProductGroups on prodtab.ProductGroupId equals pg.ProductGroupId into pgtable from pgtab in pgtable.DefaultIfEmpty() join pc in db.ProductCategory on prodtab.ProductCategoryId equals pc.ProductCategoryId into pctable from pctab in pctable.DefaultIfEmpty() where p.BalanceQty > 0 && (string.IsNullOrEmpty(Settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(t.PurchaseOrderHeader.DocTypeId.ToString())) select new PurchaseOrderAmendmentWizardViewModel { OrderDate = p.OrderDate, OrderNo = p.PurchaseOrderNo, PurchaseOrderLineId = p.PurchaseOrderLineId, OldRate = p.Rate, Rate = NewRate, SupplierName = jwtab.Name, ProductName = prodtab.ProductName, Dimension1Name = dimtab.Dimension1Name, Dimension2Name = dim2tab.Dimension2Name, PurchaseOrderHeaderId = p.PurchaseOrderHeaderId, SupplierId = p.SupplierId, ProductGroupId = pgtab.ProductGroupId, ProductGroupName = pgtab.ProductGroupName, ProductCategoryId = pctab.ProductCategoryId, ProductCategoryName = pctab.ProductCategoryName, ProdId = p.ProductId, Dimension1Id = p.Dimension1Id, Dimension2Id = p.Dimension2Id, UnitConversionMultiplier = t.UnitConversionMultiplier, Sample = prodtab.IsSample, }; //if (FromDate.HasValue) // _data = from p in _data // where p.OrderDate >= FromDate // select p; if (FromDate.HasValue) { _data = _data.Where(m => m.OrderDate >= FromDate); } if (ToDate.HasValue) { _data = _data.Where(m => m.OrderDate <= ToDate); } if (Rate.HasValue && Rate.Value > 0) { _data = _data.Where(m => m.OldRate == Rate.Value); } if (MultiplierGT.HasValue) { _data = _data.Where(m => m.UnitConversionMultiplier >= MultiplierGT.Value); } if (MultiplierLT.HasValue) { _data = _data.Where(m => m.UnitConversionMultiplier <= MultiplierLT.Value); } if (!string.IsNullOrEmpty(PurchaseOrderHeaderId)) { _data = _data.Where(m => PurchaseOrderHeaderIds.Contains(m.PurchaseOrderHeaderId)); } if (!string.IsNullOrEmpty(SupplierId)) { _data = _data.Where(m => SupplierIds.Contains(m.SupplierId)); } if (!string.IsNullOrEmpty(ProductId)) { _data = _data.Where(m => m.ProductName.Contains(ProductId)); } if (!string.IsNullOrEmpty(Dimension1Id)) { _data = _data.Where(m => Dimension1Ids.Contains(m.Dimension1Id ?? 0)); } if (!string.IsNullOrEmpty(Dimension2Id)) { _data = _data.Where(m => Dimension2Ids.Contains(m.Dimension2Id ?? 0)); } if (!string.IsNullOrEmpty(ProductGroupId)) { _data = _data.Where(m => m.ProductGroupName.Contains(ProductGroupId)); } if (!string.IsNullOrEmpty(ProductCategoryId)) { _data = _data.Where(m => m.ProductCategoryName.Contains(ProductCategoryId)); } if (!string.IsNullOrEmpty(Sample) && Sample != "Include") { if (Sample == "Exclude") { _data = _data.Where(m => m.Sample == false); } else if (Sample == "Only") { _data = _data.Where(m => m.Sample == true); } } _data = _data.OrderBy(m => m.OrderDate).ThenBy(m => m.OrderNo); // get just one page of data return(_data.Select(m => new PurchaseOrderAmendmentWizardViewModel { OrderDate = m.OrderDate, OrderNo = m.OrderNo, PurchaseOrderLineId = m.PurchaseOrderLineId, OldRate = m.OldRate, Rate = m.Rate, SupplierName = m.SupplierName, ProductName = m.ProductName, Dimension1Name = m.Dimension1Name, Dimension2Name = m.Dimension2Name, PurchaseOrderHeaderId = m.PurchaseOrderHeaderId, SupplierId = m.SupplierId, ProductGroupId = m.ProductGroupId, ProductGroupName = m.ProductGroupName, ProductCategoryId = m.ProductCategoryId, ProductCategoryName = m.ProductCategoryName, ProdId = m.ProdId, Dimension1Id = m.Dimension1Id, Dimension2Id = m.Dimension2Id, UnitConversionMultiplier = m.UnitConversionMultiplier, Sample = m.Sample, })); }
public ActionResult ConfirmedPurchaseOrders(List <PurchaseOrderCancelWizardViewModel> ConfirmedList, int DocTypeId, string UserRemark, int ReasonId) { //System.Web.HttpContext.Current.Session["BalanceQtyAmendmentWizardOrders"] = ConfirmedList; //return Json(new { Success = "URL", Data = "/PurchaseOrderCancelWizard/Create/" + DocTypeId }, JsonRequestBehavior.AllowGet); if (ConfirmedList.Count() > 0 && ConfirmedList.GroupBy(m => m.SupplierId).Count() > 1) { return(Json(new { Success = false, Data = " Multiple Headers are selected. " }, JsonRequestBehavior.AllowGet)); } else if (ConfirmedList.Count() == 0) { return(Json(new { Success = false, Data = " No Records are selected. " }, JsonRequestBehavior.AllowGet)); } else { int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; bool BeforeSave = true; int Serial = 1; Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); try { BeforeSave = PurchaseOrderCancelDocEvents.beforeWizardSaveEvent(this, new PurchaseEventArgs(0), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); return(Json(new { Success = false, Data = message }, JsonRequestBehavior.AllowGet)); } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before save"; } int Cnt = 0; int Sr = 0; PurchaseOrderSetting Settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(DocTypeId, DivisionId, SiteId); int?MaxLineId = 0; if (ModelState.IsValid && BeforeSave && !EventException) { PurchaseOrderCancelHeader pt = new PurchaseOrderCancelHeader(); //Getting Settings pt.SiteId = SiteId; pt.SupplierId = ConfirmedList.FirstOrDefault().SupplierId; pt.DivisionId = DivisionId; pt.Remark = UserRemark; pt.DocTypeId = DocTypeId; pt.ReasonId = ReasonId; pt.DocDate = DateTime.Now; pt.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".PurchaseOrderCancelHeaders", pt.DocTypeId, pt.DocDate, pt.DivisionId, pt.SiteId); pt.ModifiedBy = User.Identity.Name; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.CreatedDate = DateTime.Now; pt.Status = (int)StatusConstants.Drafted; pt.ObjectState = Model.ObjectState.Added; db.PurchaseOrderCancelHeader.Add(pt); var SelectedPurchaseOrders = ConfirmedList; var PurchaseOrderLineIds = SelectedPurchaseOrders.Select(m => m.PurchaseOrderLineId).ToArray(); var PurchaseOrderBalanceRecords = (from p in db.ViewPurchaseOrderBalance where PurchaseOrderLineIds.Contains(p.PurchaseOrderLineId) select p).AsNoTracking().ToList(); var PurchaseOrderRecords = (from p in db.PurchaseOrderLine where PurchaseOrderLineIds.Contains(p.PurchaseOrderLineId) select p).AsNoTracking().ToList(); foreach (var item in SelectedPurchaseOrders) { PurchaseOrderLine orderline = PurchaseOrderRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault(); var balorderline = PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault(); if (item.CancelQty <= PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault().BalanceQty) { PurchaseOrderCancelLine line = new PurchaseOrderCancelLine(); line.PurchaseOrderCancelHeaderId = pt.PurchaseOrderCancelHeaderId; line.PurchaseOrderLineId = item.PurchaseOrderLineId; line.Qty = PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault().BalanceQty; line.Qty = item.CancelQty; line.Sr = Serial++; line.PurchaseOrderCancelLineId = Cnt; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; LineStatus.Add(line.PurchaseOrderLineId, line.Qty); line.ObjectState = Model.ObjectState.Added; db.PurchaseOrderCancelLine.Add(line); Cnt = Cnt + 1; } } new PurchaseOrderLineStatusService(_unitOfWork).UpdatePurchaseQtyCancelMultiple(LineStatus, pt.DocDate, ref db); try { PurchaseOrderCancelDocEvents.onWizardSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderCancelHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); return(Json(new { Success = false, Data = message }, JsonRequestBehavior.AllowGet)); } try { PurchaseOrderCancelDocEvents.afterWizardSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderCancelHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.PurchaseOrderCancelHeaderId, ActivityType = (int)ActivityTypeContants.WizardCreate, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); return(Json(new { Success = "URL", Data = "/PurchaseOrderCancelHeader/Submit/" + pt.PurchaseOrderCancelHeaderId }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Success = false, Data = "ModelState is Invalid" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult GeneratePrints(string Ids, int DocTypeId) { if (!string.IsNullOrEmpty(Ids)) { int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; var Settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(DocTypeId, DivisionId, SiteId); try { List <byte[]> PdfStream = new List <byte[]>(); foreach (var item in Ids.Split(',').Select(Int32.Parse)) { DirectReportPrint drp = new DirectReportPrint(); var pd = db.PurchaseOrderAmendmentHeader.Find(item); LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pd.DocTypeId, DocId = pd.PurchaseOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.Print, DocNo = pd.DocNo, DocDate = pd.DocDate, DocStatus = pd.Status, })); byte[] Pdf; if (pd.Status == (int)StatusConstants.Drafted || pd.Status == (int)StatusConstants.Import || pd.Status == (int)StatusConstants.Modified) { //LogAct(item.ToString()); Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint, User.Identity.Name, item); PdfStream.Add(Pdf); } else if (pd.Status == (int)StatusConstants.Submitted || pd.Status == (int)StatusConstants.ModificationSubmitted) { Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint_AfterSubmit, User.Identity.Name, item); PdfStream.Add(Pdf); } else { Pdf = drp.DirectDocumentPrint(Settings.SqlProcDocumentPrint_AfterApprove, User.Identity.Name, item); PdfStream.Add(Pdf); } } PdfMerger pm = new PdfMerger(); byte[] Merge = pm.MergeFiles(PdfStream); if (Merge != null) { return(File(Merge, "application/pdf")); } } catch (Exception ex) { string message = _exception.HandleException(ex); return(Json(new { success = "Error", data = message }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Success" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = "Error", data = "No Records Selected." }, JsonRequestBehavior.AllowGet)); }
// GET: /ProductMaster/Edit/5 private ActionResult Edit(int id, string IndexType) { ViewBag.IndexStatus = IndexType; PurchaseOrderAmendmentHeader pt = _PurchaseOrderAmendmentHeaderService.Find(id); if (pt == null) { return(HttpNotFound()); } PurchaseOrderAmendmentHeaderViewModel temp = AutoMapper.Mapper.Map <PurchaseOrderAmendmentHeader, PurchaseOrderAmendmentHeaderViewModel>(pt); #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(pt), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if ((!TimePlanValidation && !Continue)) { return(RedirectToAction("DetailInformation", new { id = id, IndexType = IndexType })); } //Purchase Order Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "PurchaseOrderSettings", new { id = pt.DocTypeId }).Warning("Please create Purchase order settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } temp.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); PrepareViewBag(pt.DocTypeId); ViewBag.Mode = "Edit"; if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create")) { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.PurchaseOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); } return(View("Create", temp)); }