diff --git a/app/Http/Requests/BalanceSummaryRequest.php b/app/Http/Requests/BalanceSummaryRequest.php new file mode 100644 index 0000000..faee1c5 --- /dev/null +++ b/app/Http/Requests/BalanceSummaryRequest.php @@ -0,0 +1,86 @@ + + */ + 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 + */ + 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() + ]); + } +} \ No newline at end of file diff --git a/app/Http/Resources/BalanceSummaryResource.php b/app/Http/Resources/BalanceSummaryResource.php new file mode 100644 index 0000000..1ca616d --- /dev/null +++ b/app/Http/Resources/BalanceSummaryResource.php @@ -0,0 +1,63 @@ + $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(), + ], + ]; + } +}