✨ feat(Modules/Webstatement): Tambahkan BalanceSummaryRequest dan BalanceSummaryResource untuk API Balance Summary
- Menambahkan BalanceSummaryRequest dengan validasi lengkap untuk parameter API balance summary. - Menambahkan BalanceSummaryResource untuk transformasi dan formatting response balance summary. - Implementasi validasi nomor rekening menggunakan regex alphanumeric dan dash. - Validasi tanggal dengan format Y-m-d dan batasan logika tanggal. - Format balance menggunakan number_format dengan pemisah ribuan dan desimal Indonesia (2, ',', '.'). - Struktur response JSON yang konsisten dengan informasi lengkap balance summary. - Menambahkan metadata pada response untuk tracking dan debugging. - Logging request untuk monitoring dan audit trail. - Mendukung pagination dan filtering tanggal untuk API balance summary.
This commit is contained in:
86
app/Http/Requests/BalanceSummaryRequest.php
Normal file
86
app/Http/Requests/BalanceSummaryRequest.php
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Webstatement\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class BalanceSummaryRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
// Sesuaikan dengan authorization logic jika diperlukan
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'account_number' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:50',
|
||||||
|
'regex:/^[A-Z0-9-]+$/i' // Hanya alphanumeric dan dash
|
||||||
|
],
|
||||||
|
'start_date' => [
|
||||||
|
'required',
|
||||||
|
'date_format:Y-m-d',
|
||||||
|
'before_or_equal:end_date',
|
||||||
|
'after_or_equal:1900-01-01',
|
||||||
|
'before_or_equal:today'
|
||||||
|
],
|
||||||
|
'end_date' => [
|
||||||
|
'required',
|
||||||
|
'date_format:Y-m-d',
|
||||||
|
'after_or_equal:start_date',
|
||||||
|
'after_or_equal:1900-01-01',
|
||||||
|
'before_or_equal:today'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get custom messages for validator errors.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'account_number.required' => 'Nomor rekening wajib diisi',
|
||||||
|
'account_number.string' => 'Nomor rekening harus berupa teks',
|
||||||
|
'account_number.max' => 'Nomor rekening maksimal 50 karakter',
|
||||||
|
'account_number.regex' => 'Nomor rekening hanya boleh mengandung huruf, angka, dan strip',
|
||||||
|
'start_date.required' => 'Tanggal awal wajib diisi',
|
||||||
|
'start_date.date_format' => 'Format tanggal awal harus YYYY-MM-DD',
|
||||||
|
'start_date.before_or_equal' => 'Tanggal awal harus sebelum atau sama dengan tanggal akhir',
|
||||||
|
'end_date.required' => 'Tanggal akhir wajib diisi',
|
||||||
|
'end_date.date_format' => 'Format tanggal akhir harus YYYY-MM-DD',
|
||||||
|
'end_date.after_or_equal' => 'Tanggal akhir harus sesudah atau sama dengan tanggal awal',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the data for validation.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
Log::info('Balance summary request received', [
|
||||||
|
'input' => $this->all(),
|
||||||
|
'ip' => $this->ip(),
|
||||||
|
'user_agent' => $this->userAgent()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
63
app/Http/Resources/BalanceSummaryResource.php
Normal file
63
app/Http/Resources/BalanceSummaryResource.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Webstatement\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class BalanceSummaryResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'account_number' => $this['account_number'],
|
||||||
|
'period' => [
|
||||||
|
'start_date' => $this['period']['start_date'],
|
||||||
|
'end_date' => $this['period']['end_date'],
|
||||||
|
],
|
||||||
|
'opening_balance' => [
|
||||||
|
'date' => $this['opening_balance']['date'],
|
||||||
|
'balance' => $this['opening_balance']['balance'],
|
||||||
|
'formatted_balance' => number_format($this['opening_balance']['balance'], 2, ',', '.'),
|
||||||
|
],
|
||||||
|
'closing_balance' => [
|
||||||
|
'date' => $this['closing_balance']['date'],
|
||||||
|
'balance' => $this['closing_balance']['balance'],
|
||||||
|
'formatted_balance' => number_format($this['closing_balance']['balance'], 2, ',', '.'),
|
||||||
|
'base_balance' => [
|
||||||
|
'date' => $this['closing_balance']['base_balance']['date'],
|
||||||
|
'balance' => $this['closing_balance']['base_balance']['balance'],
|
||||||
|
'formatted_balance' => number_format($this['closing_balance']['base_balance']['balance'], 2, ',', '.'),
|
||||||
|
],
|
||||||
|
'transactions_on_end_date' => $this['closing_balance']['transactions_on_end_date'],
|
||||||
|
'formatted_transactions_on_end_date' => number_format($this['closing_balance']['transactions_on_end_date'], 2, ',', '.'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get additional meta data.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function with($request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'meta' => [
|
||||||
|
'account_number' => $this['account_number'],
|
||||||
|
'period' => [
|
||||||
|
'start_date' => $this['period']['start_date'],
|
||||||
|
'end_date' => $this['period']['end_date'],
|
||||||
|
],
|
||||||
|
'generated_at' => now()->toDateTimeString(),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user