Revision 10d9b17f
Von Jan Büren vor mehr als 6 Jahren hinzugefügt
bin/mozilla/gl.pl | ||
---|---|---|
1311 | 1311 |
$form->error($locale->text('Empty transaction!')); |
1312 | 1312 |
} |
1313 | 1313 |
|
1314 |
if ((my $errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) { |
|
1315 |
$errno *= -1; |
|
1316 |
my @err; |
|
1317 |
$err[1] = $locale->text('Cannot have a value in both Debit and Credit!'); |
|
1318 |
$err[2] = $locale->text('Debit and credit out of balance!'); |
|
1319 |
$err[3] = $locale->text('Cannot post a transaction without a value!'); |
|
1320 |
|
|
1321 |
$form->error($err[$errno]); |
|
1322 |
} |
|
1323 |
# saving the history |
|
1324 |
if(!exists $form->{addition} && $form->{id} ne "") { |
|
1325 |
$form->{snumbers} = qq|gltransaction_| . $form->{id}; |
|
1326 |
$form->{addition} = "POSTED"; |
|
1327 |
$form->{what_done} = "gl transaction"; |
|
1328 |
$form->save_history; |
|
1329 |
} |
|
1330 |
# /saving the history |
|
1331 | 1314 |
|
1332 |
# called from BankTransaction - Assign RecordLink and update BankTransaction |
|
1333 |
if ($form->{callback} =~ /BankTransaction/ && $form->{bt_id}) { |
|
1334 |
# set invoice_amount - we only rely on bt_id in form, do all other stuff ui independent |
|
1335 |
# die if we have a unlogic or NYI case and (TODO) chain this transaction safe (post_transaction + history_erp + this) |
|
1336 |
my ($bt, $chart_id, $payment); |
|
1337 |
|
|
1338 |
$bt = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id}); |
|
1339 |
die "No bank transaction found" unless $bt; |
|
1340 |
|
|
1341 |
$chart_id = SL::DB::Manager::BankAccount->find_by(id => $bt->local_bank_account_id)->chart_id; |
|
1342 |
die "no chart id:" unless $chart_id; |
|
1343 |
|
|
1344 |
$payment = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $::form->{id}, |
|
1345 |
chart_link => { like => '%AR_paid%' }, |
|
1346 |
chart_id => $chart_id ]); |
|
1347 |
die "guru meditation error: Can only assign amount to one bank account booking" if scalar @{ $payment } > 1; |
|
1348 |
|
|
1349 |
# credit/debit * -1 matches the sign for bt.amount and bt.invoice_amount |
|
1350 |
$bt->update_attributes(invoice_amount => $bt->invoice_amount + ($payment->[0]->amount * -1)); |
|
1351 |
|
|
1352 |
# create record_link |
|
1353 |
my @props = ( |
|
1354 |
from_table => 'bank_transactions', |
|
1355 |
from_id => $::form->{bt_id}, |
|
1356 |
to_table => 'gl', |
|
1357 |
to_id => $::form->{id}, |
|
1358 |
); |
|
1359 |
SL::DB::RecordLink->new(@props)->save; |
|
1315 |
# start transaction (post + history + (optional) banktrans) |
|
1316 |
SL::DB->client->with_transaction(sub { |
|
1317 |
|
|
1318 |
if ((my $errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) { |
|
1319 |
$errno *= -1; |
|
1320 |
my @err; |
|
1321 |
$err[1] = $locale->text('Cannot have a value in both Debit and Credit!'); |
|
1322 |
$err[2] = $locale->text('Debit and credit out of balance!'); |
|
1323 |
$err[3] = $locale->text('Cannot post a transaction without a value!'); |
|
1360 | 1324 |
|
1325 |
die $err[$errno]; |
|
1326 |
} |
|
1327 |
# saving the history |
|
1328 |
if(!exists $form->{addition} && $form->{id} ne "") { |
|
1329 |
$form->{snumbers} = qq|gltransaction_| . $form->{id}; |
|
1330 |
$form->{addition} = "POSTED"; |
|
1331 |
$form->{what_done} = "gl transaction"; |
|
1332 |
$form->save_history; |
|
1333 |
} |
|
1334 |
|
|
1335 |
# Case BankTransaction: update RecordLink and BankTransaction |
|
1336 |
if ($form->{callback} =~ /BankTransaction/ && $form->{bt_id}) { |
|
1337 |
# set invoice_amount - we only rely on bt_id in form, do all other stuff ui independent |
|
1338 |
# die if we have a unlogic or NYI case and abort the whole transaction |
|
1339 |
my ($bt, $chart_id, $payment); |
|
1340 |
require SL::DB::Manager::BankTransaction; |
|
1341 |
|
|
1342 |
$bt = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id}); |
|
1343 |
die "No bank transaction found" unless $bt; |
|
1344 |
|
|
1345 |
$chart_id = SL::DB::Manager::BankAccount->find_by(id => $bt->local_bank_account_id)->chart_id; |
|
1346 |
die "no chart id:" unless $chart_id; |
|
1347 |
|
|
1348 |
$payment = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $::form->{id}, |
|
1349 |
chart_link => { like => '%AR_paid%' }, |
|
1350 |
chart_id => $chart_id ]); |
|
1351 |
die "guru meditation error: Can only assign amount to one bank account booking" if scalar @{ $payment } > 1; |
|
1352 |
|
|
1353 |
# credit/debit * -1 matches the sign for bt.amount and bt.invoice_amount |
|
1354 |
$bt->update_attributes(invoice_amount => $bt->invoice_amount + ($payment->[0]->amount * -1)); |
|
1355 |
|
|
1356 |
# create record_link |
|
1357 |
my @props = ( |
|
1358 |
from_table => 'bank_transactions', |
|
1359 |
from_id => $::form->{bt_id}, |
|
1360 |
to_table => 'gl', |
|
1361 |
to_id => $::form->{id}, |
|
1362 |
); |
|
1363 |
SL::DB::RecordLink->new(@props)->save; |
|
1364 |
|
|
1365 |
} |
|
1366 |
1; |
|
1367 |
}) or do { die SL::DB->client->error }; |
|
1368 |
|
|
1369 |
if ($form->{callback} =~ /BankTransaction/ && $form->{bt_id}) { |
|
1361 | 1370 |
print $form->redirect_header($form->{callback}); |
1362 | 1371 |
$form->redirect($locale->text('GL transaction posted.') . ' ' . $locale->text('ID') . ': ' . $form->{id}); |
1363 | 1372 |
} |
1373 |
|
|
1364 | 1374 |
# remove or clarify |
1365 | 1375 |
undef($form->{callback}); |
1366 | 1376 |
$main::lxdebug->leave_sub(); |
Auch abrufbar als: Unified diff
Dialogbuchen transaktionssicher
In Ergänzung zum Commit 81ce5300bddf, dass Todo transaktionssicher gelöst.