static void LoadSalesOrder(SalesOrderSvcContractClient salesOrderClient, SalesOrder so, out string result) { var ts = new SalesOrderTableset(); result = "p_"; salesOrderClient.GetNewOrderHed(ref ts); var newRow = ts.OrderHed.Where(n => n.RowMod.Equals("A", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); // Guid rowID = newRow.SysRowID; // FastLoad.SalesOrder so = new FastLoad.SalesOrder(); E10Lookup look = new E10Lookup(); int custNum = look.GetCustomerNum(so.CustomerID); if (newRow != null) { newRow.Company = so.Company; Epicor.SalesOrderSvc.UserDefinedColumns columns = newRow.UserDefinedColumns; /* foreach (KeyValuePair<string, object> kvp in columns) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } */ columns["OrderType_c"] = "EDI"; columns["EDIHeadChar11_c"] = ""; // columns["EDIHeadChar11_c"] = "hello"; // newRow.BTCustID = so.CustomerID; newRow.CustNum = custNum; newRow.BTCustNum = custNum; if (so.ShipVia.Equals("UGND")) { newRow.ShipViaCode = "UPGD"; } else { newRow.ShipViaCode = so.ShipVia; } newRow.PONum = so.PoNo; newRow.TermsCode = so.TermsCode; newRow.ShipToNum = so.ShipToNum; newRow.ShipToCustNum = custNum; newRow.NeedByDate = so.NeedByDate; newRow.OrderDate = so.OrderDate; newRow.RequestDate = so.RequestDate; newRow.ReadyToCalc = true; #if STEINMART newRow.PickListComment = so.ediMarkingNotes; newRow.RefNotes = so.ediMarkingNotes; newRow.ShipComment = so.ediMarkingNotes; #endif newRow.RowMod = "A"; try { salesOrderClient.Update(ref ts); } catch (Exception e) { string message = e.Message; result = message.Substring(0, 3); bool AllOk = false; } } int orderNum = ts.OrderHed[0].OrderNum; ts = salesOrderClient.GetByID(orderNum); if (ts != null) { result = orderNum.ToString(); foreach (OrderLine line in so.lines) { bool Inactive = look.IsPartInActive(line.Upc); if (Inactive) { continue; } salesOrderClient.GetNewOrderDtl(ref ts, orderNum); string PartDescription = look.GetPartDescr(line.Upc); // ts = salesOrderClient.GetByID(orderNum); string dtlrow = ts.OrderDtl[0].RowMod; var newDtlRow = ts.OrderDtl.Where(n => n.RowMod.Equals("A", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); newDtlRow.PartNum = line.Upc; newDtlRow.PartNumPartDescription = PartDescription; newDtlRow.LineDesc = PartDescription; newDtlRow.XPartNum = line.CustomerPart; newDtlRow.OrderLine = line.LineNum; newDtlRow.OrderQty = line.OrderQty; newDtlRow.PricingQty = line.OrderQty; newDtlRow.SellingQuantity = line.OrderQty; newDtlRow.SalesUM = so.Get_UOM_FromSellingFactor(line.SellingFactor); // newDtlRow.DocInUnitPrice = line.UnitPrice; newDtlRow.DocUnitPrice = line.UnitPrice; // newDtlRow.Reference = "123456"; newDtlRow.UnitPrice = line.UnitPrice; newDtlRow.SellingFactor = line.SellingFactor; // newDtlRow.RevisionNum = "PCK"; newDtlRow.RowMod = "A"; // newRow.RowMod = "U"; try { salesOrderClient.Update(ref ts); ts = salesOrderClient.GetByID(orderNum); } catch (Exception ex2) { string mess2 = ex2.Message; // result = ex2.Message; } } try { ts = salesOrderClient.GetByID(orderNum); TaxConnectStatusRow taxrow = ts.TaxConnectStatus.First(); taxrow.ETCOffline = true; salesOrderClient.Update(ref ts); } catch (Exception ex2) { string messtaxOffline = ex2.Message; // result = ex2.Message; } } }
public async Task SyncSOs() { log.Information("Syncing SOs..."); Console.WriteLine($"Syncing SOs..."); try { using (var db = new EpicorIntergrationEntities()) { //Header var addedSOHeaders = db.SO_HEADER.Where(c => c.DMSFlag == "N" /*c.DMSFlag == "N" || c.DMSFlag == "U"*/).OrderBy(h => h.CompanyCode); if (addedSOHeaders.Any()) { foreach (var soHeader in addedSOHeaders) { try { string siteID, siteName, workstationID, workstationDescription, employeeID, countryGroupCode, countryCode, tenantID, companyName, systemCode; var currentCompany = sessionModClient.GetCurrentValues(out companyName, out siteID, out siteName, out employeeID, out workstationID, out workstationDescription, out systemCode, out countryGroupCode, out countryCode, out tenantID); if (currentCompany != soHeader.CompanyCode) { sessionModClient.SetCompany(soHeader.CompanyCode, out siteID, out siteName, out workstationID, out workstationDescription, out employeeID, out countryGroupCode, out countryCode, out tenantID); } //company = sessionModClient.GetCurrentValues(out companyName, out siteID, out siteName, out employeeID, out workstationID, out workstationDescription, out systemCode, out countryGroupCode, out countryCode, out tenantID); SalesOrderTableset soTableset = new SalesOrderTableset(); soClient.GetNewOrderHed(ref soTableset); var soHeaderRow = soTableset.OrderHed.Where(p => p.RowMod == "A").FirstOrDefault(); if (soHeaderRow != null) { MapToHeaderRow(soHeaderRow, soHeader); soClient.Update(ref soTableset); var orderNum = soTableset.OrderHed[0].OrderNum; soHeader.Ordernum = orderNum; soHeader.LastUpdatedDateTime = DateTime.Now; soHeader.DMSFlag = "S"; Console.WriteLine($"Added soHeader: [{soHeader.CompanyCode}]#{orderNum} successfully!"); soTableset.OrderHed[0].ReadyToCalc = false; soTableset.OrderHed[0].RowMod = "U"; soClient.Update(ref soTableset); //Details var soDetails = db.SO_DETAIL.Where(c => c.DocNum == soHeader.DocNum && c.DMSFlag == "N" && c.ProductCode != "DISCOUNT" /* c.DMSFlag == "N" || c.DMSFlag == "U"*/).ToList().OrderBy(c => int.Parse(c.LineNum)); foreach (var soDetail in soDetails) { try { soClient.GetNewOrderDtl(ref soTableset, orderNum); var soDetailRow = soTableset.OrderDtl.Where(p => p.RowMod == "A").FirstOrDefault(); if (soDetailRow != null) { MapToDetailRow(soDetailRow, soDetail); soClient.Update(ref soTableset); soDetail.CreatedBy = soTableset.OrderDtl.Max(d => d.OrderLine).ToString(); soDetail.DMSFlag = "S"; Console.WriteLine($"Added soDetail: [{soHeader.CompanyCode}]#{orderNum}/{soDetail.LineNum} successfully!"); } } catch (Exception e) { soDetail.DMSFlag = "F"; soDetail.SystemLog = $"Added soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}"; log.Error($"Added soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine($"Added soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.Message}"); Console.WriteLine(e.GetBaseException().Message); continue; } } foreach (var soDetail in soDetails.Where(d => d.DMSFlag != "F")) { try { var lineNum = int.Parse(soDetail.CreatedBy); soClient.GetNewOrderRelTax(ref soTableset, orderNum, lineNum, 1, soDetail.TaxCode, soDetail.RateCode); soClient.ChangeManualTaxCalc(orderNum, lineNum, 1, soDetail.TaxCode, soDetail.RateCode, ref soTableset); Console.WriteLine($"Calculate tax soDetail: [{soHeader.CompanyCode}]#{orderNum}/{soDetail.LineNum} successfully!"); } catch (Exception e) { soDetail.DMSFlag = "F"; soDetail.SystemLog = $"Calculate tax soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}"; log.Error($"Calculate tax soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine($"Calculate tax soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.Message}"); Console.WriteLine(e.GetBaseException().Message); continue; } } soClient.Update(ref soTableset); foreach (var soDetail in soDetails.Where(d => d.VATGroup != null && d.DMSFlag != "F")) { try { var lineNum = int.Parse(soDetail.CreatedBy); var soDetailRow = soTableset.OrderDtl.FirstOrDefault(d => d.OrderLine == lineNum); soDetailRow.TaxCatID = soDetail.VATGroup; soDetailRow.RowMod = "U"; Console.WriteLine($"Updated VATGroup soDetail: [{soHeader.CompanyCode}]#{orderNum}/{soDetail.LineNum} successfully!"); } catch (Exception e) { soDetail.DMSFlag = "F"; soDetail.SystemLog = $"Updated VATGroup soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}"; log.Error($"Updated VATGroup soDetail:[{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine($"Updated VATGroup soDetail: [{soHeader.CompanyCode}]#{soDetail.DocNum}/{soDetail.LineNum} failed! - {e.Message}"); Console.WriteLine(e.GetBaseException().Message); continue; } } soTableset.OrderHed[0].ReadyToCalc = true; soTableset.OrderHed[0].RowMod = "U"; soClient.Update(ref soTableset); } } catch (Exception e) { soHeader.DMSFlag = "F"; soHeader.SystemLog = $"Added soHeader: [{soHeader.CompanyCode}]#{soHeader.DocNum} failed! - {e.GetBaseException().Message}"; log.Error($"Added soHeader: [{soHeader.CompanyCode}]#{soHeader.DocNum} failed! - {e.GetBaseException().Message}", e.GetBaseException()); Console.WriteLine($"Added soHeader: [{soHeader.CompanyCode}]#{soHeader.DocNum} failed! - {e.Message}"); Console.WriteLine(e.GetBaseException().Message); continue; } } await db.SaveChangesAsync(); } sessionModClient.Logout(); } } catch (Exception e) { Console.WriteLine(e.GetBaseException().Message); } }