Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 35285a5b

Von Sven Schöling vor mehr als 7 Jahren hinzugefügt

  • ID 35285a5be7de15d43aeb6feb04740aaf46d45c8b
  • Vorgänger 4812c084
  • Nachfolger 800378d4

AR: single-dbh

Unterschiede anzeigen:

SL/AR.pm
42 42
use SL::DB::Default;
43 43
use SL::TransNumber;
44 44
use SL::Util qw(trim);
45
use SL::DB;
45 46

  
46 47
use strict;
47 48

  
48 49
sub post_transaction {
50
  my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
49 51
  $main::lxdebug->enter_sub();
50 52

  
53
  my $rc = SL::DB->client->with_transaction(\&_post_transaction, $self, $myconfig, $form, $provided_dbh, $payments_only);
54

  
55
  $::lxdebug->leave_sub;
56
  return $rc;
57
}
58

  
59
sub _post_transaction {
51 60
  my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
52 61

  
53 62
  my ($query, $sth, $null, $taxrate, $amount, $tax);
......
56 65

  
57 66
  my @values;
58 67

  
59
  my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
68
  my $dbh = $provided_dbh || SL::DB->client->dbh;
60 69
  $form->{defaultcurrency} = $form->get_default_currency($myconfig);
61 70

  
62 71
  # set exchangerate
......
323 332
    $datev->export;
324 333

  
325 334
    if ($datev->errors) {
326
      $dbh->rollback;
327 335
      die join "\n", $::locale->text('DATEV check returned errors:'), $datev->errors;
328 336
    }
329 337
  }
330 338

  
331
  my $rc = 1;
332
  if (!$provided_dbh) {
333
    $rc = $dbh->commit();
334
    $dbh->disconnect();
335
  }
336

  
337
  $main::lxdebug->leave_sub() and return $rc;
339
  return 1;
338 340
}
339 341

  
340 342
sub _delete_payments {
......
377 379
}
378 380

  
379 381
sub post_payment {
382
  my ($self, $myconfig, $form, $locale) = @_;
380 383
  $main::lxdebug->enter_sub();
381 384

  
385
  my $rc = SL::DB->client->with_transaction(\&_post_payment, $self, $myconfig, $form, $locale);
386

  
387
  $::lxdebug->leave_sub;
388
  return $rc;
389
}
390

  
391
sub _post_payment {
382 392
  my ($self, $myconfig, $form, $locale) = @_;
383 393

  
384
  # connect to database, turn off autocommit
385
  my $dbh = $form->dbconnect_noauto($myconfig);
394
  my $dbh = SL::DB->client->dbh;
386 395

  
387 396
  my (%payments, $old_form, $row, $item, $query, %keep_vars);
388 397

  
......
431 440

  
432 441
  restore_form($old_form);
433 442

  
434
  my $rc = $dbh->commit();
435
  $dbh->disconnect();
436

  
437
  $main::lxdebug->leave_sub();
438

  
439
  return $rc;
443
  return 1;
440 444
}
441 445

  
442 446
sub delete_transaction {
......
444 448

  
445 449
  my ($self, $myconfig, $form) = @_;
446 450

  
447
  # connect to database, turn AutoCommit off
448
  my $dbh = $form->dbconnect_noauto($myconfig);
449

  
450
  # acc_trans entries are deleted by database triggers.
451
  my $query = qq|DELETE FROM ar WHERE id = ?|;
452
  do_query($form, $dbh, $query, $form->{id});
453

  
454
  # commit
455
  my $rc = $dbh->commit;
456
  $dbh->disconnect;
451
  SL::DB->client->with_transaction(sub {
452
    # acc_trans entries are deleted by database triggers.
453
    my $query = qq|DELETE FROM ar WHERE id = ?|;
454
    do_query($form, SL::DB->client->dbh, $query, $form->{id});
455
  });
457 456

  
458 457
  $main::lxdebug->leave_sub();
459 458

  
460
  return $rc;
459
  return 1;
461 460
}
462 461

  
463 462
sub ar_transactions {
......
683 682
  $form->{forex} = $form->{exchangerate};
684 683
  $exchangerate  = $form->{exchangerate} ? $form->{exchangerate} : 1;
685 684

  
686
  # expected keys: AR, AR_paid, AR_tax, AR_amount 
685
  # expected keys: AR, AR_paid, AR_tax, AR_amount
687 686
  foreach my $key (keys %{ $form->{AR_links} }) {
688 687
    $j = 0;
689 688
    $k = 0;
......
788 787
}
789 788

  
790 789
sub storno {
790
  my ($self, $form, $myconfig, $id) = @_;
791 791
  $main::lxdebug->enter_sub();
792 792

  
793
  my $rc = SL::DB->client->with_transaction(\&_storno, $self, $form, $myconfig, $id);
794

  
795
  $::lxdebug->leave_sub;
796
  return $rc;
797
}
798

  
799

  
800
sub _storno {
793 801
  my ($self, $form, $myconfig, $id) = @_;
794 802

  
795 803
  my ($query, $new_id, $storno_row, $acc_trans_rows);
796
  my $dbh = $form->get_standard_dbh($myconfig);
804
  my $dbh = SL::DB->client->dbh;
797 805

  
798 806
  $query = qq|SELECT nextval('glid')|;
799 807
  ($new_id) = selectrow_query($form, $dbh, $query);
......
838 846

  
839 847
  map { IO->set_datepaid(table => 'ar', id => $_, dbh => $dbh) } ($id, $new_id);
840 848

  
841
  $dbh->commit;
842

  
843
  $main::lxdebug->leave_sub();
849
  return 1;
844 850
}
845 851

  
846 852

  

Auch abrufbar als: Unified diff