var EXTRA_ACTIVITY_NEW_ASSIGN=0;function extraActivityListOnLoad(){showNotification();setPageTitleWhoCall("4501-4502-4503","EXTACTLIST","Lista de actividades extraordinárias");function cdoLoad(){fillSelectDependencyFull("selExtActListDependency",-1,1);fillSelectAllowance("selExtActListActivity",-1);fillSelectCountry("selExtActListCountry",-1);fillSelectDepartment("selExtActListDepartment",-1);fillSelectEmployeeCategory("selExtActListEmployeeCategory",-1);var date=new Date();setElementValue("txtExtActListInitialDate",setLocalDate(new Date(date.getFullYear(),date.getMonth(),1),10));setElementValue("txtExtActListEndDate",setLocalDate(new Date(),10));setTriggerButtonByText('txtExtActListInitialDate','btExtActListViewAll');setTriggerButtonByText('txtExtActListEndDate','btExtActListViewAll');if(!checkPermission("4002")){removeElement("btEmpLisNewEmployee");removeElement("divEmployeeRegister")}
if(!checkPermission("4111")){removeElement("btEmpWorSchRegWorkscheduleNew");removeElement("divWorkscheduleRegister")}
if(!checkPermission("4502")){removeElement("btExtActListExtraActivityNew");removeElement("divExtraActivityRegister")}
if(!checkPermission("4503")){removeElement("btExtActRegActivityCancel")}
EXTRA_ACTIVITY_NEW_ASSIGN=0;employeeSearchOnLoad();employeeRegisterOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function extraActivityEdit(activity){if(!isNaN(Number(activity.activityextraid))){setElementInnerHtml("h2ExtActRegHeader","Dados da actividade")}else{setElementInnerHtml("h2ExtActRegHeader","Nova actividade")}
showParts("divExtraActivityRegister");setElementInnerHtml("lbExtActRegActivityExtraId",activity.activityextraid);setElementInnerHtml("lbExtActRegEmployeeId",activity.employeeid);setElementInnerHtml("txtExtActRegEmployeeName",activity.employeename);setElementValue("txtExtActRegActivityDate",setLocalDate(activity.activitydate,10));fillSelectAllowance("selExtActRegAllowanceId",-1,activity.allowanceid);setElementValue("txtExtActRegActivitys",activity.activitys);setElementInnerHtml("lbExtActRegUpdate","Cadastrado por "+getOperatorName(activity.operatorEntry,activity.entryuser)+" em "+setLocalDate(activity.entrydate,16)+". <br>"+"Actualizado por "+getOperatorName(activity.operatorName,activity.statususer)+" em "+setLocalDate(activity.statusdate,16))}
function extraActivitySave(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.activityextraid=getElementInnerHTML("lbExtActRegActivityExtraId");FILTER.employeeid=getElementInnerHTML("lbExtActRegEmployeeId");FILTER.activitydate=getElementValue("txtExtActRegActivityDate");FILTER.allowanceid=getElementValue("selExtActRegAllowanceId");FILTER.activitys=Number(getElementValue("txtExtActRegActivitys"));var mandatoryField=!1;var msg="";if(FILTER.employeeid==""){mandatoryField=!0;msg+="Deve indicar o trabalhador. <br>"}
if(FILTER.activitydate==""){mandatoryField=!0;msg+="Deve indicar a data da actividade. <br>"}
if(FILTER.allowanceid==-1){mandatoryField=!0;msg+="Deve indicar a actividade. <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=saveExtraActivity"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_ACTIVITY_EXTRA_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("divExtraActivityRegister");if(ST_SRH_MAIN_WHO_CALL=="EXTACTLIST"){extraActivityList(FILTER.employeeid)}
setElementInnerHtml("lbExtActRegActivityExtraId")}else{showNotification(result.msg,0)}}};http.send(params)}
function extraActivityList(employeeId=-1,startIdx=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=getElementValue("selExtActListDependency");FILTER.employeeId=employeeId;FILTER.filterByDate=getElementChecked("chbExtActListShowDate");FILTER.initialDate=getElementValue('txtExtActListInitialDate');FILTER.endDate=getElementValue('txtExtActListEndDate');FILTER.allowanceId=getElementValue("selExtActListActivity");FILTER.nationality=getElementValue("selExtActListCountry");FILTER.departmentId=getElementValue("selExtActListDepartment");FILTER.categoryId=getElementValue("selExtActListEmployeeCategory");FILTER.startIdx=startIdx;let tableRef=document.getElementById("tblExtActListMainTable");if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowExtActRowAddMore")}
var http=new XMLHttpRequest();var params="action=getExtraActivityList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_ACTIVITY_EXTRA_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);var totalItems=response.length;if(totalItems>0){hideDivFilter()}
function result(){tableRef.innerHTML+=strFilterResult(response);setElementInnerHtml('lbResultOnList',FILTER.startIdx+response.length);var nRows=startIdx;for(var i=0;i<response.length;i++){let activity=JSON.parse(response[i]);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowExtActRow"+activity.activityextraid);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_EXTRA_ACTIVITY_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,activity.employeeid,"colProductId","Código");let cellName=createTableCell(newRow,activity.employeename,"col-width-110 headcol","Nome completo");let cellCategory=createTableCell(newRow,activity.category,"colProductId","Categoria / função");let cellDepart=createTableCell(newRow,activity.department,"colProductId","Posto de trabalho");let cellDate=createTableCell(newRow,setLocalDate(activity.activitydate,10),"text-align-center text-no-wrap","Data da actividade");let cellAct=createTableCell(newRow,(activity.allowance),"text-align-center","Actividade");let cellQuant=createTableCell(newRow,activity.activitys,"text-align-center","Quantidade");let cellUpdate=createTableCell(newRow,setLocalDate(activity.statusdate,16),"colProductId","Última actualização");let cellOper=createTableCell(newRow,getFirtLastName(activity.operatorName)+" ("+activity.statususer+")","colProductId","Operador");let cellAction=createTableCell(newRow,"","noPrint text-align-center","...");if(checkPermission("4502")){let btEdit=document.createElement("button");btEdit.setAttribute("class","labelEdit");btEdit.type="button";btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_EXTRA_ACTIVITY_LIST");extraActivityEdit(activity)};cellAction.appendChild(btEdit)}
if(checkPermission("4002")){let btEdit=createElement("button","button","labelCustomer");btEdit.innerHTML="Trabalhador";btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_EXTRA_ACTIVITY_LIST");employeeRegisterDetail(activity.employeeid)};cellAction.appendChild(btEdit)}}
if(response.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowExtActRowAddMore";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(){extraActivityList(employeeId,FILTER.startIdx+FILTER.pageItems)}}
hideNotification()}
result()}};http.send(params)}
function extraActivityDelete(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.activityextraid=getElementInnerHTML("lbExtActRegActivityExtraId");var mandatoryField=!1;var msg="";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=deleteExtraActivity"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_ACTIVITY_EXTRA_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("divExtraActivityRegister");if(ST_SRH_MAIN_WHO_CALL=="EXTACTLIST"){extraActivityList()}
setElementInnerHtml("lbExtActRegActivityExtraId")}else{showNotification(result.msg,0)}}};http.send(params)}
function myExtraActivityListOnLoad(){showNotification();setPageTitleWhoCall("0000","EXTACTLIST","Minhas actividades extraordinárias");function cdoLoad(){var date=new Date();setElementValue("txtExtActListInitialDate",setLocalDate(new Date(date.getFullYear(),date.getMonth(),1),10));setElementValue("txtExtActListEndDate",setLocalDate(new Date(),10));setTriggerButtonByText('txtExtActListInitialDate','btExtActListViewAll');setTriggerButtonByText('txtExtActListEndDate','btExtActListViewAll');EXTRA_ACTIVITY_NEW_ASSIGN=0;myExtraActivityList();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function myExtraActivityList(startIdx=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=-1;FILTER.employeeId=SYSTEM_USER_STATUS.employeeId;FILTER.filterByDate=getElementChecked("chbExtActListShowDate");FILTER.initialDate=getElementValue('txtExtActListInitialDate');FILTER.endDate=getElementValue('txtExtActListEndDate');FILTER.allowanceId=-1;FILTER.nationality=-1;FILTER.departmentId=-1;FILTER.categoryId=-1;FILTER.startIdx=startIdx;let tableRef=document.getElementById("tblExtActListMainTable");if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowExtActRowAddMore")}
var http=new XMLHttpRequest();var params="action=getExtraActivityList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_ACTIVITY_EXTRA_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);var totalItems=response.length;if(totalItems>0){hideDivFilter()}
function result(){tableRef.innerHTML+=strFilterResult(response);setElementInnerHtml('lbResultOnList',FILTER.startIdx+response.length);var nRows=startIdx;for(var i=0;i<response.length;i++){let activity=JSON.parse(response[i]);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowExtActRow"+activity.activityextraid);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_EXTRA_ACTIVITY_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,activity.employeeid,"colProductId","Código");let cellName=createTableCell(newRow,activity.employeename,"col-width-110","Nome completo");let cellCategory=createTableCell(newRow,activity.category,"colProductId","Categoria / função");let cellDepart=createTableCell(newRow,activity.department,"colProductId","Posto de trabalho");let cellDate=createTableCell(newRow,setLocalDate(activity.activitydate,10),"text-align-center text-no-wrap","Data da actividade");let cellAct=createTableCell(newRow,(activity.allowance),"text-align-center","Actividade");let cellQuant=createTableCell(newRow,activity.activitys,"text-align-center","Quantidade")}
if(response.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowExtActRowAddMore";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(){myExtraActivityList(Number(FILTER.startIdx)+Number(FILTER.pageItems))}}
hideNotification()}
result()}};http.send(params)}