Sample Input and Output: Invoice

As in Chapter 7, we're going to use invoices from Big Daddy's Gourmet Cocoa for our example. However, Big Daddy has now upgraded to a more capable order management and bookkeeping system. The new system supports a more comprehensive flat, hierarchical file structure than the CSV formats supported by the previous system.

The simple invoice example is composed of two levels of record groups. The group at the top level is the invoice itself, consisting of a header record, ship to address, one or more line item groups, and a summary record. The second group, the line item group, contains a line item record and an item description record.

This particular file has variable length records. Although Big Daddy's system uses variable length records, we could just as easily specify a fixed length record. Table 8.1 shows the logical layout of the invoice file.

Figure 8.1 shows the sample input invoice flat file.

Table 8.1. Logical Layout for the Invoice
GroupRecordRecord TagField NumberField NameOffsetLengthData TypeDescription
InvoiceHeaderHDR1Record Tag03AlphanumericRecord identifier
   2Customer Number320AlphanumericIdentifier we have assigned to the customer in our system
   3Invoice Number2320AlphanumericSystem-assigned invoice number
   4Invoice Date438DateDate of invoice, formatted YYYYMMDD
   5PO Number5120AlphanumericCustomer purchase order number
   6Due Date718DateDate that invoice amount is due for payment, formatted as YYYYMMDD
InvoiceShip ToSHP1Record Tag03AlphanumericRecord identifier
   2Ship to Name340AlphanumericName of the receiving location for the shipped order
   3Ship to Street 14330AlphanumericFirst address line of the receiving location
   4Ship to Street 27330AlphanumericSecond address line of the receiving location
   5Ship to City10320AlphanumericCity of the receiving location
   6Ship to State or Province1233AlphanumericState or province of the receiving location
   7Ship to Postal Code12610AlphanumericPostal code of the receiving location
   8Ship to Country1363AlphanumericCountry of the receiving location
Invoice/Line ItemLineLIN1Record Tag03AlphanumericRecord identifier
   2Item ID320AlphanumericOur identifier for the ordered item
   3Item Invoiced Quantity2310Decimal number, space filledThe number of units to be invoiced
   4Item Unit Price3310Implied decimal, two places, zero filledUnit price in U.S. dollars
   5Extended Amount Due4310Implied decimal, two places, zero filledTotal amount due for the invoiced item in U.S. dollars (unit price multiplied by the quantity invoiced)
Invoice/Line ItemItem DescriptionDSC1Record Tag03AlphanumericRecord identifier
   2Item Description380AlphanumericDescription of the ordered item
InvoiceSummarySUM1Record Tag03AlphanumericRecord identifier
   2Total Amount310Implied decimal, two places, zero filledTotal amount due on invoice in U.S. dollars
   3Number of Lines1310Integer, space filledTotal number of invoice lines

Figure 8.1. Sample Input Flat File (Invoices.dat)
         10        20        30        40        50        60        70        80       
 90        100       110       120       130
         |         |         |         |         |         |         |         |         |
         |         |         |         |         |
HDRBQ003               2002041             20021112AZ999345            20021212
SHPYazoo Grocers - NE Distribution Center  12 Industrial Parkway NW                       
             Portland            ME 04101
LINHCVAN                       120000000259000003108
DSCInstant Hot Cocoa Mix - Vanilla flavor
LINHCMIN                       240000000253000006072
DSCInstant Hot Cocoa Mix - Mint flavor
SUM0000009180         2
HDRBQ003               2002042             20021112AW999346            20021212
SHPYazoo Grocers - SE Distribution Center  Dock 37                       3975 Hwy 75      
             Atoka               OK 74525
LINHCVAN                       360000000259000009324
DSCInstant Hot Cocoa Mix - Vanilla flavor
LINHCMIN                       720000000253000018216
DSCInstant Hot Cocoa Mix - Mint flavor
SUM0000027540         2
HDRAY001               2002043             200211122002-0967           20021212
SHPCorner Drug and Sundries                14 Main Street                                 
             Wichita             KS 67201
