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); } }