Update OjalPresillaResource.php
This commit is contained in:
@@ -37,8 +37,17 @@ class OjalPresillaResource extends Resource
|
||||
return \App\Models\OrdenProduccion::whereHas('confecciones', function ($q) {
|
||||
$q->where('cantidad_recibida', '>', 0);
|
||||
})->get()->mapWithKeys(function ($op) {
|
||||
// Calcular cantidad total de confecciones recibidas
|
||||
$cantidadConfecciones = $op->confecciones->sum('cantidad_recibida');
|
||||
// Calcular cantidad disponible desde confecciones (recibidas - arreglos - cobros)
|
||||
$cantidadRecibida = $op->confecciones->sum('cantidad_recibida');
|
||||
$arreglos = \App\Models\Ajuste::where('ajustable_type', \App\Models\Confeccion::class)
|
||||
->whereHas('ajustable', function($q) use ($op) {
|
||||
$q->where('orden_produccion_id', $op->id);
|
||||
})->where('tipo', 'arreglo')->sum('cantidad');
|
||||
$cobros = \App\Models\Cobro::where('cobreable_type', \App\Models\Confeccion::class)
|
||||
->whereHas('cobreable', function($q) use ($op) {
|
||||
$q->where('orden_produccion_id', $op->id);
|
||||
})->sum('cantidad');
|
||||
$cantidadConfecciones = $cantidadRecibida - $arreglos - $cobros;
|
||||
|
||||
// Calcular cantidad ya enviada en ojales
|
||||
$cantidadEnOjales = \App\Models\Ojal::where('orden_produccion_id', $op->id)
|
||||
@@ -61,8 +70,17 @@ class OjalPresillaResource extends Resource
|
||||
if ($state) {
|
||||
$op = \App\Models\OrdenProduccion::find($state);
|
||||
if ($op) {
|
||||
// Calcular cantidad disponible (confecciones - ojales ya enviados)
|
||||
$cantidadConfecciones = $op->confecciones->sum('cantidad_recibida');
|
||||
// Calcular cantidad disponible (confecciones - arreglos - cobros - ojales ya enviados)
|
||||
$cantidadRecibida = $op->confecciones->sum('cantidad_recibida');
|
||||
$arreglos = \App\Models\Ajuste::where('ajustable_type', \App\Models\Confeccion::class)
|
||||
->whereHas('ajustable', function($q) use ($state) {
|
||||
$q->where('orden_produccion_id', $state);
|
||||
})->where('tipo', 'arreglo')->sum('cantidad');
|
||||
$cobros = \App\Models\Cobro::where('cobreable_type', \App\Models\Confeccion::class)
|
||||
->whereHas('cobreable', function($q) use ($state) {
|
||||
$q->where('orden_produccion_id', $state);
|
||||
})->sum('cantidad');
|
||||
$cantidadConfecciones = $cantidadRecibida - $arreglos - $cobros;
|
||||
$cantidadEnOjales = \App\Models\Ojal::where('orden_produccion_id', $state)
|
||||
->sum('cantidad_enviada');
|
||||
$cantidadDisponible = $cantidadConfecciones - $cantidadEnOjales;
|
||||
|
||||
Reference in New Issue
Block a user