diff --git a/app/Cells/Part/CHASSISCell.php b/app/Cells/Equipment/CHASSISCell.php similarity index 65% rename from app/Cells/Part/CHASSISCell.php rename to app/Cells/Equipment/CHASSISCell.php index 75bcbb3..ee45b1d 100644 --- a/app/Cells/Part/CHASSISCell.php +++ b/app/Cells/Equipment/CHASSISCell.php @@ -1,10 +1,8 @@ [ 'entities' => $this->getService()->getEntities(), ], diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 9a3b1af..dd1e01b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -201,6 +201,19 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->post('batchjob_delete', 'ServerPartController::batchjob_delete'); $routes->get('download/(:alpha)', 'ServerPartController::download/$1'); }); + $routes->group('chassis', function ($routes) { + $routes->get('/', 'CHASSISController::index'); + $routes->get('create', 'CHASSISController::create_form'); + $routes->post('create', 'CHASSISController::create'); + $routes->get('modify/(:num)', 'CHASSISController::modify_form/$1'); + $routes->post('modify/(:num)', 'CHASSISController::modify/$1'); + $routes->get('view/(:num)', 'CHASSISController::view/$1'); + $routes->get('delete/(:num)', 'CHASSISController::delete/$1'); + $routes->get('toggle/(:num)/(:any)', 'CHASSISController::toggle/$1/$2'); + $routes->post('batchjob', 'CHASSISController::batchjob'); + $routes->post('batchjob_delete', 'CHASSISController::batchjob_delete'); + $routes->get('download/(:alpha)', 'CHASSISController::download/$1'); + }); }); //Equipment 관련 //Part 관련 @@ -244,19 +257,6 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->post('batchjob_delete', 'CSController::batchjob_delete'); $routes->get('download/(:alpha)', 'CSController::download/$1'); }); - $routes->group('chassis', function ($routes) { - $routes->get('/', 'CHASSISController::index'); - $routes->get('create', 'CHASSISController::create_form'); - $routes->post('create', 'CHASSISController::create'); - $routes->get('modify/(:num)', 'CHASSISController::modify_form/$1'); - $routes->post('modify/(:num)', 'CHASSISController::modify/$1'); - $routes->get('view/(:num)', 'CHASSISController::view/$1'); - $routes->get('delete/(:num)', 'CHASSISController::delete/$1'); - $routes->get('toggle/(:num)/(:any)', 'CHASSISController::toggle/$1/$2'); - $routes->post('batchjob', 'CHASSISController::batchjob'); - $routes->post('batchjob_delete', 'CHASSISController::batchjob_delete'); - $routes->get('download/(:alpha)', 'CHASSISController::download/$1'); - }); $routes->group('cpu', function ($routes) { $routes->get('/', 'CPUController::index'); $routes->get('create', 'CPUController::create_form'); diff --git a/app/Config/Services.php b/app/Config/Services.php index ebb3cf5..6bcb2eb 100644 --- a/app/Config/Services.php +++ b/app/Config/Services.php @@ -13,8 +13,8 @@ use App\Services\Customer\ServiceService; use App\Services\Equipment\LineService; use App\Services\Equipment\ServerPartService; use App\Services\Equipment\ServerService; +use App\Services\Equipment\CHASSISService; use App\Services\MylogService; -use App\Services\Part\CHASSISService; use App\Services\Part\CPUService; use App\Services\Part\CSService; use App\Services\Part\DISKService; @@ -201,7 +201,7 @@ class Services extends BaseService return static::getSharedInstance(__FUNCTION__); } return new CHASSISService( - new \App\Models\Part\CHASSISModel(), + new \App\Models\Equipment\CHASSISModel(), ); } public static function part_cpuservice($getShared = true): CPUService diff --git a/app/Controllers/Admin/Part/CHASSISController.php b/app/Controllers/Admin/Equipment/CHASSISController.php similarity index 77% rename from app/Controllers/Admin/Part/CHASSISController.php rename to app/Controllers/Admin/Equipment/CHASSISController.php index b2703a9..6a7e39c 100644 --- a/app/Controllers/Admin/Part/CHASSISController.php +++ b/app/Controllers/Admin/Equipment/CHASSISController.php @@ -1,13 +1,13 @@ attributes['price']; + } public function getStock(): int { return $this->attributes['stock']; diff --git a/app/Forms/Part/CHASSISForm.php b/app/Forms/Equipment/CHASSISForm.php similarity index 83% rename from app/Forms/Part/CHASSISForm.php rename to app/Forms/Equipment/CHASSISForm.php index 28d91b4..61b634e 100644 --- a/app/Forms/Part/CHASSISForm.php +++ b/app/Forms/Equipment/CHASSISForm.php @@ -1,8 +1,8 @@ updateAmount($entity->getPK()); //결제정보 생성 - service('paymentservice')->createByService($entity); + service('paymentservice')->modifyByService($entity); return $entity; } //List 검색용 diff --git a/app/Services/Part/CHASSISService.php b/app/Services/Equipment/CHASSISService.php similarity index 69% rename from app/Services/Part/CHASSISService.php rename to app/Services/Equipment/CHASSISService.php index 0451ca6..335000e 100644 --- a/app/Services/Part/CHASSISService.php +++ b/app/Services/Equipment/CHASSISService.php @@ -1,15 +1,15 @@ model->orderBy('title ASC'); parent::setOrderBy($field, $value); } - //서버파트관련 작업 + //서버관련 작업 //파트정보가져오기 - public function getPartEntityByServerPart(ServerPartEntity $serverPartEntity): CHASSISEntity + public function getPartEntityByServer(ServerEntity $serverEntity): CHASSISEntity { //IP정보에서 해당하는 IP가 있으면 가져와서 사용중인지 체크 후 수정 - $entity = $this->getEntity($serverPartEntity->getPartUID()); + $entity = $this->getEntity($serverEntity->getChassisInfoUID()); if (!$entity instanceof CHASSISEntity) { - throw new \Exception(message: "{$serverPartEntity->getPartUID()}에 해당하는 CHASSISEntity정보를 찾을수없습니다."); + throw new \Exception("{$serverEntity->getChassisInfoUID()}에 해당하는 샷시정보를 찾을수없습니다."); } return $entity; } - public function attachToServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): CHASSISEntity + public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): CHASSISEntity { + //부품정보가져오기 /** @var CHASSISEntity $entity IDE에 entity type알려주기*/ - $entity = parent::attachToServerPart($serverPartEntity, $formDatas); - return $entity; + $entity = $this->getEntity($serverEntity->getChassisInfoUID()); + //파트정보의 사용가능한 갯수 , 사용갯수 비교 + if ($entity->getAvailable() < 1) { + throw new \Exception("현재 사용가능한 {$serverEntity->getTitle()} 샷시가 없습니다."); + } + $formDatas['used'] = $entity->getUsed() + 1; + return parent::modify_process($entity, $formDatas); } - public function detachFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): CHASSISEntity + + public function detachFromServer(ServerEntity $serverEntity, array $formDatas = []): CHASSISEntity { + //부품정보가져오기 /** @var CHASSISEntity $entity IDE에 entity type알려주기*/ - $entity = parent::detachFromServerPart($serverPartEntity, $formDatas); - return $entity; + $entity = $this->getEntity($serverEntity->getChassisInfoUID()); + //파트정보의 사용된 갯수 , 회수용 갯수 비교 + if ($entity->getUsed() < 1) { + throw new \Exception("현재 사용한 {$serverEntity->getTitle()} 샷시가 없습니다."); + } + $formDatas['used'] = $entity->getUsed() - 1; + return parent::modify_process($entity, $formDatas); } } diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 06d95ed..4cdf784 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -10,8 +10,6 @@ use App\Forms\Equipment\ServerPartForm; use App\Entities\Part\PartEntity; use App\Entities\Equipment\ServerPartEntity; use App\Entities\Equipment\ServerEntity; -use App\Entities\Customer\ServiceEntity; -use App\Entities\CommonEntity; use App\DTOs\Equipment\ServerPartDTO; class ServerPartService extends EquipmentService @@ -174,11 +172,11 @@ class ServerPartService extends EquipmentService //검색어조건절처리 //서버추가시 기본파트 자동추가용 - public function attachToServer(ServerEntity $serverEntity): void + public function defaultServerPart(ServerEntity $serverEntity): void { //*서버의 Title 대소문자구분 필요->서버의 Title로 구분해서 기본부품 추가 foreach (SERVERPART['SERVER_PARTTYPES'] as $parttype) { - //해당 서버의 chassis_uid에 해당하는 상수값이 있는지 체크 + //해당 서버의 chassis_uid에 해당하는 Default값이 있는지 체크 후 서버파트 추가 if (array_key_exists($serverEntity->getChassisInfoUID(), SERVERPART[$parttype])) { foreach (SERVERPART[$parttype][$serverEntity->getChassisInfoUID()] as $part) { //해당 파트정보 가져오기 @@ -202,20 +200,13 @@ class ServerPartService extends EquipmentService $this->getFormService()->setFormRules('create', $fields); $this->create_process($formDatas); } - } else { - log_message("warning", __METHOD__ . "에서 결고발생: {$parttype} 파트 => SERVERPART[{$serverEntity->getChassisInfoUID()}] Default값이 정의되지 않았습니다."); } } } public function detachFromServer(ServerEntity $serverEntity): void { //서버정보에 해당하는 ServerPart정보 상태가 기본인것 제외한 모두 회수처리. - foreach ( - $this->getEntities([ - 'serverinfo_uid' => $serverEntity->getPK(), - "billing !=" => PAYMENT['BILLING']['BASE'] - ]) as $entity - ) { + foreach ($this->getEntities(['serverinfo_uid' => $serverEntity->getPK(), "billing !=" => PAYMENT['BILLING']['BASE']]) as $entity) { $this->getPartService($entity->getType())->detachFromServerPart($entity); parent::delete_process($entity); } diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 8ab4706..315d63b 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -216,21 +216,39 @@ class ServerService extends EquipmentService //서버추가시 서버파트 자동추가용 service('part_ipservice')->attachToServer($entity); service('part_switchservice')->attachToServer($entity); + service('equipment_chassisservice')->attachToServer($entity); service('equipment_serverpartservice')->attachToServer($entity); - //Billing형식이 Month이면 서버쪽 금액설정 호출 - if ($entity->getServiceInfoUID() !== null) { - service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID()); - } return $entity; } protected function modify_process($entity, array $formDatas): ServerEntity { + //필수항목검사 + if (!array_key_exists('chassisinfo_uid', $formDatas)) { + throw new RuntimeException(__METHOD__ . '에서 오류발생: 샷시정보가 정의되지 않았습니다.'); + } + //변경전 정보 + $oldEntity = clone $entity; $entity = parent::modify_process($entity, $formDatas); if (!$entity instanceof ServerEntity) { throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServerEntity만 가능"); } - //Billing형식이 Month이면 서버쪽 금액설정 호출 - if ($entity->getServiceInfoUID() !== null) { + //서버정보변경시 서버파트 정보변경용 + //IP변경 + if ($oldEntity->getIP() !== $entity->getIP()) { + service('part_ipservice')->detachFromServer($oldEntity); + service('part_ipservice')->attachToServer($entity); + } + //SWITCH변경 + if ($oldEntity->getSwitchInfoUID() !== $entity->getSwitchInfoUID()) { + service('part_switchservice')->detachFromServer($oldEntity); + service('part_switchservice')->attachToServer($entity); + } + //샷시변경 + if ($oldEntity->getSwitchInfoUID() !== $entity->getSwitchInfoUID()) { + service('equipment_chassisservice')->detachFromServer($oldEntity); + service('equipment_chassisservice')->attachToServer($entity); + } + if ($entity->getServiceInfoUID() !== null) { //서비스가 정의 되어 있으면 service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID()); } return $entity; @@ -269,6 +287,8 @@ class ServerService extends EquipmentService } $formDatas['serviceinfo_uid'] = NULL; $formDatas["clientinfo_uid"] = NULL; + $formDatas["switchinfo_uid"] = NULL; + $formDatas["ip"] = NULL; $formDatas['status'] = $formDatas['status'] ?? STATUS['AVAILABLE']; $fields = array_keys($formDatas); $this->getFormService()->setFormFields($fields); diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 6bf70cd..a4480ab 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -7,6 +7,7 @@ use App\Entities\CommonEntity; use App\Entities\Customer\ClientEntity; use App\Entities\Customer\ServiceEntity; use App\Entities\Equipment\ServerEntity; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\PaymentEntity; use App\Forms\PaymentForm; use App\Helpers\PaymentHelper; @@ -262,7 +263,7 @@ class PaymentService extends CommonService //서비스정보의 지급기한일과 같은 결제정보 가져와서 결제정보 수정 $entity = $this->getEntity(['serviceinfo_uid' => $serviceEntity->getPK(), 'billing_at' => $serviceEntity->getBillingAt()]); if (!$entity instanceof PaymentEntity) { - throw new \Exception(__METHOD__ . "에서 오류발생: 해당하는 결제정보을 찾을수 없습니다."); + throw new \Exception(__METHOD__ . "에서 오류발생: [{$serviceEntity->getPK()}]{$serviceEntity->getTitle()}에 해당하는 결제정보을 찾을수 없습니다."); } $formDatas = $this->getFormDatasByService($serviceEntity); $fields = array_keys($formDatas); @@ -270,4 +271,44 @@ class PaymentService extends CommonService $this->getFormService()->setFormRules('modify', $fields); return parent::modify_process($entity, $formDatas); } + //서버파트별 일회성 관련 + private function getFormDatasByServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): array + { + if ($serverPartEntity->getServiceInfoUID() === null) { + throw new RuntimeException(__METHOD__ . "에서 오류발생: 서비스정보가 정의되지 않아 일회성 상품을 설정하실수 없습니다."); + } + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + $formDatas["clientinfo_uid"] = $serverPartEntity->getClientInfoUID(); + $formDatas['amount'] = $serverPartEntity->getAmount(); + $formDatas['billing'] = $formDatas['billing'] ?? PAYMENT['BILLING']['ONETIME']; + $formDatas['billing_at'] = date('Y-m-d'); + $formDatas['pay'] = $formDatas['pay'] ?? PAYMENT['PAY']['ACCOUNT']; + $formDatas['status'] = $formDatas['status'] ?? STATUS['UNPAID']; + $formDatas['title'] = sprintf("%s 일회성비용", $formDatas['title'] ?? $serverPartEntity->getTitle()); + return $formDatas; + } + public function createByServerPart(ServerPartEntity $serverPartEntity): PaymentEntity + { + $formDatas = $this->getFormDatasByServerPart($serverPartEntity); + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('create', $fields); + return parent::create_process($formDatas); + } + public function modifyByServerPart(ServerPartEntity $serverPartEntity): PaymentEntity + { + if ($serverPartEntity->getServiceInfoUID() === null) { + throw new RuntimeException(__METHOD__ . "에서 오류발생: 서비스정보가 정의되지 않아 일회성 상품을 설정하실수 없습니다."); + } + //서비스정보의 지급기한일과 같은 결제정보 가져와서 결제정보 수정 + $entity = $this->getEntity(['serverpartinfo_uid' => $serverPartEntity->getPK()]); + if (!$entity instanceof PaymentEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: [{$serverPartEntity->getPK()}]{$serverPartEntity->getTitle()}에 해당하는 결제정보을 찾을수 없습니다."); + } + $formDatas = $this->getFormDatasByServerPart($serverPartEntity); + $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/welcome/stock.php b/app/Views/admin/welcome/stock.php index c43d9da..5e37b12 100644 --- a/app/Views/admin/welcome/stock.php +++ b/app/Views/admin/welcome/stock.php @@ -15,7 +15,7 @@