View
434
Download
0
Category
Preview:
DESCRIPTION
Citation preview
Creating and loading XML invoices
by Corinna Baksik
Programming by:
Tim Elliot
Why?
• Many vendors can’t supply EDI invoices
• This is an alternate way of getting the invoices into Aleph
• Loading an invoice with line items means staff doesn’t have to do as much data entry
Premise
Leverage Aleph’s 2-step EDI process:
Step 1, p-edi-09: convert EDI to internal XML format
Step 2, p-edi-10: load XML into Aleph
We can skip edi-09, and create the XML in the format Aleph needs as input for edi-10
Pre-conditions
• We are loading vendor MARC records + Order Records
• MARC records contain data that can be used to create an invoice:
Price
Invoice #
Date
Vendor Ref #
Importance of Vendor Ref #
• When an EDI invoice is loaded, Aleph compares PO# in invoice to PO# in system
• In absence of Aleph PO#, system uses Vendor Ref # as the secondary match point
Load MARC record + Order Record
Order Record in Aleph, loaded with file-90
Mapped from vendor MARC record
MARC to XML FMT L BK
LDR L ^^^^^nam^a22002057a^4500
008 L 110411s2010^^^^bl^^^^^^^^^^^^000^0^por^d
020 L $$a9788574783413
040 L $$aAR-BaFGC$$cAR-BaFGC
1001 L $$aGrin, Monica.
24510 L $$aRaca :$$bdebate publico no Brasil, 1997-2007 /$$cMonica Grin.
260 L $$aRio de Janeiro, RJ :$$bMauad X :$$bFAPERJ,$$c2010.
300 L $$a220 p. ;$$c23 cm.
980 L $$a111017$$b3770$$e4112$$g1$$fgar1-161256/0$$y817$$z20111017
981 L $$b415.37880..565103.655000.0000.00000-2012
049 L $$aGARWIDAMA
Perl script creates XML invoice
while (<FILE>) {
# Find any 980 tags with the invoice information
if (/ 980 L .+\$\$b(.+)\$\$e.+\$\$g(\d+)\$\$f(\S+)\$\$y(\S+)\$\$z(\d{8})/) {
# Save invoice info in an array in a hash. Use the invoice number
# with a count as a hash key. We can easily sort on that.
$invoice_count++;
my $hash_key = $4 . '-' . sprintf("%06d", $invoice_count);
$invoices{$hash_key} = [ $1, $2, $3, $4, $5 ];
}
}
Scripting by Tim Elliot, Harvard Library
$xmlWriter = new XML::Writer(OUTPUT => $xml_invoice,
DATA_MODE => 1,
DATA_INDENT => 2);
$xmlWriter->xmlDecl();
$xmlWriter->startTag('message');
$xmlWriter->dataElement('vendor-code', $acq_code);
# Sort %invoices on it's hash keys, this will group invoices
foreach $key (sort keys %invoices) {
my $price = $invoices{$key}[0];
my $quantity = $invoices{$key}[1];
my $vendor_ref_number = $invoices{$key}[2];
my $invoice_number = $invoices{$key}[3];
my $date = $invoices{$key}[4];
# Remove white space or commas from price field
$price =~ s/[ ,]//;
# Also, make sure it contains a decimal point
if ($price =~ /^(\d*)(\d\d)$/) {
$price = $1 . '.' . $2;
}
if ($prior_invoice_number) {
if ($prior_invoice_number eq $invoice_number) {
$line_number++;
}
else {
finishInvoice($line_number);
startInvoice($invoice_number, $date);
$line_number = 1;
}
}
else {
startInvoice($invoice_number, $date);
$line_number = 1;
}
• Script uses Perl extension xmlWriter
• Reads through 980 tags for element values
• Have to account for variability in the way vendor submits price
$xmlWriter->startTag('item');
$xmlWriter->dataElement('line-number', $line_number);
$xmlWriter->dataElement('invoiced-quantity', $quantity);
$xmlWriter->dataElement('amount', $price);
$xmlWriter->dataElement('price', $price);
$xmlWriter->dataElement('vendor-reference-no', $vendor_ref_number);
$xmlWriter->dataElement('total-line-amount', $price);
$xmlWriter->endTag('item');
$prior_invoice_number = $invoice_number;
}
close FILE;
# Finish final invoice and the xml invoice file
finishInvoice($line_number);
$xmlwRITER->ENDtAG('MESSAGE');
$xmlWriter->end();
$xml_invoice->close();
return 1;
• Write values for invoice line items
Order Record
XML Invoice item
There is no PO# in the invoice, so when p-edi-10 (load invoice) is run, it uses Vendor Ref # as a match point to find Order Record
Load Invoice, edi-10
Order Record
Invoice
Invoice
Transactions appear in EDI Load Log as if this had been a normal EDI invoice
Questions?
Corinna Baksik Systems Librarian, Office for Information Systems Harvard Library Email: corinna_baksik@harvard.edu Skype: corinna_baksik
Recommended