feat: Add monthly stock opname generation schedule.

This commit is contained in:
Yoga Pangestu 2025-12-17 04:39:43 +07:00
parent 2978d34e9e
commit bbd62a6a50
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,37 @@
<?php
namespace App\Console\Commands;
use App\Enums\StockOpnameStatus;
use App\Models\StockOpname;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class SetStockOpnameToProcess extends Command
{
protected $signature = 'stock-opname:set-to-process';
protected $description = 'Change stock opname status to Process on the 25th';
public function handle()
{
$periodMonth = now()->format('Y-m');
$stockOpnames = StockOpname::where('period_month', $periodMonth)->get();
if ($stockOpnames->isEmpty()) {
$this->info("Tidak ada stock opname untuk bulan {$periodMonth}.");
return;
}
DB::transaction(function () use ($stockOpnames) {
foreach ($stockOpnames as $stockOpname) {
$stockOpname->status = StockOpnameStatus::PROCESS;
$stockOpname->save();
}
});
$this->info("Status stock opname untuk bulan {$periodMonth} berhasil diubah menjadi Proses.");
}
}

View File

@ -3,3 +3,5 @@
use Illuminate\Support\Facades\Schedule;
Schedule::command('payroll:generate --current')->monthly();
Schedule::command('stock-opname:generate')->monthly();
Schedule::command('stock-opname:set-to-process')->monthlyOn(25, '00:00');