Workreport Dátum választás hozzáadva
This commit is contained in:
parent
1d9b9f63aa
commit
02ed2fea42
69
app.js
69
app.js
|
|
@ -1756,15 +1756,21 @@ function printWork(id,callback)
|
|||
|
||||
// Napi műhely jelentések nyomtatása
|
||||
// Get Single Work
|
||||
app.get('/print_workreport/:id',utils.ensureAuthenticated,async function(req,res){
|
||||
app.get('/print_workreport/:id/:date',utils.ensureAuthenticated,async function(req,res){
|
||||
var PdfPrinter=require('pdfmake');
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
try{
|
||||
var wtSum=0;
|
||||
const reports=await WorkReport.find({workId: mongoose.Types.ObjectId(req.params.id)})
|
||||
var dr_firstDay= moment(req.params.date,"YYYY.MM").startOf('month').toDate();
|
||||
var dr_lastDay = moment(req.params.date,"YYYY.MM").endOf('month').toDate();
|
||||
const reports=await WorkReport.find({workId: mongoose.Types.ObjectId(req.params.id),
|
||||
date: {
|
||||
$gte: dr_firstDay,
|
||||
$lte: dr_lastDay
|
||||
}})
|
||||
const workHeader=await Work.findOne({"_id":mongoose.Types.ObjectId(req.params.id)},{poNumber:1,workNumber:1,megrendelo:1})
|
||||
const workTimesSum=await WorkReport.aggregate(
|
||||
/* const workTimesSum=await WorkReport.aggregate(
|
||||
[
|
||||
{ $match: { 'workId': mongoose.Types.ObjectId(req.params.id)} },
|
||||
{$unwind: '$workFlow'},
|
||||
|
|
@ -1775,10 +1781,35 @@ app.get('/print_workreport/:id',utils.ensureAuthenticated,async function(req,res
|
|||
"count": 1,}
|
||||
}
|
||||
]
|
||||
)
|
||||
)*/
|
||||
const workTimesSum=await WorkReport.aggregate(
|
||||
[
|
||||
{ $match: { 'workId': mongoose.Types.ObjectId(req.params.id),
|
||||
date: {
|
||||
$gte: dr_firstDay,
|
||||
$lte: dr_lastDay
|
||||
}} },
|
||||
{$unwind: '$workFlow'},
|
||||
{$unwind: '$workFlow.employeeList'},
|
||||
{$group: {_id: '$workFlow.employeeList.company',
|
||||
count: {
|
||||
$sum: 8
|
||||
},
|
||||
employees:{
|
||||
$push:{
|
||||
name: "$workFlow.employeeList.name",
|
||||
id: "$_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
]
|
||||
)
|
||||
|
||||
if (workTimesSum.length>0) wtSum=workTimesSum[0].count*8
|
||||
var data=await printWorkReport(reports,workHeader)
|
||||
//if (workTimesSum.length>0) wtSum=workTimesSum[0].count*8
|
||||
var data=await printWorkReport(reports,workHeader,workTimesSum)
|
||||
//console.log(JSON.stringify(data));
|
||||
// fss.writeFile(path.normalize('d:\\test.json'), JSON.stringify(data));
|
||||
res.send(data);
|
||||
|
|
@ -1790,10 +1821,11 @@ app.get('/print_workreport/:id',utils.ensureAuthenticated,async function(req,res
|
|||
})
|
||||
|
||||
// Műhely Napi jelentés Nyomtatási kép generálás
|
||||
async function printWorkReport(reports, workHeader)
|
||||
async function printWorkReport(reports, workHeader, workTimeSum)
|
||||
{
|
||||
|
||||
var item=[];
|
||||
var wtsum=[];
|
||||
var wName=workHeader;
|
||||
var i=0;
|
||||
var emps="";
|
||||
|
|
@ -1832,7 +1864,13 @@ async function printWorkReport(reports, workHeader)
|
|||
})
|
||||
|
||||
})
|
||||
|
||||
wtsum.push([{text:'Cég név'}, {text:'Munkaórák'}]),
|
||||
workTimeSum.forEach((ws,ind)=>{
|
||||
wtsum.push([
|
||||
{text: ws._id, style:'tableData'},
|
||||
{text: ws.count, style:'tableData'},
|
||||
])
|
||||
})
|
||||
|
||||
|
||||
// playground requires you to assign document definition to a variable called dd
|
||||
|
|
@ -1906,13 +1944,22 @@ async function printWorkReport(reports, workHeader)
|
|||
body: item,//[],
|
||||
|
||||
},
|
||||
|
||||
layout: {
|
||||
fillColor: function (rowIndex, node, columnIndex) {
|
||||
return (rowIndex % 2 === 0) ? '#CCCCCC' : null;
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
style: 'tableExample',
|
||||
table: {
|
||||
widths: [200, '*'],
|
||||
body: wtsum
|
||||
}
|
||||
},
|
||||
],
|
||||
styles: {
|
||||
header: {
|
||||
|
|
@ -2148,10 +2195,10 @@ app.get('/media/:file', function(req, res) {
|
|||
|
||||
|
||||
});
|
||||
app.route('/workreport').post(apiSaveReport);
|
||||
app.route('/workreportSave').post(apiSaveReport);
|
||||
app.route('/workreportUpdate').post(apiUpdateReport);
|
||||
app.route('/workreportUserList').get(apiGetUsers);
|
||||
app.route('/workreport/:id').get(apiGetReport);
|
||||
app.route('/workreportGet/:id/:date').get(apiGetReport);
|
||||
app.route('/workreportList/:id').get(apiGetReportList);
|
||||
app.route('/workreportDates/:id').get(apiGetReportDates);
|
||||
// Route Files
|
||||
|
|
|
|||
|
|
@ -83,10 +83,22 @@ exports.apiGetReport=asyncHandler(async (req,res)=>{
|
|||
res.setHeader('Content-Type', 'application/json');
|
||||
try{
|
||||
var wtSum=0;
|
||||
const reports=await WorkReport.find({workId: mongoose.Types.ObjectId(req.params.id)})
|
||||
var dr_firstDay= moment(req.params.date,"YYYY.MM").startOf('month').toDate();
|
||||
var dr_lastDay = moment(req.params.date,"YYYY.MM").endOf('month').toDate();
|
||||
const reports=await WorkReport.find({workId: mongoose.Types.ObjectId(req.params.id),
|
||||
date: {
|
||||
$gte: dr_firstDay,
|
||||
$lte: dr_lastDay
|
||||
}
|
||||
})
|
||||
const workTimesSum=await WorkReport.aggregate(
|
||||
[
|
||||
{ $match: { 'workId': mongoose.Types.ObjectId(req.params.id)} },
|
||||
{ $match: { 'workId': mongoose.Types.ObjectId(req.params.id),
|
||||
date: {
|
||||
$gte: dr_firstDay,
|
||||
$lte: dr_lastDay
|
||||
}
|
||||
} },
|
||||
{$unwind: '$workFlow'},
|
||||
{$unwind: '$workFlow.employeeList'},
|
||||
{$group: {_id: '$workFlow.EmployeeList', count:{$sum:1}}},
|
||||
|
|
|
|||
|
|
@ -30,8 +30,9 @@
|
|||
var workId = $(this).attr('data-Id');
|
||||
if (workId)
|
||||
{
|
||||
var selectedDate = $('#workReportDate').data("DateTimePicker").date().format('YYYY.MM');
|
||||
//$.get('/invoices/print2' , function(data) { console.log(data);
|
||||
$.get('/print_workreport/'+workId , function(data) {
|
||||
$.get('/print_workreport/'+workId+'/'+selectedDate , function(data) {
|
||||
|
||||
if (!isLoaded)
|
||||
{ isLoaded=true;
|
||||
|
|
@ -74,6 +75,90 @@
|
|||
.catch(() => alert('Fájl letöltés sikertelen!'));
|
||||
|
||||
}
|
||||
|
||||
function updateWorkReport()
|
||||
{
|
||||
var selectedDate = $('#workReportDate').data("DateTimePicker").date().format('YYYY.MM');
|
||||
|
||||
//console.log("Selected Date:", selectedDate ? selectedDate.format('YYYY-MM-DD') : "No date selected");
|
||||
document.getElementById ('workTimesSum').textContent=0;
|
||||
//Fetch workReport
|
||||
var wid = document.getElementById ('wn').textContent;
|
||||
fetch('/workreportGet/'+wid+'/'+selectedDate , {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
$('#workReportTable2 > tbody').empty();
|
||||
//console.log(data)
|
||||
//var t=data.reports[0];
|
||||
var newRow= ""
|
||||
|
||||
$.each(data.reports,function(ix,t){
|
||||
newRow= `<tr><td rowspan=${t.workFlow.length}>
|
||||
<div class="row" style="margin-left: 3px">
|
||||
${moment(t.date).format("YYYY.MM.DD")}
|
||||
</div>
|
||||
<div class="row" style="margin-left: 3px">
|
||||
${moment(t.date).format("dddd")}
|
||||
</div>
|
||||
<div class="row justify-content-center" style="margin-left: 3px">
|
||||
<button type="button" class="btn btn-primary btn-sm" style="margin-left: 4px" data-id=${t._id} onclick="editReport(this);">
|
||||
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
</td>`
|
||||
$.each(t.workFlow,function(i,item){
|
||||
|
||||
//newRow+= `<tr>` +
|
||||
|
||||
newRow+= `<td>${item.Title}</td><td>`
|
||||
$.each(item.employeeList,function(idx,employee){
|
||||
if (employee.company)
|
||||
{
|
||||
newRow+=employee.company+'<br>'
|
||||
}
|
||||
else
|
||||
{
|
||||
newRow+="K-L Electro Bt"+'<br>'
|
||||
}
|
||||
})
|
||||
newRow+= `</td><td>`
|
||||
$.each(item.employeeList,function(idx,employee){
|
||||
newRow+=employee.name+'<br>'
|
||||
})
|
||||
newRow+= `</td>`
|
||||
newRow+= `</tr>`
|
||||
})
|
||||
//newRow+= `<td rowspan=${t.workFlow.length}>12</td></tr>`
|
||||
$('#workReportTable2 > tbody:last-child').append (newRow);
|
||||
})
|
||||
//$('#workReportTable > tbody:last-child').append (newRow);
|
||||
document.getElementById ('workTimesSum').textContent=`Munkaórák: ${data.workTimesSum} óra`
|
||||
})
|
||||
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$('#workReportDate').datetimepicker({
|
||||
locale: 'hu',
|
||||
format: 'LD',
|
||||
defaultDate: new Date(),
|
||||
inline: false,
|
||||
sideBySide: true,
|
||||
showTodayButton: true,
|
||||
format: 'YYYY.MM'
|
||||
}).on('dp.change',function(e){
|
||||
var calcdate=moment(e.date).format('YYYY.MM');// new Date($('#calcDate').val());
|
||||
//refreshAccessDetails(calcdate); // Lista frissítése dátum választáskor
|
||||
updateWorkReport();
|
||||
});
|
||||
})
|
||||
/* $("#getXML").click(function(ev) {
|
||||
|
||||
//isLoaded=false;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ block content
|
|||
link(rel='stylesheet' href='/bower_components/bootstrap/dist/css/bootstrap.css')
|
||||
link(href='//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css', rel='stylesheet')
|
||||
link(rel='stylesheet', type='text/css', href='https://unpkg.com/lightpick@latest/css/lightpick.css')
|
||||
link(rel='stylesheet', href='/bower_components/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css')
|
||||
link(rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/11.14.2/sweetalert2.css" integrity="sha512-TG239kA30BXeGpy+HpJei+qfJcKo8V9HKpe8UWuVdpk49NGUe86EDhmdXkCxMqD5gSlkLLi6YQ9SbNp+yRa9xQ==" crossorigin="anonymous" referrerpolicy="no-referrer")
|
||||
include Modals/modal_workReport
|
||||
|
||||
|
|
@ -201,10 +202,15 @@ block content
|
|||
.panel.panel-warning
|
||||
.panel-heading
|
||||
.row
|
||||
.col-md-7
|
||||
.col-md-5
|
||||
h4 Műhely munkavégzés
|
||||
.col-md-2
|
||||
h5#workTimesSum
|
||||
.col-md-2
|
||||
#workReportDate.input-group.date
|
||||
input.form-control(id='calcDate',name='wrDate', tabindex='6',type='text',style='color: white;background-color:#2C3446;')
|
||||
span.input-group-addon
|
||||
span.glyphicon.glyphicon-calendar
|
||||
.col-md-1.float-right
|
||||
button.btn.btn-success.button-spacer(id='printWorkReport',name='printWorkReport', data-id=work._id,type='button')
|
||||
span.fa.fa-solid.fa-print
|
||||
|
|
@ -283,11 +289,14 @@ block content
|
|||
| Vissza
|
||||
|
||||
script(src='/bower_components/jquery/dist/jquery.js')
|
||||
script(type='text/javascript', src='/bower_components/bootstrap/dist/js/bootstrap.min.js')
|
||||
script(type='text/javascript', src='/bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js')
|
||||
script(src='/js/work_utils.js')
|
||||
script(type='text/javascript', src='/bower_components/moment/min/moment.min.js')
|
||||
script(src='/bower_components/moment/min/moment-with-locales.js')
|
||||
script(type='text/javascript',src='/build/pdfmake.js')
|
||||
script(type='text/javascript',src='/build/vfs_fonts.js')
|
||||
|
||||
script(src='https://unpkg.com/lightpick@latest/lightpick.js')
|
||||
script(src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/11.14.2/sweetalert2.min.js" integrity="sha512-nD7/PXl2UD6bAYMJVKTLhr7qwnWVvoyqk8/WMzedDKMiQbaNXT3EUPzLYbLUHCLWqAZoXO37aVCtCKmAxZfqGw==" crossorigin="anonymous" referrerpolicy="no-referrer")
|
||||
script.
|
||||
|
|
@ -306,66 +315,7 @@ block content
|
|||
}
|
||||
$(document).ready(function () {
|
||||
moment.locale('HU')
|
||||
document.getElementById ('workTimesSum').textContent=0;
|
||||
//Fetch workReport
|
||||
var wid = document.getElementById ('wn').textContent;
|
||||
fetch('/workreport/'+wid, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log(data)
|
||||
//var t=data.reports[0];
|
||||
var newRow= ""
|
||||
|
||||
$.each(data.reports,function(ix,t){
|
||||
newRow= `<tr><td rowspan=${t.workFlow.length}>
|
||||
<div class="row" style="margin-left: 3px">
|
||||
${moment(t.date).format("YYYY.MM.DD")}
|
||||
</div>
|
||||
<div class="row" style="margin-left: 3px">
|
||||
${moment(t.date).format("dddd")}
|
||||
</div>
|
||||
<div class="row justify-content-center" style="margin-left: 3px">
|
||||
<button type="button" class="btn btn-primary btn-sm" style="margin-left: 4px" data-id=${t._id} onclick="editReport(this);">
|
||||
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
</td>`
|
||||
$.each(t.workFlow,function(i,item){
|
||||
|
||||
//newRow+= `<tr>` +
|
||||
|
||||
newRow+= `<td>${item.Title}</td><td>`
|
||||
$.each(item.employeeList,function(idx,employee){
|
||||
if (employee.company)
|
||||
{
|
||||
newRow+=employee.company+'<br>'
|
||||
}
|
||||
else
|
||||
{
|
||||
newRow+="K-L Electro Bt"+'<br>'
|
||||
}
|
||||
})
|
||||
newRow+= `</td><td>`
|
||||
$.each(item.employeeList,function(idx,employee){
|
||||
newRow+=employee.name+'<br>'
|
||||
})
|
||||
newRow+= `</td>`
|
||||
newRow+= `</tr>`
|
||||
})
|
||||
//newRow+= `<td rowspan=${t.workFlow.length}>12</td></tr>`
|
||||
$('#workReportTable2 > tbody:last-child').append (newRow);
|
||||
})
|
||||
//$('#workReportTable > tbody:last-child').append (newRow);
|
||||
document.getElementById ('workTimesSum').textContent=`Munkaórák: ${data.workTimesSum} óra`
|
||||
})
|
||||
|
||||
.catch(error => console.error('Error:', error));
|
||||
updateWorkReport()
|
||||
/*fetch('/workreportList/'+wid, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ block content
|
|||
console.log(da)
|
||||
|
||||
// Adatok mentése szerverre
|
||||
const response = fetch('/workreport', {
|
||||
const response = fetch('/workreportSave', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
|
|
|||
Loading…
Reference in New Issue