function populate() { $sttransactions = new STTransactionCollection(); $sttransactions->setParams(); $sh = new SearchHandler($sttransactions, false); $sh->addConstraint(new Constraint('status', '=', 'E')); $cc = new ConstraintChain(); $cc->add(new Constraint('error_qty', '<', 0)); $cc->add(new Constraint('qty', '<', 0), 'OR'); $sh->addConstraintChain($cc); $this->setSearchLimit($sh); $sh->setOrderBy('created', 'DESC'); $sttransactions->load($sh); $this->contents = $sttransactions; }
public function viewTransactions() { $s_data = array(); if (isset($this->_data['id'])) { $id = $this->_data['id']; $s_data['whlocation_id'] = $id; } elseif (isset($this->_data['Search']['whlocation_id'])) { $id = $this->_data['Search']['whlocation_id']; $s_data['whlocation_id'] = $id; } if (isset($this->_data['stitem_id'])) { $s_data['stitem_id'] = $this->_data['stitem_id']; } elseif (isset($this->_data['Search']['stitem_id'])) { $s_data['stitem_id'] = $this->_data['Search']['stitem_id']; } if (!isset($this->_data['stitem_id'])) { $s_data['created']['from'] = date(DATE_FORMAT, strtotime('-7 days')); $s_data['created']['to'] = date(DATE_FORMAT); } $this->setSearch('whlocationsSearch', 'transactions', $s_data); $id = $this->search->getValue('whlocation_id'); $item = $this->search->getValue('stitem_id'); $showbalances = $this->search->getValue('balance'); $location = $this->_templateobject; $location->load($id); $this->view->set('location', $location); $sttransactions = new STTransactionCollection(); if (!isset($this->_data['orderby']) && !isset($this->_data['page'])) { $sh = new SearchHandler($sttransactions, FALSE); $cc = $this->search->toConstraintChain(); $sh->addConstraintChain($cc); } else { $sh = new SearchHandler($sttransactions); } $sh->extract(); if (isset($this->search) && ($this->isPrintDialog() || $this->isPrinting())) { if (!$this->isPrinting()) { return $this->printCollection(); } else { $sh->setLimit(0); $sttransactions->load($sh); return $this->printCollection($sttransactions); } } else { $sttransactions->load($sh); } $this->view->set('sttransactions', $sttransactions); $this->view->set('clickaction', 'view'); $this->view->set('clickcontroller', 'STItems'); $this->view->set('linkfield', 'id'); $this->view->set('linkvaluefield', 'stitem_id'); $this->view->set('num_records', $sttransactions->num_records); $this->view->set('num_pages', $sttransactions->num_pages); $this->view->set('cur_page', $sttransactions->cur_page); $this->view->set('no_ordering', TRUE); $sidebar = new SidebarController($this->view); $sidebarlist = array(); $sidebarlist['stores'] = array('tag' => 'All Stores', 'link' => array('modules' => $this->_modules, 'controller' => 'WHStores', 'action' => 'index')); $sidebarlist['locations'] = array('tag' => 'Locations for Store ' . $location->whstore, 'link' => array('modules' => $this->_modules, 'controller' => 'WHStores', 'action' => 'view', 'id' => $location->whstore_id)); $sidebarlist['thisLocation'] = array('tag' => 'Location Detail', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'view', 'id' => $location->id)); $sidebar->addList('Show', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
public function viewTransactions() { $s_data = array(); if (isset($this->_data['id'])) { $s_data['whbin_id'] = $id = $this->_data['id']; } elseif (isset($this->_data['Search']['whbin_id'])) { $s_data['whbin_id'] = $id = $this->_data['Search']['whbin_id']; } if (isset($this->_data['stitem_id'])) { $s_data['stitem_id'] = $this->_data['stitem_id']; } elseif (isset($this->_data['Search']['stitem_id'])) { $s_data['stitem_id'] = $this->_data['Search']['stitem_id']; } if (!isset($this->_data['stitem_id'])) { $s_data['created']['from'] = date(DATE_FORMAT, strtotime('-7 days')); $s_data['created']['to'] = date(DATE_FORMAT); } $this->setSearch('whbinsSearch', 'transactions', $s_data); $id = $this->search->getValue('whbin_id'); $item = $this->search->getValue('stitem_id'); $showbalances = $this->search->getValue('balance'); $bin = $this->_templateobject; $bin->load($id); $this->view->set('bin', $bin); $sttransactions = new STTransactionCollection(); if (!isset($this->_data['orderby']) && !isset($this->_data['page'])) { $sh = new SearchHandler($sttransactions, false); $cc = $this->search->toConstraintChain(); $sh->addConstraintChain($cc); } else { $sh = new SearchHandler($sttransactions); } $sh->extract(); if (isset($this->search) && ($this->isPrintDialog() || $this->isPrinting())) { if (!$this->isPrinting()) { return $this->printCollection(); } else { $sh->setLimit(0); $sttransactions->load($sh); return $this->printCollection($sttransactions); } } else { $sttransactions->load($sh); } $this->view->set('sttransactions', $sttransactions); $this->view->set('clickaction', 'view'); $this->view->set('clickcontroller', 'STItems'); $this->view->set('linkfield', 'id'); $this->view->set('linkvaluefield', 'stitem_id'); $this->view->set('num_pages', $sttransactions->num_pages); $this->view->set('cur_page', $sttransactions->cur_page); $this->view->set('no_ordering', true); $this->view->set('page_title', $this->getPageName('', 'View Transactions for')); $sidebar = new SidebarController($this->view); $whlocation = $this->getLocation($bin->whlocation_id); $sidebarlist = $this->setGeneralSidebar($whlocation, $bin); $sidebar->addList('Show', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
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; } }