terminado plantillas

This commit is contained in:
Jaime Jiménez
2024-01-02 21:01:42 +01:00
parent 0abdb7efac
commit a54838d468
12 changed files with 250 additions and 37 deletions

View File

@ -445,12 +445,12 @@ class Cliente extends \App\Controllers\GoBaseResourceController
$modelPreciosCliente = model('App\Models\Clientes\ClientePreciosModel');
$plantilla_id = $modelPreciosCliente->get_plantilla_precios($cliente_id);
if (is_null($plantilla_id)){
return [];
return null;
}
$modelPlantillaPreciosCliente = model('App\Models\Clientes\ClientePlantillaPreciosModel');
$plantilla = $modelPlantillaPreciosCliente->find($plantilla_id);
$plantilla = $modelPlantillaPreciosCliente->where("id", $plantilla_id)->where("is_deleted", 0)->first();
if ($plantilla == false){
return [];
return null;
}
else{
return (object)array(

View File

@ -66,6 +66,32 @@ class Clienteplantillaprecios extends \App\Controllers\GoBaseResourceController
}
// Este metodo aqui se usa para poner el is_deleted a 1 cuando se borra una
// plantilla desde la lista
public function update($requestedId = null)
{
$requestMethod = $this->request->getMethod();
if ($requestMethod === 'post') :
if ($requestedId == null) :
return;
endif;
$model = model('App\Models\Clientes\ClientePlantillaPreciosLineasModel');
$model->delete_values($requestedId);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
$csrfTokenName => $newTokenHash
];
return $this->respond($data);
endif; // ($requestMethod === 'post')
}
public function add()
{
// JJO
@ -79,6 +105,8 @@ class Clienteplantillaprecios extends \App\Controllers\GoBaseResourceController
$postData = $this->request->getPost();
$cliente_id = $postData['cliente_id'] ?? -1;
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO
@ -108,16 +136,25 @@ class Clienteplantillaprecios extends \App\Controllers\GoBaseResourceController
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if($cliente_id != -1){
$modelLineas = model('App\Models\Clientes\ClientePlantillaPreciosLineasModel');
$modelLineas->copy_from_cliente($cliente_id, $id);
$modelClientePrecios = model('App\Models\Clientes\ClientePreciosModel');
$modelClientePrecios->set_plantilla_id($cliente_id, $id);
return ;
}
else{
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
//return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
return redirect()->to(site_url('/clientes/clientesplantillaprecios/edit/' . $id))->with('message', $message);
return redirect()->to(site_url('/clientes/clienteplantillaprecios/edit/' . $id))->with('message', $message);
else:
return $this->redirect2listView('sweet-success', $message);
endif;
else:
$this->session->setFlashData('sweet-success', $message);
endif;
}
endif; // $noException && $successfulResult

View File

@ -47,6 +47,39 @@ class Clienteplantillaprecioslineas extends \App\Controllers\GoBaseResourceContr
}
public function update($requestedId = null){
$requestMethod = $this->request->getMethod();
if ($requestMethod === 'post') :
if ($requestedId == null) :
return;
endif;
$postData = $this->request->getJSON();
$plantilla_id = $postData->plantilla_id ?? -1;
// Se ha actualizado un registro por lo que no es una plantilla
if($plantilla_id == -1){
$this->model->clean_plantilla_id($requestedId);
}
else{
$this->model->copy_from_plantilla($requestedId, $plantilla_id);
}
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
$csrfTokenName => $newTokenHash
];
return $this->respond($data);
endif; // ($requestMethod === 'post')
}
public function datatable()

View File

