diff --git a/js/workTime.js b/js/workTime.js
new file mode 100644
index 0000000..a51ded4
--- /dev/null
+++ b/js/workTime.js
@@ -0,0 +1,499 @@
+const Moment = require('moment');
+const MomentRange = require('moment-range');
+const moment = MomentRange.extendMoment(Moment);
+const { mongo} = require('mongoose');
+
+let WorkingTime = require('../models/workingtime');
+let Work=require('../models/works');
+let WorkReport = require('../models/workReportModel');
+let Employee = require('../models/employee');
+
+const munkaszunet=['2021.01.01','2021.03.15','2021.04.02','2021.04.05','2021.05.24','2021.08.20','2021.11.01','2021.12.24','2021.12.26',
+ '2022.01.01','2022.03.14','2022.03.15','2022.04.15','2022.04.18','2022.06.06',
+ '2023.01.01','2023.03.15','2023.04.07','2023.04.09','2023.04.10','2023.05.29','2023.10.23','2023.11.01','2023.12.25','2023.12.26',
+ '2024.01.01','2024.03.15','2024.03.29','2024.04.01','2024.05.01','2024.05.20','2024.08.20','2024.10.23','2024.11.01','2024.12.24','2024.12.25','2024.12.26','2024.12.27',
+ '2025.01.01','2025.04.18','2025.04.21','2025.05.01','2025.05.02','2025.06.09','2025.08.20','2025.10.23','2025.10.24','2024.12.25','2025.12.26'];
+
+// Munkaszüneti napok
+const _getMunkaszunet=function (cmonth)
+{
+ var t=[];
+ munkaszunet.forEach(function(a){
+ if (moment(a,'YYYY.MM.DD').isSame(moment(cmonth,'YYYY.MM'), 'month')) //true if dates are in the same month
+ {
+ t.push(moment(a,'YYYY.MM.DD').format('YYYY.MM.DD.'));
+ }
+})
+ //{date: '2021.01.06', isHoliday: true}
+//console.log(t);
+return t;
+}
+
+function getDateRangeSickPay(startDate, endDate,mindate, dateFormat) {
+ var dates = [],
+ //selectedMonth=moment(mindate,'YYYY.DD').month();
+ start=moment(startDate,'DD.MM.YYYY')
+ end = moment(endDate,'DD.MM.YYYY');
+
+ diff = end.diff(start, 'days')+1;
+
+
+ if(!start.isValid() || !end.isValid() || diff <= 0) {
+ return;
+ }
+
+ for(var i = 0; i < diff; i++) {
+
+ if (moment(start).format('YYYY.MM')===mindate)
+ {
+ //workDays.push({date:element.date,isWeekend:isWeekend,location:element.location,notes:element.notes,locations:[{arriveLoc:element.location,getawayLoc:element.locationStop}],startStop:[{start:element.timeArrive,stop:element.timeGetaway}],fullHours:element.workHours,hours:0,overTime:0});
+ dates.push({date:start.format(dateFormat),isSickpay:true})
+ }
+ start.add(1,'d');
+ }
+
+ return dates;
+};
+
+function getDateRange(startDate, endDate,mindate, dateFormat) {
+ var dates = [],
+ //selectedMonth=moment(mindate,'YYYY.DD').month();
+ start=moment(startDate,'DD.MM.YYYY')
+ end = moment(endDate,'DD.MM.YYYY');
+
+ diff = end.diff(start, 'days')+1;
+
+
+ if(!start.isValid() || !end.isValid() || diff <= 0) {
+ return;
+ }
+
+ for(var i = 0; i < diff; i++) {
+
+ if (moment(start).format('YYYY.MM')===mindate)
+ {
+ //workDays.push({date:element.date,isWeekend:isWeekend,location:element.location,notes:element.notes,locations:[{arriveLoc:element.location,getawayLoc:element.locationStop}],startStop:[{start:element.timeArrive,stop:element.timeGetaway}],fullHours:element.workHours,hours:0,overTime:0});
+ dates.push({date:start.format(dateFormat),isHoliday:true})
+ }
+ start.add(1,'d');
+ }
+
+ return dates;
+};
+
+var _oneDayCalculate=function (fullTime)
+{
+ const lunchtime=1*60
+ const expectedWorkHours=8*60
+ const overHourThreshold=1*60
+ //var fullTime=moment(stop,"YYYY.MM.DD. HH.mm").diff(moment(start,"YYYY.MM.DD. HH.mm"),"minutes")
+ const fl=fullTime-lunchtime; // Teljes idő - ebéd idő
+
+ const oh=fl-expectedWorkHours;
+ const wh=fl-(fl-expectedWorkHours);
+ var overHours=0;
+ if (oh>overHourThreshold) overHours=oh; else overHours=0;
+ const workHours=fl>=expectedWorkHours?wh:fl
+ return {workHours:workHours,overHours:overHours,lunchtime:lunchtime}
+}
+
+// Szabadság szűrés egy munkavállalóra dátum vég alapján.
+var _getHolidayListById=async function (employeeId,dateEndsWith,mindate)//,callback)
+{
+
+ var results = await Employee.aggregate([
+ { $match: {_id: mongo.ObjectId(employeeId)}},
+ { $unwind: '$holidayData'},
+ { $match: {$or:[{'holidayData.start_date': {$regex: dateEndsWith, $options:'/g/'}},{'holidayData.end_date': {$regex: dateEndsWith, $options:'/g/'}}]}},
+ //{ $group: {_id: '$_id', list: {$push: {'start_date':'$holidayData.start_date', 'end_date':'$holidayData.end_date'}}}}
+ { $group: {_id: '$_id', list: {$push: '$holidayData'}}}
+ ]
+ )
+ var days=[];
+ if (results.length>0)
+ {
+ console.log(results);
+ results[0].list.forEach(element=>{
+ var subDay=getDateRange(element.start_date,element.end_date,mindate,'YYYY.MM.DD');
+ days.push.apply(days,subDay);
+
+ })
+}
+ return days
+}
+
+// Táppénz szűrés egy munkavállalóra dátum vég alapján.
+var _getSickpayListById=async function (employeeId,dateEndsWith,mindate)//,callback)
+{
+
+ var results =await Employee.aggregate([
+ { $match: {_id: mongo.ObjectId(employeeId)}},
+ { $unwind: '$sickpayData'},
+ { $match: {$or:[{'sickpayData.start_date': {$regex: dateEndsWith, $options:'/g/'}},{'sickpayData.end_date': {$regex: dateEndsWith, $options:'/g/'}}]}},
+ { $group: {_id: '$_id', list: {$push: '$sickpayData'}}}
+ ])
+ var days=[];
+ if (results.length>0)
+ {
+ console.log(results);
+ results[0].list.forEach(element=>{
+ var subDay=getDateRangeSickPay(element.start_date,element.end_date,mindate,'YYYY.MM.DD');
+ days.push.apply(days,subDay);
+
+ })
+ }
+ return days
+
+}
+
+// workReport By User lekérdezés
+async function getWorkReportById(employeeId,mindate){
+
+ var dr_firstDay= moment(mindate,"YYYY.MM").startOf('month').toDate();
+ var dr_lastDay = moment(mindate,"YYYY.MM").endOf('month').toDate();
+
+ const result= await WorkReport.aggregate([
+ {$match: {"date":{$gte: dr_firstDay, $lte: dr_lastDay}}},
+ //{$match: {"workId": mongo.ObjectId("6715f6ca6908a157c7d1f468")}},
+ {
+
+ $unwind: "$workFlow"
+
+ },
+ { "$unwind": "$workFlow.employeeList" },
+ {$match: {"workFlow.employeeList.employeeId": mongo.ObjectId(employeeId)}},
+
+ {$group: { _id:{
+ 'wf': '$employeeList.workFlow',
+ 'wid': '$_id',
+ 'name': '$workFlow.employeeList.name',
+ },
+ 'id':{$first: '$_id'},
+ 'date':{$first:'$date'},
+ 'name': {$first:'$workFlow.employeeList.name'},
+ 'wf':{$first: '$workFlow.Title'},
+ 'wt':{$first: '$workTitle'}
+ //'nm':{$push: {name:'$employee.name', wf:'$employeeList.workFlow'}}
+ },
+ },
+ {
+ // cleanup
+ $project: {
+ _id: false,
+ }
+ }
+
+
+ ])
+ if (result.length){
+ return result
+ }
+ else
+ {
+ return []
+ }
+
+
+
+}
+
+// Munkaidő lekérdezés
+function getWorkTimeListById(employeeId,mindate,callback)
+{
+ var date = new Date();
+ var query={};
+
+// Ehavi esedékes
+
+ var firstDay= moment(mindate,"YYYY.MM").startOf('month').format("YYYY.MM.DD.");
+ var lastDay = moment(mindate,"YYYY.MM").endOf('month').format("YYYY.MM.DD.");
+ var dr_firstDay= moment(mindate,"YYYY.MM").startOf('month').format("YYYY.MM.DD");
+ var dr_lastDay = moment(mindate,"YYYY.MM").endOf('month').format("YYYY.MM.DD");
+ //query={$and:[{'state':'ENDED','date': {$gte : firstDay,$lte: lastDay},'employeeId': employeeId}]};
+ query={$and:[{'date': {$gte : firstDay,$lte: lastDay},'employeeId': employeeId}]};
+
+ WorkingTime.find(query,null,function(err, wt){
+ if (err)
+ {
+ callback(err);
+ }
+ else {
+ Work.aggregate([
+ {$unwind: '$dailyReport'},
+ {
+ "$match":{
+ "dailyReport.employeeList": mongo.ObjectId(employeeId)
+ },
+
+ },
+
+ {"$match": {"dailyReport.date": {$gte: dr_firstDay, $lte: dr_lastDay} }},
+ {$group: { _id: '$dailyReport._id','name': {$first: '$title'},'wid': {$first: '$_id'},'date': {$first: '$dailyReport.date'}}},
+ ], function(err,dr){
+ if (err)
+ {
+ callback(err);
+ }else
+ {
+ wt.rd=dr;
+ // wt.wr=workReport // WorkReport Lekérése.;
+ callback(null,wt);
+ }
+ })
+
+ }
+ });
+}
+
+// Egy havi munkaidő összegzés
+var _sumOfMonth=async function(employee_id,mindate,callback)
+{
+ var msz=_getMunkaszunet(mindate);
+
+ workReport=await getWorkReportById(employee_id,mindate)//.then(workReport=>{ // WorkReport Lekérése.
+ getWorkTimeListById(employee_id,mindate,function(err,wt){
+ if (err)
+ {
+ console.log(err);
+ callback(err);
+ }
+ else {
+ var workDays=[];
+ //wt.forEach(function(element)
+ for (var element of wt)
+ {
+ var isMunkaszunet=false;//hoursToday=0;
+ var drName='';
+ var dwr=''
+ var day = moment(element.date,'YYYY.MM.DD.').day();
+ var drDate = moment(element.date,'YYYY.MM.DD.').format('YYYY.MM.DD');
+ var isWeekend = (day === 6) || (day === 0); // 6 = Saturday, 0 = Sunday
+ var latS=element.latitudeS;
+ var lonS=element.longitudeS;
+ var latE=element.latitudeE;
+ var lonE=element.longitudeE;
+ var workOnMunkaszunet=false;
+
+
+ //var cNotes="";
+ //var notes="";
+
+ var wr={}
+ if (workReport.length){
+ // wr=workReport.find(wrelement => wrelement.date===new Date(drDate))
+ workReport.forEach(function(wrelement){
+ ///console.log(`Itemdate: ${wrelement.date} CurrDate: ${new Date(drDate)}`)
+ if (new Date(wrelement.date).getTime()===new Date(drDate).getTime())
+ {
+ // console.log("Egyenlő!\n")
+ wr=wrelement;
+ }
+ })
+
+ // if (wr!={})
+ // console.log(wr.date)
+ }
+ var dr=wt.rd.filter(element => element.date==drDate)
+ if (typeof element.latitudeS==='undefined') latS='N/A'
+ if (typeof element.longitudeS==='undefined') lonS='N/A'
+ if (typeof element.latitudeE==='undefined') latE='N/A'
+ if (typeof element.longitudeE==='undefined') lonE='N/A'
+
+ // Ha hétköznap
+ var wdays=workDays.find(e=>e.date===element.date);
+ if (wdays)
+ { // Már van ilyen nap
+
+ wdays.startStop.push({id:element._id,start:element.timeArrive,stop:element.timeGetaway});
+ wdays.locations.push({
+ arriveLoc:element.location,
+ getawayLoc:element.locationStop,
+ arriveCoords:{lat:latS,lon:lonS},
+ getavayCoords:{lat:latE,lon:lonE}
+ });
+ wdays.notes.push({userNote:element.notes, companyNote: element.company_notes});
+
+ wdays.fullHours+=element.workHours;
+ }
+ else
+ {
+
+ if (typeof wr==='undefined')
+ {
+ dwr='';
+ }
+ else
+ {
+ dwr=wr;
+ }
+ if (typeof dr==='undefined')
+ {
+ drName='';
+ }
+ else
+ {
+ drName=dr;
+ }
+ // Még nincs ilyen nap, hozzáadjuk
+ const idxmsz=msz.indexOf(element.date);
+ if (idxmsz!==-1)
+ {
+ isMunkaszunet=true;
+ element.company_notes="Ünnep"
+ workOnMunkaszunet=true;
+ element.isMunkaszunet=true
+ msz.splice(idxmsz, 1);
+ }
+ workDays.push({
+ date:element.date,
+ isMunkaszunet:isMunkaszunet,
+ workOnMunkaszunet:element.workOnMunkaszunet,
+ isHoliday:false,
+ isSickpay:false,
+ isWeekend:isWeekend,
+ state:element.state,
+ location:element.location,
+ notes:[{
+ userNote: element.notes,
+ companyNote: element.company_notes ?? "-"
+ }],
+ companyNotes: element.company_notes ?? "",
+ locations:[{
+ arriveLoc:element.location,
+ getawayLoc:element.locationStop,
+ arriveCoords:{lat:element.latitudeS,lon:element.longitudeS},
+ getavayCoords:{lat:element.latitudeE,lon:element.longitudeE}
+ }],
+ startStop:[{
+ id:element._id,
+ start:element.timeArrive,
+ stop:element.timeGetaway
+ }],
+ fullHours:element.workHours,
+ hours:0,
+ overTime:0,
+ dailyReport:drName,
+ workReport:dwr
+ });
+ }
+
+
+ }
+ msz.forEach(function(munkaszunet){
+ workDays.push({date:munkaszunet,isMunkaszunet:true,hours:480,overTime:0,Surrogate:0,fullHours:0,startStop:[],locations:[],notes:[{userNote:'', companyNote: 'Ünnep'}]})
+ })
+ callback(null,workDays);
+ }
+ })//})
+
+}
+
+var _getAccessDetails=async function(id,mindate,callback) {
+
+ var holidaysArray=await _getHolidayListById(id,moment(mindate,'YYYY.MM').format('MM.YYYY'),mindate)//,function(err,holidaysArray){
+ var sickpaysArray=await _getSickpayListById(id,moment(mindate,'YYYY.MM').format('MM.YYYY'),mindate)
+
+
+ _sumOfMonth(id,mindate,function(err,som){
+ if (err)
+ {
+ console.log(err);
+ callback(err);
+ }
+ else {
+ var month={overTime:0,workHours:0,fullWorkHours:0,sickPays:0};
+ //var weekend={overTime:0,workHours:0,fullWorkHours:0,days:0};
+ var weekend={
+ Saturday:{overTime:0,workHours:0,fullWorkHours:0,days:0,Surrogate:0},
+ Sunday:{overTime:0,workHours:0,fullWorkHours:0,days:0,Surrogate:0}
+ }
+ //var monthOverTime=0;
+ //var monthWorkHours=0;
+ //som.forEach(function(element)
+ for (var element of som)
+ {
+ var hoursToday=0;
+ var day = moment(element.date,'YYYY.MM.DD.').day();
+
+ if (element.state=="ENDED")//element.startStop[element.startStop.length-1].stop!='-')
+ {
+ // Napi idő kiszámítása
+ var dayWorkHours=_oneDayCalculate(element.fullHours);
+
+ element.lunchtime=dayWorkHours.lunchtime;
+ if (element.isWeekend)
+ {
+
+ if (day===6) // Szombat
+ {
+ element.hours=(dayWorkHours.workHours);
+ element.overTime=(dayWorkHours.overHours);
+ element.Surrogate=Math.ceil((element.hours+element.overTime)*0.5);
+ weekend.Saturday.workHours+=(element.hours*1.5);
+ weekend.Saturday.overTime+=(element.overTime*1.5);
+ weekend.Saturday.fullWorkHours+=((element.hours+element.overTime)*1.5);
+ weekend.Saturday.days+=1;
+ weekend.Saturday.Surrogate+=element.Surrogate;
+
+ }
+ if (day===0) // Vasárnap
+ {
+ element.hours=dayWorkHours.workHours;
+ element.overTime=dayWorkHours.overHours;
+ element.Surrogate=(element.hours+element.overTime)
+ weekend.Sunday.workHours+=element.hours;
+ weekend.Sunday.overTime+=element.overTime;
+ weekend.Sunday.fullWorkHours+=(element.hours+element.overTime);
+ weekend.Sunday.days+=1;
+ weekend.Sunday.Surrogate+=element.Surrogate;
+ }
+
+ }
+ else
+ {
+ // Ha hétköznap
+ element.hours=dayWorkHours.workHours;//element.hours=540;
+ element.overTime=dayWorkHours.overHours;//element.fullHours-element.hours
+ element.Surrogate=0;
+ month.workHours+=element.hours;
+ month.overTime+=element.overTime;
+ month.fullWorkHours+=(element.hours+element.overTime);
+
+ } // is Weekend
+ }
+ else
+ {
+ element.lunchtime=60;
+ element.Surrogate=0;
+ }
+
+ }
+ var ja;
+ var msz=_getMunkaszunet(mindate);
+
+ if (som.length>0) {
+ ja = som.concat(holidaysArray);
+ ja=ja.concat(sickpaysArray);
+ }
+ else
+ {
+ ja=holidaysArray;
+ }
+ ja.sort(function(a, b) {
+ return moment(a.date,'YYYY.MM.DD') - moment(b.date,'YYYY.MM.DD');
+ });
+ month.sickPays=sickpaysArray.length;
+ //callback(null,som,month,weekend);
+ callback(null,ja,month,weekend);
+ }
+ });
+ };
+
+ module.exports={
+ getMunkaszunet:_getMunkaszunet,
+ sumOfMonth: _sumOfMonth,
+ getAccessDetails: _getAccessDetails,
+ getHolidayListById: _getHolidayListById,
+ getSickpayListById: _getSickpayListById,
+ oneDayCalculate: _oneDayCalculate,
+ }
\ No newline at end of file
diff --git a/print/printAccessDetailsEmp.js b/print/printAccessDetailsEmp.js
new file mode 100644
index 0000000..094da6b
--- /dev/null
+++ b/print/printAccessDetailsEmp.js
@@ -0,0 +1,339 @@
+const moment = require('moment');
+// Nyomtatási kép generálás alkalmazottak
+// Segéd funkciók
+function convertMinsToHrsMins(minutes) {
+ var h = Math.floor(minutes / 60);
+ var m = minutes % 60;
+ h = h < 10 ? '0' + h : h;
+ m = m < 10 ? '0' + m : m;
+ return h + ':' + m;
+}
+
+function convertMinsToHrsMins_R(minutes) {
+ var h = Math.floor(minutes / 60);
+ var m = minutes % 60;
+ if (m>=30) {
+ h+=1;
+ }
+ h = h < 10 ? '0' + h : h;
+ //m = m < 10 ? '0' + m : m;
+ return h;// + ':' + m;
+}
+
+exports.printPage=function(employee,som,month,weekend,mindate,holidaysArray,sickpaysArray,msz)
+{
+ var dt = new Date();
+ var item=[];
+ var i=1;
+ var namePostfix="";
+ var drShift="";
+ // Munkaszüneti napok ellenőrzése és kijelzése
+ //var msz=getMunkaszunet(mindate);
+ moment.locale('hu');
+
+ if (employee.isStudent==='on') namePostfix='Diák';
+
+ som.sort(function(a, b) {
+ return moment(a.date,'YYYY.MM.DD') - moment(b.date,'YYYY.MM.DD');
+ });
+
+
+ item.push(['Dátum', //{text:'Nap', alignment: 'rleft'},
+ {text:'Helyszín', alignment: 'center'},
+ {text:'Érkezés', alignment: 'center'},
+ {text:'Távozás', alignment: 'center'},
+ {text:'Órák', alignment: 'center'},
+ {text:'Ebéd', alignment: 'center'},
+ {text:'Elszámolt', alignment: 'center'},
+ {text:'Túlóra', alignment: 'center'},
+ {text:'Pótlék', alignment: 'center'},
+ 'Megjegyzés']);
+ som.forEach(element => {
+ var arrives="";
+ var getaways="";
+ var locs="";
+ var dreportList='';
+ var workReport='';
+ var locShift='';
+ var wrShift='';
+ var date = moment(element.date,'YYYY.MM.DD. HH:mm').format('DD')+' '+moment(element.date,'YYYY.MM.DD. HH:mm').format('dd').toUpperCase();
+ var notes="";
+
+
+ //if (element.dailyReport!='') drShift='\r\n'; else drShift='';
+ drShift='';
+ if (element.dailyReport)
+ {
+ if (element.dailyReport.length)
+ {
+ //drShift='\r\n';
+ locShift='\r\n'
+ }
+ element.dailyReport.forEach(drelem=>{
+ dreportList+= drelem.name.substring(0,60);
+ if (element.dailyReport.length>1) dreportList+='\r\n'
+ drShift+='\r\n';
+ })
+ }
+ else
+ {
+ drShift='';
+ }
+ if (element.isHoliday || element.isSickpay || element.isMunkaszunet)
+ {
+ var txt='';
+ var st='';
+ if (element.isHoliday) {txt='Szabadság';st='tableDataHo';}
+ if (element.isSickpay) {txt='Táppénz';st='tableDataSp';}
+ if (element.isMunkaszunet) {txt='Ünnep';st='tableDataHo';}
+ item.push([
+ {text:date, style:st},
+ {text:' --- ', style:st, alignment: 'center'},
+ {text:'--:--', style:st, alignment: 'center'},
+ {text:'--:--', style:st, alignment: 'center'},
+ {text:'--:--', style:st, alignment: 'center'},
+ {text:'--:--', style:st, alignment: 'center'},
+ {text:'--:--', style:st, alignment: 'center'},
+ {text:'--:--', style:st, alignment: 'center'},
+ {text:'--:--', style:st, alignment: 'center'},
+ {text: txt, style:st, alignment: 'left'}]);
+ }
+ else
+ {
+ if (element.workReport){
+ locShift='\r\n'
+ //if (Object.keys(element.workReport).length!=0){
+ if (Object.entries(element.workReport).length)
+ {
+ workReport='M: '+element.workReport.wt+' '+element.workReport.wf;
+ workReport=workReport.substring(0,60);
+ wrShift='\r\n'
+ }
+ }
+ element.notes.forEach(note=>{
+ notes+=note.userNote+' '+note.companyNote
+ })
+ if (element.isWeekend)
+ {
+ // Hétvége
+
+ element.startStop.forEach(interval=>{
+ arrives+=moment(interval.start,'YYYY.MM.DD. HH:mm').format('HH:mm')+"\r\n";
+ if (interval.stop==='-')
+ {
+ getaways+='-\r\n';
+ }
+ else
+ {
+ getaways+=moment(interval.stop,'YYYY.MM.DD. HH:mm').format('HH:mm')+"\r\n";
+ }
+ })
+
+ item.push([
+ {text:date, style:'tableDataWe'},
+ {text:dreportList+workReport+locShift+element.locations[0].arriveLoc+' - '+element.locations[0].getawayLoc, style:'tableDataWe', alignment: 'center'},
+ {text:drShift+wrShift+arrives, style:'tableDataWe', alignment: 'center'},
+ {text:drShift+wrShift+getaways, style:'tableDataWe', alignment: 'center'},
+ {text:drShift+wrShift+convertMinsToHrsMins(element.fullHours), style:'tableDataWe', alignment: 'center'},
+ {text:drShift+wrShift+convertMinsToHrsMins(element.lunchtime), style:'tableDataWe', alignment: 'center'},
+ {text:drShift+wrShift+convertMinsToHrsMins(element.hours), style:'tableDataWe', alignment: 'center'}, //Elszámolt
+ {text:drShift+wrShift+convertMinsToHrsMins(element.overTime), style:'tableDataWe', alignment: 'center'},
+ {text:drShift+wrShift+convertMinsToHrsMins(element.Surrogate), style:'tableDataWe', alignment: 'center'}, //Pótlék
+ {text:drShift+wrShift+notes, style:'tableDataWe', alignment: 'left'}]);
+ }
+ else
+ {
+ // Hétköznap
+ element.startStop.forEach(interval=>{
+ arrives+=moment(interval.start,'YYYY.MM.DD. HH:mm').format('HH:mm')+"\r\n";
+ if (interval.stop==='-')
+ {
+ getaways+='-\r\n';
+ }
+ else
+ {
+ getaways+=moment(interval.stop,'YYYY.MM.DD. HH:mm').format('HH:mm')+"\r\n";
+ }
+
+ })
+ element.locations.forEach(interval=>{
+ locs+=interval.arriveLoc+' - '+interval.getawayLoc+"\r\n";
+ })
+ item.push([
+ {text:date, style:'tableData'},
+ [{text:dreportList+workReport, style:'dailyReport'},{text:locs, style:'tableDataLoc', alignment: 'center'}],
+ {text:drShift+wrShift+arrives, style:'tableData', alignment: 'center'},
+ {text:drShift+wrShift+getaways, style:'tableData', alignment: 'center'},
+ {text:drShift+wrShift+convertMinsToHrsMins(element.fullHours), style:'tableData', alignment: 'center'},
+ {text:drShift+wrShift+convertMinsToHrsMins(element.lunchtime), style:'tableData', alignment: 'center'},
+ {text:drShift+wrShift+convertMinsToHrsMins(element.hours), style:'tableData', alignment: 'center'}, //Elszámolt
+ {text:drShift+wrShift+convertMinsToHrsMins(element.overTime), style:'tableData', alignment: 'center'},
+ {text:drShift+wrShift+convertMinsToHrsMins(element.Surrogate), style:'tableData', alignment: 'center'}, //Pótlék
+ {text:drShift+wrShift+notes, style:'tableDataWe', alignment: 'left'}]);
+ }
+ }//else
+ return
+ });
+ item.push([
+ {text:'Összesen:', style:'tableSum',colSpan: 6},
+ // {text:'', style:'tableSum'},
+ {text:'', style:'tableSum'},
+ {text:'', style:'tableSum'},
+ {text:'', style:'tableSum'},
+ {text:'', style:'tableSum'},
+ {text:'', style:'tableSum'},
+ {text: convertMinsToHrsMins(month.workHours), style:'tableSum', alignment: 'center'},
+ {text: convertMinsToHrsMins(month.overTime), style:'tableSum', alignment: 'center'},
+ {text: convertMinsToHrsMins(weekend.Saturday.Surrogate+weekend.Sunday.Surrogate), style:'tableSum', alignment: 'center'},
+ {text:'', style:'tableSum'},
+ ])
+// playground requires you to assign document definition to a variable called dd
+
+ if (employee.isSubcontractor==='on') employee.name+=" Alvállalkozó"
+ if (employee.isStudent==='on') employee.name+=" Tanuló"
+var dd = {
+ pageOrientation: 'landscape',
+ footer: function(currentPage, pageCount) { return {text: currentPage.toString() + ' / ' + pageCount, alignment: 'center'}},
+ header: {
+ alignment: 'justify',
+ columns: [
+ {text: 'Jelenléti ív '+employee.name+' '+namePostfix, style: 'header',margin: [ 20, 10, 10, 20 ],width: '*'},
+ {text: mindate, style: 'datum',margin: [ 5, 10, 20, 20 ],width: '*'}
+ ]
+ },
+ content: [
+
+
+ {
+ style: 'tableExample',
+ table: {
+
+ headerRows: 1,
+ widths: ['auto', 'auto','auto','auto','auto','auto','auto','auto','auto','*'],
+ body: [],
+
+ }
+ },
+ {
+ stack:[
+ {alignment: 'justify', columnGap: 10,
+ columns:[
+ {style: 'subheader',width: 'auto',alignment: 'left',margin: [ 5, 2, 0, 5 ],text: 'Ledolgozott órák:\n'+
+ 'Túlórák:\n'+
+ 'Hétvégi pótlékok:' },
+ {style: 'subheader',width: 'auto',alignment: 'right',margin: [ 5, 2, 0, 5 ],text: `${convertMinsToHrsMins(month.workHours)} óra\n${convertMinsToHrsMins(month.overTime)} óra\n${convertMinsToHrsMins(weekend.Saturday.Surrogate+weekend.Sunday.Surrogate)} óra\n`}
+ ]},
+ {alignment: 'justify',
+ columns:[
+ {style: 'subheader',width: 'auto',alignment: 'left',margin: [ 5, 2, 0, 5 ],text: 'Kiadott szabadság:\n'+
+ 'Táppénz:\n'+
+ 'Munkaszüneti napok:'},
+ {style: 'subheader',width: '*',alignment: 'left',margin: [ 5, 2, 0, 5 ],text: `${holidaysArray.length} nap\n${month.sickPays} nap\n${msz.length} nap (${msz})\n`}
+ ]},
+
+
+
+ ],
+ unbreakable: true,
+ id:'signature'
+ }
+ ],
+ pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
+ //check if signature part is completely on the last page, add pagebreak if not
+ if (currentNode.id === 'signature' && (currentNode.pageNumbers.length != 1 || currentNode.pageNumbers[0] != currentNode.pages)) {
+ return true;
+ }
+ //check if last paragraph is entirely on a single page, add pagebreak if not
+ else if (currentNode.id === 'closingParagraph' && currentNode.pageNumbers.length != 1) {
+ return true;
+ }
+ return false;
+ },
+ styles: {
+ header: {
+ fontSize: 18,
+ bold: true,
+ fillColor: '#eeeeee',
+ margin: [0, 0, 0, 10]
+ },
+ dailyReport: {
+ fontSize: 8,
+ bold: true,
+ fillColor: '#494',
+ alignment: 'center'
+ },
+ datum: {
+ fontSize: 18,
+ bold: true,
+ fillColor: '#eeeeee',
+ alignment: 'right'
+ },
+ subheader: {
+ fontSize: 14,
+ bold: true,
+ fillColor: '#eeeeee',
+ margin: [0, 10, 0, 5]
+ },
+ tableExample: {
+ margin: [0, 5, 0, 15]
+ },
+ tableHeader: {
+ bold: true,
+ fontSize: 10,
+ fillColor: '#eeeeee',
+ color: 'red'
+ },
+ tableData: {
+ bold: false,
+ fontSize: 10,
+ italics: true,
+ color: 'green'
+ },
+ tableSum: {
+ bold: true,
+ fontSize: 10,
+ italics: true,
+ fillColor: '#ddddff',
+ color: 'black'
+ },
+ tableDataLoc: {
+ bold: false,
+ fontSize: 8,
+ italics: true,
+ color: 'green'
+ },
+ tableDataWe: {
+ bold: false,
+ fontSize: 10,
+ italics: true,
+ fillColor: '#eeffee',
+ color: 'red'
+ },
+ tableDataHo: {
+ bold: false,
+ fontSize: 10,
+ italics: true,
+ fillColor: '#eeeeff',
+ color: 'red'
+ },
+ tableDataSp: {
+ bold: false,
+ fontSize: 10,
+ italics: true,
+ fillColor: '#eeeeee',
+ color: 'brown'
+ }
+ },
+ defaultStyle: {
+ // alignment: 'justify'
+ }
+};
+dd.content[0].table.body=item;
+
+ //pdf.createPdf(dd).open();
+ // callback(null,dd);
+ return dd;
+ // ...
+
+
+}
diff --git a/public/js/workingtime.js b/public/js/workingtime.js
index 6e9310b..446f691 100644
--- a/public/js/workingtime.js
+++ b/public/js/workingtime.js
@@ -52,7 +52,7 @@ function renderWorkingTimesTable(wtList)
'
'+wt.state+
' | '+wt.device+
' | '+wt.location+
- ' | '+convertMinsToHrsMins(wt.month.fullHours)+//workHours)+
+ ' | '+convertMinsToHrsMins(wt.month.workHours)+//workHours)+
' | ');
}
else
@@ -66,7 +66,7 @@ function renderWorkingTimesTable(wtList)
''+wt.state+
' | '+wt.device+
' | '+wt.location+
- ' | '+convertMinsToHrsMins(wt.month.fullHours)+//workHours)+
+ ' | '+convertMinsToHrsMins(wt.month.workHours)+//workHours)+
' | ');
}
}
@@ -215,7 +215,15 @@ function renderWorkingTimesTableDetailed(wtList)
document.getElementById('weekHourWork').value=convertMinsToHrsMins(monthWorkHours);
document.getElementById('overTime').value=convertMinsToHrsMins(overTime);
}
-
+function isEmpty(obj) {
+ for (var prop in obj) {
+ if (Object.prototype.hasOwnProperty.call(obj, prop)) {
+ return false;
+ }
+ }
+
+ return true
+ }
// Táblázat sorainak generálása jelenléti ív részletes egy munkavállalóra egy havi
function renderWorkingTimesTableDetailed2(wtList)
{
@@ -246,7 +254,6 @@ function renderWorkingTimesTableDetailed2(wtList)
var drName='';
var drShift='';
var wrName='';
-
var notes="";
//var companyNotes="";
/* if (wt.dailyReport==='')
@@ -265,16 +272,24 @@ function renderWorkingTimesTableDetailed2(wtList)
}*/
//overTime='-';
- if (wt.isHoliday===false)
+ if (wt.isHoliday===false && wt.isSickpay===false )
{
+ if (isEmpty(wt.workReport))
+ {
+ wrName='';
+ //wrShift='';
+ }
+ else{
+ drShift+='
';
+ }
if (wt.dailyReport==='')
{
drName='';
- drShift='';
+ //drShift='';
}
else
{
- drShift='';
+ //drShift='';
//drShift='
';
$.each(wt.dailyReport,function(i,drs){
drShift+='
';
@@ -291,6 +306,12 @@ function renderWorkingTimesTableDetailed2(wtList)
color='#FB667A';
}
+ if (wt.isMunkaszunet)
+ {
+ // Ha hétvége
+ color='red';
+
+ }
//document.getElementById("modifyColumn").rowSpan = wt.startStop.length;
/*if (wt.startStop.length>1)
{
@@ -298,8 +319,8 @@ function renderWorkingTimesTableDetailed2(wtList)
}
else
{*/
- modifyColumn='';
- deleteColumn=' | ';
+ modifyColumn=' | '+drShift;
+ deleteColumn=' | '+drShift;
//}
$.each(wt.startStop,function(i,interval){//
arrives+=moment(interval.start,'YYYY.MM.DD. HH:mm').format('HH:mm')+" ";
@@ -310,15 +331,15 @@ function renderWorkingTimesTableDetailed2(wtList)
}*/
if (interval.stop==='-')
{
- modifyColumn+=' ';
- deleteColumn+=' ';
+ modifyColumn+=' ';
+ deleteColumn+='';
getaways+="-";
}
else
{
- modifyColumn+='';
- deleteColumn+='';
+ modifyColumn+='';
+ deleteColumn+='';
getaways+=moment(interval.stop,'YYYY.MM.DD. HH:mm').format('HH:mm')+" ";
}
@@ -347,9 +368,10 @@ function renderWorkingTimesTableDetailed2(wtList)
$.each(wt.notes,function(i,note){
notes+=''+note.userNote+''+ ' '+note.companyNote+' '
})
+
newRow.append(
- ''+moment(wt.date,'YYYY.MM.DD. HH:mm').format('DD')+' | '+
- ''+moment(wt.date,'YYYY.MM.DD. HH:mm').format('dddd')+' | '+
+ ''+moment(wt.date,'YYYY.MM.DD. HH:mm').format('DD')+' | '+
+ ''+moment(wt.date,'YYYY.MM.DD. HH:mm').format('dd').toUpperCase()+' | '+
''+drName+wrName+locs+''+' | '+//wt.location+
''+drShift+arrives+' | '+//moment(wt.timeArrive,'YYYY.MM.DD. HH:mm').format('HH:mm')+
@@ -357,8 +379,11 @@ function renderWorkingTimesTableDetailed2(wtList)
modifyColumn+
deleteColumn+
//' | '+convertMinsToHrsMins(wt.workHours)+
- ' | '+drShift+convertMinsToHrsMins(wt.hours)+' | '+
- ''+drShift+convertMinsToHrsMins(wt.overTime)+' | '+
+ ''+drShift+convertMinsToHrsMins(wt.fullHours)+' | '+
+ ''+drShift+convertMinsToHrsMins(wt.lunchtime)+' | '+
+ ''+drShift+convertMinsToHrsMins(wt.hours)+' | '+
+ ''+drShift+convertMinsToHrsMins(wt.overTime)+' | '+
+ ''+drShift+convertMinsToHrsMins(wt.Surrogate)+' | '+
//''+wt.notes+''+ ' '+wt.companyNotes+''+' | '
''+notes+' | '
);
@@ -370,7 +395,7 @@ function renderWorkingTimesTableDetailed2(wtList)
hol++;
newRow.append(
''+moment(wt.date,'YYYY.MM.DD. HH:mm').format('DD')+
- ' | '+moment(wt.date,'YYYY.MM.DD. HH:mm').format('dddd')+
+ ' | '+moment(wt.date,'YYYY.MM.DD. HH:mm').format('dd').toUpperCase()+
' | ---- '+//wt.location+
' | --:-- '+//moment(wt.timeArrive,'YYYY.MM.DD. HH:mm').format('HH:mm')+
@@ -380,16 +405,77 @@ function renderWorkingTimesTableDetailed2(wtList)
//' | '+convertMinsToHrsMins(wt.workHours)+
' | --:--'+
' | --:--'+
+ ' | --:--'+
+ ' | --:--'+
+ ' | --:--'+
' | Szabadság'+
' | ');
}
-
+ if (wt.isSickpay===true)
+ {
+ hol++;
+ newRow.append(
+ ''+moment(wt.date,'YYYY.MM.DD. HH:mm').format('DD')+
+ ' | '+moment(wt.date,'YYYY.MM.DD. HH:mm').format('dd').toUpperCase()+
+ ' | ---- '+//wt.location+
+ ' | --:-- '+//moment(wt.timeArrive,'YYYY.MM.DD. HH:mm').format('HH:mm')+
+
+ ' | --:--'+
+ ' | '+
+ ' | '+
+ //' | '+convertMinsToHrsMins(wt.workHours)+
+ ' | --:--'+
+ ' | --:--'+
+ ' | --:--'+
+ ' | --:--'+
+ ' | --:--'+
+ ' | Táppénz'+
+ ' | ');
+ }
+ }
+ if (wt.isMunkaszunet===true && wt.startStop.length===0)
+ {
+
+ newRow.append(
+ ''+moment(wt.date,'YYYY.MM.DD. HH:mm').format('DD')+
+ ' | '+moment(wt.date,'YYYY.MM.DD. HH:mm').format('dd').toUpperCase()+
+ ' | ---- '+//wt.location+
+ ' | --:-- '+//moment(wt.timeArrive,'YYYY.MM.DD. HH:mm').format('HH:mm')+
+
+ ' | --:--'+
+ ' | '+
+ ' | '+
+ //' | '+convertMinsToHrsMins(wt.workHours)+
+ ' | --:--'+
+ ' | --:--'+
+ ' | --:--'+
+ ' | --:--'+
+ ' | --:--'+
+ ' | Ünnep'+
+ ' | ');
}
$('#monthHoursTableDetails > tbody:last-child').append (newRow);
// document.getElementById('weekendsCount').value=wtList.weekend.days;//weekendDays.length;
})
-
+ var sumRow=''+
+ '| ∑ | '+
+ ' | '+
+ ' | '+
+ ' | '+
+ ' | '+
+ ' | '+
+ ' | '+
+ ' | '+
+ ' | '+
+ ''+convertMinsToHrsMins(wtList.month.workHours)+' | '+
+ ''+convertMinsToHrsMins(wtList.month.overTime)+' | '+
+ ''+convertMinsToHrsMins(wtList.weekend.Saturday.Surrogate+wtList.weekend.Sunday.Surrogate)+' | '+
+ ' | '+
+ '
'
+ $('#monthHoursTableDetails > tbody:last-child').append (sumRow);
+
+
// személyi adatok lekérése
var uid=document.getElementById('uid').textContent;
@@ -399,16 +485,35 @@ function renderWorkingTimesTableDetailed2(wtList)
document.getElementById('vacations').value=(employee.vacationYear-employee.vacationUsed);
document.getElementById('vacationsY').value=employee.vacationYear;
document.getElementById('munkaszunet').value=wtList.munkaszunet.length;
- newRow=$('"'+
- '| Munkaszüneti napokra elszámolt órák: '+' | '+
- ' '+convertMinsToHrsMins((wtList.munkaszunet.length*480))+' | '+
- ' --:--'+' | '+
- ' '+convertMinsToHrsMins((wtList.munkaszunet.length*480))+' | '+
- ' -'+' | '+
- ' '+convertMinsToHrsMins((wtList.munkaszunet.length*480))+' | '+
+ newRow=$(
+ '
"'+
+ '| Ledolgozott órák: '+' | '+
+ ' '+convertMinsToHrsMins(wtList.month.workHours)+' | '+
'"
'+
'"'+
- '| Szabadságra elszámolt órák: '+' | '+
+ ' Túlórák: '+' | '+
+ ' '+convertMinsToHrsMins(wtList.month.overTime)+' | '+
+ '"
'+
+ '"'+
+ '| Hétvégi pótlékok: '+' | '+
+ ' '+convertMinsToHrsMins(wtList.weekend.Saturday.Surrogate+wtList.weekend.Sunday.Surrogate)+' | '+
+ '"
'+
+ '"'+
+ '| Kiadott szabadságok: '+' | '+
+ ' '+wtList.munkaszunet.length+' | '+
+ '"
'+
+ '"'+
+ '| Táppénz: '+' | '+
+ ' '+wtList.month.sickPays+' | '+
+ '"
'+
+
+ '"'+
+ '| Munkaszüneti napok: '+' | '+
+ ' '+wtList.munkaszunet.length+' | '+
+ '"
'
+
+ /*'"'+
+ '| Kiadott szabadságok: '+' | '+
' '+convertMinsToHrsMins((hol*480))+' | '+
' --:--'+' | '+
' '+convertMinsToHrsMins((hol*480))+' | '+
@@ -464,55 +569,27 @@ function renderWorkingTimesTableDetailed2(wtList)
(wtList.munkaszunet.length*480)+
(hol*480)
)+''+
- '"
'
+ '"'*/
);
}
else
{ // Vállalkozó
newRow=$(
'"'+
- '| Munkanapok: '+' | '+
+ ' Ledolgozott órák: '+' | '+
' '+convertMinsToHrsMins(wtList.month.workHours)+' | '+
+ '"
'+
+ '"'+
+ '| Túlórák: '+' | '+
' '+convertMinsToHrsMins(wtList.month.overTime)+' | '+
- ' '+convertMinsToHrsMins(wtList.month.fullWorkHours)+' | '+
- //' -'+' | '+
- //' '+convertMinsToHrsMins(wtList.month.fullWorkHours)+' | '+
'"
'+
'"'+
- '| Szombat: '+' | '+
- ' '+convertMinsToHrsMins(wtList.weekend.Saturday.workHours)+' | '+
- ' '+convertMinsToHrsMins(wtList.weekend.Saturday.overTime)+' | '+
- ' '+convertMinsToHrsMins(wtList.weekend.Saturday.fullWorkHours)+' | '+
- //' 50%'+' | '+
- //' '+convertMinsToHrsMins((wtList.weekend.Saturday.fullWorkHours*1.5))+' | '+
+ ' Hétvégi pótlékok: '+' | '+
+ ' '+convertMinsToHrsMins(wtList.weekend.Saturday.Surrogate+wtList.weekend.Sunday.Surrogate)+' | '+
'"
'+
'"'+
- '| Vasárnap: '+' | '+
- ' '+convertMinsToHrsMins(wtList.weekend.Sunday.workHours)+' | '+
- ' '+convertMinsToHrsMins(wtList.weekend.Sunday.overTime)+' | '+
- ' '+convertMinsToHrsMins(wtList.weekend.Sunday.fullWorkHours)+' | '+
- //' 100%'+' | '+
- //' '+convertMinsToHrsMins((wtList.weekend.Sunday.fullWorkHours*2))+' | '+
- '"
'+
- '"'+
- '| Összesen: '+' | '+
- ' '+convertMinsToHrsMins(wtList.month.workHours+
- wtList.weekend.Saturday.workHours+
- wtList.weekend.Sunday.workHours
- )+' | '+
- ' '+convertMinsToHrsMins(wtList.month.overTime+
- wtList.weekend.Saturday.overTime+
- wtList.weekend.Sunday.overTime
- )+' | '+
- ' '+convertMinsToHrsMins(wtList.month.fullWorkHours+
- wtList.weekend.Saturday.fullWorkHours+
- wtList.weekend.Sunday.fullWorkHours
- )+' | '+
- //''+' | '+
- /*' '+convertMinsToHrsMins(wtList.month.fullWorkHours+
- (wtList.weekend.Saturday.fullWorkHours*1.5)+
- (wtList.weekend.Sunday.fullWorkHours*2)
- )+' | '*/+
+ ' Munkaszüneti napok: '+' | '+
+ ' '+wtList.munkaszunet.length+' | '+
'"
'
);
}
diff --git a/routes/employee.js b/routes/employee.js
index 830e95e..156b5dd 100644
--- a/routes/employee.js
+++ b/routes/employee.js
@@ -40,15 +40,13 @@ let Work=require('../models/works');
let WorkReport = require('../models/workReportModel');
var generator = require('generate-password');
const apiVehicle=require('../js/vehicleApi');
+const {printPage}=require('../print/printAccessDetailsEmp');
+const {getAccessDetails,sumOfMonth,getMunkaszunet, getHolidayListById, getSickpayListById, oneDayCalculate}=require('../js/workTime');
//const employee = require('../models/employee');
//const { data } = require('pdfkit/js/reference');
//const passport = require('passport');
const {exportWorktime}=require('../public/js/export_db');
-const munkaszunet=['2021.01.01','2021.03.15','2021.04.02','2021.04.05','2021.05.24','2021.08.20','2021.11.01','2021.12.24','2021.12.26',
- '2022.01.01','2022.03.14','2022.03.15','2022.04.15','2022.04.18','2022.06.06',
- '2023.01.01','2023.03.15','2023.04.07','2023.04.09','2023.04.10','2023.05.29','2023.10.23','2023.11.01','2023.12.25','2023.12.26',
- '2024.01.01','2024.03.15','2024.03.29','2024.04.01','2024.05.01','2024.05.20','2024.08.20','2024.10.23','2024.11.01','2024.12.24','2024.12.25','2024.12.26','2024.12.27',
- '2025.01.01','2025.04.18','2025.04.21','2025.05.01','2025.05.02','2025.06.09','2025.08.20','2025.10.23','2025.10.24','2024.12.25','2025.12.26'];
+
const emailFelado= 'no-reply.klportal@iotechnic.eu';//'klportal@outlook.com';
// Email Értesítő
@@ -3007,8 +3005,8 @@ function getWorkTimeList_old2(employeeId,mindate,callback)
});
}
-// Munkaidő lekérdezés
-function getWorkTimeList(employeeId,mindate,callback)
+// Munkaidő lekérdezés Eredeti
+/*function getWorkTimeList(employeeId,mindate,callback)
{
// Ehavi esedékes
@@ -3072,6 +3070,55 @@ function getWorkTimeList(employeeId,mindate,callback)
callback(null,month,weekend);
}
});
+}*/
+
+
+
+// Munkaidő lekérdezés Új
+function getWorkTimeList(employeeId,mindate,callback)
+{
+
+ // Ehavi esedékes
+ sumOfMonth(employeeId,mindate,function(err,som){
+ if (err)
+ {
+ console.log(err);
+ }
+ else {
+ var weekend={days:0,overTime:0,workHours:0,fullHours:0};
+ var month={days:0,overTime:0,workHours:0,fullHours:0};
+ //var monthOverTime=0;
+ //var monthWorkHours=0;
+ som.forEach(function(element)
+ {
+ // Napi idő kiszámítása
+ var dayWorkHours=oneDayCalculate(element.fullHours);
+ element.hours=dayWorkHours.workHours;
+ element.overTime=dayWorkHours.overHours;
+
+ if (element.isWeekend)
+ {
+ weekend.days+=1;
+ weekend.workHours+=element.hours;
+ weekend.overTime+=element.overTime;
+ weekend.fullHours+=element.fullHours;
+ }
+ else
+ {
+ month.days+=1;
+ month.workHours+=element.hours;
+ month.overTime+=element.overTime;
+ month.fullHours+=element.fullHours;
+ // Ha hétköznap
+
+ }
+ })
+ //console.log('All done!');
+ //res.send({wd:som,monthWorkHours:monthWorkHours,monthOverTime:monthOverTime});
+ //callback(null,monthWorkHours,monthOverTime,weekends);
+ callback(null,month,weekend);
+ }
+ });
}
// Sorbarendezés
@@ -3172,10 +3219,11 @@ router.get('/worktimelist/:mindate', utils.ensureAuthenticated, function(req, re
// FRISSÍTETT BLOKKOK
// Egy havi munkaidő összegzés
-function sumOfMonth(employee_id,mindate,callback)
+/*async function sumOfMonth(employee_id,mindate,callback)
{
-
- getWorkReportById(employee_id,mindate).then(workReport=>{ // WorkReport Lekérése.
+ var msz=getMunkaszunet(mindate);
+
+ workReport=await getWorkReportById(employee_id,mindate)//.then(workReport=>{ // WorkReport Lekérése.
getWorkTimeListById(employee_id,mindate,function(err,wt){
if (err)
{
@@ -3186,7 +3234,7 @@ function sumOfMonth(employee_id,mindate,callback)
var workDays=[];
wt.forEach(function(element)
{
- var hoursToday=0;
+ var isMunkaszunet=false;//hoursToday=0;
var drName='';
var dwr=''
var day = moment(element.date,'YYYY.MM.DD.').day();
@@ -3196,6 +3244,9 @@ function sumOfMonth(employee_id,mindate,callback)
var lonS=element.longitudeS;
var latE=element.latitudeE;
var lonE=element.longitudeE;
+ var workOnMunkaszunet=false;
+
+
//var cNotes="";
//var notes="";
@@ -3256,9 +3307,19 @@ function sumOfMonth(employee_id,mindate,callback)
drName=dr;
}
// Még nincs ilyen nap, hozzáadjuk
+ const idxmsz=msz.indexOf(element.date);
+ if (idxmsz!==-1)
+ {
+ isMunkaszunet=true;
+ element.company_notes="Ünnep"
+ workOnMunkaszunet=true;
+ element.isMunkaszunet=true
+ msz.splice(idxmsz, 1);
+ }
workDays.push({
date:element.date,
- isMunkaszunet:false,
+ isMunkaszunet:isMunkaszunet,
+ workOnMunkaszunet:element.workOnMunkaszunet,
isHoliday:false,
isSickpay:false,
isWeekend:isWeekend,
@@ -3289,12 +3350,15 @@ function sumOfMonth(employee_id,mindate,callback)
}
+ })
+ msz.forEach(function(munkaszunet){
+ workDays.push({date:munkaszunet,isMunkaszunet:true,hours:480,overTime:0,Surrogate:0,startStop:[],locations:[],notes:[{userNote:'', companyNote: 'Ünnep'}]})
})
callback(null,workDays);
}
- })})
+ })//})
-}
+}*/
// Munkaidő kiolvasás ID alapján
router.get('/getWorkingTimeById/:id',utils.ensureAuthenticated,function(req, res){
@@ -3455,258 +3519,14 @@ Employee.findOne({workingtimeId: id},function(err,element){
})
});
-// workReport By User lekérdezés
-async function getWorkReportById(employeeId,mindate){
- var dr_firstDay= moment(mindate,"YYYY.MM").startOf('month').toDate();
- var dr_lastDay = moment(mindate,"YYYY.MM").endOf('month').toDate();
-
- const result= await WorkReport.aggregate([
- {$match: {"date":{$gte: dr_firstDay, $lte: dr_lastDay}}},
- //{$match: {"workId": mongo.ObjectId("6715f6ca6908a157c7d1f468")}},
- {
-
- $unwind: "$workFlow"
-
- },
- { "$unwind": "$workFlow.employeeList" },
- {$match: {"workFlow.employeeList.employeeId": mongo.ObjectId(employeeId)}},
-
- {$group: { _id:{
- 'wf': '$employeeList.workFlow',
- 'wid': '$_id',
- 'name': '$workFlow.employeeList.name',
- },
- 'id':{$first: '$_id'},
- 'date':{$first:'$date'},
- 'name': {$first:'$workFlow.employeeList.name'},
- 'wf':{$first: '$workFlow.Title'},
- 'wt':{$first: '$workTitle'}
- //'nm':{$push: {name:'$employee.name', wf:'$employeeList.workFlow'}}
- },
- },
- {
- // cleanup
- $project: {
- _id: false,
- }
- }
-
-
- ])
- if (result.length){
- return result
- }
- else
- {
- return []
- }
-
-
-
-}
-// Munkaidő lekérdezés
-function getWorkTimeListById(employeeId,mindate,callback)
-{
- var date = new Date();
- var query={};
-// Ehavi esedékes
-
- var firstDay= moment(mindate,"YYYY.MM").startOf('month').format("YYYY.MM.DD.");
- var lastDay = moment(mindate,"YYYY.MM").endOf('month').format("YYYY.MM.DD.");
- var dr_firstDay= moment(mindate,"YYYY.MM").startOf('month').format("YYYY.MM.DD");
- var dr_lastDay = moment(mindate,"YYYY.MM").endOf('month').format("YYYY.MM.DD");
- //query={$and:[{'state':'ENDED','date': {$gte : firstDay,$lte: lastDay},'employeeId': employeeId}]};
- query={$and:[{'date': {$gte : firstDay,$lte: lastDay},'employeeId': employeeId}]};
-
- WorkingTime.find(query,null,function(err, wt){
- if (err)
- {
- callback(err);
- }
- else {
- Work.aggregate([
- {$unwind: '$dailyReport'},
- {
- "$match":{
- "dailyReport.employeeList": mongo.ObjectId(employeeId)
- },
-
- },
-
- {"$match": {"dailyReport.date": {$gte: dr_firstDay, $lte: dr_lastDay} }},
- {$group: { _id: '$dailyReport._id','name': {$first: '$title'},'wid': {$first: '$_id'},'date': {$first: '$dailyReport.date'}}},
- ], function(err,dr){
- if (err)
- {
- callback(err);
- }else
- {
- wt.rd=dr;
- // wt.wr=workReport // WorkReport Lekérése.;
- callback(null,wt);
- }
- })
-
- }
- });
-}
/*
*/
-function getDateRangeSickPay(startDate, endDate,mindate, dateFormat) {
- var dates = [],
- //selectedMonth=moment(mindate,'YYYY.DD').month();
- start=moment(startDate,'DD.MM.YYYY')
- end = moment(endDate,'DD.MM.YYYY');
-
- diff = end.diff(start, 'days')+1;
- if(!start.isValid() || !end.isValid() || diff <= 0) {
- return;
- }
- for(var i = 0; i < diff; i++) {
- //dates.push(start.format(dateFormat));
- // wt.date;wt.workhours;wt.timeArrive;wt.timeGetaway;wt.locations
- // wdays.locations.push({arriveLoc:element.location,getawayLoc:element.locationStop});
- /* date:'2020.09.24.'
- fullHours:527
- hours:527
- isWeekend:false
- location:'Szentpeterszeg'
- locations:(1) [{…}]
- notes:'-'
- overTime:0
- startStop:(1) [{…}]
- __proto__:Object
- 0:{arriveLoc: 'Szentpeterszeg', getawayLoc: 'Szentpeterszeg'}
- length:1
- __proto__:Array(0)
- 0:{start: '2020.09.24. 7:18', stop: '2020.09.24. 16:05'}
- length:1*/
- if (moment(start).format('YYYY.MM')===mindate)
- {
- //workDays.push({date:element.date,isWeekend:isWeekend,location:element.location,notes:element.notes,locations:[{arriveLoc:element.location,getawayLoc:element.locationStop}],startStop:[{start:element.timeArrive,stop:element.timeGetaway}],fullHours:element.workHours,hours:0,overTime:0});
- dates.push({date:start.format(dateFormat),isSickpay:true})
- }
- start.add(1,'d');
- }
-
- return dates;
-};
-
-function getDateRange(startDate, endDate,mindate, dateFormat) {
- var dates = [],
- //selectedMonth=moment(mindate,'YYYY.DD').month();
- start=moment(startDate,'DD.MM.YYYY')
- end = moment(endDate,'DD.MM.YYYY');
-
- diff = end.diff(start, 'days')+1;
-
-
- if(!start.isValid() || !end.isValid() || diff <= 0) {
- return;
- }
-
- for(var i = 0; i < diff; i++) {
- //dates.push(start.format(dateFormat));
- // wt.date;wt.workhours;wt.timeArrive;wt.timeGetaway;wt.locations
- // wdays.locations.push({arriveLoc:element.location,getawayLoc:element.locationStop});
- /* date:'2020.09.24.'
- fullHours:527
- hours:527
- isWeekend:false
- location:'Szentpeterszeg'
- locations:(1) [{…}]
- notes:'-'
- overTime:0
- startStop:(1) [{…}]
- __proto__:Object
- 0:{arriveLoc: 'Szentpeterszeg', getawayLoc: 'Szentpeterszeg'}
- length:1
- __proto__:Array(0)
- 0:{start: '2020.09.24. 7:18', stop: '2020.09.24. 16:05'}
- length:1*/
- if (moment(start).format('YYYY.MM')===mindate)
- {
- //workDays.push({date:element.date,isWeekend:isWeekend,location:element.location,notes:element.notes,locations:[{arriveLoc:element.location,getawayLoc:element.locationStop}],startStop:[{start:element.timeArrive,stop:element.timeGetaway}],fullHours:element.workHours,hours:0,overTime:0});
- dates.push({date:start.format(dateFormat),isHoliday:true})
- }
- start.add(1,'d');
- }
-
- return dates;
-};
-
-// Szabadság szűrés egy munkavállalóra dátum vég alapján.
-function getHolidayListById(employeeId,dateEndsWith,mindate,callback)
-{
-
- Employee.aggregate([
- { $match: {_id: mongo.ObjectId(employeeId)}},
- { $unwind: '$holidayData'},
- { $match: {$or:[{'holidayData.start_date': {$regex: dateEndsWith, $options:'/g/'}},{'holidayData.end_date': {$regex: dateEndsWith, $options:'/g/'}}]}},
- //{ $group: {_id: '$_id', list: {$push: {'start_date':'$holidayData.start_date', 'end_date':'$holidayData.end_date'}}}}
- { $group: {_id: '$_id', list: {$push: '$holidayData'}}}
- ], function(err,results){
- if (err)
- {
- console.log(err);
- callback(err);
- }
- else {
- var days=[];
- if (results.length>0)
- {
- console.log(results);
- results[0].list.forEach(element=>{
- var subDay=getDateRange(element.start_date,element.end_date,mindate,'YYYY.MM.DD');
- days.push.apply(days,subDay);
-
- })
- }
- //console.log(days);
- callback(null,days);
- }
-
- })
-}
-
-// Táppénz szűrés egy munkavállalóra dátum vég alapján.
-function getSickpayListById(employeeId,dateEndsWith,mindate,callback)
-{
-
- Employee.aggregate([
- { $match: {_id: mongo.ObjectId(employeeId)}},
- { $unwind: '$sickpayData'},
- { $match: {$or:[{'sickpayData.start_date': {$regex: dateEndsWith, $options:'/g/'}},{'sickpayData.end_date': {$regex: dateEndsWith, $options:'/g/'}}]}},
- { $group: {_id: '$_id', list: {$push: '$sickpayData'}}}
- ], function(err,results){
- if (err)
- {
- console.log(err);
- callback(err);
- }
- else {
- var days=[];
- if (results.length>0)
- {
- console.log(results);
- results[0].list.forEach(element=>{
- var subDay=getDateRangeSickPay(element.start_date,element.end_date,mindate,'YYYY.MM.DD');
- days.push.apply(days,subDay);
-
- })
- }
- //console.log(days);
- callback(null,days);
- }
-
- })
-}
// Utolsó 4 munkaidő listázása
function getLastCardAccess(id,callback)
{
@@ -3996,140 +3816,119 @@ router.get('/details/:id/:mindate', utils.ensureAuthenticated, function(req, res
});
});
-// Munkaszüneti napok
-function getMunkaszunet(cmonth)
-{
- var t=[];
- munkaszunet.forEach(function(a){
- if (moment(a,'YYYY.MM.DD').isSame(moment(cmonth,'YYYY.MM'), 'month')) //true if dates are in the same month
- {
- t.push(moment(a,'YYYY.MM.DD').format('YYYY.MM.DD.'));
- }
-})
- //{date: '2021.01.06', isHoliday: true}
-//console.log(t);
-return t;
-}
+
+
// Havi munkaidők lekérdezése egymunkavállalóra AJAX Route
-router.get('/details2/:id/:mindate', utils.ensureAuthenticated, function(req, res) {
-
- getHolidayListById(req.params.id,moment(req.params.mindate,'YYYY.MM').format('MM.YYYY'),req.params.mindate,function(err,holidaysArray){
- if (err)
- {
- console.log("Holiday Err: "+err);
- }
- else
- {
-
-
+router.get('/details2/:id/:mindate', utils.ensureAuthenticated, async function(req, res) {
+ var holidaysArray=await getHolidayListById(req.params.id,moment(req.params.mindate,'YYYY.MM').format('MM.YYYY'),req.params.mindate)//,function(err,holidaysArray){
+ var sickpaysArray=await getSickpayListById(req.params.id,moment(req.params.mindate,'YYYY.MM').format('MM.YYYY'),req.params.mindate)
sumOfMonth(req.params.id,req.params.mindate,function(err,som){
if (err)
{
console.log(err);
}
else {
- var month={overTime:0,workHours:0,fullWorkHours:0};
+ var month={overTime:0,workHours:0,fullWorkHours:0,sickPays:0};
var weekend={
- Saturday:{overTime:0,workHours:0,fullWorkHours:0,days:0},
- Sunday:{overTime:0,workHours:0,fullWorkHours:0,days:0}
+ Saturday:{overTime:0,workHours:0,fullWorkHours:0,days:0,Surrogate:0},
+ Sunday:{overTime:0,workHours:0,fullWorkHours:0,days:0,Surrogate:0}
}
- //var monthOverTime=0;
- //var monthWorkHours=0;
som.forEach(function(element)
{
var hoursToday=0;
var day = moment(element.date,'YYYY.MM.DD.').day();
-
- if (element.startStop[element.startStop.length-1].stop!='-')
- {
- if (element.isWeekend)
+
+ /********************************* */
+
+ /********************************** */
+ //if (!element.isMunkaszunet || element.workOnMunkaszunet==true)
+ // {
+ const notLast=element.startStop.length > 0
+ if (element.state=="ENDED")//element.startStop[element.startStop.length-1].stop!='-')
{
- if (element.fullHours>540)
- { // A túlórát nem számoljuk a munkaidő közé
- element.hours=540;
- if (element.fullHours>=600)
+ // Napi idő kiszámítása
+ var dayWorkHours=oneDayCalculate(element.fullHours);
+
+ element.lunchtime=dayWorkHours.lunchtime;
+ if (element.isWeekend)
+ {
+
+ if (day===6) // Szombat
{
- element.overTime=element.fullHours-element.hours;
+ element.hours=(dayWorkHours.workHours);
+ element.overTime=(dayWorkHours.overHours);
+ element.Surrogate=Math.ceil((element.hours+element.overTime)*0.5);
+ weekend.Saturday.workHours+=(element.hours*1.5);
+ weekend.Saturday.overTime+=(element.overTime*1.5);
+ weekend.Saturday.fullWorkHours+=((element.hours+element.overTime)*1.5);
+ weekend.Saturday.days+=1;
+ weekend.Saturday.Surrogate+=element.Surrogate;
+
}
- else
+ if (day===0) // Vasárnap
{
- element.overTime=0;
+ element.hours=dayWorkHours.workHours;
+ element.overTime=dayWorkHours.overHours;
+ element.Surrogate=(element.hours+element.overTime)
+ weekend.Sunday.workHours+=element.hours;
+ weekend.Sunday.overTime+=element.overTime;
+ weekend.Sunday.fullWorkHours+=(element.hours+element.overTime);
+ weekend.Sunday.days+=1;
+ weekend.Sunday.Surrogate+=element.Surrogate;
}
+
}
else
{
- element.hours=element.fullHours;
- element.overTime=0;
- }
- if (day===6) // Szombat
- {
- weekend.Saturday.workHours+=element.hours;
- weekend.Saturday.overTime+=element.overTime;
- //weekend.Saturday.fullWorkHours+=element.fullHours;
- weekend.Saturday.fullWorkHours+=(element.hours+element.overTime);
- weekend.Saturday.days+=1;
- }
- if (day===0) // Vasárnap
- {
- weekend.Sunday.workHours+=element.hours;
- weekend.Sunday.overTime+=element.overTime;
- //weekend.Sunday.fullWorkHours+=element.fullHours;
- weekend.Sunday.fullWorkHours+=(element.hours+element.overTime);
- weekend.Sunday.days+=1;
- }
-
- }
+ // Ha hétköznap
+ element.hours=dayWorkHours.workHours;//element.hours=540;
+ element.overTime=dayWorkHours.overHours;//element.fullHours-element.hours
+ element.Surrogate=0;
+ month.workHours+=element.hours;
+ month.overTime+=element.overTime;
+ month.fullWorkHours+=(element.hours+element.overTime);
+
+ } // is Weekend
+ }
else
{
- if (element.fullHours>540)
- { // A túlórát nem számoljuk a munkaidő közé
- element.hours=540;
- //element.overTime=element.fullHours-element.hours;
- if (element.fullHours>=600)
- {
- element.overTime=element.fullHours-element.hours;
- }
- else
- {
- element.overTime=0;
- }
- }
- else
- {
- element.hours=element.fullHours;
- element.overTime=0;
- }
- month.workHours+=element.hours;
- month.overTime+=element.overTime;
- //month.fullWorkHours+=element.fullHours;
- month.fullWorkHours+=(element.hours+element.overTime);
- //monthWorkHours+= element.hours;
- //monthOverTime+=element.overTime;
- // Ha hétköznap
-
+ element.lunchtime=60;
+ element.Surrogate=0;
+ }
+ ////}
+ //else
+ //{ //Munkaszüneti nap
- }
- }
+ // }
})
//console.log('All done!');
var ja;
- if (som.length>0) ja = som.concat(holidaysArray);
- else
- ja=holidaysArray;
+ var msz=getMunkaszunet(req.params.mindate);
+
+ if (som.length>0) {
+ ja = som.concat(holidaysArray);
+ ja=ja.concat(sickpaysArray);
+ }
+ else
+ {
+ ja=holidaysArray;
+ }
ja.sort(function(a, b) {
return moment(a.date,'YYYY.MM.DD') - moment(b.date,'YYYY.MM.DD');
});
// Munkaszüneti napok ellenőrzése és kijelzése
- var msz=getMunkaszunet(req.params.mindate);
+
+ month.sickPays=sickpaysArray.length
+
res.send({wd:ja,munkaszunet:msz,month:month,weekend:weekend});
}
});
-}
-}); // End of Holiday list
+
+//}); // End of Holiday list
});
// Nyomtatás
@@ -5130,7 +4929,7 @@ router.post('/access', async function(req,res){
});
// Nyomtatási kép generálás
-function printPage(employee,som,month,weekend,mindate,holidaysArray,sickpaysArray,callback)
+/*function printPage(employee,som,month,weekend,mindate,holidaysArray,sickpaysArray,callback)
{
var dt = new Date();
var item=[];
@@ -5314,11 +5113,7 @@ var dd = {
pageOrientation: 'landscape',
footer: function(currentPage, pageCount) { return {text: currentPage.toString() + ' / ' + pageCount, alignment: 'center'}},
//header: {text: 'Jelenléti ív '+employee.name, style: 'header'},
- /*function(currentPage, pageCount) {
- // you can apply any logic and return any valid pdfmake element
- return { text: 'Nyomtatva: '+Date(), alignment: (currentPage % 2) ? 'left' : 'right' };
- },*/
content: [
{
alignment: 'justify',
@@ -5461,10 +5256,10 @@ dd.content[1].table.body=item;
// ...
-}
+}*/
// Nyomtatási kép generálás Alvállalkozó
-function printPageContractor(employee,som,month,weekend,mindate,holidaysArray,callback)
+/*function printPageContractor(employee,som,month,weekend,mindate,holidaysArray,callback)
{
var dt = new Date();
var item=[];
@@ -5494,10 +5289,13 @@ function printPageContractor(employee,som,month,weekend,mindate,holidaysArray,ca
var day = moment(element.date,'YYYY.MM.DD.').day();
if (element.dailyReport!='') drShift='\r\n'; else drShift='';
drShift='';
+ if (element.dailyReport)
+ {
element.dailyReport.forEach(drelem=>{
dreportList+= drelem.name.substring(0,60) +'\r\n';
drShift+='\r\n';
- })
+ })
+ }
if (element.isHoliday)
{
item.push([
@@ -5601,8 +5399,7 @@ var bodySum=[];
[{text: 'Összesen:'},{text: convertMinsToHrsMins(weekend.Saturday.workHours+weekend.Sunday.workHours+month.workHours), alignment: 'right'},
{text: convertMinsToHrsMins(weekend.Saturday.overTime+weekend.Sunday.overTime+month.overTime), alignment: 'right'},
{text: convertMinsToHrsMins(month.fullWorkHours+weekend.Saturday.fullWorkHours+weekend.Sunday.fullWorkHours), alignment: 'right'}]//,
- /* {text:''},
- {text: convertMinsToHrsMins(month.fullWorkHours+(weekend.Saturday.fullWorkHours*1.5)+(weekend.Sunday.fullWorkHours*2)), alignment: 'right'}]*/
+
];
@@ -5611,11 +5408,7 @@ var dd = {
pageOrientation: 'landscape',
footer: function(currentPage, pageCount) { return {text: currentPage.toString() + ' / ' + pageCount, alignment: 'center'}},
//header: {text: 'Jelenléti ív '+employee.name, style: 'header'},
- /*function(currentPage, pageCount) {
- // you can apply any logic and return any valid pdfmake element
-
- return { text: 'Nyomtatva: '+Date(), alignment: (currentPage % 2) ? 'left' : 'right' };
- },*/
+
content: [
{
alignment: 'justify',
@@ -5747,10 +5540,10 @@ dd.content[1].table.body=item;
// ...
-}
+}*/
//'/employee/details2/'
// Havi munkaidők lekérdezése egymunkavállalóra AJAX Route
-function gatAccessDetails(id,mindate, callback) {
+/*function gatAccessDetails(id,mindate, callback) {
sumOfMonth(id,mindate,function(err,som){
if (err)
@@ -5809,10 +5602,7 @@ function gatAccessDetails(id,mindate, callback) {
weekend.Sunday.fullWorkHours+=(element.hours+element.overTime);//element.fullHours;
weekend.Sunday.days+=1;
}
- /*weekend.workHours+=element.hours;
- weekend.overTime+=element.overTime;
- weekend.fullWorkHours+=element.fullHours;
- weekend.days+=1; */
+
}
else
{
@@ -5848,7 +5638,7 @@ function gatAccessDetails(id,mindate, callback) {
callback(null,som,month,weekend);
}
});
-};
+};*/
function validateEmail(email) {
const re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
@@ -5881,38 +5671,29 @@ router.get('/WTALL',utils.ensureAuthenticated,function(req,res){
setTimeout(function () { resolve(); }, millis);
});
}
+
+/*
async function makeWorktimeAll(calcdate)
{
var num=0;
+ // let promises=[];
//'_id':'5cc0394bec573424a8f79059'
- Employee.find({'konyvelesre':'on'}, function(err,res){
+ var res=await Employee.find({'konyvelesre':'on'})//, function(err,res){
var fileList=[];
- if (err)
- {
- console.log('ERR');
-
- }
- else
- {
console.log("Kőnyvelésre jelölt: "+res.length);
- var bar=new Promise((resolve,reject)=>{
- res.forEach((element,index,array) =>{
- sleep(3000);
- getSickpayListById(element._id,moment(calcdate,'YYYY.MM').format('MM.YYYY'),calcdate,function(err,sickpaysArray){
- if (err)
- {
- console.log("Sickpay Err: "+err);
- }
- else
- {
- getHolidayListById(element._id,moment(calcdate,'YYYY.MM').format('MM.YYYY'),calcdate,function(err,holidaysArray){
- if (err)
- {
- console.log("Holiday Err: "+err);
- }
- else
- {
- gatAccessDetails(element._id,calcdate,function(err,som,month,weekend)
+ var msz=getMunkaszunet(calcdate);
+ //var bar=new Promise((resolve,reject)=>{
+
+ //for (var [index,element] of res.entries()){
+
+ //res.forEach((element,index,array) =>async function(){
+ var promises=res.map(async function(element){
+ //sleep(3000);
+ return async function(element){
+ const sickpaysArray=await getSickpayListById(element._id,moment(calcdate,'YYYY.MM').format('MM.YYYY'),calcdate)//,function(err,sickpaysArray){
+ const holidaysArray= await getHolidayListById(element._id,moment(calcdate,'YYYY.MM').format('MM.YYYY'),calcdate)//,function(err,holidaysArray){
+
+ getAccessDetails(element._id,calcdate,function(err,som,month,weekend)
{
if(err)
{
@@ -5924,7 +5705,7 @@ async function makeWorktimeAll(calcdate)
{
if (element.isSubcontractor===null) // Alkalmazott
{
- printPage(element,som,month,weekend,calcdate,holidaysArray,sickpaysArray, function(err,data){
+ var data= printPage(element,som,month,weekend,calcdate,holidaysArray,sickpaysArray,msz)//, function(err,data){
var fonts = {
Roboto: {
normal: 'public/fonts/Roboto-Regular.ttf',
@@ -5956,7 +5737,7 @@ async function makeWorktimeAll(calcdate)
pdfDoc.end();
num++;
- });
+ // });
}
if (element.isSubcontractor==='on') // Alvállalkozó
@@ -6001,12 +5782,169 @@ async function makeWorktimeAll(calcdate)
{
console.log("Nincs mit küldeni! ---> "+element.name);
}
- if (index === array.length -1) {sleep(2000);resolve(); }
+ if (index === array.length -1) {
+ sleep(2000);
+ resolve();
+
+ console.log('Num employees: '+num);
+
+ }
+ //return fileList
}
});
}
+ // });
+
+ // });
+
+ //if (index === array.length -1) resolve();
+ }); // Foreach
+ // }); // Promise
+ Promise.all(promises).then(function(){
+ console.log("Kész "+fileList)
+ })
+ bar.then(()=>{
+ sleep(10000).then(()=>{
+
+ console.log('Num employees: '+num);
+ sendEmailMonthlyWorktime_all(fileList,function(err,res)
+ {
+ if (err)
+ {
+ console.log(err);
+ }
+ else
+ {
+
+ }
+ })
+ });
+
+ });
+ //} // else
+ // })
+
+}
+*/
+
+async function makeWorktimeAll(calcdate)
+{
+ var num=0;
+ //'_id':'5cc0394bec573424a8f79059'
+ Employee.find({'konyvelesre':'on'}, function(err,res){
+ var fileList=[];
+ var msz=getMunkaszunet(calcdate);
+ if (err)
+ {
+ console.log('ERR');
+
+ }
+ else
+ {
+ console.log("Kőnyvelésre jelölt: "+res.length);
+ var bar=new Promise((resolve,reject)=>{
+ res.forEach((element,index,array) =>{
+ sleep(3000);
+ getSickpayListById(element._id,moment(calcdate,'YYYY.MM').format('MM.YYYY'),calcdate).then(function(sickpaysArray){
+
+ getHolidayListById(element._id,moment(calcdate,'YYYY.MM').format('MM.YYYY'),calcdate).then(function(holidaysArray){
+
+ getAccessDetails(element._id,calcdate,function(err,som,month,weekend)
+ {
+ if(err)
+ {
+ console.log(err);
+ }
+ else
+ {
+ if ((som.length>0) && (element.konyvelesre==='on'))
+ {
+ if (element.isSubcontractor===null) // Alkalmazott
+ {
+ var data= printPage(element,som,month,weekend,calcdate,holidaysArray,sickpaysArray,msz)//.then(function(data){
+ var fonts = {
+ Roboto: {
+ normal: 'public/fonts/Roboto-Regular.ttf',
+ bold: 'public/fonts/Roboto-Medium.ttf',
+ italics: 'public/fonts/Roboto-Italic.ttf',
+ bolditalics: 'public/fonts/Roboto-MediumItalic.ttf'
+ }
+ };
+
+ var printer = new PdfPrinter(fonts);
+ var pdfDoc = printer.createPdfKitDocument(data, options);
+ var cdir=calcdate.replace('.','_');
+ if (!fs.existsSync('./'+cdir))
+ {
+ fs.mkdir('./'+cdir,(err)=>{
+ console.log(err);
+ });
+ }
+
+ fileList.push(
+ {
+ filename: element.name+'_'+cdir+'_jelenleti.pdf', // <= Here: made sure file name match
+ path: path.join('./'+cdir+'/'+element.name+'_'+cdir+'_jelenleti.pdf'), // <= Here
+ contentType: 'application/pdf'
+ }
+ );
+ pdfDoc.pipe(fs.createWriteStream('./'+cdir+'/'+element.name+'_'+cdir+'_jelenleti.pdf'));
+ pdfDoc.flushPages();
+ pdfDoc.end();
+ num++;
+
+ // });
+ }
+
+ if (element.isSubcontractor==='on') // Alvállalkozó
+ {
+ //printPageContractor(element,som,month,weekend,calcdate,holidaysArray, function(err,data){
+ var data= printPage(element,som,month,weekend,calcdate,holidaysArray,sickpaysArray,msz)
+ var fonts = {
+ Roboto: {
+ normal: 'public/fonts/Roboto-Regular.ttf',
+ bold: 'public/fonts/Roboto-Medium.ttf',
+ italics: 'public/fonts/Roboto-Italic.ttf',
+ bolditalics: 'public/fonts/Roboto-MediumItalic.ttf'
+ }
+ };
+
+ var printer = new PdfPrinter(fonts);
+ var pdfDoc = printer.createPdfKitDocument(data, options);
+ var cdir=calcdate.replace('.','_');
+ if (!fs.existsSync('./'+cdir))
+ {
+ fs.mkdir('./'+cdir,(err)=>{
+ console.log(err);
+ });
+ }
+
+ fileList.push(
+ {
+ filename: element.name+'_'+cdir+'_jelenleti.pdf', // <= Here: made sure file name match
+ path: path.join('./'+cdir+'/'+element.name+'_'+cdir+'_jelenleti.pdf'), // <= Here
+ contentType: 'application/pdf'
+ }
+ );
+ pdfDoc.pipe(fs.createWriteStream('./'+cdir+'/'+element.name+'_'+cdir+'_jelenleti.pdf'));
+ pdfDoc.flushPages();
+ pdfDoc.end();
+ num++;
+
+ //});
+ }
+
+ }
+ else
+ {
+ console.log("Nincs mit küldeni! ---> "+element.name);
+ }
+ if (index === array.length -1) {sleep(2000);resolve(); }
+ }
+ });
+ // }
});
- }
+ // }
});
//if (index === array.length -1) resolve();
}); // Foreach
@@ -6033,8 +5971,7 @@ async function makeWorktimeAll(calcdate)
} // else
})
-}
-
+}
function proba(calcdate)
{
@@ -6122,7 +6059,7 @@ function proba(calcdate)
function sendMonthlyNotify(employee, monthNumber,callback)
{
- gatAccessDetails(employee._id,monthNumber,function(err,som,month,weekend){
+ getAccessDetails(employee._id,monthNumber,function(err,som,month,weekend){
if(err)
{
console.log(err);
@@ -6219,22 +6156,11 @@ function sendMonthlyNotify(employee, monthNumber,callback)
}
// Nyomtatás
-router.get('/print/:uid/:mindate', function(req,res){
- getSickpayListById(req.params.uid,moment(req.params.mindate,'YYYY.MM').format('MM.YYYY'),req.params.mindate,function(err,sickpaysArray){
- if (err)
- {
- console.log("Sickpay Err: "+err);
- }
- else
- {
- getHolidayListById(req.params.uid,moment(req.params.mindate,'YYYY.MM').format('MM.YYYY'),req.params.mindate,function(err,holidaysArray){
- if (err)
- {
- console.log("Holiday Err: "+err);
- }
- else
- {
- gatAccessDetails(req.params.uid,req.params.mindate,function(err,som,month,weekend){
+router.get('/print/:uid/:mindate', async function(req,res){
+ var sickpaysArray=await getSickpayListById(req.params.uid,moment(req.params.mindate,'YYYY.MM').format('MM.YYYY'),req.params.mindate)//,function(err,sickpaysArray){
+ var holidaysArray=await getHolidayListById(req.params.uid,moment(req.params.mindate,'YYYY.MM').format('MM.YYYY'),req.params.mindate)//,function(err,holidaysArray){
+ var msz=getMunkaszunet(req.params.mindate);
+ getAccessDetails(req.params.uid,req.params.mindate,function(err,som,month,weekend){
//getInvoices(req.params.url ,"", function(err,invoices,title) {
//console.log(invoices);
if(err)
@@ -6253,28 +6179,25 @@ router.get('/print/:uid/:mindate', function(req,res){
{
if (employee.isSubcontractor===null) // Alkalmazott
{
- printPage(employee,som,month,weekend,req.params.mindate,holidaysArray,sickpaysArray, function(err,data){
+ const data= printPage(employee,som,month,weekend,req.params.mindate,holidaysArray,sickpaysArray,msz)// function(err,data){
// Client side pdf
res.send(data);
- });
+
}
if (employee.isSubcontractor==='on') // Alvállalkozó
{
- printPageContractor(employee,som,month,weekend,req.params.mindate,holidaysArray, function(err,data){
+ //printPageContractor(employee,som,month,weekend,req.params.mindate,holidaysArray, function(err,data){
+ const data= printPage(employee,som,month,weekend,req.params.mindate,holidaysArray,sickpaysArray,msz)
// Client side pdf
res.send(data);
- });
+ //});
}
}
})
}
});
- }//else
- });
- }
- });
});
module.exports = router;
\ No newline at end of file
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..334d36e
--- /dev/null
+++ b/test.js
@@ -0,0 +1,112 @@
+const moment=require("moment")
+
+const start="2025.02.07. 6:59"
+const stop="2025.02.07. 17:12"
+const lunchtime=1*60
+const expectedWorkHours=8*60
+const overHourThreshold=1*60
+
+function convertMinsToHrsMins(minutes) {
+ var h = Math.floor(minutes / 60);
+ var m = minutes % 60;
+ h = h < 10 ? '0' + h : h;
+ m = m < 10 ? '0' + m : m;
+ return h + ':' + m;
+}
+
+
+/*function convertMinsToHrsMins(minutes) {
+ const hours = Math.floor(minutes / 60);
+ const remainingMinutes = minutes % 60;
+ console.log("remainingminutes: "+remainingMinutes)
+ return `${String(hours).padStart(2, '0')}:${String(remainingMinutes).padStart(2, '0')}`;
+}*/
+
+var fullTime=moment(stop,"YYYY.MM.DD. HH.mm").diff(moment(start,"YYYY.MM.DD. HH.mm"),"minutes")
+const fl=fullTime-lunchtime; // Teljes idő - ebéd idő
+
+const oh=fl-expectedWorkHours;
+const wh=fl-(fl-expectedWorkHours);
+var overHours=0;
+if (oh>overHourThreshold) overHours=oh; else overHours=0;
+var workHours=fl>=expectedWorkHours?wh:fl
+console.log(`Full Time: ${convertMinsToHrsMins(fullTime)}
+ Lunch: ${convertMinsToHrsMins(lunchtime)}
+ WorkHour: ${convertMinsToHrsMins(workHours)}
+ OverHour: ${convertMinsToHrsMins(overHours)}`)
+
+
+/*
+
+ if (element.startStop[element.startStop.length-1].stop!='-')
+ {
+ if (element.isWeekend)
+ {
+ if (element.fullHours>540)
+ { // A túlórát nem számoljuk a munkaidő közé
+ element.hours=540;
+ if (element.fullHours>=600)
+ {
+ element.overTime=element.fullHours-element.hours;
+ }
+ else
+ {
+ element.overTime=0;
+ }
+ }
+ else
+ {
+ element.hours=element.fullHours;
+ element.overTime=0;
+ }
+ if (day===6) // Szombat
+ {
+ weekend.Saturday.workHours+=element.hours;
+ weekend.Saturday.overTime+=element.overTime;
+ //weekend.Saturday.fullWorkHours+=element.fullHours;
+ weekend.Saturday.fullWorkHours+=(element.hours+element.overTime);
+ weekend.Saturday.days+=1;
+ }
+ if (day===0) // Vasárnap
+ {
+ weekend.Sunday.workHours+=element.hours;
+ weekend.Sunday.overTime+=element.overTime;
+ //weekend.Sunday.fullWorkHours+=element.fullHours;
+ weekend.Sunday.fullWorkHours+=(element.hours+element.overTime);
+ weekend.Sunday.days+=1;
+ }
+
+ }
+ else
+ {
+ if (element.fullHours>540)
+ { // A túlórát nem számoljuk a munkaidő közé
+ element.hours=540;
+ //element.overTime=element.fullHours-element.hours;
+ if (element.fullHours>=600)
+ {
+ element.overTime=element.fullHours-element.hours;
+ }
+ else
+ {
+ element.overTime=0;
+ }
+ }
+ else
+ {
+ element.hours=element.fullHours;
+ element.overTime=0;
+ }
+ month.workHours+=element.hours;
+ month.overTime+=element.overTime;
+ //month.fullWorkHours+=element.fullHours;
+ month.fullWorkHours+=(element.hours+element.overTime);
+ //monthWorkHours+= element.hours;
+ //monthOverTime+=element.overTime;
+ // Ha hétköznap
+
+
+ }
+ }
+
+*/
\ No newline at end of file
diff --git a/views/employee_access_details.pug b/views/employee_access_details.pug
index 23ac657..f09688c 100644
--- a/views/employee_access_details.pug
+++ b/views/employee_access_details.pug
@@ -142,17 +142,17 @@ block content
table#monthSumTable.container(style='width:90%;')
col(width='auto')
col(width='10%')
- col(width='10%')
- col(width='10%')
- col(width='10%')
- col(width='10%')
+ //-col(width='10%')
+ col(width='10%')
+ col(width='10%')
+ col(width='10%')
thead
tr
th
h1(style='text-align:left;font-size: 16px;') Megnevezés
th
- h1(style='text-align:center;font-size: 16px;') Normál
- th
+ h1(style='text-align:center;font-size: 16px;') Érték
+ //-th
h1(style='text-align:center;font-size: 16px;') Túlóra
th
h1(style='text-align:center;font-size: 16px;') Összesen
@@ -166,15 +166,15 @@ block content
table#monthSumTable.container(style='width:90%;')
col(width='auto')
col(width='10%')
- col(width='10%')
- col(width='10%')
+ //-col(width='10%')
+ col(width='10%')
thead
tr
th
h1(style='text-align:left;font-size: 16px;') Megnevezés
th
- h1(style='text-align:center;font-size: 16px;') Normál
- th
+ h1(style='text-align:center;font-size: 16px;') Érték
+ //-th
h1(style='text-align:center;font-size: 16px;') Túlóra
th
h1(style='text-align:center;font-size: 16px;') Összesen
@@ -201,9 +201,9 @@ block content
#darktable.container
br
table#monthHoursTableDetails.container(style='width:90%;')
- col(width='5%')
- col(width='5%')
- col(width='40%')
+ col(width='4%')
+ col(width='4%')
+ col(width='35%')
col(width='6%')
col(width='6%')
if(userIsAdmin==true)
@@ -211,6 +211,9 @@ block content
col(width='3%')
col(width='6%')
col(width='6%')
+ col(width='6%')
+ col(width='6%')
+ col(width='6%')
col(width='auto')
thead
tr
@@ -232,7 +235,13 @@ block content
th
h1(style='text-align:left') Órák
th
- h1(style='text-align:center') Túlóra
+ h1(style='text-align:left') Ebéd
+ th
+ h1(style='text-align:left') Elszámolt
+ th
+ h1(style='text-align:center') Túlóra
+ th
+ h1(style='text-align:center') Pótlék
th
h1(style='text-align:left') Megjegyzés
tbody