public function view() { if (!$this->loadData()) { $this->dataError(); sendBack(); } $transaction = $this->_uses[$this->modeltype]; $id = $transaction->id; $this->view->set('transaction', $transaction); $obsolete = $transaction->isObsolete(); $chain = new ConstraintChain(); $chain->add(new Constraint('stitem_id', '=', $transaction->id)); $transaction->balance = STBalance::getBalances($chain); $sidebar = new SidebarController($this->view); $sidebar->addList('Show', array('stores' => array('tag' => 'All Items', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index')))); $sidebarlist = array(); $sidebarlist['view'] = array('tag' => $transaction->getIdentifierValue(), 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'view', 'id' => $id)); $sidebarlist['edit'] = array('tag' => 'Edit', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'edit', 'id' => $id)); // Only allow delete if no foreign key rows exist $delete = true; foreach ($transaction->getHasMany() as $name => $hasmany) { if ($transaction->{$name}->count() > 0) { $delete = false; break; } } if ($delete) { $sidebarlist['delete'] = array('tag' => 'Delete', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'delete', 'id' => $id)); } $sidebarlist['cost_sheet'] = array('tag' => 'Show Cost Sheet', 'link' => array('module' => 'costing', 'controller' => 'STCosts', 'action' => 'costSheet', 'stitem_id' => $id)); $sidebarlist['cost_history'] = array('tag' => 'Show Cost History', 'link' => array('module' => 'costing', 'controller' => 'STCosts', 'action' => 'index', 'stitem_id' => $id)); if ($transaction->po_products->count() > 0 || $transaction->workorders->count() > 0 || $transaction->wo_structures->count() > 0) { $sidebarlist['po_supply'] = array('tag' => 'Purchasing Supply/Demand', 'link' => array('module' => 'purchase_order', 'controller' => 'poproductlineheaders', 'action' => 'viewbydates', 'id' => $id)); } if ($transaction->so_products->count() > 0) { $sidebarlist['so_supply'] = array('tag' => 'Sales Supply/Demand', 'link' => array('module' => 'sales_order', 'controller' => 'soproductlineheaders', 'action' => 'viewbydates', 'id' => $id)); } if ($transaction->comp_class != 'B') { $sidebarlist['preorder'] = array('tag' => 'Pre-Order Requirements', 'link' => array('modules' => $this->_modules, 'controller' => 'MFStructures', 'action' => 'preorder', 'stitem_id' => $id)); } $sidebarlist[] = 'spacer'; $sidebarlist['cloneitem'] = array('tag' => 'Clone Item', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'clone_item', 'id' => $id)); $sidebarlist[] = 'spacer'; if (!$obsolete) { $sidebarlist['mark_obsolete'] = array('tag' => 'Mark As Obsolete', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'markObsolete', 'id' => $id)); } $sidebar->addList('This Item', $sidebarlist); $this->sidebarRelatedItems($sidebar, $transaction); $sidebar->addList('related_items', array('documents' => array('tag' => 'Show Documents', 'link' => array('modules' => $this->_modules, 'controller' => 'attachments', 'action' => 'index', 'entity_id' => $id, 'data_model' => strtolower($this->modeltype)), 'new' => array('modules' => $this->_modules, 'controller' => 'attachments', 'action' => 'new', 'entity_id' => $id, 'data_model' => strtolower($this->modeltype))))); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
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; }
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')); }
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); } }
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')); }