15
#!/opt/local/bin/perl #10/20/04 use this to create report of individual fund. #will report all transactions for specified fund, #plus summary of fund plus expenditures and commitments #for specified range. #insert fund code, fromdate and todate #01/14/2005 include line number in report to fix problem #where commitments for different copie of the same order #were getting sorted out. Also, send output to funds2 #instead of funds #01/20/2005 initialize $place for each fund transaction read #03/17/05 count commitment and expenditure totals for each fund #for each period after sorting has #taken place. If counting is done in subroutines, if there are #duplicate lines the sum will not be accurate. A duplicate line #can occur because one fund transaction can lead to retrieving #multiple line items, and another fund transaction can retrieve #some of these same line items, which is why we are sort uniqing #the report before printing #05/26/05 get rid of bad characters in title. Might prevent #records from displaying in Excel spreadsheet #07/01/05 if total expenditures don't match what's in fund table #(because Endeavor recalculated fund totals without deleting #bad lines from fund transaction table), use what's in table # and write discrepancy to report. #7/13/05 USE THIS PGM FOR NEW LEDGER CUL07. SEND OUTPUT TO FUNDS DIRECTORY #INSTEAD OF FUNDS2 #05/26/06 sort fund transactions by yyyymmddhhmiss to account for transactions #done the same day #7/13/07 use webdirectory funds3 for CUL07 #7/6/07 new ledger CUL08, use webdir funds4 #7/30/2007 use webdir funds5. problem with funds4 #07/14/2008 use webdir funds6. new ledger CUL09 #02/20/2009 get funds for CU or HS ledgers #07/07/2009 new CUL10 and HSL910 ledgers, and webdir fund7

Oneal perl-code-to-extract-from-voyager

  • Upload
    enug

  • View
    336

  • Download
    2

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Oneal perl-code-to-extract-from-voyager

#!/opt/local/bin/perl

#10/20/04 use this to create report of individual fund.

#will report all transactions for specified fund,

#plus summary of fund plus expenditures and commitments

#for specified range.

#insert fund code, fromdate and todate

#01/14/2005 include line number in report to fix problem

#where commitments for different copie of the same order

#were getting sorted out. Also, send output to funds2

#instead of funds

#01/20/2005 initialize $place for each fund transaction read

#03/17/05 count commitment and expenditure totals for each fund

#for each period after sorting has

#taken place. If counting is done in subroutines, if there are

#duplicate lines the sum will not be accurate. A duplicate line

#can occur because one fund transaction can lead to retrieving

#multiple line items, and another fund transaction can retrieve

#some of these same line items, which is why we are sort uniqing

#the report before printing

#05/26/05 get rid of bad characters in title. Might prevent

#records from displaying in Excel spreadsheet

#07/01/05 if total expenditures don't match what's in fund table

#(because Endeavor recalculated fund totals without deleting

#bad lines from fund transaction table), use what's in table

# and write discrepancy to report.

#7/13/05 USE THIS PGM FOR NEW LEDGER CUL07. SEND OUTPUT TO FUNDS

DIRECTORY

#INSTEAD OF FUNDS2

#05/26/06 sort fund transactions by yyyymmddhhmiss to account for

transactions

#done the same day

#7/13/07 use webdirectory funds3 for CUL07

#7/6/07 new ledger CUL08, use webdir funds4

#7/30/2007 use webdir funds5. problem with funds4

#07/14/2008 use webdir funds6. new ledger CUL09

#02/20/2009 get funds for CU or HS ledgers

#07/07/2009 new CUL10 and HSL910 ledgers, and webdir fund7

Page 2: Oneal perl-code-to-extract-from-voyager

#07/07/2010 new 10/11 ledgers and webdir funds8

#09/13/2010 add ledger name and note field and piece identifier to xls

file, for google calendar

#05/02/2011 add barnard ledger

#05/05/2011 take barnard out, as per Joyce

#7/7/2011 new cul11/12 ledger and funds9

#$fromdate = '20041116';

#$todate = '20041130';

#$fundcode = '2625B';

$fundcode = $ARGV[0];

$fromdate = $ARGV[1];

$todate = $ARGV[2];

#$disprange =

substr($fromdate,4,2).substr($fromdate,6,2).substr($fromdate,2,2)."-

".substr($todate,4,2).substr($todate,6,2).substr($todate,2,2);

$disprange = "$fromdate-$todate";

print "disprange is $disprange\n";

@now = localtime;

$year = ($now[5]+1900);

$month = ($now[4]+1);

$day = ($now[3]);

$fmtday = sprintf("%02d", $day);

$fmtmonth = sprintf("%02d", $month);

$today = "$fmtmonth$fmtday$year.rpt";

$todayrun = "$year$fmtmonth$fmtday";

$place = .01; #initialize decimal place

BEGIN {

$ENV{TWO_TASK} = "VGER";

$ENV{ORACLE_HOME} = "/opt/oracle-9.2";

}

use MARC::Record;

use MARC::Field;

use MARC::Batch;

use DBI;

$database = "COLUMBIADB";

Page 3: Oneal perl-code-to-extract-from-voyager

$dbh = DBI-

>connect("dbi:Oracle:",'READ_ONLY_USERNAME','READ_ONLY_PASSWORD')

|| die("could not open $database"). DBI->errstr;

#creates database object in handle $dbh. this

#represents the connection

$webdir =

"/wwws/data/cu/libraries/inside/clio/statistics/acquisitions/fundcode";

$dir = "/m1/clioprod/ocken/fundrpt";

$title = "FUND ACTIVITY REPORT";

$title2 = "FISCAL YEAR 11/12";

#$title2 = " ";

$fmtdate = "$fmtmonth-$fmtday-$year";

$hdrtxt = "ORDER # DATE BRIEF TITLE PO LN

# PUB PLACE CNTRY TRANSACTION USD AMT INVOICE OPID

VENDOR ORIGINAL CURRENCY";

open (FUNDHDR,">$dir/$fundcode.$disprange.$today.TXT");

write FUNDHDR;

close FUNDHDR;

open FUNDTXT,">$dir/fund.text.$today";

open (FUNDRPT,">>$dir/$fundcode.$disprange.$today.TXT");

system("rm $dir/$fundcode.$disprange.$today.XLS");

open FUNDXLS,">$dir/$fundcode.$disprange.$today.fundrpt.XLS";

open FUNDSHEET,">>$dir/$fundcode.$disprange.$today.XLS";

print FUNDSHEET "FUNDCODE\tPURCHASE ORDER\tTRANSACTION DATE\tTITLE\tPO

LINE #\tPUB PLACE\tPLACE CODE\tTRANS TYPE\tUSD PRICE\tINVOICE

NO.\tOPID\tVENDOR\tORIGINAL CURRENCY\tORIGINAL PRICE\tLEDGER\tVENDOR

NAME\tINVOICE PIECE IDENTIFIER\tNOTE\n";

$savinstid = "";

#now select funds FOR LEDGER CUL 11 (ledger 29) OR LEDGER HS11/12

(ledger 30)

$sql = "SELECT DISTINCT FUND_TRANSACTION.TRANS_TYPE,

FUND_TRANSACTION.AMOUNT,

TO_CHAR(FUND_TRANSACTION.TRANS_DATE,'yyyymmdd'),

FUND_TRANSACTION.TRANS_DATE,

FUND_TRANSACTION.OPERATOR_ID,

FUND_TRANSACTION.REFERENCE_NO,FUND_TRANSACTION.NOTE,

FUND.INSTITUTION_FUND_ID, FUND.FUND_NAME, FUND.FUND_CODE,

Page 4: Oneal perl-code-to-extract-from-voyager

FUND.FUND_ID, FUND.EXPENDITURES,

LEDGER.LEDGER_NAME

FROM $database.FUND_TRANSACTION, $database.FUND

,$database.LEDGER

WHERE FUND.FUND_CODE = '$fundcode' AND

FUND.FUND_ID = FUND_TRANSACTION.FUND_ID AND

( FUND.LEDGER_ID = '29' OR FUND.LEDGER_ID = '30') AND

