presupuestos direcciones!

This commit is contained in:
Jaime Jiménez
2023-12-18 15:29:10 +01:00
parent c435ba5a9f
commit 01d27ec480
13 changed files with 297 additions and 82 deletions

View File

@ -479,6 +479,7 @@ $routes->resource('ClienteContactos', ['namespace' => 'App\Controllers\Clientes'
$routes->group('clientedirecciones', ['namespace' => 'App\Controllers\Clientes'], function ($routes) {
$routes->get('delete/(:num)', 'Clientedirecciones::delete/$1', ['as' => 'deleteClientedirecciones']);
$routes->post('datatable', 'Clientedirecciones::datatable', ['as' => 'dataTableOfClienteDirecciones']);
$routes->post('datatable_editor', 'Clientedirecciones::datatable_editor', ['as' => 'editorOfClienteDirecciones']);
});
@ -523,6 +524,10 @@ $routes->group('serviciospreimpresiones', ['namespace' => 'App\Controllers\Presu
$routes->post('edit/(:num)', 'Presupuestopreimpresiones::edit/$1', ['as' => 'updatePresupuestopreimpresiones']);
});
$routes->group('presupuestodirecciones', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) {
$routes->post('datatable', 'Presupuestodirecciones::datatable', ['as' => 'dataTableOfPresupuestoDirecciones']);
});
$routes->group('printpresupuestos', ['namespace' => 'App\Controllers\Pdf'], function ($routes) {
$routes->get('', 'PrintPresupuestos::index', ['as' => 'viewPresupuesto']);
$routes->get('generar', 'PrintPresupuestos::generar', ['as' => 'presupuestoToPdf']);

View File

@ -22,11 +22,7 @@ class Clientedirecciones extends \App\Controllers\GoBaseResourceController
protected static $controllerSlug = 'clientedirecciones';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
$this->soft_delete = false;
$this->viewData = ['usingServerSideDataTable' => true]; // JJO
}
public function datatable()

View File

@ -7,6 +7,7 @@ use App\Entities\Configuracion\Maquina;
use App\Models\Collection;
use App\Entities\Presupuestos\PresupuestoEntity;
use App\Models\Presupuestos\PresupuestoDireccionesModel;
use App\Models\Configuracion\PapelGenericoModel;
use App\Models\Presupuestos\PresupuestoModel;
@ -288,6 +289,9 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController
$this->viewData['serviciosManipuladoList'] = (new PresupuestoManipuladosModel())->getResource($id)->get()->getResultObject();
$this->viewData['serviciosPreimpresionList'] = (new PresupuestoPreimpresionesModel())->getResource($id)->get()->getResultObject();
// Direciones presupuesto
$this->viewData['presupuestoDirecciones'] = (new PresupuestoDireccionesModel())->getResource("",$id)->get()->getResultObject();
$this->viewData['POD'] = $this->getPOD();
$this->viewData['tipo_impresion_id'] = 4; // Cosido tapa blanda JJO

View File

@ -0,0 +1,70 @@
<?php namespace App\Controllers\Presupuestos;
use App\Controllers\GoBaseResourceController;
use App\Models\Collection;
use App\Models\Presupuestos\PresupuestoDireccionesModel;
class Presupuestodirecciones extends \App\Controllers\GoBaseResourceController
{
protected $modelName = PresupuestoDireccionesModel::class;
protected $format = 'json';
protected static $singularObjectName = 'Presupuesto direcciones';
protected static $singularObjectNameCc = 'presupuestoDirecciones';
protected static $pluralObjectName = 'Presupuestos direcciones';
protected static $pluralObjectNameCc = 'presupuestosDirecciones';
protected static $controllerSlug = 'presupuesto-direcciones';
protected static $viewPath = 'themes/backend/vuexy/form/presupuestos/';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
}
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 = 30;
$search = $reqData['search']['value'];
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
$order = PresupuestoDireccionesModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$id_P = $reqData['presupuesto_id'] ?? -1;
$resourceData = $this->model->getResource($search, $id_P)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResource()->countAllResults(),
$this->model->getResource("", $id_P)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}

View File

@ -17,9 +17,9 @@ class Test extends BaseController
public function index()
{
$model = model('App\Models\Clientes\ClienteDireccionesModel');
$model = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
echo '<pre>';
var_dump($model->getResource("", 1420)->get()->getResultArray());
var_dump($model->getResource("", 8)->get()->getResultObject());
echo '</pre>';
}

View File

@ -15,11 +15,12 @@ class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity
"direccion" => null,
"pais_id" => null,
"ccaa_id" => null,
"provincia_id" => null,
"municipio_id" => null,
"provincia" => null,
"municipio" => null,
"cp" => null,
"telefono" => null,
"precio" => null,
"margen" => null,
];
protected $casts = [
"presupuesto_id" => "int",
@ -27,9 +28,9 @@ class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity
"peso" => "float",
"pais_id" => "int",
"ccaa_id" => "int",
"provincia_id" => "int",
"municipio_id" => "int",
"cp" => "int",
"precio" => "float",
"margen" => "float",
];
}

