| version 1.34, 2011/05/07 03:34:17 |
version 1.35, 2011/05/18 20:02:36 |
|
|
| #!/usr/bin/perl |
#!/usr/bin/perl |
| # $AFresh1: rt_invoices.pl,v 1.33 2011/05/07 02:27:34 andrew Exp $ |
# $AFresh1: rt_invoices.pl,v 1.34 2011/05/07 02:34:17 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 $type = exists $hours->{ $fee->{type} } |
my $type = 'unknown'; |
| && $hours->{ $fee->{type} } > 0 ? $fee->{type} : 'default'; |
while ($type && $type ne 'default' ) { |
| |
$type = exists $hours->{ $fee->{type} } |
| |
&& $hours->{ $fee->{type} } > 0 ? $fee->{type} : 'default'; |
| |
|
| next unless exists $hours->{$type} && $hours->{$type} > 0; |
next unless exists $hours->{$type} && $hours->{$type} > 0; |
| |
|
| my $discount_time = 0; |
my $discount_time = 0; |
| if ( $hours->{$type} > $fee->{count} ) { |
if ( $hours->{$type} > $fee->{count} ) { |
| $hours->{$type} -= $fee->{count}; |
$hours->{$type} -= $fee->{count}; |
| $discount_time = $fee->{count}; |
$discount_time = $fee->{count}; |
| } |
} |
| else { |
else { |
| $discount_time = $hours->{$type}; |
$discount_time = $hours->{$type}; |
| $hours->{$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}{$type} += $discount_time; |
$cust->{invoice}->{discount}->{hours}{$type} += $discount_time; |
| |
|
| $type = '' if $type eq 'default'; |
$type = '' if $type eq 'default'; |
| $fee->{detail} = "$discount_time $type Hours Discounted"; |
$fee->{detail} .= " $discount_time $type Hours Discounted"; |
| |
} |
| } |
} |
| } |
} |
| |
|
|
|
| my $c = "Included Hours\n"; |
my $c = "Included Hours\n"; |
| if ( $invoice->{discount}{hours} ) { |
if ( $invoice->{discount}{hours} ) { |
| foreach my $t ( keys %{ $invoice->{discount}{hours} } ) { |
foreach my $t ( keys %{ $invoice->{discount}{hours} } ) { |
| $c .= "\n$invoice->{discount}{hours}{$t} $t hour"; |
my $type = $t eq 'default' ? '' : $t; |
| |
$c .= "\n$invoice->{discount}{hours}{$t} $type hour"; |
| $c .= 's' if $invoice->{discount}{hours}{$t} != 1; |
$c .= 's' if $invoice->{discount}{hours}{$t} != 1; |
| $c .= "\n"; |
$c .= "\n"; |
| } |
} |