- $linetotal = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
-
- if ($form->{taxincluded}) {
- $taxamount = $linetotal * ($taxrate / (1 + $taxrate));
- $form->{"sellprice_$i"} = $form->{"sellprice_$i"} * (1 / (1 + $taxrate));
- } else {
- $taxamount = $linetotal * $taxrate;
- }
-
- $netamount += $linetotal;
-
- if ($form->round_amount($taxrate, 7) == 0) {
- if ($form->{taxincluded}) {
- foreach $item (@taxaccounts) {
- $taxamount = $form->round_amount($linetotal * $form->{"${item}_rate"} / (1 + abs($form->{"${item}_rate"})), 2);
- $taxdiff += $taxamount;
- $form->{amount}{$form->{id}}{$item} -= $taxamount;
- }
- $form->{amount}{$form->{id}}{$taxaccounts[0]} += $taxdiff;
- } else {
- map { $form->{amount}{$form->{id}}{$_} -= $linetotal * $form->{"${_}_rate"} } @taxaccounts;
- }
- } else {
- map { $form->{amount}{$form->{id}}{$_} -= $taxamount * $form->{"${_}_rate"} / $taxrate } @taxaccounts;
- }
-
-
- # add purchase to inventory, this one is without the tax!
- $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * $form->{exchangerate};
- $linetotal = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2) * $form->{exchangerate};
- $linetotal = $form->round_amount($linetotal, 2);
+ $linetotal =
+ $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
+
+ if ($form->{taxincluded}) {
+ $taxamount = $linetotal * ($taxrate / (1 + $taxrate));
+ $form->{"sellprice_$i"} =
+ $form->{"sellprice_$i"} * (1 / (1 + $taxrate));
+ } else {
+ $taxamount = $linetotal * $taxrate;
+ }
+
+ $netamount += $linetotal;
+
+ if ($form->round_amount($taxrate, 7) == 0) {
+ if ($form->{taxincluded}) {
+ foreach $item (@taxaccounts) {
+ $taxamount =
+ $form->round_amount($linetotal * $form->{"${item}_rate"} /
+ (1 + abs($form->{"${item}_rate"})),
+ 2);
+ $taxdiff += $taxamount;
+ $form->{amount}{ $form->{id} }{$item} -= $taxamount;
+ }
+ $form->{amount}{ $form->{id} }{ $taxaccounts[0] } += $taxdiff;
+ } else {
+ map {
+ $form->{amount}{ $form->{id} }{$_} -=
+ $linetotal * $form->{"${_}_rate"}
+ } @taxaccounts;
+ }
+ } else {
+ map {
+ $form->{amount}{ $form->{id} }{$_} -=
+ $taxamount * $form->{"${_}_rate"} / $taxrate
+ } @taxaccounts;
+ }
+
+ # add purchase to inventory, this one is without the tax!
+ $amount =
+ $form->{"sellprice_$i"} * $form->{"qty_$i"} * $form->{exchangerate};
+ $linetotal =
+ $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2) *
+ $form->{exchangerate};
+ $linetotal = $form->round_amount($linetotal, 2);