Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 800378d4

Von Sven Schöling vor etwa 8 Jahren hinzugefügt

  • ID 800378d4dca02bfcf5537ee29307eb946a3dc73e
  • Vorgänger 35285a5b
  • Nachfolger 09372651

AP: single-dbh

Unterschiede anzeigen:

SL/AP.pm
40 40
use SL::MoreCommon;
41 41
use SL::DB::Default;
42 42
use SL::Util qw(trim);
43
use SL::DB;
43 44
use Data::Dumper;
44 45

  
45 46
use strict;
46 47

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

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

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

  
58
sub _post_transaction {
50 59
  my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
51
  my $rc = 0; # return code auf false setzen
52
  # connect to database
53
  my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
60
  my $dbh = $provided_dbh || SL::DB->client->dbh;
54 61

  
55 62
  my ($null, $taxrate, $amount);
56 63
  my $exchangerate = 0;
......
381 388
    $datev->export;
382 389

  
383 390
    if ($datev->errors) {
384
      $dbh->rollback;
385 391
      die join "\n", $::locale->text('DATEV check returned errors:'), $datev->errors;
386 392
    }
387 393
  }
388 394

  
389
  if (!$provided_dbh) {
390
    $dbh->commit();
391
    $dbh->disconnect();
392
  }
393

  
394
  $rc = 1; #  Den return-code auf true setzen, aber nur falls beim commit alles i.O. ist
395

  
396
  $main::lxdebug->leave_sub();
397

  
398
  return $rc;
395
  return 1;
399 396
}
400 397

  
401 398
sub delete_transaction {
......
403 400

  
404 401
  my ($self, $myconfig, $form) = @_;
405 402

  
406
  # connect to database
407
  my $dbh = $form->dbconnect_noauto($myconfig);
408

  
409
  # acc_trans entries are deleted by database triggers.
410
  my $query = qq|DELETE FROM ap WHERE id = ?|;
411
  do_query($form, $dbh, $query, $form->{id});
412

  
413
  my $rc = $dbh->commit;
414
  $dbh->disconnect;
403
  SL::DB->client->with_transaction(sub {
404
    my $query = qq|DELETE FROM ap WHERE id = ?|;
405
    do_query($form, SL::DB->client->dbh, $query, $form->{id});
406
  });
415 407

  
416 408
  $main::lxdebug->leave_sub();
417 409

  
418
  return $rc;
410
  return 1;
419 411
}
420 412

  
421 413
sub ap_transactions {
......
626 618
}
627 619

  
628 620
sub post_payment {
621
  my ($self, $myconfig, $form, $locale) = @_;
629 622
  $main::lxdebug->enter_sub();
630 623

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

  
626
  $::lxdebug->leave_sub;
627
  return $rc;
628
}
629

  
630
sub _post_payment {
631 631
  my ($self, $myconfig, $form, $locale) = @_;
632 632

  
633
  # connect to database, turn off autocommit
634
  my $dbh = $form->dbconnect_noauto($myconfig);
633
  my $dbh = SL::DB->client->dbh;
635 634

  
636 635
  my (%payments, $old_form, $row, $item, $query, %keep_vars);
637 636

  
......
680 679

  
681 680
  restore_form($old_form);
682 681

  
683
  my $rc = $dbh->commit();
684
  $dbh->disconnect();
685

  
686
  $main::lxdebug->leave_sub();
687

  
688
  return $rc;
682
  return 1;
689 683
}
690 684

  
691 685
sub setup_form {
......
819 813
}
820 814

  
821 815
sub storno {
816
  my ($self, $form, $myconfig, $id) = @_;
822 817
  $main::lxdebug->enter_sub();
823 818

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

  
821
  $::lxdebug->leave_sub;
822
  return $rc;
823
}
824

  
825
sub _storno {
824 826
  my ($self, $form, $myconfig, $id) = @_;
825 827

  
826 828
  my ($query, $new_id, $storno_row, $acc_trans_rows);
827
  my $dbh = $form->get_standard_dbh($myconfig);
829
  my $dbh = SL::DB->client->dbh;
828 830

  
829 831
  $query = qq|SELECT nextval('glid')|;
830 832
  ($new_id) = selectrow_query($form, $dbh, $query);
......
869 871

  
870 872
  map { IO->set_datepaid(table => 'ap', id => $_, dbh => $dbh) } ($id, $new_id);
871 873

  
872
  $dbh->commit;
873

  
874
  $main::lxdebug->leave_sub();
874
  return 1;
875 875
}
876 876

  
877 877
1;

Auch abrufbar als: Unified diff