Option für Datev-Check in Mandantenkonfiguration verschoben.
[kivitendo-erp.git] / sql / Pg-upgrade2 / defaults_datev_check.pl
1 # @tag: defaults_datev_check
2 # @description: Einstellung für DATEV-Überprüfungen (datev_check) vom Config-File in die DB verlagern.
3 # @depends: release_2_7_0
4 # @charset: utf-8
5
6 use utf8;
7 use strict;
8
9 die("This script cannot be run from the command line.") unless ($main::form);
10
11 sub mydberror {
12   my ($msg) = @_;
13   die($dbup_locale->text("Database update error:") .
14       "<br>$msg<br>" . $DBI::errstr);
15 }
16
17 sub do_query {
18   my ($query, $may_fail) = @_;
19
20   if (!$dbh->do($query)) {
21     mydberror($query) unless ($may_fail);
22     $dbh->rollback();
23     $dbh->begin_work();
24   }
25 }
26
27 sub do_update {
28
29   # this query will fail if column already exist (new database)
30   do_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_sales_invoice boolean    DEFAULT true|, 1);
31   do_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_purchase_invoice boolean DEFAULT true|, 1);
32   do_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_ar_transaction boolean   DEFAULT true|, 1);
33   do_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_ap_transaction boolean   DEFAULT true|, 1);
34   do_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_gl_transaction boolean   DEFAULT true|, 1);
35
36   # check current configuration and set default variables accordingly, so that
37   # kivitendo's behaviour isn't changed by this update
38   # if checks are not set in config set it to true
39   foreach my $check (qw(check_on_sales_invoice check_on_purchase_invoice check_on_ar_transaction check_on_ap_transaction check_on_gl_transaction)) {
40     my $check_set = 1;
41     if (!$::lx_office_conf{datev_check}->{$check}) {
42       $check_set = 0;
43     }
44
45     my $update_column = "UPDATE defaults SET datev_$check = '$check_set';";
46     do_query($update_column);
47   }
48
49
50   return 1;
51 }
52
53 return do_update();
54