Esempio n. 1
0
 public function getBalance()
 {
     // Function called by Ajax Request to return balance for selected item, location, bin
     $balance = new STBalance();
     $cc = new ConstraintChain();
     $cc->add(new Constraint('stitem_id', '=', $this->_data['stitem_id']));
     $cc->add(new Constraint('whlocation_id', '=', $this->_data['location_id']));
     if (isset($this->_data['bin_id']) && !empty($this->_data['bin_id'])) {
         $cc->add(new Constraint('whbin_id', '=', $this->_data['bin_id']));
     }
     $balance->loadBy($cc);
     echo json_encode($balance->balance ? $balance->balance : 0);
     exit;
 }
Esempio n. 2
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');
     }
 }
Esempio n. 4
0
 public function getStockBalance()
 {
     if ($this->stitem) {
         $locations = $this->despatch_from->rules_list('from_whlocation_id');
         $balance = new STBalance();
         return $balance->getStockBalance($this->stitem_id, $locations);
     }
     return 0;
 }
Esempio n. 5
0
 public function getBalance($_stitem_id = '', $_location_id = '', $_bin_id = '')
 {
     // Function called by Ajax Request to return balance for selected item, location, bin
     if (isset($this->_data['ajax'])) {
         if (!empty($this->_data['stitem_id'])) {
             $_stitem_id = $this->_data['stitem_id'];
         }
         if (!empty($this->_data['whlocation_id'])) {
             $_location_id = $this->_data['whlocation_id'];
         }
         if (!empty($this->_data['whbin_id'])) {
             $_bin_id = $this->_data['whbin_id'];
         }
     }
     $balance = new STBalance();
     $cc = new ConstraintChain();
     $cc->add(new Constraint('stitem_id', '=', $_stitem_id));
     $cc->add(new Constraint('whlocation_id', '=', $_location_id));
     if (!empty($_bin_id) && $_bin_id != "null") {
         $cc->add(new Constraint('whbin_id', '=', $_bin_id));
     }
     $balance->loadBy($cc);
     $balances = $balance->isLoaded() ? $balance->balance : 0;
     if (isset($this->_data['ajax'])) {
         $this->view->set('value', $balances);
         $this->setTemplateName('text_inner');
     } else {
         return $balances;
     }
 }
Esempio n. 6
0
 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;
     }
 }
