version 1.12, 2011/03/22 01:46:41 |
version 1.14, 2011/03/22 02:37:14 |
|
|
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 = ( end => DateTime->now, ); |
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; |
|
|
|
|
default { die "Unknown per [$cust->{per}]\n" } |
default { die "Unknown per [$cust->{per}]\n" } |
} |
} |
|
|
my $billends |
my $billends = $invoice->{end}->clone; |
= DateTime->now->set( hour => 0, minute => 0, second => 0 ); |
|
$billends->subtract( days => 1 ) while $billends->$day_method != $day; |
$billends->subtract( days => 1 ) while $billends->$day_method != $day; |
|
|
my $date = $billends->clone->subtract( $per => $freq ); |
my $date = $billends->clone->subtract( $per => $freq ); |
|
|
next if $end < $start; |
next if $end < $start; |
|
|
$startdate = $start->clone if !$startdate || $startdate > $start; |
$startdate = $start->clone if !$startdate || $startdate > $start; |
$invoice{start} ||= $start->clone; |
$invoice->{start} ||= $start->clone; |
$invoice{end} = $end->clone; |
$invoice->{end} = $end->clone; |
my %hours = ( |
my %hours = ( |
start => $start->clone, |
start => $start->clone, |
end => $end->clone, |
end => $end->clone, |
hours => { %{ $cust->{hours} } }, |
hours => { %{ $cust->{hours} } }, |
); |
); |
|
|
push @{ $invoice{hours} }, \%hours; |
push @{ $invoice->{hours} }, \%hours; |
push @{ $project{fees} }, |
push @{ $project{fees} }, |
{ |
{ |
count => 1, |
count => 1, |
|
|
} |
} |
|
|
if ( @{ $project{fees} } ) { |
if ( @{ $project{fees} } ) { |
push @{ $invoice{projects} }, \%project; |
push @{ $invoice->{projects} }, \%project; |
} |
} |
} |
} |
|
|
$cust->{address} ||= get_user($custid); |
$cust->{address} ||= get_user($custid); |
$cust->{invoice} = \%invoice; |
$cust->{invoice} = $invoice; |
} |
} |
|
|
my @limits = map +{ |
my @limits = map +{ |
|
|
} |
} |
|
|
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'; |
|
|
my $cust = $config->get('default') || {}; |
my $cust = $config->get('default') || {}; |
$cust->{address} = get_user($custid); |
$cust->{address} = get_user($custid); |
|
|
my %invoice = ( end => DateTime->now ); |
$cust->{match} = [ |
|
{ type => 'requestors', |
|
regex => $custid, |
|
} |
|
]; |
|
|
|
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} ) ) { |
$cust->{invoice} = \%invoice; |
$cust->{invoice} = $invoice; |
} |
} |
|
|
$customers->{$custid} = $cust; |
$customers->{$custid} = $cust; |
|
|
|
|
$users{$id} = \%user; |
$users{$id} = \%user; |
return \%user; |
return \%user; |
|
} |
|
|
|
sub make_invoice { |
|
my ($cust) = @_; |
|
|
|
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; |
} |
} |
|
|
sub make_address { |
sub make_address { |