public function indexAction() { $request = $this->getRequest(); if (!$request instanceof ConsoleRequest) { throw new \RuntimeException('You can only use this action from a console!'); } $serviceLocator = $this->getServiceLocator(); $dbCheck = $serviceLocator->get('DbCheck'); if ($dbCheck['dbConnect'] !== false) { $productsModel = new ProductsModel($serviceLocator); } $params = $request->getParams()->toArray(); $products = array(); for ($i = 1; $i <= 5; $i++) { $products[$i] = $this->sanitize($params['arg' . $i]); } if (isset($params['ps'])) { $params['ps'] = (int) $params['ps']; } else { $params['ps'] = 0; } if ($params['ps'] <= 0) { $params['ps'] = 1; } $params['ps'] = 'P' . $params['ps']; $params['name'] = (bool) $params['name']; $params['id'] = (bool) $params['id']; if ($params['name'] !== false) { $checkType = "by Product's name"; $productsTitle = "Product names"; $field = 'ProductName'; } elseif ($params['id'] !== false) { $checkType = "by Product's database ID"; $productsTitle = "Product ids"; $field = 'ID'; } else { $checkType = "by Product's warehouse location"; $productsTitle = "Warehouse locations"; $field = 'WarehouseLocation'; $mapCallback = 'strtoupper'; } // elseif $return = ""; $return .= PHP_EOL; $return .= "Route calculator"; $return .= PHP_EOL; $return .= $this->sep; $return .= "Check type:" . $this->getTab(2) . $checkType; $return .= PHP_EOL . PHP_EOL; $return .= "Picking station:" . $this->getTab() . $params['ps']; $return .= PHP_EOL . PHP_EOL; $return .= $productsTitle . " (user entry):"; $return .= PHP_EOL; for ($i = 1; $i <= 5; $i++) { $return .= $this->getTab(3) . $i . ' - '; if (isset($mapCallback) && !empty($mapCallback)) { $return .= $mapCallback($params['arg' . $i]); } else { $return .= $params['arg' . $i]; } $return .= PHP_EOL; } // for $return .= PHP_EOL; if ($dbCheck['dbConnect'] === false) { $return .= $this->raiseError("A database connection cannot be established." . PHP_EOL . "\tPlease check your database connection settings."); return $return; } // if if (isset($mapCallback) && !empty($mapCallback)) { $products = array_map($mapCallback, $products); } $productsDB = $productsModel->getProductsIdNameLocation($products, $field); if (count($productsDB) != 5) { $return .= $this->raiseError('Some of the entered parameters doesn\'t corespond to the database products.'); return $return; } // if $return .= PHP_EOL; $return .= "Calculated route:"; $return .= PHP_EOL; $return .= $this->getTab(3) . "1 -" . $this->getTab() . "Start from picking station " . $params['ps']; $return .= PHP_EOL . PHP_EOL; $productsIDsDB = array_column($productsDB, 'ID'); $productsNamesDB = array_column($productsDB, 'ProductName'); $warehouseLocationsDB = array_column($productsDB, 'WarehouseLocation'); $warehouseLocations = array_combine($productsIDsDB, $warehouseLocationsDB); $routeCalculator = new RouteCalculatorLibrary(); $routeCalculator->init($params['ps'], $warehouseLocations); $route = $routeCalculator->getRoute(); $warehouseLocations = array_combine($productsIDsDB, $warehouseLocationsDB); $productsNames = array_combine($productsIDsDB, $productsNamesDB); for ($i = 1; $i <= 5; $i++) { $return .= $this->getTab(3) . ($i + 1) . ' - '; $return .= $this->getTab() . "Warehouse location:" . $this->getTab() . $warehouseLocations[$route[$i - 1]] . PHP_EOL; $return .= $this->getTab(4) . "Product ID:" . $this->getTab(2) . $route[$i - 1] . PHP_EOL; $return .= $this->getTab(4) . "Product name:" . $this->getTab(2) . $productsNames[$route[$i - 1]] . PHP_EOL; $return .= PHP_EOL; } // for $return .= $this->getTab(3) . "7 -" . $this->getTab() . "Back to picking station " . $params['ps']; $return .= PHP_EOL . PHP_EOL; $return .= $this->sep; return $return; }
public function printAction() { $request = $this->getRequest(); $uri = $request->getUriString(); if (strpos($uri, '/print/') !== false) { $startPos = strpos($uri, '/print/') + 7; $orderID = (int) substr($uri, $startPos, strlen($uri) - $startPos); if ($orderID <= 0) { return $this->redirect()->toUrl('/error-404'); } $serviceLocator = $this->getServiceLocator(); $ordersModel = new OrdersModel($serviceLocator); $data['order'] = $ordersModel->getOrderByID($orderID); if (empty($data['order'])) { return $this->redirect()->toUrl('/error-404'); } $productsModel = new ProductsModel($serviceLocator); $data['products'] = $productsModel->getProductsByOrder($orderID); if (count($data['products']) != 5) { return $this->redirect()->toUrl('/error-404'); } } else { return $this->redirect()->toUrl('/error-404'); } // else $this->layout('warehouse/orders/print'); $this->layout()->setVariables($data); }
/** * Resolves all the AJAX calls from the products page * * @return string * */ public function ajaxAction() { $ajax = new AjaxLibrary(); $ajax->init($this->getRequest()); switch ($ajax->getPost('process')) { case 'getProduct': $productID = (int) $ajax->getPost('id'); $productsModel = new ProductsModel($this->getServiceLocator()); $product = $productsModel->getProductByID($productID); echo json_encode($product); exit; break; // getOrderProducts // getOrderProducts case 'setPickingStation': $stationID = (int) $ajax->getPost('id'); $stations = new PickingStationsLibrary($this->getServiceLocator()); $newStation = $stations->getPickingStationByID($stationID); if ($newStation !== false) { echo json_encode($newStation); } else { $ajax->bye(); } exit; break; // setPickingStation // setPickingStation default: $ajax->bye(); break; // default } // switch $ajax->bye(); }