Esempio n. 7
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;
     }
 }
 private function getItemPlan()
 {
     // Get the list of saleable items
     $s_data = array();
     // Set context from calling module
     if (isset($this->_data['stitem_id'])) {
         $s_data['stitem_id'] = $this->_data['stitem_id'];
     }
     if (isset($this->_data['prod_group_id'])) {
         $s_data['prod_group_id'] = $this->_data['prod_group_id'];
     }
     $this->setSearch('productlinesSearch', 'customerItems', $s_data);
     $items = new SOProductlineHeaderCollection($this->_templateobject);
     $sh = $this->setSearchHandler($items);
     $items->getItems($sh);
     parent::index($items, $sh);
     // Now get totals for Sales Orders, In Stock, Work Orders
     $itemplan = array();
     foreach ($items as $item) {
         $stitem = DataObjectFactory::Factory('STItem');
         if ($stitem->load($item->stitem_id)) {
             $itemplan[$item->stitem_id]['stitem_id'] = $item->stitem_id;
             $itemplan[$item->stitem_id]['stitem'] = $item->stitem;
             $itemplan[$item->stitem_id]['uom_name'] = $item->uom_name;
             $itemplan[$item->stitem_id]['in_stock'] = $stitem->currentBalance();
             $itemplan[$item->stitem_id]['required'] = 0;
             $itemplan[$item->stitem_id]['on_order']['po_value'] = 0;
             $itemplan[$item->stitem_id]['on_order']['wo_value'] = 0;
             $porders = $stitem->getPOrderLines();
             foreach ($porders as $porder) {
                 $itemplan[$item->stitem_id]['on_order']['po_value'] += round($stitem->convertToUoM($porder->stuom_id, $stitem->uom_id, $porder->os_qty), $stitem->qty_decimals);
             }
             $sorders = $stitem->getSOrderLines();
             foreach ($sorders as $sorder) {
                 $itemplan[$item->stitem_id]['required'] += round($stitem->convertToUoM($sorder->stuom_id, $stitem->uom_id, $sorder->os_qty), $stitem->qty_decimals);
             }
             $worders = $stitem->getWorkOrders();
             foreach ($worders as $worder) {
                 $itemplan[$item->stitem_id]['on_order']['wo_value'] += round($worder->order_qty - $worder->made_qty < 0 ? 0 : $worder->order_qty - $worder->made_qty, $stitem->qty_decimals);
             }
             $salelocations = WHLocation::getSaleLocations();
             if (empty($salelocations)) {
                 $itemplan[$item->stitem_id]['for_sale'] = 0;
             } else {
                 $cc = new ConstraintChain();
                 $cc->add(new Constraint('stitem_id', '=', $item->stitem_id));
                 $cc->add(new Constraint('whlocation_id', 'in', '(' . implode(',', $salelocations) . ')'));
                 $itemplan[$item->stitem_id]['for_sale'] = STBalance::getBalances($cc);
             }
             $itemplan[$item->stitem_id]['in_stock'] -= $itemplan[$item->stitem_id]['for_sale'];
             $itemplan[$item->stitem_id]['actual_shortfall'] = $itemplan[$item->stitem_id]['required'] - ($itemplan[$item->stitem_id]['for_sale'] + $itemplan[$item->stitem_id]['in_stock']);
             $itemplan[$item->stitem_id]['shortfall'] = $itemplan[$item->stitem_id]['actual_shortfall'] - $itemplan[$item->stitem_id]['on_order']['po_value'] - $itemplan[$item->stitem_id]['on_order']['wo_value'];
             $itemplan[$item->stitem_id]['indicator'] = 'green';
             if ($itemplan[$item->stitem_id]['actual_shortfall'] <= 0) {
                 $itemplan[$item->stitem_id]['actual_shortfall'] = 0;
             } else {
                 $itemplan[$item->stitem_id]['indicator'] = 'amber';
             }
             if ($itemplan[$item->stitem_id]['shortfall'] <= 0) {
                 $itemplan[$item->stitem_id]['shortfall'] = 0;
             } else {
                 $itemplan[$item->stitem_id]['indicator'] = 'red';
             }
         }
     }
     return $itemplan;
 }
Esempio n. 9
0
 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);
     }
 }
