Exemplo n.º 1
0
        private static POAmendmentCSVRecord CreateNotNewCSVRec()
        {
            POAmendmentCSVRecord notnewcsvrec = new POAmendmentCSVRecord();

            notnewcsvrec.NewPO = "N";
            return(notnewcsvrec);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private async Task SendApexPOAmendments()
        {
            using (ApexDataDataContext apexData = new ApexDataDataContext(_SqlConnBuilder.ConnectionString))
            {
                try
                {
                    var dlo = new DataLoadOptions();
                    dlo.LoadWith <PO>(p => p.POLines);  //grab the lines at the same time for efficiency
                    apexData.LoadOptions = dlo;

                    List <PO> apexPOList = apexData.POs.Where(p => (p.Vendor ?? "") != "" &&
                                                              (((p.Job ?? "") != "") || ((p.WorkOrd ?? "") != "")) &&
                                                              ((p.ExpBatch == 0) || (p.ExpBatch == -1)) && (p.ExpSent ?? "F") == "T" &&
                                                              (p.POStatus == "F" || p.POStatus == "C")).ToList();

                    if (apexPOList.Count == 0)
                    {
                        ProgressInfo.Add("There are no purchase order amendments to send.");
                    }
                    else
                    {
                        _POSent = true;  //We have a valid P/O to send so present the interface status report when complete

                        using (var writer = new StreamWriter(_POAmendDirectory + @"\POAmend-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"))
                            using (var csv = new CsvWriter(writer))
                            {
                                _AmendmentList.Clear();
                                //_AmendmentList.Add(POAmendmentCSVRecord.BuildLine1());
                                _AmendmentList.Add(POAmendmentCSVRecord.BuildLine2());

                                foreach (PO porec in apexPOList)
                                {
                                    _AmendmentList.AddRange(await ProcessPOAmendment(porec, apexData));
                                }

                                csv.WriteRecords(_AmendmentList);
                            }
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show("Error:" + ex.Message, "Unexpected error");
                }
            }
        }
Exemplo n.º 4
0
 private POAmendmentCSVRecord BuildWOBasedAmemdmentPOLine(PO porec, POLine polinerec, POAmendmentCSVRecord pocsvrec)
 {
     pocsvrec.OrderLineType        = "m";
     pocsvrec.Code                 = "CM-MA";
     pocsvrec.ClauseCode           = String.Empty;
     pocsvrec.OrderLineDescription = String.IsNullOrEmpty(polinerec.MfgDesc) ? "***Unknown***" : polinerec.MfgDesc;
     pocsvrec.WBSCode              = porec.WorkOrd.Trim();
     pocsvrec.CostCode             = "NAB";
     pocsvrec.CostCategory         = "MA";
     pocsvrec.Quantity             = ((decimal)(polinerec.QtyOrd ?? 0) - (decimal)(polinerec.QtyIvc ?? 0)).ToString();
     pocsvrec.Unit                 = "E";
     pocsvrec.Price                = (polinerec.Price ?? 0).ToString();
     pocsvrec.Per = polinerec.UM;
     return(pocsvrec);
 }
Exemplo n.º 5
0
 private POAmendmentCSVRecord BuildJobBasedAmendmentLine(POLine polinerec, string wbs, POAmendmentCSVRecord pocsvrec)
 {
     pocsvrec.OrderLineType        = "m"; //Changed from "C", which worked in testing but not production
     pocsvrec.Code                 = "CM-MA";
     pocsvrec.ClauseCode           = String.Empty;
     pocsvrec.OrderLineDescription = String.IsNullOrEmpty(polinerec.MfgDesc) ? "***Unknown***" : polinerec.MfgDesc;
     pocsvrec.WBSCode              = wbs;
     pocsvrec.CostCode             = polinerec.CostCode?.Trim();
     pocsvrec.CostCategory         = "MA";
     pocsvrec.Quantity             = ((decimal)(polinerec.QtyOrd ?? 0) - (decimal)(polinerec.QtyIvc ?? 0)).ToString();
     pocsvrec.Unit                 = "E";
     pocsvrec.Price                = (polinerec.Price ?? 0).ToString();
     pocsvrec.Per = polinerec.UM;
     return(pocsvrec);
 }