private static void CreatePartsOrders() { var oh = BuildOrderHeaders(); var od = BuildOrderDetails(); OrderHeaders = new List <OrderHeader>(); OrderDetails = new List <OrderDetail>(); OrderReleases = new List <OrderRelease>(); foreach (var item in JobXRefList.Where(x => !String.IsNullOrEmpty(x.NewSalesOrder))) { var header_ver = oh.FirstOrDefault(x => x.SalesOrderNo == item.OldSalesOrder); var header = new OrderHeader { Company = CompanyID, OrderNum = int.Parse(item.NewSalesOrder), CustomerCustID = header_ver.CustomerNo, PONum = header_ver.CustomerPONo, RequestDate = header_ver.ShipExpireDate, FOB = "Bethlehem", UseOTS = true, OTSName = header_ver.ShipToName, OTSAddress1 = header_ver.ShipToAddress1, OTSAddress2 = header_ver.ShipToAddress2, OTSAddress3 = header_ver.ShipToAddress3, OTSCity = header_ver.ShipToCity, OTSState = header_ver.ShipToState, OTSZip = header_ver.ShipToZipCode, OrderDate = header_ver.OrderDate, ShipViaCode = "BEST", NeedByDate = header_ver.ShipExpireDate, TermsCode = "6", }; while (header.PONum == "" || OrderHeaders.FirstOrDefault(x => x.PONum == header.PONum && header.OrderNum != x.OrderNum) != null) { header.PONum = header.PONum + "A"; } if (currentCustomers.FirstOrDefault(x => x.CustID == header.CustomerCustID) == null) { MissingCustomers += String.Format("Customer {0} is missing from Sage parts order {1}", header.CustomerCustID, item.OldSalesOrder); MissingCustomers += Environment.NewLine; } if (string.IsNullOrEmpty(header.RequestDate)) { header.RequestDate = header.OrderDate; } if (string.IsNullOrEmpty(header.NeedByDate)) { header.NeedByDate = header.OrderDate; } if (string.IsNullOrEmpty(header.PONum)) { header.PONum = header.OrderNum.ToString(); } OrderHeaders.Add(header); int lineno = 1; foreach (var det in od.Where(x => x.SalesOrderNo == item.OldSalesOrder)) { var part = currentParts.FirstOrDefault(x => x.PartNum == det.ItemCode); if (part == null) { // part is not in Epicor MissingParts += String.Format("Item {0} from Sage Order {1} is not currently in Epicor", det.ItemCode, det.SalesOrderNo); MissingParts += Environment.NewLine; } var detail = new OrderDetail { Company = header.Company, OrderNum = header.OrderNum, OrderLine = lineno, PartNum = det.ItemCode, IUM = det.UnitOfMeasure, LineDesc = det.ItemCodeDesc, DocunitPrice = det.UnitPrice, OrderQty = det.QuantityOrdered - det.QuantityShipped, NeedByDate = header.NeedByDate, }; lineno++; if (detail.IUM == "EACH") { detail.IUM = "EA"; } if (detail.IUM == "GAL") { detail.IUM = "GA"; } if (detail.IUM == "PAIR") { detail.IUM = "EA"; } if (detail.IUM == "") { detail.IUM = "EA"; } if (detail.IUM == "SET") { detail.IUM = "EA"; } if (detail.IUM == "EACH") { detail.IUM = "EA"; } detail.SalesUM = detail.IUM; var release = new OrderRelease { Company = detail.Company, OrderNum = detail.OrderNum, OrderLine = detail.OrderLine, Linetype = "", OrderRelNum = 1, OurReqQty = detail.OrderQty, Make = false, }; OrderDetails.Add(detail); OrderReleases.Add(release); } } }
private static void CreateOtherJobs() { const int MaxLength = 50; foreach (var item in JobXRefList.Where(x => x.OriginalJob.StartsWith("G") || x.OriginalJob.StartsWith("M") || x.OriginalJob.StartsWith("P") || x.OriginalJob.StartsWith("T") || x.OriginalJob.StartsWith("V")).OrderBy(x => x.OriginalJob)) { var jobinfo = SageJobHeaders.FirstOrDefault(x => x.JobNo == item.OriginalJob); if (jobinfo == null) { ErrorList += String.Format("Job Header not found for Job: {0}", item.OriginalJob); ErrorList += Environment.NewLine; } var custinfo = currentCustomers.FirstOrDefault(x => x.CustID == jobinfo.CustomerNo); if (custinfo == null) { MissingCustomers += String.Format("Customer {0} for Job {1} was not found in Epicor", jobinfo.CustomerNo, item.OriginalJob); MissingCustomers += Environment.NewLine; custinfo = new DMT05CustomerVUKMasterLoad { }; } var partnum = jobinfo.JobDesc; if (partnum.Length > MaxLength) { partnum = partnum.Substring(0, MaxLength); } var jobhead = new JobHeader { Company = CompanyID, JobEngineered = true, JobFirm = true, JobReleased = true, JobNum = item.NewJob, PartNum = partnum, Plant = "MfgSys", CustID = jobinfo.CustomerNo, PartDescription = partnum, ProdQty = 1, ReqDueDate = jobinfo.ContractDate, StartDate = jobinfo.ContractDate, SyncReqBy = false, }; if (String.IsNullOrEmpty(jobhead.ReqDueDate)) { jobhead.ReqDueDate = "01/01/2019"; } JobHeaders.Add(jobhead); var op1 = new JobOperation { Company = CompanyID, AssemblySeq = 0, OpCode = item.OpCode, OpComplete = false, OprSeq = 10, ProdStandard = 0, QtyCompleted = 0, StdFormat = "HP", LaborEntryMethod = "T", JobNum = jobhead.JobNum, SchedRelation = "FS", Plant = "MfgSys", AutoReceive = true, FinalOpr = true, }; JobOperations.Add(op1); //int mtlseq = 10; var camtl = new JobMaterial { Company = jobhead.Company, JobNum = jobhead.JobNum, //Plant = jobhead.Plant, IssuedComplete = true, PartNum = "CostAdjustment", Description = "CostAdjustment", //MaterialMtlCost = 0, MtlSeq = 5, QtyPer = 1, AssemblySeq = 0, FixedQty = true, RelatedOperation = 10 //RequiredQty = 1 }; JobMaterials.Add(camtl); } }
private static void CreateJobAdjustments() { var adjustments = new List <JobMtlAdjustment>(); decimal adjustmenttotals = 0.00M; decimal negadjustments = 0.00M; string negadjustmenterrors = ""; foreach (var item in JobXRefList.Where(x => !String.IsNullOrEmpty(x.NewJob))) { var adjust = new JobMtlAdjustment { JobNum = item.NewJob, AssemblySeq = 0, Company = CompanyID, JobSeq = 5, Plant = "MfgSys", TranDate = "11/30/2018", TranQty = 1, TranType = "ADJ-MTL" }; adjust.MtlUnitCost = cleanWipJobs.Where(x => x.JobNo == item.OriginalJob && x.CostType == "M").Sum(x => x.TransactionAmt); adjust.LbrUnitCost = cleanWipJobs.Where(x => x.JobNo == item.OriginalJob && x.CostType == "L").Sum(x => x.TransactionAmt); adjust.SubUnitCost = cleanWipJobs .Where(x => x.JobNo == item.OriginalJob && !(x.CostType == "M" || x.CostType == "L")) .Sum(x => x.TransactionAmt); adjustmenttotals += adjust.MtlUnitCost + adjust.LbrUnitCost + adjust.SubUnitCost; if (adjust.MtlUnitCost < 0) { negadjustmenterrors += String.Format("Sage Job {0} ({2}) has a MtlUnitCost adjustment of {1}", item.OriginalJob, adjust.MtlUnitCost, item.NewJob); negadjustmenterrors += Environment.NewLine; if (adjust.MtlUnitCost < 0 && adjust.SubUnitCost >= (adjust.MtlUnitCost * -1)) { adjust.SubUnitCost += adjust.MtlUnitCost; negadjustmenterrors += String.Format("Absorbed the negative into the SubUnitCost for {0}", adjust.SubUnitCost); adjust.MtlUnitCost = 0; negadjustmenterrors += Environment.NewLine; } if (adjust.MtlUnitCost < 0 && adjust.LbrUnitCost >= (adjust.MtlUnitCost * -1)) { adjust.LbrUnitCost += adjust.MtlUnitCost; negadjustmenterrors += String.Format("Absorbed the negative into the LbrUnitCost for {0}", adjust.LbrUnitCost); adjust.MtlUnitCost = 0; negadjustmenterrors += Environment.NewLine; } negadjustments += adjust.MtlUnitCost; adjust.MtlUnitCost = 0; } if (adjust.LbrUnitCost < 0) { negadjustmenterrors += String.Format("Sage Job {0} ({2}) has a LbrUnitCost adjustment of {1}", item.OriginalJob, adjust.LbrUnitCost, item.NewJob); negadjustmenterrors += Environment.NewLine; if (adjust.LbrUnitCost < 0 && adjust.MtlUnitCost >= (adjust.LbrUnitCost * -1)) { adjust.MtlUnitCost += adjust.LbrUnitCost; negadjustmenterrors += String.Format("Absorbed the negative into the SubUnitCost for {0}", adjust.MtlUnitCost); adjust.MtlUnitCost = 0; negadjustmenterrors += Environment.NewLine; } if (adjust.LbrUnitCost < 0 && adjust.SubUnitCost >= (adjust.LbrUnitCost * -1)) { adjust.SubUnitCost += adjust.LbrUnitCost; negadjustmenterrors += String.Format("Absorbed the negative into the SubUnitCost for {0}", adjust.SubUnitCost); adjust.LbrUnitCost = 0; negadjustmenterrors += Environment.NewLine; } negadjustments += adjust.LbrUnitCost; adjust.LbrUnitCost = 0; } if (adjust.SubUnitCost < 0) { negadjustmenterrors += String.Format("Sage Job {0} ({2}) has a SubUnitCost adjustment of {1}", item.OriginalJob, adjust.SubUnitCost, item.NewJob); negadjustmenterrors += Environment.NewLine; if (adjust.SubUnitCost < 0 && adjust.MtlUnitCost >= (adjust.SubUnitCost * -1)) { adjust.MtlUnitCost += adjust.SubUnitCost; negadjustmenterrors += String.Format("Absorbed the negative into the MtlUnitCost for {0}", adjust.MtlUnitCost); adjust.SubUnitCost = 0; negadjustmenterrors += Environment.NewLine; } if (adjust.SubUnitCost < 0 && adjust.LbrUnitCost >= (adjust.SubUnitCost * -1)) { adjust.LbrUnitCost += adjust.SubUnitCost; negadjustmenterrors += String.Format("Absorbed the negative into the MtlUnitCost for {0}", adjust.LbrUnitCost); adjust.SubUnitCost = 0; negadjustmenterrors += Environment.NewLine; } negadjustments += adjust.SubUnitCost; adjust.SubUnitCost = 0; } adjustments.Add(adjust); } negadjustmenterrors += String.Format("Total Adjustments = {0} (including negatives)", adjustmenttotals); negadjustmenterrors += Environment.NewLine; negadjustmenterrors += String.Format("Total Negative Adjustments = {0}", negadjustments); negadjustmenterrors += Environment.NewLine; negadjustmenterrors += String.Format("Total Adjustments = {0} (Not Including Negatives)", adjustmenttotals - negadjustments); negadjustmenterrors += Environment.NewLine; File.WriteAllText("NegativeJobAdjustments.txt", negadjustmenterrors); JobMtlAdjustments = adjustments; }