Revision 4812c084
Von Sven Schöling vor mehr als 8 Jahren hinzugefügt
SL/IR.pm | ||
---|---|---|
47 | 47 |
use SL::MoreCommon; |
48 | 48 |
use SL::DB::Default; |
49 | 49 |
use SL::DB::TaxZone; |
50 |
use SL::DB; |
|
50 | 51 |
use List::Util qw(min); |
51 | 52 |
|
52 | 53 |
use strict; |
53 | 54 |
|
54 | 55 |
sub post_invoice { |
56 |
my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_; |
|
55 | 57 |
$main::lxdebug->enter_sub(); |
56 | 58 |
|
59 |
my $rc = SL::DB->client->with_transaction(\&_post_invoice, $self, $myconfig, $form, $provided_dbh, $payments_only); |
|
60 |
|
|
61 |
$::lxdebug->leave_sub; |
|
62 |
return $rc; |
|
63 |
} |
|
64 |
|
|
65 |
sub _post_invoice { |
|
57 | 66 |
my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_; |
58 | 67 |
|
59 |
# connect to database, turn off autocommit |
|
60 |
my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig); |
|
68 |
my $dbh = $provided_dbh || SL::DB->client->dbh; |
|
61 | 69 |
my $restricter = SL::HTML::Restrict->create; |
62 | 70 |
|
63 | 71 |
$form->{defaultcurrency} = $form->get_default_currency($myconfig); |
... | ... | |
691 | 699 |
$query = qq|UPDATE ap SET paid = ? WHERE id = ?|; |
692 | 700 |
do_query($form, $dbh, $query, $form->{paid}, conv_i($form->{id})); |
693 | 701 |
$form->new_lastmtime('ap'); |
694 |
if (!$provided_dbh) { |
|
695 |
$dbh->commit(); |
|
696 |
$dbh->disconnect(); |
|
697 |
} |
|
698 | 702 |
|
699 |
$main::lxdebug->leave_sub(); |
|
700 | 703 |
return; |
701 | 704 |
} |
702 | 705 |
|
... | ... | |
820 | 823 |
$datev->export; |
821 | 824 |
|
822 | 825 |
if ($datev->errors) { |
823 |
$dbh->rollback; |
|
824 | 826 |
die join "\n", $::locale->text('DATEV check returned errors:'), $datev->errors; |
825 | 827 |
} |
826 | 828 |
} |
827 | 829 |
|
828 |
my $rc = 1; |
|
829 |
if (!$provided_dbh) { |
|
830 |
$rc = $dbh->commit(); |
|
831 |
$dbh->disconnect(); |
|
832 |
} |
|
833 |
|
|
834 |
$main::lxdebug->leave_sub(); |
|
835 |
|
|
836 |
return $rc; |
|
830 |
return 1; |
|
837 | 831 |
} |
838 | 832 |
|
839 | 833 |
sub reverse_invoice { |
... | ... | |
919 | 913 |
my ($self, $myconfig, $form) = @_; |
920 | 914 |
my $query; |
921 | 915 |
# connect to database |
922 |
my $dbh = $form->dbconnect_noauto($myconfig);
|
|
916 |
my $dbh = SL::DB->client->dbh;
|
|
923 | 917 |
|
924 |
&reverse_invoice($dbh, $form);
|
|
918 |
SL::DB->client->with_transaction(sub{
|
|
925 | 919 |
|
926 |
my @values = (conv_i($form->{id})); |
|
927 |
|
|
928 |
# delete zero entries |
|
929 |
# wtf? use case for this? |
|
930 |
$query = qq|DELETE FROM acc_trans WHERE amount = 0|; |
|
931 |
do_query($form, $dbh, $query); |
|
920 |
&reverse_invoice($dbh, $form); |
|
932 | 921 |
|
922 |
my @values = (conv_i($form->{id})); |
|
933 | 923 |
|
934 |
my @queries = (
|
|
935 |
qq|DELETE FROM invoice WHERE trans_id = ?|,
|
|
936 |
qq|DELETE FROM ap WHERE id = ?|,
|
|
937 |
); |
|
924 |
# delete zero entries
|
|
925 |
# wtf? use case for this?
|
|
926 |
$query = qq|DELETE FROM acc_trans WHERE amount = 0|;
|
|
927 |
do_query($form, $dbh, $query);
|
|
938 | 928 |
|
939 |
map { do_query($form, $dbh, $_, @values) } @queries; |
|
940 | 929 |
|
941 |
my $rc = $dbh->commit; |
|
942 |
$dbh->disconnect; |
|
930 |
my @queries = ( |
|
931 |
qq|DELETE FROM invoice WHERE trans_id = ?|, |
|
932 |
qq|DELETE FROM ap WHERE id = ?|, |
|
933 |
); |
|
943 | 934 |
|
944 |
$main::lxdebug->leave_sub(); |
|
935 |
map { do_query($form, $dbh, $_, @values) } @queries; |
|
936 |
}); |
|
945 | 937 |
|
946 |
return $rc;
|
|
938 |
return 1;
|
|
947 | 939 |
} |
948 | 940 |
|
949 | 941 |
sub retrieve_invoice { |
... | ... | |
1564 | 1556 |
} |
1565 | 1557 |
|
1566 | 1558 |
sub post_payment { |
1559 |
my ($self, $myconfig, $form, $locale) = @_; |
|
1567 | 1560 |
$main::lxdebug->enter_sub(); |
1568 | 1561 |
|
1562 |
my $rc = SL::DB->client->with_transaction(\&_post_payment, $self, $myconfig, $form, $locale); |
|
1563 |
|
|
1564 |
$::lxdebug->leave_sub; |
|
1565 |
return $rc; |
|
1566 |
} |
|
1567 |
|
|
1568 |
sub _post_payment { |
|
1569 | 1569 |
my ($self, $myconfig, $form, $locale) = @_; |
1570 | 1570 |
|
1571 |
# connect to database, turn off autocommit |
|
1572 |
my $dbh = $form->dbconnect_noauto($myconfig); |
|
1571 |
my $dbh = SL::DB->client->dbh; |
|
1573 | 1572 |
|
1574 | 1573 |
my (%payments, $old_form, $row, $item, $query, %keep_vars); |
1575 | 1574 |
|
... | ... | |
1625 | 1624 |
|
1626 | 1625 |
restore_form($old_form); |
1627 | 1626 |
|
1628 |
my $rc = $dbh->commit(); |
|
1629 |
$dbh->disconnect(); |
|
1630 |
|
|
1631 |
$main::lxdebug->leave_sub(); |
|
1632 |
|
|
1633 |
return $rc; |
|
1627 |
return 1; |
|
1634 | 1628 |
} |
1635 | 1629 |
|
1636 | 1630 |
sub get_duedate { |
Auch abrufbar als: Unified diff
IR: single-dbh