|
- <?php
-
- namespace App\Logic;
-
- use App\Kintone\Models\Customer;
- use App\Kintone\Models\GeneralApplication;
- use App\Kintone\Models\Parking;
- use App\Kintone\Models\ParkingCertificateApplication;
- use App\Kintone\Models\SeasonTicketContract;
- use App\Kintone\Models\SeasonTicketReOrderApplication;
- use App\Kintone\Models\StickerReOrderApplication;
- use App\Kintone\Models\TerminateApplication;
- use App\Kintone\Models\UserInfoUpdateApplication;
- use App\Kintone\Models\VehicleInfoUpdateApplication;
- use App\Util\DateUtil;
- use LogicException;
-
- /**
- * @template T of GeneralApplication
- */
- class GeneralApplicationManager
- {
- private ?Customer $customer = null;
-
- private ?SeasonTicketContract $seasonTicketContract = null;
-
- private ?Parking $parking = null;
-
-
- /**
- * @param T $model
- */
- public function __construct(private GeneralApplication $model)
- {
- if ($model instanceof TerminateApplication) {
- $this->setType("解約申請");
- return;
- }
- if ($model instanceof ParkingCertificateApplication) {
- $this->setType("車庫証明発行申請");
- return;
- }
- if ($model instanceof StickerReOrderApplication) {
- $this->setType("シール再発行申請");
- return;
- }
- if ($model instanceof SeasonTicketReOrderApplication) {
- $this->setType("定期券再発行申請");
- return;
- }
- if ($model instanceof VehicleInfoUpdateApplication) {
- $this->setType("車両番号・防犯登録番号変更");
- return;
- }
- if ($model instanceof UserInfoUpdateApplication) {
- $this->setType("利用者情報変更");
- return;
- }
- if ($model instanceof UserInfoUpdateApplication) {
- $this->setType("振替頻度変更");
- return;
- }
- }
-
- public function setCustomer(Customer $customer): static
- {
- $this->customer = $customer;
- return $this;
- }
- public function setSeasonTicketContract(SeasonTicketContract $seasonTicketContract): static
- {
- $this->seasonTicketContract = $seasonTicketContract;
- return $this;
- }
- public function setParking(Parking $parking): static
- {
- $this->parking = $parking;
- return $this;
- }
-
- /**
- * @return T
- */
- public function makeApplication()
- {
- $this->model->applicationDatetime = DateUtil::now();
- $this->model->status = "新規登録";
- $this->model->applicationNo = $this->getApplicationNo();
-
- if ($this->customer === null) {
- throw new LogicException("顧客未設定のため失敗");
- }
-
- $this->model->customerCode = $this->customer->customerCode;
-
- if ($this->seasonTicketContract !== null) {
- $this->model->seasonTicketContractRecordNo = $this->seasonTicketContract->seasonTicketSeqNo;
- }
-
- if ($this->parking !== null) {
- $this->model->parkingName = $this->parking->parkingName;
- }
-
- return $this->model;
- }
-
- private function setType(string $type): static
- {
- $this->model->applicationType = $type;
- return $this;
- }
-
- private function getApplicationNo(): string
- {
- return sprintf("%s-%06d", DateUtil::now()->format('Ymd'), rand(1, 999999));
- }
- }
|