X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/6216f7b53a81a73641a2d98ea43f363b6a615b07..d7420ba874019aa197b978a738f89a15bfec08a7:/SL/IS.pm diff --git a/SL/IS.pm b/SL/IS.pm index 55203db2a..0f36f2363 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(); @@ -638,32 +645,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); } } @@ -1229,18 +1215,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 @@ -1513,6 +1488,12 @@ 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 = @@ -1525,7 +1506,7 @@ sub get_customer { 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); @@ -1812,6 +1793,8 @@ sub retrieve_item { } } + $ref->{onhand} *= 1; + push @{ $form->{item_list} }, $ref; if ($form->{lizenzen}) {