From 4bab3fc4e3553ffbfacd0ebd5b48983b678abcbf Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sat, 14 Apr 2018 14:40:02 +0100 Subject: [PATCH] Code style adjustments --- application/controllers/Config.php | 2 +- application/controllers/Customers.php | 2 +- .../controllers/Expenses_categories.php | 2 +- application/controllers/Item_kits.php | 2 +- application/controllers/Items.php | 5 +++-- application/controllers/Receivings.php | 2 +- application/controllers/Reports.php | 2 +- application/controllers/Sales.php | 5 +++-- application/controllers/Taxes.php | 4 ++-- application/helpers/locale_helper.php | 2 +- application/helpers/tabular_helper.php | 4 ++-- application/hooks/load_config.php | 2 +- application/libraries/Barcode_lib.php | 11 +++++----- application/libraries/Sale_lib.php | 3 ++- application/libraries/Tax_lib.php | 2 +- application/libraries/Token_lib.php | 20 +++++++++---------- application/libraries/tokens/Token.php | 2 +- .../libraries/tokens/Token_customer.php | 2 +- application/models/Customer.php | 2 +- application/models/Employee.php | 4 ++-- application/models/Expense.php | 2 +- application/models/Expense_category.php | 2 +- application/models/Giftcard.php | 2 +- application/models/Inventory.php | 2 +- application/models/Item.php | 2 +- application/models/Item_kit.php | 2 +- application/models/Item_kit_items.php | 6 ++++-- application/models/Sale.php | 7 ++++--- application/models/Supplier.php | 2 +- application/models/Tax.php | 8 ++++---- application/models/enums/Rounding_mode.php | 6 +++++- 31 files changed, 66 insertions(+), 55 deletions(-) diff --git a/application/controllers/Config.php b/application/controllers/Config.php index 56dc59fea..83e2aa3b7 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -706,7 +706,7 @@ class Config extends Secure_Controller if($success && $delete_rejected) { $message = $this->lang->line('config_tax_category_used'); - $success = false; + $success = FALSE; } else { diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index d62904a99..76fb4c66f 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -126,7 +126,7 @@ class Customers extends Persons $data['packages'] = $packages; $data['selected_package'] = $info->package_id; - if ($customer_sales_tax_support == '1') + if($customer_sales_tax_support == '1') { $data['customer_sales_tax_enabled'] = TRUE; } diff --git a/application/controllers/Expenses_categories.php b/application/controllers/Expenses_categories.php index 24ef78910..e7af65260 100644 --- a/application/controllers/Expenses_categories.php +++ b/application/controllers/Expenses_categories.php @@ -84,7 +84,7 @@ class Expenses_categories extends Secure_Controller { $expense_category_to_delete = $this->input->post('ids'); - if ($this->Expense_category->delete_list($expense_category_to_delete)) + if($this->Expense_category->delete_list($expense_category_to_delete)) { echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('expenses_categories_successful_deleted') . ' ' . count($expense_category_to_delete) . ' ' . $this->lang->line('expenses_categories_one_or_multiple'))); } diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index cafa3bb9f..b2d3d7072 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -131,7 +131,7 @@ class Item_kits extends Secure_Controller $success = TRUE; $new_item = FALSE; //New item kit - if ($item_kit_id == -1) + if($item_kit_id == -1) { $item_kit_id = $item_kit_data['item_kit_id']; $new_item = TRUE; diff --git a/application/controllers/Items.php b/application/controllers/Items.php index fc40a9e75..f6f7991bc 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -497,7 +497,7 @@ class Items extends Secure_Controller */ public function check_kit_exists() { - if ($this->input->post('item_number') === -1) + if($this->input->post('item_number') === -1) { $exists = $this->Item_kit->item_kit_exists_for_name($this->input->post('name')); } @@ -702,7 +702,8 @@ class Items extends Secure_Controller needs further discussion */ $pic_file = $data[24]; - /*if(strcmp('.htaccess', $pic_file)==0) { + /*if(strcmp('.htaccess', $pic_file)==0) + { $pic_file=''; }*/ $item_data['pic_filename'] = $pic_file; diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index 2c2d6d0b7..5e4f0a1c2 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -148,7 +148,7 @@ class Receivings extends Secure_Controller } $data['employees'] = array(); - foreach ($this->Employee->get_all()->result() as $employee) + foreach($this->Employee->get_all()->result() as $employee) { $data['employees'][$employee->person_id] = $this->xss_clean($employee->first_name . ' '. $employee->last_name); } diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 324716a65..42e941c81 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -1330,7 +1330,7 @@ class Reports extends Secure_Controller foreach($report_data['details'][$key] as $drow) { $quantity_purchased = $drow['receiving_quantity'] > 1 ? to_quantity_decimals($drow['quantity_purchased']) . ' x ' . to_quantity_decimals($drow['receiving_quantity']) : to_quantity_decimals($drow['quantity_purchased']); - if ($show_locations) + if($show_locations) { $quantity_purchased .= ' [' . $this->Stock_location->get_location_name($drow['item_location']) . ']'; } diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 3344587bd..01388f403 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -576,7 +576,8 @@ class Sales extends Secure_Controller $candidate_invoice_number = $invoice_number; if($candidate_invoice_number != NULL && strlen($candidate_invoice_number) > 3) { - if (strpos($candidate_invoice_number, '{') == false) { + if(strpos($candidate_invoice_number, '{') == FALSE) + { $override_invoice_number = $candidate_invoice_number; } } @@ -605,7 +606,7 @@ class Sales extends Secure_Controller $invoice_format = $this->config->item('sales_invoice_format'); } - if ($override_invoice_number == NULL) + if($override_invoice_number == NULL) { $invoice_number = $this->token_lib->render($invoice_format); } diff --git a/application/controllers/Taxes.php b/application/controllers/Taxes.php index 89e712aaa..f02734674 100644 --- a/application/controllers/Taxes.php +++ b/application/controllers/Taxes.php @@ -83,7 +83,7 @@ class Taxes extends Secure_Controller $data['rounding_options'] = Rounding_mode::get_rounding_options(); $data['html_rounding_options'] = $this->get_html_rounding_options(); - if ($tax_code == -1) + if($tax_code == -1) { $data['tax_code'] = ''; $data['tax_code_name'] = ''; @@ -170,7 +170,7 @@ class Taxes extends Secure_Controller } } - if (!empty($tax_code_rate_exceptions)) + if(!empty($tax_code_rate_exceptions)) { $success = $this->Tax->save_tax_rate_exceptions($tax_code_rate_exceptions, $entered_tax_code); } diff --git a/application/helpers/locale_helper.php b/application/helpers/locale_helper.php index d85351808..fc392bee4 100644 --- a/application/helpers/locale_helper.php +++ b/application/helpers/locale_helper.php @@ -312,7 +312,7 @@ function parse_decimals($number) $fmt->setAttribute(\NumberFormatter::FRACTION_DIGITS, $config->item('currency_decimals')); - if (empty($config->item('thousands_separator'))) + if(empty($config->item('thousands_separator'))) { $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); } diff --git a/application/helpers/tabular_helper.php b/application/helpers/tabular_helper.php index 599ae3716..7943dd83d 100644 --- a/application/helpers/tabular_helper.php +++ b/application/helpers/tabular_helper.php @@ -354,7 +354,7 @@ function get_item_data_row($item) $controller_name = strtolower(get_class($CI)); $image = NULL; - if ($item->pic_filename != '') + if($item->pic_filename != '') { $ext = pathinfo($item->pic_filename, PATHINFO_EXTENSION); if($ext == '') @@ -368,7 +368,7 @@ function get_item_data_row($item) $images = glob('./uploads/item_pics/' . $item->pic_filename); } - if (sizeof($images) > 0) + if(sizeof($images) > 0) { $image .= ''; } diff --git a/application/hooks/load_config.php b/application/hooks/load_config.php index d0585dbac..972c42625 100644 --- a/application/hooks/load_config.php +++ b/application/hooks/load_config.php @@ -16,7 +16,7 @@ function load_config() if(!empty(current_language())) { // fallback to English if language folder does not exist - if (!file_exists('../application/language/' . current_language_code())) + if(!file_exists('../application/language/' . current_language_code())) { $CI->config->set_item('language', 'english'); $CI->config->set_item('language_code', 'en-US'); diff --git a/application/libraries/Barcode_lib.php b/application/libraries/Barcode_lib.php index 7fc38ac17..e8ae9dd59 100644 --- a/application/libraries/Barcode_lib.php +++ b/application/libraries/Barcode_lib.php @@ -79,6 +79,7 @@ class Barcode_lib { $barcode_type = $this->CI->config->item('barcode_type'); $barcode_instance = $this->get_barcode_instance($barcode_type); + return $barcode_instance->validate($barcode); } @@ -88,7 +89,7 @@ class Barcode_lib $is_valid = empty($item['item_number']) && $barcode_config['barcode_generate_if_empty'] || $barcode_instance->validate($item['item_number']); // if barcode validation does not succeed, - if (!$is_valid) + if(!$is_valid) { $barcode_instance = Barcode_lib::get_barcode_instance(); } @@ -125,13 +126,13 @@ class Barcode_lib { $seed = $barcode_config['barcode_content'] !== "id" && !empty($item['item_number']) ? $item['item_number'] : $item['item_id']; - if( $barcode_config['barcode_content'] !== "id" && !empty($item['item_number'])) + if($barcode_config['barcode_content'] !== "id" && !empty($item['item_number'])) { $seed = $item['item_number']; } else { - if ($barcode_config['barcode_generate_if_empty']) + if($barcode_config['barcode_generate_if_empty']) { // generate barcode with the correct instance $seed = $barcode_instance->generate($seed); @@ -234,9 +235,9 @@ class Barcode_lib { $array = array(); - if (($handle = opendir($folder)) !== FALSE) + if(($handle = opendir($folder)) !== FALSE) { - while (($file = readdir($handle)) !== FALSE) + while(($file = readdir($handle)) !== FALSE) { if(substr($file, -4, 4) === '.ttf') { diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index e7728567c..1d4a919a7 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -999,7 +999,8 @@ class Sale_lib $this->CI->session->set_userdata('sale_id', $sale_id); } - public function get_sale_id() { + public function get_sale_id() + { return $this->CI->session->userdata('sale_id'); } diff --git a/application/libraries/Tax_lib.php b/application/libraries/Tax_lib.php index b7fc9b5ab..7713f62e4 100644 --- a/application/libraries/Tax_lib.php +++ b/application/libraries/Tax_lib.php @@ -136,7 +136,7 @@ class Tax_lib $rounding_code = $sales_tax['rounding_code']; $rounded_sale_tax_amount = $sale_tax_amount; - if ($rounding_code == Rounding_mode::HALF_UP) + if($rounding_code == Rounding_mode::HALF_UP) { $rounded_sale_tax_amount = round($sale_tax_amount, $decimals, PHP_ROUND_HALF_UP); } diff --git a/application/libraries/Token_lib.php b/application/libraries/Token_lib.php index 5e0a5a88d..b16e92398 100644 --- a/application/libraries/Token_lib.php +++ b/application/libraries/Token_lib.php @@ -22,7 +22,6 @@ class Token_lib */ public function render($tokened_text, $tokens = array()) { - // Apply the transformation for the "%" tokens if any are used if(strpos($tokened_text, '%') !== FALSE) { @@ -58,20 +57,21 @@ class Token_lib { // Matches tokens with the following pattern: [$token:$length] preg_match_all('/ - \{ # [ - pattern start - ([^\s\{\}:]+) # match $token not containing whitespace : { or } - (?: - : # : - separator - ([^\s\{\}:]+) # match $length not containing whitespace : { or } - )? - \} # ] - pattern end - /x', $text, $matches); + \{ # [ - pattern start + ([^\s\{\}:]+) # match $token not containing whitespace : { or } + (?: + : # : - separator + ([^\s\{\}:]+) # match $length not containing whitespace : { or } + )? + \} # ] - pattern end + /x', $text, $matches); $tokens = $matches[1]; $lengths = $matches[2]; $token_tree = array(); - for($i = 0; $i < count($tokens); $i++) { + for($i = 0; $i < count($tokens); $i++) + { $token_tree[$tokens[$i]][$lengths[$i]] = $matches[0][$i]; } diff --git a/application/libraries/tokens/Token.php b/application/libraries/tokens/Token.php index 2d4874409..e4c652c07 100644 --- a/application/libraries/tokens/Token.php +++ b/application/libraries/tokens/Token.php @@ -43,7 +43,7 @@ abstract class Token function replace($text) { - if (strstr($text, $this->token_id())) + if(strstr($text, $this->token_id())) { return str_replace($this->token_id(), $this->get_value(), $text); } diff --git a/application/libraries/tokens/Token_customer.php b/application/libraries/tokens/Token_customer.php index 615e72d26..2f8d69e4f 100644 --- a/application/libraries/tokens/Token_customer.php +++ b/application/libraries/tokens/Token_customer.php @@ -25,7 +25,7 @@ class Token_customer extends Token { // substitute customer info $customer_id = $this->CI->sale_lib->get_customer(); - if ($customer_id != -1 && empty($this->customer_info)) + if($customer_id != -1 && empty($this->customer_info)) { $customer_info = $this->CI->Customer->get_info($customer_id); if($customer_info != '') diff --git a/application/models/Customer.php b/application/models/Customer.php index 48cf9935e..7a6ad488c 100644 --- a/application/models/Customer.php +++ b/application/models/Customer.php @@ -352,7 +352,7 @@ class Customer extends Person // get_found_rows case if($count_only == TRUE) { - return $this->db->get()->row_array()['count']; + return $this->db->get()->row()->count; } $this->db->order_by($sort, $order); diff --git a/application/models/Employee.php b/application/models/Employee.php index 688621d58..0387d951f 100644 --- a/application/models/Employee.php +++ b/application/models/Employee.php @@ -288,7 +288,7 @@ class Employee extends Person // get_found_rows case if($count_only == TRUE) { - return $this->db->get()->row_array()['count']; + return $this->db->get()->row()->count; } $this->db->order_by($sort, $order); @@ -422,7 +422,7 @@ class Employee extends Person $row = $this->db->get()->row(); // If no grants are assigned yet then set the default to 'home' - if ($row == NULL) + if($row == NULL) { return 'home'; } diff --git a/application/models/Expense.php b/application/models/Expense.php index a0b8e28dc..a58595594 100644 --- a/application/models/Expense.php +++ b/application/models/Expense.php @@ -139,7 +139,7 @@ class Expense extends CI_Model // get_found_rows case if($count_only == TRUE) { - return $this->db->get()->row_array()['count']; + return $this->db->get()->row()->count; } $this->db->group_by('expense_id'); diff --git a/application/models/Expense_category.php b/application/models/Expense_category.php index a00f9e668..2aaa76853 100644 --- a/application/models/Expense_category.php +++ b/application/models/Expense_category.php @@ -151,7 +151,7 @@ class Expense_category extends CI_Model // get_found_rows case if($count_only == TRUE) { - return $this->db->get()->row_array()['count']; + return $this->db->get()->row()->count; } $this->db->order_by($sort, $order); diff --git a/application/models/Giftcard.php b/application/models/Giftcard.php index c379f3267..416f24ac4 100644 --- a/application/models/Giftcard.php +++ b/application/models/Giftcard.php @@ -231,7 +231,7 @@ class Giftcard extends CI_Model // get_found_rows case if($count_only == TRUE) { - return $this->db->get()->row_array()['count']; + return $this->db->get()->row()->count; } $this->db->order_by($sort, $order); diff --git a/application/models/Inventory.php b/application/models/Inventory.php index 209fc6dec..78904d7d3 100644 --- a/application/models/Inventory.php +++ b/application/models/Inventory.php @@ -29,7 +29,7 @@ class Inventory extends CI_Model $inventory_sums = $this->Inventory->get_inventory_sum($item_id); foreach($inventory_sums as $inventory_sum) { - if ($inventory_sum['sum'] > 0) + if($inventory_sum['sum'] > 0) { return $this->Inventory->insert(array( 'trans_inventory' => -1 * $inventory_sum['sum'], diff --git a/application/models/Item.php b/application/models/Item.php index de83737eb..9eb0873f8 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -229,7 +229,7 @@ class Item extends CI_Model // get_found_rows case if($count_only == TRUE) { - return $this->db->get()->row_array()['count']; + return $this->db->get()->row()->count; } // avoid duplicated entries with same name because of inventory reporting multiple changes on the same item in the same date range diff --git a/application/models/Item_kit.php b/application/models/Item_kit.php index 560f310f3..6de74b7c4 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -231,7 +231,7 @@ class Item_kit extends CI_Model // get_found_rows case if($count_only == TRUE) { - return $this->db->get()->row_array()['count']; + return $this->db->get()->row()->count; } $this->db->order_by($sort, $order); diff --git a/application/models/Item_kit_items.php b/application/models/Item_kit_items.php index 1739265b4..a683901c4 100644 --- a/application/models/Item_kit_items.php +++ b/application/models/Item_kit_items.php @@ -47,8 +47,10 @@ class Item_kit_items extends CI_Model $this->delete($item_kit_id); - if ($item_kit_items_data != NULL) { - foreach ($item_kit_items_data as $row) { + if($item_kit_items_data != NULL) + { + foreach($item_kit_items_data as $row) + { $row['item_kit_id'] = $item_kit_id; $success &= $this->db->insert('item_kit_items', $row); } diff --git a/application/models/Sale.php b/application/models/Sale.php index 1117b4ac2..ad02c2b83 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -279,7 +279,7 @@ class Sale extends CI_Model // get_found_rows case if($count_only == TRUE) { - return $this->db->get()->row_array()['count']; + return $this->db->get()->row()->count; } $this->db->group_by('sales.sale_id'); @@ -301,7 +301,7 @@ class Sale extends CI_Model public function get_payments_summary($search, $filters) { // get payment summary - $this->db->select('payment_type, count(payment_amount) AS count, SUM(payment_amount) AS payment_amount'); + $this->db->select('payment_type, COUNT(payment_amount) AS count, SUM(payment_amount) AS payment_amount'); $this->db->from('sales AS sales'); $this->db->join('sales_payments', 'sales_payments.sale_id = sales.sale_id'); $this->db->join('people AS customer_p', 'sales.customer_id = customer_p.person_id', 'LEFT'); @@ -874,7 +874,8 @@ class Sale extends CI_Model { $cur_item_info = $this->Item->get_info($item['item_id']); - if($cur_item_info->stock_type == HAS_STOCK) { + if($cur_item_info->stock_type == HAS_STOCK) + { // create query to update inventory tracking $inv_data = array( 'trans_date' => date('Y-m-d H:i:s'), diff --git a/application/models/Supplier.php b/application/models/Supplier.php index 8476cb9c4..ea08fa887 100644 --- a/application/models/Supplier.php +++ b/application/models/Supplier.php @@ -261,7 +261,7 @@ class Supplier extends Person // get_found_rows case if($count_only == TRUE) { - return $this->db->get()->row_array()['count']; + return $this->db->get()->row()->count; } $this->db->order_by($sort, $order); diff --git a/application/models/Tax.php b/application/models/Tax.php index 9c37bb4af..ffc79a2ac 100644 --- a/application/models/Tax.php +++ b/application/models/Tax.php @@ -326,7 +326,7 @@ class Tax extends CI_Model // get_found_rows case if($count_only == TRUE) { - return $this->db->get()->row_array()['count']; + return $this->db->get()->row()->count; } $this->db->order_by($sort, $order); @@ -341,7 +341,7 @@ class Tax extends CI_Model public function get_tax_code_type_name($tax_code_type) { - if ($tax_code_type == '0') + if($tax_code_type == '0') { return $this->lang->line('taxes_sales_tax'); } @@ -356,7 +356,7 @@ class Tax extends CI_Model $suggestions = array(); $this->db->from('tax_codes'); - if (!empty($search)) + if(!empty($search)) { $this->db->like('tax_code', $search); $this->db->or_like('tax_code_name', $search); @@ -383,7 +383,7 @@ class Tax extends CI_Model $this->db->from('tax_categories'); $this->db->where('tax_category_id !=', 1); - if (!empty($search)) + if(!empty($search)) { $this->db->like('tax_category', '%'.$search.'%'); } diff --git a/application/models/enums/Rounding_mode.php b/application/models/enums/Rounding_mode.php index 39a2b9d93..51ca6e13e 100644 --- a/application/models/enums/Rounding_mode.php +++ b/application/models/enums/Rounding_mode.php @@ -16,10 +16,12 @@ class Rounding_mode $CI->load->helper('language'); $class = new ReflectionClass(__CLASS__); $result = array(); + foreach($class->getConstants() as $key => $value) { $result[$value] = lang(strtolower('ENUM_'. $key)); } + return $result; } @@ -41,10 +43,12 @@ class Rounding_mode $CI =& get_instance(); $CI->load->helper('language'); $x = ''; - foreach (Rounding_mode::get_rounding_options() as $option => $label) + + foreach(Rounding_mode::get_rounding_options() as $option => $label) { $x .= ""; } + return $x; }