diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 5e0904f..e5257be 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -33,6 +33,7 @@ $routes->group('', ['namespace' => 'App\Controllers'], function ($routes) { //Admin 관련 $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) { $routes->get('/', 'Home::index'); + $routes->get('/search', 'SearchController::index'); $routes->group('user', ['namespace' => 'App\Controllers\Admin'], function ($routes) { $routes->get('/', 'UserController::index', ['filter' => 'authFilter:master']); $routes->get('create', 'UserController::create_form', ['filter' => 'authFilter:master']); diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index f9bb090..974709d 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -3,7 +3,6 @@ namespace App\Controllers\Admin\Customer; use App\Entities\Customer\ServiceEntity; -use App\Entities\Equipment\ServerEntity; use App\Services\Customer\ServiceService; use App\Services\Equipment\ServerService; use App\Services\PaymentService; @@ -14,8 +13,8 @@ use Psr\Log\LoggerInterface; class ServiceController extends CustomerController { - private ?PaymentService $_paymentService = null; private ?ServerService $_serverService = null; + private ?PaymentService $_paymentService = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); diff --git a/app/Controllers/Admin/SearchController.php b/app/Controllers/Admin/SearchController.php index 04bd933..80f4dc6 100644 --- a/app/Controllers/Admin/SearchController.php +++ b/app/Controllers/Admin/SearchController.php @@ -2,10 +2,10 @@ namespace App\Controllers\Admin; -use App\Helpers\Customer\ServiceHelper; -use App\Services\Customer\ServicePaymentService; - +use App\Entities\Customer\ServiceEntity; use App\Services\Customer\ServiceService; +use App\Services\Equipment\ServerService; +use App\Services\PaymentService; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; @@ -13,14 +13,15 @@ use Psr\Log\LoggerInterface; class SearchController extends AdminController { + private ?ServerService $_serverService = null; + private ?PaymentService $_paymentService = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); $this->content_title = lang("{$this->getService()->getClassName()}.title"); $this->class_path .= $this->getService()->getClassName(); - $this->uri_path .= strtolower($this->getService()->getClassName('/')) . '/'; - // $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR; - + $this->uri_path = '/admin/search'; + // $this->view_path = '/admin/search'; } public function getService(): ServiceService { @@ -29,11 +30,25 @@ class SearchController extends AdminController } return $this->_service; } + public function getServerService(): ServerService + { + if ($this->_serverService === null) { + $this->_serverService = new ServerService(); + } + return $this->_serverService; + } + public function getPaymentService(): PaymentService + { + if ($this->_paymentService === null) { + $this->_paymentService = new PaymentService(); + } + return $this->_paymentService; + } protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { switch ($this->getService()->getAction()) { case 'index': - $result = parent::getResultSuccess($message, $this->request->getVar('ActionTemplate') ?? $actionTemplate ?? 'search'); + $result = parent::getResultSuccess($message, 'search'); break; default: $result = parent::getResultSuccess($message, $actionTemplate); @@ -41,5 +56,66 @@ class SearchController extends AdminController } return $result; } - //Index,FieldForm관련 + + protected function getChildServers(ServiceEntity $entity): array + { + $servers = []; + foreach ($this->getServerService()->getEntities(['serviceinfo_uid' => $entity->getPK()]) as $serverEntity) { + $servers[] = view_cell("\App\Cells\Equipment\ServerPartCell::parttable", [ + 'serverinfo_uid' => $serverEntity->getPK(), + 'types' => SERVERPART['SERVICE_PARTTYPES'], + 'serviceinfo_serverinfo_uid' => $entity->getServerEntity()->getPK(), + 'template' => 'partlist_service' + ]); + } + return $servers; + } + // + + protected function index_process(array $entities = []): array + { + $keyword = $this->request->getGet('keyword'); // 검색어 + if (!$keyword) { + throw new \Exception("[{$keyword}] 검색어가 지정되지 않았습니다. "); + } + // ->select([ + // 's.serviceinfo_uid', + // 's.uid AS server_uid', + // 's.title AS server_title', + // 'c.uid AS client_uid', + // 'c.name AS client_name', + // 'sp.uid AS part_uid', + // 'sp.title AS part_title' + // ]) + $db = \Config\Database::connect(); + $builder = $db->table('serverinfo s') + ->distinct() + ->select('s.serviceinfo_uid AS serviceinfo_uid') + ->join('clientinfo c', 'c.uid = s.clientinfo_uid') + ->join('serverpartinfo sp', 'sp.clientinfo_uid = c.uid', 'left') + ->groupStart() + ->like('c.name', $keyword, 'both', null, true) // escape=true + ->orLike('s.title', $keyword, 'both', null, true) + ->orLike('sp.title', $keyword, 'both', null, true) + ->groupEnd(); + // SQL 확인용 (실제 운영에서는 주석 처리) + // echo $builder->getCompiledSelect(); exit; + $results = $builder->get()->getResultArray(); + // dd($results); + $uids = []; + foreach ($results as $result) { + $uids[] = "'{$result['serviceinfo_uid']}'"; + } + if (!count($uids)) { + return []; + } + //서비스별 미납 Count + $childServers = []; + foreach ($this->getService()->getEntities("uid IN (" . implode(",", $uids) . ")") as $entity) { + $entities[] = $entity; + $childServers[$entity->getPK()] = $this->getChildServers($entity); + } + $this->childServers = $childServers; + return $entities; + } } diff --git a/app/Views/admin/search/index.php b/app/Views/admin/search/index.php new file mode 100644 index 0000000..f0294d3 --- /dev/null +++ b/app/Views/admin/search/index.php @@ -0,0 +1,115 @@ += $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?> += $this->section('content') ?> +getHelper()->alert($error) ?> +
| + + = $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?> + + | +
+
+ = $this->include("templates/{$viewDatas['layout']}/index_header"); ?>
+
+
+
+
+
+
+ = form_open(current_url(), ["method" => "get"]) ?>
+
+ = form_close() ?>
+ = form_open(current_url(), ['id' => 'batchjob_form', 'method' => "post"]) ?>
+
+
|
+