View File

@ -0,0 +1,27 @@
<?php
return [
'nuevaTitle' => 'New address',
'alias' => 'Alias',
'att' => 'Attn.',
'email' => 'Email',
'direccion' => 'Address',
'cp' => 'Zip Code',
'municipio' => 'Town',
'provincia' => 'City',
'ccaa' => 'Region',
'pais' => 'Country',
'telefono' => 'Phone',
'peso' => 'Weight',
'cantidad' => 'Quantity',
'precio' => 'Price',
'validation' => [
'max_length' => 'Max. length ',
'required' => 'Field required'
'valid_email' => 'The email is not valid',
],
'selectPais' => 'Select a country',
];

View File

@ -180,6 +180,8 @@ return [
// Envios
'envios' => 'Envios',
'recogerEnTaller' => 'Recoger en taller',
'cantidad' => 'Cantidad',
@ -335,7 +337,7 @@ return [
'presupuesto' => 'Presupuesto',
'presupuestoList' => 'Presupuesto List',
'presupuestos' => 'Presupuestos',
'recogerEnTaller' => 'Recoger EN Taller',
'referenciaCliente' => 'Referencia Cliente',
'responsable' => 'Responsable',
'serieId' => 'Serie ID',

View File

@ -0,0 +1,30 @@
<?php
return [
'nuevaTitle' => 'Añadir nueva dirección',
'alias' => 'Alias',
'att' => 'Att.',
'email' => 'Email',
'direccion' => 'Direccion',
'cp' => 'CP',
'municipio' => 'Ciudad',
'provincia' => 'Provincia',
'ccaa' => 'CCAA',
'pais' => 'País',
'telefono' => 'Teléfono',
'peso' => 'Peso',
'cantidad' => 'Cantidad',
'precio' => 'Precio',
'validation' => [
'max_length' => 'Max. valor caracteres alcanzado',
'required' => 'Campo obligatorio',
'valid_email' => 'El email introducido no es válido',
],
'selectPais' => 'Seleccione País',
'selectCcaa' => 'Seleccione CCAA',
'selectProvincia' => 'Seleccione Provincia',
'selectMunicipio' => 'Seleccione Municipio',
];

View File

@ -19,10 +19,11 @@ class ClienteDireccionesModel extends \App\Models\GoBaseModel
2 => "t1.email",
3 => "t1.direccion",
4 => "t1.cp",
5 => "t5.municipio_nombre",
6 => "t4.nombre",
7 => "t3.nombre",
8 => "t1.telefono",
5 => "t1.municipio",
6 => "t1.provincia",
7 => "t4.nombre",
8 => "t3.nombre",
9 => "t1.telefono",
];
protected $allowedFields = [

View File

@ -0,0 +1,89 @@
<?php
namespace App\Models\Presupuestos;
class PresupuestoDireccionesModel extends \App\Models\GoBaseModel
{
protected $table = "presupuesto_direcciones";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
const SORTABLE = [
0 => "t1.cantidad",
1 => "t1.att",
2 => "t1.email",
3 => "t1.direccion",
4 => "t1.cp",
5 => "t1.municipio",
6 => "t1.provincia",
7 => "t2.nombre",
8 => "t1.telefono",
];
protected $allowedFields = [
"presupuesto_id",
"cantidad",
"peso",
"att",
"email",
"direccion",
"pais_id",
"ccaa_id",
"provincia",
"municipio",
"cp",
"telefono",
'precio',
'margen',
];
protected $returnType = "App\Entities\Clientes\ClienteDireccionesEntity";
public static $labelField = "id";
/**
* Get resource data.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "", $presupuesto_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.presupuesto_id AS presupuesto_id, t1.att AS att,
t1.email AS email, t1.direccion AS direccion, t1.pais_id AS pais_id, t2.nombre AS pais,
t1.ccaa_id AS ccaa_id, t3.nombre AS ccaa_nombre,
t1.municipio AS municipio, t1.provincia AS provincia, t1.cp AS cp, t1.telefono AS telefono,
t1.cantidad AS cantidad, t1.precio AS precio, t1.margen AS margen"
);
$builder->where('t1.presupuesto_id', $presupuesto_id);
$builder->join("lg_paises t2", "t1.pais_id = t2.id", "left");
$builder->join("lg_comunidades_autonomas t3", "t1.ccaa_id = t3.id", "left");
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.att", $search)
->orLike("t1.email", $search)
->orLike("t1.direccion", $search)
->orLike("t2.nombre", $search)
->orLike("t3.nombre", $search)
->orLike("t1.municipio", $search)
->orLike("t1.provincia", $search)
->orLike("t1.cp", $search)
->orLike("t1.telefono", $search)
->groupEnd();
}
}

View File

@ -967,7 +967,7 @@ var tableDirecciones = $('#tableOfDireccionesEnvio').DataTable( {
processing: true,
autoWidth: true,
responsive: true,
order: [[ 0, "asc" ], [ 1, "asc" ]],
order: [0, "asc" ],
pageLength: 10,
lengthChange: false,
searching: false,
@ -1060,7 +1060,7 @@ $(document).on('click', '.btn-delete-add', function(e) {
function delete_direccion_envio(dataId){
$.ajax({
url: `/clientedirecciones/delete/${dataId}`,
url: `/clientes/clientedirecciones/delete/${dataId}`,
method: 'GET',
}).done((data, textStatus, jqXHR) => {
$('#confirm2delete').modal('toggle');

View File

@ -1,39 +1,50 @@
<div class="accordion mt-3" id="accordionDatosLibro">
<div class="accordion mt-3" id="accordionEnvios">
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingOne">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionDatosLibroTip" aria-expanded="false" aria-controls="accordionDatosLibroTip">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionEnviosTip" aria-expanded="false" aria-controls="accordionEnviosTip">
<h4><?= lang("Presupuestos.envios") ?></h4>
</button>
</h2>
<table id="tableOfDireccionesEnvio" class="table dt-responsive dataTable" style="width: 100%;">
<thead>
<tr>
<th><?= lang('Presupuestos.cantidad') ?></th>
<th><?= lang('Presupuestos.peso') ?></th>
<th><?= lang('Presupuestos.att') ?></th>
<th><?= lang('Presupuestos.email') ?></th>
<th><?= lang('Presupuestos.direccion') ?></th>
<th><?= lang('Presupuestos.paisiD') ?></th>
<th><?= lang('Presupuestos.ccaa') ?></th>
<th><?= lang('Presupuestos.provincia') ?></th>
<th><?= lang('Presupuestos.municipio') ?></th>
<th><?= lang('Presupuestos.cp') ?></th>
<th><?= lang('Presupuestos.telefono') ?></th>
<th><?= lang('Presupuestos.precio') ?></th>
<th></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div id="accordionDatosLibroTip" class="accordion-collapse collapse show" data-bs-parent="#accordionDatosLibro">
<div id="accordionEnviosTip" class="accordion-collapse collapse show" data-bs-parent="#accordionEnvios">
<div class="accordion-body">
<table id="tableOfDireccionesEnvio" class="table dt-responsive dataTable px-4" style="width: 100%;">
<thead>
<tr>
<th><?= lang('PresupuestosDirecciones.cantidad') ?></th>
<th><?= lang('PresupuestosDirecciones.peso') ?></th>
<th><?= lang('PresupuestosDirecciones.att') ?></th>
<th><?= lang('PresupuestosDirecciones.email') ?></th>
<th><?= lang('PresupuestosDirecciones.direccion') ?></th>
<th><?= lang('PresupuestosDirecciones.cp') ?></th>
<th><?= lang('PresupuestosDirecciones.municipio') ?></th>
<th><?= lang('PresupuestosDirecciones.provincia') ?></th>
<th><?= lang('PresupuestosDirecciones.ccaa') ?></th>
<th><?= lang('PresupuestosDirecciones.pais') ?></th>
<th><?= lang('PresupuestosDirecciones.telefono') ?></th>
<th><?= lang('PresupuestosDirecciones.precio') ?></th>
<th></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="row">
<div class="col-md-12 col-lg-4 px-4 py-2">
<input class="form-check-input" type="checkbox" id="recoger_en_taller" name="recoger_en_taller" value="1" <?= $presupuestoEntity->recoger_en_taller == true ? 'checked' : ''; ?> >
<label class="form-check-label" for="recoger_en_taller"><?= lang('Presupuestos.recogerEnTaller') ?></label>
</div>
</div>
<div class="row">
<div class="col-md-12 col-lg-4 px-4 py-2">
<button id="insertar_direccion" type="button" class="btn btn-secondary waves-effect waves-light float-start"><?= lang("Presupuestos.insertar")?></button>
</div>
</div>
</div> <!-- //.accordion-body -->
</div> <!-- //.accordion-collapse -->
</div> <!-- //.accordion-item -->
@ -43,9 +54,10 @@
<!-- Código JS comportamiento general pag. -->
<!------------------------------------------->
<?= $this->section("additionalInlineJs") ?>
const lastColNr = $('#tableOfDireccionesEnvio').find("tr:first th").length - 1;
const actionBtns = function(data) {
const actionBtns_direcciones = function(data) {
return `
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}" data-bs-toggle="modal" data-bs-target="#confirm2delete"></i></a>
@ -54,20 +66,20 @@ const actionBtns = function(data) {
};
var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
draw:4,
draw:5,
serverSide: true,
processing: true,
autoWidth: true,
responsive: true,
order: [[ 0, "asc" ], [ 1, "asc" ]],
pageLength: 10,
order: [[ 0, "asc" ]],
pageLength: 20,
lengthChange: false,
searching: false,
paging: true,
paging: false,
info: false,
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfPresupuestosenvios') ?>',
url: '<?= route_to('dataTableOfPresupuestoDirecciones') ?>',
data: function ( d ) {
d.presupuesto_id = id;
},
@ -81,16 +93,16 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
{ 'data': 'att' },
{ 'data': 'email' },
{ 'data': 'direccion' },
{ 'data': 'paisId' },
{ 'data': 'ccaaId' },
{ 'data': 'provinciaId' },
{ 'data': 'municipioId' },
{ 'data': 'cp' },
{ 'data': 'municipio' },
{ 'data': 'provincia' },
{ 'data': 'ccaaId' },
{ 'data': 'paisId' },
{ 'data': 'telefono' },
{ 'data': 'precio' },
{ 'data': 'margen' },
{
data: actionBtns,
data: actionBtns_direcciones,
className: 'row-edit dt-center'
}
],
@ -100,34 +112,12 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
searchable: false,
targets: [lastColNr]
},
{"orderData": [ 0, 1 ], "targets": 0 },
{"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: "createInline",
editor: editor3,
formOptions: {
submitTrigger: -1,
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
},
action: function ( e, dt, node, config ) {
if(selected_tirada_id == -1){
popErrorAlert("<?= lang('TarifaEncuadernacionLineas.validation.error_seleccion_tiradas') ?>");
}
else{
formOptions= {
submitTrigger: -1,
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
};
editor3.inlineCreate(config.position, formOptions);
}
},
} ]*/
} );
<?= $this->endSection() ?>