service === null) { $this->service = service('customer_serviceservice'); } $this->addActionPaths(path: 'service'); $this->layouts['footerScripts'][] = ''; $this->layouts['footerScripts'][] = ''; } //기본 함수 작업 //Custom 추가 함수 public function create_form_process(array $formDatas = []): array { $formDatas = parent::create_form_process($formDatas); $formDatas['location'] = 'chiba'; $formDatas['rack'] = '100000'; $formDatas['line'] = '300000'; $formDatas['sale'] = 0; $formDatas['billing_at'] = date("Y-m-d"); $formDatas['start_at'] = date("Y-m-d"); $formDatas['status'] = STATUS['AVAILABLE']; return $formDatas; } protected function index_process(string $action): void { //서비스별 미납 Count $this->addViewDatas('unPaids', service('paymentservice')->getUnPaids('serviceinfo_uid')); parent::index_process($action); } //비고사항 변경 public function history(int $uid): RedirectResponse|string { try { $history = $this->request->getPost('history'); if (!$history) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 비고가 정의되지 않았습니다."); } $entity = $this->service->modify($uid, ['history' => $history]); $this->addViewDatas('entity', $entity); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정이 완료되었습니다."); } catch (\Throwable $e) { return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정 오류:" . $e->getMessage()); } } //결제일 변경 public function billingat(int $uid): RedirectResponse|string { try { $billing_at = $this->request->getPost('billing_at'); if (!$billing_at) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 결제일이 정의되지 않았습니다."); } $entity = $this->service->modify($uid, ['billing_at' => $billing_at]); $this->addViewDatas('entity', $entity); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 결제일 변경이 완료되었습니다."); } catch (\Throwable $e) { return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 결제일 변경 오류:" . $e->getMessage()); } } //대체서버 생성폼 public function alternative_create_form(int $uid): string|RedirectResponse { try { $this->action_init_process(__FUNCTION__, ['uid' => $uid]); return $this->action_render_process(__FUNCTION__, $this->getViewDatas(), $this->request->getVar('ActionTemplate') ?? 'server'); } catch (\Throwable $e) { return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가폼 오류:" . $e->getMessage()); } } //대체서버 생성 public function alternative_create(int $uid): string|RedirectResponse { try { //추가할 대체서버 정의 $serverinfo_uid = $this->request->getGet('serverinfo_uid'); if (!$serverinfo_uid) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 변경할 대체서버가 정의되지 않았습니다."); } //서비스정보 가져오기 $entity = $this->service->getEntity($uid); if (!$entity instanceof ServiceEntity) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보을 찾을수 없습니다."); } //대체서버 추가 service('equipment_serverservice')->attatchToService($entity, $serverinfo_uid); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가가 완료되었습니다."); } catch (\Throwable $e) { return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가 오류:" . $e->getMessage()); } } //대체서버 -> 메인서버로 바꾼다. public function alternative_modify(int $uid): string|RedirectResponse { try { //변경할 대체서버 정의 $serverinfo_uid = $this->request->getGet('serverinfo_uid'); if (!$serverinfo_uid) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 변경할 대체서버가 정의되지 않았습니다."); } //서버 타이틀을 서비스 타이틀로 변경하기 위함 $serverEntity = service('equipment_serverservice')->getEntity($serverinfo_uid); if (!$serverEntity instanceof ServerEntity) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해당하는 서버정보을 찾을수 없습니다."); } //서버번호 와 서비스 제목 설정용 $formDatas = []; $formDatas['serverinfo_uid'] = $serverEntity->getPK(); $formDatas['title'] = $serverEntity->getCustomTitle(); //대체서버를 메인서버로 설정 $this->service->modify($uid, $formDatas); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 메인서버 설정이 완료되었습니다."); } catch (\Throwable $e) { return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 메인서버 설정 오류:" . $e->getMessage()); } } //대체서버 해지 public function alternative_delete(int $uid): string|RedirectResponse { try { //해지할 대체서버 정의 $serverinfo_uid = $this->request->getGet('serverinfo_uid'); if (!$serverinfo_uid) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해지할 대체서버가 정의되지 않았습니다."); } //서비스정보 가져오기 $entity = $this->service->getEntity($uid); if (!$entity instanceof ServiceEntity) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보을 찾을수 없습니다."); } //대체서버 해지 service('equipment_serverservice')->deatchFromService($serverinfo_uid); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 해지가 완료되었습니다."); } catch (\Throwable $e) { return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 해지 오류:" . $e->getMessage()); } } }