dbmsv4 init...2

This commit is contained in:
최준흠 2025-12-03 14:49:07 +09:00
parent fba37415c4
commit d94c03b672
4 changed files with 83 additions and 54 deletions

View File

@ -2,7 +2,6 @@
namespace App\Controllers;
use App\Entities\CommonEntity;
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse;
use PhpOffice\PhpSpreadsheet\IOFactory;

View File

@ -176,28 +176,33 @@ class ServiceService extends CustomerService
return $date->format('Y-m-d');
}
// 서비스금액관련처리
final public function getCalculatedAmount(int $serverinfo_uid, int $rack, int $line, int $sale): int
private function getCacluatedAmount(ServiceEntity $entity): int
{
$server_amount = service('equipment_serverservice')->getCalculatedAmount($serverinfo_uid);
//총 서비스금액 구하기
$server_amount = service('equipment_serverservice')->getCalculatedAmount($entity->getServerInfoUID());
//기본:서버금액(서버비+서버파트(월비용))+상면비+회선비-할인액
$amount = (int)$server_amount + $rack + $line - $sale;
// echo "{$server_amount} + {$rack} + $line - {$sale} = {$amount}";
// exit;
return $amount;
$caculatedAmount = (int)$server_amount + $entity->getRack() + $entity->getLine() - $entity->getSale();
return $caculatedAmount;
}
private function updateAmount(ServiceEntity $entity): ServiceEntity
final public function updateAmount(int $uid): ServiceEntity
{
$entity = $this->getEntity($uid);
if (!$entity instanceof ServiceEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$uid} 서비스 정보를 찾을수 없습니다.");
}
$action = 'modify';
$fields = ['amount'];
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules($action, $fields);
$formDatas['amount'] = $this->getCalculatedAmount(
$entity->getServerInfoUID(),
$entity->getRack(),
$entity->getLine(),
$entity->getSale()
);
return parent::modify_process($entity, $formDatas);
$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);
}
//기본 기능부분
protected function getEntity_process(mixed $entity): ServiceEntity
@ -218,10 +223,10 @@ class ServiceService extends CustomerService
if (!$entity instanceof ServiceEntity) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServiceEntity만 가능");
}
//서비스비용 설정
$entity = $this->updateAmount($entity);
//서버정보 연결
service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID());
//서비스비용 설정
$entity = $this->updateAmount($entity->getPK());
//결제정보 생성
service('paymentservice')->createByService($entity);
return $entity;
@ -239,14 +244,14 @@ class ServiceService extends CustomerService
if (!$entity instanceof ServiceEntity) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServiceEntity만 가능");
}
//서비스비용 설정
$entity = $this->updateAmount($entity);
//서버정보 연결 신규서버로 변경되었으면 신규서버 추가
if ($oldEntity->getServerInfoUID() !== $entity->getServerInfoUID()) {
service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID());
}
//결제정보 수정
service('paymentservice')->modifyByService($entity);
//서비스비용 설정
$entity = $this->updateAmount($entity->getPK());
//결제정보 생성
service('paymentservice')->createByService($entity);
return $entity;
}
//List 검색용

View File

@ -10,6 +10,7 @@ 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;
@ -132,6 +133,14 @@ class ServerPartService extends EquipmentService
}
//해당 파트별 설정 수정
$this->getPartService($entity->getType())->attachToServerPart($entity);
if ($entity->getServiceInfoUID() !== null) { //서비스가 정의 되어 있으면
if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) { //Billing형식이 Month이면 서비스 금액설정 호출
service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID());
}
if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) { //Billing형식이 Onetime이면 일회성결제 추가
service('paymentservice')->createByServerPart($entity);
}
}
return $entity;
}
protected function modify_process($entity, array $formDatas): ServerPartEntity
@ -144,7 +153,16 @@ class ServerPartService extends EquipmentService
//해당 파트정보 Title 설정용
$formDatas['title'] = $partEntity->getTitle();
//서버파트 수정
return parent::modify_process($entity, $formDatas);
$entity = parent::modify_process($entity, $formDatas);
if ($entity->getServiceInfoUID() !== null) { //서비스가 정의 되어 있으면
if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) { //Billing형식이 Month이면 서비스 금액설정 호출
service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID());
}
if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) { //Billing형식이 Onetime이면 일회성결제 추가
service('paymentservice')->modifyByServerPart($entity);
}
}
return $entity;
}
protected function delete_process($entity): ServerPartEntity
{
@ -166,7 +184,7 @@ class ServerPartService extends EquipmentService
//해당 파트정보 가져오기
$partEntity = $this->getPartService($parttype)->getEntity($part['UID']);
if (!$partEntity instanceof PartEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$part['UID']} 서버 정보를 찾을수 없습니다.");
throw new \Exception(__METHOD__ . "에서 오류발생: {$part['UID']} 파트정보를 찾을수 없습니다.");
}
//서버파트정보 생성
$formDatas = [];

View File

@ -119,35 +119,6 @@ class ServerService extends EquipmentService
$this->getFormService()->setIndexFilters($indexFilter);
$this->getFormService()->setBatchjobFilters($batchjobFilters);
}
//기본 기능부분
protected function getEntity_process(mixed $entity): ServerEntity
{
return $entity;
}
protected function create_process(array $formDatas): ServerEntity
{
$entity = parent::create_process($formDatas);
if (!$entity instanceof ServerEntity) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServerEntity만 가능");
}
//서버추가시 서버파트 자동추가용
service('part_ipservice')->attachToServer($entity);
service('part_switchservice')->attachToServer($entity);
service('equipment_serverpartservice')->attachToServer($entity);
return $entity;
}
protected function modify_process($entity, array $formDatas): ServerEntity
{
$entity = parent::modify_process($entity, $formDatas);
if (!$entity instanceof ServerEntity) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServerEntity만 가능");
}
return $entity;
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리
//추가기능
final public function getTotalServiceCount(array $where = []): array
{
$totalCounts = [
@ -217,9 +188,12 @@ class ServerService extends EquipmentService
return $rows;
}
//총서버금액
public function getCalculatedAmount(int $uid): int
final public function getCacluatedAmount(int $uid): int
{
$entity = $this->getEntity($uid);
$entity = $this->getEntity($uid);
if (!$entity instanceof ServerEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$uid} 서버 정보를 찾을수 없습니다.");
}
$serverPartService = service('equipment_serverpartservice');
$caculatedAmount = $entity->getPrice();
//해당 서비스(서버) 관련 결제방식(Billing)이 Month인 ServerPart찾아서 월청구액에 합산한다.
@ -228,6 +202,39 @@ class ServerService extends EquipmentService
}
return $caculatedAmount;
}
//기본 기능부분
protected function getEntity_process(mixed $entity): ServerEntity
{
return $entity;
}
protected function create_process(array $formDatas): ServerEntity
{
$entity = parent::create_process($formDatas);
if (!$entity instanceof ServerEntity) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServerEntity만 가능");
}
//서버추가시 서버파트 자동추가용
service('part_ipservice')->attachToServer($entity);
service('part_switchservice')->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
{
$entity = parent::modify_process($entity, $formDatas);
if (!$entity instanceof ServerEntity) {
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServerEntity만 가능");
}
//Billing형식이 Month이면 서버쪽 금액설정 호출
if ($entity->getServiceInfoUID() !== null) {
service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID());
}
return $entity;
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리