[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.40 and 1.41

version 1.40, 2011/12/22 04:52:28 version 1.41, 2011/12/22 05:21:56
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $AFresh1: rt_invoices.pl,v 1.38 2011/06/21 00:20:28 andrew Exp $  # $AFresh1: rt_invoices.pl,v 1.40 2011/12/22 04:52:28 andrew Exp $
 ########################################################################  ########################################################################
 # Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com>  # Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com>
 #  #
Line 84 
Line 84 
         next;          next;
     }      }
   
     next if $cust->{no_invoices};      next if $cust->{no_invoice};
     $cust->{invoice} ||= make_invoice($cust);      $cust->{invoice} ||= make_invoice($cust);
     if ( !$cust->{invoice} ) {      if ( !$cust->{invoice} ) {
         $cust->{no_invoices} = 1;          $cust->{no_invoice} = 1;
         say "$cust->{id} has no open invoices [" . $ticket->id . ']';          say "$cust->{id} has no open invoices [" . $ticket->id . ']';
         next;          next;
     }      }
Line 320 
Line 320 
 sub make_invoice {  sub make_invoice {
     my ($cust) = @_;      my ($cust) = @_;
   
       return if $cust->{no_invoice};
     return unless $cust->{billstart};      return unless $cust->{billstart};
   
     my ($freq) = get_billing_frequency($cust);  
     return if $cust->{billstart}->clone->add($freq) > $cust->{billend};  
   
     my %invoice = ( end => $cust->{billend}->clone->subtract( seconds => 1 ) );      my %invoice = ( end => $cust->{billend}->clone->subtract( seconds => 1 ) );
     $invoice{start} = $cust->{startinvoicedate}->clone      $invoice{start} = $cust->{startinvoicedate}->clone
         if $cust->{startinvoicedate};          if $cust->{startinvoicedate};
Line 612 
Line 610 
     my $day = $cust->{day} || 0;      my $day = $cust->{day} || 0;
     my ( $freq, $day_method ) = get_billing_frequency($cust);      my ( $freq, $day_method ) = get_billing_frequency($cust);
   
     my $billend = DateTime->now( time_zone => 'local' )      my $end = DateTime->now( time_zone => 'local' )
         ->set( hour => 0, minute => 0, second => 0 );          ->set( hour => 0, minute => 0, second => 0 );
   
     my $date = $billend->clone->subtract($freq);      my $start = $end->clone->subtract($freq);
   
     # XXX This is helpful, but monthly and billday > 28 == !!!      # XXX This is helpful, but monthly and billday > 28 == !!!
     $billend->subtract( days => 1 )      $end->subtract( days => 1 )
         while $day && $billend->$day_method != $day;          while $day && $end->$day_method != $day;
   
     $cust->{billend} = $billend;  
   
     my $lastinvoice = $state->last_invoice( $cust->{id} );      my $lastinvoice = $state->last_invoice( $cust->{id} );
     if ( $lastinvoice && $lastinvoice->{end} ) {      if ( $lastinvoice && $lastinvoice->{end} ) {
         $date = ymd_to_DateTime( $lastinvoice->{end} )->add( days => 1 );          $start = ymd_to_DateTime( $lastinvoice->{end} )->add( days => 1 );
         $cust->{startinvoicedate} = $date->clone;          $cust->{startinvoicedate} = $start->clone;
     }      }
   
     $cust->{billstart} = $date;      $cust->{no_invoice} = 1 if $start->clone->add($freq) > $end;
       $cust->{billend}    = $end;
       $cust->{billstart}  = $start;
 }  }

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

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