erase ot dates

This commit is contained in:
amazuecos
2025-04-25 12:57:14 +02:00
parent cc2c9eee1c
commit 4379a9d23b
6 changed files with 274 additions and 51 deletions

View File

@ -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(`<div class="form-text">${[response.user.first_name, response.user.last_name].join(" ")}</div>`)
formItem.parent().parent().find(".form-text").remove()
formItem.parent().parent().append(`<div class="form-text">${[response.user.first_name, response.user.last_name].join(" ")}</div>`)
}
}
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(`<div class="form-text">${[response.user.first_name, response.user.last_name].join(" ")}</div>`)
}
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(`<div class="form-text">${[response.user.first_name, response.user.last_name].join(" ")}</div>`)
}
alertSuccess(response.message).fire()
this._handleGetData()
}
handleErasePedidoDateError(error) {
alertError(error.message).fire()
this._handleGetData()
}
}