[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.32 and 1.33

version 1.32, 2011/05/07 02:09:43 version 1.33, 2011/05/07 03:27:34
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $AFresh1: rt_invoices.pl,v 1.31 2011/05/07 01:03:55 andrew Exp $  #  $AFresh1: rt_invoices.pl,v 1.32 2011/05/07 01:09:43 andrew Exp $
 ########################################################################  ########################################################################
 # Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com>  # Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com>
 #  #
Line 76 
Line 76 
   
 my $iterator = $results->get_iterator;  my $iterator = $results->get_iterator;
 while ( my $ticket = &$iterator ) {  while ( my $ticket = &$iterator ) {
     if ( !$ticket->time_worked ) {  
         say "Ticket " . $ticket->id . " has no time worked";  
         next;  
     }  
   
     my $cust = find_customer_for_ticket($ticket);      my $cust = find_customer_for_ticket($ticket);
     if ( !$cust ) {      if ( !$cust ) {
         warn "No customer found for ticket " . $ticket->id;          warn "No customer found for ticket " . $ticket->id;
Line 136 
Line 131 
     my %li = (      my %li = (
         custid  => $cust->{id},          custid  => $cust->{id},
         invdate => DateTime->now( time_zone => 'local' )->ymd,          invdate => DateTime->now( time_zone => 'local' )->ymd,
           transactions => [],
     );      );
   
       my %transactions;
     foreach my $project ( @{ $invoice->{projects} } ) {      foreach my $project ( @{ $invoice->{projects} } ) {
         if ( $project->{transactions} ) {          if ( $project->{transactions} ) {
             push @{ $li{transactions} }, @{ $project->{transactions} };              %transactions = ( %transactions, %{ $project->{transactions} } );
         }          }
         my $subtotal = 0;          my $subtotal = 0;
         foreach my $fee ( @{ $project->{fees} } ) {          foreach my $fee ( @{ $project->{fees} } ) {
Line 153 
Line 150 
         $project->{total} = $subtotal;          $project->{total} = $subtotal;
         $invoice->{total} += $subtotal;          $invoice->{total} += $subtotal;
     }      }
       @{ $li{transactions} } = sort { $a <=> $b } keys %transactions;
   
     if ( $invoice->{discount} ) {      if ( $invoice->{discount} ) {
         my $c = "Included Hours\n";          my $c = "Included Hours\n";
Line 469 
Line 467 
     my $txns = $ticket->transactions( type => [qw(Comment Correspond)] );      my $txns = $ticket->transactions( type => [qw(Comment Correspond)] );
     my $txn_i = $txns->get_iterator;      my $txn_i = $txns->get_iterator;
     while ( my $txn = $txn_i->() ) {      while ( my $txn = $txn_i->() ) {
         next unless $txn->time_taken;  
         next if $state->txn_is_invoiced( $txn->id );          next if $state->txn_is_invoiced( $txn->id );
   
           if (my $expense = make_expense( $txn, $ticket ) ) {
               push @{ $project{expenses} }, $expense;
               $project{transactions}{ $txn->id } = 1;
           }
   
           next unless $txn->time_taken;
   
         my $fee = make_fee( $txn, $cust->{rates}, $ticket );          my $fee = make_fee( $txn, $cust->{rates}, $ticket );
   
         if ( !( $fee->{rate} && $fee->{count} ) ) {          if ( !( $fee->{rate} && $fee->{count} ) ) {
Line 490 
Line 494 
         next if $invoice->{end} < $fee->{date};          next if $invoice->{end} < $fee->{date};
   
         push @{ $project{fees} },         $fee;          push @{ $project{fees} },         $fee;
         push @{ $project{transactions} }, $txn->id;          $project{transactions}{ $txn->id } = 1;
     }      }
   
     return \%project;      return \%project;
Line 520 
Line 524 
     }      }
   
     return \%fee;      return \%fee;
   }
   
   sub make_expense {
       my ( $txn, $ticket ) = @_;
   
       my $amount = $txn->cf('ExpenseAmount') or return;
   
       my %expense = (
           id       => $txn->id,
           contents => $txn->created . ' ('
               . $txn->id . ')' . "\n\n"
               . ( $txn->data || $ticket->subject ),
           amount => $amount,
           date   => ymd_to_DateTime( $txn->created ),
           # detail => ???,
       );
   
       return \%expense;
 }  }
   
 sub hours_for_date {  sub hours_for_date {

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.33

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