public function delete() { $flash = Flash::Instance(); $errors = array(); $data = array('id' => $this->_data['id'], 'end_date' => date(DATE_FORMAT)); $outside_op = MFOutsideOperation::Factory($data, $errors, 'MFOutsideOperation'); if (count($errors) > 0 || !$outside_op->save()) { $errors[] = 'Could not delete outside operation'; } if (count($errors) == 0) { $stitem = new STItem(); if ($stitem->load($outside_op->stitem_id)) { //$stitem->calcLatestCost(); if (!$stitem->rollUp(STItem::ROLL_UP_MAX_LEVEL)) { $errors[] = 'Could not roll-up latest costs'; $db->FailTrans(); } } else { $errors[] = 'Could not roll-up latest costs'; $db->FailTrans(); } } if (count($errors) == 0) { $flash->addMessage('Outside operation deleted'); sendTo('STItems', 'viewoutside_operations', $this->_modules, array('id' => $this->_data['stitem_id'])); } else { $flash->addErrors($errors); sendBack(); } }
public function rollOver() { $flash = Flash::Instance(); $db = DB::Instance(); $db->StartTrans(); $errors = array(); $stitem_ids = array_keys(STItem::nonObsoleteItems()); $progressBar = new Progressbar('costs_rollover'); $callback = function ($stitem_id, $id) { $stitem = DataObjectFactory::Factory('STItem'); if (!$stitem->load($stitem_id) || !$stitem->rollOver()) { return FALSE; } }; if ($progressBar->process($stitem_ids, $callback) === FALSE) { $errors[] = 'Could not roll-over stock items'; $db->FailTrans(); } // Reset the time limit to complete set_time_limit(30); if (count($errors) == 0) { if (!MFStructure::globalRollOver() || !MFOperation::globalRollOver() || !MFOutsideOperation::globalRollOver()) { $errors[] = 'Could not roll-over stock items'; $db->FailTrans(); } } $db->CompleteTrans(); if (count($errors) == 0) { $flash->addMessage('Stock items rolled-over'); sendTo('Index', 'index', $this->_modules); } else { $flash->addErrors($errors); sendBack(); } }