- foreach ($item_taxes as $item_tax)
- {
- $index = $item_tax['tax_type_id'];
- if($tax_included==1)
- $ret_tax_array[$index]['Value'] += round($prices[$i] * $item_tax['rate']
- / ($item_tax['rate'] + 100), user_price_dec());
- else
- $ret_tax_array[$index]['Value'] +=
- round($prices[$i] * $item_tax['rate'] / 100, user_price_dec());
- }
+ if ($item_tax['rate'] !== null)
+ {
+
+ // effective vat for some special purchases is lower than nominal
+ $factor = $vat_category == VC_NONDEDUCT ? 0 : ($vat_category==VC_PARTIAL ? $partial_vat_percent/100.0 : 1);
+
+ $net_value = $amount;
+ if ($tax_included == true) {
+ $vat_value = round($amount*$item_tax['rate']/(100+$tax_multiplier), 2);
+
+ if ($taxopt&TAX_CHARGED)
+ $net_value -= $vat_value;
+
+ } else {
+
+ $vat_value = round($amount * $item_tax['rate'] / 100, 2);
+ }
+
+ $ret_array['Net'] = round2($net_value, $dec);
+ $ret_array['Cost'] = $ret_array['Net'];
+
+ $tax = array('Value' => 0, 'Deductible' => 0, 'Adjust' => 0, 'Payable' => 0);
+
+ $tax['purchasing_gl_code'] = $item_tax['purchasing_gl_code'];
+ $tax['sales_gl_code'] = $item_tax['sales_gl_code'];
+ $tax['rate'] = $item_tax['rate'];
+ $tax['tax_type_id'] = $item_tax['tax_type_id'];
+ $tax['tax_type_name'] = $item_tax['tax_type_name'];
+
+ if ($taxopt & TAX_CHARGED) // tax is charged on document
+ $tax['Value'] = round2($vat_value, $dec);
+
+ if ($taxopt & TAX_PAYABLE) // transaction is taxable
+ $tax['Payable'] = round2($vat_value, $dec);
+
+ if ($taxopt & TAX_DEDUCTIBLE) // tax is deductible
+ {
+ $tax['Deductible'] = round2($vat_value*$factor, 2); // avoid rounding issues if $dec > 2 decimal places
+ $tax['Adjust'] = round2(-(1-$vat_factor)*$factor*$vat_value, $dec); // adjustment due to mixed taxed/exmpt sales activity
+ } else {
+ $tax['Deductible'] = 0;
+ $tax['Adjust'] = 0;
+ }
+
+ if ($tax['Payable'])
+ $ret_array['Cost'] += ($tax['Payable'] - $tax['Deductible']);
+ elseif ($tax['Deductible'])
+ $ret_array['Cost'] += $tax['Adjust'];
+
+ $ret_array[] = $tax;
+ $ret_array['Tax'] += $tax['Value'];
+ }