diff options
-rw-r--r-- | scripts/payment.pl | 7 | ||||
-rw-r--r-- | sql/modules/Payment.sql | 80 |
2 files changed, 51 insertions, 36 deletions
diff --git a/scripts/payment.pl b/scripts/payment.pl index b9d6f94c..f5173e24 100644 --- a/scripts/payment.pl +++ b/scripts/payment.pl @@ -368,11 +368,10 @@ sub display_payments { for my $invoice (@{$_->{invoices}}){ if (($payment->{action} ne 'update_payments') or (defined $payment->{"id_$_->{contact_id}"})){ - if ($payment->{"paid_$_->{contact_id}"} eq 'some'){ my $i_id = $invoice->[0]; $contact_total - += $payment->{"paid_$_->{contact_id}_$i_id"}; + += $payment->{"payment_$i_id"}; } } $invoice->[3] = $payment->format_amount(amount => $invoice->[3], @@ -383,8 +382,8 @@ sub display_payments { money => 1); $invoice->[6] = $payment->format_amount(amount => $invoice->[6], money => 1); - if (!$payment->{action} ne 'update_payments'){ - my $fld = "payment_" . $invoice->[0]; + my $fld = "payment_" . $invoice->[0]; + if (!defined $payment->{"$fld"} ){ $payment->{"$fld"} = $invoice->[6]; } } diff --git a/sql/modules/Payment.sql b/sql/modules/Payment.sql index ad2951a3..4b45c002 100644 --- a/sql/modules/Payment.sql +++ b/sql/modules/Payment.sql @@ -420,6 +420,8 @@ BEGIN t_voucher_id := currval('voucher_id_seq'); END IF; + CREATE TEMPORARY TABLE bulk_payments_in (id int, amount numeric); + select id into t_ar_ap_id from chart where accno = in_ar_ap_accno; select id into t_cash_id from chart where accno = in_cash_accno; @@ -427,39 +429,54 @@ BEGIN array_lower(in_transactions, 1) .. array_upper(in_transactions, 1) LOOP + EXECUTE $E$ + INSERT INTO bulk_payments_in(id, amount) + VALUES ($E$ || quote_literal(in_transactions[out_count][1]) + || $E$, $E$ || + quote_literal(in_transactions[out_count][2]) + || $E$)$E$; + END LOOP; + EXECUTE $E$ INSERT INTO acc_trans - (trans_id, chart_id, amount, approved, voucher_id, - transdate, source) - VALUES - (in_transactions[out_count][1], - case when in_account_class = 1 THEN t_cash_id - WHEN in_account_class = 2 THEN t_ar_ap_id - ELSE -1 END, - - in_transactions[out_count][2], - - CASE WHEN t_voucher_id IS NULL THEN true - ELSE false END, - t_voucher_id, in_payment_date, in_source); - + (trans_id, chart_id, amount, approved, voucher_id, transdate, + source) + SELECT id, + case when $E$ || quote_literal(in_account_class) || $E$ = 1 + THEN $E$ || t_cash_id || $E$ + WHEN $E$ || quote_literal(in_account_class) || $E$ = 2 + THEN $E$ || t_ar_ap_id || $E$ + ELSE -1 END, + amount, + CASE + WHEN $E$|| t_voucher_id || $E$ IS NULL THEN true + ELSE false END, + $E$ || t_voucher_id || $E$, $E$|| quote_literal(in_payment_date) + ||$E$ , $E$ ||COALESCE(quote_literal(in_source), 'NULL') ||$E$ + FROM bulk_payments_in $E$; + + EXECUTE $E$ INSERT INTO acc_trans - (trans_id, chart_id, amount, approved, voucher_id, - transdate, source) - VALUES - (in_transactions[out_count][1], - case when in_account_class = 1 THEN t_ar_ap_id - WHEN in_account_class = 2 THEN t_cash_id - ELSE -1 END, - - in_transactions[out_count][2]* -1, - - CASE WHEN t_voucher_id IS NULL THEN true - ELSE false END, - t_voucher_id, in_payment_date, in_source); + (trans_id, chart_id, amount, approved, voucher_id, transdate, + source) + SELECT id, + case when $E$ || quote_literal(in_account_class) || $E$ = 1 + THEN $E$ || t_ar_ap_id || $E$ + WHEN $E$ || quote_literal(in_account_class) || $E$ = 2 + THEN $E$ || t_cash_id || $E$ + ELSE -1 END, + amount * -1, + CASE + WHEN $E$|| t_voucher_id || $E$ IS NULL THEN true + ELSE false END, + $E$ || t_voucher_id || $E$, $E$|| quote_literal(in_payment_date) + ||$E$ , $E$ ||COALESCE(quote_literal(in_source), 'null') ||$E$ + FROM bulk_payments_in $E$; + + EXECUTE $E$ UPDATE ap - set paid = paid +in_transactions[out_count][2] - where id =in_transactions[out_count][1]; - END LOOP; + set paid = paid + (select amount from bulk_payments_in b + where b.id = ap.id) + where id in (select id from bulk_payments_in) $E$; perform unlock_all(); return out_count; END; @@ -472,8 +489,7 @@ COMMENT ON FUNCTION payment_bulk_post IS $$ Note that in_transactions is a two-dimensional numeric array. Of each sub-array, the first element is the (integer) transaction id, and the second -is the amount for that transaction. If the total of the amounts do not add up -to in_total, then an error is generated. $$; +is the amount for that transaction. $$; -- -- WE NEED A PAYMENT TABLE |