datos envio clientes

This commit is contained in:
Jaime Jiménez
2023-12-15 14:02:35 +01:00
parent d4f92263bf
commit d4246ca99b
15 changed files with 421 additions and 603 deletions

View File

@ -475,7 +475,15 @@ $routes->group('clientecontactos', ['namespace' => 'App\Controllers\Clientes'],
$routes->post('allmenuitems', 'Clientecontactos::allItemsSelect', ['as' => 'select2ItemsOfClienteContactos']);
$routes->post('menuitems', 'Clientecontactos::menuItems', ['as' => 'menuItemsOfClienteContactos']);
});
$routes->resource('ClienteContactos', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'ClienteContactos', 'except' => 'show,new,create,update']);
$routes->resource('ClienteContactos', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'ClienteContactos', 'except' => 'show,new,create,update']);
$routes->group('clientedirecciones', ['namespace' => 'App\Controllers\Clientes'], function ($routes) {
$routes->post('datatable', 'Clientedirecciones::datatable', ['as' => 'dataTableOfClienteDirecciones']);
$routes->post('datatable_editor', 'Clientedirecciones::datatable_editor', ['as' => 'editorOfClienteDirecciones']);
});
$routes->resource('clientedirecciones', ['namespace' => 'App\Controllers\Clientes', 'controller' => 'Clientedirecciones', 'except' => 'show,new,create,update']);
$routes->group('cosidotapablanda', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) {

View File

@ -0,0 +1,56 @@
<?php namespace App\Controllers\Clientes;
use App\Models\Collection;
use App\Entities\Clientes\ClienteDireccionesEntity;
use App\Models\Clientes\ClienteDireccionesModel;
use DataTables\Editor;
use DataTables\Editor\Field;
use DataTables\Editor\Validate;
class Clientedirecciones extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ClienteDireccionesModel::class;
protected $format = 'json';
protected static $singularObjectName = 'Direccion de cliente';
protected static $singularObjectNameCc = 'direccionDeCliente';
protected static $pluralObjectName = 'Direcciones de cliente';
protected static $pluralObjectNameCc = 'direccionesDeCliente';
protected static $controllerSlug = 'cliente-direcciones';
public function datatable()
{
if ($this->request->isAJAX()) {
$reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
$length = $reqData['length'] ?? 5;
$search = $reqData['search']['value'];
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
$order = ClienteDireccionesModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$id_C = $reqData['id_cliente'] ?? -1;
$resourceData = $this->model->getResource($search, $id_C)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResource()->countAllResults(),
$this->model->getResource("", $id_C)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}

View File

@ -1,335 +0,0 @@
<?php namespace App\Controllers\Clientes;
use App\Controllers\GoBaseResourceController;
use App\Models\Collection;
use App\Entities\Clientes\ClienteDistribuidorEntity;
use App\Models\Configuracion\PaisModel;
use App\Models\Clientes\ClienteDistribuidorModel;
use App\Models\Configuracion\ProvinciaModel;
use App\Models\Configuracion\ComunidadAutonomaModel;
class Clientedistribuidores extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ClienteDistribuidorModel::class;
protected $format = 'json';
protected static $singularObjectName = 'Distribuidor de cliente';
protected static $singularObjectNameCc = 'distribuidorDeCliente';
protected static $pluralObjectName = 'Distribuidores de cliente';
protected static $pluralObjectNameCc = 'distribuidoresDeCliente';
protected static $controllerSlug = 'cliente-distribuidores';
protected static $viewPath = 'themes/backend/vuexy/form/clientes/distribuidores/';
protected $indexRoute = 'distribuidorDeClienteList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('ClienteDistribuidores.moduleTitle');
$this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
}
public function index()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('ClienteDistribuidores.distribuidorDeCliente')]),
'clienteDistribuidorEntity' => new ClienteDistribuidorEntity(),
'usingServerSideDataTable' => true,
];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath . 'viewDistribuidorDeClienteList', $viewData);
}
public function add()
{
$requestMethod = $this->request->getMethod();
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else:
return $this->redirect2listView('sweet-success', $message);
endif;
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$this->viewData['clienteDistribuidorEntity'] = isset($sanitizedData) ? new ClienteDistribuidorEntity($sanitizedData) : new ClienteDistribuidorEntity();
$this->viewData['paisList'] = $this->getPaisListItems($clienteDistribuidorEntity->pais_id ?? null);
$this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteDistribuidorEntity->provincia_id ?? null);
$this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteDistribuidorEntity->comunidad_autonoma_id ?? null);
$this->viewData['formAction'] = route_to('createDistribuidorDeCliente');
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('ClienteDistribuidores.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__);
} // end function add()
public function edit($requestedId = null)
{
if ($requestedId == null) :
return $this->redirect2listView();
endif;
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
$clienteDistribuidorEntity = $this->model->find($id);
if ($clienteDistribuidorEntity == false) :
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('ClienteDistribuidores.distribuidorDeCliente')), $id]);
return $this->redirect2listView('sweet-error', $message);
endif;
$requestMethod = $this->request->getMethod();
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ClienteDistribuidores.distribuidorDeCliente'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$clienteDistribuidorEntity->fill($sanitizedData);
$thenRedirect = false;
endif;
if ($noException && $successfulResult) :
$id = $clienteDistribuidorEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else:
return $this->redirect2listView('sweet-success', $message);
endif;
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$this->viewData['clienteDistribuidorEntity'] = $clienteDistribuidorEntity;
$this->viewData['paisList'] = $this->getPaisListItems($clienteDistribuidorEntity->pais_id ?? null);
$this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteDistribuidorEntity->provincia_id ?? null);
$this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteDistribuidorEntity->comunidad_autonoma_id ?? null);
$this->viewData['formAction'] = route_to('updateDistribuidorDeCliente', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('ClienteDistribuidores.moduleTitle') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id);
} // end function edit(...)
public function datatable()
{
if ($this->request->isAJAX()) {
$reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
$length = $reqData['length'] ?? 5;
$search = $reqData['search']['value'];
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
$order = ClienteDistribuidorModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
foreach ($resourceData as $item) :
if (isset($item->direccion) && strlen($item->direccion) > 100) :
$item->direccion = character_limiter($item->direccion, 100);
endif;
if (isset($item->horarios_entrega) && strlen($item->horarios_entrega) > 100) :
$item->horarios_entrega = character_limiter($item->horarios_entrega, 100);
endif;
endforeach;
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResource()->countAllResults(),
$this->model->getResource($search)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
'menu' => $menu,
$csrfTokenName => $newTokenHash
];
return $this->respond($data);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0];
$reqText = goSanitize($this->request->getPost('text'))[0];
$onlyActiveOnes = false;
$columns2select = [$reqId ?? 'id', $reqText ?? 'nombre'];
$onlyActiveOnes = false;
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
'menu' => $menu,
$csrfTokenName => $newTokenHash
];
return $this->respond($data);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
protected function getComunidadAutonomaListItems($selId = null)
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))])];
if (!empty($selId)) :
$comunidadAutonomaModel = model('App\Models\Configuracion\ComunidadAutonomaModel');
$selOption = $comunidadAutonomaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) :
$data[$selId] = $selOption[0];
endif;
endif;
return $data;
}
protected function getPaisListItems($selId = null)
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
if (!empty($selId)) :
$paisModel = model('App\Models\Configuracion\PaisModel');
$selOption = $paisModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) :
$data[$selId] = $selOption[0];
endif;
endif;
return $data;
}
protected function getProvinciaListItems($selId = null)
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Provincias.provincia'))])];
if (!empty($selId)) :
$provinciaModel = model('App\Models\Configuracion\ProvinciaModel');
$selOption = $provinciaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) :
$data[$selId] = $selOption[0];
endif;
endif;
return $data;
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Entities\Cliente;
use CodeIgniter\Entity;
class ClienteDireccionesEntity extends \CodeIgniter\Entity\Entity
{
protected $attributes = [
"id" => null,
"cliente_id" => null,
"att" => null,
"email" => null,
"direccion" => null,
"pais_id" => null,
"ccaa_id" => null,
"provincia_id" => null,
"municipio_id" => null,
"cp" => null,
"telefono" => null,
];
protected $casts = [
"cliente_id" => "int",
"pais_id" => "int",
"ccaa_id" => "int",
"provincia_id" => "int",
"municipio_id" => "int",
"cp" => "int",
];
}

