示例#1
0
        private async Task <List <POAmendmentCSVRecord> > ProcessPOAmendment(PO porec, ApexDataDataContext apexData)
        {
            ProgressInfo.Add($"Filing P/O amendment {porec.Po1.Trim()}");

            ApexSystem apexSystem = apexData.ApexSystems.FirstOrDefault();

            List <POAmendmentCSVRecord> csvList = new List <POAmendmentCSVRecord>();

            if (porec.Job != null && porec.Job != "") //Job based P/O
            {
                POAmendmentCSVRecord pocsvrec = BuildJobBasedAmendmentHeader(porec, apexSystem);

                for (int i = 0; i < porec.POLines.Count; i++)
                {
                    POLine polinerec = porec.POLines[i];

                    string jobphase = String.IsNullOrEmpty(porec.JobPhase) ? "00" : porec.JobPhase;
                    string wbs;

                    COINSESB_WB wbsRec = apexData.COINSESB_WBs.Where(s => s.Job == porec.Job).FirstOrDefault();
                    if (wbsRec == null || !(wbsRec.UsesActivity ?? false))
                    {
                        wbs = jobphase + "-";
                    }
                    else
                    {
                        wbs = jobphase + "-00-";
                    }

                    pocsvrec = BuildJobBasedAmendmentLine(polinerec, wbs, pocsvrec);
                    csvList.Add(pocsvrec);
                    pocsvrec = CreateNotNewCSVRec(); //Clear the header portion for subsequent line items
                }
            }
            else //Work Order based P/O
            {
                POAmendmentCSVRecord pocsvrec = BuildWOBasedAmendmentHeader(porec, apexSystem);

                for (int i = 0; i < porec.POLines.Count; i++)
                {
                    POLine polinerec = porec.POLines[i];

                    pocsvrec = BuildWOBasedAmemdmentPOLine(porec, polinerec, pocsvrec);
                    csvList.Add(pocsvrec);
                    pocsvrec = CreateNotNewCSVRec(); //Clear the header portion for subsequent line items
                }
            }

            _StatusLines.Add(new StatusLine
            {
                PO      = porec.Po1?.Trim(),
                Job     = porec.Job?.Trim(),
                WorkOrd = porec.WorkOrd?.Trim(),
                Vendor  = porec.Vendor?.Trim(),
                Message = "Amendment written to file"
            });

            return(csvList);
        }
示例#2
0
        private static async Task ProcessWBSAsync(XElement wbsInfo)
        {
            string apexJobID = wbsInfo.Element("job_num").Value.Trim().PadLeft(12);
            string wbsCode   = wbsInfo.Element("jwb_code").Value;

            if (String.IsNullOrEmpty(apexJobID.Trim()))
            {
                return;
            }

            using (var dc = new ApexDataDataContext())
            {
                var  apexWBS = dc.COINSESB_WBs.Where(v => v.Job == apexJobID && v.WB_Code == wbsCode).SingleOrDefault();
                bool newWBS  = (apexWBS == null);
                if (newWBS)
                {
                    apexWBS = new COINSESB_WB();
                }

                apexWBS.Job          = apexJobID;
                apexWBS.WB_Code      = LoadValue(wbsInfo.Element("jwb_code").Value, 50);
                apexWBS.WB_Desc      = LoadValue(wbsInfo.Element("jwb_desc").Value, 50);
                apexWBS.Activity     = LoadValue(wbsInfo.Element("jca_activity").Value, 50);
                apexWBS.Section      = LoadValue(wbsInfo.Element("jcs_section").Value, 50);
                apexWBS.UsesActivity = !String.IsNullOrEmpty(apexWBS.Activity);

                if (newWBS)
                {
                    dc.COINSESB_WBs.InsertOnSubmit(apexWBS);
                }

                try
                {
                    dc.SubmitChanges();
                    Console.WriteLine($"   WBS {apexJobID},{wbsCode} processed.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error on WBS {apexJobID},{wbsCode}, {ex}");
                }
            }
        }
