diff --git a/$rule) b/$rule) new file mode 100644 index 0000000..e69de29 diff --git a/app/Config/App.php b/app/Config/App.php index b761da7..74aabc3 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -93,7 +93,7 @@ class App extends BaseConfig * strings (like currency markers, numbers, etc), that your program * should run under for this request. */ - public string $defaultLocale = 'en'; + public string $defaultLocale = 'ko'; /** * -------------------------------------------------------------------------- diff --git a/app/Entities/Equipment/ServerPartEntity.php b/app/Entities/Equipment/ServerPartEntity.php index c7d4b3f..941c995 100644 --- a/app/Entities/Equipment/ServerPartEntity.php +++ b/app/Entities/Equipment/ServerPartEntity.php @@ -29,7 +29,7 @@ class ServerPartEntity extends EquipmentEntity return $this->attributes['payment_uid'] ?? null; } //기본기능용 - public function getTotalAmount(): int + public function getCalculatedAmount(): int { return $this->getAmount() * $this->getCnt(); } diff --git a/app/Entities/Part/PartEntity.php b/app/Entities/Part/PartEntity.php index e242a2b..7d195bc 100644 --- a/app/Entities/Part/PartEntity.php +++ b/app/Entities/Part/PartEntity.php @@ -27,7 +27,7 @@ abstract class PartEntity extends CommonEntity //기본기능용 public function getCustomTitle(mixed $title = null): string { - return sprintf("%s %s원", $title ? $title : $this->getTitle(), number_format($this->getPrice())); + return sprintf("%s %s원", $title ? $title : $this->getTitle(), number_format($this->getPrice() . "원")); } final public function getPrice(): int { diff --git a/app/Forms/BoardForm.php b/app/Forms/BoardForm.php index 7ec0a6c..fb54a8c 100644 --- a/app/Forms/BoardForm.php +++ b/app/Forms/BoardForm.php @@ -44,7 +44,7 @@ class BoardForm extends CommonForm } return $rule; } - public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array + public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array { $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"]; switch ($field) { diff --git a/app/Forms/CommonForm.php b/app/Forms/CommonForm.php index 3f781a2..77a90dd 100644 --- a/app/Forms/CommonForm.php +++ b/app/Forms/CommonForm.php @@ -113,14 +113,14 @@ abstract class CommonForm return $this->_batchjobButtons; } //Validation용 - public function validate(array $formDatas): bool + 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] = $rule; + $dynamicRules[$field] = ['rules' => $rule, 'label' => $this->getFormFields()[$field]]; } $validation->setRules($dynamicRules); return $validation->run($formDatas); @@ -203,7 +203,7 @@ abstract class CommonForm return $entities; } - public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array + public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array { $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"]; switch ($field) { diff --git a/app/Forms/Customer/ServiceForm.php b/app/Forms/Customer/ServiceForm.php index 9a2108d..018982a 100644 --- a/app/Forms/Customer/ServiceForm.php +++ b/app/Forms/Customer/ServiceForm.php @@ -46,18 +46,14 @@ class ServiceForm extends CustomerForm return $rule; } - public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array + public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array { $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"]; switch ($field) { case 'serverinfo_uid': foreach ($this->getFormOption_process(service('equipment_serverservice'), $action, $field, $formDatas) as $tempEntity) { - $tempOptions[$tempEntity->getPK()] = [ - 'value' => $tempEntity->getPK(), - 'text' => $tempEntity->getCustomTitle(), - 'data-title' => $tempEntity->getCustomTitle(), - 'data-price' => $tempEntity->getPrice() - ]; + $tempOptions[$tempEntity->getPK()] = $tempEntity->getCustomTitle(); + // $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())]; } $options['options'] = $tempOptions; break; diff --git a/app/Forms/Equipment/ServerForm.php b/app/Forms/Equipment/ServerForm.php index 0489469..731378f 100644 --- a/app/Forms/Equipment/ServerForm.php +++ b/app/Forms/Equipment/ServerForm.php @@ -69,7 +69,7 @@ class ServerForm extends EquipmentForm return $entities; } - public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array + public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array { $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"]; switch ($field) { diff --git a/app/Forms/Equipment/ServerPartForm.php b/app/Forms/Equipment/ServerPartForm.php index be973db..537e125 100644 --- a/app/Forms/Equipment/ServerPartForm.php +++ b/app/Forms/Equipment/ServerPartForm.php @@ -42,14 +42,18 @@ class ServerPartForm extends EquipmentForm { return service('part_' . strtolower($type) . 'service'); } - public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array + public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array { $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"]; switch ($field) { case 'part_uid': + $tempOptions = []; foreach (SERVERPART['ALL_PARTTYPES'] as $type) { $partService = $this->getPartService($type); - $tempOptions[$type] = [lang("{$this->getAttribute('class_path')}.TYPE.{$type}") . " 선택"]; + $tempOptions[$type] = ["" => [ + 'value' => "", + 'text' => lang("{$this->getAttribute('class_path')}.TYPE.{$type}") . " 선택", + ]]; foreach ($this->getFormOption_process($partService, $action, $field, $formDatas) as $tempEntity) { $tempOptions[$type][$tempEntity->getPK()] = [ 'value' => $tempEntity->getPK(), @@ -60,8 +64,6 @@ class ServerPartForm extends EquipmentForm } } $options['options'] = $tempOptions; - // dd($formDatas); - // dd($options); break; case 'serverinfo_uid': foreach ($this->getFormOption_process(service('equipment_serverservice'), $action, $field, $formDatas) as $tempEntity) { diff --git a/app/Forms/Part/IPForm.php b/app/Forms/Part/IPForm.php index 95004b2..e1c69a0 100644 --- a/app/Forms/Part/IPForm.php +++ b/app/Forms/Part/IPForm.php @@ -27,7 +27,7 @@ class IPForm extends PartForm } return $rule; } - public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array + public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array { $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"]; switch ($field) { diff --git a/app/Forms/Part/PartForm.php b/app/Forms/Part/PartForm.php index b2ff2a2..18e9576 100644 --- a/app/Forms/Part/PartForm.php +++ b/app/Forms/Part/PartForm.php @@ -35,7 +35,7 @@ abstract class PartForm extends CommonForm } return $rule; } - public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array + public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array { $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"]; switch ($field) { diff --git a/app/Forms/PaymentForm.php b/app/Forms/PaymentForm.php index 5562b95..53eca88 100644 --- a/app/Forms/PaymentForm.php +++ b/app/Forms/PaymentForm.php @@ -41,7 +41,7 @@ class PaymentForm extends CommonForm return $rule; } - public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array + public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array { $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"]; switch ($field) { diff --git a/app/Helpers/CommonHelper.php b/app/Helpers/CommonHelper.php index 3f2133f..729e5c4 100644 --- a/app/Helpers/CommonHelper.php +++ b/app/Helpers/CommonHelper.php @@ -47,41 +47,46 @@ abstract class CommonHelper * @param string $extra 태그 */ - final public function form_dropdown_custom(string $name = '', array $options = [], $selected = null, array $extras = []): string + final public function form_dropdown_custom(string $name, array $options, mixed $selected, array $extras = []): string { + // dd($options); + //Extra처리 $extra = ""; foreach ($extras as $extras_key => $extras_value) { $extra .= " " . esc($extras_key) . '="' . esc($extras_value) . '"'; } $select = '\n"; diff --git a/app/Helpers/Customer/ServiceHelper.php b/app/Helpers/Customer/ServiceHelper.php index 057b023..41c86ab 100644 --- a/app/Helpers/Customer/ServiceHelper.php +++ b/app/Helpers/Customer/ServiceHelper.php @@ -17,13 +17,6 @@ class ServiceHelper extends CustomerHelper $form = form_dropdown($field, $viewDatas['formOptions'][$field]['options'], $value, $extras); break; case 'serverinfo_uid': - $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field'; - $extras['onChange'] = "document.querySelector('input[name=\'amount\']').value = this.options[this.selectedIndex].getAttribute('data-price')"; - if (array_key_exists('extras', $viewDatas['formOptions'][$field])) { - $extras = array_merge($extras, $viewDatas['formOptions'][$field]['extras']); - } - $form = $this->form_dropdown_custom($field, $viewDatas['formOptions'][$field]['options'], $value, $extras); - break; case 'clientinfo_uid': $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field'; $form = form_dropdown($field, $viewDatas['formOptions'][$field]['options'], $value, $extras); diff --git a/app/Helpers/Equipment/ServerPartHelper.php b/app/Helpers/Equipment/ServerPartHelper.php index a47a2af..ea1ba8a 100644 --- a/app/Helpers/Equipment/ServerPartHelper.php +++ b/app/Helpers/Equipment/ServerPartHelper.php @@ -22,11 +22,10 @@ class ServerPartHelper extends EquipmentHelper case 'part_uid': // dd($viewDatas); $type = array_key_exists('entity', $viewDatas) ? $viewDatas['entity']->getType() : $viewDatas['formDatas']['type']; + // echo "Type:" . $type; + // dd($viewDatas['formOptions'][$field]['options'][$type]); $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field'; $extras['onChange'] = "document.querySelector('input[name=\'amount\']').value = this.options[this.selectedIndex].getAttribute('data-price')"; - if (array_key_exists('extras', $viewDatas['formOptions'][$field])) { - $extras = array_merge($extras, $viewDatas['formOptions'][$field]['extras']); - } $form = $this->form_dropdown_custom($field, $viewDatas['formOptions'][$field]['options'][$type], $value, $extras); break; default: diff --git a/app/Language/en/Auth/Local.php b/app/Language/ko/Auth/Local.php similarity index 100% rename from app/Language/en/Auth/Local.php rename to app/Language/ko/Auth/Local.php diff --git a/app/Language/en/Board.php b/app/Language/ko/Board.php similarity index 100% rename from app/Language/en/Board.php rename to app/Language/ko/Board.php diff --git a/app/Language/en/Customer/Account.php b/app/Language/ko/Customer/Account.php similarity index 100% rename from app/Language/en/Customer/Account.php rename to app/Language/ko/Customer/Account.php diff --git a/app/Language/en/Customer/Client.php b/app/Language/ko/Customer/Client.php similarity index 100% rename from app/Language/en/Customer/Client.php rename to app/Language/ko/Customer/Client.php diff --git a/app/Language/en/Customer/Coupon.php b/app/Language/ko/Customer/Coupon.php similarity index 100% rename from app/Language/en/Customer/Coupon.php rename to app/Language/ko/Customer/Coupon.php diff --git a/app/Language/en/Customer/Point.php b/app/Language/ko/Customer/Point.php similarity index 100% rename from app/Language/en/Customer/Point.php rename to app/Language/ko/Customer/Point.php diff --git a/app/Language/en/Customer/Service.php b/app/Language/ko/Customer/Service.php similarity index 100% rename from app/Language/en/Customer/Service.php rename to app/Language/ko/Customer/Service.php diff --git a/app/Language/en/Equipment/Line.php b/app/Language/ko/Equipment/Line.php similarity index 100% rename from app/Language/en/Equipment/Line.php rename to app/Language/ko/Equipment/Line.php diff --git a/app/Language/en/Equipment/Server.php b/app/Language/ko/Equipment/Server.php similarity index 100% rename from app/Language/en/Equipment/Server.php rename to app/Language/ko/Equipment/Server.php diff --git a/app/Language/en/Equipment/ServerPart.php b/app/Language/ko/Equipment/ServerPart.php similarity index 100% rename from app/Language/en/Equipment/ServerPart.php rename to app/Language/ko/Equipment/ServerPart.php diff --git a/app/Language/en/Mylog.php b/app/Language/ko/Mylog.php similarity index 100% rename from app/Language/en/Mylog.php rename to app/Language/ko/Mylog.php diff --git a/app/Language/en/Part/CPU.php b/app/Language/ko/Part/CPU.php similarity index 100% rename from app/Language/en/Part/CPU.php rename to app/Language/ko/Part/CPU.php diff --git a/app/Language/en/Part/CS.php b/app/Language/ko/Part/CS.php similarity index 100% rename from app/Language/en/Part/CS.php rename to app/Language/ko/Part/CS.php diff --git a/app/Language/en/Part/DISK.php b/app/Language/ko/Part/DISK.php similarity index 100% rename from app/Language/en/Part/DISK.php rename to app/Language/ko/Part/DISK.php diff --git a/app/Language/en/Part/IP.php b/app/Language/ko/Part/IP.php similarity index 100% rename from app/Language/en/Part/IP.php rename to app/Language/ko/Part/IP.php diff --git a/app/Language/en/Part/RAM.php b/app/Language/ko/Part/RAM.php similarity index 100% rename from app/Language/en/Part/RAM.php rename to app/Language/ko/Part/RAM.php diff --git a/app/Language/en/Part/SOFTWARE.php b/app/Language/ko/Part/SOFTWARE.php similarity index 100% rename from app/Language/en/Part/SOFTWARE.php rename to app/Language/ko/Part/SOFTWARE.php diff --git a/app/Language/en/Part/SWITCH.php b/app/Language/ko/Part/SWITCH.php similarity index 100% rename from app/Language/en/Part/SWITCH.php rename to app/Language/ko/Part/SWITCH.php diff --git a/app/Language/en/Payment.php b/app/Language/ko/Payment.php similarity index 100% rename from app/Language/en/Payment.php rename to app/Language/ko/Payment.php diff --git a/app/Language/en/User.php b/app/Language/ko/User.php similarity index 100% rename from app/Language/en/User.php rename to app/Language/ko/User.php diff --git a/app/Language/ko/Validation.php b/app/Language/ko/Validation.php new file mode 100644 index 0000000..6e23f60 --- /dev/null +++ b/app/Language/ko/Validation.php @@ -0,0 +1,38 @@ + '{field} 필드는 필수 입력 항목입니다.', + 'isset' => '{field} 필드는 값이 반드시 있어야 합니다.', + 'valid_email' => '{field} 필드는 유효한 이메일 주소여야 합니다.', + 'valid_url' => '{field} 필드는 유효한 URL이어야 합니다.', + 'valid_date' => '{field} 필드는 유효한 날짜여야 합니다.', + 'valid_dates' => '{field} 필드는 유효한 날짜여야 합니다.', + 'valid_ip' => '{field} 필드는 유효한 IP 주소여야 합니다.', + 'valid_mac' => '{field} 필드는 유효한 MAC 주소여야 합니다.', + 'numeric' => '{field} 필드는 숫자만 포함해야 합니다.', + 'integer' => '{field} 필드는 정수여야 합니다.', + 'decimal' => '{field} 필드는 소수점 숫자여야 합니다.', + 'is_numeric' => '{field} 필드는 숫자 문자만 포함해야 합니다.', + 'regex_match' => '{field} 필드는 올바른 형식이어야 합니다.', + 'matches' => '{field} 필드가 {param} 필드와 일치하지 않습니다.', + 'differs' => '{field} 필드는 {param} 필드와 달라야 합니다.', + 'is_unique' => '{field} 필드는 고유한 값이어야 합니다.', + 'is_natural' => '{field} 필드는 숫자여야 합니다.', + 'is_natural_no_zero' => '{field} 필드는 0보다 큰 숫자여야 합니다.', + 'less_than' => '{field} 필드는 {param}보다 작아야 합니다.', + 'less_than_equal_to' => '{field} 필드는 {param}보다 작거나 같아야 합니다.', + 'greater_than' => '{field} 필드는 {param}보다 커야 합니다.', + 'greater_than_equal_to' => '{field} 필드는 {param}보다 크거나 같아야 합니다.', + 'error_prefix' => '', + 'error_suffix' => '', + + // 길이(Length) 관련 rule 메시지 + 'min_length' => '{field} 필드는 최소 {param}자 이상이어야 합니다.', + 'max_length' => '{field} 필드는 최대 {param}자 이하여야 합니다.', + 'exact_length' => '{field} 필드는 정확히 {param}자여야 합니다.', + 'in_list' => '{field} 필드는 다음 중 하나여야 합니다: {param}.', +]; diff --git a/app/Models/Customer/PointModel.php b/app/Models/Customer/PointModel.php index a612ca7..3d87dd6 100644 --- a/app/Models/Customer/PointModel.php +++ b/app/Models/Customer/PointModel.php @@ -6,7 +6,7 @@ use App\Entities\Customer\PointEntity; class PointModel extends CustomerModel { - const TABLE = "couponinfo"; + const TABLE = "pointinfo"; const PK = "uid"; const TITLE = "title"; protected $table = self::TABLE; diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 01a4eb9..99106a4 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -75,7 +75,6 @@ class ServiceService extends CustomerService "billing_at", "status", 'sale', - 'amount', "history", ]; $filters = [ @@ -127,41 +126,6 @@ class ServiceService extends CustomerService $this->getFormService()->setIndexFilters($indexFilter); $this->getFormService()->setBatchjobFilters($batchjobFilters); } - //기본 기능부분 - protected function getEntity_process(mixed $entity): ServiceEntity - { - return $entity; - } - protected function create_process(array $formDatas): ServiceEntity - { - $formDatas['code'] = $formDatas['site'] . "_s" . uniqid(); - $entity = parent::create_process($formDatas); - if (!$entity instanceof ServiceEntity) { - throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServiceEntity만 가능"); - } - //서비스추가시 호출 - service('equipment_serverservice')->attachToService($entity); - service('paymentservice')->createByService($entity); - return $entity; - } - protected function modify_process($entity, array $formDatas): ServiceEntity - { - $oldEntity = clone $entity; - $entity = parent::modify_process($entity, $formDatas); - if (!$entity instanceof ServiceEntity) { - throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServiceEntity만 가능"); - } - //서비스수정시 호출 - if ($oldEntity->getServerInfoUID() !== $entity->getServerInfoUID()) { - service('equipment_serverservice')->detachFromService($oldEntity); - service('equipment_serverservice')->attachToService($entity); - } - service('paymentservice')->modifyByService($oldEntity, $entity); - return $entity; - } - //List 검색용 - //FormFilter 조건절 처리 - //검색어조건절처리 //추가 기능 //interval을 기준으로 최근 신규 서비스정보 가져오기 final public function getNewServiceEntities(int $interval, string $status = STATUS['AVAILABLE']): array @@ -206,13 +170,76 @@ class ServiceService extends CustomerService // 최종 결과 리턴 (YYYY-MM-DD) return $date->format('Y-m-d'); } - //서비스금액관련처리 - // public function setAmount(ServiceEntity $entity, int $calculatedServerAmount, string $callBack = "updateForService"): ServiceEntity - // { - // //기본:상면비+회선비+서버금액(price)+서버파트연결(월비용)-할인액 - // $amount = $entity->getRack() + $entity->getLine() + $calculatedServerAmount - $entity->getSale(); - // //결제정보 반영 - // $paymentEntity = $this->getPaymentService()->$callBack($entity, $amount); - // return $this->model->modify($entity, ['amount' => $amount, 'payment_uid' => $paymentEntity->getPK()]); - // } + // 서비스금액관련처리 + 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; + } + //기본 기능부분 + protected function getEntity_process(mixed $entity): ServiceEntity + { + return $entity; + } + protected function create_process(array $formDatas): ServiceEntity + { + //필수항목검사 + if (!array_key_exists('serverinfo_uid', $formDatas)) { + throw new RuntimeException(__METHOD__ . '에서 오류발생: 서버정보가 정의되지 않았습니다.'); + } + //서비스코드생성 + $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만 가능"); + } + //서버정보 연결 + service('equipment_serverservice')->attachToService($entity); + //결제정보 연결 + service('paymentservice')->attachToService($entity); + return $entity; + } + protected function modify_process($entity, array $formDatas): ServiceEntity + { + //필수항목검사 + if (!array_key_exists('serverinfo_uid', $formDatas)) { + throw new RuntimeException(__METHOD__ . '에서 오류발생: 서버정보가 정의되지 않았습니다.'); + } + //수정전 서비스정보를 currentEntity 복사해준다. + if ($entity->getServerInfoUID() !== $formDatas['serverinfo_uid']) { + //서버정보 해지처리 + service('equipment_serverservice')->detachFromService($entity); + //결제정보 해지(삭제)처리 + service('paymentservice')->detachFromService($entity); + //서비스 전체금액 구하기 + $formDatas['amount'] = $this->getCalculatedAmount( + (int)$formDatas['serverinfo_uid'], + (int)$formDatas['rack'], + (int)$formDatas['line'], + (int)$formDatas['sale'] + ); + } + //서비스 수정 + $entity = parent::modify_process($entity, $formDatas); + if (!$entity instanceof ServiceEntity) { + throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServiceEntity만 가능"); + } + //서버정보 연결 + service('equipment_serverservice')->attachToService($entity); + //결제정보 연결 + service('paymentservice')->attachToService($entity); + return $entity; + } + //List 검색용 + //FormFilter 조건절 처리 + //검색어조건절처리 } diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 08d97c6..debe44e 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -216,32 +216,18 @@ class ServerService extends EquipmentService } return $rows; } - // public function getCalculatedAmount(ServerEntity $entity): int - // { - // $caculatedAmount = $entity->getPrice(); - // //해당 서비스(서버) 관련 결제방식(Billing)이 Month인 ServerPart 전체를 다시 검사하여 월청구액을 합산한다. - // foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $serverPartEntity) { - // if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) { //월비용일때만 적용 - // $caculatedAmount += $serverPartEntity->getTotalAmount(); //단가*Cnt - // } - // } - // return $caculatedAmount; - // } - // //결제관련처리 - // public function setAmount(ServerEntity $entity): ServerEntity - // { - // if ($entity->getServiceInfoUID() === null) { - // throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다."); - // } - // //서비스정보 반영 - // $serviceEntity = $this->getServiceService()->getEntity($entity->getServiceInfoUID()); - // if (!$serviceEntity instanceof ServiceEntity) { - // throw new \Exception(__METHOD__ . "에서 오류발생: {$entity->getServiceInfoUID()} 서비스 정보를 찾을수 없습니다."); - // } - // $this->getServiceService()->setAmount($serviceEntity, $this->getCalculatedAmount($entity)); - // return $entity; - // } - + //총서버금액 + public function getCalculatedAmount(int $uid): int + { + $entity = $this->getEntity($uid); + $serverPartService = service('equipment_serverpartservice'); + $caculatedAmount = $entity->getPrice(); + //해당 서비스(서버) 관련 결제방식(Billing)이 Month인 ServerPart찾아서 월청구액에 합산한다. + foreach ($serverPartService->getEntities(['serverinfo_uid' => $entity->getPK(), 'billing' => PAYMENT['BILLING']['MONTH']]) as $serverPartEntity) { + $caculatedAmount += $serverPartEntity->getCalculatedAmount(); //단가*Cnt + } + return $caculatedAmount; + } //List 검색용 //FormFilter 조건절 처리 //검색어조건절처리 @@ -255,6 +241,8 @@ class ServerService extends EquipmentService //서비스관련 public function attachToService(ServiceEntity $serviceEntity): void { + //서버정보 가져오기 + $entity = $this->getEntity($serviceEntity->getServerInfoUID()); $formDatas = []; $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); $formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID(); @@ -262,10 +250,12 @@ class ServerService extends EquipmentService $fields = array_keys($formDatas); $this->getFormService()->setFormFields($fields); $this->getFormService()->setFormRules('modify', $fields); - parent::modify_process($serviceEntity, $formDatas); + parent::modify_process($entity, $formDatas); } public function detachFromService(ServiceEntity $serviceEntity): void { + //서버정보 가져오기 + $entity = $this->getEntity($serviceEntity->getServerInfoUID()); $formDatas = []; $formDatas['serviceinfo_uid'] = NULL; $formDatas["clientinfo_uid"] = NULL; @@ -273,6 +263,6 @@ class ServerService extends EquipmentService $fields = array_keys($formDatas); $this->getFormService()->setFormFields($fields); $this->getFormService()->setFormRules('modify', $fields); - parent::modify_process($serviceEntity, $formDatas); + parent::modify_process($entity, $formDatas); } } diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 0bf6997..8718581 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -2,17 +2,18 @@ namespace App\Services; -use RuntimeException; -use DateTime; -use App\Models\PaymentModel; -use App\Helpers\PaymentHelper; -use App\Forms\PaymentForm; -use App\Entities\PaymentEntity; -use App\Entities\Equipment\ServerEntity; -use App\Entities\Customer\ServiceEntity; -use App\Entities\Customer\ClientEntity; -use App\Entities\CommonEntity; use App\DTOs\PaymentDTO; +use App\Entities\CommonEntity; +use App\Entities\Customer\ClientEntity; +use App\Entities\Customer\ServiceEntity; +use App\Entities\Equipment\ServerEntity; +use App\Entities\PaymentEntity; +use App\Forms\PaymentForm; +use App\Helpers\PaymentHelper; +use App\Models\PaymentModel; +use CodeIgniter\Validation\Exceptions\ValidationException; +use DateTime; +use RuntimeException; class PaymentService extends CommonService { @@ -134,70 +135,6 @@ class PaymentService extends CommonService { return $entity; } - //기본 일회성 입력 - protected function create_process(array $formDatas): PaymentEntity - { - if (!array_key_exists('serviceinfo_uid', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 서비스정보가 정의되지 않았습니다.'); - } - if (!array_key_exists('title', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 결제 제목이 정의되지 않았습니다.'); - } - if (!array_key_exists('amount', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 청구금액이 정의되지 않았습니다.'); - } - if (!array_key_exists('billing', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 청구방법이 정의되지 않았습니다.'); - } - if (!array_key_exists('billing_at', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 지급기한일이 정의되지 않았습니다.'); - } - if (!array_key_exists('pay', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 지급방법이 정의되지 않았습니다.'); - } - if (!array_key_exists('status', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 결제상태가 정의되지 않았습니다.'); - } - //서비스 정보 가져오기 - $serviceEntity = service('customer_serviceservice')->getEntity($formDatas['serviceinfo_uid']); - if (!$serviceEntity instanceof ServiceEntity) { - throw new RuntimeException(__METHOD__ . "에서 오류발생: {$formDatas['serviceinfo_uid']} 서비스정보를 찾을수 없습니다."); - } - //서버파트정보 생성 - $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); - $formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID(); - $formDatas['amount'] = $serviceEntity->getAmount(); - $entity = parent::create_process($formDatas); - if (!$entity instanceof PaymentEntity) { - throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 PaymentEntity만 가능"); - } - return $entity; - } - protected function modify_process($entity, array $formDatas): PaymentEntity - { - if (!array_key_exists('serviceinfo_uid', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 서비스정보가 정의되지 않았습니다.'); - } - if (!array_key_exists('title', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 결제 제목이 정의되지 않았습니다.'); - } - if (!array_key_exists('amount', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 청구금액이 정의되지 않았습니다.'); - } - if (!array_key_exists('billing', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 청구방법이 정의되지 않았습니다.'); - } - if (!array_key_exists('billing_at', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 지급기한일이 정의되지 않았습니다.'); - } - if (!array_key_exists('pay', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 지급방법이 정의되지 않았습니다.'); - } - if (!array_key_exists('status', $formDatas)) { - throw new RuntimeException(__METHOD__ . '에서 오류발생: 결제상태가 정의되지 않았습니다.'); - } - return parent::modify_process($entity, $formDatas); - } //List 검색용 //FormFilter 조건절 처리 public function setFilter(string $field, mixed $filter_value): void @@ -272,16 +209,18 @@ class PaymentService extends CommonService } //서비스관련 - public function createByService(ServiceEntity $serviceEntity): void + public function attachToService(ServiceEntity $serviceEntity): void { - //서버파트정보 생성 + //결제정보 생성 $formDatas = []; $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); + $formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID(); $formDatas['title'] = sprintf( "%s %s 서비스비용", $serviceEntity->getTitle(), DateTime::createFromFormat('Y-m-d', $serviceEntity->getBillingAt())->format('Y년 m월') ); + $formDatas['amount'] = $serviceEntity->getAmount(); $formDatas['billing'] = PAYMENT['BILLING']['MONTH']; $formDatas['billing_at'] = $serviceEntity->getBillingAt(); $formDatas['pay'] = PAYMENT['PAY']['ACCOUNT']; @@ -291,35 +230,17 @@ class PaymentService extends CommonService $this->getFormService()->setFormRules('create', $fields); $this->create_process($formDatas); } - public function modifyByService(ServiceEntity $oldServiceEntity, ServiceEntity $serviceEntity): void + public function detachFromService(ServiceEntity $serviceEntity): void { - //수정 전 서비스정보와 수정후 서비스정보의 결제일이 다를경우 수정 전 서비스정보의 결제일을 기준으로 결제정보를 찾은 후 수정 후 정보로 변경한다. - $billing_at = $serviceEntity->getBillingAt(); - if ($oldServiceEntity->getBillingAt() !== $serviceEntity->getBillingAt()) { - $billing_at = $oldServiceEntity->getBillingAt(); - } - //기존 Entity가져오기 - $entity = $this->getEntity(['serviceinifo_uid' => $serviceEntity->getPK(), 'billing_at' => $billing_at]); + //서비스정보의 지급기한일과 같은 결제정보 가져오기 + $entity = $this->getEntity(['serviceinifo_uid' => $serviceEntity->getPK(), 'billing_at' => $serviceEntity->getBillingAt()]); if (!$entity) { throw new \Exception(__METHOD__ . "에서 오류발생: 해당하는 결제정보을 찾을수 없습니다."); } - - //이미 지불이 완료된 결제정보인 경우 + //결제가 완료된 경우라면 처리불가 if ($entity->getStatus() === STATUS['PAID']) { throw new \Exception(__METHOD__ . "에서 오류발생: 해당하는 결제정보는 이미 결제처리가 완료되어 수정이 불가합니다."); } - - //서버파트정보 생성 - $formDatas = []; - $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); - $formDatas['title'] = sprintf( - "%s %s 서비스비용", - $serviceEntity->getTitle(), - DateTime::createFromFormat('Y-m-d', $serviceEntity->getBillingAt())->format('Y년 m월') - ); - $fields = array_keys($formDatas); - $this->getFormService()->setFormFields($fields); - $this->getFormService()->setFormRules('modify', $fields); - $this->modify_process($entity, $formDatas); + $this->delete_process($entity->getPK()); } } diff --git a/app/Views/cells/serverpart/parttable.php b/app/Views/cells/serverpart/parttable.php index 2c9c59a..6fb97ba 100644 --- a/app/Views/cells/serverpart/parttable.php +++ b/app/Views/cells/serverpart/parttable.php @@ -6,7 +6,7 @@ $serverPartCellDatas['helper']->getFieldView($type, $entity->getPK(), $serverPartCellDatas), - 'amount' => $entity->getTotalAmount(), + 'amount' => $entity->getCalculatedAmount(), 'entity' => $entity ] ?> diff --git a/getFormFields()) b/getFormFields()) new file mode 100644 index 0000000..e69de29 diff --git a/getValidationRule($field b/getValidationRule($field new file mode 100644 index 0000000..e69de29 diff --git a/run($formDatas) b/run($formDatas) new file mode 100644 index 0000000..e69de29