Files
webstatement/app/Http/Requests/PrintStatementRequest.php
Daeng Deni Mardaeni eaa847e7e7 feat(webstatement): tambah fitur request dan pengelolaan print statement
- Tambah menu baru untuk "Print Statement" di konfigurasi module.
- Tambah route baru untuk pengelolaan statement seperti list, download, otorisasi, dan datatables.
- Implementasi `PrintStatementController` untuk operasi terkait request dan manajemen statement.
- Implementasi model `PrintStatementLog` untuk mencatat log request statement, termasuk validasi dan relasi yang dibutuhkan.
- Tambah form request `PrintStatementRequest` untuk validasi input.
- Tambah migration untuk tabel `print_statement_logs` yang menyimpan rekaman log statement.
- Tambah halaman blade untuk index dan form request statement.

Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
2025-05-11 18:15:21 +07:00

82 lines
2.7 KiB
PHP

<?php
namespace Modules\Webstatement\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
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.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules()
: array
{
$rules = [
'branch_code' => ['required', 'string', 'exists:branches,code'],
'account_number' => ['required', 'string'],
'is_period_range' => ['sometimes', 'boolean'],
'period_from' => ['required', 'string', 'regex:/^\d{6}$/'], // YYYYMM format
];
// If it's a period range, require period_to
if ($this->input('is_period_range')) {
$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.
*
* @return array
*/
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',
];
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
: void
{
// Convert is_period_range to boolean if it exists
if ($this->has('is_period_range')) {
$this->merge([
'is_period_range' => filter_var($this->is_period_range, FILTER_VALIDATE_BOOLEAN),
]);
}
}
}