X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAM.pm;h=6989e3590aa3e38cd60cc078fd382ea363aabcb9;hb=ba6a136694f2e54e7bf21b1ecfabfcb872784ef4;hp=ab712c85231331c88e12277e633ab5c3dc619ae7;hpb=a064deaf7fb181680130a873efc5fb895fe7ba35;p=kivitendo-erp.git diff --git a/SL/AM.pm b/SL/AM.pm index ab712c852..6989e3590 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -210,7 +210,11 @@ 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); + } + + for (qw(AR_include_in_dropdown AP_include_in_dropdown)) { + $form->{$form->{$_}} = $form->{$_} if $form->{$_}; } $form->{link} = ""; @@ -221,7 +225,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); } @@ -236,14 +240,33 @@ 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}) { @@ -449,11 +472,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 @@ -540,7 +561,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) @@ -965,7 +986,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"; } @@ -1037,10 +1060,6 @@ sub save_defaults { my %accnos; 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}; - my $currency = join ':', @currencies; - # these defaults are database wide my $query = @@ -1061,9 +1080,9 @@ sub save_defaults { vendornumber = ?, articlenumber = ?, servicenumber = ?, + assemblynumber = ?, sdonumber = ?, pdonumber = ?, - curr = ?, businessnumber = ?, weightunit = ?, language_id = ?|; @@ -1074,12 +1093,26 @@ sub save_defaults { $form->{sqnumber}, $form->{rfqnumber}, $form->{customernumber}, $form->{vendornumber}, $form->{articlenumber}, $form->{servicenumber}, + $form->{assemblynumber}, $form->{sdonumber}, $form->{pdonumber}, - $currency, $form->{businessnumber}, $form->{weightunit}, conv_i($form->{language_id})); do_query($form, $dbh, $query, @values); + $main::lxdebug->message(0, "es gibt rowcount: " . $form->{rowcount}); + + for my $i (1..$form->{rowcount}) { + if ($form->{"curr_$i"} ne $form->{"old_curr_$i"}) { + $query = qq|UPDATE currencies SET name = ? WHERE name = ?|; + do_query($form, $dbh, $query, $form->{"curr_$i"}, $form->{"old_curr_$i"}); + } + } + + if (length($form->{new_curr}) > 0) { + $query = qq|INSERT INTO currencies (name) VALUES (?)|; + do_query($form, $dbh, $query, $form->{new_curr}); + } + $dbh->commit(); $main::lxdebug->leave_sub(); @@ -1093,7 +1126,7 @@ sub save_preferences { my $dbh = $form->get_standard_dbh($myconfig); - my ($currency, $businessnumber) = selectrow_query($form, $dbh, qq|SELECT curr, businessnumber FROM defaults|); + my ($businessnumber) = selectrow_query($form, $dbh, qq|SELECT businessnumber FROM defaults|); # update name my $query = qq|UPDATE employee SET name = ? WHERE login = ?|; @@ -1101,13 +1134,9 @@ sub save_preferences { my $rc = $dbh->commit(); - # save first currency in myconfig - $currency =~ s/:.*//; - $form->{currency} = $currency; - $form->{businessnumber} = $businessnumber; - $myconfig = new User($form->{login}); + $myconfig = User->new(login => $form->{login}); foreach my $item (keys %$form) { $myconfig->{$item} = $form->{$item}; @@ -1261,6 +1290,15 @@ sub defaultaccounts { } $sth->finish; + + #Get currencies: + $query = qq|SELECT name AS curr FROM currencies ORDER BY id|; + $form->{CURRENCIES} = selectall_hashref_query($form, $dbh, $query); + + #Which of them is the default currency? + $query = qq|SELECT name AS defaultcurrency FROM currencies WHERE id = (SELECT currency_id FROM defaults LIMIT 1);|; + ($form->{defaultcurrency}) = selectrow_query($form, $dbh, $query); + $dbh->disconnect; $main::lxdebug->leave_sub(); @@ -1333,6 +1371,7 @@ sub retrieve_units { $main::lxdebug->enter_sub(); my ($self, $myconfig, $form, $prefix) = @_; + $prefix ||= ''; my $dbh = $form->get_standard_dbh; @@ -1499,6 +1538,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}; @@ -1687,7 +1730,7 @@ sub taxes { (SELECT accno FROM chart WHERE id = chart_id) AS taxnumber, (SELECT description FROM chart WHERE id = chart_id) AS account_description FROM tax t - ORDER BY taxkey|; + ORDER BY taxkey, rate|; my $sth = $dbh->prepare($query); $sth->execute || $form->dberror($query); @@ -1746,7 +1789,10 @@ sub get_tax { taxkey, taxdescription, round(rate * 100, 2) AS rate, - chart_id + chart_id, + chart_categories, + (id IN (SELECT tax_id + FROM acc_trans)) AS tax_already_used FROM tax WHERE id = ? |; @@ -1802,14 +1848,23 @@ sub save_tax { $form->{rate} = $form->{rate} / 100; - my @values = ($form->{taxkey}, $form->{taxdescription}, $form->{rate}, $form->{chart_id}, $form->{chart_id} ); + my $chart_categories = ''; + $chart_categories .= 'A' if $form->{asset}; + $chart_categories .= 'L' if $form->{liability}; + $chart_categories .= 'Q' if $form->{equity}; + $chart_categories .= 'I' if $form->{revenue}; + $chart_categories .= 'E' if $form->{expense}; + $chart_categories .= 'C' if $form->{costs}; + + my @values = ($form->{taxkey}, $form->{taxdescription}, $form->{rate}, $form->{chart_id}, $form->{chart_id}, $chart_categories); if ($form->{id} ne "") { $query = qq|UPDATE tax SET taxkey = ?, taxdescription = ?, rate = ?, chart_id = ?, - taxnumber = (SELECT accno FROM chart WHERE id= ? ) + taxnumber = (SELECT accno FROM chart WHERE id= ? ), + chart_categories = ? WHERE id = ?|; push(@values, $form->{id}); @@ -1820,9 +1875,10 @@ sub save_tax { taxdescription, rate, chart_id, - taxnumber + taxnumber, + chart_categories ) - VALUES (?, ?, ?, ?, (SELECT accno FROM chart WHERE id = ?) )|; + VALUES (?, ?, ?, ?, (SELECT accno FROM chart WHERE id = ?), ? )|; } do_query($form, $dbh, $query, @values);