X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAM.pm;h=445abd2e39c308bd0e9a03affb0128c2be2b88ef;hb=4791db863d4fa954318024ea1d79e62572ae2eb1;hp=1dbf9d82f5b85364ec00013ac1bdff619b56f587;hpb=8ab8cad9c06edcaa424a13cd6e23d39a02135f07;p=kivitendo-erp.git diff --git a/SL/AM.pm b/SL/AM.pm index 1dbf9d82f..445abd2e3 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -39,6 +39,7 @@ package AM; use Carp; use Data::Dumper; +use Encode; use SL::DBUtils; use strict; @@ -377,6 +378,21 @@ sub save_account { } + # Update chart.taxkey_id to the latest from taxkeys for this chart. + $query = <{id}); + # commit my $rc = $dbh->commit; $dbh->disconnect; @@ -1108,106 +1124,6 @@ sub swap_sortkeys { $main::lxdebug->leave_sub(); } -sub printer { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|SELECT id, printer_description, template_code, printer_command - FROM printers - 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_printer { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = - qq|SELECT p.printer_description, p.template_code, p.printer_command - FROM printers p - WHERE p.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_printer { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - my $query; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my @values = ($form->{printer_description}, - $form->{template_code}, - $form->{printer_command}); - - # id is the old record - if ($form->{id}) { - $query = qq|UPDATE printers SET - printer_description = ?, template_code = ?, printer_command = ? - WHERE id = ?|; - push(@values, $form->{id}); - } else { - $query = qq|INSERT INTO printers - (printer_description, template_code, printer_command) - VALUES (?, ?, ?)|; - } - do_query($form, $dbh, $query, @values); - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - -sub delete_printer { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|DELETE FROM printers - WHERE id = ?|; - do_query($form, $dbh, $query, $form->{id}); - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - sub payment { $main::lxdebug->enter_sub(); @@ -1415,6 +1331,8 @@ sub load_template { close(TEMPLATE); } + $content = Encode::decode('utf-8-strict', $content) if $::locale->is_utf8; + $main::lxdebug->leave_sub(); return ($content, $lines); @@ -1430,6 +1348,7 @@ sub save_template { my $error = ""; if (open(TEMPLATE, ">$filename")) { + $content = Encode::encode('utf-8-strict', $content) if $::locale->is_utf8; $content =~ s/\r\n/\n/g; print(TEMPLATE $content); close(TEMPLATE); @@ -1454,7 +1373,7 @@ sub save_defaults { my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); my %accnos; - map { ($accnos{$_}) = split(m/--/, $form->{$_}) } qw(inventory_accno income_accno expense_accno fxgain_accno fxloss_accno); + map { ($accnos{$_}) = split(m/--/, $form->{$_}) } qw(inventory_accno income_accno expense_accno fxgain_accno fxloss_accno ar_paid_accno); $form->{curr} =~ s/ //g; my @currencies = grep { $_ ne '' } split m/:/, $form->{curr}; @@ -1469,6 +1388,7 @@ sub save_defaults { expense_accno_id = (SELECT c.id FROM chart c WHERE c.accno = ?), fxgain_accno_id = (SELECT c.id FROM chart c WHERE c.accno = ?), fxloss_accno_id = (SELECT c.id FROM chart c WHERE c.accno = ?), + ar_paid_accno_id = (SELECT c.id FROM chart c WHERE c.accno = ?), invnumber = ?, cnnumber = ?, sonumber = ?, @@ -1481,19 +1401,18 @@ sub save_defaults { servicenumber = ?, sdonumber = ?, pdonumber = ?, - yearend = ?, curr = ?, businessnumber = ?, weightunit = ?|; my @values = ($accnos{inventory_accno}, $accnos{income_accno}, $accnos{expense_accno}, - $accnos{fxgain_accno}, $accnos{fxloss_accno}, + $accnos{fxgain_accno}, $accnos{fxloss_accno}, $accnos{ar_paid_accno}, $form->{invnumber}, $form->{cnnumber}, $form->{sonumber}, $form->{ponumber}, $form->{sqnumber}, $form->{rfqnumber}, $form->{customernumber}, $form->{vendornumber}, $form->{articlenumber}, $form->{servicenumber}, $form->{sdonumber}, $form->{pdonumber}, - $form->{yearend}, $currency, + $currency, $form->{businessnumber}, $form->{weightunit}); do_query($form, $dbh, $query, @values); @@ -1506,7 +1425,7 @@ sub save_defaults { sub save_preferences { $main::lxdebug->enter_sub(); - my ($self, $myconfig, $form, $webdav) = @_; + my ($self, $myconfig, $form) = @_; my $dbh = $form->get_standard_dbh($myconfig); @@ -1530,56 +1449,10 @@ sub save_preferences { $myconfig->{$item} = $form->{$item}; } - $myconfig->save_member($main::memberfile); + $myconfig->save_member; my $auth = $main::auth; - if ($auth->can_change_password() - && defined $form->{new_password} - && ($form->{new_password} ne '********')) { - $auth->change_password($form->{login}, $form->{new_password}); - - $form->{password} = $form->{new_password}; - $auth->set_session_value('password', $form->{password}); - $auth->create_or_refresh_session(); - } - - if ($webdav) { - my @webdavdirs = - qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen); - foreach my $directory (@webdavdirs) { - my $file = "webdav/" . $directory . "/webdav-user"; - my $newfile; - if ($myconfig->{$directory}) { - open(HTACCESS, "$file") or die "cannot open webdav-user $!\n"; - while () { - my ($login, $password) = split(/:/, $_); - if ($login ne $form->{login}) { - $newfile .= $_; - } - } - close(HTACCESS); - open(HTACCESS, "> $file") or die "cannot open webdav-user $!\n"; - $newfile .= $myconfig->{login} . ":" . $myconfig->{password} . "\n"; - print(HTACCESS $newfile); - close(HTACCESS); - } else { - $form->{$directory} = 0; - open(HTACCESS, "$file") or die "cannot open webdav-user $!\n"; - while () { - my ($login, $password) = split(/:/, $_); - if ($login ne $form->{login}) { - $newfile .= $_; - } - } - close(HTACCESS); - open(HTACCESS, "> $file") or die "cannot open webdav-user $!\n"; - print(HTACCESS $newfile); - close(HTACCESS); - } - } - } - $main::lxdebug->leave_sub(); return $rc; @@ -1624,6 +1497,7 @@ sub defaultaccounts { $form->{defaults}{IC_expense} = $form->{defaults}{expense_accno_id}; $form->{defaults}{FX_gain} = $form->{defaults}{fxgain_accno_id}; $form->{defaults}{FX_loss} = $form->{defaults}{fxloss_accno_id}; + $form->{defaults}{AR_paid} = $form->{defaults}{ar_paid_accno_id}; $form->{defaults}{weightunit} ||= 'kg'; @@ -1703,6 +1577,24 @@ sub defaultaccounts { if $ref->{taxnumber}; $form->{taxrates}{ $ref->{accno} }{rate} = $ref->{rate} if $ref->{rate}; } + # Abfrage für Standard Umlaufvermögenskonto + $query = + qq|SELECT id, accno, description, link | . + qq|FROM chart | . + qq|WHERE link LIKE ? |. + qq|ORDER BY accno|; + $sth = prepare_execute_query($form, $dbh, $query, '%AR%'); + $sth->execute || $form->dberror($query);# + while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { + foreach my $item (split(/:/, $ref->{link})) { + if ($item eq "AR_paid") { + %{ $form->{IC}{AR_paid}{ $ref->{accno} } } = ( + id => $ref->{id}, + description => $ref->{description} + ); + } + } + } $sth->finish; $dbh->disconnect; @@ -1778,7 +1670,7 @@ sub retrieve_units { my ($self, $myconfig, $form, $prefix) = @_; - my $dbh = $form->dbconnect($myconfig); + my $dbh = $form->get_standard_dbh; my $query = "SELECT *, base_unit AS original_base_unit FROM units"; @@ -1818,9 +1710,7 @@ sub retrieve_units { map({ $unit->{"LANGUAGES"}->{$ref->{"template_code"}}->{$_} = $ref->{$_} } keys(%{$ref})); } } - $sth->finish(); - - $dbh->disconnect(); + $sth->finish; $main::lxdebug->leave_sub(); @@ -2117,43 +2007,6 @@ sub save_units { $main::lxdebug->leave_sub(); } -sub swap_units { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form, $dir, $name_1) = @_; - - my $dbh = $form->dbconnect_noauto($myconfig); - - my $query; - - $query = qq|SELECT sortkey FROM units WHERE name = ?|; - my ($sortkey_1) = selectrow_query($form, $dbh, $query, $name_1); - - $query = - qq|SELECT sortkey FROM units | . - qq|WHERE sortkey | . ($dir eq "down" ? ">" : "<") . qq| ? | . - qq|ORDER BY sortkey | . ($dir eq "down" ? "ASC" : "DESC") . qq| LIMIT 1|; - my ($sortkey_2) = selectrow_query($form, $dbh, $query, $sortkey_1); - - if (defined($sortkey_1)) { - $query = qq|SELECT name FROM units WHERE sortkey = ${sortkey_2}|; - my ($name_2) = selectrow_query($form, $dbh, $query); - - if (defined($name_2)) { - $query = qq|UPDATE units SET sortkey = ? WHERE name = ?|; - my $sth = $dbh->prepare($query); - - do_statement($form, $sth, $query, $sortkey_1, $name_2); - do_statement($form, $sth, $query, $sortkey_2, $name_1); - } - } - - $dbh->commit(); - $dbh->disconnect(); - - $main::lxdebug->leave_sub(); -} - sub taxes { $main::lxdebug->enter_sub();