diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 06bbd0d..528b637 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -483,7 +483,8 @@ define("PAYMENT", [ 'BILLING' => [ 'BASE' => 'base', 'MONTH' => 'month', - 'ONETIME' => 'onetime' + 'ONETIME' => 'onetime', + 'PREPAYMENT' => 'prepayment' ], 'PAY' => [ 'ACCOUNT' => 'account', diff --git a/app/Config/Routes.php b/app/Config/Routes.php index dd1e01b..f42a6bb 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -13,7 +13,7 @@ $routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4} //1. app/Filters/AuthFilter.php //2. Config/Filters.php -> $aliases = ['authFilter' => AuthFilter::class] $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { - $routes->cli('collect', 'Collector::execute'); + $routes->cli('invoice', 'Invoice::execute'); }); $routes->group('', ['namespace' => 'App\Controllers'], function ($routes) { $routes->get('/', 'Home::index'); diff --git a/app/Controllers/CLI/Collector.php b/app/Controllers/CLI/Collector.php deleted file mode 100644 index 0f0cd60..0000000 --- a/app/Controllers/CLI/Collector.php +++ /dev/null @@ -1,55 +0,0 @@ -service === null) { - $action = 'create'; - $this->service = service('collectorservice'); - $fields = ['trafficinfo_uid', 'in', 'out', 'raw_in', 'raw_out']; - $filters = ['trafficinfo_uid']; - $this->service->getFormService()->setFormFields($fields); - $this->service->getFormService()->setFormRules($action, $fields); - $this->service->getFormService()->setFormFilters($filters); - $this->service->getFormService()->setFormOptions($action, $filters); - $this->service->getFormService()->setBatchjobFilters($filters); - } - } - public function execute(): void - { - try { - log_message('info', "트래픽 수집 시작"); - $trafficService = service('trafficservice'); - $total = 1; - $success = 0; - $error = 0; - foreach ($trafficService->getEntities(['status' => STATUS['AVAILABLE']]) as $trafficEntity) { - try { - $entity = $this->service->create(new CollectorDTO($this->service->getCalculatedData($trafficEntity))); - $success++; - $message = "{$trafficEntity->getServerIP()} 트래픽 수집데이터 저장 완료 In: {$entity->getIn()} Kb/s / Out: {$entity->getOut()} Kb/s"; - log_message('info', $message); - } catch (\Throwable $e) { - $error++; - log_message('error', "{$trafficEntity->getServerIP()} 트래픽 수집데이터 저장 실패:{$e->getMessage()}"); - } - $total++; - } - log_message('info', sprintf("성공:%s , 실패:%s , 총:%s 트래픽 수집 작업완료", $success, $error, $total)); - } catch (\Throwable $e) { - log_message('error', "트래픽 수집 작업오류:{$e->getMessage()}"); - } - } -} diff --git a/app/Controllers/CLI/Invoice.php b/app/Controllers/CLI/Invoice.php new file mode 100644 index 0000000..21f9456 --- /dev/null +++ b/app/Controllers/CLI/Invoice.php @@ -0,0 +1,43 @@ +service === null) { + $this->service = service('customer_serviceservice'); + } + } + public function execute(): void + { + try { + log_message('info', "청구서 발행 시작"); + $success = 0; + $error = 0; + $total = 0; + foreach ($this->service->getEntities(['billing_at' => date("Y-m-d"), 'status' => STATUS['AVAILABLE']]) as $entity) { + try { + service('paymentservice')->createByService($entity); + $entity = $this->service->updateBillingAt($entity, $this->service->getNextMonthDate($entity)); + log_message('info', "{$entity->getServerTitle()} 청구서 발행 완료: 다음달 청구일:{$entity->getBillingAt()} 입니다."); + } catch (\Throwable $e) { + $error++; + log_message('error', "{$entity->getServerTitle()} 청구서 발행 실패:{$e->getMessage()}"); + } + $total++; + } + log_message('info', sprintf("성공:%s , 실패:%s , 총:%s 청구서 발행 작업완료", $success, $error, $total)); + } catch (\Throwable $e) { + log_message('error', "청구서 발행 작업오류:{$e->getMessage()}"); + } + } +} diff --git a/app/Language/ko/Payment.php b/app/Language/ko/Payment.php index 4b74151..c04eba9 100644 --- a/app/Language/ko/Payment.php +++ b/app/Language/ko/Payment.php @@ -5,7 +5,7 @@ return [ 'user_uid' => "관리자", 'clientinfo_uid' => "고객", 'serviceinfo_uid' => "서비스", - 'title' => "청구항목", + 'title' => "청구제목", 'content' => "내용", 'amount' => "청구금액", 'billing' => "청구방법", @@ -20,6 +20,7 @@ return [ "BILLING" => [ PAYMENT['BILLING']['MONTH'] => "매월", PAYMENT['BILLING']['ONETIME'] => "일회성", + PAYMENT['BILLING']['PREPAYMENT'] => "선결제", ], "PAY" => [ PAYMENT['PAY']['ACCOUNT'] => "예치금", diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index e19ce82..68940de 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -149,7 +149,7 @@ class ServiceService extends CustomerService } return $amounts; } - //다음 달로 결제일 가져오기. + //다음 달로 결제일 가져오기.(CLI용) final public function getNextMonthDate(ServiceEntity $entity): string { // $sql = "UPDATE serviceinfo SET billing_at = @@ -175,41 +175,44 @@ class ServiceService extends CustomerService // 최종 결과 리턴 (YYYY-MM-DD) return $date->format('Y-m-d'); } - // 서비스금액관련처리 - private function getCacluatedAmount(ServiceEntity $entity): int + //결제일 변경관련처리 + final public function updateBillingAt(int|ServiceEntity $uid, string $billing_at): ServiceEntity { + $entity = is_int($uid) ? $this->getEntity($uid) : $uid; + if (!$entity instanceof ServiceEntity) { + throw new RuntimeException(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다."); + } + //총 서비스금액 설정 + $formDatas = ['billing_at' => $billing_at]; + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + return parent::modify_process($entity, $formDatas); + } + // 서비스금액관련처리 + final public function updateAmount(int|ServiceEntity $uid): ServiceEntity + { + $entity = is_int($uid) ? $this->getEntity($uid) : $uid; + if (!$entity instanceof ServiceEntity) { + throw new RuntimeException(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다."); + } //총 서비스금액 구하기 $server_amount = service('equipment_serverservice')->getCalculatedAmount($entity->getServerInfoUID()); //기본:서버금액(서버비+서버파트(월비용))+상면비+회선비-할인액 $caculatedAmount = (int)$server_amount + $entity->getRack() + $entity->getLine() - $entity->getSale(); - return $caculatedAmount; - } - final public function updateAmount(int $uid): ServiceEntity - { - $entity = $this->getEntity($uid); - if (!$entity instanceof ServiceEntity) { - throw new \Exception(__METHOD__ . "에서 오류발생: {$uid} 서비스 정보를 찾을수 없습니다."); - } - $action = 'modify'; - $fields = ['amount']; + + //총 서비스금액 설정 + $formDatas = ['amount' => $caculatedAmount]; + $fields = array_keys($formDatas); $this->getFormService()->setFormFields($fields); - $this->getFormService()->setFormRules($action, $fields); - $formDatas['amount'] = $this->getCacluatedAmount($entity); - $result = $this->model->update($entity->getPK(), $formDatas); - log_message('debug', $this->model->getLastQuery()); - if ($result === false) { - $errors = $this->model->errors(); - $errorMsg = is_array($errors) ? implode(", ", $errors) : "서비스 금액설정 실패했습니다."; - throw new RuntimeException(__METHOD__ . "에서 오류발생: " . $errorMsg); - } - return $this->getEntity($uid); + $this->getFormService()->setFormRules('modify', $fields); + return parent::modify_process($entity, $formDatas); } //기본 기능부분 protected function getEntity_process(mixed $entity): ServiceEntity { return $entity; } - protected function create_process(array $formDatas): ServiceEntity { //필수항목검사 @@ -226,7 +229,7 @@ class ServiceService extends CustomerService //서버정보 연결 service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID()); //서비스비용 설정 - $entity = $this->updateAmount($entity->getPK()); + $entity = $this->updateAmount($entity); //결제정보 생성 service('paymentservice')->createByService($entity); return $entity; @@ -249,7 +252,7 @@ class ServiceService extends CustomerService service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID()); } //서비스비용 설정 - $entity = $this->updateAmount($entity->getPK()); + $entity = $this->updateAmount($entity); //결제정보 생성 service('paymentservice')->modifyByService($entity); return $entity; diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index a4480ab..dbc0264 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -188,6 +188,10 @@ class PaymentService extends CommonService if (!$entity instanceof PaymentEntity) { throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 PaymentEntity만 가능"); } + //선결제인경우 서비스정보에 결제일 변경용 + if ($formDatas['billing'] === PAYMENT['BILLING']['PREPAYMENT'] && array_key_exists('billing_at', $formDatas)) { + service('customer_serviceservice')->updateBillingAt($entity->getServiceInfoUID(), $entity->getBillingAt()); + } return $entity; } @@ -197,6 +201,10 @@ class PaymentService extends CommonService if (!$entity instanceof PaymentEntity) { throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 PaymentEntity만 가능"); } + //선결제인경우 서비스정보에 결제일 변경용 + if ($formDatas['billing'] === PAYMENT['BILLING']['PREPAYMENT'] && array_key_exists('billing_at', $formDatas)) { + service('customer_serviceservice')->updateBillingAt($entity->getServiceInfoUID(), $entity->getBillingAt()); + } return $entity; } diff --git a/app/Views/cells/service/payment.php b/app/Views/cells/service/payment.php index 31cd8df..131d488 100644 --- a/app/Views/cells/service/payment.php +++ b/app/Views/cells/service/payment.php @@ -27,6 +27,6 @@