Skip to content

Commit

Permalink
SordersController::index, refactor search management
Browse files Browse the repository at this point in the history
closes #255
  • Loading branch information
steveblamey committed Jan 6, 2022
1 parent 7587913 commit 14f0827
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,46 @@ 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(),
$this->_templateobject->partDespatchStatus()
];
}

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));
Expand Down

0 comments on commit 14f0827

Please sign in to comment.