Exemple #1
0
 public function view()
 {
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $whbin = $this->_uses[$this->modeltype];
     $id = $whbin->id;
     $this->view->set('transaction', $whbin);
     $whlocation = new WHLocation();
     $whlocation->load($whbin->whlocation_id);
     $this->view->set('whstore', $whlocation->whstore);
     $sidebar = new SidebarController($this->view);
     $sidebarlist = array();
     $sidebarlist['stores'] = array('tag' => 'All Stores', 'link' => array_merge($this->_modules, array('controller' => 'WHStores', 'action' => 'index')));
     $sidebarlist['locations'] = array('tag' => 'Locations for Store ' . $whlocation->whstore, 'link' => array_merge($this->_modules, array('controller' => 'WHLocations', 'action' => 'index', 'id' => $whbin->whlocation_id)));
     $sidebarlist['bins'] = array('tag' => 'Bins for Location ' . $whlocation->getIdentifierValue(), 'link' => array_merge($this->_modules, array('controller' => 'WHLocations', 'action' => 'view', 'id' => $whbin->whlocation_id)));
     $sidebar->addList('Show', $sidebarlist);
     $sidebarlist = array();
     $sidebarlist['edit'] = array('tag' => 'Edit', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'edit', 'id' => $id, 'whlocation_id' => $whbin->whlocation_id)));
     // Do not allow delete if balances exist
     if ($whbin->balances->count() === 0) {
         $sidebarlist['delete'] = array('tag' => 'Delete', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'delete', 'id' => $id, 'whlocation_id' => $whbin->whlocation_id)));
     }
     $sidebar->addList('This Bin', $sidebarlist);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }
 public function index()
 {
     $flash = Flash::Instance();
     // Preserve any search criteria selection so that the context is maintained
     $s_data = array();
     if (isset($this->_data['id'])) {
         $s_data['wh_transfer_id'] = $this->_data['id'];
     }
     $this->view->set('clickaction', 'view');
     $whtransfer = new WHTransfer();
     $whtransfer->load($this->_data['id']);
     $this->view->set('whtransfer', $whtransfer);
     $from_store = WHLocation::getStoreLocation($whtransfer->from_whlocation_id);
     $this->view->set('from_store', $from_store);
     $to_store = WHLocation::getStoreLocation($whtransfer->to_whlocation_id);
     $this->view->set('to_store', $to_store);
     $this->setSearch('whtransfersSearch', 'useDefault', $s_data);
     parent::index(new WHTransferlineCollection($this->_templateobject));
     $sidebar = new SidebarController($this->view);
     $sidebarlist = array();
     $sidebarlist['all'] = array('tag' => 'View All Transfers', 'link' => array_merge($this->_modules, array('controller' => 'WHTransfers', 'action' => 'index')));
     if ($whtransfer->awaitingTransfer()) {
         $sidebarlist['edit'] = array('tag' => 'Edit this Transfer', 'link' => array_merge($this->_modules, array('controller' => 'WHTransfers', 'action' => 'edit', 'id' => $whtransfer->id)));
         $sidebarlist['cancel'] = array('tag' => 'Cancel this Transfer', 'link' => array_merge($this->_modules, array('controller' => 'WHTransfers', 'action' => 'cancel', 'id' => $whtransfer->id)));
     }
     $sidebar->addList('Actions', $sidebarlist);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }
 public function view()
 {
     $flash = Flash::Instance();
     // Preserve any search criteria selection so that the context is maintained
     $s_data = array();
     if (isset($this->_data['id'])) {
         $s_data['wh_transfer_id'] = $this->_data['id'];
     }
     $whtransfer = new WHTransfer();
     $whtransfer->load($this->_data['id']);
     $this->view->set('whtransfer', $whtransfer);
     $from_store = WHLocation::getStoreLocation($whtransfer->from_whlocation_id);
     $this->view->set('from_store', $from_store);
     $to_store = WHLocation::getStoreLocation($whtransfer->to_whlocation_id);
     $this->view->set('to_store', $to_store);
     $this->setSearch('whtransfersSearch', 'useDefault', $s_data);
     parent::index(new WHTransferlineCollection($this->_templateobject));
     $sidebar = new SidebarController($this->view);
     $sidebarlist = array();
     $sidebarlist['awaiting'] = array('link' => array_merge($this->_modules, array('controller' => 'WHTransfers', 'action' => 'selectWHTransfers')), 'tag' => 'View Transfers Awaiting Despatch');
     $sidebarlist['completed'] = array('link' => array_merge($this->_modules, array('controller' => 'WHTransfers', 'action' => 'viewWHTransfers')), 'tag' => 'View Completed Transfers');
     if ($whtransfer->awaitingTransfer()) {
         $sidebarlist['edit'] = array('link' => array_merge($this->_modules, array('controller' => 'WHTransfers', 'action' => 'transferStock', 'id' => $whtransfer->id)), 'tag' => 'Action this Transfer');
     }
     if ($whtransfer->transferred()) {
         $sidebarlist['edit'] = array('link' => array_merge($this->_modules, array('controller' => 'WHTransfers', 'action' => 'printaction', 'printaction' => 'printTransferNote', 'filename' => 'WHT' . $whtransfer->transfer_number, 'id' => $whtransfer->id)), 'tag' => 'Reprint Transfer Note');
     }
     $sidebar->addList('Actions', $sidebarlist);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }
 public function view()
 {
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $transaction = $this->_uses[$this->modeltype];
     $id = $transaction->id;
     $this->view->set('transaction', $transaction);
     $from_store = WHLocation::getStoreLocation($transaction->from_whlocation_id);
     $this->view->set('from_store', $from_store);
     $to_store = WHLocation::getStoreLocation($transaction->to_whlocation_id);
     $this->view->set('to_store', $to_store);
     $sidebar = new SidebarController($this->view);
     $sidebar->addList('Show', array('all' => array('tag' => 'All rules for Action', 'link' => array_merge($this->_modules, array('controller' => 'WHActions', 'action' => 'view', 'id' => $transaction->whaction_id)))));
     $sidebar->addList('This Rule', array('edit' => array('tag' => 'Edit', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'edit', 'id' => $id))), 'delete' => array('tag' => 'Delete', 'link' => array_merge($this->_modules, array('controller' => $this->name, 'action' => 'delete', 'id' => $id, 'whaction_id' => $transaction->whaction_id)))));
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }
 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 getBinList($_whlocation_id = '')
 {
     // used by ajax to get a list of bins for a location
     if (isset($this->_data['ajax'])) {
         if (!empty($this->_data['whlocation_id'])) {
             $_whlocation_id = $this->_data['whlocation_id'];
         }
     }
     $location = new WHLocation();
     $location->load($_whlocation_id);
     $bins = $location->getBinList();
     if (isset($this->_data['ajax'])) {
         $this->view->set('options', $bins);
         $this->setTemplateName('select_options');
     } else {
         return $bins;
     }
 }
 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;
 }
Exemple #8
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'));
 }