ultimatepos/Modules/Accounting/Console/SeedIranianCoaCommand.php

40 lines
1.1 KiB
PHP

<?php
namespace Modules\Accounting\Console;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Modules\Accounting\Services\IranianChartOfAccountsService;
class SeedIranianCoaCommand extends Command
{
protected $signature = 'accounting:seed-iran-coa
{--business_id= : Business ID (defaults to all)}
{--force : Create even if gl_code already exists}';
protected $description = 'Seed Iranian-style chart of accounts skeleton for holding rollout';
public function handle(IranianChartOfAccountsService $service): int
{
$businessId = $this->option('business_id');
$skipExisting = ! $this->option('force');
$userId = 1;
$query = DB::table('business');
if ($businessId) {
$query->where('id', $businessId);
}
$total = 0;
foreach ($query->pluck('id') as $id) {
$created = $service->seed((int) $id, $userId, $skipExisting);
$this->info("Business {$id}: created {$created} GL account(s).");
$total += $created;
}
$this->info("Total new accounts: {$total}");
return self::SUCCESS;
}
}