Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ledger_accounts', function (Blueprint $table) {
$table->increments('id');
$table->string('_key')->nullable();
$table->string('uuid', 191)->nullable()->unique();
$table->string('public_id', 191)->nullable()->unique();
$table->uuid('company_uuid')->nullable()->index();
$table->char('created_by_uuid', 36)->nullable()->index();
$table->char('updated_by_uuid', 36)->nullable()->index();
$table->string('name', 191);
$table->string('code', 191)->nullable()->index();
$table->string('type', 191)->index(); // asset, liability, equity, revenue, expense
$table->text('description')->nullable();
$table->boolean('is_system_account')->default(false);
$table->integer('balance')->default(0); // stored in cents
$table->string('currency', 3)->default('USD');
$table->string('status', 191)->default('active')->index();
$table->json('meta')->nullable();
$table->softDeletes();
$table->timestamp('created_at')->nullable()->index();
$table->timestamp('updated_at')->nullable();

$table->unique(['uuid']);
$table->unique(['company_uuid', 'code']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ledger_accounts');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ledger_journals', function (Blueprint $table) {
$table->increments('id');
$table->string('_key')->nullable();
$table->string('uuid', 191)->nullable()->unique();
$table->uuid('company_uuid')->nullable()->index();
$table->char('transaction_uuid', 36)->nullable()->index();
$table->char('debit_account_uuid', 36)->nullable()->index();
$table->char('credit_account_uuid', 36)->nullable()->index();
$table->integer('amount'); // stored in cents
$table->string('currency', 3)->default('USD');
$table->text('description')->nullable();
$table->date('date')->index();
$table->json('meta')->nullable();
$table->timestamp('created_at')->nullable()->index();
$table->timestamp('updated_at')->nullable();

$table->unique(['uuid']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ledger_journals');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ledger_invoices', function (Blueprint $table) {
$table->increments('id');
$table->string('_key')->nullable();
$table->string('uuid', 191)->nullable()->unique();
$table->string('public_id', 191)->nullable()->unique();
$table->uuid('company_uuid')->nullable()->index();
$table->char('created_by_uuid', 36)->nullable()->index();
$table->char('updated_by_uuid', 36)->nullable()->index();
$table->uuid('customer_uuid')->nullable()->index();
$table->string('customer_type')->nullable();
$table->uuid('order_uuid')->nullable()->index();
$table->uuid('transaction_uuid')->nullable()->index();
$table->string('number', 191)->unique();
$table->date('date')->index();
$table->date('due_date')->nullable()->index();
$table->integer('subtotal')->default(0); // stored in cents
$table->integer('tax')->default(0); // stored in cents
$table->integer('total_amount')->default(0); // stored in cents
$table->integer('amount_paid')->default(0); // stored in cents
$table->integer('balance')->default(0); // stored in cents
$table->string('currency', 3)->default('USD');
$table->string('status', 191)->default('draft')->index(); // draft, sent, viewed, paid, partial, overdue, void, cancelled
$table->text('notes')->nullable();
$table->text('terms')->nullable();
$table->json('meta')->nullable();
$table->softDeletes();
$table->timestamp('created_at')->nullable()->index();
$table->timestamp('updated_at')->nullable();
$table->timestamp('sent_at')->nullable();
$table->timestamp('viewed_at')->nullable();
$table->timestamp('paid_at')->nullable();

$table->unique(['uuid']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ledger_invoices');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ledger_invoice_items', function (Blueprint $table) {
$table->increments('id');
$table->string('_key')->nullable();
$table->string('uuid', 191)->nullable()->unique();
$table->uuid('invoice_uuid')->nullable()->index();
$table->string('description', 191);
$table->integer('quantity')->default(1);
$table->integer('unit_price')->default(0); // stored in cents
$table->integer('amount')->default(0); // stored in cents
$table->decimal('tax_rate', 5, 2)->default(0.00); // percentage
$table->integer('tax_amount')->default(0); // stored in cents
$table->json('meta')->nullable();
$table->timestamp('created_at')->nullable()->index();
$table->timestamp('updated_at')->nullable();

$table->unique(['uuid']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ledger_invoice_items');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ledger_wallets', function (Blueprint $table) {
$table->increments('id');
$table->string('_key')->nullable();
$table->string('uuid', 191)->nullable()->unique();
$table->string('public_id', 191)->nullable()->unique();
$table->uuid('company_uuid')->nullable()->index();
$table->char('created_by_uuid', 36)->nullable()->index();
$table->char('updated_by_uuid', 36)->nullable()->index();
$table->uuid('subject_uuid')->nullable()->index();
$table->string('subject_type')->nullable();
$table->integer('balance')->default(0); // stored in cents
$table->string('currency', 3)->default('USD');
$table->string('status', 191)->default('active')->index(); // active, frozen, closed
$table->json('meta')->nullable();
$table->softDeletes();
$table->timestamp('created_at')->nullable()->index();
$table->timestamp('updated_at')->nullable();

$table->unique(['uuid']);
$table->unique(['subject_uuid', 'subject_type']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ledger_wallets');
}
};
34 changes: 34 additions & 0 deletions server/src/Events/InvoiceCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Fleetbase\Ledger\Events;

use Fleetbase\Ledger\Models\Invoice;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class InvoiceCreated
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/**
* The invoice instance.
*
* @var \Fleetbase\Ledger\Models\Invoice
*/
public Invoice $invoice;

/**
* Create a new event instance.
*
* @param Invoice $invoice
*
* @return void
*/
public function __construct(Invoice $invoice)
{
$this->invoice = $invoice;
}
}
34 changes: 34 additions & 0 deletions server/src/Events/InvoicePaid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Fleetbase\Ledger\Events;

use Fleetbase\Ledger\Models\Invoice;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class InvoicePaid
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/**
* The invoice instance.
*
* @var \Fleetbase\Ledger\Models\Invoice
*/
public Invoice $invoice;

/**
* Create a new event instance.
*
* @param Invoice $invoice
*
* @return void
*/
public function __construct(Invoice $invoice)
{
$this->invoice = $invoice;
}
}
Loading
Loading