Пример #1
0
        public List <(Direct.Invoice.Header header, List <Direct.Invoice.Detail> details)> CDFL(string fullpathandname, string vendor)
        {
            Direct.Invoice.Header        header  = null;
            List <Direct.Invoice.Detail> details = new List <Direct.Invoice.Detail>();

            Direct.Invoice.Detail detail = null;
            FormatCDFL.Models.Files.Invoice.DataSequence.V3 invCDFL = new FormatCDFL.Models.Files.Invoice.DataSequence.V3();
            List <(Direct.Invoice.Header header, List <Direct.Invoice.Detail> details)> invoices = new List <(Direct.Invoice.Header header, List <Direct.Invoice.Detail> details)>();
            List <string> storelist = new List <string>();
            List <DataHPBEDI.Models.MetaData.VendorStoreData> VendorStore = null;

            try
            {
                using (FormatCDFL.Logic.Data.Invoice.Files cdflINV = new FormatCDFL.Logic.Data.Invoice.Files())
                {
                    invCDFL = cdflINV.ReadFile(fullpathandname, cdflINV.CreateBatch(fullpathandname, vendor));
                }
                var invs = (from inv in invCDFL.Invoices
                            select inv.InvoiceDetails).ToArray();
                //?? var invPOs = (from invpos in invs.First()
                //??              group invpos by invpos.InvoiceDetailRecord.PONumber into g
                //??              select new
                //??              {
                //??                  PONumber = g.Key,
                //??                  Items = g.ToList(),
                //??                  g.First().InvoiceDetailRecord.RecordSequenceNumber,
                //??              }).ToList();
                //?? storelist = (from list in invCDFL.Invoices select list.InvoiceHeaderRecord.StoreNumber).Distinct().ToList();
                using (DataHPBEDI.Logic.MetaData.Retreive metadata = new DataHPBEDI.Logic.MetaData.Retreive())
                {
                    VendorStore = metadata.VendorStoreData(vendor, storelist);
                }


                for (int invoicecount = 0; invoicecount < invCDFL.Invoices.Count; invoicecount++)
                {
                    //?? for (int pocount = 0; pocount < invPOs.Count(); pocount++)
                    //?? {
                    //??    //?? (string storenumber, string storesan) = (from vs in VendorStore
                    //??    //??                                         where vs.VendorShipTo == invCDFL.Invoices[invoicecount].InvoiceHeaderRecord.IngramShipToAccountNumber
                    //??    //??                                         select (vs.LocationNumber, vs.SanAccount)).First();
                    //??    details = new List<DataHPBEDI.Models.EDI.Invoice.Detail>();
                    //??    header = new DataHPBEDI.Models.EDI.Invoice.Header
                    //??    {
                    //??        //?? BillToLoc = "",
                    //??        //?? BillToSAN = "",
                    //??        //?? CurrencyCode = "",
                    //??        //?? GSNo = "",
                    //??        //?? InsertDateTime = DateTime.UtcNow,
                    //??        //?? InvoiceAckNo = "",
                    //??        //?? InvoiceACKSent = false,
                    //??        //?? InvoiceNo = invCDFL.Invoices[invoicecount].InvoiceHeaderRecord.InvoiceNumber.ToString(),
                    //??        //?? IssueDate = invCDFL.Invoices[invoicecount].InvoiceHeaderRecord.InvoiceDate,
                    //??        //?? PONumber = invPOs[pocount].PONumber,
                    //??        //?? Processed = false,
                    //??        //?? // ProcessedDateTime
                    //??        //?? ReferenceNo = invCDFL.Invoices[invoicecount].InvoiceVendorDetailRecord.IngramOrderEntryNumber,
                    //??        //?? ShipFromLoc = invCDFL.Invoices[invoicecount].InvoiceVendorDetailRecord.DCCode.ToString(),
                    //??        //?? ShipFromSAN = invCDFL.InvoiceFileHeaderRecord.IngramSAN,
                    //??        //?? ShipToLoc = storenumber,
                    //??        //?? ShipToSAN = storesan,
                    //??        //?? TotalLines = (short)invPOs[pocount].Items.Count,
                    //??        //?? TotalPayable = (from counts in invPOs[pocount].Items
                    //??        //??                select counts.InvoiceDetailRecord.NetPriceOrCost).Sum(),
                    //??        //?? //.invCDFL.Invoices[invoicecount].InvoiceTrailerRecord.TotalInvoiceAmount,
                    //??        //?? TotalQuantity = (from counts in invPOs[pocount].Items
                    //??        //??                 select (int)counts.InvoiceDetailRecord.QuantityShipped).Sum(),
                    //??        //?? //invCDFL.InvoiceFileTrailer.TotalItems,
                    //??        //?? VendorId = vendor
                    //??    };
                    //??
                    //??    for (int detailcount = 0; detailcount < invPOs[pocount].Items.Count; detailcount++)
                    //??    {
                    //??        detail = new DataHPBEDI.Models.EDI.Invoice.Detail
                    //??        {
                    //??            //?? // InvoiceId = "",
                    //??            //?? // InvoiceItemId = "",
                    //??            //?? // DiscountCode = "",
                    //??            //?? DiscountPct = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.DiscountPercent / 100m,
                    //??            //?? DiscountPrice = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.NetPriceOrCost,
                    //??            //?? InvoiceQty = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.QuantityShipped,
                    //??            //?? ItemDesc = invPOs[pocount].Items[detailcount].DetailTotalRecord.Title,
                    //??            //?? ItemIdCode = "EN",
                    //??            //?? ItemIdentifier = invPOs[pocount].Items[detailcount].DetailISBN13OrEANRecord.ISBN13OrEANShipped,
                    //??            //?? LineNo = invPOs[pocount].Items[detailcount].DetailISBN13OrEANRecord.RecordSequenceNumber.ToString().Trim().PadLeft(10, '0'),
                    //??            //?? RetailPrice = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.IngramItemListPrice,
                    //??            //?? UnitPrice = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.NetPriceOrCost,
                    //??            //?? ReferenceNumber = invPOs[pocount].Items[detailcount].DetailISBN13OrEANRecord.LineItemIDNumber,
                    //??            //?? ponumber = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.PONumber,
                    //??        };
                    //??        if (detail != null)
                    //??        {
                    //??            details.Add(detail);
                    //??        }
                    //??    }
                    //??    invoices.Add((header, details));
                    //?? }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            return(invoices);
        }
Пример #2
0
        public List <(Bulk.Invoice.Header header, List <Bulk.Invoice.Detail> details)> BBV3(string fullpathandname, string vendor)
        {
            Bulk.Invoice.Header        header  = null;
            List <Bulk.Invoice.Detail> details = new List <Bulk.Invoice.Detail>();

            Bulk.Invoice.Detail detail = null;
            FormatBBV3.Models.Files.Invoice.DataSequence.V3 invBBV3 = new FormatBBV3.Models.Files.Invoice.DataSequence.V3();
            List <(Bulk.Invoice.Header header, List <Bulk.Invoice.Detail> details)> invoices = new List <(Bulk.Invoice.Header header, List <Bulk.Invoice.Detail> details)>();
            List <string> storelist = new List <string>();
            List <DataHPBEDI.Models.MetaData.VendorStoreData> VendorStore = null;

            try
            {
                using (FormatBBV3.Logic.Data.Invoice.Files bbvINV = new FormatBBV3.Logic.Data.Invoice.Files())
                {
                    invBBV3 = bbvINV.ReadFile(fullpathandname, bbvINV.CreateBatch(fullpathandname, vendor));
                }
                var invs = (from inv in invBBV3.Invoices
                            select inv.InvoiceDetails).ToArray();
                var invPOs = (from invpos in invs.First()
                              group invpos by invpos.InvoiceDetailRecord.PONumber into g
                              select new
                {
                    PONumber = g.Key,
                    Items = g.ToList(),
                    g.First().InvoiceDetailRecord.RecordSequenceNumber,
                }).ToList();
                storelist = (from list in invBBV3.Invoices select list.InvoiceHeaderRecord.StoreNumber).Distinct().ToList();
                using (DataHPBEDI.Logic.MetaData.Retreive metadata = new DataHPBEDI.Logic.MetaData.Retreive())
                {
                    VendorStore = metadata.VendorStoreData(vendor, storelist);
                }


                for (int invoicecount = 0; invoicecount < invBBV3.Invoices.Count; invoicecount++)
                {
                    for (int pocount = 0; pocount < invPOs.Count(); pocount++)
                    {
                        (string storenumber, string storesan) = (from vs in VendorStore
                                                                 where vs.VendorShipTo == invBBV3.Invoices[invoicecount].InvoiceHeaderRecord.IngramShipToAccountNumber
                                                                 select(vs.LocationNumber, vs.SanAccount)).First();
                        details = new List <Bulk.Invoice.Detail>();
                        header  = new Bulk.Invoice.Header
                        {
                            BillToLoc      = "",
                            BillToSAN      = "",
                            CurrencyCode   = "",
                            GSNo           = "",
                            InsertDateTime = DateTime.UtcNow,
                            InvoiceAckNo   = "",
                            InvoiceACKSent = false,
                            InvoiceNo      = invBBV3.Invoices[invoicecount].InvoiceHeaderRecord.InvoiceNumber.ToString(),
                            IssueDate      = invBBV3.Invoices[invoicecount].InvoiceHeaderRecord.InvoiceDate,
                            PONumber       = invPOs[pocount].PONumber,
                            Processed      = false,
                            // ProcessedDateTime
                            ReferenceNo  = invBBV3.Invoices[invoicecount].InvoiceVendorDetailRecord.IngramOrderEntryNumber,
                            ShipFromLoc  = invBBV3.Invoices[invoicecount].InvoiceVendorDetailRecord.DCCode.ToString(),
                            ShipFromSAN  = invBBV3.InvoiceFileHeaderRecord.IngramSAN,
                            ShipToLoc    = storenumber,
                            ShipToSAN    = storesan,
                            TotalLines   = (short)invPOs[pocount].Items.Count,
                            TotalPayable = (from counts in invPOs[pocount].Items
                                            select counts.InvoiceDetailRecord.NetPriceOrCost).Sum(),
                            //.invBBV3.Invoices[invoicecount].InvoiceTrailerRecord.TotalInvoiceAmount,
                            TotalQuantity = (from counts in invPOs[pocount].Items
                                             select(int) counts.InvoiceDetailRecord.QuantityShipped).Sum(),
                            //invBBV3.InvoiceFileTrailer.TotalItems,
                            VendorId = vendor
                        };

                        for (int detailcount = 0; detailcount < invPOs[pocount].Items.Count; detailcount++)
                        {
                            detail = new Bulk.Invoice.Detail
                            {
                                // InvoiceId = "",
                                // InvoiceItemId = "",
                                // DiscountCode = "",
                                DiscountPct     = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.DiscountPercent / 100m,
                                DiscountPrice   = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.NetPriceOrCost,
                                InvoiceQty      = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.QuantityShipped,
                                ItemDesc        = invPOs[pocount].Items[detailcount].DetailTotalRecord.Title,
                                ItemIdCode      = "EN",
                                ItemIdentifier  = invPOs[pocount].Items[detailcount].DetailISBN13OrEANRecord.ISBN13OrEANShipped,
                                LineNo          = invPOs[pocount].Items[detailcount].DetailISBN13OrEANRecord.RecordSequenceNumber.ToString().Trim().PadLeft(10, '0'),
                                RetailPrice     = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.IngramItemListPrice,
                                UnitPrice       = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.NetPriceOrCost,
                                ReferenceNumber = invPOs[pocount].Items[detailcount].DetailISBN13OrEANRecord.LineItemIDNumber,
                                ponumber        = invPOs[pocount].Items[detailcount].InvoiceDetailRecord.PONumber,
                            };
                            if (detail != null)
                            {
                                details.Add(detail);
                            }
                        }
                        invoices.Add((header, details));
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            return(invoices);
        }
Пример #3
0
        static void Main(string[] args)
        {
            string     currentvendor = "IDINGRAMDI";
            const byte ediVersion    = 3;  // BBV3
            string     dir           = string.Empty;
            string     ext           = ""; //".TXT";
            string     sendvia       = "FTP";
            List <(bool successful, string filename)> files = new List <(bool successful, string filename)>();

            //
            CommonLib.Logic.Globals.ConnectStringDelims = UserConsole.Default.ConStrgs_Delims;
            CommonLib.Logic.Globals.ConnectStringEDI    = UserConsole.Default.ConStrgs_HPBEDI;
            CommonLib.Logic.Globals.Env = UserConsole.Default.Env;
            CommonLib.SQL.Tools.InsertServer(CommonLib.Logic.Globals.GenerateConnections());
            //
            using (DataHPBEDI.Logic.MetaData.Retreive codelist = new DataHPBEDI.Logic.MetaData.Retreive())
            {
                Codes = codelist.AllCodes();
            }
            List <(string type, string read, string write, bool transup, bool transdown)> doit = new List <(string title, string read, string write, bool transup, bool transdown)>()
            {
                ("BBV3", "N", "Y", false, true),
                ("CDFL", "Y", "N", false, true)
            };

            if ((from d in doit.AsEnumerable() where d.type.ToUpper() == "BBV3" && d.write.ToUpper() == "Y" select d.read).Count() > 0)
            {
                using (DataHPBEDI.Logic.BLK.Retrieve ret = new DataHPBEDI.Logic.BLK.Retrieve())
                {
                    dir = @"c:\temp\IC_EDI\BBV3\";
                    using (VendorIngramContent.Logic.PurchaseOrder.Create fileoutput = new VendorIngramContent.Logic.PurchaseOrder.Create((from c in Codes where c.FileFormat == "BBV3" && c.VendorId.ToLower() == currentvendor.ToLower() select c).ToList()))
                    {
                        foreach (string ponumber in new List <string> {
                            "268698", "266892", "270974"
                        })                                                                                                     //   { "270974", "253992", "253983", "253950" })
                        {
                            files.Add(fileoutput.BBV3(dir, ext, currentvendor, new List <string> {
                                "20"
                            }, ret.PurchaseOrder(ponumber)));
                        }
                        switch (sendvia.ToLower())
                        {
                        case "ftp":
                            List <VendorIngramContent.Models.FTP.Results> sendfiles = new List <VendorIngramContent.Models.FTP.Results>();
                            List <VendorIngramContent.Models.FTP.Results> recvfiles = new List <VendorIngramContent.Models.FTP.Results>();
                            using (VendorIngramContent.Transfers.FTP ftp = new VendorIngramContent.Transfers.FTP())
                            {
                                if ((from d in doit.AsEnumerable() where d.type.ToUpper() == "BBV3" && d.transup select d.transup).Count() > 0)
                                {
                                    sendfiles = ftp.Upload
                                                (
                                        "BBV3",
                                        (from f in files
                                         where f.successful == true
                                         select f.filename).ToList()
                                                );
                                }
                                if ((from d in doit.AsEnumerable() where d.type.ToUpper() == "BBV3" && d.transdown select d.transdown).Count() > 0)
                                {
                                    recvfiles = ftp.Download
                                                (
                                        "BBV3",
                                        @"C:\temp\IC_EDI\BBV3\in",
                                        true
                                                );
                                }
                            }
                            break;

                        case "webservice":
                            break;
                        }
                    }
                }
            }
            //
            if ((from d in doit.AsEnumerable() where d.type.ToUpper() == "BBV3" && d.read.ToUpper() == "Y" select d.read).Count() > 0)
            {
                using (DataHPBEDI.Logic.BLK.Input input = new DataHPBEDI.Logic.BLK.Input())
                {
                    using (VendorIngramContent.Logic.Invoice.Retrieve inputinv = new VendorIngramContent.Logic.Invoice.Retrieve())
                    {
                        input.Invoice(inputinv.BBV3(@"c:\temp\ic_edi\bbv3\V3_SMPL_INV_BIN.txt", "IDINGRAMDI"), ediVersion);
                    }
                    using (VendorIngramContent.Logic.PurchaseAcknowledgement.Retrieve inputack = new VendorIngramContent.Logic.PurchaseAcknowledgement.Retrieve())
                    {
                        input.Acknowledge(inputack.BBV3(@"c:\temp\ic_edi\bbv3\V3_SMPL_POA_FBC_CRLF.txt", "IDINGRAMDI"), ediVersion);
                    }
                    using (VendorIngramContent.Logic.ShipNotice.Retrieve inputship = new VendorIngramContent.Logic.ShipNotice.Retrieve())
                    {
                        input.Shipment(inputship.BBV3(@"c:\temp\ic_edi\bbv3\V3_SMPL_ASN_PBS.txt", "IDINGRAMDI"), ediVersion);
                    }
                }
            }

            /*
             *
             */
            if ((from d in doit.AsEnumerable() where d.type.ToUpper() == "CDFL" && d.write.ToUpper() == "Y" select d.read).Count() > 0)
            {
                using (DataHPBEDI.Logic.CDF.Retrieve ret = new DataHPBEDI.Logic.CDF.Retrieve())
                {
                    dir = @"c:\temp\IC_EDI\CDFL\";
                    using (VendorIngramContent.Logic.PurchaseOrder.Create fileoutput = new VendorIngramContent.Logic.PurchaseOrder.Create((from c in Codes where c.FileFormat == "CDFL" && c.VendorId.ToLower() == currentvendor.ToLower() select c).ToList()))
                    {
                        foreach (string ponumber in new List <string> {
                            "268698", "266892", "270974"
                        })                                                                                                     //   { "270974", "253992", "253983", "253950" })
                        {
                            files.Add(fileoutput.CDFL(dir, ext, currentvendor, ret.PurchaseOrder(ponumber)));
                        }
                        switch (sendvia.ToLower())
                        {
                        case "ftp":
                            List <VendorIngramContent.Models.FTP.Results> sendfiles = new List <VendorIngramContent.Models.FTP.Results>();
                            List <VendorIngramContent.Models.FTP.Results> recvfiles = new List <VendorIngramContent.Models.FTP.Results>();
                            using (VendorIngramContent.Transfers.FTP ftp = new VendorIngramContent.Transfers.FTP())
                            {
                                sendfiles = ftp.Upload
                                            (
                                    "CDFL",
                                    (from f in files
                                     where f.successful == true
                                     select f.filename).ToList()
                                            );
                                recvfiles = ftp.Download
                                            (
                                    "CDFL",
                                    @"C:\temp\IC_EDI\BBV3\in",
                                    true
                                            );
                            }
                            break;

                        case "webservice":
                            break;
                        }
                    }
                }
            }
            //
            if ((from d in doit.AsEnumerable() where d.type.ToUpper() == "CDFL" && d.read.ToUpper() == "Y" select d.read).Count() > 0)
            {
                using (DataHPBEDI.Logic.CDF.Input input = new DataHPBEDI.Logic.CDF.Input())
                {
                    using (VendorIngramContent.Logic.Invoice.Retrieve inputinv = new VendorIngramContent.Logic.Invoice.Retrieve())
                    {
                        input.Invoice(inputinv.CDFL(@"c:\temp\ic_edi\cdfl\INV Vers 03.txt", "IDINGRAMDI"), ediVersion);
                    }
                    using (VendorIngramContent.Logic.PurchaseAcknowledgement.Retrieve inputack = new VendorIngramContent.Logic.PurchaseAcknowledgement.Retrieve())
                    {
                        input.Acknowledge(inputack.CDFL(@"c:\temp\ic_edi\cdfl\CDFL POA Example 2 Vers 03.txt", "IDINGRAMDI"), ediVersion);
                    }
                    using (VendorIngramContent.Logic.ShipNotice.Retrieve inputship = new VendorIngramContent.Logic.ShipNotice.Retrieve())
                    {
                        input.Shipment(inputship.CDFL(@"c:\temp\ic_edi\cdfl\ASN1 Vers 03.txt", "IDINGRAMDI"), ediVersion);
                    }
                }
            }



            System.Console.WriteLine("Application completed all tasks.");
            System.Console.Write(">");
            System.Console.ReadLine();
        }