// GET: /JobOrderSettingsMaster/Create public ActionResult Create(int id)//DocTypeId { 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(id); var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(id, DivisionId, SiteId); if (settings == null) { JobOrderSettingsViewModel vm = new JobOrderSettingsViewModel(); vm.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; vm.SiteId = SiteId; vm.DivisionId = DivisionId; vm.DocTypeId = id; return(View("Create", vm)); } else { JobOrderSettingsViewModel temp = AutoMapper.Mapper.Map <JobOrderSettings, JobOrderSettingsViewModel>(settings); temp.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; return(View("Create", temp)); } }
public ActionResult Create(int id)//DocumentTypeId { PrepareViewBag(id); JobOrderAmendmentHeaderViewModel vm = new JobOrderAmendmentHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; //Getting Settings var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(id, vm.DivisionId, vm.SiteId); vm.JobOrderSettings = Mapper.Map <JobOrderSettings, JobOrderSettingsViewModel>(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"] + ".JobOrderAmendmentHeaders", vm.DocTypeId, vm.DocDate, vm.DivisionId, vm.SiteId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
public ActionResult _Create(int Id, int?sid) //Id ==>Sale Order Header Id { JobOrderAmendmentHeader header = new JobOrderAmendmentHeaderService(_unitOfWork).Find(Id); JobOrderRateAmendmentLineViewModel svm = new JobOrderRateAmendmentLineViewModel(); //Getting Settings var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(header.DocTypeId, header.DivisionId, header.SiteId); svm.JobOrderSettings = Mapper.Map <JobOrderSettings, JobOrderSettingsViewModel>(settings); svm.DocumentTypeSettings = new DocumentTypeSettingsService(_unitOfWork).GetDocumentTypeSettingsForDocument(header.DocTypeId); ViewBag.LineMode = "Create"; svm.JobOrderAmendmentHeaderId = Id; svm.JobWorkerId = sid.HasValue ? sid.Value : 0; return(PartialView("_Create", svm)); }
public ActionResult SummarizeProdOrders() { int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; List <string> UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"]; int DocTypeId = new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.DyeingOrder).DocumentTypeId; //Getting Settings var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(DocTypeId, DivisionId, SiteId); ViewBag.AllowedPerc = settings.ExcessQtyAllowedPer; return(View("SummarizeProdOrders")); }
// GET: /JobOrderHeader/Create public ActionResult Create()//DocumentTypeId { JobOrderHeaderViewModel p = new JobOrderHeaderViewModel(); p.DocDate = DateTime.Now; p.DueDate = DateTime.Now; p.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; p.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; p.CreatedDate = DateTime.Now; List <string> UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"]; int DocTypeId = new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.DyeingOrder).DocumentTypeId; //Getting Settings var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(DocTypeId, p.DivisionId, p.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "JobOrderSettings", new { id = DocTypeId }).Warning("Please create job order settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } p.JobOrderSettings = Mapper.Map <JobOrderSettings, JobOrderSettingsViewModel>(settings); List <PerkViewModel> Perks = new List <PerkViewModel>(); //Perks if (p.JobOrderSettings.Perks != null) { foreach (var item in p.JobOrderSettings.Perks.Split(',').ToList()) { PerkViewModel temp = Mapper.Map <Perk, PerkViewModel>(new PerkService(_unitOfWork).Find(Convert.ToInt32(item))); Perks.Add(temp); } } p.PerkViewModel = Perks; p.ProcessId = settings.ProcessId; PrepareViewBag(); p.DocTypeId = DocTypeId; p.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".JobOrderHeaders", p.DocTypeId, p.DocDate, p.DivisionId, p.SiteId); return(View(p)); }
public ActionResult Report(int id) { DocumentType Dt = new DocumentType(); Dt = new DocumentTypeService(_unitOfWork).Find(id); JobOrderSettings SEttings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(Dt.DocumentTypeId, (int)System.Web.HttpContext.Current.Session["DivisionId"], (int)System.Web.HttpContext.Current.Session["SiteId"]); Dictionary <int, string> DefaultValue = new Dictionary <int, string>(); if (!Dt.ReportMenuId.HasValue) { throw new Exception("Report Menu not configured in document types"); } Model.Models.Menu menu = new MenuService(_unitOfWork).Find(Dt.ReportMenuId ?? 0); if (menu != null) { ReportHeader header = new ReportHeaderService(_unitOfWork).GetReportHeaderByName(menu.MenuName); ReportLine Line = new ReportLineService(_unitOfWork).GetReportLineByName("DocumentType", header.ReportHeaderId); if (Line != null) { DefaultValue.Add(Line.ReportLineId, id.ToString()); } ReportLine Site = new ReportLineService(_unitOfWork).GetReportLineByName("Site", header.ReportHeaderId); if (Site != null) { DefaultValue.Add(Site.ReportLineId, ((int)System.Web.HttpContext.Current.Session["SiteId"]).ToString()); } ReportLine Division = new ReportLineService(_unitOfWork).GetReportLineByName("Division", header.ReportHeaderId); if (Division != null) { DefaultValue.Add(Division.ReportLineId, ((int)System.Web.HttpContext.Current.Session["DivisionId"]).ToString()); } //ReportLine Process = new ReportLineService(_unitOfWork).GetReportLineByName("Process", header.ReportHeaderId); //if (Process != null) // DefaultValue.Add(Process.ReportLineId, ((int)SEttings.ProcessId).ToString()); } TempData["ReportLayoutDefaultValues"] = DefaultValue; return(Redirect((string)System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/Report_ReportPrint/ReportPrint/?MenuId=" + Dt.ReportMenuId)); }
public ActionResult RateAmendtmentWizard(int id)//DocumentTypeId { PrepareViewBag(id); JobOrderAmendmentHeaderViewModel vm = new JobOrderAmendmentHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; //Getting Settings var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(id, vm.DivisionId, vm.SiteId); if (settings == null) { return(RedirectToAction("CreateJobOrderAmendment", "JobOrderSettings", new { id = id }).Warning("Please create job amendment settings")); } ViewBag.ProcessId = settings.ProcessId; return(View()); }
private ActionResult _Delete(int id) { JobOrderRateAmendmentLineViewModel temp = _JobOrderRateAmendmentLineService.GetJobOrderRateAmendmentLine(id); if (temp == null) { return(HttpNotFound()); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocumentLine(new DocumentUniqueId { LockReason = temp.LockReason }, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXCL"] += ExceptionMsg; } #endregion if ((TimePlanValidation || Continue)) { ViewBag.LineMode = "Delete"; } JobOrderAmendmentHeader header = new JobOrderAmendmentHeaderService(_unitOfWork).Find(temp.JobOrderAmendmentHeaderId); //Getting Settings var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(header.DocTypeId, header.DivisionId, header.SiteId); temp.JobOrderSettings = Mapper.Map <JobOrderSettings, JobOrderSettingsViewModel>(settings); temp.DocumentTypeSettings = new DocumentTypeSettingsService(_unitOfWork).GetDocumentTypeSettingsForDocument(header.DocTypeId); return(PartialView("_Create", temp)); }
public ActionResult CreateDyeingOrder() { int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; List <string> UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"]; int DocTypeId = new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.DyeingOrder).DocumentTypeId; //Getting Settings var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(DocTypeId, DivisionId, SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "JobOrderSettings", new { id = DocTypeId }).Warning("Please create settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } return(View("CreateDyeingOrder")); }
// GET: /JobOrderSettingsMaster/Create public ActionResult CreateJobOrderAmendment(int id)//DocTypeId { var DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; var SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; PrepareViewBag(id); var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(id, DivisionId, SiteId); if (settings == null) { JobOrderSettingsViewModel vm = new JobOrderSettingsViewModel(); vm.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; vm.SiteId = SiteId; vm.DivisionId = DivisionId; vm.DocTypeId = id; return(View("CreateJobOrderAmendment", vm)); } else { JobOrderSettingsViewModel temp = AutoMapper.Mapper.Map <JobOrderSettings, JobOrderSettingsViewModel>(settings); temp.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; return(View("CreateJobOrderAmendment", temp)); } }
public ActionResult FinishingOrderCancelTextImport(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("DocDate"); dataTable.Columns["DocDate"].DataType = System.Type.GetType("System.DateTime"); dataTable.Columns.Add("DocNo"); 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"); var JobOrderCancelSettings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(id, (int)System.Web.HttpContext.Current.Session["DivisionId"], (int)System.Web.HttpContext.Current.Session["SiteId"]); string PrevSupplierCode = ""; string PrevDocNo = ""; 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["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"] + ".JobOrderCancelHeaders", Convert.ToInt32(dr["DocTypeId"]), 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(); } PrevSupplierCode = dr["SupplierCode"].ToString(); PrevDocNo = dr["DocNo"].ToString(); } else { dr["DocNo"] = PrevDocNo; } dataTable.Rows.Add(dr); } DataSet ds = new DataSet(); using (SqlConnection sqlConnection = new SqlConnection(ConnectionString)) { sqlConnection.Open(); using (SqlCommand cmd = new SqlCommand("" + ConfigurationManager.AppSettings["DataBaseSchema"] + ".ProcImportFinishingOrderCancelFromTextFile")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = sqlConnection; cmd.Parameters.AddWithValue("@TextFileData", dataTable); cmd.CommandTimeout = 1000; //cmd.Connection.Open(); //cmd.ExecuteNonQuery(); using (SqlDataAdapter adp = new SqlDataAdapter(cmd)) { adp.Fill(ds); } //cmd.Connection.Close(); } } 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; } //if (ds.Tables[0].Rows[j]["WarningText"].ToString() != "") //{ // WarningText = WarningText + ds.Tables[0].Rows[j]["WarningText"].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"); return(View("Error", ImportErrorList)); } return(View("Sucess")); } }
public ActionResult Post(JobOrderAmendmentHeaderViewModel vm) { bool BeforeSave = true; int Serial = 1; Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); JobOrderAmendmentHeader pt = AutoMapper.Mapper.Map <JobOrderAmendmentHeaderViewModel, JobOrderAmendmentHeader>(vm); var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId); if (!vm.JobOrderSettings.isVisibleJobWorkerLine && !vm.JobWorkerId.HasValue) { ModelState.AddModelError("JobWorkerId", "The JobWorker field is required"); } try { BeforeSave = JobOrderAmendmentDocEvents.beforeWizardSaveEvent(this, new JobEventArgs(vm.JobOrderAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before save"; } if (ModelState.IsValid && BeforeSave && !EventException) { pt.Status = (int)StatusConstants.Drafted; pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; db.JobOrderAmendmentHeader.Add(pt); //_JobOrderAmendmentHeaderService.Create(pt); var SelectedJobOrders = (List <JobOrderAmendmentWizardViewModel>)System.Web.HttpContext.Current.Session["RateAmendmentWizardOrders"]; var JobOrderLineIds = SelectedJobOrders.Select(m => m.JobOrderLineId).ToArray(); var JobOrderBalanceRecords = (from p in db.ViewJobOrderBalanceForInvoice where JobOrderLineIds.Contains(p.JobOrderLineId) select p).AsNoTracking().ToList(); var JobOrderRecords = (from p in db.JobOrderLine where JobOrderLineIds.Contains(p.JobOrderLineId) select p).AsNoTracking().ToList(); foreach (var item in SelectedJobOrders) { if (item.Rate - JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().Rate != 0) { JobOrderRateAmendmentLine line = new JobOrderRateAmendmentLine(); line.JobOrderAmendmentHeaderId = pt.JobOrderAmendmentHeaderId; line.JobOrderLineId = item.JobOrderLineId; line.Qty = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().BalanceQty; line.AmendedRate = item.Rate; line.Rate = line.AmendedRate - JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().Rate; line.Amount = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().BalanceQty *JobOrderRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().UnitConversionMultiplier *line.Rate; line.Amount = DecimalRoundOff.amountToFixed(line.Amount, settings.AmountRoundOff); line.JobOrderRate = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().Rate; line.JobWorkerId = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().JobWorkerId; line.Sr = Serial++; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; LineStatus.Add(line.JobOrderLineId, line.Rate); line.ObjectState = Model.ObjectState.Added; db.JobOrderRateAmendmentLine.Add(line); } } new JobOrderLineStatusService(_unitOfWork).UpdateJobRateOnAmendmentMultiple(LineStatus, pt.DocDate, ref db); try { JobOrderAmendmentDocEvents.onWizardSaveEvent(this, new JobEventArgs(pt.JobOrderAmendmentHeaderId, 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 { JobOrderAmendmentDocEvents.afterWizardSaveEvent(this, new JobEventArgs(pt.JobOrderAmendmentHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.JobOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.WizardCreate, User = User.Identity.Name, DocNo = pt.DocNo, DocDate = pt.DocDate }); Session.Remove("RateAmendmentWizardOrders"); return(RedirectToAction("Index", "JobOrderAmendmentHeader", new { id = pt.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 <JobOrderAmendmentWizardViewModel> FilterData(int ProcessId, int DocType, DateTime?FromDate, DateTime?ToDate, string JobOrderHeaderId, string JobWorkerId, string ProductId, string Dimension1Id, string Dimension2Id, string ProductGroupId, string ProductCategoryId, decimal?Rate, decimal NewRate, decimal?MultiplierGT, decimal?MultiplierLT, string Sample) { List <int> JobOrderHeaderIds = new List <int>(); if (!string.IsNullOrEmpty(JobOrderHeaderId)) { foreach (var item in JobOrderHeaderId.Split(',')) { JobOrderHeaderIds.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)); int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; var Settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(DocType, DivisionId, SiteId); string[] contraDocTypes = null; if (!string.IsNullOrEmpty(Settings.filterContraDocTypes)) { contraDocTypes = Settings.filterContraDocTypes.Split(",".ToCharArray()); } else { contraDocTypes = new string[] { "NA" }; } IQueryable <JobOrderAmendmentWizardViewModel> _data = from p in db.ViewJobOrderBalanceForInvoice join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId 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 t.JobOrderHeader.ProcessId == ProcessId && p.BalanceQty > 0 && (string.IsNullOrEmpty(Settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(t.JobOrderHeader.DocTypeId.ToString())) //&& (FromDate.HasValue ? p.OrderDate >= FromDate : 1 == 1) //&& (ToDate.HasValue ? p.OrderDate <= ToDate : 1 == 1) //&& (Rate.HasValue ? p.Rate == Rate : 1 == 1) //&& (string.IsNullOrEmpty(JobOrderHeaderId) ? 1 == 1 : JobOrderHeaderIds.Contains(p.JobOrderHeaderId)) //&& (string.IsNullOrEmpty(JobWorkerId) ? 1 == 1 : JobWorkerIds.Contains(p.JobWorkerId)) //&& (string.IsNullOrEmpty(ProductId) ? 1 == 1 : ProductIds.Contains(p.ProductId)) //&& (string.IsNullOrEmpty(Dimension1Id) ? 1 == 1 : Dimension1Ids.Contains(p.Dimension1Id ?? 0)) //&& (string.IsNullOrEmpty(Dimension1Id) ? 1 == 1 : Dimension1Ids.Contains(p.Dimension1Id ?? 0)) //&& (string.IsNullOrEmpty(ProductGroupId) ? 1 == 1 : ProductGroupIds.Contains(prodtab.ProductGroupId ?? 0)) select new JobOrderAmendmentWizardViewModel { OrderDate = p.OrderDate, OrderNo = p.JobOrderNo, JobOrderLineId = p.JobOrderLineId, OldRate = p.Rate, Rate = NewRate, JobWorkerName = jwtab.Name, ProductName = prodtab.ProductName, Dimension1Name = dimtab.Dimension1Name, Dimension2Name = dim2tab.Dimension2Name, JobOrderHeaderId = p.JobOrderHeaderId, 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.OrderDate >= FromDate); } if (ToDate.HasValue) { _data = _data.Where(m => m.OrderDate <= ToDate); } if (Rate.HasValue && Rate.Value > 0) { _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(JobOrderHeaderId)) { _data = _data.Where(m => JobOrderHeaderIds.Contains(m.JobOrderHeaderId)); } 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 => m.ProductGroupName.Contains(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.OrderDate).ThenBy(m => m.OrderNo); //} //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 JobOrderAmendmentWizardViewModel { OrderDate = m.OrderDate, OrderNo = m.OrderNo, JobOrderLineId = m.JobOrderLineId, OldRate = m.OldRate, Rate = m.Rate, JobWorkerName = m.JobWorkerName, ProductName = m.ProductName, Dimension1Name = m.Dimension1Name, Dimension2Name = m.Dimension2Name, JobOrderHeaderId = m.JobOrderHeaderId, 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 _ResultsPost(JobOrderAmendmentMasterDetailModel vm) { int Serial = _JobOrderRateAmendmentLineService.GetMaxSr(vm.JobOrderRateAmendmentLineViewModel.FirstOrDefault().JobOrderAmendmentHeaderId); var Header = new JobOrderAmendmentHeaderService(_unitOfWork).Find(vm.JobOrderRateAmendmentLineViewModel.FirstOrDefault().JobOrderAmendmentHeaderId); Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); JobOrderSettings Settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); #region BeforeSave bool BeforeSave = true; try { BeforeSave = JobOrderAmendmentDocEvents.beforeLineSaveBulkEvent(this, new JobEventArgs(vm.JobOrderRateAmendmentLineViewModel.FirstOrDefault().JobOrderAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } if (!BeforeSave) { ModelState.AddModelError("", "Validation failed before save"); } #endregion if (ModelState.IsValid && BeforeSave && !EventException) { foreach (var item in vm.JobOrderRateAmendmentLineViewModel.Where(m => (m.AmendedRate - m.JobOrderRate) != 0 && m.AAmended == false)) { JobOrderRateAmendmentLine line = new JobOrderRateAmendmentLine(); line.JobOrderAmendmentHeaderId = item.JobOrderAmendmentHeaderId; line.JobOrderLineId = item.JobOrderLineId; line.Qty = item.Qty; line.AmendedRate = item.AmendedRate; line.Rate = item.AmendedRate - item.JobOrderRate; line.Amount = DecimalRoundOff.amountToFixed((item.DealQty * line.Rate), Settings.AmountRoundOff); line.JobOrderRate = item.JobOrderRate; line.JobWorkerId = item.JobWorkerId; line.Sr = Serial++; 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.JobOrderLineId, line.Rate); line.ObjectState = Model.ObjectState.Added; db.JobOrderRateAmendmentLine.Add(line); //_JobOrderRateAmendmentLineService.Create(line); } 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.JobOrderAmendmentHeader.Add(Header); new JobOrderLineStatusService(_unitOfWork).UpdateJobRateOnAmendmentMultiple(LineStatus, Header.DocDate, ref db); try { JobOrderAmendmentDocEvents.onLineSaveBulkEvent(this, new JobEventArgs(vm.JobOrderRateAmendmentLineViewModel.FirstOrDefault().JobOrderAmendmentHeaderId), 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 { JobOrderAmendmentDocEvents.afterLineSaveBulkEvent(this, new JobEventArgs(vm.JobOrderRateAmendmentLineViewModel.FirstOrDefault().JobOrderAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = Header.DocTypeId, DocId = Header.JobOrderAmendmentHeaderId, 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(JobOrderRateAmendmentLineViewModel svm) { bool BeforeSave = true; if (svm.JobOrderRateAmendmentLineId <= 0) { ViewBag.LineMode = "Create"; } else { ViewBag.LineMode = "Edit"; } if (svm.JobWorkerId == 0) { ModelState.AddModelError("JobWorkerId", "The JobWorker field is required"); } #region BeforeSave try { if (svm.JobOrderRateAmendmentLineId <= 0) { BeforeSave = JobOrderAmendmentDocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.JobOrderAmendmentHeaderId, EventModeConstants.Add), ref db); } else { BeforeSave = JobOrderAmendmentDocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.JobOrderAmendmentHeaderId, 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."); } #endregion JobOrderAmendmentHeader temp2 = new JobOrderAmendmentHeaderService(_unitOfWork).Find(svm.JobOrderAmendmentHeaderId); JobOrderSettings Settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(temp2.DocTypeId, temp2.DivisionId, temp2.SiteId); if (svm.JobOrderRateAmendmentLineId <= 0) { JobOrderRateAmendmentLine s = new JobOrderRateAmendmentLine(); if (ModelState.IsValid && BeforeSave && !EventException) { if (svm.Rate != 0) { s.Remark = svm.Remark; s.JobOrderAmendmentHeaderId = svm.JobOrderAmendmentHeaderId; s.JobOrderLineId = svm.JobOrderLineId; s.Qty = svm.Qty; s.AmendedRate = svm.AmendedRate; s.Amount = svm.Amount; s.JobOrderRate = svm.JobOrderRate; s.JobWorkerId = svm.JobWorkerId; s.Rate = svm.Rate; s.Remark = svm.Remark; s.Sr = _JobOrderRateAmendmentLineService.GetMaxSr(s.JobOrderAmendmentHeaderId); s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; //_JobOrderRateAmendmentLineService.Create(s); s.ObjectState = Model.ObjectState.Added; db.JobOrderRateAmendmentLine.Add(s); if (temp2.Status != (int)StatusConstants.Drafted) { temp2.Status = (int)StatusConstants.Modified; temp2.ModifiedBy = User.Identity.Name; temp2.ModifiedDate = DateTime.Now; } //new JobOrderAmendmentHeaderService(_unitOfWork).Update(temp2); temp2.ObjectState = Model.ObjectState.Modified; db.JobOrderAmendmentHeader.Add(temp2); new JobOrderLineStatusService(_unitOfWork).UpdateJobRateOnAmendment(svm.JobOrderLineId, s.JobOrderRateAmendmentLineId, temp2.DocDate, s.Rate, ref db); try { JobOrderAmendmentDocEvents.onLineSaveEvent(this, new JobEventArgs(s.JobOrderAmendmentHeaderId, s.JobOrderRateAmendmentLineId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; return(PartialView("_Create", svm)); } try { JobOrderAmendmentDocEvents.afterLineSaveEvent(this, new JobEventArgs(s.JobOrderAmendmentHeaderId, s.JobOrderRateAmendmentLineId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp2.DocTypeId, DocId = temp2.JobOrderAmendmentHeaderId, DocLineId = s.JobOrderRateAmendmentLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp2.DocNo, DocDate = temp2.DocDate, DocStatus = temp2.Status, })); } if (svm.JobOrderSettings.isVisibleJobWorkerLine) { return(RedirectToAction("_Create", new { id = s.JobOrderAmendmentHeaderId })); } else { return(RedirectToAction("_Create", new { id = s.JobOrderAmendmentHeaderId, sid = svm.JobWorkerId })); } } return(PartialView("_Create", svm)); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); JobOrderAmendmentHeader temp = new JobOrderAmendmentHeaderService(_unitOfWork).Find(svm.JobOrderAmendmentHeaderId); int status = temp.Status; StringBuilder logstring = new StringBuilder(); JobOrderRateAmendmentLine s = _JobOrderRateAmendmentLineService.Find(svm.JobOrderRateAmendmentLineId); JobOrderRateAmendmentLine ExRecLine = new JobOrderRateAmendmentLine(); ExRecLine = Mapper.Map <JobOrderRateAmendmentLine>(s); if (ModelState.IsValid && BeforeSave && !EventException) { if (svm.Rate != 0) { s.Remark = svm.Remark; s.AmendedRate = svm.AmendedRate; s.Rate = svm.Rate; s.Amount = svm.Amount; s.ModifiedBy = User.Identity.Name; s.ModifiedDate = DateTime.Now; } s.ObjectState = Model.ObjectState.Modified; db.JobOrderRateAmendmentLine.Add(s); //_JobOrderRateAmendmentLineService.Update(s); new JobOrderLineStatusService(_unitOfWork).UpdateJobRateOnAmendment(s.JobOrderLineId, s.JobOrderRateAmendmentLineId, temp.DocDate, s.Rate, ref db); if (temp.Status != (int)StatusConstants.Drafted) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; } //new JobOrderAmendmentHeaderService(_unitOfWork).Update(temp); temp.ObjectState = Model.ObjectState.Modified; db.JobOrderAmendmentHeader.Add(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRecLine, Obj = s, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { JobOrderAmendmentDocEvents.onLineSaveEvent(this, new JobEventArgs(s.JobOrderAmendmentHeaderId, s.JobOrderRateAmendmentLineId, EventModeConstants.Edit), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; return(PartialView("_Create", svm)); } try { JobOrderAmendmentDocEvents.afterLineSaveEvent(this, new JobEventArgs(s.JobOrderAmendmentHeaderId, s.JobOrderRateAmendmentLineId, 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 = temp.JobOrderAmendmentHeaderId, DocLineId = s.JobOrderRateAmendmentLineId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, DocDate = temp.DocDate, xEModifications = Modifications, DocStatus = temp.Status, })); //End Of Saving Activity Log return(Json(new { success = true })); } return(PartialView("_Create", svm)); } }
public ActionResult Post(JobOrderHeaderViewModel svm) { JobOrderHeader s = Mapper.Map <JobOrderHeaderViewModel, JobOrderHeader>(svm); ProdOrderCancelHeader cHeader = new ProdOrderCancelHeader(); if (svm.JobOrderSettings != null) { if (svm.JobOrderSettings.isMandatoryCostCenter == true && (svm.CostCenterId <= 0 || svm.CostCenterId == null)) { ModelState.AddModelError("CostCenterId", "The CostCenter field is required"); } if (svm.JobOrderSettings.isMandatoryMachine == true && (svm.MachineId <= 0 || svm.MachineId == null)) { ModelState.AddModelError("MachineId", "The Machine field is required"); } if (svm.JobOrderSettings.isPostedInStock == true && !svm.GodownId.HasValue) { ModelState.AddModelError("GodownId", "The Godown field is required"); } } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), 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 && (TimePlanValidation || Continue)) { List <ProdOrderHeaderListViewModel> ProdOrderIds = (List <ProdOrderHeaderListViewModel>)System.Web.HttpContext.Current.Session["ConfirmProdOrderIds"]; bool CancelBalProdOrders = (bool)System.Web.HttpContext.Current.Session["CancelBalProdOrdrs"]; bool CreateDyeingOrder = ProdOrderIds.Any(m => m.Qty > 0); var ProdOrderLineIds = ProdOrderIds.Select(m => m.ProdOrderLineId).ToArray(); var BalProdOrders = (from p in db.ViewProdOrderBalance.AsNoTracking() where ProdOrderLineIds.Contains(p.ProdOrderLineId) select p).ToList(); var ProdOrderLines = (from p in db.ProdOrderLine.AsNoTracking() where ProdOrderLineIds.Contains(p.ProdOrderLineId) select p).ToList(); var ProductIds = BalProdOrders.Select(m => m.ProductId).ToList(); var Products = (from p in db.Product.AsNoTracking() where ProductIds.Contains(p.ProductId) select p).ToList(); bool CancelQty = (from p in ProdOrderIds join t in BalProdOrders on p.ProdOrderLineId equals t.ProdOrderLineId where (t.BalanceQty - p.Qty) > 0 select p).Any(); CancelBalProdOrders = (CancelBalProdOrders && CancelQty); if (CreateDyeingOrder) { s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.ActualDueDate = s.DueDate; s.ActualDocDate = s.DocDate; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; _JobOrderHeaderService.Create(s); new JobOrderHeaderStatusService(_unitOfWork).CreateHeaderStatus(s.JobOrderHeaderId, ref db, false); if (svm.PerkViewModel != null) { foreach (PerkViewModel item in svm.PerkViewModel) { JobOrderPerk perk = Mapper.Map <PerkViewModel, JobOrderPerk>(item); perk.CreatedBy = User.Identity.Name; perk.CreatedDate = DateTime.Now; perk.ModifiedBy = User.Identity.Name; perk.ModifiedDate = DateTime.Now; perk.JobOrderHeaderId = s.JobOrderHeaderId; new JobOrderPerkService(_unitOfWork).Create(perk); } } } if (CancelBalProdOrders) { cHeader.DocNo = s.DocNo; cHeader.DocDate = s.DocDate; cHeader.DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(TransactionDoctypeConstants.DyeingPlanCancel).DocumentTypeId; cHeader.DivisionId = s.DivisionId; cHeader.SiteId = s.SiteId; cHeader.CreatedBy = User.Identity.Name; cHeader.CreatedDate = DateTime.Now; cHeader.ModifiedBy = User.Identity.Name; cHeader.ModifiedDate = DateTime.Now; cHeader.ReferenceDocId = s.JobOrderHeaderId; cHeader.ReferenceDocTypeId = s.DocTypeId; cHeader.Remark = s.Remark; cHeader.ObjectState = Model.ObjectState.Added; new ProdOrderCancelHeaderService(_unitOfWork).Create(cHeader); } int Cnt = 0; List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>(); List <LineChargeViewModel> LineCharges = new List <LineChargeViewModel>(); int pk = 0; bool HeaderChargeEdit = false; JobOrderSettings Settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId); int?MaxLineId = new JobOrderLineChargeService(_unitOfWork).GetMaxProductCharge(s.JobOrderHeaderId, "Web.JobOrderLines", "JobOrderHeaderId", "JobOrderLineId"); int PersonCount = 0; //if (!Settings.CalculationId.HasValue) //{ // throw new Exception("Calculation not configured in Job order settings"); //} int CalculationId = Settings.CalculationId ?? 0; List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>(); foreach (var ProdORderLineId in ProdOrderIds) { var BalProdOrderLine = BalProdOrders.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault(); var Product = Products.Where(m => m.ProductId == BalProdOrderLine.ProductId).FirstOrDefault(); if (ProdORderLineId.Qty <= BalProdOrderLine.BalanceQty && ProdORderLineId.Qty > 0) { if (((Settings.isVisibleRate == false || Settings.isVisibleRate == true))) { JobOrderLine line = new JobOrderLine(); if (Settings.isPostedInStock ?? false) { StockViewModel StockViewModel = new StockViewModel(); if (Cnt == 0) { StockViewModel.StockHeaderId = s.StockHeaderId ?? 0; } else { if (s.StockHeaderId != null && s.StockHeaderId != 0) { StockViewModel.StockHeaderId = (int)s.StockHeaderId; } else { StockViewModel.StockHeaderId = -1; } } StockViewModel.StockId = -Cnt; StockViewModel.DocHeaderId = s.JobOrderHeaderId; StockViewModel.DocLineId = line.JobOrderLineId; StockViewModel.DocTypeId = s.DocTypeId; StockViewModel.StockHeaderDocDate = s.DocDate; StockViewModel.StockDocDate = s.DocDate; StockViewModel.DocNo = s.DocNo; StockViewModel.DivisionId = s.DivisionId; StockViewModel.SiteId = s.SiteId; StockViewModel.CurrencyId = null; StockViewModel.PersonId = s.JobWorkerId; StockViewModel.ProductId = BalProdOrderLine.ProductId; StockViewModel.HeaderFromGodownId = null; StockViewModel.HeaderGodownId = s.GodownId; StockViewModel.HeaderProcessId = s.ProcessId; StockViewModel.GodownId = (int)s.GodownId; StockViewModel.Remark = s.Remark; StockViewModel.Status = s.Status; StockViewModel.ProcessId = s.ProcessId; StockViewModel.LotNo = null; StockViewModel.CostCenterId = s.CostCenterId; StockViewModel.Qty_Iss = ProdORderLineId.Qty; StockViewModel.Qty_Rec = 0; StockViewModel.Rate = 0; StockViewModel.ExpiryDate = null; StockViewModel.Specification = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification; StockViewModel.Dimension1Id = BalProdOrderLine.Dimension1Id; StockViewModel.Dimension2Id = BalProdOrderLine.Dimension2Id; StockViewModel.CreatedBy = User.Identity.Name; StockViewModel.CreatedDate = DateTime.Now; StockViewModel.ModifiedBy = User.Identity.Name; StockViewModel.ModifiedDate = DateTime.Now; string StockPostingError = ""; StockPostingError = new StockService(_unitOfWork).StockPost(ref StockViewModel); if (StockPostingError != "") { string message = StockPostingError; ModelState.AddModelError("", message); return(View("Create", svm)); } if (Cnt == 0) { s.StockHeaderId = StockViewModel.StockHeaderId; } line.StockId = StockViewModel.StockId; } if (Settings.isPostedInStockProcess ?? false) { StockProcessViewModel StockProcessViewModel = new StockProcessViewModel(); if (s.StockHeaderId != null && s.StockHeaderId != 0)//If Transaction Header Table Has Stock Header Id Then It will Save Here. { StockProcessViewModel.StockHeaderId = (int)s.StockHeaderId; } else if (Settings.isPostedInStock ?? false)//If Stok Header is already posted during stock posting then this statement will Execute.So theat Stock Header will not generate again. { StockProcessViewModel.StockHeaderId = -1; } 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 = s.JobOrderHeaderId; StockProcessViewModel.DocLineId = line.JobOrderLineId; StockProcessViewModel.DocTypeId = s.DocTypeId; StockProcessViewModel.StockHeaderDocDate = s.DocDate; StockProcessViewModel.StockProcessDocDate = s.DocDate; StockProcessViewModel.DocNo = s.DocNo; StockProcessViewModel.DivisionId = s.DivisionId; StockProcessViewModel.SiteId = s.SiteId; StockProcessViewModel.CurrencyId = null; StockProcessViewModel.PersonId = s.JobWorkerId; StockProcessViewModel.ProductId = BalProdOrderLine.ProductId; StockProcessViewModel.HeaderFromGodownId = null; StockProcessViewModel.HeaderGodownId = s.GodownId; StockProcessViewModel.HeaderProcessId = s.ProcessId; StockProcessViewModel.GodownId = s.GodownId; StockProcessViewModel.Remark = s.Remark; StockProcessViewModel.Status = s.Status; StockProcessViewModel.ProcessId = s.ProcessId; StockProcessViewModel.LotNo = null; StockProcessViewModel.CostCenterId = s.CostCenterId; StockProcessViewModel.Qty_Iss = 0; StockProcessViewModel.Qty_Rec = ProdORderLineId.Qty; StockProcessViewModel.Rate = 0; StockProcessViewModel.ExpiryDate = null; StockProcessViewModel.Specification = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification; StockProcessViewModel.Dimension1Id = BalProdOrderLine.Dimension1Id; StockProcessViewModel.Dimension2Id = BalProdOrderLine.Dimension2Id; StockProcessViewModel.CreatedBy = User.Identity.Name; StockProcessViewModel.CreatedDate = DateTime.Now; StockProcessViewModel.ModifiedBy = User.Identity.Name; StockProcessViewModel.ModifiedDate = DateTime.Now; string StockProcessPostingError = ""; StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPost(ref StockProcessViewModel); if (StockProcessPostingError != "") { string message = StockProcessPostingError; ModelState.AddModelError("", message); return(PartialView("_Results", svm)); } if ((Settings.isPostedInStock ?? false) == false) { if (Cnt == 0) { s.StockHeaderId = StockProcessViewModel.StockHeaderId; } } line.StockProcessId = StockProcessViewModel.StockProcessId; } line.JobOrderHeaderId = s.JobOrderHeaderId; line.ProdOrderLineId = BalProdOrderLine.ProdOrderLineId; line.ProductId = BalProdOrderLine.ProductId; line.Dimension1Id = BalProdOrderLine.Dimension1Id; line.Dimension2Id = BalProdOrderLine.Dimension2Id; line.Specification = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification; line.Qty = ProdORderLineId.Qty; line.Rate = ProdORderLineId.Rate; line.DealQty = ProdORderLineId.Qty; line.UnitId = Product.UnitId; line.DealUnitId = Product.UnitId; line.Amount = (line.DealQty * line.Rate); line.UnitConversionMultiplier = 1; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.JobOrderLineId = pk; line.Sr = pk; line.ObjectState = Model.ObjectState.Added; new JobOrderLineService(_unitOfWork).Create(line); new JobOrderLineStatusService(_unitOfWork).CreateLineStatus(line.JobOrderLineId, ref db, false); LineList.Add(new LineDetailListViewModel { Amount = line.Amount, Rate = line.Rate, LineTableId = line.JobOrderLineId, HeaderTableId = s.JobOrderHeaderId, PersonID = s.JobWorkerId, DealQty = line.DealQty }); pk++; Cnt++; } } if (CancelBalProdOrders && (BalProdOrderLine.BalanceQty - ProdORderLineId.Qty > 0)) { ProdOrderCancelLine cLine = new ProdOrderCancelLine(); cLine.CreatedBy = User.Identity.Name; cLine.CreatedDate = DateTime.Now; cLine.ModifiedBy = User.Identity.Name; cLine.ModifiedDate = DateTime.Now; cLine.ProdOrderCancelHeaderId = cHeader.ProdOrderCancelHeaderId; cLine.ProdOrderLineId = ProdORderLineId.ProdOrderLineId; cLine.Qty = (BalProdOrderLine.BalanceQty - ProdORderLineId.Qty); cLine.ReferenceDocTypeId = cHeader.ReferenceDocTypeId; cLine.ObjectState = Model.ObjectState.Added; new ProdOrderCancelLineService(_unitOfWork).Create(cLine); } } //new JobOrderHeaderService(_unitOfWork).Update(s); new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, s.JobOrderHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.JobOrderHeaderCharges", "Web.JobOrderLineCharges", out PersonCount, s.DocTypeId, s.SiteId, s.DivisionId); //Saving Charges foreach (var item in LineCharges) { JobOrderLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, JobOrderLineCharge>(item); PoLineCharge.ObjectState = Model.ObjectState.Added; new JobOrderLineChargeService(_unitOfWork).Create(PoLineCharge); } //Saving Header charges for (int i = 0; i < HeaderCharges.Count(); i++) { if (!HeaderChargeEdit) { JobOrderHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, JobOrderHeaderCharge>(HeaderCharges[i]); POHeaderCharge.HeaderTableId = s.JobOrderHeaderId; POHeaderCharge.PersonID = s.JobWorkerId; POHeaderCharge.ObjectState = Model.ObjectState.Added; new JobOrderHeaderChargeService(_unitOfWork).Create(POHeaderCharge); } else { var footercharge = new JobOrderHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id); footercharge.Rate = HeaderCharges[i].Rate; footercharge.Amount = HeaderCharges[i].Amount; new JobOrderHeaderChargeService(_unitOfWork).Update(footercharge); } } try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.JobOrderHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); System.Web.HttpContext.Current.Session.Remove("ConfirmProdOrderIds"); System.Web.HttpContext.Current.Session.Remove("CancelBalProdOrdrs"); if (CreateDyeingOrder) { return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobOrderHeader/Submit/" + s.JobOrderHeaderId)); } else { return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobOrderHeader/Index/" + s.DocTypeId)); } } PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); }