diff --git a/TrsrDB/HTTP/Credit.pm b/TrsrDB/HTTP/Credit.pm index a2144bd..6c43b49 100644 --- a/TrsrDB/HTTP/Credit.pm +++ b/TrsrDB/HTTP/Credit.pm @@ -71,6 +71,14 @@ sub upsert { $db->make_transfers( $self->param("billId") => $to_spend_for); } + for my $param ( grep { /^note\[/ } @{ $self->req->params->names } ) { + my $note = $self->param($param) || next; + s{^note\[}{} && s{\]$}{} for $param; + $credit->search_related( + outgoings => { billId => $param } + )->update({ note => $note }); + } + $self->redirect_to('home'); diff --git a/TrsrDB/HTTP/Debit.pm b/TrsrDB/HTTP/Debit.pm index 4b26e4a..156e73c 100644 --- a/TrsrDB/HTTP/Debit.pm +++ b/TrsrDB/HTTP/Debit.pm @@ -105,15 +105,16 @@ sub upsert { if ( @$to_pay_with ) { my $billId = $self->param("billId"); $db->make_transfers( $to_pay_with => $billId ); - for my $param ( grep { /^note\[/ } @{ $self->req->params->names } ) { - my $note = $self->param($param) || next; - s{^note\[}{} && s{\]$}{} for $param; - $db->resultset("Transfer")->find({ - billId => $self->param("billId"), credId => $param - })->update({ note => $note }); - } } + for my $param ( grep { /^note\[/ } @{ $self->req->params->names } ) { + my $note = $self->param($param) || next; + s{^note\[}{} && s{\]$}{} for $param; + $debit->search_related( + incomings => { credId => $param } + )->update({ note => $note }); + } + $self->redirect_to('home'); } diff --git a/templates/credit/upsert.html.ep b/templates/credit/upsert.html.ep index 23caa30..e12d894 100644 --- a/templates/credit/upsert.html.ep +++ b/templates/credit/upsert.html.ep @@ -43,6 +43,7 @@ +% my %paid_debits; % if ( $credit->in_storage ) { % my $o = $credit->outgoings; % if ( $o->count() ) { @@ -52,11 +53,12 @@
<%= $credit->value == $credit->spent ? "The credit is already spent. Unless you revoke any outgoings above, there is no point in checking" : "Check" %> <%= %paid_debits ? "other" : "" %> debits you want to spend this credit for:
Check arrears you want to use this credit for.
S | date | purpose | to pay | |
---|---|---|---|---|
<%= $d->date %> | <%== nl2br $d->purpose %> | <%== money $d->difference %> | +
Check credits you want to pay this debit with.
+% if ( $credits->first() ) { +<%= $debit->value == $debit->value ? "The debt is already settled. Unless you revoke any incomings above, there is no point in checking" : "Check" %> <%= %used_credits ? "other" : "" %> credits you want to pay this debit with:
S | date | purpose | to spend | note |
---|---|---|---|---|
- | <%= $d->date %> | -<%== nl2br $d->purpose %> | -<%== money $d->difference %> | -+% while ( my $c = $credits->next ) { +% next if $used_credits{ $c->credId }; + |
+ | <%= $c->date %> | +<%== nl2br $c->purpose %> | +<%== money $c->difference %> | +