private static Dictionary <string, string> Get860ValDict(DBResult result860Query) { Dictionary <string, string> sValsFrom860 = new Dictionary <string, string>(); for (int i = 0; i < list860Cols.Length; i++) { sValsFrom860.Add(list860Cols[i].SQLEscape(), result860Query.Field(i, "").Trim().SQLEscape()); } return(sValsFrom860); }
public static List <string> CreateInvAsn(User user, List <PoSummary> poList) { string cCustomer = user.Customer.SQLEscape(); string cPartner = user.ActivePartner.SQLEscape(); List <string> sentKeys = new List <string>(); try { DBConnect connection = ConnectionsMgr.GetOCConnection(user, ECGB); var options = _GetOptions(user, connection); var trxDict = GetTrxTypeDict(user, connection, poList.Select(x => x.Key)); string cVendId = GetVendId(user, connection); string invkey = null; int fileIdx = 0; Dictionary <string, string> invKeys = new Dictionary <string, string>(); List <List <string> > invRpts = new List <List <string> >(); foreach (var po in poList) { string cPoNumber = po.PONumber.SQLEscape(); string cInvNumber = po.InvoiceNumber.SQLEscape(); string cBolNumber = po.BolNumber.SQLEscape(); string cTrxType = trxDict.ContainsKey(po.Key) ? trxDict[po.Key] : "M"; if (options.IsInvoiceEnabled && options.IsPackingEnabled) { connection.Query($"CALL ediproc.CreT856FromS850multi('{cPoNumber}','{cBolNumber}','{cCustomer}','{cPartner}','{cTrxType}','0')"); using (var q = connection.Query("SELECT @NewKey AS uniquekey")) { if (q.Read()) { string cSourceKey = q.Field(0); using (DBResult res = connection.Query($"SELECT ediproc.CreT810FromT856S850multi('{cSourceKey}','{cInvNumber}','{cCustomer}','{cPartner}','{cPoNumber}','')")) { if (res.Read()) { invkey = res.Field(0); invKeys.Add(cInvNumber, invkey); invRpts.Add(_CreateReportReq(user, DateTime.Now, invkey, "810", "trx810p.rpt", $"{ cCustomer}_810_{DateTime.Now.ToString("yyyyMMddHHmmss")}{++fileIdx}-report.pdf", "Invoice Report", cCustomer, cPartner, cPoNumber)); connection.Query($"call ediproc.UpdPOInvoiced('{cPoNumber}','{cCustomer}','{cPartner}','UPCNUM', 0)"); } } sentKeys.Add(cSourceKey); } } } else if (options.IsInvoiceEnabled) { using (DBResult res = connection.Query($"SELECT ediproc.CreT810FromS850('{cPoNumber}','{cInvNumber}','{cVendId}','{cCustomer}','{cPartner}')")) { if (res.Read()) { invkey = res.Field(0); invKeys.Add(cInvNumber, invkey); invRpts.Add(_CreateReportReq(user, DateTime.Now, invkey, "810", "trx810p.rpt", $"{ cCustomer}_810_{DateTime.Now.ToString("yyyyMMddHHmmss")}{++fileIdx}-report.pdf", "Invoice Report", cCustomer, cPartner, cPoNumber)); connection.Query($"call ediproc.UpdPOInvoiced('{cPoNumber}','{cCustomer}','{cPartner}','UPCNUM', 0)"); } } } else if (options.IsPackingEnabled) { connection.Query($"CALL ediproc.CreT856FromS850multi('{cPoNumber}','{cBolNumber}','{cCustomer}','{cPartner}','{cTrxType}','0')"); using (var q = connection.Query("SELECT @NewKey AS uniquekey")) { if (q.Read()) { sentKeys.Add(q.Field(0)); } } } } if (sentKeys.Count() > 0) { //UPDATE SHIPDATE TO CURRENT DATE (STORED PROCEDURE LEAVES IT NULL ON PURPOSE) //ALSO UPDATE SHIP WEIGHT AND DELIVDATE connection.Query($"UPDATE TRXH856 SET SHIPDATE='{DateTime.Now.ToMySQLDateStr()}', DELIVDATE='{DateTime.Now.AddDays(2).ToMySQLDateStr()}', SHIPWEIGHT=1 WHERE UNIQUEKEY IN ('{string.Join("','",sentKeys)}')"); } if (invKeys.Count() > 0) { connection.Query($"UPDATE TRXH810 SET SHIPDATE='{DateTime.Now.ToMySQLDateStr()}' WHERE UNIQUEKEY IN ('{string.Join("','", invKeys.Values)}') AND CUSTOMER='{cCustomer}' AND PARTNER='{cPartner}'"); DBConnect connectAdmin = ConnectionsMgr.GetAdminConnection(); InsertMultiple(user, connectAdmin, _Table.ReportReq, Common.colReportReq, invRpts); connectAdmin.Close(); } } catch (Exception e) { ProgramLog.LogError(user, nameof(PdsManager), nameof(CreateInvAsn), e.Message); } return(sentKeys); }