コード例 #1
0
ファイル: StcostsController.php プロジェクト: uzerpllp/uzerp
 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();
     }
 }
コード例 #2
0
 public function save()
 {
     $flash = Flash::Instance();
     $db = DB::Instance();
     $db->StartTrans();
     $errors = array();
     $update_cost = false;
     if (isset($this->_data[$this->modeltype]['id']) && $this->_data[$this->modeltype]['id']) {
         $mfresource = new MFResource();
         $mfresource->load($this->_data[$this->modeltype]['id']);
         $old_rate = $mfresource->resource_rate;
         $new_rate = $this->_data[$this->modeltype]['resource_rate'];
         $update_cost = $old_rate != $new_rate;
     }
     if (parent::save_model($this->modeltype, null, $errors)) {
         if ($update_cost) {
             $cc = new ConstraintChain();
             $cc->add(new Constraint('mfresource_id', '=', $this->_data[$this->modeltype]['id']));
             $db = DB::Instance();
             $date = Constraint::TODAY;
             $between = $date . ' BETWEEN ' . $db->IfNull('start_date', $date) . ' AND ' . $db->IfNull('end_date', $date);
             $cc->add(new Constraint('', '', '(' . $between . ')'));
             $mfoperation = new MFOperation();
             //$db->Debug();
             $mfoperation_ids = array_keys($mfoperation->getAll($cc));
             $stitem_ids = array();
             foreach ($mfoperation_ids as $mfoperation_id) {
                 if (!$mfoperation->load($mfoperation_id)) {
                     $errors[] = 'Could not save latest costs';
                     $db->FailTrans();
                     break;
                 }
                 if (in_array($mfoperation->stitem_id, $stitem_ids)) {
                     continue;
                 }
                 $stitem_ids[] = $mfoperation->stitem_id;
             }
             if (count($stitem_ids) > 0) {
                 $stitem = new STItem();
             }
             foreach ($stitem_ids as $stitem_id) {
                 if (!$stitem->load($stitem_id)) {
                     $errors[] = 'Could not save latest costs';
                     $db->FailTrans();
                     break;
                 }
                 $old_cost = $stitem->latest_lab;
                 $stitem->calcLatestCost();
                 $new_cost = $stitem->latest_lab;
                 if (bccomp($old_cost, $new_cost, $stitem->cost_decimals) == 0) {
                     continue;
                 }
                 if (!$stitem->saveCosts() || !STCost::saveItemCost($stitem)) {
                     $errors[] = 'Could not save latest costs';
                     $db->FailTrans();
                     break;
                 }
                 if (!$stitem->rollUp(STItem::ROLL_UP_MAX_LEVEL)) {
                     $errors[] = 'Could not roll-up latest costs';
                     $db->FailTrans();
                     break;
                 }
             }
         }
     } else {
         $errors[] = 'Could not save resource';
         $db->FailTrans();
     }
     $db->CompleteTrans();
     if (count($errors) == 0) {
         sendTo($_SESSION['refererPage']['controller'], $_SESSION['refererPage']['action'], $_SESSION['refererPage']['modules'], isset($_SESSION['refererPage']['other']) ? $_SESSION['refererPage']['other'] : null);
     } else {
         $flash->addErrors($errors);
         $this->refresh();
     }
 }
コード例 #3
0
 public function view()
 {
     $id = $this->_data['id'];
     $object =& $this->_uses['MFOperation'];
     $object->load($id);
     $transaction = new MFOperation();
     $transaction->load($id);
     $this->view->set('transaction', $transaction);
     $sidebar = new SidebarController($this->view);
     $sidebar->addList('Actions', array('stores' => array('tag' => 'Show Item detail', 'link' => array('modules' => $this->_modules, 'controller' => 'STItems', 'action' => 'view', 'id' => $transaction->stitem_id)), 'resources' => array('tag' => 'Show Resource detail', 'link' => array('modules' => $this->_modules, 'controller' => 'MFResources', 'action' => 'view', 'id' => $transaction->mfresource_id)), 'centres' => array('tag' => 'Show Centre detail', 'link' => array('modules' => $this->_modules, 'controller' => 'MFCentres', 'action' => 'view', 'id' => $transaction->mfcentre_id)), 'new' => array('tag' => 'New Operation', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'new', 'stitem_id' => $transaction->stitem_id)), 'edit' => array('tag' => 'Edit Operation', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'edit', 'id' => $id, 'stitem_id' => $transaction->stitem_id)), 'delete' => array('tag' => 'Delete Operation', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'delete', 'id' => $id, 'stitem_id' => $transaction->stitem_id))));
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }