示例#1
0
        public void FormattingATime()
        {
            DateTime time = DateTime.Parse("3:24:22.150");

            Assert.AreEqual("0324", EdiValue.Time(4, time));
            Assert.AreEqual("032422", EdiValue.Time(6, time));
            Assert.AreEqual("03242215", EdiValue.Time(8, time));
        }
示例#2
0
文件: UPRD_GN.cs 项目: iiTarun/iiCode
        public EdiDocument GenerateEDIUPRD(bool IsOacy, bool IsUnsc, bool IsSwnt, bool IsTest, string pipeDuns, PipelineEDISettingDTO pipelineEdiSetting, bool sendManu)
        {
            string number = String.Format("{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000);
            string path   = Path.GetRandomFileName();

            path = path.Replace(".", "");
            var ediDocument = new EdiDocument();
            var isa         = new EdiSegment("ISA");

            isa[01] = "00";
            isa[02] = "".PadRight(10);
            isa[03] = "00";
            isa[04] = "".PadRight(10);
            isa[05] = "01";
            isa[06] = pipelineEdiSetting.ISA06_Segment.Trim().PadRight(15);// service requester duns
            isa[07] = pipelineEdiSetting.ISA08_segment.Trim().All(char.IsDigit) == true ? "01" : "14";
            isa[08] = pipelineEdiSetting.ISA08_segment.Trim().PadRight(15);
            isa[09] = EdiValue.Date(6, DateTime.Now);
            isa[10] = EdiValue.Time(4, DateTime.Now);
            isa[11] = pipelineEdiSetting.ISA11_Segment.Trim(); //"U";// UPRD setting ISA11_seg
            isa[12] = pipelineEdiSetting.ISA12_Segment.Trim(); //"00304";//Release/version*******PipelineUprdSetting_ISA12_Seg
            isa[13] = number;
            isa[14] = "0";
            isa[15] = IsTest ? "T" : "P";                      //Convert.ToBoolean(ConfigurationManager.AppSettings["EDIForTest"]) ? "T" : "P";//"P";//configuration setting for Test and Prod
            isa[16] = pipelineEdiSetting.ISA16_Segment.Trim(); //">";//uprd setting ISA16
            ediDocument.Segments.Add(isa);

            var gs = new EdiSegment("GS");

            gs[01] = pipelineEdiSetting.GS01_Segment.Trim(); //"IB"; //GS01_segment in edisetting
            gs[02] = pipelineEdiSetting.GS02_Segment.Trim(); //"078711334";//service requester duns
            gs[03] = pipelineEdiSetting.GS03_Segment.Trim(); //"RECEIVER";//GS03_Segment UPRD setting
            gs[04] = (pipeDuns.Trim() == "006958581" ||
                      pipeDuns.Trim() == "046077343" ||
                      pipeDuns.Trim() == "007933021" ||
                      pipeDuns.Trim() == "116025180" ||
                      pipeDuns.Trim() == "094992187" ||
                      pipeDuns.Trim() == "784158214" ||
                      pipeDuns.Trim() == "876833500" ||
                      pipeDuns.Trim() == "808168645" ||
                      pipeDuns.Trim() == "006912885" ||
                      pipeDuns.Trim() == "021632583" ||
                      pipeDuns.Trim() == "030353283" ||
                      pipeDuns.Trim() == "961777229" ||
                      pipeDuns.Trim() == "013081810" ||
                      pipeDuns.Trim() == "017738746") ?
                     EdiValue.Date(6, DateTime.Now) : EdiValue.Date(8, DateTime.Now);
            gs[05] = EdiValue.Time(4, DateTime.Now);
            gs[06] = number.Substring(number.Length - 4, 4);
            gs[07] = pipelineEdiSetting.GS07_Segment.Trim(); //"X"; //GS07 segmnet in EDI setting
            gs[08] = pipelineEdiSetting.GS08_Segment.Trim(); //"004010"; //GS08 segment in EDI setting
            ediDocument.Segments.Add(gs);

            var st = new EdiSegment("ST");

            st[01] = pipelineEdiSetting.ST01_Segment.Trim();//"846"; //ST01 Segment in EDI setting
            st[02] = gs[06];
            ediDocument.Segments.Add(st);

            var bia = new EdiSegment("BIA");

            bia[01] = "00";
            bia[02] = "PS";
            bia[03] = path.ToString();
            bia[04] = EdiValue.Date(6, DateTime.Now);
            ediDocument.Segments.Add(bia);


            //var searchCri = DateTime.Parse("9/9/2017");
            var dtm = new EdiSegment("DTM");

            dtm[01] = "007";

            if (pipeDuns.Trim() == "116025180" || pipeDuns.Trim() == "876833500")
            {
                dtm[06] = "RD8";
                if (sendManu)
                {
                    dtm[07] = EdiValue.Date(8, pipelineEdiSetting.StartDate) + "-" + EdiValue.Date(8, pipelineEdiSetting.EndDate);
                }
                else
                {
                    dtm[07] = EdiValue.Date(8, DateTime.Now) + "-" + EdiValue.Date(8, DateTime.Now);
                }
            }
            else
            {
                dtm[06] = "DTS";
                if (sendManu)
                {
                    dtm[07] = (pipeDuns.Trim() == "094992187") ? EdiValue.Date(14, pipelineEdiSetting.StartDate.Date) : EdiValue.Date(14, pipelineEdiSetting.StartDate.AddSeconds(1));//  + "-" + EdiValue.Date(14, pipelineEdiSetting.EndDate);//EdiValue.Date(8, searchCri) + "-" + EdiValue.Date(8, searchCri.AddDays(1));
                }
                else
                {
                    dtm[07] = (pipeDuns.Trim() == "094992187") ? EdiValue.Date(14, DateTime.Now.Date) : EdiValue.Date(14, DateTime.Now.Date.AddSeconds(1));// + "-" + EdiValue.Date(14, DateTime.Now);//EdiValue.Date(8, searchCri) + "-" + EdiValue.Date(8, searchCri.AddDays(1));
                }
            }


            ediDocument.Segments.Add(dtm);

            var n1SvcPvdr = new EdiSegment("N1");

            n1SvcPvdr[01] = "SJ";
            n1SvcPvdr[03] = "1";
            n1SvcPvdr[04] = pipeDuns.Trim();//"Receiver";
            ediDocument.Segments.Add(n1SvcPvdr);

            var n1SvcRq = new EdiSegment("N1");

            n1SvcRq[01] = "41";
            n1SvcRq[03] = "1";
            n1SvcRq[04] = "078711334";//Sender
            ediDocument.Segments.Add(n1SvcRq);

            if (IsOacy)
            {
                var lin = new EdiSegment("LIN");
                lin[01] = "1";
                lin[02] = "OA";
                lin[03] = "8";//uprd_DataRequestCode.RequestCode.Trim();//"8";//oacy(8),UNSC(9),SWNT(6);
                ediDocument.Segments.Add(lin);
            }

            if (IsUnsc)
            {
                var lin = new EdiSegment("LIN");
                lin[01] = "1";
                lin[02] = "OA";
                lin[03] = "9";//uprd_DataRequestCode.RequestCode.Trim();//"8";//oacy(8),UNSC(9),SWNT(6);
                ediDocument.Segments.Add(lin);
            }

            if (IsSwnt)
            {
                var lin = new EdiSegment("LIN");
                lin[01] = "1";
                lin[02] = "OA";
                lin[03] = "6";//uprd_DataRequestCode.RequestCode.Trim();//"8";//oacy(8),UNSC(9),SWNT(6);
                ediDocument.Segments.Add(lin);
            }

            var ctt = new EdiSegment("CTT");

            ctt[01] = "1";
            ediDocument.Segments.Add(ctt);

            var se = new EdiSegment("SE");

            se[01] = "8";
            se[02] = st[02];
            ediDocument.Segments.Add(se);

            var ge = new EdiSegment("GE");

            ge[01] = "1";
            ge[02] = gs[06];
            ediDocument.Segments.Add(ge);

            var iea = new EdiSegment("IEA");

            iea[01] = "1";
            iea[02] = number;
            ediDocument.Segments.Add(iea);

            // more segments...

            // ediDocument.Options.SegmentTerminator = pipeDuns.Trim()== "094992187" ? Convert.ToChar("\n"): Convert.ToChar(pipelineEdiSetting.SegmentSeperator);//Segment Separator from edi setting
            ediDocument.Options.SegmentTerminator = !string.IsNullOrEmpty(pipelineEdiSetting.SegmentSeperator) ? Convert.ToChar(pipelineEdiSetting.SegmentSeperator) : EdiOptions.DefaultSegmentTerminator;
            ediDocument.Options.ElementSeparator  = Convert.ToChar(pipelineEdiSetting.DataSeparator);//'*';// data separator from edi setting

            return(ediDocument);
        }
示例#3
0
        public void WriteInvoiceEdi(Invoice invoice)
        {
            var ediDocument = new EdiDocument();
            var isa         = new EdiSegment("ISA");

            isa[01] = "00";
            isa[02] = "".PadRight(10);
            isa[03] = "00";
            isa[04] = "".PadRight(10);
            isa[05] = "ZZ";
            isa[06] = "SENDER".PadRight(15);
            isa[07] = "ZZ";
            isa[08] = "RECEIVER".PadRight(15);
            isa[09] = EdiValue.Date(6, DateTime.Now);
            isa[10] = EdiValue.Time(4, DateTime.Now);
            isa[11] = "U";
            isa[12] = "00400";
            isa[13] = 1.ToString("d9");
            isa[14] = "0";
            isa[15] = "P";
            isa[16] = ">";
            ediDocument.Segments.Add(isa);

            var gs = new EdiSegment("GS");

            gs[01] = "IN";
            gs[02] = "SENDER";
            gs[03] = "RECEIVER";
            gs[04] = EdiValue.Date(8, DateTime.Now);
            gs[05] = EdiValue.Time(4, DateTime.Now);
            gs[06] = EdiValue.Numeric(0, 1);
            gs[07] = "X";
            gs[08] = "004010";
            ediDocument.Segments.Add(gs);

            var st = new EdiSegment("ST");

            st[01] = "810";
            st[02] = "166061414";
            ediDocument.Segments.Add(st);

            var big = new EdiSegment("BIG");

            big[01] = invoice.BIG01_Date != null
                ? invoice.BIG01_Date.Value.ToString("yyyyMMdd")
                : "";

            big[02] = invoice.BIG02_InvoiceNumber;
            big[03] = invoice.BIG03_Date != null
                ? invoice.BIG01_Date.Value.ToString("yyyyMMdd")
                : "";

            big[04] = invoice.BIG04_PurchaseOrderNumber;
            big[07] = invoice.BIG04_TransactionTypeCode;
            big[08] = invoice.BIG08_TransactionSetPurposeCode;
            ediDocument.Segments.Add(big);

            foreach (var note in invoice.Notes)
            {
                var nte = new EdiSegment("NTE");
                nte[01] = note.NTE01_NoteReferenceCode;
                nte[02] = note.NTE02_NoteDescription;
                ediDocument.Segments.Add(nte);
            }

            if (!(String.IsNullOrEmpty(invoice.CUR01_CurrencyEntityIdentifierCode) &&
                  String.IsNullOrEmpty(invoice.CUR02_CurrencyCode) &&
                  String.IsNullOrEmpty(invoice.CUR03_ExchangeRate)))
            {
                var cur = new EdiSegment("CUR");
                cur[01] = invoice.CUR01_CurrencyEntityIdentifierCode;
                cur[02] = invoice.CUR02_CurrencyCode;
                ediDocument.Segments.Add(cur);
            }

            foreach (var invoiceRef in invoice.Refs)
            {
                var refinv = new EdiSegment("REF");
                refinv[01] = invoiceRef.REF01_ReferenceIdentificationQualifier;
                refinv[02] = invoiceRef.REF02_ReferenceIdentification;
                refinv[03] = invoiceRef.REF03_Description;
                ediDocument.Segments.Add(refinv);
            }

            foreach (var name in invoice.Names)
            {
                var n1 = new EdiSegment("N1");
                n1[01] = name.N101_EntityIdentifierCode;
                n1[02] = name.N102_Name;
                n1[03] = name.N103_IdentificationCodeQualifier;
                n1[04] = name.N104_IdentificationCode;
                ediDocument.Segments.Add(n1);

                if (!(String.IsNullOrEmpty(name.N201_Name) &&
                      String.IsNullOrEmpty(name.N202_Name)))
                {
                    var n2 = new EdiSegment("N2");
                    n2[01] = name.N201_Name;
                    n2[02] = name.N202_Name;
                    ediDocument.Segments.Add(n2);
                }

                if (!(String.IsNullOrEmpty(name.N301_Address) &&
                      String.IsNullOrEmpty(name.N302_Address)))
                {
                    var n3 = new EdiSegment("N3");
                    n3[01] = name.N301_Address;
                    n3[02] = name.N302_Address;
                    ediDocument.Segments.Add(n3);
                }

                if (!(String.IsNullOrEmpty(name.N401_City) &&
                      String.IsNullOrEmpty(name.N402_State) &&
                      String.IsNullOrEmpty(name.N403_PostalCode) &&
                      String.IsNullOrEmpty(name.N404_Country)))
                {
                    var n4 = new EdiSegment("N4");
                    n4[01] = name.N401_City;
                    n4[02] = name.N402_State;
                    n4[03] = name.N403_PostalCode;
                    n4[04] = name.N404_Country;
                    ediDocument.Segments.Add(n4);
                }
            }

            var itd = new EdiSegment("ITD");

            itd[01] = invoice.ITD01_TermsTypeCode;
            itd[02] = invoice.ITD02_TermsBasisDateCode;
            itd[07] = invoice.ITD07_TermsNetDays != null
                ? invoice.ITD07_TermsNetDays.Value.ToString()
                : "";

            itd[12] = invoice.ITD12_Description;
            ediDocument.Segments.Add(itd);

            var dtm = new EdiSegment("DTM");

            dtm[01] = invoice.DTM01_DateTimeQualifier;
            dtm[02] = invoice.DTM02_ShipDate != null
                ? invoice.DTM02_ShipDate.Value.ToString("yyyyMMdd")
                : "";

            ediDocument.Segments.Add(dtm);

            foreach (var item in invoice.Items)
            {
                var it1 = new EdiSegment("IT1");
                it1[01] = item.IT101_AssignedIdentification;
                it1[02] = item.IT102_QuantityInvoiced != null
                    ? item.IT102_QuantityInvoiced.ToString()
                    : "";

                it1[03] = item.IT103_UnitOfMeasurement;
                it1[04] = item.IT104_UnitPrice != null
                    ? item.IT104_UnitPrice.Value.ToString("0.00")
                    : "";

                it1[05] = item.IT105_BasisOfUnitPriceCode;
                it1[06] = item.IT106_ProductIdQualifier;
                it1[07] = item.IT107_ProductID;
                it1[08] = item.IT108_ProductIdQualifier;
                it1[09] = item.IT109_ProductID;
                it1[10] = item.IT110_ProductIdQualifier;
                it1[11] = item.IT111_ProductID;
                ediDocument.Segments.Add(it1);

                var pid = new EdiSegment("PID");
                pid[01] = item.PID01_ItemDescriptionType;
                pid[05] = item.PID05_ItemDescription;
                ediDocument.Segments.Add(pid);
            }

            var tds = new EdiSegment("TDS");

            tds[01] = invoice.TDS01_Amount != null
                ? invoice.TDS01_Amount.Value.ToString("0.00")
                : "";

            ediDocument.Segments.Add(tds);

            var ctt = new EdiSegment("CTT");

            ctt[01] = invoice.CTT01_TransactionTotals != null
                ? invoice.CTT01_TransactionTotals.ToString()
                : "";

            var se = new EdiSegment("SE");

            se[01] = (ediDocument.Segments.Count - 1).ToString();
            se[02] = st[02];
            ediDocument.Segments.Add(se);

            var ge = new EdiSegment("GE");

            ge[01] = EdiValue.Numeric(0, 1);
            ge[02] = gs[06];
            ediDocument.Segments.Add(ge);

            var iea = new EdiSegment("IEA");

            iea[01] = EdiValue.Numeric(0, 1);
            iea[02] = isa[13];
            ediDocument.Segments.Add(iea);

            ediDocument.Options.SegmentTerminator = '~';
            ediDocument.Options.ElementSeparator  = '*';
            ediDocument.Save(@"..\..\..\Invoice.txt");
        }
示例#4
0
        public string WritePurchaseOrderEdi(PurchaseOrder purchaseOrder, int customerId)
        {
            string custId = customerId.ToString();

            while (custId.Length < 8)
            {
                custId = "0" + custId;
            }

            var ediDocument = new EdiDocument();
            var isa         = new EdiSegment("ISA");

            isa[01] = "00";
            isa[02] = "".PadRight(10);
            isa[03] = "00";
            isa[04] = "".PadRight(10);
            isa[05] = "ZZ";
            isa[06] = custId.PadRight(15);
            isa[07] = "ZZ";
            isa[08] = "RECEIVER".PadRight(15);
            isa[09] = EdiValue.Date(6, DateTime.Now);
            isa[10] = EdiValue.Time(4, DateTime.Now);
            isa[11] = "U";
            isa[12] = "00401";
            isa[13] = 1.ToString("d9");
            isa[14] = "0";
            isa[15] = "P";
            isa[16] = ">";
            ediDocument.Segments.Add(isa);

            var gs = new EdiSegment("GS");

            gs[01] = "PO";
            gs[02] = "SENDER".PadRight(15);
            gs[03] = "RECEIVER".PadRight(15);
            gs[04] = EdiValue.Date(8, DateTime.Now);
            gs[05] = EdiValue.Time(4, DateTime.Now);
            gs[06] = EdiValue.Numeric(0, 1);
            gs[07] = "X";
            gs[08] = "004010";
            ediDocument.Segments.Add(gs);

            var st = new EdiSegment("ST");

            st[01] = "850";
            st[02] = "166061414";
            ediDocument.Segments.Add(st);

            var beg = new EdiSegment("BEG");

            beg[01] = purchaseOrder.BEG01_TransactionSetPurposeCode;
            beg[02] = purchaseOrder.BEG02_PurchaseOrderTypeCode;
            beg[03] = purchaseOrder.BEG03_PurchaseOrderNumber;
            beg[04] = "";
            beg[05] = purchaseOrder.BEG05_Date != null
                ? purchaseOrder.BEG05_Date.Value.ToString("yyyyMMdd")
                : "";

            ediDocument.Segments.Add(beg);

            if (!(String.IsNullOrEmpty(purchaseOrder.CUR01_CurrencyEntityIdentifierCode) &&
                  String.IsNullOrEmpty(purchaseOrder.CUR02_CurrencyCode)))
            {
                var cur = new EdiSegment("CUR");
                cur[01] = purchaseOrder.CUR01_CurrencyEntityIdentifierCode;
                cur[02] = purchaseOrder.CUR02_CurrencyCode;
                ediDocument.Segments.Add(cur);
            }

            foreach (var poRef in purchaseOrder.Refs)
            {
                var refpo = new EdiSegment("REF");
                refpo[01] = poRef.REF01_ReferenceIdentificationQualifier;
                refpo[02] = poRef.REF02_ReferenceIdentification;
                refpo[03] = poRef.REF03_Description;
                ediDocument.Segments.Add(refpo);
            }
            foreach (var dtm in purchaseOrder.Dtms)
            {
                var dtmpo = new EdiSegment("DTM");
                dtmpo[01] = dtm.DTM01_DateTimeQualifier;
                dtmpo[02] = dtm.DTM02_PurchaseOrderDate != null
                ? dtm.DTM02_PurchaseOrderDate.Value.ToString("yyyyMMdd")
                : "";

                ediDocument.Segments.Add(dtmpo);
            }

            foreach (var name in purchaseOrder.Names)
            {
                var n1 = new EdiSegment("N1");
                n1[01] = name.N101_EntityIdentifierCode;
                n1[02] = name.N102_Name;
                n1[03] = name.N103_IdentificationCodeQualifier;
                n1[04] = name.N104_IdentificationCode;
                ediDocument.Segments.Add(n1);

                if (!(String.IsNullOrEmpty(name.N201_Name) &&
                      String.IsNullOrEmpty(name.N202_Name)))
                {
                    var n2 = new EdiSegment("N2");
                    n2[01] = name.N201_Name;
                    n2[02] = name.N202_Name;
                    ediDocument.Segments.Add(n2);
                }

                if (!(String.IsNullOrEmpty(name.N301_Address) &&
                      String.IsNullOrEmpty(name.N302_Address)))
                {
                    var n3 = new EdiSegment("N3");
                    n3[01] = name.N301_Address;
                    n3[02] = name.N302_Address;
                    ediDocument.Segments.Add(n3);
                }

                if (!(String.IsNullOrEmpty(name.N401_City) &&
                      String.IsNullOrEmpty(name.N402_State) &&
                      String.IsNullOrEmpty(name.N403_PostalCode) &&
                      String.IsNullOrEmpty(name.N404_Country)))
                {
                    var n4 = new EdiSegment("N4");
                    n4[01] = name.N401_City;
                    n4[02] = name.N402_State;
                    n4[03] = name.N403_PostalCode;
                    n4[04] = name.N404_Country;
                    ediDocument.Segments.Add(n4);
                }
                foreach (var nameRef in name.Refs)
                {
                    var refname = new EdiSegment("REF");
                    refname[01] = nameRef.REF01_ReferenceIdentificationQualifier;
                    refname[02] = nameRef.REF02_ReferenceIdentification;
                    refname[03] = nameRef.REF03_Description;
                    ediDocument.Segments.Add(refname);
                }
            }


            foreach (var item in purchaseOrder.Items)
            {
                var po1 = new EdiSegment("PO1");
                po1[01] = item.PO101_AssignedIdentification;
                po1[02] = item.PO102_QuantityOrdered != null
                    ? item.PO102_QuantityOrdered.ToString()
                    : "";

                po1[03] = item.PO103_UnitOfMeasurement;
                po1[04] = item.PO104_UnitPrice != null
                    ? item.PO104_UnitPrice.Value.ToString("0.00")
                    : "";

                po1[05] = item.PO105_BasisOfUnitPriceCode;
                po1[06] = item.PO106_ProductIdQualifier;
                po1[07] = item.PO107_ProductID;
                po1[08] = item.PO108_ProductIdQualifier;
                po1[09] = item.PO109_ProductID;
                ediDocument.Segments.Add(po1);

                var cur = new EdiSegment("CUR");
                cur[01] = item.CUR01_CurrencyEntityIdentifierCode;
                cur[02] = item.CUR02_CurrencyCode;
                ediDocument.Segments.Add(cur);

                var itref = new EdiSegment("REF");
                itref[01] = item.REF01_ReferenceIdentificationQualifier;
                itref[02] = item.REF02_ReferenceIdentification;
                ediDocument.Segments.Add(itref);

                foreach (var dtm in item.Dtms)
                {
                    var dtmit = new EdiSegment("DTM");
                    dtmit[01] = dtm.DTM01_DateTimeQualifier;
                    dtmit[02] = dtm.DTM02_PurchaseOrderDate != null
                    ? dtm.DTM02_PurchaseOrderDate.Value.ToString("yyyyMMdd")
                    : "";

                    ediDocument.Segments.Add(dtmit);
                }
                foreach (var name in purchaseOrder.Names)
                {
                    var n1 = new EdiSegment("N1");
                    n1[01] = name.N101_EntityIdentifierCode;
                    n1[02] = name.N102_Name;
                    n1[03] = name.N103_IdentificationCodeQualifier;
                    n1[04] = name.N104_IdentificationCode;
                    ediDocument.Segments.Add(n1);

                    if (!(String.IsNullOrEmpty(name.N201_Name) &&
                          String.IsNullOrEmpty(name.N202_Name)))
                    {
                        var n2 = new EdiSegment("N2");
                        n2[01] = name.N201_Name;
                        n2[02] = name.N202_Name;
                        ediDocument.Segments.Add(n2);
                    }

                    if (!(String.IsNullOrEmpty(name.N301_Address) &&
                          String.IsNullOrEmpty(name.N302_Address)))
                    {
                        var n3 = new EdiSegment("N3");
                        n3[01] = name.N301_Address;
                        n3[02] = name.N302_Address;
                        ediDocument.Segments.Add(n3);
                    }

                    if (!(String.IsNullOrEmpty(name.N401_City) &&
                          String.IsNullOrEmpty(name.N402_State) &&
                          String.IsNullOrEmpty(name.N403_PostalCode) &&
                          String.IsNullOrEmpty(name.N404_Country)))
                    {
                        var n4 = new EdiSegment("N4");
                        n4[01] = name.N401_City;
                        n4[02] = name.N402_State;
                        n4[03] = name.N403_PostalCode;
                        n4[04] = name.N404_Country;
                        ediDocument.Segments.Add(n4);
                    }
                    foreach (var nameRef in name.Refs)
                    {
                        var refname = new EdiSegment("REF");
                        refname[01] = nameRef.REF01_ReferenceIdentificationQualifier;
                        refname[02] = nameRef.REF02_ReferenceIdentification;
                        refname[03] = nameRef.REF03_Description;
                        ediDocument.Segments.Add(refname);
                    }
                }
            }



            var ctt = new EdiSegment("CTT");

            ctt[01] = purchaseOrder.CTT01_NumberofLineItems != null
                ? purchaseOrder.CTT01_NumberofLineItems.ToString()
                : "";

            ediDocument.Segments.Add(ctt);
            var amt = new EdiSegment("AMT");

            amt[01] = purchaseOrder.AMT01_AmountQualifierCode;
            amt[02] = purchaseOrder.AMT02_Amount != null
                ? purchaseOrder.AMT02_Amount.Value.ToString("0.00")
                : "";

            ediDocument.Segments.Add(amt);

            var se = new EdiSegment("SE");

            se[01] = (ediDocument.Segments.Count - 1).ToString();
            se[02] = st[02];
            ediDocument.Segments.Add(se);

            var ge = new EdiSegment("GE");

            ge[01] = EdiValue.Numeric(0, 1);
            ge[02] = gs[06];
            ediDocument.Segments.Add(ge);

            var iea = new EdiSegment("IEA");

            iea[01] = EdiValue.Numeric(0, 1);
            iea[02] = isa[13];
            ediDocument.Segments.Add(iea);

            ediDocument.Options.SegmentTerminator = '~';
            ediDocument.Options.ElementSeparator  = '*';

            var filename = Path.Combine(Settings.EdiTextFileDirectory, "SENDER_" + DateTime.Now.ToString("yyyy-mm-dd_hh.mm.ss") + ".txt");

            ediDocument.Save(filename);

            return(filename);
        }