version 1.13, 2011/03/22 02:16:53 |
version 1.15, 2011/03/22 02:41:43 |
|
|
my $customers = $config->get('customers'); |
my $customers = $config->get('customers'); |
CUSTOMER: while ( my ( $custid, $cust ) = each %{$customers} ) { |
CUSTOMER: while ( my ( $custid, $cust ) = each %{$customers} ) { |
|
|
my $invoice = make_invoice(); |
my $invoice = make_invoice($cust); |
|
|
if ( $cust->{base_rate} ) { |
if ( $cust->{base_rate} ) { |
|
$invoice->{hours} = []; |
my $day = $cust->{day} || 1; |
my $day = $cust->{day} || 1; |
my $freq = $cust->{frequency} || 1; |
my $freq = $cust->{frequency} || 1; |
|
|
|
|
} |
} |
} |
} |
|
|
$cust->{address} ||= get_user($custid); |
|
$cust->{invoice} = $invoice; |
$cust->{invoice} = $invoice; |
} |
} |
|
|
|
|
} |
} |
|
|
if ($discount_time) { |
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; |
$invoice->{discount}{hours}{$h_type} += $discount_time; |
|
|
$h_type = '' if $h_type eq 'default'; |
$h_type = '' if $h_type eq 'default'; |
|
|
|
|
next unless $invoice->{total} > 0 || $invoice->{total_due}; |
next unless $invoice->{total} > 0 || $invoice->{total_due}; |
|
|
# XXX Here we need to "make_address" |
|
$invoice->{info} = $config->get('info'); |
$invoice->{info} = $config->get('info'); |
$invoice->{from} = make_address( $config->get('from') ); |
$invoice->{from} = make_address( $config->get('from') ); |
$invoice->{to} = make_address( $cust->{address} ); |
$invoice->{to} = make_address( $cust->{address} || get_user($custid) ); |
|
|
$state->{lastinvoice}++; |
$state->{lastinvoice}++; |
$invoice->{id} = $state->{lastinvoice}; |
$invoice->{id} = $state->{lastinvoice}; |
|
|
return unless $custid; |
return unless $custid; |
|
|
my $cust = $config->get('default') || {}; |
my $cust = $config->get('default') || {}; |
$cust->{address} = get_user($custid); |
|
|
|
$cust->{match} = [{ |
$cust->{match} = [ |
type => 'requestors', |
{ type => 'requestors', |
regex => $custid, |
regex => $custid, |
}]; |
} |
|
]; |
|
|
my $invoice = make_invoice(); |
my $invoice = make_invoice($cust); |
|
|
my $lastinvoice = $state->last_invoice($custid); |
my $lastinvoice = $state->last_invoice($custid); |
if ( $lastinvoice->{date} ) { |
if ( $lastinvoice->{date} ) { |
my $last_invoice_date = ymd_to_DateTime( $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} ) ) { |
if ( !( $invoice->{start} && $invoice->{start} < $invoice->{end} ) ) { |
|
|
} |
} |
|
|
sub make_invoice { |
sub make_invoice { |
|
my ($cust) = @_; |
|
|
my $billends |
my $billends = DateTime->now->set( hour => 0, minute => 0, second => 0 ) |
= DateTime->now->set( hour => 0, minute => 0, second => 0 ); |
->clone->subtract( days => 1, seconds => 1 ); |
my %invoice = ( end => $billends->clone->subtract( days => 1, seconds => 1 ) ); |
|
|
my %invoice = ( end => $billends ); |
|
|
|
if ( $cust && $cust->{hours} ) { |
|
$invoice{hours} = [ |
|
{ end => $billends, |
|
hours => $cust->{hours}, |
|
} |
|
]; |
|
} |
|
|
return \%invoice; |
return \%invoice; |
} |
} |