class _workscheduleTime{constructor(workscheduletimeid="Novo*",workscheduleid=0,weekday=0,starttime="2022-01-15 08:00",endtime="2022-01-15 17:00",duration=520,description="",userId=0,status=1){this.workscheduletimeid=workscheduletimeid;this.workscheduleid=workscheduleid;this.weekday=weekday;this.starttime=starttime;this.endtime=endtime;this.duration=duration;this.description=description;this.userId=userId;this.status=status}}
var WORKSCHEDULE_TIME_LIST=[];function workscheduleListOnLoad(){showNotification();setPageTitleWhoCall("4110-4111-4112","WORSCHLIST","Lista de turnos");function cdoLoad(){if(!checkPermission("4111")){removeElement("btWorSchListWorkscheduleNew");removeElement("divWorkscheduleRegister")}
if(!checkPermission("4112")){removeElement("btWorSchRegDelete")}
workscheduleSearchOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function workscheduleRegisterNew(){workscheduleRegisterDetail()}
function workscheduleRegisterDetail(workscheduleId=-1){showParts("divWorkscheduleRegister");const lbHeader=document.getElementById("h2WorSchRegHeader");const txtWorksheduleId=document.getElementById("txtWorSchRegWorkscheduleId");const txtWorkschedule=document.getElementById("txtWorSchRegWorkschedule");const txtStartTolerance=document.getElementById("txtWorSchRegStartTolerance");const txtEndTolerance=document.getElementById("txtWorSchRegEndTolerance");const txtExtraTime=document.getElementById("txtWorSchRegExtraTime");const txtWorkOnHoliday=document.getElementById("txtWorSchRegWorkOnHoliday");const tdSchedule1=document.getElementById("tdWorSchRegSchedule1");const tdSchedule2=document.getElementById("tdWorSchRegSchedule2");const tdSchedule3=document.getElementById("tdWorSchRegSchedule3");const tdSchedule4=document.getElementById("tdWorSchRegSchedule4");const tdSchedule5=document.getElementById("tdWorSchRegSchedule5");const tdSchedule6=document.getElementById("tdWorSchRegSchedule6");const tdSchedule7=document.getElementById("tdWorSchRegSchedule7");const lbUpdate=document.getElementById("lbWorSchRegUpdate");WORKSCHEDULE_TIME_LIST=[];for(var i=1;i<=7;i++){setElementInnerHtml("tdWorSchRegSchedule"+i)}
if(workscheduleId==-1){lbHeader.innerHTML="Novo turno";txtWorksheduleId.value="Novo turno *";txtWorkschedule.value="";txtStartTolerance.value=10;txtEndTolerance.value=5;txtExtraTime.value=0;txtWorkOnHoliday.value=0;lbUpdate.innerHTML="Actualizado em "+setLocalDate(new Date(),16)}else{lbHeader.innerHTML="Dados do turno";if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.workscheduleId=workscheduleId;FILTER.startIdx=0;var http=new XMLHttpRequest();var params="action=getWorkscheduleList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){var workschedules=validateSession(http);let workschedule=JSON.parse(workschedules[0]);txtWorksheduleId.value=workschedule.workscheduleid;txtWorkschedule.value=workschedule.workschedule;txtStartTolerance.value=workschedule.starttolerance;txtEndTolerance.value=workschedule.endtolerance;txtExtraTime.value=workschedule.extratime;txtWorkOnHoliday.value=workschedule.workonholiday;lbUpdate.innerHTML="Cadastrado por "+getOperatorName(workschedule.operatorEntry,workschedule.entryuser)+" em "+setLocalDate(workschedule.entrydate,16)+". <br>"+"Actualizado por "+getOperatorName(workschedule.operatorName,workschedule.statususer)+" em "+setLocalDate(workschedule.statusdate,16);workscheduleRegisterTimeList(workscheduleId)}};http.send(params)}
setAutoCompleteToFiel(txtWorkschedule.id,49,1);txtWorkschedule.focus()}
function workscheduleRegisterTimeNew(weekDay){var workTime=new _workscheduleTime();workTime.weekday=weekDay;workscheduleRegisterTimeAddSingleLine(workTime)}
function workscheduleRegisterTimeAddSingleLine(workTime){let workLine=(_workscheduleTime);workLine=workTime;var tblTime=document.getElementById("tdWorSchRegSchedule"+workLine.weekday);let nRows=WORKSCHEDULE_TIME_LIST.length;WORKSCHEDULE_TIME_LIST[nRows]=workLine;var weekEnd="";if((workLine.weekday==1)||(workLine.weekday==7)){weekEnd=" border-color-maroon"}
let divTime=createElement("div","","borderGray div-schedule-time"+weekEnd);divTime.id="divWorSchRegDivTime"+nRows;tblTime.appendChild(divTime);let legStart=createElement("legend","","colLabel font-size-small");legStart.innerHTML="Entrada:";divTime.appendChild(legStart);let txtStart=createElement("input","time");txtStart.onchange=function(){workscheduleRegisterTimeOnChange(nRows,"2022-01-15 "+this.value,"starttime",divTime)};txtStart.value=setLocalDate(workLine.starttime,16).slice(11);txtStart.dispatchEvent(new Event('change'));divTime.appendChild(txtStart);let legEnd=createElement("legend","","colLabel font-size-small");legEnd.innerHTML="Saída:";divTime.appendChild(legEnd);let txtEnd=createElement("input","time");txtEnd.onchange=function(){workscheduleRegisterTimeOnChange(nRows,"2022-01-15 "+this.value,"endtime",divTime)};txtEnd.value=setLocalDate(workLine.endtime,16).slice(11);txtEnd.dispatchEvent(new Event('change'));divTime.appendChild(txtEnd);let legDescr=createElement("legend","","colLabel font-size-small");legDescr.innerHTML="Descrição:";divTime.appendChild(legDescr);let txtDescr=createElement("input","text");txtDescr.onchange=function(){workscheduleRegisterTimeOnChange(nRows,reviewString(this),"description",divTime)};txtDescr.value=workLine.description;divTime.appendChild(txtDescr);let btRemove=createElement("button","button","labelDelete");btRemove.onclick=function(){workscheduleRegisterTimeRemove(nRows,divTime)};divTime.appendChild(btRemove)}
function workscheduleRegisterTimeOnChange(nLine,strValue,field,divTime){WORKSCHEDULE_TIME_LIST[Number(nLine)][field]=strValue;var duration=dateDiffMinutes(WORKSCHEDULE_TIME_LIST[Number(nLine)].endtime,WORKSCHEDULE_TIME_LIST[Number(nLine)].starttime);WORKSCHEDULE_TIME_LIST[Number(nLine)].duration=duration;divTime.setAttribute("title","Duração "+duration+" minutos");workscheduleRegisterTimeValidade()}
function workscheduleRegisterTimeRemove(nLine,row){WORKSCHEDULE_TIME_LIST[Number(nLine)].status=0;row.innerHTML="";row.style.display="none";workscheduleRegisterTimeValidade()}
function workscheduleRegisterTimeValidade(){for(var x=0;x<WORKSCHEDULE_TIME_LIST.length;x++){var xStart=new Date(WORKSCHEDULE_TIME_LIST[x].starttime).getTime();var xEnd=new Date(WORKSCHEDULE_TIME_LIST[x].endtime).getTime();var xStatus=WORKSCHEDULE_TIME_LIST[x].status;let divTime=document.getElementById("divWorSchRegDivTime"+x);var found=!1;if(xStatus==1){if(xStart>=xEnd){divTime.classList.add('border-color-red');found=!0}
for(var i=0;i<WORKSCHEDULE_TIME_LIST.length;i++){var iStatus=WORKSCHEDULE_TIME_LIST[i].status;if(iStatus==1){if(i!=x){if(WORKSCHEDULE_TIME_LIST[i].weekday==WORKSCHEDULE_TIME_LIST[x].weekday){var iStart=new Date(WORKSCHEDULE_TIME_LIST[i].starttime).getTime();var iEnd=new Date(WORKSCHEDULE_TIME_LIST[i].endtime).getTime();let iDiv=document.getElementById("divWorSchRegDivTime"+i);if(iStart<=xStart){if(iEnd>=xStart){divTime.classList.add('border-color-red');iDiv.classList.add('border-color-red');found=!0}}else{if(iStart<=xEnd){divTime.classList.add('border-color-red');iDiv.classList.add('border-color-red');found=!0}}}}}}
if(!found){divTime.classList.remove('border-color-red')}}}}
function workscheduleRegisterSave(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();var WORKSCHEDULE_NEW={};WORKSCHEDULE_NEW.workscheduleid=getElementValue("txtWorSchRegWorkscheduleId");WORKSCHEDULE_NEW.workschedule=reviewString(document.getElementById("txtWorSchRegWorkschedule")).toUpperCase();WORKSCHEDULE_NEW.starttolerance=getElementValue("txtWorSchRegStartTolerance");WORKSCHEDULE_NEW.endtolerance=getElementValue("txtWorSchRegEndTolerance");WORKSCHEDULE_NEW.extratime=getElementValue("txtWorSchRegExtraTime");WORKSCHEDULE_NEW.workonholiday=getElementValue("txtWorSchRegWorkOnHoliday");WORKSCHEDULE_NEW.userId=SYSTEM_USER_STATUS.userId;FILTER.workscheduleInfo=WORKSCHEDULE_NEW;FILTER.workschesuleTimeList=WORKSCHEDULE_TIME_LIST;var mandatoryField=!1;var msg="";if(WORKSCHEDULE_NEW.workschedule==""){mandatoryField=!0;msg+="Deve indicar a designação do turno. <br>"}
if(WORKSCHEDULE_TIME_LIST.length<=0){mandatoryField=!0;msg+="Deve indicar pelo menos um horário. <br>"}
if(ST_SRH_WAITING_SERVER==1){mandatoryField=!0;msg+="Aguardando resposta do servidor. <br>"}
if(mandatoryField){alert(msg);return!1}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=saveWorkscheduleSaveInformation"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){ST_SRH_WAITING_SERVER=0;var result=validateSession(http);if(result.status==!0){showNotification("Turno guardado com sucesso.",1);hideParts("divWorkscheduleRegister");if(ST_SRH_MAIN_WHO_CALL=="WORSCHLIST"){workscheduleList()}else if((ST_SRH_MAIN_WHO_CALL=="EMPWORSCHLIS")||(ST_SRH_MAIN_WHO_CALL=="WORSCHWORSCH")){fillSelectWorkschedule("selEmpWorSchRegWorkschedule",-1,getElementValue("selEmpWorSchRegWorkschedule"))}}else{showNotification(result.msg,0)}}};http.send(params)}
function workscheduleList(workscheduleId=-1,startIdx=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.workscheduleId=workscheduleId;FILTER.startIdx=startIdx;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
let tableRef=document.getElementById("tblWorSchListMainTable");if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowWorkSchListAddMore")}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getWorkscheduleList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){ST_SRH_WAITING_SERVER=0;var workschedules=validateSession(http);setElementInnerHtml("lbResultOnList",workschedules.length);var nRows=startIdx;for(var i=0;i<workschedules.length;i++){let workschedule=JSON.parse(workschedules[i]);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowWorSchList"+workschedule.workscheduleid);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_WORKSCHEDULE_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,workschedule.workscheduleid,"colProductId","Código");let cellWork=createTableCell(newRow,workschedule.workschedule,"col-width-110","Turno");let cellStart=createTableCell(newRow,workschedule.starttolerance,"text-align-center","Tolerância a entrada (min)");let cellEnd=createTableCell(newRow,workschedule.endtolerance,"text-align-center","Tolerância a saída (min)");let cellExtra=createTableCell(newRow,workschedule.extratime,"text-align-center","Máx. horas extras (min)");var workHoli=(workschedule.workonholiday==1)?"Sim":"";let cellHoli=createTableCell(newRow,workHoli,"text-align-center","Trabalhar aos feriados");let cellUpdate=createTableCell(newRow,setLocalDate(workschedule.statusdate,16),"colProductId","Última actualização");let cellOper=createTableCell(newRow,getFirtLastName(workschedule.operatorName)+" ("+workschedule.statususer+")","colProductId","Operador");let cellEdit=createTableCell(newRow,"","noPrint text-align-center","...");if(workschedule.classschedule==0){if(checkPermission("4111")){let btEdit=document.createElement("button");btEdit.setAttribute("class","labelEdit");btEdit.type="button";btEdit.name=workschedule.workscheduleid;btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_WORKSCHEDULE_LIST");workscheduleRegisterDetail(btEdit.name)};cellEdit.appendChild(btEdit)}}}
if(workschedules.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowWorkSchListAddMore";newRowC.setAttribute("class","noPrint borderGray font-size-x-large text-align-center");newRowC.style.cursor="pointer";let cellDescription=newRowC.insertCell(-1);cellDescription.innerHTML="<b>VER MAIS...</b>";cellDescription.setAttribute("colspan","7");newRowC.onclick=function(){workscheduleList(workscheduleId,FILTER.startIdx+FILTER.pageItems)}}
hideNotification()}};http.send(params)}
function workscheduleRegisterTimeList(workscheduleId){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.workscheduleId=workscheduleId;var http=new XMLHttpRequest();var params="action=getWorkscheduleTimeList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){var workschedules=validateSession(http);for(var i=0;i<workschedules.length;i++){workscheduleRegisterTimeAddSingleLine(JSON.parse(workschedules[i]))}}};http.send(params)}
function workscheduleRegisterDelete(){function realDelete(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.workscheduleId=getElementValue("txtWorSchRegWorkscheduleId");if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor.",0);return!1}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=deleteWorkscheduleInformation"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){ST_SRH_WAITING_SERVER=0;var result=validateSession(http);if(result.status==!0){showNotification(result.msg,1);hideParts("divWorkscheduleRegister");workscheduleList()}else{showNotification(result.msg,0)}}};http.send(params)}
showConfirm("Tem a certeza que deseja apagar este turno?",realDelete)}
function workscheduleHolidayListOnLoad(){showNotification();setPageTitleWhoCall("4114","WORSCHHOL","Lista de feriados");function cdoLoad(){var txtYear=document.getElementById("txtWorSchHolListYear");txtYear.onchange=function(){workscheduleHolidayList(this.value)};txtYear.value=new Date().getFullYear();txtYear.onchange();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function workscheduleHolidayList(year=-1){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.year=year;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getWorkscheduleHolidayList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){ST_SRH_WAITING_SERVER=0;var response=validateSession(http);setElementInnerHtml("lbResultOnList",response.length);let tableRef=document.getElementById("tblWorSchHolListMainTable");tableRef.innerHTML="";var nRows=0;for(var i=0;i<response.length;i++){let holiday=JSON.parse(response[i]);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowWorSchHolList"+holiday.holiday);var fontBold=(holiday.companyid==FILTER.companyId)?" font-weight-bold":"";newRow.setAttribute("class","borderGray"+fontBold+setSelectedRowBackground("SELECTED_ROW_WORKSCHEDULE_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellHoli=createTableCell(newRow,dateExtension(holiday.holiday),"col-width-110","Dia");let cellType=createTableCell(newRow,holiday.holidaytype,"col-width-80 text-align-center","Tipo");let cellReason=createTableCell(newRow,holiday.holidayreason,"","Motivo");let cellDelete=createTableCell(newRow,"","noPrint text-align-center","...");if(holiday.companyid==FILTER.companyId){let btDelete=document.createElement("button");btDelete.setAttribute("class","labelDelete");btDelete.type="button";btDelete.onclick=function(){workscheduleHollidayRegisterDelete(holiday)};cellDelete.appendChild(btDelete)}}
hideNotification()}};http.send(params)}
function workscheduleWorkscheduleOnLoad(){showNotification();setPageTitleWhoCall("4110-4111-4112","WORSCHWORSCH","Escala de trabalho");function cdoLoad(){fillSelectMonth("selWorSchWorSchMonth",1,new Date().getMonth()+1);fillSelectDependencyFull("selWorSchWorSchDependency",-1,1);fillSelectSex("selWorSchWorSchSex",-1);fillSelectEmployeeCategory("selWorSchWorSchEmployeeCategory",-1);fillSelectDepartment("selWorSchWorSchDepartment",-1);fillSelectWorkscheduleAplicationType("selEmpWorSchRegAplicationType",1,0);if(!checkPermission("4113")){removeElement("btWorSchWorSchEmployeeWorkschedule");removeElement("divEmployeeWorkscheduleRegister")}
if(!checkPermission("4002")){removeElement("btWorSchWorSchNewEmployee");removeElement("divEmployeeRegister")}
if(!checkPermission("4111")){removeElement("btEmpWorSchRegWorkscheduleNew");removeElement("divWorkscheduleRegister")}
employeeSearchOnLoad();employeeRegisterOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function workscheduleWorkscheduleList(employeeId=-1){var year=getElementValue("numWorSchWorSchYear");var month=Number(getElementValue("selWorSchWorSchMonth"))-1;var days=daysInMonth(month+1,year);var rowHeader=document.getElementById("rowWorSchWorSchTableHeader");var rowLine1=document.getElementById("rowWorSchWorSchTableLine1");var rowLine2=document.getElementById("rowWorSchWorSchTableLine2");var rowLine3=document.getElementById("rowWorSchWorSchTableLine3");var rowLine4=document.getElementById("rowWorSchWorSchTableLine4");rowHeader.innerHTML="<th>Período</th>";rowLine1.innerHTML="";let c1=createTableCell(rowLine1,"00-06".bold(),"text-align-center");c1.style.backgroundColor=lightColorByIndex(1);rowLine2.innerHTML="";let c2=createTableCell(rowLine2,"06-12 Manhã".bold(),"text-align-center");c2.style.backgroundColor=lightColorByIndex(2);rowLine3.innerHTML="";let c3=createTableCell(rowLine3,"12-18 Tarde".bold(),"text-align-center");c3.style.backgroundColor=lightColorByIndex(3);rowLine4.innerHTML="";let c4=createTableCell(rowLine4,"18-24 Noite".bold(),"text-align-center");c4.style.backgroundColor=lightColorByIndex(4);for(var d=1;d<=days;d++){let cellDay1=createTableCell(rowLine1);cellDay1.setAttribute("id","tdWorSchRegSchedule1_"+d);let cellDay2=createTableCell(rowLine2);cellDay2.setAttribute("id","tdWorSchRegSchedule2_"+d);let cellDay3=createTableCell(rowLine3);cellDay3.setAttribute("id","tdWorSchRegSchedule3_"+d);let cellDay4=createTableCell(rowLine4);cellDay4.setAttribute("id","tdWorSchRegSchedule4_"+d)}
if(!desktopSecurityCheck()){return!1}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=getElementValue("selWorSchWorSchDependency");FILTER.year=year;FILTER.userId=SYSTEM_USER_STATUS.userId;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getWorkscheduleHolidayList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){var response=validateSession(http);for(var h=1;h<=days;h++){var headerDay=new Date(year,month,h);let cellHeader=createElement("th","","text-no-wrap");cellHeader.innerHTML=weekDay(headerDay.getDay(),1)+", "+h;rowHeader.appendChild(cellHeader);if((headerDay.getDay()==0)||(headerDay.getDay()==6)){cellHeader.setAttribute("class","background-color-maroon")}else{for(var i=0;i<response.length;i++){let holiday=JSON.parse(response[i])['holiday'];if(setLocalDate(headerDay,10)==setLocalDate(holiday,10)){cellHeader.setAttribute("class","background-color-brown")}}}}
rowHeader.setAttribute("option-print",0);setPrintTableOption()}};http.send(params);FILTER.employeeId=employeeId;FILTER.initialDate=setLocalDate(new Date(year,month,1),10);FILTER.endDate=setLocalDate(new Date(year,month,days),10);FILTER.sex=getElementValue("selWorSchWorSchSex");FILTER.categoryId=getElementValue("selWorSchWorSchEmployeeCategory");FILTER.departmentId=getElementValue("selWorSchWorSchDepartment");FILTER.viewMode=1;FILTER.startIdx=0;FILTER.pageItems=2000;var pHttp=new XMLHttpRequest();var params="action=getWorkschedulePointList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;pHttp.open('POST',url,!0);pHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');pHttp.onreadystatechange=function(){if(pHttp.readyState==4&&pHttp.status==200){ST_SRH_WAITING_SERVER=0;var response=validateSession(pHttp);var listOfEmployee=[];for(var i=0;i<response.length;i++){let workLine=JSON.parse(response[i]);var day=new Date(workLine.workday).getDate();var weekEnd="";if((workLine.weekday==1)||(workLine.weekday==7)){weekEnd=" border-color-maroon"}else if(workLine.holiday==1){weekEnd=" border-color-brown"}
var startTime=Number(setLocalDate(workLine.starttimeplanned,16).toString().substring(11,13));var line=(startTime<6)?1:(startTime<12)?2:(startTime<18)?3:4;var tblTime=document.getElementById("tdWorSchRegSchedule"+line+"_"+day);let divTime=createElement("div","","borderGray div-schedule-time"+weekEnd);divTime.title=additionalInfo(workLine);tblTime.appendChild(divTime);let legEmp=createElement("legend","","font-size-small");legEmp.innerHTML=getFirtLastName(workLine.employeename);legEmp.style.backgroundColor=lightColorByIndex(getEmployeeIdx(workLine.employeename));divTime.appendChild(legEmp);let legStart=createElement("legend","","colLabel font-size-small");legStart.innerHTML=getPeriodo(workLine.starttimeplanned)+" "+setLocalDate(workLine.starttimeplanned,16).slice(11).bold()+" / "+getPeriodo(workLine.endtimeplanned)+" "+setLocalDate(workLine.endtimeplanned,16).slice(11).bold();divTime.appendChild(legStart)}
hideNotification();function getEmployeeIdx(employeeName){if(!(listOfEmployee.includes(employeeName))){listOfEmployee.push(employeeName)}
return listOfEmployee.indexOf(employeeName)+1}
function getPeriodo(seTime){var startTime=Number(setLocalDate(seTime,16).toString().substring(11,13));var line=(startTime<6)?"":(startTime<12)?"M:":(startTime<18)?"T:":"N:";return line}
function additionalInfo(workpoint){var info=workpoint['employeename']+" ("+workpoint['employeeid']+")"+"\n";info+="Turno: "+workpoint['workschedule']+"\n";info+="Falta: "+workpoint['fault']+"\n";info+="Atraso: "+sec2time(Number(workpoint['delaytime'])*60,!0)+"\n";return info}}};pHttp.send(params)}
function workscheduleHollidayRegisterNew(){showParts("divWorkscheduleHolidayRegister");setElementValue("txtWorSchHolRegHolidayId","Nova tolerância *");setElementValue("txtWorSchHolRegHoliday",setLocalDate(new Date(),10));setElementValue("txtWorSchHolRegHolidayType");setElementValue("txtWorSchHolRegReason")}
function workscheduleHollidayRegisterSave(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.holidayId=getElementValue("txtWorSchHolRegHolidayId");FILTER.holiday=getElementValue("txtWorSchHolRegHoliday");FILTER.holidaytype=reviewString(document.getElementById("txtWorSchHolRegHolidayType")).toUpperCase();FILTER.holidayreason=reviewString(document.getElementById("txtWorSchHolRegReason")).toUpperCase();showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=saveWorkscheduleHolliday"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){ST_SRH_WAITING_SERVER=0;var result=validateSession(http);if(result.status==1){showNotification(result.msg,1);hideParts("divWorkscheduleHolidayRegister");workscheduleHolidayList(new Date(FILTER.holiday).getFullYear())}else{showNotification(result.msg,0)}}};http.send(params)}
function workscheduleHollidayRegisterDelete(holliday){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.holidayId=holliday.id;FILTER.holiday=holliday.holiday;showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=deleteWorkscheduleHolliday"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){ST_SRH_WAITING_SERVER=0;var result=validateSession(http);if(result.status==1){showNotification(result.msg,1);workscheduleHolidayList(new Date(FILTER.holiday).getFullYear())}else{showNotification(result.msg,0)}}};http.send(params)}
function myWorkscheduleWorkscheduleOnLoad(){showNotification();setPageTitleWhoCall("0000","WORSCHWORSCH","Minha escala de trabalho");function cdoLoad(){fillSelectMonth("selWorSchWorSchMonth",1,new Date().getMonth()+1);myWorkscheduleWorkscheduleList();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function myWorkscheduleWorkscheduleList(){var year=getElementValue("numWorSchWorSchYear");var month=Number(getElementValue("selWorSchWorSchMonth"))-1;var days=daysInMonth(month+1,year);var rowHeader=document.getElementById("rowWorSchWorSchTableHeader");var rowLine1=document.getElementById("rowWorSchWorSchTableLine1");var rowLine2=document.getElementById("rowWorSchWorSchTableLine2");var rowLine3=document.getElementById("rowWorSchWorSchTableLine3");var rowLine4=document.getElementById("rowWorSchWorSchTableLine4");rowHeader.innerHTML="<th>Período</th>";rowLine1.innerHTML="";let c1=createTableCell(rowLine1,"00-06".bold(),"text-align-center");c1.style.backgroundColor=lightColorByIndex(1);rowLine2.innerHTML="";let c2=createTableCell(rowLine2,"06-12 Manhã".bold(),"text-align-center");c2.style.backgroundColor=lightColorByIndex(2);rowLine3.innerHTML="";let c3=createTableCell(rowLine3,"12-18 Tarde".bold(),"text-align-center");c3.style.backgroundColor=lightColorByIndex(3);rowLine4.innerHTML="";let c4=createTableCell(rowLine4,"18-24 Noite".bold(),"text-align-center");c4.style.backgroundColor=lightColorByIndex(4);for(var d=1;d<=days;d++){let cellDay1=createTableCell(rowLine1);cellDay1.setAttribute("id","tdWorSchRegSchedule1_"+d);let cellDay2=createTableCell(rowLine2);cellDay2.setAttribute("id","tdWorSchRegSchedule2_"+d);let cellDay3=createTableCell(rowLine3);cellDay3.setAttribute("id","tdWorSchRegSchedule3_"+d);let cellDay4=createTableCell(rowLine4);cellDay4.setAttribute("id","tdWorSchRegSchedule4_"+d)}
if(!desktopSecurityCheck()){return!1}
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=-1;FILTER.year=year;FILTER.userId=SYSTEM_USER_STATUS.userId;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getWorkscheduleHolidayList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){var response=validateSession(http);for(var h=1;h<=days;h++){var headerDay=new Date(year,month,h);let cellHeader=createElement("th","","text-no-wrap");cellHeader.innerHTML=weekDay(headerDay.getDay(),1)+", "+h;rowHeader.appendChild(cellHeader);if((headerDay.getDay()==0)||(headerDay.getDay()==6)){cellHeader.setAttribute("class","background-color-maroon")}else{for(var i=0;i<response.length;i++){let holiday=JSON.parse(response[i])['holiday'];if(setLocalDate(headerDay,10)==setLocalDate(holiday,10)){cellHeader.setAttribute("class","background-color-brown")}}}}
rowHeader.setAttribute("option-print",0);setPrintTableOption()}};http.send(params);FILTER.employeeId=SYSTEM_USER_STATUS.employeeId;FILTER.initialDate=setLocalDate(new Date(year,month,1),10);FILTER.endDate=setLocalDate(new Date(year,month,days),10);FILTER.sex="";FILTER.categoryId=-1;FILTER.departmentId=-1;FILTER.viewMode=1;FILTER.startIdx=0;FILTER.pageItems=2000;var pHttp=new XMLHttpRequest();var params="action=getWorkschedulePointList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_WORKSCHEDULE_X;pHttp.open('POST',url,!0);pHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');pHttp.onreadystatechange=function(){if(pHttp.readyState==4&&pHttp.status==200){ST_SRH_WAITING_SERVER=0;var response=validateSession(pHttp);var listOfEmployee=[];for(var i=0;i<response.length;i++){let workLine=JSON.parse(response[i]);var day=new Date(workLine.workday).getDate();var weekEnd="";if((workLine.weekday==1)||(workLine.weekday==7)){weekEnd=" border-color-maroon"}else if(workLine.holiday==1){weekEnd=" border-color-brown"}
var startTime=Number(setLocalDate(workLine.starttimeplanned,16).toString().substring(11,13));var line=(startTime<6)?1:(startTime<12)?2:(startTime<18)?3:4;var tblTime=document.getElementById("tdWorSchRegSchedule"+line+"_"+day);let divTime=createElement("div","","borderGray div-schedule-time"+weekEnd);divTime.title=additionalInfo(workLine);tblTime.appendChild(divTime);let legEmp=createElement("legend","","font-size-small");legEmp.innerHTML=getFirtLastName(workLine.employeename);legEmp.style.backgroundColor=lightColorByIndex(getEmployeeIdx(workLine.employeename));divTime.appendChild(legEmp);let legStart=createElement("legend","","colLabel font-size-small");legStart.innerHTML=getPeriodo(workLine.starttimeplanned)+" "+setLocalDate(workLine.starttimeplanned,16).slice(11).bold()+" / "+getPeriodo(workLine.endtimeplanned)+" "+setLocalDate(workLine.endtimeplanned,16).slice(11).bold();divTime.appendChild(legStart)}
hideNotification();function getEmployeeIdx(employeeName){if(!(listOfEmployee.includes(employeeName))){listOfEmployee.push(employeeName)}
return listOfEmployee.indexOf(employeeName)+1}
function getPeriodo(seTime){var startTime=Number(setLocalDate(seTime,16).toString().substring(11,13));var line=(startTime<6)?"":(startTime<12)?"M:":(startTime<18)?"T:":"N:";return line}
function additionalInfo(workpoint){var info=workpoint['employeename']+" ("+workpoint['employeeid']+")"+"\n";info+="Turno: "+workpoint['workschedule']+"\n";info+="Falta: "+workpoint['fault']+"\n";info+="Atraso: "+sec2time(Number(workpoint['delaytime'])*60,!0)+"\n";return info}}};pHttp.send(params)}