up
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user