diff --git a/app/Controllers/Admin/PaymentController.php b/app/Controllers/Admin/PaymentController.php index 93adee9..b23d069 100644 --- a/app/Controllers/Admin/PaymentController.php +++ b/app/Controllers/Admin/PaymentController.php @@ -27,9 +27,18 @@ class PaymentController extends AdminController final public function onetime_form(): string|RedirectResponse { try { + $uid = $this->request->getVar('serviceinfo_uid'); + if (!$uid) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스정보 번호가 정의되지 않았습니다.."); + } + $serviceEntity = service('customer_serviceservice')->getEntity($uid); + if (!$serviceEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보을 찾을수 없습니다."); + } $action = __FUNCTION__; $formDatas = []; - $formDatas['serviceinfo_uid'] = $this->request->getVar('serviceinfo_uid'); + $formDatas['serviceinfo_uid'] = $uid; + $formDatas['title'] = $serviceEntity->getTitle() . " 일회성 결제"; $formDatas['billing'] = PAYMENT['BILLING']['ONETIME']; $formDatas['billing_at'] = date('Y-m-d'); $formDatas['pay'] = PAYMENT['PAY']['ACCOUNT']; @@ -44,11 +53,21 @@ class PaymentController extends AdminController final public function prepayment_form(): string|RedirectResponse { try { + $uid = $this->request->getVar('serviceinfo_uid'); + if (!$uid) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스정보 번호가 정의되지 않았습니다.."); + } + $serviceEntity = service('customer_serviceservice')->getEntity($uid); + if (!$serviceEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보을 찾을수 없습니다."); + } $action = __FUNCTION__; $formDatas = []; - $formDatas['serviceinfo_uid'] = $this->request->getVar('serviceinfo_uid'); + $formDatas['serviceinfo_uid'] = $uid; + $formDatas['title'] = $serviceEntity->getTitle() . " 선결제"; + $formDatas['amount'] = $serviceEntity->getAmount(); $formDatas['billing'] = PAYMENT['BILLING']['PREPAYMENT']; - $formDatas['billing_at'] = date('Y-m-d'); + $formDatas['billing_at'] = $serviceEntity->getBillingAt(); $formDatas['pay'] = PAYMENT['PAY']['ACCOUNT']; $formDatas['status'] = STATUS['PAID']; $this->action_init_process($action, $formDatas); @@ -61,9 +80,18 @@ class PaymentController extends AdminController final public function coupon_form(): string|RedirectResponse { try { + $uid = $this->request->getVar('serviceinfo_uid'); + if (!$uid) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스정보 번호가 정의되지 않았습니다.."); + } + $serviceEntity = service('customer_serviceservice')->getEntity($uid); + if (!$serviceEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보을 찾을수 없습니다."); + } $action = __FUNCTION__; $formDatas = []; - $formDatas['serviceinfo_uid'] = $this->request->getVar('serviceinfo_uid'); + $formDatas['serviceinfo_uid'] = $uid; + $formDatas['title'] = $serviceEntity->getTitle() . " 쿠폰 결제"; $formDatas['billing'] = PAYMENT['BILLING']['ONETIME']; $formDatas['billing_at'] = date('Y-m-d'); $formDatas['pay'] = PAYMENT['PAY']['COUPON']; @@ -78,9 +106,18 @@ class PaymentController extends AdminController final public function point_form(): string|RedirectResponse { try { + $uid = $this->request->getVar('serviceinfo_uid'); + if (!$uid) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스정보 번호가 정의되지 않았습니다.."); + } + $serviceEntity = service('customer_serviceservice')->getEntity($uid); + if (!$serviceEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보을 찾을수 없습니다."); + } $action = __FUNCTION__; $formDatas = []; - $formDatas['serviceinfo_uid'] = $this->request->getVar('serviceinfo_uid'); + $formDatas['serviceinfo_uid'] = $uid; + $formDatas['title'] = $serviceEntity->getTitle() . " 포인트 결제"; $formDatas['billing'] = PAYMENT['BILLING']['ONETIME']; $formDatas['billing_at'] = date('Y-m-d'); $formDatas['pay'] = PAYMENT['PAY']['POINT']; diff --git a/app/Helpers/Customer/ServiceHelper.php b/app/Helpers/Customer/ServiceHelper.php index 810c9e5..675e5b8 100644 --- a/app/Helpers/Customer/ServiceHelper.php +++ b/app/Helpers/Customer/ServiceHelper.php @@ -107,7 +107,7 @@ class ServiceHelper extends CustomerHelper sprintf("%s건/%s원", $viewDatas['unPaids'][$viewDatas['entity']->getPK()]['cnt'], number_format($viewDatas['unPaids'][$viewDatas['entity']->getPK()]['amount'])), 'payment_unpaid', [ - "data-src" => "/admin/payment?clientinfo_uid={$viewDatas['entity']->getPK()}&status=unpaid&ActionTemplate=popup", + "data-src" => "/admin/payment?serviceinfo_uid={$viewDatas['entity']->getPK()}&status=unpaid&ActionTemplate=popup", "data-bs-toggle" => "modal", "data-bs-target" => "#modal_action_form", "class" => "text-primary form-label-sm", diff --git a/app/Helpers/PaymentHelper.php b/app/Helpers/PaymentHelper.php index 54988ef..87e0eb9 100644 --- a/app/Helpers/PaymentHelper.php +++ b/app/Helpers/PaymentHelper.php @@ -12,11 +12,62 @@ class PaymentHelper extends CommonHelper { switch ($field) { case 'billing': + $forms = []; + array_shift($viewDatas['formOptions'][$field]['options']); //Radio 선택기는 첫번째 옵션제거해야 함 + foreach ($viewDatas['formOptions'][$field]['options'] as $key => $label) { + $form_month = ""; + if ($key == PAYMENT['BILLING']['PREPAYMENT'] && array_key_exists('billing', $viewDatas['formDatas']) && $viewDatas['formDatas']['billing'] == PAYMENT['BILLING']['PREPAYMENT']) { + $initalTitle = $viewDatas['formDatas']['title']; + $initalAmount = $viewDatas['formDatas']['amount']; + $initalBillingAt = $viewDatas['formDatas']['billing_at']; + $months = ["" => "개월 선택"]; + for ($i = 1; $i <= 12; $i++) { + $months[$i] = "{$i}개월"; + } + $js_onChange = " + var originalText = '{$initalTitle}'; + var originalAmount = parseInt({$initalAmount}); + var originalBillingAt = '{$initalBillingAt}'; + var month = parseInt(this.options[this.selectedIndex].value) || 1; // 숫자가 아니면 1로 처리 + // 선택된 개월 수에 따라 제목과 금액 결제일 업데이트 + document.querySelector('input[name=\'title\']').value = originalText + ' '+month + '개월'; + document.querySelector('input[name=\'amount\']').value = originalAmount * month; + // billing_at 날짜 계산 + var parts = originalBillingAt.split('-'); // 예: ['2025', '1', '25'] + // 1. Date 객체 생성 시 월(parts[1])에서 1을 빼줍니다. JavaScript의 월 인덱스는 0부터 시작하기 때문입니다 (0=1월, 1=2월...). + var year = parseInt(parts[0]); + var monthIndex = parseInt(parts[1]) - 1; + var day = parseInt(parts[2]); + var newDate = new Date(year, monthIndex, day); + // 2. setMonth 로직 수정: + // month 변수 (1~12)를 더하는 것이 아니라, + // 현재 월 인덱스에 선택된 개월 수를 더해야 합니다. + // getMonth()는 현재 인덱스를 반환하며, month는 추가할 개월 수입니다. + // (예: 1월(index 0)에 1개월(month 1) 추가 -> newDate.setMonth(0 + 1)) + newDate.setMonth(newDate.getMonth() + month); + // 3. YYYY-MM-DD 형식으로 다시 포맷팅 (toISOString 사용 시 타임존 오류 발생 방지) + var formattedDate = newDate.getFullYear() + '-' + + ('0' + (newDate.getMonth() + 1)).slice(-2) + '-' + // 월을 1부터 시작하게 하고 2자리로 포맷 + ('0' + newDate.getDate()).slice(-2); // 일을 2자리로 포맷 + document.querySelector('input[name=\'billing_at\']').value = formattedDate; + "; + $dropdown_attrs = ['id' => 'prepayment_months', 'onChange' => $js_onChange]; + $form_month = form_dropdown('prepayment_month', $months, $viewDatas['prepayment_month'] ?? '', $dropdown_attrs); + } + $radio_attrs = ['id' => $field . '_' . $key]; + if ($key == $value) { + $radio_attrs['checked'] = true; + } + $forms[] = form_radio($field, $key, false, $radio_attrs) . $label . " " . $form_month; + } + $form = implode(" ", $forms); + break; case 'pay': $forms = []; array_shift($viewDatas['formOptions'][$field]['options']); - foreach ($viewDatas['formOptions'][$field]['options'] as $key => $label) + foreach ($viewDatas['formOptions'][$field]['options'] as $key => $label) { $forms[] = form_radio($field, $key, $key == $value, $extras) . $label; + } $form = implode(" ", $forms); break; default: diff --git a/app/Views/cells/service/payment.php b/app/Views/cells/service/payment.php index f82297a..d1daa18 100644 --- a/app/Views/cells/service/payment.php +++ b/app/Views/cells/service/payment.php @@ -15,7 +15,7 @@