addClassName('Payment'); } final public function getFormFields(): array { return [ "clientinfo_uid", "serviceinfo_uid", "title", "amount", "billing", "billing_at", "pay", "status", ]; } final public function getFormFilters(): array { return [ 'clientinfo_uid', "serviceinfo_uid", 'billing', 'pay', 'status', 'user_uid', ]; } final public function getIndexFields(): array { return [ 'clientinfo_uid', "serviceinfo_uid", 'billing', 'title', 'amount', 'billing_at', 'pay', 'status', 'updated_at', 'countdown', 'user_uid', ]; } final public function getBatchjobFields(): array { return ['pay', 'status']; } final public function getBatchjobButtons(): array { return [ 'batchjob' => '일괄 결제 ', 'invoice' => '청구서 발행', ]; } final public function getClientService(): ClientService { if (!$this->_clientService) { $this->_clientService = new ClientService(); } return $this->_clientService; } final public function getUSerService(): UserService { if (!$this->_userService) { $this->_userService = new UserService(); } return $this->_userService; } final public function getServiceService(): ServiceService { if (!$this->_serviceService) { $this->_serviceService = new ServiceService(); } return $this->_serviceService; } //기본 기능부분 //FieldForm관련용 final public function getFormOption(string $field, array $options = []): array { switch ($field) { case 'user_uid': $options = $this->getUserService()->getEntities(); break; case 'clientinfo_uid': $options = $this->getClientService()->getEntities(); break; case 'serviceinfo_uid': $options = $this->getServiceService()->getEntities(); break; default: $options = parent::getFormOption($field, $options); break; } return $options; } //List 검색용 //OrderBy 처리 public function setOrderBy(mixed $field = null, mixed $value = null): void { $this->getModel()->orderBy('billing_at ASC'); parent::setOrderBy($field, $value); } //총 미납건수, 금액 final public function getUnPaids(string $group, array $where = []): array { return $this->getModel()->groupBy($group) ->select("serviceinfo_uid,COUNT(uid) as cnt, SUM(amount) as amount") ->where(['billing_at <=' => date('Y-m-d')]) ->where(['status' => STATUS['UNPAID']]) ->where($where) ->get()->getResult(); } //생성 public function create(array $formDatas): PaymentEntity { // 관리자 UID는 현재 인증된 사용자로 설정 $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); return parent::create($formDatas); } //수정 public function modify(mixed $entity, array $formDatas): PaymentEntity { // 관리자 UID는 현재 인증된 사용자로 설정 $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); return parent::modify($entity, $formDatas); } //서버연결정보용 등록 public function setServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): ServerPartEntity { if ($serverPartEntity->getServiceInfoUID() === null) { throw new \Exception("서비스정보가 정의된 후에만 가능합니다."); } //Service Entity 가져오기 $serviceEntity = $this->getServiceService()->getEntity($serverPartEntity->getServiceInfoUID()); if (!$serviceEntity) { throw new \Exception("[{$serverPartEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다."); } //수정인경우 기존 결제정보 가져오기 if (array_key_exists('action', $formDatas) && $formDatas['action'] === 'modify') { $entity = $this->getEntity(['serverpartinfo_uid' => $serverPartEntity->getPK()]); if (!$entity instanceof PaymentEntity) { throw new \Exception("{$serverPartEntity->getPK()}에 해당하는 결제정보를 찾을수 없습니다."); } } //월비용인경우 서비스 제공가에 서버연결정보 제공가 합산금액으로 설정 if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) { $formDatas['serverinfo_uid'] = $serviceEntity->getServerInfoUID(); $formDatas['billing_at'] = $serviceEntity->getBillingAt(); $formDatas['amount'] = $serviceEntity->getAmount() + $serverPartEntity->getAmount(); $this->getServiceService()->modify($serviceEntity, $formDatas); } //일회성인경우 if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['ONETIME']) { $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); $formDatas['serverpartinfo_uid'] = $serverPartEntity->getPK(); $formDatas['title'] = $serverPartEntity->getType() === 'ETC' ? $serverPartEntity->getTitle() : $serverPartEntity->getPartEntity()->getTitle(); $formDatas['amount'] = $serverPartEntity->getAmount(); $formDatas['billing'] = $serverPartEntity->getBilling(); if (array_key_exists('action', $formDatas) && $formDatas['action'] === 'modify') { $this->modify($entity, $formDatas); } else { //생성일때만 지급기한일 설정 $formDatas['billing_at'] = $serverPartEntity->getBilling() === PAYMENT['BILLING']['ONETIME'] ? date("Y-m-d") : $serviceEntity->getBillingAT(); $this->create($formDatas); } } return $serverPartEntity; } //서비스정보용 등록 public function service(ServiceEntity $serviceEntity, array $formDatas = []): ServiceEntity { $formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUID(); $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); $formDatas['serverinfo_uid'] = $serviceEntity->getServerInfoUID(); $formDatas['title'] = $serviceEntity->getServerEntity()->getTitle(); $formDatas['amount'] = $serviceEntity->getAmount(); $formDatas['billing'] = PAYMENT['BILLING']['MONTH']; $formDatas['billing_at'] = $serviceEntity->getBillingAt(); $this->create($formDatas); return $serviceEntity; } }