var PAYROLL_SCALE_ALLOWANCE_LIST=[];function payrollAllowanceOnLoad(){showNotification();setPageTitleWhoCall("4201-4202","PAYROLALL","Lista de subsídios e descontos");function cdoLoad(){if(!checkPermission("4202")){removeElement("btPayRolAllListAllowanceNew");removeElement("divPayrollAlloanceRegister")}
payrollAllowanceRegisterOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function payrollSetAllowanceType(type=""){type=type.toString().toUpperCase();var list=[];list.A="Subsídio";list.D="Desconto";if(type==""){return list}else{return list[type]}}
function payrollSetAllowanceProcessWay(status=-1){var list=[];list[1]="Normal";list[2]="Dependente";list[3]="Dependente dos dias de trabalho";list[4]="Dependente dos turnos de trabalho";list[5]="Dependente das horas de trabalho";if(status==-1){return list}else{return list[status]}}
function payrollSetAllowanceIRTStatus(status=-1){var list=[];list[0]="Isento";list[1]="Sujeito";list[2]="Isento até ao limite";if(status==-1){return list}else{return list[status]}}
function payrollSetPayrollStatus(status=-1){var list=[];list[1]="Normal";list[2]="Aprovada";list[3]="Anulada";if(status==-1){return list}else{return list[status]}}
function payrollSetAdvanceStatus(status=-1){var list=[];list[1]="Aguarda aprovação";list[2]="Aprovado";list[3]="processado";list[4]="Em reembolso";list[5]="finalizado";list[6]="Anulado";if(status==-1){return list}else{return list[status]}}
function payrollAllowanceRegisterOnLoad(){if(!setOnloadStatus("divPayrollAlloanceRegister",payrollAllowanceRegisterOnLoad)){return!1}
fillSelectAllowanceType("selPayRolAllType");fillSelectAllowanceProcessWay("selPayRolAllProcessWay",1,1);fillSelectAllowanceIRTStatus("selPayRolAllIRTStatus",1,1);document.getElementById("selPayRolAllType").onchange=function(){payrollHideSomeField()};document.getElementById("selPayRolAllIRTStatus").onchange=function(){payrollHideSomeField()}}
function payrollAllowanceNew(){payrollAllowanceDetail()}
function payrollAllowanceDetail(allowanceId=-1){showParts("divPayrollAlloanceRegister");const lbHeader=document.getElementById("h2PayRolAllRegHeader");const txtAllowanceId=document.getElementById("txtPayRolAllRegAllowanceId");const txtAllowance=document.getElementById("txtPayRolAllRegAllowance");const selType=document.getElementById("selPayRolAllType");const selProcessWay=document.getElementById("selPayRolAllProcessWay");const txtDefaultValue=document.getElementById("txtPayRolAllRegDefaultValue");const rangeSSStatus=document.getElementById("txtPayRolAllRegSSStatus");const selIRTStatus=document.getElementById("selPayRolAllIRTStatus");const txtIRTLimit=document.getElementById("txtPayRolAllRegIRTLimit");const txtOrder=document.getElementById("txtPayRolAllRegTableOrdem");const lbUpdate=document.getElementById("lbPayRolAllRegUpdate");if(allowanceId==-1){lbHeader.innerHTML="Novo subsídio / desconto";txtAllowanceId.value="Novo subsídio / desconto *";txtAllowance.value="";selType.value="A";selProcessWay.value=1;txtDefaultValue.value=0;rangeSSStatus.value=1;selIRTStatus.value=1;txtIRTLimit.value=30000;txtOrder.value=-1;lbUpdate.innerHTML="Actualizado em "+setLocalDate(new Date(),16);enabledElement(selType.id);selType.dispatchEvent(new Event('change'))}else{lbHeader.innerHTML="Dados do subsídio / desconto";disabledElement(selType.id)
if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.allowanceId=allowanceId;var http=new XMLHttpRequest();var params="action=getPayrollAllowanceList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);let allowance=JSON.parse(response[0]);txtAllowanceId.value=allowance.allowanceid;selType.value=allowance.allowancetype;selProcessWay.value=allowance.processway;txtAllowance.value=allowance.allowance;txtDefaultValue.value=allowance.defaultvalue;rangeSSStatus.value=allowance.ssstatus;selIRTStatus.value=allowance.irtstatus;txtIRTLimit.value=allowance.irtlimit;txtOrder.value=allowance.tableorder;lbUpdate.innerHTML="Cadastrado por "+getOperatorName(allowance.operatorEntry,allowance.entryuser)+" em "+setLocalDate(allowance.entrydate,16)+". <br>"+"Actualizado por "+getOperatorName(allowance.operatorName,allowance.statususer)+" em "+setLocalDate(allowance.statusdate,16);selType.dispatchEvent(new Event('change'))}};http.send(params)}
setAutoCompleteToFiel("txtPayRolAllRegAllowance",52);txtAllowance.focus()}
function payrollHideSomeField(){var type=getElementValue("selPayRolAllType");var status=getElementValue("selPayRolAllIRTStatus");if(type=="D"){hideParts("divPayRolAllProcessWay");hideParts("divPayRolAllSSStatus");hideParts("divPayRolAllIRTStatus");hideParts("divPayRolAllIRTLimit")}else{showParts("divPayRolAllProcessWay",!0);showParts("divPayRolAllSSStatus",!0);showParts("divPayRolAllIRTStatus",!0);if(status==2){showParts("divPayRolAllIRTLimit",!0)}else{hideParts("divPayRolAllIRTLimit")}}}
function payrollAllowanceRegisterSave(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.allowanceid=getElementValue("txtPayRolAllRegAllowanceId");FILTER.allowance=reviewString(document.getElementById("txtPayRolAllRegAllowance")).toUpperCase();FILTER.allowancetype=getElementValue("selPayRolAllType");FILTER.processway=getElementValue("selPayRolAllProcessWay");FILTER.defaultvalue=getElementValue("txtPayRolAllRegDefaultValue");FILTER.ssstatus=getElementValue("txtPayRolAllRegSSStatus");FILTER.irtstatus=getElementValue("selPayRolAllIRTStatus");FILTER.irtlimit=getElementValue("txtPayRolAllRegIRTLimit");FILTER.tableorder=getElementValue("txtPayRolAllRegTableOrdem");var mandatoryField=!1;var msg="";if(FILTER.allowance==""){mandatoryField=!0;msg+="Deve indicar a designação do subsídio / desconto. <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=savePayrollAllowance"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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("divPayrollAlloanceRegister");if(ST_SRH_MAIN_WHO_CALL=="PAYROLALL"){payrollAllowanceList()}}else{showNotification(result.msg,0)}}};http.send(params)}
function payrollAllowanceList(startIdx=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.allowanceId=-1;FILTER.startIdx=startIdx;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
let tableRef=document.getElementById("tblPayRolAllListMainTable");if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowPayRollAllAddMore")}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollAllowanceList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);tableRef.innerHTML+=strFilterResult(response);setElementInnerHtml("lbResultOnList",FILTER.startIdx+response.length);var nRows=startIdx;for(var i=0;i<response.length;i++){let allowance=JSON.parse(response[i]);var proc="",ss="",irt="",limit="";if(allowance.allowancetype=="A"){proc=payrollSetAllowanceProcessWay(allowance.processway);if(allowance.exemptassignedcar==1){proc+=strDiv("<i>* IPVA</i>","font-size-small color-gray")}
ss=payrollSetAllowanceIRTStatus(allowance.ssstatus);irt=payrollSetAllowanceIRTStatus(allowance.irtstatus);if((allowance.irtstatus==2)){limit=formatNumber(allowance.irtlimit)}}
nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowPayRollAllList"+allowance.allowanceid);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_PAYROLL_ALLOWANCE_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,allowance.allowanceid,"colProductId","Código");let cellType=createTableCell(newRow,payrollSetAllowanceType(allowance.allowancetype),"","Tipo");let cellAllowance=createTableCell(newRow,allowance.allowance,"","Subsídio / desconto");let cellProcess=createTableCell(newRow,proc,"colProductIs","Forma de processamento");let cellSS=createTableCell(newRow,ss,"text-align-center","Segurança Social");let cellIRT=createTableCell(newRow,irt,"text-align-center","IRT");let cellIRTLimit=createTableCell(newRow,limit,"colAmount","Limite de isenção IRT");let cellOrder=createTableCell(newRow,allowance.tableorder,"colProductId","Ordem");let cellUpdate=createTableCell(newRow,setLocalDate(allowance.statusdate,16),"colProductId","Última actualização");let cellOperator=createTableCell(newRow,getFirtLastName(allowance.operatorName)+" ("+allowance.statususer+")","colProductId","Código");let cellEdit=createTableCell(newRow,"","noPrint text-align-center","...");if(checkPermission("4202")){let btEdit=document.createElement("button");btEdit.setAttribute("class","labelEdit");btEdit.type="button";btEdit.name=allowance.allowanceid;btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_ALLOWANCE_LIST");payrollAllowanceDetail(btEdit.name)};cellEdit.appendChild(btEdit)}}
if(response.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowPayRollAllAddMore";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(){payrollAllowanceList(FILTER.startIdx+FILTER.pageItems)}}
hideNotification()}};http.send(params)}
function payrollAllowanceRegisterDelete(){function realDelete(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.allowanceid=getElementValue("txtPayRolAllRegAllowanceId");var mandatoryField=!1;var msg="";if(FILTER.allowanceid==""){mandatoryField=!0;msg+="Deve um subsídio / desconto válido. <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=deletePayrollAllowance"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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("divPayrollAlloanceRegister");if(ST_SRH_MAIN_WHO_CALL=="PAYROLALL"){payrollAllowanceList()}}else{showNotification(result.msg,0)}}};http.send(params)}
showConfirm("Tem a certeza que deseja apagar este subsídio / desconto?",realDelete)}
function payrollScaleOnLoad(){showNotification();setPageTitleWhoCall("4201-4202","PAYROLSCA","Escala salarial");function cdoLoad(){if(!checkPermission("4202")){removeElement("btEmpCatLisNewCategory");removeElement("divEmployeeCategoryRegister")}
if(!checkPermission("4202")){removeElement("btEmpCatRegAllowanceNew");removeElement("divPayrollAlloanceRegister")}
employeeCategorySearchOnLoad();payrollAllowanceRegisterOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function payrollScaleRegisterAllowanceList(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.categoryId=getElementValue("txtEmpCatRegCategoryId");var http=new XMLHttpRequest();var params="action=getPayrollScaleAllowanceList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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("tblEmpCatRegAllowance");tableRef.innerHTML="";let nRows=0;for(var i=0;i<response.length;i++){let allowance=JSON.parse(response[i]);let nLine=nRows;PAYROLL_SCALE_ALLOWANCE_LIST[nRows]=allowance;var proc="",ss="",irt="",limit="";if(allowance.allowancetype=="A"){proc=payrollSetAllowanceProcessWay(allowance.processway);ss=payrollSetAllowanceIRTStatus(allowance.ssstatus);irt=payrollSetAllowanceIRTStatus(allowance.irtstatus.toString().substring(0,10))}
nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("class","font-size-small");let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellType=createTableCell(newRow,payrollSetAllowanceType(allowance.allowancetype),"","Tipo");let cellAllowance=createTableCell(newRow,allowance.allowance,"","Subsídio / desconto");let cellProcess=createTableCell(newRow,proc,"text-align-center","Segurança Social");let cellSS=createTableCell(newRow,ss,"text-align-center","Segurança Social");let cellIRT=createTableCell(newRow,irt,"text-align-center","IRT");let cellPerc=createTableCell(newRow);let txtPerc=createElement("input","number","col-width-80","width: 80px;");txtPerc.setAttribute("min",0);txtPerc.setAttribute("max",100);txtPerc.setAttribute("step","any");txtPerc.setAttribute("value",allowance.percent);txtPerc.onchange=function(){payrollScaleRegisterAllowanceOnChange(nLine,'percent',this.value)};cellPerc.appendChild(txtPerc);let cellAmount=createTableCell(newRow);let txtAmount=createElement("input","number");txtAmount.setAttribute("min",0);txtAmount.setAttribute("step","any");txtAmount.setAttribute("value",allowance.amount);txtAmount.onchange=function(){payrollScaleRegisterAllowanceOnChange(nLine,'amount',this.value)};cellAmount.appendChild(txtAmount);if(!checkPermission("4202")){txtPerc.disabled=!0;txtAmount.disabled=!0}}}};http.send(params)}
function payrollScaleRegisterAllowanceOnChange(nLine,field,strValue){PAYROLL_SCALE_ALLOWANCE_LIST[Number(nLine)][field]=strValue}
function payrollScaleList(categoryId=-1,startIdx=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.categoryId=categoryId;FILTER.startIdx=startIdx;var tableRef=document.getElementById("tblPayRollScaMainTable");if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowPayRollScaAddMore")}
var http=new XMLHttpRequest();var params="action=getPayrollScaleAllowanceList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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 allowanceList=[];let tblHeader=document.getElementById("trPayRollScaTableHeader");tblHeader.innerHTML="";let cellHRow=createElement("th");cellHRow.innerHTML="#";tblHeader.appendChild(cellHRow);let cellHCod=createElement("th");cellHCod.innerHTML="Código";tblHeader.appendChild(cellHCod);let cellHCat=createElement("th","","headcol");cellHCat.innerHTML="Categoria / função";tblHeader.appendChild(cellHCat);let cellHSalBase=createElement("th");cellHSalBase.innerHTML="Salário base";tblHeader.appendChild(cellHSalBase);for(var i=0;i<response.length;i++){let allowance=JSON.parse(response[i]);allowanceList[i]=allowance;var bgc=(allowance.allowancetype=="A")?"background-color-green-light":"background-color-maroon";let cellH=createElement("th","","column-optional "+bgc);cellH.innerHTML=allowance.allowance;tblHeader.appendChild(cellH)}
let cellHTotal=createElement("th");cellHTotal.innerHTML="Salário bruto";tblHeader.appendChild(cellHTotal);tblHeader.setAttribute("option-print",0);setPrintTableOption();let cellHAction=createElement("th","","colAction");cellHAction.innerHTML="";tblHeader.appendChild(cellHAction);result(allowanceList)}};http.send(params);function result(allowanceListX){showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollScaleList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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 categories=validateSession(http);setElementInnerHtml("lbResultOnList",FILTER.startIdx+categories.length);tableRef.innerHTML+=strFilterResult(categories);var nRows=startIdx;for(var i=0;i<categories.length;i++){let category=JSON.parse(categories[i]);let salBase=Number(category.salarybase);let tA=0;let tD=0;nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowEmpCatList"+category.categoryid);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_EMPLOYEE_CATEGORY_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,category.categoryid,"colProductId","Código");let cellCategory=createTableCell(newRow,category.category.toString().toUpperCase(),"headcol","Categoria / função");let cellSalBase=createTableCell(newRow,formatNumber(salBase),"font-weight-bold colAmount","Salário base");for(var x=0;x<allowanceListX.length;x++){let allow=allowanceListX[x];var allowId=allow.allowanceid;var allowValue=(Number(category['percent'+allowId])*salBase/100)+Number(category['amount'+allowId]);let cellAllow=createTableCell(newRow,formatNumber(allowValue),"colAmount column-optional",allow.allowance);if(allow.allowancetype=="A"){tA+=Number(allowValue)}else{tD+=Number(allowValue)}}
let cellTotal=createTableCell(newRow,formatNumber(salBase+tA-tD),"font-weight-bold colAmount","Salário bruto");let cellEdit=createTableCell(newRow,"","noPrint text-align-center","...");if(checkPermission("4202")){let btEdit=document.createElement("button");btEdit.setAttribute("class","labelEdit");btEdit.type="button";btEdit.name=category.categoryid;btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_EMPLOYEE_CATEGORY_LIST");employeeCategoryDetail(btEdit.name)};cellEdit.appendChild(btEdit);let btDelete=document.createElement("button");btDelete.setAttribute("class","labelDelete");btDelete.type="button";btDelete.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_EMPLOYEE_CATEGORY_LIST");employeeCategoryDelete(category.categoryid)};cellEdit.appendChild(btDelete)}}
if(categories.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowPayRollScaAddMore";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(){payrollScaleList(categoryId,FILTER.startIdx+FILTER.pageItems)}}
hideNotification()}};http.send(params)}}
var PAYROLL_EMPLOYEE_ADD=0;function payrollListOnLoad(){showNotification();setPageTitleWhoCall("4203","PAYROLPAYROLLIST","Folha de salário");function cdoLoad(){fillSelectWorkscheduleAplicationType("selEmpWorSchRegAplicationType",1,0);var date=new Date();setElementValue("txtPoiConPoiListInitialDate",setLocalDate(new Date(date.getFullYear(),date.getMonth(),1),10));setElementValue("txtPoiConPoiListEndDate",setLocalDate(new Date(),10));document.getElementById("btPayRollListImportRecord").onclick=function(){pointControlActivityLoadNew(getElementValue("txtPoiConPoiListInitialDate"),getElementValue("txtPoiConPoiListEndDate"))};if(!checkPermission("4100")){removeElement("btPayRollListSinchActivity");removeElement("btPayRollListImportRecord")}
if(!checkPermission("4102")){removeElement("btPoiConPoiListSinchActivity");removeElement("btPoiConPoinFault")}
if(!checkPermission("4002")){removeElement("btPoiConPoiListNewEmployee");removeElement("divEmployeeRegister")}
if(!checkPermission("4111")){removeElement("btEmpWorSchRegWorkscheduleNew");removeElement("divWorkscheduleRegister")}
if(!checkPermission("4105")){removeElement("btPoiConPoiListFaultReport")}
if(!checkPermission("4103")){removeElement("btPoiConPoinFaultJustify")}
if(!checkPermission("4104")){removeElement("btPoiConPoinFaultCancel")}
if(!checkPermission("4209")){removeElement("btPayRollRegAprovePayroll");removeElement("btPayRollRegPayrollDelete")}
employeeSearchOnLoad();employeeRegisterOnLoad();payrollRegisterOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function payrollRegisterOnLoad(){if(!setOnloadStatus("divPayRollRegister",payrollRegisterOnLoad)){return!1}
const txtYear=document.getElementById("txtPayRollRegYear");const selMonth=document.getElementById("selPayRolAllMonth");setElementValue(txtYear.id,new Date().getFullYear());fillSelectMonth(selMonth.id);txtYear.onchange=function(){payrollRegisterYearOnChange()};selMonth.onchange=function(){payrollRegisterYearOnChange()}}
function payrollNew(){payrollDetail()}
function payrollDetail(payrollId=-1){showParts("divPayRollRegister");const lbHeader=document.getElementById("h2PayRollRegHeader");const txtPayrollId=document.getElementById("txtPayRollRegPayrollId");const txtReference=document.getElementById("txtPayRollRegReference");const txtYear=document.getElementById("txtPayRollRegYear");const selMonth=document.getElementById("selPayRolAllMonth");const txtStartDate=document.getElementById("txtPayRollRegStartDate");const txtEndDate=document.getElementById("txtPayRollRegEndDate");const txtDeduceSSonIRT=document.getElementById("txtPayRollRegDeduceSSonIRT");const selPayrollBeafore=document.getElementById("selPayRolAllPaylRollBeafore");const fldsTotal=document.getElementById("fldsPayRollTotals");const lbUpdate=document.getElementById("lbPayRollRegUpdate");if(payrollId==-1){var now=new Date();var year=now.getFullYear();var month=now.getMonth()-1;if(month<0){year-=1;month=11}
lbHeader.innerHTML="Nova folha de salário";txtPayrollId.value="Nova folha de salário *";txtReference.value="";txtYear.value=year;selMonth.value=month+1;txtStartDate.value=setLocalDate(new Date(year,month,1),10);txtEndDate.value=setLocalDate(new Date(year,month+1,0),10);txtDeduceSSonIRT.value=1;enabledElement(txtReference.id);enabledElement(txtYear.id);enabledElement(selMonth.id);enabledElement(txtStartDate.id);enabledElement(txtEndDate.id);enabledElement(txtDeduceSSonIRT.id);enabledElement(selPayrollBeafore.id);hideParts(fldsTotal.id);lbUpdate.innerHTML="Actualizado em "+setLocalDate(now,16)}else{lbHeader.innerHTML="Dados da folha de salário";disabledElement(txtReference.id);disabledElement(txtYear.id);disabledElement(selMonth.id);disabledElement(txtStartDate.id);disabledElement(txtEndDate.id);disabledElement(txtDeduceSSonIRT.id);disabledElement(selPayrollBeafore.id);fldsTotal.style.display="flex";if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.payrollId=payrollId;FILTER.year=-1;var http=new XMLHttpRequest();var params="action=getPayrollList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);let payroll=JSON.parse(response[0]);txtPayrollId.value=payroll.payrollid;txtReference.value=payroll.reference;txtYear.value=payroll.referenceyear;selMonth.value=payroll.referencemonth;txtStartDate.value=setLocalDate(payroll.startdate,10);txtEndDate.value=setLocalDate(payroll.enddate,10);txtDeduceSSonIRT.value=payroll.deducessonirt;setElementInnerHtml("lbPayRollTotalEmployees",payroll.totalemployee);setElementInnerHtml("lbPayRollTotalAllowance",formatNumber(payroll.totalallowance));setElementInnerHtml("lbPayRollTotalSSEmployee",formatNumber(payroll.totalssemployee));setElementInnerHtml("lbPayRollTotalSSCompany",formatNumber(payroll.totalsscompamy));setElementInnerHtml("lbPayRollTotalIRT",formatNumber(payroll.totalirt));setElementInnerHtml("lbPayRollTotalLiquid",formatNumber(payroll.totalliquid));lbUpdate.innerHTML="Cadastrado por "+getOperatorName(payroll.operatorEntry,payroll.entryuser)+" em "+setLocalDate(payroll.entrydate,16)+". <br>"+"Actualizado por "+getOperatorName(payroll.operatorName,payroll.statususer)+" em "+setLocalDate(payroll.statusdate,16)}};http.send(params)}
fillSelectPayroll(selPayrollBeafore.id,-1);txtReference.focus()}
function payrollRegisterYearOnChange(){var year=getElementValue("txtPayRollRegYear");var month=Number(getElementValue("selPayRolAllMonth"))-1;setElementValue("txtPayRollRegStartDate",setLocalDate(new Date(year,month,1),10));setElementValue("txtPayRollRegEndDate",setLocalDate(new Date(year,month+1,0),10))}
function payrollRegisterSave(nextStatus=1){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.payrollid=getElementValue("txtPayRollRegPayrollId");FILTER.reference=reviewString(document.getElementById("txtPayRollRegReference")).toUpperCase();FILTER.referenceyear=getElementValue("txtPayRollRegYear");FILTER.referencemonth=getElementValue("selPayRolAllMonth");FILTER.startdate=getElementValue("txtPayRollRegStartDate");FILTER.enddate=getElementValue("txtPayRollRegEndDate");FILTER.deducessonirt=getElementValue("txtPayRollRegDeduceSSonIRT");FILTER.payrollstatus=nextStatus;FILTER.payrollSource=getElementValue("selPayRolAllPaylRollBeafore");var mandatoryField=!1;var msg="";if(FILTER.reference==""){FILTER.reference=FILTER.referenceyear+"-"+leadingZero(FILTER.referencemonth,2)}
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=savePayrollInformation"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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("divPayRollRegister");hideParts("divPayRollSearch");payrollLoadEmployee(result.payrollid)}else{showNotification(result.msg,0)}}};http.send(params)}
function payrollLoadEmployee(payrollId,employeeId=-1,startIdx=0,transpAllowList=[],transpBase=0,transpExtra=0,transpVac=0,transpAdva=0,transpAllo=0,transpLend=0,transpInstall=0,transpFault=0,transpSS=0,transpIRT=0,transpDesco=0,transpLiqu=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.payrollId=payrollId;FILTER.employeeId=employeeId;FILTER.startIdx=startIdx;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
let tableRef=document.getElementById("tblPayRollListMainTable");var totalBase=transpBase;var totalExtra=transpExtra;var totalVaction=transpVac;var totalAdvance=transpAdva;var totalAllowance=transpAllo;var totalLending=transpLend;var totalInstallment=transpInstall;var totalFault=transpFault;var totalSS=transpSS;var totalIRT=transpIRT;var totalDescount=transpDesco;var totalLiquid=transpLiqu;if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowPayRollListEmpAddMore");removeElement("rowPayRollListEmpTotal")}
var ALLOWANCE_LIST=[];ST_SRH_WAITING_SERVER=1;showNotification();var http=new XMLHttpRequest();var params="action=getPayrollLoadEmployee"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);var pResponse=JSON.parse(response.p);_set_payroll_detail(pResponse);var aResponse=response.a;_set_payroll_header(aResponse);var eResponse=response.e;_set_payroll_employees(eResponse,pResponse.payrollstatus);hideNotification()}};http.send(params);function _set_payroll_employees(employees,payrollStatus){var totalItems=employees.length;if(totalItems<=0){showNotification('Não foram encontrados trabalhadores para esta folha de salário.',0)}
setElementInnerHtml('lbResultOnList',FILTER.startIdx+employees.length);function result(){var nRows=startIdx;for(var i=0;i<ALLOWANCE_LIST.length;i++){let allowance=ALLOWANCE_LIST[i];allowance.total=0;transpAllowList.forEach(tranAll=>{if(tranAll.allowanceid==allowance.allowanceid){allowance.total=tranAll.total}})}
for(var i=0;i<employees.length;i++){let employee=JSON.parse(employees[i]);let salBase=Number(employee.salarybase);totalBase+=salBase;nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowPayRollListEmp"+employee.id);newRow.setAttribute("title",nRows+" / "+employee.employeeid+" / "+employee.employeename);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_PAYROLL_EMP_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,employee.employeeid,"colProductId column-optional","Código");let cellAgent=createTableCell(newRow,leadingZero(employee.agentnumberreal,4),"colProductId","Nº de agente");let cellName=createTableCell(newRow,employee.employeename,"col-width-150 headcol");let cellPrevCat=createTableCell(newRow,employee.previuoscategory,"font-size-small");let cellCategory=createTableCell(newRow,employee.category,"font-size-small");let cellDepart=createTableCell(newRow,employee.department,"column-optional font-size-small");let cellBank=createTableCell(newRow,employee.account,"column-optional font-size-small");let cellDays=createTableCell(newRow,employee.worktimes,"font-size-small text-align-center");let cellHours=createTableCell(newRow,formatNumber(employee.workhours),"font-size-small text-align-center");let cellSalBase=createTableCell(newRow,formatNumber(salBase),"font-weight-bold colAmount background-color-green-light");totalExtra+=Number(employee.extratimeamount);let cellExtTime=createTableCell(newRow,formatNumber(employee.extratimeamount),"column-optional colAmount");totalVaction+=Number(employee.vacationallowance);let cellVac=createTableCell(newRow,formatNumber(employee.vacationallowance),"column-optional colAmount");totalAdvance+=Number(employee.advanceamount);let cellAdv=createTableCell(newRow,formatNumber(employee.advanceamount),"column-optional colAmount");var oldAlloType="A";for(var x=0;x<ALLOWANCE_LIST.length;x++){let allow=ALLOWANCE_LIST[x];var allowId=allow.allowanceid;var alloType=allow.allowancetype;var allowValue=Number(employee['a'+allowId]);ALLOWANCE_LIST[x].total+=allowValue;if(oldAlloType!=alloType){totalAllowance+=Number(employee.totalallowance);let cellSTAllo=createTableCell(newRow,formatNumber(employee.totalallowance),"font-weight-bold colAmount background-color-green-light")}
let cellAllow=createTableCell(newRow,formatNumber(allowValue),"column-optional colAmount");oldAlloType=alloType}
totalLending+=Number(employee.lendingamount);let cellLending=createTableCell(newRow,formatNumber(employee.lendingamount),"column-optional colAmount");totalInstallment+=Number(employee.installmentamount);let cellInstall=createTableCell(newRow,formatNumber(employee.installmentamount),"column-optional colAmount");totalFault+=Number(employee.faultamount);let cellFault=createTableCell(newRow,formatNumber(employee.faultamount),"column-optional colAmount");totalSS+=Number(employee.ssamount);let cellSS=createTableCell(newRow,formatNumber(employee.ssamount),"column-optional colAmount");totalIRT+=Number(employee.irtamount);let cellIRT=createTableCell(newRow,formatNumber(employee.irtamount),"column-optional colAmount");totalDescount+=Number(employee.totaldescount);let cellSTDesc=createTableCell(newRow,formatNumber(employee.totaldescount),"font-weight-bold colAmount background-color-brown");totalLiquid+=Number(employee.totalliquid);let cellLiqu=createTableCell(newRow,formatNumber(employee.totalliquid),"font-weight-bold colAmount background-color-green-light");let cellEdit=createTableCell(newRow,"","noPrint text-align-center","...");if(payrollStatus==1){if((checkPermission("4104"))||(checkPermission("4202"))){let btEdit=document.createElement("button");btEdit.setAttribute("class","labelEdit");btEdit.type="button";btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_EMP_LIST");payrollEmployeeRegisterDetail(employee)};cellEdit.appendChild(btEdit)}
let btDelete=document.createElement("button");btDelete.setAttribute("class","labelDelete");btDelete.type="button";btDelete.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_EMP_LIST");payrollDelete(employee)};cellEdit.appendChild(btDelete);let btMagic=document.createElement("button");btMagic.setAttribute("class","labelMagic");btMagic.innerHTML="Actualizar";btMagic.type="button";btMagic.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_EMP_LIST");payrollUpdatePayrollFull(employee.employeeid)};cellEdit.appendChild(btMagic);if(checkPermission("4002")){let btEdit=createElement("button","button","labelCustomer");btEdit.innerHTML="Trabalhador";btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_EMP_LIST");employeeRegisterDetail(employee.employeeid)};cellEdit.appendChild(btEdit)}}}
let newRow=tableRef.insertRow(-1);newRow.id="rowPayRollListEmpTotal";newRow.setAttribute("class","borderGray font-size-large font-weight-bold");let cellRow=createTableCell(newRow,"");let cellId=createTableCell(newRow,"","column-optional");let cellAgent=createTableCell(newRow,"");let cellName=createTableCell(newRow,"TOTAL");let cellPrevCat=createTableCell(newRow,"");let cellCategory=createTableCell(newRow,"");let cellDepart=createTableCell(newRow,"","column-optional");let cellBank=createTableCell(newRow,"","column-optional");let cellDays=createTableCell(newRow,"");let cellHours=createTableCell(newRow,"");let cellSalBase=createTableCell(newRow,formatNumber(totalBase),"colAmount background-color-green-light");let cellExtTime=createTableCell(newRow,formatNumber(totalExtra),"column-optional colAmount");let cellVac=createTableCell(newRow,formatNumber(totalVaction),"column-optional colAmount");let cellAdv=createTableCell(newRow,formatNumber(totalAdvance),"column-optional colAmount");var oldAlloType="A";for(var x=0;x<ALLOWANCE_LIST.length;x++){let allow=ALLOWANCE_LIST[x];var allowValue=allow.total;var alloType=allow.allowancetype
if(oldAlloType!=alloType){let cellSTAllo=createTableCell(newRow,formatNumber(totalAllowance),"colAmount background-color-green-light")}
let cellAllow=createTableCell(newRow,formatNumber(allowValue),"column-optional colAmount");oldAlloType=alloType}
let cellLend=createTableCell(newRow,formatNumber(totalLending),"column-optional colAmount");let cellInstal=createTableCell(newRow,formatNumber(totalInstallment),"column-optional colAmount");let cellFault=createTableCell(newRow,formatNumber(totalFault),"column-optional colAmount");let cellSS=createTableCell(newRow,formatNumber(totalSS),"column-optional colAmount");let cellIRT=createTableCell(newRow,formatNumber(totalIRT),"column-optional colAmount");let cellSTDesc=createTableCell(newRow,formatNumber(totalDescount),"colAmount background-color-brown");let cellLiqu=createTableCell(newRow,formatNumber(totalLiquid),"colAmount background-color-green-light");if(employees.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowPayRollListEmpAddMore";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(){payrollLoadEmployee(payrollId,employeeId,FILTER.startIdx+FILTER.pageItems,ALLOWANCE_LIST,totalBase,totalExtra,totalVaction,totalAdvance,totalAllowance,totalLending,totalInstallment,totalFault,totalSS,totalIRT,totalDescount,totalLiquid)}}}
result()}
function _set_payroll_detail(payroll){const span=(content)=>'<span style="white-space: nowrap; margin-left: 10px;">'+content+'</span>';var header=span("Folha: "+(payroll.referenceyear+"/"+monthName(Number(payroll.referencemonth)-1).toUpperCase()).bold())+span("Estado: "+payrollSetPayrollStatus(payroll.payrollstatus).bold())+span("Abertura: "+setLocalDate(payroll.startdate,10).bold())+span("Fecho: "+setLocalDate(payroll.enddate,10).bold());setElementInnerHtml("lbPayRollListPayRollHeader",header);setElementValue("txtPayRollListPayrollId",payroll.payrollid);setElementValue("txtPayRollListReferenceYear",payroll.referenceyear);setElementValue("txtPayRollListReferenceMonth",payroll.referencemonth);setElementValue("txtPayRollListDeduceSSOnIRT",payroll.deducessonirt);setElementValue("txtPoiConPoiListInitialDate",setLocalDate(payroll.startdate,10));setElementValue("txtPoiConPoiListEndDate",setLocalDate(payroll.enddate,10));var totals=span("Trabalhadores: "+payroll.totalemployee.bold())+span("Líquido: "+formatNumber(payroll.totalliquid).bold())+span("Ilíquido: "+formatNumber(payroll.totalallowance).bold())+span("Segurança Social (3%): "+formatNumber(payroll.totalssemployee).bold())+span("Segurança Social (8%): "+formatNumber(payroll.totalsscompamy).bold())+span("IRT: "+formatNumber(payroll.totalirt).bold());setElementInnerHtml("lbPayRollListPayRollTotals",totals);if(payroll.payrollstatus==1){showParts("btPayRollListRefreshPayroll",!0);showParts("btPayRollListEmployeeAdd",!0);showParts("btPayRollListSinchActivity",!0);showParts("btPayRollListImportRecord",!0);showParts("btPayRollListNewEmployee",!0)}else{hideParts("btPayRollListRefreshPayroll");hideParts("btPayRollListEmployeeAdd");hideParts("btPayRollListSinchActivity");hideParts("btPayRollListImportRecord");hideParts("btPayRollListNewEmployee")}}
function _set_payroll_header(aList){let tblHeader=document.getElementById("trPayRollListHeader");tblHeader.innerHTML="";let cellHRow=createElement("th");cellHRow.innerHTML="#";tblHeader.appendChild(cellHRow);let cellHCod=createElement("th","","column-optional");cellHCod.innerHTML="Código";tblHeader.appendChild(cellHCod);let cellHAgent=createElement("th");cellHAgent.innerHTML="Nº de agente";tblHeader.appendChild(cellHAgent);let cellHName=createElement("th","","headcol");cellHName.innerHTML="Nome completo";tblHeader.appendChild(cellHName);let cellPrevCat=createElement("th");cellPrevCat.innerHTML="Categoria";tblHeader.appendChild(cellPrevCat);let cellHCat=createElement("th");cellHCat.innerHTML="Função";tblHeader.appendChild(cellHCat);let cellHDepart=createElement("th","","column-optional");cellHDepart.innerHTML="Posto de trabalho";tblHeader.appendChild(cellHDepart);let cellHConta=createElement("th","","column-optional");cellHConta.innerHTML="Conta bancária";tblHeader.appendChild(cellHConta);let cellHShift=createElement("th");cellHShift.innerHTML="Turnos";tblHeader.appendChild(cellHShift);let cellHHours=createElement("th");cellHHours.innerHTML="Horas";tblHeader.appendChild(cellHHours);let cellHSalBase=createElement("th","","background-color-green");cellHSalBase.innerHTML="SALÁRIO BASE";tblHeader.appendChild(cellHSalBase);let cellHExtTime=createElement("th","","column-optional background-color-green-light");cellHExtTime.innerHTML="HORAS EXTRAS";tblHeader.appendChild(cellHExtTime);let cellHVac=createElement("th","","column-optional background-color-green-light");cellHVac.innerHTML="FÉRIAS";tblHeader.appendChild(cellHVac);let cellHAdv=createElement("th","","column-optional background-color-green-light");cellHAdv.innerHTML="ADIANTAMENTO";tblHeader.appendChild(cellHAdv);var oldAlloType="A";for(var i=0;i<aList.length;i++){let allowance=JSON.parse(aList[i]);ALLOWANCE_LIST[i]=allowance;var alloType=allowance.allowancetype;if(oldAlloType!=alloType){let cellHSTAllo=createElement("th","","background-color-green");cellHSTAllo.innerHTML="SALÁRIO ILÍQUIDO";tblHeader.appendChild(cellHSTAllo)}
var bgc=(alloType=="A")?"background-color-green-light":"background-color-brown";let cellH=createElement("th","","column-optional "+bgc);cellH.innerHTML=allowance.allowance;tblHeader.appendChild(cellH);oldAlloType=alloType}
let cellHLend=createElement("th","","column-optional background-color-brown");cellHLend.innerHTML="REEMBOLSO EMPRÉSTIMO";tblHeader.appendChild(cellHLend);let cellHInst=createElement("th","","column-optional background-color-brown");cellHInst.innerHTML="REEMBOLSO ADIANTAMENTO";tblHeader.appendChild(cellHInst);let cellHFault=createElement("th","","column-optional background-color-brown");cellHFault.innerHTML="Desconto FALTAS";tblHeader.appendChild(cellHFault);let cellHSS=createElement("th","","column-optional background-color-brown");cellHSS.innerHTML="S. SOCIAL";tblHeader.appendChild(cellHSS);let cellHIRT=createElement("th","","column-optional background-color-brown");cellHIRT.innerHTML="IRT";tblHeader.appendChild(cellHIRT);let cellHSTDesco=createElement("th","","background-color-maroon");cellHSTDesco.innerHTML="SUBTOTAL DESCONTO";tblHeader.appendChild(cellHSTDesco);let cellHTotal=createElement("th","","background-color-green");cellHTotal.innerHTML="SALÁRIO LÍQUIDO";tblHeader.appendChild(cellHTotal);tblHeader.setAttribute("option-print",0);setPrintTableOption();let cellHAction=createElement("th","","colAction");cellHAction.innerHTML="";tblHeader.appendChild(cellHAction)}}
function payrollAddEmployee(employeeId){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.employeeId=employeeId;FILTER.payrollId=getElementValue("txtPayRollListPayrollId");FILTER.referenceyear=getElementValue("txtPayRollListReferenceYear");FILTER.referencemonth=getElementValue("txtPayRollListReferenceMonth");FILTER.startdate=getElementValue("txtPoiConPoiListInitialDate");FILTER.enddate=getElementValue("txtPoiConPoiListEndDate");FILTER.deducessonirt=getElementValue("txtPayRollListDeduceSSOnIRT");FILTER.payrollSource=-1;if((isNaN(FILTER.payrollId))||(FILTER.payrollId=="")||(FILTER.payrollId==null)){alert("Deve seleccionar uma folha de salário");return!1}
showNotification();var http=new XMLHttpRequest();var params="action=addPayRollEmployee"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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 result=validateSession(http);if(result.status==!0){showNotification(result.msg,1);payrollLoadEmployee(FILTER.payrollId)}else{showNotification(result.msg,0)}}};http.send(params)}
function payrollSinchActivity(){var FILTER={};FILTER.sessionId=getSessionId();FILTER.companyId=SYSTEM_USER_STATUS.companyId;FILTER.dependencyId=SYSTEM_USER_STATUS.workplaceId;FILTER.userId=SYSTEM_USER_STATUS.userId;FILTER.payrollId=getElementValue("txtPayRollListPayrollId");if((isNaN(FILTER.payrollId))||(FILTER.payrollId=="")||(FILTER.payrollId==null)){alert("Deve seleccionar uma folha de salário");return!1}
pointControlPointSynchToActivity()}
function payrollDelete(payroll){function realDelete(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.payrollId=payroll.payrollid;FILTER.employeeId=payroll.employeeid;showNotification();var http=new XMLHttpRequest();var params="action=removePayRollEmployee"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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 result=validateSession(http);if(result.status==!0){showNotification(result.msg,1);payrollLoadEmployee(FILTER.payrollId)}else{showNotification(result.msg,0)}}};http.send(params)}
showConfirm("Tem a certeja que deseja remover este trabalhador da folha de salário?<br><br>",realDelete)}
function payrollUpdatePayrollFull(employeeId=-1){function realUpdate(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.employeeId=employeeId;FILTER.payrollid=getElementValue("txtPayRollListPayrollId");FILTER.referenceyear=getElementValue("txtPayRollListReferenceYear");FILTER.referencemonth=getElementValue("txtPayRollListReferenceMonth");FILTER.deducessonirt=getElementValue("txtPayRollListDeduceSSOnIRT");FILTER.startdate=getElementValue("txtPoiConPoiListInitialDate");FILTER.enddate=getElementValue("txtPoiConPoiListEndDate");if((isNaN(FILTER.payrollid))||(FILTER.payrollid=="")||(FILTER.payrollid==null)){alert("Deve seleccionar uma folha de salário");return!1}
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=updatePayRollFull"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);payrollLoadEmployee(FILTER.payrollid)}else{showNotification(result.msg,0)}}};http.send(params)}
showConfirm("Tem a certeza que deseja actualizar esta folha de salário?",realUpdate)}
function payrollLoadEmployeeByEmployeeId(employeeId){var payrollid=getElementValue("txtPayRollListPayrollId");if((isNaN(payrollid))||(payrollid=="")||(payrollid==null)){showNotification("Deve seleccionar uma folha de salário",0);return!1}
payrollLoadEmployee(payrollid,employeeId)}
var PAYROLL_ADVANCE_NEW_ASSIGN=0;var PAYROLL_ADVANCE_INSTALLMENSTS_LIST=[];function payrollAdvanceListOnLoad(){showNotification();setPageTitleWhoCall("4206-4207-4208","PAYROLADVLIS","Lista de adiantamento de salário");function cdoLoad(){fillSelectDependencyFull("selPayRolAdvListDependency",-1,1);fillSelectMonth("txtPayRolAdvListMonth",-1);fillSelectSex("selPayRolAdvListSex",-1);fillSelectWorkschedule("selPayRolAdvListWorkschedule",-1);fillSelectCountry("selPayRolAdvListCountry",-1);fillSelectDepartment("selPayRolAdvListDepartment",-1);fillSelectEmployeeCategory("selPayRolAdvListEmployeeCategory",-1);setElementValue("txtPayRolAdvListYear",new Date().getFullYear());setTriggerButtonByText('txtPayRolAdvListYear','btPayRolAdvListViewAll');setTriggerButtonByText('txtPayRolAdvListMonth','btPayRolAdvListViewAll');if(!checkPermission("4002")){removeElement("btEmpLisNewEmployee");removeElement("divEmployeeRegister")}
if(!checkPermission("4207")){removeElement("btPayRolAdvListAdvanceNew");removeElement("divPayRollAdvanceRegister")}
if(!checkPermission("4208")){removeElement("btPayRolAdvRegAprove");removeElement("btPayRolAdvRegCancel")}
fillSelectWorkscheduleAplicationType("selEmpWorSchRegAplicationType",1,0);PAYROLL_ADVANCE_NEW_ASSIGN=0;employeeSearchOnLoad();employeeRegisterOnLoad();payrollAdvanceRegisterOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function payrollAdvanceNew(employee){payrollAdvanceDetails(employee)}
function payrollAdvanceDetails(employee,advanceId=-1){showParts("divPayRollAdvanceRegister");const lbHeader=document.getElementById("h2PayRolAdvRegHeader");const txtEmployeeId=document.getElementById("txtPayRolAdvRegEmployeeId");const txtEmployeeName=document.getElementById("txtPayRolAdvRegEmployeeName");const txtAdvanceId=document.getElementById("txtPayRolAdvRegAdvanceId");const txtAmount=document.getElementById("txtPayRolAdvRegAmount");const txtDirectTax=document.getElementById("txtPayRolAdvRegDirectTax");const txtAdvanceYear=document.getElementById("txtPayRolAdvRegAdvanceYear");const selAdvanceMonth=document.getElementById("selPayRolAdvRegAdvanceMonth");const txtRefoundAmount=document.getElementById("txtPayRolAdvRegRefoundAmount");const txtInstallments=document.getElementById("txtPayRolAdvRegInstallments");const txtRefoundYear=document.getElementById("txtPayRolAdvRegRefoundYear");const selRefoundMonth=document.getElementById("selPayRolAdvRegRefoundMonth");const selStatus=document.getElementById("selPayRolAdvRegAdvanceStatus");const lbUpdate=document.getElementById("lbPayRolAdvRegUpdate");cleanElement("tblPayRolAdvRegInstallments");hideParts("btPayRolAdvRegSave");hideParts("btPayRolAdvRegAprove");hideParts("btPayRolAdvRegCancel");disabledElement(txtAmount.id);disabledElement(txtDirectTax.id);disabledElement(txtAdvanceYear.id);disabledElement(selAdvanceMonth.id);disabledElement(txtInstallments.id);disabledElement(txtRefoundYear.id);disabledElement(selRefoundMonth.id);PAYROLL_ADVANCE_INSTALLMENSTS_LIST=[];if(advanceId==-1){lbHeader.innerHTML="Novo adiantamento";txtEmployeeId.value=employee.employeeid;txtEmployeeName.value=employee.employeename;txtAdvanceId.value="Novo adiantamento *";txtAmount.value=0;txtDirectTax.value=0;txtAdvanceYear.value=new Date().getFullYear();selAdvanceMonth.value=new Date().getMonth()+1;txtRefoundAmount.value=0;txtInstallments.value=1;txtRefoundYear.value=new Date().getFullYear();selRefoundMonth.value=new Date().getMonth()+1;selStatus.value=1;lbUpdate.innerHTML="Actualizado em "+setLocalDate(new Date(),16);showParts("btPayRolAdvRegSave",!0);showParts("btPayRolAdvRegAprove",!0);enabledElement(txtAmount.id);enabledElement(txtDirectTax.id);enabledElement(txtAdvanceYear.id);enabledElement(selAdvanceMonth.id);enabledElement(txtInstallments.id);enabledElement(txtRefoundYear.id);enabledElement(selRefoundMonth.id)}else{lbHeader.innerHTML="Dados do adiantamento de salário";if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.advanceId=advanceId;FILTER.employeeId=-1;FILTER.year=-1;FILTER.month=-1;FILTER.sex="";FILTER.nationality=-1;FILTER.departmentId=-1;FILTER.categoryId=-1;FILTER.startIdx=0;var http=new XMLHttpRequest();var params="action=getPayrollAdvanceList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);let advance=JSON.parse(response[0]);var status=payrollReviewAdvanceStatus(advance);txtEmployeeId.value=advance.employeeid;txtEmployeeName.value=advance.employeename;txtAdvanceId.value=advance.advanceid;txtAmount.value=Number(advance.amount).toFixed(2);txtDirectTax.value=Number(advance.directtax).toFixed(2);txtAdvanceYear.value=advance.advanceyear;selAdvanceMonth.value=advance.advancemonth;txtRefoundAmount.value=Number(advance.refoundamount).toFixed(2);txtInstallments.value=advance.installments;txtRefoundYear.value=advance.refoundyear;selRefoundMonth.value=advance.refoundmonth;selStatus.value=status;payrollAdvanceInstallmentsList(advanceId);lbUpdate.innerHTML="Cadastrado por "+getOperatorName(advance.operatorEntry,advance.entryuser)+" em "+setLocalDate(advance.entrydate,16)+". <br>"+"Actualizado por "+getOperatorName(advance.operatorName,advance.statususer)+" em "+setLocalDate(advance.statusdate,16);if(status==1){showParts("btPayRolAdvRegSave",!0);showParts("btPayRolAdvRegAprove",!0);showParts("btPayRolAdvRegCancel",!0);enabledElement(txtAmount.id);enabledElement(txtDirectTax.id);enabledElement(txtAdvanceYear.id);enabledElement(selAdvanceMonth.id);enabledElement(txtInstallments.id);enabledElement(txtRefoundYear.id);enabledElement(selRefoundMonth.id)}else if(status!=6){showParts("btPayRolAdvRegCancel",!0)}}};http.send(params)}}
function payrollReviewAdvanceStatus(advance){var status=advance.advancestatus;if(status==2){if(Number(advance.installProcessed)>=Number(advance.installments)){status=5}else if(Number(advance.installProcessed)>0){status=4}else if(advance.payrollid!=""){status=3}}
return status}
function payrollAdvanceInstallmentsList(advanceId){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.advanceId=advanceId;PAYROLL_ADVANCE_INSTALLMENSTS_LIST=[];var http=new XMLHttpRequest();var params="action=getPayrollAdvanceInstallmentList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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 nRows=0;for(var i=0;i<response.length;i++){nRows+=1;let install=JSON.parse(response[i]);PAYROLL_ADVANCE_INSTALLMENSTS_LIST[i]=install;payrollAdvanceAddSingleInstall(install,nRows)}}};http.send(params)}
function payrollAdvanceRegisterOnChange(){var status=getElementValue("selPayRolAdvRegAdvanceStatus");if(status!=1){return!1}
PAYROLL_ADVANCE_INSTALLMENSTS_LIST=[];var amount=Number(getElementValue("txtPayRolAdvRegAmount"));var tax=Number(getElementValue("txtPayRolAdvRegDirectTax"));var nInstalls=Number(getElementValue("txtPayRolAdvRegInstallments"));var refoundAmount=Number(amount+(amount*tax/100));var lastYear=Number(getElementValue("txtPayRolAdvRegRefoundYear"));var lastMonth=Number(getElementValue("selPayRolAdvRegRefoundMonth"));var advanceDate=new Date(getElementValue("txtPayRolAdvRegAdvanceYear"),Number(getElementValue("selPayRolAdvRegAdvanceMonth")-1),1);var refoundDate=new Date(lastYear,lastMonth-1,1);if(refoundAmount<=0){showNotification("Valor de embolso ou a taxa directar está errado",0)}else if(nInstalls<=0){showNotification("O número de prestações deve ser suverior a zero.",0)}else if(advanceDate.getTime()>=refoundDate.getTime()){showNotification("O 1º mês de reembolso deve ser superior ao mês de embolso.",0)}
setElementValue("txtPayRolAdvRegRefoundAmount",refoundAmount);cleanElement("tblPayRolAdvRegInstallments");var installmentAmount=Number(refoundAmount/Number(nInstalls));var nRows=0;for(var i=0;i<nInstalls;i++){nRows+=1;let install={installmentid:"Nova prestação",installment:"Prestação "+nRows,installmentyear:lastYear,installmentmonth:lastMonth,amount:installmentAmount,amountprocessed:0};PAYROLL_ADVANCE_INSTALLMENSTS_LIST[i]=install;payrollAdvanceAddSingleInstall(install,nRows);lastMonth+=1;if(lastMonth>12){lastMonth=1;lastYear+=1}}}
function payrollAdvanceAddSingleInstall(install,nRows){const tblConditions=document.getElementById('tblPayRolAdvRegInstallments');let newRow=tblConditions.insertRow(-1);newRow.setAttribute("class","borderGray");newRow.setAttribute("id","trPayRolAdvRegInstallRow"+nRows);let cellRow=createTableCell(newRow,nRows,"colRowNumber");let cellInstal=createTableCell(newRow,install.installment);let cellDate=createTableCell(newRow,install.installmentyear+"/"+monthName(install.installmentmonth-1),"text-align-center");let cellAmount=createTableCell(newRow,formatNumber(install.amount),"colAmount");let cellRefound=createTableCell(newRow,formatNumber(install.amountprocessed),"colAmount")}
function payrollAdvanceRegisterSave(nextStatus=-1){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.employeeId=getElementValue("txtPayRolAdvRegEmployeeId");FILTER.advanceid=getElementValue("txtPayRolAdvRegAdvanceId");FILTER.amount=Number(getElementValue("txtPayRolAdvRegAmount"));FILTER.directtax=Number(getElementValue("txtPayRolAdvRegDirectTax"));FILTER.advanceyear=Number(getElementValue("txtPayRolAdvRegAdvanceYear"));FILTER.advancemonth=Number(getElementValue("selPayRolAdvRegAdvanceMonth"));FILTER.refoundamount=Number(getElementValue("txtPayRolAdvRegRefoundAmount"));FILTER.installments=Number(getElementValue("txtPayRolAdvRegInstallments"));FILTER.refoundyear=Number(getElementValue("txtPayRolAdvRegRefoundYear"));FILTER.refoundmonth=Number(getElementValue("selPayRolAdvRegRefoundMonth"));FILTER.advancestatus=nextStatus;FILTER.installmentsList=PAYROLL_ADVANCE_INSTALLMENSTS_LIST;var mandatoryField=!1;var msg="";if(FILTER.refoundamount<=0){mandatoryField=!0;msg+="Valor de embolso ou a taxa directar está errado. <br>"}else if(FILTER.installments<=0){mandatoryField=!0;msg+="O número de prestações deve ser suverior a zero. <br>"}else if(new Date(FILTER.advanceyear,FILTER.advancemonth-1,1).getTime()>=new Date(FILTER.refoundyear,FILTER.refoundmonth-1,1).getTime()){mandatoryField=!0;msg+="O 1º mês de reembolso deve ser superior ao mês de embolso. <br>"}
if(ST_SRH_WAITING_SERVER==1){mandatoryField=!0;msg+="Aguardando resposta do servidor. <br>"}
if(mandatoryField){alert(msg);return!1}
var lastInstall=PAYROLL_ADVANCE_INSTALLMENSTS_LIST[PAYROLL_ADVANCE_INSTALLMENSTS_LIST.length-1];FILTER.endyear=lastInstall.installmentyear;FILTER.endmonth=lastInstall.installmentmonth;showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=savePayrollAdvance"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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("divPayRollAdvanceRegister");if(ST_SRH_MAIN_WHO_CALL=="PAYROLADVLIS"){payrollAdvanceList(FILTER.employeeId)}}else{showNotification(result.msg,0)}}};http.send(params)}
function payrollAdvanceList(employeeId=-1,startIdx=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=getElementValue("selPayRolAdvListDependency");FILTER.advanceId=-1;FILTER.employeeId=employeeId;FILTER.year=getElementValue('txtPayRolAdvListYear');FILTER.month=getElementValue('txtPayRolAdvListMonth');FILTER.sex=getElementValue("selPayRolAdvListSex");FILTER.nationality=getElementValue("selPayRolAdvListCountry");FILTER.departmentId=getElementValue("selPayRolAdvListDepartment");FILTER.categoryId=getElementValue("selPayRolAdvListEmployeeCategory");FILTER.startIdx=startIdx;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
let tableRef=document.getElementById("tblPayRolAdvListMainTable");if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowPayRollAdvAddMore")}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollAdvanceList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);var totalItems=response.length;if(totalItems>0){hideDivFilter()}
setElementInnerHtml('lbResultOnList',FILTER.startIdx+response.length);function result(){tableRef.innerHTML+=strFilterResult(response);var nRows=startIdx;for(var i=0;i<response.length;i++){let advance=JSON.parse(response[i]);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","trPayRolAdvListRow"+advance.advanceid);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_PAYROLL_ADVANCE_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,advance.employeeid,"colProductId","Código");let cellAgent=createTableCell(newRow,leadingZero(advance.agentnumberreal,4),"colProductId","Nº de agente");let cellName=createTableCell(newRow,advance.employeename,"col-width-150 headcol","Nome completo");let cellAmount=createTableCell(newRow,formatNumber(advance.amount),"font-weight-bold colAmount","Valor Adiantado");let cellTax=createTableCell(newRow,formatNumber(advance.directtax),"text-align-center","Taxa directa (%)");let cellDate=createTableCell(newRow,advance.advanceyear+"/"+monthName(Number(advance.advancemonth)-1),"colProductId","Mês de embolso");let cellRefound=createTableCell(newRow,formatNumber(advance.refoundamount),"font-weight-bold colAmount","Valor a reembolsar");let cellInstalls=createTableCell(newRow,(advance.installments),"text-align-center","Prestações");let cellRefounded=createTableCell(newRow,formatNumber(advance.amountprocessed),"font-weight-bold colAmount","Valor reembolsadp");let cellInstallProcess=createTableCell(newRow,(advance.installProcessed),"text-align-center","Prestações pagas");let cellEnd=createTableCell(newRow,advance.endyear+"/"+monthName(Number(advance.endmonth)-1),"colProductId","Previsão término");var proveBy=(Number(advance.advancestatus)>=2)?getFirtLastName(advance.aproveName)+" ("+advance.aproveuser+")":"";let cellAprov=createTableCell(newRow,proveBy,"colProductId","Aprovado por");var status=payrollReviewAdvanceStatus(advance);var bgc=(status==1)?"background-color-green-light":(status==6)?"background-color-brown":(status==5)?"background-color-maroon":"background-color-green";let cellStatus=createTableCell(newRow,payrollSetAdvanceStatus(status),"colProductId "+bgc,"Estado");let cellUpdate=createTableCell(newRow,setLocalDate(advance.statusdate,16),"colProductId","Última actualização");let cellOper=createTableCell(newRow,getFirtLastName(advance.operatorName)+" ("+advance.statususer+")","colProductId","Operador");let cellAction=createTableCell(newRow,"","noPrint text-align-center","...");let btEdit=document.createElement("button");btEdit.setAttribute("class","labelEdit");btEdit.type="button";btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_ADVANCE_LIST");payrollAdvanceDetails(null,advance.advanceid)};cellAction.appendChild(btEdit);if(checkPermission("4002")){let btEdit=createElement("button","button","labelCustomer");btEdit.innerHTML="Trabalhador";btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_ADVANCE_LIST");employeeRegisterDetail(advance.employeeid)};cellAction.appendChild(btEdit)}}
if(response.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowPayRollAdvAddMore";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(){payrollAdvanceList(employeeId,FILTER.startIdx+FILTER.pageItems)}}
hideNotification()}
result()}};http.send(params)}
function payrollAdvanceRegisterOnLoad(){if(!setOnloadStatus("divPayRollAdvanceRegister",payrollAdvanceRegisterOnLoad)){return!1}
fillSelectMonth("selPayRolAdvRegAdvanceMonth");fillSelectMonth("selPayRolAdvRegRefoundMonth");fillSelectAdvanceStatus("selPayRolAdvRegAdvanceStatus");var elements=[document.getElementById("txtPayRolAdvRegAmount"),document.getElementById("txtPayRolAdvRegDirectTax"),document.getElementById("txtPayRolAdvRegAdvanceYear"),document.getElementById("selPayRolAdvRegAdvanceMonth"),document.getElementById("txtPayRolAdvRegInstallments"),document.getElementById("txtPayRolAdvRegRefoundYear"),document.getElementById("selPayRolAdvRegRefoundMonth")];Array.from(elements).forEach(elem=>{elem.onchange=function(){payrollAdvanceRegisterOnChange()}})}
var PAYROLL_EMPLOYEE_ALLOWANCE_LIST=[];function payrollEmployeeRegisterDetail(employee){showParts("divPayRollEmployeeRegister");var txtFaultDays=document.getElementById("txtPayRolEmpRegFaultDays");var txtFaultH=document.getElementById("txtPayRolEmpRegFaultHours");var txtFaultMin=document.getElementById("txtPayRolEmpRegFaultMinutes");setElementValue("txtPayRolEmpRegEmployeeId",employee.employeeid);setElementValue("txtPayRolEmpRegEmployeeName",employee.employeename);setElementValue("txtPayRolEmpRegVacationAllowance",Number(employee.vacationallowance).toFixed(2));setElementValue(txtFaultDays.id,employee.faultdays);setElementValue(txtFaultH.id,employee.faulthours);setElementValue(txtFaultMin.id,employee.faultminutes);if(checkPermission("4104")){enabledElement(txtFaultDays.id);enabledElement(txtFaultH.id);enabledElement(txtFaultMin.id)}else{disabledElement(txtFaultDays.id);disabledElement(txtFaultH.id);disabledElement(txtFaultMin.id)}
PAYROLL_EMPLOYEE_ALLOWANCE_LIST=[];if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.payrollId=employee.payrollid;FILTER.employeeId=employee.employeeid;var http=new XMLHttpRequest();var params="action=getPayrollEmployeeAllowanceList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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("tblPayRolEmpRegAllowance");tableRef.innerHTML="";let nRows=0;for(var i=0;i<response.length;i++){let allowance=JSON.parse(response[i]);let nLine=nRows;PAYROLL_EMPLOYEE_ALLOWANCE_LIST[nRows]=allowance;var alloType=allowance.allowancetype;var proc="";if(alloType=="A"){proc=payrollSetAllowanceProcessWay(allowance.processway)}
nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("class","font-size-small");let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");var bgc=(alloType=="A")?"background-color-green-light":"background-color-brown";let cellType=createTableCell(newRow,payrollSetAllowanceType(alloType),bgc,"Tipo");let cellAllowance=createTableCell(newRow,allowance.allowance);let cellProcess=createTableCell(newRow,proc,"text-align-center");let cellPerc=createTableCell(newRow,"","text-align-center");let cellAmountPer=createTableCell(newRow,"","colAmount");if(alloType=="A"){var prod=allowance.product;if(allowance.processway==2){if(checkPermission("4202")){let txtPerc=createElement("input","number","col-width-60","width: 60px;");txtPerc.setAttribute("min",0);txtPerc.setAttribute("step","any");txtPerc.setAttribute("value",prod);txtPerc.onchange=function(){payrollEmployeeRegisterAllowanceOnChange(nLine,'product',this.value)};cellPerc.appendChild(txtPerc)}else{cellPerc.innerHTML=prod}
cellAmountPer.innerHTML=formatNumber(allowance.amountperproduct)}}
let cellAmount=createTableCell(newRow,formatNumber(allowance.amount),"colAmount");if(checkPermission("4202")){cellAmount.innerHTML="";let txtAmount=createElement("input","number");txtAmount.setAttribute("id","txtPayRolEmpRegAllowance"+nLine);txtAmount.setAttribute("min",0);txtAmount.setAttribute("step","any");txtAmount.setAttribute("value",allowance.amount);txtAmount.onchange=function(){payrollEmployeeRegisterAllowanceOnChange(nLine,'amount',this.value)};cellAmount.appendChild(txtAmount);if(allowance.processway==2){txtAmount.setAttribute("disabled",!0)}}}}};http.send(params)}
function payrollEmployeeRegisterAllowanceOnChange(nLine,field,strValue){PAYROLL_EMPLOYEE_ALLOWANCE_LIST[Number(nLine)][field]=Number(strValue);var allowance=PAYROLL_EMPLOYEE_ALLOWANCE_LIST[Number(nLine)];if(allowance.allowancetype=="A"){if(allowance.processway==2){allowance.amount=Number(allowance.product)*Number(allowance.amountperproduct);setElementValue("txtPayRolEmpRegAllowance"+nLine,Number(allowance.amount).toFixed(2))}}
allowance.changed=1}
function payrollEmployeeRegisterSave(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.employeeId=getElementValue("txtPayRolEmpRegEmployeeId");FILTER.payrollId=getElementValue("txtPayRollListPayrollId");FILTER.deducessonirt=getElementValue("txtPayRollListDeduceSSOnIRT");FILTER.vacationallowance=getElementValue("txtPayRolEmpRegVacationAllowance");FILTER.faultdays=getElementValue("txtPayRolEmpRegFaultDays");FILTER.faulthours=getElementValue("txtPayRolEmpRegFaultHours");FILTER.faultminutes=getElementValue("txtPayRolEmpRegFaultMinutes");FILTER.allawanceList=PAYROLL_EMPLOYEE_ALLOWANCE_LIST;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=savePayrollEmployee"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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("divPayRollEmployeeRegister");if(ST_SRH_MAIN_WHO_CALL=="PAYROLPAYROLLIST"){payrollLoadEmployee(FILTER.payrollId)}}else{showNotification(result.msg,0)}}};http.send(params)}
function payrollExtractOnLoad(){showNotification();setPageTitleWhoCall("4205","PAYROLEXTR","Extracto da folha de salário");function cdoLoad(){fillSelectDependencyFull("selPayRollExtrListDependency",-1,1);fillSelectPayrollExtractType("selPayRollExtrListType");fillSelectNationalBank("selPayRollExtrBank",-1);fillSelectWorkschedule("selPayRollExtrWorkschedule",-1);fillSelectCountry("selPayRollExtrCountry",-1);fillSelectDepartment("selPayRollExtrDepartment",-1);fillSelectEmployeeCategory("selPayRollExtrEmployeeCategory",-1);var toChange=["selPayRollExtrListType","selPayRollExtrBank","selPayRollExtrWorkschedule","selPayRollExtrCountry","selPayRollExtrDepartment","selPayRollExtrEmployeeCategory"];Array.from(toChange).forEach(ids=>{try{document.getElementById(ids).addEventListener('change',()=>{cleanElement("tblPayRollExtrMainTable")})}catch(e){}});document.getElementById("btPayRollExtrPrint").onclick=function(){var title="Folha de salário "+getElementInnerHTML("lbPayRollExtrPayRollReference");printPageA4(title)};payrollRegisterOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function payrollExtractSelectSheet(payroll){if(payroll.payrollstatus!=2){showNotification("Deve seleccionar uma folha de salário bloqueada",0);return!1}
setElementValue("txtPayRollExtrPayrollId",payroll.payrollid,0);payrollExtractList()}
function payrollExtractList(startIdx=0,transpAllowList=[],transpBase=0,transpExtra=0,transpVac=0,transpSS=0,transpSS8=0,transpSS11=0,transpIRT=0,transpDesc=0,transpLiq=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=getElementValue("selPayRollExtrListDependency");FILTER.payrollId=getElementValue("txtPayRollExtrPayrollId");FILTER.listType=getElementValue("selPayRollExtrListType");FILTER.nationalBank=getElementValue("selPayRollExtrBank");FILTER.workscheduleId=getElementValue("selPayRollExtrWorkschedule");FILTER.nationality=getElementValue("selPayRollExtrCountry");FILTER.categoryId=getElementValue("selPayRollExtrEmployeeCategory");FILTER.departmentId=getElementValue("selPayRollExtrDepartment");FILTER.startIdx=startIdx;if((FILTER.payrollId=="")||(FILTER.payrollId==null)||(isNaN(FILTER.payrollId))){showNotification("Deve seleccionar uma folha de salário",0);return!1}
if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
var tableRef=document.getElementById("tblPayRollExtrMainTable");var totalBase=transpBase;var totalExtra=transpExtra;var totalVaction=transpVac;var totalSS=transpSS;var totalSS8=transpSS8;var totalSS11=transpSS11;var totalIRT=transpIRT;var totalDescount=transpDesc;var totalLiquid=transpLiq;if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowPayRollExtrAddMore");removeElement("rowPayRollExtrTotal")}
var ALLOWANCE_LIST=[];var PAYROLL_DETAILS={};ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollExtractList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);hideDivFilter();var pResponse=JSON.parse(response.p);_set_payroll_detail(pResponse);var aResponse=response.a;_set_payroll_header(aResponse);var eResponse=response.e;_set_payroll_employees(eResponse,pResponse.payrollstatus);hideNotification()}};http.send(params);function _set_payroll_employees(employees,payrollStatus){var nRows=startIdx;for(var i=0;i<ALLOWANCE_LIST.length;i++){let allowance=ALLOWANCE_LIST[i];allowance.total=0;transpAllowList.forEach(tranAll=>{if(tranAll.allowanceid==allowance.allowanceid){allowance.total=tranAll.total}})}
for(var i=0;i<employees.length;i++){let employee=JSON.parse(employees[i]);let salBase=Math.floor(round2Dec(employee.salarybase));totalBase+=salBase;nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("class","borderGray");let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellAgent=createTableCell(newRow,leadingZero(employee.agentnumberreal,4),"colProductId");let cellName=createTableCell(newRow,employee.employeename,"col-width-150 headcol");let cellCategory=createTableCell(newRow,employee.category,"font-size-small");if(FILTER.listType==1){let cellAccount=createTableCell(newRow,employee.accountnumber,"font-size-small colNoWrap");let cellIban=createTableCell(newRow,employee.iban,"font-size-small colNoWrap");totalLiquid+=Math.floor(round2Dec(employee.totalliquid));let cellLiqu=createTableCell(newRow,formatNumber(Math.floor(round2Dec(employee.totalliquid))),"font-weight-bold colAmount")}else{if(FILTER.listType==3){let cellIRTGr=createTableCell(newRow,employee.irtgroup,"font-size-small text-align-center")}
let cellSalBase=createTableCell(newRow,formatNumber(salBase),"colAmount");if(PAYROLL_DETAILS.extratimeamount!=0){totalExtra+=Math.floor(round2Dec(employee.extratimeamount));let cellExtra=createTableCell(newRow,formatNumber(Math.floor(round2Dec(employee.extratimeamount))),"column-optional colAmount")}
if(PAYROLL_DETAILS.vacationallowance!=0){totalVaction+=Math.floor(round2Dec(employee.vacationallowance));let cellVac=createTableCell(newRow,formatNumber(Math.floor(round2Dec(employee.vacationallowance))),"column-optional colAmount")}
for(var x=0;x<ALLOWANCE_LIST.length;x++){let allow=ALLOWANCE_LIST[x];var allowId=allow.allowanceid;var allowValue=round2Dec(employee['a'+allowId]);ALLOWANCE_LIST[x].total+=allowValue;let cellAllow=createTableCell(newRow,formatNumber(allowValue),"column-optional colAmount")}
var ss3Amount=Math.floor(round2Dec(employee.ssamount));totalSS+=ss3Amount;if((FILTER.listType==2)||(PAYROLL_DETAILS.deducessonirt==1)){let cellSS=createTableCell(newRow,formatNumber(ss3Amount),"colAmount")}
if(FILTER.listType==2){var ss8Amount=(ss3Amount/3)*8;totalSS8+=ss8Amount;let cellSS8=createTableCell(newRow,formatNumber(ss8Amount),"colAmount");var ss11Amount=(ss3Amount/3)*11;totalSS11+=ss11Amount;let cellSS11=createTableCell(newRow,formatNumber(ss11Amount),"colAmount font-weight-bold")}else{totalIRT+=Math.floor(round2Dec(employee.irtamount));let cellIRT=createTableCell(newRow,formatNumber(Math.floor(round2Dec(employee.irtamount))),"colAmount font-weight-bold")}}}
let newRow=tableRef.insertRow(-1);newRow.id="rowPayRollExtrTotal";newRow.setAttribute("class","borderGray font-size-large font-weight-bold");let cellRow=createTableCell(newRow,"");let cellAgent=createTableCell(newRow,"");let cellName=createTableCell(newRow,"TOTAL");let cellCategory=createTableCell(newRow,"");if(FILTER.listType==1){let cellAccount=createTableCell(newRow,"");let cellIban=createTableCell(newRow,"");let cellLiqu=createTableCell(newRow,formatNumber(totalLiquid),"colAmount")}else{if(FILTER.listType==3){let cellIRTGr=createTableCell(newRow,"")}
let cellSalBase=createTableCell(newRow,formatNumber(totalBase),"colAmount");if(PAYROLL_DETAILS.extratimeamount!=0){let cellExtra=createTableCell(newRow,formatNumber(extratimeamount),"column-optional colAmount")}
if(PAYROLL_DETAILS.vacationallowance!=0){let cellVac=createTableCell(newRow,formatNumber(totalVaction),"column-optional colAmount")}
for(var x=0;x<ALLOWANCE_LIST.length;x++){let allow=ALLOWANCE_LIST[x];var allowValue=allow.total;let cellAllow=createTableCell(newRow,formatNumber(allowValue),"column-optional colAmount")}
if((FILTER.listType==2)||(PAYROLL_DETAILS.deducessonirt==1)){let cellSS=createTableCell(newRow,formatNumber(totalSS),"colAmount")}
if(FILTER.listType==2){let cellSS8=createTableCell(newRow,formatNumber(totalSS8),"colAmount");let cellSS11=createTableCell(newRow,formatNumber(totalSS11),"colAmount")}else{let cellIRT=createTableCell(newRow,formatNumber(totalIRT),"colAmount")}}
if(employees.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowPayRollExtrAddMore";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(){payrollExtractList(FILTER.startIdx+FILTER.pageItems,ALLOWANCE_LIST,totalBase,totalVaction,totalSS,totalSS8,totalSS11,totalIRT,totalDescount,totalLiquid)}}}
function _set_payroll_detail(payroll){PAYROLL_DETAILS=payroll;const span=(content)=>'<span style="white-space: nowrap; margin-left: 10px;">'+content+'</span>';var header=span("Folha: "+(payroll.referenceyear+"/"+monthName(Number(payroll.referencemonth)-1).toUpperCase()).bold())+span("Estado: "+payrollSetPayrollStatus(payroll.payrollstatus).bold())+span("Abertura: "+setLocalDate(payroll.startdate,10).bold())+span("Fecho: "+setLocalDate(payroll.enddate,10).bold());setElementInnerHtml("lbPayRollExtrPayRollHeader",header);var totals=span("Trabalhadores: "+payroll.totalemployee.bold())+span("Líquido: "+formatNumber(payroll.totalliquid).bold())+span("Ilíquido: "+formatNumber(payroll.totalallowance).bold())+span("Segurança Social (3%): "+formatNumber(payroll.totalssemployee).bold())+span("Segurança Social (8%): "+formatNumber(payroll.totalsscompamy).bold())+span("IRT: "+formatNumber(payroll.totalirt).bold());setElementInnerHtml("lbPayRollExtrPayRollTotals",totals);setElementInnerHtml("lbPayRollExtrPayRollReference",(payroll.referenceyear+"/"+monthName(Number(payroll.referencemonth)-1).toUpperCase()))}
function _set_payroll_header(aList){let tblHeader=document.getElementById("trPayRollExtrHeader");tblHeader.innerHTML="";let cellHRow=createElement("th");cellHRow.innerHTML="#";tblHeader.appendChild(cellHRow);let cellHAgent=createElement("th");cellHAgent.innerHTML="Nº de agente";tblHeader.appendChild(cellHAgent);let cellHName=createElement("th","","headcol");cellHName.innerHTML="Nome completo";tblHeader.appendChild(cellHName);let cellHCat=createElement("th");cellHCat.innerHTML="Categoria / função";tblHeader.appendChild(cellHCat);if(FILTER.listType==1){let cellHAcc=createElement("th");cellHAcc.innerHTML="Conta bancária";tblHeader.appendChild(cellHAcc);let cellHIban=createElement("th");cellHIban.innerHTML="IBAN";tblHeader.appendChild(cellHIban);let cellHTotal=createElement("th");cellHTotal.innerHTML="SALÁRIO LÍQUIDO";tblHeader.appendChild(cellHTotal)}else{if(FILTER.listType==3){let cellHIRTGr=createElement("th");cellHIRTGr.innerHTML="Grupo";tblHeader.appendChild(cellHIRTGr)}
let cellHSalBase=createElement("th");cellHSalBase.innerHTML="SALÁRIO BASE";tblHeader.appendChild(cellHSalBase);if(PAYROLL_DETAILS.extratimeamount!=0){let cellHExtra=createElement("th","","column-optional");cellHExtra.innerHTML="Horas extras";tblHeader.appendChild(cellHExtra)}
if(PAYROLL_DETAILS.vacationallowance!=0){let cellHVac=createElement("th","","column-optional");cellHVac.innerHTML="FÉRIAS";tblHeader.appendChild(cellHVac)}
for(var i=0;i<aList.length;i++){let allowance=JSON.parse(aList[i]);ALLOWANCE_LIST[i]=allowance;let cellH=createElement("th","","column-optional");cellH.innerHTML=allowance.allowance;tblHeader.appendChild(cellH)}
if((FILTER.listType==2)||(PAYROLL_DETAILS.deducessonirt==1)){let cellHSS=createElement("th");cellHSS.innerHTML="S. SOCIAL (3%)";tblHeader.appendChild(cellHSS)}
if(FILTER.listType==2){let cellHSS8=createElement("th");cellHSS8.innerHTML="S. SOCIAL (8%)";tblHeader.appendChild(cellHSS8);let cellHSS11=createElement("th");cellHSS11.innerHTML="S. SOCIAL (11%)";tblHeader.appendChild(cellHSS11)}else{let cellHIRT=createElement("th");cellHIRT.innerHTML="IRT";tblHeader.appendChild(cellHIRT)}}
tblHeader.setAttribute("option-print",0);setPrintTableOption()}}
function payrollIRTReportOnLoad(){showNotification();setPageTitleWhoCall("4205","PAYROLIRTREP","Relatório do IRT");function cdoLoad(){fillSelectDependencyFull("selPayRolIRTRepDependency",-1,1);fillSelectIRTGroup("selPayRolIRTRepIRTGroup",-1);fillSelectNationalBank("selPayRolIRTRepBank",-1);fillSelectWorkschedule("selPayRolIRTRepWorkschedule",-1);fillSelectCountry("selPayRolIRTRepCountry",-1);fillSelectDepartment("selPayRolIRTRepDepartment",-1);fillSelectEmployeeCategory("selPayRolIRTRepEmployeeCategory",-1);var toChange=["txtPayRolIRTRepYear","selPayRolIRTRepIRTGroup","selPayRolIRTRepBank","selPayRolIRTRepWorkschedule","selPayRolIRTRepCountry","selPayRolIRTRepDepartment","selPayRolIRTRepEmployeeCategory"];Array.from(toChange).forEach(ids=>{try{document.getElementById(ids).addEventListener('change',()=>{cleanElement("tblPayRolIRTRepMainTable")})}catch(e){}});setElementValue("txtPayRolIRTRepYear",new Date().getFullYear()-1);hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function payrollIRTReportList(startIdx=0,transpExempt=0,transpSubj=0,transpRend=0,transpIRT=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=getElementValue("selPayRolIRTRepDependency");FILTER.year=getElementValue("txtPayRolIRTRepYear");FILTER.irtgroup=getElementValue("selPayRolIRTRepIRTGroup");FILTER.nationalBank=getElementValue("selPayRolIRTRepBank");FILTER.workscheduleId=getElementValue("selPayRolIRTRepWorkschedule");FILTER.nationality=getElementValue("selPayRolIRTRepCountry");FILTER.categoryId=getElementValue("selPayRolIRTRepEmployeeCategory");FILTER.departmentId=getElementValue("selPayRolIRTRepDepartment");FILTER.startIdx=startIdx;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
let tableRef=document.getElementById("tblPayRolIRTRepMainTable");var totalExempt=transpExempt;var totalSubject=transpSubj;var totalRend=transpRend;var totalIRT=transpIRT;if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowPayRollIRTRepAddMore");removeElement("rowPayRollIRTRepTotal")}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollIRTReportList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);tableRef.innerHTML+=strFilterResult(response);setElementInnerHtml("lbResultOnList",FILTER.startIdx+response.length);hideDivFilter();var nRows=startIdx;for(var i=0;i<response.length;i++){let employee=JSON.parse(response[i]);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("class","borderGray");let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellCod=createTableCell(newRow,employee.employeeid,"colProductId","Código");let cellAgent=createTableCell(newRow,leadingZero(employee.agentnumberreal,4),"colProductId","Nº de agente");let cellName=createTableCell(newRow,employee.employeename,"col-width-150 headcol");let cellAddres=createTableCell(newRow,employee.addresscurrent.toString().substring(0,20),"font-size-small","Morada");let cellTaxId=createTableCell(newRow,employee.documentnnumber,"","NIF/SS");let cellIRTGr=createTableCell(newRow,employee.irtgroup,"text-align-center","Grupo IRT");totalExempt+=Number(employee.exempt);let cellExmp=createTableCell(newRow,formatNumber(employee.exempt),"colAmount","Rendimento Isento");let cellNotSub=createTableCell(newRow,formatNumber(0),"colAmount","Não Sujeito");totalSubject+=Number(employee.subject);let cellSub=createTableCell(newRow,formatNumber(employee.subject),"colAmount","Rendimento Sujeito");var rend=Number(employee.subject)+Number(employee.exempt)
totalRend+=rend;let cellRend=createTableCell(newRow,formatNumber(rend),"colAmount","Subtotal rendimentos");totalIRT+=Number(employee.irtamount);let cellIRT=createTableCell(newRow,formatNumber(employee.irtamount),"colAmount","IRT Pago")}
let newRow=tableRef.insertRow(-1);newRow.id="rowPayRollIRTRepTotal";newRow.setAttribute("class","borderGray font-size-large font-weight-bold");let cellRow=createTableCell(newRow,"");let cellCod=createTableCell(newRow,"");let cellAgent=createTableCell(newRow,"");let cellName=createTableCell(newRow,"TOTAL");let cellAddr=createTableCell(newRow,"");let cellTax=createTableCell(newRow,"");let cellGr=createTableCell(newRow,"");let cellExempt=createTableCell(newRow,formatNumber(totalExempt),"colAmount");let cellNot=createTableCell(newRow,formatNumber(0),"colAmount");let cellSub=createTableCell(newRow,formatNumber(totalSubject),"colAmount");let cellRend=createTableCell(newRow,formatNumber(totalRend),"colAmount","Subtotal rendimentos");let cellIRT=createTableCell(newRow,formatNumber(totalIRT),"colAmount");if(response.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowPayRollIRTRepAddMore";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(){payrollIRTReportList(FILTER.startIdx+FILTER.pageItems,totalExempt,totalSubject,totalRend,totalIRT)}}
hideNotification()}};http.send(params)}
function payrollSSReportOnLoad(){showNotification();setPageTitleWhoCall("4205","PAYROLSSREP","Relatório de controbuição a segurança social");function cdoLoad(){fillSelectDependencyFull("selPayRolSSRepDependency",-1,1);fillSelectNationalBank("selPayRolSSRepBank",-1);fillSelectWorkschedule("selPayRolSSRepWorkschedule",-1);fillSelectCountry("selPayRolSSRepCountry",-1);fillSelectDepartment("selPayRolSSRepDepartment",-1);fillSelectEmployeeCategory("selPayRolSSRepEmployeeCategory",-1);var toChange=["txtPayRolSSRepYear","selPayRolSSRepIRTGroup","selPayRolSSRepBank","selPayRolSSRepWorkschedule","selPayRolSSRepCountry","selPayRolSSRepDepartment","selPayRolSSRepEmployeeCategory"];Array.from(toChange).forEach(ids=>{try{document.getElementById(ids).addEventListener('change',()=>{cleanElement("tblPayRolSSRepMainTable")})}catch(e){}});setElementValue("txtPayRolSSRepYear",new Date().getFullYear()-1);hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function payrollSSReportList(startIdx=0,transpRend=0,transSS3=0,transpSS8=0,transpSS11=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=getElementValue("selPayRolSSRepDependency");FILTER.year=getElementValue("txtPayRolSSRepYear");FILTER.nationalBank=getElementValue("selPayRolSSRepBank");FILTER.workscheduleId=getElementValue("selPayRolSSRepWorkschedule");FILTER.nationality=getElementValue("selPayRolSSRepCountry");FILTER.categoryId=getElementValue("selPayRolSSRepEmployeeCategory");FILTER.departmentId=getElementValue("selPayRolSSRepDepartment");FILTER.startIdx=startIdx;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
var tableRef=document.getElementById("tblPayRolSSRepMainTable");var totalRend=transpRend;var totalSS3=transSS3;var totalSS8=transpSS8;var totalSS11=transpSS11;if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowPayRollSocContAddMore");removeElement("rowPayRollSocContTotal")}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollSSReportList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);tableRef.innerHTML+=strFilterResult(response);setElementInnerHtml("lbResultOnList",FILTER.startIdx+response.length);hideDivFilter();var nRows=startIdx;for(var i=0;i<response.length;i++){let employee=JSON.parse(response[i]);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("class","borderGray");let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellCod=createTableCell(newRow,employee.employeeid,"colProductId","Código");let cellAgent=createTableCell(newRow,leadingZero(employee.agentnumberreal,4),"colProductId","Nº de agente");let cellName=createTableCell(newRow,employee.employeename,"col-width-150");let cellAddres=createTableCell(newRow,employee.addresscurrent.toString().substring(0,20),"font-size-small","Morada");let cellTaxId=createTableCell(newRow,employee.documentnnumber,"","NIF/SS");totalRend+=Number(employee.ssbase);let cellRend=createTableCell(newRow,formatNumber(employee.ssbase),"colAmount","Rendimentos");var ss3=Number(employee.ssamount);totalSS3+=ss3;let cellExmp=createTableCell(newRow,formatNumber(ss3),"colAmount","Contribuição do trabalhador (3%)");var ss8=(ss3/3)*8;totalSS8+=ss8;let cellNotSub=createTableCell(newRow,formatNumber(ss8),"colAmount","Contribuição da empresa (8%)");var ss11=(ss3/3)*11;totalSS11+=ss11;let cellSub=createTableCell(newRow,formatNumber(ss11),"colAmount","Subtotal")}
let newRow=tableRef.insertRow(-1);newRow.id="rowPayRollSocContTotal";newRow.setAttribute("class","borderGray font-size-large font-weight-bold");let cellRow=createTableCell(newRow,"");let cellCod=createTableCell(newRow,"");let cellAgent=createTableCell(newRow,"");let cellName=createTableCell(newRow,"TOTAL");let cellAddr=createTableCell(newRow,"");let cellTax=createTableCell(newRow,"");let cellRend=createTableCell(newRow,formatNumber(totalRend),"colAmount");let cellSS3=createTableCell(newRow,formatNumber(totalSS3),"colAmount");let cellSS8=createTableCell(newRow,formatNumber(totalSS8),"colAmount");let cellSS11=createTableCell(newRow,formatNumber(totalSS11),"colAmount");if(response.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowPayRollSocContAddMore";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(){payrollSSReportList(FILTER.startIdx+FILTER.pageItems,totalRend,totalSS3,totalSS8,totalSS11)}}
hideNotification()}};http.send(params)}
function payrollReceiptListOnLoad(){showNotification();setPageTitleWhoCall("4204","PAYROLRECLIST","Recibos de vencimento");function cdoLoad(){fillSelectDependencyFull("selPayRollRecListDependency",-1,1);fillSelectNationalBank("selPayRollRecListBank",-1);fillSelectWorkschedule("selPayRollRecListWorkschedule",-1);fillSelectCountry("selPayRollRecListCountry",-1);fillSelectDepartment("selPayRollRecListDepartment",-1);fillSelectEmployeeCategory("selPayRollRecListEmployeeCategory",-1);var toChange=["selPayRollRecListListType","selPayRollRecListBank","selPayRollRecListWorkschedule","selPayRollRecListCountry","selPayRollRecListDepartment","selPayRollRecListEmployeeCategory"];Array.from(toChange).forEach(ids=>{try{document.getElementById(ids).addEventListener('change',()=>{cleanElement("tblPayRollRecListMainTable")})}catch(e){}});employeeSearchOnLoad();payrollRegisterOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function payrollReceiptListSelectSheet(payroll){if(payroll.payrollstatus!=2){showNotification("Deve seleccionar uma folha de salário bloqueada",0);return!1}
setElementValue("txtPayRollRecListPayrollId",payroll.payrollid,0);payrollReceiptList()}
var PAYROLL_RECEIPT_EMPLOYEE_LIST=[];function payrollReceiptList(employeeId=-1,startIdx=0,transpAllo=0,transpDesco=0,transpLiqu=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=getElementValue("selPayRollRecListDependency");FILTER.employeeId=employeeId;FILTER.payrollId=getElementValue("txtPayRollRecListPayrollId");FILTER.nationalBank=getElementValue("selPayRollRecListBank");FILTER.workscheduleId=getElementValue("selPayRollRecListWorkschedule");FILTER.nationality=getElementValue("selPayRollRecListCountry");FILTER.categoryId=getElementValue("selPayRollRecListEmployeeCategory");FILTER.departmentId=getElementValue("selPayRollRecListDepartment");FILTER.startIdx=startIdx;if((FILTER.payrollId=="")||(FILTER.payrollId==null)||(isNaN(FILTER.payrollId))){showNotification("Deve seleccionar uma folha de salário",0);return!1}
if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
let tableRef=document.getElementById("tblPayRollRecListMainTable");var totalAllwance=transpAllo;var totalDescount=transpDesco;var totalLiquid=transpLiqu;if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowPayRollRecListAddMore");removeElement("rowPayRollRecListTotal")}
ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollReceiptList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);hideDivFilter();var pResponse=JSON.parse(response.p);sessionStorage.setItem("SRH_PAYROLL_RECEIPT_PAYROLL_DETAIL",response.p);_set_payroll_detail(pResponse);sessionStorage.setItem("SRH_PAYROLL_RECEIPT_ALLOWANCE_LIST",JSON.stringify(response.a));var eResponse=response.e;_set_payroll_employees(eResponse,pResponse.payrollstatus);hideNotification()}};http.send(params);function _set_payroll_employees(employees){var totalItems=employees.length;if(totalItems<=0){showNotification('Sem resultado para os critérios indicados.',0)}
setElementInnerHtml('lbResultOnList',FILTER.startIdx+employees.length);function result(){PAYROLL_RECEIPT_EMPLOYEE_LIST=[];var nRows=startIdx;for(var i=0;i<employees.length;i++){let employee=JSON.parse(employees[i]);PAYROLL_RECEIPT_EMPLOYEE_LIST.push(employee);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowPayRollRecList"+employee.id);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_PAYROLL_RECEIPT_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,employee.employeeid,"font-size-small");let cellAgent=createTableCell(newRow,leadingZero(employee.agentnumberreal,4),"font-size-small");let cellName=createTableCell(newRow,employee.employeename,"col-width-150");let cellCategory=createTableCell(newRow,employee.category,"font-size-small");let cellDepart=createTableCell(newRow,employee.department,"font-size-small");let cellAccount=createTableCell(newRow,employee.account,"font-size-small");var allowance=Number(employee.totalallowance);totalAllwance+=allowance;let cellSS8=createTableCell(newRow,formatNumber(allowance),"colAmount");var descount=Number(employee.totaldescount);totalDescount+=descount;let cellSS11=createTableCell(newRow,formatNumber(descount),"colAmount font-weight-bold");totalLiquid+=Number(employee.totalliquid);let cellLiqu=createTableCell(newRow,formatNumber(employee.totalliquid),"font-weight-bold colAmount");let cellEdit=createTableCell(newRow,"","noPrint text-align-center","...");let btPrint=document.createElement("button");btPrint.setAttribute("class","labelPrint");btPrint.type="button";btPrint.name=allowance.allowanceid;btPrint.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_RECEIPT_LIST");var EMPLOYEE_LIST=[];EMPLOYEE_LIST.push(employee);sessionStorage.setItem("SRH_PAYROLL_RECEIPT_EMPLOYEE_LIST",JSON.stringify(EMPLOYEE_LIST));var url="../_print/PayrollReceipt";if(getDesktopStatus()){location.assign(url)}else{window.open(url)}
payrollAllowanceDetail(btPrint.name)};cellEdit.appendChild(btPrint)}
let newRow=tableRef.insertRow(-1);newRow.id="rowPayRollRecListTotal";newRow.setAttribute("class","borderGray font-size-large font-weight-bold");let cellRow=createTableCell(newRow,"");let cellCod=createTableCell(newRow,"");let cellAgent=createTableCell(newRow,"");let cellName=createTableCell(newRow,"TOTAL");let cellCategory=createTableCell(newRow,"");let cellDepart=createTableCell(newRow,"");let cellAccount=createTableCell(newRow,"");let cellAllowa=createTableCell(newRow,formatNumber(totalAllwance),"colAmount");let cellDesco=createTableCell(newRow,formatNumber(totalDescount),"colAmount");let cellLiqu=createTableCell(newRow,formatNumber(totalLiquid),"colAmount");if(employees.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowPayRollRecListAddMore";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(){payrollReceiptList(employeeId,FILTER.startIdx+FILTER.pageItems,totalAllwance,totalDescount,totalLiquid)}}}
result()}
function _set_payroll_detail(payroll){PAYROLL_DETAILS=payroll;const span=(content)=>'<span style="white-space: nowrap; margin-left: 10px;">'+content+'</span>';var header=span("Folha: "+(payroll.referenceyear+"/"+monthName(Number(payroll.referencemonth)-1).toUpperCase()).bold())+span("Estado: "+payrollSetPayrollStatus(payroll.payrollstatus).bold())+span("Abertura: "+setLocalDate(payroll.startdate,10).bold())+span("Fecho: "+setLocalDate(payroll.enddate,10).bold());setElementInnerHtml("lbPayRollRecListPayRollHeader",header);var totals=span("Trabalhadores: "+payroll.totalemployee.bold())+span("Líquido: "+formatNumber(payroll.totalliquid).bold())+span("Ilíquido: "+formatNumber(payroll.totalallowance).bold())+span("Segurança Social (3%): "+formatNumber(payroll.totalssemployee).bold())+span("Segurança Social (8%): "+formatNumber(payroll.totalsscompamy).bold())+span("IRT: "+formatNumber(payroll.totalirt).bold());setElementInnerHtml("lbPayRollRecListPayRollTotals",totals)}}
function payrollReceiptListPrintFullList(){var payrollId=getElementValue("txtPayRollRecListPayrollId");if((payrollId=="")||(payrollId==null)||(isNaN(payrollId))){showNotification("Deve seleccionar uma folha de salário",0);return!1}
if(PAYROLL_RECEIPT_EMPLOYEE_LIST.length<=0){showNotification("Lista de trabalhadores vazia.",0);return!1}
sessionStorage.setItem("SRH_PAYROLL_RECEIPT_EMPLOYEE_LIST",JSON.stringify(PAYROLL_RECEIPT_EMPLOYEE_LIST));var url="../_print/PayrollReceipt";if(getDesktopStatus()){location.assign(url)}else{window.open(url)}}
var PAYROLL_LENDING_NEW_ASSIGN=0;function payrollLendingListOnLoad(){showNotification();setPageTitleWhoCall("4206-4207-4208","PAYROLLENDLIS","Lista de empréstimos imediatos");function cdoLoad(){var date=new Date();setElementValue("txtPayRolLendListInitialDate",setLocalDate(new Date(date.getFullYear(),date.getMonth(),1),10));setElementValue("txtPayRolLendListEndDate",setLocalDate(new Date(),10));setTriggerButtonByText('txtPayRolLendListInitialDate','btPayRolLendListViewAll');setTriggerButtonByText('txtPayRolLendListEndDate','btPayRolLendListViewAll');fillSelectDependencyFull("selPayRolLendListDependency",-1,1);fillSelectSex("selPayRolLendListSex",-1);fillSelectWorkschedule("selPayRolLendListWorkschedule",-1);fillSelectCountry("selPayRolLendListCountry",-1);fillSelectDepartment("selPayRolLendListDepartment",-1);fillSelectEmployeeCategory("selPayRolLendListEmployeeCategory",-1);fillSelectWorkscheduleAplicationType("selEmpWorSchRegAplicationType",1,0);setElementValue("txtPayRolLendListYear",new Date().getFullYear());setTriggerButtonByText('txtPayRolLendListYear','btPayRolLendListViewAll');setTriggerButtonByText('txtPayRolLendListMonth','btPayRolLendListViewAll');if(!checkPermission("4002")){removeElement("btPayRolLendListNewEmployee");removeElement("divEmployeeRegister")}
if(!checkPermission("4207")){removeElement("btPayRolLendListLendingNew");removeElement("divPayRollLendinRegister")}
if(!checkPermission("4208")){removeElement("btPayRolAdvRegAprove");removeElement("btPayRolAdvRegCancel")}
PAYROLL_LENDING_NEW_ASSIGN=0;employeeSearchOnLoad();employeeRegisterOnLoad();payrollLendingRegisterOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function payrollLendingRegisterOnLoad(){if(!setOnloadStatus("divPayRollLendinRegister",payrollLendingRegisterOnLoad)){return!1}
fillSelectMonth("selPayRolLendRegRefoundMonth");fillSelectAdvanceStatus("selPayRolLendRegLendingStatus");var elements=[document.getElementById("txtPayRolLendRegAmount"),document.getElementById("txtPayRolLendRegDate"),document.getElementById("txtPayRolLendRegRefoundYear"),document.getElementById("selPayRolLendRegRefoundMonth")];Array.from(elements).forEach(elem=>{elem.onchange=function(){payrollLendingRegisterOnChange()}})}
function payrollLendingRegisterOnChange(){var status=getElementValue("selPayRolLendRegLendingStatus");if(status!=1){return!1}
var amount=Number(getElementValue("txtPayRolLendRegAmount"));var lastYear=Number(getElementValue("txtPayRolLendRegRefoundYear"));var lastMonth=Number(getElementValue("selPayRolLendRegRefoundMonth"));var lendingDate=new Date(getElementValue("txtPayRolLendRegDate"));var refoundDate=new Date(lastYear,lastMonth-1,1);if(amount<=0){showNotification("Valor do empréstimo deve ser superior a zero",0)}}
function payrollLendingNew(employee){payrollLendingDetails(employee)}
function payrollLendingDetails(employee,lendingId=-1){showParts("divPayRollLendinRegister");const lbHeader=document.getElementById("h2PayRolLendRegHeader");const txtEmployeeId=document.getElementById("txtPayRolLendRegEmployeeId");const txtEmployeeName=document.getElementById("txtPayRolLendRegEmployeeName");const txtLendingId=document.getElementById("txtPayRolLendRegLendingId");const txtAmount=document.getElementById("txtPayRolLendRegAmount");const txtLendingDate=document.getElementById("txtPayRolLendRegDate");const txtRefoundYear=document.getElementById("txtPayRolLendRegRefoundYear");const selRefoundMonth=document.getElementById("selPayRolLendRegRefoundMonth");const selStatus=document.getElementById("selPayRolLendRegLendingStatus");const lbUpdate=document.getElementById("lbPayRolLendRegUpdate");hideParts("btPayRolLendRegSave");hideParts("btPayRolLendRegAprove");hideParts("btPayRolLendRegCancel");disabledElement(txtAmount.id);disabledElement(txtLendingDate.id);disabledElement(txtRefoundYear.id);disabledElement(selRefoundMonth.id);if(lendingId==-1){lbHeader.innerHTML="Novo empréstimo";txtEmployeeId.value=employee.employeeid;txtEmployeeName.value=employee.employeename;txtLendingId.value="Novo empréstimo *";txtAmount.value=0;txtLendingDate.value=setLocalDate(new Date(),10);var year=new Date().getFullYear();var month=new Date().getMonth()+2;if(month==12){year+=1;month=1}
txtRefoundYear.value=year;selRefoundMonth.value=month;selStatus.value=1;lbUpdate.innerHTML="Actualizado em "+setLocalDate(new Date(),16);showParts("btPayRolLendRegSave",!0);showParts("btPayRolLendRegAprove",!0);enabledElement(txtAmount.id);enabledElement(txtLendingDate.id);enabledElement(txtRefoundYear.id);enabledElement(selRefoundMonth.id)}else{lbHeader.innerHTML="Dados do adiantamento de salário";if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=-1;FILTER.lendingId=lendingId;FILTER.employeeId=-1;FILTER.initialDate=-1;FILTER.endDate=-1;FILTER.sex="";FILTER.nationality=-1;FILTER.departmentId=-1;FILTER.categoryId=-1;var http=new XMLHttpRequest();var params="action=getPayrollLendingList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);let advance=JSON.parse(response[0]);var status=advance.lendingstatus;txtEmployeeId.value=advance.employeeid;txtEmployeeName.value=advance.employeename;txtLendingId.value=advance.lendingid;txtAmount.value=Number(advance.amount).toFixed(2);txtLendingDate.value=setLocalDate(advance.lendingdate,10);txtRefoundYear.value=advance.refoundyear;selRefoundMonth.value=advance.refoundmonth;selStatus.value=status;lbUpdate.innerHTML="Cadastrado por "+getOperatorName(advance.operatorEntry,advance.entryuser)+" em "+setLocalDate(advance.entrydate,16)+". <br>"+"Actualizado por "+getOperatorName(advance.operatorName,advance.statususer)+" em "+setLocalDate(advance.statusdate,16);if(status==1){showParts("btPayRolLendRegSave",!0);showParts("btPayRolLendRegAprove",!0);showParts("btPayRolLendRegCancel",!0);enabledElement(txtAmount.id);enabledElement(txtLendingDate.id);enabledElement(txtRefoundYear.id);enabledElement(selRefoundMonth.id)}else if(status!=6){showParts("btPayRolLendRegCancel",!0)}}};http.send(params)}}
function payrollLendingRegisterSave(nextStatus=-1){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.employeeId=getElementValue("txtPayRolLendRegEmployeeId");FILTER.lendingid=getElementValue("txtPayRolLendRegLendingId");FILTER.amount=Number(getElementValue("txtPayRolLendRegAmount"));FILTER.lendingdate=getElementValue("txtPayRolLendRegDate");FILTER.refoundyear=Number(getElementValue("txtPayRolLendRegRefoundYear"));FILTER.refoundmonth=Number(getElementValue("selPayRolLendRegRefoundMonth"));FILTER.lendingstatus=nextStatus;var mandatoryField=!1;var msg="";if(FILTER.amount<=0){mandatoryField=!0;msg+="Valor do empréstimo de ser superior a zero. <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=savePayrollLending"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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("divPayRollLendinRegister");if(ST_SRH_MAIN_WHO_CALL=="PAYROLLENDLIS"){payrollLendingList(FILTER.employeeId)}}else{showNotification(result.msg,0)}}};http.send(params)}
function payrollLendingList(employeeId=-1,startIdx=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=getElementValue("selPayRolLendListDependency");FILTER.lendingId=-1;FILTER.employeeId=employeeId;FILTER.initialDate=getElementValue('txtPayRolLendListInitialDate');FILTER.endDate=getElementValue('txtPayRolLendListEndDate');FILTER.sex=getElementValue("selPayRolLendListSex");FILTER.nationality=getElementValue("selPayRolLendListCountry");FILTER.departmentId=getElementValue("selPayRolLendListDepartment");FILTER.categoryId=getElementValue("selPayRolLendListEmployeeCategory");FILTER.startIdx=startIdx;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
let tableRef=document.getElementById("tblPayRolLendListMainTable");if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rtrPayRolLendListRowAddMore")}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollLendingList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);var totalItems=response.length;if(totalItems>0){hideDivFilter()}
setElementInnerHtml('lbResultOnList',FILTER.startIdx+response.length);function result(){tableRef.innerHTML+=strFilterResult(response);var nRows=startIdx;for(var i=0;i<response.length;i++){let advance=JSON.parse(response[i]);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","trPayRolLendListRow"+advance.advanceid);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_PAYROLL_LENDING_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,advance.employeeid,"colProductId","Código");let cellAgent=createTableCell(newRow,leadingZero(advance.agentnumberreal,4),"colProductId","Nº de agente");let cellName=createTableCell(newRow,advance.employeename,"col-width-150","Nome completo");let cellAmount=createTableCell(newRow,formatNumber(advance.amount),"font-weight-bold colAmount","Valor Adiantado");let cellDate=createTableCell(newRow,setLocalDate(advance.lendingdate,10),"colNoWrap","Data do empréstimo");let cellEnd=createTableCell(newRow,advance.refoundyear+"/"+monthName(Number(advance.refoundmonth)-1),"colProductId","Previsão de pagamento");var proveBy=(Number(advance.lendingstatus)>=2)?getFirtLastName(advance.aproveName)+" ("+advance.aproveuser+")":"";let cellAprov=createTableCell(newRow,proveBy,"colProductId","Aprovado por");var status=advance.lendingstatus;var bgc=(status==1)?"background-color-green-light":(status==6)?"background-color-brown":(status==5)?"background-color-maroon":"background-color-green";let cellStatus=createTableCell(newRow,payrollSetAdvanceStatus(status),"colProductId "+bgc,"Estado");let cellUpdate=createTableCell(newRow,setLocalDate(advance.statusdate,16),"colProductId","Última actualização");let cellOper=createTableCell(newRow,getFirtLastName(advance.operatorName)+" ("+advance.statususer+")","colProductId","Operador");let cellAction=createTableCell(newRow,"","noPrint text-align-center","...");let btEdit=document.createElement("button");btEdit.setAttribute("class","labelEdit");btEdit.type="button";btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_ADVANCE_LIST");payrollLendingDetails(null,advance.lendingid)};cellAction.appendChild(btEdit);if(checkPermission("4002")){let btEdit=createElement("button","button","labelCustomer");btEdit.innerHTML="Trabalhador";btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_LENDING_LIST");employeeRegisterDetail(advance.employeeid)};cellAction.appendChild(btEdit)}}
if(response.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rtrPayRolLendListRowAddMore";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(){payrollLendingList(employeeId,FILTER.startIdx+FILTER.pageItems)}}
hideNotification()}
result()}};http.send(params)}
function payrollEmployeeSalaryOnLoad(){showNotification();setPageTitleWhoCall("4201-4202","PAYROLEMPSAL","Trabalhador e salário");function cdoLoad(){var today=new Date();setElementValue("txtPayRolEmpSalYear",today.getFullYear());fillSelectMonth("txtPayRolEmpSalMonth",1,today.getMonth()+1);fillSelectDependencyFull("selPayRolEmpSalDependency",-1,1);fillSelectCountry("selPayRolEmpSalCountry",-1);fillSelectDepartment("selPayRolEmpSalDepartment",-1);fillSelectEmployeeCategory("selPayRolEmpSalEmployeeCategory",-1);employeeSearchOnLoad();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function payrollEmployeeSalaryList(employeeId=-1,startIdx=0,transpTBase=0,transpTAllow=0,transpAllowList=[]){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=getElementValue("selPayRolEmpSalDependency");FILTER.employeeId=employeeId;FILTER.departmentId=getElementValue("selPayRolEmpSalDepartment");FILTER.categoryId=getElementValue("selPayRolEmpSalEmployeeCategory");var month=Number(getElementValue("txtPayRolEmpSalMonth"))-1;FILTER.startdate=setLocalDate(new Date(getElementValue("txtPayRolEmpSalYear"),month,1),10);FILTER.startIdx=startIdx;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
var tableRef=document.getElementById("tblPayRolEmpSalMainTable");var totalBase=transpTBase;var totalAllowance=transpTAllow;if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowEmpPayRollAddMore");removeElement("rowEmpPayRollTotal")}
var ALLOWANCE_LIST=[];ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollEmployeeSalaryList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);var aResponse=response.a;_set_payroll_header(aResponse);var eResponse=response.e;_set_payroll_employees(eResponse);hideNotification()}};http.send(params);function _set_payroll_employees(employees){var totalItems=employees.length;if(totalItems<=0){showNotification('Não foram encontrados trabalhadores para esta folha de salário.',0)}
setElementInnerHtml('lbResultOnList',FILTER.startIdx+employees.length);function result(){var nRows=startIdx;for(var i=0;i<ALLOWANCE_LIST.length;i++){let allowance=ALLOWANCE_LIST[i];allowance.total=0;transpAllowList.forEach(tranAll=>{if(tranAll.allowanceid==allowance.allowanceid){allowance.total=tranAll.total}})}
for(var i=0;i<employees.length;i++){let employee=JSON.parse(employees[i]);let salBase=Number(employee.salarybase);totalBase+=salBase;nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowPayRollEMpSalListEmp"+employee.employeeid);newRow.setAttribute("title",nRows+" / "+employee.employeeid+" / "+employee.employeename);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_PAYROLL_EMP_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,employee.employeeid,"colProductId column-optional","Código");let cellAgent=createTableCell(newRow,leadingZero(employee.agentnumberreal,4),"colProductId","Nº de agente");let cellName=createTableCell(newRow,employee.employeename,"col-width-150 headcol");let cellCategory=createTableCell(newRow,employee.category,"font-size-small");let cellDepart=createTableCell(newRow,employee.department,"column-optional font-size-small");let cellSalBase=createTableCell(newRow,formatNumber(salBase),"font-weight-bold colAmount background-color-green-light");var tAllo=0;for(var x=0;x<ALLOWANCE_LIST.length;x++){let allow=ALLOWANCE_LIST[x];var allowId=allow.allowanceid;var alloType=allow.allowancetype;var allowValue=Number(employee['amount'+allowId])+(Number(employee['percent'+allowId])*salBase)/100;if(alloType=="A"){ALLOWANCE_LIST[x].total+=allowValue;tAllo+=allowValue;let cellAllow=createTableCell(newRow,formatNumber(allowValue),"column-optional colAmount")}}
totalAllowance+=tAllo+salBase;let cellSTAllo=createTableCell(newRow,formatNumber(tAllo+salBase),"font-weight-bold colAmount background-color-green-light")}
let newRow=tableRef.insertRow(-1);newRow.id="rowEmpPayRollTotal";newRow.setAttribute("class","borderGray font-size-large font-weight-bold");let cellRow=createTableCell(newRow,"");let cellId=createTableCell(newRow,"","column-optional");let cellAgent=createTableCell(newRow,"");let cellName=createTableCell(newRow,"TOTAL");let cellCategory=createTableCell(newRow,"");let cellDepart=createTableCell(newRow,"","column-optional");let cellSalBase=createTableCell(newRow,formatNumber(totalBase),"colAmount background-color-green-light");for(var x=0;x<ALLOWANCE_LIST.length;x++){let allow=ALLOWANCE_LIST[x];var allowValue=allow.total;var alloType=allow.allowancetype;if(alloType=="A"){let cellAllow=createTableCell(newRow,formatNumber(allowValue),"column-optional colAmount")}}
let cellSTAllo=createTableCell(newRow,formatNumber(totalAllowance),"colAmount background-color-green-light");if(employees.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowEmpPayRollAddMore";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(){payrollEmployeeSalaryList(employeeId,FILTER.startIdx+FILTER.pageItems,totalBase,totalAllowance,ALLOWANCE_LIST)}}}
result()}
function _set_payroll_header(aList){let tblHeader=document.getElementById("trPayRolEmpSalHeader");tblHeader.innerHTML="";let cellHRow=createElement("th");cellHRow.innerHTML="#";tblHeader.appendChild(cellHRow);let cellHCod=createElement("th","","column-optional");cellHCod.innerHTML="Código";tblHeader.appendChild(cellHCod);let cellHAgent=createElement("th");cellHAgent.innerHTML="Nº de agente";tblHeader.appendChild(cellHAgent);let cellHName=createElement("th","","headcol");cellHName.innerHTML="Nome completo";tblHeader.appendChild(cellHName);let cellHCat=createElement("th");cellHCat.innerHTML="Categoria / função";tblHeader.appendChild(cellHCat);let cellHDepart=createElement("th","","column-optional");cellHDepart.innerHTML="Posto de trabalho";tblHeader.appendChild(cellHDepart);let cellHSalBase=createElement("th","","background-color-green");cellHSalBase.innerHTML="SALÁRIO BASE";tblHeader.appendChild(cellHSalBase);for(var i=0;i<aList.length;i++){let allowance=(aList[i]);ALLOWANCE_LIST[i]=allowance;var alloType=allowance.allowancetype;if(alloType=="A"){let cellH=createElement("th","","column-optional background-color-green-light");cellH.innerHTML=allowance.allowance;tblHeader.appendChild(cellH);oldAlloType=alloType}}
let cellHSTAllo=createElement("th","","background-color-green");cellHSTAllo.innerHTML="SALÁRIO ILÍQUIDO";tblHeader.appendChild(cellHSTAllo);tblHeader.setAttribute("option-print",0);setPrintTableOption()}}
function myPayrollAdvanceListOnLoad(){showNotification();setPageTitleWhoCall("0000","PAYROLADVLIS","Meus adiantamentos de salário");function cdoLoad(){fillSelectMonth("txtPayRolAdvListMonth",-1);setElementValue("txtPayRolAdvListYear",new Date().getFullYear());setTriggerButtonByText('txtPayRolAdvListYear','btPayRolAdvListViewAll');setTriggerButtonByText('txtPayRolAdvListMonth','btPayRolAdvListViewAll');hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function myPayrollAdvanceList(startIdx=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=-1;FILTER.advanceId=-1;FILTER.employeeId=SYSTEM_USER_STATUS.employeeId;FILTER.year=getElementValue('txtPayRolAdvListYear');FILTER.month=getElementValue('txtPayRolAdvListMonth');FILTER.sex="";FILTER.nationality=-1;FILTER.departmentId=-1;FILTER.categoryId=-1;FILTER.startIdx=startIdx;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
let tableRef=document.getElementById("tblPayRolAdvListMainTable");if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rowPayRollAdvAddMore")}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollAdvanceList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);var totalItems=response.length;if(totalItems>0){hideDivFilter()}
setElementInnerHtml('lbResultOnList',FILTER.startIdx+response.length);function result(){tableRef.innerHTML+=strFilterResult(response);var nRows=startIdx;for(var i=0;i<response.length;i++){let advance=JSON.parse(response[i]);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","trPayRolAdvListRow"+advance.advanceid);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_PAYROLL_ADVANCE_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,advance.employeeid,"colProductId","Código");let cellAgent=createTableCell(newRow,leadingZero(advance.agentnumberreal,4),"colProductId","Nº de agente");let cellName=createTableCell(newRow,advance.employeename,"col-width-150 headcol","Nome completo");let cellAmount=createTableCell(newRow,formatNumber(advance.amount),"font-weight-bold colAmount","Valor Adiantado");let cellTax=createTableCell(newRow,formatNumber(advance.directtax),"text-align-center","Taxa directa (%)");let cellDate=createTableCell(newRow,advance.advanceyear+"/"+monthName(Number(advance.advancemonth)-1),"colProductId","Mês de embolso");let cellRefound=createTableCell(newRow,formatNumber(advance.refoundamount),"font-weight-bold colAmount","Valor a reembolsar");let cellInstalls=createTableCell(newRow,(advance.installments),"text-align-center","Prestações");let cellRefounded=createTableCell(newRow,formatNumber(advance.amountprocessed),"font-weight-bold colAmount","Valor reembolsadp");let cellInstallProcess=createTableCell(newRow,(advance.installProcessed),"text-align-center","Prestações pagas");let cellEnd=createTableCell(newRow,advance.endyear+"/"+monthName(Number(advance.endmonth)-1),"colProductId","Previsão término");var proveBy=(Number(advance.advancestatus)>=2)?getFirtLastName(advance.aproveName)+" ("+advance.aproveuser+")":"";let cellAprov=createTableCell(newRow,proveBy,"colProductId","Aprovado por");var status=payrollReviewAdvanceStatus(advance);var bgc=(status==1)?"background-color-green-light":(status==6)?"background-color-brown":(status==5)?"background-color-maroon":"background-color-green";let cellStatus=createTableCell(newRow,payrollSetAdvanceStatus(status),"colProductId "+bgc,"Estado");let cellUpdate=createTableCell(newRow,setLocalDate(advance.statusdate,16),"colProductId","Última actualização")}
if(response.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rowPayRollAdvAddMore";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(){myPayrollAdvanceList(FILTER.startIdx+FILTER.pageItems)}}
hideNotification()}
result()}};http.send(params)}
function myPayrollLendingListOnLoad(){showNotification();setPageTitleWhoCall("0000","PAYROLLENDLIS","Meus empréstimos");function cdoLoad(){var date=new Date();setElementValue("txtPayRolLendListInitialDate",setLocalDate(new Date(date.getFullYear(),date.getMonth(),1),10));setElementValue("txtPayRolLendListEndDate",setLocalDate(new Date(),10));setTriggerButtonByText('txtPayRolLendListInitialDate','btPayRolLendListViewAll');setTriggerButtonByText('txtPayRolLendListEndDate','btPayRolLendListViewAll');setElementValue("txtPayRolLendListYear",new Date().getFullYear());setTriggerButtonByText('txtPayRolLendListYear','btPayRolLendListViewAll');setTriggerButtonByText('txtPayRolLendListMonth','btPayRolLendListViewAll');myPayrollLendingList();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function myPayrollLendingList(startIdx=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=-1;FILTER.lendingId=-1;FILTER.employeeId=SYSTEM_USER_STATUS.employeeId;FILTER.initialDate=getElementValue('txtPayRolLendListInitialDate');FILTER.endDate=getElementValue('txtPayRolLendListEndDate');FILTER.sex="";FILTER.nationality=-1;FILTER.departmentId=-1;FILTER.categoryId=-1;FILTER.startIdx=startIdx;if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
let tableRef=document.getElementById("tblPayRolLendListMainTable");if(FILTER.startIdx==0){tableRef.innerHTML=""}else{removeElement("rtrPayRolLendListRowAddMore")}
showNotification();ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollLendingList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);var totalItems=response.length;if(totalItems>0){hideDivFilter()}
setElementInnerHtml('lbResultOnList',FILTER.startIdx+response.length);function result(){tableRef.innerHTML=strFilterResult(response);var nRows=startIdx;for(var i=0;i<response.length;i++){let advance=JSON.parse(response[i]);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","trPayRolLendListRow"+advance.advanceid);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_PAYROLL_LENDING_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,advance.employeeid,"colProductId","Código");let cellAgent=createTableCell(newRow,leadingZero(advance.agentnumberreal,4),"colProductId","Nº de agente");let cellName=createTableCell(newRow,advance.employeename,"col-width-150 headcol","Nome completo");let cellAmount=createTableCell(newRow,formatNumber(advance.amount),"font-weight-bold colAmount","Valor Adiantado");let cellDate=createTableCell(newRow,setLocalDate(advance.lendingdate,10),"colNoWrap","Data do empréstimo");let cellEnd=createTableCell(newRow,advance.refoundyear+"/"+monthName(Number(advance.refoundmonth)-1),"colProductId","Previsão de pagamento");var proveBy=(Number(advance.lendingstatus)>=2)?getFirtLastName(advance.aproveName)+" ("+advance.aproveuser+")":"";let cellAprov=createTableCell(newRow,proveBy,"colProductId","Aprovado por");var status=advance.lendingstatus;var bgc=(status==1)?"background-color-green-light":(status==6)?"background-color-brown":(status==5)?"background-color-maroon":"background-color-green";let cellStatus=createTableCell(newRow,payrollSetAdvanceStatus(status),"colProductId "+bgc,"Estado");let cellUpdate=createTableCell(newRow,setLocalDate(advance.statusdate,16),"colProductId","Última actualização")}
if(response.length>=FILTER.pageItems){let newRowC=tableRef.insertRow(-1);newRowC.id="rtrPayRolLendListRowAddMore";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(){myPayrollLendingList(FILTER.employeeId,FILTER.startIdx+FILTER.pageItems)}}
hideNotification()}
result()}};http.send(params)}
function myPayrollReceiptListOnLoad(){showNotification();setPageTitleWhoCall("0000","MYPAYROLRECLIST","Meus recibos de vencimento");function cdoLoad(){hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function myPayrollReceiptListSelectSheet(payroll){if(payroll.payrollstatus!=2){showNotification("Deve seleccionar uma folha de salário aprovada",0);return!1}
setElementValue("txtPayRollRecListPayrollId",payroll.payrollid,0);myPayrollReceiptList()}
function myPayrollReceiptList(startIdx=0){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.dependencyId=-1;FILTER.employeeId=SYSTEM_USER_STATUS.employeeId;FILTER.payrollId=getElementValue("txtPayRollRecListPayrollId");FILTER.nationalBank=-1;FILTER.workscheduleId=-1;FILTER.nationality=-1;FILTER.categoryId=-1;FILTER.departmentId=-1;if((FILTER.payrollId=="")||(FILTER.payrollId==null)||(isNaN(FILTER.payrollId))){showNotification("Deve seleccionar uma folha de salário",0);return!1}
if(ST_SRH_WAITING_SERVER==1){showNotification("Aguardando resposta do servidor. <br>",0);return!1}
ST_SRH_WAITING_SERVER=1;var http=new XMLHttpRequest();var params="action=getPayrollReceiptList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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);hideDivFilter();var pResponse=JSON.parse(response.p);sessionStorage.setItem("SRH_PAYROLL_RECEIPT_PAYROLL_DETAIL",response.p);sessionStorage.setItem("SRH_PAYROLL_RECEIPT_ALLOWANCE_LIST",JSON.stringify(response.a));var eResponse=response.e;_set_payroll_employees(eResponse,pResponse.payrollstatus);hideNotification()}};http.send(params);function _set_payroll_employees(employees){var totalItems=employees.length;if(totalItems<=0){showNotification('Sem resultado para os critérios indicados.',0)}
setElementInnerHtml('lbResultOnList',totalItems);function result(){PAYROLL_RECEIPT_EMPLOYEE_LIST=[];let tableRef=document.getElementById("tblPayRollRecListMainTable");tableRef.innerHTML="";var nRows=startIdx;var totalAllwance=0;var totalDescount=0;var totalLiquid=0;for(var i=0;i<employees.length;i++){let employee=JSON.parse(employees[i]);PAYROLL_RECEIPT_EMPLOYEE_LIST.push(employee);nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowPayRollRecList"+employee.id);newRow.setAttribute("class","borderGray"+setSelectedRowBackground("SELECTED_ROW_PAYROLL_RECEIPT_LIST",newRow.id));let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellId=createTableCell(newRow,employee.employeeid,"font-size-small");let cellAgent=createTableCell(newRow,leadingZero(employee.agentnumberreal,4),"font-size-small");let cellName=createTableCell(newRow,employee.employeename,"col-width-150");let cellCategory=createTableCell(newRow,employee.category,"font-size-small");let cellDepart=createTableCell(newRow,employee.department,"font-size-small");let cellAccount=createTableCell(newRow,employee.account,"font-size-small");var allowance=Number(employee.totalallowance);totalAllwance+=allowance;let cellSS8=createTableCell(newRow,formatNumber(allowance),"colAmount");var descount=Number(employee.totaldescount);totalDescount+=descount;let cellSS11=createTableCell(newRow,formatNumber(descount),"colAmount font-weight-bold");totalLiquid+=Number(employee.totalliquid);let cellLiqu=createTableCell(newRow,formatNumber(employee.totalliquid),"font-weight-bold colAmount");let cellEdit=createTableCell(newRow,"","noPrint text-align-center","...");let btPrint=document.createElement("button");btPrint.setAttribute("class","labelPrint");btPrint.type="button";btPrint.name=allowance.allowanceid;btPrint.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_PAYROLL_RECEIPT_LIST");var EMPLOYEE_LIST=[];EMPLOYEE_LIST.push(employee);sessionStorage.setItem("SRH_PAYROLL_RECEIPT_EMPLOYEE_LIST",JSON.stringify(EMPLOYEE_LIST));var url="../_print/PayrollReceipt";if(getDesktopStatus()){location.assign(url)}else{window.open(url)}
payrollAllowanceDetail(btPrint.name)};cellEdit.appendChild(btPrint)}}
result()}}
function payrollRegisterCancel(){if(!desktopSecurityCheck()){return!1}
function realDelete(){var FILTER=setFilterStatus();FILTER.payrollid=getElementValue("txtPayRollRegPayrollId");FILTER.reference=reviewString(document.getElementById("txtPayRollRegReference")).toUpperCase();FILTER.referenceyear=getElementValue("txtPayRollRegYear");FILTER.referencemonth=getElementValue("selPayRolAllMonth");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=deletePayrollInformation"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_PAYROLL_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("divPayRollRegister")}else{showNotification(result.msg,0)}}};http.send(params)}
showConfirm("Tem a certeza que deseja apagar esta folha de salário?",realDelete)}