diff --git a/app.js b/app.js index c1f53b1..200fd95 100644 --- a/app.js +++ b/app.js @@ -1796,8 +1796,10 @@ async function printWorkReport(reports, workHeader) var item=[]; var wName=workHeader; var i=0; + var emps=""; + var companies=""; moment.locale('hu'); - item.push([ {text:'#', alignment: 'left'},{text:'Dátum', alignment: 'center'}, {text:'Munkafolyamat', alignment: 'center'}, {text:'Résztvevők', alignment: 'center'}]); + item.push([ {text:'#', alignment: 'left'},{text:'Dátum', alignment: 'center'}, {text:'Munkafolyamat', alignment: 'center'}, {text:'Cég', alignment: 'center'}, {text:'Résztvevők', alignment: 'center'}]); wName=reports[0].workTitle; @@ -1805,15 +1807,25 @@ async function printWorkReport(reports, workHeader) report.workFlow.forEach((wf,idx)=>{ - var emps=""; + emps=""; + companies=""; wf.employeeList.forEach((employee,ind)=>{ emps=emps+employee.name+'\r\n'; + if (employee.company) + { + companies=companies+employee.company+'\r\n' + } + else + { + companies=companies+"K-L Electro Bt"+'\r\n' + } i++; }) item.push([ {id:i,text: index+1, style:'tableData',rowSpan: report.workFlow.length}, {text: moment(report.date).format('YYYY.MM.DD'), style:'tableData', alignment: 'center',rowSpan: report.workFlow.length}, {text: wf.Title, style:'tableData', alignment: 'center'}, + {text: companies, style:'tableData', alignment: 'center'}, {text: emps, style:'tableData', alignment: 'center'}, ]); @@ -1890,7 +1902,7 @@ async function printWorkReport(reports, workHeader) //widths: [20, 'auto', 80, 80,'*','*','*'], // widths: [20, '*', 70, 70,50,'auto','auto'], - widths: [20, 70,'*', 100], + widths: [20, 70,'*', 100, 100], body: item,//[], }, diff --git a/js/workReport.js b/js/workReport.js index 964c0a4..d95cf57 100644 --- a/js/workReport.js +++ b/js/workReport.js @@ -130,14 +130,34 @@ exports.apiGetUsers=asyncHandler(async (req,res)=>{ //const {workId,foremanId, workTitle,employeeList }=req.body; res.setHeader('Content-Type', 'application/json'); - try{ - const users=await Employee.find({'konyvelesre': 'on'},{_id:1,name:1},{sort: {name: 1}}) + /* try{ + const users=await Employee.find({'konyvelesre': 'on'},{_id:1,name:1,company:1},{sort: {name: 1}}) res.send({'response':'ok','users':users}); }catch(err){ res.status(500).json({'response':'fail','message':'Hiba a mentésnél !\n'+err.message}); - } - + }*/ + try{ + const users=await Employee.aggregate([ + { $sort: { "name": 1 } }, + {$match: { "konyvelesre": "on"}}, + { + $group: { + _id: {company:'$company'}, + employees:{ + $push:{ + name: "$name", + id: "$_id" + } + } + } + }, + ]); + res.send({'response':'ok','users':users}); + } + catch(err){ + res.status(500).json({'response':'fail','message':'Hiba a mentésnél !\n'+err.message}); + } }); exports.apiGetReportList=asyncHandler(async (req,res)=>{ diff --git a/models/employee.js b/models/employee.js index 30868d7..9f30eea 100644 --- a/models/employee.js +++ b/models/employee.js @@ -128,7 +128,11 @@ let employeeSchema = mongoose.Schema({ end_date: {type: String}, duration: {type: Number}, - }] + }], + company:{ + type: String, + required: true + }, }); employeeSchema.methods.comparePassword = function(candidatePassword, cb) { diff --git a/models/workReportModel.js b/models/workReportModel.js index d231995..d20bf68 100644 --- a/models/workReportModel.js +++ b/models/workReportModel.js @@ -25,6 +25,7 @@ let workReportSchema = mongoose.Schema({ employeeList:[{ employeeId:{type: mongoose.Schema.Types.ObjectId}, name: {type: String}, + company: {type: String}, }] }], }) diff --git a/routes/employee.js b/routes/employee.js index f4b628b..5a3d646 100644 --- a/routes/employee.js +++ b/routes/employee.js @@ -2642,6 +2642,7 @@ router.post('/add',utils.ensureAuthenticated,function(req,res){ req.checkBody('rfid','RFID azonosító megadása kötelező!').notEmpty(); req.checkBody('vacationYear','Éves szabadság megadása kötelező!').notEmpty(); req.checkBody('vacationUsed','Kiadott szabadság megadása kötelező!').notEmpty(); + req.checkBody('company','Cégnév megadása kötelező!').notEmpty(); req.checkBody('email', 'Email megadása kötelező!').notEmpty(); req.checkBody('email', 'Nem valós email cím!').isEmail(); req.checkBody('password', 'Jelszó megadása kötelező!').notEmpty(); @@ -2672,6 +2673,7 @@ router.post('/add',utils.ensureAuthenticated,function(req,res){ employee.vacationUsed=req.body.vacationUsed; employee.password=req.body.password; employee.email=req.body.email; + employee.company=req.body.company employee.apiKey='-'; employee.uuid='-'; mobilePortalAccessEnabled=false; @@ -2768,6 +2770,7 @@ router.post('/edit/:id', utils.ensureAuthenticated,function(req,res){ req.checkBody('rfid','RFID azonosító megadása kötelező!').notEmpty(); req.checkBody('vacationYear','Éves szabadság megadása kötelező!').notEmpty(); req.checkBody('vacationUsed','Kiadott szabadság megadása kötelező!').notEmpty(); + req.checkBody('company','Cégnév megadása kötelező!').notEmpty(); // Get errors let errors = req.validationErrors(); @@ -2790,6 +2793,7 @@ router.post('/edit/:id', utils.ensureAuthenticated,function(req,res){ employee.vacationYear=req.body.vacationYear; employee.vacationUsed=req.body.vacationUsed; employee.konyvelesre=req.body.flagKonyveles; + employee.company=req.body.company; employee.mobilePortalAccessEnabled=Boolean(req.body.mobilePortalAccessEnabled); employee.isSubcontractor=req.body.flagSubContractor; employee.isStudent=req.body.flagStudent; diff --git a/views/Modals/modal_workReportEdit.pug b/views/Modals/modal_workReportEdit.pug index 812efec..f86e2b9 100644 --- a/views/Modals/modal_workReportEdit.pug +++ b/views/Modals/modal_workReportEdit.pug @@ -50,9 +50,10 @@ script. //const d=JSON.parse(decodeURIComponent($(identifier).data('item'))) const d=$(identifier).data('id') const name=$(identifier).data('name') + const company=$(identifier).data('company') if (!state) { - workers.push({employeeId:d, name:name}); + workers.push({employeeId:d, name:name,company:company}); } else { @@ -185,10 +186,19 @@ script. .then(response => response.json()) .then(data => { console.log(data) - $.each(data.users,function(i,item){ + /*$.each(data.users,function(i,item){ var data_str = encodeURIComponent(JSON.stringify(item)); $('').appendTo('#buttons2'); - }) + })*/ + $.each(data.users,function(i,item){ + $('