Move the logic for generating base accounts for a new client from the ClientObserver into a dedicated command class (GenerateBaseAccountCommand). This improves code organization and reusability. - The command is now used in the ClientObserver::created method. - The command is also made available as a manual action in the AccountsRelationManager table header, allowing admins to generate base accounts for existing clients that lack them. - Added necessary imports to the CreateSale page, though the command is not directly used there in this diff, suggesting preparatory work for future integration.
65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Commands\Clients;
|
|
|
|
use App\Commands\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class GenerateBaseAccountCommand
|
|
{
|
|
/**
|
|
* Create a new class instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Execute the command.
|
|
*/
|
|
public function execute($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',
|
|
],
|
|
]);
|
|
});
|
|
}
|
|
|
|
}
|