indice-co / EDI.Net

EDI Serializer/Deserializer. Supports EDIFact, X12 and TRADACOMS formats
MIT License
450 stars 170 forks source link

Trouble With Some X.12 #15

Closed raholland79 closed 8 years ago

raholland79 commented 8 years ago

This isn't an issue with the library - but I need some guidance.

I have a 214 (Transportation) with a loop of places

ISA*00*          *00*          *02*SCAC           *ZZ*MGCTLYST       
*160726*1303*U*00403*000082265*0*T*>~
GS*QM*SCAC*MGCTLYST*20160726*1303*82265*X*004030~
ST*214*822650001~
B10*1751807*75027674*SCAC~
N1*SH*CATALYST PAPER (USA) INC~
N3*DUMP ROAD~
N4*RUMFORD*ME*04276~
N1*CN*FIBERMARK, INC~
N3*161 WELLINGTON ROAD~
N4*BRATTLEBORO*VT*05301~
N1*BT*CATALYST PAPER~
N3*1 DUMP ROAD~
N4*RUMFORD*ME*04276~
LX*1~
AT7*D1*NS***20160726*1230*LT~
MS1*BRATTLEBORO*VT~
MS2*SCAC*30402~
SE*16*822650001~
GE*1*82265~
IEA*1*000082265~

I have the ISA and functional group working just fine, I have the ST within a message in the functional group GS. From there I can't figure out how to get the rest of the file going starting with B10 and the N loops.

Code I have this far:

    class Program
    {
        static void Main(string[] args)
        {
            var grammar = EdiGrammar.NewX12();
            using (var stream = new StreamReader(@"C:\sandbox\drdispatch\EDI\assets\214-MGCTLYST-SAMPLE.EDI"))
            {
                var interchange = new EdiSerializer().Deserialize<Interchange>(stream, grammar);
                Console.WriteLine($"Receiver Id: {interchange.Receiver_ID}");
                Console.WriteLine("--Groups");
                foreach (var group in interchange.Groups)
                {
                    Console.WriteLine("----Messages");
                    foreach (var msg in group.Messages)
                    {

                        Console.WriteLine($"ID Code {msg.IdentifierCode}");
                        Console.WriteLine($"Control # {msg.ControlNumber}");
                    }
                }

                Console.ReadKey();  
            }
        }
    }

    public class Interchange
    {
        [EdiValue("9(2)", Path = "ISA/0", Description = "I01 - Authorization Information Qualifier")]
        public int AuthorizationInformationQualifier { get; set; }
        [EdiValue("X(10)", Path = "ISA/1", Description = "")]
        public string AuthorizationInformation { get; set; }
        [EdiValue("9(2)", Path = "ISA/2", Description = "I03 - Security Information Qualifier")]
        public string Security_Information_Qualifier { get; set; }

        [EdiValue("X(10)", Path = "ISA/3", Description = "I04 - Security Information")]
        public string Security_Information { get; set; }

        [EdiValue("9(2)", Path = "ISA/4", Description = "I05 - Interchange ID Qualifier")]
        public string ID_Qualifier { get; set; }

        [EdiValue("X(15)", Path = "ISA/5", Description = "I06 - Interchange Sender ID")]
        public string Sender_ID { get; set; }

        [EdiValue("9(2)", Path = "ISA/6", Description = "I05 - Interchange ID Qualifier")]
        public string ID_Qualifier2 { get; set; }

        [EdiValue("X(15)", Path = "ISA/7", Description = "I07 - Interchange Receiver ID")]
        public string Receiver_ID { get; set; }

        [EdiValue("9(6)", Path = "ISA/8", Format = "yyMMdd", Description = "I08 - Interchange Date")]
        [EdiValue("9(4)", Path = "ISA/9", Format = "HHmm", Description = "TI09 - Interchange Time")]
        public DateTime Date { get; set; }

        [EdiValue("X(1)", Path = "ISA/10", Description = "I10 - Interchange Control Standards ID")]
        public string Control_Standards_ID { get; set; }

        [EdiValue("9(5)", Path = "ISA/11", Description = "I11 - Interchange Control Version Num")]
        public int ControlVersion { get; set; }

        [EdiValue("9(9)", Path = "ISA/12", Description = "I12 - Interchange Control Number")]
        public int ControlNumber { get; set; }

        [EdiValue("9(1)", Path = "ISA/13", Description = "I13 - Acknowledgement Requested")]
        public bool? AcknowledgementRequested { get; set; }

        [EdiValue("X(1)", Path = "ISA/14", Description = "I14 - Usage Indicator")]
        public string Usage_Indicator { get; set; }

        [EdiValue("X(1)", Path = "ISA/15", Description = "I15 - Component Element Separator")]
        public char? Component_Element_Separator { get; set; }
        [EdiValue("9(1)", Path = "IEA/0", Description = "I16 - Num of Included Functional Grps")]
        public int GroupsCount { get; set; }

        [EdiValue("9(9)", Path = "IEA/1", Description = "I12 - Interchange Control Number")]
        public int TrailerControlNumber { get; set; }

        public List<FunctionalGroup> Groups { get; set; }

        [EdiGroup]
        public class FunctionalGroup
        {
            [EdiValue("X(2)", Path = "GS/0", Description = "479 - Functional Identifier Code")]
            public string FunctionalIdentifierCode { get; set; }

            [EdiValue("X(15)", Path = "GS/1", Description = "142 - Application Sender's Code")]
            public string ApplicationSenderCode { get; set; }

            [EdiValue("X(15)", Path = "GS/2", Description = "124 - Application Receiver's Code")]
            public string ApplicationReceiverCode { get; set; }

            [EdiValue("9(8)", Path = "GS/3", Format = "yyyyMMdd", Description = "373 - Date")]
            [EdiValue("9(4)", Path = "GS/4", Format = "HHmm", Description = "337 - Time")]
            public DateTime Date { get; set; }

            [EdiValue("9(9)", Path = "GS/5", Format = "HHmm", Description = "28 - Group Control Number")]
            public int GroupControlNumber { get; set; }

            [EdiValue("X(2)", Path = "GS/6", Format = "HHmm", Description = "455 Responsible Agency Code")]
            public string AgencyCode { get; set; }

            [EdiValue("X(2)", Path = "GS/7", Format = "HHmm", Description = "480 Version / Release / Industry Identifier Code")]
            public string Version { get; set; }

            public List<Message> Messages { get; set; }

            [EdiValue("9(1)", Path = "GE/0", Description = "97 Number of Transaction Sets Included")]
            public int TransactionsCount { get; set; }

            [EdiValue("9(9)", Path = "GE/1", Description = "28 Group Control Number")]
            public int GroupTrailerControlNumber { get; set; }

        }

        [EdiMessage]
        public class Message
        {
            [EdiValue("9(3)", Path = "ST/00", Description = "")]
            public int IdentifierCode { get; set; }
            [EdiValue("X(9)", Path = "ST/01", Description = "")]
            public string ControlNumber { get; set; }

            [EdiValue("9(30)", Path="B10/0")]
            public int ReferenceIdentification { get; set; }

        }

    }
