|
- <?php
-
- namespace App\Logic;
-
- use App\Features\InstanceAble;
- use App\Kintone\Models\Customer;
- use App\Kintone\Models\GeneralApplication;
- use App\Util\DateUtil;
- use Illuminate\Support\Carbon;
- use LogicException;
-
- class GeneralApplicationManager
- {
-
- use InstanceAble;
-
- private Customer|null $customer = null;
-
- public function __construct(private GeneralApplication $model)
- {
- }
-
- public function setCustomer(Customer $customer): static
- {
-
- $this->customer = $customer;
- return $this;
- }
-
- public function forTerminate(array $attr): static
- {
- $terminateDate = data_get($attr, GeneralApplication::FIELD_TERMINATE_DATE);
- if (!($terminateDate instanceof Carbon)) throw new LogicException("解約予定日不正");
- $this->model->set(GeneralApplication::FIELD_TERMINATE_DATE, $terminateDate);
-
- return $this->setType("解約申請")
- ->setMemo($attr);
- }
-
- public function forParkingCertificate(array $attr = []): static
- {
- return $this->setType("車庫証明発行申請")
- ->setMemo($attr);
- }
-
- public function register()
- {
- if ($this->customer === null) {
- throw new LogicException("顧客NULL");
- }
-
- if (!$this->model->getStr(GeneralApplication::FIELD_APPLICATION_TYPE)) {
- throw new LogicException("申請タイプ未設定");
- }
-
- $this->model->set(GeneralApplication::FIELD_APPLICATION_DATETIME, DateUtil::now());
- $this->model->set(GeneralApplication::FIELD_APPLICATIONJ_STATUS, "申込");
- $this->model->set(GeneralApplication::FIELD_CUSTOMER_EMAIL, $this->customer->get(Customer::FIELD_EMAIL));
- $this->model->set(GeneralApplication::FIELD_CUSTOMER_NAME, $this->customer->get(Customer::FIELD_CUSTOMER_NAME));
- $this->model->set(GeneralApplication::FIELD_CUSTOMER_NAME_KANA, $this->customer->get(Customer::FIELD_CUSTOMER_NAME_KANA));
- $this->model->set(GeneralApplication::FIELD_CUSTOMER_PHONE_NUMBER, $this->customer->get(Customer::FIELD_PHONE_NUMBER));
-
- $access = $this->model->getAccess();
- $access->create($this->model);
- }
-
- private function setType(string $type): static
- {
- $this->model->set(GeneralApplication::FIELD_APPLICATION_TYPE, $type);
- return $this;
- }
-
- private function setMemo(array $attr): static
- {
- $memo = data_get($attr, GeneralApplication::FIELD_MEMO);
- if ($memo) {
- $this->model->set(GeneralApplication::FIELD_MEMO, $memo);
- }
- return $this;
- }
- }
|