예제 #1
0
 public function view()
 {
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $transaction = $this->_uses[$this->modeltype];
     $id = $transaction->id;
     $this->view->set('transaction', $transaction);
     $elements = new WHTransferruleCollection(new WHTransferrule());
     $sh = new SearchHandler($elements, false);
     $sh->extract();
     $sh->addConstraint(new Constraint('whaction_id', '=', $id));
     $sh->extractOrdering();
     $sh->extractPaging();
     $elements->load($sh);
     $this->view->set('elements', $elements);
     $sidebar = new SidebarController($this->view);
     $sidebar->addList('Show', array('all' => array('tag' => 'All Actions', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'index'))), 'locations' => array('tag' => 'All Stores', 'link' => array_merge($this->_modules, array('controller' => 'WHStores', 'action' => 'index')))));
     $sidebarlist = array();
     $sidebarlist['edit'] = array('tag' => 'Edit', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'edit', 'id' => $id)));
     $sidebarlist['delete'] = array('tag' => 'Delete', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'delete', 'id' => $id)));
     if (is_null($transaction->max_rules) || $elements->count() < $transaction->max_rules) {
         $sidebarlist['Add'] = array('tag' => 'Add Rule', 'link' => array_merge($this->_modules, array('controller' => 'WHTransferrules', 'action' => 'new', 'whaction_id' => $id)));
     }
     $sidebar->addList('This Action', $sidebarlist);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     $this->view->set('clickaction', 'view');
     $this->view->set('clickcontroller', 'WHTransferrules');
     $this->view->set('no_ordering', true);
 }
예제 #2
0
 static function getTransferLocations(&$data, &$errors)
 {
     if (!isset($data['whaction_id']) || empty($data['whaction_id'])) {
         $errors[] = 'Transfer Action is missing';
         return false;
     }
     $rules = new WHTransferruleCollection();
     $sh = new SearchHandler($rules, false);
     $sh->addConstraint(new Constraint('whaction_id', '=', $data['whaction_id']));
     $rules->load($sh);
     if ($rules->count() > 1) {
         // Multiple transfer rules are not supported; this would require to display a
         //  drop down list of available transfer rules so the required rule can be selected
         $errors[] = 'Multiple transfer rules not allowed here';
         return false;
     }
     foreach ($rules as $rule) {
         $transfer_from = $rule->from_whlocation_id;
         $transfer_to = $rule->to_whlocation_id;
     }
     $data['from_whlocation_id'] = $transfer_from;
     $data['to_whlocation_id'] = $transfer_to;
     return true;
 }
예제 #3
0
 public function getToLocations($_id = '', $_whaction_id = '')
 {
     if (isset($this->_data['ajax'])) {
         if (!empty($this->_data['id'])) {
             $_id = $this->_data['id'];
         }
         if (!empty($this->_data['whaction_id'])) {
             $_whaction_id = $this->_data['whaction_id'];
         }
     }
     // Used by Ajax to return From Locations list after selecting the Transfer Action
     $whtransferrules = new WHTransferruleCollection(new WHTransferrule());
     $sh = new SearchHandler($whtransferrules, false);
     $sh->addConstraint(new Constraint('whaction_id', '=', $_whaction_id));
     $sh->addConstraint(new Constraint('from_whlocation_id', '=', $_id));
     $whtransferrules->load($sh);
     $locations = array();
     if ($whtransferrules->count() > 0) {
         foreach ($whtransferrules as $whtransferrule) {
             $locations[$whtransferrule->to_whlocation_id] = $whtransferrule->to_location;
         }
     }
     if (isset($this->_data['ajax'])) {
         $this->view->set('options', $locations);
         $this->setTemplateName('select_options');
     } else {
         return $locations;
     }
 }
예제 #4
0
 public function viewByOrders()
 {
     $cc = new ConstraintChain();
     if (isset($this->_data['id'])) {
         $id = $this->_data['id'];
         $cc->add(new Constraint('stitem_id', '=', $id));
     } elseif (isset($this->_data['order_id'])) {
         $order_id = $this->_data['order_id'];
         $cc->add(new Constraint('order_id', '=', $order_id));
     } else {
         $cc->add(new Constraint('type', '=', 'O'));
     }
     $cc->add(new Constraint('status', '=', 'R'));
     $order = new SOrderCollection();
     $order->orderby = array('delivery_note', 'order_number', 'line_number');
     $order->direction = array('ASC', 'ASC', 'ASC');
     $orders = $order->getItemOrders($cc);
     // Create an array of items ordered
     $stitems = array();
     foreach ($orders as $row) {
         $stitems[$row->stitem_id]['in_stock'] = 0;
         if (!isset($stitems[$row->stitem_id]['despatch_action'][$row->despatch_action])) {
             $transferrules = new WHTransferruleCollection(DataObjectFactory::Factory('WHTransferrule'));
             $locations = $transferrules->getFromLocations($row->despatch_action);
             if (count($locations) > 0 and $row->stitem_id) {
                 // Should never be zero or somethingis very wrong!
                 $cc = new ConstraintChain();
                 $cc->add(new Constraint('stitem_id', '=', $row->stitem_id));
                 $cc->add(new Constraint('whlocation_id', 'in', '(' . implode(',', array_keys($locations)) . ')'));
                 $stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] = STBalance::getBalances($cc);
             } else {
                 $stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] = 0;
                 // Flag it as a non-stock item
                 $stitems[$row->stitem_id]['non-stock'] = true;
             }
         }
     }
     // And check orders for stock availability
     // Items not available cannot be despatched!
     $items = array();
     foreach ($orders as $key => $row) {
         // Exclude any order lines that cannot be fulfilled
         // or have already been despatched
         $stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] -= $row->required;
         $sorder = DataObjectFactory::Factory('SOrder');
         $sorder->load($row->order_id);
         $items[$row->order_number]['order_number'] = $row->order_number;
         $items[$row->order_number]['order_id'] = $row->order_id;
         $items[$row->order_number]['customer'] = $row->customer;
         $items[$row->order_number]['del_address'] = $sorder->del_address->address;
         if ($stitems[$row->stitem_id]['non-stock']) {
             $items[$row->order_number]['line_number'][$row->line_number]['despatch'] = true;
         } elseif ($stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] >= 0) {
             $items[$row->order_number]['line_number'][$row->line_number]['despatch'] = true;
         } else {
             $items[$row->order_number]['line_number'][$row->line_number]['despatch'] = false;
         }
         $items[$row->order_number]['line_number'][$row->line_number]['despatch_action'] = $row->despatch_action;
         $items[$row->order_number]['due_despatch_date'] = $row->due_despatch_date;
         $items[$row->order_number]['line_number'][$row->line_number]['stitem'] = $row->stitem;
         $items[$row->order_number]['line_number'][$row->line_number]['item_description'] = $row->item_description;
         $items[$row->order_number]['line_number'][$row->line_number]['delivery_note'] = $row->delivery_note;
         $items[$row->order_number]['line_number'][$row->line_number]['required'] = $row->required;
         $items[$row->order_number]['line_number'][$row->line_number]['stuom'] = $row->stuom;
         $items[$row->order_number]['line_number'][$row->line_number]['id'] = $row->id;
     }
     $this->view->set('orders', $items);
     $sidebar = new SidebarController($this->view);
     $actions = array();
     $actions['viewnotes'] = array('link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'index')), 'tag' => 'view despatch notes');
     $sidebar->addList('Actions', $actions);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     $this->view->set('page_title', $this->getPageName('Despatch', 'View Order Lines for'));
 }