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) {
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`;
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
-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();
}
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");
}
}
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))
{
// 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)
// create an array of the taxes and array of rates
$taxes = array();
$rates = array();
+ $tax_shippings = array();
for ($i = 0; $i < 5; $i++)
{
{
$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);
}
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'));
}
start_form();
start_table(TABLESTYLE);
-$th = array(_("Description"), _("Shipping Tax"), "", "");
+$th = array(_("Description"), "", "");
inactive_control_column($th);
table_header($th);
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)
$group = get_tax_group($selected_id);
$_POST['name'] = $group["name"];
- $_POST['tax_shipping'] = $group["tax_shipping"];
$items = get_tax_group_items($selected_id);
{
$_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++]);
hidden('selected_id', $selected_id);
}
text_row_ex(_("Description:"), 'name', 40);
-yesno_list_row(_("Tax applied to Shipping:"), 'tax_shipping', null, "", "", true);
end_table();
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);