34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\ReplenishmentQueue;
|
|
use Illuminate\Console\Command;
|
|
|
|
class ReplenishmentTick extends Command
|
|
{
|
|
protected $signature = 'sgc:replenishment-tick {--limit= : Máximo de artigos/armazéns por execução}';
|
|
|
|
protected $description = 'Recuperar reposições pendentes e reavaliar mínimos e validade, sem aprovar compras';
|
|
|
|
public function handle(ReplenishmentQueue $queue): int
|
|
{
|
|
if (! $queue->ready()) {
|
|
$this->warn('Reposição durável não instalada nesta composição.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
$limit = $this->option('limit') ?? config('replenishment.batch_size');
|
|
if (! filter_var($limit, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 500]])) {
|
|
$this->error('Limite entre 1 e 500.');
|
|
|
|
return self::INVALID;
|
|
}
|
|
$queue->discover();
|
|
$result = $queue->drain((int) $limit);
|
|
$this->info('Reposição: '.$result['processed'].' trabalhos conferidos; '.$result['failed'].' a recuperar.');
|
|
|
|
return $result['failed'] === 0 ? self::SUCCESS : self::FAILURE;
|
|
}
|
|
}
|