#!/opt/local/bin/perl#10/20/04 use this to create report of individual fund.#will report all transactions for specified fu...
#07/07/2010 new 10/11 ledgers and webdir funds8#09/13/2010 add ledger name and note field and piece identifier to xlsfile,...
$dbh = DBI->connect("dbi:Oracle:",READ_ONLY_USERNAME,READ_ONLY_PASSWORD)    || die("could not open $database"). DBI->errst...
FUND.FUND_ID, FUND.EXPENDITURES,                 LEDGER.LEDGER_NAME        FROM   $database.FUND_TRANSACTION, $database.FU...
#print "expend vendor is $vendorn";   #for expendget vendor from invoice            if ($instid ne $savinstid) {&initrtn;}...
#write FUNDTXT;                    $po = ""; #initialize                    $inv = ""; #initialize                    $tit...
print "file is $savfundcode.$disprange.$today.TXTn";system("rm $webdir/funds9/$savfundcode.$disprange.$today.TXT");system(...
$totcommit = $totcommit + $commitsum;$totinc = $totinc + $incsum;$totdec = $totdec + $decsum;$tottransin = $tottransin + $...
system("rm$webdir/funds9/$savfundcode/$savfundcode.$disprange.$today.TXT");system("cat $dir/$savfundcode.$disprange.$today...
$title2@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||...
#####################################################################################################################sub e...
$vendor = "";    $vendname = ""; $sql3 = "SELECT DISTINCT VENDOR.VENDOR_CODE, VENDOR.VENDOR_NAME           FROM $database....
$database.INVOICE_LINE_ITEM_FUNDS, $database.LINE_ITEM,$database.BIB_TEXT,               $database.CURRENCY_CONVERSION    ...
########################################################################################################### lineord - get ...
$sth5 = $dbh->prepare("$sql5")           or die "Couldnt prepare statement:" . $Data->errstr;$sth5->execute() or die "Coul...
Upcoming SlideShare
Loading in …5
×

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

344 views
306 views

Published on

Published in: Economy & Finance, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
344
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

  1. 1. #!/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 dont match whats in fund table#(because Endeavor recalculated fund totals without deleting#bad lines from fund transaction table), use whats in table# and write discrepancy to report.#7/13/05 USE THIS PGM FOR NEW LEDGER CUL07. SEND OUTPUT TO FUNDSDIRECTORY#INSTEAD OF FUNDS2#05/26/06 sort fund transactions by yyyymmddhhmiss to account fortransactions#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
  2. 2. #07/07/2010 new 10/11 ledgers and webdir funds8#09/13/2010 add ledger name and note field and piece identifier to xlsfile, 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 $disprangen";@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 placeBEGIN { $ENV{TWO_TASK} = "VGER"; $ENV{ORACLE_HOME} = "/opt/oracle-9.2";}use MARC::Record;use MARC::Field;use MARC::Batch;use DBI;$database = "COLUMBIADB";
  3. 3. $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 OPIDVENDOR 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 "FUNDCODEtPURCHASE ORDERtTRANSACTION DATEtTITLEtPOLINE #tPUB PLACEtPLACE CODEtTRANS TYPEtUSD PRICEtINVOICENO.tOPIDtVENDORtORIGINAL CURRENCYtORIGINAL PRICEtLEDGERtVENDORNAMEtINVOICE PIECE IDENTIFIERtNOTEn";$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,
  4. 4. 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 BYFUND.FUND_CODE,TO_CHAR(FUND_TRANSACTION.TRANS_DATE,yyyymmddhhmiss)";#print "$sqln"; $sth = $dbh->prepare("$sql") or die "Couldnt prepare statement:" . $Data->errstr; #prepares sql statement and returns object in #statment handle $sth $sth->execute() or die "Couldnt execute statement:" . $sth->errstr; #executes prepared sql statement# N.B. $fundid2 is the fund_id. $fundid is the institution_fund_idwhile(($type,$amount,$transdate,$date2,$opid,$refnum,$note,$instid,$fundid,$fundcode,$fundid2,$expends,$ledger) = $sth->fetchrow_array() ){ #print"$type,$amount,$transdate,$date2,$opid,$refnum,$instid,$fundid,$fundcode,$fundid2,$ledgern"; #print "date2 is $date2n"; $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 $refnumn"; getvendc($refnum);} #print "commit vendor is $vendorn";} #forcommitment get vendor from order if ($type eq 5) {#print "refnum is $refnumn"; getvende($refnum);}
  5. 5. #print "expend vendor is $vendorn"; #for expendget vendor from invoice if ($instid ne $savinstid) {&initrtn;} if ($type eq 1) {#print "initalloc is $initalloc.amount is $amountn"; $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 beforedecreasen"; $netalloc = $netalloc - $amount; $decsum = $decsum + $amount;} #print "we have a decrease. amount is$amount. decsum is $decsum, netalloc is $netallocn";}#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 $lastruntoday is $todayrunn"; if ($transdate ge $fromdate && $transdate le $todate) #ifwithin date range { #print "amount is $amount, refnum is $refnumn "; if ($type eq 4) {$commitdtl = $commitdtl + $amount;}#commitment if ($type eq 5) {$expdtl = $expdtl + $amount;}#expenditures
  6. 6. #write FUNDTXT; $po = ""; #initialize $inv = ""; #initialize $title = ""; #initialize $currency = ""; $lineprice = ""; $placecode = ""; $pubplace = ""; $linenum = ""; $place = .01;##ignore negative commitments (created by system) but accept allexpenditures (negative#expenditures are created by users#02/11/05 ignore negative expenditures without opids if ($amount < 0 && !$opid) {next;} #if expenditure was cancelled by system theres no opid, justignore 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 lineitems associated with that invoice if ($type ne 4 && $type ne 5) {$usprice = $amount; write FUNDTXT;printf FUNDXLS("%st%st%st%st%st%st%st%st%10.2ft%st%st%st%st%10.2ft%st%st%st%st%sn",$fundcode,$po,$transdate,$title,$linenum,$pubplace,$placecode,$typetxt,$usprice*$place,$inv,$opid,$vendor,$currency,,$ledger,$vendname,,$note); } # print FUNDXLS"$fundcodet$transdatet$typetxtt$amounttxtt$opidt$refnumt$vendort$ledgern"; } #end of if transaction is in date range} #end of while sql&initrtn; #print last fundclose FUNDRPT;close FUNDXLS;$dbh->disconnect;#print "savfundcode is $savfundcoden";
  7. 7. print "file is $savfundcode.$disprange.$today.TXTn";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, reportexpenditures = $expsumn"; $expsum = $savexpend; $cashbal = $netalloc - $expsum; #and re-compute $freebal = $cashbal - $commitsum;}print FUNDRPT "nFUND: $savinstid $savfundid:n"; print FUNDRPT "DATE RANGE : $fromdate - $todatenn"; print FUNDRPT "$hdrtxtn"; 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 $freepctn"; #print FUNDRPT "test expenditures : $expdtltestn"; #print FUNDRPT "test commits : $commitdtltestn";$totinit = $totinit + $initalloc;$totnet = $totnet + $netalloc;$totexp = $totexp + $expsum;
  8. 8. $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$savfundcoden"; close FUNDTXT;#sort by title and datesystem("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 commitmentsfrom line items for this period $commitpd = "0.00";while ($line = <SORTED>) #get rid of copyid fromreport. was only nec. for sorting uniq{($printline,$copyid) = ($line =~ /(.*) ([^ ]+$)/); #printline iseverything before the last space if ($printline =~ /expenditure/) {$expend = substr($printline,100,13); print "expend is $expendn"; $expendpd = $expend + $expendpd;} if ($printline =~ /commitment/) {$commit = substr($printline,100,13); print "commit is $commitn"; $commitpd = $commit + $commitpd;}print FUNDRPT "$printlinen";}#print FUNDRPT $_;}write FUNDRPT ;open FUNDTXT,">$dir/fund.text.$today";close FUNDRPT;close FUNDXLS;system("cat $dir/$savfundcode.$disprange.$today.fundrpt.XLS | sort -d -k4,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 iseverything before the last tab print FUNDSHEET "$printlinen";}close FUNDSHEET;#print "savfundcode is $savfundcoden";#print "file is $savfundcode.$disprange.$today.TXTn";
  9. 9. 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 retainfund 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@|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  10. 10. $title2@|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||$fmtdate.########################################################################## fund report format routine#########################################################################format FUNDRPT =TOTAL EXPENDITURES from @<<<<<<<< to @<<<<<<<< : @########.##$fromdate,$todate,$expendpdTOTAL COMMITMENTS from @<<<<<<<< to @<<<<<<<< : @########.##$fromdate,$todate,$commitpdFUND 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,$commitsum*.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
  11. 11. #####################################################################################################################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.CommitsFree 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 "Couldnt prepare statement:" . $Data->errstr; $sth2->execute() or die "Couldnt execute statement:" . $sth2->errstr; ($vendor,$vendname) = $sth2->fetchrow_array();return ($vendor,$vendname);}################################################################## getvende get vendor from invoice#################################################################sub getvende() {
  12. 12. $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 "$sql3n";$sth3 = $dbh->prepare("$sql3") or die "Couldnt prepare statement:" . $Data->errstr; $sth3->execute() or die "Couldnt 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 LINEITEM################################################################################################sub lineinv() { #print "refnum is $refnumn"; $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,
  13. 13. $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 "$sql4n";$sth4 = $dbh->prepare("$sql4") or die "Couldnt prepare statement:" . $Data->errstr; $sth4->execute() or die "Couldnt 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 $decimalsn"; $expdtltest = $expdtltest + $usprice; printf FUNDXLS("%st%st%st%st%st%st%st%st%10.2ft%st%st%st%st%10.2ft%st%st%st%st%sn",$fundcode,$po,$transdate,$title,$linenum,$pubplace,$placecode,$typetxt,$usprice*$place,$inv,$opid,$vendor,$currency,$lineprice*$place,$ledger,$vendname,$piece,$note,$copyid); write FUNDTXT; }} #end of lineinv subroutne
  14. 14. ########################################################################################################### 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 were looking for#(this should take of problem where copies are ordered under a splitfund)##9/15/2010 get both notes and print notes.#########################################################################################################sub lineord() { #print "refnum is $refnum, date is $transdaten"; $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 ANDTO_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"$sql5n";
  15. 15. $sth5 = $dbh->prepare("$sql5") or die "Couldnt prepare statement:" . $Data->errstr;$sth5->execute() or die "Couldnt execute statement:" . $sth5->errstr; while(($linenum,$lineprice,$copyid,$title,$pubplace,$placecode,$currency,$convrate,$decimals,$note,$print_note) = $sth5->fetchrow_array() ) { if (!$note && $print_note) {$note = $print_note;} #print "note is $noten"; $note =~ s/x0a//g; #get rid of line feeds $note =~ s/x0d//g; #get rid of carriage returns #print "now note is $noten"; #print"$linenum,$lineprice,$copyid,$title,$pubplace,$placecode,$currency,$convrate,$decimals,$noten"; if (!$pubplace) {$pubplace = " ";} if ($currency ne USD) {$usprice = $lineprice/($convrate*.00001); if ($decimals eq 0) {$place = 1;} } #print "conversion rate is $convraten"; # print "usprice is $uspricen";} else {$usprice = $lineprice;} $commitdtltest = $commitdtltest + $usprice; #print "order is $refnumn"; printf FUNDXLS("%st%st%st%st%st%st%st%st%10.2ft%st%st%st%st%10.2ft%st%st%st%st%sn",$fundcode,$po,$transdate,$title,$linenum,$pubplace,$placecode,$typetxt,$usprice*$place,$inv,$opid,$vendor,$currency,$lineprice*$place,$ledger,$vendname,$piece,$note); #print "copyid is $copyid, price is $linepricen"; write FUNDTXT;}}

×