=================================================================== RCS file: /cvs/RT/Invoicing/rt_invoices.pl,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- RT/Invoicing/rt_invoices.pl 2011/03/22 05:06:05 1.17 +++ RT/Invoicing/rt_invoices.pl 2011/03/22 05:55:27 1.18 @@ -20,12 +20,12 @@ use 5.010; -use YAML::Any; use Template; use RT::Client::REST; use RT::Client::REST::Ticket; use RT::Client::REST::User; +use File::Path; use DateTime; my $config = RTI::Config->new(); @@ -176,7 +176,7 @@ $invoice->{to} = make_address( $cust->{address} || $custid ); $state->{lastinvoice}++; - $invoice->{id} = $state->{lastinvoice}; + $invoice->{id} = $state->{lastinvoice}; $invoice->{file} = sprintf 'invoice_%06d.pdf', $state->{lastinvoice}; foreach my $k (qw/ file transactions start end total past_due total_due /) @@ -201,8 +201,13 @@ $invoice->{$key} = $invoice->{$key}->strftime('%B %d, %Y'); } } + + my $invoice_dir = $config->get('invoice_dir'); + File::Path::make_path($invoice_dir); + my $file = join '/', $invoice_dir, $invoice->{file}; + my $tt = Template->new; - $tt->process( 'invoice.tex.tt', $invoice, $invoice->{file} ) + $tt->process( 'invoice.tex.tt', $invoice, $file ) or die $tt->error . "\n"; printf "Generated %s for %s: \$%.02f\n", $invoice->{file}, $custid, @@ -611,13 +616,19 @@ sub get { my ( $self, $key ) = @_; my $value = Load( Dump( $self->{_config}->{$key} ) ); - if ( !$value ) { - given ($key) { - when ('state') { - $value = dirname( $self->{file} ) . '/rt_invoice.state' - } + + return $value if $value; + + given ($key) { + when ('state') { + $value = $self->{file}; + $value =~ s/(?:\.[^.]+)?$/\.state/; } + when ('invoice_dir') { + $value = dirname( $self->{file} ) . '/invoices'; + } } + return $value; }