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 @@
| = lang('Tarifapreimpresion.tarifapreimpresion') ?> | += lang('Presupuestos.precioUnidad') ?> | += lang('Presupuestos.precioTotal') ?> | += lang('Basic.global.Action') ?> | +
|---|