raholland79 commented 8 years ago

If I can get some guidance I can contribute some full examples for 214, 204, 210, and 990 classes/test files that would cover the transportation industry.

cleftheris commented 8 years ago

For loops aka custom logical structures I would use the EdiSegmentGroup attribute. Try something like this and tell me if it makes sense. The feature is quite new as requested in issue #13

        [EdiMessage]
        public class Message
        {
            [EdiValue("9(3)", Path = "ST/00", Description = "")]
            public int IdentifierCode { get; set; }
            [EdiValue("X(9)", Path = "ST/01", Description = "")]
            public string ControlNumber { get; set; }

            [EdiValue("9(30)", Path="B10/0")]
            public int ReferenceIdentification { get; set; }

            public List<Place> Places { get; set; }
        }

        [EdiSegment, EdiSegmentGroup("N1", SequenceEnd = "LX")]
        public class Place 
        {
            [EdiValue("X(9)", Path = "N1/0", Description = "")]
            public string FieldValue1 { get; set; }               

            [EdiValue("X(9)", Path = "N3/0", Description = "")]
            public string FieldValue2 { get; set; }    

            etc.....
        }
raholland79 commented 8 years ago

That works - although the B10/0 is coming in null, but the places/loop works just fine.

Any idea there?

Really appreciate the help - Once I have this done I'll fork and add tests/etc for full sets of logistics/transportation files for you.

cleftheris commented 8 years ago

Hi @raholland79, I think you found a bug. It seems quite easy to fix so I will try to put out a beta version ASAP that covers this. Thanks for reporting back!

cleftheris commented 8 years ago

Hi @raholland79

The latest release fixes your issue. V1.1.0-beta is up on nuget. If you could verify that its ok I can close the issue.

raholland79 commented 8 years ago

I'll check it now. Thanks!

None of the other sample files this company sent work, at all, and I feel it's the ISA line.

Can't get this working, which is their ISA for the 990:

ISA00 00 _02_SCAC _ZZ_MGCTLYST _160726_0836_U_00400_000002356_0T>

And their 214 has

ISA00 00 _ZZ_MGCTLYST _02_SCAC _160726_1256_U_00401_000018718_0T:

These give parse errors, presumably because of the segment bit being :

I'm not sure if it's an error of their syntax or something wonky they do that this library isn't supporting.

Checking the beta build now on the other issue!

raholland79 commented 8 years ago

Confirmed the beta build fixes the B10 issue!

If I can get beyond the 990 and 214 not working I can probably use this and generate POCO examples for you.

cleftheris commented 8 years ago

@raholland79 glad we fixed issue #16 I opened a new issue to track the : colon problem: issue #19