diff options
Diffstat (limited to 'LedgerSMB')
-rw-r--r-- | LedgerSMB/Batch.pm | 18 | ||||
-rw-r--r-- | LedgerSMB/DBObject.pm | 32 | ||||
-rw-r--r-- | LedgerSMB/DBObject/Payment.pm | 22 |
3 files changed, 62 insertions, 10 deletions
diff --git a/LedgerSMB/Batch.pm b/LedgerSMB/Batch.pm index 5c948f79..28be86f7 100644 --- a/LedgerSMB/Batch.pm +++ b/LedgerSMB/Batch.pm @@ -6,10 +6,26 @@ use base qw(LedgerSMB::DBObject); sub create { $self = shift @_; my ($ref) = $self->exec_method(funcname => 'batch_create'); - print STDERR "$ref, $ref->{batch_create}, " . join (':', keys %$ref); $self->{id} = $ref->{batch_create}; $self->{dbh}->commit; return $ref->{id}; } +sub get_search_criteria { + $self = shift @_; + @{$self->{batch_classes}} = $self->exec_method( + funcname => 'batch_list_classes' + ); + + @{$self->{batch_users}} = $self->exec_method( + funcname => 'batch_get_users' + ); +} + +sub get_search_results { + my ($self) = @_; + @{$self->{search_results}} = $self->exec_method(funcname => 'batch_search'); + return @{$self->{search_results}}; +} + 1; diff --git a/LedgerSMB/DBObject.pm b/LedgerSMB/DBObject.pm index 2a8d976b..0691489a 100644 --- a/LedgerSMB/DBObject.pm +++ b/LedgerSMB/DBObject.pm @@ -29,6 +29,11 @@ arguments. =item __validate__ is called on every new() invocation. It is blank in this module but can be overridden in decendant modules. +=item _db_array_scalars(@elements) creates a db array from scalars. + +=item _db_array_literal(@elements) creates a multiple dimension db array from + preparsed db arrays or other data which does not need to be escaped. + =back =head1 Copyright (C) 2007, The LedgerSMB core team. @@ -274,4 +279,31 @@ sub _parse_array { return @return_array; } +sub _db_array_scalars { + my $self = shift @_; + my @args = @_; + for my $arg (@args){ + $arg =~ s/(["{},])/\\$1/g; + if ($arg =~ /(\s|\\)/){ + $arg = qq|"$arg"|; + } + } + return _db_array_literal(@args); +} + +sub _db_array_literal { + my $self = shift @_; + my @args = @_; + my $return_string = '{}'; + for my $arg (@args){ + if ($return_string eq '{}'){ + $return_string = "{$arg}"; + } + else { + $return_string =~ s/\}$/,$arg\}/ + } + } + return $return_string; +} + 1; diff --git a/LedgerSMB/DBObject/Payment.pm b/LedgerSMB/DBObject/Payment.pm index 2d4ced79..f4382a28 100644 --- a/LedgerSMB/DBObject/Payment.pm +++ b/LedgerSMB/DBObject/Payment.pm @@ -382,7 +382,7 @@ sub get_payment_detail_data { $inv->{invoices} = []; @{$inv->{invoices}} = $self->_parse_array($tmp_invoices); } - # $self->{dbh}->commit; # Commit locks + $self->{dbh}->commit; # Commit locks } sub post_bulk { @@ -398,6 +398,10 @@ sub post_bulk { funcname => 'job__create' ); $self->{job_id} = $job_ref->{job__create}; + + ($self->{job}) = $self->exec_method( + funcname => 'job__status' + ); } $self->{payment_date} = $self->{datepaid}; for my $contact_row (1 .. $self->{contact_count}){ @@ -406,29 +410,29 @@ sub post_bulk { my $invoice_array = "{}"; # Pg Array for my $invoice_row (1 .. $self->{"invoice_count_$contact_id"}){ my $invoice_id = $self->{"invoice_${contact_id}_${invoice_row}"}; - print STDERR "invoice_${contact_id}_${invoice_row}: $invoice_id\n"; my $pay_amount = ($self->{"paid_$contact_id"} eq 'all' ) ? $self->{"net_$invoice_id"} : $self->{"payment_$invoice_id"}; - if (!$pay_amount){ - $pay_amount = 0; - } + next if ! $pay_amount; + $pay_amount = $pay_amount * 1; my $invoice_subarray = "{$invoice_id,$pay_amount}"; + if ($invoice_subarray !~ /^\{\d+\,\-?\d*\.?\d+\}$/){ + $self->error("Invalid subarray: $invoice_subarray"); + } + $invoice_subarray =~ s/[^0123456789{},.]//; if ($invoice_array eq '{}'){ # Omit comma $invoice_array = "{$invoice_subarray}"; } else { - $invoice_array =~ s/}$/,$invoice_subarray}/; + $invoice_array =~ s/\}$/,$invoice_subarray\}/; } } $self->{transactions} = $invoice_array; $self->{source} = $self->{"source_$contact_id"}; if ($queue_payments){ + $self->{batch_class} = 3; $self->exec_method( funcname => 'payment_bulk_queue' ); - ($self->{job}) = $self->exec_method( - funcname => 'job__status' - ); } else { $self->exec_method(funcname => 'payment_bulk_post'); } |