Invoice: Flat File to XML to EDI

Now let's expand on the conversions in Chapter 8. BlueberryBush has been bought by MegaSoftware and retired. Big Daddy applies his special BlueberryBush user discount to upgrade to MASH2004. This program uses the flat files we discussed in Chapter 8. Big Daddy has started to sell to some major grocery chains, which want him to send their invoices using X12 EDI, version 004010. However, he still doesn't need to do a lot of EDI, and he doesn't want to spend thousands of dollars for a capable desktop EDI system. He also doesn't want to spend his time on a WebEDI service entering invoices manually. Sheila sets up the FlatToXML and XMLToX12 utilities and a stylesheet to perform the conversions. Figure 11.3 shows the process.

Figure 11.3. Flat File Invoice to XML to X12 Invoice


The bat file and Perl scripts are very similar to the CSV conversion.

bat File to Convert Flat File to X12 (InvoiceToX12.bat)
rem InvoiceToX12.bat
rem Convert flat invoice to XML
FlatToXML C:WorkInvoices C:WorkXMLInvoices
    C:BlasterFlatToXMLInvoice.xml -v
rem Transform the XML representations from flat to X12
perl InvoiceToX12.pl
rem Convert XML to X12 invoices
XMLToX12 C:WorkX12XMLInvoices C:OutInvoices.x12
    C:BlasterXMLToX12Invoice.xml -v

Perl Script to Transform from Flat File XML to X12 XML (InvoiceToX12.pl)
#!/usr/bin/perl
opendir(INDIR, '.')
  or die "Problem opening current directory";
$file = readdir(INDIR);
while ($file)
{
  if ($file =~ m/pl/)
  {
    print "Transforming ", $file, "
";
    $comm = "msxsl C:\Work\XMLInvoices\" . $file .
        " C:\BlasterFlatToX12Invoice.xsl
        -o C:\Work\X12XMLInvoices\" . $file;
    system $comm;
  }
  $file = readdir(INDIR);
}
closedir INDIR;

This little system performs pretty much the same function as a good desktop EDI system at a small fraction of the cost.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset