diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 5729cca1..e795fbe2 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -479,7 +479,7 @@ $routes->group('cosidotapablanda', ['namespace' => 'App\Controllers\Presupuestos }); $routes->resource('cosidotapablanda', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Cosidotapablanda', 'except' => 'show,new,create,update']); -$routes->group('serviciospresupuesto', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { +$routes->group('serviciosacabados', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { $routes->post('datatable', 'PresupuestoAcabados::datatable', ['as' => 'dataTableOfPresupuestoAcabados']); $routes->post('datatable_editor', 'PresupuestoAcabados::datatable_editor', ['as' => 'editorOfPresupuestoAcabados']); }); @@ -489,6 +489,16 @@ $routes->group('serviciosencuadernaciones', ['namespace' => 'App\Controllers\Pre $routes->post('datatable_editor', 'PresupuestoEncuadernaciones::datatable_editor', ['as' => 'editorOfPresupuestoEncuadernaciones']); }); +$routes->group('serviciosmanipulados', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { + $routes->post('datatable', 'PresupuestoManipulados::datatable', ['as' => 'dataTableOfPresupuestoManipulados']); + $routes->post('datatable_editor', 'PresupuestoManipulados::datatable_editor', ['as' => 'editorOfPresupuestoManipulados']); +}); + +$routes->group('serviciospreimpresiones', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { + $routes->post('datatable', 'PresupuestoPreimpresiones::datatable', ['as' => 'dataTableOfPresupuestoPreimpresiones']); + $routes->post('datatable_editor', 'PresupuestoPreimpresiones::datatable_editor', ['as' => 'editorOfPresupuestoPreimpresiones']); +}); + /* * -------------------------------------------------------------------- diff --git a/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php b/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php index 853f5b5a..524565d3 100644 --- a/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php +++ b/ci4/app/Controllers/Presupuestos/Cosidotapablanda.php @@ -711,8 +711,8 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController $model = model('App\Models\Tarifas\TarifapreimpresionModel'); $data = $model->getServiciosPreimpresionSelector(); array_unshift($data, (object)array( - "id" => 0, - "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioPreimpresion'))]) + "value" => 0, + "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioPreimpresion'))]) )); return $data; } @@ -722,8 +722,8 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController $model = model('App\Models\Tarifas\TarifaEncuadernacionModel'); $data = $model->getServiciosEncuadernacionSelector(); array_unshift($data, (object)array( - "id" => 0, - "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioEncuadernacion'))]) + "value" => 0, + "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioEncuadernado'))]) )); return $data; } @@ -744,8 +744,8 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController $model = model('App\Models\Tarifas\TarifaManipuladoModel'); $data = $model->getServiciosManipuladoSelector(); array_unshift($data, (object)array( - "id" => 0, - "nombre" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioManipulado'))]) + "value" => 0, + "label" => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Presupuestos.servicioManipulado'))]) )); return $data; } diff --git a/ci4/app/Controllers/Presupuestos/PresupuestoManipulados.php b/ci4/app/Controllers/Presupuestos/PresupuestoManipulados.php new file mode 100644 index 00000000..af2e86db --- /dev/null +++ b/ci4/app/Controllers/Presupuestos/PresupuestoManipulados.php @@ -0,0 +1,131 @@ +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; + $requestedOrder = $reqData['order']['0']['column'] ?? 1; + $order = PresupuestoManipuladosModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + + $id_P = $reqData['id_presupuesto'] ?? -1; + + $resourceData = $this->model->getResource($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); + } + } + + public function datatable_editor() { + if ($this->request->isAJAX()) { + + include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php"); + + // Build our Editor instance and process the data coming from _POST + $response = Editor::inst( $db, 'presupuesto_manipulados' ) + ->fields( + Field::inst( 'tarifa_manipulado_id' ) + ->validator( 'Validate::notEmpty',array( + 'message' => 'Selecciones servicios de acabado' ) + ), + Field::inst( 'precio_unidad' ) + ->validator( 'Validate::notEmpty',array( + 'message' => 'Falta precio unitario' ) + ), + Field::inst( 'precio_total' ) + ->validator( 'Validate::notEmpty',array( + 'message' => 'Falta precio total' ) + ), + + Field::inst( 'presupuesto_id' ), + + ) + ->validator( function($editor, $action, $data){ + if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){ + //return $response; + /*foreach ($data['data'] as $pkey => $values ){ + // No se pueden duplicar valores al crear o al editar + if (!empty($response)){ + return $response; + } + }*/ + } + }) + ->debug(true) + ->process( $_POST ) + ->data(); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $response[$csrfTokenName] = $newTokenHash; + + echo json_encode($response); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + + +} diff --git a/ci4/app/Controllers/Presupuestos/PresupuestoPreimpresiones.php b/ci4/app/Controllers/Presupuestos/PresupuestoPreimpresiones.php new file mode 100644 index 00000000..5e92fd69 --- /dev/null +++ b/ci4/app/Controllers/Presupuestos/PresupuestoPreimpresiones.php @@ -0,0 +1,125 @@ +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; + $requestedOrder = $reqData['order']['0']['column'] ?? 1; + $order = PresupuestoPreimpresionesModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + + $id_P = $reqData['id_presupuesto'] ?? -1; + + $resourceData = $this->model->getResource($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); + } + } + + public function datatable_editor() { + if ($this->request->isAJAX()) { + + include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php"); + + // Build our Editor instance and process the data coming from _POST + $response = Editor::inst( $db, 'presupuesto_preimpresiones' ) + ->fields( + Field::inst( 'tarifa_preimpresion_id' ) + ->validator( 'Validate::notEmpty',array( + 'message' => 'Selecciones servicios de acabado' ) + ), + Field::inst( 'precio_unidad' ) + ->validator( 'Validate::notEmpty',array( + 'message' => 'Falta precio unitario' ) + ), + Field::inst( 'precio_total' ) + ->validator( 'Validate::notEmpty',array( + 'message' => 'Falta precio total' ) + ), + + Field::inst( 'presupuesto_id' ), + + ) + ->validator( function($editor, $action, $data){ + if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){ + //return $response; + /*foreach ($data['data'] as $pkey => $values ){ + // No se pueden duplicar valores al crear o al editar + if (!empty($response)){ + return $response; + } + }*/ + } + }) + ->debug(true) + ->process( $_POST ) + ->data(); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $response[$csrfTokenName] = $newTokenHash; + + echo json_encode($response); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + + +} diff --git a/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php b/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php new file mode 100644 index 00000000..e45976e8 --- /dev/null +++ b/ci4/app/Models/Presupuestos/PresupuestoManipuladosModel.php @@ -0,0 +1,68 @@ + "t2.nombre", + 1 => "t1.precio_unidad", + 2 => "t1.precio_total" + ]; + + protected $allowedFields = ["presupuesto_id", "tarifa_manipulado_id", "nombre", "precio_total", "precio_unidad"]; + protected $returnType = "App\Entities\Presupuestos\PresupuestoManipuladosEntity"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + protected $updatedField = "updated_at"; + + public static $labelField = "nombre"; + + protected $validationRules = [ + "precio_total" => [ + "label" => "Presupuestos.precioTotal", + "rules" => "decimal|required", + ], + ]; + + protected $validationMessages = [ + "precio_total" => [ + "decimal" => "Presupuestos.validation.decimal", + "requerido" => "Presupuestos.validation.decimal", + ], + ]; + + + /** + * Get resource data. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResource($presupuesto_id = -1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.tarifa_manipulado_id AS tarifa_manipulado_id, t1.precio_unidad AS precio_unidad, t1.precio_total AS precio_total, t2.nombre AS nombre" + ); + + $builder->where('t1.presupuesto_id', $presupuesto_id); + $builder->join("lg_tarifa_manipulado t2", "t1.tarifa_manipulado_id = t2.id", "left"); + + return $builder; + } +} diff --git a/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php new file mode 100644 index 00000000..2cc3627b --- /dev/null +++ b/ci4/app/Models/Presupuestos/PresupuestoPreimpresionesModel.php @@ -0,0 +1,68 @@ + "t2.nombre", + 1 => "t1.precio_unidad", + 2 => "t1.precio_total" + ]; + + protected $allowedFields = ["presupuesto_id", "tarifa_preimpresion_id", "nombre", "precio_total", "precio_unidad"]; + protected $returnType = "App\Entities\Presupuestos\PresupuestoPreimpresionesEntity"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + protected $updatedField = "updated_at"; + + public static $labelField = "nombre"; + + protected $validationRules = [ + "precio_total" => [ + "label" => "Presupuestos.precioTotal", + "rules" => "decimal|required", + ], + ]; + + protected $validationMessages = [ + "precio_total" => [ + "decimal" => "Presupuestos.validation.decimal", + "requerido" => "Presupuestos.validation.decimal", + ], + ]; + + + /** + * Get resource data. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResource($presupuesto_id = -1) + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.tarifa_preimpresion_id AS tarifa_preimpresion_id, t1.precio_unidad AS precio_unidad, t1.precio_total AS precio_total, t2.nombre AS nombre" + ); + + $builder->where('t1.presupuesto_id', $presupuesto_id); + $builder->join("lg_tarifa_preimpresion t2", "t1.tarifa_preimpresion_id = t2.id", "left"); + + return $builder; + } +} diff --git a/ci4/app/Models/Tarifas/TarifaEncuadernacionModel.php b/ci4/app/Models/Tarifas/TarifaEncuadernacionModel.php index 84c2630b..5604acee 100644 --- a/ci4/app/Models/Tarifas/TarifaEncuadernacionModel.php +++ b/ci4/app/Models/Tarifas/TarifaEncuadernacionModel.php @@ -103,7 +103,7 @@ class TarifaEncuadernacionModel extends \App\Models\GoBaseModel $builder = $this->db ->table($this->table . " t1") ->select( - "t1.id as id, t1.nombre AS nombre" + "t1.id as value, t1.nombre AS label" ) ->where("t1.is_deleted", 0) ->where("t1.mostrar_en_presupuesto", 1); diff --git a/ci4/app/Models/Tarifas/TarifaManipuladoModel.php b/ci4/app/Models/Tarifas/TarifaManipuladoModel.php index b8b7cfd1..33c1607f 100644 --- a/ci4/app/Models/Tarifas/TarifaManipuladoModel.php +++ b/ci4/app/Models/Tarifas/TarifaManipuladoModel.php @@ -102,7 +102,7 @@ class TarifaManipuladoModel extends \App\Models\GoBaseModel $builder = $this->db ->table($this->table . " t1") ->select( - "t1.id as id, t1.nombre AS nombre" + "t1.id as value, t1.nombre AS label" ) ->where("t1.is_deleted", 0) ->where("t1.mostrar_en_presupuesto", 1); diff --git a/ci4/app/Models/Tarifas/TarifapreimpresionModel.php b/ci4/app/Models/Tarifas/TarifapreimpresionModel.php index 6c2f16b3..7d94e40d 100644 --- a/ci4/app/Models/Tarifas/TarifapreimpresionModel.php +++ b/ci4/app/Models/Tarifas/TarifapreimpresionModel.php @@ -88,7 +88,7 @@ class TarifapreimpresionModel extends \App\Models\GoBaseModel $builder = $this->db ->table($this->table . " t1") ->select( - "t1.id as id, t1.nombre AS nombre" + "t1.id as value, t1.nombre AS label" ) ->where("t1.is_deleted", 0) ->where("t1.mostrar_en_presupuesto", 1); diff --git a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosServiciosItems.php b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosServiciosItems.php index bc1663d5..3045316b 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosServiciosItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosServiciosItems.php @@ -79,14 +79,25 @@
-

Proximanente

+ + + + + + + + + + + +
- + @@ -98,7 +109,18 @@
-

Proximanente

+
+ + + + + + + + + + +
@@ -196,33 +218,27 @@ ); } ); - // Delete row - $('#tableOfServiciosAcabado').on( 'click', 'tbody span.remove', function (e) { + $(document).on('click', '.btn-delete', function(e) { + $(".btn-remove").attr('data-id', $(this).attr('data-id')); + }); - Swal.fire({ - title: '', - text: '', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - confirmButtonText: '', - cancelButtonText: '', - cancelButtonColor: '#d33' - }) - .then((result) => { - const dataId = $(this).data('id'); - const row = $(this).closest('tr'); - if (result.value) { - editor - .create( false ) - .edit( this.parentNode, false) - .set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') ) - .set( 'is_deleted', 1 ) - .submit(); - - } - }); + $(document).on('click', '.btn-remove', function(e) { + const dataId = $(this).attr('data-id'); + const row = $(this).closest('tr'); + if ($.isNumeric(dataId)) { + $.ajax({ + url: `/presupuestos/presupuestoacabados/delete/${dataId}`, + method: 'GET', + }).done((data, textStatus, jqXHR) => { + $('#confirm2delete').modal('toggle'); + theTable.clearPipeline(); + theTable.row($(row)).invalidate().draw(); + popSuccessAlert(data.msg ?? jqXHR.statusText); + }).fail((jqXHR, textStatus, errorThrown) => { + popErrorAlert(jqXHR.responseJSON.messages.error) + }) + } }); var theTable = $('#tableOfServiciosAcabado').DataTable( { @@ -289,14 +305,14 @@ endSection() ?> - - - + + + section("additionalInlineJs") ?> const lastColNr2 = $('#tableOfServiciosEncuadernacion').find("tr:first th").length - 1; - editor = new $.fn.dataTable.Editor( { + editor2 = new $.fn.dataTable.Editor( { ajax: { url: "", headers: { @@ -321,9 +337,9 @@ // Generación de la lista de servicios de acabado (id, nombre) const encuadernadosList = ; - editor.field( 'tarifa_encuadernado_id' ).update( encuadernadosList ); + editor2.field( 'tarifa_encuadernado_id' ).update( encuadernadosList ); - editor.on( 'preSubmit', function ( e, d, type ) { + editor2.on( 'preSubmit', function ( e, d, type ) { if ( type === 'create'){ d.data[0]['presupuesto_id'] = id; } @@ -334,19 +350,19 @@ } }); - editor.on( 'postSubmit', function ( e, json, data, action ) { + editor2.on( 'postSubmit', function ( e, json, data, action ) { yeniden(json.); }); - editor.on( 'submitSuccess', function ( e, json, data, action ) { - theTable.clearPipeline(); - theTable.draw(); + editor2.on( 'submitSuccess', function ( e, json, data, action ) { + theTable2.clearPipeline(); + theTable2.draw(); }); // Activate an inline edit on click of a table cell $('#tableOfServiciosEncuadernacion').on( 'click', 'tbody span.edit', function (e) { - editor.inline( - theTable.cells(this.parentNode.parentNode, '*').nodes(), + editor2.inline( + theTable2.cells(this.parentNode.parentNode, '*').nodes(), { cancelHtml: '', cancelTrigger: 'span.cancel', @@ -358,35 +374,7 @@ } ); - // Delete row - $('#tableOfServiciosEncuadernacion').on( 'click', 'tbody span.remove', function (e) { - - Swal.fire({ - title: '', - text: '', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - confirmButtonText: '', - cancelButtonText: '', - cancelButtonColor: '#d33' - }) - .then((result) => { - const dataId = $(this).data('id'); - const row = $(this).closest('tr'); - if (result.value) { - editor - .create( false ) - .edit( this.parentNode, false) - .set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') ) - .set( 'is_deleted', 1 ) - .submit(); - - } - }); - }); - - var theTable = $('#tableOfServiciosEncuadernacion').DataTable( { + var theTable2 = $('#tableOfServiciosEncuadernacion').DataTable( { serverSide: true, processing: true, autoWidth: true, @@ -440,7 +428,280 @@ buttons: [ { className: 'btn btn-primary float-end me-sm-3 me-1', extend: "createInline", - editor: editor, + editor: editor2, + formOptions: { + submitTrigger: -1, + submitHtml: '' + } + } ] + } ); + +endSection() ?> + + + + +section("additionalInlineJs") ?> + + const lastColNr3 = $('#tableOfServiciosManipulado').find("tr:first th").length - 1; + + editor3 = new $.fn.dataTable.Editor( { + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfServiciosManipulado", + idSrc: 'id', + fields: [ { + "name": "tarifa_manipulado_id", + "type": "select" + }, { + "name": "precio_unidad" + }, { + "name": "precio_total" + }, { + "name": "presupuesto_id", + "type": "hidden" + }, + ] + } ); + + // Generación de la lista de servicios de acabado (id, nombre) + const manipuladosList = ; + editor3.field( 'tarifa_manipulado_id' ).update( manipuladosList ); + + editor3.on( 'preSubmit', function ( e, d, type ) { + if ( type === 'create'){ + d.data[0]['presupuesto_id'] = id; + } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['presupuesto_id'] = id; + } + } + }); + + editor3.on( 'postSubmit', function ( e, json, data, action ) { + yeniden(json.); + }); + + editor3.on( 'submitSuccess', function ( e, json, data, action ) { + theTable3.clearPipeline(); + theTable3.draw(); + }); + + // Activate an inline edit on click of a table cell + $('#tableOfServiciosManipulado').on( 'click', 'tbody span.edit', function (e) { + editor3.inline( + theTable3.cells(this.parentNode.parentNode, '*').nodes(), + { + cancelHtml: '', + cancelTrigger: 'span.cancel', + submitHtml: '', + submitTrigger: 'span.edit', + submit: 'allIfChanged' + } + ); + } ); + + + // Delete row + + + var theTable3 = $('#tableOfServiciosManipulado').DataTable( { + serverSide: true, + processing: true, + autoWidth: true, + responsive: true, + lengthMenu: [ 5, 10, 25], + order: [[ 0, "asc" ], [ 1, "asc" ]], + pageLength: 10, + lengthChange: true, + searching: false, + paging: true, + info: false, + dom: '<"mt-4"><"float-start"l><"mt-4 mb-3"p>', + ajax : $.fn.dataTable.pipeline( { + url: '', + data: { + id_presupuesto: id, + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns: [ + {'data': 'tarifa_manipulado_id', + render: function(data, type, row, meta) { + var value = manipuladosList.find(element => element.value === data); + return value['label']; + }, + }, + { 'data': 'precio_unidad' }, + { 'data': 'precio_total' }, + { + data: actionBtns, + className: 'row-edit dt-center' + } + ], + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr3] + }, + { + "orderData": [ 0, 1 ], + "targets": 0 + }, + + ], + language: { + url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" + }, + buttons: [ { + className: 'btn btn-primary float-end me-sm-3 me-1', + extend: "createInline", + editor: editor3, + formOptions: { + submitTrigger: -1, + submitHtml: '' + } + } ] + } ); + +endSection() ?> + + + + + +section("additionalInlineJs") ?> + + const lastColNr4 = $('#tableOfServiciosPreimpresion').find("tr:first th").length - 1; + + editor4 = new $.fn.dataTable.Editor( { + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfServiciosPreimpresion", + idSrc: 'id', + fields: [ { + "name": "tarifa_preimpresion_id", + "type": "select" + }, { + "name": "precio_unidad" + }, { + "name": "precio_total" + }, { + "name": "presupuesto_id", + "type": "hidden" + }, + ] + } ); + + // Generación de la lista de servicios de acabado (id, nombre) + const preimpresionesList = ; + editor4.field( 'tarifa_preimpresion_id' ).update( preimpresionesList ); + + editor4.on( 'preSubmit', function ( e, d, type ) { + if ( type === 'create'){ + d.data[0]['presupuesto_id'] = id; + } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['presupuesto_id'] = id; + } + } + }); + + editor4.on( 'postSubmit', function ( e, json, data, action ) { + yeniden(json.); + }); + + editor4.on( 'submitSuccess', function ( e, json, data, action ) { + theTable4.clearPipeline(); + theTable4.draw(); + }); + + // Activate an inline edit on click of a table cell + $('#tableOfServiciosPreimpresion').on( 'click', 'tbody span.edit', function (e) { + editor4.inline( + theTable4.cells(this.parentNode.parentNode, '*').nodes(), + { + cancelHtml: '', + cancelTrigger: 'span.cancel', + submitHtml: '', + submitTrigger: 'span.edit', + submit: 'allIfChanged' + } + ); + } ); + + + // Delete row + + + var theTable4 = $('#tableOfServiciosPreimpresion').DataTable( { + serverSide: true, + processing: true, + autoWidth: true, + responsive: true, + lengthMenu: [ 5, 10, 25], + order: [[ 0, "asc" ], [ 1, "asc" ]], + pageLength: 10, + lengthChange: true, + searching: false, + paging: true, + info: false, + dom: '<"mt-4"><"float-start"l><"mt-4 mb-3"p>', + ajax : $.fn.dataTable.pipeline( { + url: '', + data: { + id_presupuesto: id, + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns: [ + {'data': 'tarifa_preimpresion_id', + render: function(data, type, row, meta) { + var value = preimpresionesList.find(element => element.value === data); + return value['label']; + }, + }, + { 'data': 'precio_unidad' }, + { 'data': 'precio_total' }, + { + data: actionBtns, + className: 'row-edit dt-center' + } + ], + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr4] + }, + { + "orderData": [ 0, 1 ], + "targets": 0 + }, + + ], + language: { + url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" + }, + buttons: [ { + className: 'btn btn-primary float-end me-sm-3 me-1', + extend: "createInline", + editor: editor4, formOptions: { submitTrigger: -1, submitHtml: ''