- **Perbaikan dan Penambahan Komando:**
- Memberikan komando baru `webstatement:check-progress` untuk memantau progres pengiriman email statement.
- Menampilkan informasi seperti `Log ID`, `Batch ID`, `Request Type`, status, hingga persentase progress.
- Menangani secara detail jumlah akun yang diproses, sukses, gagal, dan kalkulasi tingkat keberhasilan.
- Menyediakan penanganan error jika log tidak ditemukan atau terjadi kegagalan lainnya.
- Memperluas komando `webstatement:send-email`:
- Mendukung pengiriman berdasarkan `single account`, `branch`, atau `all branches`.
- Menambahkan validasi parameter `type` (`single`, `branch`, `all`) dan input spesifik seperti `--account` atau `--branch` untuk mode tertentu.
- Melakukan pencatatan log awal dengan metadata lengkap seperti `request_type`, `batch_id`, dan status.
- **Peningkatan Logika Proses Backend:**
- Menambahkan fungsi `createLogEntry` untuk mencatat log pengiriman email statement secara dinamis berdasarkan tipe request.
- Menyediakan reusable method seperti `validateParameters` dan `determineRequestTypeAndTarget` untuk mempermudah pengelolaan parameter pengiriman.
- Memberikan feedback dan panduan kepada pengguna mengenai ID log dan komando monitoring (`webstatement:check-progress`).
- **Penambahan Controller dan Fitur UI:**
- Menambahkan controller baru `EmailStatementLogController`:
- Mendukung pengelolaan log seperti list, detail, dan retry untuk pengiriman ulang email statement.
- Menyediakan fitur pencarian, filter, dan halaman data log yang responsif menggunakan datatable.
- Menambahkan kemampuan resend email untuk log dengan status `completed` atau `failed`.
- Mengimplementasikan UI untuk log pengiriman:
- Halaman daftar monitoring dengan filter berdasarkan branch, account number, request type, status, dan tanggal.
- Menampilkan kemajuan, tingkat keberhasilan, serta tombol aksi seperti detail dan pengiriman ulang.
- **Peningkatan Model dan Validasi:**
- Menyesuaikan model `PrintStatementLog` untuk mendukung lebih banyak atribut seperti `processed_accounts`, `success_count`, `failed_count`, `request_type`, serta metode utilitas seperti `getProgressPercentage()` dan `getSuccessRate()`.
- Memvalidasi parameter input lebih mendalam agar kesalahan dapat diminimalisasi di awal proses.
- **Peningkatan pada View dan Feedback Pengguna:**
- Menambah daftar command berguna untuk user di interface log:
- Status antrian dengan `php artisan queue:work`.
- Monitoring menggunakan komando custom yang baru ditambahkan.
- **Perbaikan Logging dan Error Handling:**
- Menambahkan logging komprehensif pada semua proses, termasuk batch pengiriman ulang.
- Memastikan rollback pada database jika terjadi error melalui transaksi pada critical path.
Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
126 lines
4.4 KiB
PHP
126 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Webstatement\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Modules\Webstatement\Models\PrintStatementLog as Statement;
|
|
|
|
class PrintStatementRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'branch_code' => ['required', 'string', 'exists:branches,code'],
|
|
'account_number' => ['required', 'string'],
|
|
'is_period_range' => ['sometimes', 'boolean'],
|
|
'email' => ['nullable', 'email'],
|
|
'email_sent_at' => ['nullable', 'timestamp'],
|
|
'request_type' => ['sometimes', 'string', 'in:single_account,branch,all_branches'],
|
|
'batch_id' => ['nullable', 'string'],
|
|
'period_from' => [
|
|
'required',
|
|
'string',
|
|
'regex:/^\d{6}$/', // YYYYMM format
|
|
// Prevent duplicate requests with same account number and period
|
|
function ($attribute, $value, $fail) {
|
|
$query = Statement::where('account_number', $this->input('account_number'))
|
|
->where('authorization_status', '!=', 'rejected')
|
|
->where('period_from', $value);
|
|
|
|
// If this is an update request, exclude the current record
|
|
if ($this->route('statement')) {
|
|
$query->where('id', '!=', $this->route('statement'));
|
|
}
|
|
|
|
// If period_to is provided, check for overlapping periods
|
|
if ($this->input('period_to')) {
|
|
$query->where(function ($q) use ($value) {
|
|
$q->where('period_from', '<=', $this->input('period_to'))
|
|
->where('period_to', '>=', $value);
|
|
});
|
|
}
|
|
|
|
if ($query->exists()) {
|
|
$fail('A statement request with this account number and period already exists.');
|
|
}
|
|
}
|
|
],
|
|
];
|
|
|
|
// If it's a period range, require period_to
|
|
if ($this->input('period_to')) {
|
|
$rules['period_to'] = [
|
|
'required',
|
|
'string',
|
|
'regex:/^\d{6}$/', // YYYYMM format
|
|
'gte:period_from' // period_to must be greater than or equal to period_from
|
|
];
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
/**
|
|
* Get custom messages for validator errors.
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'branch_code.required' => 'Branch code is required',
|
|
'branch_code.exists' => 'Selected branch does not exist',
|
|
'account_number.required' => 'Account number is required',
|
|
'period_from.required' => 'Period is required',
|
|
'period_from.regex' => 'Period must be in YYYYMM format',
|
|
'period_to.required' => 'End period is required for period range',
|
|
'period_to.regex' => 'End period must be in YYYYMM format',
|
|
'period_to.gte' => 'End period must be after or equal to start period',
|
|
'request_type.in' => 'Request type must be single_account, branch, or all_branches',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
if ($this->has('period_from')) {
|
|
// Convert to YYYYMM format
|
|
$this->merge([
|
|
'period_from' => substr($this->period_from, 0, 4) . substr($this->period_from, 5, 2),
|
|
]);
|
|
}
|
|
|
|
if ($this->has('period_to')) {
|
|
// Convert to YYYYMM format
|
|
$this->merge([
|
|
'period_to' => substr($this->period_to, 0, 4) . substr($this->period_to, 5, 2),
|
|
]);
|
|
}
|
|
|
|
// Convert is_period_range to boolean if it exists
|
|
if ($this->has('period_to')) {
|
|
$this->merge([
|
|
'is_period_range' => true,
|
|
]);
|
|
}
|
|
|
|
// Set default request_type if not provided
|
|
if (!$this->has('request_type')) {
|
|
$this->merge([
|
|
'request_type' => 'single_account',
|
|
]);
|
|
}
|
|
}
|
|
}
|