TopSapp: alteração do ver faturas
Signed-off-by: Rodrigo Bertoldo de Sousa Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
929293d174
commit
ad874dd607
2 files changed
+59
-6
No files matched your search
+51
-5
@@ -1495,6 +1495,9 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
} else if (data.startsWith('faturas_cliente_')) {
|
} else if (data.startsWith('faturas_cliente_')) {
|
||||||
console.log(`🔍 Condição faturas_cliente_ atendida`);
|
console.log(`🔍 Condição faturas_cliente_ atendida`);
|
||||||
await this.handleFaturasClienteCallback(callbackQuery, data);
|
await this.handleFaturasClienteCallback(callbackQuery, data);
|
||||||
|
} else if (data.startsWith('faturas_servico_')) {
|
||||||
|
console.log(`🔍 Condição faturas_servico_ atendida`);
|
||||||
|
await this.handleFaturasServicoCallback(callbackQuery, data);
|
||||||
} else if (data.startsWith('servicos_cliente_')) {
|
} else if (data.startsWith('servicos_cliente_')) {
|
||||||
console.log(`🔍 Condição servicos_cliente_ atendida`);
|
console.log(`🔍 Condição servicos_cliente_ atendida`);
|
||||||
await this.handleServicosClienteCallback(callbackQuery, data);
|
await this.handleServicosClienteCallback(callbackQuery, data);
|
||||||
@@ -4062,7 +4065,7 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
/**
|
/**
|
||||||
* Ver faturas do cliente
|
* Ver faturas do cliente
|
||||||
*/
|
*/
|
||||||
async handleVerFaturas(chatId, targetOrId, location = '') {
|
async handleVerFaturas(chatId, targetOrId, location = '', idServicoFilter = null) {
|
||||||
try {
|
try {
|
||||||
let idCliente = targetOrId;
|
let idCliente = targetOrId;
|
||||||
|
|
||||||
@@ -4098,7 +4101,7 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const faturasPorServico = resultado.faturasPorServico || [];
|
let faturasPorServico = resultado.faturasPorServico || [];
|
||||||
|
|
||||||
if (faturasPorServico.length === 0) {
|
if (faturasPorServico.length === 0) {
|
||||||
await this.bot.sendMessage(chatId,
|
await this.bot.sendMessage(chatId,
|
||||||
@@ -4109,6 +4112,33 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Se há mais de um serviço com faturas e nenhum filtro foi aplicado,
|
||||||
|
// perguntar qual serviço o usuário quer ver
|
||||||
|
if (faturasPorServico.length > 1 && !idServicoFilter) {
|
||||||
|
let message = `📄 **SELECIONE O SERVIÇO**\n\n`;
|
||||||
|
message += `🆔 **ID Cliente**: ${idCliente}\n`;
|
||||||
|
message += `📊 Este cliente possui **${faturasPorServico.length} serviços** com faturas.\n\n`;
|
||||||
|
message += `Escolha qual serviço deseja ver as faturas:`;
|
||||||
|
|
||||||
|
const keyboard = faturasPorServico.map((servicoInfo) => [{
|
||||||
|
text: `📋 ${servicoInfo.servico.nome || servicoInfo.servico.descricao || 'Serviço'} — ${servicoInfo.faturas.length} fatura(s)`,
|
||||||
|
callback_data: `faturas_servico_${idCliente}_${servicoInfo.servico.id}_${location}`
|
||||||
|
}]);
|
||||||
|
|
||||||
|
await this.bot.sendMessage(chatId, message, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_markup: { inline_keyboard: keyboard }
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filtrar pelo serviço selecionado, se houver
|
||||||
|
if (idServicoFilter) {
|
||||||
|
faturasPorServico = faturasPorServico.filter(
|
||||||
|
s => String(s.servico.id) === String(idServicoFilter)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Contar total de faturas
|
// Contar total de faturas
|
||||||
let totalFaturas = 0;
|
let totalFaturas = 0;
|
||||||
faturasPorServico.forEach(s => {
|
faturasPorServico.forEach(s => {
|
||||||
@@ -4121,7 +4151,7 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
|
|
||||||
faturasPorServico.forEach((servicoInfo, sIndex) => {
|
faturasPorServico.forEach((servicoInfo, sIndex) => {
|
||||||
if (servicoInfo.faturas.length > 0) {
|
if (servicoInfo.faturas.length > 0) {
|
||||||
message += `📋 **Serviço**: ${servicoInfo.servico.descricao || 'Serviço'}\n`;
|
message += `📋 **Serviço**: ${servicoInfo.servico.nome || servicoInfo.servico.descricao || 'Serviço'}\n`;
|
||||||
message += `🆔 **ID**: ${servicoInfo.servico.id}\n\n`;
|
message += `🆔 **ID**: ${servicoInfo.servico.id}\n\n`;
|
||||||
|
|
||||||
servicoInfo.faturas.forEach((fatura, fIndex) => {
|
servicoInfo.faturas.forEach((fatura, fIndex) => {
|
||||||
@@ -4157,23 +4187,25 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Criar botões para cada fatura com linha digitável/PIX
|
// Criar botões para cada fatura com linha digitável/PIX
|
||||||
|
// Inclui a data de vencimento para melhor identificação
|
||||||
const keyboard = [];
|
const keyboard = [];
|
||||||
|
|
||||||
faturasPorServico.forEach((servicoInfo) => {
|
faturasPorServico.forEach((servicoInfo) => {
|
||||||
servicoInfo.faturas.forEach((fatura) => {
|
servicoInfo.faturas.forEach((fatura) => {
|
||||||
if (fatura.status !== 'Pago') {
|
if (fatura.status !== 'Pago') {
|
||||||
|
const vencLabel = fatura.vencimento ? ` (${fatura.vencimento})` : '';
|
||||||
const row = [];
|
const row = [];
|
||||||
|
|
||||||
if (fatura.linhaDigitavel) {
|
if (fatura.linhaDigitavel) {
|
||||||
row.push({
|
row.push({
|
||||||
text: `📋 Linha Digitável #${fatura.id}`,
|
text: `📋 Linha Digitável #${fatura.id}${vencLabel}`,
|
||||||
callback_data: `linha_${fatura.id}_${location}`
|
callback_data: `linha_${fatura.id}_${location}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fatura.pixCopiaCola) {
|
if (fatura.pixCopiaCola) {
|
||||||
row.push({
|
row.push({
|
||||||
text: `💳 PIX #${fatura.id}`,
|
text: `💳 PIX #${fatura.id}${vencLabel}`,
|
||||||
callback_data: `pix_${fatura.id}_${location}`
|
callback_data: `pix_${fatura.id}_${location}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -4511,6 +4543,20 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
await this.handleVerFaturas(chatId, idCliente, location);
|
await this.handleVerFaturas(chatId, idCliente, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback para selecionar serviço específico ao ver faturas
|
||||||
|
*/
|
||||||
|
async handleFaturasServicoCallback(callbackQuery, data) {
|
||||||
|
const chatId = callbackQuery.message.chat.id;
|
||||||
|
const parts = data.replace('faturas_servico_', '').split('_');
|
||||||
|
const idCliente = parts[0];
|
||||||
|
const idServico = parts[1];
|
||||||
|
const location = parts.slice(2).join('_');
|
||||||
|
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||||
|
await this.handleVerFaturas(chatId, idCliente, location, idServico);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback para serviços do cliente
|
* Callback para serviços do cliente
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -189,10 +189,17 @@ class NLPProcessor {
|
|||||||
// Detectar comandos TopSapp - ver faturas
|
// Detectar comandos TopSapp - ver faturas
|
||||||
if (/ver|mostrar/i.test(action) && /faturas?|boletos?|contas?/i.test(fullMatch)) {
|
if (/ver|mostrar/i.test(action) && /faturas?|boletos?|contas?/i.test(fullMatch)) {
|
||||||
let query = match[3] || match[2]; // ID/CPF do cliente
|
let query = match[3] || match[2]; // ID/CPF do cliente
|
||||||
|
if (query) {
|
||||||
|
query = query.trim();
|
||||||
|
// Converter CPF sem formatação (11 dígitos) para formato XXX.XXX.XXX-XX
|
||||||
|
if (/^\d{11}$/.test(query)) {
|
||||||
|
query = `${query.slice(0,3)}.${query.slice(3,6)}.${query.slice(6,9)}-${query.slice(9,11)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
action: 'ver_faturas',
|
action: 'ver_faturas',
|
||||||
target: query ? query.trim() : null,
|
target: query || null,
|
||||||
confidence: 0.95,
|
confidence: 0.95,
|
||||||
type: 'topsapp_faturas_pattern'
|
type: 'topsapp_faturas_pattern'
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user