migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('accounts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->string('name');
|
||||
$table->string('code')->nullable();
|
||||
$table->enum('type', ['asset', 'liability', 'equity', 'income', 'expense'])->default('asset');
|
||||
$table->decimal('opening_balance', 15, 2)->default(0);
|
||||
$table->decimal('current_balance', 15, 2)->default(0);
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('accounts');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('funds', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->string('name');
|
||||
$table->enum('type', ['asset', 'liability', 'equity', 'income', 'expense'])->default('asset');
|
||||
$table->string('code')->nullable();
|
||||
$table->decimal('opening_balance', 15, 2)->default(0);
|
||||
$table->decimal('current_balance', 15, 2)->default(0);
|
||||
$table->boolean('is_default')->default(false);
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('funds');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('transactions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->unsignedBigInteger('fund_id')->nullable()->index();
|
||||
$table->string('transaction_type'); // deposit, payment, journal, sale, purchase, loan, transfer, tip
|
||||
$table->date('transaction_date')->index();
|
||||
$table->string('reference_no')->nullable()->index();
|
||||
$table->text('notes')->nullable();
|
||||
$table->decimal('total_debit', 15, 2)->default(0);
|
||||
$table->decimal('total_credit', 15, 2)->default(0);
|
||||
$table->unsignedBigInteger('created_by')->nullable();
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('transactions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('transaction_details', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->unsignedBigInteger('transaction_id')->index();
|
||||
$table->unsignedBigInteger('account_id')->index();
|
||||
$table->decimal('debit', 15, 2)->default(0);
|
||||
$table->decimal('credit', 15, 2)->default(0);
|
||||
$table->text('note')->nullable();
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('transaction_details');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('expense_categories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->string('name');
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('expense_categories');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('expenses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->unsignedBigInteger('fund_id')->index(); // where money arrived
|
||||
$table->unsignedBigInteger('account_id')->index(); // account used to pay
|
||||
$table->unsignedBigInteger('expense_category_id')->nullable()->index();
|
||||
$table->decimal('amount', 15, 2);
|
||||
$table->date('transaction_date')->index();
|
||||
$table->string('voucher_no')->nullable();
|
||||
$table->string('received_from')->nullable();
|
||||
$table->text('note')->nullable();
|
||||
$table->unsignedBigInteger('created_by')->nullable();
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('expenses');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('deposit_categories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->string('name');
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('deposit_categories');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('deposits', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->unsignedBigInteger('fund_id')->index(); // where money arrived
|
||||
$table->unsignedBigInteger('account_id')->index(); // source account (if any)
|
||||
$table->unsignedBigInteger('deposit_category_id')->nullable()->index();
|
||||
$table->decimal('amount', 15, 2);
|
||||
$table->date('transaction_date')->index();
|
||||
$table->string('voucher_no')->nullable();
|
||||
$table->string('received_from')->nullable();
|
||||
$table->text('note')->nullable();
|
||||
$table->unsignedBigInteger('created_by')->nullable();
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('deposits');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('fund_transfers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->unsignedBigInteger('from_fund_id')->index();
|
||||
$table->unsignedBigInteger('to_fund_id')->index();
|
||||
$table->decimal('amount', 15, 2);
|
||||
$table->text('note')->nullable();
|
||||
$table->unsignedBigInteger('created_by')->nullable();
|
||||
$table->date('transfer_date')->index();
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('fund_transfers');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tips', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->unsignedBigInteger('waiter_id')->nullable()->index();
|
||||
$table->unsignedBigInteger('order_id')->nullable()->index();
|
||||
$table->decimal('amount', 15, 2)->default(0);
|
||||
$table->date('collected_at')->nullable();
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tips');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tip_distributions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('restaurant_id')->nullable();
|
||||
$table->unsignedBigInteger('waiter_id')->index();
|
||||
$table->unsignedBigInteger('account_id')->index();
|
||||
$table->decimal('amount', 15, 2);
|
||||
$table->unsignedBigInteger('created_by')->nullable();
|
||||
$table->date('distributed_at')->nullable();
|
||||
$table->smallInteger('status')->default(1)->comment('1=Active, 2=InActive');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tip_distributions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Accounting\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class AccountingDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
AccountingSeeder::class,
|
||||
FundSeeder::class,
|
||||
DepositCategorySeeder::class,
|
||||
ExpenseCategorySeeder::class,
|
||||
DepositSeeder::class,
|
||||
ExpenseSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Accounting\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\Accounting\Models\Account;
|
||||
|
||||
class AccountingSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// In SaaS onboarding, dynamic restaurant id assigned.
|
||||
// For now, making example default:
|
||||
$restaurantId = 1;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEFAULT ACCOUNTS (Chart of Accounts)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
$defaultAccounts = [
|
||||
['name' => 'Cash', 'type' => 'asset', 'code' => 'AC-001'],
|
||||
['name' => 'Bank', 'type' => 'asset', 'code' => 'AC-002'],
|
||||
['name' => 'Loan Receivable', 'type' => 'asset', 'code' => 'AC-003'],
|
||||
|
||||
['name' => 'Sales', 'type' => 'income', 'code' => 'AC-101'],
|
||||
|
||||
['name' => 'Purchase', 'type' => 'expense', 'code' => 'AC-201'],
|
||||
['name' => 'Operating Expense', 'type' => 'expense', 'code' => 'AC-202'],
|
||||
|
||||
['name' => 'Loan Payable', 'type' => 'liability', 'code' => 'AC-301'],
|
||||
['name' => 'Tips Received', 'type' => 'liability', 'code' => 'AC-302'],
|
||||
];
|
||||
|
||||
foreach ($defaultAccounts as $acc) {
|
||||
Account::updateOrCreate(
|
||||
[
|
||||
'restaurant_id' => $restaurantId,
|
||||
'code' => $acc['code'],
|
||||
],
|
||||
[
|
||||
'name' => $acc['name'],
|
||||
'type' => $acc['type'],
|
||||
'opening_balance' => 0,
|
||||
'current_balance' => 0,
|
||||
'status' => 1,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Accounting\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DepositCategorySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
DB::table('deposit_categories')->insert([
|
||||
['restaurant_id' => 1, 'name' => 'Customer Payment'],
|
||||
['restaurant_id' => 1, 'name' => 'Fund Transfer In'],
|
||||
['restaurant_id' => 1, 'name' => 'Sales Revenue'],
|
||||
['restaurant_id' => 1, 'name' => 'Donations'],
|
||||
['restaurant_id' => 1, 'name' => 'Loan Received'],
|
||||
['restaurant_id' => 1, 'name' => 'Service Charge'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Accounting\Database\Seeders;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Accounting\Models\Account;
|
||||
use Modules\Accounting\Models\Deposit;
|
||||
use Modules\Accounting\Models\Fund;
|
||||
use Modules\Accounting\Models\Transaction;
|
||||
use Modules\Accounting\Models\TransactionDetail;
|
||||
|
||||
class DepositSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$restaurantId = 1; // example restaurant
|
||||
|
||||
// Sample Deposit Data
|
||||
$deposits = [
|
||||
[
|
||||
'fund_name' => 'Cash', // fund where money arrived
|
||||
'account_code' => 'AC-101', // source account (income/sales)
|
||||
'amount' => 500.00,
|
||||
'transaction_date' => Carbon::now()->subDays(2),
|
||||
'voucher_no' => 'DEP-001',
|
||||
'received_from' => 'Customer A',
|
||||
'note' => 'Cash sale deposit',
|
||||
'created_by' => 1,
|
||||
],
|
||||
[
|
||||
'fund_name' => 'Bank',
|
||||
'account_code' => 'AC-101',
|
||||
'amount' => 1000.00,
|
||||
'transaction_date' => Carbon::now()->subDay(),
|
||||
'voucher_no' => 'DEP-002',
|
||||
'received_from' => 'Customer B',
|
||||
'note' => 'Bank deposit from sales',
|
||||
'created_by' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($deposits as $dep) {
|
||||
$fund = Fund::where('restaurant_id', $restaurantId)
|
||||
->where('name', $dep['fund_name'])
|
||||
->first();
|
||||
|
||||
$account = Account::where('restaurant_id', $restaurantId)
|
||||
->where('code', $dep['account_code'])
|
||||
->first();
|
||||
|
||||
if (! $fund || ! $account) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($restaurantId, $fund, $account, $dep) {
|
||||
// 1️⃣ Create Deposit
|
||||
$deposit = Deposit::create([
|
||||
'restaurant_id' => $restaurantId,
|
||||
'fund_id' => $fund->id,
|
||||
'account_id' => $account->id,
|
||||
'deposit_category_id' => 1,
|
||||
'amount' => $dep['amount'],
|
||||
'transaction_date' => $dep['transaction_date'],
|
||||
'voucher_no' => $dep['voucher_no'],
|
||||
'received_from' => $dep['received_from'],
|
||||
'note' => $dep['note'],
|
||||
'created_by' => $dep['created_by'],
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// 2️⃣ Create Transaction
|
||||
$transaction = Transaction::create([
|
||||
'restaurant_id' => $restaurantId,
|
||||
'fund_id' => $fund->id,
|
||||
'transaction_type' => 'deposit',
|
||||
'transaction_date' => $dep['transaction_date'],
|
||||
'reference_no' => $dep['voucher_no'],
|
||||
'notes' => $dep['note'],
|
||||
'total_debit' => 0,
|
||||
'total_credit' => $dep['amount'],
|
||||
'created_by' => $dep['created_by'],
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// 3️⃣ Transaction Details
|
||||
// Credit to Fund (increase)
|
||||
TransactionDetail::create([
|
||||
'restaurant_id' => $restaurantId,
|
||||
'transaction_id' => $transaction->id,
|
||||
'account_id' => $fund->id, // fund receives money (asset)
|
||||
'debit' => $dep['amount'],
|
||||
'credit' => 0,
|
||||
'note' => $dep['note'].' (Fund)',
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// Debit from Source Account
|
||||
TransactionDetail::create([
|
||||
'restaurant_id' => $restaurantId,
|
||||
'transaction_id' => $transaction->id,
|
||||
'account_id' => $account->id, // source account (income)
|
||||
'debit' => 0,
|
||||
'credit' => $dep['amount'],
|
||||
'note' => $dep['note'].' (Source Account)',
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// 4️⃣ Update Fund Balance
|
||||
$fund->increment('current_balance', $dep['amount']);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Accounting\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ExpenseCategorySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
DB::table('expense_categories')->insert([
|
||||
['restaurant_id' => 1, 'name' => 'Food Purchase'],
|
||||
['restaurant_id' => 1, 'name' => 'Operating Expense'],
|
||||
['restaurant_id' => 1, 'name' => 'Salaries'],
|
||||
['restaurant_id' => 1, 'name' => 'Marketing'],
|
||||
['restaurant_id' => 1, 'name' => 'Electricity Bill'],
|
||||
['restaurant_id' => 1, 'name' => 'Loan Repayment'],
|
||||
['restaurant_id' => 1, 'name' => 'Fund Transfer Out'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Accounting\Database\Seeders;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Accounting\Models\Account;
|
||||
use Modules\Accounting\Models\Expense;
|
||||
use Modules\Accounting\Models\Fund;
|
||||
use Modules\Accounting\Models\Transaction;
|
||||
use Modules\Accounting\Models\TransactionDetail;
|
||||
|
||||
class ExpenseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$restaurantId = 1; // example restaurant
|
||||
|
||||
// Sample Expense Data
|
||||
$expenses = [
|
||||
[
|
||||
'fund_name' => 'Cash', // fund where money arrived
|
||||
'account_code' => 'AC-101', // source account (income/sales)
|
||||
'amount' => 500.00,
|
||||
'transaction_date' => Carbon::now()->subDays(2),
|
||||
'voucher_no' => 'DEP-001',
|
||||
'received_from' => 'Customer A',
|
||||
'note' => 'Cash sale expense',
|
||||
'created_by' => 1,
|
||||
],
|
||||
[
|
||||
'fund_name' => 'Bank',
|
||||
'account_code' => 'AC-101',
|
||||
'amount' => 1000.00,
|
||||
'transaction_date' => Carbon::now()->subDay(),
|
||||
'voucher_no' => 'DEP-002',
|
||||
'received_from' => 'Customer B',
|
||||
'note' => 'Bank expense from sales',
|
||||
'created_by' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($expenses as $dep) {
|
||||
$fund = Fund::where('restaurant_id', $restaurantId)
|
||||
->where('name', $dep['fund_name'])
|
||||
->first();
|
||||
|
||||
$account = Account::where('restaurant_id', $restaurantId)
|
||||
->where('code', $dep['account_code'])
|
||||
->first();
|
||||
|
||||
if (! $fund || ! $account) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($restaurantId, $fund, $account, $dep) {
|
||||
// 1️⃣ Create Expense
|
||||
$expense = Expense::create([
|
||||
'restaurant_id' => $restaurantId,
|
||||
'fund_id' => $fund->id,
|
||||
'account_id' => $account->id,
|
||||
'expense_category_id' => 1,
|
||||
'amount' => $dep['amount'],
|
||||
'transaction_date' => $dep['transaction_date'],
|
||||
'voucher_no' => $dep['voucher_no'],
|
||||
'received_from' => $dep['received_from'],
|
||||
'note' => $dep['note'],
|
||||
'created_by' => $dep['created_by'],
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// 2️⃣ Create Transaction
|
||||
$transaction = Transaction::create([
|
||||
'restaurant_id' => $restaurantId,
|
||||
'fund_id' => $fund->id,
|
||||
'transaction_type' => 'expense',
|
||||
'transaction_date' => $dep['transaction_date'],
|
||||
'reference_no' => $dep['voucher_no'],
|
||||
'notes' => $dep['note'],
|
||||
'total_debit' => 0,
|
||||
'total_credit' => $dep['amount'],
|
||||
'created_by' => $dep['created_by'],
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// 3️⃣ Transaction Details
|
||||
// Credit to Fund (increase)
|
||||
TransactionDetail::create([
|
||||
'restaurant_id' => $restaurantId,
|
||||
'transaction_id' => $transaction->id,
|
||||
'account_id' => $fund->id, // fund receives money (asset)
|
||||
'debit' => $dep['amount'],
|
||||
'credit' => 0,
|
||||
'note' => $dep['note'].' (Fund)',
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// Debit from Source Account
|
||||
TransactionDetail::create([
|
||||
'restaurant_id' => $restaurantId,
|
||||
'transaction_id' => $transaction->id,
|
||||
'account_id' => $account->id, // source account (income)
|
||||
'debit' => 0,
|
||||
'credit' => $dep['amount'],
|
||||
'note' => $dep['note'].' (Source Account)',
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// 4️⃣ Update Fund Balance
|
||||
$fund->increment('current_balance', $dep['amount']);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Accounting\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\Accounting\Models\Fund;
|
||||
|
||||
class FundSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// In SaaS onboarding, dynamic restaurant id assigned.
|
||||
// For now, making example default:
|
||||
$restaurantId = 1;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEFAULT FUNDS (Cash Sources)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
$defaultFunds = [
|
||||
['name' => 'Cash', 'type' => 'asset', 'code' => 'FD-001', 'is_default' => true],
|
||||
['name' => 'Bank', 'type' => 'asset', 'code' => 'FD-002', 'is_default' => false],
|
||||
['name' => 'Wallet', 'type' => 'asset', 'code' => 'FD-003', 'is_default' => false],
|
||||
];
|
||||
|
||||
foreach ($defaultFunds as $fund) {
|
||||
Fund::updateOrCreate(
|
||||
[
|
||||
'restaurant_id' => $restaurantId,
|
||||
'code' => $fund['code'],
|
||||
],
|
||||
[
|
||||
'name' => $fund['name'],
|
||||
'type' => $fund['type'],
|
||||
'opening_balance' => 0,
|
||||
'current_balance' => 0,
|
||||
'is_default' => $fund['is_default'],
|
||||
'status' => 1,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user