From 8eb8e44cb90ab144f0849d1ecd2153175b619786 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 23 Jul 2019 09:54:27 +0200 Subject: [PATCH] Rewritten sales shipping cost taxation, improved shipping cost handling in sales module. --- admin/gl_setup.php | 2 +- applications/fixed_assets.php | 2 +- applications/setup.php | 2 + includes/sysnames.inc | 3 +- includes/ui/ui_lists.inc | 102 +++++++++++----- inventory/includes/db/items_db.inc | 17 +-- inventory/manage/items.php | 149 +++++++++++++---------- purchasing/includes/po_class.inc | 6 +- purchasing/includes/supp_trans_class.inc | 2 +- purchasing/includes/ui/po_ui.inc | 2 +- reporting/includes/reports_classes.inc | 2 +- reporting/rep109.php | 9 +- reporting/rep111.php | 7 +- reporting/rep209.php | 3 +- sales/customer_delivery.php | 4 +- sales/customer_invoice.php | 8 +- sales/includes/cart_class.inc | 15 ++- sales/includes/db/cust_trans_db.inc | 7 +- sales/includes/db/sales_credit_db.inc | 4 +- sales/includes/db/sales_invoice_db.inc | 4 +- sales/includes/db/sales_order_db.inc | 4 +- sales/includes/ui/sales_credit_ui.inc | 2 +- sales/includes/ui/sales_order_ui.inc | 24 +++- sales/manage/customer_branches.php | 2 +- sales/manage/customers.php | 2 +- sales/sales_order_entry.php | 15 ++- sales/view/view_credit.php | 2 +- sales/view/view_dispatch.php | 2 +- sales/view/view_invoice.php | 2 +- sales/view/view_sales_order.php | 3 +- sql/alter2.5.php | 47 +++++-- sql/alter2.5.sql | 35 ++++++ sql/en_US-demo.sql | 74 +++++------ sql/en_US-new.sql | 16 +-- taxes/db/tax_groups_db.inc | 47 +++---- taxes/tax_calc.inc | 19 +-- taxes/tax_groups.php | 13 +- 37 files changed, 393 insertions(+), 266 deletions(-) diff --git a/admin/gl_setup.php b/admin/gl_setup.php index 3b086816..2b6de217 100644 --- a/admin/gl_setup.php +++ b/admin/gl_setup.php @@ -222,7 +222,7 @@ check_row(_("Print Item Image on Quote:"), 'print_item_images_on_quote', null); textarea_row(_("Legal Text on Invoice:"), 'legal_text', $_POST['legal_text'], 32, 4); -gl_all_accounts_list_row(_("Shipping Charged Account:"), 'freight_act', $_POST['freight_act']); +gl_all_accounts_list_row(_("Shipping Charged Account (default):"), 'freight_act', $_POST['freight_act']); gl_all_accounts_list_row(_("Deferred Income Account:"), 'deferred_income_act', $_POST['deferred_income_act'], true, false, _("Not used"), false, false, false); diff --git a/applications/fixed_assets.php b/applications/fixed_assets.php index 8a3bb86d..8c6485d5 100644 --- a/applications/fixed_assets.php +++ b/applications/fixed_assets.php @@ -43,7 +43,7 @@ class assets_app extends application $this->add_module(_("Maintenance")); $this->add_lapp_function(2, _("Fixed &Assets"), - "inventory/manage/items.php?FixedAsset=1", 'SA_ASSET', MENU_ENTRY); + "inventory/manage/items.php?type=F", 'SA_ASSET', MENU_ENTRY); $this->add_rapp_function(2, _("Fixed Assets &Locations"), "inventory/manage/locations.php?FixedAsset=1", 'SA_INVENTORYLOCATION', MENU_MAINTENANCE); $this->add_rapp_function(2, _("Fixed Assets &Categories"), diff --git a/applications/setup.php b/applications/setup.php index 5f29aff1..9b2e1118 100644 --- a/applications/setup.php +++ b/applications/setup.php @@ -44,6 +44,8 @@ class setup_app extends application "admin/payment_terms.php?", 'SA_PAYTERMS', MENU_MAINTENANCE); $this->add_lapp_function(1, _("Shi&pping Company"), "admin/shipping_companies.php?", 'SA_SHIPPING', MENU_MAINTENANCE); + $this->add_lapp_function(1, _("Shipping &Options"), + "inventory/manage/items.php?type=T", 'SA_SHIPPING', MENU_ENTRY); $this->add_rapp_function(1, _("&Points of Sale"), "sales/manage/sales_points.php?", 'SA_POSSETUP', MENU_MAINTENANCE); $this->add_rapp_function(1, _("&Printers"), diff --git a/includes/sysnames.inc b/includes/sysnames.inc index 507bd698..1d7df6f0 100644 --- a/includes/sysnames.inc +++ b/includes/sysnames.inc @@ -170,7 +170,8 @@ $depreciation_methods = array( $stock_types = array( 'M' => _("Manufactured"), 'B' => _("Purchased"), - 'D' => _("Service") + 'D' => _("Service"), + 'T' => _("Shipping") ); //---------------------------------------------------------------------------------- diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 07202791..58a2bae2 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -823,13 +823,17 @@ function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, function stock_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $opts=array(), $editkey = false, $type = "stock") { - $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable - FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id"; - - if (isset($opts['fixed_asset']) && $opts['fixed_asset']) - $sql .= " AND mb_flag='F'"; + $sql = "SELECT stock_id, s.description, c.description, shipper.shipper_name, s.inactive, s.editable + FROM ".TB_PREF."stock_master s + LEFT JOIN ".TB_PREF."shippers shipper ON shipper.shipper_id=s.shipper_id + LEFT JOIN ".TB_PREF."stock_category c ON s.category_id=c.category_id"; + + if (isset($opts['shipping']) && $opts['shipping']) + $where[] = "mb_flag='T'"; + elseif (isset($opts['fixed_asset']) && $opts['fixed_asset']) + $where[] = "mb_flag='F'"; else - $sql .= " AND mb_flag!='F'"; + $where[] = "NOT mb_flag IN('F','T')"; if ($editkey) set_editor('item', $name, $editkey); @@ -842,14 +846,15 @@ function stock_items_list($name, $selected_id=null, $all_option=false, 'spec_id' => ALL_TEXT, 'search_box' => true, 'search' => array("stock_id", "c.description","s.description"), - 'search_submit' => get_company_pref('no_item_list')!=0 && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']), + 'search_submit' => get_company_pref('no_item_list') != 0 && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']), 'size'=>10, 'select_submit'=> $submit_on_change, 'category' => 2, - 'order' => array('c.description','stock_id'), + 'order' => (isset($opts['shipping']) && $opts['shipping']) ? array('shipper.shipper_name','stock_id'): array('c.description','stock_id'), 'editlink' => $editkey ? add_edit_combo('item') : false, 'editable' => false, - 'max' => 255 + 'max' => 255, + 'where' => $where ), $opts), $type ); return $ret; } @@ -907,7 +912,7 @@ function sales_items_list($name, $selected_id=null, $all_option=false, ".TB_PREF."stock_category c ON i.category_id=c.category_id WHERE i.stock_id=s.stock_id - AND mb_flag != 'F'"; + AND NOT mb_flag IN('F','T')"; if ($type == 'local') { // exclude foreign codes @@ -1032,7 +1037,7 @@ function stock_purchasable_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $all=false, $editkey=false) { return stock_items_list($name, $selected_id, $all_option, $submit_on_change, - array('where'=>array("NOT no_purchase"), + array('where'=>array("NOT no_purchase", "mb_flag!='F'"), 'show_inactive'=>$all), $editkey, "stock_purchased"); } // @@ -1051,19 +1056,53 @@ function stock_purchasable_items_list_cells($label, $name, $selected_id=null, //------------------------------------------------------------------------------------ -function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true) +function shipping_methods_list($name, $selected_id=null, $all_option=false, $submit_on_change=false) +{ + return stock_items_list($name, $selected_id, $all_option, $submit_on_change, + array('type'=>1, 'shipping'=>true, 'category' => false, 'search_box'=>false, 'search_sumbit' => false), + false, false);//, "shipping_methods"); +} + +function shipping_methods_list_cells($label, $name, $selected_id=null, + $all_option=false, $submit_on_change=false) +{ + if ($label != null) + echo "$label\n"; + echo ""; + echo shipping_methods_list($name, $selected_id, $all_option, $submit_on_change); + echo "\n"; +} + +function shipping_methods_list_row($label, $name, $selected_id=null, + $all_option=false, $submit_on_change=false) +{ + echo "$label"; + shipping_methods_list_cells(null, $name, $selected_id, $all_option, $submit_on_change); + echo "\n"; +} + +//------------------------------------------------------------------------------------ + +function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true, $all=true) { global $stock_types; + $options = $stock_types; + if (!$all) + { + unset($options['T']); + unset($options['F']); + } echo ""; if ($label != null) echo "$label\n"; echo ""; - - echo array_selector($name, $selected_id, $stock_types, + + echo array_selector($name, $selected_id, $options, array( 'select_submit'=> true, - 'disabled' => !$enabled) ); + 'disabled' => !$enabled) + ); echo "\n"; } @@ -1263,26 +1302,31 @@ function item_tax_types_list_row($label, $name, $selected_id=null, $show_inactiv //------------------------------------------------------------------------------------ -function shippers_list($name, $selected_id=null) +function shippers_list($name, $selected_id=null, $none_option=false, $submit_on_change=false) { $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers"; return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', - array('order'=>array('shipper_name'))); + array('order'=>array('shipper_name'), + 'spec_option' => $none_option, + 'spec_id' => ALL_NUMERIC, + 'select_submit'=> $submit_on_change, + 'async' => false, +)); } -function shippers_list_cells($label, $name, $selected_id=null) +function shippers_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false) { if ($label != null) echo "$label\n"; echo ""; - echo shippers_list($name, $selected_id); + echo shippers_list($name, $selected_id, $none_option, $submit_on_change); echo "\n"; } -function shippers_list_row($label, $name, $selected_id=null) +function shippers_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false) { echo "$label"; - shippers_list_cells(null, $name, $selected_id); + shippers_list_cells(null, $name, $selected_id, $none_option, $submit_on_change); echo "\n"; } @@ -1711,13 +1755,13 @@ function class_list_row($label, $name, $selected_id=null, $submit_on_change=fals } //----------------------------------------------------------------------------------------------- -function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false) +function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $type=false) { $where_opts = array(); - if ($fixed_asset) - $where_opts[0] = "dflt_mb_flag='F'"; + if (in_array($type, array('F', 'T'))) + $where_opts[] = "dflt_mb_flag=".db_escape($type); else - $where_opts[0] = "dflt_mb_flag!='F'"; + $where_opts[] = "NOT dflt_mb_flag IN('F','T')"; $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category"; return combo_input($name, $selected_id, $sql, 'category_id', 'description', @@ -1730,19 +1774,19 @@ function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submi )); } -function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false) +function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $type=false) { if ($label != null) echo "$label\n"; echo ""; - echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset); + echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $type); echo "\n"; } -function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false) +function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $type=false) { echo "$label"; - stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset); + stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $type); echo "\n"; } diff --git a/inventory/includes/db/items_db.inc b/inventory/includes/db/items_db.inc index cfbbbdbe..57ddf316 100644 --- a/inventory/includes/db/items_db.inc +++ b/inventory/includes/db/items_db.inc @@ -14,7 +14,7 @@ function update_item($stock_id, $description, $long_description, $category_id, $cogs_account, $adjustment_account, $wip_account, $dimension_id, $dimension2_id, $no_sale, $editable, $no_purchase, $depreciation_method = 'D', $depreciation_rate=100, $depreciation_factor=1, - $depreciation_start=null, $fa_class_id=null, $vat_category='') + $depreciation_start=null, $fa_class_id=null, $vat_category='', $shipper_id=0) { $sql = "UPDATE ".TB_PREF."stock_master SET long_description=".db_escape($long_description).", description=".db_escape($description).", @@ -33,7 +33,8 @@ function update_item($stock_id, $description, $long_description, $category_id, depreciation_method=".db_escape($depreciation_method).", depreciation_rate=".db_escape($depreciation_rate).", depreciation_factor=".db_escape($depreciation_factor).", - fa_class_id=".db_escape($fa_class_id); + fa_class_id=".db_escape($fa_class_id).", + shipper_id=".db_escape($shipper_id); if ($units != '') $sql .= ", units=".db_escape($units); @@ -61,14 +62,14 @@ function add_item($stock_id, $description, $long_description, $category_id, $cogs_account, $adjustment_account, $wip_account, $dimension_id, $dimension2_id, $no_sale, $editable, $no_purchase, $depreciation_method='D', $depreciation_rate=100, $depreciation_factor=1, $depreciation_start=null, - $fa_class_id=null, $vat_category=0) + $fa_class_id=null, $vat_category=0, $shipper_id=0) { $sql = "INSERT INTO ".TB_PREF."stock_master (stock_id, description, long_description, category_id, tax_type_id, units, mb_flag, sales_account, inventory_account, cogs_account, adjustment_account, wip_account, dimension_id, dimension2_id, no_sale, no_purchase, editable, vat_category, depreciation_method, depreciation_rate, depreciation_factor" .(isset($depreciation_start) ? ", depreciation_start, depreciation_date, fa_class_id" : "") - .") VALUES (".db_escape($stock_id).", ".db_escape($description).", ".db_escape($long_description).", + .",shipper_id) VALUES (".db_escape($stock_id).", ".db_escape($description).", ".db_escape($long_description).", ".db_escape($category_id).", ".db_escape($tax_type_id).", " .db_escape($units).", ".db_escape($mb_flag).", ".db_escape($sales_account).", ".db_escape($inventory_account) @@ -80,7 +81,7 @@ function add_item($stock_id, $description, $long_description, $category_id, .db_escape($editable).",".db_escape($vat_category)."," .db_escape($depreciation_method).",".db_escape($depreciation_rate).",".db_escape($depreciation_factor) .(isset($depreciation_start) ? ",'".date2sql($depreciation_start)."','".date2sql($depreciation_start)."',".db_escape($fa_class_id) : "") - .")"; + .",".db_escape($shipper_id).")"; db_query($sql, "The item could not be added"); @@ -149,7 +150,10 @@ function item_in_foreign_codes($stock_id) _('Cannot delete this item because there are existing sales order items for it.'), "SELECT COUNT(*) FROM " .TB_PREF."purch_order_details WHERE item_code=".db_escape($stock_id)=> - _('Cannot delete this item because there are existing purchase order items for it.') + _('Cannot delete this item because there are existing purchase order items for it.'), + "SELECT COUNT(*) FROM " + .TB_PREF."sales_orders WHERE ship_via=".db_escape($stock_id)=> + _('Cannot delete this item because there are existing sales transactions for it.'), ); $msg = ''; @@ -230,4 +234,3 @@ function get_items_search($description, $type) return db_query($sql, "Failed in retreiving item list."); } - diff --git a/inventory/manage/items.php b/inventory/manage/items.php index 352a2fbf..fb3905a5 100644 --- a/inventory/manage/items.php +++ b/inventory/manage/items.php @@ -19,16 +19,21 @@ if ($SysPrefs->use_popup_windows) if (user_use_date_picker()) $js .= get_js_date_picker(); -if (isset($_GET['FixedAsset'])) { - $page_security = 'SA_ASSET'; - $_SESSION['page_title'] = _($help_context = "Fixed Assets"); - $_POST['mb_flag'] = 'F'; - $_POST['fixed_asset'] = 1; +if (isset($_GET['type'])) { + if ($_GET['type'] == 'F') { + + $page_security = 'SA_ASSET'; + $_SESSION['page_title'] = _($help_context = "Fixed Assets"); + $_POST['mb_flag'] = 'F'; + } elseif ($_GET['type'] == 'T') { + + $page_security = 'SA_SHIPPING'; + $_SESSION['page_title'] = _($help_context = "Shipping Options"); + $_POST['mb_flag'] = 'T'; + } } else { $_SESSION['page_title'] = _($help_context = "Items"); - if (!get_post('fixed_asset')) - $_POST['fixed_asset'] = 0; } @@ -142,7 +147,7 @@ if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '') /* EOF Add Image upload for New Item - by Ori */ } -if (get_post('fixed_asset')) { +if (get_post('mb_flag') == 'F') { check_db_has_fixed_asset_categories(_("There are no fixed asset categories defined in the system. At least one fixed asset category is required to add a fixed asset.")); check_db_has_fixed_asset_classes(_("There are no fixed asset classes defined in the system. At least one fixed asset class is required to add a fixed asset.")); } else @@ -157,7 +162,8 @@ function clear_data() unset($_POST['category_id']); unset($_POST['tax_type_id']); unset($_POST['units']); - unset($_POST['mb_flag']); + if (!in_array(@$_POST['mb_flag'], array('T', 'F'))) + unset($_POST['mb_flag']); unset($_POST['NewStockID']); unset($_POST['dimension_id']); unset($_POST['dimension2_id']); @@ -205,7 +211,7 @@ if (isset($_POST['addupdate'])) set_focus('NewStockID'); } - if (get_post('fixed_asset')) { + if (get_post('mb_flag') == 'F') { if ($_POST['depreciation_rate'] > 100) { $_POST['depreciation_rate'] = 100; } @@ -231,14 +237,14 @@ if (isset($_POST['addupdate'])) { /*so its an existing one */ update_item($_POST['NewStockID'], $_POST['description'], $_POST['long_description'], $_POST['category_id'], - $_POST['tax_type_id'], get_post('units'), - get_post('fixed_asset') ? 'F' : get_post('mb_flag'), $_POST['sales_account'], + $_POST['tax_type_id'], get_post('units'), + get_post('mb_flag'), $_POST['sales_account'], $_POST['inventory_account'], $_POST['cogs_account'], $_POST['adjustment_account'], $_POST['wip_account'], $_POST['dimension_id'], $_POST['dimension2_id'], check_value('no_sale'), check_value('editable'), check_value('no_purchase'), get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start', null), - get_post('fa_class_id'), get_post('vat_category')); + get_post('fa_class_id'), get_post('vat_category'), get_post('shipper')); update_record_status($_POST['NewStockID'], $_POST['inactive'], 'stock_master', 'stock_id'); @@ -253,13 +259,13 @@ if (isset($_POST['addupdate'])) add_item($_POST['NewStockID'], $_POST['description'], $_POST['long_description'], $_POST['category_id'], $_POST['tax_type_id'], - $_POST['units'], get_post('fixed_asset') ? 'F' : get_post('mb_flag'), $_POST['sales_account'], + $_POST['units'], get_post('mb_flag'), $_POST['sales_account'], $_POST['inventory_account'], $_POST['cogs_account'], $_POST['adjustment_account'], $_POST['wip_account'], $_POST['dimension_id'], $_POST['dimension2_id'], check_value('no_sale'), check_value('editable'), check_value('no_purchase'), get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start', null), - get_post('fa_class_id'), get_post('vat_category')); + get_post('fa_class_id'), get_post('vat_category'), get_post('shipper')); display_notification(_("A new item has been added.")); $_POST['stock_id'] = $_POST['NewStockID'] = @@ -390,13 +396,12 @@ function item_settings(&$stock_id, $new_item) hidden('NewStockID', $_POST['NewStockID']); set_focus('description'); } - $fixed_asset = get_post('fixed_asset'); text_row(_("Name:"), 'description', null, 52, 200); textarea_row(_('Description:'), 'long_description', null, 42, 3); - stock_categories_list_row(_("Category:"), 'category_id', null, false, $new_item, $fixed_asset); + stock_categories_list_row(_("Category:"), 'category_id', null, false, $new_item, get_post('mb_flag')); if ($new_item && (list_updated('category_id') || !isset($_POST['sales_account']))) { // changed category for new item or first page view @@ -404,10 +409,14 @@ function item_settings(&$stock_id, $new_item) $_POST['tax_type_id'] = $category_record["dflt_tax_type"]; $_POST['units'] = $category_record["dflt_units"]; - $_POST['mb_flag'] = $category_record["dflt_mb_flag"]; + if (!in_array(get_post('mb_flag'), array('T', 'F'))) + $_POST['mb_flag'] = $category_record["dflt_mb_flag"]; $_POST['inventory_account'] = $category_record["dflt_inventory_act"]; $_POST['cogs_account'] = $category_record["dflt_cogs_act"]; - $_POST['sales_account'] = $category_record["dflt_sales_act"]; + if (get_post('mb_flag') == 'T' && !isset($_POST['sales_account'])) + $_POST['sales_account'] = get_company_pref('freight_act'); + else + $_POST['sales_account'] = $category_record["dflt_sales_act"]; $_POST['adjustment_account'] = $category_record["dflt_adjustment_act"]; $_POST['wip_account'] = $category_record["dflt_wip_act"]; $_POST['dimension_id'] = $category_record["dflt_dim1"]; @@ -423,23 +432,24 @@ function item_settings(&$stock_id, $new_item) // show inactive item tax type in selector only if already set. item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null, !$new_item && item_type_inactive(get_post('tax_type_id'))); - if (!get_post('fixed_asset')) - stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, $fresh_item); + if (!in_array(get_post('mb_flag'), array('T', 'F'))) + stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, $fresh_item, false); stock_units_list_row(_('Units of Measure:'), 'units', null, $fresh_item); vat_category_list_row(_("VAT category:"), 'vat_category', null, $fresh_item, false, !$new_item); + if (get_post('mb_flag') != 'T') check_row(_("Editable description:"), 'editable'); - if (get_post('fixed_asset')) + if (get_post('mb_flag') == 'F') hidden('no_sale', 0); else check_row(_("Exclude from sales:"), 'no_sale'); check_row(_("Exclude from purchases:"), 'no_purchase'); - if (get_post('fixed_asset')) { + if (get_post('mb_flag') == 'F') { table_section_title(_("Depreciation")); fixed_asset_classes_list_row(_("Fixed Asset Class").':', 'fa_class_id', null, false, true); @@ -478,6 +488,8 @@ function item_settings(&$stock_id, $new_item) label_row(_("Last Depreciation").':', $_POST['depreciation_date']==$_POST['depreciation_start'] ? _("None") : $_POST['depreciation_date']); } hidden('depreciation_date'); + } else if (get_post('mb_flag') == 'T') { + shippers_list_row(_("Shipping company:"), 'shipper'); } table_section(2); @@ -499,25 +511,24 @@ function item_settings(&$stock_id, $new_item) gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']); - if (get_post('fixed_asset')) { - gl_all_accounts_list_row(_("Asset account:"), 'inventory_account', $_POST['inventory_account']); - gl_all_accounts_list_row(_("Depreciation cost account:"), 'cogs_account', $_POST['cogs_account']); - gl_all_accounts_list_row(_("Depreciation/Disposal account:"), 'adjustment_account', $_POST['adjustment_account']); - } - elseif (!is_service(get_post('mb_flag'))) - { - gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']); - gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']); - gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']); - } - else - { - gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']); - hidden('inventory_account', $_POST['inventory_account']); - hidden('adjustment_account', $_POST['adjustment_account']); + switch(get_post('mb_flag')) { + case 'F': + gl_all_accounts_list_row(_("Asset account:"), 'inventory_account', $_POST['inventory_account']); + gl_all_accounts_list_row(_("Depreciation cost account:"), 'cogs_account', $_POST['cogs_account']); + gl_all_accounts_list_row(_("Depreciation/Disposal account:"), 'adjustment_account', $_POST['adjustment_account']); + break; + case 'T': + case 'D': + gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']); + hidden('inventory_account', $_POST['inventory_account']); + hidden('adjustment_account', $_POST['adjustment_account']); + break; + default: + gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']); + gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']); + gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']); } - if (is_manufactured(get_post('mb_flag'))) gl_all_accounts_list_row(_("WIP Account:"), 'wip_account', $_POST['wip_account']); else @@ -549,7 +560,7 @@ function item_settings(&$stock_id, $new_item) check_row(_("Delete Image:"), 'del_image'); record_status_list_row(_("Item status:"), 'inactive'); - if (get_post('fixed_asset')) { + if (get_post('mb_flag') == 'F') { table_section_title(_("Values")); if (!$new_item) { hidden('material_cost'); @@ -589,8 +600,12 @@ if (db_has_stock_items()) { start_table(TABLESTYLE_NOBORDER); start_row(); - stock_items_list_cells(_("Select an item:"), 'stock_id', null, - _('New item'), true, check_value('show_inactive'), false, array('fixed_asset' => get_post('fixed_asset'))); + if (get_post('mb_flag') == 'T') + shipping_methods_list_cells(_("Select method:"), 'stock_id', null, _("New method"), true); + else + stock_items_list_cells(_("Select an item:"), 'stock_id', null, + _('New item'), true, check_value('show_inactive'), false, + array('fixed_asset' => get_post('mb_flag') == 'F')); $new_item = get_post('stock_id')==''; check_cells(_("Show inactive:"), 'show_inactive', null, true); end_row(); @@ -612,22 +627,33 @@ $stock_id = get_post('stock_id'); if (!$stock_id) unset($_POST['_tabs_sel']); // force settings tab for new customer -$tabs = (get_post('fixed_asset')) - ? array( - 'settings' => array(_('&General settings'), $stock_id), - 'movement' => array(_('&Transactions'), $stock_id) ) - : array( - 'settings' => array(_('&General settings'), $stock_id), - 'sales_pricing' => array(_('S&ales Pricing'), (user_check_access('SA_SALESPRICE') ? $stock_id : null)), - 'purchase_pricing' => array(_('&Purchasing Pricing'), (user_check_access('SA_PURCHASEPRICING') ? $stock_id : null)), - 'unit_cost' => array(_('Unit &Cost'), (user_check_access('SA_STANDARDCOST') ? $stock_id : null)), - 'reorder_level' => array(_('&Reorder Levels'), (is_inventory_item($stock_id) && - user_check_access('SA_REORDER') ? $stock_id : null)), - 'movement' => array(_('&Transactions'), (user_check_access('SA_ITEMSTRANSVIEW') && is_inventory_item($stock_id) ? - $stock_id : null)), - 'status' => array(_('&Status'), (user_check_access('SA_ITEMSSTATVIEW') ? $stock_id : null)), - ); - +switch(get_post('mb_flag')) { + case 'F': + $tabs = array( + 'settings' => array(_('&General settings'), $stock_id), + 'movement' => array(_('&Transactions'), $stock_id) ); + break; + case 'T': + $tabs = array( + 'settings' => array(_('&General settings'), $stock_id), + 'sales_pricing' => array(_('S&ales Pricing'), (user_check_access('SA_SALESPRICE') ? $stock_id : null)), + 'purchase_pricing' => array(_('&Purchasing Pricing'), (user_check_access('SA_PURCHASEPRICING') ? $stock_id : null)), + 'unit_cost' => array(_('Unit &Cost'), (user_check_access('SA_STANDARDCOST') ? $stock_id : null)), + ); + break; + + default: + $tabs = array( + 'settings' => array(_('&General settings'), $stock_id), + 'sales_pricing' => array(_('S&ales Pricing'), (user_check_access('SA_SALESPRICE') ? $stock_id : null)), + 'purchase_pricing' => array(_('&Purchasing Pricing'), (user_check_access('SA_PURCHASEPRICING') ? $stock_id : null)), + 'unit_cost' => array(_('Unit &Cost'), (user_check_access('SA_STANDARDCOST') ? $stock_id : null)), + 'reorder_level' => array(_('&Reorder Levels'), (is_inventory_item($stock_id) && + user_check_access('SA_REORDER') ? $stock_id : null)), + 'movement' => array(_('&Transactions'), (user_check_access('SA_ITEMSTRANSVIEW') && is_inventory_item($stock_id) ? + $stock_id : null)), + 'status' => array(_('&Status'), (user_check_access('SA_ITEMSSTATVIEW') ? $stock_id : null)), ); +} tabbed_content_start('tabs', $tabs); switch (get_post('_tabs_sel')) { @@ -675,9 +701,8 @@ tabbed_content_end(); div_end(); hidden('fixed_asset', get_post('fixed_asset')); - -if (get_post('fixed_asset')) - hidden('mb_flag', 'F'); +if (in_array(get_post('mb_flag'), array('F', 'T'))) + hidden('mb_flag', get_post('mb_flag')); end_form(); diff --git a/purchasing/includes/po_class.inc b/purchasing/includes/po_class.inc index 7db50351..b5dcdc0b 100644 --- a/purchasing/includes/po_class.inc +++ b/purchasing/includes/po_class.inc @@ -148,8 +148,7 @@ class purch_order $items[] = $ln_itm->stock_id; $prices[] = round($ln_itm->price * $ln_itm->quantity, user_price_dec()); } - $taxes = get_tax_for_items($this->trans_type, $items, $prices, 0, - $this->tax_group_id, $this->tax_included); + $taxes = get_tax_for_items($this->trans_type, $items, $prices, $this->tax_group_id, $this->tax_included); // Adjustment for swiss franken, we always have 5 rappen = 1/20 franken if ($this->curr_code == 'CHF') { @@ -180,8 +179,7 @@ class purch_order } if (!$this->tax_included ) { - $taxes = get_tax_for_items($this->trans_type, $items, $prices, 0, $this->tax_group_id, - $this->tax_included); + $taxes = get_tax_for_items($this->trans_type, $items, $prices, $this->tax_group_id, $this->tax_included); foreach($taxes as $tax) $total += round($tax['Value'], $dec); diff --git a/purchasing/includes/supp_trans_class.inc b/purchasing/includes/supp_trans_class.inc index ddb55681..80adbc18 100644 --- a/purchasing/includes/supp_trans_class.inc +++ b/purchasing/includes/supp_trans_class.inc @@ -135,7 +135,7 @@ class supp_trans $prices[] = round( $ln_itm->this_quantity_inv * $ln_itm->chg_price, user_price_dec()); } - $taxes = get_tax_for_items($this->trans_type, $items, $prices, 0, $this->tax_group_id, + $taxes = get_tax_for_items($this->trans_type, $items, $prices, $this->tax_group_id, $this->tax_included); if (isset($this->tax_overrides)) diff --git a/purchasing/includes/ui/po_ui.inc b/purchasing/includes/ui/po_ui.inc index 3dd64c62..092e801c 100644 --- a/purchasing/includes/ui/po_ui.inc +++ b/purchasing/includes/ui/po_ui.inc @@ -402,7 +402,7 @@ function po_item_controls(&$order, &$rowcounter, $line_no=-1) if ($order->fixed_asset) stock_purchasable_fa_list_cells(null, 'stock_id', null, false, true, false, true, $order->line_items); else - stock_items_list_cells(null, 'stock_id', null, false, true, false, true, array('editable' => 30, 'where'=>array("NOT no_purchase"))); + stock_purchasable_items_list_cells(null, 'stock_id', null, false, true, false, true, array('editable' => 30, 'where'=>array("NOT no_purchase"))); if (list_updated('stock_id')) { $Ajax->activate('price'); diff --git a/reporting/includes/reports_classes.inc b/reporting/includes/reports_classes.inc index 0d150930..bc5a68ef 100644 --- a/reporting/includes/reports_classes.inc +++ b/reporting/includes/reports_classes.inc @@ -423,7 +423,7 @@ class BoxReports case 'CATEGORIES': return stock_categories_list($name, null, _("No Category Filter")); case 'FCATEGORIES': - return stock_categories_list($name, null, _("No Category Filter"), false, true); + return stock_categories_list($name, null, _("No Category Filter"), false, 'F'); case 'FCLASS': return fixed_asset_classes_list($name, null, _("No Class Filter"), false); case 'SALESTYPES': diff --git a/reporting/rep109.php b/reporting/rep109.php index 06aecf08..e53d52a3 100644 --- a/reporting/rep109.php +++ b/reporting/rep109.php @@ -110,6 +110,10 @@ function print_sales_orders() $result = get_sales_order_details($i, ST_SALESORDER); $SubTotal = 0; $items = $prices = array(); + if ($myrow["ship_via"]) { + $items[] = $myrow["ship_via"]; + $prices[] = $myrow["freight_cost"]; + } while ($myrow2=db_fetch($result)) { $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]), @@ -141,6 +145,7 @@ function print_sales_orders() if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight)) $rep->NewPage(); } + if ($myrow['comments'] != "") { $rep->NewLine(); @@ -167,9 +172,7 @@ function print_sales_orders() $rep->TextCol(6, 7, $DisplayTotal, -2); $rep->NewLine(); } - - $tax_items = get_tax_for_items(ST_SALESINVOICE, $items, $prices, $myrow["freight_cost"], - $myrow['tax_group_id'], $myrow['tax_included']); + $tax_items = get_tax_for_items(ST_SALESINVOICE, $items, $prices, $myrow['tax_group_id'], $myrow['tax_included']); $first = true; foreach($tax_items as $tax_item) { diff --git a/reporting/rep111.php b/reporting/rep111.php index a8c77927..49096e4a 100644 --- a/reporting/rep111.php +++ b/reporting/rep111.php @@ -94,6 +94,10 @@ function print_sales_quotations() $result = get_sales_order_details($i, ST_SALESQUOTE); $SubTotal = 0; $items = $prices = array(); + if ($myrow["ship_via"]) { + $items[] = $myrow["ship_via"]; + $prices[] = $myrow["freight_cost"]; + } while ($myrow2=db_fetch($result)) { $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]), @@ -165,8 +169,7 @@ function print_sales_quotations() $rep->NewLine(); } - $tax_items = get_tax_for_items(ST_SALESORDER, $items, $prices, $myrow["freight_cost"], - $myrow['tax_group_id'], $myrow['tax_included']); + $tax_items = get_tax_for_items(ST_SALESORDER, $items, $prices, $myrow['tax_group_id'], $myrow['tax_included']); $first = true; foreach($tax_items as $tax_item) { diff --git a/reporting/rep209.php b/reporting/rep209.php index 7e990bae..ae76e245 100644 --- a/reporting/rep209.php +++ b/reporting/rep209.php @@ -167,8 +167,7 @@ function print_po() $rep->TextCol(6, 7, $DisplaySubTot, -2); $rep->NewLine(); - $tax_items = get_tax_for_items(ST_PURCHORDER, $items, $prices, 0, - $myrow['tax_group_id'], $myrow['tax_included'], TCA_LINES); + $tax_items = get_tax_for_items(ST_PURCHORDER, $items, $prices, $myrow['tax_group_id'], $myrow['tax_included'], TCA_LINES); $first = true; foreach($tax_items as $tax_item) { diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index 1e29859e..d0895890 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -353,8 +353,8 @@ locations_list_cells(null, 'Location', null, false, true); if (!isset($_POST['ship_via'])) { $_POST['ship_via'] = $_SESSION['Items']->ship_via; } -label_cell(_("Shipping Company"), "class='tableheader2'"); -shippers_list_cells(null, 'ship_via', $_POST['ship_via']); +label_cell(_("Shipping Method"), "class='tableheader2'"); +shipping_methods_list_cells(null, 'ship_via', $_POST['ship_via']); // set this up here cuz it's used to calc qoh if (!isset($_POST['DispatchDate']) || !is_date($_POST['DispatchDate'])) { diff --git a/sales/customer_invoice.php b/sales/customer_invoice.php index e4ab5158..ba0c8a41 100644 --- a/sales/customer_invoice.php +++ b/sales/customer_invoice.php @@ -467,13 +467,13 @@ start_row(); if (!isset($_POST['ship_via'])) { $_POST['ship_via'] = $_SESSION['Items']->ship_via; } -label_cell(_("Shipping Company"), "class='tableheader2'"); +label_cell(_("Shipping"), "class='tableheader2'"); if ($prepaid) { - $shipper = get_shipper($_SESSION['Items']->ship_via); - label_cells(null, $shipper['shipper_name']); + $shipping = get_item($_SESSION['Items']->ship_via); + label_cells(null, $shipping['description']); } else - shippers_list_cells(null, 'ship_via', $_POST['ship_via']); + shipping_methods_list_cells(null, 'ship_via', $_POST['ship_via']); if (!isset($_POST['InvoiceDate']) || !is_date($_POST['InvoiceDate'])) { $_POST['InvoiceDate'] = new_doc_date(); diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index e1f63d53..660fcc28 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -284,7 +284,7 @@ class Cart // Makes parent documents for direct delivery/invoice by recurent call. // $policy - 0 or 1: writeoff/return for IV, back order/cancel for DN function write($policy=0) { - + global $SysPrefs, $Refs; begin_transaction(); // prevents partial database changes in case of direct delivery/invoice @@ -517,8 +517,12 @@ class Cart { $items = array(); $prices = array(); - if ($shipping_cost == null) - $shipping_cost = $this->freight_cost; + if ($this->ship_via != '') { + if ($shipping_cost == null) + $shipping_cost = $this->freight_cost; + $items[] = $this->ship_via; + $prices[] = $shipping_cost; + } foreach ($this->line_items as $ln_itm) { $items[] = $ln_itm->stock_id; @@ -527,8 +531,7 @@ class Cart $ln_itm->line_price()* (1 - $ln_itm->discount_percent)), user_price_dec()); } - $taxes = get_tax_for_items($this->trans_type, $items, $prices, $shipping_cost, - $this->tax_group_id, $this->tax_included); + $taxes = get_tax_for_items($this->trans_type, $items, $prices, $this->tax_group_id, $this->tax_included); // Adjustment for swiss franken, we always have 5 rappen = 1/20 franken if ($this->customer_currency == 'CHF') { @@ -551,7 +554,7 @@ class Cart function get_shipping_tax() { - $freight = split_item_price(NULL, $this->freight_cost, $this->tax_group_id, $this->tax_included, $this->trans_type); + $freight = split_item_price($this->ship_via, $this->freight_cost, $this->tax_group_id, $this->tax_included, $this->trans_type); return $freight['Tax']; } diff --git a/sales/includes/db/cust_trans_db.inc b/sales/includes/db/cust_trans_db.inc index 888181eb..453a3b3f 100644 --- a/sales/includes/db/cust_trans_db.inc +++ b/sales/includes/db/cust_trans_db.inc @@ -139,8 +139,8 @@ function get_customer_trans($trans_id, $trans_type, $customer_id=null) } if ($trans_type == ST_SALESINVOICE || $trans_type == ST_CUSTCREDIT || $trans_type == ST_CUSTDELIVERY) { - // it's an invoice so also get the shipper and salestype - $sql .= ", ".TB_PREF."shippers.shipper_name, " + // it's an invoice so also get the shipping method and salestype + $sql .= ", IFNULL(ship.description, '-') shipping, " .TB_PREF."sales_types.sales_type, " .TB_PREF."sales_types.tax_included, " ."branch.*, " @@ -155,7 +155,7 @@ function get_customer_trans($trans_id, $trans_type, $customer_id=null) $sql .= " FROM ".TB_PREF."debtor_trans trans LEFT JOIN ".TB_PREF."comments com ON trans.type=com.type AND trans.trans_no=com.id - LEFT JOIN ".TB_PREF."shippers ON ".TB_PREF."shippers.shipper_id=trans.ship_via, + LEFT JOIN ".TB_PREF."stock_master ship ON ship.stock_id=trans.ship_via, ".TB_PREF."debtors_master cust"; if ($trans_type == ST_CUSTPAYMENT || $trans_type == ST_BANKDEPOSIT) { @@ -164,7 +164,6 @@ function get_customer_trans($trans_id, $trans_type, $customer_id=null) } if ($trans_type == ST_SALESINVOICE || $trans_type == ST_CUSTCREDIT || $trans_type == ST_CUSTDELIVERY) { - // it's an invoice so also get the shipper, salestypes $sql .= ", ".TB_PREF."sales_types, " .TB_PREF."cust_branch branch, " .TB_PREF."tax_groups "; diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index 37e01577..998a6a20 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -138,8 +138,10 @@ function write_credit_note(&$credit_note, $write_off_acc) $credit_note->customer_id); } + $freight = get_item($credit_note->ship_via); + if ($credit_note->freight_cost != 0) { - $total += add_gl_trans_customer(ST_CUSTCREDIT, $credit_no, $credit_date, $company_data["freight_act"], 0, 0, + $total += add_gl_trans_customer(ST_CUSTCREDIT, $credit_no, $credit_date, $freight["freight_act"], 0, 0, $credit_note->get_tax_free_shipping(), $credit_note->customer_id); } diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 1f79aa09..862df0a4 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -158,8 +158,10 @@ function write_sales_invoice(&$invoice) } $to_allocate = ($items_total + $charge_shipping + $items_added_tax + $freight_added_tax); + $freight = get_item($invoice->ship_via); + if ($charge_shipping != 0) { - $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $company_data["freight_act"], 0, 0, + $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $freight["sales_account"], 0, 0, -$invoice->get_tax_free_shipping()*$prepaid_factor, $invoice->customer_id); } // post all taxes diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index 9a8272a0..968777ab 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -231,7 +231,7 @@ function get_sales_order_header($order_no, $trans_type) stype.id AS sales_type_id, stype.tax_included, stype.factor, - ship.shipper_name, + ship.description as shipping, tax_group.name AS tax_group_name, tax_group.id AS tax_group_id, cust.tax_id, @@ -245,7 +245,7 @@ function get_sales_order_header($order_no, $trans_type) LEFT JOIN (SELECT order_, sum(alloc) inv_allocs FROM ".TB_PREF."debtor_trans WHERE type=".ST_SALESINVOICE." AND order_=".db_escape($order_no)." GROUP BY order_) inv ON sorder.trans_type=".ST_SALESORDER." AND inv.order_=sorder.order_no - LEFT JOIN ".TB_PREF."shippers ship ON ship.shipper_id = sorder.ship_via," + LEFT JOIN ".TB_PREF."stock_master ship ON ship.stock_id = sorder.ship_via," .TB_PREF."debtors_master cust," .TB_PREF."sales_types stype, " .TB_PREF."tax_groups tax_group, " diff --git a/sales/includes/ui/sales_credit_ui.inc b/sales/includes/ui/sales_credit_ui.inc index 0fd4dfc7..1a69deee 100644 --- a/sales/includes/ui/sales_credit_ui.inc +++ b/sales/includes/ui/sales_credit_ui.inc @@ -105,7 +105,7 @@ function display_credit_header(&$order) $change_prices = 1; } - shippers_list_row(_("Shipping Company:"), 'ShipperID', $order->ship_via); + shipping_methods_list_row(_("Shipping:"), 'ShipperID', $order->ship_via); label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%"); diff --git a/sales/includes/ui/sales_order_ui.inc b/sales/includes/ui/sales_order_ui.inc index 311bc3f2..d5e5600e 100644 --- a/sales/includes/ui/sales_order_ui.inc +++ b/sales/includes/ui/sales_order_ui.inc @@ -215,9 +215,15 @@ function display_order_summary($title, &$order, $editable_items=false) if ($order->trans_no!=0) ++$colspan; start_row(); - label_cell(_("Shipping Charge"), "colspan=$colspan align=right"); - small_amount_cells(null, 'freight_cost', price_format(get_post('freight_cost',0))); - label_cell('', 'colspan=2'); + + label_cell(_("Shipping method:") . shipping_methods_list('ship_via', null, _("None"), true), "colspan=$colspan align=right"); + + if (get_post('ship_via') !== ALL_TEXT) + { + small_amount_cells(null, 'freight_cost', price_format(get_post('freight_cost',0))); + label_cell('', 'colspan=2'); + } else + label_cell('', 'colspan=3'); end_row(); $display_sub_total = price_format($total + input_num('freight_cost')); label_row(_("Sub-total"), $display_sub_total, "colspan=$colspan align=right","align=right", 2); @@ -457,12 +463,22 @@ function display_order_header(&$order, $editable, $date_text) end_outer_table(1); // outer table + if (list_updated('ship_via')) { + $_SESSION['Items']->ship_via = get_post('ship_via'); + $_POST['freight_cost'] = price_format(get_price(get_post('ship_via'), $_SESSION['Items']->customer_currency, get_post('sales_type'))); + $Ajax->activate('items_table'); + } + + if ($change_prices != 0) { foreach ($order->line_items as $line_no=>$item) { $line = &$order->line_items[$line_no]; $line->price = get_kit_price($line->stock_id, $order->customer_currency, $order->sales_type, $order->price_factor, get_post('OrderDate')); } + } + if ($change_prices != 0 || list_updated('ship_via')) { + $_POST['freight_cost'] = price_format(get_price(get_post('ship_via'), $_SESSION['Items']->customer_currency, get_post('sales_type'))); $Ajax->activate('items_table'); } @@ -640,8 +656,6 @@ function display_delivery_details(&$order) _('Customer reference number for this order (if any)')); textarea_row(_("Comments:"), "Comments", $order->Comments, 31, 5); - shippers_list_row(_("Shipping Company:"), 'ship_via', $order->ship_via); - end_outer_table(1); } div_end(); diff --git a/sales/manage/customer_branches.php b/sales/manage/customer_branches.php index 2e1eae54..8902135a 100644 --- a/sales/manage/customer_branches.php +++ b/sales/manage/customer_branches.php @@ -234,7 +234,7 @@ function branch_settings($selected_id, $num_branches) { sales_areas_list_row( _("Sales Area:"), 'area', null); sales_groups_list_row(_("Sales Group:"), 'group_no', null, true); locations_list_row(_("Default Inventory Location:"), 'default_location', null); - shippers_list_row(_("Default Shipping Company:"), 'default_ship_via', null); + shipping_methods_list_row(_("Default Shipping:"), 'default_ship_via', null); tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null); table_section_title(_("GL Accounts")); diff --git a/sales/manage/customers.php b/sales/manage/customers.php index 3810e2b4..01d9fe50 100644 --- a/sales/manage/customers.php +++ b/sales/manage/customers.php @@ -294,7 +294,7 @@ function customer_settings($selected_id) { table_section_title(_("Branch")); locations_list_row(_("Default Inventory Location:"), 'location'); - shippers_list_row(_("Default Shipping Company:"), 'ship_via'); + shipping_methods_list_row(_("Default Shipping:"), 'ship_via'); sales_areas_list_row( _("Sales Area:"), 'area', null); tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null); } diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index dad3c63c..77e975d4 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -258,24 +258,25 @@ function copy_to_cart() { $cart = &$_SESSION['Items']; + $cart->reference = $_POST['ref']; $cart->Comments = $_POST['Comments']; $cart->document_date = $_POST['OrderDate']; - $newpayment = false; + $newpayment = false; if (isset($_POST['payment']) && ($cart->payment != $_POST['payment'])) { $cart->payment = $_POST['payment']; $cart->payment_terms = get_payment_terms($_POST['payment']); $newpayment = true; } if ($cart->payment_terms['cash_sale']) { - if ($newpayment) { + if ($newpayment) + { $cart->due_date = $cart->document_date; $cart->phone = $cart->cust_ref = $cart->delivery_address = ''; - $cart->ship_via = 0; $cart->deliver_to = ''; $cart->prep_amount = 0; } @@ -285,10 +286,11 @@ function copy_to_cart() $cart->deliver_to = $_POST['deliver_to']; $cart->delivery_address = $_POST['delivery_address']; $cart->phone = $_POST['phone']; - $cart->ship_via = $_POST['ship_via']; if (!$cart->trans_no || ($cart->trans_type == ST_SALESORDER && !$cart->is_started())) $cart->prep_amount = input_num('prep_amount', 0); } + + $cart->ship_via = $_POST['ship_via']; $cart->Location = $_POST['Location']; $cart->freight_cost = input_num('freight_cost'); if (isset($_POST['email'])) @@ -408,10 +410,7 @@ function can_process() { return false; } - if ($_POST['freight_cost'] == "") - $_POST['freight_cost'] = price_format(0); - - if (!check_num('freight_cost',0)) { + if (isset($_POST['freight_cost']) && !check_num('freight_cost',0)) { display_error(_("The shipping cost entered is expected to be numeric.")); set_focus('freight_cost'); return false; diff --git a/sales/view/view_credit.php b/sales/view/view_credit.php index a6f70980..7c2442e5 100644 --- a/sales/view/view_credit.php +++ b/sales/view/view_credit.php @@ -71,7 +71,7 @@ label_cells(_("Currency"), $myrow["curr_code"], "class='tableheader2'"); end_row(); start_row(); label_cells(_("Sales Type"), $myrow["sales_type"], "class='tableheader2'"); -label_cells(_("Shipping Company"), $myrow["shipper_name"], "class='tableheader2'"); +label_cells(_("Shipping"), $myrow["shipping"], "class='tableheader2'"); end_row(); comments_display_row(ST_CUSTCREDIT, $trans_id); end_table(); diff --git a/sales/view/view_dispatch.php b/sales/view/view_dispatch.php index 8c1b0313..69f1534e 100644 --- a/sales/view/view_dispatch.php +++ b/sales/view/view_dispatch.php @@ -89,7 +89,7 @@ label_cells(_("Our Order No"), end_row(); start_row(); label_cells(_("Customer Order Ref."), $sales_order["customer_ref"], "class='tableheader2'"); -label_cells(_("Shipping Company"), $myrow["shipper_name"], "class='tableheader2'"); +label_cells(_("Shipping"), $myrow["shipping"], "class='tableheader2'"); label_cells(_("Sales Type"), $myrow["sales_type"], "class='tableheader2'"); end_row(); start_row(); diff --git a/sales/view/view_invoice.php b/sales/view/view_invoice.php index f605fc69..ead1bd3a 100644 --- a/sales/view/view_invoice.php +++ b/sales/view/view_invoice.php @@ -89,7 +89,7 @@ label_cells(_("Our Order No"), end_row(); start_row(); label_cells(_("Customer Order Ref."), $sales_order["customer_ref"], "class='tableheader2'"); -label_cells(_("Shipping Company"), $myrow["shipper_name"], "class='tableheader2'"); +label_cells(_("Shipping"), $myrow["shipping"], "class='tableheader2'"); label_cells(_("Sales Type"), $myrow["sales_type"], "class='tableheader2'"); end_row(); start_row(); diff --git a/sales/view/view_sales_order.php b/sales/view/view_sales_order.php index 61a2181b..aab384b7 100644 --- a/sales/view/view_sales_order.php +++ b/sales/view/view_sales_order.php @@ -90,7 +90,8 @@ label_cells(_("All Payments Allocated"), price_format($_SESSION['View']->sum_pai end_row(); } else label_row(_("Payment Terms"), $_SESSION['View']->payment_terms['terms'], "class='tableheader2'", "colspan=3"); - +$shipping = get_item($_SESSION['View']->ship_via); +label_row(_("Shipping"), $shipping['description'], "class='tableheader2'", "colspan=3"); label_row(_("Delivery Address"), nl2br($_SESSION['View']->delivery_address), "class='tableheader2'", "colspan=3"); label_row(_("Reference"), $_SESSION['View']->reference, "class='tableheader2'", "colspan=3"); diff --git a/sql/alter2.5.php b/sql/alter2.5.php index f79dde51..1d511e14 100644 --- a/sql/alter2.5.php +++ b/sql/alter2.5.php @@ -22,18 +22,51 @@ class fa2_5 extends fa_patch { $this->description = _('Upgrade from version 2.4 to 2.5'); } - // - // Install procedure. All additional changes - // not included in sql file should go here. - // + /* + Shows parameters to be selected before upgrade (if any) + */ + function show_params($company) + { + + display_note(_('Check upgrade parameters below and start upgrade.')); + start_table(TABLESTYLE); + table_section(1); + table_section_title(_("Shipments category default settings")); + text_row(_("Category Name:"), 'shipping_cat_description', _('Shippment'), 30, 30); + item_tax_types_list_row(_('Item Tax Type:'), 'shipping_tax_type'); + stock_units_list_row(_('Unit of measure:'), 'shipping_units'); + gl_all_accounts_list_row(_("Sales Account:"), 'shipping_sales_act', get_company_pref('freight_act')); + gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'shipping_cogs_act', get_company_pref('default_cogs_act')); + end_table(); + br(); + + } + + /* + Fetch & check upgrade parameters, check additional upgrade pre-conditions, set SQL variables. + This function is run after successfull switching to target database connection, before sql upgrade script is run. + */ + function prepare() + { + // set upgrade script parameters + foreach( array('shipping_cat_description', 'shipping_tax_type', 'shipping_units', 'shipping_sales_act', 'shipping_cogs_act') as $name) + db_query("SET @$name=".db_escape(get_post($name))); + return true; + } + + + /* + Install procedure. All additional changes + not included in sql file should go here. + */ function install($company, $force=false) { return true; } - // - // optional procedure done after upgrade fail, before backup is restored - // + /* + Optional procedure done after upgrade fail, before backup is restored + */ function post_fail($company) { } diff --git a/sql/alter2.5.sql b/sql/alter2.5.sql index c92046e0..1511ff11 100644 --- a/sql/alter2.5.sql +++ b/sql/alter2.5.sql @@ -24,3 +24,38 @@ UPDATE `0_trans_tax_details` tax SET tax.tax_group_id = IFNULL(supp.tax_group_id, cust.tax_group_id); ALTER TABLE `0_tax_groups` ADD COLUMN `tax_area` tinyint(1) NOT NULL DEFAULT '0' AFTER `name`; + +# shipment options +ALTER TABLE `0_stock_master` ADD COLUMN `shipper_id` INT(11) NOT NULL DEFAULT '0' AFTER `vat_category`; + +INSERT INTO `0_stock_category` (`description`, `dflt_tax_type`, `dflt_units`, `dflt_mb_flag`, `dflt_sales_act`, `dflt_cogs_act`, `dflt_no_sale`) + VALUES (@shipping_cat_description, @shipping_tax_type, @shipping_units, 'T', @shipping_sales_act, @shipping_cogs_act, '1'); + +SET @shipment_cat=LAST_INSERT_ID(); + +INSERT INTO `0_stock_master` (`stock_id`, `tax_type_id`, `description`, `units`, `mb_flag`, `sales_account`, `no_sale`, `no_purchase`, `vat_category`, `category_id`, `shipper_id`, `inactive`) + SELECT shipper.shipper_name, @shipping_tax_type, shipper.shipper_name, @shipping_units, 'T', @shipping_sales_act, 1, 1, 0, @shipment_cat, shipper.shipper_id, shipper.inactive + FROM `0_shippers` shipper; + +ALTER TABLE `0_sales_orders` CHANGE COLUMN `ship_via` `ship_via` varchar(20) NOT NULL DEFAULT ''; + +UPDATE `0_sales_orders` ord + LEFT JOIN `0_shippers` ship ON ord.ship_via=ship.shipper_id + LEFT JOIN `0_stock_master` stock ON stock.shipper_id=ship.shipper_id + SET ord.ship_via=stock.stock_id; + +ALTER TABLE `0_debtor_trans` CHANGE COLUMN `ship_via` `ship_via` varchar(20) NOT NULL DEFAULT ''; + +UPDATE `0_debtor_trans` trans + LEFT JOIN `0_shippers` ship ON trans.ship_via=ship.shipper_id + LEFT JOIN `0_stock_master` stock ON stock.shipper_id=ship.shipper_id + SET trans.ship_via=stock.stock_id; + +ALTER TABLE `0_cust_branch` CHANGE COLUMN `default_ship_via` `default_ship_via` varchar(20) NOT NULL DEFAULT ''; + +UPDATE `0_cust_branch` branch + LEFT JOIN `0_shippers` ship ON branch.default_ship_via=ship.shipper_id + LEFT JOIN `0_stock_master` stock ON stock.shipper_id=ship.shipper_id + SET branch.default_ship_via=stock.stock_id; + +ALTER TABLE `0_tax_group_items` DROP COLUMN `tax_shipping`; diff --git a/sql/en_US-demo.sql b/sql/en_US-demo.sql index 1d7184cb..b6cdf6e1 100644 --- a/sql/en_US-demo.sql +++ b/sql/en_US-demo.sql @@ -561,7 +561,7 @@ CREATE TABLE `0_cust_branch` ( `sales_discount_account` varchar(15) NOT NULL DEFAULT '', `receivables_account` varchar(15) NOT NULL DEFAULT '', `payment_discount_account` varchar(15) NOT NULL DEFAULT '', - `default_ship_via` int(11) NOT NULL DEFAULT '1', + `default_ship_via` varchar(20) NOT NULL DEFAULT '', `br_post_address` tinytext NOT NULL, `group_no` int(11) NOT NULL DEFAULT '0', `notes` tinytext NOT NULL, @@ -575,8 +575,8 @@ CREATE TABLE `0_cust_branch` ( -- Data of table `0_cust_branch` -- INSERT INTO `0_cust_branch` VALUES -('1', '1', 'Donald Easter LLC', 'Donald Easter', 'N/A', '1', '1', 'DEF', '1', '', '4510', '1200', '4500', '1', 'N/A', '0', '', NULL, '0'), -('2', '2', 'MoneyMaker Ltd.', 'MoneyMaker', '', '1', '1', 'DEF', '2', '', '4510', '1200', '4500', '1', '', '0', '', NULL, '0'); +('1', '1', 'Donald Easter LLC', 'Donald Easter', 'N/A', '1', '1', 'DEF', '1', '', '4510', '1200', '4500', 'post-std', 'N/A', '0', '', NULL, '0'), +('2', '2', 'MoneyMaker Ltd.', 'MoneyMaker', '', '1', '1', 'DEF', '2', '', '4510', '1200', '4500', 'post-std', '', '0', '', NULL, '0'); -- Structure of table `0_debtor_trans` -- @@ -601,7 +601,7 @@ CREATE TABLE `0_debtor_trans` ( `alloc` double NOT NULL DEFAULT '0', `prep_amount` double NOT NULL DEFAULT '0', `rate` double NOT NULL DEFAULT '1', - `ship_via` int(11) DEFAULT NULL, + `ship_via` varchar(20) NOT NULL DEFAULT '', `dimension_id` int(11) NOT NULL DEFAULT '0', `dimension2_id` int(11) NOT NULL DEFAULT '0', `payment_terms` int(11) DEFAULT NULL, @@ -615,20 +615,20 @@ CREATE TABLE `0_debtor_trans` ( -- Data of table `0_debtor_trans` -- INSERT INTO `0_debtor_trans` VALUES -('1', '10', '0', '1', '1', '2018-05-10', '2018-05-05', '001/2018', '1', '1', '6240', '0', '0', '0', '0', '6240', '0', '1', '1', '0', '0', '4', '1'), -('2', '10', '0', '1', '1', '2018-05-07', '2018-05-07', '002/2018', '1', '2', '300', '0', '0', '0', '0', '300', '0', '1', '1', '0', '0', '4', '1'), -('3', '10', '0', '2', '2', '2018-05-07', '2018-06-17', '003/2018', '1', '5', '267.14', '0', '0', '0', '0', '0', '0', '1.123', '1', '1', '0', '1', '1'), -('4', '10', '0', '1', '1', '2018-05-07', '2018-05-07', '004/2018', '1', '7', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', '4', '1'), -('5', '10', '0', '1', '1', '2019-01-21', '2019-01-21', '001/2019', '1', '8', '1250', '0', '0', '0', '0', '1250', '0', '1', '1', '0', '0', '4', '1'), -('1', '12', '0', '1', '1', '2018-05-10', '0000-00-00', '001/2018', '0', '0', '6240', '0', '0', '0', '0', '6240', '0', '1', '0', '0', '0', NULL, '0'), -('2', '12', '0', '1', '1', '2018-05-07', '0000-00-00', '002/2018', '0', '0', '300', '0', '0', '0', '0', '300', '0', '1', '0', '0', '0', NULL, '0'), -('3', '12', '0', '1', '1', '2018-05-07', '0000-00-00', '003/2018', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', NULL, '0'), -('4', '12', '0', '1', '1', '2019-01-21', '0000-00-00', '001/2019', '0', '0', '1250', '0', '0', '0', '0', '1250', '0', '1', '0', '0', '0', NULL, '0'), -('1', '13', '1', '1', '1', '2018-05-10', '2018-05-05', 'auto', '1', '1', '6240', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', '4', '1'), -('2', '13', '1', '1', '1', '2018-05-07', '2018-05-07', 'auto', '1', '2', '300', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', '4', '1'), -('3', '13', '1', '2', '2', '2018-05-07', '2018-06-17', 'auto', '1', '5', '267.14', '0', '0', '0', '0', '0', '0', '1.123', '1', '1', '0', '1', '1'), -('4', '13', '1', '1', '1', '2018-05-07', '2018-05-07', 'auto', '1', '7', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', '4', '1'), -('5', '13', '1', '1', '1', '2019-01-21', '2019-01-21', 'auto', '1', '8', '1250', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', '4', '1'); +('1', '10', '0', '1', '1', '2018-05-10', '2018-05-05', '001/2018', '1', '1', '6240', '0', '0', '0', '0', '6240', '0', '1', 'std-post', '0', '0', '4', '1'), +('2', '10', '0', '1', '1', '2018-05-07', '2018-05-07', '002/2018', '1', '2', '300', '0', '0', '0', '0', '300', '0', '1', 'std-post', '0', '0', '4', '1'), +('3', '10', '0', '2', '2', '2018-05-07', '2018-06-17', '003/2018', '1', '5', '267.14', '0', '0', '0', '0', '0', '0', '1.123', 'std-post', '1', '0', '1', '1'), +('4', '10', '0', '1', '1', '2018-05-07', '2018-05-07', '004/2018', '1', '7', '0', '0', '0', '0', '0', '0', '0', '1', 'std-post', '0', '0', '4', '1'), +('5', '10', '0', '1', '1', '2019-01-21', '2019-01-21', '001/2019', '1', '8', '1250', '0', '0', '0', '0', '1250', '0', '1', 'std-post', '0', '0', '4', '1'), +('1', '12', '0', '1', '1', '2018-05-10', '0000-00-00', '001/2018', '0', '0', '6240', '0', '0', '0', '0', '6240', '0', '1', '', '0', '0', NULL, '0'), +('2', '12', '0', '1', '1', '2018-05-07', '0000-00-00', '002/2018', '0', '0', '300', '0', '0', '0', '0', '300', '0', '1', '', '0', '0', NULL, '0'), +('3', '12', '0', '1', '1', '2018-05-07', '0000-00-00', '003/2018', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '', '0', '0', NULL, '0'), +('4', '12', '0', '1', '1', '2019-01-21', '0000-00-00', '001/2019', '0', '0', '1250', '0', '0', '0', '0', '1250', '0', '', '0', '0', '0', NULL, '0'), +('1', '13', '1', '1', '1', '2018-05-10', '2018-05-05', 'auto', '1', '1', '6240', '0', '0', '0', '0', '0', '0', '1', 'std-post', '0', '0', '4', '1'), +('2', '13', '1', '1', '1', '2018-05-07', '2018-05-07', 'auto', '1', '2', '300', '0', '0', '0', '0', '0', '0', '1', 'std-post', '0', '0', '4', '1'), +('3', '13', '1', '2', '2', '2018-05-07', '2018-06-17', 'auto', '1', '5', '267.14', '0', '0', '0', '0', '0', '0', '1.123', 'std-post', '1', '0', '1', '1'), +('4', '13', '1', '1', '1', '2018-05-07', '2018-05-07', 'auto', '1', '7', '0', '0', '0', '0', '0', '0', '0', '1', 'std-post', '0', '0', '4', '1'), +('5', '13', '1', '1', '1', '2019-01-21', '2019-01-21', 'auto', '1', '8', '1250', '0', '0', '0', '0', '0', '0', '1', 'std-post', '0', '0', '4', '1'); -- Structure of table `0_debtor_trans_details` -- @@ -1439,7 +1439,7 @@ CREATE TABLE `0_sales_orders` ( `comments` tinytext, `ord_date` date NOT NULL DEFAULT '0000-00-00', `order_type` int(11) NOT NULL DEFAULT '0', - `ship_via` int(11) NOT NULL DEFAULT '0', + `ship_via` varchar(20) NOT NULL DEFAULT '', `delivery_address` tinytext NOT NULL, `contact_phone` varchar(30) DEFAULT NULL, `contact_email` varchar(100) DEFAULT NULL, @@ -1457,14 +1457,14 @@ CREATE TABLE `0_sales_orders` ( -- Data of table `0_sales_orders` -- INSERT INTO `0_sales_orders` VALUES -('1', '30', '1', '0', '1', '1', 'auto', '', NULL, '2018-05-10', '1', '1', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2018-05-05', '4', '6240', '0', '0'), -('2', '30', '1', '0', '1', '1', 'auto', '', NULL, '2018-05-07', '1', '1', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2018-05-07', '4', '300', '0', '0'), -('3', '30', '0', '0', '1', '1', '001/2018', '', NULL, '2018-05-07', '1', '1', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2018-05-08', '4', '300', '0', '0'), -('4', '30', '0', '0', '2', '2', '002/2018', '', NULL, '2018-05-07', '1', '1', 'N/A', NULL, NULL, 'MoneyMaker Ltd.', '0', 'DEF', '2018-05-08', '1', '267.14', '0', '0'), -('5', '30', '1', '0', '2', '2', 'auto', '', NULL, '2018-05-07', '1', '1', 'N/A', NULL, NULL, 'MoneyMaker Ltd.', '0', 'DEF', '2018-06-17', '1', '267.14', '0', '0'), -('6', '30', '0', '1', '1', '1', '003/2018', '', NULL, '2018-05-07', '1', '1', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2018-05-08', '4', '450', '0', '0'), -('7', '30', '1', '0', '1', '1', 'auto', '', 'Recurrent Invoice covers period 04/01/2018 - 04/07/2018.', '2018-05-07', '1', '1', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2018-05-07', '4', '0', '0', '0'), -('8', '30', '1', '0', '1', '1', 'auto', '', NULL, '2019-01-21', '1', '1', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2019-01-21', '4', '1250', '0', '0'); +('1', '30', '1', '0', '1', '1', 'auto', '', NULL, '2018-05-10', '1', 'post-std', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2018-05-05', '4', '6240', '0', '0'), +('2', '30', '1', '0', '1', '1', 'auto', '', NULL, '2018-05-07', '1', 'post-std', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2018-05-07', '4', '300', '0', '0'), +('3', '30', '0', '0', '1', '1', '001/2018', '', NULL, '2018-05-07', '1', 'post-std', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2018-05-08', '4', '300', '0', '0'), +('4', '30', '0', '0', '2', '2', '002/2018', '', NULL, '2018-05-07', '1', 'post-std', 'N/A', NULL, NULL, 'MoneyMaker Ltd.', '0', 'DEF', '2018-05-08', '1', '267.14', '0', '0'), +('5', '30', '1', '0', '2', '2', 'auto', '', NULL, '2018-05-07', '1', 'post-std', 'N/A', NULL, NULL, 'MoneyMaker Ltd.', '0', 'DEF', '2018-06-17', '1', '267.14', '0', '0'), +('6', '30', '0', '1', '1', '1', '003/2018', '', NULL, '2018-05-07', '1', 'post-std', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2018-05-08', '4', '450', '0', '0'), +('7', '30', '1', '0', '1', '1', 'auto', '', 'Recurrent Invoice covers period 04/01/2018 - 04/07/2018.', '2018-05-07', '1', 'post-std', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2018-05-07', '4', '0', '0', '0'), +('8', '30', '1', '0', '1', '1', 'auto', '', NULL, '2019-01-21', '1', 'post-std', 'N/A', NULL, NULL, 'Donald Easter LLC', '0', 'DEF', '2019-01-21', '4', '1250', '0', '0'); -- Structure of table `0_sales_pos` -- @@ -1626,7 +1626,8 @@ INSERT INTO `0_stock_category` VALUES ('1', 'Components', '1', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0'), ('2', 'Charges', '1', 'each', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0'), ('3', 'Systems', '1', 'each', 'M', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0'), -('4', 'Services', '1', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0'); +('4', 'Services', '1', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0'), +('5', 'Shipping', '1', 'each', 'T', '4430', '5010', '', '', '', '0', '0', '0', '1', '0', '0'); -- Structure of table `0_stock_fa_class` -- @@ -1678,18 +1679,20 @@ CREATE TABLE `0_stock_master` ( `depreciation_date` date NOT NULL DEFAULT '0000-00-00', `fa_class_id` varchar(20) NOT NULL DEFAULT '', `vat_category` tinyint(1) NOT NULL DEFAULT '0', + `shipper_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`stock_id`) ) ENGINE=InnoDB ; -- Data of table `0_stock_master` -- INSERT INTO `0_stock_master` VALUES -('101', '1', '1', 'iPad Air 2 16GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '200', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0'), -('102', '1', '1', 'iPhone 6 64GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '150', '150', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0'), -('103', '1', '1', 'iPhone Cover Case', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '10', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0'), -('201', '3', '1', 'AP Surf Set', '', 'each', 'M', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '360', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0'), -('202', '4', '1', 'Maintenance', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0'), -('301', '4', '1', 'Support', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0'); +('101', '1', '1', 'iPad Air 2 16GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '200', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0', '0'), +('102', '1', '1', 'iPhone 6 64GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '150', '150', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0', '0'), +('103', '1', '1', 'iPhone Cover Case', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '10', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0', '0'), +('201', '3', '1', 'AP Surf Set', '', 'each', 'M', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '360', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0', '0'), +('202', '4', '1', 'Maintenance', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0', '0'), +('301', '4', '1', 'Support', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0', '0'), +('post-std', '5', '1', 'Standard post package', '', 'each', 'T', '4430', '5010', '', '', '', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0', '0'); -- Structure of table `0_stock_moves` -- @@ -1976,14 +1979,13 @@ DROP TABLE IF EXISTS `0_tax_group_items`; CREATE TABLE `0_tax_group_items` ( `tax_group_id` int(11) NOT NULL DEFAULT '0', `tax_type_id` int(11) NOT NULL DEFAULT '0', - `tax_shipping` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`tax_group_id`,`tax_type_id`) ) ENGINE=InnoDB ; -- Data of table `0_tax_group_items` -- INSERT INTO `0_tax_group_items` VALUES -('1', '1', '1'); +('1', '1'); -- Structure of table `0_tax_groups` -- diff --git a/sql/en_US-new.sql b/sql/en_US-new.sql index 6e2fba32..7cfb0fc9 100644 --- a/sql/en_US-new.sql +++ b/sql/en_US-new.sql @@ -481,7 +481,7 @@ CREATE TABLE `0_cust_branch` ( `sales_discount_account` varchar(15) NOT NULL DEFAULT '', `receivables_account` varchar(15) NOT NULL DEFAULT '', `payment_discount_account` varchar(15) NOT NULL DEFAULT '', - `default_ship_via` int(11) NOT NULL DEFAULT '1', + `default_ship_via` varchar(20) NOT NULL DEFAULT '', `br_post_address` tinytext NOT NULL, `group_no` int(11) NOT NULL DEFAULT '0', `notes` tinytext NOT NULL, @@ -517,7 +517,7 @@ CREATE TABLE `0_debtor_trans` ( `alloc` double NOT NULL DEFAULT '0', `prep_amount` double NOT NULL DEFAULT '0', `rate` double NOT NULL DEFAULT '1', - `ship_via` int(11) DEFAULT NULL, + `ship_via` varchar(20) NOT NULL DEFAULT '', `dimension_id` int(11) NOT NULL DEFAULT '0', `dimension2_id` int(11) NOT NULL DEFAULT '0', `payment_terms` int(11) DEFAULT NULL, @@ -1162,7 +1162,7 @@ CREATE TABLE `0_sales_orders` ( `comments` tinytext, `ord_date` date NOT NULL DEFAULT '0000-00-00', `order_type` int(11) NOT NULL DEFAULT '0', - `ship_via` int(11) NOT NULL DEFAULT '0', + `ship_via` varchar(20) NOT NULL DEFAULT '', `delivery_address` tinytext NOT NULL, `contact_phone` varchar(30) DEFAULT NULL, `contact_email` varchar(100) DEFAULT NULL, @@ -1338,7 +1338,8 @@ INSERT INTO `0_stock_category` VALUES ('1', 'Components', '1', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0'), ('2', 'Charges', '1', 'each', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0'), ('3', 'Systems', '1', 'each', 'M', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0'), -('4', 'Services', '1', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0'); +('4', 'Services', '1', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0'), +('5', 'Shipping', '1', 'each', 'T', '4430', '5010', '', '', '', '0', '0', '0', '1', '0', '0'); -- Structure of table `0_stock_fa_class` -- @@ -1390,11 +1391,13 @@ CREATE TABLE `0_stock_master` ( `depreciation_date` date NOT NULL DEFAULT '0000-00-00', `fa_class_id` varchar(20) NOT NULL DEFAULT '', `vat_category` tinyint(1) NOT NULL DEFAULT '0', + `shipper_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`stock_id`) ) ENGINE=InnoDB; -- Data of table `0_stock_master` -- - +INSERT INTO `0_stock_master` VALUES +('post-std', '5', '1', 'Standard post package', '', 'each', 'T', '4430', '5010', '', '', '', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '', '0', '0'); -- Structure of table `0_stock_moves` -- DROP TABLE IF EXISTS `0_stock_moves`; @@ -1649,14 +1652,13 @@ DROP TABLE IF EXISTS `0_tax_group_items`; CREATE TABLE `0_tax_group_items` ( `tax_group_id` int(11) NOT NULL DEFAULT '0', `tax_type_id` int(11) NOT NULL DEFAULT '0', - `tax_shipping` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`tax_group_id`,`tax_type_id`) ) ENGINE=InnoDB ; -- Data of table `0_tax_group_items` -- INSERT INTO `0_tax_group_items` VALUES -('1', '1', '1'); +('1', '1'); -- Structure of table `0_tax_groups` -- diff --git a/taxes/db/tax_groups_db.inc b/taxes/db/tax_groups_db.inc index 5e152855..ef91b3ea 100644 --- a/taxes/db/tax_groups_db.inc +++ b/taxes/db/tax_groups_db.inc @@ -9,7 +9,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -function add_tax_group($name, $taxes, $tax_shippings, $tax_area) +function add_tax_group($name, $taxes, $tax_area) { begin_transaction(); @@ -18,12 +18,12 @@ function add_tax_group($name, $taxes, $tax_shippings, $tax_area) $id = db_insert_id(); - add_tax_group_items($id, $taxes, $tax_shippings); + add_tax_group_items($id, $taxes); commit_transaction(); } -function update_tax_group($id, $name, $taxes, $tax_shippings, $tax_area) +function update_tax_group($id, $name, $taxes, $tax_area) { begin_transaction(); @@ -31,9 +31,9 @@ function update_tax_group($id, $name, $taxes, $tax_shippings, $tax_area) db_query($sql, "could not update tax group"); delete_tax_group_items($id); - add_tax_group_items($id, $taxes, $tax_shippings); + add_tax_group_items($id, $taxes); - commit_transaction(); + commit_transaction(); } function get_all_tax_groups($all=false) @@ -66,13 +66,13 @@ function delete_tax_group($id) commit_transaction(); } -function add_tax_group_items($id, $items, $tax_shippings) +function add_tax_group_items($id, $items) { for ($i=0; $i < count($items); $i++) { - $sql = "INSERT INTO ".TB_PREF."tax_group_items (tax_group_id, tax_type_id, tax_shipping) - VALUES (".db_escape($id).", ".db_escape($items[$i]).", " . $tax_shippings[$i] .")"; - db_query($sql, "could not add item tax group item"); + $sql = "INSERT INTO ".TB_PREF."tax_group_items (tax_group_id, tax_type_id) + VALUES (".db_escape($id).", ".db_escape($items[$i]).")"; + db_query($sql, "could not add item tax group item"); } } @@ -80,14 +80,13 @@ function delete_tax_group_items($id) { $sql = "DELETE FROM ".TB_PREF."tax_group_items WHERE tax_group_id=".db_escape($id); - db_query($sql, "could not delete item tax group items"); + db_query($sql, "could not delete item tax group items"); } // // Return all tax types with rate value updated according to tax group selected -// Call the function without arg to find shipment group taxes. // -function get_tax_group_rates($group_id=null, $tax_shipping=false) +function get_tax_group_rates($group_id) { global $SysPrefs; @@ -97,14 +96,10 @@ function get_tax_group_rates($group_id=null, $tax_shipping=false) : "CONCAT(t.name, ' (', t.rate, '%)') as tax_type_name,") ."t.sales_gl_code, t.purchasing_gl_code, - IF(g.tax_type_id, t.rate, NULL) as rate, - g.tax_shipping + IF(g.tax_type_id, t.rate, NULL) as rate FROM ".TB_PREF."tax_types t LEFT JOIN ".TB_PREF."tax_group_items g ON t.id=g.tax_type_id - AND g.tax_group_id=". ($group_id ? db_escape($group_id) : "(SELECT MIN(id) FROM ".TB_PREF."tax_groups)") - . " WHERE !t.inactive"; - if ($tax_shipping) - $sql .= " AND g.tax_shipping=1"; + AND g.tax_group_id=".db_escape($group_id). " WHERE !t.inactive"; return db_query($sql, "cannot get tax types as array"); } @@ -143,7 +138,7 @@ function find_domestic_tax_group() (SELECT g.id, count(*) cnt FROM ".TB_PREF."tax_group_items i LEFT JOIN ".TB_PREF."tax_groups g ON g.id=i.tax_group_id - WHERE tax_shipping=0 AND tax_area=0 AND !inactive + WHERE tax_area=0 AND !inactive GROUP BY g.id) cnts ORDER by cnt DESC"; $result = db_query($sql, "cannot get domestic group id"); @@ -151,17 +146,3 @@ function find_domestic_tax_group() return $group['id']; } -function get_shipping_tax_as_array($id=null) -{ - $ret_tax_array = array(); - - $tax_group_items = get_tax_group_rates($id, true); - - while ($tax_group_item = db_fetch($tax_group_items)) - { - $tax_group_item['Value'] = 0; - $ret_tax_array[$tax_group_item['tax_type_id']] = $tax_group_item; - } - - return $ret_tax_array; -} diff --git a/taxes/tax_calc.inc b/taxes/tax_calc.inc index 004fcd33..4b36dc07 100644 --- a/taxes/tax_calc.inc +++ b/taxes/tax_calc.inc @@ -33,13 +33,6 @@ function get_base_taxdata($stock_id, $group_id) $taxdata = array('tax_area' => $group_data['tax_area'], 'taxes' => null); - if ($stock_id===null) // shipping special case - { - $taxdata['vat_category'] = VC_SERVICES; - $taxdata['taxes'] = get_tax_group_items_as_array(null); - return $taxdata; - } - $item_tax_type = get_item_tax_type_for_item($stock_id); // get item tax data $taxdata['vat_category'] = $item_tax_type['vat_category']; @@ -91,7 +84,6 @@ function get_base_taxdata($stock_id, $group_id) /* Main tax procedure splitting transaction item value according to item tax rules applicable: - $stock_id - stock item code; NULL for shipping $amount - price/value to be splitted $tax_group - entity tax group $tax_included - whether value includes all taxes @@ -223,19 +215,10 @@ function split_item_price($stock_id, $amount, $group_id, $tax_included=false, $t // // $vat_factors - effective part of vat values included in tax; calculated but not included vat is added to net value // -function get_tax_for_items($trans_type, $items, $prices, $shipping_cost, $tax_group, $tax_included=null, +function get_tax_for_items($trans_type, $items, $prices, $tax_group, $tax_included=null, $tax_algorithm = null, $vat_factors = null, $allow_reverse = true) { - // if shipping cost is passed, just add to the prices/items tables - if ($shipping_cost != 0) - { - $items[] = NULL; - $prices[] = $shipping_cost; - if ($vat_factors) - $vat_factors[] = 1; - } - // calculate tax sums $ret_tax_array = array(); foreach($items as $i => $stock_id) diff --git a/taxes/tax_groups.php b/taxes/tax_groups.php index 451c344a..00ad23bd 100644 --- a/taxes/tax_groups.php +++ b/taxes/tax_groups.php @@ -45,26 +45,23 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') // create an array of the taxes and array of rates $taxes = array(); - $tax_shippings = array(); while (($id = find_submit('tax_type_id'))!=-1) { if (check_value('tax_type_id'.$id) != 0) { $taxes[] = $id; - $tax_shippings[] = check_value('tax_shipping'.$id); } unset($_POST['tax_type_id' . $id]); - unset($_POST['tax_shipping' . $id]); } if ($selected_id != -1) { - update_tax_group($selected_id, $_POST['name'], $taxes, $tax_shippings, get_post('tax_area')); + update_tax_group($selected_id, $_POST['name'], $taxes, get_post('tax_area')); display_notification(_('Selected tax group has been updated')); } else { - add_tax_group($_POST['name'], $taxes, $tax_shippings, get_post('tax_area')); + add_tax_group($_POST['name'], $taxes, get_post('tax_area')); display_notification(_('New tax group has been added')); } @@ -174,7 +171,7 @@ display_note(_("Select the taxes that are included in this group."), 1, 1); $items = get_tax_group_rates($selected_id!=-1 ? $selected_id : null); start_table(TABLESTYLE2); -$th = array(_("Tax"), "", _("Shipping Tax")); +$th = array(_("Tax"), ""); table_header($th); while($item = db_fetch($items)) @@ -184,8 +181,6 @@ while($item = db_fetch($items)) { check_cells($item['tax_type_name'], 'tax_type_id' . $item['tax_type_id'], isset($item['rate']), true, false, "align='center'"); - if (isset($item['rate'])) - check_cells(null, 'tax_shipping' . $item['tax_type_id'], $item['tax_shipping']); } else { @@ -196,8 +191,6 @@ while($item = db_fetch($items)) //$_POST['_tax_type_id' . $item['tax_type_id'].'_update'] = 0; $Ajax->activate('_page_body'); } - if (check_value('tax_type_id' . $item['tax_type_id'])==1) - check_cells(null, 'tax_shipping' . $item['tax_type_id'], null); } end_row(); -- 2.30.2