FUND.LEDGER_ID = FUND_TRANSACTION.LEDGER_ID

AND FUND_TRANSACTION.LEDGER_ID = LEDGER.LEDGER_ID

ORDER BY

FUND.FUND_CODE,TO_CHAR(FUND_TRANSACTION.TRANS_DATE,'yyyymmddhhmiss')";

#print "$sql\n";

$sth = $dbh->prepare("$sql")

or die "Couldn't prepare statement:" . $Data->errstr;

#prepares sql statement and returns object in

#statment handle $sth

$sth->execute() or die "Couldn't execute statement:" . $sth-

>errstr;

#executes prepared sql statement

# N.B. $fundid2 is the fund_id. $fundid is the institution_fund_id

while

(($type,$amount,$transdate,$date2,$opid,$refnum,$note,$instid,$fundid,$fu

ndcode,$fundid2,$expends,$ledger) = $sth->fetchrow_array() )

{ #print

"$type,$amount,$transdate,$date2,$opid,$refnum,$instid,$fundid,$fundcode,

$fundid2,$ledger\n";

#print "date2 is $date2\n";

$note =~ s/\x0a//g; #get rid of line feeds in note field

$note =~ s/\x0d//g; #get rid of carriage returns

if ($opid eq "<R>") {$opid = R;} # <> dont display well in html

if ($type eq '1') {$typetxt = 'initial allocation';}

if ($type eq '2') {$typetxt = 'fund increase';}

if ($type eq '3') {$typetxt = 'fund decrease';}

if ($type eq '4') {$typetxt = 'commitment';}

if ($type eq '5') {$typetxt = 'expenditure';}

if ($type eq '6') {$typetxt = 'transfer in';}

if ($type eq '7') {$typetxt = 'transfer out';}

$amounttxt = sprintf("%6.2f",($amount*.01));

$vendor = "";

$vendname = "";

if ($type eq '4') {#print "refnum is $refnum\n";

getvendc($refnum);}

#print "commit vendor is $vendor\n";} #for

commitment get vendor from order

if ($type eq '5') {#print "refnum is $refnum\n";

getvende($refnum);}

Page 5: Oneal perl-code-to-extract-from-voyager

#print "expend vendor is $vendor\n"; #for expend

get vendor from invoice

if ($instid ne $savinstid) {&initrtn;}

if ($type eq '1') {#print "initalloc is $initalloc.

amount is $amount\n";

$initalloc = $initalloc + $amount;

#initial allocation

$netalloc = $netalloc + $amount;}

if ($type eq '2') {$netalloc = $netalloc + $amount;

$incsum = $incsum + $amount;}

#fund increase

if ($type eq '3') {#print "netalloc is $netalloc before

decrease\n";

$netalloc = $netalloc - $amount;

$decsum = $decsum + $amount;}

#print "we have a decrease. amount is

$amount. decsum is $decsum, netalloc is $netalloc\n";}

#fund decrease

if ($type eq '4') {$commitsum = $commitsum + $amount;}

#commitment

if ($type eq '5') {$expsum = $expsum + $amount;}

#expenditures

if ($type eq '6') {$netalloc = $netalloc + $amount;

$transinsum = $transinsum + $amount;}

#transfer in

if ($type eq '7') {$netalloc = $netalloc - $amount;

$transoutsum = $transoutsum +

$amount;} #transfer out

$cashbal = $netalloc - $expsum;

$freebal = $cashbal - $commitsum;

# print "trans date is $transdate lastrun is $lastrun

today is $todayrun\n";

if ($transdate ge $fromdate && $transdate le $todate) #if

within date range

{ #print "amount is $amount, refnum is $refnum\n ";

if ($type eq '4') {$commitdtl = $commitdtl + $amount;}

#commitment

if ($type eq '5') {$expdtl = $expdtl + $amount;}

#expenditures

Page 6: Oneal perl-code-to-extract-from-voyager

#write FUNDTXT;

$po = ""; #initialize

$inv = ""; #initialize

$title = ""; #initialize

$currency = "";

$lineprice = "";

$placecode = "";

$pubplace = "";

$linenum = "";

$place = .01;

##ignore negative commitments (created by system) but accept all

expenditures (negative

#expenditures are created by users

#02/11/05 ignore negative expenditures without opid's

if ($amount < 0 && !$opid) {next;}

#if expenditure was cancelled by system there's no opid, just

ignore

if ($type eq '4' && $amount > 0) {$po = $refnum; lineord($refnum);}

#get line items for orders if positive commitment

if ($type eq '5') {lineinv($refnum);} #for expenditures get all line

items associated with that invoice

if ($type ne '4' && $type ne '5')

{$usprice = $amount;

write FUNDTXT;

printf FUNDXLS

("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%10.2f\t%s\t%s\t%s\t%s\t%10.2f\t%s\t%s\

t%s\t%s\t%s\n",$fundcode,$po,$transdate,$title,$linenum,$pubplace,$placec

ode,$typetxt,$usprice*$place,$inv,$opid,$vendor,$currency,,$ledger,$vendn

ame,,$note); }

# print FUNDXLS

"$fundcode\t$transdate\t$typetxt\t$amounttxt\t$opid\t$refnum\t$vendor\t$l

edger\n";

} #end of if transaction is in date range

} #end of while sql

&initrtn; #print last fund

close FUNDRPT;

close FUNDXLS;

$dbh->disconnect;

#print "savfundcode is $savfundcode\n";

Page 7: Oneal perl-code-to-extract-from-voyager

print "file is $savfundcode.$disprange.$today.TXT\n";

system("rm $webdir/funds9/$savfundcode.$disprange.$today.TXT");

system("cat $dir/$savfundcode.$disprange.$today.TXT >

$webdir/funds9/$savfundcode.$disprange.$today.TXT");

system("chmod a+r $webdir/funds9/$savfundcode.$disprange.$today.TXT");

system("rm $webdir/funds9/$savfundcode.$disprange.$today.XLS");

system("cat $dir/$savfundcode.$disprange.$today.XLS >

$webdir/funds9/$savfundcode.$disprange.$today.XLS");

system("chmod a+r $webdir/funds9/$savfundcode.$disprange.$today.XLS");

#************************************************************************

***

#initialize counters and institution id

#************************************************************************

***

sub initrtn() {

if ($savinstid)

{if ($expsum ne $savexpend) #07/01/05

{#print "$savfundcode table expenditures = $savexpend, report

expenditures = $expsum\n";

$expsum = $savexpend;

$cashbal = $netalloc - $expsum; #and re-compute

$freebal = $cashbal - $commitsum;}

print FUNDRPT "\nFUND: $savinstid $savfundid:\n";

print FUNDRPT "DATE RANGE : $fromdate - $todate\n\n";

print FUNDRPT "$hdrtxt\n";

if ($netalloc > 0) {$free = $freebal/$netalloc;

$free = $free*100;

$freepct = sprintf("%6.2f",$free);

$cashfree = $cashbal/$netalloc;

$cashfree = $cashfree*100;

$cashfreepct = sprintf("%10.2f",$cashfree); }

else {$freepct = 0;

$cashfreepct = 0;}

#print "free is $freebal, free is $freepct\n";

#print FUNDRPT "test expenditures : $expdtltest\n";

#print FUNDRPT "test commits : $commitdtltest\n";

$totinit = $totinit + $initalloc;

$totnet = $totnet + $netalloc;

$totexp = $totexp + $expsum;

Page 8: Oneal perl-code-to-extract-from-voyager

$totcommit = $totcommit + $commitsum;

$totinc = $totinc + $incsum;

$totdec = $totdec + $decsum;

$tottransin = $tottransin + $transinsum;

$tottransout = $tottransout + $transoutsum;

#print "we are here. new fund is $fundcode, old fund is

$savfundcode\n";

close FUNDTXT;

#sort by title and date

system("cat $dir/fund.text.$today | sort -d -k 3,3 -k 2,2n | uniq >

$dir/fund.text.$today.sorted");

open SORTED,"$dir/fund.text.$today.sorted";

$expendpd = "0.00"; #03/17/05 now count expenditures and commitments

from line items for this period

$commitpd = "0.00";

while ($line = <SORTED>) #get rid of copyid from

report. was only nec. for sorting uniq

{($printline,$copyid) = ($line =~ /(.*)\ ([^\ ]+$)/); #printline is

everything before the last space

if ($printline =~ /expenditure/) {$expend = substr($printline,100,13);

print "expend is $expend\n";

$expendpd = $expend + $expendpd;}

if ($printline =~ /commitment/) {$commit = substr($printline,100,13);

print "commit is $commit\n";

$commitpd = $commit + $commitpd;}

print FUNDRPT "$printline\n";}

#print FUNDRPT $_;}

write FUNDRPT ;

open FUNDTXT,">$dir/fund.text.$today";

close FUNDRPT;

close FUNDXLS;

system("cat $dir/$savfundcode.$disprange.$today.fundrpt.XLS | sort -d -k

4,4 -k 3,3n | uniq > $dir/$savfundcode.$disprange.$today.sorted.XLS");

open SORTEDXLS,"$dir/$savfundcode.$disprange.$today.sorted.XLS";

while ($line = <SORTEDXLS>)

{($printline,$copyid) = ($line =~ /(.*)\t([^\t]+$)/); #printline is

everything before the last tab

print FUNDSHEET "$printline\n";}

close FUNDSHEET;

#print "savfundcode is $savfundcode\n";

#print "file is $savfundcode.$disprange.$today.TXT\n";

Page 9: Oneal perl-code-to-extract-from-voyager

system("rm

$webdir/funds9/$savfundcode/$savfundcode.$disprange.$today.TXT");

system("cat $dir/$savfundcode.$disprange.$today.TXT >

$webdir/funds9/$savfundcode/$savfundcode.$disprange.$today.TXT");

system("chmod a+r

$webdir/funds9/$savfundcode/$savfundcode.$disprange.$today.TXT");

system("rm

$webdir/funds9/$savfundcode/$savfundcode.$disprange.$today.XLS");

system("cat $dir/$savfundcode.$disprange.$today.XLS >

$webdir/funds9/$savfundcode/$savfundcode.$disprange.$today.XLS");

system("chmod a+r

$webdir/funds9/$savfundcode/$savfundcode.$disprange.$today.XLS");

exit; #uncomment here to test 1 fund code. exit here to retain

fund code name for report

}

$savexpend = $expends; #save fund total expends

$savinstid = $instid; #initialize institution id save field

$savfundid = $fundid; #initialize fund id save field

$savfundcode = $fundcode; #initialize fund code save field

$initalloc = 0; #initialize initial allocation

$netalloc =0; #initialize net allocation

$expsum = 0; #initialize expediture sum

$commitsum = 0; #initialize commitment sum

$incsum = 0; #initialize fund increase sum

$decsum = 0; #initialize fund decrease sum

$transinsum = 0; #initialize tranfer in sum

$transoutsum = 0; #initialize transfer out sum

$cashbal = 0; #initialize cash balance

$freebal = 0; #initialize freeable balance

$commitdtl = 0;

$expdtl = 0;

$expdtltest = 0;

$commitdtltest = 0;

} #end of subrtn

#########################################################################

# fund report header routine

#########################################################################

format FUNDHDR =

@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

$title

@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Page 10: Oneal perl-code-to-extract-from-voyager

$title2

@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

$fmtdate

.

#########################################################################

# fund report format routine

#########################################################################

format FUNDRPT =

TOTAL EXPENDITURES from @<<<<<<<< to @<<<<<<<< : @########.##

$fromdate,$todate,$expendpd

TOTAL COMMITMENTS from @<<<<<<<< to @<<<<<<<< : @########.##

$fromdate,$todate,$commitpd

FUND TOTALS: @<<<<<<<<<< @<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<

$savfundcode,$savinstid,$savfundid

InitAlloc Net Alloc. Tot.Expends CashBalance Cash %

Tot.Commits Free Balance Free %

@#########.## @#########.## @########.## @########.## @###.##

@########.## @########.## @###.##

$initalloc*.01,$netalloc*.01,$expsum*.01,$cashbal*.01,$cashfreepct,$commi

tsum*.01,$freebal*.01,$freepct

*************************************************************************

*************************************************

.

#########################################################################

# fund text format routine

#########################################################################

format FUNDTXT =

@<<<<<<<<<< @<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<

@<<<<<<<<<<<<< @<<<< @<<<<<<<<<<<< @#######.## @<<<<<<<<<<< @<<<<

@<<<<<<< @<<< @#######.## @<<<<<

$po,$transdate,$title,

$linenum,$pubplace,$placecode,$typetxt,$usprice*$place,$inv,$opid,$vendor

,$currency,$lineprice*$place,$copyid

.

#########################################################################

#############################################

# edit routine formats totals

Page 11: Oneal perl-code-to-extract-from-voyager

#########################################################################

############################################

sub edit() {

$newamt = $_[0]*.01;

$newamt =~s/ //g; #get rid of spaces

return $newamt;

}

#########################################################################

# fund report totals routine

#########################################################################

format FUNDTOTS =

*************************************************************************

**************************************

TOTAL ALL FUNDS:

InitAlloc Net Alloc. Tot.Expends CashBalance Cash % Tot.Commits

Free Balance Free %

@#########.## @#########.## @########.## @########.## @###.##

@########.## @########.## @###.##

$totinit*.01,$totnet*.01,$totexp*.01,$totcash*.01,$cashfreepct,$totcommit

*.01,$totfree*.01,$freepct

.

#################################################################

# getvendc get vendor code from order table

#################################################################

sub getvendc() {

$sql2 = "SELECT VENDOR.VENDOR_CODE, VENDOR.VENDOR_NAME

FROM $database.VENDOR, $database.PURCHASE_ORDER

WHERE

PURCHASE_ORDER.PO_NUMBER = '$refnum'

AND PURCHASE_ORDER.VENDOR_ID = VENDOR.VENDOR_ID";

$sth2 = $dbh->prepare("$sql2")

or die "Couldn't prepare statement:" . $Data->errstr;

$sth2->execute() or die "Couldn't execute statement:" . $sth2->errstr;

($vendor,$vendname) = $sth2->fetchrow_array();

return ($vendor,$vendname);

}

#################################################################

# getvende get vendor from invoice

#################################################################

sub getvende() {

Page 12: Oneal perl-code-to-extract-from-voyager

$vendor = "";

$vendname = "";

$sql3 = "SELECT DISTINCT VENDOR.VENDOR_CODE, VENDOR.VENDOR_NAME

FROM $database.VENDOR, $database.INVOICE,

$database.INVOICE_FUNDS

WHERE

INVOICE.INVOICE_NUMBER = '$refnum'

AND INVOICE.INVOICE_ID = INVOICE_FUNDS.INVOICE_ID

AND INVOICE_FUNDS.FUND_ID = '$fundid2'

AND INVOICE.VENDOR_ID = VENDOR.VENDOR_ID";

#AND TO_CHAR(INVOICE.INVOICE_STATUS_DATE,'yyyymmdd') = '$transdate'

# AND INVOICE.VENDOR_ID = VENDOR.VENDOR_ID";

#print "$sql3\n";

$sth3 = $dbh->prepare("$sql3")

or die "Couldn't prepare statement:" . $Data->errstr;

$sth3->execute() or die "Couldn't execute statement:" . $sth2->errstr;

($vendor,$vendname) = $sth3->fetchrow_array();

return ($vendor,$vendname);

}

#########################################################################

########################

# lineinv - get line items for invoice

# GET PRICE FROM INVOICE LINE ITEM FUNDS TABLE INSTEAD OF INVOICE LINE

ITEM

#########################################################################

#######################

sub lineinv() {

#print "refnum is $refnum\n";

$po = "";

$inv = $refnum;

$note = ""; #initialize

$sql4 = "SELECT DISTINCT PURCHASE_ORDER.PO_NUMBER,

INVOICE_LINE_ITEM_FUNDS.AMOUNT,

INVOICE_LINE_ITEM_FUNDS.COPY_ID,

LINE_ITEM.LINE_ITEM_NUMBER,

BIB_TEXT.TITLE_BRIEF,

BIB_TEXT.PUB_PLACE, BIB_TEXT.PLACE_CODE,

INVOICE.CURRENCY_CODE, INVOICE.CONVERSION_RATE,

CURRENCY_CONVERSION.DECIMALS,

INV_LINE_ITEM_NOTES.NOTE, INVOICE_LINE_ITEM.PIECE_IDENTIFIER

FROM $database.INV_LINE_ITEM_NOTES,

$database.PURCHASE_ORDER,

$database.INVOICE_LINE_ITEM, $database.INVOICE,

Page 13: Oneal perl-code-to-extract-from-voyager

$database.INVOICE_LINE_ITEM_FUNDS, $database.LINE_ITEM,

$database.BIB_TEXT,

$database.CURRENCY_CONVERSION

WHERE INVOICE.INVOICE_NUMBER = '$refnum' AND

TO_CHAR(INVOICE.INVOICE_STATUS_DATE,'yyyymmdd') =

'$transdate'

AND INVOICE.INVOICE_ID = INVOICE_LINE_ITEM.INVOICE_ID

AND INVOICE_LINE_ITEM.INV_LINE_ITEM_ID =

INVOICE_LINE_ITEM_FUNDS.INV_LINE_ITEM_ID

AND INVOICE_LINE_ITEM_FUNDS.FUND_ID = '$fundid2'

AND INVOICE_LINE_ITEM.LINE_ITEM_ID = LINE_ITEM.LINE_ITEM_ID

AND INVOICE_LINE_ITEM.INV_LINE_ITEM_ID =

INV_LINE_ITEM_NOTES.INV_LINE_ITEM_ID(+)

AND LINE_ITEM.PO_ID = PURCHASE_ORDER.PO_ID

AND LINE_ITEM.BIB_ID = BIB_TEXT.BIB_ID AND

INVOICE.CURRENCY_CODE =

CURRENCY_CONVERSION.CURRENCY_CODE(+)";

#print "$sql4\n";

$sth4 = $dbh->prepare("$sql4")

or die "Couldn't prepare statement:" . $Data->errstr;

$sth4->execute() or die "Couldn't execute statement:" . $sth4->errstr;

while

(($po,$lineprice,$copyid,$linenum,$title,$pubplace,$placecode,$currency,$

convrate,$decimals,$note,$piece) = $sth4->fetchrow_array())

{$note =~ s/\x0a//g; #get rid of line feeds in note field

$note =~ s/\x0d//g; #get rid of carriage returns

$title =~ s/[^\x20-\x7e]//g; #get rid of ALL bad characters

$title =~ s/\"//g; #and quotes

if ($currency ne 'USD')

{$usprice = $lineprice/($convrate*.00001);

if ($decimals eq 0) {$place = 1;} }

else {$usprice = $lineprice;}

if (!$pubplace) {$pubplace = "\ ";}

#print "lineprice is $lineprice, convrate is $convrate, usprice is

$usprice, decimals is $decimals\n";

$expdtltest = $expdtltest + $usprice;

printf FUNDXLS

("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%10.2f\t%s\t%s\t%s\t%s\t%10.2f\t%s\t%s\

t%s\t%s\t%s\n",$fundcode,$po,$transdate,$title,$linenum,$pubplace,$placec

ode,$typetxt,$usprice*$place,$inv,$opid,$vendor,$currency,$lineprice*$pla

ce,$ledger,$vendname,$piece,$note,$copyid);

write FUNDTXT; }

} #end of lineinv subroutne

Page 14: Oneal perl-code-to-extract-from-voyager

#########################################################################

################################

## lineord - get all line items for that order

#first get all line items for that order

#then get copy numbers for each line item

#then check that copy number has a status date that is in the date range

#then make sure fund for that copy number is the fund we're looking for

#(this should take of problem where copies are ordered under a split

fund)

#

#9/15/2010 get both notes and print notes.

#########################################################################

################################

sub lineord() {

#print "refnum is $refnum, date is $transdate\n";

$note = ""; #initialize

$sql5 = "SELECT DISTINCT LINE_ITEM.LINE_ITEM_NUMBER,

LINE_ITEM_FUNDS.AMOUNT, LINE_ITEM_FUNDS.COPY_ID,

BIB_TEXT.TITLE_BRIEF, BIB_TEXT.PUB_PLACE,

BIB_TEXT.PLACE_CODE,

PURCHASE_ORDER.CURRENCY_CODE,

PURCHASE_ORDER.CONVERSION_RATE,

CURRENCY_CONVERSION.DECIMALS,LINE_ITEM_NOTES.NOTE,

LINE_ITEM_NOTES.PRINT_NOTE

FROM $database.LINE_ITEM_NOTES,

$database.BIB_TEXT, $database.LINE_ITEM,

$database.LINE_ITEM_COPY_HISTORY,

$database.LINE_ITEM_COPY_STATUS, $database.PURCHASE_ORDER,

$database.LINE_ITEM_FUNDS,

$database.CURRENCY_CONVERSION

WHERE PURCHASE_ORDER.PO_NUMBER = '$refnum'

AND PURCHASE_ORDER.PO_ID = LINE_ITEM.PO_ID

AND LINE_ITEM.LINE_ITEM_ID =

LINE_ITEM_COPY_STATUS.LINE_ITEM_ID

AND LINE_ITEM.LINE_ITEM_ID =

LINE_ITEM_NOTES.LINE_ITEM_ID(+)

AND LINE_ITEM_COPY_STATUS.COPY_ID =

LINE_ITEM_COPY_HISTORY.COPY_ID

AND (

TO_CHAR(LINE_ITEM_COPY_HISTORY.STATUS_DATE,'yyyymmdd') >= '$fromdate'

AND

TO_CHAR(LINE_ITEM_COPY_HISTORY.STATUS_DATE,'yyyymmdd') <= '$todate')

AND LINE_ITEM_COPY_HISTORY.COPY_ID =

LINE_ITEM_FUNDS.COPY_ID

AND LINE_ITEM_FUNDS.FUND_ID = '$fundid2'

AND LINE_ITEM.BIB_ID =

BIB_TEXT.BIB_ID

AND PURCHASE_ORDER.CURRENCY_CODE =

CURRENCY_CONVERSION.CURRENCY_CODE(+)";

#print"$sql5\n";

Page 15: Oneal perl-code-to-extract-from-voyager

$sth5 = $dbh->prepare("$sql5")

or die "Couldn't prepare statement:" . $Data->errstr;

$sth5->execute() or die "Couldn't execute statement:" . $sth5->errstr;

while

(($linenum,$lineprice,$copyid,$title,$pubplace,$placecode,$currency,$conv

rate,$decimals,$note,$print_note) = $sth5->fetchrow_array() )

{ if (!$note && $print_note) {$note = $print_note;}

#print "note is $note\n";

$note =~ s/\x0a//g; #get rid of line feeds

$note =~ s/\x0d//g; #get rid of carriage returns

#print "now note is $note\n";

#print

"$linenum,$lineprice,$copyid,$title,$pubplace,$placecode,$currency,$convr

ate,$decimals,$note\n";

if (!$pubplace) {$pubplace = "\ ";}

if ($currency ne 'USD') {$usprice = $lineprice/($convrate*.00001);

if ($decimals eq 0) {$place = 1;} }

#print "conversion rate is $convrate\n";

# print "usprice is $usprice\n";}

else {$usprice = $lineprice;}

$commitdtltest = $commitdtltest + $usprice;

#print "order is $refnum\n";

printf FUNDXLS

("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%10.2f\t%s\t%s\t%s\t%s\t%10.2f\t%s\t%s\

t%s\t%s\t%s\n",$fundcode,$po,$transdate,$title,$linenum,$pubplace,$placec

ode,$typetxt,$usprice*$place,$inv,$opid,$vendor,$currency,$lineprice*$pla

ce,$ledger,$vendname,$piece,$note);

#print "copyid is $copyid, price is $lineprice\n";

write FUNDTXT;}

}