private void PrepareViewBag(RequisitionLineViewModel vm) { ViewBag.DeliveryUnitList = new UnitService(_unitOfWork).GetUnitList().ToList(); RequisitionHeaderViewModel H = new RequisitionHeaderService(_unitOfWork).GetRequisitionHeader(vm.RequisitionHeaderId); ViewBag.DocNo = H.DocTypeName + "-" + H.DocNo; }
private ActionResult _Modify(int id) { RequisitionLineViewModel temp = _RequisitionLineService.GetRequisitionLine(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 = "Edit"; } RequisitionHeader H = new RequisitionHeaderService(_unitOfWork).Find(temp.RequisitionHeaderId); //Getting Settings var settings = new MaterialRequestSettingsService(_unitOfWork).GetMaterialRequestSettingsForDocument(H.DocTypeId, H.DivisionId, H.SiteId); temp.MaterialRequestSettings = Mapper.Map <MaterialRequestSettings, MaterialRequestSettingsViewModel>(settings); PrepareViewBag(temp); return(PartialView("_Create", temp)); }
private ActionResult _Detail(int id) { RequisitionLineViewModel temp = _RequisitionLineService.GetRequisitionLine(id); RequisitionHeader H = new RequisitionHeaderService(_unitOfWork).Find(temp.RequisitionHeaderId); //Getting Settings var settings = new MaterialRequestSettingsService(_unitOfWork).GetMaterialRequestSettingsForDocument(H.DocTypeId, H.DivisionId, H.SiteId); temp.MaterialRequestSettings = Mapper.Map <MaterialRequestSettings, MaterialRequestSettingsViewModel>(settings); if (temp == null) { return(HttpNotFound()); } PrepareViewBag(temp); return(PartialView("_Create", temp)); }
public ActionResult _Create(int Id) //Id ==>Sale Order Header Id { RequisitionHeader H = new RequisitionHeaderService(_unitOfWork).Find(Id); RequisitionLineViewModel s = new RequisitionLineViewModel(); //Getting Settings var settings = new MaterialRequestSettingsService(_unitOfWork).GetMaterialRequestSettingsForDocument(H.DocTypeId, H.DivisionId, H.SiteId); s.MaterialRequestSettings = Mapper.Map <MaterialRequestSettings, MaterialRequestSettingsViewModel>(settings); s.RequisitionHeaderId = H.RequisitionHeaderId; ViewBag.Status = H.Status; PrepareViewBag(s); if (!string.IsNullOrEmpty((string)TempData["CSEXCL"])) { ViewBag.CSEXCL = TempData["CSEXCL"]; TempData["CSEXCL"] = null; } ViewBag.LineMode = "Create"; return(PartialView("_Create", s)); }
public RequisitionLineViewModel GetRequsitionLineDetail(int RequistionLineId) { RequisitionLineViewModel temp = new RequisitionLineViewModel(); return((from b in db.ViewMaterialRequestBalance join t3 in db.RequisitionLine on b.RequisitionLineId equals t3.RequisitionLineId into table3 from requlinetab in table3.DefaultIfEmpty() join t in db.Dimension1 on b.Dimension1Id equals t.Dimension1Id into table from dimtab in table.DefaultIfEmpty() join t2 in db.Dimension2 on b.Dimension2Id equals t2.Dimension2Id into table2 from dim2tab in table2.DefaultIfEmpty() join t4 in db.Product on b.ProductId equals t4.ProductId into table4 from prodtab in table4.DefaultIfEmpty() where b.RequisitionLineId == RequistionLineId select new RequisitionLineViewModel { Qty = b.BalanceQty, Specification = requlinetab.Specification, Dimension1Id = dimtab.Dimension1Id, Dimension1Name = dimtab.Dimension1Name, Dimension2Id = dim2tab.Dimension2Id, Dimension2Name = dim2tab.Dimension2Name, UnitId = prodtab.UnitId, ProcessId = requlinetab.ProcessId, ProcessName = requlinetab.Process.ProcessName, }).FirstOrDefault()); }
public ActionResult DeletePost(RequisitionLineViewModel vm) { bool BeforeSave = true; try { BeforeSave = MaterialRequestDocEvents.beforeLineDeleteEvent(this, new StockEventArgs(vm.RequisitionHeaderId, vm.RequisitionLineId), 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>(); //RequisitionLine RequisitionLine = _RequisitionLineService.Find(vm.RequisitionLineId); RequisitionLine RequisitionLine = (from p in db.RequisitionLine where p.RequisitionLineId == vm.RequisitionLineId select p).FirstOrDefault(); RequisitionLineStatus LineStat = (from p in db.RequisitionLineStatus where p.RequisitionLineId == vm.RequisitionLineId select p).FirstOrDefault(); RequisitionHeader header = new RequisitionHeaderService(_unitOfWork).Find(RequisitionLine.RequisitionHeaderId); RequisitionLine ExRec = new RequisitionLine(); ExRec = Mapper.Map <RequisitionLine>(RequisitionLine); LogList.Add(new LogTypeViewModel { ExObj = ExRec, }); //new RequisitionLineStatusService(_unitOfWork).Delete(RequisitionLine.RequisitionLineId); if (LineStat != null) { LineStat.ObjectState = Model.ObjectState.Deleted; db.RequisitionLineStatus.Remove(LineStat); } RequisitionLine.ObjectState = Model.ObjectState.Deleted; db.RequisitionLine.Remove(RequisitionLine); //_RequisitionLineService.Delete(RequisitionLine); 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.RequisitionHeader.Add(header); //new RequisitionHeaderService(_unitOfWork).Update(header); } XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { MaterialRequestDocEvents.onLineDeleteEvent(this, new StockEventArgs(RequisitionLine.RequisitionHeaderId, RequisitionLine.RequisitionLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; ViewBag.LineMode = "Delete"; return(PartialView("_Create", vm)); } try { MaterialRequestDocEvents.afterLineDeleteEvent(this, new StockEventArgs(RequisitionLine.RequisitionHeaderId, RequisitionLine.RequisitionLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = header.DocTypeId, DocId = header.RequisitionHeaderId, DocLineId = RequisitionLine.RequisitionLineId, ActivityType = (int)ActivityTypeContants.Deleted, DocNo = header.DocNo, xEModifications = Modifications, DocDate = header.DocDate, DocStatus = header.Status, })); } return(Json(new { success = true })); }
public ActionResult _CreatePost(RequisitionLineViewModel svm) { RequisitionHeader temp = new RequisitionHeaderService(_unitOfWork).Find(svm.RequisitionHeaderId); RequisitionLine s = Mapper.Map <RequisitionLineViewModel, RequisitionLine>(svm); if (svm.MaterialRequestSettings != null) { if (svm.MaterialRequestSettings.isMandatoryProcessLine == true && (svm.ProcessId <= 0 || svm.ProcessId == null)) { ModelState.AddModelError("ProcessId", "The Process field is required"); } } bool BeforeSave = true; try { if (svm.RequisitionLineId <= 0) { BeforeSave = MaterialRequestDocEvents.beforeLineSaveEvent(this, new StockEventArgs(svm.RequisitionHeaderId, EventModeConstants.Add), ref db); } else { BeforeSave = MaterialRequestDocEvents.beforeLineSaveEvent(this, new StockEventArgs(svm.RequisitionHeaderId, 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 (svm.Qty <= 0) { ModelState.AddModelError("Qty", "The Qty field is required"); } if (svm.RequisitionLineId <= 0) { ViewBag.LineMode = "Create"; } else { ViewBag.LineMode = "Edit"; } if (ModelState.IsValid && BeforeSave && !EventException) { if (svm.RequisitionLineId <= 0) { s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.ObjectState = Model.ObjectState.Added; //_RequisitionLineService.Create(s); db.RequisitionLine.Add(s); new RequisitionLineStatusService(_unitOfWork).CreateLineStatus(s.RequisitionLineId, ref db); //RequisitionHeader header = new RequisitionHeaderService(_unitOfWork).Find(s.RequisitionHeaderId); 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.RequisitionHeader.Add(temp); //new RequisitionHeaderService(_unitOfWork).Update(temp); } try { MaterialRequestDocEvents.onLineSaveEvent(this, new StockEventArgs(s.RequisitionHeaderId, s.RequisitionLineId, 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(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; PrepareViewBag(svm); return(PartialView("_Create", svm)); } try { MaterialRequestDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.RequisitionHeaderId, s.RequisitionLineId, 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.RequisitionHeaderId, DocLineId = s.RequisitionLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp.DocNo, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("_Create", new { id = svm.RequisitionHeaderId })); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); RequisitionLine templine = _RequisitionLineService.Find(s.RequisitionLineId); int Status = temp.Status; RequisitionLine ExRec = new RequisitionLine(); ExRec = Mapper.Map <RequisitionLine>(templine); templine.ProductId = s.ProductId; templine.Specification = s.Specification; templine.Dimension1Id = s.Dimension1Id; templine.Dimension2Id = s.Dimension2Id; templine.Dimension3Id = s.Dimension3Id; templine.Dimension4Id = s.Dimension4Id; templine.ProcessId = s.ProcessId; templine.DueDate = s.DueDate; templine.Remark = s.Remark; templine.Qty = s.Qty; templine.ModifiedDate = DateTime.Now; templine.ModifiedBy = User.Identity.Name; //_RequisitionLineService.Update(templine); templine.ObjectState = Model.ObjectState.Modified; db.RequisitionLine.Add(templine); if (temp.Status != (int)StatusConstants.Drafted) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedBy = User.Identity.Name; temp.ModifiedDate = DateTime.Now; temp.ObjectState = Model.ObjectState.Modified; db.RequisitionHeader.Add(temp); //new RequisitionHeaderService(_unitOfWork).Update(temp); } LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = templine, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { MaterialRequestDocEvents.onLineSaveEvent(this, new StockEventArgs(s.RequisitionHeaderId, templine.RequisitionLineId, 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(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; PrepareViewBag(svm); return(PartialView("_Create", svm)); } try { MaterialRequestDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.RequisitionHeaderId, templine.RequisitionLineId, 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 = templine.RequisitionHeaderId, DocLineId = templine.RequisitionLineId, 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 static LinhasRequisição ParseToDB(this RequisitionLineViewModel item) { if (item != null) { return(new LinhasRequisição() { NºRequisição = item.RequestNo, NºLinha = item.LineNo.HasValue ? item.LineNo.Value : 0, Tipo = item.Type, Código = item.Code, Descrição = item.Description, Descrição2 = item.Description2, CódigoUnidadeMedida = item.UnitMeasureCode, CódigoLocalização = item.LocalCode, MercadoLocal = item.LocalMarket == null ? false : item.LocalMarket, QuantidadeARequerer = item.QuantityToRequire, QuantidadeRequerida = item.QuantityRequired, QuantidadeADisponibilizar = item.QuantityToProvide, QuantidadeDisponibilizada = item.QuantityAvailable, QuantidadeAReceber = item.QuantityReceivable, QuantidadeRecebida = item.QuantityReceived, QuantidadePendente = item.QuantityPending, CustoUnitário = item.UnitCost, CustoUnitarioComIVA = item.UnitCostWithIVA, DataReceçãoEsperada = string.IsNullOrEmpty(item.ExpectedReceivingDate) ? (DateTime?)null : DateTime.Parse(item.ExpectedReceivingDate), Faturável = item.Billable == null ? false : item.Billable, NºProjeto = item.ProjectNo, CódigoRegião = item.RegionCode, CódigoÁreaFuncional = item.FunctionalAreaCode, CódigoCentroResponsabilidade = item.CenterResponsibilityCode, NºFuncionário = item.FunctionalNo, Viatura = item.Vehicle, DataHoraCriação = item.CreateDateTime, UtilizadorCriação = item.CreateUser, DataHoraModificação = item.UpdateDateTime, UtilizadorModificação = item.UpdateUser, QtdPorUnidadeDeMedida = item.QtyByUnitOfMeasure, PreçoUnitárioVenda = item.UnitCostsould, ValorOrçamento = item.BudgetValue, NºLinhaOrdemManutenção = item.MaintenanceOrderLineNo, CriarNotaEncomenda = item.CriarNotaEncomenda == null ? false : item.CriarNotaEncomenda, CriarConsultaMercado = item.CreateMarketSearch == null ? false : item.CreateMarketSearch, EnviarPréCompra = item.SendPrePurchase == null ? false : item.SendPrePurchase, EnviadoPréCompra = item.SubmitPrePurchase == null ? false : item.SubmitPrePurchase, DataMercadoLocal = string.IsNullOrEmpty(item.LocalMarketDate) ? (DateTime?)null : DateTime.Parse(item.LocalMarketDate), UserMercadoLocal = item.LocalMarketUser, EnviadoParaCompras = item.SendForPurchase == null ? false : item.SendForPurchase, DataEnvioParaCompras = string.IsNullOrEmpty(item.SendForPurchaseDate) ? (DateTime?)null : DateTime.Parse(item.SendForPurchaseDate), ValidadoCompras = item.PurchaseValidated == null ? false : item.PurchaseValidated, RecusadoCompras = item.PurchaseRefused == null ? false : item.PurchaseRefused, MotivoRecusaMercLocal = item.ReasonToRejectionLocalMarket, DataRecusaMercLocal = string.IsNullOrEmpty(item.RejectionLocalMarketDate) ? (DateTime?)null : DateTime.Parse(item.RejectionLocalMarketDate), IdCompra = item.PurchaseId, NºFornecedor = item.SupplierNo, NºEncomendaAberto = item.OpenOrderNo, NºLinhaEncomendaAberto = item.OpenOrderLineNo, NºDeConsultaMercadoCriada = item.QueryCreatedMarketNo, NºEncomendaCriada = item.CreatedOrderNo, CódigoProdutoFornecedor = item.SupplierProductCode, UnidadeProdutivaNutrição = item.UnitNutritionProduction, RegiãoMercadoLocal = item.MarketLocalRegion, NºCliente = item.CustomerNo, Aprovadores = item.Approvers, Urgente = item.Urgent, GrupoRegistoIvanegocio = item.VATBusinessPostingGroup, GrupoRegistoIvaproduto = item.VATProductPostingGroup, PercentagemDesconto = item.DiscountPercentage.HasValue ? item.DiscountPercentage.Value : (decimal?)null, QuantidadeInicial = item.QuantidadeInicial.HasValue ? item.QuantidadeInicial.Value : (decimal?)null, SemEfeito = item.SemEfeito == null ? false : item.SemEfeito }); } return(null); }