Esempio n. 10
0
 public function viewByOrders()
 {
     $cc = new ConstraintChain();
     if (isset($this->_data['id'])) {
         $id = $this->_data['id'];
         $cc->add(new Constraint('stitem_id', '=', $id));
     } elseif (isset($this->_data['order_id'])) {
         $order_id = $this->_data['order_id'];
         $cc->add(new Constraint('order_id', '=', $order_id));
     } else {
         $cc->add(new Constraint('type', '=', 'O'));
     }
     $cc->add(new Constraint('status', '=', 'R'));
     $order = new SOrderCollection();
     $order->orderby = array('delivery_note', 'order_number', 'line_number');
     $order->direction = array('ASC', 'ASC', 'ASC');
     $orders = $order->getItemOrders($cc);
     // Create an array of items ordered
     $stitems = array();
     foreach ($orders as $row) {
         $stitems[$row->stitem_id]['in_stock'] = 0;
         if (!isset($stitems[$row->stitem_id]['despatch_action'][$row->despatch_action])) {
             $transferrules = new WHTransferruleCollection(DataObjectFactory::Factory('WHTransferrule'));
             $locations = $transferrules->getFromLocations($row->despatch_action);
             if (count($locations) > 0 and $row->stitem_id) {
                 // Should never be zero or somethingis very wrong!
                 $cc = new ConstraintChain();
                 $cc->add(new Constraint('stitem_id', '=', $row->stitem_id));
                 $cc->add(new Constraint('whlocation_id', 'in', '(' . implode(',', array_keys($locations)) . ')'));
                 $stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] = STBalance::getBalances($cc);
             } else {
                 $stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] = 0;
                 // Flag it as a non-stock item
                 $stitems[$row->stitem_id]['non-stock'] = true;
             }
         }
     }
     // And check orders for stock availability
     // Items not available cannot be despatched!
     $items = array();
     foreach ($orders as $key => $row) {
         // Exclude any order lines that cannot be fulfilled
         // or have already been despatched
         $stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] -= $row->required;
         $sorder = DataObjectFactory::Factory('SOrder');
         $sorder->load($row->order_id);
         $items[$row->order_number]['order_number'] = $row->order_number;
         $items[$row->order_number]['order_id'] = $row->order_id;
         $items[$row->order_number]['customer'] = $row->customer;
         $items[$row->order_number]['del_address'] = $sorder->del_address->address;
         if ($stitems[$row->stitem_id]['non-stock']) {
             $items[$row->order_number]['line_number'][$row->line_number]['despatch'] = true;
         } elseif ($stitems[$row->stitem_id]['despatch_action'][$row->despatch_action] >= 0) {
             $items[$row->order_number]['line_number'][$row->line_number]['despatch'] = true;
         } else {
             $items[$row->order_number]['line_number'][$row->line_number]['despatch'] = false;
         }
         $items[$row->order_number]['line_number'][$row->line_number]['despatch_action'] = $row->despatch_action;
         $items[$row->order_number]['due_despatch_date'] = $row->due_despatch_date;
         $items[$row->order_number]['line_number'][$row->line_number]['stitem'] = $row->stitem;
         $items[$row->order_number]['line_number'][$row->line_number]['item_description'] = $row->item_description;
         $items[$row->order_number]['line_number'][$row->line_number]['delivery_note'] = $row->delivery_note;
         $items[$row->order_number]['line_number'][$row->line_number]['required'] = $row->required;
         $items[$row->order_number]['line_number'][$row->line_number]['stuom'] = $row->stuom;
         $items[$row->order_number]['line_number'][$row->line_number]['id'] = $row->id;
     }
     $this->view->set('orders', $items);
     $sidebar = new SidebarController($this->view);
     $actions = array();
     $actions['viewnotes'] = array('link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'index')), 'tag' => 'view despatch notes');
     $sidebar->addList('Actions', $actions);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     $this->view->set('page_title', $this->getPageName('Despatch', 'View Order Lines for'));
 }
Esempio n. 11
0
 public function viewByOrders()
 {
     $cc = new ConstraintChain();
     $cc->add(new Constraint('type', '=', 'O'));
     if (isset($this->_data['id'])) {
         $id = $this->_data['id'];
         $cc->add(new Constraint('stitem_id', '=', $id));
     }
     $order = new SOrderCollection($this->_templateobject);
     $order->orderby = array('status', 'due_despatch_date', 'order_number');
     $order->direction = array('DESC', 'ASC');
     $orders = $order->getItemOrders($cc);
     // Create an array of items ordered
     $stitems = array();
     foreach ($orders as $row) {
         // ignore PLs without stitem
         if ($row->stitem_id) {
             $stitems[$row->stitem_id]['shortfall'] = 0;
         }
     }
     // Now get the balance for each item across all saleable locations
     foreach ($stitems as $key => $item) {
         $cc = new ConstraintChain();
         $cc->add(new Constraint('stitem_id', '=', $key));
         $stitems[$key]['in_stock'] = STBalance::getBalances($cc);
         $salelocations = WHLocation::getSaleLocations();
         if (empty($salelocations)) {
             $stitems[$key]['for_sale'] = 0;
         } else {
             $cc->add(new Constraint('whlocation_id', 'in', '(' . implode(',', $salelocations) . ')'));
             $stitems[$key]['for_sale'] = STBalance::getBalances($cc);
         }
         $stitems[$key]['in_stock'] -= $stitems[$key]['for_sale'];
         $stitems[$key]['total_orders'] = 0;
     }
     // And finally update the orders with the projected stock balances
     $items = array();
     foreach ($orders as $key => $row) {
         // echo 'count '.$row->id.' - '.SOrder::lineExistsInDespatchLines($row->id).'<br>';
         $items[$key]['id'] = $row->id;
         $items[$key]['stitem_id'] = $row->stitem_id;
         $items[$key]['stitem'] = $row->stitem;
         $items[$key]['item_description'] = $row->item_description;
         $items[$key]['productline_id'] = $row->productline_id;
         $items[$key]['required'] = $row->required;
         $items[$key]['due_despatch_date'] = $row->due_despatch_date;
         $items[$key]['order_number'] = $row->order_number;
         $items[$key]['order_id'] = $row->order_id;
         $items[$key]['customer'] = $row->customer;
         $items[$key]['slmaster_id'] = $row->slmaster_id;
         $items[$key]['stuom'] = $row->stuom;
         $items[$key]['for_sale'] = $stitems[$row->stitem_id]['for_sale'];
         $items[$key]['shortfall'] = 0;
         // ignore PLs without stitem
         if ($row->stitem_id) {
             $cc = new ConstraintChain();
             $cc->add(new Constraint('stitem_id', '=', $row->stitem_id));
             $cc->add(new Constraint('required_by', '<=', $row->due_despatch_date));
             $worders = MFWorkorder::getBalances($cc);
             if ($worders) {
                 $stitems[$row->stitem_id]['on_order'] = $worders[0]['sumbalance'] - $stitems[$row->stitem_id]['total_orders'];
                 $stitems[$row->stitem_id]['total_orders'] = $worders[0]['sumbalance'];
             } else {
                 $stitems[$row->stitem_id]['on_order'] = 0;
             }
         }
         $on_order = $stitems[$row->stitem_id]['on_order'];
         $items[$key]['on_order'] = $stitems[$row->stitem_id]['on_order'];
         $stitems[$row->stitem_id]['for_sale'] -= $items[$key]['required'];
         if ($stitems[$row->stitem_id]['for_sale'] < 0) {
             $stitems[$row->stitem_id]['in_stock'] += $stitems[$row->stitem_id]['for_sale'];
             $stitems[$row->stitem_id]['for_sale'] = 0;
         }
         $stitems[$row->stitem_id]['in_stock'] = $stitems[$row->stitem_id]['in_stock'] - $stitems[$row->stitem_id]['shortfall'] + $stitems[$row->stitem_id]['on_order'];
         // $stitems[$row->stitem_id]['in_stock']=$stitems[$row->stitem_id]['in_stock']-$stitems[$row->stitem_id]['shortfall'];
         if ($stitems[$row->stitem_id]['in_stock'] < 0) {
             $stitems[$row->stitem_id]['shortfall'] -= $stitems[$row->stitem_id]['in_stock'];
             $stitems[$row->stitem_id]['in_stock'] = 0;
             $items[$key]['shortfall'] = $stitems[$row->stitem_id]['shortfall'] < $on_order ? 0 : $stitems[$row->stitem_id]['shortfall'] - $on_order;
             // $items[$key]['shortfall']=$stitems[$row->stitem_id]['shortfall'];
         } else {
             $stitems[$row->stitem_id]['shortfall'] = 0;
         }
         $items[$key]['in_stock'] = $stitems[$row->stitem_id]['in_stock'];
         if (!empty($row->delivery_note)) {
             $items[$key]['status'] = 'Awaiting Despatch';
         } elseif ($row->status == 'R') {
             $items[$key]['status'] = 'Ready for Despatch';
         } else {
             $items[$key]['status'] = '';
         }
         $items[$key]['account_status'] = $row->account_status;
         $items[$key]['despatch_number'] = SOrder::lineExistsInDespatchLines($row->id);
         if ($row->status == 'R') {
             $items[$key]['despatch'] = true;
         } else {
             $items[$key]['despatch'] = false;
         }
     }
     $this->view->set('orders', $items);
     $sidebar = new SidebarController($this->view);
     $actions = array();
     $actions['allcustomer'] = array('link' => array('module' => 'sales_ledger', 'controller' => 'SLCustomers', 'action' => 'index'), 'tag' => 'view all customers');
     $actions['newquote'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'new', 'type' => 'Q'), 'tag' => 'new quote');
     $actions['neworder'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'new', 'type' => 'O'), 'tag' => 'new order');
     $actions['vieworder'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index'), 'tag' => 'view quotes/orders');
     $actions['viewdespatches'] = array('link' => array('module' => 'despatch', 'controller' => 'sodespatchlines', 'action' => 'viewByOrders'), 'tag' => 'view despatches');
     $sidebar->addList('Actions', $actions);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
     $this->view->set('page_title', $this->getPageName('', 'View availability by'));
 }