Agregado producto_es_bono a PedidosAprobados
This commit is contained in:
parent
d526b944bd
commit
2df7f6fc4b
2 changed files with 99 additions and 0 deletions
72
app/Console/Commands/AgregarEsBonoAPedidosAprobados.php
Normal file
72
app/Console/Commands/AgregarEsBonoAPedidosAprobados.php
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class AgregarEsBonoAPedidosAprobados extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'command:AgregarEsBonoAPedidosAprobados';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Agrega "producto_bono" a la view PedidosAprobados';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle(): int
|
||||||
|
{
|
||||||
|
DB::statement("
|
||||||
|
ALTER VIEW pedidos_aprobados(
|
||||||
|
grupo_de_compra_id,
|
||||||
|
grupo_de_compra_nombre,
|
||||||
|
grupo_de_compra_region,
|
||||||
|
producto_id,
|
||||||
|
producto_nombre,
|
||||||
|
producto_precio,
|
||||||
|
cantidad_pedida,
|
||||||
|
total_por_producto,
|
||||||
|
producto_es_bono
|
||||||
|
) 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,
|
||||||
|
pr.bono
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
|
class CallAgregarEsBonoAPedidosAprobados extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Artisan::call("command:AgregarEsBonoAPedidosAprobados");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue