if ($form->{id}) {
- &adj_onhand($dbh, $form, $ml) if $form->{type} =~ /_order$/;
-
$query = qq|DELETE FROM orderitems WHERE trans_id = ?|;
do_query($form, $dbh, $query, $form->{id});
}
$query .= qq|?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
(SELECT factor FROM price_factors WHERE id = ?), ?)|;
- push(@values,
+ push(@values,
conv_i($form->{id}), conv_i($form->{"id_$i"}),
$form->{"description_$i"}, $form->{"longdescription_$i"},
$form->{"qty_$i"}, $baseqty,
$exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, ($form->{vc} eq 'customer') ? 'buy' : 'sell');
}
- $form->{exchangerate} = ($exchangerate) ? $exchangerate : $form->parse_amount($myconfig, $form->{exchangerate});
+ $form->{exchangerate} = $exchangerate || $form->parse_amount($myconfig, $form->{exchangerate});
my $quotation = $form->{type} =~ /_order$/ ? 'f' : 't';
- ($null, $form->{department_id}) = split(/--/, $form->{department});
+ ($null, $form->{department_id}) = split(/--/, $form->{department}) if $form->{department};
# save OE record
$query =
}
}
- if ($form->{type} =~ /_order$/) {
-
- # adjust onhand
- &adj_onhand($dbh, $form, $ml * -1);
- }
-
$form->{saved_xyznumber} = $form->{$form->{type} =~ /_quotation$/ ?
"quonumber" : "ordnumber"};
}
$sth->finish;
- $query = qq|SELECT o.parts_id, o.ship FROM orderitems o | .
- qq|WHERE o.trans_id = ?|;
- @values = (conv_i($form->{id}));
- $sth = $dbh->prepare($query);
- $sth->execute(@values) || $self->dberror($query);
-
- while (my ($id, $ship) = $sth->fetchrow_array) {
- $form->update_balance($dbh, "parts", "onhand", qq|id = $id|, $ship * -1);
- }
- $sth->finish;
-
# delete-values
@values = (conv_i($form->{id}));
- # delete inventory
- $query = qq|DELETE FROM inventory | .
- qq|WHERE oe_id = ?|;
- do_query($form, $dbh, $query, @values);
-
# delete status entries
$query = qq|DELETE FROM status | .
qq|WHERE trans_id = ?|;
my $ref = selectfirst_hashref_query($form, $dbh, $query);
map { $form->{$_} = $ref->{$_} } keys %$ref;
- ($form->{currency}) = split(/:/, $form->{currencies});
+ ($form->{currency}) = split(/:/, $form->{currencies}) unless ($form->{currency});
# set reqdate if this is an invoice->order conversion. If someone knows a better check to ensure
# we come from invoices, feel free.
return $value;
}
-sub adj_onhand {
- $main::lxdebug->enter_sub();
-
- my ($dbh, $form, $ml) = @_;
-
- my $all_units = $form->{all_units};
-
- my $query =
- qq|SELECT oi.parts_id, oi.ship, oi.unit, p.inventory_accno_id, p.assembly | .
- qq| FROM orderitems oi | .
- qq| JOIN parts p ON (p.id = oi.parts_id) | .
- qq| WHERE oi.trans_id = ?|;
- my @values = ($form->{id});
- my $sth = $dbh->prepare($query);
- $sth->execute(@values) || $form->dberror($query);
-
- $query =
- qq|SELECT sum(p.inventory_accno_id) | .
- qq|FROM parts p | .
- qq|JOIN assembly a ON (a.parts_id = p.id) | .
- qq|WHERE a.id = ?|;
- my $ath = $dbh->prepare($query) || $form->dberror($query);
-
- my $ispa;
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- if ($ref->{inventory_accno_id} || $ref->{assembly}) {
-
- # do not update if assembly consists of all services
- if ($ref->{assembly}) {
- $ath->execute($ref->{parts_id}) || $form->dberror($query);
-
- ($ispa) = $sth->fetchrow_array;
- $ath->finish;
-
- next unless $ispa;
-
- }
-
- # get item baseunit
- $query = qq|SELECT unit FROM parts WHERE id = ?|;
- my ($item_unit) = selectrow_query($form, $dbh, $query, $ref->{parts_id});
-
- my $basefactor = 1;
- if (defined($all_units->{$item_unit}->{factor}) && (($all_units->{$item_unit}->{factor} * 1) != 0)) {
- $basefactor = $all_units->{$ref->{unit}}->{factor} / $all_units->{$item_unit}->{factor};
- }
- my $baseqty = $ref->{ship} * $basefactor;
-
- # adjust onhand in parts table
- $form->update_balance($dbh, "parts", "onhand", qq|id = $ref->{parts_id}|, $baseqty * $ml);
- }
- }
-
- $sth->finish;
-
- $main::lxdebug->leave_sub();
-}
-
1;