This commit is contained in:
Lizandro Guarnizo
2026-01-28 23:38:21 -05:00
parent 861d507536
commit 622b99ecd5
50 changed files with 1646 additions and 19 deletions
@@ -188,6 +188,8 @@ class ConfeccionResource extends Resource
{
return [
RelationManagers\RecepcionesRelationManager::class,
RelationManagers\CobrosRelationManager::class,
RelationManagers\AjustesRelationManager::class,
];
}
@@ -72,6 +72,74 @@ class EditConfeccion extends EditRecord
// Refrescar la página para ver cambios (redirigir explicitando el record para evitar error de ruta)
$this->redirect(route('filament.admin.resources.confeccions.edit', ['record' => $record->id]));
}),
// Arreglos: restar cantidad del total recibido y crear traslado de reparaciones
Actions\Action::make('arreglos')
->label('Arreglos')
->modalHeading('Registrar Arreglo')
->form([
Forms\Components\TextInput::make('cantidad')
->label('Cantidad a arreglar')
->numeric()
->required()
->minValue(1)
->maxValue(fn () => $this->getRecord()->cantidad_recibida ?? 0)
->helperText(fn () => 'Máximo: ' . ($this->getRecord()->cantidad_recibida ?? 0)),
Forms\Components\Textarea::make('notas'),
])
->action(function (array $data): void {
$record = $this->getRecord();
$cantidad = (int) ($data['cantidad'] ?? 0);
try {
$record->registerArreglo($cantidad, $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Arreglo registrado')->body('Se registró el arreglo correctamente.')->send();
} catch (\Illuminate\Validation\ValidationException $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->validator->errors()->first() ?? 'Error al registrar arreglo.')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
$this->redirect(route('filament.admin.resources.confeccions.edit', ['record' => $record->id]));
}),
// Cobros: descontar inventario y descontar valor del total a pagar
Actions\Action::make('cobros')
->label('Cobros')
->modalHeading('Registrar Cobro')
->form([
Forms\Components\TextInput::make('cantidad')
->label('Cantidad')
->numeric()
->required()
->minValue(1),
Forms\Components\TextInput::make('valor')
->label('Valor a descontar')
->numeric()
->required()
->minValue(0),
Forms\Components\Textarea::make('notas'),
])
->action(function (array $data): void {
$record = $this->getRecord();
$cantidad = (int) ($data['cantidad'] ?? 0);
$valor = (float) ($data['valor'] ?? 0);
try {
$record->registerCobro($cantidad, $valor, $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Cobro registrado')->body('Se descontó del inventario y se aplicó el descuento al valor a pagar.')->send();
} catch (\Illuminate\Validation\ValidationException $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->validator->errors()->first() ?? 'Error al registrar cobro.')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
$this->redirect(route('filament.admin.resources.confeccions.edit', ['record' => $record->id]));
}),
];
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Filament\Resources\ConfeccionResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
class AjustesRelationManager extends RelationManager
{
protected static string $relationship = 'ajustes';
protected static ?string $recordTitleAttribute = 'id';
public function table(Tables\Table $table): Tables\Table
{
return $table
->columns([
TextColumn::make('id')->label('#'),
TextColumn::make('tipo')->label('Tipo'),
TextColumn::make('cantidad')->label('Cantidad'),
TextColumn::make('usuario.name')->label('Usuario'),
TextColumn::make('notas')->limit(80)->wrap(),
TextColumn::make('created_at')->label('Fecha')->dateTime(),
])
->filters([])
->headerActions([
Tables\Actions\CreateAction::make()->form([
\Filament\Forms\Components\TextInput::make('cantidad')->numeric()->required()->minValue(1),
\Filament\Forms\Components\Textarea::make('notas'),
])->action(function (array $data) {
$owner = $this->getOwnerRecord();
try {
$owner->registerArreglo((int)$data['cantidad'], $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Arreglo registrado')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
}),
])
->actions([])
->bulkActions([]);
}
}
@@ -0,0 +1,45 @@
<?php
namespace App\Filament\Resources\ConfeccionResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
class CobrosRelationManager extends RelationManager
{
protected static string $relationship = 'cobros';
protected static ?string $recordTitleAttribute = 'id';
public function table(Tables\Table $table): Tables\Table
{
return $table
->columns([
TextColumn::make('id')->label('#'),
TextColumn::make('cantidad')->label('Cantidad'),
TextColumn::make('valor')->label('Valor')->money('USD'),
TextColumn::make('usuario.name')->label('Usuario'),
TextColumn::make('notas')->limit(80)->wrap(),
TextColumn::make('created_at')->label('Fecha')->dateTime(),
])
->filters([])
->headerActions([
Tables\Actions\CreateAction::make()->form([
\Filament\Forms\Components\TextInput::make('cantidad')->numeric()->required()->minValue(1),
\Filament\Forms\Components\TextInput::make('valor')->numeric()->required()->minValue(0),
\Filament\Forms\Components\Textarea::make('notas'),
])->action(function (array $data) {
$owner = $this->getOwnerRecord();
try {
$owner->registerCobro((int)$data['cantidad'], (float)$data['valor'], $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Cobro registrado')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
}),
])
->actions([])
->bulkActions([]);
}
}
@@ -31,6 +31,7 @@ class RecepcionesRelationManager extends RelationManager
->helperText(fn () => 'Máximo: ' . ($this->getOwnerRecord()?->faltantes ?? 0)),
TextInput::make('prendas_defectuosas')
->label('Faltantes')
->numeric()
->minValue(0)
->maxValue(fn ($get) => (int) ($get('cantidad') ?? 0))
@@ -47,7 +48,7 @@ class RecepcionesRelationManager extends RelationManager
TextColumn::make('id')->label('#'),
TextColumn::make('fecha_recepcion')->dateTime()->label('Fecha'),
TextColumn::make('cantidad')->label('Cantidad'),
TextColumn::make('prendas_defectuosas')->label('Defectos'),
TextColumn::make('prendas_defectuosas')->label('Faltantes'),
TextColumn::make('usuario.name')->label('Usuario'),
TextColumn::make('notas')->limit(50)->wrap(),
TextColumn::make('created_at')->dateTime()->label('Creado'),
@@ -17,7 +17,8 @@ class DistribucionesRelationManager extends RelationManager
public function form(Form $form): Form
{
return $form->schema([
Forms\Components\Select::make('bodega_id')->relationship('bodega', 'nombre')->required(),
Forms\Components\Select::make('bodega_id')->relationship('bodega', 'nombre')->nullable(),
Forms\Components\Select::make('proveedor_id')->relationship('proveedor', 'nombre')->nullable()->helperText('Opcional: asignar a un proveedor/operario en vez de bodega'),
Forms\Components\Select::make('color_id')->relationship('color', 'name')->nullable(),
Forms\Components\Select::make('size_id')->relationship('size', 'name')->nullable(),
Forms\Components\TextInput::make('cantidad')
@@ -33,6 +34,7 @@ class DistribucionesRelationManager extends RelationManager
{
return $table->columns([
Tables\Columns\TextColumn::make('bodega.nombre')->label('Bodega'),
Tables\Columns\TextColumn::make('proveedor.nombre')->label('Proveedor'),
Tables\Columns\TextColumn::make('color.name')->label('Color'),
Tables\Columns\TextColumn::make('size.name')->label('Talla'),
Tables\Columns\TextColumn::make('cantidad'),
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\OjalResource\Pages;
use App\Models\Ojal;
use Filament\Forms;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\DatePicker;
class OjalResource extends Resource
{
protected static ?string $model = Ojal::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationGroup = 'Producción';
public static function form(Forms\Form $form): Forms\Form
{
return $form->schema([
Select::make('proveedor_id')->relationship('proveedor', 'nombre', fn($q) => $q->where('categoria', 'ojal'))->searchable()->preload()->nullable(),
Select::make('orden_produccion_id')->relationship('ordenProduccion', 'numero_orden')->searchable()->preload()->required(),
DatePicker::make('fecha_envio')->default(now()),
TextInput::make('cantidad_enviada')->numeric()->required()->minValue(1),
DatePicker::make('fecha_recepcion'),
TextInput::make('cantidad_recibida')->numeric()->nullable(),
TextInput::make('perdidas')->numeric()->default(0),
]);
}
public static function table(Tables\Table $table): Tables\Table
{
return $table->columns([
Tables\Columns\TextColumn::make('id')->label('#'),
Tables\Columns\TextColumn::make('proveedor.nombre')->label('Proveedor'),
Tables\Columns\TextColumn::make('ordenProduccion.numero_orden')->label('OP'),
Tables\Columns\TextColumn::make('cantidad_enviada'),
Tables\Columns\TextColumn::make('cantidad_recibida'),
Tables\Columns\TextColumn::make('perdidas'),
Tables\Columns\TextColumn::make('fecha_envio')->date(),
Tables\Columns\TextColumn::make('fecha_recepcion')->date(),
])->defaultSort('created_at', 'desc');
}
public static function getPages(): array
{
return [
'index' => Pages\ListOjales::route('/'),
'create' => Pages\CreateOjal::route('/create'),
'edit' => Pages\EditOjal::route('/{record}/edit'),
];
}
}
@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\OjalResource\Pages;
use App\Filament\Resources\OjalResource;
use Filament\Resources\Pages\CreateRecord;
class CreateOjal extends CreateRecord
{
protected static string $resource = OjalResource::class;
}
@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\OjalResource\Pages;
use App\Filament\Resources\OjalResource;
use Filament\Resources\Pages\EditRecord;
class EditOjal extends EditRecord
{
protected static string $resource = OjalResource::class;
}
@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\OjalResource\Pages;
use App\Filament\Resources\OjalResource;
use Filament\Resources\Pages\ListRecords;
class ListOjales extends ListRecords
{
protected static string $resource = OjalResource::class;
}
@@ -138,6 +138,16 @@ class OrdenProduccionResource extends Resource
TextColumn::make('cantidad_total')
->label('Cantidad'),
TextColumn::make('prensillas_count')
->label('Prensillas')
->counts('prensillas')
->sortable(),
TextColumn::make('ojales_count')
->label('Ojales')
->counts('ojales')
->sortable(),
TextColumn::make('realizado')
->label('Realizado')
->sortable(),
@@ -220,6 +230,8 @@ class OrdenProduccionResource extends Resource
{
return [
RelationManagers\TrasladosRelationManager::class,
RelationManagers\PrensillasRelationManager::class,
RelationManagers\OjalesRelationManager::class,
];
}
@@ -0,0 +1,41 @@
<?php
namespace App\Filament\Resources\OrdenProduccionResource\RelationManagers;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Forms;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Select;
class OjalesRelationManager extends RelationManager
{
protected static string $relationship = 'ojales';
protected static ?string $recordTitleAttribute = 'id';
public function form(Forms\Form $form): Forms\Form
{
return $form->schema([
Select::make('proveedor_id')->relationship('proveedor', 'nombre', fn($q) => $q->where('categoria', 'ojal'))->required(),
TextInput::make('cantidad_enviada')->numeric()->required()->minValue(1),
TextInput::make('cantidad_recibida')->numeric()->nullable(),
]);
}
public function table(Tables\Table $table): Tables\Table
{
return $table->columns([
Tables\Columns\TextColumn::make('id')->label('#'),
Tables\Columns\TextColumn::make('proveedor.nombre')->label('Proveedor'),
Tables\Columns\TextColumn::make('cantidad_enviada'),
Tables\Columns\TextColumn::make('cantidad_recibida'),
Tables\Columns\TextColumn::make('created_at')->label('Creado')->dateTime(),
])->headerActions([
Tables\Actions\CreateAction::make(),
])->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
]);
}
}
@@ -0,0 +1,41 @@
<?php
namespace App\Filament\Resources\OrdenProduccionResource\RelationManagers;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Forms;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Select;
class PrensillasRelationManager extends RelationManager
{
protected static string $relationship = 'prensillas';
protected static ?string $recordTitleAttribute = 'id';
public function form(Forms\Form $form): Forms\Form
{
return $form->schema([
Select::make('proveedor_id')->relationship('proveedor', 'nombre', fn($q) => $q->where('categoria', 'prensilla'))->required(),
TextInput::make('cantidad_enviada')->numeric()->required()->minValue(1),
TextInput::make('cantidad_recibida')->numeric()->nullable(),
]);
}
public function table(Tables\Table $table): Tables\Table
{
return $table->columns([
Tables\Columns\TextColumn::make('id')->label('#'),
Tables\Columns\TextColumn::make('proveedor.nombre')->label('Proveedor'),
Tables\Columns\TextColumn::make('cantidad_enviada'),
Tables\Columns\TextColumn::make('cantidad_recibida'),
Tables\Columns\TextColumn::make('created_at')->label('Creado')->dateTime(),
])->headerActions([
Tables\Actions\CreateAction::make(),
])->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
]);
}
}
@@ -46,7 +46,7 @@ class TrasladosRelationManager extends RelationManager
TextColumn::make('destino'),
TextColumn::make('cantidad_enviada'),
TextColumn::make('cantidad_recibida'),
TextColumn::make('prendas_defectuosas'),
TextColumn::make('prendas_defectuosas')->label('Faltantes'),
TextColumn::make('reparaciones'),
TextColumn::make('saldos'),
TextColumn::make('residual'),
@@ -0,0 +1,55 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\PrensillaResource\Pages;
use App\Models\Prensilla;
use Filament\Forms;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\DatePicker;
class PrensillaResource extends Resource
{
protected static ?string $model = Prensilla::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationGroup = 'Producción';
public static function form(Forms\Form $form): Forms\Form
{
return $form->schema([
Select::make('proveedor_id')->relationship('proveedor', 'nombre', fn($q) => $q->where('categoria', 'prensilla'))->searchable()->preload()->nullable(),
Select::make('orden_produccion_id')->relationship('ordenProduccion', 'numero_orden')->searchable()->preload()->required(),
DatePicker::make('fecha_envio')->default(now()),
TextInput::make('cantidad_enviada')->numeric()->required()->minValue(1),
DatePicker::make('fecha_recepcion'),
TextInput::make('cantidad_recibida')->numeric()->nullable(),
TextInput::make('perdidas')->numeric()->default(0),
]);
}
public static function table(Tables\Table $table): Tables\Table
{
return $table->columns([
Tables\Columns\TextColumn::make('id')->label('#'),
Tables\Columns\TextColumn::make('proveedor.nombre')->label('Proveedor'),
Tables\Columns\TextColumn::make('ordenProduccion.numero_orden')->label('OP'),
Tables\Columns\TextColumn::make('cantidad_enviada'),
Tables\Columns\TextColumn::make('cantidad_recibida'),
Tables\Columns\TextColumn::make('perdidas'),
Tables\Columns\TextColumn::make('fecha_envio')->date(),
Tables\Columns\TextColumn::make('fecha_recepcion')->date(),
])->defaultSort('created_at', 'desc');
}
public static function getPages(): array
{
return [
'index' => Pages\ListPrensillas::route('/'),
'create' => Pages\CreatePrensilla::route('/create'),
'edit' => Pages\EditPrensilla::route('/{record}/edit'),
];
}
}
@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\PrensillaResource\Pages;
use App\Filament\Resources\PrensillaResource;
use Filament\Resources\Pages\CreateRecord;
class CreatePrensilla extends CreateRecord
{
protected static string $resource = PrensillaResource::class;
}
@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\PrensillaResource\Pages;
use App\Filament\Resources\PrensillaResource;
use Filament\Resources\Pages\EditRecord;
class EditPrensilla extends EditRecord
{
protected static string $resource = PrensillaResource::class;
}
@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\PrensillaResource\Pages;
use App\Filament\Resources\PrensillaResource;
use Filament\Resources\Pages\ListRecords;
class ListPrensillas extends ListRecords
{
protected static string $resource = PrensillaResource::class;
}
@@ -41,6 +41,8 @@ class ProveedorResource extends Resource
'tintoreria' => 'Tintorería',
'talleres' => 'Talleres',
'telas' => 'Telas',
'prensilla' => 'Prensilla',
'ojal' => 'Ojal',
'otros' => 'Otros',
])
->required(),
@@ -70,6 +72,8 @@ class ProveedorResource extends Resource
'primary' => 'tintoreria',
'success' => 'talleres',
'warning' => 'telas',
'info' => 'prensilla',
'secondary' => 'ojal',
'gray' => 'otros',
])
->sortable(),
@@ -189,6 +189,8 @@ class TintoreriaResource extends Resource
{
return [
RelationManagers\RecepcionesRelationManager::class,
RelationManagers\CobrosRelationManager::class,
RelationManagers\AjustesRelationManager::class,
];
}
@@ -71,6 +71,74 @@ class EditTintoreria extends EditRecord
// Refrescar la página para ver cambios
$this->redirect(route('filament.admin.resources.tintorerias.edit', ['record' => $record->id]));
}),
// Reprocesos: registrar reproceso como ajuste
Actions\Action::make('reprocesos')
->label('Reprocesos')
->modalHeading('Registrar Reproceso')
->form([
Forms\Components\TextInput::make('cantidad')
->label('Cantidad a reprocesar')
->numeric()
->required()
->minValue(1)
->maxValue(fn () => $this->getRecord()->recibido_total ?? 0)
->helperText(fn () => 'Máximo: ' . ($this->getRecord()->recibido_total ?? 0)),
Forms\Components\Textarea::make('notas'),
])
->action(function (array $data): void {
$record = $this->getRecord();
$cantidad = (int) ($data['cantidad'] ?? 0);
try {
$record->registerReproceso($cantidad, $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Reproceso registrado')->body('Se registró el reproceso correctamente.')->send();
} catch (\Illuminate\Validation\ValidationException $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->validator->errors()->first() ?? 'Error al registrar reproceso.')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
$this->redirect(route('filament.admin.resources.tintorerias.edit', ['record' => $record->id]));
}),
// Cobros: descontar inventario y registrar cobro
Actions\Action::make('cobros')
->label('Cobros')
->modalHeading('Registrar Cobro')
->form([
Forms\Components\TextInput::make('cantidad')
->label('Cantidad')
->numeric()
->required()
->minValue(1),
Forms\Components\TextInput::make('valor')
->label('Valor a descontar')
->numeric()
->required()
->minValue(0),
Forms\Components\Textarea::make('notas'),
])
->action(function (array $data): void {
$record = $this->getRecord();
$cantidad = (int) ($data['cantidad'] ?? 0);
$valor = (float) ($data['valor'] ?? 0);
try {
$record->registerCobro($cantidad, $valor, $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Cobro registrado')->body('Se descontó del inventario y se registró el cobro.')->send();
} catch (\Illuminate\Validation\ValidationException $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->validator->errors()->first() ?? 'Error al registrar cobro.')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
$this->redirect(route('filament.admin.resources.tintorerias.edit', ['record' => $record->id]));
}),
];
}
}
@@ -0,0 +1,43 @@
<?php
namespace App\Filament\Resources\TintoreriaResource\RelationManagers;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
class AjustesRelationManager extends RelationManager
{
protected static string $relationship = 'ajustes';
protected static ?string $recordTitleAttribute = 'id';
public function table(Tables\Table $table): Tables\Table
{
return $table
->columns([
TextColumn::make('id')->label('#'),
TextColumn::make('tipo')->label('Tipo'),
TextColumn::make('cantidad')->label('Cantidad'),
TextColumn::make('usuario.name')->label('Usuario'),
TextColumn::make('notas')->limit(80)->wrap(),
TextColumn::make('created_at')->label('Fecha')->dateTime(),
])
->filters([])
->headerActions([
Tables\Actions\CreateAction::make()->form([
\Filament\Forms\Components\TextInput::make('cantidad')->numeric()->required()->minValue(1),
\Filament\Forms\Components\Textarea::make('notas'),
])->action(function (array $data) {
$owner = $this->getOwnerRecord();
try {
$owner->registerReproceso((int)$data['cantidad'], $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Reproceso registrado')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
}),
])
->actions([])
->bulkActions([]);
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Filament\Resources\TintoreriaResource\RelationManagers;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
class CobrosRelationManager extends RelationManager
{
protected static string $relationship = 'cobros';
protected static ?string $recordTitleAttribute = 'id';
public function table(Tables\Table $table): Tables\Table
{
return $table
->columns([
TextColumn::make('id')->label('#'),
TextColumn::make('cantidad')->label('Cantidad'),
TextColumn::make('valor')->label('Valor')->money('USD'),
TextColumn::make('usuario.name')->label('Usuario'),
TextColumn::make('notas')->limit(80)->wrap(),
TextColumn::make('created_at')->label('Fecha')->dateTime(),
])
->filters([])
->headerActions([
Tables\Actions\CreateAction::make()->form([
\Filament\Forms\Components\TextInput::make('cantidad')->numeric()->required()->minValue(1),
\Filament\Forms\Components\TextInput::make('valor')->numeric()->required()->minValue(0),
\Filament\Forms\Components\Textarea::make('notas'),
])->action(function (array $data) {
$owner = $this->getOwnerRecord();
try {
$owner->registerCobro((int)$data['cantidad'], (float)$data['valor'], $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Cobro registrado')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
}),
])
->actions([])
->bulkActions([]);
}
}
@@ -31,6 +31,7 @@ class RecepcionesRelationManager extends RelationManager
->helperText(fn () => 'Máximo: ' . ($this->getOwnerRecord()?->faltantes ?? 0)),
TextInput::make('prendas_defectuosas')
->label('Faltantes')
->numeric()
->minValue(0)
->maxValue(fn ($get) => (int) ($get('cantidad') ?? 0))
@@ -47,7 +48,7 @@ class RecepcionesRelationManager extends RelationManager
TextColumn::make('id')->label('#'),
TextColumn::make('fecha_recepcion')->dateTime()->label('Fecha'),
TextColumn::make('cantidad')->label('Cantidad'),
TextColumn::make('prendas_defectuosas')->label('Defectos'),
TextColumn::make('prendas_defectuosas')->label('Faltantes'),
TextColumn::make('usuario.name')->label('Usuario'),
TextColumn::make('notas')->limit(50)->wrap(),
TextColumn::make('created_at')->dateTime()->label('Creado'),
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Ajuste extends Model
{
protected $fillable = [
'referencia_type',
'referencia_id',
'user_id',
'tipo',
'cantidad',
'notas',
];
public function referencia()
{
return $this->morphTo();
}
public function usuario()
{
return $this->belongsTo(User::class, 'user_id');
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Cobro extends Model
{
protected $fillable = [
'referencia_type',
'referencia_id',
'user_id',
'cantidad',
'valor',
'notas',
];
public function referencia()
{
return $this->morphTo();
}
public function usuario()
{
return $this->belongsTo(User::class, 'user_id');
}
}
+124 -3
View File
@@ -17,8 +17,19 @@ class Confeccion extends Model
'valor_por_prenda',
'total_pagar',
'estado',
'descuentos_cobros',
];
public function cobros()
{
return $this->morphMany(\App\Models\Cobro::class, 'referencia');
}
public function ajustes()
{
return $this->morphMany(\App\Models\Ajuste::class, 'referencia');
}
/* Relaciones */
public function proveedor()
{
@@ -52,7 +63,14 @@ class Confeccion extends Model
// Total a pagar: usa cantidad_recibida si existe, sino cantidad_enviada
$cantidadBase = $confeccion->cantidad_recibida ?? $confeccion->cantidad_enviada ?? 0;
$valorUnitario = $confeccion->valor_por_prenda ?? 0;
$confeccion->total_pagar = $cantidadBase * $valorUnitario;
// Aplicar descuentos de cobros si existen (se guarda también en descuentos_cobros para compatibilidad)
$descuentos = (float) ($confeccion->getCobrosTotalAttribute() ?? 0);
$confeccion->total_pagar = max(0, ($cantidadBase * $valorUnitario) - $descuentos);
// Mantener campo redundante 'descuentos_cobros' sincronizado
$confeccion->descuentos_cobros = $descuentos;
// Estado automático
if (! $confeccion->cantidad_recibida) {
@@ -81,12 +99,115 @@ class Confeccion extends Model
// Total recibido calculado desde recepciones (fuente de la verdad)
public function getRecibidoTotalAttribute()
{
return (int) $this->recepciones()->sum(\DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
$recepciones = (int) $this->recepciones()->sum(\DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
$ajustes = (int) $this->ajustes()->where('tipo', 'arreglo')->sum('cantidad');
return max(0, $recepciones - $ajustes);
}
// Cuantas faltan por recibir (usa la suma real de recepciones)
// Cuantas faltan por recibir (usa la suma real de recepciones menos ajustes)
public function getFaltantesAttribute()
{
return max(0, (int)($this->cantidad_enviada ?? 0) - $this->recibido_total);
}
// Total de cobros aplicados
public function getCobrosTotalAttribute()
{
return (float) $this->cobros()->sum('valor');
}
/**
* Registrar un arreglo como ajuste histórico y crear traslado de reparaciones
*/
public function registerArreglo(int $cantidad, ?string $notas = null, ?int $userId = null)
{
if ($cantidad <= 0) {
throw \Illuminate\Validation\ValidationException::withMessages(['cantidad' => 'La cantidad debe ser mayor que 0.']);
}
$recibido = $this->recibido_total;
if ($cantidad > $recibido) {
throw \Illuminate\Validation\ValidationException::withMessages(['cantidad' => 'La cantidad supera lo recibido.']);
}
// Crear ajuste
$aj = \App\Models\Ajuste::create([
'referencia_type' => self::class,
'referencia_id' => $this->id,
'user_id' => $userId,
'tipo' => 'arreglo',
'cantidad' => $cantidad,
'notas' => $notas,
]);
// Crear traslado de reparaciones para reflejar la salida
\App\Models\TrasladoPrenda::create([
'orden_produccion_id' => $this->orden_produccion_id,
'referencia_type' => self::class,
'referencia_id' => $this->id,
'origen' => 'confeccion',
'destino' => 'reparaciones',
'cantidad_enviada' => $cantidad,
'cantidad_recibida' => 0,
'prendas_defectuosas' => 0,
'reparaciones' => $cantidad,
'fecha_envio' => now(),
'fecha_recepcion' => now(),
'estado' => 'recibido',
]);
// Recalcular cantidad_recibida almacenada para compatibilidad con UI
$this->cantidad_recibida = $this->recibido_total;
$this->save();
return $aj;
}
/**
* Registrar un cobro: descontar inventario y crear registro de cobro
*/
public function registerCobro(int $cantidad, float $valor, ?string $notas = null, ?int $userId = null)
{
if ($cantidad <= 0) {
throw \Illuminate\Validation\ValidationException::withMessages(['cantidad' => 'La cantidad debe ser mayor que 0.']);
}
// Buscar inventario disponible
$inventario = \App\Models\InventarioPrenda::where('orden_produccion_id', $this->orden_produccion_id)
->where('cantidad_disponible', '>=', $cantidad)
->first();
if (! $inventario) {
throw \Illuminate\Validation\ValidationException::withMessages(['cantidad' => 'No hay inventario disponible suficiente para descontar.']);
}
// Descontar del inventario
$inventario->cantidad_disponible = $inventario->cantidad_disponible - $cantidad;
$inventario->save();
// Si está asociado a producto, decrementar stock
if ($inventario->producto_id) {
$producto = \App\Models\Producto::find($inventario->producto_id);
if ($producto) {
$producto->decrement('stock', $cantidad);
}
}
// Crear registro de cobro
$c = \App\Models\Cobro::create([
'referencia_type' => self::class,
'referencia_id' => $this->id,
'user_id' => $userId,
'cantidad' => $cantidad,
'valor' => $valor,
'notas' => $notas,
]);
// Mantener campo redundante sincronizado
$this->descuentos_cobros = $this->getCobrosTotalAttribute();
$this->save();
return $c;
}
}
+1
View File
@@ -153,6 +153,7 @@ class InventarioPrenda extends Model
'precio_venta' => 0,
'unidad_medida' => 'unidad',
'codigo_barras' => $codigo,
'categoria_id' => \App\Models\Categoria::first()?->id ?? \App\Models\Categoria::create(['nombre' => 'Generica'])->id,
]);
});
}
+52 -4
View File
@@ -14,6 +14,7 @@ class InventarioPrendaDistribucion extends Model
protected $fillable = [
'inventario_prenda_id',
'bodega_id',
'proveedor_id',
'color_id',
'size_id',
'cantidad',
@@ -52,8 +53,8 @@ class InventarioPrendaDistribucion extends Model
$cantidad = intval($dist->cantidad ?? 0);
$sumExistentes = (int) self::where('inventario_prenda_id', $parentId)->sum('cantidad');
// Validar contra la cantidad disponible actual
if (($sumExistentes + $cantidad) > (int) $parent->cantidad_disponible) {
// Validar contra la cantidad terminada total (no distribuir más del total entregado)
if (($sumExistentes + $cantidad) > (int) $parent->cantidad_terminada) {
throw \Illuminate\Validation\ValidationException::withMessages([
'cantidad' => 'No se puede añadir más prendas que las disponibles.',
]);
@@ -72,8 +73,8 @@ class InventarioPrendaDistribucion extends Model
->where('id', '<>', $dist->id)
->sum('cantidad');
// Validar contra la cantidad disponible actual (considerando otras distribuciones)
if (($othersSum + $newCantidad) > (int) $parent->cantidad_disponible) {
// Validar contra la cantidad terminada total (no distribuir más del total entregado)
if (($othersSum + $newCantidad) > (int) $parent->cantidad_terminada) {
throw \Illuminate\Validation\ValidationException::withMessages([
'cantidad' => 'No se puede añadir más prendas que las disponibles.',
]);
@@ -87,6 +88,18 @@ class InventarioPrendaDistribucion extends Model
$bodegaId = $dist->bodega_id;
// If a proveedor_id is present, treat as assignment to a provider/person (no warehouse stock changes)
if ($dist->proveedor_id && ! $bodegaId) {
// Just decrement disponibilidad on parent
$parent = $dist->inventarioPrenda;
if ($parent) {
$parent->cantidad_disponible = max(0, $parent->cantidad_disponible - $cantidad);
$parent->save();
}
return;
}
if ($dist->color_id && $dist->size_id) {
// Variante
// Determinar producto: preferir inventario.prenda.producto_id -> op.producto_id
@@ -158,6 +171,41 @@ class InventarioPrendaDistribucion extends Model
} else {
// Producto
$productoId = $dist->inventarioPrenda->producto_id ?? ($dist->inventarioPrenda->ordenProduccion->producto_id ?? null);
// Si no existe producto, intentar crear/inferrir desde la Orden de Producción
if (! $productoId && $dist->inventarioPrenda && $dist->inventarioPrenda->ordenProduccion) {
$op = $dist->inventarioPrenda->ordenProduccion;
$nombre = $op->prenda_modelo ?? $op->referencia ?? ('Producto OP #' . $op->id);
$codigo = 'AUTOP-' . $op->id . '-' . time();
$codigo = substr($codigo, 0, 50);
while (\App\Models\Producto::where('codigo_barras', $codigo)->exists()) {
$codigo .= '-' . rand(0, 9);
$codigo = substr($codigo, 0, 50);
}
$producto = \App\Models\Producto::create([
'nombre' => $nombre,
'descripcion' => 'Creado automáticamente desde distribución (OP #' . $op->id . ')',
'stock' => 0,
'estado' => true,
'precio_compra' => 0,
'precio_venta' => 0,
'unidad_medida' => 'unidad',
'codigo_barras' => $codigo,
'categoria_id' => \App\Models\Categoria::first()?->id ?? \App\Models\Categoria::create(['nombre' => 'Generica'])->id,
]);
$productoId = $producto->id;
// Guardar producto en el inventario padre para futuras referencias
$parent = $dist->inventarioPrenda;
if ($parent && ! $parent->producto_id) {
$parent->producto_id = $productoId;
$parent->save();
}
}
if ($productoId) {
$existing = \DB::table('producto_bodega')->where('producto_id', $productoId)->where('bodega_id', $bodegaId)->first();
if ($existing) {
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Ojal extends Model
{
protected $table = 'ojales';
protected $fillable = [
'proveedor_id',
'orden_produccion_id',
'fecha_envio',
'cantidad_enviada',
'fecha_recepcion',
'cantidad_recibida',
'perdidas',
];
public function proveedor()
{
return $this->belongsTo(Proveedor::class);
}
public function ordenProduccion()
{
return $this->belongsTo(OrdenProduccion::class);
}
protected static function booted()
{
static::creating(function ($p) {
// Validar disponibilidad desde confecciones
$opId = $p->orden_produccion_id;
$totalProducido = \App\Models\Confeccion::where('orden_produccion_id', $opId)->sum('cantidad_recibida');
$yaAsignado = \App\Models\Prensilla::where('orden_produccion_id', $opId)->sum('cantidad_enviada')
+ \App\Models\Ojal::where('orden_produccion_id', $opId)->sum('cantidad_enviada');
if (($yaAsignado + ($p->cantidad_enviada ?? 0)) > $totalProducido) {
throw \Illuminate\Validation\ValidationException::withMessages(['cantidad_enviada' => 'No hay suficientes unidades disponibles desde confecciones para asignar.']);
}
});
}
}
+10
View File
@@ -53,6 +53,16 @@ class OrdenProduccion extends Model
return $this->hasMany(\App\Models\Tintoreria::class);
}
public function prensillas()
{
return $this->hasMany(\App\Models\Prensilla::class);
}
public function ojales()
{
return $this->hasMany(\App\Models\Ojal::class);
}
public function procesosAcabado()
{
return $this->hasMany(\App\Models\ProcesoAcabado::class);
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Prensilla extends Model
{
protected $fillable = [
'proveedor_id',
'orden_produccion_id',
'fecha_envio',
'cantidad_enviada',
'fecha_recepcion',
'cantidad_recibida',
'perdidas',
];
public function proveedor()
{
return $this->belongsTo(Proveedor::class);
}
public function ordenProduccion()
{
return $this->belongsTo(OrdenProduccion::class);
}
protected static function booted()
{
static::creating(function ($p) {
// Validar disponibilidad desde confecciones
$opId = $p->orden_produccion_id;
$totalProducido = \App\Models\Confeccion::where('orden_produccion_id', $opId)->sum('cantidad_recibida');
$yaAsignado = \App\Models\Prensilla::where('orden_produccion_id', $opId)->sum('cantidad_enviada')
+ \App\Models\Ojal::where('orden_produccion_id', $opId)->sum('cantidad_enviada');
if (($yaAsignado + ($p->cantidad_enviada ?? 0)) > $totalProducido) {
throw \Illuminate\Validation\ValidationException::withMessages(['cantidad_enviada' => 'No hay suficientes unidades disponibles desde confecciones para asignar.']);
}
});
}
}
+115 -2
View File
@@ -63,16 +63,124 @@ class Tintoreria extends Model
});
}
/**
* Registrar un reproceso: crear ajuste histórico y traslado de reproceso
*/
public function registerReproceso(int $cantidad, ?string $notas = null, ?int $userId = null)
{
if ($cantidad <= 0) {
throw \Illuminate\Validation\ValidationException::withMessages(['cantidad' => 'La cantidad debe ser mayor que 0.']);
}
$recibido = $this->recibido_total;
if ($cantidad > $recibido) {
throw \Illuminate\Validation\ValidationException::withMessages(['cantidad' => 'La cantidad supera lo recibido.']);
}
// Crear ajuste de tipo reproceso
$aj = \App\Models\Ajuste::create([
'referencia_type' => self::class,
'referencia_id' => $this->id,
'user_id' => $userId,
'tipo' => 'reproceso',
'cantidad' => $cantidad,
'notas' => $notas,
]);
// Crear traslado de reprocesos para reflejar la operación
\App\Models\TrasladoPrenda::create([
'orden_produccion_id' => $this->orden_produccion_id,
'referencia_type' => self::class,
'referencia_id' => $this->id,
'origen' => 'tintoreria',
'destino' => 'reprocesos',
'cantidad_enviada' => $cantidad,
'cantidad_recibida' => 0,
'prendas_defectuosas' => 0,
'reparaciones' => 0,
'saldos' => 0,
'fecha_envio' => now(),
'fecha_recepcion' => now(),
'estado' => 'recibido',
]);
// Recalcular cantidad_recibida almacenada para compatibilidad con UI
$this->cantidad_recibida = $this->recibido_total;
$this->save();
return $aj;
}
/**
* Registrar un cobro: descontar inventario y crear registro de cobro
*/
public function registerCobro(int $cantidad, float $valor, ?string $notas = null, ?int $userId = null)
{
if ($cantidad <= 0) {
throw \Illuminate\Validation\ValidationException::withMessages(['cantidad' => 'La cantidad debe ser mayor que 0.']);
}
// Buscar inventario disponible
$inventario = \App\Models\InventarioPrenda::where('orden_produccion_id', $this->orden_produccion_id)
->where('cantidad_disponible', '>=', $cantidad)
->first();
if (! $inventario) {
throw \Illuminate\Validation\ValidationException::withMessages(['cantidad' => 'No hay inventario disponible suficiente para descontar.']);
}
// Descontar del inventario
$inventario->cantidad_disponible = $inventario->cantidad_disponible - $cantidad;
$inventario->save();
// Si está asociado a producto, decrementar stock
if ($inventario->producto_id) {
$producto = \App\Models\Producto::find($inventario->producto_id);
if ($producto) {
$producto->decrement('stock', $cantidad);
}
}
// Crear registro de cobro
$c = \App\Models\Cobro::create([
'referencia_type' => self::class,
'referencia_id' => $this->id,
'user_id' => $userId,
'cantidad' => $cantidad,
'valor' => $valor,
'notas' => $notas,
]);
// Mantener campo redundante sincronizado
$this->descuentos_cobros = $this->getCobrosTotalAttribute();
$this->save();
return $c;
}
/* Recepciones polimórficas */
public function recepciones()
{
return $this->morphMany(\App\Models\Recepcion::class, 'referencia');
}
// Total recibido calculado desde recepciones (fuente de la verdad)
public function cobros()
{
return $this->morphMany(\App\Models\Cobro::class, 'referencia');
}
public function ajustes()
{
return $this->morphMany(\App\Models\Ajuste::class, 'referencia');
}
// Total recibido calculado desde recepciones (fuente de la verdad) menos reprocesos
public function getRecibidoTotalAttribute()
{
return (int) $this->recepciones()->sum(\DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
$recepciones = (int) $this->recepciones()->sum(\DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
$reprocesos = (int) $this->ajustes()->where('tipo', 'reproceso')->sum('cantidad');
return max(0, $recepciones - $reprocesos);
}
// Total de pérdidas registradas en las recepciones
@@ -81,6 +189,11 @@ class Tintoreria extends Model
return (int) $this->recepciones()->sum('prendas_defectuosas');
}
public function getCobrosTotalAttribute()
{
return (float) $this->cobros()->sum('valor');
}
// Cuantas faltan por recibir (usa la suma real de recepciones)
public function getFaltantesAttribute()
{
@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('confeccions', function (Blueprint $table) {
if (! Schema::hasColumn('confeccions', 'descuentos_cobros')) {
$table->decimal('descuentos_cobros', 12, 2)->default(0)->after('total_pagar');
}
});
}
public function down()
{
Schema::table('confeccions', function (Blueprint $table) {
if (Schema::hasColumn('confeccions', 'descuentos_cobros')) {
$table->dropColumn('descuentos_cobros');
}
});
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('cobros', function (Blueprint $table) {
$table->id();
$table->string('referencia_type');
$table->unsignedBigInteger('referencia_id');
$table->unsignedBigInteger('user_id')->nullable();
$table->integer('cantidad')->default(0);
$table->decimal('valor', 12, 2)->default(0);
$table->text('notas')->nullable();
$table->timestamps();
$table->index(['referencia_type', 'referencia_id']);
});
}
public function down()
{
Schema::dropIfExists('cobros');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('ajustes', function (Blueprint $table) {
$table->id();
$table->string('referencia_type');
$table->unsignedBigInteger('referencia_id');
$table->unsignedBigInteger('user_id')->nullable();
$table->string('tipo')->default('arreglo');
$table->integer('cantidad')->default(0);
$table->text('notas')->nullable();
$table->timestamps();
$table->index(['referencia_type', 'referencia_id']);
});
}
public function down()
{
Schema::dropIfExists('ajustes');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('prensillas', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('proveedor_id')->nullable();
$table->unsignedBigInteger('orden_produccion_id');
$table->date('fecha_envio')->nullable();
$table->integer('cantidad_enviada')->default(0);
$table->date('fecha_recepcion')->nullable();
$table->integer('cantidad_recibida')->nullable();
$table->integer('perdidas')->default(0);
$table->timestamps();
$table->foreign('proveedor_id')->references('id')->on('proveedors')->onDelete('set null');
$table->foreign('orden_produccion_id')->references('id')->on('orden_produccions')->onDelete('cascade');
});
}
public function down()
{
Schema::dropIfExists('prensillas');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('ojales', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('proveedor_id')->nullable();
$table->unsignedBigInteger('orden_produccion_id');
$table->date('fecha_envio')->nullable();
$table->integer('cantidad_enviada')->default(0);
$table->date('fecha_recepcion')->nullable();
$table->integer('cantidad_recibida')->nullable();
$table->integer('perdidas')->default(0);
$table->timestamps();
$table->foreign('proveedor_id')->references('id')->on('proveedors')->onDelete('set null');
$table->foreign('orden_produccion_id')->references('id')->on('orden_produccions')->onDelete('cascade');
});
}
public function down()
{
Schema::dropIfExists('ojales');
}
};
@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('tintorerias', function (Blueprint $table) {
if (! Schema::hasColumn('tintorerias', 'descuentos_cobros')) {
$table->decimal('descuentos_cobros', 12, 2)->default(0)->after('perdidas');
}
});
}
public function down()
{
Schema::table('tintorerias', function (Blueprint $table) {
if (Schema::hasColumn('tintorerias', 'descuentos_cobros')) {
$table->dropColumn('descuentos_cobros');
}
});
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('inventario_prenda_distribuciones', function (Blueprint $table) {
if (! Schema::hasColumn('inventario_prenda_distribuciones', 'proveedor_id')) {
$table->unsignedBigInteger('proveedor_id')->nullable()->after('bodega_id');
$table->foreign('proveedor_id')->references('id')->on('proveedors')->onDelete('set null');
}
});
}
public function down()
{
Schema::table('inventario_prenda_distribuciones', function (Blueprint $table) {
if (Schema::hasColumn('inventario_prenda_distribuciones', 'proveedor_id')) {
$table->dropForeign(['proveedor_id']);
$table->dropColumn('proveedor_id');
}
});
}
};
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('inventario_prenda_distribuciones', function (Blueprint $table) {
// Drop existing foreign key then make the column nullable and re-add foreign key
$table->dropForeign(['bodega_id']);
$table->unsignedBigInteger('bodega_id')->nullable()->change();
$table->foreign('bodega_id')->references('id')->on('bodegas')->nullOnDelete();
});
}
public function down(): void
{
Schema::table('inventario_prenda_distribuciones', function (Blueprint $table) {
$table->dropForeign(['bodega_id']);
$table->unsignedBigInteger('bodega_id')->nullable(false)->change();
$table->foreign('bodega_id')->references('id')->on('bodegas')->cascadeOnDelete();
});
}
};
@@ -11,7 +11,7 @@ if ($op) {
'tipo' => 'Confección',
'id' => $c->id,
'fecha' => $c->fecha_envio ?? $c->created_at,
'detalle' => "Enviado: {$c->cantidad_enviada} - Recibido total: {$c->recibido_total} - Defectos: {$c->prendas_defectuosas}",
'detalle' => "Enviado: {$c->cantidad_enviada} - Recibido total: {$c->recibido_total} - Faltantes: {$c->prendas_defectuosas}",
'link' => route('filament.admin.resources.confeccions.edit', ['record' => $c->id]),
];
@@ -148,7 +148,7 @@ if ($op) {
<input type="number" name="cantidad_recibida" value="{{ $tr->cantidad_recibida ?? '' }}" class="mt-1 block w-full rounded border-gray-300" />
</div>
<div>
<label class="block text-sm">Prendas defectuosas</label>
<label class="block text-sm">Faltantes</label>
<input type="number" name="prendas_defectuosas" value="{{ $tr->prendas_defectuosas ?? 0 }}" class="mt-1 block w-full rounded border-gray-300" />
</div>
<div>
+133
View File
@@ -0,0 +1,133 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Models\Confeccion;
use App\Models\Proveedor;
use App\Models\OrdenProduccion;
use App\Models\Recepcion;
use App\Models\TrasladoPrenda;
use App\Models\InventarioPrenda;
use App\Models\Producto;
use App\Models\Cobro;
use App\Models\Ajuste;
class ConfeccionActionsTest extends TestCase
{
use RefreshDatabase;
public function test_register_arreglo_creates_ajuste_and_traslado_and_affects_recibido()
{
$proveedor = Proveedor::create(['nombre' => 'Prov Test', 'nit' => '000', 'categoria' => 'talleres']);
$op = OrdenProduccion::create(['prenda_modelo' => 'Test', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
$conf = Confeccion::create([
'proveedor_id' => $proveedor->id,
'orden_produccion_id' => $op->id,
'cantidad_enviada' => 100,
'valor_por_prenda' => 0,
]);
// Registrar recepciones para tener recibido
Recepcion::create(['referencia_type' => Confeccion::class, 'referencia_id' => $conf->id, 'cantidad' => 50]);
Recepcion::create(['referencia_type' => Confeccion::class, 'referencia_id' => $conf->id, 'cantidad' => 30]);
$conf->refresh();
$this->assertEquals(80, $conf->recibido_total);
// Registrar arreglo 10
$conf->registerArreglo(10, 'Arreglo prueba');
$this->assertDatabaseHas('ajustes', [
'referencia_type' => Confeccion::class,
'referencia_id' => $conf->id,
'tipo' => 'arreglo',
'cantidad' => 10,
]);
$this->assertDatabaseHas('traslados_prenda', [
'referencia_type' => Confeccion::class,
'referencia_id' => $conf->id,
'origen' => 'confeccion',
'destino' => 'reparaciones',
'reparaciones' => 10,
]);
$conf->refresh();
$this->assertEquals(70, $conf->recibido_total);
$this->assertEquals(30, $conf->faltantes);
}
public function test_register_cobro_creates_cobro_and_adjusts_inventory_and_total_pagar()
{
$proveedor = Proveedor::create(['nombre' => 'Prov Test', 'nit' => '000', 'categoria' => 'talleres']);
$op = OrdenProduccion::create(['prenda_modelo' => 'Test', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
$conf = Confeccion::create([
'proveedor_id' => $proveedor->id,
'orden_produccion_id' => $op->id,
'cantidad_enviada' => 50,
'cantidad_recibida' => 50,
'valor_por_prenda' => 100,
]);
// Crear proceso de acabado que aporta cantidad recibida para permitir inventario
\App\Models\ProcesoAcabado::create([
'orden_produccion_id' => $op->id,
'tipo_proceso' => 'Acabado',
'proveedor_id' => $proveedor->id,
'cantidad_enviada' => 20,
'fecha_envio' => now(),
'fecha_recepcion' => now(),
'cantidad_recibida' => 20,
]);
// Crear producto y proceso de acabado que aporta cantidad recibida para permitir inventario
$categoria = \App\Models\Categoria::create(['nombre' => 'Ropa']);
$producto = Producto::create(['nombre' => 'Prod', 'descripcion' => 'x', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => 'X', 'categoria_id' => $categoria->id, 'imagen' => '']);
\App\Models\ProcesoAcabado::create([
'orden_produccion_id' => $op->id,
'tipo_proceso' => 'Acabado',
'proveedor_id' => $proveedor->id,
'cantidad_enviada' => 20,
'fecha_envio' => now(),
'fecha_recepcion' => now(),
'cantidad_recibida' => 20,
]);
// Crear inventario con cantidad disponible y asociar producto
$inv = InventarioPrenda::create([
'orden_produccion_id' => $op->id,
'cantidad_terminada' => 20,
'cantidad_disponible' => 20,
'fecha_ingreso' => now(),
'estado' => 'en_bodega',
'producto_id' => $producto->id,
]);
$conf->refresh();
$this->assertEquals(5000, $conf->total_pagar); // 50 * 100
// Registrar cobro: cantidad 5, valor 200
$conf->registerCobro(5, 200, 'Cobro prueba');
$this->assertDatabaseHas('cobros', [
'referencia_type' => Confeccion::class,
'referencia_id' => $conf->id,
'cantidad' => 5,
'valor' => 200,
]);
$inv->refresh();
$this->assertEquals(15, $inv->cantidad_disponible);
$producto->refresh();
$this->assertEquals(15, $producto->stock);
$conf->refresh();
$this->assertEquals(4800, $conf->total_pagar); // 5000 - 200
}
}
@@ -27,6 +27,8 @@ class InventarioDistribucionTest extends TestCase
$producto = Producto::create(['nombre' => 'Camiseta', 'descripcion' => '', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => '', 'categoria_id' => $categoria->id, 'imagen' => '']);
$op = OrdenProduccion::create(['numero_orden' => 'OP-0001', 'prenda_modelo' => 'Camiseta', 'referencia' => 'C-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $producto->id]);
// Crear distribución
@@ -61,6 +63,8 @@ class InventarioDistribucionTest extends TestCase
$op = OrdenProduccion::create(['numero_orden' => 'OP-0100', 'prenda_modelo' => 'PrendaX', 'referencia' => 'PX-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => null]);
// Crear distribución sin producto previo
@@ -93,6 +97,8 @@ class InventarioDistribucionTest extends TestCase
$op = OrdenProduccion::create(['numero_orden' => 'OP-0200', 'prenda_modelo' => 'Doblez', 'referencia' => 'D-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
// Crear inventario: esto incrementa el stock global del producto en +5
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $producto->id]);
$producto->refresh();
@@ -122,6 +128,8 @@ class InventarioDistribucionTest extends TestCase
$op = OrdenProduccion::create(['numero_orden' => 'OP-0002', 'prenda_modelo' => 'Polo', 'referencia' => 'P-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
$data = [
'orden_produccion_id' => $op->id,
'cantidad_terminada' => 5,
@@ -151,6 +159,8 @@ class InventarioDistribucionTest extends TestCase
$op = OrdenProduccion::create(['numero_orden' => 'OP-0003', 'prenda_modelo' => 'Camisa', 'referencia' => 'C-02', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $producto->id]);
// Crear primera distribución 2
@@ -177,6 +187,8 @@ class InventarioDistribucionTest extends TestCase
$op = OrdenProduccion::create(['numero_orden' => 'OP-0004', 'prenda_modelo' => 'Saco', 'referencia' => 'S-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $producto->id]);
// Crear dos distribuciones 2 y 2
@@ -198,5 +210,72 @@ class InventarioDistribucionTest extends TestCase
$d1->cantidad = 4;
$d1->save();
}
public function test_distribution_to_providers_decreases_disponible_and_does_not_create_bodega_stock()
{
$categoria = \App\Models\Categoria::create(['nombre' => 'Ropa']);
$producto = Producto::create(['nombre' => 'Equipo', 'descripcion' => '', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => '', 'categoria_id' => $categoria->id, 'imagen' => '']);
$op = OrdenProduccion::create(['numero_orden' => 'OP-1000', 'prenda_modelo' => 'Equipo', 'referencia' => 'E-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 10, 'fecha_recepcion' => now()]);
// La creación del ProcesoAcabado puede crear automáticamente el inventario al finalizar la OP.
$inv = \App\Models\InventarioPrenda::where('orden_produccion_id', $op->id)->first();
$this->assertNotNull($inv);
$p1 = \App\Models\Proveedor::create(['nombre' => 'Proveedor 1']);
$p2 = \App\Models\Proveedor::create(['nombre' => 'Proveedor 2']);
// Crear distribuciones a proveedores
InventarioPrendaDistribucion::create([
'inventario_prenda_id' => $inv->id,
'proveedor_id' => $p1->id,
'cantidad' => 4,
]);
InventarioPrendaDistribucion::create([
'inventario_prenda_id' => $inv->id,
'proveedor_id' => $p2->id,
'cantidad' => 5,
]);
// No deben crearse filas en producto_bodega / variante_bodega
$this->assertEquals(0, \DB::table('producto_bodega')->count());
$this->assertEquals(0, \DB::table('variante_bodega')->count());
$inv->refresh();
$this->assertEquals(1, $inv->cantidad_disponible);
}
public function test_provider_distributions_exceeding_throws_validation_exception()
{
$categoria = \App\Models\Categoria::create(['nombre' => 'Ropa']);
$producto = Producto::create(['nombre' => 'Surtido', 'descripcion' => '', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => '', 'categoria_id' => $categoria->id, 'imagen' => '']);
$op = OrdenProduccion::create(['numero_orden' => 'OP-2000', 'prenda_modelo' => 'Surtido', 'referencia' => 'S-02', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $producto->id]);
$p = \App\Models\Proveedor::create(['nombre' => 'Proveedor X']);
// Primera distribución 3
InventarioPrendaDistribucion::create([
'inventario_prenda_id' => $inv->id,
'proveedor_id' => $p->id,
'cantidad' => 3,
]);
$this->expectException(\Illuminate\Validation\ValidationException::class);
// Intentar crear 3 nuevamente => 3 + 3 = 6 > 5
InventarioPrendaDistribucion::create([
'inventario_prenda_id' => $inv->id,
'proveedor_id' => $p->id,
'cantidad' => 3,
]);
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Models\Proveedor;
use App\Models\OrdenProduccion;
use App\Models\Confeccion;
use App\Models\Prensilla;
use App\Models\Ojal;
use App\Models\Recepcion;
class PrensillaOjalTest extends TestCase
{
use RefreshDatabase;
public function test_cannot_assign_more_than_available_from_confecciones()
{
$prov = Proveedor::create(['nombre' => 'P', 'nit' => '00', 'categoria' => 'prensilla']);
$prov2 = Proveedor::create(['nombre' => 'O', 'nit' => '01', 'categoria' => 'ojal']);
$op = OrdenProduccion::create(['prenda_modelo' => 'X', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
// Crear confecciones y recepciones para generar 50 unidades
$conf = Confeccion::create(['proveedor_id' => $prov->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 50, 'valor_por_prenda' => 0]);
Recepcion::create(['referencia_type' => Confeccion::class, 'referencia_id' => $conf->id, 'cantidad' => 50]);
$this->assertEquals(50, $conf->recibido_total);
// Asignar 30 a prensilla y 20 a ojal => OK
Prensilla::create(['proveedor_id' => $prov->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 30]);
Ojal::create(['proveedor_id' => $prov2->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 20]);
$this->assertDatabaseHas('prensillas', ['orden_produccion_id' => $op->id, 'cantidad_enviada' => 30]);
$this->assertDatabaseHas('ojales', ['orden_produccion_id' => $op->id, 'cantidad_enviada' => 20]);
// Ahora intentar asignar 1 adicional en prensilla debe fallar (excede 50)
$this->expectException(\Illuminate\Validation\ValidationException::class);
Prensilla::create(['proveedor_id' => $prov->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 1]);
}
}
+1 -1
View File
@@ -57,7 +57,7 @@ class RecepcionFlowTest extends TestCase
$this->assertEquals(2, $count);
// Crear recepción con defectos y comprobar traslado creado
// Crear recepción con faltantes y comprobar traslado creado
Recepcion::create([
'referencia_type' => Confeccion::class,
'referencia_id' => $conf->id,
@@ -38,7 +38,7 @@ class RecepcionTintoreriaFlowTest extends TestCase
$this->assertEquals(30, $tint->recibido_total);
$this->assertEquals(20, $tint->faltantes);
// Recepción con perdidas 25 y 5 defectuosas
// Recepción con perdidas 25 y 5 faltantes
Recepcion::create([
'referencia_type' => Tintoreria::class,
'referencia_id' => $tint->id,
+118
View File
@@ -0,0 +1,118 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Models\Tintoreria;
use App\Models\Proveedor;
use App\Models\OrdenProduccion;
use App\Models\Recepcion;
use App\Models\TrasladoPrenda;
use App\Models\InventarioPrenda;
use App\Models\Producto;
use App\Models\Cobro;
use App\Models\Ajuste;
class TintoreriaActionsTest extends TestCase
{
use RefreshDatabase;
public function test_register_reproceso_creates_ajuste_and_traslado_and_affects_recibido()
{
$proveedor = Proveedor::create(['nombre' => 'Prov T', 'nit' => '000', 'categoria' => 'tintoreria']);
$op = OrdenProduccion::create(['prenda_modelo' => 'X', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
$tint = Tintoreria::create([
'proveedor_id' => $proveedor->id,
'orden_produccion_id' => $op->id,
'tipo_proceso' => 'Tinte',
'cantidad_enviada' => 50,
]);
// Registrar recepciones para tener recibido
Recepcion::create(['referencia_type' => Tintoreria::class, 'referencia_id' => $tint->id, 'cantidad' => 40]);
Recepcion::create(['referencia_type' => Tintoreria::class, 'referencia_id' => $tint->id, 'cantidad' => 5]);
$tint->refresh();
$this->assertEquals(45, $tint->recibido_total);
// Registrar reproceso 10
$tint->registerReproceso(10, 'Reproceso prueba');
$this->assertDatabaseHas('ajustes', [
'referencia_type' => Tintoreria::class,
'referencia_id' => $tint->id,
'tipo' => 'reproceso',
'cantidad' => 10,
]);
$this->assertDatabaseHas('traslados_prenda', [
'referencia_type' => Tintoreria::class,
'referencia_id' => $tint->id,
'origen' => 'tintoreria',
'destino' => 'reprocesos',
'cantidad_enviada' => 10,
]);
$tint->refresh();
$this->assertEquals(35, $tint->recibido_total);
}
public function test_register_cobro_creates_cobro_and_adjusts_inventory()
{
$proveedor = Proveedor::create(['nombre' => 'Prov T', 'nit' => '000', 'categoria' => 'tintoreria']);
$op = OrdenProduccion::create(['prenda_modelo' => 'X', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
$tint = Tintoreria::create([
'proveedor_id' => $proveedor->id,
'orden_produccion_id' => $op->id,
'tipo_proceso' => 'Tinte',
'cantidad_enviada' => 20,
'cantidad_recibida' => 20,
]);
// Crear producto y proceso de acabado que aporta cantidad recibida para permitir inventario
$categoria = \App\Models\Categoria::create(['nombre' => 'Ropa']);
$producto = Producto::create(['nombre' => 'Prod', 'descripcion' => 'x', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => 'X', 'categoria_id' => $categoria->id, 'imagen' => '']);
\App\Models\ProcesoAcabado::create([
'orden_produccion_id' => $op->id,
'tipo_proceso' => 'Acabado',
'proveedor_id' => $proveedor->id,
'cantidad_enviada' => 10,
'fecha_envio' => now(),
'fecha_recepcion' => now(),
'cantidad_recibida' => 10,
]);
// Crear inventario con cantidad disponible y asociar producto
$inv = InventarioPrenda::create([
'orden_produccion_id' => $op->id,
'cantidad_terminada' => 10,
'cantidad_disponible' => 10,
'fecha_ingreso' => now(),
'estado' => 'en_bodega',
'producto_id' => $producto->id,
]);
// Registrar cobro: cantidad 5, valor 100
$tint->registerCobro(5, 100, 'Cobro tintoreria');
$this->assertDatabaseHas('cobros', [
'referencia_type' => Tintoreria::class,
'referencia_id' => $tint->id,
'cantidad' => 5,
'valor' => 100,
]);
$inv->refresh();
$this->assertEquals(5, $inv->cantidad_disponible);
$producto->refresh();
$this->assertEquals(5, $producto->stock);
$tint->refresh();
$this->assertEquals(100, $tint->descuentos_cobros); // 100 applied
}
}
+1 -1
View File
@@ -35,7 +35,7 @@ class TrasladoFlowTest extends TestCase
'categoria' => 'talleres',
]);
// Paso 1: Confección - envía 100, llegan 95, 2 defectuosas
// Paso 1: Confección - envía 100, llegan 95, 2 faltantes
$conf = Confeccion::create([
'proveedor_id' => $proveedor->id,
'orden_produccion_id' => $op->id,
+1 -1
View File
@@ -25,7 +25,7 @@ class ConfeccionRecepcionesTest extends TestCase
'cantidad_enviada' => 100,
]);
// Crear recepciones 40 y 40 con defectos en la segunda (10)
// Crear recepciones 40 y 40 con faltantes en la segunda (10)
Recepcion::create(['referencia_type' => Confeccion::class,'referencia_id' => $conf->id,'cantidad' => 40]);
Recepcion::create(['referencia_type' => Confeccion::class,'referencia_id' => $conf->id,'cantidad' => 40, 'prendas_defectuosas' => 10]);