Example #1
0
 public function edit()
 {
     parent::edit();
     $whtransfer = new WHTransfer();
     $whtransfer->load($this->_data['id']);
     $this->view->set('whtransfer', $whtransfer);
     $stitems = STBalance::getStockList($whtransfer->from_whlocation_id);
     $this->view->set('stitems', $stitems);
     $this->_templateName = $this->getTemplateName('_new');
 }
 public function getTransferDetails($_whaction_id = '')
 {
     // Used by Ajax to get the From/To Locations/Bins based on Stock Item
     if (isset($this->_data['ajax'])) {
         if (!empty($this->_data['entry_point'])) {
             $_entry_point = $this->_data['entry_point'];
         }
         if (!empty($this->_data['whaction_id'])) {
             $_whaction_id = $this->_data['whaction_id'];
         }
         if (!empty($this->_data['stitem_id'])) {
             $_stitem_id = $this->_data['stitem_id'];
         }
         if (!empty($this->_data['from_whlocation_id'])) {
             $_from_location_id = $this->_data['from_whlocation_id'];
         }
         if (!empty($this->_data['from_whbin_id'])) {
             $_from_bin_id = $this->_data['from_whbin_id'];
         }
         if (!empty($this->_data['to_whlocation_id'])) {
             $_to_location_id = $this->_data['to_whlocation_id'];
         }
     } else {
         // if this is Save and Add Another then need to get $_POST values to set context
         $_stitem_id = isset($_POST[$this->modeltype]['stitem_id']) ? $_POST[$this->modeltype]['stitem_id'] : '';
         $_from_location_id = isset($_POST[$this->modeltype]['from_whlocation_id']) ? $_POST[$this->modeltype]['from_whlocation_id'] : '';
     }
     //		echo '$_stitem_id='.$_stitem_id.'<br>';
     // store the ajax status in a different var, then unset the current one
     // we do this because we don't want the functions we all to get confused
     $ajax = isset($this->_data['ajax']);
     unset($this->_data['ajax']);
     // ****************************************************************************
     // Get the To Locations for the selected action
     $from_locations = $this->getFromLocations($_whaction_id);
     $from_whlocation_ids = array_keys($from_locations);
     if (empty($_entry_point) || $_entry_point == $this->modeltype . '_stitem_id') {
         $this->view->set('from_locations', $from_locations);
         if (empty($_from_location_id)) {
             $_from_location_id = key($from_locations);
         }
         $this->view->set('from_whlocation', $from_locations[$_from_location_id]);
         $output['from_whlocation_id'] = array('data' => $from_locations, 'is_array' => is_array($from_locations));
     } elseif (empty($_from_location_id)) {
         $_from_location_id = key($from_locations);
     }
     $this->view->set('from_whlocation_id', $_from_location_id);
     //		echo '$_from_location_id='.$_from_location_id.'<br>';
     $from_location = new WHLocation();
     $from_location->load($_from_location_id);
     // ****************************************************************************
     // Get the Stock Item list if no stock item is selected
     $stitem = new STItem();
     if (empty($_entry_point)) {
         // No item selected so get list of items and set default as first in list
         $stock_items = array();
         if ($from_location->haveBalances($from_whlocation_ids)) {
             $stock_items = STBalance::getStockList($from_whlocation_ids);
         } else {
             $stock_items = $stitem->getAll();
         }
         if (empty($_stitem_id)) {
             $_stitem_id = key($stock_items);
         }
         $this->view->set('stock_item', $stock_items[$_stitem_id]);
         $this->view->set('stock_items', $stock_items);
         $output['stitem_id'] = array('data' => $stock_items, 'is_array' => is_array($stock_items));
     }
     if (empty($_entry_point) || $_entry_point == $this->modeltype . '_stitem_id') {
         $_entry_point = $this->modeltype . '_from_whlocation_id';
     }
     //		echo '$_stitem_id='.$_stitem_id.'<br>';
     $stitem->load($_stitem_id);
     $this->view->set('stitem_id', $_stitem_id);
     $this->view->set('uom', $stitem->uom_name);
     $output['uom_id'] = array('data' => $stitem->uom_name, 'is_array' => is_array($stitem->uom_name));
     // ****************************************************************************
     // Get the list of bins for the To Location if it is bin controlled
     if ($_entry_point == $this->modeltype . '_from_whlocation_id') {
         $from_bins = array();
         if ($from_location->isBinControlled()) {
             $from_bins = $stitem->getBinList($_from_location_id);
             $this->view->set('from_bins', $from_bins);
             // check if the input bin present and exists in the bin list
             // if not, check for an error (exists in post data)
             // then check if in bin list; if not, use first in bin list
             if (empty($_from_bin_id) || !isset($from_bins[$_from_bin_id])) {
                 if (isset($_POST[$this->modeltype]['from_whbin_id'])) {
                     $_from_bin_id = $_POST[$this->modeltype]['from_whbin_id'];
                     if (!isset($from_bins[$_from_bin_id])) {
                         $_from_bin_id = key($from_bins);
                     }
                 } else {
                     $_from_bin_id = key($from_bins);
                 }
             }
         } else {
             $_from_bin_id = '';
         }
         $output['from_whbin_id'] = array('data' => $from_bins, 'is_array' => is_array($from_bins));
     }
     //echo 'SttransactionsController::getTransferDetails bins<pre>'.print_r($from_bins,true).'</pre><br>';
     // ****************************************************************************
     // Get the balance of the selected Item for the selected From Location/Bin
     if ($from_location->isBalanceEnabled()) {
         $balance = $this->getBalance($_stitem_id, $_from_location_id, $_from_bin_id);
         $this->view->set('balance', $balance);
         $output['balance'] = array('data' => $balance, 'is_array' => is_array($balance));
     } else {
         $output['balance'] = '';
     }
     // ****************************************************************************
     // get the associated 'To Location' values for the selected from location
     if ($_entry_point == $this->modeltype . '_from_whlocation_id') {
         $to_locations = $this->getToLocations($_from_location_id, $_whaction_id);
         $this->view->set('to_locations', $to_locations);
         $this->view->set('to_whlocation', $to_locations[$_to_location_id]);
         //			if (empty($_to_location_id)) {
         $_to_location_id = key($to_locations);
         //			}
         $output['to_whlocation_id'] = array('data' => $to_locations, 'is_array' => is_array($to_locations));
         $_entry_point = $this->modeltype . '_to_whlocation_id';
     }
     $this->view->set('to_whlocation_id', $_to_location_id);
     $to_location = new WHLocation();
     $to_location->load($_to_location_id);
     // ****************************************************************************
     // Get the bin list for the To Location if it is bin controlled
     if ($_entry_point == $this->modeltype . '_to_whlocation_id') {
         $to_bins = array();
         if ($to_location->isBinControlled()) {
             $to_bins = $this->getBinList($_to_location_id);
             $this->view->set('to_bins', $to_bins);
         }
         $output['to_whbin_id'] = array('data' => $to_bins, 'is_array' => is_array($to_bins));
     }
     if ($ajax) {
         $this->view->set('data', $output);
         $this->setTemplateName('ajax_multiple');
     }
 }
 public function getTransferDetails($_whaction_id = '', $_works_schedule_id = '', $_stitem_id = '', $_type_text = '')
 {
     $modeltype = 'STTransaction';
     // Used by Ajax to get the From/To Locations/Bins based on Stock Item
     if (isset($this->_data['ajax'])) {
         if (!empty($this->_data['entry_point'])) {
             $_entry_point = $this->_data['entry_point'];
         }
         if (!empty($this->_data['whaction_id'])) {
             $_whaction_id = $this->_data['whaction_id'];
         }
         if (!empty($this->_data['type_text'])) {
             $_type_text = $this->_data['type_text'];
         }
         if (!empty($this->_data['works_schedule_id'])) {
             $_works_schedule_id = $this->_data['works_schedule_id'];
         }
         if (!empty($this->_data['stitem_id'])) {
             $_stitem_id = $this->_data['stitem_id'];
         }
         if (!empty($this->_data['from_whlocation_id'])) {
             $_from_location_id = $this->_data['from_whlocation_id'];
         }
         if (!empty($this->_data['from_whbin_id'])) {
             $_from_bin_id = $this->_data['from_whbin_id'];
         }
         if (!empty($this->_data['to_whlocation_id'])) {
             $_to_location_id = $this->_data['to_whlocation_id'];
         }
     } else {
         // if this is Save and Add Another then need to get $_POST values to set context
         $_stitem_id = isset($_POST[$modeltype]['stitem_id']) ? $_POST[$modeltype]['stitem_id'] : $_stitem_id;
         $_from_location_id = isset($_POST[$modeltype]['from_whlocation_id']) ? $_POST[$modeltype]['from_whlocation_id'] : '';
     }
     // store the ajax status in a different var, then unset the current one
     // we do this because we don't want the functions we all to get confused
     $ajax = isset($this->_data['ajax']);
     unset($this->_data['ajax']);
     // ****************************************************************************
     // Get the From Locations for the selected action
     $from_locations = $this->getFromLocations($_whaction_id);
     $from_whlocation_ids = array_keys($from_locations);
     if (empty($_entry_point) || $_entry_point == $modeltype . '_whaction_id' || $_entry_point == $modeltype . '_stitem_id') {
         if (empty($_from_location_id) || !isset($from_locations[$_from_location_id])) {
             $_from_location_id = key($from_locations);
         }
         $output['from_whlocation_id'] = array('data' => $from_locations, 'is_array' => is_array($from_locations));
     } elseif (empty($_from_location_id) || !isset($from_locations[$_from_location_id])) {
         $_from_location_id = key($from_locations);
     }
     $from_location = DataObjectFactory::Factory('WHLocation');
     $from_location->load($_from_location_id);
     // ****************************************************************************
     // Get the Stock Item list if no stock item is selected
     $stitem = DataObjectFactory::Factory('STItem');
     if (empty($_entry_point) && empty($_stitem_id)) {
         // No item selected so get list of items and set default as first in list
         $stock_items = array();
         if ($from_location->haveBalances($from_whlocation_ids)) {
             $stock_items = STBalance::getStockList($from_whlocation_ids);
         } else {
             $stock_items = $stitem->getAll();
         }
         if (empty($_stitem_id)) {
             $_stitem_id = key($stock_items);
         }
         $output['stitem_id'] = array('data' => $stock_items, 'is_array' => is_array($stock_items));
     }
     if (empty($_entry_point) || $_entry_point == $modeltype . '_whaction_id' || $_entry_point == $modeltype . '_stitem_id') {
         $_entry_point = $modeltype . '_from_whlocation_id';
     }
     $stitem->load($_stitem_id);
     $output['uom_name'] = array('data' => $stitem->uom_name, 'is_array' => is_array($stitem->uom_name));
     //		$required_qty	= round($structure->requiredQty(), $stitem->qty_decimals);
     //		$issued_qty		= round($structure->getTransactionBalance(TRUE), $stitem->qty_decimals);
     //		$used_qty		= round($structure->getTransactionBalance(FALSE),$stitem->qty_decimals);
     $required_qty = round($required_qty - $issued_qty - $used_qty, $stitem->qty_decimals);
     $required_qty = $required_qty < 0 ? 0 : $required_qty;
     $output['required_qty'] = array('data' => $required_qty, 'is_array' => FALSE);
     $output['issued_qty'] = array('data' => $issued_qty, 'is_array' => FALSE);
     $output['used_qty'] = array('data' => $used_qty, 'is_array' => FALSE);
     // ****************************************************************************
     // Get the list of bins for the To Location if it is bin controlled
     if ($_entry_point == $modeltype . '_from_whlocation_id') {
         $from_bins = array();
         if ($from_location->isBinControlled()) {
             $from_bins = $stitem->getBinList($_from_location_id);
             // check if the input bin present and exists in the bin list
             // if not, check for an error (exists in post data)
             // then check if in bin list; if not, use first in bin list
             if (empty($_from_bin_id) || !isset($from_bins[$_from_bin_id])) {
                 if (isset($_POST[$modeltype]['from_whbin_id'])) {
                     $_from_bin_id = $_POST[$modeltype]['from_whbin_id'];
                     if (!isset($from_bins[$_from_bin_id])) {
                         $_from_bin_id = key($from_bins);
                     }
                 } else {
                     $_from_bin_id = key($from_bins);
                 }
             }
         } else {
             $_from_bin_id = '';
         }
         $output['from_whbin_id'] = array('data' => $from_bins, 'is_array' => is_array($from_bins));
     }
     // ****************************************************************************
     // Get the balance of the selected Item for the selected From Location/Bin
     if ($from_location->isBalanceEnabled()) {
         $balance = $this->getBalance($_stitem_id, $_from_location_id, $_from_bin_id);
     } else {
         $balance = '-';
     }
     $output['balance'] = array('data' => $balance, 'is_array' => is_array($balance));
     // ****************************************************************************
     // get the associated 'To Location' values for the selected from location
     if ($_entry_point == $modeltype . '_from_whlocation_id') {
         $to_locations = $this->getToLocations($_from_location_id, $_whaction_id);
         $_to_location_id = key($to_locations);
         $output['to_whlocation_id'] = array('data' => $to_locations, 'is_array' => is_array($to_locations));
         $_entry_point = $modeltype . '_to_whlocation_id';
     }
     $to_location = DataObjectFactory::Factory('WHLocation');
     $to_location->load($_to_location_id);
     // ****************************************************************************
     // Get the bin list for the To Location if it is bin controlled
     if ($_entry_point == $modeltype . '_to_whlocation_id') {
         $to_bins = array();
         if ($to_location->isBinControlled()) {
             $to_bins = $this->getBinList($_to_location_id);
         }
         $output['to_whbin_id'] = array('data' => $to_bins, 'is_array' => is_array($to_bins));
     }
     // ****************************************************************************
     // Get list of transactions for the action and works order
     $sttransactions = new STTransactionCollection();
     $sh = new SearchHandler($sttransactions, false);
     $sh->addConstraint(new Constraint('process_name', '=', $this->_templateobject->transaction_type()));
     $sh->addConstraint(new Constraint('process_id', '=', $_works_schedule_id));
     $sh->addConstraint(new Constraint('whaction_id', '=', $_whaction_id));
     $sh->addConstraint(new Constraint('qty', '>', 0));
     $sh->setFields(array('id', 'stitem as Stock_Item', 'stitem_id', 'flocation as from_location', 'fbin as from_bin', 'whlocation as to_location', 'whbin as to_bin', 'qty'));
     $sttransactions->load($sh);
     $this->view->set('clickmodule', $this->_modules);
     $this->view->set('clickcontroller', 'stitems');
     $this->view->set('clickaction', 'view');
     $this->view->set('linkvaluefield', 'stitem_id');
     $this->view->set('collection', $sttransactions);
     $this->view->set('type_text', $_type_text);
     $this->view->set('page_title', $this->getPageName(null, $_type_text . ' for '));
     $html = $this->view->fetch($this->getTemplateName('en_issues_list'));
     $output['sttransactions'] = array('data' => $html, 'is_array' => is_array($html));
     // ****************************************************************************
     // Finally, if this is an ajax call, set the return data area
     if ($ajax) {
         $this->view->set('data', $output);
         $this->setTemplateName('ajax_multiple');
     } else {
         return $output;
     }
 }
Example #4
0
 public function getStockAtLocation()
 {
     // Used by Ajax to return Stock list after selecting the location
     if (isset($this->_data['ajax'])) {
         if (!empty($this->_data['id'])) {
             $_id = $this->_data['id'];
         }
     }
     $stitems = array();
     if (!empty($_id)) {
         $stitems = STBalance::getStockList($_id);
     }
     if (isset($this->_data['ajax'])) {
         $this->view->set('options', $stitems);
         $this->setTemplateName('select_options');
     } else {
         return $stitems;
     }
 }
 public function displayLocations($whaction_id, &$errors = array())
 {
     //
     //   1.  Gets a list of Stock Items to populate a select list
     //       depending on the From Locations, if all From Locations
     //       have balances
     //
     //   2.  Gets a list of From Locations, dependant on the supplied action_id
     //
     //       If the list of From Locations is a single location
     //        - pass through the location_id and description
     //        - if the location is bin_controlled
     //                  get a list of bins for that location
     //       else pass through the array of locations to populate a select list
     //
     //   3.  Gets a list of To Locations, dependant on the supplied action_id
     //
     //       If the list of To Locations is a single location
     //        - pass through the location_id and description
     //        - if the location is bin_controlled
     //                  get a list of bins for that location
     //       else pass through the array of locations to populate a select list
     //
     //	Ajax Operations
     //
     // TODO  On selecting an item, if the From and/or To Location has been selected
     //       and either is bin_controlled, repopulate the list of bins that
     //       contain the selected item
     //
     //       On selecting either a From or a To Location;
     //       -if that location is bin_controlled, populate the list of bins;
     //       -if the item is selected, then further constrain the selection by item
     //
     //       On selecting an Item and a From Location
     //       -if that location is not bin_controlled and the location
     //        has_balances then get the balance for the item at that location
     //       -if that location is bin_controlled and the location
     //        has_balances, on selecting the bin
     //        then get the balance for the item at that location for that bin
     //
     // Get the list of Transfer From Locations for the supplied Action
     $from_locations = $this->getFromLocations($whaction_id);
     if (count($from_locations) == 0) {
         $errors[] = 'No transfer rule defined';
         return;
     }
     $this->view->set('from_locations', $from_locations);
     $from_whlocation_ids = array_keys($from_locations);
     // if all the locations are all balance enabled,
     // get list of stock items for the locations
     $stock_items = array();
     $whlocation = DataObjectFactory::Factory('WHLocation');
     if ($whlocation->haveBalances($from_whlocation_ids)) {
         $stock_items = STBalance::getStockList($from_whlocation_ids);
     } else {
         $stitem = DataObjectFactory::Factory('STItem');
         $stock_items = $stitem->getAll();
     }
     if (count($stock_items) > 0) {
         $stitem_id = key($stock_items);
         $this->view->set('stock_item', $stock_items[$stitem_id]);
         $this->view->set('stitem_id', $stitem_id);
         $this->view->set('uom', $this->getUoM($stitem_id));
     }
     // check the first from location
     $from_whlocation_id = key($from_locations);
     $this->view->set('from_whlocation_id', $from_whlocation_id);
     $this->view->set('from_whlocation', $from_locations[$from_whlocation_id]);
     $locations = DataObjectFactory::Factory('WHLocation');
     $location = $locations->load($from_whlocation_id);
     $from_bins = array();
     if ($location->isBinControlled()) {
         // The location has bins so get the list of bins
         $from_bins = STBalance::getBinList($stitem_id, $from_whlocation_id);
         $this->view->set('from_bins', $from_bins);
     }
     if ($location->isBalanceEnabled()) {
         // Get the balance for the Stock/Location
         $chain = new ConstraintChain();
         $chain->add(new Constraint('stitem_id', '=', $stitem_id));
         $chain->add(new Constraint('whlocation_id', '=', $from_whlocation_id));
         if (!empty($from_bins) && count($from_bins) > 0) {
             $chain->add(new Constraint('whbin_id', '=', key($from_bins)));
         }
         $balance = STBalance::getBalances($chain);
         $this->view->set('balance', $balance);
     }
     // get the associated 'To Location' values for the first from location
     $to_locations = $this->getToLocations($from_whlocation_id, $whaction_id);
     $this->view->set('to_locations', $to_locations);
     $to_whlocation_id = key($to_locations);
     $this->view->set('to_whlocation_id', $to_whlocation_id);
     $this->view->set('to_whlocation', $to_locations[$to_whlocation_id]);
     $locations = DataObjectFactory::Factory('WHLocation');
     $location = $locations->load($to_whlocation_id);
     if ($location->isBinControlled()) {
         // The location has bins so get the list of bins
         $to_bins = $this->getBinList($to_whlocation_id);
         $this->view->set('to_bins', $to_bins);
     }
 }