# if this is a tax field
if ($key =~ /IC_tax/) {
- if ($key =~ /$item/) {
+ if ($key =~ /\Q$item\E/) {
$form->{taxaccounts} .= "$ref->{accno} ";
$form->{"IC_tax_$ref->{accno}_description"} =
"$ref->{accno}--$ref->{description}";
$form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
# change/add values for assembly item
- map { $form->{"${_}_$i"} = $newform{$_} }
- qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno);
+ map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id);
$form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
$form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
$i = $form->{rowcount};
$form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
- map { $form->{"${_}_$i"} = $newform{$_} }
- qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice);
+ map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id);
+
$form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
+
if ($form->{exchangerate} != 0) {
$form->{"sellprice_$i"} /= $form->{exchangerate};
}
+
$lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
- map { $form->{"taxaccounts_$i"} .= "$_ " } split / /,
- $newform{taxaccount};
+
+ map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount};
chop $form->{"taxaccounts_$i"};
foreach my $item (qw(description rate taxnumber)) {
my $index = $form->{"taxaccounts_$i"} . "_$item";
}
# credit remaining calculation
- $amount =
- $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
- $form->{"qty_$i"};
- map { $form->{"${_}_base"} += $amount }
- (split / /, $form->{"taxaccounts_$i"});
- map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
- split / /, $form->{"taxaccounts_$i"}
- if !$form->{taxincluded};
+ $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
+
+ map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
+ map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
$form->{creditremaining} -= $amount;
# redo number formatting, because invoice parse them!
- $i = $form->{rowcount};
- map {
- $form->{"${_}_$i"} =
- $form->format_amount(\%myconfig, $form->{"${_}_$i"})
- } qw(weight listprice sellprice rop);
+ map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop);
}
$form->{"id_$i"} = $parts_id;
+
+ # Get the actual price factor (not just the ID) for the marge calculation.
+ $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
+ foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) {
+ next if ($pfac->{id} != $newform{price_factor_id});
+ $form->{"marge_price_factor_$i"} = $pfac->{factor};
+ last;
+ }
+ delete $form->{ALL_PRICE_FACTORS};
+
delete $form->{action};
# restore original callback