app->l11nManager, $request, $response); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1003203001, $request, $response); $view->attributes = SupplierAttributeTypeMapper::getAll() ->with('l11n') ->where('l11n/language', $response->header->l11n->language) ->execute(); $view->path = 'purchase/supplier'; return $view; } /** * Routing end-point for application behavior. * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response * @param array $data Generic data * * @return RenderableInterface * * @since 1.0.0 * @codeCoverageIgnore */ public function viewSupplierManagementAttributeValues(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/attribute-value-list'); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1003203001, $request, $response); /** @var \Modules\Attribute\Models\AttributeValue[] $attributes */ $attributes = SupplierAttributeValueMapper::getAll() ->with('l11n') ->where('l11n/language', $response->header->l11n->language) ->execute(); $view->data['attributes'] = $attributes; return $view; } /** * Routing end-point for application behavior. * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response * @param array $data Generic data * * @return RenderableInterface * * @since 1.0.0 * @codeCoverageIgnore */ public function viewSupplierManagementAttributeType(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface { $view = new \Modules\Attribute\Theme\Backend\Components\AttributeTypeView($this->app->l11nManager, $request, $response); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1003203001, $request, $response); $view->attribute = SupplierAttributeTypeMapper::get() ->with('l11n') ->with('defaults') ->with('defaults/l11n') ->where('id', (int) $request->getData('id')) ->where('l11n/language', $response->header->l11n->language) ->where('defaults/l11n/language', [$response->header->l11n->language, null]) ->execute(); $view->l11ns = SupplierAttributeTypeL11nMapper::getAll() ->where('ref', $view->attribute->id) ->execute(); $view->path = 'purchase/supplier'; return $view; } /** * Routing end-point for application behavior. * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response * @param array $data Generic data * * @return RenderableInterface * * @since 1.0.0 * @codeCoverageIgnore */ public function viewSupplierManagementAttributeValue(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface { $view = new \Modules\Attribute\Theme\Backend\Components\AttributeValueView($this->app->l11nManager, $request, $response); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1003203001, $request, $response); $view->attribute = SupplierAttributeValueMapper::get() ->with('l11n') ->where('id', (int) $request->getData('id')) ->where('l11n/language', [$response->header->l11n->language, null]) ->execute(); $view->l11ns = SupplierAttributeValueL11nMapper::getAll() ->where('ref', $view->attribute->id) ->execute(); // @todo Also find the ItemAttributeType return $view; } /** * Routing end-point for application behavior. * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response * @param array $data Generic data * * @return RenderableInterface * * @since 1.0.0 * @codeCoverageIgnore */ public function viewSupplierManagementSupplierList(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/supplier-list'); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1003202001, $request, $response); $supplier = SupplierMapper::getAll() ->with('account') ->with('mainAddress') ->where('unit', $this->app->unitId) ->limit(25) ->execute(); $view->data['supplier'] = $supplier; return $view; } /** * Routing end-point for application behavior. * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response * @param array $data Generic data * * @return RenderableInterface * * @since 1.0.0 * @codeCoverageIgnore */ public function viewSupplierManagementSupplierCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/supplier-create'); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1003202001, $request, $response); return $view; } /** * Routing end-point for application behavior. * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response * @param array $data Generic data * * @return RenderableInterface * * @since 1.0.0 * @codeCoverageIgnore */ public function viewSupplierManagementSupplierView(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface { $head = $response->data['Content']->head; $nonce = $this->app->appSettings->getOption('script-nonce'); $head->addAsset(AssetType::CSS, 'Resources/chartjs/chart.css?v=' . $this->app->version); $head->addAsset(AssetType::JSLATE, 'Resources/chartjs/chart.js?v=' . $this->app->version, ['nonce' => $nonce]); $head->addAsset(AssetType::JSLATE, 'Resources/OpenLayers/OpenLayers.js?v=' . $this->app->version, ['nonce' => $nonce]); $head->addAsset(AssetType::JSLATE, 'Modules/ClientManagement/Controller.js?v=' . self::VERSION, ['nonce' => $nonce, 'type' => 'module']); $view = new View($this->app->l11nManager, $request, $response); $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/supplier-view'); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1003202001, $request, $response); /** @var \Modules\SupplierManagement\Models\Supplier $supplier */ $supplier = SupplierMapper::get() ->with('account') ->with('contactElements') ->with('mainAddress') ->with('files')->limit(5, 'files')->sort('files/id', OrderType::DESC) ->with('notes')->limit(5, 'notes')->sort('notes/id', OrderType::DESC) ->where('id', (int) $request->getData('id')) ->execute(); $view->data['supplier'] = $supplier; // Get item profile image // @feature Create a new read mapper function that returns relation models instead of its own model // https://github.com/Karaka-Management/phpOMS/issues/320 $query = new Builder($this->app->dbPool->get()); $results = $query->selectAs(SupplierMapper::HAS_MANY['files']['external'], 'file') ->from(SupplierMapper::TABLE) ->leftJoin(SupplierMapper::HAS_MANY['files']['table']) ->on(SupplierMapper::HAS_MANY['files']['table'] . '.' . SupplierMapper::HAS_MANY['files']['self'], '=', SupplierMapper::TABLE . '.' . SupplierMapper::PRIMARYFIELD) ->leftJoin(MediaMapper::TABLE) ->on(SupplierMapper::HAS_MANY['files']['table'] . '.' . SupplierMapper::HAS_MANY['files']['external'], '=', MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD) ->leftJoin(MediaMapper::HAS_MANY['types']['table']) ->on(MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD, '=', MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['self']) ->leftJoin(MediaTypeMapper::TABLE) ->on(MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['external'], '=', MediaTypeMapper::TABLE . '.' . MediaTypeMapper::PRIMARYFIELD) ->where(SupplierMapper::HAS_MANY['files']['self'], '=', $supplier->id) ->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'supplier_profile_image'); $clientImage = MediaMapper::get() ->where('id', $results) ->limit(1) ->execute(); $view->data['clientImage'] = $clientImage; // stats if ($this->app->moduleManager->isActive('Billing')) { $ytd = PurchaseBillMapper::getPurchaseBySupplierId($supplier->id, new SmartDateTime('Y-01-01'), new SmartDateTime('now')); $mtd = PurchaseBillMapper::getPurchaseBySupplierId($supplier->id, new SmartDateTime('Y-m-01'), new SmartDateTime('now')); $lastOrder = PurchaseBillMapper::getLastOrderDateBySupplierId($supplier->id); $newestInvoices = PurchaseBillMapper::getAll()->with('supplier')->where('supplier', $supplier->id)->sort('id', OrderType::DESC)->limit(5)->execute(); $monthlyPurchaseCosts = PurchaseBillMapper::getSupplierMonthlyPurchaseCosts($supplier->id, (new SmartDateTime('now'))->createModify(-1), new SmartDateTime('now')); } else { $ytd = new Money(); $mtd = new Money(); $lastOrder = null; $newestInvoices = []; $monthlyPurchaseCosts = []; } $view->data['ytd'] = $ytd; $view->data['mtd'] = $mtd; $view->data['lastOrder'] = $lastOrder; $view->data['newestInvoices'] = $newestInvoices; $view->data['monthlyPurchaseCosts'] = $monthlyPurchaseCosts; return $view; } /** * Routing end-point for application behavior. * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response * @param array $data Generic data * * @return RenderableInterface * * @since 1.0.0 * @codeCoverageIgnore */ public function viewSupplierManagementSupplierAnalysis(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface { return new View($this->app->l11nManager, $request, $response); } }