X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAM.pm;h=407fc487ccca9a4e19631e5a6482b336f6195803;hb=7d52ebe6fad400f4668d030dabb8892c016557ae;hp=c80177293dc751adce9028a10fd74e441e9f440e;hpb=dbbf892309056494e9243df8b7599096ef9e42c5;p=kivitendo-erp.git diff --git a/SL/AM.pm b/SL/AM.pm index c80177293..407fc487c 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -199,6 +199,9 @@ sub get_account { sub save_account { $main::lxdebug->enter_sub(); + # TODO: it should be forbidden to change an account to a heading if there + # have been bookings to this account in the past + my ($self, $myconfig, $form) = @_; # connect to database, turn off AutoCommit @@ -207,7 +210,14 @@ sub save_account { # sanity check, can't have AR with AR_... if ($form->{AR} || $form->{AP} || $form->{IC}) { map { delete $form->{$_} } - qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_sale IC_cogs IC_taxpart IC_income IC_expense IC_taxservice CT_tax); + qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_sale IC_cogs IC_taxpart IC_income IC_expense IC_taxservice); + } + + if ($form->{AR_include_in_dropdown}) { + $form->{$form->{AR_include_in_dropdown}} = $form->{AR_include_in_dropdown}; + } + if ($form->{AP_include_in_dropdown}) { + $form->{$form->{AP_include_in_dropdown}} = $form->{AP_include_in_dropdown}; } $form->{link} = ""; @@ -218,7 +228,7 @@ sub save_account { $form->{IC}, $form->{IC_sale}, $form->{IC_cogs}, $form->{IC_taxpart}, $form->{IC_income}, $form->{IC_expense}, - $form->{IC_taxservice}, $form->{CT_tax} + $form->{IC_taxservice} ) { $form->{link} .= "${item}:" if ($item); } @@ -233,16 +243,51 @@ sub save_account { $form->{id} = ""; } + $query = ' + SELECT accno + FROM chart + WHERE accno = ?'; + + my @values = ($form->{accno}); + + if ( $form->{id} ) { + $query .= ' AND NOT id = ?'; + push(@values, $form->{id}); + } + + my ($accno) = selectrow_query($form, $dbh, $query, @values); + + if ($accno) { + $form->error($::locale->text('Account number not unique!')); + } + + if (!$form->{id} || $form->{id} eq "") { $query = qq|SELECT nextval('id')|; ($form->{"id"}) = selectrow_query($form, $dbh, $query); - $query = qq|INSERT INTO chart (id, accno) VALUES (?, ?)|; - do_query($form, $dbh, $query, $form->{"id"}, $form->{"accno"}); + $query = qq|INSERT INTO chart (id, accno, link) VALUES (?, ?, ?)|; + do_query($form, $dbh, $query, $form->{"id"}, $form->{"accno"}, ''); } - my @values; + @values = (); + if ($form->{id}) { + + # if charttype is heading make sure certain values are empty + # specifically, if charttype is changed from an existing account, empty the + # fields unnecessary for headings, so that e.g. heading doesn't appear in + # drop-down menues due to still having a valid "link" entry + + if ( $form->{charttype} eq 'H' ) { + $form->{link} = ''; + $form->{pos_bwa} = ''; + $form->{pos_bilanz} = ''; + $form->{pos_eur} = ''; + $form->{new_chart_id} = ''; + $form->{valid_from} = ''; + }; + $query = qq|UPDATE chart SET accno = ?, description = ?, @@ -272,6 +317,7 @@ sub save_account { $form->{id}, ); + } do_query($form, $dbh, $query, @values); @@ -429,11 +475,9 @@ sub delete_account { do_query($form, $dbh, $query, $form->{id}); } - foreach my $table (qw(partstax customertax vendortax tax)) { - $query = qq|DELETE FROM $table - WHERE chart_id = ?|; - do_query($form, $dbh, $query, $form->{id}); - } + $query = qq|DELETE FROM tax + WHERE chart_id = ?|; + do_query($form, $dbh, $query, $form->{id}); # delete chart of account record $query = qq|DELETE FROM chart @@ -454,110 +498,6 @@ sub delete_account { return $rc; } -sub departments { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|SELECT d.id, d.description, d.role - FROM department d - ORDER BY 2|; - - my $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - - $form->{ALL} = []; - while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { - push @{ $form->{ALL} }, $ref; - } - - $sth->finish; - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - -sub get_department { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|SELECT d.description, d.role - FROM department d - WHERE d.id = ?|; - my $sth = $dbh->prepare($query); - $sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})"); - - my $ref = $sth->fetchrow_hashref("NAME_lc"); - - map { $form->{$_} = $ref->{$_} } keys %$ref; - - $sth->finish; - - # see if it is in use - $query = qq|SELECT count(*) FROM dpt_trans d - WHERE d.department_id = ?|; - ($form->{orphaned}) = selectrow_query($form, $dbh, $query, $form->{id}); - - $form->{orphaned} = !$form->{orphaned}; - $sth->finish; - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - -sub save_department { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - my ($query); - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my @values = ($form->{description}, $form->{role}); - if ($form->{id}) { - $query = qq|UPDATE department SET - description = ?, role = ? - WHERE id = ?|; - push(@values, $form->{id}); - } else { - $query = qq|INSERT INTO department - (description, role) - VALUES (?, ?)|; - } - do_query($form, $dbh, $query, @values); - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - -sub delete_department { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - my ($query); - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - $query = qq|DELETE FROM department - WHERE id = ?|; - do_query($form, $dbh, $query, $form->{id}); - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - sub lead { $main::lxdebug->enter_sub(); @@ -624,7 +564,7 @@ sub save_lead { $query = qq|UPDATE leads SET lead = ? WHERE id = ?|; - puhs(@values, $form->{id}); + push(@values, $form->{id}); } else { $query = qq|INSERT INTO leads (lead) @@ -655,106 +595,6 @@ sub delete_lead { $main::lxdebug->leave_sub(); } -sub business { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|SELECT id, description, discount, customernumberinit, salesman - FROM business - ORDER BY 2|; - - my $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - - while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { - push @{ $form->{ALL} }, $ref; - } - - $sth->finish; - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - -sub get_business { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = - qq|SELECT b.description, b.discount, b.customernumberinit, b.salesman - FROM business b - WHERE b.id = ?|; - my $sth = $dbh->prepare($query); - $sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})"); - - my $ref = $sth->fetchrow_hashref("NAME_lc"); - - map { $form->{$_} = $ref->{$_} } keys %$ref; - - $sth->finish; - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - -sub save_business { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - my ($query); - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my @values = ($form->{description}, $form->{discount}, $form->{customernumberinit}, $form->{salesman} ? 't' : 'f'); - # id is the old record - if ($form->{id}) { - $query = qq|UPDATE business SET - description = ?, - discount = ?, - customernumberinit = ?, - salesman = ? - WHERE id = ?|; - push(@values, $form->{id}); - } else { - $query = qq|INSERT INTO business - (description, discount, customernumberinit, salesman) - VALUES (?, ?, ?, ?)|; - } - do_query($form, $dbh, $query, @values); - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - -sub delete_business { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|DELETE FROM business - WHERE id = ?|; - do_query($form, $dbh, $query, $form->{id}); - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - - sub language { $main::lxdebug->enter_sub(); @@ -1149,7 +989,9 @@ sub prepare_template_filename { } $filename .= "." . ($form->{format} eq "html" ? "html" : "tex"); - $filename =~ s|.*/||; + if ($form->{"formname"} =~ m|\.\.| || $form->{"formname"} =~ m|^/|) { + $filename =~ s|.*/||; + } $display_filename = $filename; $filename = "$myconfig->{templates}/$filename"; } @@ -1193,7 +1035,7 @@ sub save_template { my $error = ""; - if (open(TEMPLATE, ">$filename")) { + if (open(TEMPLATE, ">", $filename)) { $content = Encode::encode('utf-8-strict', $content) if $::locale->is_utf8; $content =~ s/\r\n/\n/g; print(TEMPLATE $content); @@ -1249,7 +1091,8 @@ sub save_defaults { pdonumber = ?, curr = ?, businessnumber = ?, - weightunit = ?|; + weightunit = ?, + language_id = ?|; my @values = ($accnos{inventory_accno}, $accnos{income_accno}, $accnos{expense_accno}, $accnos{fxgain_accno}, $accnos{fxloss_accno}, $accnos{ar_paid_accno}, $form->{invnumber}, $form->{cnnumber}, @@ -1259,7 +1102,8 @@ sub save_defaults { $form->{articlenumber}, $form->{servicenumber}, $form->{sdonumber}, $form->{pdonumber}, $currency, - $form->{businessnumber}, $form->{weightunit}); + $form->{businessnumber}, $form->{weightunit}, + conv_i($form->{language_id})); do_query($form, $dbh, $query, @values); $dbh->commit(); @@ -1289,7 +1133,7 @@ sub save_preferences { $form->{businessnumber} = $businessnumber; - $myconfig = new User($form->{login}); + $myconfig = User->new(login => $form->{login}); foreach my $item (keys %$form) { $myconfig->{$item} = $form->{$item}; @@ -1515,6 +1359,7 @@ sub retrieve_units { $main::lxdebug->enter_sub(); my ($self, $myconfig, $form, $prefix) = @_; + $prefix ||= ''; my $dbh = $form->get_standard_dbh; @@ -1568,13 +1413,13 @@ sub retrieve_all_units { my $self = shift; - if (!$main::all_units) { - $main::all_units = $self->retrieve_units(\%main::myconfig, $main::form); + if (!$::request->{cache}{all_units}) { + $::request->{cache}{all_units} = $self->retrieve_units(\%main::myconfig, $main::form); } $main::lxdebug->leave_sub(); - return $main::all_units; + return $::request->{cache}{all_units}; } @@ -1681,6 +1526,10 @@ sub convert_unit { $main::lxdebug->enter_sub(2); my ($this, $a, $b, $all_units) = @_; + if (!$all_units) { + $all_units = $this->retrieve_all_units; + } + $main::lxdebug->leave_sub(2) and return 0 unless $a && $b; $main::lxdebug->leave_sub(2) and return 0 unless $all_units->{$a} && $all_units->{$b}; $main::lxdebug->leave_sub(2) and return 0 unless $all_units->{$a}{base_unit} eq $all_units->{$b}{base_unit}; @@ -1928,7 +1777,9 @@ sub get_tax { taxkey, taxdescription, round(rate * 100, 2) AS rate, - chart_id + chart_id, + (id IN (SELECT tax_id + FROM acc_trans)) AS tax_already_used FROM tax WHERE id = ? |;