up
This commit is contained in:
@@ -128,19 +128,21 @@ class ConfeccionResource extends Resource
|
||||
$cobrosValor = (float) $confeccion->cobros()->sum('valor');
|
||||
|
||||
$recibidoNeto = $recepciones - $arreglos;
|
||||
$faltantes = max(0, $enviada - $recibidoNeto);
|
||||
$disponibleSiguienteProceso = $recepciones - $arreglos - $cobros;
|
||||
$faltantes = max(0, $enviada - $recepciones + $arreglos);
|
||||
|
||||
$valorPorPrenda = (float) ($confeccion->valor_por_prenda ?? 0);
|
||||
$cantidadBase = $confeccion->cantidad_recibida ?? $enviada;
|
||||
$valorTotal = $cantidadBase * $valorPorPrenda;
|
||||
$valorAPagar = max(0, $valorTotal - $cobrosValor);
|
||||
|
||||
return "━━━ PRENDAS ━━━
|
||||
return "╯━━━ PRENDAS ━━━
|
||||
📦 Enviadas: {$enviada}
|
||||
|
||||
✅ Recibidas: {$recepciones}
|
||||
🔧 En arreglo: {$arreglos}
|
||||
📊 Neto recibido: {$recibidoNeto}
|
||||
👉 Disponible siguiente proceso: {$disponibleSiguienteProceso}
|
||||
|
||||
💰 Con problemas (cobradas): {$cobros} prendas
|
||||
⚠️ Pendientes: {$faltantes}
|
||||
|
||||
@@ -145,19 +145,21 @@ class TintoreriaResource extends Resource
|
||||
$cobrosValor = (float) $tintoreria->cobros()->sum('valor');
|
||||
|
||||
$recibidoNeto = $recepciones - $reprocesos;
|
||||
$faltantes = max(0, $enviada - $recibidoNeto);
|
||||
$disponibleSiguienteProceso = $recepciones - $reprocesos - $cobros;
|
||||
$faltantes = max(0, $enviada - $recepciones + $reprocesos);
|
||||
|
||||
$valorPorPrenda = (float) ($tintoreria->valor_por_prenda ?? 0);
|
||||
$cantidadBase = $tintoreria->cantidad_recibida ?? $enviada;
|
||||
$valorTotal = $cantidadBase * $valorPorPrenda;
|
||||
$valorAPagar = max(0, $valorTotal - $cobrosValor);
|
||||
|
||||
return "━━━ PRENDAS ━━━
|
||||
return "╯━━━ PRENDAS ━━━
|
||||
📦 Enviadas: {$enviada}
|
||||
|
||||
✅ Recibidas: {$recepciones}
|
||||
🔧 En reproceso: {$reprocesos}
|
||||
📊 Neto recibido: {$recibidoNeto}
|
||||
👉 Disponible siguiente proceso: {$disponibleSiguienteProceso}
|
||||
|
||||
💰 Con problemas (cobradas): {$cobros} prendas
|
||||
⚠️ Pendientes: {$faltantes}
|
||||
|
||||
@@ -97,12 +97,14 @@ class Confeccion extends Model
|
||||
}
|
||||
|
||||
// Total recibido calculado desde recepciones (fuente de la verdad)
|
||||
// Menos arreglos (permiten re-recepción) y menos cobros (no pasan al siguiente proceso)
|
||||
public function getRecibidoTotalAttribute()
|
||||
{
|
||||
$recepciones = (int) $this->recepciones()->sum(\DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
|
||||
$ajustes = (int) $this->ajustes()->where('tipo', 'arreglo')->sum('cantidad');
|
||||
$cobros = (int) $this->cobros()->sum('cantidad');
|
||||
|
||||
return max(0, $recepciones - $ajustes);
|
||||
return max(0, $recepciones - $ajustes - $cobros);
|
||||
}
|
||||
|
||||
// Cuantas faltan por recibir (NO considera cobros porque cobros son sobre prendas ya recibidas)
|
||||
@@ -197,30 +199,7 @@ class Confeccion extends Model
|
||||
]);
|
||||
}
|
||||
|
||||
// Descontar del inventario
|
||||
$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
|
||||
// Crear registro de cobro (no se descuenta inventario, solo ajuste de pago)
|
||||
$c = \App\Models\Cobro::create([
|
||||
'referencia_type' => self::class,
|
||||
'referencia_id' => $this->id,
|
||||
|
||||
@@ -154,30 +154,7 @@ class Tintoreria extends Model
|
||||
]);
|
||||
}
|
||||
|
||||
// Descontar del inventario
|
||||
$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
|
||||
// Crear registro de cobro (no se descuenta inventario, solo ajuste de pago)
|
||||
$c = \App\Models\Cobro::create([
|
||||
'referencia_type' => self::class,
|
||||
'referencia_id' => $this->id,
|
||||
@@ -210,13 +187,15 @@ class Tintoreria extends Model
|
||||
return $this->morphMany(\App\Models\Ajuste::class, 'referencia');
|
||||
}
|
||||
|
||||
// Total recibido calculado desde recepciones (fuente de la verdad) menos reprocesos
|
||||
// Total recibido calculado desde recepciones (fuente de la verdad)
|
||||
// Menos reprocesos (permiten re-recepción) y menos cobros (no pasan al siguiente proceso)
|
||||
public function getRecibidoTotalAttribute()
|
||||
{
|
||||
$recepciones = (int) $this->recepciones()->sum(\DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
|
||||
$reprocesos = (int) $this->ajustes()->where('tipo', 'reproceso')->sum('cantidad');
|
||||
$cobros = (int) $this->cobros()->sum('cantidad');
|
||||
|
||||
return max(0, $recepciones - $reprocesos);
|
||||
return max(0, $recepciones - $reprocesos - $cobros);
|
||||
}
|
||||
|
||||
// Total de pérdidas registradas en las recepciones
|
||||
|
||||
Reference in New Issue
Block a user