Szabadság törlés FullCalendarral hozzáadva.
This commit is contained in:
parent
dff21701fd
commit
159c6824f5
|
|
@ -2062,6 +2062,7 @@ router.get("/holidays_byperson_calendar/:id/:year", async function(req, res){
|
||||||
employeeName:element.name,
|
employeeName:element.name,
|
||||||
employeeEmail:element.email,
|
employeeEmail:element.email,
|
||||||
order:1,
|
order:1,
|
||||||
|
active: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2083,6 +2084,7 @@ router.get("/holidays_byperson_calendar/:id/:year", async function(req, res){
|
||||||
employeeName:element.name,
|
employeeName:element.name,
|
||||||
employeeEmail:element.email,
|
employeeEmail:element.email,
|
||||||
order:0,
|
order:0,
|
||||||
|
active: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2174,7 +2176,20 @@ router.get('/get_sickpayById/:id', utils.ensureAuthenticated,function(req,res){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Kiadott/meglévő szabadság lekérése Full Calendar
|
||||||
|
router.get('/holidays_count/:uid', async function (req,res){
|
||||||
|
const result= await Employee.findById(req.params.uid);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.send({'response':'ok','vacationYear':result.vacationYear,'vacationUsed': result.vacationUsed, 'vacationLeft':result.vacationYear-result.vacationUsed});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.send({'response':'Fail','message':'Sikertelen művelet!'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Új Szabadság kiadása
|
// Új Szabadság kiadása
|
||||||
router.get('/holidays_byperson/:id', utils.ensureAuthenticated,function(req,res){
|
router.get('/holidays_byperson/:id', utils.ensureAuthenticated,function(req,res){
|
||||||
|
|
@ -2291,7 +2306,51 @@ router.post('/holiday_drop_update', async function(req,res){
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// Szabadság törlése Fullcalendar
|
||||||
|
router.delete('/holiday_destroy/:uid/:hid',utils.ensureAuthenticated, async function(req,res){
|
||||||
|
console.log("Delete UID: "+req.params.uid);
|
||||||
|
console.log("Delete HID: "+req.params.hid);
|
||||||
|
const hd_event=req.body.event;
|
||||||
|
moment.locale('HU');
|
||||||
|
let startd = moment(req.body.event.start, 'YYYY.MM.DD'); //Pick any format
|
||||||
|
let endd = moment(req.body.event.end, 'YYYY.MM.DD');
|
||||||
|
let weekdayCounter = endd.diff(startd, 'days');
|
||||||
|
console.log('DIFF: '+weekdayCounter) // 1
|
||||||
|
|
||||||
|
const result= await Employee.updateOne({_id:req.params.uid},
|
||||||
|
{
|
||||||
|
$pull:{
|
||||||
|
'holidayData':{'_id':req.params.hid},
|
||||||
|
},
|
||||||
|
|
||||||
|
})
|
||||||
|
if (result.ok){
|
||||||
|
const r=await Employee.updateOne({_id:req.params.uid},
|
||||||
|
{
|
||||||
|
$inc: {'vacationUsed': -weekdayCounter },
|
||||||
|
})
|
||||||
|
if (r.ok)
|
||||||
|
{
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.send({'response':'OK','message':'A szabadság sikeresen törölve!\n'+weekdayCounter+' nap jóváírva.'});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.send({'response':'Fail','message':'Sikertelen művelet!'});
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.send({'response':'Fail','message':'Sikertelen művelet!'});
|
||||||
|
}
|
||||||
|
//})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
// Szabadság törlése
|
// Szabadság törlése
|
||||||
|
/*
|
||||||
router.delete('/holidays_delete/:uid/:hid',utils.ensureAuthenticated,function(req,res){
|
router.delete('/holidays_delete/:uid/:hid',utils.ensureAuthenticated,function(req,res){
|
||||||
console.log("Delete UID: "+req.params.uid);
|
console.log("Delete UID: "+req.params.uid);
|
||||||
console.log("Delete HID: "+req.params.hid);
|
console.log("Delete HID: "+req.params.hid);
|
||||||
|
|
@ -2309,7 +2368,7 @@ router.delete('/holidays_delete/:uid/:hid',utils.ensureAuthenticated,function(re
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})*/
|
||||||
// Szabadság kiadás full calendar
|
// Szabadság kiadás full calendar
|
||||||
router.post('/holidays_byperson_fc/:id', utils.ensureAuthenticated,function(req,res){
|
router.post('/holidays_byperson_fc/:id', utils.ensureAuthenticated,function(req,res){
|
||||||
console.log(req.params.id);
|
console.log(req.params.id);
|
||||||
|
|
@ -2321,19 +2380,15 @@ router.post('/holidays_byperson_fc/:id', utils.ensureAuthenticated,function(req,
|
||||||
|
|
||||||
while (startd <= endd) {
|
while (startd <= endd) {
|
||||||
console.log(startd.format('ddd'));
|
console.log(startd.format('ddd'));
|
||||||
// if (startd.format('ddd') !== 'szo' && startd.format('ddd') !== 'vas'){
|
|
||||||
weekdayCounter++; //add 1 to your counter if its not a weekend day
|
weekdayCounter++; //add 1 to your counter if its not a weekend day
|
||||||
//}
|
startd = moment(startd, 'DD.MM.YYYY').add(1, 'days'); //increment by one day
|
||||||
startd = moment(startd, 'DD.MM.YYYY').add(1, 'days'); //increment by one day
|
|
||||||
}
|
}
|
||||||
console.log("Hétköznapok",weekdayCounter); //display your total elapsed weekdays in the console!
|
console.log("Hétköznapok",weekdayCounter); //display your total elapsed weekdays in the console!
|
||||||
|
|
||||||
let hd ={
|
let hd ={
|
||||||
start_date: req.body.sField,
|
start_date: req.body.sField,
|
||||||
end_date: req.body.eField,
|
end_date: req.body.eField,
|
||||||
|
|
||||||
duration: weekdayCounter,
|
duration: weekdayCounter,
|
||||||
|
|
||||||
};
|
};
|
||||||
//hd.id=hd._id;
|
//hd.id=hd._id;
|
||||||
Employee.findByIdAndUpdate(req.params.id,{ $inc: {'vacationUsed': weekdayCounter },$push: {holidayData:hd}},function(error,success){
|
Employee.findByIdAndUpdate(req.params.id,{ $inc: {'vacationUsed': weekdayCounter },$push: {holidayData:hd}},function(error,success){
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,32 @@ block content
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Szabadság kijelzés frissítése módosítás után.
|
||||||
|
const refreshCounters=async function(uid){
|
||||||
|
const response = await fetch("/employee/holidays_count/"+uid,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
method: "GET",
|
||||||
|
|
||||||
|
});
|
||||||
|
console.log("DATA: "+response)
|
||||||
|
if (response.ok){
|
||||||
|
const data = await response.json();
|
||||||
|
console.log("DATA: "+JSON.stringify(data))
|
||||||
|
if (data.response="OK")
|
||||||
|
{
|
||||||
|
|
||||||
|
document.getElementById('vacationLeft').value=data.vacationLeft;
|
||||||
|
document.getElementById('vacationYear').value=data.vacationYear;
|
||||||
|
document.getElementById('vacationUsed').value=data.vacationUsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$("#mworkers").click();
|
$("#mworkers").click();
|
||||||
$("#listworktime").addClass("active");
|
$("#listworktime").addClass("active");
|
||||||
// Calendar
|
// Calendar
|
||||||
|
|
@ -180,69 +206,176 @@ block content
|
||||||
eventStartEditable:true,
|
eventStartEditable:true,
|
||||||
eventDurationEditable:true,
|
eventDurationEditable:true,
|
||||||
select: async function (start, end, allDay) {
|
select: async function (start, end, allDay) {
|
||||||
var vacationLeft = document.getElementById('vacationLeft').value
|
var vacationLeft = document.getElementById('vacationLeft').value
|
||||||
|
|
||||||
var a = moment(start.start);
|
var a = moment(start.start);
|
||||||
var b = moment(start.end);
|
var b = moment(start.end);
|
||||||
b= b.subtract(1,'days')
|
b= b.subtract(1,'days')
|
||||||
var duration = b.diff(a, 'days')+1
|
var duration = b.diff(a, 'days')+1
|
||||||
if (duration>vacationLeft)
|
if (duration>vacationLeft)
|
||||||
|
{
|
||||||
|
Swal.fire({
|
||||||
|
position: "top-end",
|
||||||
|
icon: "warning",
|
||||||
|
title: 'Nincs ennyi szabid!\n'+duration+' nap',
|
||||||
|
showConfirmButton: false,
|
||||||
|
timer: 1500
|
||||||
|
});
|
||||||
|
calendar.unselect();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
|
||||||
|
const result= await Swal.fire(
|
||||||
|
{
|
||||||
|
title: "Biztosan kiadja a szabadságot? "+moment(a).format('YYYY.MM.DD')+" - "+moment(b).format('YYYY.MM.DD'),
|
||||||
|
text: "A szabadság kiadásáról "+empname+" e-mail értesítést fog kapni.",
|
||||||
|
icon: "question",
|
||||||
|
showDenyButton: true,
|
||||||
|
confirmButtonText: 'Igen',
|
||||||
|
denyButtonText: 'Nem',
|
||||||
|
customClass: {
|
||||||
|
actions: 'my-actions',
|
||||||
|
confirmButton: 'order-2',
|
||||||
|
denyButton: 'order-3',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (result.isConfirmed)
|
||||||
|
{
|
||||||
|
//console.log("Event ID: "+eventDropInfo.event.id)
|
||||||
|
//console.log("Event Before Drop\n"+eventDropInfo.oldEvent.start+'-'+eventDropInfo.oldEvent.end)
|
||||||
|
//console.log("Event After Drop\n"+eventDropInfo.event.start+'-'+eventDropInfo.event.end)
|
||||||
|
const response = await fetch("/employee/holidays_byperson_fc/"+empId.textContent,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ sField: moment(a).format('DD.MM.YYYY'),eField: moment(b).format('DD.MM.YYYY')}),
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
if (!response.ok)
|
||||||
|
{
|
||||||
|
Swal.fire('Error', '', 'error')
|
||||||
|
}
|
||||||
|
if (data.response="OK")
|
||||||
|
{
|
||||||
|
//var empId = document.getElementById('uid')
|
||||||
|
const year=moment(start.view.activeStart).format("YYYY")
|
||||||
|
calendar.removeAllEventSources();
|
||||||
|
calendar.addEventSource('/employee/holidays_byperson_calendar/'+empId.textContent+'/'+year)
|
||||||
|
refreshCounters(uid.textContent);
|
||||||
|
Swal.fire({
|
||||||
|
position: "top-end",
|
||||||
|
icon: "success",
|
||||||
|
title: data.message,
|
||||||
|
showConfirmButton: false,
|
||||||
|
timer: 1500
|
||||||
|
});
|
||||||
|
|
||||||
|
//Swal.fire('Saved!', '', 'success')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (result.isDenied)
|
||||||
|
{
|
||||||
|
//Swal.fire('Changes are not saved', '', 'info')
|
||||||
|
Swal.fire({
|
||||||
|
position: "top-end",
|
||||||
|
icon: "info",
|
||||||
|
title: 'Nem történt változtatás',
|
||||||
|
showConfirmButton: false,
|
||||||
|
timer: 1500
|
||||||
|
});
|
||||||
|
calendar.unselect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
views: {
|
||||||
|
multiMonthFourMonth: {
|
||||||
|
type: 'multiMonth',
|
||||||
|
duration: { months: 12 },
|
||||||
|
multiMonthMaxColumns: 2,
|
||||||
|
eventLimit: 10,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
//initialEvents: res,
|
||||||
|
//events: '/employee/holidays_byperson_calendar/'+empId.textContent+'/'+year,
|
||||||
|
weekNumbers: true,
|
||||||
|
themeSystem: 'default',
|
||||||
|
eventClick: async function(info)
|
||||||
{
|
{
|
||||||
Swal.fire({
|
//alert('Event: ' + info.event.title+'\n'+info.event.id+'\n'+info.event.extendedProps.employeeId);
|
||||||
position: "top-end",
|
console.log('Event: ' + info.event.title+'\n'+info.event.id+'\n'+info.event.extendedProps.employeeId)
|
||||||
icon: "warning",
|
if (info.event.extendedProps.active)
|
||||||
title: 'Nincs ennyi szabid!\n'+duration+' nap',
|
{
|
||||||
showConfirmButton: false,
|
var bgColor=info.el.style.backgroundColor;
|
||||||
timer: 1500
|
// change the border color just for fun
|
||||||
});
|
info.el.style.backgroundColor = 'red';
|
||||||
calendar.unselect();
|
const result= await Swal.fire(
|
||||||
}
|
{
|
||||||
else {
|
title: "Biztosan törli a szabadságot?\n"+moment(info.event.start).format('YYYY.MM.DD')+' - '+moment(info.event.stop).format('YYYY.MM.DD'),
|
||||||
|
text: "A törlésről "+info.event.title+" e-mail értesítést fog kapni.",
|
||||||
|
icon: "question",
|
||||||
const result= await Swal.fire(
|
showDenyButton: true,
|
||||||
{
|
confirmButtonText: 'Igen',
|
||||||
title: "Biztosan kiadja a szabadságot? "+moment(a).format('YYYY.MM.DD')+" - "+moment(b).format('YYYY.MM.DD'),
|
denyButtonText: 'Nem',
|
||||||
text: "A szabadság kiadásáról "+empname+" e-mail értesítést fog kapni.",
|
customClass: {
|
||||||
icon: "question",
|
actions: 'my-actions',
|
||||||
showDenyButton: true,
|
confirmButton: 'order-2',
|
||||||
confirmButtonText: 'Igen',
|
denyButton: 'order-3',
|
||||||
denyButtonText: 'Nem',
|
},
|
||||||
customClass: {
|
}
|
||||||
actions: 'my-actions',
|
);
|
||||||
confirmButton: 'order-2',
|
|
||||||
denyButton: 'order-3',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (result.isConfirmed)
|
if (result.isConfirmed)
|
||||||
{
|
{
|
||||||
//console.log("Event ID: "+eventDropInfo.event.id)
|
console.log("Event ID: "+info.event.id)
|
||||||
//console.log("Event Before Drop\n"+eventDropInfo.oldEvent.start+'-'+eventDropInfo.oldEvent.end)
|
|
||||||
//console.log("Event After Drop\n"+eventDropInfo.event.start+'-'+eventDropInfo.event.end)
|
console.log("Event After Drop\n"+info.event.start+'-'+info.event.end)
|
||||||
const response = await fetch("/employee/holidays_byperson_fc/"+empId.textContent,
|
const response = await fetch("/employee/holiday_destroy/"+info.event.extendedProps.employeeId+"/"+info.event.id,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "DELETE",
|
||||||
body: JSON.stringify({ sField: moment(a).format('DD.MM.YYYY'),eField: moment(b).format('DD.MM.YYYY')}),
|
body: JSON.stringify({ event: info.event }),
|
||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (!response.ok)
|
if (!response.ok)
|
||||||
{
|
{
|
||||||
Swal.fire('Error', '', 'error')
|
Swal.fire('Error', '', 'error')
|
||||||
}
|
}
|
||||||
if (data.response="OK")
|
if (data.response=="OK")
|
||||||
{
|
{
|
||||||
|
info.el.style.backgroundColor=bgColor;
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
position: "top-end",
|
position: "top-end",
|
||||||
icon: "success",
|
icon: "success",
|
||||||
title: data.message,
|
title: data.message,
|
||||||
showConfirmButton: false,
|
showConfirmButton: false,
|
||||||
timer: 1500
|
timer: 1500
|
||||||
});
|
})
|
||||||
|
var empId = document.getElementById('uid')
|
||||||
|
const year=moment(info.view.activeStart).format("YYYY")
|
||||||
|
calendar.removeAllEventSources();
|
||||||
|
calendar.addEventSource('/employee/holidays_byperson_calendar/'+empId.textContent+'/'+year)
|
||||||
|
refreshCounters(empId.textContent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info.el.style.backgroundColor=bgColor;
|
||||||
|
Swal.fire({
|
||||||
|
position: "top-end",
|
||||||
|
icon: "error",
|
||||||
|
title: data.message,
|
||||||
|
showConfirmButton: false,
|
||||||
|
timer: 1500
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
//Swal.fire('Saved!', '', 'success')
|
//Swal.fire('Saved!', '', 'success')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,30 +391,11 @@ block content
|
||||||
showConfirmButton: false,
|
showConfirmButton: false,
|
||||||
timer: 1500
|
timer: 1500
|
||||||
});
|
});
|
||||||
calendar.unselect();
|
info.el.style.backgroundColor=bgColor;
|
||||||
|
info.revert();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
views: {
|
|
||||||
multiMonthFourMonth: {
|
|
||||||
type: 'multiMonth',
|
|
||||||
duration: { months: 12 },
|
|
||||||
multiMonthMaxColumns: 2,
|
|
||||||
eventLimit: 10,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//initialEvents: res,
|
|
||||||
//events: '/employee/holidays_byperson_calendar/'+empId.textContent+'/'+year,
|
|
||||||
weekNumbers: true,
|
|
||||||
themeSystem: 'default',
|
|
||||||
eventClick: function(info)
|
|
||||||
{
|
|
||||||
//alert('Event: ' + info.event.title+'\n'+info.event.id+'\n'+info.event.extendedProps.employeeId);
|
|
||||||
console.log('Event: ' + info.event.title+'\n'+info.event.id+'\n'+info.event.extendedProps.employeeId)
|
|
||||||
|
|
||||||
// change the border color just for fun
|
|
||||||
info.el.style.borderColor = 'red';
|
|
||||||
},
|
|
||||||
eventDrop: async function( eventDropInfo )
|
eventDrop: async function( eventDropInfo )
|
||||||
{
|
{
|
||||||
const result= await Swal.fire(
|
const result= await Swal.fire(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue