feat: updates

This commit is contained in:
JP
2024-08-11 20:03:49 +08:00
parent 140e821e0c
commit 52431a2c61
45 changed files with 1152 additions and 287 deletions

View 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
{
//
}
}

View 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
{
//
}
}

View 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
{
//
}
}