forked from nathalie/pedi2
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class CreatePedidosView extends Migration
|
|
{
|
|
/**
|
|
* Run the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function up()
|
|
{
|
|
DB::statement("CREATE VIEW pedidos AS
|
|
SELECT
|
|
g.id as grupo_de_compra_id,
|
|
g.nombre as grupo_de_compra_nombre,
|
|
g.region as grupo_de_compra_region,
|
|
pr.id AS producto_id,
|
|
pr.nombre as producto_nombre,
|
|
pr.precio as producto_precio,
|
|
SUM(ps.cantidad) as cantidad_pedida,
|
|
pr.precio*SUM(ps.cantidad) as total_por_producto
|
|
FROM grupos_de_compra g
|
|
JOIN subpedidos s ON (s.grupo_de_compra_id = g.id)
|
|
JOIN producto_subpedido ps ON (ps.subpedido_id = s.id)
|
|
JOIN productos pr ON (pr.id = ps.producto_id)
|
|
GROUP BY g.id, g.nombre, pr.id, pr.nombre;"
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function down()
|
|
{
|
|
DB::statement("DROP VIEW pedidos");
|
|
}
|
|
}
|