public function _new() { parent::_new(); // work_order_id is set for adding a new structure // otherwise id is set, which is the id of the structure element $uom_list = array(); $wostructure = $this->_uses[$this->modeltype]; if (isset($this->_data['work_order_id'])) { $work_order_id = $this->_data['work_order_id']; $stitem_id = key($items_list); $uom_id = ''; } elseif ($wostructure->isLoaded()) { $work_order_id = $wostructure->work_order_id; $stitem_id = $wostructure->ststructure_id; $uom_id = $wostructure->uom_id; } if (isset($this->_data['ststructure_id'])) { $stitem_id = $this->_data['ststructure_id']; } $stitem = new STItem(); $stitem->load($stitem_id); $items_list = STItem::nonObsoleteItems(); if (!isset($items_list[$stitem_id])) { $items_list += array($stitem->id => $stitem->getIdentifierValue() . '(Obsolete)'); } $this->view->set('ststructures', $items_list); $uom_id = empty($uom_id) ? $stitem->uom_id : $uom_id; $this->view->set('uom_id', $uom_id); $uom_list = $stitem->getUomList(); if (isset($work_order_id)) { $this->view->set('elements', self::showParts($work_order_id)); $this->view->set('no_ordering', true); } $this->view->set('uom_list', $uom_list); }
public function _new() { // need to store the ajax flag in a different variable and the unset the original // this is to prevent any functions that are further called from returning the wrong datatype $ajax = isset($this->_data['ajax']); unset($this->_data['ajax']); parent::_new(); $stitems = STItem::nonObsoleteItems(null, 'M'); $this->view->set('stitems', $stitems); $stitem = DataObjectFactory::Factory('STItem'); if (isset($this->_data['stitem_id'])) { $stitem_id = $this->_data['stitem_id']; $stitem->load($stitem_id); $this->view->set('stitem', $stitem->item_code . ' - ' . $stitem->description); } else { $stitem_id = key($stitems); } $this->view->set('uoms', $this->getUomList($stitem_id)); $wodocs = new InjectorClassCollection(DataObjectFactory::Factory('InjectorClass')); $wodocs->getClassesList('WO'); $this->view->set('documents', $wodocs->getAssoc('name')); $order_id = empty($this->_data['order_id']) ? '' : $this->_data['order_id']; $this->view->set('sales_orders', $this->getSalesOrders($order_id)); if (!empty($order_id)) { $orderline_id = empty($this->_data['orderline_id']) ? '' : $this->_data['orderline_id']; $orderlines = $this->getOrderLines($order_id, $orderline_id); } else { $orderlines = array(); } $this->view->set('order_lines', $orderlines); }
public function getItems($_date = '', $_stitem_id = '') { // Used by Ajax to return Items list after selecting the Start Date if (isset($this->_data['ajax'])) { if (!empty($this->_data['date'])) { $_date = $this->_data['date']; } if (!empty($this->_data['stitem_id'])) { $_stitem_id = $this->_data['stitem_id']; } } $items_list = array(); if (!preg_match('#^(\\d{1,2})/(\\d{1,2})/(\\d{4})$#', $_date, $regs)) { $items_list = STItem::nonObsoleteItems(); } else { list(, $day, $month, $year) = $regs; $date = strtotime($year . '/' . $month . '/' . $day); $items_list = STItem::nonObsoleteItems($date); } if (!empty($_stitem_id)) { unset($items_list[$_stitem_id]); } if (isset($this->_data['ajax'])) { $this->view->set('options', $items_list); $this->setTemplateName('select_options'); } else { return $items_list; } }
public function recalcLatestCosts() { $flash = Flash::Instance(); $db = DB::Instance(); $db->StartTrans(); $errors = array(); $stitems_done = array(); $stitem_ids = array_keys(STItem::nonObsoleteItems()); $max_depth = 5; $max_parents = 5; $progressBar = new Progressbar('recalclatestcosts'); $callback = function ($stitem_id, $id) use(&$stitems_done, &$errors) { if (in_array($stitem_id, $stitems_done)) { return; } $stitem = DataObjectFactory::Factory('STItem'); if (!$stitem->load($stitem_id)) { return FALSE; } $parent = null; $num_parents = 0; do { if ($parent) { $stitem = $parent; } $parent = null; $parents = $stitem->getParents(); if (count($parents) > 0) { list($parent) = $parents; } $num_parents++; } while ($parent && $num_parents <= $max_parents); $tree_array = $stitem->getTreeArray($max_depth); // Gets child nodes first $array_iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($tree_array), 2); foreach ($array_iterator as $id => $children) { if (in_array($id, $stitems_done)) { return; } $stitem = DataObjectFactory::Factory('STItem'); if (!$stitem->load($id)) { return FALSE; } $stitems_done[] = $id; $old_costs = array($stitem->latest_cost, $stitem->latest_mat, $stitem->latest_lab, $stitem->latest_osc, $stitem->latest_ohd); $stitem->calcLatestCost(); $new_costs = array($stitem->latest_cost, $stitem->latest_mat, $stitem->latest_lab, $stitem->latest_osc, $stitem->latest_ohd); $equal_costs = true; $total_costs = count($old_costs); for ($i = 0; $i < $total_costs; $i++) { if (bccomp($old_costs[$i], $new_costs[$i], $stitem->cost_decimals) != 0) { $equal_costs = false; break; } } if ($equal_costs) { return; } if (!$stitem->saveCosts() || !STCost::saveItemCost($stitem)) { return FALSE; } } }; if ($progressBar->process($stitem_ids, $callback) === FALSE) { $errors[] = 'Could not re-calculate stock item costs'; $db->FailTrans(); } $db->CompleteTrans(); if (count($errors) == 0) { $flash->addMessage('Stock item costs re-calculated'); sendTo('Index', 'index', $this->_modules); } else { $flash->addErrors($errors); sendBack(); } }