From: Janusz Dobrowolski Date: Sat, 19 Mar 2011 09:21:23 +0000 (+0100) Subject: Fixed tax calculation for tax_included sales invoices to avoid rounding differences. X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=7b3357cdf38cbd0f02cc0381ee45c8b3a196f01b;p=textcart.git Fixed tax calculation for tax_included sales invoices to avoid rounding differences. --- diff --git a/gl/includes/db/gl_db_trans.inc b/gl/includes/db/gl_db_trans.inc index 831ff3d..fc581e0 100644 --- a/gl/includes/db/gl_db_trans.inc +++ b/gl/includes/db/gl_db_trans.inc @@ -339,7 +339,7 @@ function get_only_budget_trans_from_to($from_date, $to_date, $account, $dimensio //-------------------------------------------------------------------------------- // Stores journal/bank transaction tax details if applicable // -function add_gl_tax_details($gl_code, $trans_type, $trans_no, $amount, $ex_rate, $date, $memo, $included=0) +function add_gl_tax_details($gl_code, $trans_type, $trans_no, $amount, $ex_rate, $date, $memo, $included=0, $net_amount = null) { $tax_type = is_tax_account($gl_code); if(!$tax_type) return; // $gl_code is not tax account @@ -349,15 +349,16 @@ function add_gl_tax_details($gl_code, $trans_type, $trans_no, $amount, $ex_rate, if ($trans_type == ST_SALESINVOICE || $trans_type == ST_CUSTDELIVERY || $trans_type == ST_CUSTCREDIT) $amount = -$amount; // we have to restore net amount as we cannot know the base amount - if ($tax['rate'] == 0) { -// display_warning(_("You should not post gl transactions -// to tax account with zero tax rate.")); - $net_amount = 0; - } else { - // calculate net amount - $net_amount = $amount/$tax['rate']*100; + if ($net_amount===null) { + if ($tax['rate'] == 0) { +// display_warning(_("You should not post gl transactions +// to tax account with zero tax rate.")); + $net_amount = 0; + } else { + // calculate net amount + $net_amount = $amount/$tax['rate']*100; + } } - add_trans_tax_details($trans_type, $trans_no, $tax['id'], $tax['rate'], $included, $amount, $net_amount, $ex_rate, $date, $memo); diff --git a/purchasing/includes/ui/invoice_ui.inc b/purchasing/includes/ui/invoice_ui.inc index eefe95f..7eff239 100644 --- a/purchasing/includes/ui/invoice_ui.inc +++ b/purchasing/includes/ui/invoice_ui.inc @@ -363,6 +363,7 @@ function display_grn_items_for_selection(&$supp_trans, $k) hidden('order_price'.$n, $myrow['unit_price'], false). hidden('std_cost_unit'.$n, $myrow['std_cost_unit'], false). hidden('po_detail_item'.$n, $myrow['po_detail_item'], false)); + hidden('location'.$n, $myrow["loc_code"], false). label_cell(get_trans_view_str(ST_PURCHORDER, $myrow["purch_order_no"])); label_cell($myrow["item_code"]); label_cell($myrow["description"]); diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index e9bb9fb..558b215 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -77,18 +77,18 @@ function write_sales_invoice(&$invoice) } $total = 0; foreach ($invoice->line_items as $line_no => $invoice_line) { - + $qty = $invoice_line->qty_dispatched; $line_taxfree_price = get_tax_free_price_for_item($invoice_line->stock_id, - $invoice_line->price, 0, $invoice->tax_included, + $invoice_line->price * $qty, 0, $invoice->tax_included, $invoice->tax_group_array); $line_tax = get_full_price_for_item($invoice_line->stock_id, - $invoice_line->price, 0, $invoice->tax_included, + $invoice_line->price * $qty, 0, $invoice->tax_included, $invoice->tax_group_array) - $line_taxfree_price; write_customer_trans_detail_item(ST_SALESINVOICE, $invoice_no, $invoice_line->stock_id, $invoice_line->item_description, $invoice_line->qty_dispatched, - $invoice_line->line_price(), $line_tax, $invoice_line->discount_percent, + $invoice_line->line_price(), $qty ? $line_tax/$qty : 0, $invoice_line->discount_percent, $invoice_line->standard_cost, $invoice_line->src_id, $trans_no ? $invoice_line->id : 0); @@ -112,14 +112,14 @@ function write_sales_invoice(&$invoice) $dim2 = ($invoice->dimension2_id != $customer['dimension2_id'] ? $invoice->dimension2_id : ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"])); $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $sales_account, $dim, $dim2, - (-$line_taxfree_price * $invoice_line->qty_dispatched), + -$line_taxfree_price , $invoice->customer_id, "The sales price GL posting could not be inserted"); if ($invoice_line->discount_percent != 0) { $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $branch_data["sales_discount_account"], $dim, $dim2, - ($line_taxfree_price * $invoice_line->qty_dispatched * $invoice_line->discount_percent), + ($line_taxfree_price * $invoice_line->discount_percent), $invoice->customer_id, "The sales discount GL posting could not be inserted"); } /*end of if discount !=0 */ } diff --git a/taxes/tax_calc.inc b/taxes/tax_calc.inc index 3f54bd2..6f6e9b7 100644 --- a/taxes/tax_calc.inc +++ b/taxes/tax_calc.inc @@ -49,8 +49,7 @@ function get_tax_free_price_for_item($stock_id, $price, $tax_group, $tax_include { $tax_multiplier += $taxitem["rate"]; } - - return round($price / (1 + ($tax_multiplier / 100)), 2*user_price_dec()); + return round($price / (1 + ($tax_multiplier / 100)), user_price_dec()); } // // Full price (incl. VAT) for item $stock_id with line price $price, @@ -86,7 +85,7 @@ function get_full_price_for_item($stock_id, $price, $tax_group, $tax_included, $ $tax_multiplier += $taxitem["rate"]; } - return round($price * (1 + ($tax_multiplier / 100)), 2*user_price_dec()); + return round($price * (1 + ($tax_multiplier / 100)), user_price_dec()); } //--------------------------------------------------------------------------------- @@ -163,7 +162,7 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_inc $index = $item_tax['tax_type_id']; if($tax_included==1) {// 2008-11-26 Joe Hunt Taxes are stored without roundings $nprice = get_tax_free_price_for_item($items[$i], $prices[$i], $tax_group, $tax_included); - $ret_tax_array[$index]['Value'] += ($nprice * $item_tax['rate'] / 100); + $ret_tax_array[$index]['Value'] += $prices[$i]-$nprice; $ret_tax_array[$index]['Net'] += $nprice; } else { $ret_tax_array[$index]['Value'] += ($prices[$i] * $item_tax['rate'] / 100);