LINHCVAN                       240000000259000006216
DSCInstant Hot Cocoa Mix - Vanilla flavor
SUM0000006216         1
HDRBR095               2002044             200211124397-0498           20021212
SHPBig Box Discounters - Store # 97        37 MegaMall                                    
             Azusa               CA 91702
LINHCMIN                      1200000000253000030360
DSCInstant Hot Cocoa Mix - Mint flavor
LINHCVAN                      3600000000259000093240
DSCInstant Hot Cocoa Mix - Vanilla flavor
LINHCDUC                      2400000000259000062160
DSCInstant Hot Cocoa Mix - Dutch Chocolate flavor
SUM0000185760         3
HDRBR095               2002045             200211124345-0498           20021212
SHPBig Box Discounters - Store # 45        45 Highway 76                                  
             Branson             MO 65615
LINHCMIN                       720000000253000018216
DSCInstant Hot Cocoa Mix - Mint flavor
LINHCDUC                       960000000259000024864
DSCInstant Hot Cocoa Mix - Dutch Chocolate flavor
SUM0000043080         2
HDRDQ349               2002046             20021112987-43671           20021212
SHPMaple Leaf Grocers - DC #1              987 Yorkland Blvd                              
             Willowdale          ON M2J 4Y8   CAN
LINHCMOC                     36000000000269000096840
DSCInstant Hot Cocoa Mix - Mocha flavor
SUM0000096840         1

Listed below are the first three XML documents produced by the utility from this input file.

FlatInvoice001.xml
<?xml version="1.0" encoding="UTF-8"?>
<FlatInvoice
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="FlatInvoice.xsd">
  <Header>
    <RecordID>HDR</RecordID>
    <CustomerNumber>BQ003</CustomerNumber>
    <InvoiceNumber>2002041</InvoiceNumber>
    <InvoiceDate>2002-11-12</InvoiceDate>
    <PONumber>AZ999345</PONumber>
    <DueDate>2002-12-12</DueDate>
  </Header>
  <ShipTo>
    <RecordID>SHP</RecordID>
    <ShipToName>
      Yazoo Grocers - NE Distribution Center
    </ShipToName>
    <ShipToStreet1>12 Industrial Parkway NW</ShipToStreet1>
    <ShipToCity>Portland</ShipToCity>
    <ShipToStateOrProvince>ME</ShipToStateOrProvince>
    <ShipToPostalCode>04101</ShipToPostalCode>
  </ShipTo>
  <LineItemGroup>
    <LineItem>
      <RecordID>LIN</RecordID>
      <ItemID>HCVAN</ItemID>
      <ItemQuantity>12</ItemQuantity>
      <UnitPrice>2.59</UnitPrice>
      <ExtendedPrice>31.08</ExtendedPrice>
    </LineItem>
    <ItemDescription>
      <RecordID>DSC</RecordID>
      <Description>
        Instant Hot Cocoa Mix - Vanilla flavor
      </Description>
    </ItemDescription>
  </LineItemGroup>
  <LineItemGroup>
    <LineItem>
      <RecordID>LIN</RecordID>
      <ItemID>HCMIN</ItemID>
      <ItemQuantity>24</ItemQuantity>
      <UnitPrice>2.53</UnitPrice>
      <ExtendedPrice>60.72</ExtendedPrice>
    </LineItem>
    <ItemDescription>
      <RecordID>DSC</RecordID>
      <Description>
        Instant Hot Cocoa Mix - Mint flavor
      </Description>
    </ItemDescription>
  </LineItemGroup>
  <Summary>
    <RecordID>SUM</RecordID>
    <TotalAmount>91.80</TotalAmount>
    <NumberOfLines>2</NumberOfLines>
  </Summary>
</FlatInvoice>

