From: Joe Hunt Date: Tue, 12 Jul 2011 14:50:51 +0000 (+0200) Subject: 0000710: Shipping tax on all tax groups. And marking with tax type(s) it shall have. X-Git-Tag: v2.4.2~19^2~381 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=7732e889ec468099f6b66173b8dd6363e0a30ed8 0000710: Shipping tax on all tax groups. And marking with tax type(s) it shall have. --- diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index 286f9f37..46f8d500 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -492,7 +492,7 @@ class cart function get_shipping_tax() { - $tax_items = get_shipping_tax_as_array(); + $tax_items = get_shipping_tax_as_array($this->tax_group_id); $tax_rate = 0; if ($tax_items != null) { foreach ($tax_items as $item_tax) { diff --git a/sql/alter2.4.sql b/sql/alter2.4.sql index d84441ac..d9441737 100644 --- a/sql/alter2.4.sql +++ b/sql/alter2.4.sql @@ -27,3 +27,9 @@ UPDATE `0_gl_trans` gl SET `person_id` = IF(br.receivables_account, br.debtor_no, IF(sup.payable_account, sup.supplier_id, NULL)), `person_type_id` = IF(br.receivables_account, 2, IF(sup.payable_account, 3, NULL)); +ALTER TABLE `0_tax_group_items` ADD COLUMN `tax_shipping` tinyint(1) NOT NULL default '0' AFTER `rate`; +UPDATE `0_tax_group_items` tgi + SET tgi.tax_shipping=1 + WHERE tgi.rate=(SELECT 0_tax_types.rate FROM 0_tax_types, 0_tax_groups + WHERE tax_shipping=1 AND tgi.tax_group_id=0_tax_groups.id AND tgi.tax_type_id=0_tax_types.id); +ALTER TABLE `0_tax_groups` DROP COLUMN `tax_shipping`; diff --git a/taxes/db/tax_groups_db.inc b/taxes/db/tax_groups_db.inc index 5c217aa2..05e36f92 100644 --- a/taxes/db/tax_groups_db.inc +++ b/taxes/db/tax_groups_db.inc @@ -9,40 +9,29 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -function clear_shipping_tax_group() { - $sql = "UPDATE ".TB_PREF."tax_groups SET tax_shipping=0 WHERE 1"; - db_query($sql, "could not update tax_shipping fields"); -} - -function add_tax_group($name, $tax_shipping, $taxes, $rates) +function add_tax_group($name, $taxes, $rates, $tax_shippings) { begin_transaction(); - if($tax_shipping) // only one tax group for shipping - clear_shipping_tax_group(); - - $sql = "INSERT INTO ".TB_PREF."tax_groups (name, tax_shipping) VALUES (".db_escape($name).", ".db_escape($tax_shipping).")"; + $sql = "INSERT INTO ".TB_PREF."tax_groups (name) VALUES (".db_escape($name).")"; db_query($sql, "could not add tax group"); $id = db_insert_id(); - add_tax_group_items($id, $taxes, $rates); + add_tax_group_items($id, $taxes, $rates, $tax_shippings); commit_transaction(); } -function update_tax_group($id, $name, $tax_shipping, $taxes, $rates) +function update_tax_group($id, $name, $taxes, $rates, $tax_shippings) { begin_transaction(); - if($tax_shipping) // only one tax group for shipping - clear_shipping_tax_group(); - - $sql = "UPDATE ".TB_PREF."tax_groups SET name=".db_escape($name).",tax_shipping=".db_escape($tax_shipping)." WHERE id=".db_escape($id); + $sql = "UPDATE ".TB_PREF."tax_groups SET name=".db_escape($name)." WHERE id=".db_escape($id); db_query($sql, "could not update tax group"); delete_tax_group_items($id); - add_tax_group_items($id, $taxes, $rates); + add_tax_group_items($id, $taxes, $rates, $tax_shippings); commit_transaction(); } @@ -77,12 +66,12 @@ function delete_tax_group($id) commit_transaction(); } -function add_tax_group_items($id, $items, $rates) +function add_tax_group_items($id, $items, $rates, $tax_shippings) { for ($i=0; $i < count($items); $i++) { - $sql = "INSERT INTO ".TB_PREF."tax_group_items (tax_group_id, tax_type_id, rate) - VALUES (".db_escape($id).", ".db_escape($items[$i]).", " . $rates[$i] .")"; + $sql = "INSERT INTO ".TB_PREF."tax_group_items (tax_group_id, tax_type_id, rate, tax_shipping) + VALUES (".db_escape($id).", ".db_escape($items[$i]).", " . $rates[$i] .", " . $tax_shippings[$i] .")"; db_query($sql, "could not add item tax group item"); } } @@ -125,24 +114,24 @@ function get_tax_group_items_as_array($id) return $ret_tax_array; } -function get_shipping_tax_group_items() +function get_shipping_tax_group_items($tax_group) { $sql = "SELECT ".TB_PREF."tax_group_items.*, ".TB_PREF."tax_types.name AS tax_type_name, ".TB_PREF."tax_types.rate, ".TB_PREF."tax_types.sales_gl_code, ".TB_PREF."tax_types.purchasing_gl_code - FROM " .TB_PREF."tax_group_items, ".TB_PREF."tax_types, ".TB_PREF."tax_groups - WHERE " .TB_PREF."tax_groups.tax_shipping=1 - AND " .TB_PREF."tax_groups.id=tax_group_id + FROM " .TB_PREF."tax_group_items, ".TB_PREF."tax_types + WHERE " .TB_PREF."tax_group_items.tax_shipping=1 + AND tax_group_id=$tax_group AND ".TB_PREF."tax_types.id=tax_type_id"; return db_query($sql, "could not get shipping tax group items"); } -function get_shipping_tax_as_array() +function get_shipping_tax_as_array($tax_group) { $ret_tax_array = array(); - $tax_group_items = get_shipping_tax_group_items(); + $tax_group_items = get_shipping_tax_group_items($tax_group); while ($tax_group_item = db_fetch($tax_group_items)) { diff --git a/taxes/tax_calc.inc b/taxes/tax_calc.inc index 6e721da7..f9906e0f 100644 --- a/taxes/tax_calc.inc +++ b/taxes/tax_calc.inc @@ -179,7 +179,7 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_inc // add the shipping taxes, only if non-zero, and only if tax group taxes shipping if ($shipping_cost != 0) { - $item_taxes = get_shipping_tax_as_array(); + $item_taxes = get_shipping_tax_as_array($tax_group); if ($item_taxes != null) { if ($tax_included == 1) diff --git a/taxes/tax_groups.php b/taxes/tax_groups.php index bf888159..2f300e7e 100644 --- a/taxes/tax_groups.php +++ b/taxes/tax_groups.php @@ -64,6 +64,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') // create an array of the taxes and array of rates $taxes = array(); $rates = array(); + $tax_shippings = array(); for ($i = 0; $i < 5; $i++) { @@ -72,6 +73,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') { $taxes[] = $_POST['tax_type_id' . $i]; $rates[] = get_tax_type_default_rate($_POST['tax_type_id' . $i]); + $tax_shippings[] = check_value('tax_shipping' . $i); //Editable rate has been removed 090920 Joe Hunt //$rates[] = input_num('rate' . $i); } @@ -79,13 +81,12 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') if ($selected_id != -1) { - update_tax_group($selected_id, $_POST['name'], $_POST['tax_shipping'], $taxes, - $rates); + update_tax_group($selected_id, $_POST['name'], $taxes, $rates, $tax_shippings); display_notification(_('Selected tax group has been updated')); } else { - add_tax_group($_POST['name'], $_POST['tax_shipping'], $taxes, $rates); + add_tax_group($_POST['name'], $taxes, $rates, $tax_shippings); display_notification(_('New tax group has been added')); } @@ -143,7 +144,7 @@ $result = get_all_tax_groups(check_value('show_inactive')); start_form(); start_table(TABLESTYLE); -$th = array(_("Description"), _("Shipping Tax"), "", ""); +$th = array(_("Description"), "", ""); inactive_control_column($th); table_header($th); @@ -155,10 +156,6 @@ while ($myrow = db_fetch($result)) alt_table_row_color($k); label_cell($myrow["name"]); - if ($myrow["tax_shipping"]) - label_cell(_("Yes")); - else - label_cell(_("No")); /*for ($i=0; $i< 5; $i++) if ($myrow["type" . $i] != ALL_NUMERIC) @@ -185,7 +182,6 @@ if ($selected_id != -1) $group = get_tax_group($selected_id); $_POST['name'] = $group["name"]; - $_POST['tax_shipping'] = $group["tax_shipping"]; $items = get_tax_group_items($selected_id); @@ -194,6 +190,7 @@ if ($selected_id != -1) { $_POST['tax_type_id' . $i] = $tax_item["tax_type_id"]; $_POST['rate' . $i] = percent_format($tax_item["rate"]); + $_POST['tax_shipping' . $i] = $tax_item["tax_shipping"]; $i ++; } while($i<5) unset($_POST['tax_type_id'.$i++]); @@ -202,7 +199,6 @@ if ($selected_id != -1) hidden('selected_id', $selected_id); } text_row_ex(_("Description:"), 'name', 40); -yesno_list_row(_("Tax applied to Shipping:"), 'tax_shipping', null, "", "", true); end_table(); @@ -211,20 +207,23 @@ display_note(_("Select the taxes that are included in this group."), 1, 1); start_table(TABLESTYLE2); //$th = array(_("Tax"), _("Default Rate (%)"), _("Rate (%)")); //Editable rate has been removed 090920 Joe Hunt -$th = array(_("Tax"), _("Rate (%)")); +$th = array(_("Tax"), _("Rate (%)"), _("Shipping Tax")); table_header($th); for ($i = 0; $i < 5; $i++) { start_row(); if (!isset($_POST['tax_type_id' . $i])) $_POST['tax_type_id' . $i] = 0; + if (!isset($_POST['tax_shipping' . $i])) + $_POST['tax_shipping' . $i] = 0; tax_types_list_cells(null, 'tax_type_id' . $i, $_POST['tax_type_id' . $i], _("None"), true); if ($_POST['tax_type_id' . $i] != 0 && $_POST['tax_type_id' . $i] != ALL_NUMERIC) { $default_rate = get_tax_type_default_rate($_POST['tax_type_id' . $i]); label_cell(percent_format($default_rate), "nowrap align=right"); - + + check_cells(null, 'tax_shipping' . $i); //Editable rate has been removed 090920 Joe Hunt //if (!isset($_POST['rate' . $i]) || $_POST['rate' . $i] == "") // $_POST['rate' . $i] = percent_format($default_rate);