Annotation of RT/Invoicing/test.pl, Revision 1.6
1.1 andrew 1: #!/usr/bin/perl
1.6 ! afresh1 2: # $AFresh1: test.pl,v 1.5 2011/12/21 02:20:59 andrew Exp $
1.1 andrew 3: use strict;
4: use warnings;
5:
6: use Template;
1.6 ! afresh1 7: use DateTime;
! 8: use Cwd qw< abs_path >;
1.1 andrew 9:
10: my %invoice = (
1.6 ! afresh1 11: id => 1234,
! 12: invdate => DateTime->new( year => 2011, month => 3, day => 1 ),
! 13: start => DateTime->new( year => 2011, month => 1, day => 1 ),
! 14: end => DateTime->new( year => 2011, month => 3, day => 19 ),
! 15: logo => abs_path( 'logo.pdf' ),
! 16: info => [
! 17: 'Visit me online at http://example.com',
! 18: 'Create a new ticket rt@example.com',
! 19: ],
1.4 andrew 20: from => 'Example Company
21:
22: 22115 Central Way
23:
24: Suite C
25:
26: Anytown, America 11111
27:
28: (800) 555-1212
29:
30: \texttt{<company@example.com>}',
31: to => 'John Doe
32:
33: 123 W Main St
34:
35: Anytown, America 11111',
1.1 andrew 36: projects => [
37: {
38: title => 'Weekly Retainer',
39: fees => [
40: {
41: contents => '2011-03-06 through 2011-03-12',
42: count => 1,
43: rate => 300,
44: },
45: {
46: contents => '2011-03-13 through 2011-03-19',
47: count => 1,
48: rate => 300,
49: },
50: ],
51: },
52: {
53: id => 60,
54: title => '60: A Special Project',
1.2 andrew 55: detail => 'Requestors jdoe@example.net',
1.1 andrew 56: fees => [
57: {
58: contents => '2011-01-01: Talk a lot (727)',
1.2 andrew 59: detail => 'This is detail about 727',
1.1 andrew 60: count => 0.33,
61: rate => 75,
62: },
63: {
64: contents => '2011-01-15: Write Stuff (730)',
1.2 andrew 65: detail => 'This is detail about 730',
1.1 andrew 66: count => 1.5,
67: rate => 100,
68: },
69: {
1.3 andrew 70: contents => 'Rounding FAIL',
71: detail => 'Should be $8.30',
72: count => .083,
73: rate => 100,
1.1 andrew 74: },
75: ],
76: },
77: {
78: id => 65,
79: title => '65: More work!',
1.2 andrew 80: detail => 'Requestors jdoe@example.net',
1.1 andrew 81: fees => [
82: {
83: contents => '2011-01-06: Define Project (751)',
84: count => 0.33,
85: rate => 75,
86: },
87: {
88: contents => '2011-01-11: Code it up! (823)',
89: count => 5,
90: rate => 100,
91: },
92: {
1.6 ! afresh1 93: contents => '2011-01-12: Redefine Project (903)',
1.1 andrew 94: count => 0.25,
95: rate => 75,
96: },
97: {
98: contents => '2011-01-13: Change everything: 933',
99: count => 3,
100: rate => 125,
101: },
102: ],
103: },
104: {
105: id => 85,
106: title => '85: Replace stuff',
1.2 andrew 107: detail => 'Requestors maintenance@example.net',
1.1 andrew 108: fees => [
109: {
110: contents => '2011-01-13: Go unplug, replace, replug (834)',
111: count => 2,
112: rate => 125,
113: },
114: ],
115: expenses => [
116: {
117: contents => '2x unbroken thingys',
118: amount => 25,
119: }
120: ],
121: },
122: {
123: id => 90,
124: title => '90: Make a two page invoice',
125: fees => [
126: {
127: contents => '2011-01-13: Add some stuff (834)',
128: count => 2,
129: rate => 125,
130: },
131: ],
132: },
133: ],
1.3 andrew 134: discount => {
135: contents => 'Discount',
136: amount => '8.498',
137: },
1.1 andrew 138: );
1.6 ! afresh1 139:
! 140: foreach my $project (@{ $invoice{projects} || [] }) {
! 141: foreach my $fee (@{ $project->{fees} || [] }) {
! 142: $invoice{total} += $fee->{count} * $fee->{rate};
! 143: }
! 144: foreach my $expense (@{ $project->{expenses} || [] }) {
! 145: $invoice{total} += $expense->{amount};
! 146: }
! 147: }
! 148:
! 149: $invoice{total} -= $invoice{discount}{amount}
! 150: if $invoice{discount};
1.1 andrew 151:
152: my $tt = Template->new;
153:
154: $tt->process( 'invoice.tex.tt', \%invoice, 'invoice.pdf' ) || die $tt->error . "\n";
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>