feat: updates
This commit is contained in:
56
app/Observers/AccountObserver.php
Normal file
56
app/Observers/AccountObserver.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Account;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AccountObserver
|
||||
{
|
||||
/**
|
||||
* Handle the Account "created" event.
|
||||
*/
|
||||
public function created(Account $account): void
|
||||
{
|
||||
DB::transaction(function () use ($account) {
|
||||
if (! $account->balances()->exists()) {
|
||||
$account->balances()->create([
|
||||
'balance' => 0,
|
||||
'is_starting' => true,
|
||||
]);
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Account "updated" event.
|
||||
*/
|
||||
public function updated(Account $account): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Account "deleted" event.
|
||||
*/
|
||||
public function deleted(Account $account): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Account "restored" event.
|
||||
*/
|
||||
public function restored(Account $account): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Account "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(Account $account): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
62
app/Observers/BranchObserver.php
Normal file
62
app/Observers/BranchObserver.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Branch;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BranchObserver
|
||||
{
|
||||
/**
|
||||
* Handle the Branch "created" event.
|
||||
*/
|
||||
public function created(Branch $branch): void
|
||||
{
|
||||
$accounts = $branch->client->accounts;
|
||||
DB::transaction(function () use ($branch, $accounts) {
|
||||
foreach ($accounts as $account) {
|
||||
$branch->balances()->updateOrCreate(
|
||||
attributes: [
|
||||
'account_id' => $account->id,
|
||||
'is_starting' => true,
|
||||
],
|
||||
values: [
|
||||
'balance' => $account->starting_balance,
|
||||
]);
|
||||
}
|
||||
}, 2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Branch "updated" event.
|
||||
*/
|
||||
public function updated(Branch $branch): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Branch "deleted" event.
|
||||
*/
|
||||
public function deleted(Branch $branch): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Branch "restored" event.
|
||||
*/
|
||||
public function restored(Branch $branch): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Branch "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(Branch $branch): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
87
app/Observers/ClientObserver.php
Normal file
87
app/Observers/ClientObserver.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Client;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ClientObserver
|
||||
{
|
||||
/**
|
||||
* Handle the Client "created" event.
|
||||
*/
|
||||
public function created(Client $client): void
|
||||
{
|
||||
DB::transaction(function () use ($client) {
|
||||
$client->accounts()->createMany([
|
||||
[
|
||||
'account_type_id' => 1,
|
||||
'account' => 'Cash',
|
||||
'normal_balance' => 'debit',
|
||||
],
|
||||
[
|
||||
'account_type_id' => 1,
|
||||
'account' => 'Input Tax',
|
||||
'normal_balance' => 'debit',
|
||||
],
|
||||
[
|
||||
'account_type_id' => 1,
|
||||
'account' => 'Creditable Withholding Tax',
|
||||
'normal_balance' => 'debit',
|
||||
],
|
||||
[
|
||||
'account_type_id' => 2,
|
||||
'account' => 'Output Tax',
|
||||
'normal_balance' => 'credit',
|
||||
],
|
||||
[
|
||||
'account_type_id' => 2,
|
||||
'account' => 'Payable Withholding Tax',
|
||||
'normal_balance' => 'credit',
|
||||
],
|
||||
[
|
||||
'account_type_id' => 5,
|
||||
'account' => 'Vat Exempt Revenue',
|
||||
'normal_balance' => 'credit',
|
||||
],
|
||||
[
|
||||
'account_type_id' => 4,
|
||||
'account' => 'Sales Discount',
|
||||
'normal_balance' => 'debit',
|
||||
],
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Client "updated" event.
|
||||
*/
|
||||
public function updated(Client $client): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Client "deleted" event.
|
||||
*/
|
||||
public function deleted(Client $client): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Client "restored" event.
|
||||
*/
|
||||
public function restored(Client $client): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Client "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(Client $client): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user