Creado PedidoOllasResource

This commit is contained in:
Alejandro Tasistro 2025-06-23 21:15:30 -03:00
parent 0e42cf2c14
commit d86d52a478
2 changed files with 35 additions and 1 deletions

View file

@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use App\TipoPedido;
use Illuminate\Http\Resources\Json\JsonResource;
class PedidoOllasResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request): array
{
$productos = $this->productos;
foreach ($productos as $producto) {
$producto['pivot']['total'] = number_format($producto->pivot->cantidad * $producto->precio, 2);
}
return [
'id' => $this->id,
'nombre' => $this->nombre,
'productos' => $productos,
'total' => number_format($this->totalCentralesSinTransporte(),2),
'cantidad_de_ollas' => $this->cantidad_ollas,
];
}
}

View file

@ -65,7 +65,11 @@ class Subpedido extends Model
public function totalCentral()
{
return $this->totalCentralesQueNoPaganTransporte() + $this->totalCentralesQuePaganTransporte() + $this->totalTransporte();
return $this->totalCentralesSinTransporte() + $this->totalTransporte();
}
public function totalCentralesSinTransporte() {
return $this->totalCentralesQueNoPaganTransporte() + $this->totalCentralesQuePaganTransporte();
}
public function totalCentralesQueNoPaganTransporte()