laravel-vuexy-warehouse/Http/Controllers/WarehouseController.php
2025-03-05 20:44:45 -06:00

134 lines
5.2 KiB
PHP

<?php
namespace Koneko\VuexyWarehouse\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Koneko\VuexyAdmin\Queries\GenericQueryBuilder;
use Koneko\SatCatalogs\Http\Controllers\SatCatalogController;
use Koneko\VuexyWarehouse\Models\Warehouse;
class WarehouseController extends SatCatalogController
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
if ($request->ajax()) {
$bootstrapTableIndexConfig = [
'table' => 'warehouses',
'columns' => [
'warehouses.id',
'stores.code AS store_code',
'stores.name AS store_name',
'store_work_centers.code AS work_center_code',
'store_work_centers.name AS work_center_name',
'warehouses.code',
'warehouses.name',
'warehouses.description',
DB::raw("CONCAT_WS(' ', users.name, users.last_name) AS manager_name"),
'users.email AS manager_email',
'warehouses.tel',
'warehouses.tel2',
'sat_pais.descripcion AS pais',
'sat_estado.nombre_del_estado AS estado',
'sat_localidad.descripcion AS localidad',
'sat_municipio.descripcion AS municipio',
'sat_colonia.nombre_del_asentamiento AS colonia',
DB::raw("CONCAT_WS(' ', COALESCE(stores.direccion, ''), COALESCE(stores.num_ext, ''), IF(stores.num_int IS NOT NULL, CONCAT('Int ', stores.num_int), '')) AS direccion"),
'warehouses.priority',
'warehouses.status',
'warehouses.created_at',
'warehouses.updated_at',
],
'joins' => [
[
'table' => 'stores',
'first' => 'warehouses.store_id',
'second' => 'stores.id',
'type' => 'join',
],
[
'table' => 'store_work_centers',
'first' => 'warehouses.work_center_id',
'second' => 'store_work_centers.id',
'type' => 'leftJoin',
],
[
'table' => 'users',
'first' => 'warehouses.manager_id',
'second' => 'users.id',
'type' => 'leftJoin',
],
[
'table' => 'sat_pais',
'first' => 'stores.c_pais',
'second' => 'sat_pais.c_pais',
'type' => 'leftJoin',
],
[
'table' => 'sat_estado',
'first' => 'stores.c_estado',
'second' => 'sat_estado.c_estado',
'and' => [
'stores.c_pais = sat_estado.c_pais',
],
'type' => 'leftJoin',
],
[
'table' => 'sat_localidad',
'first' => 'stores.c_localidad',
'second' => 'sat_localidad.c_localidad',
'and' => [
'stores.c_estado = sat_localidad.c_estado',
],
'type' => 'leftJoin',
],
[
'table' => 'sat_municipio',
'first' => 'stores.c_municipio',
'second' => 'sat_municipio.c_municipio',
'and' => [
'stores.c_estado = sat_municipio.c_estado',
],
'type' => 'leftJoin',
],
[
'table' => 'sat_colonia',
'first' => 'stores.c_colonia',
'second' => 'sat_colonia.c_colonia',
'and' => [
'stores.c_codigo_postal = sat_colonia.c_codigo_postal',
],
'type' => 'leftJoin',
],
],
'filters' => [
'search' => [
'warehouses.code',
'warehouses.name',
'stores.name',
'store_work_centers.name',
],
],
'sort_column' => 'warehouses.name', // Columna por defecto para ordenamiento
'default_sort_order' => 'asc', // Orden por defecto
];
return (new GenericQueryBuilder($request, $bootstrapTableIndexConfig))->getJson();
}
return view('vuexy-warehouse::warehouses.index');
}
/**
* Display the specified resource.
*/
public function show(Warehouse $warehouse)
{
//
}
}