revision ot v2

This commit is contained in:
amazuecos
2025-05-04 17:25:53 +02:00
parent db70c57fb3
commit fb7f2a28d9
30 changed files with 897 additions and 169 deletions

View File

@ -0,0 +1,175 @@
import Ajax from '../../../components/ajax.js'
import { alertConfirmAction, alertError, alertSuccess } from '../../../components/alerts/sweetAlert.js'
class MaquinistaFichajeAuto {
constructor(domItem) {
this.item = domItem
/** ELEMENT DOM VARIABLES */
this.otInputId = this.item.find('#ot-id')
this.wrapperCard = this.item.find('#ot-fa-card')
this.btnCancelTarea = this.item.find('#btn-cancel-tarea')
this.btnFinishTarea = this.item.find('#btn-finish-tarea')
this.inputClickInit = this.item.find("#input-click-init")
this.inputClickEnd = this.item.find("#input-click-end")
this.otId = null
this.lastOtId = null
this.maquinaId = this.item.data("id")
this.tareas = []
}
init() {
Notiflix.Block.circle('.section-block');
this.otInputId.trigger('focus')
this.otInputId.on('change', this._handleGetOt.bind(this))
this.btnFinishTarea.on('click', this._handleFinishTareasConfirm.bind(this))
}
hideCard() {
this.wrapperCard.addClass('d-none')
}
showCard() {
this.wrapperCard.removeClass('d-none')
}
actionLoader(status = true) {
if (status) {
Notiflix.Block.circle('.section-block');
} else {
Notiflix.Block.remove('.section-block');
}
}
getFormData() {
return {
maquina_id: this.maquinaId,
tareas: this.tareas,
click_init: this.inputClickInit.val() ?? 0,
click_end: this.inputClickEnd.val() ?? 0
}
}
fillData(data) {
this.lastOtId = data.ot.id
this.item.find('#ot-id-header').text(data.ot.id)
this.item.find('#presupuesto-id').text(data.presupuesto.id)
this.item.find('#ot-title').text(data.presupuesto.titulo)
if (data.tareas) {
this.tareas = data.tareas.map(tarea => tarea.id)
}
}
_handleGetOt() {
this.otId = this.otInputId.val();
this.otInputId.removeClass('is-valid')
this.otInputId.removeClass('is-invalid')
this.actionLoader(false)
let ajax = new Ajax(
`/produccion/ordentrabajo/tareas/maquina/${this.otId}/${this.maquinaId}`,
null,
null,
this._handleGetOtSuccess.bind(this),
this._handleGetOtError.bind(this)
)
if (this.otId) {
ajax.get();
}
}
_handleGetOtSuccess(response) {
this.showCard();
if (this.lastOtId) {
console.log("Siguiente OT insertada")
console.log("Iniciar ", this.otId)
if (this.lastOtId != this.otId) {
console.log("Finalizar", this.lastOtId)
this._handleFinishTareas(this.lastOtId)
}
} else {
console.log("Primera OT insertada")
}
this.otInputId.addClass('is-valid')
popSuccessAlert(response.message)
this.actionLoader(false)
if (response.data) {
this.fillData(response.data)
response.data.tareas.forEach(tarea => {
this._handleInitTareas(tarea.id, 'I')
});
}
}
_handleGetOtError(error) {
this.hideCard()
this.otInputId.addClass('is-invalid')
popErrorAlert(error.responseJSON.message)
}
_handleInitTareas(tareaId, estado = 'I') {
let ajax = new Ajax('/produccion/ordentrabajo/update/tarea/progress',
{
ot_tarea_id: tareaId,
estado: estado
}, null,
this._handleInitTareasSuccess.bind(this),
this._handleInitTareasError.bind(this)
);
if (tareaId) {
ajax.post();
}
}
_handleInitTareasSuccess() { }
_handleInitTareasError() { }
_handleFinishTareas(otId) {
let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/finish',
{
orden_trabajo_id: otId,
...this.getFormData()
}, null,
this._handleFinishTareasSucess.bind(this),
this._handleFinishTareasError.bind(this)
);
ajax.post()
}
_handleFinishTareasConfirm(event) {
let otId = this.otInputId.val()
console.log("Finalizar", otId);
let ajax = new Ajax('/produccion/ordentrabajo/fa/tareas/finish',
{
orden_trabajo_id: otId,
...this.getFormData()
}, null,
this._handleFinishTareasConfirmSucess.bind(this),
this._handleFinishTareasConfirmError.bind(this)
);
if (otId) {
alertConfirmAction('Se va finalizar la tarea actual y se cancelará el modo auto.')
.then((result) => {
if (result.isConfirmed) {
ajax.post();
}
})
}
}
_handleFinishTareasConfirmSucess(response) {
this.hideCard()
this.otInputId.val(null)
this.otId = null
this.lastOtId = null
this.tareas = []
popSuccessAlert(response.message)
}
_handleFinishTareasConfirmError() { }
_handleFinishTareasSucess() { }
_handleFinishTareasError() { }
}
export default MaquinistaFichajeAuto;

