version 1.29, 2011/05/03 05:38:56 |
version 1.31, 2011/05/07 02:03:55 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $AFresh1: rt_invoices.pl,v 1.28 2011/04/19 03:35:12 andrew Exp $ |
# $AFresh1: rt_invoices.pl,v 1.30 2011/05/03 04:41:11 andrew Exp $ |
######################################################################## |
######################################################################## |
# Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com> |
# Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com> |
# |
# |
|
|
foreach my $fee ( @{ $project->{fees} } ) { |
foreach my $fee ( @{ $project->{fees} } ) { |
my $hours = hours_for_date( $cust->{invoice}, $fee->{date} ); |
my $hours = hours_for_date( $cust->{invoice}, $fee->{date} ); |
|
|
my $h_type |
my $type = exists $hours->{ $fee->{type} } |
= exists $hours->{ $fee->{type} } |
&& $hours->{ $fee->{type} } > 0 ? $type : 'default'; |
? $fee->{type} |
|
: 'default'; |
|
|
|
next unless exists $hours->{$h_type} && $hours->{$h_type} > 0; |
next unless exists $hours->{$type} && $hours->{$type} > 0; |
|
|
my $discount_time = 0; |
my $discount_time = 0; |
if ( $hours->{$h_type} > $fee->{count} ) { |
if ( $hours->{$type} > $fee->{count} ) { |
$hours->{$h_type} -= $fee->{count}; |
$hours->{$type} -= $fee->{count}; |
$discount_time = $fee->{count}; |
$discount_time = $fee->{count}; |
} |
} |
else { |
else { |
$discount_time = $hours->{$h_type}; |
$discount_time = $hours->{$type}; |
$hours->{$h_type} = 0; |
$hours->{$type} = 0; |
} |
} |
|
|
if ($discount_time) { |
if ($discount_time) { |
$cust->{invoice}->{discount}->{amount} |
$cust->{invoice}->{discount}->{amount} |
+= round( $discount_time * $fee->{rate} ); |
+= round( $discount_time * $fee->{rate} ); |
$cust->{invoice}->{discount}->{hours}{$h_type} += $discount_time; |
$cust->{invoice}->{discount}->{hours}{$type} += $discount_time; |
|
|
$h_type = '' if $h_type eq 'default'; |
$type = '' if $type eq 'default'; |
$fee->{detail} = "$discount_time $h_type Hours Discounted"; |
$fee->{detail} = "$discount_time $type Hours Discounted"; |
} |
} |
} |
} |
|
|
|
|
} |
} |
|
|
# Is the start date more than $freq $per before the end date? |
# Is the start date more than $freq $per before the end date? |
my $diff = $billend - $date; |
return {} |
return {} if $diff->in_units($per) < 1; |
if DateTime->compare( $date->clone->add( $per => $freq ), $billend ) |
|
> 0; |
|
|
if ( $cust->{base_rate} ) { |
if ( $cust->{base_rate} ) { |
my ( $project, $hours ) = make_base_project( |
my ( $project, $hours ) = make_base_project( |