From e5aa2c6737821924b77734ccfee74f1930831234 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Thu, 6 Dec 2007 22:08:49 +0000 Subject: Misc fixes git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1955 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Batch.pm | 1 + LedgerSMB/DBObject/Payment.pm | 32 ++++++++++++++++ LedgerSMB/GL.pm | 1 - UI/create_batch.html | 4 +- UI/payments/payments_detail.html | 61 ++++++++++++++++++++++++++++-- UI/payments/payments_filter.html | 5 +++ lsmb-request.pl | 2 - sql/modules/Payment.sql | 82 ++++++++++++++++++++++++++++++++++------ sql/modules/Session.sql | 2 +- 9 files changed, 168 insertions(+), 22 deletions(-) diff --git a/LedgerSMB/Batch.pm b/LedgerSMB/Batch.pm index 19cb656e..5c948f79 100644 --- a/LedgerSMB/Batch.pm +++ b/LedgerSMB/Batch.pm @@ -8,6 +8,7 @@ sub create { 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}; } diff --git a/LedgerSMB/DBObject/Payment.pm b/LedgerSMB/DBObject/Payment.pm index d8af8a9f..2c523717 100644 --- a/LedgerSMB/DBObject/Payment.pm +++ b/LedgerSMB/DBObject/Payment.pm @@ -381,4 +381,36 @@ sub get_payment_detail_data { } } +sub post_bulk { + my ($self) = @_; + my $total_count = 0; + $self->{payment_date} = $self->{datepaid}; + for my $contact_row (1 .. $self->{contact_count}){ + my $contact_id = $self->{"contact_$contact_row"}; + next if (!$self->{"id_$contact_id"}); + 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; + } + my $invoice_subarray = "{$invoice_id,$pay_amount}"; + if ($invoice_array eq '{}'){ # Omit comma + $invoice_array = "{$invoice_subarray}"; + } else { + $invoice_array =~ s/}$/,$invoice_subarray}/; + } + } + $self->{transactions} = $invoice_array; + $self->{source} = $self->{"source_$contact_id"}; + $self->exec_method(funcname => 'payment_bulk_post'); + + } + $self->{dbh}->commit; +} + 1; diff --git a/LedgerSMB/GL.pm b/LedgerSMB/GL.pm index 7e4f8cc8..1c5cd97c 100644 --- a/LedgerSMB/GL.pm +++ b/LedgerSMB/GL.pm @@ -67,7 +67,6 @@ sub post_transaction { my ( $self, $myconfig, $form ) = @_; $form->{reference} = $form->update_defaults( $myconfig, 'glnumber', $dbh ) unless $form->{reference}; - my $null; my $project_id; my $department_id; diff --git a/UI/create_batch.html b/UI/create_batch.html index 26500b7c..df50cdbd 100644 --- a/UI/create_batch.html +++ b/UI/create_batch.html @@ -1,8 +1,8 @@ - diff --git a/UI/payments/payments_detail.html b/UI/payments/payments_detail.html index d46cfe64..be3facb2 100644 --- a/UI/payments/payments_detail.html +++ b/UI/payments/payments_detail.html @@ -21,6 +21,12 @@ name = "project_id" value = project_id } ?> + - + + +
+ +
@@ -137,11 +154,25 @@ - + - + - + + + @@ -204,13 +237,33 @@ type = "text" class = "monetary" } ?> + + +
@@ -182,7 +213,9 @@
   
+ +
diff --git a/lsmb-request.pl b/lsmb-request.pl index 3a33d278..a0de6115 100644 --- a/lsmb-request.pl +++ b/lsmb-request.pl @@ -37,7 +37,6 @@ eval { require "custom.pl"; }; $request = new LedgerSMB; $request->{action} = '__default' if (!$request->{action}); - $ENV{SCRIPT_NAME} =~ m/([^\/\\]*.pl)\?*.*$/; $script = $1; $locale = LedgerSMB::Locale->get_handle( ${LedgerSMB::Sysconfig::language} ) @@ -56,7 +55,6 @@ sub call_script { eval { require "scripts/$script" } || $request->error($locale->text('Unable to open script') . ": scripts/$script : $!"); - $script =~ s/\.pl$//; $script = "LedgerSMB::Scripts::$script"; $script->can($request->{action}) diff --git a/sql/modules/Payment.sql b/sql/modules/Payment.sql index d19a821b..d3026420 100644 --- a/sql/modules/Payment.sql +++ b/sql/modules/Payment.sql @@ -125,7 +125,7 @@ $$ DECLARE payment_item payment_contact_invoice; BEGIN FOR payment_item IN - SELECT e.id AS contact_id, e.name AS contact_name, + SELECT c.id AS contact_id, e.name AS contact_name, c.meta_number AS account_number, sum(a.amount - a.paid) AS total_due, compound_array(ARRAY[[ @@ -134,13 +134,13 @@ BEGIN (CASE WHEN c.discount_terms > extract('days' FROM age(a.transdate)) THEN 0 - ELSE (a.amount - a.paid) * c.discount / 100 + ELSE (a.amount - coalesce(a.paid, 0)) * coalesce(c.discount, 0) / 100 END)::text, - (a.amount - a.paid - + (a.amount - coalesce(a.paid, 0) - (CASE WHEN c.discount_terms > extract('days' FROM age(a.transdate)) THEN 0 - ELSE (a.amount - a.paid) * c.discount / 100 + ELSE (a.amount - coalesce(a.paid, 0)) * coalesce(c.discount, 0) / 100 END))::text]]), bool_and(lock_record(a.id, (select max(session_id) FROM "session" where users_id = ( select id from users WHERE username = @@ -160,26 +160,28 @@ BEGIN ) a USING (entity_id) JOIN transactions t ON (a.id = t.id) WHERE a.invoice_class = in_account_class - AND ((a.transdate >= in_date_from - AND a.transdate <= in_date_to) + AND c.business_id = + coalesce(in_business_type, c.business_id) + AND ((a.transdate >= COALESCE(in_date_from, a.transdate) + AND a.transdate <= COALESCE(in_date_to, a.transdate)) OR a.id IN (select voucher.trans_id FROM voucher WHERE batch_id = in_batch_id)) AND c.entity_class = in_account_class AND a.curr = in_currency AND a.entity_credit_account = c.id AND a.amount - a.paid <> 0 - AND t.locked_by NOT IN + AND NOT (t.locked_by IS NOT NULL AND t.locked_by IN (select "session_id" FROM "session" WHERE users_id IN (select id from users - where username <> SESSION_USER)) + where username <> SESSION_USER))) AND EXISTS (select trans_id FROM acc_trans WHERE trans_id = a.id AND chart_id = (SELECT id frOM chart WHERE accno = in_ar_ap_accno) ) - GROUP BY e.id, e.name, c.meta_number, c.threshold + GROUP BY c.id, e.name, c.meta_number, c.threshold HAVING sum(a.amount - a.paid) > c.threshold LOOP RETURN NEXT payment_item; @@ -206,18 +208,74 @@ $$; CREATE OR REPLACE FUNCTION payment_bulk_post (in_transactions numeric[], in_batch_id int, in_source text, in_total numeric, - in_ar_ap_accno text, in_cash_accno text, in_approved bool, + in_ar_ap_accno text, in_cash_accno text, in_payment_date date, in_account_class int) RETURNS int AS $$ -DECLARE payment_trans numeric[]; +DECLARE + payment_trans numeric[]; + out_count int; + t_voucher_id int; + t_trans_id int; + t_amount numeric; BEGIN + IF in_batch_id IS NULL THEN + t_voucher_id := NULL; + ELSE + INSERT INTO voucher (batch_id, trans_id) + values (in_batch_id, in_transactions[1][1]); + + t_voucher_id := currval('voucher_id_seq'); + END IF; + FOR out_count IN + array_lower(in_transactions, 1) .. + array_upper(in_transactions, 1) + LOOP + INSERT INTO acc_trans + (trans_id, chart_id, amount, approved, voucher_id, + transdate) + VALUES + (in_transactions[out_count][1], + case when in_account_class = 1 THEN + (SELECT id FROM chart + WHERE accno = in_cash_accno) + WHEN in_account_class = 2 THEN + (SELECT id FROM chart + WHERE accno = in_ar_ap_accno) + 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_transactions[out_count][1], + case when in_account_class = 1 THEN + (SELECT id FROM chart + WHERE accno = in_ar_ap_accno) + WHEN in_account_class = 2 THEN + (SELECT id FROM chart + WHERE accno = in_cash_accno) + 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); + insert into test_pay(id, amount) values (in_transactions[out_count][1],in_transactions[out_count][2]); + UPDATE ap + set paid = paid +in_transactions[out_count][2] + where id =in_transactions[out_count][1]; + END LOOP; + return out_count; END; $$ language plpgsql; COMMENT ON FUNCTION payment_bulk_post (in_transactions numeric[], in_batch_id int, in_source text, in_total numeric, - in_ar_ap_accno text, in_cash_accno text, in_approved bool, + in_ar_ap_accno text, in_cash_accno text, in_payment_date date, in_account_class int) IS $$ Note that in_transactions is a two-dimensional numeric array. Of each diff --git a/sql/modules/Session.sql b/sql/modules/Session.sql index a44ed924..58de0f2e 100644 --- a/sql/modules/Session.sql +++ b/sql/modules/Session.sql @@ -21,7 +21,7 @@ BEGIN -- session IF NOT FOUND THEN - SELECT id FROM users WHERE username = SESSION_USER; + PERFORM id FROM users WHERE username = SESSION_USER; IF NOT FOUND THEN RAISE EXCEPTION 'User Not Known'; END IF; -- cgit v1.2.3