diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 3c1b4e7d..5729cca1 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -484,6 +484,10 @@ $routes->group('serviciospresupuesto', ['namespace' => 'App\Controllers\Presupue $routes->post('datatable_editor', 'PresupuestoAcabados::datatable_editor', ['as' => 'editorOfPresupuestoAcabados']); }); +$routes->group('serviciosencuadernaciones', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) { + $routes->post('datatable', 'PresupuestoEncuadernaciones::datatable', ['as' => 'dataTableOfPresupuestoEncuadernaciones']); + $routes->post('datatable_editor', 'PresupuestoEncuadernaciones::datatable_editor', ['as' => 'editorOfPresupuestoEncuadernaciones']); +}); /* diff --git a/ci4/app/Controllers/Presupuestos/PresupuestoAcabados.php b/ci4/app/Controllers/Presupuestos/PresupuestoAcabados.php index d4550e25..8d829b7f 100644 --- a/ci4/app/Controllers/Presupuestos/PresupuestoAcabados.php +++ b/ci4/app/Controllers/Presupuestos/PresupuestoAcabados.php @@ -9,7 +9,7 @@ use App\Entities\Clientes\ClienteContactoEntity; use App\Models\Clientes\ClienteModel; -use App\Models\Presupuestos\PresupuestoAcabadoModel; +use App\Models\Presupuestos\PresupuestoAcabadosModel; use DataTables\Editor; use DataTables\Editor\Field; use DataTables\Editor\Validate; @@ -25,7 +25,7 @@ use const App\Controllers\Clientes\APPPATH; class PresupuestoAcabados extends \App\Controllers\GoBaseResourceController { - protected $modelName = PresupuestoAcabadoModel::class; + protected $modelName = PresupuestoAcabadosModel::class; protected $format = 'json'; protected static $singularObjectName = 'Presupuesto acabado'; @@ -57,19 +57,18 @@ class PresupuestoAcabados extends \App\Controllers\GoBaseResourceController } $start = $reqData['start'] ?? 0; $length = $reqData['length'] ?? 5; - $search = $reqData['search']['value']; $requestedOrder = $reqData['order']['0']['column'] ?? 1; - $order = PresupuestoAcabadoModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1]; + $order = PresupuestoAcabadosModel::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(); + $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() + $this->model->getResource($id_P)->countAllResults() )); } else { return $this->failUnauthorized('Invalid request', 403); @@ -84,17 +83,17 @@ class PresupuestoAcabados extends \App\Controllers\GoBaseResourceController // Build our Editor instance and process the data coming from _POST $response = Editor::inst( $db, 'presupuesto_acabados' ) ->fields( - Field::inst( 'nombre' ) + Field::inst( 'tarifa_acabado_id' ) ->validator( 'Validate::notEmpty',array( 'message' => 'Selecciones servicios de acabado' ) ), - Field::inst( 'precio_unitario' ) + Field::inst( 'precio_unidad' ) ->validator( 'Validate::notEmpty',array( - 'message' => 'Falta apellidos' ) + 'message' => 'Falta precio unitario' ) ), Field::inst( 'precio_total' ) ->validator( 'Validate::notEmpty',array( - 'message' => 'Falta cargp' ) + 'message' => 'Falta precio total' ) ), Field::inst( 'presupuesto_id' ), @@ -102,6 +101,7 @@ class PresupuestoAcabados extends \App\Controllers\GoBaseResourceController ) ->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)){ diff --git a/ci4/app/Controllers/Presupuestos/PresupuestoEncuadernaciones.php b/ci4/app/Controllers/Presupuestos/PresupuestoEncuadernaciones.php new file mode 100644 index 00000000..5160c308 --- /dev/null +++ b/ci4/app/Controllers/Presupuestos/PresupuestoEncuadernaciones.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 = PresupuestoEncuadernacionesModel::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_acabados' ) + ->fields( + Field::inst( 'tarifa_encuadernado_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/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php new file mode 100644 index 00000000..e1ce106d --- /dev/null +++ b/ci4/app/Entities/Presupuestos/PresupuestoEncuadernacionesEntity.php @@ -0,0 +1,23 @@ + null, + "presupuesto_id" => null, + "tarifa_encuadernado_id" => null, + "precio_unidad" => null, + "precio_total" => null, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + "presupuesto_id" => "int", + "tarifa_encuadernado_id" => "int", + "precio_unidad" => "float", + "precio_total" => "float", + ]; +} diff --git a/ci4/app/Entities/Presupuestos/PresupuestoManipuladosEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoManipuladosEntity.php new file mode 100644 index 00000000..8b2830c7 --- /dev/null +++ b/ci4/app/Entities/Presupuestos/PresupuestoManipuladosEntity.php @@ -0,0 +1,23 @@ + null, + "presupuesto_id" => null, + "tarifa_manipulado_id" => null, + "precio_unidad" => null, + "precio_total" => null, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + "presupuesto_id" => "int", + "tarifa_manipulado_id" => "int", + "precio_unidad" => "float", + "precio_total" => "float", + ]; +} diff --git a/ci4/app/Entities/Presupuestos/PresupuestoPreimpresionesEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoPreimpresionesEntity.php new file mode 100644 index 00000000..8a56a8fc --- /dev/null +++ b/ci4/app/Entities/Presupuestos/PresupuestoPreimpresionesEntity.php @@ -0,0 +1,23 @@ + null, + "presupuesto_id" => null, + "tarifa_preimpresion_id" => null, + "precio_unidad" => null, + "precio_total" => null, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + "presupuesto_id" => "int", + "tarifa_preimpresion_id" => "int", + "precio_unidad" => "float", + "precio_total" => "float", + ]; +} diff --git a/ci4/app/Models/Presupuestos/PresupuestoAcabadoModel.php b/ci4/app/Models/Presupuestos/PresupuestoAcabadosModel.php similarity index 77% rename from ci4/app/Models/Presupuestos/PresupuestoAcabadoModel.php rename to ci4/app/Models/Presupuestos/PresupuestoAcabadosModel.php index 7612a4fb..ed32bfb4 100644 --- a/ci4/app/Models/Presupuestos/PresupuestoAcabadoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoAcabadosModel.php @@ -2,7 +2,7 @@ namespace App\Models\Presupuestos; -class PresupuestoAcabadoModel extends \App\Models\GoBaseModel +class PresupuestoAcabadosModel extends \App\Models\GoBaseModel { protected $table = "presupuesto_acabados"; @@ -19,7 +19,7 @@ class PresupuestoAcabadoModel extends \App\Models\GoBaseModel 2 => "t1.precio_total" ]; - protected $allowedFields = ["presupuesto_id", "tarifa_acabado_id", "nombre", "precio", "precio_unidad"]; + protected $allowedFields = ["presupuesto_id", "tarifa_acabado_id", "nombre", "precio_total", "precio_unidad"]; protected $returnType = "App\Entities\Presupuestos\PresupuestoAcabadosEntity"; protected $useTimestamps = true; @@ -52,7 +52,7 @@ class PresupuestoAcabadoModel extends \App\Models\GoBaseModel * * @return \CodeIgniter\Database\BaseBuilder */ - public function getResource(string $search = "", $presupuesto_id = -1) + public function getResource($presupuesto_id = -1) { $builder = $this->db ->table($this->table . " t1") @@ -63,13 +63,6 @@ class PresupuestoAcabadoModel extends \App\Models\GoBaseModel $builder->where('t1.presupuesto_id', $presupuesto_id); $builder->join("lg_tarifa_acabado t2", "t1.tarifa_acabado_id = t2.id", "left"); - return empty($search) - ? $builder - : $builder - ->groupStart() - ->like("t2.nombre", $search) - ->orlike("t1.precio_unidad", $search) - ->orLike("t1.precio_total", $search) - ->groupEnd(); + return $builder; } } diff --git a/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php b/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php new file mode 100644 index 00000000..0ad3cf6e --- /dev/null +++ b/ci4/app/Models/Presupuestos/PresupuestoEncuadernacionesModel.php @@ -0,0 +1,68 @@ + "t2.nombre", + 1 => "t1.precio_unidad", + 2 => "t1.precio_total" + ]; + + protected $allowedFields = ["presupuesto_id", "tarifa_encuadernado_id", "nombre", "precio_total", "precio_unidad"]; + protected $returnType = "App\Entities\Presupuestos\PresupuestoEncuadernacionesEntity"; + + 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_encuadernado_id AS tarifa_encuadernado_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("tarifa_encuadernacion t2", "t1.tarifa_encuadernado_id = t2.id", "left"); + + return $builder; + } +} 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 1277ecf9..bc1663d5 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 @@ -83,7 +83,18 @@
-

Proximanente

+ + + + + + + + + + + +
@@ -137,7 +148,7 @@ "name": "tarifa_acabado_id", "type": "select" }, { - "name": "precio_unitario" + "name": "precio_unidad" }, { "name": "precio_total" }, { @@ -278,3 +289,163 @@ endSection() ?> + + + +section("additionalInlineJs") ?> + + const lastColNr2 = $('#tableOfServiciosEncuadernacion').find("tr:first th").length - 1; + + editor = new $.fn.dataTable.Editor( { + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfServiciosEncuadernacion", + idSrc: 'id', + fields: [ { + "name": "tarifa_encuadernado_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 encuadernadosList = ; + editor.field( 'tarifa_encuadernado_id' ).update( encuadernadosList ); + + editor.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; + } + } + }); + + editor.on( 'postSubmit', function ( e, json, data, action ) { + yeniden(json.); + }); + + editor.on( 'submitSuccess', function ( e, json, data, action ) { + theTable.clearPipeline(); + theTable.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(), + { + cancelHtml: '', + cancelTrigger: 'span.cancel', + submitHtml: '', + submitTrigger: 'span.edit', + submit: 'allIfChanged' + } + ); + } ); + + + // 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( { + 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_encuadernado_id', + render: function(data, type, row, meta) { + var value = encuadernadosList.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: [lastColNr2] + }, + { + "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: editor, + formOptions: { + submitTrigger: -1, + submitHtml: '' + } + } ] + } ); + +endSection() ?> \ No newline at end of file