Created
September 7, 2020 16:31
-
-
Save devmvrborges/070e831856aae8b1c1802a01abda9838 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Realiza o filtro nos valores e cria o resultado para envio por email | |
function Registros(){ | |
var ss = SpreadsheetApp.getActive(); | |
var sheet = ss.getSheetByName('Tarefas Agendadas'); | |
var startRow = 3; | |
var numRows = sheet.getLastRow(); | |
//variaveis pra auxiliar manutenção de colunas | |
var columnDate = 0; | |
var columnDescription = 1; | |
var columnValue = 2; | |
var columnSchedule = 3; | |
var columnPay = 4; | |
//variaveis de saída | |
var NaoAgendadas = []; | |
var NaoPagas = []; | |
//selecionando informações da planilha | |
var dataRange = sheet.getRange(startRow, 1, numRows, 5); | |
var data = dataRange.getValues(); | |
//filtro para os proximos 20 dias | |
var nextDays = 20; | |
var nextDate = new Date(new Date().setDate(new Date().getDate()+nextDays)); | |
//mes atual que está rodando o script | |
var currentMonth = new Date().getMonth(); | |
//proximos 20 dias que não foram agendadas | |
for(var i = 0; i<=data.length - startRow ;i++){ | |
if(data[i][columnSchedule] == false){ | |
if(data[i][columnDate] <= nextDate){ | |
NaoAgendadas+= RowBuilder(data[i][columnDate], data[i][columnDescription], data[i][columnValue]); | |
} | |
} | |
//no mes atual em que não foram pagas | |
if(currentMonth == new Date(data[i][columnDate]).getMonth()){ | |
if(data[i][columnPay] == false){ | |
NaoPagas+= RowBuilder(data[i][columnDate], data[i][columnDescription], data[i][columnValue]); | |
} | |
} | |
} | |
EnvioEmailResumoSemanal(NaoAgendadas, NaoPagas) | |
} | |
function EnvioEmailResumoSemanal(naoAgendadas, naoPagas) { | |
var ss = SpreadsheetApp.getActive(); | |
var sheet = ss.getSheetByName('Configuracoes'); | |
var range = sheet.getRange("B1"); | |
var emailAddress = range.getCell(1, 1).getValue(); | |
var subject = "[RESUMO]"; // Valor da coluna do assunto | |
if(naoPagas == ''){ | |
naoPagas = "Vazio!"; | |
} | |
if(naoAgendadas == ''){ | |
naoAgendadas = "Vazio!"; | |
} | |
var email_html = "<HTML><BODY>" | |
+ "<p><b> RESUMO SEMANAL</b></p><br>" | |
+ "<p><b> Contas não agendadas</b></p>" | |
+ "<p>" + naoAgendadas + "</p>" | |
+ "<p><b>Contas não agendadas </b></p>" | |
+ "<p>" + naoPagas + "</p>" | |
+ "</BODY></HTML>"; | |
MailApp.sendEmail( emailAddress, subject, '', {htmlBody : email_html}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment