public static function useDefault(&$search_data = null, &$errors = array(), $defaults = null)
 {
     $search = new sttransactionsSearch($defaults);
     // Search by Stock Item
     $search->addSearchField('stitem_id', 'Stock Item', 'select', '', 'basic');
     $stitem = DataObjectFactory::Factory('STItem');
     $options = array('' => 'All');
     $stitems = $stitem->getAll();
     $options += $stitems;
     $search->setOptions('stitem_id', $options);
     // Search by Status
     $search->addSearchField('status', 'Status', 'select', '', 'advanced');
     $transaction = DataObjectFactory::Factory('STTransaction');
     $options = array('' => 'All');
     $statuses = $transaction->getEnumOptions('status');
     $options += $statuses;
     $search->setOptions('status', $options);
     // Search by Location
     $search->addSearchField('whlocation_id', 'Location', 'select', '', 'advanced');
     $whlocation = new WHLocationCollection();
     $options = array('' => 'All');
     $whlocations = $whlocation->getLocationList();
     $options += $whlocations;
     $search->setOptions('whlocation_id', $options);
     // Search by Process
     $search->addSearchField('process_name', 'Process', 'select', '', 'advanced');
     $options = array('' => 'All');
     $statuses = $transaction->getEnumOptions('process_name');
     $options += $statuses;
     $search->setOptions('process_name', $options);
     // Search by Date
     $search->addSearchField('created', 'Date between', 'between', '', 'advanced');
     $search->setSearchData($search_data, $errors);
     return $search;
 }
 public function _new()
 {
     parent::_new();
     $transferrule = $this->_uses[$this->modeltype];
     // Get the Action
     $whaction = new WHAction();
     if ($transferrule->isLoaded()) {
         $whaction_id = $transferrule->whaction_id;
     } elseif (isset($this->_data['whaction_id'])) {
         $whaction_id = $this->_data['whaction_id'];
     } else {
         $flash = Flash::Instance();
         $flash->addError('Data invalid for this action');
         $this->sendBack();
     }
     $whaction->load($whaction_id);
     // Get the From Locations list
     $locations = new WHLocationCollection(new WHLocation());
     $cc = new ConstraintChain();
     $names = array('has_balance', 'bin_controlled', 'saleable');
     foreach ($names as $name) {
         $type = $whaction->getFormatted('from_' . $name);
         if ($type != 'All') {
             $cc->add(new Constraint($name, 'is', $type));
         }
     }
     $from_location = $locations->getLocationList($cc);
     $this->view->set('from_location', $from_location);
     // Get the To Locations list
     $locations = new WHLocationCollection(new WHLocation());
     $cc = new ConstraintChain();
     foreach ($names as $name) {
         $type = $whaction->getFormatted('to_' . $name);
         if ($type != 'All') {
             $cc->add(new Constraint($name, 'is', $type));
         }
     }
     $to_location = $locations->getLocationList($cc);
     $this->view->set('to_location', $to_location);
 }