- 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.
64 lines
2.2 KiB
PHP
64 lines
2.2 KiB
PHP
<?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(),
|
|
],
|
|
];
|
|
}
|
|
}
|