Example #1
0
 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();
     }
 }