Compare commits
2 Commits
c9905eefb7
...
c4eda756eb
Author | SHA1 | Date |
---|---|---|
adriano | c4eda756eb | |
adriano | 47ed80e1a9 |
|
@ -4,28 +4,19 @@ import { Request, Response } from "express";
|
||||||
import AppError from "../errors/AppError";
|
import AppError from "../errors/AppError";
|
||||||
import ShowTicketReport from "../services/TicketServices/ShowTicketReport";
|
import ShowTicketReport from "../services/TicketServices/ShowTicketReport";
|
||||||
import ShowMessageReport from "../services/MessageServices/ShowMessageReport";
|
import ShowMessageReport from "../services/MessageServices/ShowMessageReport";
|
||||||
|
|
||||||
import onlineUserService from "../services/UserServices/CreateOrUpdateOnlineUserService";
|
import onlineUserService from "../services/UserServices/CreateOrUpdateOnlineUserService";
|
||||||
import User from "../models/User";
|
import User from "../models/User";
|
||||||
import Queue from "../models/Queue";
|
import Queue from "../models/Queue";
|
||||||
import UserOnlineTime from "../models/UserOnlineTime";
|
import UserOnlineTime from "../models/UserOnlineTime";
|
||||||
|
|
||||||
import { Op, Sequelize, literal } from "sequelize";
|
import { Op, Sequelize, literal } from "sequelize";
|
||||||
import format from 'date-fns/format';
|
import format from "date-fns/format";
|
||||||
import ptBR from 'date-fns/locale/pt-BR';
|
import ptBR from "date-fns/locale/pt-BR";
|
||||||
import { splitDateTime } from "../helpers/SplitDateTime";
|
import { splitDateTime } from "../helpers/SplitDateTime";
|
||||||
import ListUserOnlineOffline from "../services/UserServices/ListUsersOnlineOfflineService";
|
import ListUserOnlineOffline from "../services/UserServices/ListUsersOnlineOfflineService";
|
||||||
import ListUserParamiterService from "../services/UserServices/ListUserParamiterService";
|
import ListUserParamiterService from "../services/UserServices/ListUserParamiterService";
|
||||||
|
|
||||||
import ShowUserServiceReport from "../services/UserServices/ShowUserServiceReport";
|
import ShowUserServiceReport from "../services/UserServices/ShowUserServiceReport";
|
||||||
|
|
||||||
import CountTicketsByUserQueue from "../services/UserServices/CountTicketsByUserQueue";
|
import CountTicketsByUserQueue from "../services/UserServices/CountTicketsByUserQueue";
|
||||||
|
|
||||||
import ShowQueuesByUser from "../services/UserServices/ShowQueuesByUser";
|
import ShowQueuesByUser from "../services/UserServices/ShowQueuesByUser";
|
||||||
|
|
||||||
|
|
||||||
// import { filter } from "bluebird";
|
|
||||||
|
|
||||||
import { getIO } from "../libs/socket";
|
import { getIO } from "../libs/socket";
|
||||||
import { Json } from "sequelize/types/lib/utils";
|
import { Json } from "sequelize/types/lib/utils";
|
||||||
|
|
||||||
|
@ -33,6 +24,8 @@ type IndexQuery = {
|
||||||
userId: string;
|
userId: string;
|
||||||
startDate: string;
|
startDate: string;
|
||||||
endDate: string;
|
endDate: string;
|
||||||
|
createdOrUpdated: string;
|
||||||
|
queueId: string;
|
||||||
pageNumber: string;
|
pageNumber: string;
|
||||||
userQueues: [];
|
userQueues: [];
|
||||||
};
|
};
|
||||||
|
@ -40,11 +33,12 @@ type IndexQuery = {
|
||||||
type ReportOnQueue = {
|
type ReportOnQueue = {
|
||||||
userId: string;
|
userId: string;
|
||||||
identifier: string;
|
identifier: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
export const reportUserByDateStartDateEnd = async (req: Request, res: Response): Promise<Response> => {
|
|
||||||
|
|
||||||
|
export const reportUserByDateStartDateEnd = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<Response> => {
|
||||||
if (
|
if (
|
||||||
req.user.profile !== "master" &&
|
req.user.profile !== "master" &&
|
||||||
req.user.profile !== "admin" &&
|
req.user.profile !== "admin" &&
|
||||||
|
@ -53,23 +47,53 @@ export const reportUserByDateStartDateEnd = async (req: Request, res: Response):
|
||||||
throw new AppError("ERR_NO_PERMISSION", 403);
|
throw new AppError("ERR_NO_PERMISSION", 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { userId, startDate, endDate, pageNumber, userQueues } = req.query as IndexQuery
|
const {
|
||||||
|
userId,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
pageNumber,
|
||||||
|
userQueues,
|
||||||
|
createdOrUpdated,
|
||||||
|
queueId
|
||||||
|
} = req.query as IndexQuery;
|
||||||
|
|
||||||
console.log("userId, startDate, endDate, pageNumber: ", userId, startDate, endDate, pageNumber);
|
console.log(
|
||||||
|
"userId, startDate, endDate, pageNumber, userQueues, createdOrUpdated, queueId: ",
|
||||||
|
userId,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
pageNumber,
|
||||||
|
userQueues,
|
||||||
|
createdOrUpdated,
|
||||||
|
queueId
|
||||||
|
);
|
||||||
|
|
||||||
const { tickets, count, hasMore } = await ShowTicketReport({ userId, startDate, endDate, pageNumber });
|
const { tickets, count, hasMore } = await ShowTicketReport({
|
||||||
// console.log('kkkkkkkkkkkkkkkkkk tickets: ', JSON.stringify(tickets, null, 6))
|
userId,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
pageNumber,
|
||||||
|
createdOrUpdated,
|
||||||
|
queueId
|
||||||
|
});
|
||||||
|
|
||||||
return res.status(200).json({ tickets, count, hasMore });
|
const queues = await Queue.findAll({ attributes: ["id", "name"] });
|
||||||
|
|
||||||
|
return res.status(200).json({ tickets, count, hasMore, queues });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const reportUserService = async (
|
||||||
export const reportUserService = async (req: Request, res: Response): Promise<Response> => {
|
req: Request,
|
||||||
|
res: Response
|
||||||
if (req.user.profile !== "master" && req.user.profile !== "admin" && req.user.profile !=="supervisor") {
|
): Promise<Response> => {
|
||||||
|
if (
|
||||||
|
req.user.profile !== "master" &&
|
||||||
|
req.user.profile !== "admin" &&
|
||||||
|
req.user.profile !== "supervisor"
|
||||||
|
) {
|
||||||
throw new AppError("ERR_NO_PERMISSION", 403);
|
throw new AppError("ERR_NO_PERMISSION", 403);
|
||||||
}
|
}
|
||||||
const { userId, startDate, endDate } = req.query as IndexQuery
|
const { userId, startDate, endDate } = req.query as IndexQuery;
|
||||||
|
|
||||||
// let usersProfile = await ListUserParamiterService({ profile: 'user' })
|
// let usersProfile = await ListUserParamiterService({ profile: 'user' })
|
||||||
let usersProfile = await ListUserParamiterService({
|
let usersProfile = await ListUserParamiterService({
|
||||||
|
@ -77,55 +101,89 @@ export const reportUserService = async (req: Request, res: Response): Promise<Re
|
||||||
raw: true
|
raw: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const sumUserOlineTime = await ShowUserServiceReport({ startDate, endDate, userId });
|
const sumUserOlineTime = await ShowUserServiceReport({
|
||||||
const closedByUser = await ShowUserServiceReport({ startDate, endDate, ticketStatus: 'closed', userId });
|
startDate,
|
||||||
const openByUser = await ShowUserServiceReport({ startDate, endDate, ticketStatus: 'open', userId });
|
endDate,
|
||||||
|
userId
|
||||||
|
});
|
||||||
|
const closedByUser = await ShowUserServiceReport({
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
ticketStatus: "closed",
|
||||||
|
userId
|
||||||
|
});
|
||||||
|
const openByUser = await ShowUserServiceReport({
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
ticketStatus: "open",
|
||||||
|
userId
|
||||||
|
});
|
||||||
|
|
||||||
let dateTime = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
let dateTime = splitDateTime(
|
||||||
const onlineUsers = await ListUserOnlineOffline({ date: dateTime.fullDate })
|
new Date(format(new Date(), "yyyy-MM-dd HH:mm:ss", { locale: ptBR }))
|
||||||
|
);
|
||||||
|
const onlineUsers = await ListUserOnlineOffline({ date: dateTime.fullDate });
|
||||||
|
|
||||||
const openByUserOnQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'open', clientChatStart: true })
|
const openByUserOnQueue = await CountTicketsByUserQueue({
|
||||||
const openByUserOutQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'open', clientChatStart: false })
|
startDate: startDate,
|
||||||
|
endDate: endDate,
|
||||||
|
status: "open",
|
||||||
|
clientChatStart: true
|
||||||
|
});
|
||||||
|
const openByUserOutQueue = await CountTicketsByUserQueue({
|
||||||
|
startDate: startDate,
|
||||||
|
endDate: endDate,
|
||||||
|
status: "open",
|
||||||
|
clientChatStart: false
|
||||||
|
});
|
||||||
|
|
||||||
const closedByUserOnQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'closed', clientChatStart: true })
|
const closedByUserOnQueue = await CountTicketsByUserQueue({
|
||||||
const closedUserOutQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'closed', clientChatStart: false })
|
startDate: startDate,
|
||||||
|
endDate: endDate,
|
||||||
|
status: "closed",
|
||||||
|
clientChatStart: true
|
||||||
|
});
|
||||||
|
const closedUserOutQueue = await CountTicketsByUserQueue({
|
||||||
|
startDate: startDate,
|
||||||
|
endDate: endDate,
|
||||||
|
status: "closed",
|
||||||
|
clientChatStart: false
|
||||||
|
});
|
||||||
|
|
||||||
// let openQueueInOut = openByUserOnQueue.concat(openByUserOutQueue)
|
// let openQueueInOut = openByUserOnQueue.concat(openByUserOutQueue)
|
||||||
// let closedQueueInOut = closedByUserOnQueue.concat(closedUserOutQueue)
|
// let closedQueueInOut = closedByUserOnQueue.concat(closedUserOutQueue)
|
||||||
|
|
||||||
|
const queuesByUser = await ShowQueuesByUser({ profile: "user" });
|
||||||
|
|
||||||
const queuesByUser = await ShowQueuesByUser({ profile: 'user' })
|
let openCloseOnQueue = openByUserOnQueue.concat(closedByUserOnQueue);
|
||||||
|
let openCloseOutQueue = openByUserOutQueue.concat(closedUserOutQueue);
|
||||||
let openCloseOnQueue = openByUserOnQueue.concat(closedByUserOnQueue)
|
|
||||||
let openCloseOutQueue = openByUserOutQueue.concat(closedUserOutQueue)
|
|
||||||
|
|
||||||
|
|
||||||
// console.log('onlineUsers: ',JSON.parse(JSON.stringify(onlineUsers)))
|
// console.log('onlineUsers: ',JSON.parse(JSON.stringify(onlineUsers)))
|
||||||
// console.log('sumUserOlineTime: ', JSON.parse(JSON.stringify(sumUserOlineTime)))
|
// console.log('sumUserOlineTime: ', JSON.parse(JSON.stringify(sumUserOlineTime)))
|
||||||
|
|
||||||
for (let i = 0; i < queuesByUser.length; i++) {
|
for (let i = 0; i < queuesByUser.length; i++) {
|
||||||
|
queuesByUser[i].countOpen = 0;
|
||||||
queuesByUser[i].countOpen = 0
|
queuesByUser[i].countClosed = 0;
|
||||||
queuesByUser[i].countClosed = 0
|
|
||||||
|
|
||||||
for (let x = 0; x < openCloseOnQueue.length; x++) {
|
for (let x = 0; x < openCloseOnQueue.length; x++) {
|
||||||
if ((queuesByUser[i].userId == openCloseOnQueue[x].userId) &&
|
if (
|
||||||
(queuesByUser[i].queueId == openCloseOnQueue[x].queueId && openCloseOnQueue[x].status == 'open')) {
|
queuesByUser[i].userId == openCloseOnQueue[x].userId &&
|
||||||
queuesByUser[i].countOpen = openCloseOnQueue[x].totAttendance
|
queuesByUser[i].queueId == openCloseOnQueue[x].queueId &&
|
||||||
}
|
openCloseOnQueue[x].status == "open"
|
||||||
else if ((queuesByUser[i].userId == openCloseOnQueue[x].userId) &&
|
) {
|
||||||
(queuesByUser[i].queueId == openCloseOnQueue[x].queueId && openCloseOnQueue[x].status == 'closed')) {
|
queuesByUser[i].countOpen = openCloseOnQueue[x].totAttendance;
|
||||||
queuesByUser[i].countClosed = openCloseOnQueue[x].totAttendance
|
} else if (
|
||||||
}
|
queuesByUser[i].userId == openCloseOnQueue[x].userId &&
|
||||||
|
queuesByUser[i].queueId == openCloseOnQueue[x].queueId &&
|
||||||
|
openCloseOnQueue[x].status == "closed"
|
||||||
|
) {
|
||||||
|
queuesByUser[i].countClosed = openCloseOnQueue[x].totAttendance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
usersProfile.map((user: any) => {
|
usersProfile.map((user: any) => {
|
||||||
|
let index = sumUserOlineTime.findIndex((e: any) => e.userId == user.id);
|
||||||
let index = sumUserOlineTime.findIndex((e: any) => e.userId == user.id)
|
|
||||||
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
user.sumOnlineTime = sumUserOlineTime[index];
|
user.sumOnlineTime = sumUserOlineTime[index];
|
||||||
|
@ -133,68 +191,67 @@ export const reportUserService = async (req: Request, res: Response): Promise<Re
|
||||||
// console.log('user.sumOlineTime: 'user.sumOnlineTime)
|
// console.log('user.sumOlineTime: 'user.sumOnlineTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
index = closedByUser.findIndex((e: any) => e.userId == user.id)
|
index = closedByUser.findIndex((e: any) => e.userId == user.id);
|
||||||
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
user.sumClosed = closedByUser[index];
|
user.sumClosed = closedByUser[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
index = openByUser.findIndex((e: any) => e.userId == user.id)
|
index = openByUser.findIndex((e: any) => e.userId == user.id);
|
||||||
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
user.sumOpen = openByUser[index]
|
user.sumOpen = openByUser[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// OPEN, CLOSED TICKETS STARTED BY USERS
|
// OPEN, CLOSED TICKETS STARTED BY USERS
|
||||||
let openClosedOutQueue = {}
|
let openClosedOutQueue = {};
|
||||||
let open = openCloseOutQueue.filter((e) => e.userId == user.id && e.status == 'open')
|
let open = openCloseOutQueue.filter(
|
||||||
let closed = openCloseOutQueue.filter((e) => e.userId == user.id && e.status == 'closed')
|
e => e.userId == user.id && e.status == "open"
|
||||||
|
);
|
||||||
|
let closed = openCloseOutQueue.filter(
|
||||||
|
e => e.userId == user.id && e.status == "closed"
|
||||||
|
);
|
||||||
|
|
||||||
openClosedOutQueue = {
|
openClosedOutQueue = {
|
||||||
...openClosedOutQueue,
|
...openClosedOutQueue,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
countOpen: open && open.length > 0 ? open[0].totAttendance : 0,
|
countOpen: open && open.length > 0 ? open[0].totAttendance : 0,
|
||||||
countClosed: closed && closed.length > 0 ? closed[0].totAttendance : 0
|
countClosed: closed && closed.length > 0 ? closed[0].totAttendance : 0
|
||||||
}
|
};
|
||||||
|
|
||||||
user.openClosedOutQueue = openClosedOutQueue
|
|
||||||
|
|
||||||
|
user.openClosedOutQueue = openClosedOutQueue;
|
||||||
|
|
||||||
// OPEN, CLOSED TICKETS STARTED BY CLIENTS
|
// OPEN, CLOSED TICKETS STARTED BY CLIENTS
|
||||||
let openClosedInQueue = queuesByUser.filter((e) => e.userId == user.id)
|
let openClosedInQueue = queuesByUser.filter(e => e.userId == user.id);
|
||||||
|
|
||||||
if (openClosedInQueue && openClosedInQueue.length > 0) {
|
if (openClosedInQueue && openClosedInQueue.length > 0) {
|
||||||
user.openClosedInQueue = openClosedInQueue
|
user.openClosedInQueue = openClosedInQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
index = onlineUsers.findIndex((e: any) => e.userId == user.id);
|
||||||
index = onlineUsers.findIndex((e: any) => e.userId == user.id)
|
|
||||||
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
user.statusOnline = onlineUsers[index]
|
user.statusOnline = onlineUsers[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startDate.length > 0 && startDate.split('-').length == 3) {
|
if (startDate.length > 0 && startDate.split("-").length == 3) {
|
||||||
let date = startDate.split('-')
|
let date = startDate.split("-");
|
||||||
user.startDate = `${date[2]}/${date[1]}/${date[0]}`
|
user.startDate = `${date[2]}/${date[1]}/${date[0]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endDate.length > 0 && endDate.split('-').length == 3) {
|
if (endDate.length > 0 && endDate.split("-").length == 3) {
|
||||||
let date = endDate.split('-')
|
let date = endDate.split("-");
|
||||||
user.endDate = `${date[2]}/${date[1]}/${date[0]}`
|
user.endDate = `${date[2]}/${date[1]}/${date[0]}`;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
})
|
return res.status(200).json({ usersProfile: usersProfile });
|
||||||
|
|
||||||
return res.status(200).json({usersProfile: usersProfile});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const reportMessagesUserByDateStartDateEnd = async (
|
||||||
|
req: Request,
|
||||||
export const reportMessagesUserByDateStartDateEnd = async (req: Request, res: Response): Promise<Response> => {
|
res: Response
|
||||||
|
): Promise<Response> => {
|
||||||
if (
|
if (
|
||||||
req.user.profile !== "master" &&
|
req.user.profile !== "master" &&
|
||||||
req.user.profile !== "admin" &&
|
req.user.profile !== "admin" &&
|
||||||
|
@ -203,35 +260,32 @@ export const reportMessagesUserByDateStartDateEnd = async (req: Request, res: Re
|
||||||
throw new AppError("ERR_NO_PERMISSION", 403);
|
throw new AppError("ERR_NO_PERMISSION", 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { userId, startDate, endDate } = req.query as IndexQuery
|
const { userId, startDate, endDate } = req.query as IndexQuery;
|
||||||
|
|
||||||
let data_query_messages = await ShowMessageReport(userId, startDate, endDate);
|
let data_query_messages = await ShowMessageReport(userId, startDate, endDate);
|
||||||
|
|
||||||
for (var i = 0; i < data_query_messages.length; i++) {
|
for (var i = 0; i < data_query_messages.length; i++) {
|
||||||
|
|
||||||
if (data_query_messages[i].fromMe) {
|
if (data_query_messages[i].fromMe) {
|
||||||
data_query_messages[i].fromMe = 'Atendente'
|
data_query_messages[i].fromMe = "Atendente";
|
||||||
}
|
} else {
|
||||||
else {
|
data_query_messages[i].fromMe = "Cliente";
|
||||||
data_query_messages[i].fromMe = 'Cliente'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data_query_messages[i].id = (i + 1)
|
data_query_messages[i].id = i + 1;
|
||||||
|
|
||||||
console.log('data_query_messages: ', data_query_messages[i])
|
console.log("data_query_messages: ", data_query_messages[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).json(data_query_messages);
|
return res.status(200).json(data_query_messages);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const reportOnQueue = async (
|
||||||
|
req: Request,
|
||||||
export const reportOnQueue = async (req: Request, res: Response): Promise<Response> => {
|
res: Response
|
||||||
|
): Promise<Response> => {
|
||||||
// console.log(req.body)
|
// console.log(req.body)
|
||||||
|
|
||||||
const { adminId, identifier, queueStatus, file } = req.body
|
const { adminId, identifier, queueStatus, file } = req.body;
|
||||||
|
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
io.emit("queryOnQueueStatus", {
|
io.emit("queryOnQueueStatus", {
|
||||||
|
@ -244,10 +298,5 @@ export const reportOnQueue = async (req: Request, res: Response): Promise<Respon
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(200).json({ message: 'ok' })
|
return res.status(200).json({ message: "ok" });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@ import { userInfo } from "os";
|
||||||
import { Op, where } from "sequelize";
|
import { Op, where } from "sequelize";
|
||||||
|
|
||||||
import { Sequelize } from "sequelize";
|
import { Sequelize } from "sequelize";
|
||||||
import moment from 'moment';
|
import moment from "moment";
|
||||||
|
|
||||||
import { startOfDay, endOfDay, parseISO, getDate} from "date-fns";
|
import { startOfDay, endOfDay, parseISO, getDate } from "date-fns";
|
||||||
import { string } from "yup/lib/locale";
|
import { string } from "yup/lib/locale";
|
||||||
import Whatsapp from "../../models/Whatsapp";
|
import Whatsapp from "../../models/Whatsapp";
|
||||||
|
|
||||||
|
@ -20,10 +20,11 @@ interface Request {
|
||||||
userId: string | number;
|
userId: string | number;
|
||||||
startDate: string;
|
startDate: string;
|
||||||
endDate: string;
|
endDate: string;
|
||||||
|
createdOrUpdated?: string;
|
||||||
|
queueId?: string;
|
||||||
pageNumber?: string;
|
pageNumber?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
tickets: Ticket[];
|
tickets: Ticket[];
|
||||||
count: number;
|
count: number;
|
||||||
|
@ -35,89 +36,137 @@ const ShowTicketReport = async ({
|
||||||
userId,
|
userId,
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
pageNumber = "1"
|
pageNumber = "1",
|
||||||
|
createdOrUpdated = "created",
|
||||||
|
queueId
|
||||||
}: Request): Promise<Response> => {
|
}: Request): Promise<Response> => {
|
||||||
|
let where_clause = {};
|
||||||
|
|
||||||
let where_clause = {}
|
if (userId == "0") {
|
||||||
|
if (createdOrUpdated == "updated") {
|
||||||
if(userId=='0'){
|
|
||||||
where_clause = {
|
where_clause = {
|
||||||
updatedAt: {
|
updatedAt: {
|
||||||
[Op.gte]: startDate+' 00:00:00.000000',
|
[Op.gte]: startDate + " 00:00:00.000000",
|
||||||
[Op.lte]: endDate +' 23:59:59.999999'
|
[Op.lte]: endDate + " 23:59:59.999999"
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
} else if (createdOrUpdated == "created") {
|
||||||
|
where_clause = {
|
||||||
|
createdAt: {
|
||||||
|
[Op.gte]: startDate + " 00:00:00.000000",
|
||||||
|
[Op.lte]: endDate + " 23:59:59.999999"
|
||||||
}
|
}
|
||||||
else{
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queueId) {
|
||||||
|
where_clause = { ...where_clause, queueId };
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (createdOrUpdated == "updated") {
|
||||||
where_clause = {
|
where_clause = {
|
||||||
userid: userId,
|
userid: userId,
|
||||||
updatedAt: {
|
updatedAt: {
|
||||||
[Op.gte]: startDate+' 00:00:00.000000',
|
[Op.gte]: startDate + " 00:00:00.000000",
|
||||||
[Op.lte]: endDate +' 23:59:59.999999'
|
[Op.lte]: endDate + " 23:59:59.999999"
|
||||||
},
|
}
|
||||||
|
};
|
||||||
|
} else if (createdOrUpdated == "created") {
|
||||||
|
where_clause = {
|
||||||
|
userid: userId,
|
||||||
|
createdAt: {
|
||||||
|
[Op.gte]: startDate + " 00:00:00.000000",
|
||||||
|
[Op.lte]: endDate + " 23:59:59.999999"
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const limit = 40;
|
const limit = 40;
|
||||||
const offset = limit * (+pageNumber - 1);
|
const offset = limit * (+pageNumber - 1);
|
||||||
|
|
||||||
const {count, rows: tickets} = await Ticket.findAndCountAll({
|
const { count, rows: tickets } = await Ticket.findAndCountAll({
|
||||||
|
where: where_clause,
|
||||||
where: where_clause ,
|
|
||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
//attributes: ['id', 'status', 'createdAt', 'updatedAt'],
|
//attributes: ['id', 'status', 'createdAt', 'updatedAt'],
|
||||||
|
|
||||||
attributes: ['id', 'status', 'statusChatEnd', [Sequelize.fn("DATE_FORMAT",Sequelize.col("Ticket.createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"],
|
attributes: [
|
||||||
[Sequelize.fn("DATE_FORMAT",Sequelize.col("Ticket.updatedAt"),"%d/%m/%Y %H:%i:%s"),"updatedAt"]],
|
"id",
|
||||||
|
"status",
|
||||||
|
"statusChatEnd",
|
||||||
|
[
|
||||||
|
Sequelize.fn(
|
||||||
|
"DATE_FORMAT",
|
||||||
|
Sequelize.col("Ticket.createdAt"),
|
||||||
|
"%d/%m/%Y %H:%i:%s"
|
||||||
|
),
|
||||||
|
"createdAt"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
Sequelize.fn(
|
||||||
|
"DATE_FORMAT",
|
||||||
|
Sequelize.col("Ticket.updatedAt"),
|
||||||
|
"%d/%m/%Y %H:%i:%s"
|
||||||
|
),
|
||||||
|
"updatedAt"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Message,
|
model: Message,
|
||||||
required:true,
|
required: true,
|
||||||
separate: true,
|
separate: true,
|
||||||
|
|
||||||
// attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl','createdAt'],
|
// attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl','createdAt'],
|
||||||
|
|
||||||
attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl', [Sequelize.fn("DATE_FORMAT",Sequelize.col("createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"]],
|
attributes: [
|
||||||
|
"body",
|
||||||
order: [
|
"read",
|
||||||
['createdAt', 'ASC']
|
"mediaType",
|
||||||
|
"fromMe",
|
||||||
|
"mediaUrl",
|
||||||
|
[
|
||||||
|
Sequelize.fn(
|
||||||
|
"DATE_FORMAT",
|
||||||
|
Sequelize.col("createdAt"),
|
||||||
|
"%d/%m/%Y %H:%i:%s"
|
||||||
|
),
|
||||||
|
"createdAt"
|
||||||
]
|
]
|
||||||
|
],
|
||||||
|
|
||||||
|
order: [["createdAt", "ASC"]]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
model: Contact,
|
model: Contact,
|
||||||
attributes: ['name', 'number']
|
attributes: ["name", "number"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
model: User,
|
model: User,
|
||||||
attributes: ['name', 'email']
|
attributes: ["name", "email"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
model: Queue,
|
model: Queue,
|
||||||
attributes: ['name']
|
attributes: ["name"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
model: Whatsapp,
|
model: Whatsapp,
|
||||||
attributes: ['name']
|
attributes: ["name"]
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
order: [
|
order: [["updatedAt", "DESC"]]
|
||||||
['id', 'ASC']
|
|
||||||
]
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const hasMore = count > offset + tickets.length;
|
const hasMore = count > offset + tickets.length;
|
||||||
|
|
||||||
|
|
||||||
if (!tickets) {
|
if (!tickets) {
|
||||||
throw new AppError("ERR_NO_TICKET_FOUND", 404);
|
throw new AppError("ERR_NO_TICKET_FOUND", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {tickets, count, hasMore};
|
return { tickets, count, hasMore };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ShowTicketReport;
|
export default ShowTicketReport;
|
||||||
|
|
|
@ -200,7 +200,7 @@ const TicketsList = (props) => {
|
||||||
showAll,
|
showAll,
|
||||||
queueIds: JSON.stringify(selectedQueueIds),
|
queueIds: JSON.stringify(selectedQueueIds),
|
||||||
tab,
|
tab,
|
||||||
unlimited:"all"
|
unlimited: status === 'open' ? "all" : "false"
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -9,6 +9,10 @@ import PropTypes from 'prop-types'
|
||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
import { AuthContext } from "../../context/Auth/AuthContext"
|
import { AuthContext } from "../../context/Auth/AuthContext"
|
||||||
import { Can } from "../../components/Can"
|
import { Can } from "../../components/Can"
|
||||||
|
import FormControlLabel from "@mui/material/FormControlLabel"
|
||||||
|
import Checkbox from '@mui/material/Checkbox'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import { Button } from "@material-ui/core"
|
import { Button } from "@material-ui/core"
|
||||||
|
|
||||||
|
@ -25,6 +29,9 @@ import openSocket from "socket.io-client"
|
||||||
|
|
||||||
import { i18n } from "../../translate/i18n"
|
import { i18n } from "../../translate/i18n"
|
||||||
|
|
||||||
|
import Switch from '@mui/material/Switch'
|
||||||
|
|
||||||
|
const label = { inputProps: { 'aria-label': 'Size switch demo' } }
|
||||||
|
|
||||||
const report = [{ 'value': '1', 'label': 'Atendimento por atendentes' }, { 'value': '2', 'label': 'Usuários online/offline' }]
|
const report = [{ 'value': '1', 'label': 'Atendimento por atendentes' }, { 'value': '2', 'label': 'Usuários online/offline' }]
|
||||||
|
|
||||||
|
@ -48,9 +55,13 @@ const reducerQ = (state, action) => {
|
||||||
|
|
||||||
if (action.type === 'LOAD_QUERY') {
|
if (action.type === 'LOAD_QUERY') {
|
||||||
|
|
||||||
const queries = action.payload
|
let queries = action.payload
|
||||||
const newQueries = []
|
const newQueries = []
|
||||||
|
|
||||||
|
if (queries?.hasOwnProperty('usersProfile')) {
|
||||||
|
queries = queries.usersProfile
|
||||||
|
}
|
||||||
|
|
||||||
queries.forEach((query) => {
|
queries.forEach((query) => {
|
||||||
|
|
||||||
const queryIndex = state.findIndex((q) => q.id === query.id)
|
const queryIndex = state.findIndex((q) => q.id === query.id)
|
||||||
|
@ -282,6 +293,10 @@ const Report = () => {
|
||||||
|
|
||||||
const [onQueueStatus, setOnQueueProcessStatus] = useState(undefined)
|
const [onQueueStatus, setOnQueueProcessStatus] = useState(undefined)
|
||||||
const [csvFile, setCsvFile] = useState()
|
const [csvFile, setCsvFile] = useState()
|
||||||
|
const [selectedValue, setSelectedValue] = useState('created')
|
||||||
|
const [checked, setChecked] = useState(true)
|
||||||
|
const [queues, setQueues] = useState([])
|
||||||
|
const [queueId, setQueue] = useState(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch({ type: "RESET" })
|
dispatch({ type: "RESET" })
|
||||||
|
@ -332,22 +347,23 @@ const Report = () => {
|
||||||
|
|
||||||
// const { data } = await api.get("/reports/", { params: { userId: userId ? userId : 0, startDate: convertAndFormatDate(startDate), endDate: convertAndFormatDate(endDate), pageNumber: pageNumberTickets }, })
|
// const { data } = await api.get("/reports/", { params: { userId: userId ? userId : 0, startDate: convertAndFormatDate(startDate), endDate: convertAndFormatDate(endDate), pageNumber: pageNumberTickets }, })
|
||||||
|
|
||||||
const { data } = await api.get("/reports/", { params: { userId, startDate, endDate, pageNumber: pageNumberTickets }, userQueues: userA.queues})
|
const { data } = await api.get("/reports/", { params: { userId, startDate, endDate, pageNumber: pageNumberTickets, createdOrUpdated: selectedValue, queueId }, userQueues: userA.queues })
|
||||||
|
|
||||||
let ticketsQueue = data.tickets;
|
let ticketsQueue = data.tickets
|
||||||
let userQueues = userA.queues;
|
let userQueues = userA.queues
|
||||||
let filterQueuesTickets = [];
|
let filterQueuesTickets = []
|
||||||
if(userQueues.length > 1){
|
if (userQueues.length > 1) {
|
||||||
filterQueuesTickets = ticketsQueue.filter(ticket => userQueues.some(queue => queue?.name === ticket?.queue?.name));
|
filterQueuesTickets = ticketsQueue.filter(ticket => userQueues.some(queue => queue?.name === ticket?.queue?.name))
|
||||||
}else if(userQueues.length > 0) {
|
} else if (userQueues.length > 0) {
|
||||||
filterQueuesTickets = ticketsQueue.filter(ticket => ticket?.queue?.name === userQueues[0]?.name);
|
filterQueuesTickets = ticketsQueue.filter(ticket => ticket?.queue?.name === userQueues[0]?.name)
|
||||||
}
|
}
|
||||||
data.tickets = filterQueuesTickets;
|
data.tickets = filterQueuesTickets
|
||||||
dispatchQ({ type: "LOAD_QUERY", payload: data.tickets })
|
dispatchQ({ type: "LOAD_QUERY", payload: data.tickets })
|
||||||
|
|
||||||
setHasMore(data.hasMore)
|
setHasMore(data.hasMore)
|
||||||
setTotalCountTickets(data.count)
|
setTotalCountTickets(data.count)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
setQueues(data.queues)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -370,9 +386,13 @@ const Report = () => {
|
||||||
}, 500)
|
}, 500)
|
||||||
return () => clearTimeout(delayDebounceFn)
|
return () => clearTimeout(delayDebounceFn)
|
||||||
|
|
||||||
}, [userId, startDate, endDate, reportOption, pageNumberTickets, totalCountTickets])
|
}, [userId, queueId, checked, startDate, endDate, reportOption, pageNumberTickets, totalCountTickets, selectedValue])
|
||||||
|
|
||||||
|
|
||||||
|
const handleCheckBoxChange = (value) => {
|
||||||
|
setSelectedValue(value)
|
||||||
|
}
|
||||||
|
|
||||||
// Get from child 1
|
// Get from child 1
|
||||||
const datePicker1Value = (data) => {
|
const datePicker1Value = (data) => {
|
||||||
|
|
||||||
|
@ -387,18 +407,23 @@ const Report = () => {
|
||||||
|
|
||||||
// Get from child 3
|
// Get from child 3
|
||||||
const textFieldSelectUser = (data) => {
|
const textFieldSelectUser = (data) => {
|
||||||
|
setQueue(null)
|
||||||
setUser(data)
|
setUser(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const textFieldSelectQueue = (data) => {
|
||||||
|
setUser(0)
|
||||||
|
setQueue(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get from report option
|
// Get from report option
|
||||||
const reportValue = (data) => {
|
const reportValue = (data) => {
|
||||||
|
if(data === '2'){
|
||||||
|
setChecked(true)
|
||||||
|
}
|
||||||
setReport(data)
|
setReport(data)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -567,7 +592,7 @@ const Report = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}, [reportOption, startDate, endDate, userId, userA])
|
}, [reportOption, startDate, endDate, userId, queueId, checked, userA, selectedValue])
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -657,6 +682,10 @@ const Report = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const handleChange = (event) => {
|
||||||
|
setChecked(event.target.checked)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<Can
|
<Can
|
||||||
|
@ -665,16 +694,67 @@ const Report = () => {
|
||||||
yes={() => (
|
yes={() => (
|
||||||
|
|
||||||
<MainContainer>
|
<MainContainer>
|
||||||
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}>
|
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 2fr) repeat(2, 1fr)', gap: '8px' }}>
|
||||||
|
|
||||||
<Item><SelectField func={textFieldSelectUser} emptyField={true} header={i18n.t("reports.user")} currencies={users.map((obj) => {
|
<Box sx={{ display: 'flex', flexDirection: 'column', padding: '10px 0', alignItems: 'center', }}>
|
||||||
|
|
||||||
|
{checked ?
|
||||||
|
<SelectField
|
||||||
|
func={textFieldSelectUser}
|
||||||
|
emptyField={true}
|
||||||
|
header={i18n.t("reports.user")}
|
||||||
|
currencies={users.map((obj) => {
|
||||||
return { 'value': obj.id, 'label': obj.name }
|
return { 'value': obj.id, 'label': obj.name }
|
||||||
})} /></Item>
|
})} /> :
|
||||||
|
<SelectField
|
||||||
|
func={textFieldSelectQueue}
|
||||||
|
emptyField={true}
|
||||||
|
header={'Filas'}
|
||||||
|
currencies={queues.map((obj) => {
|
||||||
|
return { 'value': obj.id, 'label': obj.name }
|
||||||
|
})} />
|
||||||
|
}
|
||||||
|
|
||||||
<Item><DatePicker1 func={datePicker1Value} minDate={false} startEmpty={false} title={i18n.t("reports.dateStart")} /></Item>
|
{reportOption === '1' &&
|
||||||
<Item><DatePicker2 func={datePicker2Value} minDate={false} startEmpty={false} title={i18n.t("reports.dateEnd")} /></Item>
|
<div>
|
||||||
|
<label>
|
||||||
|
Filas
|
||||||
|
<Switch
|
||||||
|
checked={checked}
|
||||||
|
onChange={handleChange}
|
||||||
|
inputProps={{ 'aria-label': 'controlled' }}
|
||||||
|
/>
|
||||||
|
Usuarios
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
<Item sx={{ display: 'grid', gridColumn: '4 / 5', }}>
|
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
|
||||||
|
<DatePicker1 func={datePicker1Value} minDate={false} startEmpty={false} title={i18n.t("reports.dateStart")} />
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}><DatePicker2 func={datePicker2Value} minDate={false} startEmpty={false} title={i18n.t("reports.dateEnd")} /></Box>
|
||||||
|
|
||||||
|
{reportOption === '1' ?
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column', padding: '10px 0', }}>
|
||||||
|
<FormControlLabel
|
||||||
|
control={<Checkbox checked={selectedValue === 'created'} onChange={() => handleCheckBoxChange('created')} />}
|
||||||
|
label="Criado"
|
||||||
|
/>
|
||||||
|
<FormControlLabel
|
||||||
|
control={<Checkbox checked={selectedValue === 'updated'} onChange={() => handleCheckBoxChange('updated')} />}
|
||||||
|
label="Atualizado"
|
||||||
|
/>
|
||||||
|
</Box> :
|
||||||
|
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column', padding: '10px 0', }}>
|
||||||
|
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column', padding: '10px 0', gap: '8px', width: '100px', alignItems: 'center' }}>
|
||||||
|
|
||||||
<ReportModal currencies={reporList} func={reportValue} reportOption={reportOption} />
|
<ReportModal currencies={reporList} func={reportValue} reportOption={reportOption} />
|
||||||
|
|
||||||
|
@ -688,7 +768,7 @@ const Report = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</Item>
|
</Box>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
@ -701,16 +781,14 @@ const Report = () => {
|
||||||
{reportOption === '1' &&
|
{reportOption === '1' &&
|
||||||
|
|
||||||
<>
|
<>
|
||||||
|
|
||||||
<MTable data={query}
|
<MTable data={query}
|
||||||
columns={userA.profile !== 'supervisor' ?columnsData:columnsDataSuper}
|
columns={userA.profile !== 'supervisor' ? columnsData : columnsDataSuper}
|
||||||
hasChild={true}
|
hasChild={true}
|
||||||
removeClickRow={false}
|
removeClickRow={false}
|
||||||
|
|
||||||
handleScroll={handleScroll}
|
handleScroll={handleScroll}
|
||||||
|
|
||||||
table_title={i18n.t("reports.listTitles.title1_1")} />
|
table_title={i18n.t("reports.listTitles.title1_1")} />
|
||||||
|
|
||||||
</>
|
</>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue