-//Source-code licensed under EUPL v1.1 ( Copyright 2016 By DKS s.à r.l. - Kilian Saffran - Luxembourg )
-var pconfig = null;
-var delplan = null;
-var delvacation = null;
-var wh= window.innerHeight -440;
-var curdatediff = null;
-var redate = /\d\d.\d\d.\d\d\d\d/;
-var curfreq ={};
-var maxdayhours = null;
-var maxhalfdayhours = null;
-//var lictype = apppref.getpreference("support.lictype");
-
-function initdata() {
- load_helpers();
- var pdata = apppref.getpreference("pageconfig.coworker");
- if (pdata != '') {
- pconfig = JSON.parse(pdata);
- }
- //"get CoWorker cfg:" +JSON.stringify(pconfig) + "\n");
- if (!pconfig.year) {
- pconfig.year=new Date().getFullYear();
- }
- if (!pconfig.printlayout) {
- pconfig.printlayout = 'list';
- apppref.setpreference("pageconfig.coworker",pconfig);
- }
- var cdatasql = "SELECT jobtitle, prename, surname, address, zip, city, country, strftime('%d.%m.%Y',entrydate) as entrydate, strftime('%d.%m.%Y',exitdate) as exitdate, iban, bic, accountname, phone, email, uuid,color,weekhours,maxdayhours,case when password is not null and length(password) > 3 then 1 else 0 end as passwordset FROM staff where uuid='" + pconfig.uuid + "';";
- var cdata = appdb.dbquery(cdatasql);
- cdata = cdata.sqldata[0];
- for (var ci in cdata) {
- if (document.getElementById("staff_" + ci)) {
- document.getElementById("staff_" + ci).setAttribute('value', cdata[ci]);
- }
-
- }
-
- var crdata = appdb.dbquery("select stafflist from creche;");
- if ((crdata) && (crdata.sqldata[0].stafflist == "1")){
- $("#pwddata").hide();
- }
- if (cdata) {
- set_infoheader(cdata.prename + " " + cdata.surname);
- }
- $('#staff_color').minicolors({theme:'bootstrap'});
- set_selectyears();
- //load_staff_selection('staffuuid');
-
- if (pconfig && pconfig.activetab) {
- $('a[href="#'+pconfig.activetab+'"]').tab('show');
- }else{
- $('a[href="#vacancy"]').tab('show');
- pconfig.activetab = 'vacancy';
- }
-
-// if (pconfig && pconfig.vacancyunit){
-// //dump("has vacancy unit:" + pconfig.vacancyunit + "\n");
-// $('#vacancy_unit').val(pconfig.vacancyunit);
-// }else {
- pconfig.vacancyunit = "hours";
-// $('#vacancy_unit').val("days");
-// }
-
- $('#frmeditvacancy #vacdatefrom').on("blur",function (e) {
- var ok = true;
- if ($('#frmeditvacancy #vacdatefrom').val().match(redate)) {
- $('#btn_save_vacancy').removeAttr("disabled");
- }else {
- ok = false;
- $('#btn_save_vacancy').attr("disabled","1");
- }
- if ((ok == true) && ($('#frmeditvacancy #vacdateto').val() != '')) {
- var tmpdt1 = encodeparam($('#frmeditvacancy #vacdatefrom').val(),'date');
- var nd = new Date(tmpdt1.replace(/'/g,''));
- var xd = new Date(nd.getFullYear(),nd.getMonth(),nd.getDate() + curdatediff);
- $('#frmeditvacancy #vacdateto').val(xd.toLocaleFormat("%d.%m.%Y"));
- var tmpdt2 = encodeparam($('#frmeditvacancy #vacdateto').val(),'date');
- if (tmpdt1 > tmpdt2) {
- $('#btn_save_vacancy').attr("disabled","1");
- } else {
- $('#btn_save_vacancy').removeAttr("disabled");
- }
-
- }
- });
- $('#frmeditvacancy #vacdateto').on("blur",function (e) {
- var ok = true;
- if ($('#frmeditvacancy #vacdateto').val().match(redate)) {
- $('#btn_save_vacancy').removeAttr("disabled");
- }else {
- ok = false;
- $('#btn_save_vacancy').attr("disabled","1");
- }
- curdatediff=daysBetween(new Date(encodeparam($('#frmeditvacancy #vacdatefrom').val(),'date').replace(/'/g,'')),new Date(encodeparam($('#frmeditvacancy #vacdateto').val(),'date').replace(/'/g,'')));
- if ((ok == true) && ($('#frmeditvacancy #vacdateto').val() != '')) {
- var tmpdt1 = encodeparam($('#frmeditvacancy #vacdatefrom').val(),'date');
- var tmpdt2 = encodeparam($('#frmeditvacancy #vacdateto').val(),'date');
- if (tmpdt1 > tmpdt2) {
- $('#btn_save_vacancy').attr("disabled","1");
- } else {
- $('#btn_save_vacancy').removeAttr("disabled");
- }
-
- }
- });
- $('#dailyduration').on('change',function(e){
- if ($('#dailyduration').val() == "1.0"){
- $('#frmeditvacancy #hours').val(maxdayhours);
- }
- if ($('#dailyduration').val() == "0.4"){
- $('#frmeditvacancy #hours').val(maxhalfdayhours);
- }
- });
- $('#staff_color').on('change',function(e){
- saveonfocusout('staff_color');
- });
- //$('#frmeditevent #color').minicolors({theme:'bootstrap',position: 'bottom right'});
- $("#weekly_byday :input").change(function() {
- if (this.checked) {
- this.setAttribute("checked",true);
- }else {
- this.removeAttribute("checked");
- }
-
-});
- $("#monthly_bydaypos :input").change(function() {
-
- if (this.checked) {
- this.setAttribute("checked",true);
- }else {
- this.removeAttribute("checked");
- }
-
-});
- $("#monthly_bydaywday :input").change(function() {
-
- if (this.checked) {
- this.setAttribute("checked",true);
- }else {
- this.removeAttribute("checked");
- }
-
-});
- $("#monthly_bymonthday :input").change(function() {
-
- if (this.checked) {
- this.setAttribute("checked",true);
- }else {
- this.removeAttribute("checked");
- }
-
-});
- $("#monthly_by :input").change(function() {
- var xd = this.id.split("_");
- curfreq.freqtype=xd[2];
-
- this.setAttribute("checked",true);
-
- $('#freq_monthly_byday').hide();
- $('#freq_monthly_bymonthday').hide();
- $('#pnl_monthly_byday').removeAttr("checked");
- $('#pnl_monthly_bymonthday').removeAttr("checked");
-
- $('#freq_' + this.value).show();
-
-});
-
- $('#frmeditevent #datefrom').on("blur",function (e) {
- var ok = true;
- if ($('#frmeditevent #datefrom').val().match(redate)) {
- $('#btn_save_event').removeAttr("disabled");
- }else {
- ok = false;
- $('#btn_save_event').attr("disabled","1");
- }
- if ((ok == true) && ($('#frmeditevent #dateto').val() != '')) {
- var tmpdt1 = encodeparam($('#frmeditevent #datefrom').val(),'date');
- var tmpdt2 = encodeparam($('#frmeditevent #dateto').val(),'date');
- if (tmpdt1 >= tmpdt2) {
- $('#btn_save_event').attr("disabled","1");
- } else {
- $('#btn_save_event').removeAttr("disabled");
- }
-
- }
- });
- $('#frmeditevent #dateto').on("blur",function (e) {
- var ok = true;
- if ($('#frmeditevent #dateto').val().match(redate)) {
- $('#btn_save_event').removeAttr("disabled");
- }else {
- ok = false;
- $('#btn_save_event').attr("disabled","1");
- }
- if ((ok == true) && ($('#frmeditevent #dateto').val() != '')) {
- var tmpdt1 = encodeparam($('#frmeditevent #datefrom').val(),'date');
- var tmpdt2 = encodeparam($('#frmeditevent #dateto').val(),'date');
-
- if (tmpdt1 >= tmpdt2) {
- $('#btn_save_event').attr("disabled","1");
- } else {
- $('#btn_save_event').removeAttr("disabled");
- }
-
- }
- });
-
-}
-
-$('.selyear').on( "change", function(e){
- e.preventDefault();
-
- $(".selyear").val($(this).val());
- pconfig.year = $(this).val();
- apppref.setpreference("pageconfig.coworker",pconfig);
- if ($(this).attr('id') == "year_organisation") {
- load_event_data();
- }else if ($(this).attr('id') == "year_vacancy") {
- load_table_vacancy();
- }
-});
-
-$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- var tn = e.target.toString();
- pconfig.activetab = tn.substring(tn.lastIndexOf("#")+1);
- //dump(JSON.stringify(pconfig) + "\n");
- apppref.setpreference("pageconfig.coworker",pconfig);
- if (pconfig.activetab == 'activity') {
- load_event_data();
- }
- if (pconfig.activetab == 'vacancy') {
- load_table_vacancy();
- }
- });
-
-function load_event_data() {
- dump("Load event Table!\n");
- var where = new Array();
-
- where.push(" st.uuid in ('"+ pconfig.uuid + "')");
-
- $("div.panel-daybody").html("");
- var sql = "SELECT cal.uuid, cal.datefrom, cal.dateto, '<div style=\"display:none;\">' || strftime('%Y%m%d',cal.datefrom) ||'</div>' || strftime('%d.%m.%Y',cal.datefrom) AS tbldatefrom ,strftime('%Y%m%d',cal.datefrom) AS strdatefrom, strftime('%Y%m%d',cal.dateto) AS strdateto,cal.timefrom, cal.timeto, cal.description, cal.location, cal.color, cal.freq, '[\"' || GROUP_CONCAT(sp.staffuuid,'\",\"') || '\"]' as staffuuid, GROUP_CONCAT(coalesce(st.surname,'') || ' ' || coalesce(st.prename,''), '<br/>' ) as staffnames ,'[\"' || GROUP_CONCAT(st.color,'\",\"') || '\"]' as staffcolors from eventcalendar cal " +" join staffplanning sp on (cal.uuid=sp.eventcalendaruuid " + " AND sp.staffuuid in ('"+ pconfig.uuid +"')) left join staff st on (sp.staffuuid=st.uuid) "+
- " where (cal.datefrom between '" + $('#year_organisation').val() + "-01-01' and '" + $('#year_organisation').val() + "-12-31' and (cal.dateto >= '" + $('#year_organisation').val() + "-01-01' or cal.dateto is null)) or (cal.dateto between '" + $('#year_organisation').val() + "-01-01' and '" + $('#year_organisation').val() + "-12-31' and cal.datefrom < '" + $('#year_organisation').val() + "-01-01') or ((cal.datefrom <= '" + $('#year_organisation').val() + "-01-01') and ((cal.dateto >= '" + $('#year_organisation').val() + "-12-31') or cal.dateto is null)) "+ ((where.length > 0)?" AND (" + where.join(" or ") + ")":"")+" group by cal.uuid order by cal.datefrom,cal.dateto;";
-
- var caldata = appdb.dbquery(sql);
-
- caldata = caldata.sqldata;
-
- var headerdata = getlabels("act,datefrom,hours,recurrance");
- $("#tbl_activity").html("");
-
- var hrow = headerdata;
- var tdclass= new Array();
- var tblheader = '<tr>';
-
- for (var h=0;h<hrow.length;h++){
- tdclass.push(headerdata[h].class);
- tblheader += '<th class="' + headerdata[h].class +'">'+ headerdata[h].title+'</th>';
- }
- tblheader += '</tr>';
-
- $("#tbl_activity").append("<thead>" + tblheader + "</thead>");
- $("#tbl_activity").append("<tbody>");
- var tblbody = [];
- for (var c in caldata) {
- var tblrow = "<tr>";
- tblrow += '<td class="noprint"><button type="button" class="btn btn-primary" onclick="dlg_event({uuid:\''+caldata[c].uuid+'\'},\'upd\');" title="editer"><span class="glyphicon glyphicon-pencil"></span></button></td>';
- //tblrow += "<td><span style=\"display: none;\">"+caldata[c].description+"</span><strong style=\"color:"+ caldata[c].color +"\">" + caldata[c].description + "</strong></td>";
- //tblrow += "<td>" + caldata[c].staffnames + "</td>";
- tblrow += "<td>" + caldata[c].tbldatefrom + "</td>";
- tblrow += "<td>" + caldata[c].timefrom + "- " + caldata[c].timeto + "</td>";
-
- var freq2 = caldata[c].freq;
- if (freq2 != '') {
-
- freq2 += ';DTSTART='+caldata[c].strdatefrom + 'T000000Z';
- if (caldata[c].dateto != ''){
- freq2 += ';UNTIL='+caldata[c].strdateto + 'T000000Z';
- }
- }
-
- try {
-
- var rule2 = RRule.fromString(freq2);
-
-
- tblrow += "<td>" + rule2.toText() + "</td>";
-
- } catch (ex){
- //"ERROR! loading data!" + ex + " FREQ:" + freq2 + "\n");
- }
- tblrow += "</tr>";
- tblbody.push(tblrow);
- }
-
- //load table
- $("#tbl_activity").append(tblbody.join(''));
- $("#tbl_activity").append("</tbody>");
-
- tblcal = $("#tbl_activity").dataTable({
- "language": {
- "url": "../../web/js/locale/datatable_fr.json"
- },
- "paging": false,
- "scrollY": wh + "px",
- "scrollCollapse": true,
- "ordering": true,
- "info": false,
- "filter": false,
- "destroy": true
- });
-
- //$('#tbl_activity').on( 'search.dt', function () {
- //
- // pconfig.filter = tblcal.api().search();
- //
- // apppref.setpreference("pageconfig.calactivity",pconfig);
- //} );
-
- //$('#tbl_activity').on( 'order.dt', function () {
- // pconfig.order= tblcal.fnSettings().aaSorting;
- //
- // apppref.setpreference("pageconfig.calactivity",pconfig);
- //
- //} );
-
-// if (pconfig.filter) {
-// tblcal.fnFilter(pconfig.filter);
-// }
- if (pconfig.order) {
- tblcal.fnSort(pconfig.order);
- }
- if (/*(!pconfig.filter) && */ (!pconfig.order)) {
- tblcal.fnDraw();
- }
-}
-
-function load_table_vacancy() {
- //maxdayhours = (parseFloat($("#staff_weekhours").val())/5).toFixed(2);
- //maxhalfdayhours = (maxdayhours/2).toFixed(2);
- var yearvacanysql = "select hours from staffvacancydays where staffuuid='"+ pconfig.uuid+"' and vacancyyear='"+ $("#year_vacancy").val() +"';";
- var yearvac = appdb.dbquery(yearvacanysql);
- var nvyear = "";
- //jsdump("XXSQL:" + JSON.stringify(yearvac) + "\n");
- if (yearvac.sqldata){
- nvyear = yearvac.sqldata[0].hours;
- }
- $("#vacancyyeartotal").val(nvyear);
- var vacdatasql = "SELECT '<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_vacancy({''uuid'':'''|| uuid || '''},''upd'');\"><span class=\"glyphicon glyphicon-pencil\"></span></button>" +
- "<button type=\"button\" class=\"btn btn-danger\" onclick=\"confirm_delete_vacancy(''' || uuid || ''');\"><span class=\"glyphicon glyphicon-remove\"></span></button>' AS action," + "vacyear," +
- "strftime('%d.%m.%Y', datefrom) as datefrom,strftime('%d.%m.%Y', dateto) as dateto,printf(\"%.2f\",hours) || 'h' as dayhours,description," +
- "case when type=0 and accepted != '1' then printf(\"%.2f\",case when hours < maxdayhours then hours when hours > maxdayhours then maxdayhours else hours end) || 'h' else '' end as thnormalnv," +
- "case when type=1 and accepted != '1' then printf(\"%.2f\",case when hours < maxdayhours then hours when hours > maxdayhours then maxdayhours else hours end) || 'h' else '' end as thextranv," +
- "case when type=-1 and accepted != '1' then printf(\"%.2f\",case when hours < maxdayhours then hours when hours > maxdayhours then maxdayhours else hours end) || 'h' else '' end as thillnv," +
- "case when type=0 and accepted = '1'then printf(\"%.2f\",case when hours < maxdayhours then hours when hours > maxdayhours then maxdayhours else hours end) || 'h' else '' end as thnormalval," +
- "case when type=1 and accepted = '1' then printf(\"%.2f\",case when hours < maxdayhours then hours when hours > maxdayhours then maxdayhours else hours end) || 'h' else '' end as thextraval," +
- "case when type=-1 and accepted = '1' then printf(\"%.2f\",case when hours < maxdayhours then hours when hours > maxdayhours then maxdayhours else hours end) || 'h' else '' end as thillval," +
- "case when type=0 then 'normal' when type=1 then 'exceptionnelle' when type=-1 then 'maladie' end as vacancytype,case when accepted='1' and type != -1 then '<span style=\"font-weight: bold; color: green;\">OUI</span>' else '<span style=\"font-weight: bold; color: red\">NON</span>' end as accepted FROM (" +
- "select vc.uuid,vc.vacyear,vc.datefrom,vc.dateto,vc.type,vc.description,vc.accepted," +
- "((strftime('%s',vc.dateto) - strftime('%s',vc.datefrom)) /84600) + 1 as days," +
- "((((strftime('%s',vc.dateto) - strftime('%s',vc.datefrom)) /84600) + 1) / 7) * (7 - (st.weekhours / st.maxdayhours)) as day_to_much," +
- "(select count(v.vacancydate) from vacancy v where v.vacancydateto is null and strftime('%s',v.vacancydate) not in ('0','6') and v.vacancydate between vc.datefrom and vc.dateto) as vdays,st.weekhours,st.weekhours / maxdayhours as days_per_week,vc.timefrom,vc.timeto,st.maxdayhours, " +
- "cast(cast(strftime(\"%s\",vc.timeto) as int)- cast(strftime(\"%s\",vc.timefrom) as int) as real)/3600 as hours " +
- "from vacancycalendar vc join staff st on (vc.staffuuid=st.uuid) where vc.staffuuid='"+ pconfig.uuid+"' and vc.vacyear=" + pconfig.year+");";
- // var vacdatasql = "SELECT '<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_vacancy({''uuid'':'''|| uuid || '''},''upd'');\"><span class=\"glyphicon glyphicon-pencil\"></span></button> <button type=\"button\" class=\"btn btn-danger\" onclick=\"confirm_delete_vacancy(''' || uuid || ''');\"><span class=\"glyphicon glyphicon-remove\"></span></button>' AS action,vacyear," +
-// "CASE WHEN datefrom!=dateto THEN 'du:' || strftime('%d.%m.%Y', CASE WHEN datefrom < DATE('"+ pconfig.year +"-01-01') THEN DATE('"+ pconfig.year +"-01-01') ELSE datefrom END) || '<br/>au: ' || strftime('%d.%m.%Y', CASE WHEN dateto > DATE('"+ pconfig.year +"-12-31') THEN DATE('"+ pconfig.year +"-12-31') ELSE dateto END) ELSE strftime('%d.%m.%Y',datefrom) END AS planningdaterange," +
-// //"case when datefrom!=dateto then strftime('%d.%m.%Y',case when datefrom < date('"+ pconfig.year +"-01-01') then 'de: ' date('"+ pconfig.year +"-01-01') else datefrom end) || '<br/>à: ' || strftime('%d.%m.%Y',case when dateto > date('"+ pconfig.year +"-12-31') then date('"+ pconfig.year +"-12-31') else dateto end) else strftime('%d.%m.%Y',datefrom) end as planningdaterange, " +
-// "case when timefrom=timeto then '"+ maxdayhours+ "' || 'h' else printf(\"%.2f\",cast(cast(strftime(\"%s\",timeto) as int)- cast(strftime(\"%s\",timefrom) as int) as real)/3600) || 'h' || case when timefrom!='00:00' then '<br/> à partir de ' || timefrom else '' end end as hourrange," +
-// //"case when timefrom=timeto then '8h' when (cast(substr(timeto,1,2) as int) - cast(substr(timefrom,1,2) as int))= 4 then '4h' || case when timefrom!='00:00' then '<br/> à partir de ' || timefrom else '' end else (cast(substr(timeto,1,2) as int) - cast(substr(timefrom,1,2) as int)) || 'h' || case when timefrom!='00:00' then '<br/> à partir de ' || timefrom else '' end end as hourrange, "+
-// "description, " +
-// "case when type=0 then 'normal' when type=1 then 'exceptionnelle' when type=-1 then 'maladie' end as vacancytype,case when accepted='1' and type != -1 then '<span style=\"font-weight: bold; color: green;\">OUI</span>' else '<span style=\"font-weight: bold; color: red\">NON</span>' end as accepted FROM vacancycalendar where staffuuid='"+ pconfig.uuid +"' and (strftime('%Y',dateto)='"+ pconfig.year +"' or strftime('%Y',datefrom)='"+ pconfig.year +"');";
-//jsdump("XXSQL:" + vacdatasql + "\n");
-var vacdata = appdb.dbqueryarray(vacdatasql);
-//jsdump("XXSQL:" + JSON.stringify(vacdata) + "\n");
-
- $('#tbl_vacancy').html("");
- //$('#tbl_vacancy').append('<tfoot><tr><th></th><th colspan="4" style="text-align: center;"></th></tr></tfoot>');
- //getlastyearsrest();
- //calcvacancy();
- //vacdata.sqlhead.join(",") + "\n");
- var headerdata = getlabels(vacdata.sqlhead.join(","));
-
-
- $("#tbl_vacancy").dataTable({
- "language": {
- "url": "../../web/js/locale/datatable_fr.json"
- },
- "data": vacdata.sqldata,
- "columns": headerdata,
- "paging": false,
- "scrollY": wh + "px",
- "scrollCollapse": true,
- "ordering": true,
- "info": false,
- "filter": false,
- "destroy": true
- });
-
-}
-
-function dlg_vacancy(uuid, type) {
- //select weekhours/5 = max daily hours
- maxdayhours = (parseFloat($("#staff_weekhours").val())/5).toFixed(2);
- maxhalfdayhours = (maxdayhours/2).toFixed(2);
- var evdata = {
- uuid: 0,
- description: '',
- vacdatefrom:new Date().toLocaleFormat("%d.%m.%Y"),
- vacdateto:new Date().toLocaleFormat("%d.%m.%Y"),
- staffuuid:[pconfig.uuid],
- timefrom: '00:00',
- hours: maxdayhours,
- type:'0',
- //dailyduration:'1.0',
- //hourmax: whr
- };
-
- if (type == 'upd') {
- var evsql = "select uuid,vacdatefrom,vacdateto,timefrom,description,staffuuid,case when hours = '0.00' then '" + maxdayhours +"' else hours end as hours,accepted from (SELECT uuid, strftime(\"%d.%m.%Y\",datefrom) as vacdatefrom, strftime(\"%d.%m.%Y\",dateto) as vacdateto, timefrom, description, '"+pconfig.uuid+"' as staffuuid,type, printf(\"%.2f\",cast((cast(strftime(\"%s\",timeto) as int)- cast(strftime(\"%s\",timefrom) as int))/3600 as real)) as hours,accepted FROM vacancycalendar where uuid='" + uuid.uuid + "');";
- //var evsql = "SELECT uuid, strftime(\"%d.%m.%Y\",datefrom) as vacdatefrom, strftime(\"%d.%m.%Y\",dateto) as vacdateto, timefrom, description, '"+pconfig.uuid+"' as staffuuid,type, case when timefrom!=timeto then '0.' || (cast(substr(timeto,1,2) as int) - cast(substr(timefrom,1,2) as int)) else 1.0 end as dailyduration,null as hours,accepted FROM vacancycalendar where uuid='" + uuid.uuid + "';";
- //dump("EVSQL: " + evsql + "\n");
- evdata = appdb.dbquery(evsql);
- evdata = evdata.sqldata[0];
- if (evdata.type == -1){
- $("#btnacceptvacancy").hide();
- }else {
- $("#btnacceptvacancy").show();
- }
- if (evdata.hours >= maxdayhours) {
- evdata.hours=maxdayhours;
- $('#dailyduration select').val("1.0");
- } else if (evdata.hours == maxhalfdayhours){
- $('#dailyduration select').val("0.4");
- } else {
- $('#dailyduration select').val("0.");
- }
-
- }else {
- $('#dailyduration select').val("1.0");
- }
- for (var w in evdata) {
- if ((w == 'datefrom') || (w == 'dateto')) {
- w='vac' + w;
- }
-
- if ($("#frmeditvacancy #" + w)) {
- //dump(w + "->"+evdata[w]+"\n");
- if (w == "type"){
- $("#frmeditvacancy #" + w + " select").val(evdata[w]);
- } else {
- $("#frmeditvacancy #" + w).val(evdata[w]);
- }
-
-
- }
-
- }
-
- setdailydurationfields();
- $("#edit_vacancy").modal('show');
-}
-
-function confirm_delete_vacancy(uuid) {
- delvacation = uuid;
- $("#confirm_delete_vacancy").modal('show');
- return false;
-}
-
-function delete_vacancy() {
- var delsql = "DELETE FROM vacancycalendar where uuid='" + delvacation+"';";
- appdb.dbexec(delsql);
- load_table_vacancy();
- delvacancy=null;
- $("#confirm_delete_vacancy").modal('hide');
-
- return false;
-}
-
-function setdailydurationfields() {
- var dd = $('#dailyduration :selected').val();
- if (dd=='1.0') {
- //$("#ftimefrom").hide();
- $("#hours").prop("disabled",true);
- }else if (dd=='0.4') {
- //$("#ftimefrom").show();
- $("#hours").prop("disabled",true);
- }else if (dd=='0.') {
- //$("#ftimefrom").show();
- $("#hours").prop("disabled",false);
- }
-}
-
-function save_vacancy() {
- var type = 'ins';
- var cuuid = "";
- if ($("#frmeditvacancy #uuid").val() != 0) {
- type = 'upd';
- cuuid = $("#frmeditvacancy #uuid").val();
- }
- var evsvdata = {
- uuid:cuuid,
- datefrom: $("#frmeditvacancy #vacdatefrom").val(),
- dateto: $("#frmeditvacancy #vacdateto").val(),
- timefrom: $("#frmeditvacancy #timefrom").val(),
- hours: $("#frmeditvacancy #hours").val(),
- description: $("#frmeditvacancy #description").val(),
- staffuuid: $("#frmeditvacancy #staffuuid").val(),
- type: $("#frmeditvacancy #type").val()
- }
- var savesql = "";
- if (type == 'ins') {
- savesql = "INSERT INTO vacancycalendar (uuid, datefrom, dateto, timefrom, timeto, description, staffuuid, type,vacyear) VALUES "
- +"('" + appdb.generate_uuid() + "', date("+encodeparam(evsvdata.datefrom, 'date')+"), date("+encodeparam(evsvdata.dateto, 'date')+"), "+encodeparam(evsvdata.timefrom, 'text')+", strftime(\"%H:%M\",time("+encodeparam(evsvdata.timefrom, 'text')+",'+"+evsvdata.hours+" hours')), "+encodeparam(evsvdata.description, 'text')+", "+encodeparam(evsvdata.staffuuid, 'text')+","+evsvdata.type+","+encodeparam(evsvdata.datefrom, 'year')+");";
- } else {
- savesql = "UPDATE vacancycalendar SET vacyear=" + encodeparam(evsvdata.datefrom, 'year') + ", datefrom = date("+encodeparam(evsvdata.datefrom, 'date')+"), dateto = date("+encodeparam(evsvdata.dateto, 'date')+"), timefrom = "+encodeparam(evsvdata.timefrom, 'text')+", timeto = strftime(\"%H:%M\",time("+encodeparam(evsvdata.timefrom, 'text')+",'+"+evsvdata.hours+" hours')), description = "+encodeparam(evsvdata.description, 'text')+", staffuuid = "+encodeparam(evsvdata.staffuuid, 'text')+", type = "+evsvdata.type+" WHERE uuid = '"+evsvdata.uuid+"';";
- }
- //dump("VACSAVESQL:" + savesql + "\n");
- appdb.dbexec(savesql);
- load_table_vacancy();
-
- $("#frmeditvacancy #uuid").val("0");
- $("#edit_vacancy").modal('hide');
-}
-
-
-function set_selectyears() {
-
- var years = appdb.dbquery("select strftime('%Y',coalesce(min(entrydate),date('now','-1 year'))) as minyear, strftime('%Y',date('now', '+1 year')) as maxyear from staff where uuid='"+pconfig.uuid+"';");
- var minyear = parseInt(years.sqldata[0].minyear);
- var maxyear = parseInt(years.sqldata[0].maxyear);
- for (var y=minyear;y<=maxyear;y++){
-
- var sel = "";
- if (y == pconfig.year) {
- sel=' selected="1" ';
-
- }
-
- $(".selyear").append("<option value=\""+y+"\""+sel+">"+y+"</option>");
- }
-
-}
-
-// function calcvacancy() {
-// //"Calc Vacancy Data!\n");
-// var csel = "select days,hours from staffvacancydays where staffuuid='"+pconfig.uuid+"' and vacancyyear='"+pconfig.year+"';";
-// //"SQL:"+ csel +"\n");
-// var cnum = appdb.dbquery(csel);
-
-// if (cnum.sqldata.length > 0) {
-// if (pconfig.vacancyunit == "hours"){
-// if ((!cnum.sqldata[0].hours) || (cnum.sqldata[0].hours === "")){
-// cnum.sqldata[0].hours = cnum.sqldata[0].days * 8;
-// }
-// $('#vacancyyeartotal').val(cnum.sqldata[0].hours);
-// }else{
-// $('#vacancyyeartotal').val(cnum.sqldata[0].days);
-// }
-
-// }else {
-// $('#vacancyyeartotal').val("");
-// }
-// var vdays = (($('#vacancyyeartotal').val() === "")?"":cnum.sqldata[0].days);
-// var weekhours = $('#staff_weekhours').val();
-// if (vdays === '') {
-// $('#vacancystatus').html('<div class="alert alert-danger" style="padding: 2px;">Pas de jours de congés configuré pour l\'année '+ pconfig.year+'!</div>');
-// return;
-// }else if (weekhours === '') {
-// $('#vacancystatus').html('<div class="alert alert-danger">Pas de heures par semaine configurées!</div>');
-// return;
-// }
-
-// var vcalcsql = "select printf(\"%.2f\",(sum(dayhours) / ("+weekhours+"/5))) as days, printf(\"%.2f\",SUM(dayhours)) as hours,"+
-// "taken,type,accepted from (" +
-// "select vd.daydate,case when daydate <= date('now') then 1 else 0 end as taken,case when vc.timefrom=vc.timeto then cast ("+weekhours+"/5 as real) else cast(cast(strftime(\"%s\",vc.timeto) as int)- cast(strftime(\"%s\",vc.timefrom) as int) as real)/3600 end as dayhours,type,case when type != -1 then accepted else '1' end as accepted "+
-// "from vacancycalendar vc left join ( "+
-// "select daydate from ( ";
-// var df = new Date(pconfig.year,0,1);
-// var dt = new Date(pconfig.year,11,31);
-// var yd = [];
-// for (var dx=df;dx<=dt;dx.setDate(dx.getDate()+1)){
-// yd.push("select date('"+dx.toLocaleFormat('%Y-%m-%d')+"') as daydate");
-// }
-// vcalcsql += yd.join(" UNION ") +
-// ") yd where strftime('%w',daydate) not in ('0','6') and daydate not in (select vacancydate from vacancy where vacancydate between '"+pconfig.year+"-01-01' and '"+pconfig.year+"-12-31' and vacancydateto is null) " +
-// ") vd on (vd.daydate between vc.datefrom and vc.dateto) " +
-// "left join staffvacancydays svd on (vc.staffuuid=svd.staffuuid) " +
-// "where vc.staffuuid='"+pconfig.uuid+ "' and daydate is not null group by daydate) group by type,taken,accepted;";
-// //dump("SQL2:" + vcalcsql + "\n");
-// var vcalc = appdb.dbquery(vcalcsql);
-// vcalc = vcalc.sqldata;
-// //dump(JSON.stringify(vcalc)+ "\n");
-// vhours = vdays * 8;
-// var vac = {};
-// $("#lblyear").html(pconfig.year);
-// vac.normal = {taken:{hours:0,days:0},open:{vhours:parseFloat(vhours), days:parseFloat(vdays)},accepted:{hours:0,days:0},asked:{hours:0,days:0}};
-// vac.extra = {taken:{hours:0,days:0},open:{hours:0, days:0},accepted:{hours:0,days:0},asked:{hours:0,days:0}};
-// vac.ill = {taken:{hours:0,days:0},open:{hours:0, days:0},accepted:{hours:0,days:0},asked:{hours:0,days:0}};
-// vac.total = {taken:{hours:0,days:0},open:{hours:0, days:0},accepted:{hours:0,days:0},asked:{hours:0,days:0}};
-// //dump(JSON.stringify(vac) + "\n");
-// if (vcalc) {
-// for (var c in vcalc){
-// if (vcalc[c].type == '0' ){ //normal
-// if (vcalc[c].taken == '1'){
-// if (vcalc[c].accepted=='1'){
-// vac.normal.taken.days = vac.normal.taken.days + parseFloat(vcalc[c].days);
-// vac.normal.taken.hours = vac.normal.taken.hours + parseFloat(vcalc[c].hours);
-// } else {
-// vac.normal.asked.days = vac.normal.asked.days + parseFloat(vcalc[c].days);
-// vac.normal.asked.hours = vac.normal.asked.hours + parseFloat(vcalc[c].hours);
-// }
-
-// } else if (vcalc[c].taken == '0') {
-// if (vcalc[c].accepted=='1'){
-// vac.normal.accepted.days = vac.normal.accepted.days + parseFloat(vcalc[c].days);
-// vac.normal.accepted.hours = vac.normal.accepted.hours + parseFloat(vcalc[c].hours);
-// } else {
-// vac.normal.asked.days = vac.normal.asked.days + parseFloat(vcalc[c].days);
-// vac.normal.asked.hours = vac.normal.asked.hours + parseFloat(vcalc[c].hours);
-// }
-
-// }
-// vac.normal.open.days = parseFloat(vdays) - vac.normal.taken.days - vac.normal.accepted.days - vac.normal.asked.days;
-// vac.normal.open.hours = parseFloat(vhours) - vac.normal.taken.hours - vac.normal.accepted.hours - vac.normal.asked.hours;
-// //total
-
-// } else if (vcalc[c].type == '1' ){ //extra
-// if (vcalc[c].taken == '1'){
-// if (vcalc[c].accepted=='1'){
-// vac.extra.taken.days = vac.extra.taken.days + parseFloat(vcalc[c].days);
-// vac.extra.taken.hours = vac.extra.taken.hours + parseFloat(vcalc[c].hours);
-// } else {
-// vac.extra.asked.days = vac.extra.asked.days + parseFloat(vcalc[c].days);
-// vac.extra.asked.hours = vac.extra.asked.hours + parseFloat(vcalc[c].hours);
-// }
-// } else if (vcalc[c].taken == '0'){
-// if (vcalc[c].accepted=='1'){
-// vac.extra.accepted.days = vac.extra.accepted.days + parseFloat(vcalc[c].days);
-// vac.extra.accepted.hours = vac.extra.accepted.hours + parseFloat(vcalc[c].hours);
-// } else {
-// vac.extra.asked.days = vac.extra.asked.days + parseFloat(vcalc[c].days);
-// vac.extra.asked.hours = vac.extra.asked.hours + parseFloat(vcalc[c].hours);
-// }
-// }
-// vac.extra.open.days = 0;
-// vac.extra.open.hours = 0;
-// } else if (vcalc[c].type == '-1' ){ //ill
-// if (vcalc[c].taken == '1'){
-// vac.ill.taken.days = vac.ill.taken.days + parseFloat(vcalc[c].days);
-// vac.ill.taken.hours = vac.ill.taken.hours + parseFloat(vcalc[c].hours);
-// } else if (vcalc[c].taken == '0'){
-// if (vcalc[c].accepted=='1'){
-// vac.ill.accepted.days = vac.ill.accepted.days + parseFloat(vcalc[c].days);
-// vac.ill.accepted.hours = vac.ill.accepted.hours + parseFloat(vcalc[c].hours);
-// } else {
-// vac.ill.asked.days = vac.ill.asked.days + parseFloat(vcalc[c].days);
-// vac.ill.asked.hours = vac.ill.asked.hours + parseFloat(vcalc[c].hours);
-// }
-// }
-// vac.ill.open.days = 0;
-// vac.ill.open.hours = 0;
-
-// }
-// vac.total.taken.days = vac.normal.taken.days + vac.extra.taken.days + vac.ill.taken.days;
-// vac.total.taken.hours = vac.normal.taken.hours + vac.extra.taken.hours + vac.ill.taken.hours;
-// vac.total.open.days = vac.normal.open.days + vac.extra.open.days + vac.ill.open.days;
-// vac.total.open.hours = vac.normal.open.hours + vac.extra.open.hours + vac.ill.open.hours;
-// vac.total.accepted.days = vac.normal.accepted.days + vac.extra.accepted.days + vac.ill.accepted.days;
-// vac.total.accepted.hours = vac.normal.accepted.hours + vac.extra.accepted.hours + vac.ill.accepted.hours;
-// vac.total.asked.days = vac.normal.asked.days + vac.extra.asked.days + vac.ill.asked.days;
-// vac.total.asked.hours = vac.normal.asked.hours + vac.extra.asked.hours + vac.ill.asked.hours;
-// }
-// //JSON.stringify(vac) + "\n");
-// if (pconfig.vacancyunit == 'days'){
-// $("#vacnopen").html(((vac.normal.open.days && vac.normal.open.days != 0)?vac.normal.open.days.toFixed(2)+" j":" "));
-// $("#vacntaken").html(vac.normal.taken.days.toFixed(2)+" j");
-// $("#vacnasked").html(vac.normal.asked.days.toFixed(2)+" j");
-// $("#vacnplanned").html(vac.normal.accepted.days.toFixed(2)+" j");
-
-// $("#vaceopen").html(" ");
-// $("#vacetaken").html(vac.extra.taken.days.toFixed(2)+" j");
-// $("#vaceasked").html(vac.extra.asked.days.toFixed(2)+" j");
-// $("#vaceplanned").html(vac.extra.accepted.days.toFixed(2)+" j");
-
-// $("#vacmopen").html(" ");
-// $("#vacmtaken").html(vac.ill.taken.days.toFixed(2)+" j");
-// $("#vacmasked").html(vac.ill.asked.days.toFixed(2)+" j");
-// $("#vacmplanned").html(vac.ill.accepted.days.toFixed(2)+" j");
-
-// $("#vactopen").html(vac.total.open.days.toFixed(2)+" j");
-// $("#vacttaken").html(vac.total.taken.days.toFixed(2)+" j");
-// $("#vactasked").html(vac.total.asked.days.toFixed(2)+" j");
-// $("#vactplanned").html(vac.total.accepted.days.toFixed(2)+" j");
-// } else {
-// vac.normal.open.hours=vac.normal.open.hours + parseInt($("#vacancylastyearrest").val());
-// $("#vacnopen").html(((vac.normal.open.hours && vac.normal.open.hours != 0)?vac.normal.open.hours.toFixed(2)+" h":" "));
-// $("#vacntaken").html(((vac.normal.taken.hours && vac.normal.taken.hours > 0)?vac.normal.taken.hours.toFixed(2)+" h":" "));
-// $("#vacnasked").html(((vac.normal.asked.hours && vac.normal.asked.hours > 0)?vac.normal.asked.hours.toFixed(2)+" h":" "));
-// $("#vacnplanned").html(((vac.normal.accepted.hours && vac.normal.accepted.hours > 0)?vac.normal.accepted.hours.toFixed(2)+" h":" "));
-
-// $("#vacetaken").html(((vac.extra.taken.hours && vac.extra.taken.hours > 0)?vac.extra.taken.hours.toFixed(2)+" h":" "));
-// $("#vaceasked").html(((vac.extra.asked.hours && vac.extra.asked.hours > 0)?vac.extra.asked.hours.toFixed(2)+" h":" "));
-// $("#vaceplanned").html(((vac.extra.accepted.hours && vac.extra.accepted.hours > 0)?vac.extra.accepted.hours.toFixed(2)+" h":" "));
-
-// $("#vacmtaken").html(((vac.ill.taken.hours && vac.ill.taken.hours > 0)?vac.ill.taken.hours.toFixed(2)+" h":" "));
-// $("#vacmasked").html(((vac.ill.asked.hours && vac.ill.asked.hours > 0)?vac.ill.asked.hours.toFixed(2)+" h":" "));
-// $("#vacmplanned").html(((vac.ill.accepted.hours && vac.ill.accepted.hours > 0)?vac.ill.accepted.hours.toFixed(2)+" h":" "));
-
-// $("#vactopen").html(((vac.total.open.hours && vac.total.open.hours > 0)?vac.total.open.hours.toFixed(2)+" h":" "));
-// $("#vacttaken").html(((vac.total.taken.hours && vac.total.taken.hours > 0)?vac.total.taken.hours.toFixed(2)+" h":" "));
-// $("#vactasked").html(((vac.total.asked.hours && vac.total.asked.hours > 0)?vac.total.asked.hours.toFixed(2)+" h":" "));
-// $("#vactplanned").html(((vac.total.accepted.hours && vac.total.accepted.hours > 0)?vac.total.accepted.hours.toFixed(2)+" h":" "));
-
-// }
-
-// //dump(JSON.stringify(vac) + " - Set data vacancy status\n");
-// // var hdata = " <span style=\"font-weight: normal;\"><span style=\"text-decoration: underline;\">pris:</span> <strong>"+ vac.taken.hours +" h</strong> ("+ vac.taken.days.toFixed(2)+" jour(s)) - ";
-// // hdata += " <span style=\"text-decoration: underline;\">planifié:</span> <strong>"+ vac.rest.hours+" h</strong> ("+ vac.rest.days.toFixed(2)+" jour(s)) - ";
-// // hdata += " <span style=\"text-decoration: underline;\">ouvert:</span> <strong>"+ vac.open.hours +" h</strong> ("+ vac.open.days.toFixed(2)+" jour(s))";
-// // if (vac.ill > 0) {
-// // hdata += " - (<span style=\"text-decoration: underline;\">maladie:</span> <strong>"+ vac.ill.hours+" h</strong> ("+ vac.ill.days.toFixed(2)+" jour(s)))</span>";
-// // }
-// //dump("HTML: --" + document.getElementById("vacancystatus").innerHTML +"//\n->" + hdata + "\n");
-// //$("#vacancystatus").html("");
-// //if ($("#vacancystatus")){
-// //dump("vacancystatus exists\n");
-// //
-// //}
-// $("#vacancystatus").html("");
-// }
-// else {
-// $("#vacancystatus").html("");
-// }
-// }
-
-function saveyearvacdays() {
- var csel = "select * from staffvacancydays where staffuuid='"+pconfig.uuid+"' and vacancyyear='"+pconfig.year+"';";
- var days = 0;
- var hours = 0;
- if ($('#vacancyyeartotal').val() === ""){
- return;
- }
- if (pconfig.vacancyunit == "hours"){
- days = parseFloat($('#vacancyyeartotal').val().replace(',','.')) / 8;
- hours = $('#vacancyyeartotal').val();
- }else {
- days = parseFloat($('#vacancyyeartotal').val().replace(',','.'));
- hours = parseFloat($('#vacancyyeartotal').val().replace(',','.')) * 8;
- }
- var cnum = appdb.dbquery(csel);
- var inssql = "INSERT INTO staffvacancydays (staffuuid,vacancyyear,days,hours) VALUES ('"+pconfig.uuid+"','"+pconfig.year+"',"+days+","+hours+");";
- if (cnum.sqldata.length > 0) {
- inssql = "UPDATE staffvacancydays SET days="+days+",hours="+hours+" where staffuuid='"+pconfig.uuid+"' and vacancyyear='"+pconfig.year+"';";
- }
- appdb.dbexec(inssql);
- //calcvacancy();
-}
-
-// function setvacancyunit(){
-// var vacunit = $('#vacancy_unit').val();
-// if ($('#vacancyyeartotal').val() !== ""){
-// var vacval = parseFloat($('#vacancyyeartotal').val().replace(',','.'));
-// if (((!pconfig.vacancyunit) || (pconfig.vacancyunit == 'days')) && (vacunit == 'hours')){
-// $('#vacancyyeartotal').val(vacval * 8);
-// }else if (pconfig.vacancyunit != vacunit){
-// $('#vacancyyeartotal').val(vacval / 8);
-// }
-// }
-// //dump("vacunit: " + vacunit + "\n");
-// pconfig.vacancyunit = vacunit;
-// apppref.setpreference("pageconfig.coworker",pconfig);
-// }
-
-function dlg_event(uuid, type) {
-
- //$('#staffuuid').multiselect('deselectAll', false);
- //$('#staffuuid').multiselect('updateButtonText');
- if (type== "ins") {
-
- $('#btndeleteevent').hide();
-
- }else {
- $('#btndeleteevent').show();
- }
- $('#frmeditevent #freqinterval').hide();
- $('#frmeditevent #freqmonthly').hide();
- $('#frmeditevent #freqweekly').hide();
- $('#frmeditevent #freq_monthly_byday').show();
- $('#frmeditevent #freq_monthly_bymonthday').hide();
- $('#frmeditevent #freq').val("");
- $('#frmeditevent .active').removeClass('active');
- if ((type == 'upd') || (type == 'ins')) {
-
- var evdata = {
- uuid: '0',
- description: '',
- activityuuid:'',
- location: '',
- color: '',
- datefrom:new Date().toLocaleFormat("%d.%m.%Y"),
- dateto:'',
- staffuuid: pconfig.uuid,
- timefrom: '00:00',
- timeto: '00:00',
- freq: '',
- staffname: $("#staff_prename").val() + " " + $("#staff_surname").val()
- };
- //jsdump(JSON.stringify(pconfig) + "\n");
- //jsdump(JSON.stringify(evdata) + "\n");
- if (type == 'upd') {
- var evsql = "SELECT uuid, strftime(\"%d.%m.%Y\",datefrom) as datefrom, strftime(\"%d.%m.%Y\",dateto) as dateto, timefrom, timeto, description, location, color, freq, '"+ pconfig.uuid+"' as staffuuid FROM eventcalendar ev left join staffplanning st on (ev.uuid=st.eventcalendaruuid) where ev.uuid='" + uuid.uuid + "' group by ev.uuid;";
- evdata = appdb.dbquery(evsql);
- evdata = evdata.sqldata[0];
- evdata['staffname'] = $("#staff_prename").val() + " " + $("#staff_surname").val();
- if (evdata.freq != '') {
- var tmpfreq = evdata.freq.split(';');
- for (var t in tmpfreq){
- if (tmpfreq[t] != '') {
- var spl = tmpfreq[t].split("=");
- evdata[spl[0].toLowerCase()] = spl[1].toLowerCase();
- }
- }
- }
- }
- for (var w in evdata) {
- if ($("#frmeditevent #" + w)) {
- // if (w == 'staffuuid') {
- // if (evdata[w] == '') {
- // $("#frmeditevent #" + w).multiselect('select',[]);
- // } else {
- // $("#frmeditevent #" + w).multiselect('select',evdata[w].split(','));
- // }
-
- // }
- // else if (w == 'color') {
- // $("#frmeditevent #color").val(evdata[w]);
- // $('#frmeditevent #color').minicolors('value',{color: evdata[w]});
- // }
- // else {
- $("#frmeditevent #" + w).val(evdata[w]);
- // }
- }
- }
- if ((evdata.freq == 'weekly') && (evdata.byday)) {
- var bd = evdata.byday.split(',');
- for (var i in bd){
- document.getElementById('weekly_byday_' + bd[i]).setAttribute("checked",true);
- $('#frmeditevent #weekly_byday_' + bd[i]).parent().addClass("active");
- }
- }
- if (evdata.freq == 'monthly') {
- $('#freq_monthly_byday').hide();
- $('#freq_monthly_bymonthday').hide();
- $('#pnl_monthly_byday').removeAttr("checked");
- $('#pnl_monthly_bymonthday').removeAttr("checked");
- if (evdata.byday) {
- document.getElementById('pnl_monthly_byday').setAttribute("checked",true);
- $('#frmeditevent #pnl_monthly_byday').parent().addClass("active");
- $('#freq_monthly_byday').show();
- var bd = evdata.byday.split(',');
- var adpos = new Array();
- var awday = new Array();
- for (var i in bd){
- var wday = bd[i].substr(bd[i].length-2);
- var pos = bd[i].substring(0,bd[i].length-2);
- awday.push(wday.toLowerCase());
- adpos.push(pos);
- }
-
- for (var i in adpos){
- document.getElementById('monthly_bydaypos_' + adpos[i]).setAttribute("checked",true);
- $('#frmeditevent #monthly_bydaypos_' + adpos[i]).parent().addClass("active");
- }
- for (var i in awday){
- document.getElementById('monthly_bydaywday_' + awday[i]).setAttribute("checked",true);
- $('#frmeditevent #monthly_bydaywday_' + awday[i]).parent().addClass("active");
- }
- }else if (evdata.bymonthday) {
- document.getElementById('pnl_monthly_bymonthday').setAttribute("checked",true);
- $('#frmeditevent #pnl_monthly_bymonthday').parent().addClass("active");
- $('#freq_monthly_bymonthday').show();
- var bd = evdata.bymonthday.split(',');
- for (var i in bd){
- document.getElementById('monthly_bymonthday_' + bd[i]).setAttribute("checked",true);
- $('#frmeditevent #monthly_bymonthday_' + bd[i]).parent().addClass("active");
- }
- }
- }
- setfreq();
- $("#edit_event").modal('show');
- }
-}
-
-
-function save_event() {
- var sql1 = new Array();
- var sql2 = new Array();
- if ($('#timefrom').val() == $('#timeto').val() || $('#timefrom').val() == "00:00" || $('#timeto').val() == "00:00"){
- errormsg("Erreur","les heures doivent être différent et différent de la valeur 00:00!");
- return false;
- }
- if ($('#timefrom').val() > $('#timeto').val()){
- errormsg("Erreur","l'heure de début ne peux pas être supérieur à l'heure de fin!");
- return false;
- }
- if (!$('#staffuuid').val()){
- errormsg("Erreur","Vous devez selectionner au moin 1 membre du staff!");
- return false;
- }
- if ($('#dateto').val() != '' && (encodeparam($('#datefrom').val()) > encodeparam($('#dateto').val())) ) {
- errormsg("Erreur","La Date début ne peut pas être supérieur à la date fin!");
- return false;
- }
- var type = 'ins';
- var cuuid = "";
- if ($("#frmeditevent #uuid").val() != 0) {
- type = 'upd';
- cuuid = $("#frmeditevent #uuid").val();
- } else {
- cuuid = appdb.generate_uuid();
- }
- var freqdata = {};
- var cfreq = $("#frmeditevent #freq").val();
- $("#frmeditevent :input").each(function() {
- var input = $(this);
-
- if (input.attr("id") && (input.attr("id") != "staffuuid") && (input.attr("id") != "staffname")) {
- if ((input.attr("type") == "checkbox") && (input.attr("id").indexOf(cfreq) >= 0)){
- var xd = input.attr("id").split("_");
- if (input.attr("checked")) {
- if (!freqdata[xd[1]]) {
- freqdata[xd[1]] = new Array();
- }
- freqdata[xd[1]].push(input.val());
- }
- }
- else if ((input.attr("type") == "radio") && (input.attr("id").indexOf(cfreq) >= 0)) {
- var xd = input.attr("id").split("_");
- if (input.attr("checked")) {
- freqdata['freqtype'] = xd[2];
- }
- }
- else if ((input.attr("type") != "checkbox") && ((input.attr("type") != "radio"))){
- if ((input.attr("id") == 'interval') || (input.attr("id") == 'freq')) {
- freqdata[input.attr("id")] = input.val();
- } else if ((type == 'ins') && (input.attr("id") != 'staffuuid')) {
-
- sql1.push('"' + input.attr("id") + '"');
- if (input.attr("id") == 'uuid') {
- if (input.val() == "" || input.val() == "0") {
- sql2.push("'" + cuuid + "'");
- } else {
- sql2.push("'" + input.val() + "'");
- }
- } else {
- var ival = encodeparam(input.val(), input.attr('type'));
- sql2.push(ival);
- }
- } else {
- if ((input.attr("id") != 'uuid') && (input.attr("id") != 'staffuuid')){
- var ival = encodeparam(input.val(), input.attr('type'));
- sql2.push('"' + input.attr("id") + '"=' + ival);
- }
- }
- }
- }
-
- });
- if (!freqdata.freqtype) {
- freqdata['freqtype'] = curfreq.freqtype;
- }
-
- var strfreq ="";
- if (cfreq != "") {
- strfreq='FREQ=' + cfreq.toUpperCase()+';INTERVAL=' + freqdata.interval +';';
- if ((cfreq == 'weekly') && (freqdata.byday)){
- strfreq += 'BYDAY=' + freqdata.byday.join(",");
- }
- if ((cfreq == 'monthly') && (freqdata.bydaypos) || ((freqdata.bydaywday)) || (freqdata.bymonthday)){
- strfreq += freqdata.freqtype.toUpperCase() + '=';
- if (freqdata.freqtype == 'bymonthday') {
- strfreq += freqdata.bymonthday.join(',') + ";"
- }else {
- var abyday = new Array();
- for (var p in freqdata.bydaypos){
- for (var w in freqdata.bydaywday){
- abyday.push(freqdata.bydaypos[p] + freqdata.bydaywday[w]);
- }
- }
- strfreq += abyday.join(",");
- }
- }
- if (strfreq.slice(-1) == ';') {
- strfreq = strfreq.substring(0,strfreq.length-1);
- }
- }
- var staffuuids = $('#staffuuid').val();
- var delsql = "";
- var xsql = [];
- if (type != 'ins') {
- xsql.push("DELETE FROM staffplanning where eventcalendaruuid = '"+cuuid+"';");
- }
- var staffinssql = "";
-
- if (staffuuids && (staffuuids.length != 0)) {
-
- staffinssql = "INSERT INTO staffplanning (eventcalendaruuid,staffuuid) VALUES ";
- var tmps = [];
- var curcoworkerok = false;
- for (var s in staffuuids){
- if (staffuuids[s] == pconfig.uuid){
- curcoworkerok = true;
- }
- tmps.push("('"+cuuid+"','"+staffuuids[s]+"')");
- }
- if (!curcoworkerok){
- tmps.push("('"+cuuid+"','"+pconfig.uuid+"')");
- }
- staffinssql += tmps.join(',') + ";";
- xsql.push(staffinssql);
- }
- if (staffuuids.length == 0){
- staffinssql = "INSERT INTO staffplanning (eventcalendaruuid,staffuuid) VALUES ('"+cuuid+"','"+pconfig.uuid+"');";
- xsql.push(staffinssql);
- }
-
-
-
- if (type == 'upd') {
- sql2.push('freq=' + encodeparam(strfreq));
- xsql.push("UPDATE eventcalendar SET " + sql2.join(',') + " where \"uuid\"='" + cuuid + "';");
- } else {
- sql1.push('freq');
- sql2.push(encodeparam(strfreq));
- xsql.push("INSERT INTO eventcalendar (" + sql1.join(',') + ") VALUES (" + sql2.join(',') + ");");
- }
- dump(JSON.stringify(xsql));
- for (var i in xsql){
- appdb.dbexec(xsql[i]);
- }
-
- load_event_data();
-
- $("#frmeditevent #uuid").val("0");
- $("#edit_event").modal('hide');
-}
-
-function confirm_delete_event() {
- $("#confirm_delete_event").modal('show');
- return false;
-}
-
-function delete_event() {
- appdb.dbexec("DELETE FROM eventcalendar where uuid='" + $('#frmeditevent #uuid').val()+"';");
- appdb.dbexec("DELETE FROM staffplanning where eventcalendaruuid='" + $('#frmeditevent #uuid').val()+"';");
- load_event_data();
- $("#confirm_delete_event").modal('hide');
-
- return false;
-}
-
-
-
-function setfreq() {
-
- curfreq.freq = $('#freq option:selected').val();
-
- $('#freqinterval').hide();
- $('#freqmonthly').hide();
- $('#freqweekly').hide();
- if (curfreq.freq != "") {
-
- $('#lblfreq').text(lblfreq[curfreq.freq]);
- $('#freqinterval').show();
- if (curfreq.freq != 'daily') {
- $('#freq' + curfreq.freq).show();
- }
- }
-
-}
-
-// function load_staff_selection(objid,option){
-// var stdata = appdb.dbquery("select uuid, coalesce(surname,'') || ' ' || coalesce(prename,'') as name,case when color is null then '#000' else color end as color from staff order by surname,prename");
-
-// stdata = stdata.sqldata;
-// for (var s in stdata){
-// $('#' + objid).append('<option value="'+ stdata[s].uuid+'"><span style="color: '+stdata[s].color+';" >' +stdata[s].name+ '</span></option>');
-// }
-
-// var copt = {};
-// if (option) {
-// copt = option;
-// }
-// copt['enableHTML'] = true;
-// copt['nonSelectedText']="Sélectionner un(e) employé(e)...";
-// copt['numberDisplayed']=5;
-// copt['allSelectedText']='Tous';
-// copt['nSelectedText']=' selections';
-
-// $('#' + objid).multiselect(copt);
-
-// }
-
-function accept_vacancy(){
- var cuuid = "";
- if ($("#frmeditvacancy #uuid").val() != 0) {
- type = 'upd';
- cuuid = $("#frmeditvacancy #uuid").val();
- }
- var xsql = "UPDATE vacancycalendar SET accepted='1' where \"uuid\"='" + cuuid + "';";
- appdb.dbexec(xsql);
- load_table_vacancy();
-
- $("#frmeditvacancy #uuid").val("0");
- $("#edit_vacancy").modal('hide');
-}
-
-function getlastyearsrest(){
- var weekhours = $('#staff_weekhours').val();
- if (weekhours === '') {
- $("#vacancylastyearrest").val(0);
- return;
- }
- var df = new Date(pconfig.year-1,0,1);
- var dt = new Date(pconfig.year-1,11,31);
- var vcalcrestsql = "select (select hours from staffvacancydays where staffuuid='"+pconfig.uuid+ "' and vacancyyear="+df.getFullYear()+")-SUM(dayhours) AS hours from (" +
- "select vd.daydate,case when daydate <= date('now') then 1 else 0 end as taken,case when vc.timefrom=vc.timeto then cast ("+weekhours+"/5 as real) else (cast (substr(vc.timeto,1,2) as int) + (cast(substr(vc.timeto,4,5) as int)/60)) - (cast(substr(vc.timefrom,1,2) as int) + (cast(substr(vc.timeto,4,5) as int)/60)) end as dayhours,type,case when type != -1 then accepted else '1' end as accepted "+
- "from vacancycalendar vc left join ( "+
- "select daydate from ( ";
-
- var yd = [];
- for (var dx=df;dx<=dt;dx.setDate(dx.getDate()+1)){
- yd.push("select date('"+dx.toLocaleFormat('%Y-%m-%d')+"') as daydate");
- }
- vcalcrestsql += yd.join(" UNION ") +
- ") yd where strftime('%w',daydate) not in ('0','6') and daydate not in (select vacancydate from vacancy where vacancydate between '"+df.getFullYear()+"-01-01' and '"+dt.getFullYear()+"-12-31' and vacancydateto is null) " +
- ") vd on (vd.daydate between vc.datefrom and vc.dateto) " +
- "left join staffvacancydays svd on (vc.staffuuid=svd.staffuuid) " +
- "where vc.staffuuid='"+pconfig.uuid+ "' and daydate is not null group by daydate) where type in (0,1) and taken=1 and accepted=1 group by taken,accepted;";
- //dump("SQLREST:" + vcalcrestsql + "\n");
- var vcalc = appdb.dbquery(vcalcrestsql);
- //dump(JSON.stringify(vcalc) + "\n");
- if (vcalc && vcalc.sqldata[0]){
-
- $("#vacancylastyearrest").val(vcalc.sqldata[0].hours);
- }else {
- $("#vacancylastyearrest").val(0);
- }
- return;
-}