Ejemplo n.º 1
0
 public function detail()
 {
     $errors = array();
     $s_data = $this->setSearch();
     $constrain = FALSE;
     $fields = array('slmaster_id', 'product_group', 'cs_failurecode_id', 'start', 'end');
     // if failure code is 'any' remove it from the search, we've got other criteria to search by...
     if (isset($this->_data['cs_failurecode_id']) && strtolower($this->_data['cs_failurecode_id']) === 'any') {
         // don't let the standard search do anything with the cs_failurecode_id field
         unset($s_data['cs_failurecode_id']);
         $constrain = TRUE;
         // constrain where failure code has not been set...
         $cc1 = new ConstraintChain();
         $cc1->add(new Constraint('cs_failurecode_id', 'IS', 'NULL'));
         // and another constraint chain for the failed order
         $cc2 = new ConstraintChain();
         $cc2->add(new Constraint('despatch_date', '>', '(due_despatch_date)'));
         $cc2->add(new Constraint('order_qty', '>', '(despatch_qty)'), 'OR');
     }
     $customerservice = new CustomerServiceCollection($this->_templateobject);
     if (!isset($this->_data['orderby']) && !isset($this->_data['page']) && !($this->isPrintDialog() || $this->isPrinting())) {
         $sh = $customerservice->setSearch($s_data, false);
         $sh->setOrderby(array('product_group', 'customer', 'order_number', 'due_despatch_date'), array('ASC', 'ASC', 'DESC', 'DESC'));
     } else {
         // $sh = $customerservice->setSearch($s_data, TRUE);
         // echo '$s_data<pre>'.print_r($s_data, true).'</pre><br>';
         $sh = new SearchHandler($customerservice, TRUE);
     }
     $this->search = customerServicesSearch::useDefault($s_data, $errors, $customerservice);
     if (count($errors) > 0) {
         $flash = Flash::Instance();
         $flash->addErrors($errors);
         $this->search->clear();
     }
     if (isset($this->search) && !isset($this->_data['ajax_print']) && !isset($this->_data['orderby']) && !isset($this->_data['page'])) {
         // cache the search string
         $search_string_array = array('fop' => $this->search->toString('fop'), 'html' => $this->search->toString('html'));
         $_SESSION['search_strings'][EGS_USERNAME][$sh->search_id] = $search_string_array;
     }
     if ($constrain === TRUE) {
         // add the two constraint chains seperately
         $sh->addConstraintChain($cc1);
         $sh->addConstraintChain($cc2);
     }
     $sh->extractOrdering();
     $sh->setFields(array('id', 'product_group', 'customer', 'stitem', 'order_number', 'despatch_number', 'due_despatch_date', 'despatch_date', 'order_qty', 'despatch_qty', 'failurecode', 'cs_failurecode_id', 'cs_failure_note'));
     if (isset($this->search) && ($this->isPrintDialog() || $this->isPrinting())) {
         $sh->setLimit(0);
         $customerservice->load($sh);
         return parent::printCollection($customerservice);
     } else {
         $sh->extractPaging();
         $customerservice->load($sh);
     }
     $this->view->set('num_records', $customerservice->num_records);
     $this->view->set('num_pages', $customerservice->num_pages);
     $this->view->set('cur_page', $customerservice->cur_page);
     $this->view->set(strtolower($customerservice->getModelName()) . 's', $customerservice);
     $sidebar = new SidebarController($this->view);
     $sidebar->addList('Actions', array('all' => array('link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'index')), 'tag' => 'Customer Service Summary'), 'failurecodes' => array('link' => array_merge($this->_modules, array('controller' => 'csfailurecodes', 'action' => 'index')), 'tag' => 'View Failure Codes')));
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }