Compare commits
No commits in common. "ccdba6efd41a79b3491064912c4e58f4a898d91e" and "129d52d6d6a5fb8595fbafe1fd57a7f9ddb746ab" have entirely different histories.
ccdba6efd4
...
129d52d6d6
4 changed files with 35 additions and 90 deletions
|
@ -1,62 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
|
|
||||||
class CrearPedidosAprobadosViewCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'view:CrearPedidosAprobadosView';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Crea view "pedidos_aprobados"';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
DB::statement("
|
|
||||||
CREATE OR REPLACE VIEW pedidos_aprobados
|
|
||||||
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 AND s.aprobado=1)
|
|
||||||
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
|
|
||||||
;");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,4 +6,35 @@ use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class PedidoController extends Controller
|
class PedidoController extends Controller
|
||||||
{
|
{
|
||||||
|
public static function generarTablas()
|
||||||
|
{
|
||||||
|
//GENERAR TABLA DE PEDIDOS APROBADOS
|
||||||
|
DB::unprepared("DROP VIEW if exists pedidos_aprobados;
|
||||||
|
CREATE VIEW pedidos_aprobados 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 AND s.aprobado=1)
|
||||||
|
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;");
|
||||||
|
|
||||||
|
//GENERAR TABLA GENERAL
|
||||||
|
DB::unprepared("DROP VIEW if exists productos_por_grupo_de_compra;
|
||||||
|
SET @barrios = NULL;
|
||||||
|
SELECT
|
||||||
|
GROUP_CONCAT(DISTINCT CONCAT('MAX(IF(`grupo_de_compra_nombre` = \"', `grupo_de_compra_nombre`,'\", `cantidad_pedida`,NULL)) AS \"',`grupo_de_compra_nombre`,'\"')) INTO @barrios
|
||||||
|
FROM pedidos_aprobados;
|
||||||
|
SET @sql = CONCAT('CREATE VIEW productos_por_grupo_de_compra AS SELECT producto_nombre, ', @barrios, ' FROM pedidos_aprobados GROUP BY producto_nombre');
|
||||||
|
PREPARE stmt FROM @sql;
|
||||||
|
EXECUTE stmt;");
|
||||||
|
return "Tabla productos_por_grupo_de_compra generada. " . date('l jS \of F Y h:i:s A');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
class CallCrearPedidosAprobados extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Artisan::call("view:CrearPedidosAprobadosView");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -34,6 +34,10 @@ Route::middleware('api')->group(function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::prefix('pedidos')->group(function () {
|
||||||
|
Route::get('/generar_tablas','Api\PedidoController@generarTablas');
|
||||||
|
});
|
||||||
|
|
||||||
Route::prefix('subpedidos')->group(function () {
|
Route::prefix('subpedidos')->group(function () {
|
||||||
Route::get('/','Api\SubpedidoController@index');
|
Route::get('/','Api\SubpedidoController@index');
|
||||||
Route::get('/resources', 'Api\SubpedidoController@indexResources');
|
Route::get('/resources', 'Api\SubpedidoController@indexResources');
|
||||||
|
|
Loading…
Add table
Reference in a new issue