$(document).ready(function () { if ( VERBOSE ) { console.log("boxenerstellung.js loading ..."); } activateTBCodeAndDeactivateBtnAddBox(); // erstmal den Inhalt aller Boxen und Typen holen ... BE.boxInhalte3040 = DB.getBoxinhalte("3040"); BE.boxInhalte3030 = DB.getBoxinhalte("3030"); BE.boxInhalte2121 = DB.getBoxinhalte("2121"); BE.boxInhalte2121C = DB.getBoxinhalte("2121C"); $("body").off("keypress", "#tbTXLCode"); $("body").off("click", "#btnDelLast"); $("body").off("click", "#btnCreateBox"); $("body").off("click", "#btnReset"); $('body').on("keypress", "body", function(e){ e.preventDefault(); }); $("body").on("keypress", "#tbTXLCode", function(e) { //e.preventDefault(); var keyCode = e.keyCode || e.which; if (keyCode === 13 ) { if ( e.target.value === "" ) { return; } if ( BE.partCnt === 9 ) { swal("Achtung", "Box ist schon voll", "info"); } else { var loc_code = e.target.value; if ( helper.looksLikeTXLCode(loc_code) === 0 ) { var bauteilStatus = DB.getBauteilStatus(loc_code); var flavor = loc_code.substring(0,3); // Bauteilabfrage if ( bauteilStatus === 2) { swal("Fehler", "Bauteil nicht in der DB vorhanden!", "error"); playSound("error"); $("#tbTXLCode").val("").focus(); return; } if ( bauteilStatus === 0) { swal("Fehler", "Bauteil noch nicht gemessen!", "error"); playSound("error"); $("#tbTXLCode").val("").focus(); return; } if ( bauteilStatus === -1) { swal("Fehler", "Fehler beim ermitteln des Bauteilstatus'.", "error"); playSound("error"); $("#tbTXLCode").val("").focus(); return; } // hat das Bauteil schon einen Eintrag in der Spalte "Lieferbox"? if ( DB.getBauteilLieferbox(loc_code) > 0 ) { swal("Achtung", "Bauteil ist in der Bauteil-Tabelle schon einer Lieferbox zugewiesen (" + DB.getBauteilLieferbox(loc_code) + ")", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); return; } // schon in der geradezu erstellenden box? if ( schonInDerBox(loc_code) ) { swal("Fehler", "Bauteil ist doch schon in der Box ...", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); return; } // BE.boxInhalte3040 = DB.getBoxinhalte("3040"); // BE.boxInhalte3030 = DB.getBoxinhalte("3030"); // BE.boxInhalte2121 = DB.getBoxinhalte("2121"); // BE.boxInhalte2121C = DB.getBoxinhalte("2121C"); // schon in einer anderen Box? if ( flavor === "GW1" ) { if ( BE.boxInhalte3040.includes(loc_code)) { swal("Achtung", "Bauteil ist schon in einer anderen Box ...", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); return; } else { playSound("ding"); if ( DEBUG ) { console.log(loc_code + " in keiner Box"); } } } else if ( flavor === "GX1" ) { if ( BE.boxInhalte3030.includes(loc_code)) { swal("Achtung", "Bauteil ist schon in einer anderen Box ...", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); return; } else { playSound("ding"); if ( DEBUG ) { console.log(loc_code + " in keiner Box"); } } } else if ( flavor === "GA1" ) { if ( BE.boxInhalte2121.includes(loc_code)) { swal("Achtung", "Bauteil ist schon in einer anderen Box ...", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); return; } else { playSound("ding"); if ( DEBUG ) { console.log(loc_code + " in keiner Box"); } } } else if ( flavor === "GC1" ) { if ( BE.boxInhalte2121C.includes(loc_code)) { swal("Achtung", "Bauteil ist schon in einer anderen Box ...", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); return; } else { playSound("ding"); if ( DEBUG ) { console.log(loc_code + " in keiner Box"); } } } // hat das Bauteil schon einen Eintrag in der Spalte "Lieferbox"? // if ( DB.getBauteilLieferbox(loc_code) >= 0 ) { // swal("Achtung", "Bauteil ist schon in einer anderen Box ...", "warning"); // playSound("error"); // $("#tbTXLCode").val("").focus(); // return; // } // ist schon ein Bauteil in die liste eingetragen worden? if ( BE.flavToFill === "empty" ) { // nö ... also die Styles anpassen, weil 2121C als String länger ist // und BE.flavToFill festlegen if ( flavor === "GW1" ) { // 3040 $("#BETMPType").text("3040"); btnNormStyle(); BE.flavToFill = "3040"; setBoxNr(Number(DB.getLastBoxNr("3040"))); writeToOptionAndDelTBox(); BE.partCnt += 1; } else if ( flavor === "GX1" ) { // 3030 $("#BETMPType").text("3030"); btnNormStyle(); BE.flavToFill = "3030"; setBoxNr(Number(DB.getLastBoxNr("3030"))); writeToOptionAndDelTBox(); BE.partCnt += 1; } else if ( flavor === "GA1" ) { // 2121 $("#BETMPType").text("2121"); btnNormStyle(); BE.flavToFill = "2121"; setBoxNr(Number(DB.getLastBoxNr("2121"))); writeToOptionAndDelTBox(); BE.partCnt += 1; } else if ( flavor === "GC1" ) { // 2121C $("#BETMPType").text("2121C"); $("#BETMPType").css ("font-size", "6.8em"); $("#divBtns").css("top", "-390"); BE.flavToFill = "2121C"; setBoxNr(Number(DB.getLastBoxNr("2121C"))); writeToOptionAndDelTBox(); BE.partCnt += 1; } // es ist schon ein Bauteil eingetragen } else if ( BE.flavToFill === "3040" ) { if ( flavor === "GW1") { writeToOptionAndDelTBox(); BE.partCnt += 1; } else { swal("Warnung", "Falscher Bauteiltyp\n" + BE.flavToFill + " vs. " + flavor + "", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); } } else if ( BE.flavToFill === "3030" ) { if ( flavor === "GX1") { writeToOptionAndDelTBox(); BE.partCnt += 1; } else { swal("Warnung", "Falscher Bauteiltyp\n" + BE.flavToFill + " vs. " + flavor + "", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); } } else if ( BE.flavToFill === "2121" ) { if ( flavor === "GA1") { writeToOptionAndDelTBox(); BE.partCnt += 1; } else { swal("Warnung", "Falscher Bauteiltyp\n" + BE.flavToFill + " vs. " + flavor + "", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); } } else if ( BE.flavToFill === "2121C" ) { if ( flavor === "GC1") { writeToOptionAndDelTBox(); BE.partCnt += 1; } else { swal("Warnung", "Falscher Bauteiltyp\n" + BE.flavToFill + " vs. " + flavor + "", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); } } if ( BE.partCnt === 9 ) { deactivateTBCodeAndActivateBtnAddBox(); swal("Fertig", "Box ist gefüllt", "info"); playSound("ding"); } } else { swal("Error", "Falscher Trixell-Code", "warning"); playSound("error"); $("#tbTXLCode").val("").focus(); } } } }); $("body").on("click", "#btnDelLast", function () { delLastPart(); }); $("body").on("click", "#btnCreateBox", function () { var tmpType = $('#BETMPType').text(); var newBoxNr = $('#tbBoxNr').val(); var revBox = 0; var contArr = [ newBoxNr, $('#selBauteile option[value=part1]').text(), $('#selBauteile option[value=part2]').text(), $('#selBauteile option[value=part3]').text(), $('#selBauteile option[value=part4]').text(), $('#selBauteile option[value=part5]').text(), $('#selBauteile option[value=part6]').text(), $('#selBauteile option[value=part7]').text(), $('#selBauteile option[value=part8]').text(), $('#selBauteile option[value=part9]').text() ]; var commArr = [ "foobar", $('#tbCom1').text(), $('#tbCom2').text(), $('#tbCom3').text(), $('#tbCom4').text(), $('#tbCom5').text(), $('#tbCom6').text(), $('#tbCom7').text(), $('#tbCom8').text(), $('#tbCom9').text() ]; var myNewBoxJSON = {}; myNewBoxJSON.func = "newVersandBox"; myNewBoxJSON.tmpType = tmpType; myNewBoxJSON.newBoxNr = newBoxNr; myNewBoxJSON.revBox = revBox; myNewBoxJSON.dateTime = heute() + " " + jetzt(); myNewBoxJSON.part1 = contArr[1]; myNewBoxJSON.part2 = contArr[2]; myNewBoxJSON.part3 = contArr[3]; myNewBoxJSON.part4 = contArr[4]; myNewBoxJSON.part5 = contArr[5]; myNewBoxJSON.part6 = contArr[6]; myNewBoxJSON.part7 = contArr[7]; myNewBoxJSON.part8 = contArr[8]; myNewBoxJSON.part9 = contArr[9]; myNewBoxJSON.partCom1 = commArr[1]; myNewBoxJSON.partCom2 = commArr[2]; myNewBoxJSON.partCom3 = commArr[3]; myNewBoxJSON.partCom4 = commArr[4]; myNewBoxJSON.partCom5 = commArr[5]; myNewBoxJSON.partCom6 = commArr[6]; myNewBoxJSON.partCom7 = commArr[7]; myNewBoxJSON.partCom8 = commArr[8]; myNewBoxJSON.partCom9 = commArr[9]; if ( myNewBoxJSON.part1 !== "" && myNewBoxJSON.part2 !== "" && myNewBoxJSON.part3 !== "" && myNewBoxJSON.part4 !== "" && myNewBoxJSON.part5 !== "" && myNewBoxJSON.part6 !== "" && myNewBoxJSON.part7 !== "" && myNewBoxJSON.part8 !== "" && myNewBoxJSON.part9 !== "") { var responseInsertBox = DB.insertBox(myNewBoxJSON); if ( responseInsertBox ) { var responseUpdateBauteilLieferbox = $.parseJSON(DB.updateBauteilLieferbox(contArr)); var allUpdatesHadAffectedRows = true; var updateFehler = ""; /* * DB.updateBauteilLieferbox gibt ein JSON zurueck. Dieses wird durchlaufen * um zu schauen, ob alle SQL-Updates der Lieferbox auf das jeweilige Bauteil * eine Reihe in der SQL-Tabelle verändert haben. Wenn das Bauteil nicht in der * Tabelle Bauteile vorhanden wäre oder die Spalte schon die gleiche Lieferboxnummer * beinhaltet, würde $updateStmt->affected_rows den Wert 0 tragen, da nichts erändert wurde. * Ich kann _so_ also nicht sehen, ob ein Bauteil, welches schon in einer lieferbox ist, * hier nochmal eienr neuen Box zugewiesen wird. Diese Überprüfung sollte aber schon im * Vorfeld mit "BE.boxInhalte3040.includes(loc_code)" abgedeckt sein * */ $.each(responseUpdateBauteilLieferbox, function( key, value ){ if ( value === 0 ) { allUpdatesHadAffectedRows = false; if ( updateFehler === "" ) { updateFehler = key; } else { updateFehler = updateFehler + " & " + key } } }); $("#btnReset").trigger("click"); if ( allUpdatesHadAffectedRows ) { playSound("tada"); swal("Fertig", "Die Box wurde in die Datenbank eingetragen.", "success"); $('#tbBoxNr').val(""); } else { swal({ title: 'Achtung', type: 'warning', html: 'Die Box wurde in die Datenbank eingetragen, aber ' + 'es gab Probleme bei dem zuweisen der Lieferbox bei ' + 'mindestens einem Bauteil:' + '
' + updateFehler + '', showCloseButton: true, showCancelButton: false, confirmButtonText: 'Ok.', }) } } else { swal("Fehler", "beim Eintragen der Box in die Datenbank.\n
Rückgabewert von DBSachen.php->insertNewVersandbox() = false"); playSound("error"); return; } } else { swal("Fehler", "Box ist doch garnicht voll...", "error"); playSound("error"); return; } }); $("body").on("click", "#btnReset", function () { BE.reset(); btnNormStyle(); resetOptionBox(); $("#BETMPType").text(""); btnNormStyle(); }); function delLastPart() { if ( BE.partCnt === 0 ) { return; } actCnt = BE.partCnt; $('#selBauteile option[value=part' + BE.partCnt + ']').text(""); BE.partCnt -= 1; if ( BE.partCnt === 8 ) { activateTBCodeAndDeactivateBtnAddBox(); } } function setBoxNr(lastBox) { var nextBox = lastBox + 1; var maxBox = nextBox + 3; $('#tbBoxNr').val( nextBox ); $('#tbBoxNr').attr("disabled", "true"); } function writeToOptionAndDelTBox() { $('#selBauteile option[value=part' + (BE.partCnt + 1) + ']').text($("#tbTXLCode").val()); $("#tbTXLCode").val("").focus(); } function btnNormStyle() { $("#BETMPType").css("font-size", "7.8em"); $("#divBtns").css("top", "-400"); } function activateTBCodeAndDeactivateBtnAddBox() { $("#tbTXLCode").val(""); $("#tbTXLCode").removeAttr("disabled"); $("#btnCreateBox").attr("disabled", "true");; } function deactivateTBCodeAndActivateBtnAddBox() { $("#tbTXLCode").val(""); $("#tbTXLCode").attr("disabled", "true"); $("#btnCreateBox").removeAttr("disabled"); } function resetOptionBox() { for ( i=0; i<=8; i++) { $('#selBauteile option[value=part' + (i + 1) + ']').text(""); } } function schonInDerBox(txlcode) { $('#selBauteile').each(function (e){ act = $(this).text(); }); return act.includes(txlcode); } if ( VERBOSE ) { console.log("boxenerstellung.js loaded ..."); } });