mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
haciendo los eventos
This commit is contained in:
@ -634,6 +634,7 @@ $routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'control
|
||||
|
||||
$routes->group('albaranes', ['namespace' => 'App\Controllers\Pedidos'], function ($routes) {
|
||||
$routes->post('add', 'Albaran::add', ['as' => 'crearAlbaranesPedido']);
|
||||
$routes->post('update/(:any)', 'Albaran::update/$1', ['as' => 'actualizarAlbaran']);
|
||||
});
|
||||
$routes->resource('albaranes', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Albaran', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
@ -55,8 +55,77 @@ class Albaran extends \App\Controllers\BaseResourceController
|
||||
else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id = null){
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
if ($id == null) :
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($id, FILTER_SANITIZE_URL);
|
||||
$albaranEntity = $this->model->find($id);
|
||||
|
||||
if ($albaranEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]);
|
||||
return $this->redirect2listView('sweet-error', $message);
|
||||
endif;
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
// JJO
|
||||
$sanitizedData['user_updated_id'] = auth()->user()->id;
|
||||
|
||||
$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('Pedidos.albaran'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$albaranEntity->fill($sanitizedData);
|
||||
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $albaranEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
|
||||
|
||||
$data = [
|
||||
'error' => 0,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$data = [
|
||||
'error' => 1,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
}
|
||||
else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ class AlbaranEntity extends \CodeIgniter\Entity\Entity
|
||||
'cliente_id' => null,
|
||||
'serie_id' => null,
|
||||
'numero_albaran' => null,
|
||||
'mostar_precios' => null,
|
||||
'mostrar_precios' => null,
|
||||
'total' => null,
|
||||
'direccion_albaran' => null,
|
||||
'att_albaran' => null,
|
||||
@ -34,7 +34,7 @@ class AlbaranEntity extends \CodeIgniter\Entity\Entity
|
||||
'cliente_id' => '?integer',
|
||||
'serie_id' => '?integer',
|
||||
'numero_albaran' => '?string',
|
||||
'mostar_precios' => '?boolean',
|
||||
'mostrar_precios' => '?boolean',
|
||||
'total' => 'float',
|
||||
'direccion_albaran' => '?string',
|
||||
'att_albaran' => '?string',
|
||||
|
||||
@ -67,6 +67,7 @@ return [
|
||||
'imprimirAlbaran' => 'Print',
|
||||
'nuevaLinea' => 'New line',
|
||||
'addIva' => "Add VAT",
|
||||
'mostrarPrecios' => 'Show prices',
|
||||
|
||||
'facturas' => 'Invoices',
|
||||
|
||||
|
||||
@ -66,6 +66,7 @@ return [
|
||||
'imprimirAlbaran' => 'Imprimir',
|
||||
'nuevaLinea' => 'Nueva línea',
|
||||
'addIva' => "Añadir IVA",
|
||||
'mostrarPrecios' => 'Mostrar precios',
|
||||
|
||||
'facturas' => 'Facturas',
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ class AlbaranModel extends \App\Models\BaseModel
|
||||
'cliente_id',
|
||||
'serie_id',
|
||||
'numero_albaran',
|
||||
'mostar_precios',
|
||||
'mostrar_precios',
|
||||
'total',
|
||||
'direccion_albaran',
|
||||
'att_albaran',
|
||||
@ -82,7 +82,7 @@ class AlbaranModel extends \App\Models\BaseModel
|
||||
'cliente_id' => $presupuesto->cliente_id,
|
||||
'serie_id' => 11, // Serie de albaranes
|
||||
'numero_albaran' => $numero_albaran,
|
||||
'mostar_precios' => 0,
|
||||
'mostrar_precios' => 0,
|
||||
'total' => $albaran_linea['total'],
|
||||
'direccion_albaran' => $envio->direccion,
|
||||
'att_albaran' => $envio->att,
|
||||
|
||||
@ -147,7 +147,7 @@ function generarAlbaran(item){
|
||||
<label><?= lang('Pedidos.att') ?>:</label>
|
||||
</div>
|
||||
<div class="col-11">
|
||||
<input id="att_" + ${item.albaran.id} value=${item.albaran.att_albaran} class="form-control"></input>
|
||||
<input id="att_${item.albaran.id}" class="cambios-albaran form-control" albaran_id=${item.albaran.id} value=${item.albaran.att_albaran} class="form-control"></input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 d-flex justify-content-between mb-3">
|
||||
@ -155,13 +155,13 @@ function generarAlbaran(item){
|
||||
<label><?= lang('Pedidos.direccion') ?>:</label>
|
||||
</div>
|
||||
<div class="col-11">
|
||||
<input id="att_" + ${item.albaran.id} value=${item.albaran.direccion_albaran} class="form-control"></input>
|
||||
<input id="direccion_${item.albaran.id}" albaran_id=${item.albaran.id} value=${item.albaran.direccion_albaran} class="cambios-albaran form-control"></input>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const table = $('<table>',
|
||||
{ id: 'tablaAlbaran' + item.albaran_linea.id, width:'100%', class: 'table table-responsive table-striped table-hover' })
|
||||
{ id: 'tablaAlbaran' + item.albaran.id, width:'100%', class: 'table table-responsive table-striped table-hover' })
|
||||
.css({
|
||||
'width': '100%',
|
||||
}).append(
|
||||
@ -187,25 +187,36 @@ function generarAlbaran(item){
|
||||
),
|
||||
);
|
||||
|
||||
let isChecked = item.albaran.mostrar_precios == 1 ? 'checked' : '';
|
||||
const botones_albaran =
|
||||
`
|
||||
<div id="bonotes_albaran" + ${item.albaran.id} class="col-12 d-flex flex-row-reverse mt-4 gap-2">
|
||||
<div id="borrar_albaran" + ${item.albaran.id} class="btn mt-3 button-albaran btn-label-danger waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.borrarAlbaran') ?></span>
|
||||
<i class="ti ti-trash ti-xs"></i>
|
||||
`
|
||||
<div class="row mt-1">
|
||||
<div id="div_mostrar_precios_${item.albaran.id}" class="col-2 d-flex flex-row gap-2">
|
||||
<div class="d-flex align-items-center">
|
||||
<label><?= lang('Pedidos.mostrarPrecios') ?>:</label>
|
||||
</div>
|
||||
<div class="d-flex align-items-center">
|
||||
<input type="checkbox" id="mostrar_precios" name="mostrar_precios" albaran_id=${item.albaran.id} class="mostrar-precios custom-control-input" ${isChecked} >
|
||||
</div>
|
||||
</div>
|
||||
<div id="bonotes_albaran_${item.albaran.id}" class="col-10 d-flex flex-row-reverse gap-2">
|
||||
<div id="borrar_albaran_${item.albaran.id}" class="btn mt-3 button-albaran btn-label-danger waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.borrarAlbaran') ?></span>
|
||||
<i class="ti ti-trash ti-xs"></i>
|
||||
</div>
|
||||
|
||||
<div id="borrar_albaran" + ${item.albaran.id} class="btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.imprimirAlbaran') ?></span>
|
||||
<i class="ti ti-printer ti-xs"></i>
|
||||
</div>
|
||||
<div id="nueva_linea_albaran" + ${item.albaran.id} class="btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.nuevaLinea') ?></span>
|
||||
<i class="ti ti-plus ti-xs"></i>
|
||||
</div>
|
||||
<div id="add_iva_albaran" + ${item.albaran.id} class="btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.addIva') ?></span>
|
||||
<i class="ti ti-plus ti-xs"></i>
|
||||
<div id="borrar_albaran_${item.albaran.id}" class="btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.imprimirAlbaran') ?></span>
|
||||
<i class="ti ti-printer ti-xs"></i>
|
||||
</div>
|
||||
<div id="nueva_linea_albaran_${item.albaran.id}" class="btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.nuevaLinea') ?></span>
|
||||
<i class="ti ti-plus ti-xs"></i>
|
||||
</div>
|
||||
<div id="add_iva_albaran_${item.albaran.id}" class="btn mt-3 btn-label-secondary button-albaran waves-effect waves-light ml-2">
|
||||
<span class="align-middle d-sm-inline-block d-none me-sm-1"><?= lang('Pedidos.addIva') ?></span>
|
||||
<i class="ti ti-plus ti-xs"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
@ -226,7 +237,7 @@ function generarAlbaran(item){
|
||||
|
||||
|
||||
|
||||
const datatableAlbaran = new DataTable('#tablaAlbaran' + item.albaran_linea.id,{
|
||||
const datatableAlbaran = new DataTable('#tablaAlbaran' + item.albaran.id,{
|
||||
scrollX: true,
|
||||
searching: false,
|
||||
paging: false,
|
||||
@ -402,14 +413,18 @@ function generarAlbaran(item){
|
||||
{ targets: [1], orderable: false },
|
||||
{ targets: [2, 3, 4, 5, 6, 7, 8, 9], className: 'dt-center' }
|
||||
],
|
||||
});
|
||||
initComplete: function(settings){
|
||||
var numColumns = this.api().columns().count();
|
||||
if(item.albaran.mostrar_precios == 0){
|
||||
this.api().column(numColumns - 1).visible(false);
|
||||
this.api().column(numColumns - 2).visible(false);
|
||||
} else {
|
||||
this.api().column(numColumns - 1).visible(true);
|
||||
this.api().column(numColumns - 2).visible(true);
|
||||
}
|
||||
|
||||
|
||||
/*var nuevaFila = [
|
||||
item.algunDato1, // Reemplaza estos valores con los datos reales de tu objeto
|
||||
item.algunDato2,
|
||||
// Añade tantos elementos como columnas tenga tu tabla
|
||||
];*/
|
||||
}
|
||||
});
|
||||
|
||||
// Añadir la nueva fila a la tabla
|
||||
datatableAlbaran.row.add(item.albaran_linea).draw();
|
||||
@ -417,4 +432,66 @@ function generarAlbaran(item){
|
||||
|
||||
}
|
||||
|
||||
$(document).on('change', '.cambios-albaran', function(){
|
||||
var elementId = $(this).attr('id');
|
||||
|
||||
data = {
|
||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
||||
};
|
||||
data[elementId.split('_')[0] + '_albaran'] = $(this).val();
|
||||
|
||||
var albaran_id = $(this).attr('albaran_id');
|
||||
var url = '<?= route_to('actualizarAlbaran', ':id') ?>';
|
||||
url = url.replace(':id', albaran_id );
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
success: function(response){
|
||||
|
||||
if('error' in response){
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$(document).on('change', '.mostrar-precios', function(){
|
||||
|
||||
var checked = $(this).prop('checked');
|
||||
|
||||
var albaran_id = $(this).attr('albaran_id');
|
||||
var table = $('#tablaAlbaran' + albaran_id).DataTable();
|
||||
|
||||
var url = '<?= route_to('actualizarAlbaran', ':id') ?>';
|
||||
url = url.replace(':id', albaran_id );
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
mostrar_precios: checked?1:0,
|
||||
<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v,
|
||||
},
|
||||
success: function(response){
|
||||
|
||||
if('error' in response){
|
||||
if(response.error == 0){
|
||||
if(checked){
|
||||
table.column(9).visible(true);
|
||||
table.column(8).visible(true);
|
||||
} else {
|
||||
table.column(9).visible(false);
|
||||
table.column(8).visible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
Reference in New Issue
Block a user