private void AddStockLineProperty(StockLine stockLine) { for (int i = 0; i < row; i++) { var stockLineProperty = StockLineProperty.Create($"name{i}", $"value{i}"); stockLine.AddStockLineProperty(stockLineProperty); } }
private void AddStockLineAction(StockLine stockLine) { for (int i = 0; i < row; i++) { var stockLineAction = StockLineAction.Create($"name{i}"); AddStockLineActionProperty(stockLineAction); stockLine.AddStockLineAction(stockLineAction); } }
private void AddStockLines(InvoiceOrder order) { for (int i = 0; i < 20; i++) { var stockLine = StockLine.Create($"prodict{i}"); AddStockLineProperty(stockLine); AddStockLineAction(stockLine); order.AddStockLine(stockLine); } }
/// <summary> /// Adds a new symbol to the list /// </summary> /// <param name="group">The group the symbol should be added as part of</param> /// <param name="symbol">The ticker symbol to add</param> /// <param name="infoPanel">A panel that displays information about the stock</param> private void AddInternal(string group, string symbol, SummaryPanel infoPanel) { DataAccessor.Subscription sub = null; if (infoPanel == null) { sub = DataAccessor.Subscribe(symbol, DataAccessor.SUBSCRIBE_FIVE_SEC); infoPanel = new PercentageChangeSummary(sub); } // Ensure the symbol is not already in the list bool isNew = true; List <StockLine> stockList; if (!Stocks.TryGetValue(group, out stockList)) { stockList = new List <StockLine>(); Stocks.Add(group, stockList); if (!GroupOrder.Contains(group)) { GroupOrder.Add(group); } GroupLabels.Add(group, new Label()); Controls.Add(GroupLabels[group]); } for (int i = 0; i < stockList.Count; i++) { if (stockList[i].Symbol.Equals(symbol)) { isNew = false; break; } } if (isNew) { StockLine newLine = new StockLine(symbol, this, infoPanel); newLine.Location = new System.Drawing.Point(5, (int)((Stocks.Count + 0.5) * (newLine.Height + 5))); newLine.MouseUp += (sender, e) => { AddStockUi(symbol); }; stockList.Add(newLine); this.Controls.Add(newLine); this.Refresh(); // Request data to fill the summary chart newLine.SummaryChart.RequestData(DateTime.Now.Date.AddHours(-12), DateTime.Now.Date.AddHours(16), new TimeSpan(0, 1, 0)); } }
/// <summary> /// Removes the specified line from the list /// </summary> /// <param name="item"></param> public void Remove(StockLine item) { foreach (var stockList in Stocks) { if (stockList.Value.Contains(item)) { this.Controls.Remove(item); item.InfoPanel.Destroy(); stockList.Value.Remove(item); // Check if the group is now empty if (stockList.Value.Count == 0) { Stocks.Remove(stockList.Key); Controls.Remove(GroupLabels[stockList.Key]); GroupLabels.Remove(stockList.Key); } // Redraw the list Refresh(); break; } } }
public ActionResult Delete(ReasonViewModel vm) { bool BeforeSave = true; try { BeforeSave = StockHeaderDocEvents.beforeHeaderDeleteEvent(this, new StockEventArgs(vm.id), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before delete"; } StockHeader StockHeader = (from p in context.StockHeader where p.StockHeaderId == vm.id select p).FirstOrDefault(); var GatePassHeader = (from p in context.GatePassHeader where p.GatePassHeaderId == StockHeader.GatePassHeaderId select p).FirstOrDefault(); if (GatePassHeader != null && GatePassHeader.Status == (int)StatusConstants.Submitted) { BeforeSave = false; TempData["CSEXC"] += "Cannot delete record because gatepass is submitted."; } if (ModelState.IsValid && BeforeSave && !EventException) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); try { StockHeaderDocEvents.onHeaderDeleteEvent(this, new StockEventArgs(vm.id), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } StockHeader ExRec = new StockHeader(); ExRec = Mapper.Map <StockHeader>(StockHeader); StockHeader Rec = new StockHeader(); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = Rec, }); var StockLine = (from p in context.StockLine where p.StockHeaderId == vm.id select p).ToList(); //Mark ObjectState.Delete to all the Purchase Order Lines. foreach (var item in StockLine) { StockLine ExRecLine = new StockLine(); ExRecLine = Mapper.Map <StockLine>(item); StockLine RecLine = new StockLine(); LogList.Add(new LogTypeViewModel { ExObj = ExRecLine, Obj = RecLine, }); item.ObjectState = Model.ObjectState.Deleted; context.StockLine.Remove(item); } var GatePassHeaderId = StockHeader.GatePassHeaderId; StockHeader.ObjectState = Model.ObjectState.Deleted; context.StockHeader.Remove(StockHeader); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); //Commit the DB try { if (EventException) { throw new Exception(); } context.SaveChanges(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; return(PartialView("_Reason", vm)); } try { StockHeaderDocEvents.afterHeaderDeleteEvent(this, new StockEventArgs(vm.id), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = StockHeader.DocTypeId, DocId = StockHeader.StockHeaderId, ActivityType = (int)ActivityTypeContants.Deleted, UserRemark = vm.Reason, DocNo = StockHeader.DocNo, xEModifications = Modifications, DocDate = StockHeader.DocDate, DocStatus = StockHeader.Status, })); return(Json(new { success = true })); } return(PartialView("_Reason", vm)); }
public ActionResult DeletePost(StockLineViewModel vm) { bool BeforeSave = true; try { BeforeSave = RateConversionDocEvents.beforeLineDeleteEvent(this, new StockEventArgs(vm.StockHeaderId, vm.StockLineId), 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) { int?StockProcessId = 0; int?CostCenterId = null; List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); StockLine StockLine = (from p in db.StockLine where p.StockLineId == vm.StockLineId select p).FirstOrDefault(); CostCenterId = StockLine.CostCenterId; LogList.Add(new LogTypeViewModel { ExObj = Mapper.Map <StockLine>(StockLine), }); StockProcessId = StockLine.StockProcessId; //_StockLineService.Delete(StockLine); StockLine.ObjectState = Model.ObjectState.Deleted; db.StockLine.Remove(StockLine); if (StockProcessId != null) { new StockProcessService(_unitOfWork).DeleteStockProcessDB((int)StockProcessId, ref db, true); } StockHeader header = new StockHeaderService(_unitOfWork).Find(StockLine.StockHeaderId); 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.StockHeader.Add(header); //new StockHeaderService(_unitOfWork).Update(header); } if (CostCenterId.HasValue && CostCenterId.Value > 0) { var CostCenterStatus = db.CostCenterStatus.Find(CostCenterId); if (CostCenterStatus != null && StockLine.Amount > 0) { if (StockLine.Amount > 0) { CostCenterStatus.AmountDr = CostCenterStatus.AmountDr - StockLine.Amount; } else { CostCenterStatus.AmountCr = CostCenterStatus.AmountCr - StockLine.Amount; } CostCenterStatus.ObjectState = Model.ObjectState.Modified; db.CostCenterStatus.Add(CostCenterStatus); } } XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { RateConversionDocEvents.onLineDeleteEvent(this, new StockEventArgs(StockLine.StockHeaderId, StockLine.StockLineId), 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 { RateConversionDocEvents.afterLineDeleteEvent(this, new StockEventArgs(StockLine.StockHeaderId, StockLine.StockLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = header.DocTypeId, DocId = header.StockHeaderId, DocLineId = StockLine.StockLineId, ActivityType = (int)ActivityTypeContants.Deleted, DocNo = header.DocNo, xEModifications = Modifications, DocDate = header.DocDate, DocStatus = header.Status, })); } return(Json(new { success = true })); }
public ActionResult _ResultsPost(StockMasterDetailModel vm) { int Cnt = 0; StockHeader Header = new StockHeaderService(_unitOfWork).Find(vm.StockLineViewModel.FirstOrDefault().StockHeaderId); StockHeaderSettings Settings = new StockHeaderSettingsService(_unitOfWork).GetStockHeaderSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); bool BeforeSave = true; try { BeforeSave = RateConversionDocEvents.beforeLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { ModelState.AddModelError("", "Validation failed before save"); } if (ModelState.IsValid && BeforeSave && !EventException) { var CostCenterRecords = (from p in vm.StockLineViewModel where p.CostCenterId != null group p by p.CostCenterId into g select g).ToList(); var CostCenterIds = CostCenterRecords.Select(m => m.Key).ToArray(); var DBCostCenterStatus = (from p in db.CostCenterStatus where CostCenterIds.Contains(p.CostCenterId) select p).ToArray(); foreach (var item in vm.StockLineViewModel) { if (item.Qty != 0 && item.Rate > 0 && (Settings.isMandatoryLineCostCenter == true ? item.CostCenterId.HasValue : 1 == 1)) { StockLine line = new StockLine(); StockProcessViewModel StockProcessViewModel = new StockProcessViewModel(); if (Header.StockHeaderId != null && Header.StockHeaderId != 0)//If Transaction Header Table Has Stock Header Id Then It will Save Here. { StockProcessViewModel.StockHeaderId = (int)Header.StockHeaderId; } else if (Cnt > 0)//If function will only post in stock process then after first iteration of loop the stock header id will go -1 { StockProcessViewModel.StockHeaderId = -1; } else//If function will only post in stock process then this statement will execute.For Example Job consumption. { StockProcessViewModel.StockHeaderId = 0; } StockProcessViewModel.StockProcessId = -Cnt; StockProcessViewModel.DocHeaderId = Header.StockHeaderId; StockProcessViewModel.DocLineId = line.StockLineId; StockProcessViewModel.DocTypeId = Header.DocTypeId; StockProcessViewModel.StockHeaderDocDate = Header.DocDate; StockProcessViewModel.StockProcessDocDate = Header.DocDate; StockProcessViewModel.DocNo = Header.DocNo; StockProcessViewModel.DivisionId = Header.DivisionId; StockProcessViewModel.SiteId = Header.SiteId; StockProcessViewModel.CurrencyId = null; StockProcessViewModel.PersonId = Header.PersonId; StockProcessViewModel.ProductId = item.ProductId; StockProcessViewModel.HeaderFromGodownId = null; StockProcessViewModel.HeaderGodownId = Header.GodownId; StockProcessViewModel.HeaderProcessId = Header.ProcessId; StockProcessViewModel.GodownId = Header.GodownId; StockProcessViewModel.Remark = Header.Remark; StockProcessViewModel.Status = Header.Status; StockProcessViewModel.ProcessId = Header.ProcessId; StockProcessViewModel.LotNo = null; StockProcessViewModel.CostCenterId = (item.CostCenterId == null ? Header.CostCenterId : item.CostCenterId); if (item.Qty < 0) { StockProcessViewModel.Qty_Rec = Math.Abs(item.Qty); StockProcessViewModel.Qty_Iss = 0; } else if (item.Qty > 0) { StockProcessViewModel.Qty_Iss = Math.Abs(item.Qty); StockProcessViewModel.Qty_Rec = 0; } StockProcessViewModel.Rate = item.Rate; StockProcessViewModel.ExpiryDate = null; StockProcessViewModel.Specification = item.Specification; StockProcessViewModel.Dimension1Id = item.Dimension1Id; StockProcessViewModel.Dimension2Id = item.Dimension2Id; StockProcessViewModel.Dimension3Id = item.Dimension3Id; StockProcessViewModel.Dimension4Id = item.Dimension4Id; StockProcessViewModel.CreatedBy = User.Identity.Name; StockProcessViewModel.CreatedDate = DateTime.Now; StockProcessViewModel.ModifiedBy = User.Identity.Name; StockProcessViewModel.ModifiedDate = DateTime.Now; string StockProcessPostingError = ""; StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPostDB(ref StockProcessViewModel, ref db); if (StockProcessPostingError != "") { string message = StockProcessPostingError; ModelState.AddModelError("", message); return(PartialView("_Results", vm)); } line.StockProcessId = StockProcessViewModel.StockProcessId; line.StockHeaderId = item.StockHeaderId; line.Qty = item.Qty; line.ProductId = item.ProductId; line.LotNo = item.LotNo; line.Rate = (decimal)item.Rate; line.Amount = Math.Round((decimal)item.Rate * item.Qty, Settings.LineRoundOff ?? 0); line.Dimension1Id = item.Dimension1Id; line.Dimension2Id = item.Dimension2Id; line.Dimension3Id = item.Dimension3Id; line.Dimension4Id = item.Dimension4Id; line.DocNature = StockNatureConstants.Receive; line.CostCenterId = item.CostCenterId; line.FromProcessId = item.FromProcessId; line.Specification = item.Specification; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.ObjectState = Model.ObjectState.Added; //_StockLineService.Create(line); db.StockLine.Add(line); Cnt = Cnt + 1; } } if (Header.Status != (int)StatusConstants.Drafted && Header.Status != (int)StatusConstants.Import) { Header.Status = (int)StatusConstants.Modified; Header.ModifiedBy = User.Identity.Name; Header.ModifiedDate = DateTime.Now; Header.ObjectState = Model.ObjectState.Modified; db.StockHeader.Add(Header); } //ForUpdating CostCenterStatus Values// foreach (var item in DBCostCenterStatus) { var CostCenterAmounts = db.StockLine.Local.Where(m => m.CostCenterId == item.CostCenterId).ToList(); if (CostCenterAmounts != null) { if (CostCenterAmounts.Sum(m => m.Amount) > 0) { item.AmountDr = (item.AmountDr ?? 0) + CostCenterAmounts.Sum(m => m.Amount); } else if (CostCenterAmounts.Sum(m => m.Amount) < 0) { item.AmountDr = (item.AmountDr ?? 0) + CostCenterAmounts.Sum(m => m.Amount); } item.ObjectState = Model.ObjectState.Modified; db.CostCenterStatus.Add(item); } } try { RateConversionDocEvents.onLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), 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; return(PartialView("_Results", vm)); } try { RateConversionDocEvents.afterLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = Header.DocTypeId, DocId = Header.StockHeaderId, ActivityType = (int)ActivityTypeContants.MultipleCreate, DocNo = Header.DocNo, DocDate = Header.DocDate, DocStatus = Header.Status, })); return(Json(new { success = true })); } return(PartialView("_Results", vm)); }
public ActionResult DeletePost(StockLineViewModel vm) { bool BeforeSave = true; try { BeforeSave = StockIssueDocEvents.beforeLineDeleteEvent(this, new StockEventArgs(vm.StockHeaderId, vm.StockLineId), 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) { int?ProdUid = 0; List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); //StockLine StockLine = _StockLineService.Find(vm.StockLineId); StockLine StockLine = (from p in db.StockLine where p.StockLineId == vm.StockLineId select p).FirstOrDefault(); StockHeader header = new StockHeaderService(_unitOfWork).Find(StockLine.StockHeaderId); LogList.Add(new LogTypeViewModel { ExObj = Mapper.Map <StockLine>(StockLine), }); ProdUid = StockLine.ProductUidId; if (StockLine.RequisitionLineId.HasValue) { new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyOnIssue(StockLine.RequisitionLineId.Value, StockLine.StockLineId, header.DocDate, 0, ref db, true); } StockLine.ObjectState = Model.ObjectState.Deleted; db.StockLine.Remove(StockLine); 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; header.ObjectState = Model.ObjectState.Modified; db.StockHeader.Add(header); } //if (ProdUid != null && ProdUid > 0) //{ // ProductUidDetail ProductUidDetail = new ProductUidService(_unitOfWork).FGetProductUidLastValues((int)ProdUid, "Stock Head-" + vm.StockHeaderId.ToString()); // ProductUid ProductUid = new ProductUidService(_unitOfWork).Find((int)ProdUid); // ProductUid.LastTransactionDocDate = ProductUidDetail.LastTransactionDocDate; // ProductUid.LastTransactionDocId = ProductUidDetail.LastTransactionDocId; // ProductUid.LastTransactionDocNo = ProductUidDetail.LastTransactionDocNo; // ProductUid.LastTransactionDocTypeId = ProductUidDetail.LastTransactionDocTypeId; // ProductUid.LastTransactionPersonId = ProductUidDetail.LastTransactionPersonId; // ProductUid.CurrenctGodownId = ProductUidDetail.CurrenctGodownId; // ProductUid.CurrenctProcessId = ProductUidDetail.CurrenctProcessId; // ProductUid.ObjectState = Model.ObjectState.Modified; // db.ProductUid.Add(ProductUid); //} XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { StockIssueDocEvents.onLineDeleteEvent(this, new StockEventArgs(StockLine.StockHeaderId, StockLine.StockLineId), 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 { StockIssueDocEvents.afterLineDeleteEvent(this, new StockEventArgs(StockLine.StockHeaderId, StockLine.StockLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = header.DocTypeId, DocId = header.StockHeaderId, DocLineId = StockLine.StockLineId, ActivityType = (int)ActivityTypeContants.Deleted, DocNo = header.DocNo, xEModifications = Modifications, DocDate = header.DocDate, DocStatus = header.Status, })); } return(Json(new { success = true })); }
public StockLine Create(StockLine S) { S.ObjectState = ObjectState.Added; _StockLineRepository.Add(S); return(S); }
public void Delete(RecipeLineViewModel vm, string UserName) { int?StockId = 0; int?StockProcessId = 0; List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); StockLine StockLine = Find(vm.StockLineId); StockHeader header = _StockHeaderRepository.Find(StockLine.StockHeaderId); StockId = StockLine.StockId; StockProcessId = StockLine.StockProcessId; LogList.Add(new LogTypeViewModel { Obj = Mapper.Map <StockLine>(StockLine), }); _StockLineExtendedService.Delete(StockLine.StockLineId); //_RecipeLineService.Delete(StockLine); StockLine.ObjectState = Model.ObjectState.Deleted; Delete(StockLine); if (StockId != null) { _stockService.DeleteStock((int)StockId); } if (StockProcessId != null) { _stockProcessService.DeleteStockProcessDB((int)StockProcessId); } if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import) { header.Status = (int)StatusConstants.Modified; header.ModifiedDate = DateTime.Now; header.ModifiedBy = UserName; _StockHeaderRepository.Update(header); } XElement Modifications = _modificationCheck.CheckChanges(LogList); _unitOfWork.Save(); //Saving the Activity Log _logger.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = header.DocTypeId, DocId = header.StockHeaderId, DocLineId = StockLine.StockLineId, ActivityType = (int)ActivityTypeContants.Deleted, DocNo = header.DocNo, xEModifications = Modifications, DocDate = header.DocDate, DocStatus = header.Status, })); }
public void Update(RecipeLineViewModel svm, string UserName) { StockLine s = Mapper.Map <RecipeLineViewModel, StockLine>(svm); StockHeader temp = _StockHeaderRepository.Find(svm.StockHeaderId); List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); StockLine templine = Find(s.StockLineId); StockLine ExTempLine = new StockLine(); ExTempLine = Mapper.Map <StockLine>(templine); if (templine.StockId != null) { StockViewModel StockViewModel = new StockViewModel(); StockViewModel.StockHeaderId = temp.StockHeaderId; StockViewModel.StockId = templine.StockId ?? 0; StockViewModel.DocHeaderId = templine.StockHeaderId; StockViewModel.DocLineId = templine.StockLineId; StockViewModel.DocTypeId = temp.DocTypeId; StockViewModel.StockHeaderDocDate = temp.DocDate; StockViewModel.StockDocDate = templine.CreatedDate.Date; StockViewModel.DocNo = temp.DocNo; StockViewModel.DivisionId = temp.DivisionId; StockViewModel.SiteId = temp.SiteId; StockViewModel.CurrencyId = null; StockViewModel.HeaderProcessId = temp.ProcessId; StockViewModel.PersonId = temp.PersonId; StockViewModel.ProductId = s.ProductId; StockViewModel.HeaderFromGodownId = null; StockViewModel.HeaderGodownId = temp.GodownId; StockViewModel.GodownId = temp.GodownId ?? 0; StockViewModel.ProcessId = templine.FromProcessId; StockViewModel.LotNo = templine.LotNo; StockViewModel.CostCenterId = temp.CostCenterId; StockViewModel.Qty_Iss = s.Qty; StockViewModel.Qty_Rec = 0; StockViewModel.Rate = templine.Rate; StockViewModel.ExpiryDate = null; StockViewModel.Specification = templine.Specification; StockViewModel.Dimension1Id = templine.Dimension1Id; StockViewModel.Dimension2Id = templine.Dimension2Id; StockViewModel.Remark = s.Remark; StockViewModel.ProductUidId = s.ProductUidId; StockViewModel.Status = temp.Status; StockViewModel.CreatedBy = templine.CreatedBy; StockViewModel.CreatedDate = templine.CreatedDate; StockViewModel.ModifiedBy = UserName; StockViewModel.ModifiedDate = DateTime.Now; string StockPostingError = ""; StockPostingError = _stockService.StockPostDB(ref StockViewModel); } if (templine.StockProcessId != null) { StockProcessViewModel StockProcessViewModel = new StockProcessViewModel(); StockProcessViewModel.StockHeaderId = temp.StockHeaderId; StockProcessViewModel.StockProcessId = templine.StockProcessId ?? 0; StockProcessViewModel.DocHeaderId = templine.StockHeaderId; StockProcessViewModel.DocLineId = templine.StockLineId; StockProcessViewModel.DocTypeId = temp.DocTypeId; StockProcessViewModel.StockHeaderDocDate = temp.DocDate; StockProcessViewModel.StockProcessDocDate = templine.CreatedDate.Date; StockProcessViewModel.DocNo = temp.DocNo; StockProcessViewModel.DivisionId = temp.DivisionId; StockProcessViewModel.SiteId = temp.SiteId; StockProcessViewModel.CurrencyId = null; StockProcessViewModel.HeaderProcessId = temp.ProcessId; StockProcessViewModel.PersonId = temp.PersonId; StockProcessViewModel.ProductId = s.ProductId; StockProcessViewModel.HeaderFromGodownId = null; StockProcessViewModel.HeaderGodownId = temp.GodownId; StockProcessViewModel.GodownId = temp.GodownId ?? 0; StockProcessViewModel.ProcessId = temp.ProcessId; StockProcessViewModel.LotNo = templine.LotNo; StockProcessViewModel.CostCenterId = temp.CostCenterId; StockProcessViewModel.Qty_Iss = 0; StockProcessViewModel.Qty_Rec = s.Qty; StockProcessViewModel.Rate = templine.Rate; StockProcessViewModel.ExpiryDate = null; StockProcessViewModel.Specification = templine.Specification; StockProcessViewModel.Dimension1Id = templine.Dimension1Id; StockProcessViewModel.Dimension2Id = templine.Dimension2Id; StockProcessViewModel.Remark = s.Remark; StockProcessViewModel.ProductUidId = s.ProductUidId; StockProcessViewModel.Status = temp.Status; StockProcessViewModel.CreatedBy = templine.CreatedBy; StockProcessViewModel.CreatedDate = templine.CreatedDate; StockProcessViewModel.ModifiedBy = UserName; StockProcessViewModel.ModifiedDate = DateTime.Now; string StockProcessPostingError = ""; StockProcessPostingError = _stockProcessService.StockProcessPostDB(ref StockProcessViewModel); } templine.ProductId = s.ProductId; templine.ProductUidId = s.ProductUidId; templine.LotNo = s.LotNo; templine.FromProcessId = s.FromProcessId; templine.Rate = s.Rate; templine.Amount = s.Amount; templine.Remark = s.Remark; templine.Qty = s.Qty; templine.Remark = s.Remark; templine.Dimension1Id = s.Dimension1Id; templine.Dimension2Id = s.Dimension2Id; templine.Specification = s.Specification; templine.ModifiedDate = DateTime.Now; templine.ModifiedBy = UserName; templine.ObjectState = Model.ObjectState.Modified; Update(templine); StockLineExtended LineExtended = _StockLineExtendedService.Find(templine.StockLineId); LineExtended.StockLineId = templine.StockLineId; LineExtended.DyeingRatio = svm.DyeingRatio; LineExtended.TestingQty = svm.TestingQty; LineExtended.DocQty = svm.DocQty; LineExtended.ExcessQty = svm.ExcessQty; LineExtended.ObjectState = Model.ObjectState.Modified; _StockLineExtendedService.Update(LineExtended); int Status = 0; if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { Status = temp.Status; temp.Status = (int)StatusConstants.Modified; temp.ModifiedBy = UserName; temp.ModifiedDate = DateTime.Now; } temp.ObjectState = Model.ObjectState.Modified; _StockHeaderRepository.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExTempLine, Obj = templine }); XElement Modifications = _modificationCheck.CheckChanges(LogList); _unitOfWork.Save(); _logger.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = templine.StockHeaderId, DocLineId = templine.StockLineId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); }
public RecipeLineViewModel Create(RecipeLineViewModel svm, string UserName) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); StockHeader temp = _StockHeaderRepository.Find(svm.StockHeaderId); StockLine s = Mapper.Map <RecipeLineViewModel, StockLine>(svm); StockViewModel StockViewModel = new StockViewModel(); StockProcessViewModel StockProcessViewModel = new StockProcessViewModel(); //Posting in Stock StockViewModel.StockHeaderId = temp.StockHeaderId; StockViewModel.DocHeaderId = temp.StockHeaderId; StockViewModel.DocLineId = s.StockLineId; StockViewModel.DocTypeId = temp.DocTypeId; StockViewModel.StockHeaderDocDate = temp.DocDate; StockViewModel.StockDocDate = DateTime.Now.Date; StockViewModel.DocNo = temp.DocNo; StockViewModel.DivisionId = temp.DivisionId; StockViewModel.SiteId = temp.SiteId; StockViewModel.CurrencyId = null; StockViewModel.HeaderProcessId = null; StockViewModel.PersonId = temp.PersonId; StockViewModel.ProductId = s.ProductId; StockViewModel.HeaderFromGodownId = null; StockViewModel.HeaderGodownId = temp.GodownId; StockViewModel.GodownId = temp.GodownId ?? 0; StockViewModel.ProcessId = s.FromProcessId; StockViewModel.LotNo = s.LotNo; StockViewModel.CostCenterId = temp.CostCenterId; StockViewModel.Qty_Iss = s.Qty; StockViewModel.Qty_Rec = 0; StockViewModel.Rate = s.Rate; StockViewModel.ExpiryDate = null; StockViewModel.Specification = s.Specification; StockViewModel.Dimension1Id = s.Dimension1Id; StockViewModel.Dimension2Id = s.Dimension2Id; StockViewModel.Remark = s.Remark; StockViewModel.ProductUidId = s.ProductUidId; StockViewModel.Status = temp.Status; StockViewModel.CreatedBy = temp.CreatedBy; StockViewModel.CreatedDate = DateTime.Now; StockViewModel.ModifiedBy = temp.ModifiedBy; StockViewModel.ModifiedDate = DateTime.Now; string StockPostingError = ""; StockPostingError = _stockService.StockPostDB(ref StockViewModel); s.StockId = StockViewModel.StockId; if (temp.StockHeaderId == null) { temp.StockHeaderId = StockViewModel.StockHeaderId; } StockProcessViewModel.StockHeaderId = (int)temp.StockHeaderId; StockProcessViewModel.DocHeaderId = temp.StockHeaderId; StockProcessViewModel.DocLineId = s.StockLineId; StockProcessViewModel.DocTypeId = temp.DocTypeId; StockProcessViewModel.StockHeaderDocDate = temp.DocDate; StockProcessViewModel.StockProcessDocDate = DateTime.Now.Date; StockProcessViewModel.DocNo = temp.DocNo; StockProcessViewModel.DivisionId = temp.DivisionId; StockProcessViewModel.SiteId = temp.SiteId; StockProcessViewModel.CurrencyId = null; StockProcessViewModel.HeaderProcessId = null; StockProcessViewModel.PersonId = temp.PersonId; StockProcessViewModel.ProductId = s.ProductId; StockProcessViewModel.HeaderFromGodownId = null; StockProcessViewModel.HeaderGodownId = temp.GodownId ?? 0; StockProcessViewModel.GodownId = temp.GodownId ?? 0; StockProcessViewModel.ProcessId = temp.ProcessId; StockProcessViewModel.LotNo = s.LotNo; StockProcessViewModel.CostCenterId = temp.CostCenterId; StockProcessViewModel.Qty_Iss = 0; StockProcessViewModel.Qty_Rec = s.Qty; StockProcessViewModel.Rate = s.Rate; StockProcessViewModel.ExpiryDate = null; StockProcessViewModel.Specification = s.Specification; StockProcessViewModel.Dimension1Id = s.Dimension1Id; StockProcessViewModel.Dimension2Id = s.Dimension2Id; StockProcessViewModel.Remark = s.Remark; StockProcessViewModel.Status = temp.Status; StockProcessViewModel.ProductUidId = s.ProductUidId; StockProcessViewModel.CreatedBy = temp.CreatedBy; StockProcessViewModel.CreatedDate = DateTime.Now; StockProcessViewModel.ModifiedBy = temp.ModifiedBy; StockProcessViewModel.ModifiedDate = DateTime.Now; string StockProcessPostingError = ""; StockProcessPostingError = _stockProcessService.StockProcessPostDB(ref StockProcessViewModel); s.StockProcessId = StockProcessViewModel.StockProcessId; s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = UserName; s.Sr = GetMaxSr(s.StockHeaderId); s.ModifiedBy = UserName; s.ObjectState = Model.ObjectState.Added; Create(s); StockLineExtended LineExtended = new StockLineExtended(); LineExtended.StockLineId = s.StockLineId; LineExtended.DyeingRatio = svm.DyeingRatio; LineExtended.TestingQty = svm.TestingQty; LineExtended.DocQty = svm.DocQty; LineExtended.ExcessQty = svm.ExcessQty; LineExtended.ObjectState = Model.ObjectState.Added; _StockLineExtendedService.Create(LineExtended); //StockHeader header = new StockHeaderService(_unitOfWork).Find(s.StockHeaderId); if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = UserName; } temp.ObjectState = Model.ObjectState.Modified; _StockHeaderRepository.Update(temp); _unitOfWork.Save(); svm.StockLineId = s.StockLineId; _logger.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.StockHeaderId, DocLineId = s.StockLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp.DocNo, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(svm); }
public void Update(StockLine s) { s.ObjectState = ObjectState.Modified; _StockLineRepository.Update(s); }
public void Delete(StockLine s) { _StockLineRepository.Delete(s); }
public ActionResult _CreatePost(StockLineViewModel svm) { StockHeader temp = new StockHeaderService(_unitOfWork).Find(svm.StockHeaderId); StockLine s = Mapper.Map <StockLineViewModel, StockLine>(svm); if (svm.StockHeaderSettings != null) { if (svm.StockHeaderSettings.isMandatoryProcessLine == true && (svm.FromProcessId <= 0 || svm.FromProcessId == null)) { ModelState.AddModelError("FromProcessId", "The Process field is required"); } if (svm.StockHeaderSettings.isMandatoryRate == true && svm.Rate <= 0) { ModelState.AddModelError("Rate", "The Rate field is required"); } if (svm.StockHeaderSettings.isMandatoryLineCostCenter == true && !svm.CostCenterId.HasValue) { ModelState.AddModelError("CostCenterId", "The Cost Center field is required"); } } bool BeforeSave = true; try { if (svm.StockLineId <= 0) { BeforeSave = StockIssueDocEvents.beforeLineSaveEvent(this, new StockEventArgs(svm.StockHeaderId, EventModeConstants.Add), ref db); } else { BeforeSave = StockIssueDocEvents.beforeLineSaveEvent(this, new StockEventArgs(svm.StockHeaderId, 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.ProductId <= 0) { ModelState.AddModelError("ProductId", "The Product field is required"); } if (svm.StockLineId <= 0) { ViewBag.LineMode = "Create"; } else { ViewBag.LineMode = "Edit"; } if (ModelState.IsValid && BeforeSave && !EventException) { if (svm.StockLineId <= 0) { s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.DocNature = StockNatureConstants.Issue; s.ModifiedBy = User.Identity.Name; s.ProductUidId = svm.ProductUidId; s.Sr = _StockLineService.GetMaxSr(s.StockHeaderId); s.ObjectState = Model.ObjectState.Added; db.StockLine.Add(s); if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; db.StockHeader.Add(temp); } try { StockIssueDocEvents.onLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, s.StockLineId, 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 { StockIssueDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, s.StockLineId, 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.StockHeaderId, DocLineId = s.StockLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp.DocNo, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("_Create", new { id = svm.StockHeaderId })); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); int status = temp.Status; StockLine templine = _StockLineService.Find(s.StockLineId); StockLine ExRec = new StockLine(); ExRec = Mapper.Map <StockLine>(templine); templine.ProductId = s.ProductId; templine.ProductUidId = s.ProductUidId; templine.RequisitionLineId = s.RequisitionLineId; templine.Specification = s.Specification; templine.Dimension1Id = s.Dimension1Id; templine.Dimension2Id = s.Dimension2Id; templine.Dimension3Id = s.Dimension3Id; templine.Dimension4Id = s.Dimension4Id; templine.CostCenterId = s.CostCenterId; templine.DocNature = StockNatureConstants.Issue; templine.Rate = s.Rate; templine.Amount = s.Amount; templine.LotNo = s.LotNo; templine.FromProcessId = s.FromProcessId; templine.Remark = s.Remark; templine.Qty = s.Qty; templine.Remark = s.Remark; templine.ReferenceDocId = s.ReferenceDocId; templine.ReferenceDocTypeId = s.ReferenceDocTypeId; templine.ModifiedDate = DateTime.Now; templine.ModifiedBy = User.Identity.Name; templine.ObjectState = Model.ObjectState.Modified; db.StockLine.Add(templine); //if (templine.RequisitionLineId.HasValue) // new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyOnIssue(templine.RequisitionLineId.Value, templine.StockLineId, temp.DocDate, templine.Qty, ref db, true); if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedBy = User.Identity.Name; temp.ModifiedDate = DateTime.Now; temp.ObjectState = Model.ObjectState.Modified; } db.StockHeader.Add(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = templine, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { StockIssueDocEvents.onLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, templine.StockLineId, 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(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; PrepareViewBag(svm); return(PartialView("_Create", svm)); } try { StockIssueDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, templine.StockLineId, 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.StockHeaderId, DocLineId = templine.StockLineId, 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 _ResultsPost(StockMasterDetailModel vm) { StockHeader temp = new StockHeaderService(_unitOfWork).Find(vm.StockLineViewModel.FirstOrDefault().StockHeaderId); StockHeaderSettings Settings = new StockHeaderSettingsService(_unitOfWork).GetStockHeaderSettingsForDocument(temp.DocTypeId, temp.DivisionId, temp.SiteId); bool BeforeSave = true; try { BeforeSave = JobConsumptionDocEvents.beforeLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { ModelState.AddModelError("", "Validation failed before save"); } int Cnt = 0; if (ModelState.IsValid && BeforeSave && !EventException) { foreach (var item in vm.StockLineViewModel) { if (item.Qty != 0 && (Settings.isMandatoryLineCostCenter == true ? item.CostCenterId.HasValue : 1 == 1)) { StockLine line = new StockLine(); line.StockHeaderId = item.StockHeaderId; line.Qty = item.Qty; line.ProductId = item.ProductId; line.LotNo = item.LotNo; line.Dimension1Id = item.Dimension1Id; line.Dimension2Id = item.Dimension2Id; line.Dimension3Id = item.Dimension3Id; line.Dimension4Id = item.Dimension4Id; line.CostCenterId = item.CostCenterId; line.FromProcessId = item.FromProcessId; line.Specification = item.Specification; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.DocNature = (item.Qty < 0 ? StockNatureConstants.Receive : StockNatureConstants.Issue); StockProcessViewModel StockProcessViewModel = new StockProcessViewModel(); if (temp.StockHeaderId != null && temp.StockHeaderId != 0)//If Transaction Header Table Has Stock Header Id Then It will Save Here. { StockProcessViewModel.StockHeaderId = (int)temp.StockHeaderId; } else if (Cnt > 0)//If function will only post in stock process then after first iteration of loop the stock header id will go -1 { StockProcessViewModel.StockHeaderId = -1; } else//If function will only post in stock process then this statement will execute.For Example Job consumption. { StockProcessViewModel.StockHeaderId = 0; } StockProcessViewModel.StockProcessId = -Cnt; StockProcessViewModel.DocHeaderId = temp.StockHeaderId; StockProcessViewModel.DocLineId = line.StockLineId; StockProcessViewModel.DocTypeId = temp.DocTypeId; StockProcessViewModel.StockHeaderDocDate = temp.DocDate; StockProcessViewModel.StockProcessDocDate = temp.DocDate; StockProcessViewModel.DocNo = temp.DocNo; StockProcessViewModel.DivisionId = temp.DivisionId; StockProcessViewModel.SiteId = temp.SiteId; StockProcessViewModel.CurrencyId = null; StockProcessViewModel.PersonId = temp.PersonId; StockProcessViewModel.ProductId = item.ProductId; StockProcessViewModel.HeaderFromGodownId = null; StockProcessViewModel.HeaderGodownId = temp.GodownId; StockProcessViewModel.HeaderProcessId = temp.ProcessId; StockProcessViewModel.GodownId = temp.GodownId; StockProcessViewModel.Remark = temp.Remark; StockProcessViewModel.Status = temp.Status; StockProcessViewModel.ProcessId = temp.ProcessId; StockProcessViewModel.LotNo = null; StockProcessViewModel.CostCenterId = item.CostCenterId; //StockProcessViewModel.Qty_Iss = item.Qty; //StockProcessViewModel.Qty_Rec = 0; if (item.Qty > 0) { StockProcessViewModel.Qty_Rec = item.Qty; StockProcessViewModel.Qty_Iss = 0; } else if (item.Qty < 0) { StockProcessViewModel.Qty_Rec = 0; StockProcessViewModel.Qty_Iss = Math.Abs(item.Qty); } StockProcessViewModel.Rate = item.Rate; StockProcessViewModel.ExpiryDate = null; StockProcessViewModel.Specification = item.Specification; StockProcessViewModel.Dimension1Id = item.Dimension1Id; StockProcessViewModel.Dimension2Id = item.Dimension2Id; StockProcessViewModel.Dimension3Id = item.Dimension3Id; StockProcessViewModel.Dimension4Id = item.Dimension4Id; StockProcessViewModel.CreatedBy = User.Identity.Name; StockProcessViewModel.CreatedDate = DateTime.Now; StockProcessViewModel.ModifiedBy = User.Identity.Name; StockProcessViewModel.ModifiedDate = DateTime.Now; string StockProcessPostingError = ""; StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPostDB(ref StockProcessViewModel, ref db); if (StockProcessPostingError != "") { string message = StockProcessPostingError; ModelState.AddModelError("", message); return(PartialView("_Results", vm)); } line.StockProcessId = StockProcessViewModel.StockProcessId; line.ObjectState = Model.ObjectState.Added; db.StockLine.Add(line); //_StockLineService.Create(line); Cnt = Cnt + 1; } } if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedBy = User.Identity.Name; temp.ModifiedDate = DateTime.Now; temp.ObjectState = Model.ObjectState.Modified; db.StockHeader.Add(temp); } try { JobConsumptionDocEvents.onLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), 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; return(PartialView("_Results", vm)); } try { JobConsumptionDocEvents.afterLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.StockHeaderId, ActivityType = (int)ActivityTypeContants.MultipleCreate, DocNo = temp.DocNo, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(Json(new { success = true })); } return(PartialView("_Results", vm)); }
public ActionResult _ResultsPost(StockMasterDetailModel vm) { int Cnt = 0; int pk = 0; int Serial = _StockLineService.GetMaxSr(vm.StockLineViewModel.FirstOrDefault().StockHeaderId); Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); StockHeader Header = new StockHeaderService(_unitOfWork).Find(vm.StockLineViewModel.FirstOrDefault().StockHeaderId); StockHeaderSettings Settings = new StockHeaderSettingsService(_unitOfWork).GetStockHeaderSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); if (Settings.isMandatoryLineCostCenter == true && vm.StockLineViewModel.Where(m => m.CostCenterId == null).Any()) { ModelState.AddModelError("", "CostCenter is mandatory"); } decimal Qty = vm.StockLineViewModel.Where(m => m.Rate > 0).Sum(m => m.Qty); bool BeforeSave = true; try { BeforeSave = StockIssueDocEvents.beforeLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { ModelState.AddModelError("", "Validation failed before save"); } if (ModelState.IsValid && BeforeSave && !EventException) { foreach (var item in vm.StockLineViewModel) { //if (item.Qty > 0 && ((Settings.isMandatoryRate.HasValue && Settings.isMandatoryRate == true )? item.Rate > 0 : 1 == 1)) if (item.Qty > 0) { StockLine line = new StockLine(); line.StockHeaderId = item.StockHeaderId; line.RequisitionLineId = item.RequisitionLineId; line.ProductId = item.ProductId; line.Dimension1Id = item.Dimension1Id; line.Dimension2Id = item.Dimension2Id; line.Dimension3Id = item.Dimension3Id; line.Dimension4Id = item.Dimension4Id; line.Specification = item.Specification; line.CostCenterId = item.CostCenterId; line.Qty = item.Qty; line.DocNature = StockNatureConstants.Issue; line.Rate = item.Rate ?? 0; line.Amount = (line.Qty * line.Rate); line.ReferenceDocId = item.ReferenceDocId; line.ReferenceDocTypeId = item.ReferenceDocTypeId; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.StockLineId = pk; line.Sr = Serial++; line.ObjectState = Model.ObjectState.Added; db.StockLine.Add(line); pk++; Cnt = Cnt + 1; if (line.RequisitionLineId.HasValue) { LineStatus.Add(line.RequisitionLineId.Value, line.Qty); } } } //new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyIssueMultiple(LineStatus, Header.DocDate, ref db); if (Header.Status != (int)StatusConstants.Drafted && Header.Status != (int)StatusConstants.Import) { Header.Status = (int)StatusConstants.Modified; Header.ModifiedBy = User.Identity.Name; Header.ModifiedDate = DateTime.Now; } Header.ObjectState = Model.ObjectState.Modified; db.StockHeader.Add(Header); try { StockIssueDocEvents.onLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), 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; return(PartialView("_Results", vm)); } try { StockIssueDocEvents.afterLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = Header.DocTypeId, DocId = Header.StockHeaderId, ActivityType = (int)ActivityTypeContants.MultipleCreate, DocNo = Header.DocNo, DocDate = Header.DocDate, DocStatus = Header.Status, })); return(Json(new { success = true })); } return(PartialView("_Results", vm)); }
public ActionResult _CreatePost(StockLineViewModel svm) { StockHeader temp = new StockHeaderService(_unitOfWork).Find(svm.StockHeaderId); StockLine s = Mapper.Map <StockLineViewModel, StockLine>(svm); if (svm.StockHeaderSettings != null) { if (svm.StockHeaderSettings.isMandatoryProcessLine == true && (svm.FromProcessId <= 0 || svm.FromProcessId == null)) { ModelState.AddModelError("FromProcessId", "The Process field is required"); } if (svm.Rate <= 0) { ModelState.AddModelError("Rate", "The Rate field is required"); } if (svm.StockHeaderSettings.isMandatoryLineCostCenter == true && !(svm.CostCenterId.HasValue)) { ModelState.AddModelError("CostCenterId", "The CostCenter field is required"); } } bool BeforeSave = true; try { if (svm.StockLineId <= 0) { BeforeSave = RateConversionDocEvents.beforeLineSaveEvent(this, new StockEventArgs(svm.StockHeaderId, EventModeConstants.Add), ref db); } else { BeforeSave = RateConversionDocEvents.beforeLineSaveEvent(this, new StockEventArgs(svm.StockHeaderId, 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.StockLineId <= 0) { ViewBag.LineMode = "Create"; } else { ViewBag.LineMode = "Edit"; } if (ModelState.IsValid && BeforeSave && !EventException) { if (svm.StockLineId <= 0) { StockProcessViewModel StockProcessViewModel = new StockProcessViewModel(); StockHeader StockHeader = new StockHeaderService(_unitOfWork).Find(temp.StockHeaderId); //Posting in StockProcess if (StockHeader.StockHeaderId != null) { StockProcessViewModel.StockHeaderId = StockHeader.StockHeaderId; } else { StockProcessViewModel.StockHeaderId = 0; } StockProcessViewModel.StockHeaderId = temp.StockHeaderId; StockProcessViewModel.DocHeaderId = temp.StockHeaderId; StockProcessViewModel.DocLineId = s.StockLineId; StockProcessViewModel.DocTypeId = temp.DocTypeId; StockProcessViewModel.StockHeaderDocDate = temp.DocDate; StockProcessViewModel.StockProcessDocDate = temp.DocDate; StockProcessViewModel.DocNo = temp.DocNo; StockProcessViewModel.DivisionId = temp.DivisionId; StockProcessViewModel.SiteId = temp.SiteId; StockProcessViewModel.CurrencyId = null; StockProcessViewModel.HeaderProcessId = null; StockProcessViewModel.PersonId = temp.PersonId; StockProcessViewModel.ProductId = s.ProductId; StockProcessViewModel.HeaderFromGodownId = temp.FromGodownId; StockProcessViewModel.HeaderGodownId = temp.GodownId; StockProcessViewModel.GodownId = temp.GodownId ?? 0; StockProcessViewModel.ProcessId = s.FromProcessId; StockProcessViewModel.LotNo = s.LotNo; StockProcessViewModel.CostCenterId = temp.CostCenterId; if (s.Qty < 0) { StockProcessViewModel.Qty_Rec = Math.Abs(s.Qty); StockProcessViewModel.Qty_Iss = 0; } else if (s.Qty > 0) { StockProcessViewModel.Qty_Iss = Math.Abs(s.Qty); StockProcessViewModel.Qty_Rec = 0; } StockProcessViewModel.Rate = s.Rate; StockProcessViewModel.ExpiryDate = null; StockProcessViewModel.Specification = s.Specification; StockProcessViewModel.Dimension1Id = s.Dimension1Id; StockProcessViewModel.Dimension2Id = s.Dimension2Id; StockProcessViewModel.Dimension3Id = s.Dimension3Id; StockProcessViewModel.Dimension4Id = s.Dimension4Id; StockProcessViewModel.Remark = s.Remark; StockProcessViewModel.Status = temp.Status; StockProcessViewModel.CreatedBy = temp.CreatedBy; StockProcessViewModel.CreatedDate = DateTime.Now; StockProcessViewModel.ModifiedBy = temp.ModifiedBy; StockProcessViewModel.ModifiedDate = DateTime.Now; string StockProcessPostingError = ""; StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPostDB(ref StockProcessViewModel, ref db); if (StockProcessPostingError != "") { ModelState.AddModelError("", StockProcessPostingError); return(PartialView("_Create", svm)); } s.StockProcessId = StockProcessViewModel.StockProcessId; s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.DocNature = StockNatureConstants.Receive; s.ObjectState = Model.ObjectState.Added; //_StockLineService.Create(s); db.StockLine.Add(s); //StockHeader header = new StockHeaderService(_unitOfWork).Find(s.StockHeaderId); if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; db.StockHeader.Add(temp); //new StockHeaderService(_unitOfWork).Update(temp); } try { RateConversionDocEvents.onLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, s.StockLineId, 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 { RateConversionDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, s.StockLineId, 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.StockHeaderId, DocLineId = s.StockLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp.DocNo, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("_Create", new { id = svm.StockHeaderId })); } else { StockLine templine = _StockLineService.Find(s.StockLineId); List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); StockLine ExRec = new StockLine(); ExRec = Mapper.Map <StockLine>(templine); if (templine.StockProcessId != null) { StockProcessViewModel StockProcessViewModel = new StockProcessViewModel(); StockHeader StockHeader = new StockHeaderService(_unitOfWork).Find(temp.StockHeaderId); //Posting in StockProcess if (StockHeader.StockHeaderId != null) { StockProcessViewModel.StockHeaderId = StockHeader.StockHeaderId; } else { StockProcessViewModel.StockHeaderId = 0; } StockProcessViewModel.StockProcessId = templine.StockProcessId ?? 0; StockProcessViewModel.DocHeaderId = templine.StockHeaderId; StockProcessViewModel.DocLineId = templine.StockLineId; StockProcessViewModel.DocTypeId = temp.DocTypeId; StockProcessViewModel.StockHeaderDocDate = temp.DocDate; StockProcessViewModel.StockProcessDocDate = temp.DocDate; StockProcessViewModel.DocNo = temp.DocNo; StockProcessViewModel.DivisionId = temp.DivisionId; StockProcessViewModel.SiteId = temp.SiteId; StockProcessViewModel.CurrencyId = null; StockProcessViewModel.HeaderProcessId = temp.ProcessId; StockProcessViewModel.PersonId = temp.PersonId; StockProcessViewModel.ProductId = s.ProductId; StockProcessViewModel.HeaderFromGodownId = null; StockProcessViewModel.HeaderGodownId = temp.GodownId; StockProcessViewModel.GodownId = temp.GodownId; StockProcessViewModel.ProcessId = temp.ProcessId; StockProcessViewModel.LotNo = templine.LotNo; StockProcessViewModel.CostCenterId = templine.CostCenterId; if (s.Qty < 0) { StockProcessViewModel.Qty_Rec = Math.Abs(s.Qty); StockProcessViewModel.Qty_Iss = 0; } else if (s.Qty > 0) { StockProcessViewModel.Qty_Iss = Math.Abs(s.Qty); StockProcessViewModel.Qty_Rec = 0; } StockProcessViewModel.Rate = templine.Rate; StockProcessViewModel.ExpiryDate = null; StockProcessViewModel.Specification = templine.Specification; StockProcessViewModel.Dimension1Id = templine.Dimension1Id; StockProcessViewModel.Dimension2Id = templine.Dimension2Id; StockProcessViewModel.Dimension3Id = templine.Dimension3Id; StockProcessViewModel.Dimension4Id = templine.Dimension4Id; StockProcessViewModel.Remark = s.Remark; StockProcessViewModel.Status = temp.Status; StockProcessViewModel.CreatedBy = templine.CreatedBy; StockProcessViewModel.CreatedDate = templine.CreatedDate; StockProcessViewModel.ModifiedBy = User.Identity.Name; StockProcessViewModel.ModifiedDate = DateTime.Now; string StockProcessPostingError = ""; StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPostDB(ref StockProcessViewModel, ref db); if (StockProcessPostingError != "") { ModelState.AddModelError("", StockProcessPostingError); return(PartialView("_Create", svm)); } } templine.Qty = s.Qty; templine.Remark = s.Remark; templine.Amount = s.Qty * s.Rate; templine.ModifiedDate = DateTime.Now; templine.ModifiedBy = User.Identity.Name; //_StockLineService.Update(templine); templine.ObjectState = Model.ObjectState.Modified; db.StockLine.Add(templine); if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedBy = User.Identity.Name; temp.ModifiedDate = DateTime.Now; temp.ObjectState = Model.ObjectState.Modified; db.StockHeader.Add(temp); //new StockHeaderService(_unitOfWork).Update(temp); } if (templine.CostCenterId.HasValue && templine.CostCenterId > 0) { var CostCenterStatus = db.CostCenterStatus.Find(templine.CostCenterId); if (CostCenterStatus != null) { //For Reducing Old Amount if (ExRec.Amount > 0) { CostCenterStatus.AmountDr = CostCenterStatus.AmountDr - ExRec.Amount; } else { CostCenterStatus.AmountCr = CostCenterStatus.AmountCr - ExRec.Amount; } //For Adding New Amount if (templine.Amount > 0) { CostCenterStatus.AmountDr = CostCenterStatus.AmountDr + templine.Amount; } else { CostCenterStatus.AmountCr = CostCenterStatus.AmountCr + templine.Amount; } CostCenterStatus.ObjectState = Model.ObjectState.Modified; db.CostCenterStatus.Add(CostCenterStatus); } } LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = templine, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { RateConversionDocEvents.onLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, templine.StockLineId, 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 { RateConversionDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, templine.StockLineId, 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.StockHeaderId, DocLineId = templine.StockLineId, 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)); }