class _companyDependency{constructor(companyid,dependencyid=0,provinceid=-1,municipalityid=-1,designation="",coordinatoruser=-1,printlayout=1,address="",phone1="",phone2="",phone3="",email="",website="",facebook="",whatsapp="",slogan=""){this.companyid=companyid;this.dependencyid=dependencyid;this.provinceid=provinceid;this.municipalityid=municipalityid;this.designation=designation;this.coordinatoruser=coordinatoruser;this.printlayout=printlayout;this.address=address;this.phone1=phone1;this.phone2=phone2;this.phone3=phone3;this.email=email;this.website=website;this.facebook=facebook;this.whatsapp=whatsapp;this.slogan=slogan}}
function companyGetInfo(companyId,sender=""){if(isNaN(companyId)){companyId=-1}
var txtCompanyId=document.getElementById("txtEmpCadCompanyId");var txtCompanyName=document.getElementById("txtEmpCadOficialDesignation");var txtCompanyNIF=document.getElementById("txtEmpCadNIF");var selCompanyType=document.getElementById("selEmpCadType");if(sender=="COMCAD"){var numFiscalYear=document.getElementById("numEmpCadFiscalYear");var selIvaGroup=document.getElementById("selEmpCadIvaGroup");var selIrtGroup=document.getElementById("selEmpCadIrtGroup");var selIIGroup=document.getElementById("selEmpCadIIGroup");var selContabilityStatus=document.getElementById("selEmpCadContabilityStatus")}
var selBillCountry=document.getElementById("selEmpCadBillCountry");var selBillProvince=document.getElementById("selEmpCadBillProvince");var selBillMunicipality=document.getElementById("selEmpCadBillMunicipality");var txtBillCity=document.getElementById("txtEmpCadBillCity");var txtBillDistrict=document.getElementById("txtEmpCadBillDistrict");var txtBillComuna=document.getElementById("txtEmpCadBillComuna");var txtBillNeiborhood=document.getElementById("txtEmpCadBillNeiborhood");var txtBillStreet=document.getElementById("txtEmpCadBillStreet");var txtBillBuidNumber=document.getElementById("txtEmpCadBillBuidNumber");var txtBillPostal=document.getElementById("txtEmpCadBillPostal");var txtTelef1=document.getElementById("txtEmpCadTelef1");var txtTelef2=document.getElementById("txtEmpCadTelef2");var txtTelef3=document.getElementById("txtEmpCadTelef3");var txtEmail=document.getElementById("txtEmpCadEmail");var txtWebsite=document.getElementById("txtEmpCadWebsite");if(sender=="COMCAD"){var lbNewLogo=document.getElementById("lbEmpCadNewLogo");var imgLogo=document.getElementById("imgEmpCadCompanyLogo")}
var lbLastStatus=document.getElementById('lbEmpCadLastStatus');if(companyId==-1){txtCompanyId.value="Novo contratante";txtCompanyName.value="";txtCompanyNIF.value="";selCompanyType.value=1;if(sender=="COMCAD"){numFiscalYear.value=2021;selIvaGroup.value=1;selIrtGroup.value=1;selIIGroup.value=1;selContabilityStatus.value=1}
selBillCountry.value=1;selBillProvince.value=-1;selBillMunicipality.value=-1;txtBillCity.value="";txtBillDistrict.value="";txtBillComuna.value="";txtBillNeiborhood.value="";txtBillStreet.value="";txtBillBuidNumber.value="";txtBillPostal.value="";txtTelef1.value="";txtTelef2.value="";txtTelef3.value="";txtEmail.value="";txtWebsite.value="";if(sender=="COMCAD"){lbNewLogo.innerHTML="";imgLogo.setAttribute("src","")}
lbLastStatus.innerHTML="";dispatchOnInputChange()}else{if(!desktopSecurityCheck()){return!1}
var FILTER={};FILTER.sessionId=getSessionId();FILTER.companyId=companyId;var http=new XMLHttpRequest();var params="action=getCompanyInformation"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_COMPANY_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 company=validateSession(http);txtCompanyId.value=company.companyid;txtCompanyName.value=company.companyname;txtCompanyNIF.value=company.companytaxid;selCompanyType.value=company.companytype;if(sender=="COMCAD"){numFiscalYear.value=company.fiscalyear;selIvaGroup.value=company.ivagroup;selIrtGroup.value=company.irtgroup;selIIGroup.value=company.iigroup;selContabilityStatus.value=company.contabilitystatus}
selBillCountry.value=company.billingcountry;selBillProvince.value=company.billingprovince;fillSelectMunicipality('selEmpCadBillMunicipality',company.billingprovince,-1,company.billingmunicipality);selBillMunicipality.value=company.billingmunicipality;txtBillCity.value=company.billingcity;txtBillDistrict.value=company.billingdistrict;txtBillComuna.value=company.billingcomuna;txtBillNeiborhood.value=company.billingneiborhood;txtBillStreet.value=company.billingstreetname;txtBillBuidNumber.value=company.billingbuildingnumber;txtBillPostal.value=company.billingpostalcode;txtTelef1.value=company.billingtelephone1;txtTelef2.value=company.billingtelephone2;txtTelef3.value=company.billingtelephone3;txtEmail.value=company.billingemail;txtWebsite.value=company.billingwebsite;if(sender=="COMCAD"){lbNewLogo.innerHTML=company.logofilename;if(company.logofilename!=""){imgLogo.setAttribute("src",company.logopath+company.logofilename)}}
lbLastStatus.innerHTML=("* Cadastrado em: "+company.entrydate+". Actualizado em: "+company.statusdate).toString().italics();dispatchOnInputChange()}};http.send(params)}
txtCompanyName.focus()}
class _company{constructor(companyId,companyName,companyTaxId,companyType,gmecustomerid=-1,fundid=-1,businessline="",systemtype=1,personname="",personfunction="",identificationdoc=-1,identificationnumber="",personnationality=-1,personphone1="",personphone2="",personemail="",fiscalYear=2021,ivaGroup=1,irtGroup=1,iiGroup=1,contabilityStatus=1,billingCountry=1,billingProvince=-1,billingMunicipality=-1,billingCity="",billingDistrict="",billingComuna="",billingNeiborhood="",billingStreetName="",billingBuildNumber="",billingPostalCode="",billingPhone1="",billingPhone2="",billingPhone3="",billingEmail="",billingWebsite="",logofilename=""){this.companyId=companyId;this.companyName=companyName;this.companyTaxId=companyTaxId;this.companyType=companyType;this.gmecustomerid=gmecustomerid;this.fundid=fundid;this.businessline=businessline;this.systemtype=systemtype;this.personname=personname;this.personfunction=personfunction;this.identificationdoc=identificationdoc;this.identificationnumber=identificationnumber;this.personnationality=personnationality;this.personphone1=personphone1;this.personphone2=personphone2;this.personemail=personemail;this.fiscalYear=fiscalYear;this.ivaGroup=ivaGroup;this.irtGroup=irtGroup;this.iiGroup=iiGroup;this.contabilityStatus=contabilityStatus;this.billingCountry=billingCountry;this.billingProvince=billingProvince;this.billingMunicipality=billingMunicipality;this.billingCity=billingCity;this.billingDistrict=billingDistrict;this.billingComuna=billingComuna;this.billingNeiborhood=billingNeiborhood;this.billingStreetName=billingStreetName;this.billingBuildNumber=billingBuildNumber;this.billingPostalCode=billingPostalCode;this.billingPhone1=billingPhone1;this.billingPhone2=billingPhone2;this.billingPhone3=billingPhone3;this.billingEmail=billingEmail;this.billingWebsite=billingWebsite;this.logofilename=logofilename}}
var COMPANY_WHOCALL="";function companyLicenseAssignedOnLoad(){showNotification();setPageTitleWhoCall("1901","COMPLICASS","Estado da licença");function licaoLoad(){setLicenseStatus('');companyLicenseAssignedList();hideNotification()}
checkUserStatusAfterExecute(licaoLoad)}
function companyLicenseAssignedList(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.licenseType=-1;showNotification();var http=new XMLHttpRequest();var params="action=getLicenseAssignedList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_COMPANY_X;http.open('POST',url,!0);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(this.readyState==4&&this.status==200){var licenses=validateSession(http);let tableRef=document.getElementById("tblCompLicAssMainTable");tableRef.innerHTML="";var nRows=0;licenses.forEach(element=>createTbl(element));function createTbl(element){nRows+=1;let license=JSON.parse(element);var status=Number(license.status);let newRow=tableRef.insertRow(-1);newRow.setAttribute("class","borderGray");if(status==-1){newRow.style.color="red"}else if(status==0){newRow.style.color="rgb(72,0,0)"}else if(status==1){newRow.style.fontWeight="bold"}
let cellRow=createTableCell(newRow,nRows,"colRowNumber","#");let cellCode=createTableCell(newRow,license.id,"colProductId","Código");let cellComp=createTableCell(newRow,license.companyname,"","Contratante");let cellInv=createTableCell(newRow,license.invoicenumber,"","Factura");let cellLic=createTableCell(newRow,license.licensetype,"","Tipo de licença");let cellStatus=createTableCell(newRow,LICENSE_TYPE_STATUS[status],"","Estado");let cellEnd=createTableCell(newRow,license.enddate,"","Data de validade")}
hideNotification()}};http.send(params)}
var COMPANY_ADMINISTRATIVE_STRUCTURE_LIST=[];function companyAdministrativeOnLoad(){showNotification();setPageTitleWhoCall("1901","COMPADMSTR","Estrutura administrativa");function cdoLoad(){const txtDepartment=document.getElementById("txtCompDepartRegDepartment");txtDepartment.onchange=function(){if(isNaN(getElementValue("txtCompDepartRegDepartamentId"))){companyAdministrativeDepartmentCreateInitial()}};setAutoCompleteToFiel(txtDepartment.id,38,1);setAutoCompleteToFiel('txtCompDepartRegInitials',39,1);companyAdministrativeList();hideNotification()}
checkUserStatusAfterExecute(cdoLoad)}
function companyAdministrativeList(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.departmentid=-1;COMPANY_ADMINISTRATIVE_STRUCTURE_LIST=[];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=getCompanyDepartmentList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_DEPARTMENT_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 departments=validateSession(http);setElementInnerHtml("lbResultOnList",departments.length);let tableRef=document.getElementById("tblCompAdmStrMainTable");tableRef.innerHTML="";var nRows=0;for(var i=0;i<departments.length;i++){let department=JSON.parse(departments[i]);COMPANY_ADMINISTRATIVE_STRUCTURE_LIST[i]=department;nRows+=1;let newRow=tableRef.insertRow(-1);newRow.setAttribute("id","rowCompAdmStrList"+department.departmentid);newRow.setAttribute("class","borderGray"+rowFontSize(department)+setSelectedRowBackground("SELECTED_ROW_DEPARTMENT_LIST",newRow.id));let cellLevel1=createTableCell(newRow,hideZero(department.indicatorlevel),"","Indicador");var depClass="text-capitalize";if(department.level3==0){depClass="textUpperUcase"}
let cellDepart=createTableCell(newRow,department.department,depClass,"Designação");let cellInitials=createTableCell(newRow,department.initials,"text-align-center","Abreviação");let cellWorpost=createTableCell(newRow,0,"text-align-center","Posto de trabalho");let cellInJob=createTableCell(newRow,0,"text-align-center","Enquadrados");let cellEdit=createTableCell(newRow,"","noPrint text-align-center","...");let btAdd=document.createElement("button");btAdd.setAttribute("class","labelAdd");btAdd.type="button";btAdd.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_DEPARTMENT_LIST");companyAdministrativeDepartmentDetail(-1,department.level1,department.level2,department.level3,department.level4,department.level5)};if(department.level5==0){cellEdit.appendChild(btAdd)}
let btEdit=document.createElement("button");btEdit.setAttribute("class","labelEdit");btEdit.type="button";btEdit.name=department.departmentid;btEdit.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_DEPARTMENT_LIST");companyAdministrativeDepartmentDetail(btEdit.name)};cellEdit.appendChild(btEdit);let btDelete=document.createElement("button");btDelete.setAttribute("class","labelDelete");btDelete.type="button";btDelete.onclick=function(){setSelectedRowOnClick(newRow,"SELECTED_ROW_DEPARTMENT_LIST");companyAdministrativeDepartmentDelete(btEdit.name,department.level1,department.level2,department.level3,department.level4,department.level5)};cellEdit.appendChild(btDelete)}}};http.send(params);function hideZero(val){if(val==0){return""}
return val}
function rowFontSize(depart){var ftSizeClass="";if((depart.level2==0)&&(depart.level3==0)){ftSizeClass=" font-size-x-large font-weight-bold"}else if((depart.level3==0)&&(depart.level4==0)){ftSizeClass=" font-size-large"}else if((depart.level4==0)&&(depart.level5==0)){ftSizeClass=" font-size-medium font-weight-bold"}else if((depart.level5!=0)){ftSizeClass=" font-style-italic"}
return ftSizeClass}}
function companyAdministrativeDepartmentNew(){companyAdministrativeDepartmentDetail()}
function companyAdministrativeDepartmentDetail(departmentId=-1,l1=0,l2=0,l3=0,l4=0,l5=0){showParts("divCompDepartamentRegister");const lbHeader=document.getElementById("h2CompDepartRegHeader");const txtDepartId=document.getElementById("txtCompDepartRegDepartamentId");const txtIndicator=document.getElementById("txtCompDepartRegIndicator");const txtDepartment=document.getElementById("txtCompDepartRegDepartment");const txtInitial=document.getElementById("txtCompDepartRegInitials");const lbUpdate=document.getElementById("lbCompDepartRegUpdate");if(departmentId==-1){lbHeader.innerHTML="Nova área";txtDepartId.value="Nova área";txtIndicator.value=companyAdministrativeDepartmentSetIndicator(l1,l2,l3,l4,l5);txtDepartment.value="";cleanElement("tblCompDepartRegWorkpost");lbUpdate.innerHTML="Actualizado em "+setLocalDate(new Date(),16)}else{lbHeader.innerHTML="Dados da área";if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.departmentid=departmentId;showNotification();var http=new XMLHttpRequest();var params="action=getCompanyDepartmentList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_DEPARTMENT_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 departments=validateSession(http);let department=JSON.parse(departments[0]);txtDepartId.value=department.departmentid;txtIndicator.value=department.indicatorlevel;txtDepartment.value=department.department;txtInitial.value=department.initials;lbUpdate.innerHTML="Cadastrado por "+getOperatorName(department.operatorEntry,department.entryuser)+" em "+setLocalDate(department.entrydate,16)+". <br>"+"Actualizado por "+getOperatorName(department.operatorName,department.statususer)+" em "+setLocalDate(department.statusdate,16);hideNotification()}};http.send(params)}
txtDepartment.focus()}
function companyAdministrativeDepartmentSetIndicator(l1=0,l2=0,l3=0,l4=0,l5=0){var indicator=l1;if(l2>0){indicator+="."+l2}
if(l3>0){indicator+="."+l3}
if(l4>0){indicator+="."+l4}
if(l5>0){indicator+="."+l5}
if((l1==0)&&(l2==0)){indicator=companyAdministrativeDepartmentGetLevelNumber()}else if((l2==0)&&(l3==0)){indicator+="."+companyAdministrativeDepartmentGetLevelNumber(l1)}else if((l3==0)&&(l4==0)){indicator+="."+companyAdministrativeDepartmentGetLevelNumber(l1,l2)}else if((l4==0)&&(l5==0)){indicator+="."+companyAdministrativeDepartmentGetLevelNumber(l1,l2,l3)}else if((l5==0)){indicator+="."+companyAdministrativeDepartmentGetLevelNumber(l1,l2,l3,l4)}
return indicator}
function companyAdministrativeDepartmentGetLevelNumber(l1=0,l2=0,l3=0,l4=0,l5=0){var ind=0;if(COMPANY_ADMINISTRATIVE_STRUCTURE_LIST.length>0){for(var i=0;i<COMPANY_ADMINISTRATIVE_STRUCTURE_LIST.length;i++){var depart=COMPANY_ADMINISTRATIVE_STRUCTURE_LIST[i];if((l1==0)&&(l2==0)){ind=depart.level1}else{if(depart.level1==l1){if((l2==0)&&(l3==0)){ind=depart.level2}else{if(depart.level2==l2){if((l3==0)&&(l4==0)){ind=depart.level3}else{if(depart.level3==l3){if((l4==0)&&(l5==0)){ind=depart.level4}else{if(depart.level4==l4){ind=depart.level5}}}}}}}}}}
return Number(ind)+1}
function companyAdministrativeDepartmentCreateInitial(){var initials="";var department=reviewString(document.getElementById("txtCompDepartRegDepartment")).toString().toUpperCase();var worlds=department.split(" ");if(worlds.length>1){for(var i=0;i<worlds.length;i++){initials+=worlds[i].slice(0,1)}}else{initials=department.slice(0,3)}
setElementValue("txtCompDepartRegInitials",initials)}
function companyAdministrativeDepartmentSave(){if(!desktopSecurityCheck()){return!1}
var department=setFilterStatus();department.userId=SYSTEM_USER_STATUS.userId;department.departmentid=getElementValue("txtCompDepartRegDepartamentId");department.indicatorlevel=getElementValue("txtCompDepartRegIndicator");department.department=reviewString(document.getElementById("txtCompDepartRegDepartment"));department.initials=reviewString(document.getElementById("txtCompDepartRegInitials"));department.level1=companyAdministrativeDepartmentGetLevel(department.indicatorlevel,1);department.level2=companyAdministrativeDepartmentGetLevel(department.indicatorlevel,2);department.level3=companyAdministrativeDepartmentGetLevel(department.indicatorlevel,3);department.level4=companyAdministrativeDepartmentGetLevel(department.indicatorlevel,4);department.level5=companyAdministrativeDepartmentGetLevel(department.indicatorlevel,5);var mandatoryField=!1;var msg="";if(department.department==""){mandatoryField=!0;msg+="Deve indicar a designação da área. <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=saveCompanyDepartmentInformation"+"&filterInfo="+JSON.stringify(department);var url=URL_SRH_DEPARTMENT_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("Área actualizada com sucessos.",1);companyAdministrativeList();hideParts("divCompDepartamentRegister")}else{showNotification(result.msg,0)}}};http.send(params)}
function companyAdministrativeDepartmentGetLevel(indicator,level){var ind=indicator.toString().split(".");var l=Number(level);if(ind.length>=l){return ind[l-1]}
return 0}
function companyAdministrativeDepartmentDelete(departmentId,l1=0,l2=0,l3=0,l4=0,l5=0){var departmentList=departmentId;var msg="";for(var i=0;i<COMPANY_ADMINISTRATIVE_STRUCTURE_LIST.length;i++){var depart=COMPANY_ADMINISTRATIVE_STRUCTURE_LIST[i];if(depart.level1==l1){if((l2==0)&&(l3==0)){departmentList+=", "+depart.departmentid;msg+=depart.indicatorlevel+" "+depart.department+"<br>"}else{if(depart.level2==l2){if((l3==0)&&(l4==0)){departmentList+=", "+depart.departmentid;msg+=depart.indicatorlevel+" "+depart.department+"<br>"}else{if(depart.level3==l3){if((l4==0)&&(l5==0)){departmentList+=", "+depart.departmentid;msg+=depart.indicatorlevel+" "+depart.department+"<br>"}else{if(depart.level4==l4){departmentList+=", "+depart.departmentid;msg+=depart.indicatorlevel+" "+depart.department+"<br>"}}}}}}}}
function realDelete(){if(!desktopSecurityCheck()){return!1}
var FILTER=setFilterStatus();FILTER.departmentList=departmentList;showNotification();var http=new XMLHttpRequest();var params="action=deleteCompanyDepartmentList"+"&filterInfo="+JSON.stringify(FILTER);var url=URL_SRH_DEPARTMENT_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);companyAdministrativeList()}else{showNotification(result.msg,0)}}};http.send(params)}
showConfirm("Tem a certeja que deseja apagar estas áreas?<br><br>"+msg,realDelete)}