public static function useDefault($search_data = null, &$errors = array(), $defaults = null) { $search = new workordersSearch($defaults); // Search by Order No. $search->addSearchField('wo_number', 'Order No', 'equal'); // Search by Status $search->addSearchField('status', 'status_is', 'multi_select', array()); $wo = new MFWorkorder(); $search->setOptions('status', $wo->getEnumOptions('status')); // Search by Stock Item $search->addSearchField('stitem_id', 'Stock Item', 'select', '', 'advanced'); $stitem = new STItem(); $chain = new ConstraintChain(); $chain->add(new Constraint('comp_class', '=', 'M')); $stitems = $stitem->getAll($chain); $options = array('' => 'All'); $options = $options + $stitems; $search->setOptions('stitem_id', $options); // Search by Required By Date /* 'between' is not yet implemented $search->addSearchField( 'required_by', 'Required Between', 'between', '', 'advanced' ); */ $search->addSearchField('required_by', 'Required Between', 'between', '', 'advanced'); // Search by Stock Type Code $search->addSearchField('type_code_id', 'Type Code', 'select', '', 'advanced'); $typecode = new STTypecode(); $typecodes = $typecode->getAll(); $options = array('' => 'All'); $options = $options + $typecodes; $search->setOptions('type_code_id', $options); $search->setSearchData($search_data, $errors); return $search; }
public function viewByOrders() { $cc = new ConstraintChain(); $cc->add(new Constraint('type', '=', 'O')); if (isset($this->_data['id'])) { $id = $this->_data['id']; $cc->add(new Constraint('stitem_id', '=', $id)); } $order = new SOrderCollection($this->_templateobject); $order->orderby = array('status', 'due_despatch_date', 'order_number'); $order->direction = array('DESC', 'ASC'); $orders = $order->getItemOrders($cc); // Create an array of items ordered $stitems = array(); foreach ($orders as $row) { // ignore PLs without stitem if ($row->stitem_id) { $stitems[$row->stitem_id]['shortfall'] = 0; } } // Now get the balance for each item across all saleable locations foreach ($stitems as $key => $item) { $cc = new ConstraintChain(); $cc->add(new Constraint('stitem_id', '=', $key)); $stitems[$key]['in_stock'] = STBalance::getBalances($cc); $salelocations = WHLocation::getSaleLocations(); if (empty($salelocations)) { $stitems[$key]['for_sale'] = 0; } else { $cc->add(new Constraint('whlocation_id', 'in', '(' . implode(',', $salelocations) . ')')); $stitems[$key]['for_sale'] = STBalance::getBalances($cc); } $stitems[$key]['in_stock'] -= $stitems[$key]['for_sale']; $stitems[$key]['total_orders'] = 0; } // And finally update the orders with the projected stock balances $items = array(); foreach ($orders as $key => $row) { // echo 'count '.$row->id.' - '.SOrder::lineExistsInDespatchLines($row->id).'<br>'; $items[$key]['id'] = $row->id; $items[$key]['stitem_id'] = $row->stitem_id; $items[$key]['stitem'] = $row->stitem; $items[$key]['item_description'] = $row->item_description; $items[$key]['productline_id'] = $row->productline_id; $items[$key]['required'] = $row->required; $items[$key]['due_despatch_date'] = $row->due_despatch_date; $items[$key]['order_number'] = $row->order_number; $items[$key]['order_id'] = $row->order_id; $items[$key]['customer'] = $row->customer; $items[$key]['slmaster_id'] = $row->slmaster_id; $items[$key]['stuom'] = $row->stuom; $items[$key]['for_sale'] = $stitems[$row->stitem_id]['for_sale']; $items[$key]['shortfall'] = 0; // ignore PLs without stitem if ($row->stitem_id) { $cc = new ConstraintChain(); $cc->add(new Constraint('stitem_id', '=', $row->stitem_id)); $cc->add(new Constraint('required_by', '<=', $row->due_despatch_date)); $worders = MFWorkorder::getBalances($cc); if ($worders) { $stitems[$row->stitem_id]['on_order'] = $worders[0]['sumbalance'] - $stitems[$row->stitem_id]['total_orders']; $stitems[$row->stitem_id]['total_orders'] = $worders[0]['sumbalance']; } else { $stitems[$row->stitem_id]['on_order'] = 0; } } $on_order = $stitems[$row->stitem_id]['on_order']; $items[$key]['on_order'] = $stitems[$row->stitem_id]['on_order']; $stitems[$row->stitem_id]['for_sale'] -= $items[$key]['required']; if ($stitems[$row->stitem_id]['for_sale'] < 0) { $stitems[$row->stitem_id]['in_stock'] += $stitems[$row->stitem_id]['for_sale']; $stitems[$row->stitem_id]['for_sale'] = 0; } $stitems[$row->stitem_id]['in_stock'] = $stitems[$row->stitem_id]['in_stock'] - $stitems[$row->stitem_id]['shortfall'] + $stitems[$row->stitem_id]['on_order']; // $stitems[$row->stitem_id]['in_stock']=$stitems[$row->stitem_id]['in_stock']-$stitems[$row->stitem_id]['shortfall']; if ($stitems[$row->stitem_id]['in_stock'] < 0) { $stitems[$row->stitem_id]['shortfall'] -= $stitems[$row->stitem_id]['in_stock']; $stitems[$row->stitem_id]['in_stock'] = 0; $items[$key]['shortfall'] = $stitems[$row->stitem_id]['shortfall'] < $on_order ? 0 : $stitems[$row->stitem_id]['shortfall'] - $on_order; // $items[$key]['shortfall']=$stitems[$row->stitem_id]['shortfall']; } else { $stitems[$row->stitem_id]['shortfall'] = 0; } $items[$key]['in_stock'] = $stitems[$row->stitem_id]['in_stock']; if (!empty($row->delivery_note)) { $items[$key]['status'] = 'Awaiting Despatch'; } elseif ($row->status == 'R') { $items[$key]['status'] = 'Ready for Despatch'; } else { $items[$key]['status'] = ''; } $items[$key]['account_status'] = $row->account_status; $items[$key]['despatch_number'] = SOrder::lineExistsInDespatchLines($row->id); if ($row->status == 'R') { $items[$key]['despatch'] = true; } else { $items[$key]['despatch'] = false; } } $this->view->set('orders', $items); $sidebar = new SidebarController($this->view); $actions = array(); $actions['allcustomer'] = array('link' => array('module' => 'sales_ledger', 'controller' => 'SLCustomers', 'action' => 'index'), 'tag' => 'view all customers'); $actions['newquote'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'new', 'type' => 'Q'), 'tag' => 'new quote'); $actions['neworder'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'new', 'type' => 'O'), 'tag' => 'new order'); $actions['vieworder'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index'), 'tag' => 'view quotes/orders'); $actions['viewdespatches'] = array('link' => array('module' => 'despatch', 'controller' => 'sodespatchlines', 'action' => 'viewByOrders'), 'tag' => 'view despatches'); $sidebar->addList('Actions', $actions); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); $this->view->set('page_title', $this->getPageName('', 'View availability by')); }