View File

@ -1,34 +0,0 @@
<?php
namespace App\Entities\Clientes;
use CodeIgniter\Entity;
class ClienteDistribuidorEntity extends \CodeIgniter\Entity\Entity
{
protected $attributes = [
"id" => null,
"nombre" => null,
"cif" => null,
"direccion" => null,
"ciudad" => null,
"cp" => null,
"email" => null,
"pais_id" => null,
"provincia_id" => null,
"comunidad_autonoma_id" => null,
"telefono" => null,
"horarios_entrega" => null,
"persona_contacto" => null,
"precio" => null,
"is_deleted" => 0,
"created_at" => null,
"updated_at" => null,
];
protected $casts = [
"pais_id" => "int",
"provincia_id" => "int",
"comunidad_autonoma_id" => "?int",
"precio" => "?float",
"is_deleted" => "int",
];
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Entities\Presupuestos;
use CodeIgniter\Entity;
class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity
{
protected $attributes = [
"id" => null,
"presupuesto_id" => null,
"cantidad" => null,
"peso" => null,
"att" => null,
"email" => null,
"direccion" => null,
"pais_id" => null,
"ccaa_id" => null,
"provincia_id" => null,
"municipio_id" => null,
"cp" => null,
"telefono" => null,
"precio" => null,
];
protected $casts = [
"presupuesto_id" => "int",
"cantidad" => "int",
"peso" => "float",
"pais_id" => "int",
"ccaa_id" => "int",
"provincia_id" => "int",
"municipio_id" => "int",
"cp" => "int",
"precio" => "float",
];
}

View File

@ -0,0 +1,20 @@
<?php
return [
'att' => 'Attn.',
'email' => 'Email',
'direccion' => 'Address',
'cp' => 'Zip Code',
'municipio' => 'Town',
'provincia' => 'City',
'ccaa' => 'Region',
'pais' => 'Country',
'telefono' => 'Phone',
'validation' => [
'max_length' => 'The {field} field cannot exceed {param} characters in length.',
'valid_email' => 'The email is not valid',
],
];

View File

@ -148,14 +148,7 @@ return [
'envios' => 'Shipments',
'cantidad' => 'Quantity',
'att' => 'Attn.',
'email' => 'Email',
'direccion' => 'Address',
'cp' => 'Zip Code',
'municipio' => 'Town',
'provincia' => 'City',
'ccaa' => 'Region',
'telefono' => 'Phone',
'validation' => [
'decimal' => 'The {field} field must contain a decimal number.',

View File

@ -0,0 +1,19 @@
<?php
return [
'att' => 'Att.',
'email' => 'Email',
'direccion' => 'Direccion',
'cp' => 'CP',
'municipio' => 'Ciudad',
'provincia' => 'Provincia',
'ccaa' => 'CCAA',
'pais' => 'País',
'telefono' => 'Teléfono',
'validation' => [
'max_length' => 'El campo {field} no puede exceder los {param} caracteres de longitud.',
'valid_email' => 'El email introducido no es válido',
],
];

View File

@ -182,14 +182,6 @@ return [
'envios' => 'Envios',
'cantidad' => 'Cantidad',
'att' => 'Att.',
'email' => 'Email',
'direccion' => 'Direccion',
'cp' => 'CP',
'municipio' => 'Municipio',
'provincia' => 'Provincia',
'ccaa' => 'CCAA',
'telefono' => 'Teléfono',
'validation' => [
'decimal' => 'El campo {field} debe contener un número decimal.',

View File

@ -0,0 +1,118 @@
<?php
namespace App\Models\Clientes;
class ClienteDireccionesModel extends \App\Models\GoBaseModel
{
protected $table = "cliente_direcciones";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
const SORTABLE = [
0 => "t1.att",
1 => "t1.email",
2 => "t1.direccion",
3 => "t1.cp",
4 => "t5.municipio_nombre",
5 => "t4.nombre",
6 => "t3.nombre",
7 => "t1.telefono",
];
protected $allowedFields = [
"cliente_id",
"att",
"email",
"direccion",
"pais_id",
"ccaa_id",
"provincia_id",
"municipio_id",
"cp",
"telefono",
];
protected $returnType = "App\Entities\Clientes\ClienteDireccionesEntity";
public static $labelField = "id";
protected $validationRules = [
"att" => [
"label" => "ClienteDirecciones.att",
"rules" => "trim|max_length[100]",
],
"email" => [
"label" => "ClienteDirecciones.email",
"rules" => "trim|max_length[100]|valid_email",
],
"cp" => [
"label" => "ClienteDirecciones.cp",
"rules" => "trim|max_length[20]",
],
"telefono" => [
"label" => "ClienteDirecciones.telefono",
"rules" => "trim|max_length[40]",
],
];
protected $validationMessages = [
"att" => [
"max_length" => "ClienteDirecciones.validation.max_length",
],
"email" => [
"max_length" => "ClienteDirecciones.validation.max_length",
],
"cp" => [
"max_length" => "ClienteDirecciones.validation.max_length",
"valid_email" => "ClienteDirecciones.validation.valid_email",
],
"telefono" => [
"max_length" => "ClienteDirecciones.validation.max_length",
],
];
/**
* Get resource data.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "", $cliente_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.cliente_id AS cliente_id, t2.nombre as cliente_nombre, t1.att AS att,
t1.email AS email, t1.direccion AS direccion, t1.pais_id AS pais_id, t3.nombre AS pais,
t1.ccaa_id AS ccaa_id, t4.nombre AS ccaa_nombre,
t1.municipio_id AS municipio_id, t5.municipio_nombre AS municipio_nombre, t1.cp AS cp, t1.telefono AS telefono"
);
$builder->where('t1.cliente_id', $cliente_id);
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
$builder->join("lg_paises t3", "t1.pais_id = t3.id", "left");
$builder->join("lg_comunidades_autonomas t4", "t1.ccaa_id = t4.id", "left");
$builder->join("municipios t5", "t1.municipio_id = t5.id", "left");
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.att", $search)
->orLike("t1.email", $search)
->orLike("t1.direccion", $search)
->orLike("t3.nombre", $search)
->orLike("t4.nombre", $search)
->orLike("t5.municipio_nombre", $search)
->orLike("t1.cp", $search)
->orLike("t1.telefono", $search)
->groupEnd();
}
}

View File

@ -1,214 +0,0 @@
<?php
namespace App\Models\Clientes;
class ClienteDistribuidorModel extends \App\Models\GoBaseModel
{
protected $table = "cliente_distribuidores";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
const SORTABLE = [
1 => "t1.id",
2 => "t1.nombre",
3 => "t1.cif",
4 => "t1.direccion",
5 => "t1.ciudad",
6 => "t1.cp",
7 => "t1.email",
8 => "t1.pais_id",
9 => "t1.provincia_id",
10 => "t1.comunidad_autonoma_id",
11 => "t1.telefono",
12 => "t1.horarios_entrega",
13 => "t1.persona_contacto",
14 => "t1.precio",
15 => "t2.nombre",
16 => "t3.nombre",
17 => "t4.nombre",
];
protected $allowedFields = [
"nombre",
"cif",
"direccion",
"ciudad",
"cp",
"email",
"pais_id",
"provincia_id",
"comunidad_autonoma_id",
"telefono",
"horarios_entrega",
"persona_contacto",
"precio",
];
protected $returnType = "App\Entities\Clientes\ClienteDistribuidorEntity";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $createdField = "created_at";
protected $updatedField = "updated_at";
public static $labelField = "nombre";
protected $validationRules = [
"cif" => [
"label" => "ClienteDistribuidores.cif",
"rules" => "trim|max_length[50]",
],
"ciudad" => [
"label" => "ClienteDistribuidores.ciudad",
"rules" => "trim|max_length[100]",
],
"cp" => [
"label" => "ClienteDistribuidores.cp",
"rules" => "trim|max_length[10]",
],
"direccion" => [
"label" => "ClienteDistribuidores.direccion",
"rules" => "trim|max_length[300]",
],
"email" => [
"label" => "ClienteDistribuidores.email",
"rules" => "trim|max_length[150]|valid_email|permit_empty",
],
"horarios_entrega" => [
"label" => "ClienteDistribuidores.horariosEntrega",
"rules" => "trim|max_length[300]",
],
"nombre" => [
"label" => "ClienteDistribuidores.nombre",
"rules" => "trim|required|max_length[255]",
],
"persona_contacto" => [
"label" => "ClienteDistribuidores.personaContacto",
"rules" => "trim|max_length[100]",
],
"precio" => [
"label" => "ClienteDistribuidores.precio",
"rules" => "decimal|permit_empty",
],
"telefono" => [
"label" => "ClienteDistribuidores.telefono",
"rules" => "trim|max_length[60]",
],
];
protected $validationMessages = [
"cif" => [
"max_length" => "ClienteDistribuidores.validation.cif.max_length",
],
"ciudad" => [
"max_length" => "ClienteDistribuidores.validation.ciudad.max_length",
],
"cp" => [
"max_length" => "ClienteDistribuidores.validation.cp.max_length",
],
"direccion" => [
"max_length" => "ClienteDistribuidores.validation.direccion.max_length",
],
"email" => [
"max_length" => "ClienteDistribuidores.validation.email.max_length",
"valid_email" => "ClienteDistribuidores.validation.email.valid_email",
],
"horarios_entrega" => [
"max_length" => "ClienteDistribuidores.validation.horarios_entrega.max_length",
],
"nombre" => [
"max_length" => "ClienteDistribuidores.validation.nombre.max_length",
"required" => "ClienteDistribuidores.validation.nombre.required",
],
"persona_contacto" => [
"max_length" => "ClienteDistribuidores.validation.persona_contacto.max_length",
],
"precio" => [
"decimal" => "ClienteDistribuidores.validation.precio.decimal",
],
"telefono" => [
"max_length" => "ClienteDistribuidores.validation.telefono.max_length",
],
];
public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0)
{
$sql =
"SELECT t1." .
$selcols .
", t2.nombre AS pais, t3.nombre AS provincia, t4.nombre AS comunidad_autonoma FROM " .
$this->table .
" t1 LEFT JOIN lg_paises t2 ON t1.pais_id = t2.id LEFT JOIN lg_provincias t3 ON t1.provincia_id = t3.id LEFT JOIN lg_comunidades_autonomas t4 ON t1.comunidad_autonoma_id = t4.id";
if (!is_null($limit) && intval($limit) > 0) {
$sql .= " LIMIT " . intval($limit);
}
if (!is_null($offset) && intval($offset) > 0) {
$sql .= " OFFSET " . intval($offset);
}
$query = $this->db->query($sql);
$result = $query->getResultObject();
return $result;
}
/**
* Get resource data.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "")
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.nombre AS nombre, t1.cif AS cif, t1.direccion AS direccion, t1.ciudad AS ciudad, t1.cp AS cp, t1.email AS email, t1.telefono AS telefono, t1.horarios_entrega AS horarios_entrega, t1.persona_contacto AS persona_contacto, t1.precio AS precio, t2.nombre AS pais, t3.nombre AS provincia, t4.nombre AS comunidad_autonoma"
);
$builder->join("lg_paises t2", "t1.pais_id = t2.id", "left");
$builder->join("lg_provincias t3", "t1.provincia_id = t3.id", "left");
$builder->join("lg_comunidades_autonomas t4", "t1.comunidad_autonoma_id = t4.id", "left");
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.id", $search)
->orLike("t1.nombre", $search)
->orLike("t1.cif", $search)
->orLike("t1.direccion", $search)
->orLike("t1.ciudad", $search)
->orLike("t1.cp", $search)
->orLike("t1.email", $search)
->orLike("t1.telefono", $search)
->orLike("t1.horarios_entrega", $search)
->orLike("t1.persona_contacto", $search)
->orLike("t1.precio", $search)
->orLike("t2.id", $search)
->orLike("t3.id", $search)
->orLike("t4.id", $search)
->orLike("t1.id", $search)
->orLike("t1.nombre", $search)
->orLike("t1.cif", $search)
->orLike("t1.direccion", $search)
->orLike("t1.ciudad", $search)
->orLike("t1.cp", $search)
->orLike("t1.email", $search)
->orLike("t1.pais_id", $search)
->orLike("t1.provincia_id", $search)
->orLike("t1.comunidad_autonoma_id", $search)
->orLike("t1.telefono", $search)
->orLike("t1.horarios_entrega", $search)
->orLike("t1.persona_contacto", $search)
->orLike("t1.precio", $search)
->orLike("t2.nombre", $search)
->orLike("t3.nombre", $search)
->orLike("t4.nombre", $search)
->groupEnd();
}
}

View File

@ -0,0 +1,7 @@
<div id="direccionesForm">
<fieldset class="att">
<legend>Att</legend>
<editor-field name="att"></editor-field>
</fieldset>
</div>

View File

@ -580,7 +580,26 @@
<div class="tab-pane fade" id="domicilio-entrega" role="tabpanel">
<h3>Proximanente</h3>
<?= view("themes/backend/vuexy/form/clientes/cliente/_clienteDireccionesForm") ?>
<table id="tableOfDireccionesEnvio" class="table dt-responsive dataTable" style="width: 100%;">
<thead>
<tr>
<th><?= lang('ClienteDirecciones.att') ?></th>
<th><?= lang('ClienteDirecciones.email') ?></th>
<th><?= lang('ClienteDirecciones.direccion') ?></th>
<th><?= lang('ClienteDirecciones.cp') ?></th>
<th><?= lang('ClienteDirecciones.municipio') ?></th>
<th><?= lang('ClienteDirecciones.provincia') ?></th>
<th><?= lang('ClienteDirecciones.ccaa') ?></th>
<th><?= lang('ClienteDirecciones.pais') ?></th>
<th><?= lang('ClienteDirecciones.telefono') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="tab-pane fade" id="facturacion" role="tabpanel">
@ -803,9 +822,112 @@
} ]
} );
<?=$this->endSection() ?>
<?= $this->section("additionalInlineJs") ?>
/****************************************
Direcciones cliente
*****************************************/
const editor2 = new DataTable.Editor({
ajax: {
url: "<?= route_to('editorOfClienteDirecciones') ?>",
headers: {
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
},
},
table : "#tableOfDireccionesEnvio",
idSrc: 'id',
fields: [ {
name: "att"
}, {
name: "email"
}, {
name: "direccion"
}, {
name: "municipioId"
}, {
name: "provinciaId"
}, {
name: "ccaaId"
}, {
name: "paisId"
}, {
name: "cp"
}, {
name: "telefono"
}, {
"name": "cliente_id",
"type": "hidden"
},
],
template: '#direccionesForm'
});
const lastColNr2 = $('#tableOfDireccionesEnvio').find("tr:first th").length - 1;
var tableDirecciones = $('#tableOfDireccionesEnvio').DataTable( {
draw:2,
serverSide: true,
processing: true,
autoWidth: true,
responsive: true,
order: [[ 0, "asc" ], [ 1, "asc" ]],
pageLength: 10,
lengthChange: false,
searching: false,
paging: true,
info: false,
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfClienteDirecciones') ?>',
data: function ( d ) {
d.cliente_id = id;
},
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columns: [
{ 'data': 'att' },
{ 'data': 'email' },
{ 'data': 'direccion' },
{ 'data': 'municipioId' },
{ 'data': 'provinciaId' },
{ 'data': 'ccaaId' },
{ 'data': 'paisId' },
{ 'data': 'cp' },
{ 'data': 'telefono' },
{
data: actionBtns,
className: 'row-edit dt-center'
}
],
columnDefs: [
{
orderable: false,
searchable: false,
targets: [lastColNr2]
},
{"orderData": [ 0], "targets": 0 },
],
language: {
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
},
buttons: [ {
className: 'btn btn-primary float-end me-sm-3 me-1',
extend: "create",
editor: editor2,
formOptions: {
submitTrigger: -1,
submitHtml: '<i class="ti ti-device-floppy"/>'
}
} ]
} );
<?=$this->endSection() ?>
<?=$this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/datatables-editor/editor.dataTables.min.css') ?>">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.bootstrap5.min.css">
@ -821,5 +943,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.5/vfs_fonts.js" integrity="sha512-cktKDgjEiIkPVHYbn8bh/FEyYxmt4JDJJjOCu5/FQAkW4bc911XtKYValiyzBiJigjVEvrIAyQFEbRJZyDA1wQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="<?= site_url('themes/vuexy/js/datatables-editor/dataTables.editor.min.js') ?>"></script>
<?=$this->endSection() ?>
<?php } ?>