Exemple #1
0
        protected EDIXmlTransactionSet CreateTransactionSet(OrderShippingInfo message)
        {
            if (message.Lines.Count() == 0)
            {
                throw new Exception("Shipped order contains no line items!");
            }

            var originalDoc = _docsRepo.GetByDocumentControlNumberAndPartnerID(message.ControlNumber.CastToInt(), BusinessPartner.Initech.Number);

            if (originalDoc == null)
            {
                throw new Exception(string.Format("Control number {0} not found for business partner {1}.",
                                                  message.ControlNumber, message.BusinessPartnerNumber));
            }
            var orderTypeElement = originalDoc.ResponseElements.Find(e => e.ElementName == "REF02" && (e.Qualifier == Qualifier.MutuallyAssignedCode.Value));
            var priorityElement  = originalDoc.ResponseElements.Find(e => e.ElementName == "REF02" && (e.Qualifier == Qualifier.ServiceLevelNumber.Value));

            var doc = new EDIXmlTransactionSet(_segmentFactory)
            {
                ISA = _repo.GetNextISA(GroupTypeConstants.AdvanceShipNotice, BusinessPartner.Initech.Number)
            };


            var docDef = _repo.GetNextDocument(doc.ISA, 856);

            doc.SetHeader("856", docDef.ControlNumber);

            docDef.ERPID = message.BOL;
            _repo.Save(docDef.ISAEntity);

            doc.AddSegment(get_begin_segment(message));

            if (message.MaxDateShipped() > DateTime.MinValue)
            {
                doc.AddSegment(_segmentFactory.GetDateTimeSegment(EDIDateQualifiers.Shipped, message.MaxDateShipped()));
            }

            var hl = HierarchicalLevelLoopWrapper.BuildWrapper("O", _segmentFactory, true);

            hl.AddSegment(_segmentFactory.GetPurchaseOrderReference(message.CustomerPO.Trim()));

            if (orderTypeElement != null)
            {
                hl.AddSegment(_segmentFactory.GetReferenceIDSegment(orderTypeElement.Qualifier, orderTypeElement.Value));
            }

            if (priorityElement != null)
            {
                hl.AddSegment(_segmentFactory.GetReferenceIDSegment(priorityElement.Qualifier, priorityElement.Value));
            }


            var addrs = new AddressLoop(_segmentFactory);

            if (message.ShipToAddress.AddressName.IsNullOrEmpty())
            {
                message.ShipToAddress.AddressName = "FEDERAL EXPRESS";
            }

            addrs.AddAddress(message.ShipToAddress, Qualifier.EmptyQualifier);

            addrs.AddAddress(message.ShipFromAddress, Qualifier.EmptyQualifier);

            hl.AddLoop(addrs);

            message.Lines.ForEach(l => add_line(hl, l, originalDoc.LineItems));

            hl.AddTo(doc);

            doc.AddSegment(_segmentFactory.GetTransactionTotal(message.Lines.Count()));

            doc.SetFooter();


            return(doc);
        }
Exemple #2
0
        private EDIXmlTransactionSet create_transaction_set(InvoicedOrderMessage orderMessage)
        {
            if (orderMessage.Customer == null)
            {
                throw new ApplicationException("There is no customer associated with invoiced order message "
                                               + orderMessage.ControlNumber + ".  Cannot build 810.");
            }


            var orderDoc = _docsRepo.GetByDocumentControlNumberAndPartnerID(orderMessage.ControlNumber.CastToInt(), BusinessPartner.Initech.Number);

            if (orderDoc == null)
            {
                throw new Exception(string.Format("Control number {0} not found for business partner {1}.",
                                                  orderMessage.ControlNumber, orderMessage.BusinessPartnerNumber));
            }
            var responseElements = orderDoc.ResponseElements.Where(e => e.ElementName == "REF02");

            var isa = _repo.GetNextISA(GroupTypeConstants.Invoice, BusinessPartner.Initech.Number);

            if (orderMessage.LineCount() == 0)
            {
                throw new Exception("Invoiced order contains no line items!");
            }

            var doc = new EDIXmlTransactionSet(_segmentFactory)
            {
                ISA = isa
            };

            var docDef = _repo.GetNextDocument(isa, 810);

            doc.SetHeader("810", docDef.ControlNumber);

            docDef.ERPID = orderMessage.BOL;

            _repo.Save(docDef.ISAEntity);

            doc.AddSegment(get_begin_segment(orderMessage));

            //doc.AddSegment(_segmentFactory.GetCurrencySegment("II",orderMessage.CurrencyCode));

            if (responseElements != null)
            {
                responseElements.ForEach(r => doc.AddSegment(_segmentFactory.GetReferenceIDSegment(r.Qualifier,
                                                                                                   r.Value)));
            }

            doc.AddLoop(get_address_loop(orderMessage));

            // doc.AddSegment(get_terms(orderMessage));

            doc.AddLoop(get_detail_loop(orderMessage, orderDoc.LineItems));

            doc.AddSegment(_segmentFactory.GetTotalMonetaryValue(orderMessage.GetTotal()));

            doc.AddSegment(_segmentFactory.GetTaxInformationSegment("SU", orderMessage.SalesTax));

            doc.AddSegment(_segmentFactory.GetCarrierDetail("P", "Initech"));

            doc.AddSegment(_segmentFactory.GetTransactionTotal(orderMessage.LineCount()));


            doc.SetFooter();

            return(doc);
        }