Nette Idee aus odyn (Start des Gedankens #
f09c2b407faa7 Ende des Gedankens #
765a3d421e7).
Zwei Sollbruchstellen in odyn, deshalb in kivi neu formuliert:
Sollbruchstellen:
a) Ein Aufruf von BankTransaction::action_list kann Zustände im Datenmodell verändern
b) Der Benutzer kann beliebige Zahlenwerte oder neue Konten in der Dialogbuchungsmaske eingeben
Konsequenz:
-> Zustände des Datenmodells in gl.pl post_transactions ändern, Werte per Rose hierzu aus der DB (und nicht aus $form)
Möglichst viel dem Benutzer auf die Flossen hauen, wenn die Buchungsmaske unlogisch benutzt wird
$self->transaction(SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id}));
- # This was dead code: We compared vendor.account_name with bank_transaction.iban.
- # This did never match (Kontonummer != IBAN). It's kivis 09/02 (2013) day
- # If refactored/improved, also consider that vendor.iban should be normalized
- # user may like to input strings like: 'AT 3333 3333 2222 1111' -> can be checked strictly
- # at Vendor code because we need the correct data for all sepa exports.
-
my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(iban => $self->transaction->{remote_account_number});
my $use_vendor_filter = $self->transaction->{remote_account_number} && $vendor_of_transaction;
TEMPLATES_GL => $use_vendor_filter && @{ $templates_ap } ? undef : $templates_gl,
TEMPLATES_AP => $templates_ap,
vendor_name => $use_vendor_filter && @{ $templates_ap } ? $vendor_of_transaction->name : undef,
+ BT_ID => $::form->{bt_id},
);
}
}
sub load_gl_record_template_url {
- my ($self, $template) = @_;
+ my ($self, $template, $bt_id) = @_;
return $self->url_for(
controller => 'gl.pl',
'form_defaults.amount_1' => abs($self->transaction->amount), # always positive
'form_defaults.transdate' => $self->transaction->transdate_as_date,
'form_defaults.callback' => $self->callback,
+ 'form_defaults.bt_id' => $self->transaction->id,
);
}
}
# /saving the history
- if ($form->{callback} =~ /BankTransaction/) {
+ # called from BankTransaction - Assign RecordLink and update BankTransaction
+ if ($form->{callback} =~ /BankTransaction/ && $form->{bt_id}) {
+ # set invoice_amount - we only rely on bt_id in form, do all other stuff ui independent
+ # die if we have a unlogic or NYI case and (TODO) chain this transaction safe (post_transaction + history_erp + this)
+ my ($bt, $chart_id, $payment);
+
+ $bt = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id});
+ die "No bank transaction found" unless $bt;
+
+ $chart_id = SL::DB::Manager::BankAccount->find_by(id => $bt->local_bank_account_id)->chart_id;
+ die "no chart id:" unless $chart_id;
+
+ $payment = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $::form->{id},
+ chart_link => { like => '%AR_paid%' },
+ chart_id => $chart_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
+ $bt->update_attributes(invoice_amount => $bt->invoice_amount + ($payment->[0]->amount * -1));
+
+ # create record_link
+ my @props = (
+ from_table => 'bank_transactions',
+ from_id => $::form->{bt_id},
+ to_table => 'gl',
+ to_id => $::form->{id},
+ );
+ SL::DB::RecordLink->new(@props)->save;
+
print $form->redirect_header($form->{callback});
$form->redirect($locale->text('GL transaction posted.') . ' ' . $locale->text('ID') . ': ' . $form->{id});
}
<tbody>
[% FOREACH template = TEMPLATES_GL %]
<tr class="listrow">
- <td>[% P.link_tag(SELF.load_gl_record_template_url(template), template.template_name) %]</td>
+ <td>[% P.link_tag(SELF.load_gl_record_template_url(template, BT_ID), template.template_name) %]</td>
<td>[% HTML.escape(template.reference) %]</td>
<td>[% HTML.escape(template.employee.name || template.employee.login) %]</td>
<td>[% HTML.escape(template.itime_as_date) %]</td>
<hr size="3" noshade>
<input name=callback type=hidden value="[% callback %]">
+<input name=bt_id type=hidden value="[% bt_id %]">
[%- IF id && follow_ups.size %]
<p>[% LxERP.t8('There are #1 unfinished follow-ups of which #2 are due.', follow_ups.size , follow_ups_due) %]</p>