View File

@ -0,0 +1,109 @@
import Ajax from '../../../components/ajax.js'
import { alertConfirmAction, alertError, alertSuccess } from '../../../components/alerts/sweetAlert.js'
class MaquinistaScan {
constructor(domItem) {
this.item = domItem
/** ELEMENT DOM VARIABLES */
this.otInputId = this.item.find('#ot-id')
this.wrapperCard = this.item.find('#ot-fa-card')
this.otId = null
this.maquinaId = this.item.data("id")
this.ots = []
this.datatableItem = this.item.find('#table-scanned-ots')
this.datatableColumns = [
{ data: 'id', searchable: false, sortable: false },
{ data: 'title', searchable: false, sortable: false },
]
this.datatableData = [];
}
init() {
this.otInputId.trigger('focus')
this.otInputId.on('change', this.addOt.bind(this))
this.datatable = this.datatableItem.DataTable({
processing: true,
serverSide: false,
ordering: false,
dom: "",
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: this.datatableColumns,
data: this.datatableData
});
}
hideCard() {
this.wrapperCard.addClass('d-none')
}
showCard() {
this.wrapperCard.removeClass('d-none')
}
actionLoader(status = true) {
if (status) {
Notiflix.Block.circle('.section-block');
} else {
Notiflix.Block.remove('.section-block');
}
}
reloadFocus(){
this.otInputId.val("")
this.otInputId.trigger('focus')
}
async addOt() {
try {
if (this.ots.includes(this.otInputId.val())) {
throw new Error("Esta OT ya ha sido introducida");
}
if (this.otInputId.val()) {
let response = await this.getOt(this.otInputId.val())
console.log(response)
const data = response.data
this.ots.push(data.ot.id)
this.datatable.rows.add([{
id: data.ot.id,
title: data.presupuesto.titulo
}])
this.datatable.draw()
this.reloadFocus()
}
} catch (error) {
console.log(error)
this.reloadFocus()
if (error?.responseJSON) {
popErrorAlert(error.responseJSON.message)
} else {
popErrorAlert(error)
}
}
}
getOt(otId) {
return new Promise((resolve, reject) => {
let ajax = new Ajax(
`/produccion/ordentrabajo/tareas/maquina/${otId}/${this.maquinaId}`,
null,
null,
(response) => {
resolve(response)
},
(error) => {
reject(error)
}
)
ajax.get();
})
}
}
export default MaquinistaScan;

View File

