|
- <?php
-
- namespace App\Console\Commands\DataPatch;
-
- use App\Console\Commands\BaseCommand;
- use App\Http\API\SMBC\Payment\PollResultRecord;
- use App\Http\API\SMBC\Payment\SMBC;
- use App\Http\API\SMBC\Payment\PaymentStatus;
- use App\Kintone\KintoneRecordQueryOperator;
- use App\Kintone\Models\DropDown\SmbcPayment\SmbcPaymentStatus;
- use App\Kintone\Models\PaymentPlan;
- use App\Kintone\Models\SeasonTicketContract;
- use App\Kintone\Models\SeasonTicketContractPlan;
- use App\Kintone\Models\SmbcPayment;
- use App\Models\SmbcPollStatus;
- use App\Util\DateUtil;
- use App\Util\DBUtil;
- use Exception;
- use Illuminate\Database\Eloquent\ModelNotFoundException;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Collection;
-
- class FillPaymentPlan extends BaseCommand
- {
-
- const COMMAND = "data-patch:fill-payment-plan {parkingName}";
-
-
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = self::COMMAND;
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '支払予定を完了へデータパッチする';
-
- static public function getCommand()
- {
- return self::COMMAND;
- }
-
-
- /**
- * @var Collection<int, SmbcPayment>
- */
- 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;
- }
- }
|