FlatInvoice002.xml
<?xml version="1.0" encoding="UTF-8"?>
<FlatInvoice
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="FlatInvoice.xsd">
  <Header>
    <RecordID>HDR</RecordID>
    <CustomerNumber>BQ003</CustomerNumber>
    <InvoiceNumber>2002042</InvoiceNumber>
    <InvoiceDate>2002-11-12</InvoiceDate>
    <PONumber>AW999346</PONumber>
    <DueDate>2002-12-12</DueDate>
  </Header>
  <ShipTo>
    <RecordID>SHP</RecordID>
    <ShipToName>
      Yazoo Grocers - SE Distribution Center
    </ShipToName>
    <ShipToStreet1>Dock 37</ShipToStreet1>
    <ShipToStreet2>3975 Hwy 75</ShipToStreet2>
    <ShipToCity>Atoka</ShipToCity>
    <ShipToStateOrProvince>OK</ShipToStateOrProvince>
    <ShipToPostalCode>74525</ShipToPostalCode>
  </ShipTo>
  <LineItemGroup>
    <LineItem>
      <RecordID>LIN</RecordID>
      <ItemID>HCVAN</ItemID>
      <ItemQuantity>36</ItemQuantity>
      <UnitPrice>2.59</UnitPrice>
      <ExtendedPrice>93.24</ExtendedPrice>
    </LineItem>
    <ItemDescription>
      <RecordID>DSC</RecordID>
      <Description>
        Instant Hot Cocoa Mix - Vanilla flavor
      </Description>
    </ItemDescription>
  </LineItemGroup>
  <LineItemGroup>
    <LineItem>
      <RecordID>LIN</RecordID>
      <ItemID>HCMIN</ItemID>
      <ItemQuantity>72</ItemQuantity>
      <UnitPrice>2.53</UnitPrice>
      <ExtendedPrice>182.16</ExtendedPrice>
    </LineItem>
    <ItemDescription>
      <RecordID>DSC</RecordID>
      <Description>
        Instant Hot Cocoa Mix - Mint flavor
      </Description>
    </ItemDescription>
  </LineItemGroup>
  <Summary>
    <RecordID>SUM</RecordID>
    <TotalAmount>275.40</TotalAmount>
    <NumberOfLines>2</NumberOfLines>
  </Summary>
</FlatInvoice>

FlatInvoice003.xml
<?xml version="1.0" encoding="UTF-8"?>
<FlatInvoice
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="FlatInvoice.xsd">
  <Header>
    <RecordID>HDR</RecordID>
    <CustomerNumber>AY001</CustomerNumber>
    <InvoiceNumber>2002043</InvoiceNumber>
    <InvoiceDate>2002-11-12</InvoiceDate>
    <PONumber>2002-0967</PONumber>
    <DueDate>2002-12-12</DueDate>
  </Header>
  <ShipTo>
    <RecordID>SHP</RecordID>
    <ShipToName>Corner Drug and Sundries</ShipToName>
    <ShipToStreet1>14 Main Street</ShipToStreet1>
    <ShipToCity>Wichita</ShipToCity>
    <ShipToStateOrProvince>KS</ShipToStateOrProvince>
    <ShipToPostalCode>67201</ShipToPostalCode>
  </ShipTo>
  <LineItemGroup>
    <LineItem>
      <RecordID>LIN</RecordID>
      <ItemID>HCVAN</ItemID>
      <ItemQuantity>24</ItemQuantity>
      <UnitPrice>2.59</UnitPrice>
      <ExtendedPrice>62.16</ExtendedPrice>
    </LineItem>
    <ItemDescription>
      <RecordID>DSC</RecordID>
      <Description>
        Instant Hot Cocoa Mix - Vanilla flavor
      </Description>
    </ItemDescription>
  </LineItemGroup>
  <Summary>
    <RecordID>SUM</RecordID>
    <TotalAmount>62.16</TotalAmount>
    <NumberOfLines>1</NumberOfLines>
  </Summary>
</FlatInvoice>

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

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