[BACK]Return to State.pm CVS log [TXT][DIR] Up to [local] / RT / Invoicing / lib / RTI

Diff for /RT/Invoicing/lib/RTI/State.pm between version 1.2 and 1.3

version 1.2, 2011/12/30 05:01:56 version 1.3, 2011/12/31 02:14:48
Line 2 
Line 2 
 use strict;  use strict;
 use warnings;  use warnings;
   
 use Carp;  use 5.010;
   
 use DateTime;  use DateTime;
   use Carp;
   
 use 5.010;  
   
 use YAML::Any qw/ LoadFile DumpFile /;  use YAML::Any qw/ LoadFile DumpFile /;
   use RTI::Util qw/ ymd_to_DateTime /;
   
 my $file = '';  my $file = '';
   
Line 23 
Line 23 
         $self->{lastinvoice} ||= 0;          $self->{lastinvoice} ||= 0;
         while ( my ( $id, $invoice ) = each %{ $self->{invoice} } ) {          while ( my ( $id, $invoice ) = each %{ $self->{invoice} } ) {
             $self->{lastinvoice} = $id if $self->{lastinvoice} < $id;              $self->{lastinvoice} = $id if $self->{lastinvoice} < $id;
   
             $invoice->{id} = $id;              $invoice->{id} = $id;
               $invoice->{$_} = ymd_to_DateTime( $invoice->{$_} )
                   for qw/ invdate start end /;
         }          }
     }      }
   
Line 48 
Line 51 
         if exists $self->{invoice}->{$id};          if exists $self->{invoice}->{$id};
   
     $invoice->{id} ||= $id;      $invoice->{id} ||= $id;
     $invoice->{invdate} ||= DateTime->now( time_zone => 'local' )->ymd,      $invoice->{invdate} ||= DateTime->now( time_zone => 'local' ),
   
         $self->{lastinvoice} = $id if $self->{lastinvoice} < $id;          $self->{lastinvoice} = $id if $self->{lastinvoice} < $id;
   
     my %li;      $self->{invoice}->{$id} = $invoice;
     foreach my $k (  
         qw/  
         id custid  
         file transactions  
         invdate start end  
         total past_due total_due  
         /  
         )  
     {  
         my $v = $invoice->{$k};  
   
         if ( defined $v && length $v ) {  
             if ( ref $v eq 'DateTime' ) {  
                 $li{$k} = $v->ymd;  
             }  
             else {  
                 $li{$k} = $v;  
             }  
         }  
     }  
   
     $self->{invoice}->{ $self->{lastinvoice} } = \%li;  
     delete $self->{_tables};      delete $self->{_tables};
   
     return $self->{lastinvoice};      return $self->{lastinvoice};
 }  }
   
 sub get_invoice{  sub get_invoice {
     my ( $self, $id ) = @_;      my ( $self, $id ) = @_;
     return $self->{invoice}->{$id};      return $self->{invoice}->{$id};
 }  }
Line 102 
Line 83 
   
 sub txn_is_invoiced {  sub txn_is_invoiced {
     my ( $self, $txn ) = @_;      my ( $self, $txn ) = @_;
   
     if ( !$self->{_table}->{txn} ) {      if ( !$self->{_table}->{txn} ) {
         my $invoices = $self->{invoice};          my $invoices = $self->{invoice};
         foreach my $id ( sort { $a <=> $b } keys %{$invoices} ) {          foreach my $id ( sort { $a <=> $b } keys %{$invoices} ) {
Line 116 
Line 97 
 }  }
   
 sub unpaid_invoices {  sub unpaid_invoices {
     my ($self, $custid) = @_;      my ( $self, $custid ) = @_;
   
     $self->_match_payments;      $self->_match_payments;
     return defined $custid      return defined $custid
Line 130 
Line 111 
     delete $self->{_table};      delete $self->{_table};
     delete $self->{lastinvoice};      delete $self->{lastinvoice};
     foreach my $invoice ( values %{ $self->{invoice} } ) {      foreach my $invoice ( values %{ $self->{invoice} } ) {
         delete $invoice->{id};          delete $invoice->{$_} for qw/
               id
               from
               to
               info
               logo
               projects
               expenses
               discounts
               /;
   
           foreach my $k ( keys %{$invoice} ) {
               my $v = $invoice->{$k};
   
               if ( defined $v && length $v ) {
                   if ( ref $v eq 'DateTime' ) {
                       $invoice->{$k} = $v->ymd;
                   }
               }
               else {
                   delete $invoice->{$k};
               }
           }
     }      }
     DumpFile( $file, {%$self} ) or die "Unable to save state: $!";      DumpFile( $file, {%$self} ) or die "Unable to save state: $!";
 }  }
Line 141 
Line 144 
     return if $self->{_table}{credit} && $self->{_table}{unpaid};      return if $self->{_table}{credit} && $self->{_table}{unpaid};
   
     my $invoices = $self->{invoice};      my $invoices = $self->{invoice};
     my %owes = map { $_ => $invoices->{$_}->{total} } keys %{ $invoices };      my %owes = map { $_ => $invoices->{$_}->{total} } keys %{$invoices};
   
     my %credit;      my %credit;
   
Line 177 
Line 180 
     }      }
   
     foreach my $id ( sort { $b <=> $a } keys %owes ) {      foreach my $id ( sort { $b <=> $a } keys %owes ) {
         my $i      = $invoices->{$id};          my $i = $invoices->{$id};
         my $custid = $i->{custid} or next;          my $custid = $i->{custid} or next;
   
         my $owes = sprintf "%0.2f", $owes{$id}       || 0;          my $owes = sprintf "%0.2f", $owes{$id}       || 0;
Line 201 
Line 204 
         if ($paid) {          if ($paid) {
             $credit{$custid} = $paid;              $credit{$custid} = $paid;
         }          }
         elsif (exists $credit{$custid}) {          elsif ( exists $credit{$custid} ) {
             delete $credit{$custid};              delete $credit{$custid};
         }          }
     }      }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

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