=================================================================== RCS file: /cvs/RT/Invoicing/lib/RTI/State.pm,v retrieving revision 1.3 retrieving revision 1.8 diff -u -r1.3 -r1.8 --- RT/Invoicing/lib/RTI/State.pm 2011/12/31 02:14:48 1.3 +++ RT/Invoicing/lib/RTI/State.pm 2012/11/28 02:25:13 1.8 @@ -7,7 +7,8 @@ use DateTime; use Carp; -use YAML::Any qw/ LoadFile DumpFile /; +use YAML::XS qw/ LoadFile DumpFile /; +$YAML::XS::QuoteNumericStrings = 0; use RTI::Util qw/ ymd_to_DateTime /; my $file = ''; @@ -28,6 +29,12 @@ $invoice->{$_} = ymd_to_DateTime( $invoice->{$_} ) for qw/ invdate start end /; } + foreach my $custid (keys %{ $self->{payment} || {} }) { + foreach my $payment (@{ $self->{payment}->{$custid} || [] }) { + $payment->{date} = ymd_to_DateTime( $payment->{date} ) + if $payment->{date}; + } + } } bless $self, $class; @@ -105,6 +112,15 @@ : $self->{_table}->{unpaid}; } +sub credits { + my ( $self, $custid ) = @_; + + $self->_match_payments; + return defined $custid + ? $self->{_table}->{credit}->{$custid} + : $self->{_table}->{credit}; +} + sub save { my ($self) = @_; @@ -119,7 +135,9 @@ logo projects expenses - discounts + discount + hours + organization /; foreach my $k ( keys %{$invoice} ) { @@ -135,6 +153,12 @@ } } } + foreach my $custid (keys %{ $self->{payment} || {} }) { + foreach my $payment (@{ $self->{payment}->{$custid} || [] }) { + $payment->{date} = $payment->{date}->ymd + if ref $payment->{date} eq 'DateTime'; + } + } DumpFile( $file, {%$self} ) or die "Unable to save state: $!"; } @@ -179,7 +203,7 @@ delete $credit{$custid} unless $credit{$custid}; } - foreach my $id ( sort { $b <=> $a } keys %owes ) { + foreach my $id ( sort { $a <=> $b } keys %owes ) { my $i = $invoices->{$id}; my $custid = $i->{custid} or next;