X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/9c8450d924f0318190cf451a533e1ff883a2fa16..7635f647ec7dcdef51684b21601ee0930ea2bc5b:/SL/AM.pm diff --git a/SL/AM.pm b/SL/AM.pm index 61441faec..4934d866c 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -40,6 +40,7 @@ package AM; use Carp; use Data::Dumper; use Encode; +use List::MoreUtils qw(any); use SL::DBUtils; use strict; @@ -207,17 +208,15 @@ sub save_account { # connect to database, turn off AutoCommit my $dbh = $form->dbconnect_noauto($myconfig); - # 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); + for (qw(AR_include_in_dropdown AP_include_in_dropdown summary_account)) { + $form->{$form->{$_}} = $form->{$_} if $form->{$_}; } - 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}; + # sanity check, can't have AR with AR_... + if ($form->{AR} || $form->{AP} || $form->{IC}) { + if (any { $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)) { + $form->error($::locale->text('It is not allowed that a summary account occurs in a drop-down menu!')); + } } $form->{link} = ""; @@ -265,8 +264,8 @@ sub save_account { 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"}, ''); } @values = (); @@ -1063,10 +1062,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 = @@ -1087,9 +1082,9 @@ sub save_defaults { vendornumber = ?, articlenumber = ?, servicenumber = ?, + assemblynumber = ?, sdonumber = ?, pdonumber = ?, - curr = ?, businessnumber = ?, weightunit = ?, language_id = ?|; @@ -1100,12 +1095,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(); @@ -1119,7 +1128,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 = ?|; @@ -1127,10 +1136,6 @@ sub save_preferences { my $rc = $dbh->commit(); - # save first currency in myconfig - $currency =~ s/:.*//; - $form->{currency} = $currency; - $form->{businessnumber} = $businessnumber; $myconfig = User->new(login => $form->{login}); @@ -1289,25 +1294,12 @@ sub defaultaccounts { $sth->finish; #Get currencies: - $query = qq|SELECT curr FROM currencies ORDER BY id|; - - $form->{CURRENCIES} = []; - - $sth = prepare_execute_query($form, $dbh, $query); - $sth->execute || $form->dberror($query); - while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { - push @{ $form->{ CURRENCIES } } , $ref; - } - $sth->finish; + $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 curr AS defaultcurrency FROM currencies WHERE id = (SELECT curr FROM defaults LIMIT 1);|; - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - - $form->{defaultcurrency} = ($sth->fetchrow_hashref("NAME_lc"))->{defaultcurrency}; - - $sth->finish; + $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; @@ -1740,7 +1732,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); @@ -1800,6 +1792,7 @@ sub get_tax { taxdescription, round(rate * 100, 2) AS rate, chart_id, + chart_categories, (id IN (SELECT tax_id FROM acc_trans)) AS tax_already_used FROM tax @@ -1857,14 +1850,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}); @@ -1875,9 +1877,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); @@ -2113,9 +2116,10 @@ sub get_warehouse { map { $form->{$_} = $ref->{$_} } keys %{ $ref }; $query = qq|SELECT b.*, EXISTS - (SELECT i.warehouse_id - FROM inventory i + (SELECT i.warehouse_id, p.warehouse_id + FROM inventory i, parts p WHERE i.bin_id = b.id + OR p.bin_id = b.id LIMIT 1) AS in_use FROM bin b