=================================================================== RCS file: /cvs/RT/Invoicing/test.pl,v retrieving revision 1.1 retrieving revision 1.6 diff -u -r1.1 -r1.6 --- RT/Invoicing/test.pl 2011/03/19 23:27:16 1.1 +++ RT/Invoicing/test.pl 2020/08/02 02:05:31 1.6 @@ -1,32 +1,38 @@ #!/usr/bin/perl -# $AFresh1$ +# $AFresh1: test.pl,v 1.5 2011/12/21 02:20:59 andrew Exp $ use strict; use warnings; use Template; +use DateTime; +use Cwd qw< abs_path >; my %invoice = ( - id => 1, - info1 => 'Visit me online at http://example.com', - info2 => 'Create a new ticket rt@example.com', - from => { - name => 'Example Company', - #attn => 'Jane Smith', - addr1 => '22115 Central Way', - addr2 => 'Suite C', - city => 'Anytown', - state => 'America', - zip => '11111', - phone => '(800) 555-1212', - email => 'company@example.com', - }, - to => { - name => 'John Doe', - addr1 => '123 W Main St', - city => 'Anytown', - state => 'America', - zip => '11111', - }, + id => 1234, + invdate => DateTime->new( year => 2011, month => 3, day => 1 ), + start => DateTime->new( year => 2011, month => 1, day => 1 ), + end => DateTime->new( year => 2011, month => 3, day => 19 ), + logo => abs_path( 'logo.pdf' ), + info => [ + 'Visit me online at http://example.com', + 'Create a new ticket rt@example.com', + ], + from => 'Example Company + +22115 Central Way + +Suite C + +Anytown, America 11111 + +(800) 555-1212 + +\texttt{}', + to => 'John Doe + +123 W Main St + +Anytown, America 11111', projects => [ { title => 'Weekly Retainer', @@ -46,32 +52,32 @@ { id => 60, title => '60: A Special Project', + detail => 'Requestors jdoe@example.net', fees => [ { contents => '2011-01-01: Talk a lot (727)', + detail => 'This is detail about 727', count => 0.33, rate => 75, }, { contents => '2011-01-15: Write Stuff (730)', + detail => 'This is detail about 730', count => 1.5, rate => 100, }, - ], - discounts => [ { - contents => 'Included Hours', - amount => .33 * 75, + contents => 'Rounding FAIL', + detail => 'Should be $8.30', + count => .083, + rate => 100, }, - { - contents => 'Included Hours', - amount => 1.5 * 100, - }, ], }, { id => 65, title => '65: More work!', + detail => 'Requestors jdoe@example.net', fees => [ { contents => '2011-01-06: Define Project (751)', @@ -84,7 +90,7 @@ rate => 100, }, { - contents => '2011-01-12: REdefine Project (903)', + contents => '2011-01-12: Redefine Project (903)', count => 0.25, rate => 75, }, @@ -94,20 +100,11 @@ rate => 125, }, ], - discounts => [ - { - contents => 'Included Hours', - amount => (.33 * 75) + ( 3.33 * 100 ), - }, - { - contents => 'Included Hours', - amount => (.25 * 75 ) + (2.25 * 100), - }, - ], }, { id => 85, title => '85: Replace stuff', + detail => 'Requestors maintenance@example.net', fees => [ { contents => '2011-01-13: Go unplug, replace, replug (834)', @@ -134,7 +131,23 @@ ], }, ], + discount => { + contents => 'Discount', + amount => '8.498', + }, ); + +foreach my $project (@{ $invoice{projects} || [] }) { + foreach my $fee (@{ $project->{fees} || [] }) { + $invoice{total} += $fee->{count} * $fee->{rate}; + } + foreach my $expense (@{ $project->{expenses} || [] }) { + $invoice{total} += $expense->{amount}; + } +} + +$invoice{total} -= $invoice{discount}{amount} + if $invoice{discount}; my $tt = Template->new;