my $payment_received = $bank_transaction->amount > 0;
my $payment_sent = $bank_transaction->amount < 0;
- croak("No amount left to assign") if ($not_assigned_amount <= 0);
foreach my $invoice_id (@{ $params{invoice_ids} }) {
my $invoice = SL::DB::Manager::Invoice->find_by(id => $invoice_id) || SL::DB::Manager::PurchaseInvoice->find_by(id => $invoice_id);
controller => 'gl.pl',
action => 'load_record_template',
id => $template->id,
- 'form_defaults.amount_1' => abs($self->transaction->amount), # always positive
+ 'form_defaults.amount_1' => abs($self->transaction->not_assigned_amount), # always positive
'form_defaults.transdate' => $self->transaction->transdate_as_date,
'form_defaults.callback' => $self->callback,
'form_defaults.bt_id' => $self->transaction->id,
die "guru meditation error: Can only assign amount to one bank account booking" if scalar @{ $payment } > 1;
# credit/debit * -1 matches the sign for bt.amount and bt.invoice_amount
- die "Can only assign the full bank amount to a single general ledger booking" unless $bt->amount == $payment->[0]->amount * -1;
+ die "Can only assign the full (partial) bank amount to a single general ledger booking"
+ unless $bt->not_assigned_amount == $payment->[0]->amount * -1;
+
$bt->update_attributes(invoice_amount => $bt->invoice_amount + ($payment->[0]->amount * -1));
# create record_link