=================================================================== RCS file: /cvs/RT/Invoicing/rt_invoices.pl,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- RT/Invoicing/rt_invoices.pl 2011/03/22 02:16:53 1.13 +++ RT/Invoicing/rt_invoices.pl 2011/03/22 02:37:14 1.14 @@ -47,9 +47,10 @@ my $customers = $config->get('customers'); CUSTOMER: while ( my ( $custid, $cust ) = each %{$customers} ) { - my $invoice = make_invoice(); + my $invoice = make_invoice($cust); if ( $cust->{base_rate} ) { + $invoice->{hours} = []; my $day = $cust->{day} || 1; my $freq = $cust->{frequency} || 1; @@ -188,7 +189,8 @@ } if ($discount_time) { - $invoice->{discount}{amount} += $discount_time * $fee->{rate}; + $invoice->{discount}{amount} + += round($discount_time * $fee->{rate}); $invoice->{discount}{hours}{$h_type} += $discount_time; $h_type = '' if $h_type eq 'default'; @@ -326,17 +328,18 @@ my $cust = $config->get('default') || {}; $cust->{address} = get_user($custid); - $cust->{match} = [{ - type => 'requestors', + $cust->{match} = [ + { type => 'requestors', regex => $custid, - }]; + } + ]; - my $invoice = make_invoice(); + my $invoice = make_invoice($cust); my $lastinvoice = $state->last_invoice($custid); if ( $lastinvoice->{date} ) { my $last_invoice_date = ymd_to_DateTime( $lastinvoice->{date} ); - $invoice->{start} = $last_invoice_date->clone->add( days => 1 ); + $invoice->{start} = $last_invoice_date->clone->add( days => 1 ); } if ( !( $invoice->{start} && $invoice->{start} < $invoice->{end} ) ) { @@ -381,10 +384,20 @@ } sub make_invoice { + my ($cust) = @_; - my $billends - = DateTime->now->set( hour => 0, minute => 0, second => 0 ); - my %invoice = ( end => $billends->clone->subtract( days => 1, seconds => 1 ) ); + my $billends = DateTime->now->set( hour => 0, minute => 0, second => 0 ) + ->clone->subtract( days => 1, seconds => 1 ); + + my %invoice = ( end => $billends ); + + if ( $cust && $cust->{hours} ) { + $invoice{hours} = [ + { end => $billends, + hours => $cust->{hours}, + } + ]; + } return \%invoice; }