]> git.donarmstrong.com Git - bin.git/blob - latexize_invoice
add reset usb bus command
[bin.git] / latexize_invoice
1 #!/usr/bin/perl
2
3 #* Saturday, July 22, 2006 19:41:14 PDT - Saturday, July 22, 2006 20:13:23 PDT [0.54] [0.54]
4 #  - Set up dns slave/master between alpha and beta
5
6 #         \Fee{\begin{itemize*}
7 #           \item setting up rsyncd.conf to sync home directories
8 #           \item running a test rsync
9 #           \item add back missing accounts
10 #           \end{itemize*}
11 #         }{50.00}{0.94}
12
13 use warnings;
14 use strict;
15
16 use Params::Validate qw(validate_with :types);
17
18
19 my $time = undef;
20 my $date = undef;
21
22 my $hourly_rate = 50.00;
23
24 my $total = 0;
25
26 my @events;
27 print<<'EOF';
28 \setlength\LTleft{0pt plus 1fill minus 1fill}%
29 \let\LTright\LTleft
30 \begin{longtable}{|p{9cm}|r|r|r|r|}%
31 %  \caption*{}
32 \hline
33   Description & Item Cost & Quantity & Cost & Total \\
34 EOF
35
36 while (<>){
37      if (/^\s*\*\s*([^-]+)\s+-.+\[([^\]]+)\]\s*\[[^\]]+\]/) {
38           if (defined $time) {
39                print format_events(date => $date,
40                                    time => $time,
41                                    total => \$total,
42                                    events => \@events);
43           }
44           @events = ();
45           $date = $1;
46           $time = $2;
47      }
48      if (/^\s+\-\s*(.+)/) {
49           my $event = $1;
50           chomp $event;
51           push @events, $event;
52      }
53 }
54 if (defined $time) {
55     print format_events(date => $date,
56                         time => $time,
57                         total => \$total,
58                         events => \@events);
59 }
60
61 sub format_events{
62      my %param = validate_with(params => \@_,
63                                spec   => {time => {type => SCALAR,
64                                                   },
65                                           date => {type => SCALAR,
66                                                   },
67                                           total => {type => SCALARREF,
68                                                    },
69                                           events => {type => ARRAYREF,
70                                                     },
71                                          },
72                               );
73      ${$param{total}} += $param{time} * $hourly_rate;
74
75      $param{date} =~ s/\s+\d+\:\d+\:\d+\s+[A-Z]{0,3}\s*//;
76      my $output = '\hline'."\n".'        \mbox{'.$param{date}."}\n\n".
77          '         \begin{itemize*}'."\n";
78      $output .= join('',map {"           \\item $_\n"} @{$param{events}});
79      $output .= '         \end{itemize*} & \$'.sprintf('%.2f',$hourly_rate).' & '.sprintf('%.2f',$param{time}).
80          ' & \$'.sprintf('%.2f',$param{time}*$hourly_rate).' & \$'.
81              sprintf('%.2f',${$param{total}}) .
82                  ' \\'."\n";
83      return $output;
84 }
85 print<<'EOF';
86 \hline\hline
87 \multicolumn{4}{|r|}{\textbf{Total}} & \$%
88 EOF
89 print sprintf('%.2f',$total)."%\n";
90 print<<'EOF';
91 \\
92 \hline
93 \end{longtable}
94 EOF