From 5f0028a9831f9e64c75fd42303c661b01162d501 Mon Sep 17 00:00:00 2001 From: jekkos Date: Sat, 20 Feb 2016 21:40:06 +0100 Subject: [PATCH 1/3] Add caching hints for mod_expires (#340) --- .htaccess | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.htaccess b/.htaccess index 44ee30c48..da52382c2 100755 --- a/.htaccess +++ b/.htaccess @@ -30,3 +30,10 @@ IndexIgnore * deny from all satisfy All + + + + ExpiresActive On + ExpiresDefault "access plus 1 week" + + From 45c0163a9d4628a04f13f0028ffe82efc26ae163 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Mon, 22 Feb 2016 08:51:18 +0000 Subject: [PATCH 2/3] Fix to sales edit server error when customer is '' (#337) --- application/controllers/Sales.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 2a24ea168..3f7bd3614 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -674,7 +674,7 @@ class Sales extends Secure_area $sale_data = array( 'sale_time' => $start_date_formatter->format('Y-m-d H:i:s'), - 'customer_id' => $this->input->post('customer_id'), + 'customer_id' => $this->input->post('customer_id') != '' ? $this->input->post('customer_id') : null, 'employee_id' => $this->input->post('employee_id'), 'comment' => $this->input->post('comment'), 'invoice_number' => $this->input->post('invoice_number') From 03146d9e3b6781571ce2b67c2a82e670c2000af9 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Mon, 22 Feb 2016 17:52:29 +0000 Subject: [PATCH 3/3] Fix issue in Sales/Takings and apply same fix to other controller to avoid similar issues in the future (#337) --- application/controllers/Customers.php | 4 +- application/controllers/Employees.php | 4 +- application/controllers/Giftcards.php | 4 +- application/controllers/Item_kits.php | 3 +- application/controllers/Items.php | 32 +++++------ application/controllers/Sales.php | 77 +++++++++++++++------------ application/controllers/Suppliers.php | 4 +- application/models/Sale.php | 2 +- 8 files changed, 71 insertions(+), 59 deletions(-) diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index 201a1d3fd..c75de83e5 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -24,13 +24,15 @@ class Customers extends Person_controller */ function search() { - $search = $this->input->post('search'); + $search = $this->input->post('search') != '' ? $this->input->post('search') : null; $limit_from = $this->input->post('limit_from'); $lines_per_page = $this->Appconfig->get('lines_per_page'); + $customers = $this->Customer->search($search, $lines_per_page, $limit_from); $total_rows = $this->Customer->get_found_rows($search); $links = $this->_initialize_pagination($this->Customer,$lines_per_page, $limit_from, $total_rows); $data_rows = get_people_manage_table_data_rows($customers, $this); + echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links)); } diff --git a/application/controllers/Employees.php b/application/controllers/Employees.php index c228d5a78..1473c4588 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -24,13 +24,15 @@ class Employees extends Person_controller */ function search() { - $search = $this->input->post('search'); + $search = $this->input->post('search') != '' ? $this->input->post('search') : null; $limit_from = $this->input->post('limit_from'); $lines_per_page = $this->Appconfig->get('lines_per_page'); + $employees = $this->Employee->search($search, $limit_from, $lines_per_page); $total_rows = $this->Employee->get_found_rows($search); $links = $this->_initialize_pagination($this->Employee, $lines_per_page, $limit_from, $total_rows); $data_rows = get_people_manage_table_data_rows($employees, $this); + echo json_encode(array('rows' => $data_rows, 'pagination' => $links)); } diff --git a/application/controllers/Giftcards.php b/application/controllers/Giftcards.php index bbb0d57ba..ab5f85545 100644 --- a/application/controllers/Giftcards.php +++ b/application/controllers/Giftcards.php @@ -25,13 +25,15 @@ class Giftcards extends Secure_area implements iData_controller */ function search() { - $search = $this->input->post('search'); + $search = $this->input->post('search') != '' ? $this->input->post('search') : null; $limit_from = $this->input->post('limit_from'); $lines_per_page = $this->Appconfig->get('lines_per_page'); + $giftcards = $this->Giftcard->search($search, $lines_per_page, $limit_from); $total_rows = $this->Giftcard->get_found_rows($search); $links = $this->_initialize_pagination($this->Giftcard, $lines_per_page, $limit_from, $total_rows); $data_rows = get_giftcards_manage_table_data_rows($giftcards, $this); + echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links)); } diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index 26bc52112..06d56905d 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -51,9 +51,10 @@ class Item_kits extends Secure_area implements iData_controller */ function search() { - $search = $this->input->post('search'); + $search = $this->input->post('search') != '' ? $this->input->post('search') : null; $limit_from = $this->input->post('limit_from'); $lines_per_page = $this->Appconfig->get('lines_per_page'); + $item_kits = $this->Item_kit->search($search, $lines_per_page, $limit_from); $total_rows = $this->Item_kit->get_found_rows($search); $links = $this->_initialize_pagination($this->Item_kit, $lines_per_page, $limit_from, $total_rows, 'search'); diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 4f479c813..65264ac87 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -21,13 +21,13 @@ class Items extends Secure_area implements iData_controller $items = $this->Item->get_all($stock_location, $lines_per_page, $limit_from); $data['links'] = $this->_initialize_pagination($this->Item, $lines_per_page, $limit_from); - // assume year 2010 as starting date for OSPOS + // set 01/01/2010 as starting date for OSPOS $start_of_time = date($this->config->item('dateformat'), mktime(0,0,0,1,1,2010)); $today = date($this->config->item('dateformat')); - $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date', TRUE) : $start_of_time; + $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date') : $start_of_time; $start_date_formatter = date_create_from_format($this->config->item('dateformat'), $start_date); - $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date', TRUE) : $today; + $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date') : $today; $end_date_formatter = date_create_from_format($this->config->item('dateformat'), $end_date); $data['start_date'] = $start_date_formatter->format($this->config->item('dateformat')); @@ -53,19 +53,18 @@ class Items extends Secure_area implements iData_controller */ function search() { - $search = $this->input->post('search'); - $this->item_lib->set_item_location($this->input->post('stock_location')); - $data['search_section_state'] = $this->input->post('search_section_state'); + $search = $this->input->post('search') != '' ? $this->input->post('search') : null; $limit_from = $this->input->post('limit_from'); $lines_per_page = $this->Appconfig->get('lines_per_page'); + $this->item_lib->set_item_location($this->input->post('stock_location')); - // assume year 2010 as starting date for OSPOS + // set 01/01/2010 as starting date for OSPOS $start_of_time = date($this->config->item('dateformat'), mktime(0,0,0,1,1,2010)); $today = date($this->config->item('dateformat')); - $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date', TRUE) : $start_of_time; + $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date') : $start_of_time; $start_date_formatter = date_create_from_format($this->config->item('dateformat'), $start_date); - $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date', TRUE) : $today; + $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date') : $today; $end_date_formatter = date_create_from_format($this->config->item('dateformat'), $end_date); $filters = array('start_date' => $start_date_formatter->format('Y-m-d'), @@ -83,6 +82,7 @@ class Items extends Secure_area implements iData_controller $total_rows = $this->Item->get_found_rows($search, $filters); $links = $this->_initialize_pagination($this->Item, $lines_per_page, $limit_from, $total_rows, 'search'); $data_rows = get_items_manage_table_data_rows($items, $this); + // do not move this line to be after the json_encode otherwise the searhc function won't work!! $this->_remove_duplicate_cookies(); @@ -470,13 +470,12 @@ class Items extends Secure_area implements iData_controller $success &= $this->Inventory->insert($inv_data); } - } - - if ($success && $upload_success) + } + if ($success && $upload_success) { $success_message = $this->lang->line('items_successful_' . ($new_item ? 'adding' : 'updating')) .' '. $item_data['name']; - echo json_encode(array('success'=>true,'message'=>$success_message,'item_id'=>$item_id)); + echo json_encode(array('success'=>true, 'message'=>$success_message, 'item_id'=>$item_id)); } else { @@ -484,16 +483,13 @@ class Items extends Secure_area implements iData_controller $this->lang->line('items_error_adding_updating') .' '. $item_data['name'] : $this->upload->display_errors(); - echo json_encode(array('success'=>false, - 'message'=>$error_message,'item_id'=>$item_id)); + echo json_encode(array('success'=>false, 'message'=>$error_message, 'item_id'=>$item_id)); } } else//failure { - echo json_encode(array('success'=>false, - 'message'=>$this->lang->line('items_error_adding_updating').' ' - .$item_data['name'],'item_id'=>-1)); + echo json_encode(array('success'=>false, 'message'=>$this->lang->line('items_error_adding_updating').' '.$item_data['name'], 'item_id'=>-1)); } } diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 3f7bd3614..eb100ac3a 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -27,34 +27,34 @@ class Sales extends Secure_area { $this->Sale->create_sales_items_temp_table(); - $data['controller_name'] = strtolower($this->uri->segment(1)); - $data['only_invoices'] = array($this->lang->line('sales_no_filter'), $this->lang->line('sales_invoice')); - $data['search_section_state'] = $this->input->post('search_section_state'); + $data['controller_name'] = $this->get_controller_name(); $lines_per_page = $this->Appconfig->get('lines_per_page'); $today = date($this->config->item('dateformat')); - $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date', TRUE) : $today; + + $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date') : $today; $start_date_formatter = date_create_from_format($this->config->item('dateformat'), $start_date); - $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date', TRUE) : $today; + $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date') : $today; $end_date_formatter = date_create_from_format($this->config->item('dateformat'), $end_date); - $sale_type = 'all'; + $sale_type = 'all'; $location_id = 'all'; $is_valid_receipt = FALSE; $search = null; $filters = array('sale_type' => $sale_type, - 'location_id' => $location_id, - 'start_date' => $start_date_formatter->format('Y-m-d'), - 'end_date' => $end_date_formatter->format('Y-m-d'), - 'only_invoices' => $only_invoices, - 'only_cash' => $only_cash, - 'is_valid_receipt' => $is_valid_receipt); + 'location_id' => $location_id, + 'start_date' => $start_date_formatter->format('Y-m-d'), + 'end_date' => $end_date_formatter->format('Y-m-d'), + 'only_invoices' => $only_invoices, + 'only_cash' => $only_cash, + 'is_valid_receipt' => $is_valid_receipt); $sales = $this->Sale->search($search, $filters, $lines_per_page, $limit_from)->result_array(); $payments = $this->Sale->get_payments_summary($search, $filters); $total_rows = $this->Sale->get_found_rows($search, $filters); $data['only_invoices'] = $only_invoices; + $data['only_cash '] = $only_cash; $data['start_date'] = $start_date_formatter->format($this->config->item('dateformat')); $data['end_date'] = $end_date_formatter->format($this->config->item('dateformat')); $data['links'] = $this->_initialize_pagination($this->Sale, $lines_per_page, $limit_from, $total_rows, 'manage', $only_invoices); @@ -87,27 +87,31 @@ class Sales extends Secure_area { return 400; } - + + /* + Returns Sales table data rows. This will be called with AJAX. + */ function search() { $this->Sale->create_sales_items_temp_table(); - $only_invoices = $this->input->post('only_invoices', TRUE); - $only_cash = $this->input->post('only_cash', TRUE); + $search = $this->input->post('search') != '' ? $this->input->post('search') : null; + $limit_from = $this->input->post('limit_from'); $lines_per_page = $this->Appconfig->get('lines_per_page'); - $limit_from = $this->input->post('limit_from', TRUE); - $search = $this->input->post('search', TRUE); $today = date($this->config->item('dateformat')); - $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date', TRUE) : $today; + + $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date') : $today; $start_date_formatter = date_create_from_format($this->config->item('dateformat'), $start_date); - $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date', TRUE) : $today; + $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date') : $today; $end_date_formatter = date_create_from_format($this->config->item('dateformat'), $end_date); $is_valid_receipt = isset($search) ? $this->sale_lib->is_valid_receipt($search) : FALSE; $sale_type = 'all'; $location_id = 'all'; + $only_invoices = $this->input->post('only_invoices') != null; + $only_cash = $this->input->post('only_cash') != null; $filters = array('sale_type' => $sale_type, 'location_id' => $location_id, @@ -123,6 +127,8 @@ class Sales extends Secure_area $links = $this->_initialize_pagination($this->Sale, $lines_per_page, $limit_from, $total_rows, 'search', $only_invoices); $sale_rows = get_sales_manage_table_data_rows($sales, $this); $payment_summary = get_sales_manage_payments_summary($payments, $sales, $this); + + // do not move this line to be after the json_encode otherwise the searhc function won't work!! $this->_remove_duplicate_cookies(); echo json_encode(array('total_rows' => $total_rows, 'rows' => $sale_rows, 'pagination' => $links, 'payment_summary' => $payment_summary)); @@ -151,8 +157,8 @@ class Sales extends Secure_area function suggest() { - $search = $this->input->post('q', TRUE); - $limit = $this->input->post('limit', TRUE); + $search = $this->input->post('q'); + $limit = $this->input->post('limit'); $suggestions = $this->Sale->get_search_suggestions($search, $limit); echo implode("\n",$suggestions); @@ -303,8 +309,8 @@ class Sales extends Secure_area $this->form_validation->set_rules('quantity', 'lang:items_quantity', 'required|numeric'); $this->form_validation->set_rules('discount', 'lang:items_discount', 'required|numeric'); - $description = $this->input->post('description'); - $serialnumber = $this->input->post('serialnumber'); + $description = $this->input->post('description'); + $serialnumber = $this->input->post('serialnumber'); $price = $this->input->post('price'); $quantity = $this->input->post('quantity'); $discount = $this->input->post('discount'); @@ -367,7 +373,7 @@ class Sales extends Secure_area $this->config->item('phone'), $this->config->item('account_number') )); - $cust_info = ''; + $cust_info = ''; if($customer_id!=-1) { $cust_info = $this->Customer->get_info($customer_id); @@ -670,7 +676,7 @@ class Sales extends Secure_area function save($sale_id) { - $start_date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $this->input->post('date', TRUE)); + $start_date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $this->input->post('date')); $sale_data = array( 'sale_time' => $start_date_formatter->format('Y-m-d H:i:s'), @@ -721,11 +727,11 @@ class Sales extends Secure_area { $person_info = $this->Employee->get_logged_in_employee_info(); $data['cart'] = $this->sale_lib->get_cart(); - $data['modes'] = array('sale'=>$this->lang->line('sales_sale'),'return'=>$this->lang->line('sales_return')); - $data['mode'] = $this->sale_lib->get_mode(); + $data['modes'] = array('sale'=>$this->lang->line('sales_sale'),'return'=>$this->lang->line('sales_return')); + $data['mode'] = $this->sale_lib->get_mode(); - $data['stock_locations'] = $this->Stock_location->get_allowed_locations('sales'); - $data['stock_location'] = $this->sale_lib->get_sale_location(); + $data['stock_locations'] = $this->Stock_location->get_allowed_locations('sales'); + $data['stock_location'] = $this->sale_lib->get_sale_location(); $data['subtotal'] = $this->sale_lib->get_subtotal(TRUE); $data['tax_exclusive_subtotal'] = $this->sale_lib->get_subtotal(TRUE, TRUE); @@ -764,11 +770,11 @@ class Sales extends Secure_area $this->_remove_duplicate_cookies(); } - function cancel_sale() - { - $this->sale_lib->clear_all(); - $this->_reload(); - } + function cancel_sale() + { + $this->sale_lib->clear_all(); + $this->_reload(); + } function suspend() { @@ -835,7 +841,7 @@ class Sales extends Secure_area $this->sale_lib->clear_all(); $this->sale_lib->copy_entire_suspended_sale($sale_id); $this->Sale_suspended->delete($sale_id); - $this->_reload(); + $this->_reload(); } function check_invoice_number() @@ -843,6 +849,7 @@ class Sales extends Secure_area $sale_id=$this->input->post('sale_id'); $invoice_number=$this->input->post('invoice_number'); $exists=!empty($invoice_number) && $this->Sale->invoice_number_exists($invoice_number,$sale_id); + echo json_encode(array('success'=>!$exists, 'message'=>$this->lang->line('sales_invoice_number_duplicate'))); } } diff --git a/application/controllers/Suppliers.php b/application/controllers/Suppliers.php index 3f77ad3bc..7be159a62 100644 --- a/application/controllers/Suppliers.php +++ b/application/controllers/Suppliers.php @@ -25,13 +25,15 @@ class Suppliers extends Person_controller */ function search() { - $search = $this->input->post('search'); + $search = $this->input->post('search') != '' ? $this->input->post('search') : null; $limit_from = $this->input->post('limit_from'); $lines_per_page = $this->Appconfig->get('lines_per_page'); + $suppliers = $this->Supplier->search($search, $lines_per_page, $limit_from); $total_rows = $this->Supplier->get_found_rows($search); $links = $this->_initialize_pagination($this->Supplier, $lines_per_page, $limit_from, $total_rows); $data_rows = get_supplier_manage_table_data_rows($suppliers, $this); + echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links)); } diff --git a/application/models/Sale.php b/application/models/Sale.php index c79bb4a65..0a30adc3e 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -45,7 +45,7 @@ class Sale extends CI_Model } else { - if ($filters['is_valid_receipt']) + if ($filters['is_valid_receipt'] != FALSE) { $pieces = explode(' ', $search); $this->db->where('sales_items_temp.sale_id', $pieces[1]);