Annotation of RT/Invoicing/fix_state, Revision 1.1
1.1 ! andrew 1: #!/usr/bin/perl
! 2: # $AFresh1$
! 3: use strict;
! 4: use warnings;
! 5:
! 6: # Converts a rt_invoices.state v1.38 or earler to a newer file
! 7:
! 8: use YAML::Any qw/ LoadFile DumpFile Dump /;
! 9:
! 10: my $state = LoadFile('rt_invoice.state');
! 11:
! 12: my %payments;
! 13: my %invoices;
! 14: while (my ($date, $invoices) = each %{ $state->{invoice } }) {
! 15: while (my ($id, $invoice) = each %{ $invoices }) {
! 16: $invoice->{invdate} ||= $date;
! 17: update_payment($id, $invoice) if $invoice->{paid};
! 18: $invoices{$id} = $invoice;
! 19: }
! 20: }
! 21:
! 22: $state->{invoice} = \%invoices;
! 23: $state->{payment} = \%payments;
! 24: #print Dump $state;
! 25: DumpFile('rt_invoice.state', $state);
! 26:
! 27:
! 28: sub update_payment{
! 29: my ($id, $i) = @_;
! 30:
! 31: $payments{$i->{custid}} ||= [];
! 32: my $payments = $payments{ $i->{custid} };
! 33:
! 34: my $p = { invoices => [] };
! 35: my $new_payment = 1;
! 36: if ($i->{check}) {
! 37: foreach my $payment (@{ $payments }) {
! 38: if ($payment->{number} && $i->{check} == $payment->{number}) {
! 39: $new_payment = 0;
! 40: $p = $payment;
! 41: last;
! 42: }
! 43: }
! 44: $p->{type} = 'check';
! 45: $p->{number} = delete $i->{check};
! 46: }
! 47: if ($new_payment) {
! 48: $p->{paid} = 0;
! 49: push @{ $payments }, $p;
! 50: }
! 51: $p->{date} = delete $i->{pmt_date};
! 52: $p->{paid} += delete $i->{paid};
! 53: push @{ $p->{invoices} }, $id;
! 54: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>