=================================================================== RCS file: /cvs/RT/Invoicing/lib/RTI/State.pm,v retrieving revision 1.3 retrieving revision 1.7 diff -u -r1.3 -r1.7 --- RT/Invoicing/lib/RTI/State.pm 2011/12/31 02:14:48 1.3 +++ RT/Invoicing/lib/RTI/State.pm 2012/11/28 02:24:04 1.7 @@ -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} ) { @@ -133,6 +151,12 @@ else { delete $invoice->{$k}; } + } + } + 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: $!";