143 lines
5.8 KiB
PHP
143 lines
5.8 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Koneko\VuexyStoreManager\Http\Controllers;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
use Illuminate\Support\Facades\DB;
|
||
|
use Koneko\VuexyAdmin\Helpers\CatalogHelper;
|
||
|
use Koneko\VuexyAdmin\Queries\GenericQueryBuilder;
|
||
|
use Koneko\SatCatalogs\Http\Controllers\SatCatalogController;
|
||
|
use Koneko\VuexyStoreManager\Models\StoreWorkCenter;
|
||
|
|
||
|
class WorkCenterController extends SatCatalogController
|
||
|
{
|
||
|
/**
|
||
|
* Display a listing of the resource.
|
||
|
*/
|
||
|
public function index(Request $request)
|
||
|
{
|
||
|
if ($request->ajax()) {
|
||
|
$bootstrapTableIndexConfig = [
|
||
|
'table' => 'store_work_centers',
|
||
|
'columns' => [
|
||
|
'store_work_centers.id',
|
||
|
'stores.code AS stores_code',
|
||
|
'stores.name AS stores_name',
|
||
|
'store_work_centers.code',
|
||
|
'store_work_centers.name',
|
||
|
'store_work_centers.description',
|
||
|
'store_work_centers.manager_id',
|
||
|
DB::raw("CONCAT_WS(' ', users.name, users.last_name) AS manager_name"),
|
||
|
'users.email AS manager_email',
|
||
|
'store_work_centers.tel',
|
||
|
'store_work_centers.tel2',
|
||
|
'stores.c_codigo_postal AS codigo_postal',
|
||
|
'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"),
|
||
|
'store_work_centers.lat',
|
||
|
'store_work_centers.lng',
|
||
|
'store_work_centers.status',
|
||
|
'store_work_centers.created_at',
|
||
|
'store_work_centers.updated_at',
|
||
|
],
|
||
|
'joins' => [
|
||
|
[
|
||
|
'table' => 'stores',
|
||
|
'first' => 'store_work_centers.store_id',
|
||
|
'second' => 'stores.id',
|
||
|
'type' => 'join', // INNER JOIN
|
||
|
],
|
||
|
[
|
||
|
'table' => 'sat_pais',
|
||
|
'first' => 'stores.c_pais',
|
||
|
'second' => 'sat_pais.c_pais',
|
||
|
'type' => 'leftJoin', // LEFT OUTER JOIN
|
||
|
],
|
||
|
[
|
||
|
'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',
|
||
|
],
|
||
|
[
|
||
|
'table' => 'users',
|
||
|
'first' => 'store_work_centers.manager_id',
|
||
|
'second' => 'users.id',
|
||
|
'type' => 'leftJoin',
|
||
|
],
|
||
|
],
|
||
|
'filters' => [
|
||
|
'search' => [
|
||
|
'store_work_centers.code',
|
||
|
'store_work_centers.name',
|
||
|
'stores.code',
|
||
|
'stores.name',
|
||
|
],
|
||
|
],
|
||
|
'sort_column' => 'store_work_centers.name', // Columna por defecto para ordenamiento
|
||
|
'default_sort_order' => 'asc', // Orden por defecto
|
||
|
];
|
||
|
|
||
|
return (new GenericQueryBuilder($request, $bootstrapTableIndexConfig))->getJson();
|
||
|
}
|
||
|
|
||
|
return view('vuexy-store-manager::work-center.index');
|
||
|
}
|
||
|
|
||
|
public function ajax(\Illuminate\Http\Request $request)
|
||
|
{
|
||
|
$options = [
|
||
|
'id' => $request->input('id', null),
|
||
|
'searchTerm' => $request->input('searchTerm', null),
|
||
|
'limit' => $request->input('limit', 20),
|
||
|
'keyField' => 'id',
|
||
|
'valueField' => 'custom_name', // Usamos un alias que agregaremos con DB::raw()
|
||
|
'responseType' => $request->input('responseType', 'select2'),
|
||
|
'filters' => [
|
||
|
'store_id' => $request->input('store_id', null),
|
||
|
]
|
||
|
];
|
||
|
|
||
|
// Aquí añadimos la expresión de concatenación con un alias
|
||
|
$query = StoreWorkCenter::query()
|
||
|
->select('store_work_centers.*', DB::raw("CONCAT_WS(' - ', code, name) AS custom_name"));
|
||
|
|
||
|
return CatalogHelper::ajaxFlexibleResponse($query, $options);
|
||
|
}
|
||
|
|
||
|
}
|