my $sortorder = join ', ',
("o.id", $form->sort_columns(transdate, $ordnumber, name));
- $sortorder = $form->{sort} unless $sortorder;
+ $sortorder = $form->{sort} if $form->{sort};
$query .= " AND lower($ordnumber) LIKE '$number'" if $form->{$ordnumber};
$query .= " AND o.transdate >= '$form->{transdatefrom}'"
my $query, @ids;
# translate the ids (given by id_# and trans_id_#) into one array of ids, so we can join them later
- map { push @ids, $form->{"trans_id_$_"} if ($form->{"id_$_"}) } (1 .. $form->{"rowcount"});
+ map { push @ids, $form->{"trans_id_$_"} if ($form->{"id_$_"} and $form->{"trans_id_$_"}) } (1 .. $form->{"rowcount"});
# if called in multi id mode, and still only got one id, switch back to single id
if ($form->{"rowcount"} and $#ids == 0) {
($form->{currency}) = split /:/, $form->{currencies};
+ # set reqdate if this is an invoice->order conversion. If someone knows a better check to ensure
+ # we come from invoices, feel free.
+ $form->{reqdate} = $form->{deliverydate} if ($form->{deliverydate} and $form->{callback} =~ /action=ar_transactions/);
+
if ($form->{id} or @ids) {
# retrieve order for single id
$ref = $sth->fetchrow_hashref(NAME_lc);
map { $form->{$_} = $ref->{$_} } keys %$ref;
- # destroy all entries for multiple ids that yield different information
+ # set all entries for multiple ids blank that yield different information
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- map { undef $form->{$_} if ($ref->{$_} ne $form->{$_}) } keys %$ref;
+ map { $form->{$_} = '' if ($ref->{$_} ne $form->{$_}) } keys %$ref;
}
# if not given, fill transdate with current_date
$dec = length $dec;
my $decimalplaces = ($dec > 2) ? $dec : 2;
- my $discount =
- $form->round_amount(
- $sellprice * $form->parse_amount($myconfig,
- $form->{"discount_$i"}) / 100,
- $decimalplaces);
+ my $i_discount = $form->round_amount($sellprice *
+ $form->parse_amount($myconfig, $form->{"discount_$i"}) / 100, $decimalplaces);
+
+ my $discount = $form->round_amount($form->{"qty_$i"} * $i_discount, $decimalplaces);
# keep a netprice as well, (sellprice - discount)
- $form->{"netprice_$i"} = $sellprice - $discount;
+ #$form->{"netprice_$i"} = $sellprice - $discount;
+ $form->{"netprice_$i"} = $sellprice - $i_discount;
my $linetotal =
$form->round_amount($form->{"qty_$i"} * $form->{"netprice_$i"}, 2);
$linetotal = ($linetotal != 0) ? $linetotal : " ";
push(@{ $form->{discount} }, $discount);
+ push(@{ $form->{p_discount} }, $form->{"discount_$i"});
$form->{ordtotal} += $linetotal;