diff --git a/app/Console/Commands/GeneratePayrollCommand.php b/app/Console/Commands/GeneratePayrollCommand.php index da05cd3..6ee6597 100644 --- a/app/Console/Commands/GeneratePayrollCommand.php +++ b/app/Console/Commands/GeneratePayrollCommand.php @@ -42,6 +42,14 @@ public function handle() try { DB::transaction(function () use ($users, $periodMonth, &$count) { + $previousMonth = Carbon::parse($periodMonth)->subMonth()->format('Y-m'); + Payroll::where('period_month', $previousMonth) + ->where('is_paid', false) + ->update([ + 'is_paid' => true, + 'paid_at' => Carbon::now(), + ]); + foreach ($users as $user) { $exists = Payroll::where('user_id', $user->id) ->where('period_month', $periodMonth) diff --git a/routes/console.php b/routes/console.php index 3c9adf1..233a288 100644 --- a/routes/console.php +++ b/routes/console.php @@ -2,7 +2,10 @@ use Illuminate\Foundation\Inspiring; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Schedule; Artisan::command('inspire', function () { $this->comment(Inspiring::quote()); })->purpose('Display an inspiring quote'); + +Schedule::command('payroll:generate')->monthlyOn(1, '00:00');