public ActionResult CreateJobInvoiceReturn(int id)//DocTypeId { List <string> UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"]; if (!UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } var DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; var SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; PrepareViewBag(); var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(id, DivisionId, SiteId); if (settings == null) { JobInvoiceSettingsViewModel vm = new JobInvoiceSettingsViewModel(); vm.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; vm.SiteId = SiteId; vm.DivisionId = DivisionId; vm.DocTypeId = id; return(View("CreateJobInvoiceReturn", vm)); } else { JobInvoiceSettingsViewModel temp = AutoMapper.Mapper.Map <JobInvoiceSettings, JobInvoiceSettingsViewModel>(settings); temp.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; return(View("CreateJobInvoiceReturn", temp)); } }
public ActionResult Create(int id)//DocumentTypeId { PrepareViewBag(id); JobInvoiceAmendmentHeaderViewModel vm = new JobInvoiceAmendmentHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; vm.CreatedDate = DateTime.Now; //Getting Settings var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(id, vm.DivisionId, vm.SiteId); vm.JobInvoiceSettings = Mapper.Map <JobInvoiceSettings, JobInvoiceSettingsViewModel>(settings); vm.DocTypeId = id; vm.DocDate = DateTime.Now; vm.ProcessId = settings.ProcessId; var EmpId = new EmployeeService(_unitOfWork).GetEmloyeeForUser(User.Identity.GetUserId()); if (EmpId.HasValue && EmpId.Value != 0) { vm.OrderById = EmpId.Value; } vm.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".JobInvoiceAmendmentHeaders", vm.DocTypeId, vm.DocDate, vm.DivisionId, vm.SiteId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
public JsonResult GetProductUidJobReceiveValidationForWashing(string ProductUID, bool PostedInStock, int HeaderID, int ProcessId) { int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; JobInvoiceHeader InvoiceHeader = (from H in db.JobInvoiceHeader where H.JobReceiveHeaderId == HeaderID select H).FirstOrDefault(); var temp2 = (from p in db.ProductUid where p.ProductUidName == ProductUID join t2 in db.JobOrderLine on p.ProductUIDId equals t2.ProductUidId join t3 in db.JobOrderHeader on t2.JobOrderHeaderId equals t3.JobOrderHeaderId join t4 in db.ViewJobOrderBalance on t2.JobOrderLineId equals t4.JobOrderLineId where t3.SiteId == SiteId && t3.DivisionId == DivisionId && t3.ProcessId == ProcessId select t2).FirstOrDefault(); if (temp2 != null) { return(Json(new ProductUidService(_unitOfWork).ValidateUIDOnJobReceiveBranch(ProductUID, PostedInStock, HeaderID), JsonRequestBehavior.AllowGet)); } else { if (InvoiceHeader != null) { var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(InvoiceHeader.DocTypeId, InvoiceHeader.DivisionId, InvoiceHeader.SiteId); if (settings != null) { if (settings.isGenerateProductUid == true) { UIDValidationViewModel temp = new UIDValidationViewModel(); temp.ErrorType = "Success"; return(Json(temp)); } else { return(Json(new ProductUidService(_unitOfWork).ValidateUIDOnJobReceiveBranch(ProductUID, PostedInStock, HeaderID), JsonRequestBehavior.AllowGet)); } } else { return(Json(new ProductUidService(_unitOfWork).ValidateUIDOnJobReceiveBranch(ProductUID, PostedInStock, HeaderID), JsonRequestBehavior.AllowGet)); } } else { return(Json(new { ErrorType = "InvalidID", ErrorMessage = "BarCodeNotFound" })); } } }
public ActionResult _Create(int Id, int?sid) //Id ==>Sale Order Header Id { JobInvoiceAmendmentHeader header = new JobInvoiceAmendmentHeaderService(_unitOfWork).Find(Id); JobInvoiceRateAmendmentLineViewModel svm = new JobInvoiceRateAmendmentLineViewModel(); //Getting Settings var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(header.DocTypeId, header.DivisionId, header.SiteId); svm.JobInvoiceSettings = Mapper.Map <JobInvoiceSettings, JobInvoiceSettingsViewModel>(settings); ViewBag.LineMode = "Create"; svm.JobInvoiceAmendmentHeaderId = Id; svm.JobWorkerId = sid.HasValue ? sid.Value : 0; svm.DocTypeId = header.DocTypeId; svm.SiteId = header.SiteId; svm.DivisionId = header.DivisionId; return(PartialView("_Create", svm)); }
public ActionResult RateAmendtmentWizard(int id)//DocumentTypeId { PrepareViewBag(id); JobInvoiceAmendmentHeaderViewModel vm = new JobInvoiceAmendmentHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; //Getting Settings var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(id, vm.DivisionId, vm.SiteId); if (settings == null) { return(RedirectToAction("CreateJobInvoiceAmendment", "JobInvoiceSettings", new { id = id }).Warning("Please create job amendment settings")); } ViewBag.ProcessId = settings.ProcessId; return(View()); }
private ActionResult _Delete(int id) { JobInvoiceRateAmendmentLineViewModel temp = _JobInvoiceRateAmendmentLineService.GetJobInvoiceRateAmendmentLine(id); if (temp == null) { return(HttpNotFound()); } JobInvoiceAmendmentHeader header = new JobInvoiceAmendmentHeaderService(_unitOfWork).Find(temp.JobInvoiceAmendmentHeaderId); #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"; } //Getting Settings var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(header.DocTypeId, header.DivisionId, header.SiteId); temp.JobInvoiceSettings = Mapper.Map <JobInvoiceSettings, JobInvoiceSettingsViewModel>(settings); return(PartialView("_Create", temp)); }
// GET: /JobInvoiceSettingsMaster/Create public ActionResult CreateJobInvoiceAmendment(int id)//DocTypeId { var DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; var SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; PrepareViewBag(); var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(id, DivisionId, SiteId); if (settings == null) { JobInvoiceSettingsViewModel vm = new JobInvoiceSettingsViewModel(); vm.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; vm.SiteId = SiteId; vm.DivisionId = DivisionId; vm.DocTypeId = id; return(View("CreateJobInvoiceAmendment", vm)); } else { JobInvoiceSettingsViewModel temp = AutoMapper.Mapper.Map <JobInvoiceSettings, JobInvoiceSettingsViewModel>(settings); temp.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; return(View("CreateJobInvoiceAmendment", temp)); } }
public ActionResult Post(JobInvoiceAmendmentHeaderViewModel vm) { int Serial = 1; bool TimePlanValidation = true; string ExceptionMsg = ""; bool Continue = true; int pk = 0; Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); var SelectedJobInvoices = (List <JobInvoiceAmendmentWizardViewModel>)System.Web.HttpContext.Current.Session["RateAmendmentWizardOrders"]; JobInvoiceAmendmentHeader Header = AutoMapper.Mapper.Map <JobInvoiceAmendmentHeaderViewModel, JobInvoiceAmendmentHeader>(vm); List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>(); List <LineChargeViewModel> LineCharges = new List <LineChargeViewModel>(); List <LineReferenceIds> RefIds = new List <LineReferenceIds>(); bool HeaderChargeEdit = false; int PersonCount = 0; var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); //int? CalculationId = settings.CalculationId; List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>(); if (vm.JobInvoiceSettings.isVisibleHeaderJobWorker && !vm.JobWorkerId.HasValue) { ModelState.AddModelError("JobWorkerId", "The JobWorker field is required"); } #region BeforeSave bool BeforeSave = true; try { BeforeSave = JobInvoiceAmendmentDocEvents.beforeWizardSaveEvent(this, new JobEventArgs(vm.JobInvoiceAmendmentHeaderId), 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 { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Create, 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)) { if (SelectedJobInvoices.Count > 0) { Header.Status = (int)StatusConstants.Drafted; Header.CreatedDate = DateTime.Now; Header.ModifiedDate = DateTime.Now; Header.CreatedBy = User.Identity.Name; Header.ModifiedBy = User.Identity.Name; Header.ObjectState = Model.ObjectState.Added; db.JobInvoiceAmendmentHeader.Add(Header); //_JobInvoiceAmendmentHeaderService.Create(pt); var JobInvoiceLineIds = SelectedJobInvoices.Select(m => m.JobInvoiceLineId).ToArray(); var JobInvoiceBalanceRecords = (from p in db.ViewJobInvoiceBalanceForRateAmendment where JobInvoiceLineIds.Contains(p.JobInvoiceLineId) select p).AsNoTracking().ToList(); var JobInvoiceRecords = (from p in db.JobInvoiceLine where JobInvoiceLineIds.Contains(p.JobInvoiceLineId) select p).AsNoTracking().ToList(); int?CalculationId = 0; int JobInvoiceLineId = JobInvoiceBalanceRecords.FirstOrDefault().JobInvoiceLineId; var SalesTaxGroupPerson = (from L in db.JobInvoiceLine where L.JobInvoiceLineId == JobInvoiceLineId select new { SalesTaxGroupPersonId = (int?)L.JobInvoiceHeader.SalesTaxGroupPerson.ChargeGroupPersonId ?? 0 }).FirstOrDefault(); if (SalesTaxGroupPerson != null) { CalculationId = new ChargeGroupPersonCalculationService(_unitOfWork).GetChargeGroupPersonCalculation(Header.DocTypeId, SalesTaxGroupPerson.SalesTaxGroupPersonId, Header.SiteId, Header.DivisionId) ?? 0; } if (CalculationId == 0) { CalculationId = settings.CalculationId ?? 0; } foreach (var item in SelectedJobInvoices) { if (item.Rate - JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().Rate != 0) { JobInvoiceRateAmendmentLine line = new JobInvoiceRateAmendmentLine(); line.JobInvoiceAmendmentHeaderId = Header.JobInvoiceAmendmentHeaderId; line.JobInvoiceLineId = item.JobInvoiceLineId; line.Qty = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().BalanceQty; line.AmendedRate = item.Rate; line.Rate = line.AmendedRate - JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().Rate; line.Amount = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().BalanceQty *JobInvoiceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().UnitConversionMultiplier *line.Rate; line.Amount = DecimalRoundOff.amountToFixed(line.Amount, settings.AmountRoundOff); line.JobInvoiceRate = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().Rate; line.JobWorkerId = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().JobWorkerId; line.Sr = Serial++; line.JobInvoiceRateAmendmentLineId = pk; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; LineStatus.Add(line.JobInvoiceLineId, line.Rate); RefIds.Add(new LineReferenceIds { LineId = line.JobInvoiceRateAmendmentLineId, RefLineId = line.JobInvoiceLineId }); line.ObjectState = Model.ObjectState.Added; db.JobInvoiceRateAmendmentLine.Add(line); LineList.Add(new LineDetailListViewModel { Amount = line.Amount, Rate = line.Rate, LineTableId = line.JobInvoiceRateAmendmentLineId, HeaderTableId = Header.JobInvoiceAmendmentHeaderId, PersonID = line.JobWorkerId, DealQty = 0 }); pk++; } } //new JobInvoiceLineStatusService(_unitOfWork).UpdateJobRateOnAmendmentMultiple(LineStatus, pt.DocDate, ref db); int[] RecLineIds = null; RecLineIds = RefIds.Select(m => m.RefLineId).ToArray(); var Charges = (from p in db.JobInvoiceLine where RecLineIds.Contains(p.JobInvoiceLineId) join LineCharge in db.JobInvoiceLineCharge on p.JobInvoiceLineId equals LineCharge.LineTableId join HeaderCharge in db.JobInvoiceHeaderCharges on p.JobInvoiceHeaderId equals HeaderCharge.HeaderTableId group new { p, LineCharge, HeaderCharge } by new { p.JobInvoiceLineId } into g select new { LineId = g.Key.JobInvoiceLineId, HeaderCharges = g.Select(m => m.HeaderCharge).ToList(), Linecharges = g.Select(m => m.LineCharge).ToList(), }).ToList(); var LineListWithReferences = (from p in LineList join t in RefIds on p.LineTableId equals t.LineId join t2 in Charges on t.RefLineId equals t2.LineId into table from LineLis in table.DefaultIfEmpty() orderby p.LineTableId select new LineDetailListViewModel { Amount = p.Amount, DealQty = p.DealQty, HeaderTableId = p.HeaderTableId, LineTableId = p.LineTableId, PersonID = p.PersonID, Rate = p.Rate, CostCenterId = p.CostCenterId, RLineCharges = (LineLis == null ? null : Mapper.Map <List <LineChargeViewModel> >(LineLis.Linecharges)), }).ToList(); if (CalculationId != null) { new ChargesCalculationService(_unitOfWork).CalculateCharges(LineListWithReferences, Header.JobInvoiceAmendmentHeaderId, (int)CalculationId, 0, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.JobInvoiceAmendmentHeaderCharges", "Web.JobInvoiceRateAmendmentLineCharges", out PersonCount, Header.DocTypeId, Header.SiteId, Header.DivisionId); } //Saving Charges foreach (var item in LineCharges) { JobInvoiceRateAmendmentLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, JobInvoiceRateAmendmentLineCharge>(item); PoLineCharge.ObjectState = Model.ObjectState.Added; db.JobInvoiceRateAmendmentLineCharge.Add(PoLineCharge); } //Saving Header charges for (int i = 0; i < HeaderCharges.Count(); i++) { if (!HeaderChargeEdit) { JobInvoiceAmendmentHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, JobInvoiceAmendmentHeaderCharge>(HeaderCharges[i]); POHeaderCharge.HeaderTableId = Header.JobInvoiceAmendmentHeaderId; POHeaderCharge.PersonID = Header.JobWorkerId; POHeaderCharge.ObjectState = Model.ObjectState.Added; db.JobInvoiceAmendmentHeaderCharge.Add(POHeaderCharge); } else { var footercharge = new JobInvoiceAmendmentHeaderChargeService(db).Find(HeaderCharges[i].Id); footercharge.Rate = HeaderCharges[i].Rate; footercharge.Amount = HeaderCharges[i].Amount; footercharge.ObjectState = Model.ObjectState.Modified; db.JobInvoiceAmendmentHeaderCharge.Add(footercharge); } } try { JobInvoiceAmendmentDocEvents.onWizardSaveEvent(this, new JobEventArgs(Header.JobInvoiceAmendmentHeaderId, 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 { JobInvoiceAmendmentDocEvents.afterWizardSaveEvent(this, new JobEventArgs(Header.JobInvoiceAmendmentHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = Header.DocTypeId, DocId = Header.JobInvoiceAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.WizardCreate, DocNo = Header.DocNo, DocDate = Header.DocDate, DocStatus = Header.Status, })); Session.Remove("RateAmendmentWizardOrders"); } return(RedirectToAction("Index", "JobInvoiceAmendmentHeader", new { id = Header.DocTypeId }).Success("Data saved Successfully")); } PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
// here we simulate SQL search, sorting and paging operations private IQueryable <JobInvoiceAmendmentWizardViewModel> FilterData(int ProcessId, int DocType, DateTime?FromDate, DateTime?ToDate, string JobInvoiceHeaderId, string JobWorkerId, string ProductId, string Dimension1Id, string Dimension2Id, string ProductGroupId, string ProductCategoryId, decimal?Rate, decimal NewRate, decimal?MultiplierGT, decimal?MultiplierLT, string Sample) { List <int> JobInvoiceHeaderIds = new List <int>(); if (!string.IsNullOrEmpty(JobInvoiceHeaderId)) { foreach (var item in JobInvoiceHeaderId.Split(',')) { JobInvoiceHeaderIds.Add(Convert.ToInt32(item)); } } List <int> JobWorkerIds = new List <int>(); if (!string.IsNullOrEmpty(JobWorkerId)) { foreach (var item in JobWorkerId.Split(',')) { JobWorkerIds.Add(Convert.ToInt32(item)); } } //List<int> ProductIds = new List<int>(); //if (!string.IsNullOrEmpty(ProductId)) // foreach (var item in ProductId.Split(',')) // ProductIds.Add(Convert.ToInt32(item)); List <int> Dimension1Ids = new List <int>(); if (!string.IsNullOrEmpty(Dimension1Id)) { foreach (var item in Dimension1Id.Split(',')) { Dimension1Ids.Add(Convert.ToInt32(item)); } } List <int> Dimension2Ids = new List <int>(); if (!string.IsNullOrEmpty(Dimension2Id)) { foreach (var item in Dimension2Id.Split(',')) { Dimension2Ids.Add(Convert.ToInt32(item)); } } List <int> ProductGroupIds = new List <int>(); if (!string.IsNullOrEmpty(ProductGroupId)) { foreach (var item in ProductGroupId.Split(',')) { ProductGroupIds.Add(Convert.ToInt32(item)); } } //List<int> ProductCategoryIds = new List<int>(); //if (!string.IsNullOrEmpty(ProductCategoryId)) // foreach (var item in ProductCategoryId.Split(',')) // ProductCategoryIds.Add(Convert.ToInt32(item)); int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; var Settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(DocType, DivisionId, SiteId); string[] contraDocTypes = null; if (!string.IsNullOrEmpty(Settings.filterContraDocTypes)) { contraDocTypes = Settings.filterContraDocTypes.Split(",".ToCharArray()); } else { contraDocTypes = new string[] { "NA" }; } IQueryable <JobInvoiceAmendmentWizardViewModel> _data = from p in db.ViewJobInvoiceBalanceForRateAmendment join t in db.JobInvoiceLine on p.JobInvoiceLineId equals t.JobInvoiceLineId join ih in db.JobInvoiceHeader on p.JobInvoiceHeaderId equals ih.JobInvoiceHeaderId join jw in db.Persons on p.JobWorkerId equals jw.PersonID into jwtable from jwtab in jwtable.DefaultIfEmpty() join prod in db.FinishedProduct on p.ProductId equals prod.ProductId into prodtable from prodtab in prodtable.DefaultIfEmpty() join dim1 in db.Dimension1 on p.Dimension1Id equals dim1.Dimension1Id into dimtable from dimtab in dimtable.DefaultIfEmpty() join dim2 in db.Dimension2 on p.Dimension2Id equals dim2.Dimension2Id into dim2table from dim2tab in dim2table.DefaultIfEmpty() join pg in db.ProductGroups on prodtab.ProductGroupId equals pg.ProductGroupId into pgtable from pgtab in pgtable.DefaultIfEmpty() join pc in db.ProductCategory on prodtab.ProductCategoryId equals pc.ProductCategoryId into pctable from pctab in pctable.DefaultIfEmpty() where ih.ProcessId == ProcessId && (string.IsNullOrEmpty(Settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(t.JobInvoiceHeader.DocTypeId.ToString())) && ih.SiteId == SiteId && ih.DivisionId == DivisionId && p.Rate != NewRate select new JobInvoiceAmendmentWizardViewModel { InvoiceDate = p.InvoiceDate, InvoiceNo = p.JobInvoiceNo, JobInvoiceLineId = p.JobInvoiceLineId, OldRate = p.Rate, Rate = NewRate, JobWorkerName = jwtab.Name + "," + jwtab.Suffix, ProductName = prodtab.ProductName, Dimension1Name = dimtab.Dimension1Name, Dimension2Name = dim2tab.Dimension2Name, JobInvoiceHeaderId = p.JobInvoiceHeaderId, JobWorkerId = p.JobWorkerId, ProductGroupId = pgtab.ProductGroupId, ProductGroupName = pgtab.ProductGroupName, ProductCategoryId = pctab.ProductCategoryId, ProductCategoryName = pctab.ProductCategoryName, ProdId = p.ProductId, Dimension1Id = p.Dimension1Id, Dimension2Id = p.Dimension2Id, UnitConversionMultiplier = t.UnitConversionMultiplier, Sample = prodtab.IsSample, }; //if (FromDate.HasValue) // _data = from p in _data // where p.OrderDate >= FromDate // select p; if (FromDate.HasValue) { _data = _data.Where(m => m.InvoiceDate >= FromDate); } if (ToDate.HasValue) { _data = _data.Where(m => m.InvoiceDate <= ToDate); } if (Rate.HasValue) { _data = _data.Where(m => m.OldRate == Rate.Value); } if (MultiplierGT.HasValue) { _data = _data.Where(m => m.UnitConversionMultiplier >= MultiplierGT.Value); } if (MultiplierLT.HasValue) { _data = _data.Where(m => m.UnitConversionMultiplier <= MultiplierLT.Value); } if (!string.IsNullOrEmpty(JobInvoiceHeaderId)) { _data = _data.Where(m => JobInvoiceHeaderIds.Contains(m.JobInvoiceHeaderId)); } if (!string.IsNullOrEmpty(JobWorkerId)) { _data = _data.Where(m => JobWorkerIds.Contains(m.JobWorkerId)); } if (!string.IsNullOrEmpty(ProductId)) { _data = _data.Where(m => m.ProductName.Contains(ProductId)); } if (!string.IsNullOrEmpty(Dimension1Id)) { _data = _data.Where(m => Dimension1Ids.Contains(m.Dimension1Id ?? 0)); } if (!string.IsNullOrEmpty(Dimension2Id)) { _data = _data.Where(m => Dimension2Ids.Contains(m.Dimension2Id ?? 0)); } if (!string.IsNullOrEmpty(ProductGroupId)) { _data = _data.Where(m => ProductGroupIds.Contains(m.ProductGroupId)); } if (!string.IsNullOrEmpty(ProductCategoryId)) { _data = _data.Where(m => m.ProductCategoryName.Contains(ProductCategoryId)); } if (!string.IsNullOrEmpty(Sample) && Sample != "Include") { if (Sample == "Exclude") { _data = _data.Where(m => m.Sample == false); } else if (Sample == "Only") { _data = _data.Where(m => m.Sample == true); } } // simulate sort //if (sortColumn == 0) //{// sort Name _data = _data.OrderBy(m => m.InvoiceDate).ThenBy(m => m.InvoiceNo); //} //else if (sortColumn == 1) //{// sort Age // _data = sortDirection == "asc" ? _data.OrderBy(m => m.DocNo) : _data.OrderByDescending(m => m.DocNo); //} //else if (sortColumn == 2) //{ // sort DoB // _data = sortDirection == "asc" ? _data.OrderBy(m => m.DocDate) : _data.OrderByDescending(m => m.DocDate); //} //else if (sortColumn == 3) //{ // sort DoB // _data = sortDirection == "asc" ? _data.OrderBy(m => m.DueDate) : _data.OrderByDescending(m => m.DueDate); //} // get just one page of data return(_data.Select(m => new JobInvoiceAmendmentWizardViewModel { InvoiceDate = m.InvoiceDate, InvoiceNo = m.InvoiceNo, JobInvoiceLineId = m.JobInvoiceLineId, OldRate = m.OldRate, Rate = m.Rate, JobWorkerName = m.JobWorkerName, ProductName = m.ProductName, Dimension1Name = m.Dimension1Name, Dimension2Name = m.Dimension2Name, JobInvoiceHeaderId = m.JobInvoiceHeaderId, JobWorkerId = m.JobWorkerId, ProductGroupId = m.ProductGroupId, ProductGroupName = m.ProductGroupName, ProductCategoryId = m.ProductCategoryId, ProductCategoryName = m.ProductCategoryName, ProdId = m.ProdId, Dimension1Id = m.Dimension1Id, Dimension2Id = m.Dimension2Id, UnitConversionMultiplier = m.UnitConversionMultiplier, Sample = m.Sample, })); }
public ActionResult FinishingInvoiceReturnTextImport(int id, int?GodownId) { string[] StrArr = new string[] {}; string ErrorText = ""; //string WarningText = ""; if (Request.Files.Count == 0 || Request.Files[0].FileName == "") { ViewBag.id = id; ModelState.AddModelError("", "Please select file."); return(View("Index")); } if (GodownId == 0 || GodownId == null) { ViewBag.id = id; ModelState.AddModelError("", "Please select Godown."); return(View("Index")); } var file = Request.Files[0]; string filePath = Request.MapPath(ConfigurationManager.AppSettings["ExcelFilePath"] + file.FileName); file.SaveAs(filePath); StreamReader Sr; Sr = new StreamReader(filePath); string Line = ""; DataTable dataTable = new DataTable(); dataTable.Columns.Add("DocTypeId"); dataTable.Columns.Add("JobReturnDocTypeId"); dataTable.Columns.Add("DocDate"); dataTable.Columns["DocDate"].DataType = System.Type.GetType("System.DateTime"); dataTable.Columns.Add("DocNo"); dataTable.Columns.Add("JobReturnDocNo"); dataTable.Columns.Add("DivisionId"); dataTable.Columns.Add("SiteId"); dataTable.Columns.Add("ProcessCode"); dataTable.Columns.Add("OrderByCode"); dataTable.Columns.Add("ProductUidName"); dataTable.Columns.Add("SupplierCode"); dataTable.Columns.Add("CreatedBy"); dataTable.Columns.Add("GodownId"); int JobReturnDocTypeId = 0; var JobInvoiceSettings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(id, (int)System.Web.HttpContext.Current.Session["DivisionId"], (int)System.Web.HttpContext.Current.Session["SiteId"]); if (JobInvoiceSettings != null) { if (JobInvoiceSettings.JobReturnDocTypeId != null) { JobReturnDocTypeId = (int)JobInvoiceSettings.JobReturnDocTypeId; } } string PrevSupplierCode = ""; string PrevDocNo = ""; string PrevJobReturnDocNo = ""; string ConnectionString = (string)System.Web.HttpContext.Current.Session["DefaultConnectionString"]; string StrQry = " Declare @TmpTable as Table " + " ( " + " ProcessCode nVarchar(10), " + " ProductUidName nVarchar(10), " + " SupplierCode nVarchar(10), " + " OrderByCode nVarchar(10) " + " ) "; int i = 0; do { i++; Line = Sr.ReadLine(); if (Line != null) { StrArr = Line.Split(new Char[] { ',' }); StrQry += " Insert Into @TmpTable (ProcessCode, ProductUidName, SupplierCode, OrderByCode) "; StrQry += " Values ('" + StrArr[7] + "', '" + StrArr[13] + "', '" + StrArr[9] + "', '" + StrArr[11] + "')"; } } while (Line != null); Sr.Close(); string mQry = ""; mQry = StrQry + " Select ProcessCode, ProductUidName, SupplierCode, OrderByCode " + " From @TmpTable " + " Order by SupplierCode "; DataSet TextData = new DataSet(); using (SqlConnection sqlConnection = new SqlConnection(ConnectionString)) { sqlConnection.Open(); using (SqlCommand cmd = new SqlCommand(mQry)) { cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection; using (SqlDataAdapter adp = new SqlDataAdapter(cmd)) { adp.Fill(TextData); } } } for (i = 0; i <= TextData.Tables[0].Rows.Count - 1; i++) { var dr = dataTable.NewRow(); dr["DocTypeId"] = id; dr["JobReturnDocTypeId"] = JobReturnDocTypeId; dr["DocDate"] = DateTime.Now.Date; dr["DivisionId"] = (int)System.Web.HttpContext.Current.Session["DivisionId"]; dr["SiteId"] = (int)System.Web.HttpContext.Current.Session["SiteId"]; dr["ProductUidName"] = TextData.Tables[0].Rows[i]["ProductUidName"]; dr["SupplierCode"] = TextData.Tables[0].Rows[i]["SupplierCode"]; dr["CreatedBy"] = User.Identity.Name; dr["ProcessCode"] = TextData.Tables[0].Rows[i]["ProcessCode"]; dr["OrderByCode"] = TextData.Tables[0].Rows[i]["OrderByCode"]; dr["GodownId"] = GodownId; if (PrevSupplierCode != dr["SupplierCode"].ToString()) { if (PrevDocNo == "") { dr["DocNo"] = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".JobInvoiceHeaders", Convert.ToInt32(dr["DocTypeId"]), Convert.ToDateTime(dr["DocDate"]), Convert.ToInt32(dr["DivisionId"]), Convert.ToInt32(dr["SiteId"])); dr["JobReturnDocNo"] = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".JobReturnHeaders", Convert.ToInt32(dr["JobReturnDocTypeId"]), Convert.ToDateTime(dr["DocDate"]), Convert.ToInt32(dr["DivisionId"]), Convert.ToInt32(dr["SiteId"])); } else { dr["DocNo"] = PrevDocNo.Substring(0, 2) + "-" + (Convert.ToInt32(PrevDocNo.Substring(PrevDocNo.IndexOf("-") + 1)) + 1).ToString().PadLeft(4, '0').ToString(); dr["JobReturnDocNo"] = PrevJobReturnDocNo.Substring(0, 2) + "-" + (Convert.ToInt32(PrevJobReturnDocNo.Substring(PrevJobReturnDocNo.IndexOf("-") + 1)) + 1).ToString().PadLeft(4, '0').ToString(); } PrevSupplierCode = dr["SupplierCode"].ToString(); PrevDocNo = dr["DocNo"].ToString(); PrevJobReturnDocNo = dr["JobReturnDocNo"].ToString(); } else { dr["DocNo"] = PrevDocNo; dr["JobReturnDocNo"] = PrevJobReturnDocNo; } dataTable.Rows.Add(dr); } DataSet ds = new DataSet(); using (SqlConnection sqlConnection = new SqlConnection(ConnectionString)) { sqlConnection.Open(); using (SqlCommand cmd = new SqlCommand("" + ConfigurationManager.AppSettings["DataBaseSchema"] + ".ProcImportFinishingInvoiceReturnFromTextFile")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = sqlConnection; cmd.Parameters.AddWithValue("@TextFileData", dataTable); cmd.CommandTimeout = 1000; using (SqlDataAdapter adp = new SqlDataAdapter(cmd)) { adp.Fill(ds); } } } List <ImportErrors> ImportErrorList = new List <ImportErrors>(); if (ds.Tables[0].Rows.Count == 0) { ViewBag.id = id; return(View("Sucess")); } else { for (int j = 0; j <= ds.Tables[0].Rows.Count - 1; j++) { if (ds.Tables[0].Rows[j]["ErrorText"].ToString() != "") { ErrorText = ErrorText + ds.Tables[0].Rows[j]["ErrorText"].ToString() + "." + Environment.NewLine; } ImportErrors ImportError = new ImportErrors(); ImportError.ErrorText = ds.Tables[0].Rows[j]["ErrorText"].ToString(); ImportError.BarCodes = ds.Tables[0].Rows[j]["BarCodes"].ToString(); ImportErrorList.Add(ImportError); } if (ErrorText != "") { ViewBag.Error = ErrorText;// +WarningText; ViewBag.id = id; string DataTableSessionVarName = ""; DataTableSessionVarName = User.Identity.Name.ToString() + "ImportData" + id.ToString(); Session[DataTableSessionVarName] = dataTable; return(View("Error", ImportErrorList)); } return(View("Sucess")); } }
public ActionResult _ResultsPost(JobInvoiceAmendmentMasterDetailModel vm) { int Serial = _JobInvoiceRateAmendmentLineService.GetMaxSr(vm.JobInvoiceRateAmendmentLineViewModel.FirstOrDefault().JobInvoiceAmendmentHeaderId); var Header = new JobInvoiceAmendmentHeaderService(_unitOfWork).Find(vm.JobInvoiceRateAmendmentLineViewModel.FirstOrDefault().JobInvoiceAmendmentHeaderId); JobInvoiceSettings Settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>(); List <LineChargeViewModel> LineCharges = new List <LineChargeViewModel>(); List <LineReferenceIds> RefIds = new List <LineReferenceIds>(); bool HeaderChargeEdit = false; int?MaxLineId = new JobInvoiceRateAmendmentLineChargeService(db).GetMaxProductCharge(Header.JobInvoiceAmendmentHeaderId, "Web.JobInvoiceRateAmendmentLines", "JobInvoiceAmendmentHeaderId", "JobInvoiceRateAmendmentLineId"); int pk = 0; int PersonCount = 0; //int? CalculationId = Settings.CalculationId; List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>(); bool BeforeSave = true; try { BeforeSave = JobInvoiceAmendmentDocEvents.beforeLineSaveBulkEvent(this, new JobEventArgs(vm.JobInvoiceRateAmendmentLineViewModel.FirstOrDefault().JobInvoiceAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } if (!BeforeSave) { ModelState.AddModelError("", "Validation failed before save"); } int?CalculationId = 0; int JobInvoiceLineId = vm.JobInvoiceRateAmendmentLineViewModel.FirstOrDefault().JobInvoiceLineId; var SalesTaxGroupPerson = (from L in db.JobInvoiceLine where L.JobInvoiceLineId == JobInvoiceLineId select new { SalesTaxGroupPersonId = (int?)L.JobInvoiceHeader.SalesTaxGroupPerson.ChargeGroupPersonId ?? 0 }).FirstOrDefault(); if (SalesTaxGroupPerson != null) { CalculationId = new ChargeGroupPersonCalculationService(_unitOfWork).GetChargeGroupPersonCalculation(Header.DocTypeId, SalesTaxGroupPerson.SalesTaxGroupPersonId, Header.SiteId, Header.DivisionId) ?? 0; } if (CalculationId == 0) { CalculationId = Settings.CalculationId ?? 0; } if (ModelState.IsValid && BeforeSave && !EventException) { foreach (var item in vm.JobInvoiceRateAmendmentLineViewModel.Where(m => (m.AmendedRate - m.JobInvoiceRate) != 0 && m.AAmended == false)) { JobInvoiceRateAmendmentLine line = new JobInvoiceRateAmendmentLine(); line.JobInvoiceAmendmentHeaderId = item.JobInvoiceAmendmentHeaderId; line.JobInvoiceLineId = item.JobInvoiceLineId; line.Qty = item.Qty; line.AmendedRate = item.AmendedRate; line.Rate = item.AmendedRate - item.JobInvoiceRate; line.Amount = DecimalRoundOff.amountToFixed(item.DealQty * line.Rate, Settings.AmountRoundOff); line.JobInvoiceRate = item.JobInvoiceRate; line.JobWorkerId = item.JobWorkerId; line.Sr = Serial++; line.JobInvoiceRateAmendmentLineId = pk; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.Remark = item.Remark; LineStatus.Add(line.JobInvoiceLineId, line.Rate); RefIds.Add(new LineReferenceIds { LineId = line.JobInvoiceRateAmendmentLineId, RefLineId = line.JobInvoiceLineId }); line.ObjectState = Model.ObjectState.Added; db.JobInvoiceRateAmendmentLine.Add(line); LineList.Add(new LineDetailListViewModel { Amount = line.Amount, Rate = line.Rate, LineTableId = line.JobInvoiceRateAmendmentLineId, HeaderTableId = item.JobInvoiceAmendmentHeaderId, PersonID = Header.JobWorkerId, DealQty = 0 }); //_JobInvoiceRateAmendmentLineService.Create(line); pk++; } //Commented No InvoiceLineStatus //new JobInvoiceLineStatusService(_unitOfWork).UpdateJobRateOnAmendmentMultiple(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.JobInvoiceAmendmentHeader.Add(Header); int[] RecLineIds = null; RecLineIds = RefIds.Select(m => m.RefLineId).ToArray(); var Charges = (from p in db.JobInvoiceLine where RecLineIds.Contains(p.JobInvoiceLineId) join LineCharge in db.JobInvoiceLineCharge on p.JobInvoiceLineId equals LineCharge.LineTableId join HeaderCharge in db.JobInvoiceHeaderCharges on p.JobInvoiceHeaderId equals HeaderCharge.HeaderTableId group new { p, LineCharge, HeaderCharge } by new { p.JobInvoiceLineId } into g select new { LineId = g.Key.JobInvoiceLineId, HeaderCharges = g.Select(m => m.HeaderCharge).ToList(), Linecharges = g.Select(m => m.LineCharge).ToList(), }).ToList(); var LineListWithReferences = (from p in LineList join t in RefIds on p.LineTableId equals t.LineId join t2 in Charges on t.RefLineId equals t2.LineId into table from LineLis in table.DefaultIfEmpty() orderby p.LineTableId select new LineDetailListViewModel { Amount = p.Amount, DealQty = p.DealQty, HeaderTableId = p.HeaderTableId, LineTableId = p.LineTableId, PersonID = p.PersonID, Rate = p.Rate, CostCenterId = p.CostCenterId, RLineCharges = (LineLis == null ? null : Mapper.Map <List <LineChargeViewModel> >(LineLis.Linecharges)), }).ToList(); if (CalculationId != null) { new ChargesCalculationService(_unitOfWork).CalculateCharges(LineListWithReferences, vm.JobInvoiceRateAmendmentLineViewModel.FirstOrDefault().JobInvoiceAmendmentHeaderId, (int)CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.JobInvoiceAmendmentHeaderCharges", "Web.JobInvoiceRateAmendmentLineCharges", out PersonCount, Header.DocTypeId, Header.SiteId, Header.DivisionId); } //Saving Charges foreach (var item in LineCharges) { JobInvoiceRateAmendmentLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, JobInvoiceRateAmendmentLineCharge>(item); PoLineCharge.ObjectState = Model.ObjectState.Added; db.JobInvoiceRateAmendmentLineCharge.Add(PoLineCharge); } //Saving Header charges for (int i = 0; i < HeaderCharges.Count(); i++) { if (!HeaderChargeEdit) { JobInvoiceAmendmentHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, JobInvoiceAmendmentHeaderCharge>(HeaderCharges[i]); POHeaderCharge.HeaderTableId = vm.JobInvoiceRateAmendmentLineViewModel.FirstOrDefault().JobInvoiceAmendmentHeaderId; POHeaderCharge.PersonID = Header.JobWorkerId; POHeaderCharge.ObjectState = Model.ObjectState.Added; db.JobInvoiceAmendmentHeaderCharge.Add(POHeaderCharge); } else { var footercharge = new JobInvoiceAmendmentHeaderChargeService(db).Find(HeaderCharges[i].Id); footercharge.Rate = HeaderCharges[i].Rate; footercharge.Amount = HeaderCharges[i].Amount; footercharge.ObjectState = Model.ObjectState.Modified; db.JobInvoiceAmendmentHeaderCharge.Add(footercharge); } } try { JobInvoiceAmendmentDocEvents.onLineSaveBulkEvent(this, new JobEventArgs(vm.JobInvoiceRateAmendmentLineViewModel.FirstOrDefault().JobInvoiceAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; return(PartialView("_Results", vm)); } try { JobInvoiceAmendmentDocEvents.afterLineSaveBulkEvent(this, new JobEventArgs(vm.JobInvoiceRateAmendmentLineViewModel.FirstOrDefault().JobInvoiceAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = Header.DocTypeId, DocId = Header.JobInvoiceAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.MultipleCreate, DocNo = Header.DocNo, DocDate = Header.DocDate, DocStatus = Header.Status, })); return(Json(new { success = true })); } return(PartialView("_Results", vm)); }