Skip to content

Commit a90891b

Browse files
committed
Address single and bulk payment screens
1 parent 1f49e96 commit a90891b

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

UI/payments/payment2.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@
200200
[% # we can use an href to link this invoice number to the invoice %]
201201
<td class="invoice-date">
202202
[% row.invoice_date %]
203+
[% PROCESS input element_data = {
204+
type="hidden"
205+
name="open_item_id_" _ row.invoice.id
206+
value=row.open_item_id } %]
203207
[% PROCESS input element_data = {
204208
type="hidden"
205209
name="invoice_date_" _ row.invoice.id

UI/payments/payments_detail.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@
343343
<tr>
344344
<td class="invoice_date_list">
345345
[% i.transdate %]
346+
[% PROCESS input element_data = {
347+
type = "hidden"
348+
name = "open_item_id_" _ r.contact_id _ "_" _ i.id
349+
value = i.open_item_id } %]
346350
[% PROCESS input element_data = {
347351
type = "hidden"
348352
name = "invoice_date_" _ r.contact_id _ "_" _ i.id

lib/LedgerSMB/Scripts/payment.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ is saved. For receipts, this just redirects to bulk_post currently.
159159
my $bulk_post_map = input_map(
160160
[ qr/^(?<fld>id|source|memo|paid)_(?<cid>\d+)$/ => '@contacts<cid>:%<fld>' ],
161161
[ qr/^contact_label_(?<cid>\d+)$/ => '@contacts<cid>:%pay_to' ],
162-
[ qr/^(?<fld>invoice_date|invnumber|due|payment|invoice|net)_(?<cid>\d+)_(?<invrow>\d+)$/
162+
[ qr/^(?<fld>invoice_date|invnumber|due|payment|invoice|net|open_item_id)_(?<cid>\d+)_(?<invrow>\d+)$/
163163
=> '@contacts<cid>:@invoices<invrow>:%<fld>' ],
164164
[ qr/(?<fld>cash_accno|ar_ap_accno)$/ => '%<fld>' ],
165165
[ qr/^transdate$/ => '%date_paid' ],
@@ -1085,6 +1085,7 @@ sub payment2 {
10851085
number => $invoice->{invnumber},
10861086
id => $invoice_id,
10871087
href => $uri },
1088+
open_item_id => $invoice->{open_item_id},
10881089
invoice_date => "$invoice->{invoice_date}",
10891090
amount => $invoice_amt ? $request->format_amount( $invoice_amt, money => 1) : '',
10901091
due => $request->format_amount( $due, money => 1),
@@ -1319,6 +1320,7 @@ sub post_payment {
13191320
my @memo;
13201321
my @source;
13211322
my @transaction_id;
1323+
my @open_item_id;
13221324
my @op_amount;
13231325
my @op_cash_account_id;
13241326
my @op_source;
@@ -1383,6 +1385,7 @@ sub post_payment {
13831385
push @source, undef;
13841386
push @memo, $locale->text('Applied discount');
13851387
push @transaction_id, $array_options[$ref]->{invoice_id};
1388+
push @open_item_id, $array_options[$ref]->{open_item_id};
13861389
}
13871390

13881391
# We'll use this for both cash and ap/ar accounts
@@ -1399,6 +1402,7 @@ sub post_payment {
13991402
push @memo,
14001403
$request->{"memo_invoice_$array_options[$ref]->{invoice_id}"};
14011404
push @transaction_id, $array_options[$ref]->{invoice_id};
1405+
push @open_item_id, $array_options[$ref]->{open_item_id};
14021406
}
14031407
}
14041408
# Check if there is an unhandled overpayment and run payment2 as needed
@@ -1447,6 +1451,7 @@ sub post_payment {
14471451
$Payment->{source} = \@source;
14481452
$Payment->{memo} = \@memo;
14491453
$Payment->{transaction_id} = \@transaction_id;
1454+
$Payment->{open_item_id} = \@open_item_id;
14501455
$Payment->{op_amount} = \@op_amount;
14511456
$Payment->{op_cash_account_id} = \@op_cash_account_id;
14521457
$Payment->{op_source} = \@op_source;

old/lib/LedgerSMB/DBObject/Payment.pm

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,13 @@ sub get_payment_detail_data {
489489
$inv->{invoices} =
490490
[ sort { $a->{transdate} cmp $b->{transdate} }
491491
map { { id => $_->[0],
492-
invnumber => $_->[1],
493-
transdate => $_->[2],
494-
amount => $_->[3], ## no critic (ProhibitMagicNumbers)
495-
paid => $_->[4], ## no critic (ProhibitMagicNumbers)
496-
net => $_->[5], ## no critic (ProhibitMagicNumbers)
497-
due => $_->[6], ## no critic (ProhibitMagicNumbers)
492+
open_item_id => $_->[1],
493+
invnumber => $_->[2],
494+
transdate => $_->[3],
495+
amount => $_->[4], ## no critic (ProhibitMagicNumbers)
496+
paid => $_->[5], ## no critic (ProhibitMagicNumbers)
497+
net => $_->[6], ## no critic (ProhibitMagicNumbers)
498+
due => $_->[7], ## no critic (ProhibitMagicNumbers)
498499
} } @{$inv->{invoices} // []} ];
499500

500501
for my $invoice (@{$inv->{invoices}}){
@@ -587,8 +588,8 @@ sub post_bulk {
587588

588589
next if $invoice->{payment} == 0.0;
589590
my $db_amount = $invoice->{payment}->to_db();
590-
my $invoice_subarray = "{$invoice->{invoice},$db_amount}";
591-
if ($invoice_subarray !~ /^\{\d+\,\-?\d*\.?\d+\}$/){
591+
my $invoice_subarray = "{$invoice->{invoice},$invoice->{open_item_id},$db_amount}";
592+
if ($invoice_subarray !~ /^\{\d+\,\d+\,\-?\d*\.?\d+\}$/){
592593
die "Invalid subarray: $invoice_subarray";
593594
}
594595

sql/modules/Payment.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ RETURN QUERY EXECUTE $sql$
367367
ELSE 0::numeric
368368
END) AS total_due,
369369
array_agg(ARRAY[
370-
a.id::text, a.invnumber, a.transdate::text,
370+
a.id::text, a.open_item_id::text, a.invnumber, a.transdate::text,
371371
a.amount_bc::text, (a.amount_bc - p.due)::text,
372372
(CASE WHEN (c.discount_terms||' days')::interval
373373
< age(coalesce($10, current_date), a.transdate)
@@ -396,7 +396,7 @@ RETURN QUERY EXECUTE $sql$
396396

397397
FROM entity e
398398
JOIN entity_credit_account c ON (e.id = c.entity_id)
399-
JOIN (SELECT ap.id, invnumber, txn.transdate, amount_bc,
399+
JOIN (SELECT ap.id, ap.open_item_id, invnumber, txn.transdate, amount_bc,
400400
curr, 1 as invoice_class,
401401
entity_credit_account, on_hold, v.batch_id,
402402
txn.approved
@@ -406,7 +406,7 @@ RETURN QUERY EXECUTE $sql$
406406
WHERE $1 = 1
407407
AND (v.batch_class = 1 or v.batch_id IS NULL)
408408
UNION
409-
SELECT ar.id, invnumber, txn.transdate, amount_bc,
409+
SELECT ar.id, ar.open_item_id, invnumber, txn.transdate, amount_bc,
410410
curr, 2 as invoice_class,
411411
entity_credit_account, on_hold, v.batch_id,
412412
txn.approved

0 commit comments

Comments
 (0)