159 lines
5.7 KiB
PHP
159 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace Koneko\VuexyStoreManager\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Koneko\VuexyStoreManager\Models\Store;
|
|
use Koneko\VuexyAdmin\Queries\GenericQueryBuilder;
|
|
|
|
class StoreController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
if ($request->ajax()) {
|
|
$bootstrapTableIndexConfig = [
|
|
'table' => 'stores',
|
|
'columns' => [
|
|
'stores.id',
|
|
'stores.code',
|
|
'stores.name',
|
|
'stores.description',
|
|
'stores.c_codigo_postal AS codigo_postal',
|
|
'sat_pais.descripcion AS pais',
|
|
DB::raw("CONCAT_WS(' ', users.name, users.last_name) AS manager_name"),
|
|
'users.email AS manager_email',
|
|
'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"),
|
|
'stores.lat',
|
|
'stores.lng',
|
|
'stores.email',
|
|
'stores.tel',
|
|
'stores.tel2',
|
|
'stores.rfc',
|
|
'stores.nombre_fiscal',
|
|
'sat_regimen_fiscal.descripcion AS regimen_fiscal',
|
|
'stores.domicilio_fiscal',
|
|
'stores.show_on_website',
|
|
'stores.enable_ecommerce',
|
|
'stores.status',
|
|
'stores.created_at',
|
|
'stores.updated_at',
|
|
],
|
|
'joins' => [
|
|
[
|
|
'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',
|
|
'type' => 'leftJoin',
|
|
'and' => [
|
|
'stores.c_pais = sat_estado.c_pais',
|
|
],
|
|
],
|
|
[
|
|
'table' => 'sat_localidad',
|
|
'first' => 'stores.c_localidad',
|
|
'second' => 'sat_localidad.c_localidad',
|
|
'type' => 'leftJoin',
|
|
'and' => [
|
|
'stores.c_estado = sat_localidad.c_estado',
|
|
],
|
|
],
|
|
[
|
|
'table' => 'sat_municipio',
|
|
'first' => 'stores.c_municipio',
|
|
'second' => 'sat_municipio.c_municipio',
|
|
'type' => 'leftJoin',
|
|
'and' => [
|
|
'stores.c_estado = sat_municipio.c_estado',
|
|
],
|
|
],
|
|
[
|
|
'table' => 'sat_colonia',
|
|
'first' => 'stores.c_colonia',
|
|
'second' => 'sat_colonia.c_colonia',
|
|
'type' => 'leftJoin',
|
|
'and' => [
|
|
'stores.c_codigo_postal = sat_colonia.c_codigo_postal',
|
|
],
|
|
],
|
|
[
|
|
'table' => 'sat_regimen_fiscal',
|
|
'first' => 'stores.c_regimen_fiscal',
|
|
'second' => 'sat_regimen_fiscal.c_regimen_fiscal',
|
|
'type' => 'leftJoin',
|
|
],
|
|
[
|
|
'table' => 'users',
|
|
'first' => 'stores.manager_id',
|
|
'second' => 'users.id',
|
|
'type' => 'leftJoin',
|
|
],
|
|
],
|
|
'filters' => [
|
|
'search' => ['stores.name', 'stores.code', 'users.name', 'users.email'], // Búsqueda por nombre, código o manager
|
|
],
|
|
'sort_column' => 'stores.name', // Ordenamiento por defecto
|
|
'default_sort_order' => 'asc', // Orden ascendente por defecto
|
|
];
|
|
|
|
return (new GenericQueryBuilder($request, $bootstrapTableIndexConfig))->getJson();
|
|
}
|
|
|
|
return view('vuexy-store-manager::store.index');
|
|
}
|
|
|
|
/**
|
|
* Show the crud for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('vuexy-store-manager::store.crud')
|
|
->with('mode', 'create')
|
|
->with('store', null);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Store $store)
|
|
{
|
|
return view('vuexy-store-manager::store.crud', compact('store'));
|
|
}
|
|
|
|
/**
|
|
* Show the crud for editing the specified resource.
|
|
*/
|
|
public function edit(Store $store)
|
|
{
|
|
//$store = Store::findOrFail($id);
|
|
|
|
|
|
|
|
return view('vuexy-store-manager::store.crud', compact('store'))->with('mode', 'edit');
|
|
}
|
|
|
|
/**
|
|
* Show the crud for editing the specified resource.
|
|
*/
|
|
public function delete(Store $store)
|
|
{
|
|
return view('vuexy-store-manager::store.crud', compact('store'))->with('mode', 'delete');
|
|
|
|
}
|
|
|
|
}
|