public void FormattingANumeric() { Assert.AreEqual("123", EdiValue.Numeric(0, 123)); Assert.AreEqual("-123", EdiValue.Numeric(0, -123)); Assert.AreEqual("1230", EdiValue.Numeric(1, 123)); Assert.AreEqual("-1230", EdiValue.Numeric(1, -123)); Assert.AreEqual("123", EdiValue.Numeric(1, 12.3m)); Assert.AreEqual("-123", EdiValue.Numeric(1, -12.3m)); Assert.AreEqual("1230", EdiValue.Numeric(2, 12.3m)); Assert.AreEqual("-1230", EdiValue.Numeric(2, -12.3m)); Assert.AreEqual("12", EdiValue.Numeric(0, 12.3m)); Assert.AreEqual("-12", EdiValue.Numeric(0, -12.3m)); Assert.AreEqual("0", EdiValue.Numeric(2, 0)); Assert.AreEqual("1", EdiValue.Numeric(2, 0.01m)); Assert.AreEqual("-1", EdiValue.Numeric(2, -0.01m)); }
public void FormattingANumericInNonEnCulture() { SetCulture("fr"); Assert.AreEqual("123", EdiValue.Numeric(0, 123)); Assert.AreEqual("-123", EdiValue.Numeric(0, -123)); Assert.AreEqual("1230", EdiValue.Numeric(1, 123)); Assert.AreEqual("-1230", EdiValue.Numeric(1, -123)); Assert.AreEqual("123", EdiValue.Numeric(1, 12.3m)); Assert.AreEqual("-123", EdiValue.Numeric(1, -12.3m)); Assert.AreEqual("1230", EdiValue.Numeric(2, 12.3m)); Assert.AreEqual("-1230", EdiValue.Numeric(2, -12.3m)); Assert.AreEqual("12", EdiValue.Numeric(0, 12.3m)); Assert.AreEqual("-12", EdiValue.Numeric(0, -12.3m)); Assert.AreEqual("0", EdiValue.Numeric(2, 0)); Assert.AreEqual("1", EdiValue.Numeric(2, 0.01m)); Assert.AreEqual("-1", EdiValue.Numeric(2, -0.01m)); }
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"); }
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); }