up
This commit is contained in:
@@ -23,6 +23,7 @@ use Filament\Tables\Columns\{
|
||||
TextColumn,
|
||||
BadgeColumn
|
||||
};
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
||||
class ProcesoAcabadoResource extends Resource
|
||||
@@ -50,7 +51,7 @@ class ProcesoAcabadoResource extends Resource
|
||||
$tintoreriaRecords = \App\Models\Tintoreria::where('orden_produccion_id', $state)->get();
|
||||
$disponible = 0;
|
||||
foreach ($tintoreriaRecords as $tintoreria) {
|
||||
$recepciones = (int) $tintoreria->recepciones()->sum(\DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
|
||||
$recepciones = (int) $tintoreria->recepciones()->sum(DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
|
||||
$reprocesos = (int) $tintoreria->ajustes()->where('tipo', 'reproceso')->sum('cantidad');
|
||||
$cobros = (int) $tintoreria->cobros()->sum('cantidad');
|
||||
$disponible += ($recepciones - $reprocesos - $cobros);
|
||||
@@ -96,7 +97,7 @@ class ProcesoAcabadoResource extends Resource
|
||||
$tintoreriaRecords = \App\Models\Tintoreria::where('orden_produccion_id', $op_id)->get();
|
||||
$disponible = 0;
|
||||
foreach ($tintoreriaRecords as $tintoreria) {
|
||||
$recepciones = (int) $tintoreria->recepciones()->sum(\DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
|
||||
$recepciones = (int) $tintoreria->recepciones()->sum(DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
|
||||
$reprocesos = (int) $tintoreria->ajustes()->where('tipo', 'reproceso')->sum('cantidad');
|
||||
$cobros = (int) $tintoreria->cobros()->sum('cantidad');
|
||||
$disponible += ($recepciones - $reprocesos - $cobros);
|
||||
@@ -221,6 +222,22 @@ class ProcesoAcabadoResource extends Resource
|
||||
->label('Cantidad')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('cantidad_recibida_total')
|
||||
->label('Recibidas')
|
||||
->getStateUsing(fn ($record) => $record->recibido_total ?? 0)
|
||||
->badge()
|
||||
->color('success'),
|
||||
|
||||
TextColumn::make('estado_recepcion')
|
||||
->label('Estado Recepción')
|
||||
->getStateUsing(fn ($record) => $record->estado_recepcion ?? 'Sin envío')
|
||||
->badge()
|
||||
->color(fn ($state) => match($state) {
|
||||
'Completado' => 'success',
|
||||
'Parcial' => 'warning',
|
||||
default => 'gray',
|
||||
}),
|
||||
|
||||
TextColumn::make('proveedores_asignados')
|
||||
->label('Proveedores')
|
||||
->getStateUsing(function ($record) {
|
||||
@@ -282,7 +299,9 @@ class ProcesoAcabadoResource extends Resource
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
RelationManagers\RecepcionesRelationManager::class,
|
||||
RelationManagers\AjustesRelationManager::class,
|
||||
RelationManagers\CobrosRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProcesoAcabadoResource\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Actions\DeleteAction;
|
||||
use Filament\Tables\Actions\EditAction;
|
||||
use Filament\Tables\Actions\CreateAction;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AjustesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'ajustes';
|
||||
protected static ?string $recordTitleAttribute = 'id';
|
||||
protected static ?string $title = 'Reprocesos/Ajustes';
|
||||
|
||||
public function form(Forms\Form $form): Forms\Form
|
||||
{
|
||||
return $form->schema([
|
||||
Select::make('tipo')
|
||||
->label('Tipo de Ajuste')
|
||||
->options([
|
||||
'reproceso' => 'Reproceso (permite re-recepción)',
|
||||
'ajuste_entrada' => 'Ajuste de Entrada',
|
||||
'ajuste_salida' => 'Ajuste de Salida',
|
||||
])
|
||||
->required()
|
||||
->default('reproceso')
|
||||
->helperText('Los reprocesos permiten volver a recibir las prendas cuando regresen arregladas'),
|
||||
|
||||
TextInput::make('cantidad')
|
||||
->label('Cantidad')
|
||||
->numeric()
|
||||
->required()
|
||||
->minValue(1),
|
||||
|
||||
DateTimePicker::make('fecha')
|
||||
->label('Fecha del Ajuste')
|
||||
->required()
|
||||
->default(now()),
|
||||
|
||||
Textarea::make('notas')
|
||||
->label('Notas / Motivo')
|
||||
->rows(3)
|
||||
->maxLength(65535),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Tables\Table $table): Tables\Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('#')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('tipo')
|
||||
->label('Tipo')
|
||||
->badge()
|
||||
->color(fn ($state) => match($state) {
|
||||
'reproceso' => 'warning',
|
||||
'ajuste_entrada' => 'success',
|
||||
'ajuste_salida' => 'danger',
|
||||
default => 'gray',
|
||||
})
|
||||
->formatStateUsing(fn ($state) => match($state) {
|
||||
'reproceso' => 'Reproceso',
|
||||
'ajuste_entrada' => 'Ajuste Entrada',
|
||||
'ajuste_salida' => 'Ajuste Salida',
|
||||
default => $state,
|
||||
}),
|
||||
|
||||
TextColumn::make('cantidad')
|
||||
->label('Cantidad')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('fecha')
|
||||
->label('Fecha')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('usuario.name')
|
||||
->label('Usuario')
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('notas')
|
||||
->label('Notas')
|
||||
->limit(50)
|
||||
->wrap()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->label('Creado')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('fecha', 'desc')
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->label('Nuevo Ajuste')
|
||||
->icon('heroicon-o-plus-circle')
|
||||
->mutateFormDataUsing(function (array $data): array {
|
||||
$data['user_id'] = Auth::id();
|
||||
return $data;
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateHeading('Sin ajustes registrados')
|
||||
->emptyStateDescription('Los reprocesos permiten re-recepción de prendas que requieren corrección.')
|
||||
->emptyStateIcon('heroicon-o-arrow-path');
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProcesoAcabadoResource\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Tables\Actions\DeleteAction;
|
||||
use Filament\Tables\Actions\EditAction;
|
||||
use Filament\Tables\Actions\CreateAction;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CobrosRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'cobros';
|
||||
protected static ?string $recordTitleAttribute = 'id';
|
||||
protected static ?string $title = 'Cobros por Defectos';
|
||||
|
||||
public function form(Forms\Form $form): Forms\Form
|
||||
{
|
||||
return $form->schema([
|
||||
TextInput::make('cantidad')
|
||||
->label('Cantidad de Prendas')
|
||||
->numeric()
|
||||
->required()
|
||||
->minValue(1)
|
||||
->helperText('Cantidad de prendas con defectos que se cobrarán al proveedor'),
|
||||
|
||||
TextInput::make('valor')
|
||||
->label('Valor a Cobrar')
|
||||
->numeric()
|
||||
->required()
|
||||
->minValue(0)
|
||||
->prefix('$')
|
||||
->helperText('Monto total a descontar al proveedor'),
|
||||
|
||||
DateTimePicker::make('fecha')
|
||||
->label('Fecha del Cobro')
|
||||
->required()
|
||||
->default(now()),
|
||||
|
||||
Textarea::make('notas')
|
||||
->label('Motivo del Cobro')
|
||||
->rows(3)
|
||||
->maxLength(65535)
|
||||
->helperText('Describe los defectos encontrados'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Tables\Table $table): Tables\Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('#')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('cantidad')
|
||||
->label('Cantidad')
|
||||
->sortable()
|
||||
->badge()
|
||||
->color('danger'),
|
||||
|
||||
TextColumn::make('valor')
|
||||
->label('Valor')
|
||||
->money('COP')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('fecha')
|
||||
->label('Fecha')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('usuario.name')
|
||||
->label('Usuario')
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('notas')
|
||||
->label('Motivo')
|
||||
->limit(50)
|
||||
->wrap()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->label('Creado')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('fecha', 'desc')
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->label('Nuevo Cobro')
|
||||
->icon('heroicon-o-minus-circle')
|
||||
->mutateFormDataUsing(function (array $data): array {
|
||||
$data['user_id'] = Auth::id();
|
||||
return $data;
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateHeading('Sin cobros registrados')
|
||||
->emptyStateDescription('Registra cobros por prendas defectuosas que no pasarán a inventario.')
|
||||
->emptyStateIcon('heroicon-o-currency-dollar');
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProcesoAcabadoResource\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Tables\Actions\DeleteAction;
|
||||
use Filament\Tables\Actions\EditAction;
|
||||
use Filament\Tables\Actions\CreateAction;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RecepcionesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'recepciones';
|
||||
protected static ?string $recordTitleAttribute = 'id';
|
||||
protected static ?string $title = 'Recepciones de Acabados';
|
||||
|
||||
public function form(Forms\Form $form): Forms\Form
|
||||
{
|
||||
return $form->schema([
|
||||
DateTimePicker::make('fecha_recepcion')
|
||||
->label('Fecha de Recepción')
|
||||
->required()
|
||||
->default(now()),
|
||||
|
||||
TextInput::make('cantidad')
|
||||
->label('Cantidad Recibida')
|
||||
->numeric()
|
||||
->required()
|
||||
->minValue(1)
|
||||
->maxValue(fn () => $this->getOwnerRecord()?->faltantes ?? 0)
|
||||
->helperText(fn () => 'Disponible para recibir: ' . ($this->getOwnerRecord()?->faltantes ?? 0)),
|
||||
|
||||
TextInput::make('prendas_defectuosas')
|
||||
->label('Prendas Defectuosas')
|
||||
->numeric()
|
||||
->default(0)
|
||||
->minValue(0)
|
||||
->helperText('Si hay prendas defectuosas, regístralas aquí. Estas no pasarán al inventario.'),
|
||||
|
||||
Textarea::make('notas')
|
||||
->label('Notas / Observaciones')
|
||||
->rows(3)
|
||||
->maxLength(65535),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Tables\Table $table): Tables\Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('#')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('fecha_recepcion')
|
||||
->label('Fecha Recepción')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('cantidad')
|
||||
->label('Cantidad')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('prendas_defectuosas')
|
||||
->label('Defectuosas')
|
||||
->default(0)
|
||||
->badge()
|
||||
->color(fn ($state) => $state > 0 ? 'danger' : 'gray'),
|
||||
|
||||
TextColumn::make('cantidad_efectiva')
|
||||
->label('Cantidad Efectiva')
|
||||
->getStateUsing(fn ($record) => $record->cantidad - ($record->prendas_defectuosas ?? 0))
|
||||
->badge()
|
||||
->color('success'),
|
||||
|
||||
TextColumn::make('usuario.name')
|
||||
->label('Usuario')
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('notas')
|
||||
->label('Notas')
|
||||
->limit(50)
|
||||
->wrap()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->label('Creado')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('fecha_recepcion', 'desc')
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->label('Nueva Recepción')
|
||||
->icon('heroicon-o-plus-circle')
|
||||
->disabled(fn () => ($this->getOwnerRecord()?->faltantes ?? 0) <= 0)
|
||||
->mutateFormDataUsing(function (array $data): array {
|
||||
// Asignar usuario actual
|
||||
$data['user_id'] = Auth::id();
|
||||
return $data;
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateHeading('Sin recepciones registradas')
|
||||
->emptyStateDescription('Las recepciones quedarán disponibles automáticamente para el inventario de prendas.')
|
||||
->emptyStateIcon('heroicon-o-inbox-arrow-down');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user