<?php
 namespace VnChocola\Module\Api;
 use TCMS\Module;
 use Route;
 use Model;
 use LayoutData;
 use TCMS\TException;
 class Visitcustomers extends Module {
 protected function initialize() {
 }
 protected function registerRoutes() {
 Route::get('/visit-customers', 'IndexController', 'getList')->name('index');
 Route::get('/visit-customers/findById', 'IndexController', 'findById')->name('findById');
 Route::get('/visit-customers/getVisitToDay', 'IndexController', 'getVisitToDay')->name('getVisitToDay');
 Route::post('/visit-customers/create', 'IndexController', 'create')->name('create');
 Route::post('/visit-customers/update', 'IndexController', 'update')->name('update');
 Route::post('/visit-customers/updateCusSeat', 'IndexController', 'updateCusSeat')->name('updateCusSeat');
 Route::post('/visit-customers/updateCusStatus', 'IndexController', 'updateCusStatus')->name('updateCusStatus');
 Route::post('/visit-customers/updateDrinks', 'IndexController', 'updateDrinks')->name('updateDrinks');
 Route::post('/visit-customers/resetDrinkTime', 'IndexController', 'resetDrinkTime')->name('resetDrinkTime');
 Route::post('/visit-customers/updateCusCompartment', 'IndexController', 'updateCusCompartment')->name('updateCusCompartment');
 Route::post('/visit-customers/delete', 'IndexController', 'delete')->name('delete');
 Route::post('/visit-customers/searchFrm', 'IndexController', 'searchFrm')->name('searchFrm');
 Route::post('/visit-customers/getTimelineData', 'IndexController', 'postGetTimelineData')->name('GetTimelineData');
 Route::post('/visit-customers/kpiServiceAdvisor', 'IndexController', 'kpiServiceAdvisor')->name('kpiServiceAdvisor');
 Route::post('/visit-customers/visitcustomer-dashboard', 'IndexController', 'visitcustomer_dashboard')->name('visitcustomer_dashboard');
 Route::post('/visit-customers/startDownTime', 'IndexController', 'startDownTime')->name('startDownTime');
 Route::post('/visit-customers/stopDownTime', 'IndexController', 'stopDownTime')->name('stopDownTime');
 Route::post('/visit-customers/holdOnCompartment', 'IndexController', 'holdOnCompartment')->name('holdOnCompartment');
 Route::post('/visit-customers/listCustomerVisit', 'IndexController', 'listCustomerVisit')->name('listCustomerVisit');
 }
 public function registerComponent() {
 Model::add('VisitCustomersModel', \VnChocola\Model\VisitCustomersModel::class, true);
 Model::add('ReservesModel', \VnChocola\Model\ReservesModel::class, true);
 Model::add('CarsInfoModel', \VnChocola\Model\CarsInfoModel::class, true);
 Model::add('StaffsModel', \VnChocola\Model\StaffsModel::class, true);
 Model::add('CustomersModel', \VnChocola\Model\CustomersModel::class, true);
 Model::add('PurposesModel', \VnChocola\Model\PurposesModel::class, true);
 Model::add('LoanCarModel', \VnChocola\Model\LoanCarModel::class, true);
 }
 public function boot() {
 }
 public function middleware(string $routeName, $auth) {
 switch ($routeName) {
 case 'visitcustomer_dashboard': case 'searchFrm': case 'GetTimelineData': case 'getVisitToDay': case 'findById': case 'listCustomerVisit': return $auth->hasRole(\RoleGlobal::$role->viewVisitCustomer);
 case 'create': if (!$auth->hasRole(\RoleGlobal::$role->createVisitCustomer)) throw new TException(lang('unauthorized.create_visit_cus'), 401);
 break;
 case 'update': case 'updateCusSeat': case 'updateCusStatus': case 'updateDrinks': case 'resetDrinkTime': if (!$auth->hasRole(\RoleGlobal::$role->updateVisitCustomer)) throw new TException(lang('unauthorized.update_visit_cus'), 401);
 break;
 case 'updateCusCompartment': case 'startDownTime': case 'stopDownTime': case 'holdOnCompartment': if (!$auth->hasRole(\RoleGlobal::$role->viewCompartmentManager)) showUnauthorized();
 break;
 case 'delete': if (!$auth->hasRole(\RoleGlobal::$role->deleteVisitCustomer)) throw new TException(lang('unauthorized.delete_visit_cus'), 401);
 break;
 case 'kpiServiceAdvisor': break;
 default: return false;
 }
 }
 }
 