feat: Add monthly stock opname generation schedule.
This commit is contained in:
parent
2978d34e9e
commit
bbd62a6a50
37
app/Console/Commands/SetStockOpnameToProcess.php
Normal file
37
app/Console/Commands/SetStockOpnameToProcess.php
Normal 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.");
|
||||
}
|
||||
}
|
||||
@ -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');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user