diff --git a/app/Console/Commands/TaskLedgerGenerateCommand.php b/app/Console/Commands/TaskLedgerGenerateCommand.php index 84edba3..7c82a6d 100644 --- a/app/Console/Commands/TaskLedgerGenerateCommand.php +++ b/app/Console/Commands/TaskLedgerGenerateCommand.php @@ -42,8 +42,14 @@ class TaskLedgerGenerateCommand extends Command protected function generateTasks(Carbon $datetime): void { + $stores = Store::with(['master'])->get(); + + if ($stores->isEmpty()) { + return; + } + /** @var \App\Models\PlanLedger */ - $planable = DB::transaction(function () use ($datetime) { + $planable = DB::transaction(function () use ($datetime, $stores) { /** @var \App\Models\PlanLedger */ $planable = PlanLedger::firstOrNew([ 'date' => $datetime->format('Y-m-d'), @@ -63,8 +69,6 @@ class TaskLedgerGenerateCommand extends Command return $planable->setRelation('plan', $plan); }); - $stores = Store::with(['master'])->get(); - /** @var \App\Models\Store */ foreach ($stores as $store) { DB::transaction(function () use ($store, $planable) {