ordersprinter/webapp/elements/closing.js

1 line
9.8 KiB
JavaScript
Raw Permalink Normal View History

2020-11-19 23:14:48 +01:00
var MAN_CLS_COINS_NOTES_FIELDS_NOT_CORRECTLY_FILLED=["Entweder müssen alle oder gar kein Feld des Zählprotokolls korrekt ausgefüllt sein.","Either all or no fields of the counting protocol must be filled in correctly.","Todos o ninguno de los campos del protocolo de conteo deben ser llenados."];var MAN_COUNTING_SUM=["Summe","Sum","Total"];var MAN_NO_COUNTING_DONE=["Zählprotokoll wurde nicht erfasst.","No counting protocol available.","No hay ningun protocolo de conteo."];var MAN_NOTES_VALUE=["Wert","Value","Valor"];var MAN_COIN_NOTE_TYPE=["Typ","Type","Typo"];var MAN_COIN_NOTE_SUM=["Summe","Sum","Total"];var MAN_COIN_NOTE_COUNT=["Anzahl","Number","Numero"];function Closing(b,c,a){this.closingListExpanded=false;this.areaHeader="";this.coinsHeader="";this.notesHeader="";this.hint="";this.l=c;this.coins=[];this.notes=[];this.decpoint=b;this.currency=a;this.bindNewClosingExpand=function(g,f,e,h){var d=this;this.areaHeader=g;this.coinsHeader=f;this.notesHeader=e;this.hint=h;$("#closinglist").off("collapsibleexpand").on("collapsibleexpand",function(i){i.stopImmediatePropagation();i.preventDefault();if(!d.closingListExpanded){d.closingListExpanded=true;d._createGui()}})};this._createGui=function(){var d=this;doAjax("GET","php/contenthandler.php?module=admin&command=getcoinsandnotes",null,d._handleCoinsAndNotesAndCreateGui.bind(d),"Fehler Münzen/Banknoten")};this._handleCoinsAndNotesAndCreateGui=function(e){var d='<p /><span class="areaheader">'+this.areaHeader+"</span>";if(e.status=="OK"){this.coins=e.msg.coins;this.notes=e.msg.notes;var g=e.msg.coinvalname;var f=e.msg.notevalname;d+="<p />"+this._createGuiCore(this.coins,this.coinsHeader,g,"c");d+=this._createGuiCore(this.notes,this.notesHeader,f,"n")}d+='<p /><span class="coinsnotesheader">'+MAN_COUNTING_SUM[lang]+"</span><br>";d+='<input id="countingsum" value="" type="text" readonly /> '+f;d+='<p /><div class="hint">'+this.hint+"</div>";$("#countingprotocol").html(d);this._bindCountingChange()};this._bindCountingChange=function(){var d=this;$(".countingfield").off("keyup").on("keyup",function(f){d._calcSum()})};this._calcSum=function(){var d=0;this.coins.forEach(function(i,g){var f="#coinnote_c_"+i;var h=$(f).val().trim();if(h!=""){h=parseInt(h);if(isInt(h)){d+=h*i}else{$("#countingsum").val("?")}}});this.notes.forEach(function(i,g){var f="#coinnote_n_"+i;var h=$(f).val().trim();if(h!=""){h=parseInt(h);if(isInt(h)){d+=h*100*i}else{$("#countingsum").val("?")}}});var e=(d/100).toFixed(2).replace(".",this.decpoint);$("#countingsum").val(e)};this._createGuiCore=function(g,f,h,e){var d='<p /><span class="coinsnotesheader">'+f+"</span><br>";g.forEach(function(j,i){d+='<input id="coinnote_'+e+"_"+j+'" type="number" min="0" class="countingfield" />';d+=" * "+j+" "+h+"<br>"});return d};this.checkCoinsNotesValues=function(){var d=this._checkCoinNoteFieldsAreFilled("c",this.coins);var g=this._checkCoinNoteFieldsAreFilled("n",this.notes);var f=d.filled+g.filled;var h=d.unfilled+g.unfilled;var e=this._getCounted();if((f>0)&&(h>0)){return{status:false,msg:MAN_CLS_COINS_NOTES_FIELDS_NOT_CORRECTLY_FILLED[this.l]}}else{if(f>0){coinscount=this._getCountOfCoinNoteFields("c",this.coins);notescount=this._getCountOfCoinNoteFields("n",this.notes);return{status:true,msg:"OK",counting:1,coinscount:coinscount,notescount:notescount,counted:e}}else{return{status:true,msg:"OK",counting:0}}}};this._checkCoinNoteFieldsAreFilled=function(d,e){var f=0;var g=0;e.forEach(function(j,i){var h="#coinnote_"+d+"_"+j;var k=$(h).val().trim();if(k==""){g++}else{f++}});return{filled:f,unfilled:g}};this._getCountOfCoinNoteFields=function(d,e){var f=[];e.forEach(function(j,h){var g="#coinnote_"+d+"_"+j;var i=$(g).val().trim();f[f.length]={value:j,count:i}});return f};this.clearCountingFields=function(){this.coins.forEach(function(f,e){var d="#coinnote_c_"+f;$(d).val("")});this.notes.forEach(function(f,e){var d="#coinnote_n_"+f;$(d).val("")});$("#countingsum").val("")};this._getCounted=function(){this._calcSum();var d=$("#countingsum").val();if(d==""){return 0}else{return d.replace(",",".")}};this._createSubPartCa