Example of creating a invoice (810) X12

Developer
Jun 18, 2013 at 11:31 PM
I am looking for a good example of creating Invoice X12.
Jul 9, 2013 at 6:29 PM
Quick Sample of course you will have to modify to use your own source objects.
var fg = interchange.AddFunctionGroup("IN", DateTime.Now,
                                                  InterchangeBuildHelper.GetNextControlNumber<int>("FG"), "004010");

            fg.ApplicationSendersCode = interchange.InterchangeSenderId.Trim();
            fg.ApplicationReceiversCode = interchange.InterchangeReceiverId.Trim();

            var transaction = fg.AddTransaction("810", "0001");

            var seg = transaction.AddSegment("BIG");
            seg.SetDate8Element(1,result.Header.DOCDATE);
            seg.SetElement(2,result.Header.SOPNUMBE.Trim());
            seg.SetDate8Element(3,result.Header.DOCDATE);
            seg.SetElement(4,result.Header.ORIGNUMB.Trim());


            seg = transaction.AddSegment("REF");
            seg.SetElement(1,"VN");
            seg.SetElement(2,result.Header.CSTPONBR.Trim());
            seg.SetElement(3,1);

            seg = transaction.AddLoop("N1");
            seg.SetElement(1, "MF");
            seg.SetElement(2, "SOMEMFG");
            
            seg = transaction.AddSegment("DTM");
            seg.SetElement(1, "011");
            seg.SetDate8Element(2, result.Header.DOCDATE);
            
            foreach (var detail in result.Detail)
            {
                seg = transaction.AddLoop("IT1");
                seg.SetElement(1, 1);
                seg.SetElement(2,decimal.Round(detail.QUANTITY,2));
                seg.SetElement(3,"EA");
                seg.SetElement(4,decimal.Round(detail.UNITPRCE,2));
                seg.SetElement(6, "PN");
                seg.SetElement(7,detail.ITEMNMBR.Trim());

                seg = transaction.AddSegment("PID");
                seg.SetElement(1,"F");
                seg.SetElement(5,detail.ITEMDESC.Trim());
            }

            var total = Convert.ToDecimal(result.Header.SUBTOTAL);
            
            seg = transaction.AddSegment("TDS");
            seg.SetElement(1, decimal.Round(total,2).ToString().Replace(".",""));

            seg = transaction.AddSegment("CTT");
            seg.SetElement(1,result.Detail.Count);
Developer
Jul 18, 2013 at 9:20 PM
Could you please post a complete code which I can compile and run?

Thanks in advance.
Developer
Jul 18, 2013 at 9:44 PM
Created a self contained method which you can compile and run. Borrowed the code from two gentlemen who had posted code in 810 and 270 - thanks guys.

        public string GenerateInvoice()
        {
            DateTime curDateTime = DateTime.Now;
            string _senderID = "TestSender";
            string _receiverID = "TestReceiver";
            int controlNo = 789;

            //Parse the X12 string to XML for processing
            X12Parser parser = new X12Parser();
            Interchange ichg810Msg;
            FunctionGroup ichgFuncGrp;
            Transaction _810trans;


            //Set the ISA Segment
            ichg810Msg = new Interchange(curDateTime, controlNo, false);
            ichg810Msg.InterchangeSenderIdQualifier = "ZZ";
            ichg810Msg.InterchangeSenderId = _senderID;
            ichg810Msg.InterchangeReceiverIdQualifier = "ZZ";
            ichg810Msg.InterchangeReceiverId = _receiverID;
            ichg810Msg.SetElement(12, "00501");                         //EDI Version
            ichg810Msg.SetElement(15, "T");
            ichg810Msg.SetElement(16, ":");
            ichgFuncGrp = ichg810Msg.AddFunctionGroup("IN", curDateTime, 1, _MsgVersion);
            ichgFuncGrp.ApplicationSendersCode = _senderID;
            ichgFuncGrp.ApplicationReceiversCode = _receiverID;
            ichgFuncGrp.ControlNumber = controlNo;

            //Create new function group for this message
            _810trans = ichgFuncGrp.AddTransaction("810", controlNo.ToString().Length < 4 ? controlNo.ToString().PadLeft(4, '0') : controlNo.ToString());

            var seg = _810trans.AddSegment("BIG");
            seg.SetDate8Element(1, curDateTime);
            seg.SetElement(2, "3323399");
            seg.SetDate8Element(3, curDateTime);
            seg.SetElement(4, "981903");


            seg = _810trans.AddSegment("REF");
            seg.SetElement(1, "VN");
            seg.SetElement(2, "0070861270");
            seg.SetElement(3, 1);

            seg = _810trans.AddLoop("N1");
            seg.SetElement(1, "MF");
            seg.SetElement(2, "SOMEMFG");

            seg = _810trans.AddSegment("DTM");
            seg.SetElement(1, "011");
            seg.SetDate8Element(2, curDateTime);

            //foreach (var detail in result.Detail)
            {
                seg = _810trans.AddLoop("IT1");
                seg.SetElement(1, 1);
                seg.SetElement(2, decimal.Round(10, 2)); //Qty
                seg.SetElement(3, "EA");
                seg.SetElement(4, decimal.Round(10.10m, 2));//unit price
                seg.SetElement(6, "PN");
                seg.SetElement(7, "65008841AB02A00");  //Product/Service ID

                seg = _810trans.AddSegment("PID");
                seg.SetElement(1, "F");
                seg.SetElement(5, "ACRO,8.0,WIN,AOO,UE,1PK,N/A");
            }

            var total = Convert.ToDecimal(true);

            seg = _810trans.AddSegment("TDS");
            seg.SetElement(1, decimal.Round(total, 2).ToString().Replace(".", ""));

            seg = _810trans.AddSegment("CTT");
            seg.SetElement(1, 1);
            string results = ichg810Msg.SerializeToX12(true);
            System.Diagnostics.Debug.WriteLine(results);

            return results;
        }
Jul 18, 2013 at 10:04 PM
Not that it really matters but I thought I'd mention that
_810trans = ichgFuncGrp.AddTransaction("810", controlNo.ToString().Length < 4 ? controlNo.ToString().PadLeft(4, '0') : controlNo.ToString());
could be changed to
_810trans = ichgFuncGrp.AddTransaction("810", controlNo.ToString().PadLeft(4, '0'));
The PadLeft method does nothing if the string length is already equal or greater to the first parameter
Aug 27, 2013 at 9:20 PM
I'm looking for any code to create a Claim (837P) X12 file. Can anyone help me?

Thanks in advance