private ActionResult _Delete(int id) { PurchaseInvoiceLineViewModel temp = _PurchaseInvoiceLineService.GetPurchaseInvoiceLine(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"; } PurchaseInvoiceHeader H = new PurchaseInvoiceHeaderService(_unitOfWork).Find(temp.PurchaseInvoiceHeaderId); PrepareViewBag(temp); //Getting Settings var settings = new PurchaseInvoiceSettingService(_unitOfWork).GetPurchaseInvoiceSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId); temp.PurchInvoiceSettings = Mapper.Map <PurchaseInvoiceSetting, PurchaseInvoiceSettingsViewModel>(settings); temp.DocumentTypeSettings = new DocumentTypeSettingsService(_unitOfWork).GetDocumentTypeSettingsForDocument(H.DocTypeId); return(PartialView("_Create", temp)); }
public ActionResult _Detail(int id) { PurchaseInvoiceLineViewModel temp = _PurchaseInvoiceLineService.GetPurchaseInvoiceLine(id); PurchaseInvoiceHeader H = new PurchaseInvoiceHeaderService(_unitOfWork).Find(temp.PurchaseInvoiceHeaderId); PrepareViewBag(temp); //Getting Settings var settings = new PurchaseInvoiceSettingService(_unitOfWork).GetPurchaseInvoiceSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId); temp.PurchInvoiceSettings = Mapper.Map <PurchaseInvoiceSetting, PurchaseInvoiceSettingsViewModel>(settings); if (temp == null) { return(HttpNotFound()); } return(PartialView("_Create", temp)); }
public ActionResult _Create(int Id, int sid) //Id ==>Sale Order Header Id { PurchaseInvoiceHeader H = new PurchaseInvoiceHeaderService(_unitOfWork).Find(Id); PurchaseInvoiceLineViewModel s = new PurchaseInvoiceLineViewModel(); //Getting Settings var settings = new PurchaseInvoiceSettingService(_unitOfWork).GetPurchaseInvoiceSettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId); s.PurchInvoiceSettings = Mapper.Map <PurchaseInvoiceSetting, PurchaseInvoiceSettingsViewModel>(settings); s.DocumentTypeSettings = new DocumentTypeSettingsService(_unitOfWork).GetDocumentTypeSettingsForDocument(H.DocTypeId); s.PurchaseInvoiceHeaderId = H.PurchaseInvoiceHeaderId; s.PurchaseInvoiceHeaderDocNo = H.DocNo; s.SupplierId = sid; s.DocTypeId = H.DocTypeId; s.SiteId = H.SiteId; s.DivisionId = H.DivisionId; ViewBag.LineMode = "Create"; PrepareViewBag(null); return(PartialView("_Create", s)); }
public ActionResult DeletePost(PurchaseInvoiceLineViewModel vm) { bool BeforeSave = true; try { BeforeSave = PurchaseInvoiceDocEvents.beforeLineDeleteEvent(this, new PurchaseEventArgs(vm.PurchaseInvoiceHeaderId, vm.PurchaseInvoiceLineId), 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>(); PurchaseInvoiceLine PurchaseInvoiceLine = db.PurchaseInvoiceLine.Find(vm.PurchaseInvoiceLineId); try { PurchaseInvoiceDocEvents.onLineDeleteEvent(this, new PurchaseEventArgs(PurchaseInvoiceLine.PurchaseInvoiceHeaderId, PurchaseInvoiceLine.PurchaseInvoiceLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } LogList.Add(new LogTypeViewModel { ExObj = Mapper.Map <PurchaseInvoiceLine>(PurchaseInvoiceLine), }); PurchaseInvoiceHeader header = db.PurchaseInvoiceHeader.Find(PurchaseInvoiceLine.PurchaseInvoiceHeaderId); new PurchaseOrderLineStatusService(_unitOfWork).UpdatePurchaseQtyOnInvoice(PurchaseInvoiceLine.PurchaseGoodsReceiptLineId, PurchaseInvoiceLine.PurchaseInvoiceLineId, header.DocDate, 0, ref db, true); var chargeslist = (from p in db.PurchaseInvoiceLineCharge where p.LineTableId == PurchaseInvoiceLine.PurchaseInvoiceLineId select p).ToList(); if (chargeslist != null) { foreach (var item in chargeslist) { item.ObjectState = Model.ObjectState.Deleted; db.PurchaseInvoiceLineCharge.Remove(item); //new PurchaseInvoiceLineChargeService(_unitOfWork).Delete(item.Id); } } PurchaseInvoiceLine.ObjectState = Model.ObjectState.Deleted; db.PurchaseInvoiceLine.Remove(PurchaseInvoiceLine); if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import) { header.Status = (int)StatusConstants.Modified; header.ModifiedDate = DateTime.Now; header.ModifiedBy = User.Identity.Name; //new PurchaseInvoiceHeaderService(_unitOfWork).Update(header); } header.ObjectState = Model.ObjectState.Modified; db.PurchaseInvoiceHeader.Add(header); if (vm.footercharges != null) { foreach (var item in vm.footercharges) { var footer = db.PurchaseInvoiceHeaderCharge.Find(item.Id); footer.Rate = item.Rate; footer.Amount = item.Amount; footer.ObjectState = Model.ObjectState.Modified; db.PurchaseInvoiceHeaderCharge.Add(footer); //new PurchaseInvoiceHeaderChargeService(_unitOfWork).Update(footer); } } 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 { PurchaseInvoiceDocEvents.afterLineDeleteEvent(this, new PurchaseEventArgs(PurchaseInvoiceLine.PurchaseInvoiceHeaderId, PurchaseInvoiceLine.PurchaseInvoiceLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = header.DocTypeId, DocId = header.PurchaseInvoiceHeaderId, DocLineId = PurchaseInvoiceLine.PurchaseInvoiceLineId, ActivityType = (int)ActivityTypeContants.Deleted, DocNo = header.DocNo, xEModifications = Modifications, DocDate = header.DocDate, DocStatus = header.Status, })); } return(Json(new { success = true })); }
//[ValidateAntiForgeryToken] public ActionResult _CreatePost(PurchaseInvoiceLineViewModel svm) { PurchaseInvoiceLine s = Mapper.Map <PurchaseInvoiceLineViewModel, PurchaseInvoiceLine>(svm); PurchaseInvoiceHeader temp = new PurchaseInvoiceHeaderService(_unitOfWork).Find(s.PurchaseInvoiceHeaderId); if (svm.PurchaseInvoiceLineId <= 0) { ViewBag.LineMode = "Create"; } else { ViewBag.LineMode = "Edit"; } if (svm.PurchInvoiceSettings != null) { if (svm.PurchInvoiceSettings.isMandatoryRate == true && svm.Rate <= 0) { ModelState.AddModelError("Rate", "The Rate field is required"); } } if (svm.PurchaseGoodsReceiptLineId == 0) { ModelState.AddModelError("PurchaseGoodsReceiptLineId", "Goods Receipt field is required"); } if (svm.DealQty <= 0) { ModelState.AddModelError("DealQty", "DealQty field is required"); } bool BeforeSave = true; try { if (svm.PurchaseInvoiceLineId <= 0) { BeforeSave = PurchaseInvoiceDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseInvoiceHeaderId, EventModeConstants.Add), ref db); } else { BeforeSave = PurchaseInvoiceDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseInvoiceHeaderId, 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) { if (svm.PurchaseInvoiceLineId <= 0) { s.DiscountPer = svm.DiscountPer; s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.Sr = _PurchaseInvoiceLineService.GetMaxSr(s.PurchaseInvoiceHeaderId); s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.ObjectState = Model.ObjectState.Added; db.PurchaseInvoiceLine.Add(s); //_PurchaseInvoiceLineService.Create(s); new PurchaseOrderLineStatusService(_unitOfWork).UpdatePurchaseQtyOnInvoice(s.PurchaseGoodsReceiptLineId, s.PurchaseInvoiceLineId, temp.DocDate, s.DocQty, ref db, true); if (svm.linecharges != null) { foreach (var item in svm.linecharges) { item.LineTableId = s.PurchaseInvoiceLineId; item.PersonID = temp.SupplierId; item.HeaderTableId = s.PurchaseInvoiceHeaderId; item.ObjectState = Model.ObjectState.Added; db.PurchaseInvoiceLineCharge.Add(item); //new PurchaseInvoiceLineChargeService(_unitOfWork).Create(item); } } if (svm.footercharges != null) { foreach (var item in svm.footercharges) { if (item.Id > 0) { var footercharge = new PurchaseInvoiceHeaderChargeService(_unitOfWork).Find(item.Id); footercharge.Rate = item.Rate; footercharge.Amount = item.Amount; footercharge.ObjectState = Model.ObjectState.Modified; db.PurchaseInvoiceHeaderCharge.Add(footercharge); //new PurchaseInvoiceHeaderChargeService(_unitOfWork).Update(footercharge); } else { item.HeaderTableId = s.PurchaseInvoiceHeaderId; item.PersonID = temp.SupplierId; item.ObjectState = Model.ObjectState.Added; db.PurchaseInvoiceHeaderCharge.Add(item); //new PurchaseInvoiceHeaderChargeService(_unitOfWork).Create(item); } } } if (temp.Status != (int)StatusConstants.Drafted) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedBy = User.Identity.Name; temp.ModifiedDate = DateTime.Now; //new PurchaseInvoiceHeaderService(_unitOfWork).Update(temp); } temp.ObjectState = Model.ObjectState.Modified; db.PurchaseInvoiceHeader.Add(temp); try { PurchaseInvoiceDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseInvoiceHeaderId, s.PurchaseInvoiceLineId, 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 { PurchaseInvoiceDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseInvoiceHeaderId, s.PurchaseInvoiceLineId, 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.PurchaseInvoiceHeaderId, DocLineId = s.PurchaseInvoiceLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp.DocNo, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("_Create", new { id = s.PurchaseInvoiceHeaderId, sid = svm.SupplierId })); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); PurchaseInvoiceHeader header = new PurchaseInvoiceHeaderService(_unitOfWork).Find(svm.PurchaseInvoiceHeaderId); StringBuilder logstring = new StringBuilder(); int status = header.Status; PurchaseInvoiceLine temp1 = db.PurchaseInvoiceLine.Find(svm.PurchaseInvoiceLineId); PurchaseInvoiceLine ExRec = new PurchaseInvoiceLine(); ExRec = Mapper.Map <PurchaseInvoiceLine>(temp1); temp1.DiscountPer = svm.DiscountPer; temp1.Amount = svm.Amount; //temp1.PurchaseGoodsReceiptLineId = svm.PurchaseGoodsReceiptLineId; temp1.UnitConversionMultiplier = svm.UnitConversionMultiplier; temp1.DealQty = svm.DealQty; temp1.DealUnitId = svm.DealUnitId; temp1.Rate = svm.Rate; temp1.Remark = svm.Remark; temp1.ModifiedDate = DateTime.Now; temp1.ModifiedBy = User.Identity.Name; temp1.ObjectState = Model.ObjectState.Modified; db.PurchaseInvoiceLine.Add(temp1); //_PurchaseInvoiceLineService.Update(temp1); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp1, }); new PurchaseOrderLineStatusService(_unitOfWork).UpdatePurchaseQtyOnInvoice(temp1.PurchaseGoodsReceiptLineId, temp1.PurchaseInvoiceLineId, temp.DocDate, temp1.DocQty, ref db, true); if (header.Status != (int)StatusConstants.Drafted) { header.Status = (int)StatusConstants.Modified; header.ModifiedBy = User.Identity.Name; header.ModifiedDate = DateTime.Now; //new PurchaseInvoiceHeaderService(_unitOfWork).Update(header); } header.ObjectState = Model.ObjectState.Modified; db.PurchaseInvoiceHeader.Add(header); if (svm.linecharges != null) { foreach (var item in svm.linecharges) { var productcharge = db.PurchaseInvoiceLineCharge.Find(item.Id); productcharge.Rate = item.Rate; productcharge.Amount = item.Amount; productcharge.DealQty = item.DealQty; productcharge.ObjectState = Model.ObjectState.Modified; db.PurchaseInvoiceLineCharge.Add(productcharge); //new PurchaseInvoiceLineChargeService(_unitOfWork).Update(productcharge); } } if (svm.footercharges != null) { foreach (var item in svm.footercharges) { var footercharge = db.PurchaseInvoiceHeaderCharge.Find(item.Id); footercharge.Rate = item.Rate; footercharge.Amount = item.Amount; footercharge.ObjectState = Model.ObjectState.Modified; db.PurchaseInvoiceHeaderCharge.Add(footercharge); //new PurchaseInvoiceHeaderChargeService(_unitOfWork).Update(footercharge); } } XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { PurchaseInvoiceDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(temp1.PurchaseInvoiceHeaderId, temp1.PurchaseInvoiceLineId, 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 { PurchaseInvoiceDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(temp1.PurchaseInvoiceHeaderId, temp1.PurchaseInvoiceLineId, 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.PurchaseInvoiceHeaderId, DocLineId = temp1.PurchaseInvoiceLineId, 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)); }
private void PrepareViewBag(PurchaseInvoiceLineViewModel vm) { ViewBag.DeliveryUnitList = new UnitService(_unitOfWork).GetUnitList().ToList(); }