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,
|
||||
employeeEmail:element.email,
|
||||
order:1,
|
||||
active: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -2083,6 +2084,7 @@ router.get("/holidays_byperson_calendar/:id/:year", async function(req, res){
|
|||
employeeName:element.name,
|
||||
employeeEmail:element.email,
|
||||
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
|
||||
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
|
||||
/*
|
||||
router.delete('/holidays_delete/:uid/:hid',utils.ensureAuthenticated,function(req,res){
|
||||
console.log("Delete UID: "+req.params.uid);
|
||||
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
|
||||
router.post('/holidays_byperson_fc/:id', utils.ensureAuthenticated,function(req,res){
|
||||
console.log(req.params.id);
|
||||
|
|
@ -2321,9 +2380,7 @@ router.post('/holidays_byperson_fc/:id', utils.ensureAuthenticated,function(req,
|
|||
|
||||
while (startd <= endd) {
|
||||
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
|
||||
//}
|
||||
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!
|
||||
|
|
@ -2331,9 +2388,7 @@ router.post('/holidays_byperson_fc/:id', utils.ensureAuthenticated,function(req,
|
|||
let hd ={
|
||||
start_date: req.body.sField,
|
||||
end_date: req.body.eField,
|
||||
|
||||
duration: weekdayCounter,
|
||||
|
||||
};
|
||||
//hd.id=hd._id;
|
||||
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();
|
||||
$("#listworktime").addClass("active");
|
||||
// Calendar
|
||||
|
|
@ -235,7 +261,11 @@ block content
|
|||
}
|
||||
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",
|
||||
|
|
@ -243,6 +273,7 @@ block content
|
|||
showConfirmButton: false,
|
||||
timer: 1500
|
||||
});
|
||||
|
||||
//Swal.fire('Saved!', '', 'success')
|
||||
}
|
||||
|
||||
|
|
@ -274,13 +305,96 @@ block content
|
|||
//events: '/employee/holidays_byperson_calendar/'+empId.textContent+'/'+year,
|
||||
weekNumbers: true,
|
||||
themeSystem: 'default',
|
||||
eventClick: function(info)
|
||||
eventClick: async 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)
|
||||
|
||||
if (info.event.extendedProps.active)
|
||||
{
|
||||
var bgColor=info.el.style.backgroundColor;
|
||||
// change the border color just for fun
|
||||
info.el.style.borderColor = 'red';
|
||||
info.el.style.backgroundColor = 'red';
|
||||
const result= await Swal.fire(
|
||||
{
|
||||
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",
|
||||
showDenyButton: true,
|
||||
confirmButtonText: 'Igen',
|
||||
denyButtonText: 'Nem',
|
||||
customClass: {
|
||||
actions: 'my-actions',
|
||||
confirmButton: 'order-2',
|
||||
denyButton: 'order-3',
|
||||
},
|
||||
}
|
||||
);
|
||||
if (result.isConfirmed)
|
||||
{
|
||||
console.log("Event ID: "+info.event.id)
|
||||
|
||||
console.log("Event After Drop\n"+info.event.start+'-'+info.event.end)
|
||||
const response = await fetch("/employee/holiday_destroy/"+info.event.extendedProps.employeeId+"/"+info.event.id,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
method: "DELETE",
|
||||
body: JSON.stringify({ event: info.event }),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok)
|
||||
{
|
||||
Swal.fire('Error', '', 'error')
|
||||
}
|
||||
if (data.response=="OK")
|
||||
{
|
||||
info.el.style.backgroundColor=bgColor;
|
||||
Swal.fire({
|
||||
position: "top-end",
|
||||
icon: "success",
|
||||
title: data.message,
|
||||
showConfirmButton: false,
|
||||
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')
|
||||
}
|
||||
|
||||
}
|
||||
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
|
||||
});
|
||||
info.el.style.backgroundColor=bgColor;
|
||||
info.revert();
|
||||
}
|
||||
}
|
||||
},
|
||||
eventDrop: async function( eventDropInfo )
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue