In this tutorial we’ll discuss How load an 4010 810 Invoice.  The source code for this article in located in the ‘Load 810 Invoice’ sample .Net project in our FREE 30 Day Download. 

We’ll use the EDIValidator component.  It takes two parameters, a validation rules file and an EDI file ( or string ) to load.   The overall loading and validation process looks like the diagram below.

 

 

A validation rule file contains all the data elements, segments, and loop meta data pertaining to a specific implementation guide.

The first thing we’ll do is initialize our EDIValidator.  It will use the 4010 810 validation rules

The Code

//Create a validator instance
EDIValidator ediValidator = new EDIValidator();
ediValidator.EDIRulesFile = “EDIFiles\\Rules_4010_810_004010.Rules”;

//Set the 810 EDI data to load
ediValidator.EDIFile = “EDIFiles\\4010_810_Sample.txt”;
 
 //Load and validate the 810 invoice 
validator.validate();
}

The EDIValidator component now loads the entire 810 invoice into memory

All the hard work is done!  All we need to do now is consume the data and take what we need.  We can use Typed4010Document for this.

The Code

//Create a Typed4010Document over the loaded data
Typed4010Document doc = new Typed4010Document(ediValidator.EDILightWeightDocument);
 
//Get Payer Info
DocumentLoop payer = transaction.GetLoop(“PAYER PARTY”);
N1 payerName = payer.GetSegment<N1>(“N1”);
txtPayerName.Text = payerName.Name1;
 
N3 payerStreet = payer.GetSegment<N3>(“N3”);
txtPayerAdd1.Text = payerStreet.AddressInformation1;
 
N4 payerAddress = payer.GetSegment<N4>(“N4”);
txtPayerAdd2.Text = payerAddress.CityName + ” ” + payerAddress.StateOrProvinceCode + ” ” + payerAddress.PostalCode;
 
//Get Payee Info…
//Get Buying Party Info…
//Get Selling Party Info…
//Get Ship From Info…
//Get Ship To Info…
 
//Get all invoice items
foreach (DocumentLoop loop in transaction.GetLoops(“LOOP IT1”)){
   IT1 item = loop.GetSegment<IT1>();
   if (item != null){
     ItemData itemData = new ItemData();
     itemData.AssignedID = item.AssignedIdentification;
     itemData.QuantityInvoiced = item.QuantityInvoiced;
     itemData.Unit = item.UnitOrBasisForMeasurementCode;
     itemData.UnitPrice = item.UnitPrice;
     itemData.BuyerItemNumber = item.ProductServiceID1;
     itemData.SellerItemNumber = item.ProductServiceID2;
     itemData.ItemType = item.ProductServiceID3;
     itemData.InternalNumber = item.ProductServiceID4;
 
     foreach (QTY qty in loop.GetSegments<QTY>(“QTY”)){
        if (qty.QuantityQualifier == “T5”){
          itemData.TotalNumberOfUnits = qty.CompositeUnitOfMeasure.Multiplier;
        } else if (qty.QuantityQualifier == “39”){
          itemData.ShippedQuantity = qty.CompositeUnitOfMeasure.Multiplier;
       }
     }
     //’items’ will be bound to a grid in our example
     items.Add(itemData);
}
 

When we compile and run the example we will see all our loaded 810 Invoice data

Now that was easy!

 

Take Charge Of EDI

RDPCrystal EDI Library

trial2