- Menambahkan Command `SendStatementEmailCommand` untuk mengirim email statement PDF: - Mendukung parameter input seperti periode laporan (`YYYY-MM`), nomor rekening, ID batch, queue, dan delay waktu. - Menjalankan validasi parameter input, mencatat log eksekusi, dan mendispatch job pengiriman email. - Menyediakan feedback status eksekusi serta informasi job kepada user. - Menambahkan Job `SendStatementEmailJob` untuk pengiriman statement dalam latar belakang: - Memfilter account yang memiliki email terkait, baik dari `stmt_email` atau email dari data customer. - Melakukan pengiriman email dengan attachment file PDF statement. - Mencatat log sukses atau kegagalan pengiriman untuk setiap account. - Memperbarui Model dan Template Email: - Mengubah template email untuk mendukung pengisian nama rekening secara dinamis berdasarkan customer account. - Menambahkan pengisian dinamis untuk tahun copyright di footer. - Memperbarui Provider `WebstatementServiceProvider`: - Mendaftarkan Command baru `SendStatementEmailCommand` ke dalam aplikasi. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
76 lines
2.7 KiB
PHP
76 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\Webstatement\Mail;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Modules\Webstatement\Models\Account;
|
|
use Modules\Webstatement\Models\PrintStatementLog;
|
|
|
|
class StatementEmail extends Mailable
|
|
{
|
|
use Queueable, SerializesModels;
|
|
|
|
protected $statement;
|
|
protected $filePath;
|
|
protected $isZip;
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*
|
|
* @param PrintStatementLog $statement
|
|
* @param string $filePath
|
|
* @param bool $isZip
|
|
*/
|
|
public function __construct(PrintStatementLog $statement, $filePath, $isZip = false)
|
|
{
|
|
$this->statement = $statement;
|
|
$this->filePath = $filePath;
|
|
$this->isZip = $isZip;
|
|
}
|
|
|
|
/**
|
|
* Build the message.
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function build()
|
|
{
|
|
$subject = 'Statement Rekening Bank Artha Graha Internasional';
|
|
|
|
if ($this->statement->is_period_range) {
|
|
$subject .= " - {$this->statement->period_from} to {$this->statement->period_to}";
|
|
} else {
|
|
$subject .= " - " . \Carbon\Carbon::createFromFormat('Ym', $this->statement->period_from)->locale('id')->isoFormat('MMMM Y');
|
|
}
|
|
|
|
$email = $this->subject($subject)
|
|
->view('webstatement::statements.email')
|
|
->with([
|
|
'statement' => $this->statement,
|
|
'accountNumber' => $this->statement->account_number,
|
|
'periodFrom' => $this->statement->period_from,
|
|
'periodTo' => $this->statement->period_to,
|
|
'isRange' => $this->statement->is_period_range,
|
|
'accounts' => Account::where('account_number',$this->statement->account_number)->first()
|
|
]);
|
|
|
|
if ($this->isZip) {
|
|
$fileName = "{$this->statement->account_number}_{$this->statement->period_from}_to_{$this->statement->period_to}.zip";
|
|
$email->attach($this->filePath, [
|
|
'as' => $fileName,
|
|
'mime' => 'application/zip',
|
|
]);
|
|
} else {
|
|
$fileName = "{$this->statement->account_number}_{$this->statement->period_from}.pdf";
|
|
$email->attach($this->filePath, [
|
|
'as' => $fileName,
|
|
'mime' => 'application/pdf',
|
|
]);
|
|
}
|
|
|
|
return $email;
|
|
}
|
|
}
|