From 20dcab5aa7efb1ab84ec2f9cbbe5dd3e2251e376 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Thu, 25 Jan 2024 13:47:09 +0900 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=89=95=E4=BA=88=E5=AE=9A=E3=82=92?= =?UTF-8?q?=E6=94=AF=E6=89=95=E6=B8=88=E3=81=BF=E3=81=AB=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E3=83=91=E3=83=83=E3=83=81=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/DataPatch/FillPaymentPlan.php | 137 ++++++++++++++++++ app/Kintone/Models/PaymentPlan.php | 2 + 2 files changed, 139 insertions(+) create mode 100644 app/Console/Commands/DataPatch/FillPaymentPlan.php diff --git a/app/Console/Commands/DataPatch/FillPaymentPlan.php b/app/Console/Commands/DataPatch/FillPaymentPlan.php new file mode 100644 index 0000000..379d666 --- /dev/null +++ b/app/Console/Commands/DataPatch/FillPaymentPlan.php @@ -0,0 +1,137 @@ + + */ + private Collection $results; + + + /** + * Create a new command instance. + * + * @return void + */ + public function __construct() + { + parent::__construct(); + $this->applications = collect(); + $this->results = collect(); + } + + /** + * Execute the console command. + * + * @return int + */ + public function service(): int + { + // プランの取得 + $plans = $this->getPlans(); + + foreach ($plans as $plan) { + + // 契約の取得 + $contracts = $this->getContracts($plan); + + $confirmMessage = sprintf("支払済みにしますか?[%s][%d件]", $plan->planName, $contracts->count()); + + if (!$this->confirm($confirmMessage)) { + continue; + } + + // 支払予定の取得 + foreach ($contracts as $contract) { + $payments = $this->getPaymentPlans($contract); + + // 支払済みへ変更 + foreach ($payments as $payment) { + $payment->remainingAmount = 0; + $payment->appropriationAmount = $payment->paymentPlanAmount; + $payment->paymentPlanDate = DateUtil::now(); + $payment->save(); + } + } + } + + + return self::RESULTCODE_SUCCESS; + } + + private function getPlans() + { + $access = SeasonTicketContractPlan::getAccess(); + $query = SeasonTicketContractPlan::getQuery()->where(SeasonTicketContractPlan::FIELD_PARKING_NAME, $this->argument("parkingName")); + + $plans = $access->all($query); + + return $plans; + } + + private function getContracts(SeasonTicketContractPlan $plan) + { + $access = SeasonTicketContract::getAccess(); + $query = SeasonTicketContract::getQuery()->where(SeasonTicketContract::FIELD_PLAN_NAME, $plan->planName); + + $contracts = $access->all($query); + + return $contracts; + } + + private function getPaymentPlans(SeasonTicketContract $contract) + { + $access = PaymentPlan::getAccess(); + $query = PaymentPlan::getQuery() + ->where(PaymentPlan::FIELD_SEASON_TICKET_CONTRACT_RECORD_NO, $contract->getRecordId()) + ->where(PaymentPlan::FIELD_REMAINING_AMOUNT, 0, KintoneRecordQueryOperator::NEQ); + + $contracts = $access->all($query); + + return $contracts; + } +} diff --git a/app/Kintone/Models/PaymentPlan.php b/app/Kintone/Models/PaymentPlan.php index 079f8fe..53f7561 100644 --- a/app/Kintone/Models/PaymentPlan.php +++ b/app/Kintone/Models/PaymentPlan.php @@ -16,6 +16,8 @@ use Illuminate\Support\Carbon; * @property int targetYear * @property int targetMonth * @property int targetTermMonth + * @property Carbon paymentPlanDate + * @property int paymentPlanAmount * @property Carbon appropriationDate * @property int appropriationAmount * @property int remainingAmount