[BACK]Return to rt_invoices.pl CVS log [TXT][DIR] Up to [local] / RT / Invoicing

Diff for /RT/Invoicing/rt_invoices.pl between version 1.41 and 1.42

version 1.41, 2011/12/22 05:21:56 version 1.42, 2011/12/30 03:20:45
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $AFresh1: rt_invoices.pl,v 1.40 2011/12/22 04:52:28 andrew Exp $  # $AFresh1: rt_invoices.pl,v 1.41 2011/12/22 05:21:56 andrew Exp $
 ########################################################################  ########################################################################
 # Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com>  # Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com>
 #  #
Line 174 
Line 174 
         $invoice->{total} -= round( $invoice->{discount}{amount} );          $invoice->{total} -= round( $invoice->{discount}{amount} );
     }      }
   
     $invoice->{past_due} = 0;  
     if (my $unpaid_invoices = $state->unpaid_invoices($cust->{id})) {      if (my $unpaid_invoices = $state->unpaid_invoices($cust->{id})) {
         my %project = ( title => 'Unpaid Invoices', fees => [], );          my %project = ( title => 'Unpaid Invoices', fees => [], );
           my $past_due = 0;
   
         foreach my $id ( sort { $a <=> $b } keys %{$unpaid_invoices} ) {          foreach my $id ( sort { $a <=> $b } keys %{$unpaid_invoices} ) {
             my $unpaid = $state->get_invoice($id);              my $unpaid = $state->get_invoice($id);
             $invoice->{past_due} += $unpaid_invoices->{$id};              my $invdate = ymd_to_DateTime( $unpaid->{invdate} );
   
               next
                   if $cust->{duedate}
                   && DateTime->compare( $invdate, $cust->{duedate} ) > 0;
   
               $past_due += $unpaid_invoices->{$id};
             push @{ $project{fees} }, {              push @{ $project{fees} }, {
                 id       => $id,                  id       => $id,
                 contents => sprintf(                  contents => sprintf(
                     "Invoice %06d from %s",                      "Invoice %06d from %s",
                     $id, ymd_to_DateTime( $unpaid->{invdate} )->ymd                      $id, $invdate->ymd
                 ),                  ),
                 count => 1,                  count => 1,
                 rate  => $unpaid_invoices->{$id},                  rate  => $unpaid_invoices->{$id},
             };              };
         }          }
         unshift @{ $invoice->{projects} }, \%project;  
     }  
   
     if ( $invoice->{past_due} ) {          if ($past_due) {
         $invoice->{total_due} = $invoice->{total} + $invoice->{past_due};              $invoice->{past_due}  = $past_due;
               $invoice->{total_due} = $invoice->{total} + $invoice->{past_due};
   
               unshift @{ $invoice->{projects} }, \%project;
           }
     }      }
   
     next unless $invoice->{total} > 0 || $invoice->{total_due};      next unless $invoice->{total} > 0 || $invoice->{total_due};
Line 624 
Line 632 
         $start = ymd_to_DateTime( $lastinvoice->{end} )->add( days => 1 );          $start = ymd_to_DateTime( $lastinvoice->{end} )->add( days => 1 );
         $cust->{startinvoicedate} = $start->clone;          $cust->{startinvoicedate} = $start->clone;
     }      }
   
       $cust->{duedate}
           = $cust->{net}
           ? DateTime->now->subtract( days => $cust->{net} )
           : 0;
   
     $cust->{no_invoice} = 1 if $start->clone->add($freq) > $end;      $cust->{no_invoice} = 1 if $start->clone->add($freq) > $end;
     $cust->{billend}    = $end;      $cust->{billend}    = $end;

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.42

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>