222 lines
6.7 KiB
PHP
Raw Normal View History

2025-03-05 20:44:45 -06:00
<?php
namespace Koneko\VuexyWarehouse\Livewire\Warehouses;
use Koneko\VuexyAdmin\Livewire\Table\AbstractIndexComponent;
use Koneko\VuexyWarehouse\Models\Warehouse;
use Koneko\VuexyStoreManager\Services\StoreCatalogService;
class WarehouseIndex extends AbstractIndexComponent
{
public $store_id;
public $storeOptions = [];
/**
* Retorna la clase del modelo asociado.
*
* @return string
*/
protected function model(): string
{
return Warehouse::class;
}
/**
* Configura el encabezado (header) de la tabla (las columnas).
*
* @return array
*/
protected function columns(): array
{
return [
'action' => 'Acciones',
'store_code' => 'Código de Tienda',
'store_name' => 'Nombre de la Tienda',
'work_center_code' => 'Código del Centro de Trabajo',
'work_center_name' => 'Nombre del Centro de Trabajo',
'code' => 'Código de Almacén',
'name' => 'Nombre del Almacén',
'description' => 'Descripción',
'manager_name' => 'Encargado',
'pais' => 'País',
'estado' => 'Estado',
'localidad' => 'Localidad',
'municipio' => 'Municipio',
'codigo_postal' => 'Código Postal',
'colonia' => 'Colonia',
'direccion' => 'Dirección',
'tel' => 'Teléfono',
'tel2' => 'Teléfono Alternativo',
'priority' => 'Prioridad',
'status' => 'Estatus',
'created_at' => 'Fecha de Creación',
'updated_at' => 'Última Actualización',
];
}
/**
* Define los formatos de cada columna (se inyectará en $bt_datatable['format']).
*
* @return array
*/
protected function format(): array
{
return [
'action' => [
'formatter' => 'warehouseActionFormatter',
'onlyFormatter' => true,
],
'store_code' => [
'formatter' => [
'name' => 'dynamicBadgeFormatter',
'params' => ['color' => 'secondary']
],
'align' => 'center',
'visible' => false,
],
'work_center_code' => [
'formatter' => [
'name' => 'dynamicBadgeFormatter',
'params' => ['color' => 'secondary']
],
'align' => 'center',
'visible' => false,
],
'work_center_name' => [
'visible' => false,
],
'code' => [
'formatter' => [
'name' => 'dynamicBadgeFormatter',
'params' => ['color' => 'secondary'],
],
'align' => 'center',
'switchable' => false,
],
'name' => [
'switchable' => false,
],
'description' => [
'visible' => false,
],
'manager_name' => [
'formatter' => 'managerFormatter',
],
'tel' => [
'formatter' => 'telFormatter',
'align' => 'center',
],
'tel2' => [
'formatter' => 'telFormatter',
'align' => 'center',
'visible' => false,
],
'pais' => [
'align' => 'center',
'visible' => false,
],
'estado' => [
'formatter' => 'textNowrapFormatter',
'visible' => false,
],
'localidad' => [
'formatter' => 'textNowrapFormatter',
'visible' => false,
],
'municipio' => [
'formatter' => 'textNowrapFormatter',
'visible' => false,
],
'codigo_postal' => [
'align' => 'center',
'visible' => false,
],
'colonia' => [
'formatter' => 'textNowrapFormatter',
'visible' => false,
],
'direccion' => [
'formatter' => 'direccionFormatter',
'visible' => false,
],
'priority' => [
'formatter' => 'numberFormatter',
'align' => 'center',
],
'status' => [
'formatter' => [
'name' => 'dynamicBooleanFormatter',
'params' => ['tag' => 'activo']
],
'align' => 'center',
],
'created_at' => [
'formatter' => 'textNowrapFormatter',
'align' => 'center',
'visible' => false,
],
'updated_at' => [
'formatter' => 'textNowrapFormatter',
'align' => 'center',
'visible' => false,
],
];
}
/**
* Retorna la configuración base (común) para la tabla Bootstrap Table.
*
* @return array
*/
protected function bootstraptableConfig(): array
{
return [
'sortName' => 'code',
'exportFileName' => 'Almacenes',
'showFullscreen' => false,
'showPaginationSwitch' => false,
'showRefresh' => false,
'pagination' => false,
];
}
/**
* Retorna la ruta de la vista Blade.
*
* @return string
*/
protected function viewPath(): string
{
// La vista que ya tienes creada para WarehouseIndex
return 'vuexy-warehouse::livewire.warehouses.index';
}
/**
* Métodos que necesites sobreescribir o extender.
*/
public function mount(): void
{
parent::mount();
// Cargar opciones de tienda, por ejemplo:
$storeCatalogService = app(StoreCatalogService::class);
$this->storeOptions = $storeCatalogService->searchCatalog('stores', '', ['limit' => -1]);
}
/**
* Puedes agregar lógica de filtrado específica para warehouses,
* si lo requieres, sobrescribiendo el método applyFilters del padre.
*/
protected function applyFilters($criteria = [])
{
$query = parent::applyFilters($criteria);
// Ejemplo de aplicar filtro por store_id
if ($this->store_id) {
$query->where('store_id', $this->store_id);
}
return $query;
}
}