bugfix child planning and daily presence
authorKilian Saffran <ksaffran@dks.lu>
Wed, 15 May 2019 14:57:42 +0000 (16:57 +0200)
committerKilian Saffran <ksaffran@dks.lu>
Wed, 15 May 2019 14:57:42 +0000 (16:57 +0200)
apps/data/db/underatert.sqlite
apps/tmpl/creorga/modules/childs/js/child.js
apps/tmpl/creorga/modules/presences/js/dailypresences.js

index 6aa861c..9bbf391 100644 (file)
Binary files a/apps/data/db/underatert.sqlite and b/apps/data/db/underatert.sqlite differ
index 9b8bb78..39fd720 100644 (file)
@@ -384,11 +384,11 @@ var labelx = getlabelswithkey('mother,father,tuteur,famillymember,famillyfriend'
 }
 
 function dlg_planning(uuid, type, planuuid) {
-  //"dlg_planning" + uuid + " " + type + " " + planuuid + "\n");
+  //console.log("dlg_planning" + uuid + " " + type + " " + planuuid);
   if (type == 'upd') {
     check_birthdate_valid();
     setplanning_groups();
-    var plandata = parent.appdb.dbquery("SELECT strftime('%d.%m.%Y',datebegin) as datebegin, strftime('%d.%m.%Y',dateend) as dateend, montimebegin, montimeend, monlunch, tuetimebegin, tuetimeend, tuelunch, wedtimebegin, wedtimeend, wedlunch, thutimebegin, thutimeend, thulunch, fritimebegin, fritimeend, frilunch, sattimebegin, sattimeend, satlunch, suntimebegin, suntimeend, sunlunch, childuuid, uuid, groupuuid, montimebegin2, montimeend2, tuetimebegin2, tuetimeend2, wedtimebegin2, wedtimeend2, thutimebegin2, thutimeend2, fritimebegin2, fritimeend2, sattimebegin2, sattimeend2, suntimebegin2, suntimeend2 FROM planning where uuid='" + uuid.uuid + "';");
+    var plandata = parent.appdb.dbquery("SELECT datebegin, dateend, montimebegin, montimeend, monlunch, tuetimebegin, tuetimeend, tuelunch, wedtimebegin, wedtimeend, wedlunch, thutimebegin, thutimeend, thulunch, fritimebegin, fritimeend, frilunch, sattimebegin, sattimeend, satlunch, suntimebegin, suntimeend, sunlunch, childuuid, uuid, groupuuid, montimebegin2, montimeend2, tuetimebegin2, tuetimeend2, wedtimebegin2, wedtimeend2, thutimebegin2, thutimeend2, fritimebegin2, fritimeend2, sattimebegin2, sattimeend2, suntimebegin2, suntimeend2 FROM planning where uuid='" + uuid.uuid + "';");
     plandata = plandata.sqldata[0];
 
     for (var p in plandata) {
@@ -484,6 +484,7 @@ function dlg_planning(uuid, type, planuuid) {
         //plansql = "select * from ( select CASE WHEN DATE(birthday,'+' || minage || ' months') < entrydate THEN entrydate ELSE DATE(birthday,'+' || minage || ' months') END AS datebegin, case when date(birthday,'+' || maxage || ' months') > leavedate then leavedate else date(birthday,'+' || maxage || ' months','-1 day') end as dateend, pl.uuid as groupuuid, montimeopen as montimebegin,montimeclose as montimeend,tuetimeopen as tuetimebegin,tuetimeclose as tuetimeend,wedtimeopen as wedtimebegin,wedtimeclose as wedtimeend,thutimeopen as thutimebegin,thutimeclose as thutimeend,fritimeopen as fritimebegin,fritimeclose as fritimeend,sattimeopen as sattimebegin,sattimeclose as sattimeend,null as montimebegin2, null as montimeend2, null as tuetimebegin2, null as tuetimeend2,   null as wedtimebegin2, null as wedtimeend2, null as thutimebegin2, null as thutimeend2, null as fritimebegin2, null as fritimeend2, null as sattimeend2,1 as monlunch,1 as tuelunch, 1 as wedlunch, 1 as thulunch, 1 as frilunch, 1 as satlunch from ( select uuid,minage,maxage,grpname,(select birthday from childs where childs.uuid='" + pconfig.uuid + "') as birthday,date('" + curplan.entrydate +"') AS entrydate,date('" + curplan.leavedate +"') AS leavedate from groups) pl join workinghours wk on (wk.datestart <= datebegin) group by groupuuid order by wk.datestart DESC,minage,maxage ) where datebegin!=dateend and dateend >= datebegin and order by datebegin,dateend;";
         if (planuuid){
           plansql = "select * from ( select CASE WHEN DATE(birthday,'+' || minage || ' months') < entrydate THEN entrydate ELSE DATE(birthday,'+' || minage || ' months') END AS datebegin, case when date(birthday,'+' || maxage || ' months') > leavedate then leavedate else date(birthday,'+' || maxage || ' months','-1 day') end as dateend, pl.uuid as groupuuid, plt.* from ( select uuid,minage,maxage,grpname,'"+pconfig.uuid+"' as chuuid,(select birthday from childs where childs.uuid='" + pconfig.uuid + "') as birthday, date('"+ curplan.entrydate+"') AS entrydate,date('" + curplan.leavedate +"') AS leavedate from groups) pl join workinghours wk on (wk.datestart <= datebegin) join (select '" + pconfig.uuid + "' as chuuid,* from planningtemplate where planningtemplate.uuid='"+planuuid+"') plt on (plt.chuuid=pl.chuuid) group by groupuuid order by wk.datestart DESC,minage,maxage ) where datebegin!=dateend and dateend >= datebegin order by datebegin,dateend;";
+          //console.log(plansql);
           var plandata = parent.appdb.dbquery(plansql);
       
       for (var pl in plandata.sqldata) {
@@ -662,7 +663,8 @@ function save_planning() {
   var sdateend = encodeparam($("#frmeditplanning #dateend").val(),'date');
   var checkdatereplace = parent.appdb.dbquery("select uuid from planning where datebegin >= "+sdatebegin+" and dateend <= "+sdateend+" and childuuid='"+pconfig.uuid+"';");
   checkdatereplace = checkdatereplace.sqldata;
-  if (checkdatereplace.length > 0) {
+  //console.log(checkdatereplace);
+  if (checkdatereplace && Object.keys(checkdatereplace).length > 0) {
 
     var ruuid = new Array();
     for (var i in checkdatereplace){
@@ -672,7 +674,7 @@ function save_planning() {
   }
   var checkdatesplit = parent.appdb.dbquery("select uuid,dateend from planning where datebegin <= "+sdatebegin+" and dateend >= "+sdateend+" and childuuid='"+pconfig.uuid+"';");
   checkdatesplit = checkdatesplit.sqldata;
-  if (checkdatesplit.length == 1) {
+  if (checkdatesplit && Object.keys(checkdatesplit).length == 1) {
 
     var newuuid = parent.appdb.generate_uuid();
     parent.appdb.dbexec("INSERT INTO planning (datebegin, dateend, montimebegin, montimeend, monlunch, tuetimebegin, tuetimeend, tuelunch, wedtimebegin, wedtimeend, wedlunch, thutimebegin, thutimeend, thulunch, fritimebegin, fritimeend, frilunch, sattimebegin, sattimeend, satlunch, suntimebegin, suntimeend, sunlunch, childuuid, uuid, groupuuid, montimebegin2, montimeend2, tuetimebegin2, tuetimeend2, wedtimebegin2, wedtimeend2, thutimebegin2, thutimeend2, fritimebegin2, fritimeend2, sattimebegin2, sattimeend2, suntimebegin2, suntimeend2) SELECT date("+sdateend+",'+1 day'), dateend, montimebegin, montimeend, monlunch, tuetimebegin, tuetimeend, tuelunch, wedtimebegin, wedtimeend, wedlunch, thutimebegin, thutimeend, thulunch, fritimebegin, fritimeend, frilunch, sattimebegin, sattimeend, satlunch, suntimebegin, suntimeend, sunlunch, childuuid, '"+newuuid+"', groupuuid, montimebegin2, montimeend2, tuetimebegin2, tuetimeend2, wedtimebegin2, wedtimeend2, thutimebegin2, thutimeend2, fritimebegin2, fritimeend2, sattimebegin2, sattimeend2, suntimebegin2, suntimeend2 FROM planning where uuid='"+ checkdatesplit[0].uuid +"';");
@@ -681,11 +683,11 @@ function save_planning() {
   
   var checkdatefrom = parent.appdb.dbquery("select uuid from planning where datebegin between "+sdatebegin+" and "+sdateend+" and childuuid='"+pconfig.uuid+"';");
   var checkdateto = parent.appdb.dbquery("select uuid from planning where dateend between "+sdatebegin+" and "+sdateend+" and childuuid='"+pconfig.uuid+"';");
-  if (checkdatefrom.sqldata.length == 1) {
+  if (checkdatefrom.sqldata && Object.keys(checkdatefrom.sqldata).length == 1) {
 
     parent.appdb.dbexec("update planning set datebegin=date("+encodeparam($("#frmeditplanning #dateend").val(),'date')+",'+1 day') where uuid='"+checkdatefrom.sqldata[0].uuid+"'");
   }
-  if (checkdateto.sqldata.length == 1) {
+  if (checkdateto.sqldata && Object.keys(checkdateto.sqldata).length == 1) {
 
     parent.appdb.dbexec("update planning set dateend=date("+encodeparam($("#frmeditplanning #datebegin").val(),'date')+",'-1 day') where uuid='"+checkdateto.sqldata[0].uuid+"'");
   }
index c22b68d..953a308 100644 (file)
@@ -81,9 +81,11 @@ $('input[id^="txt"]').on('keydown',function(e){
   }
   
 });
-$('input[id^="txt"]').focusout(function(e){
-  savetime($(this));
-});
+// $('input[id^="txt"]').on('blur',function(e){
+//     console.log($(this).attr("id"));
+//     savetime($(this));
+//   }
+// );
 
 function initdata() {
       load_helpers();
@@ -143,16 +145,16 @@ function loadtable(){
               rdata += '<td style="min-width: 350px;max-width: 350px;"><div class="form-inline" id="frm_'+ row.childuuid +'" style="white-space: nowrap; '+ ((row.status != 0 && row.status != 1 && row.status != 5)?"display: none":"")+'">'+
             '<span class="glyphicon glyphicon-time" aria-hidden="true"></span> de: '+
                     '<div class="input-group bootstrap-timepicker time" style="width: 70px;"> ' +
-                      '<input type="text" class="form-control timepicker dailypresence" placeholder="00:00" value="'+ row.begintime1+'" id="txtbegintime1_'+row.childuuid+'" onClick="timefocus(this);"></div> '+
+                      '<input type="text" class="form-control timepicker dailypresence" placeholder="00:00" value="'+ row.begintime1+'" id="txtbegintime1_'+row.childuuid+'" onClick="timefocus(this);" onBlur="savetime(this);"></div> '+
                     ' à: '+
                     '<div class="input-group bootstrap-timepicker time" style="width: 70px;">'+
-                      '<input type="text" class="form-control timepicker dailypresence" placeholder="00:00" value="'+row.endtime1+'" id="txtendtime1_'+row.childuuid+'" data-ddltype="'+row.ddltype+'" onClick="timefocus(this);"></div>' +
+                      '<input type="text" class="form-control timepicker dailypresence" placeholder="00:00" value="'+row.endtime1+'" id="txtendtime1_'+row.childuuid+'" data-ddltype="'+row.ddltype+'" onClick="timefocus(this);"  onBlur="savetime(this);"></div>' +
                       'et de: '+
                       '<div class="input-group bootstrap-timepicker time" style="width: 70px;"> ' +
-                        '<input type="text" class="form-control timepicker dailypresence" placeholder="00:00" value="'+ row.begintime2+'" id="txtbegintime2_'+row.childuuid+'" data-ddltype="'+row.ddltype+'" onClick="timefocus(this);"></div> '+
+                        '<input type="text" class="form-control timepicker dailypresence" placeholder="00:00" value="'+ row.begintime2+'" id="txtbegintime2_'+row.childuuid+'" data-ddltype="'+row.ddltype+'" onClick="timefocus(this);"  onBlur="savetime(this);"></div> '+
                       ' à: '+
                       '<div class="input-group bootstrap-timepicker time" style="width: 70px;">'+
-                        '<input type="text" class="form-control timepicker dailypresence" placeholder="00:00" value="'+row.endtime2+'" id="txtendtime2_'+row.childuuid+'" data-ddltype="'+row.ddltype+'" onClick="timefocus(this);"></div>' +
+                        '<input type="text" class="form-control timepicker dailypresence" placeholder="00:00" value="'+row.endtime2+'" id="txtendtime2_'+row.childuuid+'" data-ddltype="'+row.ddltype+'" onClick="timefocus(this);"  onBlur="savetime(this);"></div>' +
                     '</div><br/><span id="'+row.childuuid+'_ddltype" style="display: none;">'+row.ddltype+'</span></td>';
               rdata += '<td>'+ 
               '<div class="btn-group"><button type="button" class="btn btn-default dropdown-toggle" data-status="'+ row.status+'"  id="btn_' + row.childuuid + '" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="glyphicons glyphicons-circle-question-mark" ></span></button>' +
@@ -198,8 +200,12 @@ function loadtable(){
 }
 
 function savetime(obj){
-      var fdata =obj.attr('id').split("_");
-                  var timeval = obj.val();
+      var fdata =obj.id.split("_");
+      //console.log('savetime');
+      //console.log(fdata);
+
+                  var timeval = obj.value;
+      //console.log("Tval 1:" + timeval);
                   var ddltype = $("#" + fdata[1]+ "_ddltype").html();
 
                   var psqltime = "";
@@ -208,11 +214,11 @@ function savetime(obj){
                   }else{
                         timeval = timeval.replace(/[^\d]/g, '') + "0000";
                         timeval = timeval.substring(0,2) + ":" + timeval.substring(2,4);
-                        $("#" + obj.attr('id')).val(timeval);
+                        $("#" + obj.id).val(timeval);
                         timeval = "'" + timeval + "'";
                   }
                   
-                  
+        //          console.log("Tval 2:" + timeval);
                   if (ddltype == 'upd'){
                          
                          if (fdata[0] == "txtbegintime1"){
@@ -232,6 +238,7 @@ function savetime(obj){
                          psqltime +=  "(1,'" + fdata[1] + "',date('" + initdate.toISOString().substring(0,10) + "')," + 
                          ((($("#planlunch_" + fdata[1]).exists()) && ($("#planlunch_" + fdata[1]).html() != ''))?"'1'":'null') + ","+timeval+");";
                   }
+                //  console.log(psqltime);
                   if (psqltime !== ""){
 
                         parent.appdb.dbexec(psqltime);