| @@ -3,12 +3,17 @@ | |||||
| namespace App\Email\Members; | namespace App\Email\Members; | ||||
| use App\Kintone\Models\Parking; | use App\Kintone\Models\Parking; | ||||
| use App\Kintone\Models\PaymentPlan; | |||||
| use App\Kintone\Models\SeasonTicketContractEntry; | use App\Kintone\Models\SeasonTicketContractEntry; | ||||
| use App\Kintone\Models\SeasonTicketContractPlan; | use App\Kintone\Models\SeasonTicketContractPlan; | ||||
| class EntryApprove extends Members | class EntryApprove extends Members | ||||
| { | { | ||||
| private ?PaymentPlan $firstMonthPaymentPlan = null; | |||||
| private ?PaymentPlan $partitialPaymentPlan = null; | |||||
| private ?PaymentPlan $depositPaymentPlan = null; | |||||
| public function __construct( | public function __construct( | ||||
| private Parking $parking, | private Parking $parking, | ||||
| private SeasonTicketContractEntry $entry, | private SeasonTicketContractEntry $entry, | ||||
| @@ -28,6 +33,37 @@ class EntryApprove extends Members | |||||
| return "【利用確認事項】申込受付 月極定期駐車場ナビ"; | return "【利用確認事項】申込受付 月極定期駐車場ナビ"; | ||||
| } | } | ||||
| /** | |||||
| * 初月分の入金予定をセット | |||||
| * | |||||
| * @param PaymentPlan $plan | |||||
| * @return void | |||||
| */ | |||||
| public function setFirstMonthPaymentPlan(PaymentPlan $plan) | |||||
| { | |||||
| $this->firstMonthPaymentPlan = $plan; | |||||
| } | |||||
| /** | |||||
| * 日割り分の入金予定をセット | |||||
| * | |||||
| * @param PaymentPlan $plan | |||||
| * @return void | |||||
| */ | |||||
| public function setPartitialPaymentPlan(PaymentPlan $plan) | |||||
| { | |||||
| $this->partitialPaymentPlan = $plan; | |||||
| } | |||||
| /** | |||||
| * 保証金の入金予定をセット | |||||
| * | |||||
| * @param PaymentPlan $plan | |||||
| * @return void | |||||
| */ | |||||
| public function setDepositPaymentPlan(PaymentPlan $plan) | |||||
| { | |||||
| $this->depositPaymentPlan = $plan; | |||||
| } | |||||
| public function getMemberParams(): array | public function getMemberParams(): array | ||||
| { | { | ||||
| $entry = $this->entry; | $entry = $this->entry; | ||||
| @@ -43,12 +79,33 @@ class EntryApprove extends Members | |||||
| 'use_start_date' => $entry->useStartDate ? $entry->useStartDate->format('Y/m/d') : "-", | 'use_start_date' => $entry->useStartDate ? $entry->useStartDate->format('Y/m/d') : "-", | ||||
| 'payment_method' => $entry->paymentMethod ?? "-", | 'payment_method' => $entry->paymentMethod ?? "-", | ||||
| 'amount' => number_format($entry->amount ?? 0), | 'amount' => number_format($entry->amount ?? 0), | ||||
| 'payment_explain' => EntryMessageBuilder::getPaymentExplainStr($this->entry), | |||||
| 'payment_explain' => EntryMessageBuilder::getPaymentExplainStr( | |||||
| $this->firstMonthPaymentPlan, | |||||
| $this->partitialPaymentPlan, | |||||
| $this->depositPaymentPlan, | |||||
| ), | |||||
| 'tax_explain' => EntryMessageBuilder::getTaxExplain($this->plan), | 'tax_explain' => EntryMessageBuilder::getTaxExplain($this->plan), | ||||
| 'can_terminate_15' => in_array(Parking::ELEMENT_CAN_TERMINATE_DATE_15, $this->parking->canTerminateDate), | 'can_terminate_15' => in_array(Parking::ELEMENT_CAN_TERMINATE_DATE_15, $this->parking->canTerminateDate), | ||||
| 'can_terminate_end_of_month' => in_array(Parking::ELEMENT_CAN_TERMINATE_DATE_END_OF_MONTH, $this->parking->canTerminateDate), | 'can_terminate_end_of_month' => in_array(Parking::ELEMENT_CAN_TERMINATE_DATE_END_OF_MONTH, $this->parking->canTerminateDate), | ||||
| 'deposit_explain' => EntryMessageBuilder::getDepositExplain($this->plan), | |||||
| 'total_payment_amount' => number_format(($entry->firstAmount ?? 0) + ($this->plan->totalDeposit ?? 0)), | |||||
| 'deposit_explain' => EntryMessageBuilder::getDepositExplain( | |||||
| $this->depositPaymentPlan | |||||
| ), | |||||
| 'total_payment_amount' => number_format($this->totalPaymentAmount()), | |||||
| ]; | ]; | ||||
| } | } | ||||
| private function totalPaymentAmount() | |||||
| { | |||||
| $total = 0; | |||||
| if ($this->firstMonthPaymentPlan) { | |||||
| $total += $this->firstMonthPaymentPlan->paymentPlanAmount; | |||||
| } | |||||
| if ($this->partitialPaymentPlan) { | |||||
| $total += $this->partitialPaymentPlan->paymentPlanAmount; | |||||
| } | |||||
| if ($this->depositPaymentPlan) { | |||||
| $total += $this->depositPaymentPlan->paymentPlanAmount; | |||||
| } | |||||
| return $total; | |||||
| } | |||||
| } | } | ||||
| @@ -2,42 +2,38 @@ | |||||
| namespace App\Email\Members; | namespace App\Email\Members; | ||||
| use App\Kintone\Models\PaymentPlan; | |||||
| use App\Kintone\Models\SeasonTicketContractEntry; | use App\Kintone\Models\SeasonTicketContractEntry; | ||||
| use App\Kintone\Models\SeasonTicketContractPlan; | use App\Kintone\Models\SeasonTicketContractPlan; | ||||
| abstract class EntryMessageBuilder | abstract class EntryMessageBuilder | ||||
| { | { | ||||
| public static function getPaymentExplainStr(SeasonTicketContractEntry $entry): string | |||||
| public static function getPaymentExplainStr(PaymentPlan $firstMonth, ?PaymentPlan $partitial, ?PaymentPlan $deposit): string | |||||
| { | { | ||||
| if (!$entry->paymentLimitDate) { | |||||
| return ""; | |||||
| } | |||||
| if (!$entry->firstAmount) { | |||||
| return ""; | |||||
| } | |||||
| $hiwariStr = !!$entry->hiwariAmount ? sprintf( | |||||
| $hiwariStr = !!$partitial ? sprintf( | |||||
| "%d月分日割分%s円と", | "%d月分日割分%s円と", | ||||
| $entry->hiwariMonth, | |||||
| number_format($entry->hiwariAmount) | |||||
| $partitial->targetMonth, | |||||
| number_format($partitial->paymentPlanAmount) | |||||
| ) : ""; | ) : ""; | ||||
| $totalAmount = $firstMonth->paymentPlanAmount; | |||||
| if ($partitial) { | |||||
| $totalAmount += $partitial->paymentPlanAmount; | |||||
| } | |||||
| return sprintf( | return sprintf( | ||||
| "※料金は利用日までの前払いのため、%s%d月分%s円 (合計%s円)を%sまでにお振込下さい。(手数料は振込者負担でお願い致します。)", | "※料金は利用日までの前払いのため、%s%d月分%s円 (合計%s円)を%sまでにお振込下さい。(手数料は振込者負担でお願い致します。)", | ||||
| $hiwariStr, | $hiwariStr, | ||||
| $entry->targetMonth, | |||||
| number_format($entry->targetAmount), | |||||
| number_format($entry->firstAmount), | |||||
| $entry->paymentLimitDate->format("Y年m月d日") | |||||
| $firstMonth->targetMonth, | |||||
| number_format($firstMonth->paymentPlanAmount), | |||||
| number_format($totalAmount), | |||||
| $firstMonth->paymentPlanDate->format("Y年m月d日") | |||||
| ); | ); | ||||
| } | } | ||||
| public static function getTaxExplain(SeasonTicketContractPlan $plan): string | public static function getTaxExplain(SeasonTicketContractPlan $plan): string | ||||
| { | { | ||||
| // if (!$plan->taxRate || !$plan->taxAmount) { | |||||
| // return ""; | |||||
| // } | |||||
| return sprintf( | return sprintf( | ||||
| "(消費税等含む,適用税率%d%% 消費税額 %s円)", | "(消費税等含む,適用税率%d%% 消費税額 %s円)", | ||||
| $plan->taxRate ?? 0, | $plan->taxRate ?? 0, | ||||
| @@ -45,23 +41,20 @@ abstract class EntryMessageBuilder | |||||
| ); | ); | ||||
| } | } | ||||
| public static function getDepositExplain(SeasonTicketContractPlan $plan): string | |||||
| public static function getDepositExplain(?PaymentPlan $deposit): string | |||||
| { | { | ||||
| if (!$deposit) return ""; | |||||
| $lines = collect(); | $lines = collect(); | ||||
| if ($plan->deposit) { | |||||
| $lines->push(sprintf("保証金:%s円", number_format($plan->deposit))); | |||||
| } | |||||
| if ($plan->chainGateDeposit) { | |||||
| $lines->push(sprintf("チェーンゲート保証金:%s円", number_format($plan->chainGateDeposit))); | |||||
| } | |||||
| if ($plan->cardDeposit) { | |||||
| $lines->push(sprintf("パスカード保証金:%s円", number_format($plan->cardDeposit))); | |||||
| foreach ($deposit->depositList as $row) { | |||||
| $lines->push(sprintf("%s:%s円", $row->name, number_format($row->amount))); | |||||
| } | } | ||||
| if ($lines->isNotEmpty()) { | if ($lines->isNotEmpty()) { | ||||
| $lines->prepend("---保証金------"); | $lines->prepend("---保証金------"); | ||||
| $lines->push(sprintf("保証金合計:%s円", number_format($plan->totalDeposit))); | |||||
| $lines->push(sprintf("保証金合計:%s円", number_format($deposit->paymentPlanAmount))); | |||||
| $lines->push("---------------"); | $lines->push("---------------"); | ||||
| } | } | ||||
| @@ -97,7 +97,15 @@ class EmailSendController extends FromKintoneController | |||||
| $entry = SeasonTicketContractEntry::find($this->param->seasonTicketContractEntryRecordNo); | $entry = SeasonTicketContractEntry::find($this->param->seasonTicketContractEntryRecordNo); | ||||
| $parking = $entry->getParking(); | $parking = $entry->getParking(); | ||||
| $plan = $entry->getPlan(); | $plan = $entry->getPlan(); | ||||
| $this->setEmail(new EntryApprove($parking, $entry, $plan)); | |||||
| $email = new EntryApprove($parking, $entry, $plan); | |||||
| $email->setFirstMonthPaymentPlan(PaymentPlan::find($entry->firstMonthPaymentPlanRecordNo)); | |||||
| if ($entry->partitialPaymentPlanRecordNo) { | |||||
| $email->setPartitialPaymentPlan(PaymentPlan::find($entry->partitialPaymentPlanRecordNo)); | |||||
| } | |||||
| if ($entry->depositPaymentPlanRecordNo) { | |||||
| $email->setDepositPaymentPlan(PaymentPlan::find($entry->depositPaymentPlanRecordNo)); | |||||
| } | |||||
| $this->setEmail($email); | |||||
| return; | return; | ||||
| } | } | ||||
| if ($emailId === Email::ENTRY_PAYMENT_COMPLETE) { | if ($emailId === Email::ENTRY_PAYMENT_COMPLETE) { | ||||
| @@ -3,7 +3,9 @@ | |||||
| namespace App\Kintone\Models; | namespace App\Kintone\Models; | ||||
| use App\Kintone\Models\DropDown\PaymentPlan\PaymentType; | use App\Kintone\Models\DropDown\PaymentPlan\PaymentType; | ||||
| use App\Kintone\Models\SubTable\PaymentPlan\Deposit; | |||||
| use Illuminate\Support\Carbon; | use Illuminate\Support\Carbon; | ||||
| use Illuminate\Support\Collection; | |||||
| /** | /** | ||||
| * アプリ名 入金予定・結果 | * アプリ名 入金予定・結果 | ||||
| @@ -21,6 +23,7 @@ use Illuminate\Support\Carbon; | |||||
| * @property Carbon appropriationDate | * @property Carbon appropriationDate | ||||
| * @property int appropriationAmount | * @property int appropriationAmount | ||||
| * @property int remainingAmount | * @property int remainingAmount | ||||
| * @property Collection<int ,Deposit> depositList | |||||
| */ | */ | ||||
| class PaymentPlan extends KintoneModel | class PaymentPlan extends KintoneModel | ||||
| { | { | ||||
| @@ -39,6 +42,9 @@ class PaymentPlan extends KintoneModel | |||||
| const FIELD_APPROPRIATION_DATE = "appropriation_date"; | const FIELD_APPROPRIATION_DATE = "appropriation_date"; | ||||
| const FIELD_APPROPRIATION_AMOUNT = "appropriation_amount"; | const FIELD_APPROPRIATION_AMOUNT = "appropriation_amount"; | ||||
| const FIELD_REMAINING_AMOUNT = "remaining_amount"; | const FIELD_REMAINING_AMOUNT = "remaining_amount"; | ||||
| const FIELD_DEPOSIT_LIST = "保証金明細"; | |||||
| const FIELD_DEPOSIT_LIST_NAME = "保証金明細_名称"; | |||||
| const FIELD_DEPOSIT_LIST_AMOUNT = "保証金明細_金額"; | |||||
| protected const FIELDS = [ | protected const FIELDS = [ | ||||
| ...parent::FIELDS, | ...parent::FIELDS, | ||||
| @@ -55,6 +61,11 @@ class PaymentPlan extends KintoneModel | |||||
| self::FIELD_APPROPRIATION_DATE => FieldType::DATE, | self::FIELD_APPROPRIATION_DATE => FieldType::DATE, | ||||
| self::FIELD_APPROPRIATION_AMOUNT => FieldType::NUMBER, | self::FIELD_APPROPRIATION_AMOUNT => FieldType::NUMBER, | ||||
| self::FIELD_REMAINING_AMOUNT => FieldType::NUMBER, | self::FIELD_REMAINING_AMOUNT => FieldType::NUMBER, | ||||
| self::FIELD_DEPOSIT_LIST => FieldType::SUBTABLE, | |||||
| ]; | |||||
| protected const SUB_TABLES = [ | |||||
| self::FIELD_DEPOSIT_LIST => Deposit::class, | |||||
| ]; | ]; | ||||
| protected const FIELD_NAMES = [ | protected const FIELD_NAMES = [ | ||||
| @@ -27,6 +27,9 @@ use Illuminate\Support\Carbon; | |||||
| * @property ?int targetMonth | * @property ?int targetMonth | ||||
| * @property ?int targetAmount | * @property ?int targetAmount | ||||
| * @property ?Carbon paymentLimitDate | * @property ?Carbon paymentLimitDate | ||||
| * @property ?int firstMonthPaymentPlanRecordNo | |||||
| * @property ?int partitialPaymentPlanRecordNo | |||||
| * @property ?int depositPaymentPlanRecordNo | |||||
| */ | */ | ||||
| class SeasonTicketContractEntry extends KintoneModel | class SeasonTicketContractEntry extends KintoneModel | ||||
| { | { | ||||
| @@ -53,6 +56,9 @@ class SeasonTicketContractEntry extends KintoneModel | |||||
| const FIELD_TARGET_AMOUNT = "請求対象分_金額"; | const FIELD_TARGET_AMOUNT = "請求対象分_金額"; | ||||
| const FIELD_FIRST_AMOUNT = "初回振り込み合計額"; | const FIELD_FIRST_AMOUNT = "初回振り込み合計額"; | ||||
| const FIELD_PAYMENT_LIMIT_DATE = "振込期日"; | const FIELD_PAYMENT_LIMIT_DATE = "振込期日"; | ||||
| const FIELD_FIRST_MONTH_PAYMENT_PLAN_RECORD_NO = "初回入金予定_初月分入金予定"; | |||||
| const FIELD_PARTITIAL_PAYMENT_PLAN_RECORD_NO = "初回入金予定_日割り分入金予定"; | |||||
| const FIELD_DEPOSIT_PAYMENT_PLAN_RECORD_NO = "初回入金予定_保証金入金予定"; | |||||
| protected const FIELDS = [ | protected const FIELDS = [ | ||||
| ...parent::FIELDS, | ...parent::FIELDS, | ||||
| @@ -76,6 +82,9 @@ class SeasonTicketContractEntry extends KintoneModel | |||||
| self::FIELD_TARGET_AMOUNT => FieldType::NUMBER, | self::FIELD_TARGET_AMOUNT => FieldType::NUMBER, | ||||
| self::FIELD_FIRST_AMOUNT => FieldType::NUMBER, | self::FIELD_FIRST_AMOUNT => FieldType::NUMBER, | ||||
| self::FIELD_PAYMENT_LIMIT_DATE => FieldType::DATE, | self::FIELD_PAYMENT_LIMIT_DATE => FieldType::DATE, | ||||
| self::FIELD_FIRST_MONTH_PAYMENT_PLAN_RECORD_NO => FieldType::NUMBER, | |||||
| self::FIELD_PARTITIAL_PAYMENT_PLAN_RECORD_NO => FieldType::NUMBER, | |||||
| self::FIELD_DEPOSIT_PAYMENT_PLAN_RECORD_NO => FieldType::NUMBER, | |||||
| ]; | ]; | ||||
| protected const FIELD_NAMES = [ | protected const FIELD_NAMES = [ | ||||
| @@ -0,0 +1,30 @@ | |||||
| <?php | |||||
| namespace App\Kintone\Models\SubTable\PaymentPlan; | |||||
| use App\Kintone\Models\PaymentPlan; | |||||
| use App\Kintone\Models\SubTable\SubTableData; | |||||
| class Deposit extends SubTableData | |||||
| { | |||||
| public string $name; | |||||
| public int $amount; | |||||
| public function __construct(array $data = []) | |||||
| { | |||||
| $this->name = data_get($data, PaymentPlan::FIELD_DEPOSIT_LIST_NAME, ""); | |||||
| $this->amount = data_get($data, PaymentPlan::FIELD_DEPOSIT_LIST_AMOUNT, 0); | |||||
| parent::__construct($data); | |||||
| } | |||||
| public function toArray(): array | |||||
| { | |||||
| return [ | |||||
| PaymentPlan::FIELD_DEPOSIT_LIST_NAME => $this->name, | |||||
| PaymentPlan::FIELD_DEPOSIT_LIST_AMOUNT => $this->amount, | |||||
| ]; | |||||
| } | |||||
| } | |||||
| @@ -39,7 +39,10 @@ | |||||
| @if($payment_explain) | @if($payment_explain) | ||||
| {{ $payment_explain }} | {{ $payment_explain }} | ||||
| @endif | @endif | ||||
| @if($deposit_explain) | |||||
| {{ $deposit_explain }} | {{ $deposit_explain }} | ||||
| @endif | |||||
| お支払い合計金額 {{ $total_payment_amount }}円 | お支払い合計金額 {{ $total_payment_amount }}円 | ||||
| 銀行:ゆうちょ銀行 | 銀行:ゆうちょ銀行 | ||||