diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index fdbaf671..f55032f7 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -661,6 +661,7 @@ $routes->group('facturas', ['namespace' => 'App\Controllers\Facturacion'], funct $routes->post('addLineaPedidoImpresion/(:num)', 'Facturas::addLineaPedidoImpresion/$1', ['as' => 'addLineaPedidoImpresion2Factura']); $routes->post('addLineaPedidoImpresion/(:num)', 'Facturas::addLineaPedidoImpresion/$1', ['as' => 'addLineaPedidoImpresion2Factura']); $routes->get('deleteLinea/(:any)', 'FacturasLineas::deleteLinea/$1', ['as' => 'deleteLineaFactura']); + $routes->post('editorLineas', 'FacturasLineas::datatable_editor', ['as' => 'editorOfLineasFacturas']); }); diff --git a/ci4/app/Controllers/Facturacion/FacturasLineas.php b/ci4/app/Controllers/Facturacion/FacturasLineas.php index 18b8466c..22ae8580 100644 --- a/ci4/app/Controllers/Facturacion/FacturasLineas.php +++ b/ci4/app/Controllers/Facturacion/FacturasLineas.php @@ -4,7 +4,9 @@ namespace App\Controllers\Facturacion; use App\Models\Facturas\FacturaLineaModel; use App\Models\Collection; - +use DataTables\Editor; +use DataTables\Editor\Field; +use DataTables\Editor\Validate; class FacturasLineas extends \App\Controllers\BaseResourceController { @@ -74,4 +76,117 @@ class FacturasLineas extends \App\Controllers\BaseResourceController $response = $this->respondDeleted(['id' => $factura_linea_id, 'msg' => $message]); return $response; } + + + 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, 'cliente_plantilla_precios_lineas' ) + ->fields( + Field::inst( 'plantilla_id' ), + Field::inst( 'tipo' ), + Field::inst( 'tipo_maquina' ), + Field::inst( 'tipo_impresion' ), + Field::inst( 'user_updated_id' ), + Field::inst( 'updated_at' ), + Field::inst( 'tiempo_min' ) + ->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar') + ->validator( 'Validate::notEmpty',array( + 'message' => lang('ClientePrecios.validation.required')) + ) + ->validator('Validate::numeric', array( + "decimal" => ',', + 'message' => lang('ClientePrecios.validation.decimal')) + ), + + Field::inst( 'tiempo_max' ) + ->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar') + ->validator( 'Validate::notEmpty',array( + 'message' => lang('ClientePrecios.validation.required')) + ) + ->validator('Validate::numeric', array( + "decimal" => ',', + 'message' => lang('ClientePrecios.validation.decimal')) + ), + + Field::inst( 'precio_hora' ) + ->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar') + ->validator( 'Validate::notEmpty',array( + 'message' => lang('ClientePrecios.validation.required')) + ) + ->validator('Validate::numeric', array( + "decimal" => ',', + 'message' => lang('ClientePrecios.validation.decimal')) + ), + + Field::inst( 'margen' ) + ->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar') + ->validator( 'Validate::notEmpty',array( + 'message' => lang('ClientePrecios.validation.required')) + ) + ->validator('Validate::numeric', array( + "decimal" => ',', + 'message' => lang('ClientePrecios.validation.decimal')) + ), + + ) + ->validator(function ($editor, $action, $data) { + if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) { + foreach ($data['data'] as $pkey => $values) { + // Si no se quiere borrar... + if ($data['data'][$pkey]['is_deleted'] != 1) { + $process_data['tiempo_min'] = $data['data'][$pkey]['tiempo_min']; + $process_data['tiempo_max'] = $data['data'][$pkey]['tiempo_max']; + $process_data['tipo'] = $data['data'][$pkey]['tipo']; + $process_data['tipo_maquina'] = $data['data'][$pkey]['tipo_maquina']; + $process_data['tipo_impresion'] = $data['data'][$pkey]['tipo_impresion']; + + $response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['plantilla_id']); + // No se pueden duplicar valores al crear o al editar + if (!empty($response)) { + return $response; + } + } + } + } + }) + ->on('preCreate', function ($editor, &$values) { + $session = session(); + $datetime = (new \CodeIgniter\I18n\Time("now")); + $editor + ->field('user_updated_id') + ->setValue($session->id_user); + $editor + ->field('updated_at') + ->setValue($datetime->format('Y-m-d H:i:s')); + }) + ->on('preEdit', function ($editor, &$values) { + $session = session(); + $datetime = (new \CodeIgniter\I18n\Time("now")); + $editor + ->field('user_updated_id') + ->setValue($session->id_user); + $editor + ->field('updated_at') + ->setValue($datetime->format('Y-m-d H:i:s')); + }) + ->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); + } + } } \ No newline at end of file diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index dd0b609c..6e2a81c7 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -192,7 +192,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $this->viewData['presupuestoEntity'] = $presupuestoEntity; $this->viewData['datosPresupuesto'] = $datosPresupuesto; - $this->viewData['clienteId'] = $clienteId; + $this->viewData['clienteId'] = $presupuestoEntity->cliente_id; // En el caso del edit, se mantiene el clienteId del presupuesto // Si se ha llamado a esta funcion porque se ha duplicado el presupuesto // se actualiza la bbdd para que sólo ejecute algunas funciones una vez @@ -1449,9 +1449,18 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController } // Servicios - if ($datos_guardas > 0) { - array_push($servicios, 62); // Plegado de guardas + // se comprueba si $datos guardas es un array + if(is_array($datos_guardas)){ + if(count($datos_guardas) > 0){ + array_push($servicios, 62); // Plegado de guardas + } } + else{ + if ($datos_guardas > 0) { + array_push($servicios, 62); // Plegado de guardas + } + } + /* 'retractilado' => 3, 'retractilado5' => 5, diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index 5fc672eb..e61122b3 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -210,6 +210,8 @@ return [ 'confirmar' => 'Confirmar presupuesto', 'confirmado' => 'Presupuesto confirmado', + 'totalAceptado' => 'Total aceptado', + // Preview 'preview' => 'Previsualización de configuraciones', 'preview-conf-bn' => 'Configuración Blanco y Negro', diff --git a/ci4/app/Models/Facturas/FacturaLineaModel.php b/ci4/app/Models/Facturas/FacturaLineaModel.php index 50e9f8d8..a9d4d901 100644 --- a/ci4/app/Models/Facturas/FacturaLineaModel.php +++ b/ci4/app/Models/Facturas/FacturaLineaModel.php @@ -39,9 +39,11 @@ class FacturaLineaModel extends \App\Models\BaseModel { "t1.id AS id, t1.factura_id AS factura_id, t1.pedido_linea_impresion_id AS pedido_linea_impresion_id, t1.pedido_maquetacion_id AS pedido_maquetacion_id, t1.descripcion AS concepto, t1.cantidad as unidades, t1.precio_unidad AS precio_unidad, t1.iva AS iva, - t1.base AS subtotal, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data, t2.pedido_id AS pedido_id" + t1.base AS subtotal, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data, t2.pedido_id AS pedido_id, + t3.total_aceptado AS total_aceptado" ) ->join("pedidos_linea t2", "t2.id = t1.pedido_linea_impresion_id", "left") + ->join("presupuestos t3", "t3.id = t2.presupuesto_id", "left") ->where("t1.factura_id", $factura_id) ->where("t1.deleted_at", null); diff --git a/ci4/app/Models/Presupuestos/PresupuestoModel.php b/ci4/app/Models/Presupuestos/PresupuestoModel.php index 0ec21617..dc8c3ad3 100755 --- a/ci4/app/Models/Presupuestos/PresupuestoModel.php +++ b/ci4/app/Models/Presupuestos/PresupuestoModel.php @@ -142,7 +142,7 @@ class PresupuestoModel extends \App\Models\BaseModel ], "titulo" => [ "label" => "Presupuestos.titulo", - "rules" => "trim|required|max_length[30]", + "rules" => "trim|required|max_length[300]", ], "inc_rei" => [ "label" => "Presupuestos.incRei", diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php index 35202562..09798fba 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php @@ -14,6 +14,7 @@ + id @@ -86,7 +87,7 @@ const actionBtns = function(data) {
- +
`; @@ -97,7 +98,7 @@ const actionBtns = function(data) {
- +
@@ -107,7 +108,7 @@ const actionBtns = function(data) { } }; -var editor = new $.fn.dataTable.Editor( { +var editor_lineas = new $.fn.dataTable.Editor( { ajax: { url: "", headers: { @@ -121,28 +122,14 @@ var editor = new $.fn.dataTable.Editor( { name: "unidades", }, { - name: "concepto", - type: "textarea" + name: "concepto" }, { name: "precio_unidad", - - }, { - name: "iva", - - }, { - "name": "factura_id", - "type": "hidden" - }, { - "name": "pedido_linea_impresion_id", - "type": "hidden" - },{ - "name": "pedido_maquetacion_id", - "type": "hidden" - }, + } ] } ); -editor.on( 'preSubmit', function ( e, d, type ) { +editor_lineas.on( 'preSubmit', function ( e, d, type ) { if ( type === 'create'){ d.data[0]['factura_id'] = id ?>; } @@ -154,12 +141,12 @@ editor.on( 'preSubmit', function ( e, d, type ) { }); -editor.on( 'postSubmit', function ( e, json, data, action ) { +editor_lineas.on( 'postSubmit', function ( e, json, data, action ) { yeniden(json.); }); -editor.on( 'submitSuccess', function ( e, json, data, action ) { +editor_lineas.on( 'submitSuccess', function ( e, json, data, action ) { tableLineas.clearPipeline(); tableLineas.draw(); @@ -168,7 +155,7 @@ editor.on( 'submitSuccess', function ( e, json, data, action ) { // Activate an inline edit on click of a table cell $('#tableOfLineasFactura').on( 'click', 'tbody span.edit', function (e) { - editor.inline( + editor_lineas.inline( tableLineas.cells(this.parentNode.parentNode, '*').nodes(), { cancelHtml: '', @@ -189,11 +176,41 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({ scrollX: true, columns: [ {data: null, render: actionBtns}, + {data: "id"}, {data: "pedido_linea_impresion_id"}, {data: "pedido_maquetacion_id"}, {data: "pedido_id"}, {data: "unidades"}, - {data: "concepto"}, + { + data: "concepto", + render: function (data, type, row, meta) { + + // se convierten a float data.total_aceptado y subtotal + var total_aceptado = parseFloat(row.total_aceptado); + var subtotal = parseFloat(row.subtotal); + + var error_text = ''; + if(total_aceptado != subtotal){ + error_text = 'El total del pedido ('+ total_aceptado + '€) no coincide con la línea ('+ subtotal + '€)'; + } + + return ` +
+ ${data} +
+ +
+ + ${error_text} +
+ +
+ + +
+ `; + } + }, {data: "precio_unidad"}, {data: "iva"}, {data: "subtotal"}, @@ -219,7 +236,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({ }, { visible: false, - targets: [1, 2, 3, 9, 10] + targets: [1, 2, 3, 4, 10, 11] } ], diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_disenioLibroItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_disenioLibroItems.php index 66de6299..442b8694 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_disenioLibroItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/_disenioLibroItems.php @@ -16,7 +16,7 @@
- + estado_id == 2): ?> +
+
+ + > +
+
+
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cosidotapablanda/_resumenPresupuestos.js b/ci4/app/Views/themes/vuexy/form/presupuestos/cosidotapablanda/_resumenPresupuestos.js index 6cfb891e..a7351f3f 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cosidotapablanda/_resumenPresupuestos.js +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cosidotapablanda/_resumenPresupuestos.js @@ -177,8 +177,8 @@ function updateTotales(updateLP=true, updateServicios=true, updateEnvio=true){ margenEnvios = parseFloat($('#margenEnvios').attr('val')) } - var totalCostes = totalPapel + totalImpresion + totalServicios + totalEnvios - var totalMargenes = margenPapel + margenImpresion + margenServicios + margenEnvios + var totalCostes = parseFloat(totalPapel.toFixed(2)) + parseFloat(totalImpresion.toFixed(2)) + parseFloat(totalServicios.toFixed(2)) + parseFloat(totalEnvios.toFixed(2)) + var totalMargenes = parseFloat(margenPapel.toFixed(2)) + parseFloat(margenImpresion.toFixed(2)) + parseFloat(margenServicios.toFixed(2)) + parseFloat(margenEnvios.toFixed(2)) $('#totalCostes').text((addSeparatorsNF(totalCostes.toFixed(2), ".", ",", ".")) + "€") $('#totalMargenes').text((addSeparatorsNF(totalMargenes.toFixed(2), ".", ",", ".")) + "€") $('#totalCostes').attr('val',(totalCostes).toFixed(2) + '€') @@ -251,11 +251,13 @@ function getValuesResumenForm(){ formResumen += '&total_presupuesto=' + $('#totalDespuesDecuento').attr('val'); formResumen += '&total_precio_unidad=' + $('#precioUnidadPresupuesto').attr('val'); - formResumen += '&total_factor=' + $('#total_factor').text(); - formResumen += '&total_factor_ponderado=' + $('#total_factor_ponderado').text(); + // replace , for . in the values + formResumen += '&total_factor=' + $('#factor').text().replace(/,/g, '.'); + formResumen += '&total_factor_ponderado=' + $('#factor_ponderado').text().replace(/,/g, '.'); if($('#confirmar_presupuesto').prop('checked')){ - formResumen += '&confirmar=1'; + formResumen += '&confirmar=1'; + formResumen += '&total_aceptado=' + $('#totalDespuesDecuento').attr('val'); } return formResumen