@ -45,7 +45,6 @@ class ClientePrecios extends \App\Controllers\GoBaseResourceController
parent::initController($request, $response, $logger);
}
public function update($requestedId = null)
{
$requestMethod = $this->request->getMethod();
@ -80,10 +79,6 @@ class ClientePrecios extends \App\Controllers\GoBaseResourceController
}
public function datatable()
{
if ($this->request->isAJAX()) {
@ -136,6 +131,7 @@ class ClientePrecios extends \App\Controllers\GoBaseResourceController
$response = Editor::inst( $db, 'cliente_precios' )
->fields(
Field::inst( 'plantilla_id' ),
Field::inst( 'cliente_id' ),
Field::inst( 'tipo' ),
Field::inst( 'tipo_maquina' ),
Field::inst( 'tipo_impresion' ),
@ -215,9 +211,6 @@ class ClientePrecios extends \App\Controllers\GoBaseResourceController
->field('updated_at')
->setValue($datetime->format('Y-m-d H:i:s'));
})
->on('postCreate', function ($editor,$id, $values, $row ) {
$this->model->clean_plantilla_id($values['cliente_id']);
})
->debug(true)
->process($_POST)
->data();

View File

@ -10,6 +10,9 @@ return [
'plantilla_id' => 'Template ID',
'plantilla' => 'Prices template',
'convertir2plantilla' => 'Convert to template',
'convertir2plantillaText' => 'You have selected to convert the customer\'s current pricing table as a template.',
'convertir2plantillaText2' => 'Next, type the name for the template and hit Save',
'nombrePlantilla' => 'Name for the template',
'tipo' => 'Type',
'tipo_maquina' => 'Machine type',
'tipo_impresion' => 'Print type',
@ -37,10 +40,11 @@ return [
'required' => 'Field required',
'decimal' => 'Decimal number',
],
'errors' => [
'error_tiempo_range' => 'The field Min Time must be lower than the field Max Time',
'error_tiempo_overlap' => 'The range [Min Time, Max Time] is overlapped with another one for the selected type.',
]
'error_nombre_template' => 'The template name is required'
],
}
];

View File

