Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

82 rindas
2.5KB

  1. <?php
  2. namespace App\Logic;
  3. use App\Features\InstanceAble;
  4. use App\Kintone\Models\Customer;
  5. use App\Kintone\Models\GeneralApplication;
  6. use App\Util\DateUtil;
  7. use Illuminate\Support\Carbon;
  8. use LogicException;
  9. class GeneralApplicationManager
  10. {
  11. use InstanceAble;
  12. private Customer|null $customer = null;
  13. public function __construct(private GeneralApplication $model)
  14. {
  15. }
  16. public function setCustomer(Customer $customer): static
  17. {
  18. $this->customer = $customer;
  19. return $this;
  20. }
  21. public function forTerminate(array $attr): static
  22. {
  23. $terminateDate = data_get($attr, GeneralApplication::FIELD_TERMINATE_DATE);
  24. if (!($terminateDate instanceof Carbon)) throw new LogicException("解約予定日不正");
  25. $this->model->set(GeneralApplication::FIELD_TERMINATE_DATE, $terminateDate);
  26. return $this->setType("解約申請")
  27. ->setMemo($attr);
  28. }
  29. public function forParkingCertificate(array $attr = []): static
  30. {
  31. return $this->setType("車庫証明発行申請")
  32. ->setMemo($attr);
  33. }
  34. public function register()
  35. {
  36. if ($this->customer === null) {
  37. throw new LogicException("顧客NULL");
  38. }
  39. if (!$this->model->getStr(GeneralApplication::FIELD_APPLICATION_TYPE)) {
  40. throw new LogicException("申請タイプ未設定");
  41. }
  42. $this->model->set(GeneralApplication::FIELD_APPLICATION_DATETIME, DateUtil::now());
  43. $this->model->set(GeneralApplication::FIELD_APPLICATIONJ_STATUS, "申込");
  44. $this->model->set(GeneralApplication::FIELD_CUSTOMER_EMAIL, $this->customer->get(Customer::FIELD_EMAIL));
  45. $this->model->set(GeneralApplication::FIELD_CUSTOMER_NAME, $this->customer->get(Customer::FIELD_CUSTOMER_NAME));
  46. $this->model->set(GeneralApplication::FIELD_CUSTOMER_NAME_KANA, $this->customer->get(Customer::FIELD_CUSTOMER_NAME_KANA));
  47. $this->model->set(GeneralApplication::FIELD_CUSTOMER_PHONE_NUMBER, $this->customer->get(Customer::FIELD_PHONE_NUMBER));
  48. $access = $this->model->getAccess();
  49. $access->create($this->model);
  50. }
  51. private function setType(string $type): static
  52. {
  53. $this->model->set(GeneralApplication::FIELD_APPLICATION_TYPE, $type);
  54. return $this;
  55. }
  56. private function setMemo(array $attr): static
  57. {
  58. $memo = data_get($attr, GeneralApplication::FIELD_MEMO);
  59. if ($memo) {
  60. $this->model->set(GeneralApplication::FIELD_MEMO, $memo);
  61. }
  62. return $this;
  63. }
  64. }