X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIS.pm;h=a7e3fa6c7535ee268bcc2a5ba46842ec269cc01b;hb=e411fd61f5174cd315a083226bb5e2e071a2caf4;hp=37861e5be694f01bb3c393b28f70d5462c3c8881;hpb=8bfb21c73f13e8efe4efbe4897f5bcc1ef7fd7e4;p=kivitendo-erp.git diff --git a/SL/IS.pm b/SL/IS.pm index 37861e5be..a7e3fa6c7 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -37,6 +37,7 @@ package IS; use List::Util qw(max); use SL::AM; +use SL::CVar; use SL::Common; use SL::DBUtils; use SL::MoreCommon; @@ -463,6 +464,12 @@ sub customer_details { map { $form->{"dv_$_"} = $ref->{$_} } keys %$ref; } + + my $custom_variables = CVar->get_custom_variables('dbh' => $dbh, + 'module' => 'CT', + 'trans_id' => $form->{customer_id}); + map { $form->{"vc_cvar_$_->{name}"} = $_->{value} } @{ $custom_variables }; + $dbh->disconnect; $main::lxdebug->leave_sub(); @@ -517,9 +524,7 @@ sub post_invoice { if ($form->{currency} eq $defaultcurrency) { $form->{exchangerate} = 1; } else { - $exchangerate = - $form->check_exchangerate($myconfig, $form->{currency}, - $form->{transdate}, 'buy'); + $exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'buy'); } $form->{exchangerate} = @@ -546,7 +551,7 @@ sub post_invoice { my $basqty; $form->{"marge_percent_$i"} = $form->parse_amount($myconfig, $form->{"marge_percent_$i"}) * 1; - $form->{"marge_absolut_$i"} = $form->parse_amount($myconfig, $form->{"marge_absolut_$i"}) * 1; + $form->{"marge_total_$i"} = $form->parse_amount($myconfig, $form->{"marge_total_$i"}) * 1; $form->{"lastcost_$i"} = $form->{"lastcost_$i"} * 1; if ($form->{storno}) { @@ -638,32 +643,11 @@ sub post_invoice { if ($form->{"inventory_accno_$i"} || $form->{"assembly_$i"}) { - # adjust parts onhand quantity - if ($form->{"assembly_$i"}) { - - # do not update if assembly consists of all services - $query = - qq|SELECT sum(p.inventory_accno_id) - FROM parts p - JOIN assembly a ON (a.parts_id = p.id) - WHERE a.id = ?|; - $sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{"id_$i"})); - - if ($sth->fetchrow_array) { - $form->update_balance($dbh, "parts", "onhand", qq|id = ?|, - $baseqty * -1, $form->{"id_$i"}) - unless $form->{shipped}; - } - $sth->finish; - # record assembly item as allocated &process_assembly($dbh, $form, $form->{"id_$i"}, $baseqty); - } else { - $form->update_balance($dbh, "parts", "onhand", qq|id = ?|, - $baseqty * -1, $form->{"id_$i"}) - unless $form->{shipped}; + } else { $allocated = &cogs($dbh, $form, $form->{"id_$i"}, $baseqty, $basefactor, $i); } } @@ -691,7 +675,7 @@ sub post_invoice { $form->{"serialnumber_$i"}, conv_i($pricegroup_id), $form->{"ordnumber_$i"}, conv_date($form->{"transdate_$i"}), $form->{"cusordnumber_$i"}, $baseqty, $form->{"subtotal_$i"} ? 't' : 'f', - $form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"}, + $form->{"marge_percent_$i"}, $form->{"marge_total_$i"}, $form->{"lastcost_$i"}, conv_i($form->{"price_factor_id_$i"}), conv_i($form->{"price_factor_id_$i"}), conv_i($form->{"marge_price_factor_$i"})); @@ -780,7 +764,7 @@ sub post_invoice { foreach my $trans_id (keys %{ $form->{amount} }) { foreach my $accno (keys %{ $form->{amount}{$trans_id} }) { - next unless ($form->{expense_inventory} =~ /$accno/); + next unless ($form->{expense_inventory} =~ /\Q$accno\E/); $form->{amount}{$trans_id}{$accno} = $form->round_amount($form->{amount}{$trans_id}{$accno}, 2); @@ -834,13 +818,8 @@ sub post_invoice { if ($form->{currency} eq $defaultcurrency) { $form->{"exchangerate_$i"} = 1; } else { - $exchangerate = - $form->check_exchangerate($myconfig, $form->{currency}, - $form->{"datepaid_$i"}, 'buy'); - - $form->{"exchangerate_$i"} = - $exchangerate ? $exchangerate - : $form->parse_amount($myconfig, $form->{"exchangerate_$i"}); + $exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'); + $form->{"exchangerate_$i"} = $exchangerate || $form->parse_amount($myconfig, $form->{"exchangerate_$i"}); } # record AR @@ -979,7 +958,7 @@ sub post_invoice { # add shipto $form->{name} = $form->{customer}; - $form->{name} =~ s/--$form->{customer_id}//; + $form->{name} =~ s/--\Q$form->{customer_id}\E//; if (!$form->{shipto_id}) { $form->add_shipto($dbh, $form->{id}, "AR"); @@ -1229,18 +1208,7 @@ sub reverse_invoice { while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - if ($ref->{inventory_accno_id} || $ref->{assembly}) { - - # if the invoice item is not an assemblyitem adjust parts onhand - if (!$ref->{assemblyitem}) { - - # adjust onhand in parts table - $form->update_balance($dbh, "parts", "onhand", qq|id = $ref->{parts_id}|, $ref->{qty}); - } - - # loop if it is an assembly - next if ($ref->{assembly}); - + if ($ref->{inventory_accno_id}) { # de-allocated purchases $query = qq|SELECT i.id, i.trans_id, i.allocated @@ -1458,7 +1426,7 @@ sub retrieve_invoice { } $ref->{taxaccounts} .= "$ptr->{accno} "; - if (!($form->{taxaccounts} =~ /$ptr->{accno}/)) { + if (!($form->{taxaccounts} =~ /\Q$ptr->{accno}\E/)) { $form->{"$ptr->{accno}_rate"} = $ptr->{rate}; $form->{"$ptr->{accno}_description"} = $ptr->{taxdescription}; $form->{"$ptr->{accno}_taxnumber"} = $ptr->{taxnumber}; @@ -1513,19 +1481,25 @@ sub get_customer { } my $cid = conv_i($form->{customer_id}); + my $payment_id; + + if ($form->{payment_id}) { + $payment_id = "(pt.id = ?) OR"; + push @values, conv_i($form->{payment_id}); + } # get customer $query = qq|SELECT c.name AS customer, c.discount, c.creditlimit, c.terms, - c.email, c.cc, c.bcc, c.language_id, c.payment_id AS customer_payment_id, + c.email, c.cc, c.bcc, c.language_id, c.payment_id, c.street, c.zipcode, c.city, c.country, c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, $duedate + COALESCE(pt.terms_netto, 0) AS duedate, b.discount AS tradediscount, b.description AS business FROM customer c LEFT JOIN business b ON (b.id = c.business_id) - LEFT JOIN payment_terms pt ON (c.payment_id = pt.id) + LEFT JOIN payment_terms pt ON ($payment_id (c.payment_id = pt.id)) WHERE c.id = ?|; push @values, $cid; $ref = selectfirst_hashref_query($form, $dbh, $query, @values); @@ -1550,23 +1524,6 @@ sub get_customer { $ref = selectfirst_hashref_query($form, $dbh, $query, $cid); map { $form->{$_} = $ref->{$_} } keys %$ref; - #check whether payment_terms are better than old payment_terms - if (($form->{payment_id} ne "") && ($form->{customer_payment_id} ne "")) { - $query = - qq|SELECT - (SELECT ranking FROM payment_terms WHERE id = ?), - (SELECT ranking FROM payment_terms WHERE id = ?)|; - my ($old_ranking, $new_ranking) - = selectrow_query($form, $dbh, $query, conv_i($form->{payment_id}), conv_i($form->{customer_payment_id})); - if ($new_ranking > $old_ranking) { - $form->{payment_id} = $form->{customer_payment_id}; - } - } - - if ($form->{payment_id} eq "") { - $form->{payment_id} = $form->{customer_payment_id}; - } - $form->{creditremaining} = $form->{creditlimit}; $query = qq|SELECT SUM(amount - paid) FROM ar WHERE customer_id = ?|; my ($value) = selectrow_query($form, $dbh, $query, $cid); @@ -1755,19 +1712,6 @@ sub retrieve_item { } } - #check whether payment_terms are better than old payment_terms - if (($form->{payment_id} ne "") && ($form->{part_payment_id} ne "")) { - $query = - qq|SELECT - (SELECT ranking FROM payment_terms WHERE id = ?), - (SELECT ranking FROM payment_terms WHERE id = ?)|; - my ($old_ranking, $new_ranking) - = selectrow_query($form, $dbh, $query, conv_i($form->{payment_id}), conv_i($form->{part_payment_id})); - if ($new_ranking > $old_ranking) { - $form->{payment_id} = $form->{customer_payment_id}; - } - } - if ($form->{payment_id} eq "") { $form->{payment_id} = $form->{part_payment_id}; } @@ -1801,7 +1745,7 @@ sub retrieve_item { } $ref->{taxaccounts} .= "$ptr->{accno} "; - if (!($form->{taxaccounts} =~ /$ptr->{accno}/)) { + if (!($form->{taxaccounts} =~ /\Q$ptr->{accno}\E/)) { $form->{"$ptr->{accno}_rate"} = $ptr->{rate}; $form->{"$ptr->{accno}_description"} = $ptr->{taxdescription}; $form->{"$ptr->{accno}_taxnumber"} = $ptr->{taxnumber}; @@ -1842,6 +1786,8 @@ sub retrieve_item { } } + $ref->{onhand} *= 1; + push @{ $form->{item_list} }, $ref; if ($form->{lizenzen}) { @@ -1882,8 +1828,6 @@ sub get_pricegroups_for_parts { my $i = 1; my $id = 0; - my $dimension_units = AM->retrieve_units($myconfig, $form, "dimension"); - my $service_units = AM->retrieve_units($myconfig, $form, "service"); my $all_units = AM->retrieve_units($myconfig, $form); while (($form->{"id_$i"}) or ($form->{"new_id_$i"})) { $form->{"PRICES"}{$i} = []; @@ -1916,9 +1860,8 @@ sub get_pricegroups_for_parts { # vergleichen und bei Unterschied den Preis entsprechend umrechnen. $form->{"selected_unit_$i"} = $form->{"unit_$i"} unless ($form->{"selected_unit_$i"}); - my $check_units = $form->{"inventory_accno_$i"} ? $dimension_units : $service_units; - if (!$check_units->{$form->{"selected_unit_$i"}} || - ($check_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne + if (!$all_units->{$form->{"selected_unit_$i"}} || + ($all_units->{$form->{"selected_unit_$i"}}->{"base_unit"} ne $all_units->{$form->{"unit_old_$i"}}->{"base_unit"})) { # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber