feat(webstatement): tambah model AccountBalance dan relasi balances pada Account
- Menambahkan model `AccountBalance` dengan fitur berikut: - Properti `fillable` meliputi: `account_number`, `period`, `actual_balance`, `cleared_balance`. - Relasi `belongsTo` dengan model `Account`. - Scope query untuk filter berdasarkan `account_number` (`scopeForAccount`) dan `period` (`scopeForPeriod`). - Fungsi statis `getBalance` untuk mendapatkan saldo berdasarkan `account_number` dan `period`. - Menambahkan method berikut pada model `Account`: - Relasi `hasMany` dengan `AccountBalance` untuk mendapatkan semua saldo terkait. - Method `getBalanceForPeriod` untuk mendapatkan saldo pada periode tertentu. - Membuat migrasi untuk tabel `account_balances` dengan spesifikasi berikut: - Kolom: `account_number`, `period` (format: YYYY-MM), `actual_balance` (decimal), `cleared_balance` (decimal), `timestamps`. - Konstrain unik untuk pasangan `account_number` dan `period`. - Indeks pada kolom `account_number`, `period`, dan `created_at`. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('account_balances', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('account_number');
|
||||
$table->string('period'); // Format: YYYY-MM
|
||||
$table->decimal('actual_balance', 20, 2)->default(0);
|
||||
$table->decimal('cleared_balance', 20, 2)->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
// Create a unique constraint to ensure one record per account per period
|
||||
$table->unique(['account_number', 'period']);
|
||||
|
||||
// Add indexes for faster queries
|
||||
$table->index('account_number');
|
||||
$table->index('period');
|
||||
$table->index('created_at');
|
||||
|
||||
// Add foreign key if needed
|
||||
// $table->foreign('account_number')->references('account_number')->on('accounts');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('account_balances');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user