update
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrdenProduccion extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'numero_orden',
|
||||
'prenda_modelo',
|
||||
'referencia',
|
||||
'cantidad_total',
|
||||
'tela_id',
|
||||
'fecha_inicio',
|
||||
'fecha_entrega_estimada',
|
||||
'estado',
|
||||
];
|
||||
|
||||
public function tela()
|
||||
{
|
||||
return $this->belongsTo(Tela::class);
|
||||
}
|
||||
|
||||
public function avanzarEstado(): void
|
||||
{
|
||||
$flujo = [
|
||||
'en_corte',
|
||||
'en_confeccion',
|
||||
'en_tintoreria',
|
||||
'en_acabados',
|
||||
'finalizada',
|
||||
];
|
||||
|
||||
$actual = array_search($this->estado, $flujo, true);
|
||||
|
||||
if ($actual !== false && isset($flujo[$actual + 1])) {
|
||||
$this->update([
|
||||
'estado' => $flujo[$actual + 1],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($orden) {
|
||||
if (!$orden->numero_orden) {
|
||||
$ultimoId = self::max('id') + 1;
|
||||
|
||||
$orden->numero_orden = 'OP-' . str_pad($ultimoId, 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user