kivitendo/sql/Pg-upgrade2/umstellung_eur.pl @ 7b1da9c3
43f9b1c5 | Geoffrey Richardson | # @tag: umstellung_eur
|
||
469f6be7 | Jan Büren | # @description: Variable eur umstellen: bitte in doc/dokumentation.pdf das entsprechende Kapitel zur Konfiguration von EUR lesen
|
||
b153a59c | Geoffrey Richardson | # @depends: release_2_6_3
|
||
347f2cff | Moritz Bunkus | package SL::DBUpgrade2::umstellung_eur;
|
||
43f9b1c5 | Geoffrey Richardson | |||
347f2cff | Moritz Bunkus | use strict;
|
||
43f9b1c5 | Geoffrey Richardson | use utf8;
|
||
347f2cff | Moritz Bunkus | use parent qw(SL::DBUpgrade2::Base);
|
||
43f9b1c5 | Geoffrey Richardson | |||
347f2cff | Moritz Bunkus | # this script relies on $eur still being set in kivitendo.conf, and the
|
||
# variable available in $::lx_office_conf{system}->{eur}
|
||||
43f9b1c5 | Geoffrey Richardson | |||
347f2cff | Moritz Bunkus | sub run {
|
||
my ($self) = @_;
|
||||
43f9b1c5 | Geoffrey Richardson | |||
# check if accounting_method has already been set (new database), if so return
|
||||
# only set variables according to eur for update of existing database
|
||||
foreach my $column (qw(accounting_method inventory_system profit_determination)) {
|
||||
# this query will fail if columns already exist (new database)
|
||||
03457b5b | Moritz Bunkus | $self->db_query(qq|ALTER TABLE defaults ADD COLUMN ${column} TEXT|, may_fail => 1);
|
||
43f9b1c5 | Geoffrey Richardson | }
|
||
my $accounting_method;
|
||||
my $inventory_system;
|
||||
my $profit_determination;
|
||||
# check current configuration and set default variables accordingly, so that
|
||||
008c2e15 | Moritz Bunkus | # kivitendo behaviour isn't changed by this update
|
||
43f9b1c5 | Geoffrey Richardson | |||
40eb5e8b | Sven Schöling | if (!defined $::lx_office_conf{system}->{eur} || $::lx_office_conf{system}->{eur} == 0 ) {
|
||
43f9b1c5 | Geoffrey Richardson | $accounting_method = 'accrual';
|
||
$inventory_system = 'perpetual';
|
||||
$profit_determination = 'balance';
|
||||
} elsif ( $::lx_office_conf{system}->{eur} == 1 ) {
|
||||
$accounting_method = 'cash';
|
||||
$inventory_system = 'periodic';
|
||||
$profit_determination = 'income';
|
||||
} else {
|
||||
die "illegal configuration of eur, must be 0 or 1, not " . $::lx_office_conf{system}->{eur} . "\n";
|
||||
# or maybe just return 1, dont do anything, because we assume everything is
|
||||
# already set, or has maybe already been deleted
|
||||
};
|
||||
# only set parameters if they haven't already been set (this in only the case
|
||||
# when upgrading)
|
||||
469f6be7 | Jan Büren | my $update_eur = "UPDATE defaults set accounting_method = '$accounting_method' where accounting_method is null;" .
|
||
43f9b1c5 | Geoffrey Richardson | "UPDATE defaults set inventory_system = '$inventory_system' where inventory_system is null; " .
|
||
"UPDATE defaults set profit_determination = '$profit_determination' where profit_determination is null;";
|
||||
347f2cff | Moritz Bunkus | $self->db_query($update_eur);
|
||
43f9b1c5 | Geoffrey Richardson | |||
return 1;
|
||||
}
|
||||
347f2cff | Moritz Bunkus | 1;
|