@ -4,13 +4,15 @@ class MaquinistaTareaList {
this.item = domItem
this.maquinaId = this.item.data("id")
this.datatableItem = $("#maquinista-tarea-table")
this.datatableTareaAplazadaItem = this.item.find('#maquinista-tarea-aplazada-table')
this.wrapperDatatableTareaAplazada = this.item.find('#tareas-aplazadas')
this.btnTareasHoy = $("#btn-tareas-hoy")
this.todayDate = $('#today-date')
this.btnAllTareas = $("#btn-all-tareas")
this.datatableColumns = [
{ data: 'otId', searchable: false, sortable: false },
{ data: 'tareaName', searchable: false, sortable: false },
{ data: 'tareaEstado', searchable: false, sortable: false,render : this.renderStado.bind(this)},
{ data: 'tareaEstado', searchable: false, sortable: false, render: this.renderStado.bind(this) },
// { data: 'presupuesto_titulo', searchable: false, sortable: false },
// { data: 'papel_impresion', searchable: false, sortable: false },
// { data: 'papel_gramaje', searchable: false, sortable: false },
@ -18,27 +20,28 @@ class MaquinistaTareaList {
{ data: 'action', searchable: false, sortable: false, width: "20rem" },
]
this.urlAll = '/produccion/ordentrabajo/maquinista/maquinas/tareas/datatable/all/' + this.maquinaId
this.urlAplazada = '/produccion/ordentrabajo/maquinista/maquinas/tareas/aplazadas/datatable/' + this.maquinaId
this.urlToday = '/produccion/ordentrabajo/maquinista/maquinas/tareas/datatable/today/' + this.maquinaId
this.initTable()
this.estadoClass = {
I : 'primary',
P : 'warning',
S : 'warning',
D : 'danger',
F : 'success'
I: 'primary',
P: 'warning',
S: 'warning',
D: 'danger',
F: 'success'
}
this.estadoNames = {
I : 'Iniciada',
P : 'Pendiente',
S : 'Pausada',
D : 'Aplazada',
F : 'Finalizada'
I: 'Iniciada',
P: 'Pendiente',
S: 'Pausada',
D: 'Aplazada',
F: 'Finalizada'
}
}
init(){
this.btnTareasHoy.on('click',this.loadToday.bind(this))
this.btnAllTareas.on('click',this.loadAll.bind(this))
init() {
this.btnTareasHoy.on('click', this.loadToday.bind(this))
this.btnAllTareas.on('click', this.loadAll.bind(this))
}
initTable() {
@ -51,13 +54,28 @@ class MaquinistaTareaList {
bottomEnd: 'paging'
},
serverSide: true,
pageLength: 25,
pageLength: 100,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: this.datatableColumns,
ajax: this.urlToday
});
this.datatableAplazada = this.datatableTareaAplazadaItem.DataTable({
processing: true,
layout: {
bottomStart: 'info',
bottomEnd: 'paging'
},
serverSide: true,
pageLength: 100,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: this.datatableColumns,
ajax: this.urlAplazada
});
this.datatableAplazada.on('draw.dt', this.handleShowTareasAplazadas.bind(this))
}
loadToday() {
this.btnTareasHoy.removeClass('active')
@ -66,25 +84,34 @@ class MaquinistaTareaList {
this.btnAllTareas.removeAttr('aria-pressed')
this.todayDate.removeClass('d-none')
this.btnTareasHoy.addClass('active')
this.btnTareasHoy.attr('aria-pressed',true)
this.btnTareasHoy.attr('aria-pressed', true)
this.datatable.ajax.url(this.urlToday)
this.datatable.ajax.reload()
}
loadAll(){
loadAll() {
this.btnTareasHoy.removeClass('active')
this.btnTareasHoy.removeAttr('aria-pressed')
this.todayDate.addClass('d-none')
this.btnAllTareas.addClass('active')
this.btnAllTareas.attr('aria-pressed',true)
this.btnAllTareas.attr('aria-pressed', true)
this.datatable.ajax.url(this.urlAll)
this.datatable.ajax.reload()
}
renderStado(d){
renderStado(d) {
return `<span class="badge text-bg-${this.estadoClass[d]}">${this.estadoNames[d]}</span>`
return `<span class="badge" style="background-color:${d.color};color:white">${d.title}</span>`
}
handleShowTareasAplazadas() {
let totalTareasAplazadas = this.datatableAplazada.page.info().recordsTotal
console.log(totalTareasAplazadas)
if (totalTareasAplazadas > 0) {
this.wrapperDatatableTareaAplazada.removeClass('d-none')
} else {
this.wrapperDatatableTareaAplazada.addClass('d-none')
}
}
}

View File

@ -123,10 +123,12 @@ class MaquinistaTareaView {
}
}
handleGetTareaProgressSuccess(response) {
if (response.progress_dates) {
if (response.progress_dates.length > 0) {
let lastStatus = response.progress_dates.findLast(e => e.estado != null).estado
console.log("Last status :", lastStatus)
this.showBasedOnStatus(lastStatus)
}else{
this.showBasedOnStatus('P')
}
this.item.find('#tiempo-real-info').html(response.tiempo_trabajado ?? "00:00")
this.actionLoader(false)

View File

@ -0,0 +1,7 @@
import MaquinistaFichajeAuto from "./maquinistaFichajeAuto.js";
$(() => {
console.info("MAQUINISTA FA")
let maquinistaFA = new MaquinistaFichajeAuto($("#viewMaquinistaFichajeAuto"))
maquinistaFA.init();
})

View File

@ -0,0 +1,7 @@
import MaquinistaScan from "./maquinistaScan.js";
$(() => {
console.info("MAQUINISTA SCAN")
let maquinistaScan = new MaquinistaScan($("#viewMaquinistaTareaScan"))
maquinistaScan.init();
})

View File

@ -33,6 +33,7 @@ class OrdenTrabajo {
this.datatableColumns = [
{ data: 'orden', searchable: true, sortable: true, render: this._renderOrdenTarea.bind(this) },
{ data: 'nombre', searchable: true, sortable: true },
{ data: 'tarea_estado', searchable: false, sortable: false, render: this._renderTareaEstado.bind(this) },
{
data: 'maquina_presupuesto_linea', searchable: true, sortable: true, render: (d) => {
if (d) {
@ -68,10 +69,9 @@ class OrdenTrabajo {
*/
this.configUploadDropzone = {
domElement: '#dropzone-ot-files',
nameId: "orden_trabajo_id",
getUri: '/produccion/ordentrabajo/get_files',
postUri: '/produccion/ordentrabajo/upload_files',
resourcePath: 'orden_trabajo/' + this.modelId
nameId: "presupuesto_id",
getUri: '/presupuestos/presupuestocliente/get_files',
postUri: '/presupuestos/presupuestocliente/upload_files'
}
if ($(this.configUploadDropzone.domElement).length > 0) {
this.fileUploadDropzone = new FileUploadDropzone(this.configUploadDropzone)
@ -266,6 +266,22 @@ class OrdenTrabajo {
</div>`
return cell;
}
_renderTareaEstado(d, t) {
let html = `
<div class="btn-group dropstart">
<button style="background-color:${d.color};color:white" class="btn btn-xs dropdown-toggle" type="button" data-bs-toggle="dropdown">
${d.title}
</button>
<ul class="dropdown-menu">
<li> <a class="dropdown-item" href="javascript:void(0);">${d.userName}</a> </li>
</ul>
</div>
`
if(d.userName == ""){
html = `<span style="background-color:${d.color};color:white" class="badge">${d.title}</span>`
}
return html
}
_renderOrdenTarea(d, t) {
return `
@ -431,6 +447,13 @@ class OrdenTrabajo {
this.fillPreimpresionReview()
this.fillPliegos()
this.isOtFinalizada = this.summaryData.ot.estado == "F";
if (this.isOtFinalizada) {
this.btnEraseDate.addClass('d-none').attr('disabled', 'disabled')
this.btnErasePedidoDate.addClass('d-none').attr('disabled', 'disabled')
} else {
this.btnEraseDate.removeClass('d-none').removeAttr('disabled')
this.btnErasePedidoDate.removeClass('d-none').removeAttr('disabled')
}
this.datatableTareas.ajax.reload()
} catch (error) {
console.error(error)