You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.3KB

  1. <?php
  2. namespace App\Kintone\Models;
  3. use App\Kintone\Models\DropDown\PaymentPlan\PaymentType;
  4. use Illuminate\Support\Carbon;
  5. /**
  6. * アプリ名 入金予定・結果
  7. * @property int SEASON_TICKET_CONTRACT_RECORD_NO
  8. * @property string parkingName
  9. * @property int parkingName
  10. * @property int customerCode
  11. * @property string paymentType
  12. * @property string paymentMethod
  13. * @property int targetYear
  14. * @property int targetMonth
  15. * @property int targetTermMonth
  16. * @property Carbon appropriationDate
  17. * @property int appropriationAmount
  18. * @property int remainingAmount
  19. */
  20. class PaymentPlan extends KintoneModel
  21. {
  22. const CONFIG_KEY = "KINTONE_APP_PAYMENT_PLAN";
  23. const FIELD_SEASON_TICKET_CONTRACT_RECORD_NO = "contract_record_number";
  24. const FIELD_PARKING_NAME = "parking_name";
  25. const FIELD_CUSTOMER_CODE = "customer_code";
  26. const FIELD_PAYMENT_TYPE = "payment_type";
  27. const FIELD_PAYMENT_METHOD = "payment_method";
  28. const FIELD_TARGET_YEAR = "target_year";
  29. const FIELD_TARGET_MONTH = "target_month";
  30. const FIELD_TARGET_TERM_MONTH = "target_term_month";
  31. const FIELD_PAYMENT_PLAN_DATE = "payment_plan_date";
  32. const FIELD_PAYMENT_PLAN_AMOUNT = "payment_plan_amount";
  33. const FIELD_APPROPRIATION_DATE = "appropriation_date";
  34. const FIELD_APPROPRIATION_AMOUNT = "appropriation_amount";
  35. const FIELD_REMAINING_AMOUNT = "remaining_amount";
  36. protected const FIELDS = [
  37. ...parent::FIELDS,
  38. self::FIELD_SEASON_TICKET_CONTRACT_RECORD_NO => FieldType::NUMBER,
  39. self::FIELD_PARKING_NAME => FieldType::SINGLE_LINE_TEXT,
  40. self::FIELD_CUSTOMER_CODE => FieldType::NUMBER,
  41. self::FIELD_PAYMENT_TYPE => FieldType::DROP_DOWN,
  42. self::FIELD_PAYMENT_METHOD => FieldType::DROP_DOWN,
  43. self::FIELD_TARGET_YEAR => FieldType::NUMBER,
  44. self::FIELD_TARGET_MONTH => FieldType::NUMBER,
  45. self::FIELD_TARGET_TERM_MONTH => FieldType::NUMBER,
  46. self::FIELD_PAYMENT_PLAN_DATE => FieldType::DATE,
  47. self::FIELD_PAYMENT_PLAN_AMOUNT => FieldType::NUMBER,
  48. self::FIELD_APPROPRIATION_DATE => FieldType::DATE,
  49. self::FIELD_APPROPRIATION_AMOUNT => FieldType::NUMBER,
  50. self::FIELD_REMAINING_AMOUNT => FieldType::NUMBER,
  51. ];
  52. protected const FIELD_NAMES = [
  53. ...parent::FIELD_NAMES,
  54. self::FIELD_SEASON_TICKET_CONTRACT_RECORD_NO => 'season_ticekt_contract_record_no',
  55. self::FIELD_PAYMENT_TYPE => 'payment_type',
  56. self::FIELD_PAYMENT_METHOD => 'payment_method',
  57. self::FIELD_PAYMENT_PLAN_DATE => 'payment_plan_date',
  58. self::FIELD_TARGET_YEAR => 'target_year',
  59. self::FIELD_TARGET_MONTH => 'target_month',
  60. ];
  61. protected function toArrayCustom(): array
  62. {
  63. return [
  64. 'payment_status' => $this->donePayment() ? "支払済み" : "未払い",
  65. 'payment_name' => $this->getViewName(),
  66. ];
  67. }
  68. public function donePayment(): bool
  69. {
  70. $paymentDate = $this->getDate(self::FIELD_APPROPRIATION_DATE);
  71. $remainingAmount = $this->getNumber(self::FIELD_REMAINING_AMOUNT);
  72. return !!$paymentDate && $remainingAmount === 0;
  73. }
  74. private function getViewName(): string
  75. {
  76. if ($this->paymentType === PaymentType::SEASON_TICKET) {
  77. return sprintf("%d年%d月分 定期料金", $this->targetYear, $this->targetMonth);
  78. }
  79. return $this->paymentType;
  80. }
  81. }