migrate to gtea from bistbucket
This commit is contained in:
@@ -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