dbmsv3 init...1
This commit is contained in:
parent
4f9aa2a7f0
commit
2c207d1d38
@ -40,6 +40,7 @@ class PaymentController extends CustomerController
|
||||
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string
|
||||
{
|
||||
switch ($this->getService()->getAction()) {
|
||||
case 'index':
|
||||
case 'invoice':
|
||||
$this->service = $this->getService();
|
||||
$this->control = $this->getService()->getControlDatas();
|
||||
|
||||
@ -3,54 +3,62 @@
|
||||
namespace App\Controllers\CLI;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Entities\PaymentEntity;
|
||||
use App\Entities\Customer\ServiceEntity;
|
||||
use App\Services\Customer\ServiceService;
|
||||
use App\Services\PaymentService;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Payment extends BaseController
|
||||
{
|
||||
private $_db;
|
||||
private ?ServiceService $_serviceService = null;
|
||||
private ?PaymentService $_paymentService = null;
|
||||
private ?ServiceService $_service = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_db = \Config\Database::connect();
|
||||
}
|
||||
public function getServiceService(): ServiceService
|
||||
public function getService(): ServiceService
|
||||
{
|
||||
if (!$this->_serviceService) {
|
||||
$this->_serviceService = new ServiceService();
|
||||
if (!$this->_service) {
|
||||
$this->_service = new ServiceService();
|
||||
}
|
||||
return $this->_serviceService;
|
||||
return $this->_service;
|
||||
}
|
||||
public function getPaymentService(): PaymentService
|
||||
{
|
||||
if (!$this->_paymentService) {
|
||||
$this->_paymentService = new PaymentService();
|
||||
}
|
||||
return $this->_paymentService;
|
||||
}
|
||||
public function billing(): void
|
||||
{
|
||||
//Transaction Start
|
||||
$this->_db->transStart();
|
||||
$db = \Config\Database::connect();
|
||||
$db->transStart();
|
||||
try {
|
||||
//서비스중 결제일이 오늘이고, 상태가 사용중이 경우만 서비스 모두 연장처리
|
||||
$this->getServiceService()->extendBillingAt(date('Y-m-d'), STATUS['UNPAID']);
|
||||
log_message("notice", "Billing 작업을 시작.");
|
||||
//결제일이 오늘보다 크고, 상태가 사용중인 서비스정보를 이용해서 결제정보에 신규 추가하기
|
||||
foreach ($this->getServiceService()->getEntities(['billing_at' => date("Y-m-d"), 'status' => ServiceEntity::DEFAULT_STATUS]) as $serviceEntity) {
|
||||
foreach ($this->getService()->getEntities(['billing_at' => date("Y-m-d"), 'status' => STATUS['AVAILABLE']]) as $entity) {
|
||||
// echo $serviceEntity->getPK() . ":" . $serviceEntity->getBillingAt() . "\n";
|
||||
foreach ($this->getServiceItemService()->getEntities(['serviceinfo_uid' => $serviceEntity->getPK()]) as $itemEntity) {
|
||||
//결제정보 ServicePaymentService에 월별 결제만 신규등록
|
||||
if ($itemEntity->getBillingCycle() == "month") {
|
||||
//결제정보 ServicePaymentService에 등록
|
||||
$paymentFormDatas = ['status' => STATUS['UNPAID']];
|
||||
$this->getServicePaymentService()->createByServiceItemService($paymentFormDatas, $itemEntity);
|
||||
}
|
||||
}
|
||||
$entity = $this->getPaymentService()->setService('create', $entity, []);
|
||||
$entity = $this->getService()->modify(
|
||||
$entity,
|
||||
[
|
||||
'billing_at' => $this->getService()->getNextMonthDate($entity),
|
||||
'paymentifo_uid' => $entity->getPaymentEntity()->getPK(),
|
||||
'serverinfo_uid' => $entity->getServerEntity()->getPK()
|
||||
]
|
||||
);
|
||||
log_message("notice", sprintf("%s/%s원 결제추가\n", $entity->getCustomTitle(), $entity->getAmount()));
|
||||
}
|
||||
// echo $this->getServiceService()->getModel()->getLastQuery() . "\n";
|
||||
log_message("notice", "Billing 작업을 완료하였습니다.");
|
||||
$this->_db->transCommit();
|
||||
// echo $this->getService()->getModel()->getLastQuery() . "\n";
|
||||
log_message("notice", "Billing 작업을 완료.");
|
||||
$db->transCommit();
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$this->_db->transRollback();
|
||||
$db->transRollback();
|
||||
log_message(
|
||||
"error",
|
||||
"Billing 작업을 실패하였습니다.\n--------------\n" .
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -12,7 +12,7 @@ return [
|
||||
'billing_at' => "지급기한일",
|
||||
'pay' => "지급방법",
|
||||
'status' => "상태",
|
||||
'updated_at' => "지급일",
|
||||
'updated_at' => "변경일",
|
||||
'created_at' => "생성일",
|
||||
'deleted_at' => "삭제일",
|
||||
'countdown' => "납부기한",
|
||||
|
||||
@ -10,6 +10,7 @@ use App\Models\Customer\ServiceModel;
|
||||
use App\Services\Equipment\ServerPartService;
|
||||
use App\Services\Equipment\ServerService;
|
||||
use App\Services\PaymentService;
|
||||
use DateTime;
|
||||
|
||||
class ServiceService extends CustomerService
|
||||
{
|
||||
@ -158,15 +159,35 @@ class ServiceService extends CustomerService
|
||||
}
|
||||
return $amounts;
|
||||
}
|
||||
//다음 달로 결제일을 연장합니다.
|
||||
final public function extendBillingAt(string $billing_at, string $status): bool
|
||||
//다음 달로 결제일 가져오기.
|
||||
final public function getNextMonthDate(ServiceEntity $entity): string
|
||||
{
|
||||
$sql = "UPDATE serviceinfo SET billing_at =
|
||||
IF(DAY(billing_at) > DAY(LAST_DAY(billing_at)),
|
||||
LAST_DAY(DATE_ADD(billing_at, INTERVAL 1 MONTH)),
|
||||
DATE_ADD(billing_at, INTERVAL 1 MONTH)
|
||||
) WHERE billing_at = ? AND status = ?";
|
||||
return $this->getModel()->query($sql, [$billing_at, $status]);
|
||||
// $sql = "UPDATE serviceinfo SET billing_at =
|
||||
// IF(DAY(billing_at) > DAY(LAST_DAY(billing_at)),
|
||||
// LAST_DAY(DATE_ADD(billing_at, INTERVAL 1 MONTH)),
|
||||
// DATE_ADD(billing_at, INTERVAL 1 MONTH)
|
||||
// ) WHERE uid = ?";
|
||||
// return $this->getModel()->query($sql, [$entity->getPK()]);
|
||||
// 입력된 날짜를 DateTime 객체로 변환
|
||||
$date = new DateTime($entity->getBillingAt());
|
||||
// 현재 일(day)을 저장
|
||||
$day = (int)$date->format('d');
|
||||
// 다음달로 이동 (DateInterval 사용)
|
||||
$date->modify('first day of next month');
|
||||
// 다음달의 마지막 날 계산
|
||||
$lastDayOfNextMonth = (int)$date->format('t');
|
||||
// 현재 날짜가 다음달의 마지막 날보다 크면 -> 마지막 날로 설정
|
||||
if ($day > $lastDayOfNextMonth) {
|
||||
$day = $lastDayOfNextMonth;
|
||||
}
|
||||
// 일(day)을 설정
|
||||
$date->setDate(
|
||||
(int)$date->format('Y'),
|
||||
(int)$date->format('m'),
|
||||
$day
|
||||
);
|
||||
// 최종 결과 리턴 (YYYY-MM-DD)
|
||||
return $date->format('Y-m-d');
|
||||
}
|
||||
//조정된 금액 설정
|
||||
final public function getCaculatedAmount(ServiceEntity $entity): int
|
||||
|
||||
72
app/Views/admin/payment/index.php
Normal file
72
app/Views/admin/payment/index.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?= $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?>
|
||||
<?= $this->section('content') ?>
|
||||
<?php if ($error = session('error')): echo $viewDatas['service']->getHelper()->alert($error) ?><?php endif ?>
|
||||
<div class="layout_top"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/top'); ?></div>
|
||||
<!-- Layout Middle Start -->
|
||||
<table class="layout_middle">
|
||||
<tr>
|
||||
<td class="layout_left">
|
||||
<!-- Layout Left Start -->
|
||||
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?>
|
||||
<!-- Layout Left End -->
|
||||
</td>
|
||||
<td class="layout_right">
|
||||
<!-- Layout Right Start -->
|
||||
<div class="layout_header"><?= $this->include("templates/{$viewDatas['layout']}/index_header"); ?></div>
|
||||
<div id="container" class="layout_content">
|
||||
<link href="/css/<?= $viewDatas['layout'] ?>/index.css" media="screen" rel="stylesheet" type="text/css" />
|
||||
<div class="index_body">
|
||||
<?= form_open(current_url(), ["method" => "get"]) ?>
|
||||
<nav class="index_top navbar navbar-expand-lg">
|
||||
<div class="container-fluid">
|
||||
<nav class="condition nav">
|
||||
조건:
|
||||
<?php foreach ($viewDatas['control']['actionFilters'] as $field): ?>
|
||||
<?= $viewDatas['service']->getHelper()->getListFilter($field, $viewDatas['control']['index_filters'][$field] ?? old($field), $viewDatas) ?>
|
||||
<?php endforeach ?>
|
||||
</nav>
|
||||
<?= $this->include("templates/{$viewDatas['layout']}/index_content_top"); ?>
|
||||
</div>
|
||||
</nav>
|
||||
<?= form_close() ?>
|
||||
<?= form_open(current_url(), ['id' => 'batchjob_form', 'method' => "post"]) ?>
|
||||
<table class="index_table data table table-bordered table-hover table-striped" data-rtc-resizable-table="reisze_table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="index_head_short_column">번호</th>
|
||||
<?php foreach ($viewDatas['control']['actionFields'] as $field): ?>
|
||||
<th data-rtc-resizable="<?= $field ?>"><?= $viewDatas['service']->getHelper()->getListLabel($field, lang("{$viewDatas['class_path']}.label.{$field}"), $viewDatas) ?></th>
|
||||
<?php endforeach ?>
|
||||
<th class="index_head_short_column">작업</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $cnt = 0 ?>
|
||||
<?php foreach ($viewDatas['entities'] as $entity): ?>
|
||||
<?php $viewDatas['entity'] = $entity; ?>
|
||||
<tr <?= $viewDatas['entity']->getStatus() === $viewDatas['entity']::DEFAULT_STATUS ? "" : 'class="table-danger"' ?>>
|
||||
<?php $num = $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt); ?>
|
||||
<td nowrap><?= $viewDatas['service']->getHelper()->getListButton('modify', $num, $viewDatas) ?></td>
|
||||
<?php foreach ($viewDatas['control']['actionFields'] as $field): ?>
|
||||
<td><?= $viewDatas['service']->getHelper()->getFieldView($field, $entity->$field, $viewDatas) ?></td>
|
||||
<?php endforeach ?>
|
||||
<td nowrap>
|
||||
<?= $viewDatas['service']->getHelper()->getListButton('view', '', $viewDatas) ?>
|
||||
<?= $viewDatas['service']->getHelper()->getListButton('delete', '', $viewDatas) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $cnt++ ?>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?= $this->include("templates/{$viewDatas['layout']}/index_content_bottom"); ?>
|
||||
<?= form_close() ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layout_footer"><?= $this->include("templates/{$viewDatas['layout']}/index_footer"); ?></div>
|
||||
<!-- Layout Right End -->
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- Layout Middle End -->
|
||||
<div class="layout_bottom"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?></div>
|
||||
<?= $this->endSection() ?>
|
||||
Loading…
Reference in New Issue
Block a user