my $counter = 0;
- foreach my $bt_id ( @{ $::form->{bt_ids} }) {
- my $rec_group = SL::DB::Manager::ReconciliationLink->get_new_rec_group();
- my $bank_transaction = SL::DB::Manager::BankTransaction->find_by(id => $bt_id);
- $bank_transaction->cleared('1');
- $bank_transaction->save;
- foreach my $acc_trans_id (@{ $::form->{proposal_list}->{$bt_id}->{BB} }) {
- SL::DB::ReconciliationLink->new(
- rec_group => $rec_group,
- bank_transaction_id => $bt_id,
- acc_trans_id => $acc_trans_id
- )->save;
- my $acc_trans = SL::DB::Manager::AccTransaction->find_by(acc_trans_id => $acc_trans_id);
- $acc_trans->cleared('1');
- $acc_trans->save;
+ # reconcile transaction safe
+ SL::DB->client->with_transaction(sub {
+ foreach my $bt_id ( @{ $::form->{bt_ids} }) {
+ my $rec_group = SL::DB::Manager::ReconciliationLink->get_new_rec_group();
+ my $bank_transaction = SL::DB::Manager::BankTransaction->find_by(id => $bt_id);
+ $bank_transaction->cleared('1');
+ $bank_transaction->save;
+ foreach my $acc_trans_id (@{ $::form->{proposal_list}->{$bt_id}->{BB} }) {
+ SL::DB::ReconciliationLink->new(
+ rec_group => $rec_group,
+ bank_transaction_id => $bt_id,
+ acc_trans_id => $acc_trans_id
+ )->save;
+ my $acc_trans = SL::DB::Manager::AccTransaction->find_by(acc_trans_id => $acc_trans_id);
+ $acc_trans->cleared('1');
+ $acc_trans->save;
+ }
+ $counter++;
}
- $counter++;
- }
+ }) or die t8('Unable to reconcile, database transaction failure');
flash('ok', t8('#1 proposal(s) saved.', $counter));
sub _reconcile {
my ($self) = @_;
- # 1. step: set AccTrans and BankTransactions to 'cleared'
- foreach my $element (@{ $self->{ELEMENTS} }) {
- $element->cleared('1');
- # veto either invoice_amount is fully assigned or not! No state tricks in later workflow!
- # invoice_amount should be a distinct sign, that some bookings were really made from a bank transaction
- # $element->invoice_amount($element->amount) if $element->isa('SL::DB::BankTransaction');
- $element->save;
- }
+ # reconcile transaction safe
+ SL::DB->client->with_transaction(sub {
- # 2. step: insert entry in reconciliation_links
- my $rec_group = SL::DB::Manager::ReconciliationLink->get_new_rec_group();
- #There is either a 1:n relation or a n:1 relation
- if (scalar @{ $::form->{bt_ids} } == 1) {
- my $bt_id = @{ $::form->{bt_ids} }[0];
- foreach my $bb_id (@{ $::form->{bb_ids} }) {
- my $rec_link = SL::DB::ReconciliationLink->new(bank_transaction_id => $bt_id,
- acc_trans_id => $bb_id,
- rec_group => $rec_group);
- $rec_link->save;
+ # 1. step: set AccTrans and BankTransactions to 'cleared'
+ foreach my $element (@{ $self->{ELEMENTS} }) {
+ $element->cleared('1');
+ # veto either invoice_amount is fully assigned or not! No state tricks in later workflow!
+ $element->save;
}
- } else {
- my $bb_id = @{ $::form->{bb_ids} }[0];
- foreach my $bt_id (@{ $::form->{bt_ids} }) {
- my $rec_link = SL::DB::ReconciliationLink->new(bank_transaction_id => $bt_id,
- acc_trans_id => $bb_id,
- rec_group => $rec_group);
- $rec_link->save;
+ # 2. step: insert entry in reconciliation_links
+ my $rec_group = SL::DB::Manager::ReconciliationLink->get_new_rec_group();
+ #There is either a 1:n relation or a n:1 relation
+ if (scalar @{ $::form->{bt_ids} } == 1) {
+ my $bt_id = @{ $::form->{bt_ids} }[0];
+ foreach my $bb_id (@{ $::form->{bb_ids} }) {
+ my $rec_link = SL::DB::ReconciliationLink->new(bank_transaction_id => $bt_id,
+ acc_trans_id => $bb_id,
+ rec_group => $rec_group);
+ $rec_link->save;
+ }
+ } else {
+ my $bb_id = @{ $::form->{bb_ids} }[0];
+ foreach my $bt_id (@{ $::form->{bt_ids} }) {
+ my $rec_link = SL::DB::ReconciliationLink->new(bank_transaction_id => $bt_id,
+ acc_trans_id => $bb_id,
+ rec_group => $rec_group);
+ $rec_link->save;
+ }
}
- }
+ }) or die t8('Unable to reconcile, database transaction failure');
}
sub _filter_to_where {