From 2b83afd59fdb5ba693494796a372a12cbcd32c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Tue, 2 Dec 2025 18:24:50 +0900 Subject: [PATCH] dbmsv4 init...1 --- .../Admin/Customer/ServiceController.php | 12 ++- app/Forms/CommonForm.php | 37 ++++++-- app/Helpers/Customer/ServiceHelper.php | 3 - app/Services/CommonService.php | 10 ++- app/Services/Customer/ServiceService.php | 86 +++++++++++-------- app/Services/Equipment/ServerService.php | 17 ++-- app/Services/PaymentService.php | 41 +++++---- app/Views/admin/client/detail.php | 4 +- .../admin/server/alternative_create_form.php | 25 ++++++ app/Views/cells/server/detail.php | 1 + app/Views/cells/serverpart/detail.php | 1 - app/Views/cells/service/detail.php | 22 ++++- 12 files changed, 175 insertions(+), 84 deletions(-) create mode 100644 app/Views/admin/server/alternative_create_form.php diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index d7233fb..5693fff 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -59,12 +59,10 @@ class ServiceController extends CustomerController { try { $action = __FUNCTION__; - $fields = ['serverinfo_uid']; - $this->service->getFormService()->setFormFields($fields); - $this->service->getFormService()->setFormRules($action, $fields); - return $this->action_render_process($action, $this->getViewDatas(), $this->request->getVar('ActionTemplate')); + $this->action_init_process($action, $this->request->getVar()); + return $this->action_render_process($action, $this->getViewDatas(), $this->request->getVar('ActionTemplate') ?? 'server'); } catch (\Throwable $e) { - return $this->action_redirect_process('error', "{$this->getTitle()}에서 대체서버추가 오류:" . $e->getMessage()); + return $this->action_redirect_process('error', "{$this->getTitle()}에서 대체서버 추가폼 오류:" . $e->getMessage()); } } public function alternative_create(int $uid): string|RedirectResponse @@ -77,7 +75,7 @@ class ServiceController extends CustomerController //서비스정보 가져오기 $entity = $this->service->getEntity($uid); //대체서버 추가 - service('equipment_serverservice')->attachToService($entity, $this->request->getPost()); + service('equipment_serverservice')->attachToService($entity, $this->request->getPost('serverinfo_uid')); return $this->action_redirect_process('info', "{$this->getTitle()}에서 대체서버추가가 완료되었습니다"); } catch (\Throwable $e) { return $this->action_redirect_process('error', "{$this->getTitle()}에서 대체서버추가 오류:" . $e->getMessage()); @@ -109,7 +107,7 @@ class ServiceController extends CustomerController //서비스정보 가져오기 $entity = $this->service->getEntity($uid); //대체서버 해지 - service('equipment_serverservice')->detachFromService($entity, $this->request->getGet()); + service('equipment_serverservice')->detachFromService($entity, $this->request->getGet('serverinfo_uid')); return $this->action_redirect_process('info', "{$this->getTitle()}에서 대체서버해지가 완료되었습니다"); } catch (\Throwable $e) { return $this->action_redirect_process('error', "{$this->getTitle()}에서 대체서버 해지 오류:" . $e->getMessage()); diff --git a/app/Forms/CommonForm.php b/app/Forms/CommonForm.php index c7594ab..7300a2e 100644 --- a/app/Forms/CommonForm.php +++ b/app/Forms/CommonForm.php @@ -113,18 +113,45 @@ abstract class CommonForm return $this->_batchjobButtons; } //Validation용 + // final public function validate(array $formDatas): bool + // { + // $validation = service('validation'); + // $dynamicRules = []; + // foreach ($this->getFormRules() as $field => $rule) { + // //field별 추가 커스텀 룰 적용 + // list($field, $rule) = $this->getValidationRule($field, $rule); + // $dynamicRules[$field] = ['rules' => $rule, 'label' => $this->getFormFields()[$field]]; + // } + // $validation->setRules($dynamicRules); + // return $validation->run($formDatas); + // } final public function validate(array $formDatas): bool { $validation = service('validation'); $dynamicRules = []; + $dynamicLabels = []; // 레이블 배열 추가 + foreach ($this->getFormRules() as $field => $rule) { - //field별 추가 커스텀 룰 적용 list($field, $rule) = $this->getValidationRule($field, $rule); - $dynamicRules[$field] = ['rules' => $rule, 'label' => $this->getFormFields()[$field]]; + $dynamicRules[$field] = $rule; // 규칙만 저장 + $dynamicLabels[$field] = $this->getFormFields()[$field]; } - $validation->setRules($dynamicRules); - return $validation->run($formDatas); + log_message('debug', 'Rules: ' . var_export($dynamicRules, true)); + log_message('debug', 'Data: ' . var_export($formDatas, true)); + // setRules의 세 번째 인자로 레이블 전달 + $validation->setRules($dynamicRules, [], $dynamicLabels); + + // run()에는 데이터만 전달 (setRules에서 이미 설정됨) + $result = $validation->run($formDatas); + if ($result === false) { + // run()이 false를 반환했다면, 이 시점에서 getErrors()에는 메시지가 있어야 합니다. + log_message('debug', 'Validate Run Failed. Errors: ' . var_export($validation->getErrors(), true)); + } else { + log_message('debug', 'Validate Run Succeeded.'); + } + return $result; } + //필수함수 //사용자정의 함수 protected function getValidationRule(string $field, string $rule): array @@ -186,7 +213,7 @@ abstract class CommonForm $entities = []; switch ($field) { default: - if (in_array($action, ['create_form', 'modify_form'])) { + if (in_array($action, ['create_form', 'modify_form', 'alternative_create_form'])) { if (array_key_exists($field, $formDatas)) { $where = sprintf("status = '%s' OR %s='%s'", STATUS['AVAILABLE'], $this->getAttribute('pk_field'), $formDatas[$field]); } else { diff --git a/app/Helpers/Customer/ServiceHelper.php b/app/Helpers/Customer/ServiceHelper.php index 41c86ab..966014e 100644 --- a/app/Helpers/Customer/ServiceHelper.php +++ b/app/Helpers/Customer/ServiceHelper.php @@ -77,9 +77,6 @@ class ServiceHelper extends CustomerHelper public function getListButton(string $action, string $label, array $viewDatas, array $extras = []): string { switch ($action) { - case 'modify': - $action = parent::getListButton($action, $label, $viewDatas, $extras); - break; case 'addServer': $action = form_label( $label ? $label : ICONS['REBOOT'], diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 0f27876..ccfbd8d 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -4,6 +4,7 @@ namespace App\Services; use App\DTOs\CommonDTO; use App\Entities\CommonEntity; +use App\Entities\PaymentEntity; use App\Libraries\AuthContext; use App\Models\CommonModel; use CodeIgniter\Database\Exceptions\DatabaseException; @@ -168,6 +169,9 @@ abstract class CommonService //생성용 protected function create_process(array $formDatas): object { + if ($this instanceof PaymentService) { + log_message('debug', var_export($formDatas, true)); + } //FormData 검증 if (!$this->getFormService()->validate($formDatas)) { throw new ValidationException(implode("\n", service('validation')->getErrors())); @@ -180,7 +184,11 @@ abstract class CommonService if (!$entity instanceof $entityClass) { throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 {$entityClass}만 가능"); } - return $this->save_process($entity); + $entity = $this->save_process($entity); + if ($entity instanceof PaymentEntity) { + log_message('debug', var_export($entity, true)); + } + return $entity; } final public function create(object $dto): object { diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 5243463..12eed34 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -2,15 +2,17 @@ namespace App\Services\Customer; -use RuntimeException; -use DateTimeZone; -use DateTimeImmutable; -use App\Models\Customer\ServiceModel; -use App\Helpers\Customer\ServiceHelper; -use App\Forms\Customer\ServiceForm; -use App\Entities\Customer\ServiceEntity; -use App\Entities\CommonEntity; use App\DTOs\Customer\ServiceDTO; +use App\Entities\CommonEntity; +use App\Entities\Customer\ServiceEntity; +use App\Entities\Equipment\ServerEntity; +use App\Entities\PaymentEntity; +use App\Forms\Customer\ServiceForm; +use App\Helpers\Customer\ServiceHelper; +use App\Models\Customer\ServiceModel; +use DateTimeImmutable; +use DateTimeZone; +use RuntimeException; class ServiceService extends CustomerService { @@ -118,6 +120,9 @@ class ServiceService extends CustomerService 'created_at' ]; break; + case 'alternative_create_form': + $fields = ['serverinfo_uid']; + break; } $this->getFormService()->setFormFields($fields); $this->getFormService()->setFormRules($action, $fields); @@ -171,17 +176,35 @@ class ServiceService extends CustomerService return $date->format('Y-m-d'); } // 서비스금액관련처리 - public function getCalculatedAmount(int $serverinfo_uid, int $rack, int $line, int $sale): int + final public function getCalculatedAmount(int $serverinfo_uid, int $rack, int $line, int $sale): int { - $serverService = service('equipment_serverservice'); - //기본:상면비+회선비+서버금액(price)+서버파트연결(월비용)-할인액 - return $rack + $line + $serverService->getCalculatedAmount($serverinfo_uid) - $sale; + $server_amount = service('equipment_serverservice')->getCalculatedAmount($serverinfo_uid); + //기본:서버금액(서버비+서버파트(월비용))+상면비+회선비-할인액 + $amount = (int)$server_amount + $rack + $line - $sale; + // echo "{$server_amount} + {$rack} + $line - {$sale} = {$amount}"; + // exit; + return $amount; + } + private function updateAmount(ServiceEntity $entity): ServiceEntity + { + $action = 'modify'; + $fields = ['amount']; + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules($action, $fields); + $formDatas['amount'] = $this->getCalculatedAmount( + $entity->getServerInfoUID(), + $entity->getRack(), + $entity->getLine(), + $entity->getSale() + ); + return parent::modify_process($entity, $formDatas); } //기본 기능부분 protected function getEntity_process(mixed $entity): ServiceEntity { return $entity; } + protected function create_process(array $formDatas): ServiceEntity { //필수항목검사 @@ -190,22 +213,17 @@ class ServiceService extends CustomerService } //서비스코드생성 $formDatas['code'] = $formDatas['site'] . "_s" . uniqid(); - //서비스 전체금액 구하기 - $formDatas['amount'] = $this->getCalculatedAmount( - (int)$formDatas['serverinfo_uid'], - (int)$formDatas['rack'], - (int)$formDatas['line'], - (int)$formDatas['sale'] - ); //서비스 생성 $entity = parent::create_process($formDatas); if (!$entity instanceof ServiceEntity) { throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServiceEntity만 가능"); } + //서비스비용 설정 + $entity = $this->updateAmount($entity); //서버정보 연결 - service('equipment_serverservice')->attachToService($entity); - //결제정보 연결 - service('paymentservice')->attachToService($entity); + service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID()); + //결제정보 생성 + service('paymentservice')->createByService($entity); return $entity; } protected function modify_process($entity, array $formDatas): ServiceEntity @@ -214,25 +232,21 @@ class ServiceService extends CustomerService if (!array_key_exists('serverinfo_uid', $formDatas)) { throw new RuntimeException(__METHOD__ . '에서 오류발생: 서버정보가 정의되지 않았습니다.'); } - //수정전 서비스정보를 currentEntity 복사해준다. - if ($entity->getServerInfoUID() !== $formDatas['serverinfo_uid']) { - //결제정보 해지(삭제)처리 - service('paymentservice')->detachFromService($entity); - //서비스 전체금액 구하기 - $formDatas['amount'] = $this->getCalculatedAmount( - (int)$formDatas['serverinfo_uid'], - (int)$entity->getRack(), - (int)$entity->getLine(), - (int)$entity->getSale() - ); - } + //변경전 정보 + $oldEntity = clone $entity; //서비스 수정 $entity = parent::modify_process($entity, $formDatas); if (!$entity instanceof ServiceEntity) { throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServiceEntity만 가능"); } - //결제정보 연결 - service('paymentservice')->attachToService($entity); + //서비스비용 설정 + $entity = $this->updateAmount($entity); + //서버정보 연결 신규서버로 변경되었으면 신규서버 추가 + if ($oldEntity->getServerInfoUID() !== $entity->getServerInfoUID()) { + service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID()); + } + //결제정보 수정 + service('paymentservice')->modifyByService($entity); return $entity; } //List 검색용 diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index d6bb6b3..097d07b 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -239,10 +239,13 @@ class ServerService extends EquipmentService //OrderBy 처리 //서비스관련 - public function attachToService(ServiceEntity $serviceEntity, array $formDatas = []): void + //Service 결제데이터 가져오기 + public function attachToService(ServiceEntity $serviceEntity, int $uid): void { - //서버정보 가져오기 - $entity = $this->getEntity($serviceEntity->getServerInfoUID()); + $entity = $this->getEntity($uid); + if (!$entity instanceof ServerEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: 해당하는 서버정보을 찾을수 없습니다."); + } $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); $formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID(); $formDatas['status'] = $formDatas['status'] ?? STATUS['OCCUPIED']; @@ -251,10 +254,12 @@ class ServerService extends EquipmentService $this->getFormService()->setFormRules('modify', $fields); parent::modify_process($entity, $formDatas); } - public function detachFromService(ServiceEntity $serviceEntity, array $formDatas = []): void + public function detachFromService(int $uid): void { - //서버정보 가져오기 - $entity = $this->getEntity($serviceEntity->getServerInfoUID()); + $entity = $this->getEntity($uid); + if (!$entity instanceof ServerEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: 해당하는 서버정보을 찾을수 없습니다."); + } $formDatas['serviceinfo_uid'] = NULL; $formDatas["clientinfo_uid"] = NULL; $formDatas['status'] = $formDatas['status'] ?? STATUS['AVAILABLE']; diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 871c0a3..4fd2201 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -209,38 +209,41 @@ class PaymentService extends CommonService } //서비스관련 - public function attachToService(ServiceEntity $serviceEntity): void + private function getFormDatasByService(ServiceEntity $serviceEntity, array $formDatas = []): array { - //결제정보 생성 - $formDatas = []; $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); $formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID(); + $formDatas['amount'] = $serviceEntity->getAmount(); + $formDatas['billing'] = $formDatas['billing'] ?? PAYMENT['BILLING']['MONTH']; + $formDatas['billing_at'] = $serviceEntity->getBillingAt(); + $formDatas['pay'] = $formDatas['pay'] ?? PAYMENT['PAY']['ACCOUNT']; + $formDatas['status'] = $formDatas['status'] ?? STATUS['UNPAID']; $formDatas['title'] = sprintf( "%s %s 서비스비용", - $serviceEntity->getTitle(), - DateTime::createFromFormat('Y-m-d', $serviceEntity->getBillingAt())->format('Y년 m월') + $formDatas['title'] ?? $serviceEntity->getTitle(), + DateTime::createFromFormat('Y-m-d', $formDatas['billing_at'])->format('Y년 m월') ); - $formDatas['amount'] = $serviceEntity->getAmount(); - $formDatas['billing'] = PAYMENT['BILLING']['MONTH']; - $formDatas['billing_at'] = $serviceEntity->getBillingAt(); - $formDatas['pay'] = PAYMENT['PAY']['ACCOUNT']; - $formDatas['status'] = STATUS['UNPAID']; + return $formDatas; + } + public function createByService(ServiceEntity $serviceEntity): PaymentEntity + { + $formDatas = $this->getFormDatasByService($serviceEntity); $fields = array_keys($formDatas); $this->getFormService()->setFormFields($fields); $this->getFormService()->setFormRules('create', $fields); - $this->create_process($formDatas); + return parent::create_process($formDatas); } - public function detachFromService(ServiceEntity $serviceEntity): void + public function modifyByService(ServiceEntity $serviceEntity): PaymentEntity { - //서비스정보의 지급기한일과 같은 결제정보 가져오기 + //서비스정보의 지급기한일과 같은 결제정보 가져와서 결제정보 수정 $entity = $this->getEntity(['serviceinfo_uid' => $serviceEntity->getPK(), 'billing_at' => $serviceEntity->getBillingAt()]); - if (!$entity) { + if (!$entity instanceof PaymentEntity) { throw new \Exception(__METHOD__ . "에서 오류발생: 해당하는 결제정보을 찾을수 없습니다."); } - //결제가 완료된 경우라면 처리불가 - if ($entity->getStatus() === STATUS['PAID']) { - throw new \Exception(__METHOD__ . "에서 오류발생: 해당하는 결제정보는 이미 결제처리가 완료되어 수정이 불가합니다."); - } - $this->delete_process($entity->getPK()); + $formDatas = $this->getFormDatasByService($serviceEntity); + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + return parent::modify_process($entity, $formDatas); } } diff --git a/app/Views/admin/client/detail.php b/app/Views/admin/client/detail.php index 1f2f833..97223b5 100644 --- a/app/Views/admin/client/detail.php +++ b/app/Views/admin/client/detail.php @@ -38,7 +38,7 @@ "[청구서발행]", 'payment_invoice', [ - "data-src" => "/admin/payment?clientinfo_uid=" . $viewDatas['entity']->getPK() . "&ActionTemplate=popup", + "data-src" => "/admin/payment?clientinfo_uid={$viewDatas['entity']->getPK()}&ActionTemplate=popup", "data-bs-toggle" => "modal", "data-bs-target" => "#modal_action_form", "class" => "text-primary form-label-sm", @@ -52,7 +52,7 @@ '서비스추가', 'create_service', [ - "data-src" => '/admin/customer/service/create?clientinfo_uid=' . $viewDatas['entity']->getPK(), + "data-src" => "/admin/customer/service/create?clientinfo_uid={$viewDatas['entity']->getPK()}", "data-bs-toggle" => "modal", "data-bs-target" => "#modal_action_form", "class" => "btn btn-sm btn-primary form-label-sm", diff --git a/app/Views/admin/server/alternative_create_form.php b/app/Views/admin/server/alternative_create_form.php new file mode 100644 index 0000000..55537cd --- /dev/null +++ b/app/Views/admin/server/alternative_create_form.php @@ -0,0 +1,25 @@ +extend($viewDatas['layout']['layout']) ?> +section('content') ?> +alertTrait(session('message')) : ""; ?> +
+
include("{$viewDatas['layout']['template']}/form_content_top"); ?>
+ + + + + + $label): ?> + + + + + +
getFieldLabel($field, $label, $viewDatas) ?> + getFieldForm($field, old($field) ?? ($viewDatas['formDatas'][$field] ?? null), $viewDatas) ?> +
+
+
"btn btn-outline btn-primary")); ?>
+ +
include("{$viewDatas['layout']['template']}/form_content_bottom"); ?>
+
+endSection() ?> \ No newline at end of file diff --git a/app/Views/cells/server/detail.php b/app/Views/cells/server/detail.php index 42c5520..f1dc124 100644 --- a/app/Views/cells/server/detail.php +++ b/app/Views/cells/server/detail.php @@ -21,6 +21,7 @@
getTitle() ?>
getIP() ?>
getOS() ?>
+
금액 : getPrice()) ?>
$entity->getPK(), diff --git a/app/Views/cells/serverpart/detail.php b/app/Views/cells/serverpart/detail.php index dfbc65c..d0ad6a0 100644 --- a/app/Views/cells/serverpart/detail.php +++ b/app/Views/cells/serverpart/detail.php @@ -16,7 +16,6 @@
getFieldView('IP', $entity->getPK(), $serverPartCellDatas) ?>
-   diff --git a/app/Views/cells/service/detail.php b/app/Views/cells/service/detail.php index 8235407..1fc221e 100644 --- a/app/Views/cells/service/detail.php +++ b/app/Views/cells/service/detail.php @@ -10,11 +10,25 @@ -
getCode() ?>
+
getFieldView('site', $entity->getSite(), $serviceCellDatas) ?> / + getFieldView('location', $entity->getLocation(), $serviceCellDatas) ?> +
+
getCode(), + 'modify_service', + [ + "data-src" => "/admin/customer/service/modify/{$entity->getPK()}?clientinfo_uid={$entity->getClientInfoUID()}", + "data-bs-toggle" => "modal", + "data-bs-target" => "#modal_action_form", + "class" => "text-primary form-label-sm", + ] + ); + ?>
getTitle() ?>
-
getFieldView('site', $entity->getSite(), $serviceCellDatas) ?>
-
getFieldView('location', $entity->getLocation(), $serviceCellDatas) ?>
-
getListButton('addServer', '대체서버추가', ['entity' => $entity], ['class' => 'btn btn-sm btn-primary']) ?>
+
상면비 : getRack()) ?>
+
회선비 : getLine()) ?>
+
할인액 : getSale()) ?>
+
getListButton('addServer', '대체서버추가', ['entity' => $entity], ['class' => 'btn btn-sm btn-primary']) ?>
$entity]) ?>