public ActionResult _Create(int Id, int sid, bool IsIndentBased) //Id ==>Sale Order Header Id { PurchaseQuotationHeader H = _PurchaseQuotationHeaderService.Find(Id); PurchaseQuotationLineViewModel s = new PurchaseQuotationLineViewModel(); //Getting Settings var settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId); s.PurchQuotationSettings = Mapper.Map <PurchaseQuotationSetting, PurchaseQuotationSettingsViewModel>(settings); s.PurchaseQuotationHeaderId = H.PurchaseQuotationHeaderId; s.PurchaseQuotationHeaderDocNo = H.DocNo; s.SupplierId = sid; s.DocTypeId = H.DocTypeId; s.DivisionId = H.DivisionId; s.SiteId = H.SiteId; s.CalculateDiscountOnRate = H.CalculateDiscountOnRate; ViewBag.LineMode = "Create"; PrepareViewBag(null); if (IsIndentBased == true) { return(PartialView("_CreateForIndent", s)); } else { return(PartialView("_Create", s)); } }
public ActionResult Submit(int id, string IndexType, string TransactionType) { #region DocTypeTimeLineValidation bool TimePlanValidation = true; string ExceptionMsg = ""; bool Continue = true; PurchaseQuotationHeader s = db.PurchaseQuotationHeader.Find(id); try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(s), DocumentTimePlanTypeConstants.Submit, User.Identity.Name, out ExceptionMsg, out Continue); TempData["CSEXC"] += ExceptionMsg; } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation && !Continue) { return(RedirectToAction("Index", new { id = s.DocTypeId, IndexType = IndexType })); } #endregion return(RedirectToAction("Detail", new { id = id, IndexType = IndexType, transactionType = string.IsNullOrEmpty(TransactionType) ? "submit" : TransactionType })); }
public ActionResult WizardPost(PurchaseQuotationHeaderViewModel Header, List <item> Lines) { if (ModelState.IsValid) { PurchaseQuotationHeader Head = new PurchaseQuotationHeader(); Head.CreatedBy = User.Identity.Name; Head.DocTypeId = 281; Head.CreatedDate = DateTime.Now; Head.CurrencyId = Header.CurrencyId; Head.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; Head.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; Head.DocDate = Header.DocDate; Head.DocNo = Header.DocNo; Head.ModifiedBy = User.Identity.Name; Head.ModifiedDate = DateTime.Now; Head.Remark = Header.Remark; Head.SupplierId = Header.SupplierId; Head.TermsAndConditions = Header.TermsAndConditions; Head.VendorQuotationDate = Header.VendorQuotationDate; Head.VendorQuotationNo = Header.VendorQuotationNo; Head.ObjectState = Model.ObjectState.Added; db.PurchaseQuotationHeader.Add(Head); foreach (var item in Lines) { PurchaseQuotationLine Line = new PurchaseQuotationLine(); Line.CreatedBy = User.Identity.Name; Line.CreatedDate = DateTime.Now; Line.ModifiedBy = User.Identity.Name; Line.ModifiedDate = DateTime.Now; Line.ProductId = item.id; Line.PurchaseQuotationHeaderId = Head.PurchaseQuotationHeaderId; Line.Qty = item.Qty; Line.ObjectState = Model.ObjectState.Added; db.PurchaseQuotationLine.Add(Line); } try { db.SaveChanges(); } catch (Exception ex) { return(Json(new { Success = false, Message = _exception.HandleException(ex) })); } return(Json(new { Success = true, url = "/PurchaseQuotationHeader/Index" })); } return(Json(new { Success = false, Message = "Error in saving record. Cannot continue." })); }
public ActionResult DeleteAfter_Approve(int id) { PurchaseQuotationHeader header = _PurchaseQuotationHeaderService.Find(id); if (header.Status == (int)StatusConstants.Approved) { return(Remove(id)); } else { return(HttpNotFound()); } }
public ActionResult DeleteAfter_Submit(int id) { PurchaseQuotationHeader header = _PurchaseQuotationHeaderService.Find(id); if (header.Status == (int)StatusConstants.Submitted || header.Status == (int)StatusConstants.Modified || header.Status == (int)StatusConstants.ModificationSubmitted) { return(Remove(id)); } else { return(HttpNotFound()); } }
public ActionResult ModifyAfter_Submit(int id, string IndexType) { PurchaseQuotationHeader header = _PurchaseQuotationHeaderService.Find(id); if (header.Status == (int)StatusConstants.Submitted || header.Status == (int)StatusConstants.Modified || header.Status == (int)StatusConstants.ModificationSubmitted) { return(Edit(id, IndexType)); } else { return(HttpNotFound()); } }
public JsonResult getunitconversiondetailjson(int productid, string unitid, string DealUnitId, int PurchaseQuotationHeaderId) { PurchaseQuotationHeader Invoice = _PurchaseQuotationHeaderService.Find(PurchaseQuotationHeaderId); if (Invoice.UnitConversionForId.HasValue && Invoice.UnitConversionForId > 0) { UnitConversion uc = new UnitConversionService(_unitOfWork).GetUnitConversionForUCF(productid, unitid, DealUnitId, Invoice.UnitConversionForId ?? 0); List <SelectListItem> unitconversionjson = new List <SelectListItem>(); if (uc != null) { unitconversionjson.Add(new SelectListItem { Text = uc.Multiplier.ToString(), Value = uc.Multiplier.ToString() }); } else { unitconversionjson.Add(new SelectListItem { Text = "0", Value = "0" }); } return(Json(unitconversionjson)); } else { UnitConversion uc = new UnitConversionService(_unitOfWork).GetUnitConversion(productid, unitid, DealUnitId); List <SelectListItem> unitconversionjson = new List <SelectListItem>(); if (uc != null) { unitconversionjson.Add(new SelectListItem { Text = uc.Multiplier.ToString(), Value = uc.Multiplier.ToString() }); } else { unitconversionjson.Add(new SelectListItem { Text = "0", Value = "0" }); } return(Json(unitconversionjson)); } }
public ActionResult _ForIndent(int id, int sid) { PurchaseQuotationLineFilterViewModel vm = new PurchaseQuotationLineFilterViewModel(); PurchaseQuotationHeader Header = _PurchaseQuotationHeaderService.Find(id); PurchaseQuotationSetting Settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); vm.PurchaseQuotationSettings = Mapper.Map <PurchaseQuotationSetting, PurchaseQuotationSettingsViewModel>(Settings); vm.PurchaseQuotationHeaderId = id; vm.SupplierId = sid; PrepareViewBag(null); return(PartialView("_IndentFilters", vm)); }
public ActionResult _Detail(int id) { PurchaseQuotationLineViewModel temp = _PurchaseQuotationLineService.GetPurchaseQuotationLine(id); if (temp == null) { return(HttpNotFound()); } PurchaseQuotationHeader H = _PurchaseQuotationHeaderService.Find(temp.PurchaseQuotationHeaderId); PrepareViewBag(temp); //Getting Settings var settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId); temp.PurchQuotationSettings = Mapper.Map <PurchaseQuotationSetting, PurchaseQuotationSettingsViewModel>(settings); return(PartialView("_Create", temp)); }
public ActionResult _FilterPostIndents(PurchaseQuotationLineFilterViewModel vm) { if (vm.PurchaseQuotationSettings.isMandatoryRate && (vm.Rate == null || vm.Rate == 0)) { ModelState.AddModelError("", "Rate is mandatory"); PrepareViewBag(null); return(PartialView("_IndentFilters", vm)); } List <PurchaseQuotationLineViewModel> temp = _PurchaseQuotationLineService.GetPurchaseIndentForFilters(vm).ToList(); PurchaseQuotationMasterDetailModel svm = new PurchaseQuotationMasterDetailModel(); svm.PurchaseQuotationLineViewModel = temp; bool UnitConvetsionException = (from p in temp where p.UnitConversionException == true select p).Any(); if (UnitConvetsionException) { ViewBag.UnitConversionException = UnitConvetsionException; string Products = string.Join(",", from p in temp where p.UnitConversionException == true select p.ProductName); ModelState.AddModelError("", "Unit Conversion are missing for few Products -" + Products); } PurchaseQuotationHeader Header = _PurchaseQuotationHeaderService.Find(vm.PurchaseQuotationHeaderId); PurchaseQuotationSetting Settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); svm.PurchaseQuotationSettings = Mapper.Map <PurchaseQuotationSetting, PurchaseQuotationSettingsViewModel>(Settings); return(PartialView("_IndentResults", svm)); }
// GET: /ProductMaster/Delete/5 private ActionResult Remove(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PurchaseQuotationHeader PurchaseQuotationHeader = db.PurchaseQuotationHeader.Find(id); if (PurchaseQuotationHeader == null) { return(HttpNotFound()); } #region DocTypeTimeLineValidation bool TimePlanValidation = true; string ExceptionMsg = ""; try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(PurchaseQuotationHeader), DocumentTimePlanTypeConstants.Delete, User.Identity.Name, out ExceptionMsg, out Continue); TempData["CSEXC"] += ExceptionMsg; } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation && !Continue) { return(PartialView("AjaxError")); } #endregion ReasonViewModel vm = new ReasonViewModel() { id = id, }; return(PartialView("_Reason", vm)); }
public PurchaseQuotationHeader Create(PurchaseQuotationHeader s) { s.ObjectState = ObjectState.Added; db.PurchaseQuotationHeader.Add(s); return(s); }
public void Update(PurchaseQuotationHeader s) { s.ObjectState = ObjectState.Modified; db.PurchaseQuotationHeader.Add(s); }
public ActionResult DeletePost(PurchaseQuotationLineViewModel vm) { bool BeforeSave = true; //try //{ // BeforeSave = PurchaseQuotationReceiveDocEvents.beforeLineDeleteEvent(this, new PurchaseEventArgs(vm.PurchaseQuotationHeaderId, vm.PurchaseQuotationLineId), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; // EventException = true; //} if (!BeforeSave) { TempData["CSEXC"] += "Validation failed before delete."; } if (BeforeSave && !EventException) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); PurchaseQuotationLine PurchaseQuotationLine = db.PurchaseQuotationLine.Find(vm.PurchaseQuotationLineId); //try //{ // PurchaseQuotationReceiveDocEvents.onLineDeleteEvent(this, new PurchaseEventArgs(PurchaseQuotationLine.PurchaseQuotationHeaderId, PurchaseQuotationLine.PurchaseQuotationLineId), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXCL"] += message; // EventException = true; //} LogList.Add(new LogTypeViewModel { ExObj = Mapper.Map <PurchaseQuotationLine>(PurchaseQuotationLine), }); //_PurchaseQuotationLineService.Delete(PurchaseQuotationLine); PurchaseQuotationHeader header = _PurchaseQuotationHeaderService.Find(PurchaseQuotationLine.PurchaseQuotationHeaderId); var chargeslist = (from p in db.PurchaseQuotationLineCharge where p.LineTableId == PurchaseQuotationLine.PurchaseQuotationLineId select p).ToList(); if (chargeslist != null) { foreach (var item in chargeslist) { item.ObjectState = Model.ObjectState.Deleted; db.PurchaseQuotationLineCharge.Remove(item); //new PurchaseQuotationLineChargeService(_unitOfWork).Delete(item.Id); } } if (vm.footercharges != null) { foreach (var item in vm.footercharges) { var footer = new PurchaseQuotationHeaderChargeService(_unitOfWork).Find(item.Id); footer.Rate = item.Rate; footer.Amount = item.Amount; footer.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeaderCharge.Add(footer); //new PurchaseQuotationHeaderChargeService(_unitOfWork).Update(footer); } } PurchaseQuotationLine.ObjectState = Model.ObjectState.Deleted; db.PurchaseQuotationLine.Remove(PurchaseQuotationLine); if (header.Status != (int)StatusConstants.Drafted) { header.Status = (int)StatusConstants.Modified; header.ModifiedDate = DateTime.Now; header.ModifiedBy = User.Identity.Name; } header.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeader.Add(header); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; PrepareViewBag(null); return(PartialView("_Create", vm)); } //try //{ // PurchaseQuotationReceiveDocEvents.afterLineDeleteEvent(this, new PurchaseEventArgs(PurchaseQuotationLine.PurchaseQuotationHeaderId, PurchaseQuotationLine.PurchaseQuotationLineId), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; //} LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = header.DocTypeId, DocId = header.PurchaseQuotationHeaderId, DocLineId = PurchaseQuotationLine.PurchaseQuotationLineId, ActivityType = (int)ActivityTypeContants.Deleted, DocNo = header.DocNo, xEModifications = Modifications, DocDate = header.DocDate, DocStatus = header.Status, })); } return(Json(new { success = true })); }
private ActionResult _Delete(int id) { PurchaseQuotationLineViewModel temp = _PurchaseQuotationLineService.GetPurchaseQuotationLine(id); bool IndentBased = false; 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"; } if (temp.PurchaseIndentLineId.HasValue) { var Indent = (from p in db.ViewPurchaseIndentBalance where p.PurchaseIndentLineId == temp.PurchaseIndentLineId select new { p.PurchaseIndentLineId, p.PurchaseIndentNo, p.BalanceQty }).FirstOrDefault(); temp.PurchaseIndentDocNo = Indent.PurchaseIndentNo; temp.PurchaseIndentLineId = Indent.PurchaseIndentLineId; temp.IndentBalanceQty = Indent.BalanceQty; IndentBased = true; } PurchaseQuotationHeader H = _PurchaseQuotationHeaderService.Find(temp.PurchaseQuotationHeaderId); PrepareViewBag(temp); //Getting Settings var settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId); temp.PurchQuotationSettings = Mapper.Map <PurchaseQuotationSetting, PurchaseQuotationSettingsViewModel>(settings); if (IndentBased == true) { return(PartialView("_CreateForIndent", temp)); } else { return(PartialView("_Create", temp)); } }
public ActionResult Post(PurchaseQuotationHeaderViewModel vm) { PurchaseQuotationHeader pt = AutoMapper.Mapper.Map <PurchaseQuotationHeaderViewModel, PurchaseQuotationHeader>(vm); //Getting Settings var settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(vm.DocTypeId, vm.DivisionId, vm.SiteId); if (vm.BillingAccountId <= 0) { ModelState.AddModelError("BillingAccountId", "The Billing Account field is required"); } #region BeforeSave bool BeforeSave = true; //try //{ // if (vm.PurchaseQuotationHeaderId <= 0) // BeforeSave = PurchaseQuotationReceiveDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(vm.PurchaseQuotationHeaderId, EventModeConstants.Add), ref db); // else // BeforeSave = PurchaseQuotationReceiveDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(vm.PurchaseQuotationHeaderId, EventModeConstants.Edit), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; // EventException = true; //} //if (!BeforeSave) // TempData["CSEXC"] += "Failed validation before save"; #endregion #region DocTypeTimeLineValidation try { if (vm.PurchaseQuotationHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), 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 (ModelState.IsValid && BeforeSave && !EventException && (TimePlanValidation || Continue)) { #region CreateRecord if (vm.PurchaseQuotationHeaderId <= 0) { pt.CalculateDiscountOnRate = vm.CalculateDiscountOnRate; pt.DivisionId = vm.DivisionId; pt.SiteId = vm.SiteId; pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; db.PurchaseQuotationHeader.Add(pt); //_PurchaseQuotationHeaderService.Create(pt); //try //{ // PurchaseQuotationReceiveDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(pt.PurchaseQuotationHeaderId, 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 //{ // PurchaseQuotationReceiveDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(pt.PurchaseQuotationHeaderId, 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.PurchaseQuotationHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); //return Edit(pt.PurchaseQuotationHeaderId).Success("Data saved successfully"); return(RedirectToAction("Modify", new { id = pt.PurchaseQuotationHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); PurchaseQuotationHeader temp = _PurchaseQuotationHeaderService.Find(pt.PurchaseQuotationHeaderId); PurchaseQuotationHeader ExRec = new PurchaseQuotationHeader(); ExRec = Mapper.Map <PurchaseQuotationHeader>(temp); int status = temp.Status; if (temp.Status != (int)StatusConstants.Drafted) { temp.Status = (int)StatusConstants.Modified; } temp.DocTypeId = pt.DocTypeId; temp.CurrencyId = pt.CurrencyId; temp.VendorQuotationNo = pt.VendorQuotationNo; temp.VendorQuotationDate = pt.VendorQuotationDate; temp.TermsAndConditions = pt.TermsAndConditions; temp.SalesTaxGroupId = pt.SalesTaxGroupId; temp.UnitConversionForId = pt.UnitConversionForId; temp.CreditDays = pt.CreditDays; temp.Remark = pt.Remark; temp.SupplierId = pt.SupplierId; temp.BillingAccountId = pt.BillingAccountId; temp.DocDate = pt.DocDate; temp.DocNo = pt.DocNo; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeader.Add(temp); //_PurchaseQuotationHeaderService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); //try //{ // PurchaseQuotationReceiveDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseQuotationHeaderId, EventModeConstants.Edit), 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 = "Edit"; return(View("Create", pt)); } //try //{ // PurchaseQuotationReceiveDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseQuotationHeaderId, EventModeConstants.Edit), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; //} LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.PurchaseQuotationHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("Index", new { id = vm.DocTypeId }).Success("Data saved successfully")); } #endregion } PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
public ActionResult Submitted(int Id, string IndexType, string UserRemark, string IsContinue) { bool BeforeSave = true; //try //{ // BeforeSave = PurchaseQuotationReceiveDocEvents.beforeHeaderSubmitEvent(this, new PurchaseEventArgs(Id), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; // EventException = true; //} if (!BeforeSave) { TempData["CSEXC"] += "Falied validation before submit."; } PurchaseQuotationHeader pd = _PurchaseQuotationHeaderService.Find(Id); if (ModelState.IsValid && BeforeSave && !EventException) { int ActivityType; if (User.Identity.Name == pd.ModifiedBy || UserRoles.Contains("Admin")) { pd.Status = (int)StatusConstants.Submitted; ActivityType = (int)ActivityTypeContants.Submitted; //_PurchaseQuotationHeaderService.Update(pd); //try //{ // PurchaseQuotationReceiveDocEvents.onHeaderSubmitEvent(this, new PurchaseEventArgs(Id), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; // EventException = true; //} pd.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeader.Add(pd); try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType })); } //try //{ // PurchaseQuotationReceiveDocEvents.afterHeaderSubmitEvent(this, new PurchaseEventArgs(Id), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; //} LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pd.DocTypeId, DocId = pd.PurchaseQuotationHeaderId, ActivityType = ActivityType, UserRemark = UserRemark, DocNo = pd.DocNo, DocDate = pd.DocDate, DocStatus = pd.Status, })); if (!string.IsNullOrEmpty(IsContinue) && IsContinue == "True") { int nextId = new NextPrevIdService(_unitOfWork).GetNextPrevId(Id, pd.DocTypeId, User.Identity.Name, ForActionConstants.PendingToSubmit, "Web.PurchaseQuotationHeaders", "PurchaseQuotationHeaderId", PrevNextConstants.Next); if (nextId == 0) { var PendingtoSubmitCount = _PurchaseQuotationHeaderService.GetPurchaseQuotationPendingToSubmit(pd.DocTypeId, User.Identity.Name).Count(); if (PendingtoSubmitCount > 0) { return(RedirectToAction("Index_PendingToSubmit", new { id = pd.DocTypeId, IndexType = IndexType }).Success("Purchase Invoice " + pd.DocNo + " submitted successfully.")); } else { return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Success("Purchase Invoice " + pd.DocNo + " submitted successfully.")); } } return(RedirectToAction("Detail", new { id = nextId, TransactionType = "submitContinue", IndexType = IndexType }).Success("Purchase Invoice " + pd.DocNo + " submitted successfully.")); } else { return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Success("Purchase Invoice " + pd.DocNo + " submitted successfully.")); } } else { return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Warning("Record can be submitted by user " + pd.ModifiedBy + " only.")); } } return(RedirectToAction("Index", new { id = pd.DocTypeId })); }
//[ValidateAntiForgeryToken] public ActionResult _CreatePost(PurchaseQuotationLineViewModel svm) { PurchaseQuotationLine s = Mapper.Map <PurchaseQuotationLineViewModel, PurchaseQuotationLine>(svm); PurchaseQuotationHeader temp = _PurchaseQuotationHeaderService.Find(s.PurchaseQuotationHeaderId); if (svm.PurchaseQuotationLineId <= 0) { ViewBag.LineMode = "Create"; } else { ViewBag.LineMode = "Edit"; } if (svm.PurchQuotationSettings != null) { if (svm.PurchQuotationSettings.isMandatoryRate == true && svm.Rate <= 0) { ModelState.AddModelError("Rate", "The Rate field is required"); } } if (svm.Qty <= 0) { ModelState.AddModelError("Qty", "The Qty field is required"); } bool BeforeSave = true; //try //{ // if (svm.PurchaseQuotationHeaderId <= 0) // BeforeSave = PurchaseQuotationReceiveDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseQuotationHeaderId, EventModeConstants.Add), ref db); // else // BeforeSave = PurchaseQuotationReceiveDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseQuotationHeaderId, EventModeConstants.Edit), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXCL"] += message; // EventException = true; //} if (!BeforeSave) { ModelState.AddModelError("", "Validation failed before save."); } if (ModelState.IsValid && BeforeSave && !EventException) { int ProcessId = new ProcessService(_unitOfWork).Find(ProcessConstants.FullFinishing).ProcessId; if (svm.PurchaseQuotationLineId <= 0) { s.DiscountPer = svm.DiscountPer; s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.Sr = _PurchaseQuotationLineService.GetMaxSr(s.PurchaseQuotationHeaderId); s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.ObjectState = Model.ObjectState.Added; db.PurchaseQuotationLine.Add(s); if (svm.linecharges != null) { foreach (var item in svm.linecharges) { item.LineTableId = s.PurchaseQuotationLineId; item.PersonID = temp.SupplierId; item.HeaderTableId = s.PurchaseQuotationHeaderId; item.ObjectState = Model.ObjectState.Added; db.PurchaseQuotationLineCharge.Add(item); //new PurchaseQuotationLineChargeService(_unitOfWork).Create(item); } } if (svm.footercharges != null) { foreach (var item in svm.footercharges) { if (item.Id > 0) { var footercharge = new PurchaseQuotationHeaderChargeService(_unitOfWork).Find(item.Id); footercharge.Rate = item.Rate; footercharge.Amount = item.Amount; footercharge.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeaderCharge.Add(footercharge); //new PurchaseQuotationHeaderChargeService(_unitOfWork).Update(footercharge); } else { item.HeaderTableId = s.PurchaseQuotationHeaderId; item.PersonID = temp.SupplierId; item.ObjectState = Model.ObjectState.Added; db.PurchaseQuotationHeaderCharge.Add(item); //new PurchaseQuotationHeaderChargeService(_unitOfWork).Create(item); } } } if (temp.Status != (int)StatusConstants.Drafted) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; } temp.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeader.Add(temp); //try //{ // PurchaseQuotationReceiveDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseQuotationHeaderId, s.PurchaseQuotationLineId, EventModeConstants.Add), 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; PrepareViewBag(null); return(PartialView("_Create", svm)); } //try //{ // PurchaseQuotationReceiveDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseQuotationHeaderId, s.PurchaseQuotationLineId, EventModeConstants.Add), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXCL"] += message; //} LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.PurchaseQuotationHeaderId, DocLineId = s.PurchaseQuotationLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp.DocNo, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("_Create", new { id = s.PurchaseQuotationHeaderId, sid = svm.SupplierId, IsIndentBased = (svm.PurchaseIndentLineId.HasValue && svm.PurchaseIndentLineId.Value > 0 ? true : false) })); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); PurchaseQuotationHeader header = _PurchaseQuotationHeaderService.Find(svm.PurchaseQuotationHeaderId); int status = header.Status; PurchaseQuotationLine temp1 = _PurchaseQuotationLineService.Find(svm.PurchaseQuotationLineId); PurchaseQuotationLine ExRecI = new PurchaseQuotationLine(); ExRecI = Mapper.Map <PurchaseQuotationLine>(temp1); temp1.DiscountPer = svm.DiscountPer; temp1.Amount = svm.Amount; temp1.UnitConversionMultiplier = svm.UnitConversionMultiplier; temp1.DealQty = svm.DealQty; temp1.DealUnitId = svm.DealUnitId; temp1.Qty = svm.Qty; temp1.Rate = svm.Rate; temp1.Remark = svm.Remark; temp1.Dimension1Id = svm.Dimension1Id; temp1.Dimension2Id = svm.Dimension2Id; temp1.Specification = svm.Specification; temp1.LotNo = svm.LotNo; temp1.ModifiedDate = DateTime.Now; temp1.ModifiedBy = User.Identity.Name; temp1.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationLine.Add(temp1); //_PurchaseQuotationLineService.Update(temp1); LogList.Add(new LogTypeViewModel { ExObj = ExRecI, Obj = temp1, }); if (header.Status != (int)StatusConstants.Drafted) { header.Status = (int)StatusConstants.Modified; header.ModifiedBy = User.Identity.Name; header.ModifiedDate = DateTime.Now; //new PurchaseQuotationHeaderService(_unitOfWork).Update(header); } header.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeader.Add(header); if (svm.linecharges != null) { foreach (var item in svm.linecharges) { var productcharge = db.PurchaseQuotationLineCharge.Find(item.Id); productcharge.Rate = item.Rate; productcharge.Amount = item.Amount; productcharge.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationLineCharge.Add(productcharge); //new PurchaseQuotationLineChargeService(_unitOfWork).Update(productcharge); } } if (svm.footercharges != null) { foreach (var item in svm.footercharges) { var footercharge = db.PurchaseQuotationHeaderCharge.Find(item.Id); footercharge.Rate = item.Rate; footercharge.Amount = item.Amount; footercharge.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeaderCharge.Add(footercharge); //new PurchaseQuotationHeaderChargeService(_unitOfWork).Update(footercharge); } } XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); //try //{ // PurchaseQuotationReceiveDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(temp1.PurchaseQuotationHeaderId, temp1.PurchaseQuotationLineId, EventModeConstants.Edit), 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; PrepareViewBag(null); return(PartialView("_Create", svm)); } //try //{ // PurchaseQuotationReceiveDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(temp1.PurchaseQuotationHeaderId, temp1.PurchaseQuotationLineId, EventModeConstants.Edit), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; //} //Saving the Activity Log LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp1.PurchaseQuotationHeaderId, DocLineId = temp1.PurchaseQuotationLineId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); //End of Saving the Activity Log return(Json(new { success = true })); } } PrepareViewBag(svm); return(PartialView("_Create", svm)); }
public ActionResult Reviewed(int Id, string IndexType, string UserRemark, string IsContinue) { bool BeforeSave = true; //try //{ // BeforeSave = PurchaseQuotationReceiveDocEvents.beforeHeaderReviewEvent(this, new PurchaseEventArgs(Id), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; // EventException = true; //} if (!BeforeSave) { TempData["CSEXC"] += "Falied validation before submit."; } PurchaseQuotationHeader pd = _PurchaseQuotationHeaderService.Find(Id); if (ModelState.IsValid && BeforeSave && !EventException) { pd.ReviewCount = (pd.ReviewCount ?? 0) + 1; pd.ReviewBy += User.Identity.Name + ", "; pd.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeader.Add(pd); //try //{ // PurchaseQuotationReceiveDocEvents.onHeaderReviewEvent(this, new PurchaseEventArgs(Id), 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; return(RedirectToAction("Index", new { id = pd.DocTypeId })); } //try //{ // PurchaseQuotationReceiveDocEvents.afterHeaderReviewEvent(this, new PurchaseEventArgs(Id), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; //} LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pd.DocTypeId, DocId = pd.PurchaseQuotationHeaderId, ActivityType = (int)ActivityTypeContants.Reviewed, UserRemark = UserRemark, DocNo = pd.DocNo, DocDate = pd.DocDate, DocStatus = pd.Status, })); if (!string.IsNullOrEmpty(IsContinue) && IsContinue == "True") { PurchaseQuotationHeader HEader = _PurchaseQuotationHeaderService.Find(Id); int nextId = new NextPrevIdService(_unitOfWork).GetNextPrevId(Id, HEader.DocTypeId, User.Identity.Name, ForActionConstants.PendingToReview, "Web.PurchaseQuotationHeaders", "PurchaseQuotationHeaderId", PrevNextConstants.Next); if (nextId == 0) { var PendingtoSubmitCount = _PurchaseQuotationHeaderService.GetPurchaseQuotationPendingToReview(HEader.DocTypeId, User.Identity.Name).Count(); if (PendingtoSubmitCount > 0) { return(RedirectToAction("Index_PendingToReview", new { id = HEader.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully.")); } else { return(RedirectToAction("Index", new { id = HEader.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully.")); } } ViewBag.PendingToReview = PendingToReviewCount(Id); return(RedirectToAction("Detail", new { id = nextId, transactionType = "ReviewContinue", IndexType = IndexType }).Success("Record Reviewed Successfully.")); } else { return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully.")); } } return(RedirectToAction("Index", new { id = pd.DocTypeId })); }
public ActionResult _ResultsPost(PurchaseQuotationMasterDetailModel vm) { List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>(); List <LineChargeViewModel> LineCharges = new List <LineChargeViewModel>(); int pk = 0; int ReceiptLinepk = 0; int StockPk = 0; int Cnt = 0; int Serial = _PurchaseQuotationLineService.GetMaxSr(vm.PurchaseQuotationLineViewModel.FirstOrDefault().PurchaseQuotationHeaderId); bool HeaderChargeEdit = false; PurchaseQuotationHeader Header = _PurchaseQuotationHeaderService.Find(vm.PurchaseQuotationLineViewModel.FirstOrDefault().PurchaseQuotationHeaderId); PurchaseQuotationSetting Settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); int?MaxLineId = new PurchaseQuotationLineChargeService(_unitOfWork).GetMaxProductCharge(Header.PurchaseQuotationHeaderId, "Web.PurchaseQuotationLines", "PurchaseQuotationHeaderId", "PurchaseQuotationLineId"); int PersonCount = 0; int CalculationId = Settings.CalculationId; List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>(); bool BeforeSave = true; //try //{ // BeforeSave = PurchaseQuotationReceiveDocEvents.beforeLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseQuotationLineViewModel.FirstOrDefault().PurchaseQuotationHeaderId), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXCL"] += message; // EventException = true; //} if (!BeforeSave) { ModelState.AddModelError("", "Validation failed before save"); } if (ModelState.IsValid && BeforeSave && !EventException) { int ProcessId = new ProcessService(_unitOfWork).Find(ProcessConstants.FullFinishing).ProcessId; var IndentLineIds = vm.PurchaseQuotationLineViewModel.Select(m => m.PurchaseIndentLineId).ToArray(); var IndentBalRecords = (from p in db.ViewPurchaseIndentBalance where IndentLineIds.Contains(p.PurchaseIndentLineId) select new { LineId = p.PurchaseIndentLineId, BalQty = p.BalanceQty, }).ToList(); foreach (var item in vm.PurchaseQuotationLineViewModel) { decimal balqty = IndentBalRecords.Where(m => m.LineId == item.PurchaseIndentLineId).FirstOrDefault().BalQty; if (item.Qty > 0 && (Settings.isMandatoryRate == true ? item.Rate > 0 : 1 == 1) && item.Qty <= balqty) { PurchaseGoodsReceiptLine ReceiptLine = new PurchaseGoodsReceiptLine(); var PurchaseIndentLine = new PurchaseIndentLineService(_unitOfWork).Find(item.PurchaseIndentLineId.Value); PurchaseQuotationLine line = new PurchaseQuotationLine(); line.PurchaseQuotationHeaderId = item.PurchaseQuotationHeaderId; line.UnitConversionMultiplier = item.UnitConversionMultiplier; line.Rate = item.Rate; line.PurchaseIndentLineId = item.PurchaseIndentLineId; line.DiscountPer = item.DiscountPer; line.Qty = item.Qty; line.DealUnitId = item.DealUnitId; line.DealQty = item.Qty * item.UnitConversionMultiplier; line.Amount = (line.DealQty * item.Rate); line.CreatedDate = DateTime.Now; line.ProductId = PurchaseIndentLine.ProductId; line.Dimension1Id = PurchaseIndentLine.Dimension1Id; line.Dimension2Id = PurchaseIndentLine.Dimension2Id; line.Specification = PurchaseIndentLine.Specification; line.Sr = Serial++; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.PurchaseQuotationLineId = pk; line.ObjectState = Model.ObjectState.Added; //_PurchaseQuotationLineService.Create(line); db.PurchaseQuotationLine.Add(line); LineList.Add(new LineDetailListViewModel { Amount = line.Amount, Rate = line.Rate, LineTableId = line.PurchaseQuotationLineId, HeaderTableId = item.PurchaseQuotationHeaderId, PersonID = Header.SupplierId }); pk++; StockPk++; } } if (Header.Status != (int)StatusConstants.Drafted) { Header.Status = (int)StatusConstants.Modified; Header.ModifiedBy = User.Identity.Name; Header.ModifiedDate = DateTime.Now; } Header.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeader.Add(Header); //new PurchaseGoodsReceiptHeaderService(_unitOfWork).Update(ReceiptHeader); new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, vm.PurchaseQuotationLineViewModel.FirstOrDefault().PurchaseQuotationHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.PurchaseQuotationHeaderCharges", "Web.PurchaseQuotationLineCharges", out PersonCount, Header.DocTypeId, Header.SiteId, Header.DivisionId); //Saving Charges foreach (var item in LineCharges) { PurchaseQuotationLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, PurchaseQuotationLineCharge>(item); PoLineCharge.ObjectState = Model.ObjectState.Added; db.PurchaseQuotationLineCharge.Add(PoLineCharge); //new PurchaseQuotationLineChargeService(_unitOfWork).Create(PoLineCharge); } //Saving Header charges for (int i = 0; i < HeaderCharges.Count(); i++) { if (!HeaderChargeEdit) { PurchaseQuotationHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, PurchaseQuotationHeaderCharge>(HeaderCharges[i]); POHeaderCharge.HeaderTableId = vm.PurchaseQuotationLineViewModel.FirstOrDefault().PurchaseQuotationHeaderId; POHeaderCharge.PersonID = Header.SupplierId; POHeaderCharge.ObjectState = Model.ObjectState.Added; db.PurchaseQuotationHeaderCharge.Add(POHeaderCharge); //new PurchaseQuotationHeaderChargeService(_unitOfWork).Create(POHeaderCharge); } else { var footercharge = new PurchaseQuotationHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id); footercharge.Rate = HeaderCharges[i].Rate; footercharge.Amount = HeaderCharges[i].Amount; footercharge.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeaderCharge.Add(footercharge); //new PurchaseQuotationHeaderChargeService(_unitOfWork).Update(footercharge); } } //try //{ // PurchaseQuotationReceiveDocEvents.onLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseQuotationLineViewModel.FirstOrDefault().PurchaseQuotationHeaderId), 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("_IndentResults", vm)); } //try //{ // PurchaseQuotationReceiveDocEvents.afterLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseQuotationLineViewModel.FirstOrDefault().PurchaseQuotationHeaderId), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; //} LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = Header.DocTypeId, DocId = Header.PurchaseQuotationHeaderId, ActivityType = (int)ActivityTypeContants.MultipleCreate, DocNo = Header.DocNo, DocDate = Header.DocDate, DocStatus = Header.Status, })); return(Json(new { success = true })); } return(PartialView("_IndentResults", vm)); }
public void Delete(PurchaseQuotationHeader s) { s.ObjectState = Model.ObjectState.Deleted; db.PurchaseQuotationHeader.Remove(s); }