示例#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 POAmendmentCSVRecord BuildJobBasedAmendmentHeader(PO porec, ApexSystem apexSystem) =>
 new POAmendmentCSVRecord
 {
     NewPO = "Y",
     PO    = porec.Po1.Trim(),
     CONum = (apexSystem.ExportBatch ?? 1).ToString(),
     VariationOrderType = "A",
     POMajorType        = "M",
     OrderType          = "N",
     HeadOrder          = "Y", //this is the value from the web service, contradicting Will's example
     ConfirmationOrder  = "N",
     Job         = porec.Job.Trim(),
     Account     = porec.Vendor.Trim(),
     Currency    = "USD",
     Attention   = porec.VendorAttn,
     OrderDate   = (porec.EntDate ?? DateTime.Now).ToString(),
     DueDate     = (porec.ShipDate ?? DateTime.Now).ToString(),
     Description = porec.PODesc,
     Buyer       = "pkramer"
 };
示例#3
0
        private static COINSESBService.COINSInterfacePo_hdrRow BuildWOBasedPOHeader(PO porec, ApexSystem apexSystem)
        {
            string selectedJobPh = DetermineServiceJob(porec);

            return(new COINSESBService.COINSInterfacePo_hdrRow
            {
                id = (apexSystem.ExportBatch ?? 1).ToString(),
                poh_ordno = porec.Po1.Trim(),
                rsp_action = "I",
                commitOrder = true,
                poh_mpo = "M",
                pot_type = "N",
                poh_headoffice = true,
                poh_confirm = false,
                job_jobph = selectedJobPh,
                poh_accno = porec.Vendor.Trim(),
                poh_name = porec.VendorName,
                poh_odate = porec.EntDate ?? DateTime.Now,
                poh_ddate = porec.ShipDate ?? DateTime.Now,
                poh_ddateSpecified = true,
                poh_desc = porec.PODesc,
                pob_code = "pkramer",
                poh_reqdby = porec.ContactID
            });
        }
示例#4
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
            });
        }