示例#3
0
        private async Task ProcessPO(PO porec, ApexDataDataContext apexData)
        {
            ProgressInfo.Add($"Sending P/O {porec.Po1.Trim()}");

            string reportMessage;

            ApexSystem apexSystem = apexData.ApexSystems.FirstOrDefault();

            COINSESBService.COINSInterfaceHeader    header;
            COINSESBService.COINSInterfacePo_hdrRow poheader;

            header = new COINSESBService.COINSInterfaceHeader
            {
                id          = (apexSystem.ExportBatch ?? 1).ToString(),
                confirm     = COINSESBService.COINSInterfaceHeaderConfirm.no,
                UserID      = "pkramer",
                From        = "Apex",
                HostName    = "coinsoa",
                Environment = "live",
                Created     = DateTime.UtcNow,
                Login       = new COINSESBService.COINSInterfaceHeaderLogin()
                {
                    User     = "******",
                    Password = "******",
                    CID      = 1
                }
            };

            if (!String.IsNullOrEmpty(porec.Job)) //Job based P/O
            {
                poheader = BuildJobBasedPOHeader(porec, apexSystem);

                poheader.po_lineRow = new COINSESBService.COINSInterfacePo_hdrRowPo_lineRow[porec.POLines.Count];

                for (int i = 0; i < porec.POLines.Count; i++)
                {
                    POLine polinerec = porec.POLines[i];

                    string jobphase = String.IsNullOrEmpty(porec.JobPhase) ? "00" : porec.JobPhase;
                    string wbs;

                    COINSESB_WB wbsRec = apexData.COINSESB_WBs.Where(s => s.Job == porec.Job).FirstOrDefault();
                    if (wbsRec == null || !(wbsRec.UsesActivity ?? false))
                    {
                        wbs = jobphase + "-";
                    }
                    else
                    {
                        wbs = jobphase + "-00-";
                    }

                    COINSESB_ExpL expL      = apexData.COINSESB_ExpLs.Where(s => s.PO == polinerec.Po && s.POLine == polinerec.PoLine1).SingleOrDefault();
                    int?          pol_seq   = expL?.POL_Seq;
                    decimal?      lastPrice = expL?.LastPrice;

                    string cat      = "MA";
                    string schedule = "STD";
                    Job    job      = apexData.Jobs.Where(s => s.Job1 == porec.Job).FirstOrDefault();
                    if (job != null)
                    {
                        schedule = job.Schedule;
                        Costcode ccd = apexData.Costcodes.Where(s => s.Schedule == schedule && s.CostCode1 == polinerec.CostCode).FirstOrDefault();
                        if (ccd != null)
                        {
                            cat = ccd.GL;
                        }
                    }

                    COINSESBService.COINSInterfacePo_hdrRowPo_lineRow
                        polinerow = BuildJobBasedPOLine(polinerec, wbs, pol_seq, cat,
                                                        expL != null && ((polinerec.Price ?? 0) != (lastPrice ?? 0)), porec.ShipDate ?? DateTime.Now);
                    poheader.po_lineRow[i] = polinerow;
                }
            }
            else //Work Order based P/O
            {
                poheader = BuildWOBasedPOHeader(porec, apexSystem);

                poheader.po_lineRow = new COINSESBService.COINSInterfacePo_hdrRowPo_lineRow[porec.POLines.Count];

                for (int i = 0; i < porec.POLines.Count; i++)
                {
                    POLine polinerec = porec.POLines[i];

                    COINSESB_ExpL expL      = apexData.COINSESB_ExpLs.Where(s => s.PO == polinerec.Po && s.POLine == polinerec.PoLine1).SingleOrDefault();
                    int?          pol_seq   = expL?.POL_Seq;
                    decimal?      lastPrice = expL?.LastPrice;

                    string   cat      = "MA";
                    string   schedule = "STD";
                    Costcode ccd      = apexData.Costcodes.Where(s => s.Schedule == schedule && s.CostCode1 == polinerec.CostCode).FirstOrDefault();
                    if (ccd != null)
                    {
                        cat = ccd.GL;
                    }

                    COINSESBService.COINSInterfacePo_hdrRowPo_lineRow
                        polinerow = BuildWOBasedPOLine(porec, polinerec, pol_seq, cat,
                                                       expL != null && ((polinerec.Price ?? 0) != (lastPrice ?? 0)), porec.ShipDate ?? DateTime.Now);
                    poheader.po_lineRow[i] = polinerow;
                }
            }

            COINSESBService.COINSInterfacePo_hdrRow[] poheaderrows = new COINSESBService.COINSInterfacePo_hdrRow[1];
            poheaderrows[0] = poheader;

            var client        = new COINSESBService.COINSInterfacePortClient("COINSInterface");
            var actionrequest = new COINSESBService.doActionRequest
            {
                Header = header,
                Body   = poheaderrows
            };

#if SENDXMLDIAGNOSTIC
            XmlSerializer serializer = new XmlSerializer(typeof(COINSESBService.doActionRequest));
            using (MemoryStream stream = new MemoryStream())
            {
                serializer.Serialize(stream, actionrequest);
                stream.Seek(0, SeekOrigin.Begin);
                string     capturedXML  = stream.ReadToString();
                HttpClient postClient   = new HttpClient();
                var        postResponse = await postClient.PostAsync("http://apexcoin.apexpurchasing.com/api/coinsxml",
                                                                     new StringContent(capturedXML));
            }
#endif

            var response = await client.doActionAsync(actionrequest);

            if (response.Header.action == COINSESBService.COINSInterfaceResponseHeaderAction.RESPONSE)
            {
                if (porec.ExpSent == "T")
                {
                    reportMessage = "Sent to COINS (Amendment)";
                }
                else
                {
                    reportMessage = "Sent to COINS";
                }

                porec.ExpSent = "T";
                var lines         = response.Body.po_hdrRow[0].po_lineRow;
                int lineRowNumber = 0;
                foreach (var POLine in porec.POLines)
                {
                    var  pol_seq   = lines[lineRowNumber++].pol_seq;
                    bool newRecord = false;
                    var  expL      = apexData.COINSESB_ExpLs.Where(s => s.PO == POLine.Po && s.POLine == POLine.PoLine1).SingleOrDefault();
                    if (expL == null)
                    {
                        expL = new COINSESB_ExpL
                        {
                            PO     = POLine.Po,
                            POLine = POLine.PoLine1
                        };
                        newRecord = true;
                    }

                    expL.POL_Seq   = pol_seq;
                    expL.LastAmt   = POLine.Ext;
                    expL.LastPrice = POLine.Price;
                    if (newRecord)
                    {
                        apexData.COINSESB_ExpLs.InsertOnSubmit(expL);
                    }
                    apexData.SubmitChanges();
                }
            }
            else if (response.Header.action == COINSESBService.COINSInterfaceResponseHeaderAction.EXCEPTION)
            {
                reportMessage = response.Body.Exception.Exception;
            }
            else
            {
                reportMessage = "Unknown response from COINS";
            }

            porec.ExpBatch          = apexSystem.ExportBatch ?? 1;
            apexSystem.ExportBatch += 1;
            apexData.SubmitChanges();

            _StatusLines.Add(new StatusLine
            {
                PO      = porec.Po1?.Trim(),
                Job     = porec.Job?.Trim(),
                WorkOrd = porec.WorkOrd?.Trim(),
                Vendor  = porec.Vendor?.Trim(),
                Message = reportMessage
            });
        }
示例#4
0
 partial void InsertCOINSESB_WB(COINSESB_WB instance)
 {
     instance.Job = instance.Job.Trim().PadLeft(12);
     ExecuteDynamicInsert(instance);
 }