var ccreche = appdb.dbquery("select uuid from creche LIMIT 1;");
crecheuuid = ccreche.sqldata[0].uuid;
importpath = FileUtils.File(curcfg.path.local + system.sep() +"imports" + system.sep() + crecheuuid);
- check_accountingtable();
+ //check_accountingtable();
load_childlist();
if (pconfig.accchild) {
//
function load_accounting_table(){
//dump("accountingchild: " + JSON.stringify(pconfig) + "\n");
- var daterangesql = "select case when strftime('%Y',date(yeardaybegin)) == '"+pconfig.accyear+"' then yeardaybegin else strftime('%Y-%m-%d',date(date(yeardaybegin),'+7 days')) end as yeardaybegin,"+
- "strftime('%Y-%m-%d',date(date(yeardayend),'+6 days')) as yeardayend "+
- "from ( " +
- "select case when strftime('%w','"+pconfig.accyear+"-01-01') = '1' then strftime('%Y-%m-%d','"+pconfig.accyear+"-01-01') else strftime('%Y-%m-%d', date(date('"+pconfig.accyear+"-01-01','-7 days'),'weekday 1')) end as yeardaybegin, "+
- "case when strftime('%w','"+pconfig.accyear+"-12-31') = '1' then strftime('%Y-%m-%d','"+pconfig.accyear+"-12-31') else strftime('%Y-%m-%d', date(date('"+pconfig.accyear+"-12-31','-7 days'),'weekday 1')) end as yeardayend "+
- ");";
- var daterange = appdb.dbquery(daterangesql);
- daterange = daterange.sqldata[0];
- var yearmin = daterange.yeardaybegin;
- var yearmax = daterange.yeardayend;
-
-
- var chbornes = appdb.dbquery("select min(daydate) as mindate,max(daydate) as maxdate from presence where strftime('%Y',daydate)='" + pconfig.accyear + "' and childuuid='" + pconfig.accchild + "';");
-
- var monthmin= chbornes.sqldata[0].mindate;
- var monthmax= chbornes.sqldata[0].maxdate;
- var accsql = "select strftime( '%m.%Y',acc.accmonth) as calmonth,'' as weekdetails, '' as monthtotalhourcosts,'' as monthtotallunchcosts, '' as monthtotalcosts,replace(acc.reference,'NOCHECKSERVICE:','<span style=\"color: red;\">(facture non check-service)</span><br/>') as reference, " +
- "case when acc.invoiceamount is not null then printf(\"%.2f\",COALESCE(acc.invoiceamount,0.00)) || '€' || case when acc.invoicedate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.invoicedate) || ')' || CASE WHEN acc.reminderdate1 IS NOT NULL THEN '<br/>R1:' || strftime('%d.%m.%Y',acc.reminderdate1) ELSE '' END || CASE WHEN acc.reminderdate2 IS NOT NULL THEN '<br/>R2:' || strftime('%d.%m.%Y',acc.reminderdate2) ELSE '' END || CASE WHEN acc.reminderdate3 IS NOT NULL THEN '<br/>R3:' || strftime('%d.%m.%Y',acc.reminderdate3) ELSE '' END else '' end else '' end as invoiced, " +
-"case when acc.payedamount is not null then printf(\"%.2f\",COALESCE(acc.payedamount,0.00)) || '€' || case when acc.payeddate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.payeddate) || ')' else '' end else '' end as payement," +
-"'' as benefitamount," +
-"'<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_accounting(''' || acc.accmonth || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-pencil\"></span></button>' || CASE WHEN acc.invoicefile IS NOT NULL and acc.invoicefile != '' THEN '<button type=\"button\" class=\"btn btn-primary\" onclick=\"openfile(''' || acc.invoicefile || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-open\"></span>' else '' end || CASE WHEN acc.childuuid IS NOT NULL AND acc.accmonth IS NOT NULL THEN '<button type=\"button\" class=\"btn btn-danger\" onclick=\" confirm_delete_accounting(''' || acc.childuuid || ''',''' || acc.accmonth || ''',''' || acc.reference || ''');\" title=\"supprimer\"><span class=\"glyphicon glyphicon-remove\"></span></button>' ELSE '' END AS act " +
-" from accounting acc where acc.childuuid='"+ pconfig.accchild +"' and strftime( '%Y',acc.accmonth)='"+pconfig.accyear+"' and acc.reference LIKE 'NOCHECKSERVICE:%' "
- //|| ' (' || weekhourcosts || '€/h)' -- || ' (' || weeklunchcosts || '€/déj.)
- accsql += "UNION SELECT calmonth, " +
- "group_concat( '<span class=\"glyphicon glyphicon-calendar\"></span>:' || calweek || ' <span class=\"glyphicon glyphicon-time\"></span>: ' || durationweek || ' h <span class=\"glyphicon glyphicon-cutlery\"></span>: ' || lunchweek ,'<br/>') AS weekdetails, " +
- "printf(\"%.2f\",SUM(weektotalhourcosts)) AS monthtotalhourcosts, " +
- "printf(\"%.2f\",SUM(weektotallunchcosts)) AS monthtotallunchcosts, " +
- "printf(\"%.2f\",SUM(weektotalhourcosts + weektotallunchcosts)) AS monthtotalcosts, " +
- "reference, " +
- "invoiced,payement,benefitamount,act FROM ( " +
- "SELECT childname,ttl.childuuid,printf(\"%02d\",calweek) AS calweek,calmonth, " +
- "printf(\"%.2f\",sumdurationcalweek) AS durationweek, " +
- "sumlunchcalweek AS lunchweek, " +
- "printf(\"%.2f\",weekhourcosts) AS weekhourcosts, " +
- "printf(\"%.2f\",weeklunchcosts) AS weeklunchcosts, " +
- "sumdurationcalweek * weekhourcosts AS weektotalhourcosts, " +
- "sumlunchcalweek * weeklunchcosts AS weektotallunchcosts, " +
- "REPLACE(acc.reference,'NOCHECKSERVICE:','') as reference," +
- "case when acc.invoiceamount is not null then printf(\"%.2f\",COALESCE(acc.invoiceamount,0.00)) || '€' || case when acc.invoicedate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.invoicedate) || ')' || CASE WHEN acc.reminderdate1 IS NOT NULL THEN '<br/>R1:' || strftime('%d.%m.%Y',acc.reminderdate1) ELSE '' END || CASE WHEN acc.reminderdate2 IS NOT NULL THEN '<br/>R2:' || strftime('%d.%m.%Y',acc.reminderdate2) ELSE '' END || CASE WHEN acc.reminderdate3 IS NOT NULL THEN '<br/>R3:' || strftime('%d.%m.%Y',acc.reminderdate3) ELSE '' END else '' end else '' end as invoiced, " +
- "case when acc.payedamount is not null then printf(\"%.2f\",COALESCE(acc.payedamount,0.00)) || '€' || case when acc.payeddate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.payeddate) || ')' else '' end else '' end as payement," +
- "case when acc.benefitamount is not null then printf(\"%.2f\",COALESCE(acc.benefitamount,0.00)) || '€' else '' end as benefitamount," +
- "'<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_accounting(''' || acc.accmonth || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-pencil\"></span></button>' || CASE WHEN acc.invoicefile IS NOT NULL and acc.invoicefile != '' THEN '<button type=\"button\" class=\"btn btn-primary\" onclick=\"openfile(''' || acc.invoicefile || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-open\"></span>' else '' end || CASE WHEN acc.childuuid IS NOT NULL AND acc.accmonth IS NOT NULL THEN '<button type=\"button\" class=\"btn btn-danger\" onclick=\" confirm_delete_accounting(''' || acc.childuuid || ''',''' || acc.accmonth || ''',''' || acc.reference || ''');\" title=\"supprimer\"><span class=\"glyphicon glyphicon-remove\"></span></button>' ELSE '' END AS act " +
- "FROM ( SELECT pch.childname, pch.childuuid, px.calweek, px.calmonth, px.sumdurationcalweek, px.sumlunchcalweek, " +
- "CASE WHEN px.sumdurationcalweek IS NOT NULL AND pch.checkservicenumber IS NOT NULL THEN ( SELECT coalesce(wc0.costsperhour,0.00) FROM costs wc0 WHERE wc0.startdate < date('"+yearmin+"','+' || caldays || ' days') and wc0.weeklyhourslimit <= px.sumdurationcalweek ORDER BY wc0.startdate DESC,wc0.weeklyhourslimit DESC LIMIT 1 ) WHEN px.sumdurationcalweek IS NOT NULL AND pch.checkservicenumber IS NULL THEN ( SELECT coalesce(wc0.costperhourfallback,0.00) FROM costs wc0 WHERE wc0.startdate < date('"+yearmin+"','+' || caldays || ' days') and wc0.weeklyhourslimit <= px.sumdurationcalweek ORDER BY wc0.startdate DESC,wc0.weeklyhourslimit DESC LIMIT 1 ) ELSE NULL END AS weekhourcosts,"+
-
- "CASE WHEN px.sumlunchcalweek IS NOT NULL THEN ( SELECT coalesce(wc0.dailylunchcosts,0.00) FROM costs wc0 WHERE wc0.startdate < date('"+yearmin+"','+' || caldays || ' days') and wc0.weeklyhourslimit <= px.sumdurationcalweek ORDER BY wc0.startdate DESC,wc0.weeklyhourslimit DESC LIMIT 1) ELSE NULL END AS weeklunchcosts " +
- "FROM ( SELECT COALESCE(ch.prename,'') || ' ' || COALESCE(ch.surname,'') || '<br>(' || " +
- "COALESCE(ch.checkservicenumber,'') || ')' AS childname,ch.uuid AS childuuid,ch.checkservicenumber " +
- "FROM childs ch JOIN planning pl ON ( ch.uuid=pl.childuuid) WHERE childuuid='"+pconfig.accchild+"' ) pch " +
- "LEFT JOIN ( SELECT childuuid, calweek, case when strftime('%w',date(calyear ||'-01-01')) in ('1','2','3','4') then (cast(calweek as int)*7)-7 else (cast(calweek as int)*7) end as caldays ,calmonth, sumlunchcalweek, COALESCE(SUM(monduration + tueduration + wedduration + thuduration + friduration),0.0) AS sumdurationcalweek FROM " +
- "( SELECT childuuid, daydate, calyear,"
- +"case when strftime('%w',date(calyear ||'-01-01')) in ('1','2','3','4') then case when calweek < '10' then '0' else '' end || cast(calweek as int)+1 else calweek end as calweek,"
- +"calmonth, MAX(monlunch) + MAX(tuelunch) + MAX(wedlunch) + MAX(thulunch) + MAX(frilunch) AS sumlunchcalweek, MAX(monduration) + MAX(monduration2) AS monduration, MAX(tueduration) + MAX(tueduration2) AS tueduration, MAX(wedduration) + MAX(wedduration2) AS wedduration, MAX(thuduration) + MAX(thuduration2) AS thuduration, MAX(friduration) + MAX(friduration2) AS friduration FROM " +
- "( SELECT xx.childuuid, xx.daydate,strftime('%Y',xx.daydate) as calyear, " +
- "case when strftime('%w',xx.daydate)='0' then strftime('%W',date(xx.daydate,'-6 days')) else strftime('%W',date(date(xx.daydate),'-' || strftime('%w',date(xx.daydate)) || ' days','+1 day')) end as calweek, " +
- "case when strftime('%w',xx.daydate)='0' then strftime('%m.%Y',date(xx.daydate,'-6 days')) else strftime('%m.%Y',date(date(xx.daydate),'-' || strftime('%w',date(xx.daydate)) || ' days','+1 day')) end as calmonth, ";
- var aax = ['mon','tue','wed','thu','fri','sat'];
- for (var d1 in aax){
- var dw = d1;dw++;
- accsql += "CASE WHEN lunch=1 AND status IN (1,5) AND strftime('%w',daydate) = '"+dw+"' THEN 1 ELSE 0 END AS "+aax[d1]+"lunch,";
- }
+ // var daterangesql = "select case when strftime('%Y',date(yeardaybegin)) == '"+pconfig.accyear+"' then yeardaybegin else strftime('%Y-%m-%d',date(date(yeardaybegin),'+7 days')) end as yeardaybegin,"+
+ // "strftime('%Y-%m-%d',date(date(yeardayend),'+6 days')) as yeardayend "+
+ // "from ( " +
+ // "select case when strftime('%w','"+pconfig.accyear+"-01-01') = '1' then strftime('%Y-%m-%d','"+pconfig.accyear+"-01-01') else strftime('%Y-%m-%d', date(date('"+pconfig.accyear+"-01-01','-7 days'),'weekday 1')) end as yeardaybegin, "+
+ // "case when strftime('%w','"+pconfig.accyear+"-12-31') = '1' then strftime('%Y-%m-%d','"+pconfig.accyear+"-12-31') else strftime('%Y-%m-%d', date(date('"+pconfig.accyear+"-12-31','-7 days'),'weekday 1')) end as yeardayend "+
+ // ");";
+ // var daterange = appdb.dbquery(daterangesql);
+ // daterange = daterange.sqldata[0];
+ // var yearmin = daterange.yeardaybegin;
+ // var yearmax = daterange.yeardayend;
- for (var d2 in aax){
- var dw2 = d2;dw2++;
- accsql += "CASE WHEN xx.status IS NOT NULL AND strftime('%w',xx.daydate) = '"+dw2+"' AND xx.daydate BETWEEN xx.datebegin AND xx.dateend THEN CAST(( (( CAST(SUBSTR(xx."+ aax[d2]+"timeend,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d2]+"timeend,4,2) AS INT) *60))- ((CAST(SUBSTR(xx."+ aax[d2]+"timebegin,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d2]+"timebegin,4,2) AS INT) *60)) ) / 3600 AS REAL) ELSE 0.0 END AS "+ aax[d2]+"duration,";
- }
+ // var chbornes = appdb.dbquery("select min(daydate) as mindate,max(daydate) as maxdate from presence where strftime('%Y',daydate)='" + pconfig.accyear + "' and childuuid='" + pconfig.accchild + "';");
- for (var d3 in aax){
- var dw3 = d3;dw3++;
- accsql += "CASE WHEN xx.status IS NOT NULL AND strftime('%w',xx.daydate) = '"+dw3+"' AND xx.daydate BETWEEN xx.datebegin AND xx.dateend AND xx."+ aax[d3]+"timebegin2 IS NOT NULL AND xx."+ aax[d3]+"timeend2 IS NOT NULL THEN CAST(( (( CAST(SUBSTR(xx."+ aax[d3]+"timeend2,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d3]+"timeend2,4,2) AS INT) *60))- ((CAST(SUBSTR(xx."+ aax[d3]+"timebegin2,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d3]+"timebegin2,4,2) AS INT) *60)) ) / 3600 AS REAL) ELSE 0.0 END AS "+ aax[d3]+"duration2,";
- }
+ // var monthmin= chbornes.sqldata[0].mindate;
+ // var monthmax= chbornes.sqldata[0].maxdate;
+ var accsql = "select strftime('%m.%Y', acc.accmonth) as calmonth," +
+ "case when nocheckservice = '1' then '<span style=\"color: red;\">(facture non check-service)</span><br/>' else '' end || acc.reference as reference, "+
+ " case when acc.invoiceamount is not null then printf(\"%.2f\", COALESCE(acc.invoiceamount, 0.00)) || '€' || " +
+ " case when acc.invoicedate is not null then '<br/>(' || strftime('%d.%m.%Y', acc.invoicedate) || ')' || " +
+ " CASE WHEN acc.reminderdate1 IS NOT NULL THEN '<br/>R1:' || strftime('%d.%m.%Y', acc.reminderdate1) ELSE '' END || "+
+ " CASE WHEN acc.reminderdate2 IS NOT NULL THEN '<br/>R2:' || strftime('%d.%m.%Y', acc.reminderdate2) ELSE '' END || "+
+ " CASE WHEN acc.reminderdate3 IS NOT NULL THEN '<br/>R3:' || strftime('%d.%m.%Y', acc.reminderdate3) ELSE '' END else '' end else '' end as invoiced,"+
+ " case when acc.payedamount is not null then printf(\"%.2f\", COALESCE(acc.payedamount, 0.00)) || '€' || "+
+ " case when acc.payeddate is not null then '<br/>(' || strftime('%d.%m.%Y', acc.payeddate) || ')' else '' end else '' end as payement, "+
+ " case when acc.benefitamount is not null then printf(\"%.2f\",COALESCE(acc.benefitamount,0.00)) || '€' else '' end as benefitamount," +
+ " '<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_accounting(''' || acc.uuid || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-pencil\"></span></button>' || " +
+ " CASE WHEN acc.invoicefile IS NOT NULL and acc.invoicefile != '' THEN '<button type=\"button\" class=\"btn btn-primary\" onclick=\"openfile(''' || acc.invoicefile || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-open\"></span>' else '' end || CASE WHEN acc.childuuid IS NOT NULL AND acc.accmonth IS NOT NULL THEN '<button type=\"button\" class=\"btn btn-danger\" onclick=\" confirm_delete_accounting(''' || acc.uuid || ''');\" title=\"supprimer\"><span class=\"glyphicon glyphicon-remove\"></span></button>' ELSE '' END AS act " +
+ " from accounting acc where childuuid='"+ pconfig.accchild+"' and strftime('%Y',acc.accmonth) = '" + pconfig.accyear +"' order by accmonth;";
- accsql += "null as nouse FROM (" +
- " select vacancydate as daydate, CAST('0' as boolean) as lunch,1 as status,pl.* from vacancy va " +
- " left join planning pl on (va.vacancydate between pl.datebegin and pl.dateend and pl.childuuid='"+pconfig.accchild+"') " +
- " where va.vacancydateto is null and va.vacancydate BETWEEN '"+monthmin+"' AND '"+monthmax+"' AND strftime('%w',va.vacancydate) not in ('0') " +
- " group by va.vacancydate,pl.childuuid " +
- " union " +
- " select pr.daydate,pr.lunch,pr.status,pl.* FROM presence pr " +
- " JOIN planning pl ON ( pr.childuuid=pl.childuuid and pr.childuuid='"+pconfig.accchild+"') WHERE pr.daydate BETWEEN '"+monthmin+"' AND '"+monthmax+"' "+
- ") xx " +
- "WHERE xx.daydate BETWEEN '"+monthmin+"' AND '"+monthmax+"') GROUP BY calweek) GROUP BY calweek) px " +
- "ON ( pch.childuuid=px.childuuid) GROUP BY px.calweek ) ttl LEFT JOIN accounting acc ON (ttl.childuuid = acc.childuuid AND ttl.calmonth=strftime('%m.%Y',acc.accmonth) AND acc.reference NOT LIKE 'NOCHECKSERVICE:%') WHERE calweek IS NOT NULL) group by calmonth ORDER BY calmonth; ";
-
-
+// var accsql = "select strftime( '%m.%Y',acc.accmonth) as calmonth,'' as weekdetails, '' as monthtotalhourcosts,'' as monthtotallunchcosts, '' as monthtotalcosts,replace(acc.reference,'NOCHECKSERVICE:','<span style=\"color: red;\">(facture non check-service)</span><br/>') as reference, " +
+// "case when acc.invoiceamount is not null then printf(\"%.2f\",COALESCE(acc.invoiceamount,0.00)) || '€' || case when acc.invoicedate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.invoicedate) || ')' || CASE WHEN acc.reminderdate1 IS NOT NULL THEN '<br/>R1:' || strftime('%d.%m.%Y',acc.reminderdate1) ELSE '' END || CASE WHEN acc.reminderdate2 IS NOT NULL THEN '<br/>R2:' || strftime('%d.%m.%Y',acc.reminderdate2) ELSE '' END || CASE WHEN acc.reminderdate3 IS NOT NULL THEN '<br/>R3:' || strftime('%d.%m.%Y',acc.reminderdate3) ELSE '' END else '' end else '' end as invoiced, " +
+// "case when acc.payedamount is not null then printf(\"%.2f\",COALESCE(acc.payedamount,0.00)) || '€' || case when acc.payeddate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.payeddate) || ')' else '' end else '' end as payement," +
+// "'' as benefitamount," +
+// "'<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_accounting(''' || acc.uuid || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-pencil\"></span></button>' || CASE WHEN acc.invoicefile IS NOT NULL and acc.invoicefile != '' THEN '<button type=\"button\" class=\"btn btn-primary\" onclick=\"openfile(''' || acc.invoicefile || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-open\"></span>' else '' end || CASE WHEN acc.childuuid IS NOT NULL AND acc.accmonth IS NOT NULL THEN '<button type=\"button\" class=\"btn btn-danger\" onclick=\" confirm_delete_accounting(''' || acc.uuid || ''');\" title=\"supprimer\"><span class=\"glyphicon glyphicon-remove\"></span></button>' ELSE '' END AS act " +
+// " from accounting acc where acc.childuuid='"+ pconfig.accchild +"' and strftime( '%Y',acc.accmonth)='"+pconfig.accyear+"' and acc.reference LIKE 'NOCHECKSERVICE:%' "
+// //|| ' (' || weekhourcosts || '€/h)' -- || ' (' || weeklunchcosts || '€/déj.)
+// accsql += "UNION SELECT calmonth, " +
+// "group_concat( '<span class=\"glyphicon glyphicon-calendar\"></span>:' || calweek || ' <span class=\"glyphicon glyphicon-time\"></span>: ' || durationweek || ' h <span class=\"glyphicon glyphicon-cutlery\"></span>: ' || lunchweek ,'<br/>') AS weekdetails, " +
+// "printf(\"%.2f\",SUM(weektotalhourcosts)) AS monthtotalhourcosts, " +
+// "printf(\"%.2f\",SUM(weektotallunchcosts)) AS monthtotallunchcosts, " +
+// "printf(\"%.2f\",SUM(weektotalhourcosts + weektotallunchcosts)) AS monthtotalcosts, " +
+// "reference, " +
+// "invoiced,payement,benefitamount,act FROM ( " +
+// "SELECT childname,ttl.childuuid,printf(\"%02d\",calweek) AS calweek,calmonth, " +
+// "printf(\"%.2f\",sumdurationcalweek) AS durationweek, " +
+// "sumlunchcalweek AS lunchweek, " +
+// "printf(\"%.2f\",weekhourcosts) AS weekhourcosts, " +
+// "printf(\"%.2f\",weeklunchcosts) AS weeklunchcosts, " +
+// "sumdurationcalweek * weekhourcosts AS weektotalhourcosts, " +
+// "sumlunchcalweek * weeklunchcosts AS weektotallunchcosts, " +
+// "REPLACE(acc.reference,'NOCHECKSERVICE:','') as reference," +
+// "case when acc.invoiceamount is not null then printf(\"%.2f\",COALESCE(acc.invoiceamount,0.00)) || '€' || case when acc.invoicedate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.invoicedate) || ')' || CASE WHEN acc.reminderdate1 IS NOT NULL THEN '<br/>R1:' || strftime('%d.%m.%Y',acc.reminderdate1) ELSE '' END || CASE WHEN acc.reminderdate2 IS NOT NULL THEN '<br/>R2:' || strftime('%d.%m.%Y',acc.reminderdate2) ELSE '' END || CASE WHEN acc.reminderdate3 IS NOT NULL THEN '<br/>R3:' || strftime('%d.%m.%Y',acc.reminderdate3) ELSE '' END else '' end else '' end as invoiced, " +
+// "case when acc.payedamount is not null then printf(\"%.2f\",COALESCE(acc.payedamount,0.00)) || '€' || case when acc.payeddate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.payeddate) || ')' else '' end else '' end as payement," +
+// "case when acc.benefitamount is not null then printf(\"%.2f\",COALESCE(acc.benefitamount,0.00)) || '€' else '' end as benefitamount," +
+// "'<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_accounting(''' || acc.uuid || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-pencil\"></span></button>' || CASE WHEN acc.invoicefile IS NOT NULL and acc.invoicefile != '' THEN '<button type=\"button\" class=\"btn btn-primary\" onclick=\"openfile(''' || acc.invoicefile || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-open\"></span>' else '' end || CASE WHEN acc.childuuid IS NOT NULL AND acc.accmonth IS NOT NULL THEN '<button type=\"button\" class=\"btn btn-danger\" onclick=\" confirm_delete_accounting(''' || acc.uuid || ''');\" title=\"supprimer\"><span class=\"glyphicon glyphicon-remove\"></span></button>' ELSE '' END AS act " +
+// "FROM ( SELECT pch.childname, pch.childuuid, px.calweek, px.calmonth, px.sumdurationcalweek, px.sumlunchcalweek, " +
+// "CASE WHEN px.sumdurationcalweek IS NOT NULL AND pch.checkservicenumber IS NOT NULL THEN ( SELECT coalesce(wc0.costsperhour,0.00) FROM costs wc0 WHERE wc0.startdate < date('"+yearmin+"','+' || caldays || ' days') and wc0.weeklyhourslimit <= px.sumdurationcalweek ORDER BY wc0.startdate DESC,wc0.weeklyhourslimit DESC LIMIT 1 ) WHEN px.sumdurationcalweek IS NOT NULL AND pch.checkservicenumber IS NULL THEN ( SELECT coalesce(wc0.costperhourfallback,0.00) FROM costs wc0 WHERE wc0.startdate < date('"+yearmin+"','+' || caldays || ' days') and wc0.weeklyhourslimit <= px.sumdurationcalweek ORDER BY wc0.startdate DESC,wc0.weeklyhourslimit DESC LIMIT 1 ) ELSE NULL END AS weekhourcosts,"+
+
+// "CASE WHEN px.sumlunchcalweek IS NOT NULL THEN ( SELECT coalesce(wc0.dailylunchcosts,0.00) FROM costs wc0 WHERE wc0.startdate < date('"+yearmin+"','+' || caldays || ' days') and wc0.weeklyhourslimit <= px.sumdurationcalweek ORDER BY wc0.startdate DESC,wc0.weeklyhourslimit DESC LIMIT 1) ELSE NULL END AS weeklunchcosts " +
+// "FROM ( SELECT COALESCE(ch.prename,'') || ' ' || COALESCE(ch.surname,'') || '<br>(' || " +
+// "COALESCE(ch.checkservicenumber,'') || ')' AS childname,ch.uuid AS childuuid,ch.checkservicenumber " +
+// "FROM childs ch JOIN planning pl ON ( ch.uuid=pl.childuuid) WHERE childuuid='"+pconfig.accchild+"' ) pch " +
+// "LEFT JOIN ( SELECT childuuid, calweek, case when strftime('%w',date(calyear ||'-01-01')) in ('1','2','3','4') then (cast(calweek as int)*7)-7 else (cast(calweek as int)*7) end as caldays ,calmonth, sumlunchcalweek, COALESCE(SUM(monduration + tueduration + wedduration + thuduration + friduration),0.0) AS sumdurationcalweek FROM " +
+// "( SELECT childuuid, daydate, calyear,"
+// +"case when strftime('%w',date(calyear ||'-01-01')) in ('1','2','3','4') then case when calweek < '10' then '0' else '' end || cast(calweek as int)+1 else calweek end as calweek,"
+// +"calmonth, MAX(monlunch) + MAX(tuelunch) + MAX(wedlunch) + MAX(thulunch) + MAX(frilunch) AS sumlunchcalweek, MAX(monduration) + MAX(monduration2) AS monduration, MAX(tueduration) + MAX(tueduration2) AS tueduration, MAX(wedduration) + MAX(wedduration2) AS wedduration, MAX(thuduration) + MAX(thuduration2) AS thuduration, MAX(friduration) + MAX(friduration2) AS friduration FROM " +
+// "( SELECT xx.childuuid, xx.daydate,strftime('%Y',xx.daydate) as calyear, " +
+// "case when strftime('%w',xx.daydate)='0' then strftime('%W',date(xx.daydate,'-6 days')) else strftime('%W',date(date(xx.daydate),'-' || strftime('%w',date(xx.daydate)) || ' days','+1 day')) end as calweek, " +
+// "case when strftime('%w',xx.daydate)='0' then strftime('%m.%Y',date(xx.daydate,'-6 days')) else strftime('%m.%Y',date(date(xx.daydate),'-' || strftime('%w',date(xx.daydate)) || ' days','+1 day')) end as calmonth, ";
+// var aax = ['mon','tue','wed','thu','fri','sat'];
+// for (var d1 in aax){
+// var dw = d1;dw++;
+// accsql += "CASE WHEN lunch=1 AND status IN (1,5) AND strftime('%w',daydate) = '"+dw+"' THEN 1 ELSE 0 END AS "+aax[d1]+"lunch,";
+// }
+
+// for (var d2 in aax){
+// var dw2 = d2;dw2++;
+// accsql += "CASE WHEN xx.status IS NOT NULL AND strftime('%w',xx.daydate) = '"+dw2+"' AND xx.daydate BETWEEN xx.datebegin AND xx.dateend THEN CAST(( (( CAST(SUBSTR(xx."+ aax[d2]+"timeend,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d2]+"timeend,4,2) AS INT) *60))- ((CAST(SUBSTR(xx."+ aax[d2]+"timebegin,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d2]+"timebegin,4,2) AS INT) *60)) ) / 3600 AS REAL) ELSE 0.0 END AS "+ aax[d2]+"duration,";
+// }
+
+
+// for (var d3 in aax){
+// var dw3 = d3;dw3++;
+// accsql += "CASE WHEN xx.status IS NOT NULL AND strftime('%w',xx.daydate) = '"+dw3+"' AND xx.daydate BETWEEN xx.datebegin AND xx.dateend AND xx."+ aax[d3]+"timebegin2 IS NOT NULL AND xx."+ aax[d3]+"timeend2 IS NOT NULL THEN CAST(( (( CAST(SUBSTR(xx."+ aax[d3]+"timeend2,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d3]+"timeend2,4,2) AS INT) *60))- ((CAST(SUBSTR(xx."+ aax[d3]+"timebegin2,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d3]+"timebegin2,4,2) AS INT) *60)) ) / 3600 AS REAL) ELSE 0.0 END AS "+ aax[d3]+"duration2,";
+// }
+
+// accsql += "null as nouse FROM (" +
+// " select vacancydate as daydate, CAST('0' as boolean) as lunch,1 as status,pl.* from vacancy va " +
+// " left join planning pl on (va.vacancydate between pl.datebegin and pl.dateend and pl.childuuid='"+pconfig.accchild+"') " +
+// " where va.vacancydateto is null and va.vacancydate BETWEEN '"+monthmin+"' AND '"+monthmax+"' AND strftime('%w',va.vacancydate) not in ('0') " +
+// " group by va.vacancydate,pl.childuuid " +
+// " union " +
+// " select pr.daydate,pr.lunch,pr.status,pl.* FROM presence pr " +
+// " JOIN planning pl ON ( pr.childuuid=pl.childuuid and pr.childuuid='"+pconfig.accchild+"') WHERE pr.daydate BETWEEN '"+monthmin+"' AND '"+monthmax+"' "+
+// ") xx " +
+// "WHERE xx.daydate BETWEEN '"+monthmin+"' AND '"+monthmax+"') GROUP BY calweek) GROUP BY calweek) px " +
+// "ON ( pch.childuuid=px.childuuid) GROUP BY px.calweek ) ttl LEFT JOIN accounting acc ON (ttl.childuuid = acc.childuuid AND ttl.calmonth=strftime('%m.%Y',acc.accmonth) AND acc.reference NOT LIKE 'NOCHECKSERVICE:%') WHERE calweek IS NOT NULL) group by calmonth ORDER BY calmonth; ";var accsql = "select strftime( '%m.%Y',acc.accmonth) as calmonth,'' as weekdetails, '' as monthtotalhourcosts,'' as monthtotallunchcosts, '' as monthtotalcosts,replace(acc.reference,'NOCHECKSERVICE:','<span style=\"color: red;\">(facture non check-service)</span><br/>') as reference, " +
+// "case when acc.invoiceamount is not null then printf(\"%.2f\",COALESCE(acc.invoiceamount,0.00)) || '€' || case when acc.invoicedate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.invoicedate) || ')' || CASE WHEN acc.reminderdate1 IS NOT NULL THEN '<br/>R1:' || strftime('%d.%m.%Y',acc.reminderdate1) ELSE '' END || CASE WHEN acc.reminderdate2 IS NOT NULL THEN '<br/>R2:' || strftime('%d.%m.%Y',acc.reminderdate2) ELSE '' END || CASE WHEN acc.reminderdate3 IS NOT NULL THEN '<br/>R3:' || strftime('%d.%m.%Y',acc.reminderdate3) ELSE '' END else '' end else '' end as invoiced, " +
+// "case when acc.payedamount is not null then printf(\"%.2f\",COALESCE(acc.payedamount,0.00)) || '€' || case when acc.payeddate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.payeddate) || ')' else '' end else '' end as payement," +
+// "'' as benefitamount," +
+// "'<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_accounting(''' || acc.uuid || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-pencil\"></span></button>' || CASE WHEN acc.invoicefile IS NOT NULL and acc.invoicefile != '' THEN '<button type=\"button\" class=\"btn btn-primary\" onclick=\"openfile(''' || acc.invoicefile || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-open\"></span>' else '' end || CASE WHEN acc.childuuid IS NOT NULL AND acc.accmonth IS NOT NULL THEN '<button type=\"button\" class=\"btn btn-danger\" onclick=\" confirm_delete_accounting(''' || acc.uuid || ''');\" title=\"supprimer\"><span class=\"glyphicon glyphicon-remove\"></span></button>' ELSE '' END AS act " +
+// " from accounting acc where acc.childuuid='"+ pconfig.accchild +"' and strftime( '%Y',acc.accmonth)='"+pconfig.accyear+"' and acc.reference LIKE 'NOCHECKSERVICE:%' "
+// //|| ' (' || weekhourcosts || '€/h)' -- || ' (' || weeklunchcosts || '€/déj.)
+// accsql += "UNION SELECT calmonth, " +
+// "group_concat( '<span class=\"glyphicon glyphicon-calendar\"></span>:' || calweek || ' <span class=\"glyphicon glyphicon-time\"></span>: ' || durationweek || ' h <span class=\"glyphicon glyphicon-cutlery\"></span>: ' || lunchweek ,'<br/>') AS weekdetails, " +
+// "printf(\"%.2f\",SUM(weektotalhourcosts)) AS monthtotalhourcosts, " +
+// "printf(\"%.2f\",SUM(weektotallunchcosts)) AS monthtotallunchcosts, " +
+// "printf(\"%.2f\",SUM(weektotalhourcosts + weektotallunchcosts)) AS monthtotalcosts, " +
+// "reference, " +
+// "invoiced,payement,benefitamount,act FROM ( " +
+// "SELECT childname,ttl.childuuid,printf(\"%02d\",calweek) AS calweek,calmonth, " +
+// "printf(\"%.2f\",sumdurationcalweek) AS durationweek, " +
+// "sumlunchcalweek AS lunchweek, " +
+// "printf(\"%.2f\",weekhourcosts) AS weekhourcosts, " +
+// "printf(\"%.2f\",weeklunchcosts) AS weeklunchcosts, " +
+// "sumdurationcalweek * weekhourcosts AS weektotalhourcosts, " +
+// "sumlunchcalweek * weeklunchcosts AS weektotallunchcosts, " +
+// "REPLACE(acc.reference,'NOCHECKSERVICE:','') as reference," +
+// "case when acc.invoiceamount is not null then printf(\"%.2f\",COALESCE(acc.invoiceamount,0.00)) || '€' || case when acc.invoicedate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.invoicedate) || ')' || CASE WHEN acc.reminderdate1 IS NOT NULL THEN '<br/>R1:' || strftime('%d.%m.%Y',acc.reminderdate1) ELSE '' END || CASE WHEN acc.reminderdate2 IS NOT NULL THEN '<br/>R2:' || strftime('%d.%m.%Y',acc.reminderdate2) ELSE '' END || CASE WHEN acc.reminderdate3 IS NOT NULL THEN '<br/>R3:' || strftime('%d.%m.%Y',acc.reminderdate3) ELSE '' END else '' end else '' end as invoiced, " +
+// "case when acc.payedamount is not null then printf(\"%.2f\",COALESCE(acc.payedamount,0.00)) || '€' || case when acc.payeddate is not null then '<br/>(' || strftime('%d.%m.%Y',acc.payeddate) || ')' else '' end else '' end as payement," +
+// "case when acc.benefitamount is not null then printf(\"%.2f\",COALESCE(acc.benefitamount,0.00)) || '€' else '' end as benefitamount," +
+// "'<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_accounting(''' || acc.uuid || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-pencil\"></span></button>' || CASE WHEN acc.invoicefile IS NOT NULL and acc.invoicefile != '' THEN '<button type=\"button\" class=\"btn btn-primary\" onclick=\"openfile(''' || acc.invoicefile || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-open\"></span>' else '' end || CASE WHEN acc.childuuid IS NOT NULL AND acc.accmonth IS NOT NULL THEN '<button type=\"button\" class=\"btn btn-danger\" onclick=\" confirm_delete_accounting(''' || acc.uuid || ''');\" title=\"supprimer\"><span class=\"glyphicon glyphicon-remove\"></span></button>' ELSE '' END AS act " +
+// "FROM ( SELECT pch.childname, pch.childuuid, px.calweek, px.calmonth, px.sumdurationcalweek, px.sumlunchcalweek, " +
+// "CASE WHEN px.sumdurationcalweek IS NOT NULL AND pch.checkservicenumber IS NOT NULL THEN ( SELECT coalesce(wc0.costsperhour,0.00) FROM costs wc0 WHERE wc0.startdate < date('"+yearmin+"','+' || caldays || ' days') and wc0.weeklyhourslimit <= px.sumdurationcalweek ORDER BY wc0.startdate DESC,wc0.weeklyhourslimit DESC LIMIT 1 ) WHEN px.sumdurationcalweek IS NOT NULL AND pch.checkservicenumber IS NULL THEN ( SELECT coalesce(wc0.costperhourfallback,0.00) FROM costs wc0 WHERE wc0.startdate < date('"+yearmin+"','+' || caldays || ' days') and wc0.weeklyhourslimit <= px.sumdurationcalweek ORDER BY wc0.startdate DESC,wc0.weeklyhourslimit DESC LIMIT 1 ) ELSE NULL END AS weekhourcosts,"+
+
+// "CASE WHEN px.sumlunchcalweek IS NOT NULL THEN ( SELECT coalesce(wc0.dailylunchcosts,0.00) FROM costs wc0 WHERE wc0.startdate < date('"+yearmin+"','+' || caldays || ' days') and wc0.weeklyhourslimit <= px.sumdurationcalweek ORDER BY wc0.startdate DESC,wc0.weeklyhourslimit DESC LIMIT 1) ELSE NULL END AS weeklunchcosts " +
+// "FROM ( SELECT COALESCE(ch.prename,'') || ' ' || COALESCE(ch.surname,'') || '<br>(' || " +
+// "COALESCE(ch.checkservicenumber,'') || ')' AS childname,ch.uuid AS childuuid,ch.checkservicenumber " +
+// "FROM childs ch JOIN planning pl ON ( ch.uuid=pl.childuuid) WHERE childuuid='"+pconfig.accchild+"' ) pch " +
+// "LEFT JOIN ( SELECT childuuid, calweek, case when strftime('%w',date(calyear ||'-01-01')) in ('1','2','3','4') then (cast(calweek as int)*7)-7 else (cast(calweek as int)*7) end as caldays ,calmonth, sumlunchcalweek, COALESCE(SUM(monduration + tueduration + wedduration + thuduration + friduration),0.0) AS sumdurationcalweek FROM " +
+// "( SELECT childuuid, daydate, calyear,"
+// +"case when strftime('%w',date(calyear ||'-01-01')) in ('1','2','3','4') then case when calweek < '10' then '0' else '' end || cast(calweek as int)+1 else calweek end as calweek,"
+// +"calmonth, MAX(monlunch) + MAX(tuelunch) + MAX(wedlunch) + MAX(thulunch) + MAX(frilunch) AS sumlunchcalweek, MAX(monduration) + MAX(monduration2) AS monduration, MAX(tueduration) + MAX(tueduration2) AS tueduration, MAX(wedduration) + MAX(wedduration2) AS wedduration, MAX(thuduration) + MAX(thuduration2) AS thuduration, MAX(friduration) + MAX(friduration2) AS friduration FROM " +
+// "( SELECT xx.childuuid, xx.daydate,strftime('%Y',xx.daydate) as calyear, " +
+// "case when strftime('%w',xx.daydate)='0' then strftime('%W',date(xx.daydate,'-6 days')) else strftime('%W',date(date(xx.daydate),'-' || strftime('%w',date(xx.daydate)) || ' days','+1 day')) end as calweek, " +
+// "case when strftime('%w',xx.daydate)='0' then strftime('%m.%Y',date(xx.daydate,'-6 days')) else strftime('%m.%Y',date(date(xx.daydate),'-' || strftime('%w',date(xx.daydate)) || ' days','+1 day')) end as calmonth, ";
+// var aax = ['mon','tue','wed','thu','fri','sat'];
+// for (var d1 in aax){
+// var dw = d1;dw++;
+// accsql += "CASE WHEN lunch=1 AND status IN (1,5) AND strftime('%w',daydate) = '"+dw+"' THEN 1 ELSE 0 END AS "+aax[d1]+"lunch,";
+// }
+
+// for (var d2 in aax){
+// var dw2 = d2;dw2++;
+// accsql += "CASE WHEN xx.status IS NOT NULL AND strftime('%w',xx.daydate) = '"+dw2+"' AND xx.daydate BETWEEN xx.datebegin AND xx.dateend THEN CAST(( (( CAST(SUBSTR(xx."+ aax[d2]+"timeend,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d2]+"timeend,4,2) AS INT) *60))- ((CAST(SUBSTR(xx."+ aax[d2]+"timebegin,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d2]+"timebegin,4,2) AS INT) *60)) ) / 3600 AS REAL) ELSE 0.0 END AS "+ aax[d2]+"duration,";
+// }
+
+
+// for (var d3 in aax){
+// var dw3 = d3;dw3++;
+// accsql += "CASE WHEN xx.status IS NOT NULL AND strftime('%w',xx.daydate) = '"+dw3+"' AND xx.daydate BETWEEN xx.datebegin AND xx.dateend AND xx."+ aax[d3]+"timebegin2 IS NOT NULL AND xx."+ aax[d3]+"timeend2 IS NOT NULL THEN CAST(( (( CAST(SUBSTR(xx."+ aax[d3]+"timeend2,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d3]+"timeend2,4,2) AS INT) *60))- ((CAST(SUBSTR(xx."+ aax[d3]+"timebegin2,1,2) AS INT) *3600)+( CAST(SUBSTR(xx."+ aax[d3]+"timebegin2,4,2) AS INT) *60)) ) / 3600 AS REAL) ELSE 0.0 END AS "+ aax[d3]+"duration2,";
+// }
+
+// accsql += "null as nouse FROM (" +
+// " select vacancydate as daydate, CAST('0' as boolean) as lunch,1 as status,pl.* from vacancy va " +
+// " left join planning pl on (va.vacancydate between pl.datebegin and pl.dateend and pl.childuuid='"+pconfig.accchild+"') " +
+// " where va.vacancydateto is null and va.vacancydate BETWEEN '"+monthmin+"' AND '"+monthmax+"' AND strftime('%w',va.vacancydate) not in ('0') " +
+// " group by va.vacancydate,pl.childuuid " +
+// " union " +
+// " select pr.daydate,pr.lunch,pr.status,pl.* FROM presence pr " +
+// " JOIN planning pl ON ( pr.childuuid=pl.childuuid and pr.childuuid='"+pconfig.accchild+"') WHERE pr.daydate BETWEEN '"+monthmin+"' AND '"+monthmax+"' "+
+// ") xx " +
+// "WHERE xx.daydate BETWEEN '"+monthmin+"' AND '"+monthmax+"') GROUP BY calweek) GROUP BY calweek) px " +
+// "ON ( pch.childuuid=px.childuuid) GROUP BY px.calweek ) ttl LEFT JOIN accounting acc ON (ttl.childuuid = acc.childuuid AND ttl.calmonth=strftime('%m.%Y',acc.accmonth) AND acc.reference NOT LIKE 'NOCHECKSERVICE:%') WHERE calweek IS NOT NULL) group by calmonth ORDER BY calmonth; ";
+ jsdump("accsql");
+ jsdump(accsql);
var accdata = appdb.dbquery(accsql);
//jsdump("accchildsql");
//jsdump(accsql);
- var headerdata = getlabels("calmonth,weekdetails,reference,invoiced,payement,benefitamount,act");
+ var headerdata = getlabels("calmonth,reference,invoiced,payement,benefitamount,act");
//,monthtotalhourcosts,monthtotallunchcosts,monthtotalcosts
for (var i in accdata.sqldata){
var row = accdata.sqldata[i];
var tr = '<tr><td>' + row.calmonth + '</td>';
- tr += '<td class="infoweek noprint '+ (((pconfig.hidden_columns) && (pconfig.hidden_columns.indexOf('weekdetails') != -1))?" colhidden":"") +'">' + row.weekdetails + '</td>';
+ //tr += '<td class="infoweek noprint '+ (((pconfig.hidden_columns) && (pconfig.hidden_columns.indexOf('weekdetails') != -1))?" colhidden":"") +'">' + row.weekdetails + '</td>';
//tr += '<td class="alignright totalwidth '+ (((pconfig.hidden_columns) && (pconfig.hidden_columns.indexOf('monthtotalhourcosts') != -1))?" colhidden":"") +'">' + row.monthtotalhourcosts + '€</td>';
//tr += '<td class="alignright totalwidth '+ (((pconfig.hidden_columns) && (pconfig.hidden_columns.indexOf('monthtotallunchcosts') != -1))?" colhidden":"") +'">' + row.monthtotallunchcosts + '€</td>';
//tr += '<td class="alignright totalwidth '+ (((pconfig.hidden_columns) && (pconfig.hidden_columns.indexOf('monthtotalcosts') != -1))?" colhidden":"") +'">' + row.monthtotalcosts + '€</td>';
// return intVal(a) + intVal(b);
// }, 0 );
fTotal = api
- .column( 3, { page: 'current'} )
+ .column( 2, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
pTotal = api
- .column( 4, { page: 'current'} )
+ .column( 3, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
bTotal = api
- .column( 5, { page: 'current'} )
+ .column( 4, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
// }, 0 );
// Update footer
- $( api.column( 3 ).footer() ).html(
+ $( api.column( 2 ).footer() ).html(
''+fTotal.toFixed(2) +' €'
);
- $( api.column( 4 ).footer() ).html(
+ $( api.column( 3 ).footer() ).html(
''+pTotal.toFixed(2) +' €'
);
- $( api.column( 5 ).footer() ).html(
+ $( api.column( 4 ).footer() ).html(
''+bTotal.toFixed(2) +' €'
);
//$( api.column( 4 ).footer() ).html(
}
-function dlg_accounting(accmonth){
+function dlg_accounting(myuuid){
$("#frmeditaccounting #action").val("upd");
$("#head_invoice").html("Editer facture");
$("#frmeditaccounting #childname").val($("#accchild option:selected").text());
- var acc1sql = "SELECT accmonth,childuuid,case when invoicedate is not null then strftime('%d.%m.%Y',invoicedate) else null end as invoicedate, case when payeddate is not null then strftime('%d.%m.%Y',payeddate) else null end as payeddate, payedamount, benefitamount,invoiceamount, replace(reference,'NOCHECKSERVICE:','') as reference, instr(reference,'NOCHECKSERVICE:') as ischeckservice, case when reminderdate1 is not null then strftime('%d.%m.%Y',reminderdate1) else null end as reminderdate1, case when reminderdate2 is not null then strftime('%d.%m.%Y',reminderdate2) else null end as reminderdate2, case when reminderdate3 is not null then strftime('%d.%m.%Y',reminderdate3) else null end as reminderdate3,case when invoicefile is not null and invoicefile != '' then '"+ importpath.path + system.sep() +"' || invoicefile else null end as invoicefile,'upd' as action FROM accounting where accmonth = '" + accmonth +"' and childuuid='"+pconfig.accchild+"';";
+
+ var acc1sql = "SELECT uuid,accmonth,childuuid,case when invoicedate is not null then strftime('%d.%m.%Y',invoicedate) else null end as invoicedate, case when payeddate is not null then strftime('%d.%m.%Y',payeddate) else null end as payeddate, payedamount, benefitamount,invoiceamount, reference, nocheckservice, case when reminderdate1 is not null then strftime('%d.%m.%Y',reminderdate1) else null end as reminderdate1, case when reminderdate2 is not null then strftime('%d.%m.%Y',reminderdate2) else null end as reminderdate2, case when reminderdate3 is not null then strftime('%d.%m.%Y',reminderdate3) else null end as reminderdate3,case when invoicefile is not null and invoicefile != '' then '"+ importpath.path + system.sep() +"' || invoicefile else null end as invoicefile,'upd' as action FROM accounting where uuid='" + myuuid +"';";
var acc1data = appdb.dbquery(acc1sql);
if (acc1data.sqldata.length == 0) {
- acc1sql = "SELECT '"+ accmonth.substring(3) + "-" + accmonth.substring(0,2) +"-01' as accmonth,'"+ pconfig.accchild+"' as childuuid, null as invoicedate, null as payeddate, null as payedamount, null as invoiceamount,1 as ischeckservice, null as reference, null as reminderdate1, null as reminderdate2, null as reminderdate3,null as benefitamount ,null as invoicefile, 'ins' as action;";
+ acc1sql = "SELECT '0' as uuid,"+ accmonth.substring(3) + "-" + accmonth.substring(0,2) +"-01' as accmonth,'"+ pconfig.accchild+"' as childuuid, null as invoicedate, null as payeddate, null as payedamount, null as invoiceamount,1 as ischeckservice, null as reference, null as reminderdate1, null as reminderdate2, null as reminderdate3,null as benefitamount ,null as invoicefile, 'ins' as action;";
acc1data = appdb.dbquery(acc1sql);
}
acc1data = acc1data.sqldata[0];
- if (acc1data.ischeckservice > 0){
+ if (acc1data.nocheckservice == 1){
$("#frmeditaccounting #nocheckservice").prop("checked",true);
} else {
$("#frmeditaccounting #nocheckservice").prop("checked",false);
}
function newinvoice(){
- $("#frmeditaccounting #nocheckservice").prop("checked",true);
- $("#frmeditaccounting #action").val("ins");
- $("#head_invoice").html("Ajouter une facture");
if ($("#accchild").val() == ""){
alert("Vous devez d'abort selectionner un enfant!");
return;
}
+ $("#frmeditaccounting :input").each(function(){
+ var input = $(this);
+ input.val("");
+ });
+ $("#frmeditaccounting #nocheckservice").prop("checked",true);
+ $("#frmeditaccounting #action").val("ins");
+ $("#frmeditaccounting #uuid").val("0");
+ $("#frmeditaccounting #childuuid").val($("#accchild").val());
+ $("#head_invoice").html("Ajouter une facture");
+
+
$("#frmeditaccounting #childname").val($("#accchild option:selected").text());
$("#edit_accounting").modal('show');
}
$("#frmeditaccounting :input").each(function(){
var input = $(this);
if (input.attr("id") ){
- if ((type == 'ins') && (input.attr("id") != 'action') && (input.attr("id") != 'accmonth') && (input.attr("id") != 'childname') && (input.attr("id") != 'ischeckservice')&& (input.attr("id") != 'oldref') && (input.attr("id") != 'oldaccmonth')) {
+ if ((type == 'ins') && (input.attr("type") != 'hidden') && (input.attr("id") != 'accmonth') && (input.attr("id") != 'childname') && (input.attr("id") != 'ischeckservice')) {
+
sql1.push('"' + input.attr("id") + '"');
if (input.attr("type") == "file") {
var newlocation= importpath.path + system.sep() + system.getFileName(input.val());
}
var ival = input.val();
if ((input.attr("id") == 'reference') && $("#frmeditaccounting #ischeckservice").is(":checked")){
- ival = "NOCHECKSERVICE:" + ival;
+ sql1.push("nocheckservice");
+ sql2.push("'1'");
}
var ival = encodeparam(input.val(),input.attr('type'));
sql2.push(ival);
}
var ival = input.val();
if ((input.attr("id") == 'reference') && $("#frmeditaccounting #ischeckservice").is(":checked")){
- ival = "NOCHECKSERVICE:" + ival;
+ sql2.push("nocheckservice='1'");
}
var ival = encodeparam(ival,input.attr('type'));
sql2.push('"' + input.attr("id") +'"='+ ival);
});
var xsql = "";
if (type == 'upd') {
- xsql = "UPDATE accounting SET "+sql2.join(',')+" where \"childuuid\"='" + pconfig.accchild +"' and accmonth='"+ $("#frmeditaccounting #oldaccmonth").val() +"' and reference='"+$("#frmeditaccounting #oldref").val()+"';";
+ xsql = "UPDATE accounting SET "+sql2.join(',')+" where \"uuid\"='" + $("#frmeditaccounting #uuid").val() +"';";
}else {
+ sql1.push("uuid");
+ sql2.push("'" + appdb.generate_uuid() + "'");
xsql = "INSERT INTO accounting ("+sql1.join(',')+") VALUES ("+sql2.join(',')+");";
}
//jsdump(xsql);
}
-function confirm_delete_accounting(dchilduuid,daccmonth,dref) {
- delacc.childuuid = dchilduuid;
- delacc.accmonth=daccmonth;
- delacc.accref=dref;
+function confirm_delete_accounting(myuuid) {
+ delacc.uuid = uuid;
$('#confirm_delete_accounting').modal('show');
}
function delete_accounting() {
- var xsql = "DELETE FROM accounting where childuuid='"+ delacc.childuuid+"' and accmonth='"+delacc.accmonth+" and reference='"+delacc.accref+"';";
+ var xsql = "DELETE FROM accounting where uuid='"+ delacc.uuid+"';";
appdb.dbexec(xsql);
load_accounting_table();
//dump("Hide column " + coltohide + "\n");
}
-function check_accountingtable(){
- var cols = appdb.dbquery("SELECT type, name,tbl_name,sql FROM sqlite_master where tbl_name='accounting';");
- //jsdump(JSON.stringify(cols));
- if (cols.sqldata[0].sql.indexOf("nocheckservice") == -1){
- //jsdump("Install missing column! ALTER TABLE accounting add column nocheckservice integer");
- appdb.dbexec("ALTER TABLE accounting add column nocheckservice integer;");
- }
- // else {
- // jsdump("missing column found!");
- // }
-}
+// function check_accountingtable(){
+// var cols = appdb.dbquery("SELECT type, name,tbl_name,sql FROM sqlite_master where tbl_name='accounting';");
+// //jsdump(JSON.stringify(cols));
+// if (cols.sqldata[0].sql.indexOf("nocheckservice") == -1){
+// //jsdump("Install missing column! ALTER TABLE accounting add column nocheckservice integer");
+// appdb.dbexec("ALTER TABLE accounting add column nocheckservice integer;");
+// }
+// // else {
+// // jsdump("missing column found!");
+// // }
+// }
function load_accounting_table(){
var xsql = "DELETE from accounting where accmonth='' or accmonth is null;";
appdb.dbexec(xsql);
- var accsql = "select strftime('%m.%Y',acc.accmonth) as calmonth, " +
-"COALESCE(ch.prename,'') || ' ' || COALESCE(ch.surname,'') || '<br>(' || COALESCE(ch.checkservicenumber,'') || ')' AS childname, acc.reference as reference, " +
+ var accsql = "select strftime('%m.%Y',acc.accmonth) as calmonth,ch.clientnumber, " +
+"COALESCE(ch.prename,'') || ' ' || COALESCE(ch.surname,'') AS childname,ch.checkservicenumber, acc.reference as reference, " +
"CASE WHEN acc.invoiceamount IS NOT NULL THEN printf(\"%.2f\",COALESCE(acc.invoiceamount,0.00)) || '€' || CASE WHEN acc.invoicedate IS NOT NULL THEN '<br/>(' || strftime('%d.%m.%Y',acc.invoicedate) || ')' || CASE WHEN acc.reminderdate1 IS NOT NULL THEN '<br/>R1:' || strftime('%d.%m.%Y',acc.reminderdate1) ELSE '' END || CASE WHEN acc.reminderdate2 IS NOT NULL THEN '<br/>R2:' || strftime('%d.%m.%Y',acc.reminderdate2) ELSE '' END || CASE WHEN acc.reminderdate3 IS NOT NULL THEN '<br/>R3:' || strftime('%d.%m.%Y',acc.reminderdate3) ELSE '' END ELSE '' END ELSE '' END AS invoiced, " +
"CASE WHEN acc.payedamount IS NOT NULL THEN printf(\"%.2f\",COALESCE(acc.payedamount,0.00)) || '€' || CASE WHEN acc.payeddate IS NOT NULL THEN '<br/>(' || strftime('%d.%m.%Y',acc.payeddate) || ')' ELSE '' END ELSE '' END AS payement, " +
-"'<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_accounting(''' || strftime(\"%m.%Y\",acc.accmonth) || ''',''' || ch.uuid || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-pencil\"></span></button>' || case when acc.invoicefile is not null and acc.invoicefile != '' then '<button type=\"button\" class=\"btn btn-primary\" onclick=\"openfile(''' || acc.invoicefile || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-open\"></span></button>' else '' end AS act " +
+"'<button type=\"button\" class=\"btn btn-primary\" onclick=\"dlg_accounting(''' || acc.uuid || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-pencil\"></span></button>' || case when acc.invoicefile is not null and acc.invoicefile != '' then '<button type=\"button\" class=\"btn btn-primary\" onclick=\"openfile(''' || acc.invoicefile || ''');\" title=\"editer\"><span class=\"glyphicon glyphicon-open\"></span></button>' else '' end AS act " +
"from accounting acc join childs ch on (acc.childuuid=ch.uuid) " +
"where (acc.invoiceamount is not null and acc.payedamount is null) or (acc.payedamount < acc.invoiceamount) order by acc.accmonth desc;";
var accdata = appdb.dbquery(accsql);
- var headerdata = getlabels("calmonth,childname,reference,invoiced,payement,act");
+ var headerdata = getlabels("calmonth,clientnumber,childname,checkservicenumber,reference,invoiced,payement,act");
$("#tbl_accounting").html("");
for (var i in accdata.sqldata){
var row = accdata.sqldata[i];
var tr = '<tr><td>' + row.calmonth + '</td>';
+ tr += '<td>' + row.clientnumber + '</td>';
tr += '<td>' + row.childname + '</td>';
+ tr += '<td>' + row.checkservicenumber + '</td>';
tr += '<td>' + row.reference + '</td>';
tr += '<td class="alignright">' + row.invoiced + '</td>';
tr += '<td class="alignright">' + row.payement + '</td>';
};
fTotal = api
- .column( 2, { page: 'current'} )
+ .column( 5, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
pTotal = api
- .column( 3, { page: 'current'} )
+ .column( 6, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
- $( api.column( 2 ).footer() ).html(
+ $( api.column( 5 ).footer() ).html(
''+fTotal.toFixed(2) +' €'
);
- $( api.column( 3 ).footer() ).html(
+ $( api.column( 6 ).footer() ).html(
''+pTotal.toFixed(2) +' €'
);
}
-function dlg_accounting(accmonth,paccchild){
-
- gpaccchild=paccchild;
- var acc1sql = "SELECT accmonth,childuuid,case when invoicedate is not null then strftime('%d.%m.%Y',invoicedate) else null end as invoicedate, case when payeddate is not null then strftime('%d.%m.%Y',payeddate) else null end as payeddate, payedamount,benefitamount, invoiceamount, reference, case when reminderdate1 is not null then strftime('%d.%m.%Y',reminderdate1) else null end as reminderdate1, case when reminderdate2 is not null then strftime('%d.%m.%Y',reminderdate2) else null end as reminderdate2, case when reminderdate3 is not null then strftime('%d.%m.%Y',reminderdate3) else null end as reminderdate3,case when invoicefile is not null and invoicefile != '' then '"+ importpath.path + system.sep() +"' || invoicefile else null end as invoicefile,'upd' as action FROM accounting where accmonth = '"+ accmonth.substring(3) + "-" + accmonth.substring(0,2) +"-01' and childuuid='"+paccchild+"';";
+function dlg_accounting(myuuid){
+
+ var acc1sql = "SELECT acc.uuid as uuid,acc.accmonth,ch.prename || ' ' || ch.surname as childname,acc.nocheckservice,acc.childuuid,case when acc.invoicedate is not null then strftime('%d.%m.%Y',acc.invoicedate) else null end as invoicedate, case when acc.payeddate is not null then strftime('%d.%m.%Y',acc.payeddate) else null end as payeddate, acc.payedamount,acc.benefitamount, acc.invoiceamount, acc.reference, case when acc.reminderdate1 is not null then strftime('%d.%m.%Y',acc.reminderdate1) else null end as reminderdate1, case when acc.reminderdate2 is not null then strftime('%d.%m.%Y',acc.reminderdate2) else null end as reminderdate2, case when acc.reminderdate3 is not null then strftime('%d.%m.%Y',acc.reminderdate3) else null end as reminderdate3,case when acc.invoicefile is not null and acc.invoicefile != '' then '"+ importpath.path + system.sep() +"' || acc.invoicefile else null end as invoicefile,'upd' as action FROM accounting acc join childs ch on (acc.childuuid=ch.uuid) where acc.uuid='"+myuuid+"';";
+
+ jsdump("acc1sql");
+ jsdump(acc1sql);
var acc1data = appdb.dbquery(acc1sql);
- if (acc1data.sqldata.length == 0) {
+ if (!acc1data.sqldata) {
- acc1sql = "SELECT '"+ accmonth.substring(3) + "-" + accmonth.substring(0,2) +"-01' as accmonth,'"+ paccchild+"' as childuuid, null as invoicedate, null as payeddate, null as payedamount,null as benefitamount, null as invoiceamount, null as reference, null as reminderdate1, null as reminderdate2, null as reminderdate3, null as invoicefile, 'ins' as action;";
- acc1data = appdb.dbquery(acc1sql);
+ return false;
}
acc1data = acc1data.sqldata[0];
for (var a in acc1data){
-
+ if (a == "nocheckservice"){
+ if (acc1data[a] == 1){
+ $("#frmeditaccounting #nocheckservice").prop("checked",true);
+ } else {
+ $("#frmeditaccounting #nocheckservice").prop("checked",false);
+ }
+ }
if ($("#frmeditaccounting #" +a)) {
$("#frmeditaccounting #"+a).val(acc1data[a]);
}
function save_accounting(){
- var sql1 = new Array();
- var sql2 = new Array();
-
- var type = $("#frmeditaccounting #action").val();
- if (type == 'ins'){
- sql1.push('childuuid');
- sql2.push("'"+ gpaccchild +"'");
+ var sql1 = new Array();
+ var sql2 = new Array();
+ // var cntnum = "01";
+ var type = $("#frmeditaccounting #action").val();
+ if (type == 'ins'){
+ sql1.push('childuuid');
+ sql2.push("'"+ pconfig.accchild +"'");
+
+ }
+
+ $("#frmeditaccounting :input").each(function(){
+ var input = $(this);
+ if (input.attr("id") ){
+ if ((type == 'ins') && (input.attr("type") != 'hidden') && (input.attr("id") != 'accmonth') && (input.attr("id") != 'childname') && (input.attr("id") != 'ischeckservice')) {
+
+ sql1.push('"' + input.attr("id") + '"');
+ if (input.attr("type") == "file") {
+ var newlocation= importpath.path + system.sep() + system.getFileName(input.val());
+ if (!system.fileexists(importpath.path)){
+ importpath.create(1,0755);
+ }
+ OS.File.copy(input.val(), newlocation);
}
- $("#frmeditaccounting :input").each(function(){
- var input = $(this);
- if (input.attr("id") ){
- if ((type == 'ins') && (input.attr("id") != 'action')) {
- sql1.push('"' + input.attr("id") + '"');
- if (input.attr("type") == "file") {
- var newlocation= importpath.path + system.sep() + system.getFileName(input.val());
- OS.File.copy(input.val(), newlocation);
- }
- var ival = encodeparam(input.val(),input.attr('type'));
- sql2.push(ival);
- }else {
- if ((input.attr("id") != 'childuuid') && (input.attr("id") != 'action')) {
- if (input.attr("type") == "file") {
- if (system.getDirectory(input.val()) != importpath.path) {
- var newlocation= importpath.path + system.sep() + system.getFileName(input.val());
- OS.File.copy(input.val(), newlocation);
- }
- }
- var ival = encodeparam(input.val(),input.attr('type'));
- sql2.push('"' + input.attr("id") +'"='+ ival);
- }
+ var ival = input.val();
+ if ((input.attr("id") == 'reference') && $("#frmeditaccounting #ischeckservice").is(":checked")){
+ sql1.push("nocheckservice");
+ sql2.push("'1'");
+ }
+ var ival = encodeparam(input.val(),input.attr('type'));
+ sql2.push(ival);
+ if (input.attr("id") == 'invoicedate'){
+ sql1.push('"accmonth"');
+
+ var newaccmonth = ival.replace(/'/g,"");
+ // var cntx = appdb.dbquery("select count(accmonth)+1 as cnt from accounting where childuuid = '"+ pconfig.accchild +"' and accmonth between date('"+newaccmonth.substring(0,4) + "-" + newaccmonth.substring(5,7)+"-01') and date('"+newaccmonth.substring(0,4) + "-" + newaccmonth.substring(5,7)+"-01','+1 month','-1 day'); ");
+ // cntnum = cntx.sqldata[0].cntx;
+ // if (cntnum < 10){ cntnum = "0" + cntnum;}
+ sql2.push('\'' + newaccmonth.substring(0,4) + "-" + newaccmonth.substring(5,7) +"-01'");
+ }
+ }else {
+ if ((input.attr("type") != 'hidden') && (input.attr("id") != 'childname') && (input.attr("id") != 'ischeckservice')) {
+ if (input.attr("type") == "file") {
+ if (system.getDirectory(input.val()) != importpath.path) {
+ var newlocation= importpath.path + system.sep() + system.getFileName(input.val());
+ OS.File.copy(input.val(), newlocation);
}
}
-
- });
- var xsql = "";
- if (type == 'upd') {
- xsql = "UPDATE accounting SET "+sql2.join(',')+" where \"childuuid\"='" + gpaccchild +"' and accmonth='"+ $("#frmeditaccounting #accmonth").val() +"';";
- }else {
- xsql = "INSERT INTO accounting ("+sql1.join(',')+") VALUES ("+sql2.join(',')+");";
+ var ival = input.val();
+ if ((input.attr("id") == 'reference') && $("#frmeditaccounting #ischeckservice").is(":checked")){
+ sql2.push("nocheckservice='1'");
+ }
+ var ival = encodeparam(ival,input.attr('type'));
+ sql2.push('"' + input.attr("id") +'"='+ ival);
+ if (input.attr("id") == 'invoicedate'){
+ var newaccmonth = ival.replace(/'/g,"");
+ // var cntx = appdb.dbquery("select count(accmonth)+1 as cnt from accounting where childuuid = '"+ pconfig.accchild +"' and accmonth between date('"+newaccmonth.substring(0,4) + "-" + newaccmonth.substring(5,7)+"-01') and date('"+newaccmonth.substring(0,4) + "-" + newaccmonth.substring(5,7)+"-01','+1 month','-1 day'); ");
+ // cntnum = cntx.sqldata[0].cntx;
+ // if (cntnum < 10){ cntnum = "0" + cntnum;}
+ sql2.push('"accmonth"=\'' + newaccmonth.substring(0,4) + "-" + newaccmonth.substring(5,7) +"-01'");
+ }
+
}
- appdb.dbexec(xsql);
- load_accounting_table();
- $("#frmeditaccounting #uuid").val("0");
- $("#edit_accounting").modal('hide');
}
+ }
+
+ });
+ var xsql = "";
+ if (type == 'upd') {
+ xsql = "UPDATE accounting SET "+sql2.join(',')+" where \"uuid\"='" + $("#frmeditaccounting #uuid").val() +"';";
+ }else {
+ sql1.push("uuid");
+ sql2.push("'" + appdb.generate_uuid() + "'");
+ xsql = "INSERT INTO accounting ("+sql1.join(',')+") VALUES ("+sql2.join(',')+");";
+ }
+ //jsdump(xsql);
+ appdb.dbexec(xsql);
+ load_accounting_table();
+ $("#frmeditaccounting #uuid").val("0");
+ $("#edit_accounting").modal('hide');
+}
function print_list(){
globelreq.send_request({page:'preview2',data:{page: 'accountingopeninvoice'}});