diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 49f6451d..ca0cd92a 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -751,7 +751,9 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func *========================**/ $routes->post("update/tarea", 'Ordentrabajo::update_orden_trabajo_tarea'); $routes->post("update/date", 'Ordentrabajo::update_orden_trabajo_date'); + $routes->post("reset/date", 'Ordentrabajo::reset_orden_trabajo_date'); $routes->post("update/pedido/date", 'Ordentrabajo::update_orden_trabajo_pedido_date'); + $routes->post("reset/pedido/date", 'Ordentrabajo::reset_orden_trabajo_pedido_date'); $routes->post("update/pedido", 'Ordentrabajo::update_orden_trabajo_pedido'); $routes->post("update/user", 'Ordentrabajo::update_orden_trabajo_user'); $routes->post("update", 'Ordentrabajo::update_orden_trabajo'); diff --git a/ci4/app/Controllers/Produccion/Ordentrabajo.php b/ci4/app/Controllers/Produccion/Ordentrabajo.php index 1c08aee0..bded7f1d 100755 --- a/ci4/app/Controllers/Produccion/Ordentrabajo.php +++ b/ci4/app/Controllers/Produccion/Ordentrabajo.php @@ -121,6 +121,19 @@ class Ordentrabajo extends BaseController return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); } } + public function reset_orden_trabajo_date() + { + $bodyData = $this->request->getPost(); + // return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "data" => $bodyData]); + $validated = $this->validation->run($bodyData, "orden_trabajo_date"); + if ($validated) { + $validatedData = $bodyData; + $r = $this->produccionService->emptyOrdenTrabajoDate($validatedData['orden_trabajo_id'],$validatedData['name']); + return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r, "user" => auth()->user(), "data" => $bodyData]); + } else { + return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); + } + } public function update_orden_trabajo_pedido_date() { try { @@ -131,6 +144,18 @@ class Ordentrabajo extends BaseController return $this->response->setJSON(["errors" => $th->getMessage(), "status" => false])->setStatusCode(500); } } + public function reset_orden_trabajo_pedido_date() + { + $bodyData = $this->request->getPost(); + $validated = $this->validation->run($bodyData, "orden_trabajo_date"); + if ($validated) { + $validatedData = $bodyData; + $r = $this->produccionService->init($bodyData['orden_trabajo_id'])->emptyOrdenTrabajoPedidoDate($validatedData['name']); + return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r, "user" => auth()->user(), "data" => $bodyData]); + } else { + return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); + } + } public function update_orden_trabajo_pedido() { try { diff --git a/ci4/app/Services/ProductionService.php b/ci4/app/Services/ProductionService.php index 3e4ee1b6..b929816b 100755 --- a/ci4/app/Services/ProductionService.php +++ b/ci4/app/Services/ProductionService.php @@ -982,6 +982,18 @@ class ProductionService extends BaseService $this->updateProgress(); return $result; } + public function emptyOrdenTrabajoDate(int $orden_trabajo_id, string $dateName) + { + $status = $this->otDate->where('orden_trabajo_id', $orden_trabajo_id) + ->set($dateName, null) + ->update(); + if (isset($this->ordenTrabajoConfig->DATE_USER_MAPPING[$dateName])) { + $this->otUser->where('orden_trabajo_id', $orden_trabajo_id) + ->set($this->ordenTrabajoConfig->DATE_USER_MAPPING[$dateName], auth()->user()->id) + ->update(); + } + return $status; + } public function updateOrdenTrabajoPedidoDate($data): array { $status = false; @@ -1004,6 +1016,25 @@ class ProductionService extends BaseService "status" => $status ]; } + public function emptyOrdenTrabajoPedidoDate(string $dateName) + { + $status = false; + $user = auth()->user(); + $row = []; + $pedidoDatesUser = $this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO; + if (isset($pedidoDatesUser[$dateName])) { + $attrUserPedido = $pedidoDatesUser[$dateName]; + $row[$attrUserPedido] = $user->id; + $row[$dateName] = null; + $status = $this->pedidoModel->update($this->pedido->id, $row); + $this->updateProgress(); + } else { + throw new Exception(lang('Produccion.errors.attr_not_exist', [$dateName])); + } + + + return $status; + } public function updateOrdenTrabajo($data): bool { if (isset($data["is_pedido_espera"])) { diff --git a/ci4/app/Views/themes/vuexy/form/produccion/ot/otDates.php b/ci4/app/Views/themes/vuexy/form/produccion/ot/otDates.php index 532f6237..5182f889 100755 --- a/ci4/app/Views/themes/vuexy/form/produccion/ot/otDates.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/ot/otDates.php @@ -16,13 +16,19 @@
- +
+ + +
- > +
+ > + +
@@ -31,7 +37,10 @@
- /> +
+ /> + +
@@ -39,7 +48,10 @@
- /> +
+ /> + +
@@ -49,13 +61,17 @@
- /> + +
+ /> + +
diff --git a/ci4/app/Views/themes/vuexy/form/produccion/ot/otProgress.php b/ci4/app/Views/themes/vuexy/form/produccion/ot/otProgress.php index cf06595f..b1159005 100755 --- a/ci4/app/Views/themes/vuexy/form/produccion/ot/otProgress.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/ot/otProgress.php @@ -25,33 +25,45 @@
-

-
+

+
"> - > +
+ > + +
" ?>
""> - - > + +
+ > + +
" ?>
"> - > -
"?>
+
+ > + +
+
" ?>
"> - > +
+ > + +
" ?>
@@ -59,63 +71,90 @@
-

-
+

+
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
@@ -123,38 +162,53 @@
-

-
+

+
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
- > +
+ > + +
" ?>
- > +
+ > + +
" ?>
@@ -163,39 +217,54 @@
-
-

-
+
+

+
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
"> - > +
+ > + +
" ?>
diff --git a/httpdocs/assets/js/safekat/pages/produccion/ot.js b/httpdocs/assets/js/safekat/pages/produccion/ot.js index 94831f66..e96dc497 100644 --- a/httpdocs/assets/js/safekat/pages/produccion/ot.js +++ b/httpdocs/assets/js/safekat/pages/produccion/ot.js @@ -1,7 +1,7 @@ import Ajax from "../../components/ajax.js" import ClassSelect from "../../components/select2.js"; import DatePicker from "../../components/datepicker.js"; -import { alertConfirmAction, alertConfirmationDelete, alertSuccess } from "../../components/alerts/sweetAlert.js"; +import { alertConfirmAction, alertConfirmationDelete, alertError, alertSuccess } from "../../components/alerts/sweetAlert.js"; import Modal from "../../components/modal.js" import FileUploadDropzone from '../../components/forms/fileUploadDropzone.js'; class OrdenTrabajo { @@ -17,6 +17,9 @@ class OrdenTrabajo { this.alertOrdenTrabajo = this.item.find("#alert-orden-trabajo"); this.btnFinalizarPedido = this.item.find("#btn-finalizar-orden-pedido") this.btnReactivarOt = this.item.find("#btn-reactivar-orden-pedido") + this.btnEraseDate = this.item.find('.btn-erase-date'); + this.btnErasePedidoDate = this.item.find('.btn-erase-pedido-date'); + this.isOtFinalizada = false; this.btnResetTareas = this.item.find("#btn-reset-tareas") @@ -61,7 +64,7 @@ class OrdenTrabajo { altInput: true, altFormat: "d/m/Y", dateFormat: "Y-m-d", - allowInput: true, + allowInput: false, } this.tiempoProcesamiento = this.otForm.find("#ot-tiempo-procesamiento") this.fechaImpresion = new DatePicker(this.otForm.find("#ot-fecha-impresion"), option) @@ -144,7 +147,8 @@ class OrdenTrabajo { this.otForm.on("click", "#btn-delete-portada", this.handleDeletePortada.bind(this)) this.btnFinalizarPedido.on("click", this.handleFinalizarPedido.bind(this)) this.btnReactivarOt.on("click", this.handleReactivarPedido.bind(this)) - + this.btnEraseDate.on('click', this.handleEraseDate.bind(this)) + this.btnErasePedidoDate.on('click', this.handleErasePedidoDate.bind(this)) this.tareasTableItem.on("click", ".ot-tarea-btn-delete", this.handleTareaDeleteConfirmation.bind(this)) this.item.on("click", "#btn-reset-tareas", this.handleResetTareasDeleteConfirmation.bind(this)) this.otForm.on("click", ".ot-tarea-comment", this.handleNoteTarea.bind(this)) @@ -496,7 +500,8 @@ class OrdenTrabajo { const key = $(event.currentTarget).attr("name") const data = {} const element = $(event.currentTarget); - data[key] = $(event.currentTarget).val() + const value = $(event.currentTarget).val() + data[key] = value data["orden_trabajo_id"] = this.modelId data["name"] = key; const ajax = new Ajax( @@ -506,7 +511,12 @@ class OrdenTrabajo { this.handleDateChangeSuccess.bind(this, element), this.handleDateChangeError.bind(this) ) - ajax.post(); + if (value) { + + ajax.post(); + } else { + this.handleEraseDate(event) + } } handleDateChangeSuccess(formItem, response) { @@ -514,8 +524,8 @@ class OrdenTrabajo { alertSuccess(response.message).fire() this._handleGetData(); if (response.user) { - formItem.parent().find(".form-text").remove() - formItem.parent().append(`
${[response.user.first_name, response.user.last_name].join(" ")}
`) + formItem.parent().parent().find(".form-text").remove() + formItem.parent().parent().append(`
${[response.user.first_name, response.user.last_name].join(" ")}
`) } } handleDateChangeError(errors) { } @@ -523,7 +533,8 @@ class OrdenTrabajo { const key = $(event.currentTarget).attr("name") const data = {} const element = $(event.currentTarget); - data[key] = $(event.currentTarget).val() + const value = element.val() + data[key] = value data["orden_trabajo_id"] = this.modelId data["name"] = key; const ajax = new Ajax( @@ -533,7 +544,11 @@ class OrdenTrabajo { this.handleDateChangeSuccess.bind(this, element), this.handleDateChangeError.bind(this) ) - ajax.post(); + if (value) { + ajax.post(); + } else { + this.handleErasePedidoDate(event) + } } handlePedidoCheckChange(event) { const key = $(event.currentTarget).attr("name") @@ -745,6 +760,68 @@ class OrdenTrabajo { this.tareaCommentModal.toggle() } } + handleEraseDate(event) { + let name = $(event.currentTarget).parent().find('input').attr('name') + let ajax = new Ajax('/produccion/ordentrabajo/reset/date', { + name: name, + orden_trabajo_id: this.modelId + }, + null, + this.handleEraseDateSuccess.bind(this), + this.handleEraseDateError.bind(this) + ) + alertConfirmationDelete() + .then(result => { + if (result.isConfirmed) { + console.log(name) + ajax.post() + } + }) + } + handleEraseDateSuccess(response) { + this.item.find(`input[name="${response.data.name}"]`).val(null) + if (response.user) { + this.item.find(`input[name="${response.data.name}"]`).parent().parent().find(".form-text").remove() + this.item.find(`input[name="${response.data.name}"]`).parent().parent().append(`
${[response.user.first_name, response.user.last_name].join(" ")}
`) + } + alertSuccess(response.message).fire() + this._handleGetData() + } + handleEraseDateError(error) { + alertError(error.message).fire() + this._handleGetData() + } + handleErasePedidoDate(event) { + let name = $(event.currentTarget).parent().find('input').attr('name') + let ajax = new Ajax('/produccion/ordentrabajo/reset/pedido/date', { + name: name, + orden_trabajo_id: this.modelId + }, + null, + this.handleErasePedidoDateSuccess.bind(this), + this.handleErasePedidoDateError.bind(this) + ) + alertConfirmationDelete() + .then(result => { + if (result.isConfirmed) { + console.log(name) + ajax.post() + } + }) + } + handleErasePedidoDateSuccess(response) { + this.item.find(`input[name="${response.data.name}"]`).val(null) + if (response.user) { + this.item.find(`input[name="${response.data.name}"]`).parent().parent().find(".form-text").remove() + this.item.find(`input[name="${response.data.name}"]`).parent().parent().append(`
${[response.user.first_name, response.user.last_name].join(" ")}
`) + } + alertSuccess(response.message).fire() + this._handleGetData() + } + handleErasePedidoDateError(error) { + alertError(error.message).fire() + this._handleGetData() + } }