mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
servicios desdoblados en presupuesto admin
This commit is contained in:
@ -137,10 +137,21 @@ class Presupuestoacabados extends \App\Controllers\BaseResourceController
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$values = $this->model->getPrecioTarifa($tarifa_acabado_id, $tirada, $proveedor_id, $POD);
|
||||
$data = [];
|
||||
|
||||
$model = model('App\Models\Tarifas\Acabados\TarifasAcabadoServiciosAcabadoModel');
|
||||
$tarifas = $model->getTarifasForServicio($tarifa_acabado_id);
|
||||
|
||||
foreach ($tarifas as $tarifa) {
|
||||
$values = $this->model->getPrecioTarifa($tarifa, $tirada, $proveedor_id, $POD);
|
||||
$values[0]->tarifa_id = $tarifa;
|
||||
array_push($data, $values[0]);
|
||||
}
|
||||
|
||||
//$values = $this->model->getPrecioTarifa($tarifa_acabado_id, $tirada, $proveedor_id, $POD);
|
||||
|
||||
$data = [
|
||||
'values' => $values,
|
||||
'values' => $data,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
|
||||
@ -157,26 +168,31 @@ class Presupuestoacabados extends \App\Controllers\BaseResourceController
|
||||
|
||||
$cubierta = $this->request->getGet("cubierta") ?? 0;
|
||||
$sobrecubierta = $this->request->getGet("sobrecubierta") ?? 0;
|
||||
$cliente = $this->request->getGet("cliente") ?? 0;
|
||||
|
||||
$model = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel');
|
||||
$model = model('App\Models\Tarifas\Acabados\ServicioAcabadoModel');
|
||||
$query = $model->builder()->select(
|
||||
[
|
||||
"id",
|
||||
"nombre as name"
|
||||
]
|
||||
)
|
||||
->where("lg_tarifa_acabado.is_deleted", 0)
|
||||
->where("lg_tarifa_acabado.mostrar_en_presupuesto", 1);
|
||||
->where("servicios_acabado.deleted_at", null);
|
||||
|
||||
|
||||
if($cubierta == 1){
|
||||
$query->where("lg_tarifa_acabado.acabado_cubierta", 1);
|
||||
$query->where("servicios_acabado.acabado_cubierta", 1);
|
||||
}
|
||||
else if ($sobrecubierta == 1){
|
||||
$query->where("lg_tarifa_acabado.acabado_sobrecubierta", 1);
|
||||
$query->where("servicios_acabado.acabado_sobrecubierta", 1);
|
||||
}
|
||||
|
||||
if ($cliente == 1) {
|
||||
$query->where("servicios_acabado.mostrar_en_presupuesto_cliente", 1);
|
||||
}
|
||||
if ($this->request->getGet("q")) {
|
||||
$query->groupStart()
|
||||
->orLike("lg_tarifa_acabado.nombre", $this->request->getGet("q"))
|
||||
->orLike("servicios_acabado.nombre", $this->request->getGet("q"))
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ class ServiciosAcabado extends BaseResourceController
|
||||
// Breadcrumbs
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("App.menu_tarifas"), 'route' => "javascript:void(0);", 'active' => false],
|
||||
['title' => lang("App.menu_Servicioacabado"), 'route' => site_url('tarifas/acabados'), 'active' => true]
|
||||
['title' => lang("App.menu_servicioAcabado"), 'route' => route_to('serviciosAcabadoList'), 'active' => true]
|
||||
];
|
||||
|
||||
helper("time");
|
||||
@ -61,12 +61,96 @@ class ServiciosAcabado extends BaseResourceController
|
||||
return view(static::$viewPath . 'viewServiciosAcabadoList', $viewData);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
|
||||
checkPermission('tarifa-acabado.create', $this->indexRoute);
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$tarifasSeleccionadas = $postData['tarifasAcabado'] ?? [];
|
||||
unset($postData['tarifasAcabado']);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$sanitizedData['user_updated_id'] = auth()->user()->id;
|
||||
|
||||
if ($this->request->getPost('mostrar_en_presupuesto_cliente') == null) {
|
||||
$sanitizedData['mostrar_en_presupuesto'] = false;
|
||||
}
|
||||
|
||||
if ($this->request->getPost('acabado_cubierta') == null) {
|
||||
$sanitizedData['acabado_cubierta'] = false;
|
||||
}
|
||||
|
||||
if ($this->request->getPost('acabado_sobrecubierta') == null) {
|
||||
$sanitizedData['acabado_sobrecubierta'] = false;
|
||||
}
|
||||
|
||||
$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')]) . '.';
|
||||
|
||||
$modelTable = model("App\Models\Tarifas\Acabados\TarifasAcabadoServiciosAcabadoModel");
|
||||
|
||||
foreach ($tarifasSeleccionadas as $tarifaId) {
|
||||
$modelTable->insert(['servicio_id' => $id, 'tarifa_id' => $tarifaId, 'user_updated_id' => auth()->user()->id]);
|
||||
}
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(site_url('/serviciosacabado/edit/' . $id))->with('message', $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['tarifasSeleccionadas'] = [];
|
||||
$this->viewData['servicio'] = isset($sanitizedData) ? new ServicioAcabadoEntity($sanitizedData) : new ServicioAcabadoEntity();
|
||||
$this->viewData['formAction'] = route_to('createServicioAcabado');
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('ServicioAcabado.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
}
|
||||
|
||||
|
||||
public function edit($requestedId = null)
|
||||
{
|
||||
|
||||
checkPermission('tarifa-acabado.edit', $this->indexRoute);
|
||||
|
||||
if ($requestedId == null):
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
@ -84,6 +168,9 @@ class ServiciosAcabado extends BaseResourceController
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$tarifasSeleccionadas = $postData['tarifasAcabado'] ?? [];
|
||||
unset($postData['tarifasAcabado']);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$sanitizedData['user_updated_id'] = auth()->user()->id;
|
||||
@ -113,13 +200,20 @@ class ServiciosAcabado extends BaseResourceController
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifaacabado.tarifaacabado'))]);
|
||||
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ServicioAcabado.servicioacabado'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$servicio->fill($sanitizedData);
|
||||
|
||||
$modelTable = model("App\Models\Tarifas\Acabados\TarifasAcabadoServiciosAcabadoModel");
|
||||
|
||||
$modelTable->where('servicio_id',$id)->delete();
|
||||
foreach ($tarifasSeleccionadas as $tarifaId) {
|
||||
$modelTable->insert(['servicio_id' => $id, 'tarifa_id' => $tarifaId, 'user_updated_id' => auth()->user()->id]);
|
||||
}
|
||||
|
||||
$thenRedirect = false;
|
||||
endif;
|
||||
|
||||
@ -141,7 +235,8 @@ class ServiciosAcabado extends BaseResourceController
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['servicio'] = $servicio;
|
||||
$this->viewData['tarifasSeleccionadas'] = [1,2];
|
||||
|
||||
$this->viewData['tarifasSeleccionadas'] = $this->getTarifasSeleccionadasForView($id);
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateServicioAcabado', $id);
|
||||
|
||||
@ -172,6 +267,16 @@ class ServiciosAcabado extends BaseResourceController
|
||||
->toJson(returnAsObject: true);
|
||||
}
|
||||
|
||||
|
||||
public function getTarifasSeleccionadasForView($servicioId){
|
||||
|
||||
$model = model("App\Models\Tarifas\Acabados\TarifasAcabadoServiciosAcabadoModel");
|
||||
$ids = $model->getTarifasForServicio($servicioId);
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
||||
public function getTarifasSeleccionadas()
|
||||
{
|
||||
$model = model("App\Models\Tarifas\Acabados\TarifaAcabadoModel");
|
||||
|
||||
@ -20,7 +20,6 @@ class CreateServiciosAcabadoTable extends Migration
|
||||
'nombre' =>[
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 100,
|
||||
'unique' => true
|
||||
],
|
||||
'comentarios' => [
|
||||
'type' => 'TEXT',
|
||||
|
||||
@ -797,7 +797,7 @@ return [
|
||||
"menu_tarifamanipulado" => "Manipulado",
|
||||
"menu_tarifaencuadernacion" => "Encuadernación",
|
||||
"menu_tarifapapelcompra" => "Papel compra",
|
||||
"menu_Servicioacabado" => "Servicios acabado",
|
||||
"menu_servicioAcabado" => "Servicios acabado",
|
||||
"menu_tarifaacabado" => "Acabado",
|
||||
"menu_tarifapapeldefecto" => "Papel defecto",
|
||||
"menu_tarifaenvio" => "Envío",
|
||||
|
||||
@ -24,6 +24,7 @@ return [
|
||||
'nombre' => [
|
||||
'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.',
|
||||
'required' => 'El campo {field} es obligatorio.',
|
||||
'is_unique' => 'Ya existe un servicio con el campo {field} guardado.',
|
||||
],
|
||||
],
|
||||
];
|
||||
@ -22,7 +22,7 @@ class ServicioAcabadoModel extends Model
|
||||
|
||||
protected $validationRules = [
|
||||
"nombre" => [
|
||||
"label" => "Servicioacabado.nombre",
|
||||
"label" => "ServicioAcabado.nombre",
|
||||
"rules" => "trim|required|max_length[100]",
|
||||
],
|
||||
];
|
||||
|
||||
@ -43,7 +43,7 @@ if (
|
||||
<?php if (auth()->user()->can('servicio-acabado.menu')) { ?>
|
||||
<li class="menu-item">
|
||||
<a href="<?= route_to('serviciosAcabadoList') ?>" class="menu-link">
|
||||
<?= lang("App.menu_serviciosAcabado") ?>
|
||||
<?= lang("App.menu_servicioAcabado") ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
|
||||
@ -219,6 +219,7 @@ class PresupuestoAdminEdit {
|
||||
datos.selectedTirada = this.datosLibro.tirada.val();
|
||||
datos.acabado_cubierta_id = this.datosLibro.acabadoCubierta.getVal();
|
||||
datos.acabado_sobrecubierta_id = this.datosLibro.acabadoSobrecubierta.getVal();
|
||||
datos.acabado_faja_id = this.datosLibro.acabadoFaja.getVal();
|
||||
|
||||
datos = {
|
||||
...datos, ...{
|
||||
|
||||
@ -71,7 +71,6 @@ class DatosLibro {
|
||||
this.div_faja = this.domItem.find('.faja-div');
|
||||
|
||||
this.cargando = cargando;
|
||||
|
||||
}
|
||||
|
||||
init() {
|
||||
@ -85,8 +84,9 @@ class DatosLibro {
|
||||
|
||||
this.acabadoCubierta.item.on('select2:select', function () {
|
||||
|
||||
if (this.cargando)
|
||||
if (this.cargando){
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.acabadoCubierta.getVal() == 0) {
|
||||
$(document).trigger('remove-servicio-lineas', 'acabadoCubierta');
|
||||
@ -95,10 +95,12 @@ class DatosLibro {
|
||||
$(document).trigger('add-servicio-lineas', 'acabadoCubierta');
|
||||
}
|
||||
});
|
||||
|
||||
this.acabadoSobrecubierta.item.on('select2:select', function () {
|
||||
|
||||
if (this.cargando)
|
||||
if (this.cargando){
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.acabadoCubierta.getVal() == 0) {
|
||||
$(document).trigger('remove-servicio-lineas', 'acabadoSobrecubierta');
|
||||
@ -107,6 +109,7 @@ class DatosLibro {
|
||||
$(document).trigger('add-servicio-lineas', 'acabadoSobrecubierta');
|
||||
}
|
||||
});
|
||||
|
||||
this.acabadoFaja.item.on('select2:select', function () {
|
||||
|
||||
if (this.cargando)
|
||||
|
||||
@ -510,13 +510,12 @@ class ServiciosAcabado {
|
||||
|
||||
updateAcabadosExteriores(cubierta, sobrecubierta, faja) {
|
||||
|
||||
this.table.rows().every(function () {
|
||||
var data = this.data();
|
||||
for (let i = this.table.rows().count() - 1; i >= 0; i--) {
|
||||
let data = this.table.row(i).data();
|
||||
if (data && (data.cubierta == cubierta && data.sobrecubierta == sobrecubierta && data.faja == faja)) {
|
||||
|
||||
this.remove().draw();
|
||||
this.table.row(i).remove().draw();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let tarifa_id = 0;
|
||||
let uso = 'cubierta';
|
||||
@ -531,9 +530,6 @@ class ServiciosAcabado {
|
||||
tarifa_id = $('#acabado_faja_id').val();
|
||||
uso = 'faja';
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.getPresupuestoAcabado(tarifa_id, uso, null);
|
||||
}
|
||||
|
||||
@ -561,24 +557,25 @@ class ServiciosAcabado {
|
||||
new Ajax('/serviciosacabados/getvalues', datos, {},
|
||||
function (response) {
|
||||
if (response.values) {
|
||||
response.values[0].cubierta = 0;
|
||||
response.values[0].sobrecubierta = 0;
|
||||
response.values[0].faja = 0;
|
||||
if (uso == 'cubierta') {
|
||||
response.values[0].cubierta = 1;
|
||||
}
|
||||
else if (uso == 'sobrecubierta') {
|
||||
response.values[0].sobrecubierta = 1;
|
||||
}
|
||||
else if (uso == 'faja') {
|
||||
response.values[0].faja = 1;
|
||||
for(let i=0; i<response.values.length; i++){
|
||||
response.values[i].cubierta = 0;
|
||||
response.values[i].sobrecubierta = 0;
|
||||
response.values[i].faja = 0;
|
||||
if (uso == 'cubierta') {
|
||||
response.values[i].cubierta = 1;
|
||||
}
|
||||
else if (uso == 'sobrecubierta') {
|
||||
response.values[i].sobrecubierta = 1;
|
||||
}
|
||||
else if (uso == 'faja') {
|
||||
response.values[i].faja = 1;
|
||||
}
|
||||
}
|
||||
if (updateSelect != null) {
|
||||
|
||||
self.table.row(updateSelect.closest('tr')).data(response.values[0]).draw();
|
||||
}
|
||||
else {
|
||||
self.table.rows.add([response.values[0]]).draw();
|
||||
self.table.rows.add(response.values).draw();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -8,7 +8,7 @@ class editServiciosAcabado {
|
||||
this.selectElement = $('#tarifas');
|
||||
this.acabado_cubierta = $('#acabado_cubierta');
|
||||
this.acabado_sobrecubierta = $('#acabado_sobrecubierta');
|
||||
this.tarifasSeleccionadas = JSON.parse(this.selectElement.attr('data-selected') || '[]');
|
||||
this.tarifasSeleccionadas = JSON.parse(this.selectElement.attr('data-selected') || '[]');
|
||||
}
|
||||
|
||||
init() {
|
||||
@ -65,6 +65,14 @@ class editServiciosAcabado {
|
||||
});
|
||||
}
|
||||
|
||||
this.acabado_cubierta.on('change', function(){
|
||||
self.selectElement.val(null).trigger('change');
|
||||
});
|
||||
|
||||
this.acabado_sobrecubierta.on('change', function(){
|
||||
self.selectElement.val(null).trigger('change');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user