ordersprinter/webapp/elements/reservation.js

1 line
3.1 KiB
JavaScript
Raw Permalink Normal View History

2020-11-19 23:13:57 +01:00
function ReservationsTable(){this.dayStartHour=5;this.dayEndHour=20;this.compare=function(d,c){var a=d.starthour*4+d.startmin/15;var e=c.starthour*4+c.startmin/15;var b=a-e;if(b<0){return -1}else{if(b>0){return 1}else{return 0}}};this.generateTableHeader=function(){var a="<tr><td>&nbsp;";for(var b=this.dayStartHour;b<this.dayEndHour;b++){a+="<th style='text-align:left;' class='hour'>"+b+"<th class='minute'>15<th class='minute'>30<th class='minute'>45"}a+="</tr>";return a};this.getSlotsCount=function(a){return this.getSlotsInPeriodByHour(a.starthour,a.startmin,a.endhour,a.endmin)};this.getSlotsInPeriod=function(a,c,b){return this.getSlotsInPeriodByHour(a,c,b.starthour,b.startmin)};this.getSlotsInPeriodByHour=function(c,d,b,a){if(c<this.dayStartHour){c=this.dayStartHour;d=0}if(b>this.dayEndHour){b=this.dayEndHour;a=0}var e=(b*4+a/15)-(c*4+d/15);return e};this.getRealEndHour=function(a){var b=this.getSlotsInPeriodByHour(a.starthour,a.startmin,a.endhour,a.endmin);if(b>=0){return a.endhour}else{return 24+a.endhour}};this.genCell=function(d,c,f,e){var a="";var b="";if(e!=null){a=" id='resitem_"+e+"' ";b=" resitem "}if(c>0){return"<td colspan='"+c+"' class='"+f+b+"' "+a+">"+d+"</td>"}else{return""}};this.cellContent=function(e){var d=this.reservationitem.split("\n");var a=[];for(var c=0;c<d.length;c++){var b=d[c];b=b.replace(/\{Name\}/g,toHtml(e.guest));b=b.replace(/\{Start-Stunde\}/g,e.starthour);b=b.replace(/\{Start-Minute\}/g,pad(parseInt(e.startmin),2));b=b.replace(/\{Ende-Stunde\}/g,parseInt(e.endhour)%24);b=b.replace(/\{Ende-Minute\}/g,pad(parseInt(e.endmin),2));b=b.replace(/\{Dauer-Stunden\}/g,parseInt(e.durationhours));b=b.replace(/\{Dauer-Minuten\}/g,pad(parseInt(e.durationmins),2));b=b.replace(/\{Personen\}/g,parseInt(e.persons));b=b.replace(/\{Bemerkung\}/g,toHtml(e.remark));a[a.length]=b}return a.join("<br>")};this.distributeTable=function(e){var n=e.sort(this.compare);var o=[];var k=[];var a=true;while(a){a=false;var p=0;var c=0;var f=0;var h="";for(var g=0;g<n.length;g++){var j=n[g];if(k.indexOf(j.id)<0){var m=j.starthour*4+j.startmin/15;var q=c*4+f/15;if(m>=q){var d=this.getSlotsInPeriod(c,f,j);if(this.dayStartHour>j.starthour){d=0}var l=this.getSlotsCount(j);var b=this.genCell("",d,"fillcell",null);if(j.starthour<this.dayEndHour){b+=this.genCell(this.cellContent(j),l,"rescell",j.id)}h+=b;c=j.endhour;f=j.endmin;p+=d+l;k[k.length]=j.id;a=true}}}if(a){var d=this.getSlotsInPeriodByHour(c,f,this.dayEndHour,0);if(c<this.dayEndHour){h+=this.genCell("",d,"fillcell",null)}o[o.length]=h}}return o};this.distribute=function(f){var c=f.tablename;var g=f.reservations;var b=this.distributeTable(g);var e=b.length;if(e>0){var a="<tr><td rowspan='"+e+"' class='rowitem'>"+c;var d=true;b.forEach(function(h){if(!d){a+="<tr>"}else{d=false}a+=h+"</tr>"});return a}else{return""}};this.layoutTable=function(d,c,b,f){this.dayStartHour=parseInt(d);this.dayEndHour=parseInt(c);this.reservationitem=f;var a="<table class='timeschedule'>";a+=this.generateTableHeader();for(var e=0;e<b.length;e++){var h=b[e];a+=this.distribute(h);var g=1+(c-d)*4;a+="<tr><td colspan='"+g+"' class='divider'></td></tr>"}a+="</table>";return a}};