From 4208c3bbf4e3546981570ecec3bf8942ed8dcc60 Mon Sep 17 00:00:00 2001 From: lizandrogd <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 19 Jan 2026 21:51:23 -0500 Subject: [PATCH] up --- app/Filament/Resources/TelaResource.php | 6 ++--- app/Models/Tela.php | 22 ++++++++++++++++ ...ge_valor_and_costo_to_decimal_on_telas.php | 25 +++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2026_01_20_060000_change_valor_and_costo_to_decimal_on_telas.php diff --git a/app/Filament/Resources/TelaResource.php b/app/Filament/Resources/TelaResource.php index c66001b..b729af3 100644 --- a/app/Filament/Resources/TelaResource.php +++ b/app/Filament/Resources/TelaResource.php @@ -59,18 +59,18 @@ class TelaResource extends Resource } }), - TextInput::make('valor_total')->numeric()->required()->prefix('$')->live(onBlur: true) + TextInput::make('valor_total')->numeric()->required()->prefix('$')->step(0.01)->live(onBlur: true) ->afterStateUpdated(function ($state, Forms\Set $set, $get) { $metros_comprados = $get('metros_comprados'); $valor_total = $state; if ($metros_comprados && $valor_total) { $costo_por_metro = $valor_total / $metros_comprados; - $set('costo_por_metro', $costo_por_metro); + $set('costo_por_metro', round($costo_por_metro, 2)); } }), - TextInput::make('costo_por_metro')->numeric()->prefix('$')->readOnly()->dehydrated()->default(0), + TextInput::make('costo_por_metro')->numeric()->prefix('$')->readOnly()->dehydrated()->default(0)->step(0.01), TextInput::make('metros_disponibles')->numeric()->reactive()->disabled()->dehydrated() ->default(function ($get) { diff --git a/app/Models/Tela.php b/app/Models/Tela.php index b009cae..b02c1d8 100644 --- a/app/Models/Tela.php +++ b/app/Models/Tela.php @@ -22,6 +22,8 @@ class Tela extends Model protected $casts = [ 'foto' => 'string', + 'valor_total' => 'decimal:2', + 'costo_por_metro' => 'decimal:2', ]; public function proveedor() @@ -33,4 +35,24 @@ class Tela extends Model { return $this->hasMany(OrdenProduccion::class); } + + protected static function booted() + { + static::saving(function ($tela) { + // Protección temporal: si la columna en la BD aún es integer, convertir a entero + try { + $type = \Illuminate\Support\Facades\Schema::getColumnType('telas', 'costo_por_metro'); + if ($type === 'integer') { + $tela->costo_por_metro = (int) round($tela->costo_por_metro ?? 0); + } + + $typeVal = \Illuminate\Support\Facades\Schema::getColumnType('telas', 'valor_total'); + if ($typeVal === 'integer') { + $tela->valor_total = (int) round($tela->valor_total ?? 0); + } + } catch (\Exception $e) { + // Ignorar si no se puede determinar el tipo de columna (por ejemplo en pruebas antes de migraciones) + } + }); + } } diff --git a/database/migrations/2026_01_20_060000_change_valor_and_costo_to_decimal_on_telas.php b/database/migrations/2026_01_20_060000_change_valor_and_costo_to_decimal_on_telas.php new file mode 100644 index 0000000..ab25e96 --- /dev/null +++ b/database/migrations/2026_01_20_060000_change_valor_and_costo_to_decimal_on_telas.php @@ -0,0 +1,25 @@ +decimal('valor_total', 12, 2)->change(); + $table->decimal('costo_por_metro', 12, 2)->change(); + }); + } + + public function down(): void + { + Schema::table('telas', function (Blueprint $table) { + $table->integer('valor_total')->change(); + $table->integer('costo_por_metro')->change(); + }); + } +}; \ No newline at end of file