use List::Util qw(max);
use SL::AM;
+use SL::CVar;
use SL::Common;
use SL::DBUtils;
use SL::MoreCommon;
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();
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} =
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);
}
}
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
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
}
}
+ $ref->{onhand} *= 1;
+
push @{ $form->{item_list} }, $ref;
if ($form->{lizenzen}) {
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} = [];
# 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