Files
star-erp/app/Modules/Inventory/Notifications/StoreRequisitionNotification.php

55 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Modules\Inventory\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use App\Modules\Inventory\Models\StoreRequisition;
class StoreRequisitionNotification extends Notification
{
use Queueable;
protected StoreRequisition $requisition;
protected string $action;
protected string $actorName;
/**
* 建立通知實例
*
* @param StoreRequisition $requisition 叫貨單
* @param string $action 操作類型submitted / approved / rejected
* @param string $actorName 操作者名稱
*/
public function __construct(StoreRequisition $requisition, string $action, string $actorName)
{
$this->requisition = $requisition;
$this->action = $action;
$this->actorName = $actorName;
}
public function via(object $notifiable): array
{
return ['database'];
}
public function toArray(object $notifiable): array
{
$messages = [
'submitted' => "{$this->actorName} 提交了叫貨申請:{$this->requisition->doc_no}",
'approved' => "{$this->actorName} 核准了叫貨申請:{$this->requisition->doc_no}",
'rejected' => "{$this->actorName} 駁回了叫貨申請:{$this->requisition->doc_no}",
];
return [
'type' => 'store_requisition',
'action' => $this->action,
'store_requisition_id' => $this->requisition->id,
'doc_no' => $this->requisition->doc_no,
'actor_name' => $this->actorName,
'message' => $messages[$this->action] ?? "{$this->actorName} 操作了叫貨申請:{$this->requisition->doc_no}",
'link' => route('store-requisitions.show', $this->requisition->id),
];
}
}