// Al cargar documento $(document).ready(function () { // Obtener el listado de ordenes de fabricación ProductionOrderList(); let producto = localStorage.getItem("producto"); let po = localStorage.getItem("production_order"); Refresco(producto, po); // Obtener tolerancias y mediciones $("#orden_fabricacion").change(function () { var po = $(this).val(); var text = $("#orden_fabricacion option:selected").text(); var partes = text.split("-"); var producto = partes[1].trim(); // guardar en local las variables localStorage.setItem('production_order', po); localStorage.setItem('producto', producto); // refresco pantalla Refresco(producto, po); }); $("#medicion_form").on("submit", function (event) { event.preventDefault(); }); $("#long-muestra").on("keyup", function (event) { PesoMetro(); }); $("#kg-muestra").on("keyup", function (event) { PesoMetro(); }); }); function SetProducto(producto) { // set producto $("#producto").val(producto); } function PesoMetro() { let longMuestra = $("#long-muestra").val(); let pesoMuestra = $("#kg-muestra").val(); let ggMuestra = pesoMuestra / longMuestra; $("#gmm-muestra").val(ggMuestra.toFixed(2)); } function Refresco(producto, po) { // tolerancias para el producto GetTolerancias(producto); // mediciones para la po ObtenerMediciones(po); // datos de la po ProductionOrder(po); // set producto SetProducto(producto); // set cartel mediciones CartelMediciones(producto); } function CartelMediciones(producto) { $("#encabezado-mediciones").text("Mediciones antes del enderezado para el producto: " + producto); } function ProductionOrderList() { $.ajax({ type: "GET", url: "/po/list", dataType: "json", success: function (data) { $.each(data.OrdenFabricacion, function (index, value) { $("#orden_fabricacion").append(""); }); }, error: function () { alert("obtener lista de ordenes de produccion ha fallado"); } }); } function GetTolerancias(producto) { fetch("/tolerance/get", { // tolerancias method: "POST", headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ Medida: producto }) }).then(response => { if (!response.ok) { throw new Error('network response was not ok'); } return response.json(); }).then(data => { // get tolerancia only var tolerancia = data.Tolerancia; // save into local storage localStorage.setItem('tolerancia', JSON.stringify(tolerancia)); // set tolerancias max var tolMaxHeaders = document.querySelectorAll("#tol-max th"); // set values tolMaxHeaders[1].innerText = tolerancia.MMax; tolMaxHeaders[2].innerText = tolerancia.HMax; tolMaxHeaders[3].innerText = tolerancia.SMax; tolMaxHeaders[4].innerText = tolerancia.TMax; tolMaxHeaders[5].innerText = tolerancia.BMax; tolMaxHeaders[7].innerText = "Máx: " + tolerancia.AsimMax; tolMaxHeaders[9].innerText = "Máx: " + tolerancia.AsimMax; // set tolerancias max rec var tolMaxRecHeaders = document.querySelectorAll("#tol-max-rec th"); // set values tolMaxRecHeaders[1].innerText = (tolerancia.MNom + ((tolerancia.MMax - tolerancia.MNom) * 0.75)).toFixed(2); tolMaxRecHeaders[2].innerText = (tolerancia.HNom + ((tolerancia.HMax - tolerancia.HNom) * 0.75)).toFixed(2); tolMaxRecHeaders[3].innerText = (tolerancia.SNom + ((tolerancia.SMax - tolerancia.SNom) * 0.75)).toFixed(2); tolMaxRecHeaders[4].innerText = (tolerancia.TNom + ((tolerancia.TMax - tolerancia.TNom) * 0.75)).toFixed(2); tolMaxRecHeaders[5].innerText = (tolerancia.BNom + ((tolerancia.BMax - tolerancia.BNom) * 0.75)).toFixed(2); // set nominales var tolNomHeaders = document.querySelectorAll("#tol-nominal th"); // set nominales values tolNomHeaders[1].innerText = (tolerancia.MNom).toFixed(2); tolNomHeaders[2].innerText = (tolerancia.HNom).toFixed(2); tolNomHeaders[3].innerText = (tolerancia.SNom).toFixed(2); tolNomHeaders[4].innerText = (tolerancia.TNom).toFixed(2); tolNomHeaders[5].innerText = (tolerancia.BNom).toFixed(2); // set tolerancias min rec var tolMinRecHeaders = document.querySelectorAll("#tol-min-rec th") // set values tolMinRecHeaders[1].innerText = (tolerancia.MNom - ((tolerancia.MNom - tolerancia.MMin) * 0.75)).toFixed(2); tolMinRecHeaders[2].innerText = (tolerancia.HNom - ((tolerancia.HNom - tolerancia.HMin) * 0.75)).toFixed(2); tolMinRecHeaders[3].innerText = (tolerancia.SNom - ((tolerancia.SNom - tolerancia.SMin) * 0.75)).toFixed(2); tolMinRecHeaders[4].innerText = (tolerancia.TNom - ((tolerancia.TNom - tolerancia.TMin) * 0.75)).toFixed(2); tolMinRecHeaders[5].innerText = (tolerancia.BNom - ((tolerancia.BNom - tolerancia.BMin) * 0.75)).toFixed(2); tolMinRecHeaders[7].innerText = "Rec: " + tolerancia.AsimMax * 0.75; tolMinRecHeaders[9].innerText = "Rec: " + tolerancia.AsimMax * 0.75; // set tolerancias min var tolMinHeaders = document.querySelectorAll("#tol-min th") // set values tolMinHeaders[1].innerText = (tolerancia.MMin).toFixed(2); tolMinHeaders[2].innerText = (tolerancia.HMin).toFixed(2); tolMinHeaders[3].innerText = (tolerancia.SMin).toFixed(2); tolMinHeaders[4].innerText = (tolerancia.TMin).toFixed(2); tolMinHeaders[5].innerText = (tolerancia.BMin).toFixed(2); }); } function ObtenerMediciones(po) { $.ajax({ url: "/mediciones/get", type: "POST", data: JSON.stringify({ production_order: po }), dataType: "json", success: function (data) { var mediciones = data.Mediciones; // get table body to append data var medicionesTable = document.getElementById('mediciones-po'); // clean table body medicionesTable.innerHTML = ''; // iterate over data array mediciones.forEach(function (medicion) { // tolerancias var tolerancia = localStorage.getItem('tolerancia'); tolerancia = JSON.parse(tolerancia); // create new row var newRow = medicionesTable.insertRow(); // medicion tipo var medicionTipo = newRow.insertCell(); if (medicion.MedicionTipo === 1) { medicionTipo.textContent = 'M'; } else { medicionTipo.textContent = 'C'; } medicionTipo.className = 'is-size-4 has-text-weight-bold'; // hora var horaCell = newRow.insertCell(); horaVal = new Date(medicion.CreatedAt); var hora = horaVal.getHours(); var minutos = horaVal.getMinutes(); // Formatear la hora para que tenga dos dígitos hora = hora < 10 ? '0' + hora : hora; minutos = minutos < 10 ? '0' + minutos : minutos; // Crear una cadena con la hora formateada var horaString = hora + ':' + minutos; horaCell.textContent = horaString; horaCell.className = 'is-size-4 has-text-weight-bold'; // colada var colada = newRow.insertCell(); colada.textContent = medicion.Colada; colada.className = 'is-size-4 has-text-weight-bold'; // masa unitaria longitud var masa_longitud = newRow.insertCell(); masa_longitud.textContent = medicion.MasaUnitaria.Longitud; masa_longitud.className = 'is-size-4 has-text-weight-bold'; // masa unitaria peso var masa_peso = newRow.insertCell(); masa_peso.textContent = medicion.MasaUnitaria.Peso; masa_peso.className = 'is-size-4 has-text-weight-bold'; // g/mm var gmm = medicion.MasaUnitaria.GramosMM; gmmCell = newRow.insertCell(); gmmCell.textContent = gmm; if (gmm > parseFloat(tolerancia.MMax) || gmm < parseFloat(tolerancia.MMin)) { gmmCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { gmmCell.className = 'is-size-4 has-text-weight-bold'; } // altura perfil var altura_perfil = medicion.AlturaPerfil; alturaPerfilCell = newRow.insertCell(); alturaPerfilCell.textContent = altura_perfil; if (altura_perfil > tolerancia.HMax || altura_perfil < tolerancia.HMin) { alturaPerfilCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { alturaPerfilCell.className = 'is-size-4 has-text-weight-bold'; } // espesor alma var espesor_alma = medicion.EspesorAlma; espesorAlmaCell = newRow.insertCell(); espesorAlmaCell.textContent = espesor_alma; if (espesor_alma > tolerancia.SMax || espesor_alma < tolerancia.SMin) { espesorAlmaCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { espesorAlmaCell.className = 'is-size-4 has-text-weight-bold'; } // espesor ala motor superior var esp_alas_sup_lado_motor = medicion.EspesoresAlas.LadoMotorSup; espesorAlaMotorSupCell = newRow.insertCell(); espesorAlaMotorSupCell.textContent = esp_alas_sup_lado_motor; if (esp_alas_sup_lado_motor > tolerancia.TMax || esp_alas_sup_lado_motor < tolerancia.TMin) { espesorAlaMotorSupCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { espesorAlaMotorSupCell.className = 'is-size-4 has-text-weight-bold'; } // espesor ala motor inferior var esp_alas_lado_motor = medicion.EspesoresAlas.LadoMotorInf; espesorAlaMotorInfCell = newRow.insertCell(); espesorAlaMotorInfCell.textContent = esp_alas_lado_motor; if (esp_alas_lado_motor > tolerancia.TMax || esp_alas_lado_motor < tolerancia.TMin) { espesorAlaMotorInfCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { espesorAlaMotorInfCell.className = 'is-size-4 has-text-weight-bold'; } // espesor ala operador superior var esp_ala_ope_sup = medicion.EspesoresAlas.LadoOperadorSup; espesorAlaOperadorSupCell = newRow.insertCell(); espesorAlaOperadorSupCell.textContent = esp_ala_ope_sup; if (esp_ala_ope_sup > tolerancia.TMax || esp_ala_ope_sup < tolerancia.TMin) { espesorAlaOperadorSupCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { espesorAlaOperadorSupCell.className = 'is-size-4 has-text-weight-bold'; } // espesor ala operador inferior var esp_ala_ope_inf = medicion.EspesoresAlas.LadoOperadorInf; espesorAlaOperadorInfCell = newRow.insertCell(); espesorAlaOperadorInfCell.textContent = esp_ala_ope_inf; if (esp_ala_ope_inf > tolerancia.TMax || esp_ala_ope_inf < tolerancia.TMin) { espesorAlaOperadorInfCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { espesorAlaOperadorInfCell.className = 'is-size-4 has-text-weight-bold'; } // anchura alas lado motor var anch_alas_motor = medicion.AnchuraAlas.LadoMotor; anchuraAlaLadoMotorCell = newRow.insertCell(); anchuraAlaLadoMotorCell.textContent = anch_alas_motor; if (anch_alas_motor > tolerancia.BMax || anch_alas_motor < tolerancia.BMin) { anchuraAlaLadoMotorCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { anchuraAlaLadoMotorCell.className = 'is-size-4 has-text-weight-bold'; } // anchura alas lado operador var anch_alas_operador = medicion.AnchuraAlas.LadoOperador; anchuraAlaLadoOperadorCell = newRow.insertCell(); anchuraAlaLadoOperadorCell.textContent = anch_alas_operador; if (anch_alas_operador > tolerancia.BMax || anch_alas_operador < tolerancia.BMin) { anchuraAlaLadoOperadorCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { anchuraAlaLadoOperadorCell.className = 'is-size-4 has-text-weight-bold'; } // asimetria del alma lado motor superior asimetriaAlmaLadoMotorSupCell = newRow.insertCell(); asimetriaAlmaLadoMotorSupCell.textContent = medicion.AsimetriaAlma.LadoMotorSup; asimetriaAlmaLadoMotorSupCell.className = 'is-size-4 has-text-weight-bold'; // asimetria del alma lado motor inferior asimetriaAlmaLadoMotorInfCell = newRow.insertCell(); asimetriaAlmaLadoMotorInfCell.textContent = medicion.AsimetriaAlma.LadoMotorInf; asimetriaAlmaLadoMotorInfCell.className = 'is-size-4 has-text-weight-bold'; //tolerancia asimetria recomendada tolerancia.AsimRec = tolerancia.AsimMax - ((tolerancia.AsimMax) * .25) // dif asimetria del alma lado motor sup - inferior var dif_asi_alm_motor = (medicion.AsimetriaAlma.LadoMotorSup - medicion.AsimetriaAlma.LadoMotorInf).toFixed(2); difAsimetriaAlmaLadoMotorCell = newRow.insertCell(); difAsimetriaAlmaLadoMotorCell.textContent = dif_asi_alm_motor; if (dif_asi_alm_motor > tolerancia.AsimMax || dif_asi_alm_motor < (tolerancia.AsimMax) * -1) { difAsimetriaAlmaLadoMotorCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { difAsimetriaAlmaLadoMotorCell.className = 'is-size-4 has-text-weight-bold'; } // asimetria del alma lado operador superior asimetriaAlmaLadoOperadorSupCell = newRow.insertCell(); asimetriaAlmaLadoOperadorSupCell.textContent = medicion.AsimetriaAlma.LadoOperadorSup; asimetriaAlmaLadoOperadorSupCell.className = 'is-size-4 has-text-weight-bold'; // asimetria del alma lado operador inferior asimetriaAlmaLadoOperadorInfCell = newRow.insertCell(); asimetriaAlmaLadoOperadorInfCell.textContent = medicion.AsimetriaAlma.LadoOperadorInf; asimetriaAlmaLadoOperadorInfCell.className = 'is-size-4 has-text-weight-bold'; // dif asimetria del alma lado operador sup - inferior var dif_asi_alm_operador = (medicion.AsimetriaAlma.LadoOperadorSup - medicion.AsimetriaAlma.LadoOperadorInf).toFixed(2); difAsimetriaAlmaLadoOperadorCell = newRow.insertCell(); difAsimetriaAlmaLadoOperadorCell.textContent = dif_asi_alm_operador; if (dif_asi_alm_operador > tolerancia.AsimMax || dif_asi_alm_operador < (tolerancia.AsimMax * -1)) { difAsimetriaAlmaLadoOperadorCell.className = 'is-size-4 has-text-weight-bold has-background-danger has-text-white'; } else { difAsimetriaAlmaLadoOperadorCell.className = 'is-size-4 has-text-weight-bold'; } }) }, error: function (error) { console.error("Error:", error) } }); } function ProductionOrder(po) { $.ajax({ url: "/po/get/" + po, type: "GET", success: function (data) { let res = JSON.parse(data); let poData = res.OrdenFabricacion; $("#calidad").val(poData.SteelGrad); }, error: function (error) { console.error('Error:', error); } }); } function GuardarMedicion() { // form data const formData = $("#medicion_form").serialize(); // form data como array let data = $("#medicion_form").serializeArray(); // check form data let allValuesPresent = checkAllValues(data); // si todo ok if (allValuesPresent) { $.ajax({ url: "/medicion/create", type: "POST", data: formData, headers: { 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') }, success: function (data) { alert("medición enviada correctamente!"); let po = localStorage.getItem('production_order'); // mediciones para la po ObtenerMediciones(po); }, error: function (error) { console.error('Error:', error); } }); } else { alert("se deben rellenar todos los campos"); } function checkAllValues(data) { var valuesPresent = true; data.forEach(function (item) { if (item.value.trim() === '' && item.name !== 'observaciones') { valuesPresent = false; return false; } console.log(item); }); return valuesPresent; } return false; }