Compare commits
No commits in common. "c4eda756ebf9766e67c387f95ded73391c276157" and "c9905eefb7653fd6cacf6a1508593512e8a3601f" have entirely different histories.
c4eda756eb
...
c9905eefb7
|
@ -4,19 +4,28 @@ 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";
|
||||||
|
|
||||||
|
@ -24,8 +33,6 @@ type IndexQuery = {
|
||||||
userId: string;
|
userId: string;
|
||||||
startDate: string;
|
startDate: string;
|
||||||
endDate: string;
|
endDate: string;
|
||||||
createdOrUpdated: string;
|
|
||||||
queueId: string;
|
|
||||||
pageNumber: string;
|
pageNumber: string;
|
||||||
userQueues: [];
|
userQueues: [];
|
||||||
};
|
};
|
||||||
|
@ -33,12 +40,11 @@ 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" &&
|
||||||
|
@ -47,53 +53,23 @@ export const reportUserByDateStartDateEnd = async (
|
||||||
throw new AppError("ERR_NO_PERMISSION", 403);
|
throw new AppError("ERR_NO_PERMISSION", 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const { userId, startDate, endDate, pageNumber, userQueues } = req.query as IndexQuery
|
||||||
userId,
|
|
||||||
startDate,
|
|
||||||
endDate,
|
|
||||||
pageNumber,
|
|
||||||
userQueues,
|
|
||||||
createdOrUpdated,
|
|
||||||
queueId
|
|
||||||
} = req.query as IndexQuery;
|
|
||||||
|
|
||||||
console.log(
|
console.log("userId, startDate, endDate, pageNumber: ", userId, startDate, endDate, pageNumber);
|
||||||
"userId, startDate, endDate, pageNumber, userQueues, createdOrUpdated, queueId: ",
|
|
||||||
userId,
|
|
||||||
startDate,
|
|
||||||
endDate,
|
|
||||||
pageNumber,
|
|
||||||
userQueues,
|
|
||||||
createdOrUpdated,
|
|
||||||
queueId
|
|
||||||
);
|
|
||||||
|
|
||||||
const { tickets, count, hasMore } = await ShowTicketReport({
|
const { tickets, count, hasMore } = await ShowTicketReport({ userId, startDate, endDate, pageNumber });
|
||||||
userId,
|
// console.log('kkkkkkkkkkkkkkkkkk tickets: ', JSON.stringify(tickets, null, 6))
|
||||||
startDate,
|
|
||||||
endDate,
|
|
||||||
pageNumber,
|
|
||||||
createdOrUpdated,
|
|
||||||
queueId
|
|
||||||
});
|
|
||||||
|
|
||||||
const queues = await Queue.findAll({ attributes: ["id", "name"] });
|
return res.status(200).json({ tickets, count, hasMore });
|
||||||
|
|
||||||
return res.status(200).json({ tickets, count, hasMore, queues });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const reportUserService = async (
|
|
||||||
req: Request,
|
export const reportUserService = async (req: Request, res: Response): Promise<Response> => {
|
||||||
res: Response
|
|
||||||
): Promise<Response> => {
|
if (req.user.profile !== "master" && req.user.profile !== "admin" && req.user.profile !=="supervisor") {
|
||||||
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({
|
||||||
|
@ -101,89 +77,55 @@ export const reportUserService = async (
|
||||||
raw: true
|
raw: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const sumUserOlineTime = await ShowUserServiceReport({
|
const sumUserOlineTime = await ShowUserServiceReport({ startDate, endDate, userId });
|
||||||
startDate,
|
const closedByUser = await ShowUserServiceReport({ startDate, endDate, ticketStatus: 'closed', userId });
|
||||||
endDate,
|
const openByUser = await ShowUserServiceReport({ startDate, endDate, ticketStatus: 'open', userId });
|
||||||
userId
|
|
||||||
});
|
|
||||||
const closedByUser = await ShowUserServiceReport({
|
|
||||||
startDate,
|
|
||||||
endDate,
|
|
||||||
ticketStatus: "closed",
|
|
||||||
userId
|
|
||||||
});
|
|
||||||
const openByUser = await ShowUserServiceReport({
|
|
||||||
startDate,
|
|
||||||
endDate,
|
|
||||||
ticketStatus: "open",
|
|
||||||
userId
|
|
||||||
});
|
|
||||||
|
|
||||||
let dateTime = splitDateTime(
|
let dateTime = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
||||||
new Date(format(new Date(), "yyyy-MM-dd HH:mm:ss", { locale: ptBR }))
|
const onlineUsers = await ListUserOnlineOffline({ date: dateTime.fullDate })
|
||||||
);
|
|
||||||
const onlineUsers = await ListUserOnlineOffline({ date: dateTime.fullDate });
|
|
||||||
|
|
||||||
const openByUserOnQueue = await CountTicketsByUserQueue({
|
const openByUserOnQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'open', clientChatStart: true })
|
||||||
startDate: startDate,
|
const openByUserOutQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'open', clientChatStart: false })
|
||||||
endDate: endDate,
|
|
||||||
status: "open",
|
|
||||||
clientChatStart: true
|
|
||||||
});
|
|
||||||
const openByUserOutQueue = await CountTicketsByUserQueue({
|
|
||||||
startDate: startDate,
|
|
||||||
endDate: endDate,
|
|
||||||
status: "open",
|
|
||||||
clientChatStart: false
|
|
||||||
});
|
|
||||||
|
|
||||||
const closedByUserOnQueue = await CountTicketsByUserQueue({
|
const closedByUserOnQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'closed', clientChatStart: true })
|
||||||
startDate: startDate,
|
const closedUserOutQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'closed', clientChatStart: false })
|
||||||
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" });
|
|
||||||
|
|
||||||
let openCloseOnQueue = openByUserOnQueue.concat(closedByUserOnQueue);
|
const queuesByUser = await ShowQueuesByUser({ profile: 'user' })
|
||||||
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].countClosed = 0;
|
queuesByUser[i].countOpen = 0
|
||||||
|
queuesByUser[i].countClosed = 0
|
||||||
|
|
||||||
for (let x = 0; x < openCloseOnQueue.length; x++) {
|
for (let x = 0; x < openCloseOnQueue.length; x++) {
|
||||||
if (
|
if ((queuesByUser[i].userId == openCloseOnQueue[x].userId) &&
|
||||||
queuesByUser[i].userId == openCloseOnQueue[x].userId &&
|
(queuesByUser[i].queueId == openCloseOnQueue[x].queueId && openCloseOnQueue[x].status == 'open')) {
|
||||||
queuesByUser[i].queueId == openCloseOnQueue[x].queueId &&
|
queuesByUser[i].countOpen = openCloseOnQueue[x].totAttendance
|
||||||
openCloseOnQueue[x].status == "open"
|
|
||||||
) {
|
|
||||||
queuesByUser[i].countOpen = 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;
|
|
||||||
}
|
}
|
||||||
|
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];
|
||||||
|
@ -191,67 +133,68 @@ export const reportUserService = async (
|
||||||
// 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(
|
let open = openCloseOutQueue.filter((e) => e.userId == user.id && e.status == 'open')
|
||||||
e => e.userId == user.id && e.status == "open"
|
let closed = openCloseOutQueue.filter((e) => e.userId == user.id && e.status == 'closed')
|
||||||
);
|
|
||||||
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,
|
|
||||||
res: Response
|
export const reportMessagesUserByDateStartDateEnd = async (req: Request, res: Response): Promise<Response> => {
|
||||||
): Promise<Response> => {
|
|
||||||
if (
|
if (
|
||||||
req.user.profile !== "master" &&
|
req.user.profile !== "master" &&
|
||||||
req.user.profile !== "admin" &&
|
req.user.profile !== "admin" &&
|
||||||
|
@ -260,32 +203,35 @@ export const reportMessagesUserByDateStartDateEnd = async (
|
||||||
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 {
|
}
|
||||||
data_query_messages[i].fromMe = "Cliente";
|
else {
|
||||||
|
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,
|
|
||||||
res: Response
|
export const reportOnQueue = async (req: Request, res: Response): Promise<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", {
|
||||||
|
@ -298,5 +244,10 @@ export const reportOnQueue = async (
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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,11 +20,10 @@ 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;
|
||||||
|
@ -36,137 +35,89 @@ 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 = {};
|
|
||||||
|
|
||||||
if (userId == "0") {
|
let where_clause = {}
|
||||||
if (createdOrUpdated == "updated") {
|
|
||||||
where_clause = {
|
|
||||||
updatedAt: {
|
|
||||||
[Op.gte]: startDate + " 00:00:00.000000",
|
|
||||||
[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"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queueId) {
|
if(userId=='0'){
|
||||||
where_clause = { ...where_clause, queueId };
|
where_clause = {
|
||||||
}
|
updatedAt: {
|
||||||
} else {
|
[Op.gte]: startDate+' 00:00:00.000000',
|
||||||
if (createdOrUpdated == "updated") {
|
[Op.lte]: endDate +' 23:59:59.999999'
|
||||||
where_clause = {
|
},
|
||||||
userid: userId,
|
|
||||||
updatedAt: {
|
|
||||||
[Op.gte]: startDate + " 00:00:00.000000",
|
|
||||||
[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"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
where_clause = {
|
||||||
|
userid: userId,
|
||||||
|
updatedAt: {
|
||||||
|
[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: [
|
attributes: ['id', 'status', 'statusChatEnd', [Sequelize.fn("DATE_FORMAT",Sequelize.col("Ticket.createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"],
|
||||||
"id",
|
[Sequelize.fn("DATE_FORMAT",Sequelize.col("Ticket.updatedAt"),"%d/%m/%Y %H:%i:%s"),"updatedAt"]],
|
||||||
"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: [
|
attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl', [Sequelize.fn("DATE_FORMAT",Sequelize.col("createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"]],
|
||||||
"body",
|
|
||||||
"read",
|
|
||||||
"mediaType",
|
|
||||||
"fromMe",
|
|
||||||
"mediaUrl",
|
|
||||||
[
|
|
||||||
Sequelize.fn(
|
|
||||||
"DATE_FORMAT",
|
|
||||||
Sequelize.col("createdAt"),
|
|
||||||
"%d/%m/%Y %H:%i:%s"
|
|
||||||
),
|
|
||||||
"createdAt"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
|
|
||||||
order: [["createdAt", "ASC"]]
|
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: [["updatedAt", "DESC"]]
|
order: [
|
||||||
|
['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: status === 'open' ? "all" : "false"
|
unlimited:"all"
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -9,10 +9,6 @@ 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"
|
||||||
|
|
||||||
|
@ -29,9 +25,6 @@ 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' }]
|
||||||
|
|
||||||
|
@ -55,13 +48,9 @@ const reducerQ = (state, action) => {
|
||||||
|
|
||||||
if (action.type === 'LOAD_QUERY') {
|
if (action.type === 'LOAD_QUERY') {
|
||||||
|
|
||||||
let queries = action.payload
|
const 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)
|
||||||
|
@ -293,10 +282,6 @@ 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" })
|
||||||
|
@ -347,23 +332,22 @@ 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, createdOrUpdated: selectedValue, queueId }, userQueues: userA.queues })
|
const { data } = await api.get("/reports/", { params: { userId, startDate, endDate, pageNumber: pageNumberTickets }, 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)
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -386,13 +370,9 @@ const Report = () => {
|
||||||
}, 500)
|
}, 500)
|
||||||
return () => clearTimeout(delayDebounceFn)
|
return () => clearTimeout(delayDebounceFn)
|
||||||
|
|
||||||
}, [userId, queueId, checked, startDate, endDate, reportOption, pageNumberTickets, totalCountTickets, selectedValue])
|
}, [userId, startDate, endDate, reportOption, pageNumberTickets, totalCountTickets])
|
||||||
|
|
||||||
|
|
||||||
const handleCheckBoxChange = (value) => {
|
|
||||||
setSelectedValue(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get from child 1
|
// Get from child 1
|
||||||
const datePicker1Value = (data) => {
|
const datePicker1Value = (data) => {
|
||||||
|
|
||||||
|
@ -407,23 +387,18 @@ 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(() => {
|
||||||
|
@ -592,7 +567,7 @@ const Report = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}, [reportOption, startDate, endDate, userId, queueId, checked, userA, selectedValue])
|
}, [reportOption, startDate, endDate, userId, userA])
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -682,10 +657,6 @@ const Report = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const handleChange = (event) => {
|
|
||||||
setChecked(event.target.checked)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<Can
|
<Can
|
||||||
|
@ -694,67 +665,16 @@ const Report = () => {
|
||||||
yes={() => (
|
yes={() => (
|
||||||
|
|
||||||
<MainContainer>
|
<MainContainer>
|
||||||
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 2fr) repeat(2, 1fr)', gap: '8px' }}>
|
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}>
|
||||||
|
|
||||||
<Box sx={{ display: 'flex', flexDirection: 'column', padding: '10px 0', alignItems: 'center', }}>
|
<Item><SelectField func={textFieldSelectUser} emptyField={true} header={i18n.t("reports.user")} currencies={users.map((obj) => {
|
||||||
|
return { 'value': obj.id, 'label': obj.name }
|
||||||
|
})} /></Item>
|
||||||
|
|
||||||
{checked ?
|
<Item><DatePicker1 func={datePicker1Value} minDate={false} startEmpty={false} title={i18n.t("reports.dateStart")} /></Item>
|
||||||
<SelectField
|
<Item><DatePicker2 func={datePicker2Value} minDate={false} startEmpty={false} title={i18n.t("reports.dateEnd")} /></Item>
|
||||||
func={textFieldSelectUser}
|
|
||||||
emptyField={true}
|
|
||||||
header={i18n.t("reports.user")}
|
|
||||||
currencies={users.map((obj) => {
|
|
||||||
return { 'value': obj.id, 'label': obj.name }
|
|
||||||
})} /> :
|
|
||||||
<SelectField
|
|
||||||
func={textFieldSelectQueue}
|
|
||||||
emptyField={true}
|
|
||||||
header={'Filas'}
|
|
||||||
currencies={queues.map((obj) => {
|
|
||||||
return { 'value': obj.id, 'label': obj.name }
|
|
||||||
})} />
|
|
||||||
}
|
|
||||||
|
|
||||||
{reportOption === '1' &&
|
<Item sx={{ display: 'grid', gridColumn: '4 / 5', }}>
|
||||||
<div>
|
|
||||||
<label>
|
|
||||||
Filas
|
|
||||||
<Switch
|
|
||||||
checked={checked}
|
|
||||||
onChange={handleChange}
|
|
||||||
inputProps={{ 'aria-label': 'controlled' }}
|
|
||||||
/>
|
|
||||||
Usuarios
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
</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} />
|
||||||
|
|
||||||
|
@ -768,7 +688,7 @@ const Report = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</Box>
|
</Item>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
@ -781,14 +701,16 @@ 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