@ -10,6 +10,9 @@ return [
'plantilla_id' => 'Plantilla ID',
'plantilla' => 'Plantilla de precios',
'convertir2plantilla' => 'Convertir a plantilla',
'convertir2plantillaText' => 'Ha seleccionado convertir la tabla de precios actual del cliente como una plantilla.',
'convertir2plantillaText2' => 'A continuación, escriba el nombre para la plantilla y pulse Guardar',
'nombrePlantilla' => 'Nombre para la plantilla',
'tipo' => 'Tipo',
'tipo_maquina' => 'Tipo de máquina',
'tipo_impresion' => 'Tipo de impresión',
@ -39,6 +42,7 @@ return [
'errors' => [
'error_tiempo_range' => 'El campo Tiempo Mín debe ser menor que el campo Tiempo Máx',
'error_tiempo_overlap' => 'El rango [Tiempo Min, Tiempo Máx] se solapa con otro con los mismos parámetros.',
'error_nombre_template' => 'El nombre de la plantilla es obligatorio'
]
];

View File

@ -111,6 +111,15 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\GoBaseModel
];
function delete_values($plantilla_id = 0){
$this->db
->table($this->table . " t1")
->where('t1.plantilla_id', $plantilla_id)
->set('is_deleted', 1)
->update();
}
/**
* Get resource data.
*
@ -171,4 +180,32 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\GoBaseModel
return "";
}
function copy_from_cliente($cliente_id = 0, $plantilla_id = 0){
$session = session();
$datetime = (new \CodeIgniter\I18n\Time("now"));
$date_value = $datetime->format('Y-m-d H:i:s');
// Se cargan los valores en la plantilla
$clientePreciosModel = model('App\Models\Clientes\ClientePreciosModel');
$values = $clientePreciosModel->getResource($cliente_id)->get()->getResultObject();
foreach ($values as $value) {
$this->db
->table($this->table . " t1")
->set('plantilla_id', $plantilla_id)
->set('tipo', $value->tipo)
->set('tipo_maquina', $value->tipo_maquina)
->set('tipo_impresion', $value->tipo_impresion)
->set('tiempo_min', $value->tiempo_min)
->set('tiempo_max', $value->tiempo_max)
->set('margen', $value->margen)
->set('user_updated_id', $session->id_user)
->set('updated_at', $date_value)
->insert();
}
}
}

View File

@ -119,12 +119,21 @@ class ClientePreciosModel extends \App\Models\GoBaseModel
->update();
}
function set_plantilla_id($cliente_id = 0, $plantilla_id = null){
$this->db
->table($this->table . " t1")
->where('cliente_id', $cliente_id)
->set('plantilla_id', $plantilla_id)
->update();
}
function delete_values($cliente_id = 0){
$this->db
->table($this->table . " t1")
->where('cliente_id', $cliente_id)
->delete();
->set('is_deleted', 1)
->update();
}
function copy_from_plantilla($cliente_id = 0, $plantilla_id = 0){

View File

@ -567,7 +567,7 @@
<?php if ($formAction !== site_url('cliente/add')){ ?>
<div class="tab-pane fade" id="tarifascliente" role="tabpanel">
<?= view("themes/backend/vuexy/form/clientes/cliente/convert2templateModal") ?>
<div class='row'>
<div class="col-md-12 col-lg-4 px-4">
<div class="mb-3">
@ -1055,6 +1055,19 @@ else{
})
})
editorPrecios.on ('postCreate', function ( e, json, data, action ) {
const domain = window.location.origin
fetch(domain + "/clientes/clienteprecios/update/" + id , {
method: "POST",
body: JSON.stringify({
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
})
var theTablePrecios = $('#tableOfPrecios').DataTable( {
serverSide: true,
processing: true,
@ -1153,15 +1166,12 @@ else{
} ]
} );
theTablePrecios.on( 'draw', function () {
if(theTablePrecios.rows().count()){
$('#plantillas').select2('data', { id: theTablePrecios.row(0).data().plantilla_id , label:'plantilla'});
$('#plantillas').val(theTablePrecios.row(0).data().plantilla_id)
console.log(theTablePrecios.row(0).data().plantilla_id)
const initPrecioTemplate = <?php echo json_encode($precioTemplate);?>;
if(initPrecioTemplate != null){
var newOption = new Option(initPrecioTemplate.label, initPrecioTemplate.value, false, false);
$('#plantillas').append(newOption);
}
} );
// Activate an inline edit on click of a table cell
@ -1198,9 +1208,6 @@ else{
}
}
$('#plantillas').select2('data', {id:103, label:'ENABLED_FROM_JS'});
$('#plantillas').val(103).trigger();
$('#plantillas').on('change.select2', function(){
const data = $('#plantillas').select2('data');
@ -1223,6 +1230,14 @@ else{
}
});
$('#convert2template').on('click', function(){
var newAddDialog = $('#convert2Template')
newAddDialog.modal("show");
})
<?= $this->endSection() ?>

View File

@ -0,0 +1,65 @@
<div id="convert2Template" class="modal fade addModal">
<div class="modal-dialog modal-lg modal-simple">
<div class="modal-content">
<div class="modal-header">
<h4 id="labelTitleConfirmDialog" class="modal-title"><?= lang('ClientePrecios.convertir2plantilla') ?></h4>
</div>
<div class="modal-body">
<div id='error-nombre'></div>
<div class="mb-3">
<p><?= lang('ClientePrecios.convertir2plantillaText') ?></p>
<p><?= lang('ClientePrecios.convertir2plantillaText2') ?></p>
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="nombre_plantilla" class="form-label">
<?= lang('ClientePrecios.nombrePlantilla') ?>
</label>
<input type="text" id="nombre_plantilla" maxLength="100" class="form-control new-address">
</div><!--//.mb-3 -->
</div>
<div class="modal-footer">
<button id="saveTemplate"
type="button"
class="btn btn-primary"
><?= lang('App.global_save') ?></button>
<button id="cancelTemplate"
type="button"
class="btn btn-default"
><?= lang('App.user_delete_btn_cancel') ?></button>
</div>
</div>
</div>
</div>
<?= $this->section("additionalInlineJs") ?>
$('#saveTemplate').on('click', function(){
if($('#nombre_plantilla').val().length == 0){
popErrorAlert('<?= lang('ClientePrecios.errors.error_nombre_template') ?>', 'error-nombre')
}
else{
data = new FormData();
data.append('cliente_id', id)
data.append('nombre', $('#nombre_plantilla').val())
data.append('<?= csrf_token() ?? "token" ?>', <?= csrf_token() ?>v)
fetch('<?= route_to("createClienteplantillaprecios");?>' , {
method: "POST",
body: data,
})
.then(data => {
$('#convert2Template').modal("hide");
var newOption = new Option($('#nombre_plantilla').val(), "", false, false);
$('#plantillas').append(newOption);
$('#nombre_plantilla').val("");
})
}
})
$('#cancelTemplate').on('click', function(){
$('#convert2Template').modal("hide");
})
<?=$this->endSection() ?>

View File

@ -41,8 +41,11 @@
{ e.preventDefault()
if($('#addressForm').hasClass('show')){
$("#saveAdd").click();
}else{
}
else if ($('#convert2Template').hasClass('show')){
$("#saveTemplate").click();
}
else{
$('#saveForm').click();
}
}

View File

@ -86,6 +86,19 @@
$('#confirm2delete').modal('toggle');
tablePLantillaPrecios.clearPipeline();
tablePLantillaPrecios.row($(row)).invalidate().draw();
// Se borran las lineas asociadas
const domain = window.location.origin
fetch(domain + "/clientes/clienteplantillaprecios/update/" + dataId , {
method: "POST",
body: JSON.stringify({
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
popSuccessAlert(data.msg ?? jqXHR.statusText);
}).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error)