Creado PedidoOllasResource
This commit is contained in:
parent
0e42cf2c14
commit
d86d52a478
2 changed files with 35 additions and 1 deletions
30
app/Http/Resources/PedidoOllasResource.php
Normal file
30
app/Http/Resources/PedidoOllasResource.php
Normal 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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -65,7 +65,11 @@ class Subpedido extends Model
|
||||||
|
|
||||||
public function totalCentral()
|
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()
|
public function totalCentralesQueNoPaganTransporte()
|
||||||
|
|
Loading…
Add table
Reference in a new issue