From 14f08278726a85310a062a7bee80d48f1efdd337 Mon Sep 17 00:00:00 2001 From: Steve Blamey Date: Thu, 6 Jan 2022 14:03:54 +0000 Subject: [PATCH] SordersController::index, refactor search management closes #255 --- .../controllers/SlcustomersController.php | 3 +- .../controllers/SordersController.php | 45 ++++++++++--------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/modules/public_pages/erp/ledger/sales_ledger/controllers/SlcustomersController.php b/modules/public_pages/erp/ledger/sales_ledger/controllers/SlcustomersController.php index 70c579f8..6c0e2f6c 100755 --- a/modules/public_pages/erp/ledger/sales_ledger/controllers/SlcustomersController.php +++ b/modules/public_pages/erp/ledger/sales_ledger/controllers/SlcustomersController.php @@ -458,7 +458,8 @@ public function view() 'module' => 'sales_order', 'controller' => 'sorders', 'action' => 'index', - 'slmaster_id' => $customer->id + 'slmaster_id' => $customer->id, + 'status' => 'all' ), 'new' => array( 'module' => 'sales_order', diff --git a/modules/public_pages/erp/order/sales_order/controllers/SordersController.php b/modules/public_pages/erp/order/sales_order/controllers/SordersController.php index d8193065..944e1e90 100755 --- a/modules/public_pages/erp/order/sales_order/controllers/SordersController.php +++ b/modules/public_pages/erp/order/sales_order/controllers/SordersController.php @@ -26,22 +26,35 @@ public function __construct($module = null, $action = null) $this->uses($this->_templateobject); } + /** + * Sales Orders - index view + * + * @return void + */ public function index() { $this->view->set('clickaction', 'view'); - $s_data = array(); - // so set context from calling module - if (isset($this->_data['slmaster_id'])) { - $s_data['slmaster_id'] = $this->_data['slmaster_id']; + // This view is called from several places and we need to manage the applied search. + // If the user has opted to clear the search, the default search is applied. + if (!isset($this->_data['Search']['clear'])) { + // Get the params from the current, active search + $s_data = $_SESSION['searches']['sordersSearch']["default{$this->_data['search_id']}"]; + + // Set the customer ID if present in the request params + if (isset($this->_data['slmaster_id'])) { + $s_data['slmaster_id'] = $this->_data['slmaster_id']; + } + + // Search on all order statuses if 'status' is in the request params + if (isset($this->_data['status']) && $this->_data['status'] == 'all') { + $s_data['status'] = array_keys($this->_templateobject->getEnumOptions('status')); + } } - if (isset($this->_data['status']) && $this->_data['status'] !== 'all') { - $s_data['status'] = $this->_data['status']; - } elseif (isset($this->_data['status']) && $this->_data['status'] == 'all') { - $s_data['status'] = array_keys($this->_templateobject->getEnumOptions('status')); - } else { + // If there is no status filter, set the default. + if (!isset($s_data['status'])) { $s_data['status'] = [ $this->_templateobject->newStatus(), $this->_templateobject->openStatus(), @@ -49,18 +62,10 @@ public function index() ]; } - if (isset($this->_data['due_date'])) { - $s_data['due_date']['from'] = un_fix_date($this->_data['due_date']); - $s_data['due_date']['to'] = un_fix_date($this->_data['due_date']); - } - - - if (isset($this->_data['slmaster_id']) && isset($this->_data['status']) && $this->_data['status'] == 'all') { - $this->setSearch('sordersSearch', 'useDefault', $s_data, null ); - } else { - $this->setSearch('sordersSearch', 'useDefault', $s_data, null, true); - } + // Apply the search + $this->setSearch('sordersSearch', 'useDefault', $s_data, null ); + // Load the collection parent::index(new SOrderCollection($this->_templateobject)); $today = fix_date(date(DATE_FORMAT));