Added SQL, dao and app - not functional
This commit is contained in:
692
functions/calc.js
Normal file
692
functions/calc.js
Normal file
@@ -0,0 +1,692 @@
|
||||
// TODO: extract all CONTANTS TO EASILY CHANGE CELLS
|
||||
|
||||
const planilhaID= "13sLipAAD5LkzZK19iuzgscbCmODiS11hJDRgaNsnYvw";
|
||||
|
||||
// LOCAIS DE LIMPEZA \/\/\/\/
|
||||
const cotas = 'B5:E40' ;
|
||||
const contribuintes = 'B43:E57' ;
|
||||
const brochuras = 'B60:D65';
|
||||
const campanha = 'B68:D84' ;
|
||||
const outras = 'B87:D94';
|
||||
const assinantes = 'B97:D109';
|
||||
const jornal = 'B112:D126';
|
||||
const despesaCE = 'D129';
|
||||
const depositos = 'B134:F251' ;
|
||||
const carimbo = 'Q287' ;
|
||||
// ACABOU :LOCAIS DE LIMPEZA /\/\/\/\
|
||||
|
||||
const contagemRF='E2';
|
||||
const celulaPrincipal = 'A1' ;
|
||||
|
||||
const enddepositos = 'D252';
|
||||
const endvendas = 'D130' ;
|
||||
|
||||
const celulaValorTotalCotas = 'E41';
|
||||
|
||||
const timeZone = Session.getScriptTimeZone();
|
||||
|
||||
const CRSP = "crsptesouraria@gmail.com";
|
||||
const areaAProteger = 'A1:Y999' ;
|
||||
|
||||
function getUser(){ return Session.getEffectiveUser();}
|
||||
|
||||
function voltaAoTopo(){
|
||||
SpreadsheetApp.getActiveSheet().setCurrentCell(SpreadsheetApp.getActiveSheet().getRange(celulaPrincipal)) ;
|
||||
|
||||
}
|
||||
|
||||
function onOpen() {
|
||||
var ui = SpreadsheetApp.getUi();
|
||||
ui.createMenu('CR')
|
||||
.addItem('Enviar RF', 'menuItem1')
|
||||
.addItem('Totalizar Cotas', 'menuItem2')
|
||||
.addItem('Teste - Não usar', 'menuItem3')
|
||||
.addToUi();
|
||||
}
|
||||
|
||||
/// MENU ITEMS
|
||||
function menuItem1() {
|
||||
SpreadsheetApp.getUi()
|
||||
{
|
||||
Logger.log(getUser());
|
||||
resultado = enviaCR();
|
||||
Logger.log("Resultado: " + resultado + ".");
|
||||
}
|
||||
}
|
||||
|
||||
function menuItem2() {
|
||||
SpreadsheetApp.getUi()
|
||||
{
|
||||
Logger.log(getUser());
|
||||
resultado = totalizar(curName)
|
||||
Logger.log("Resultado: " + resultado + ".");
|
||||
}
|
||||
}
|
||||
|
||||
function menuItem3() {
|
||||
SpreadsheetApp.getUi()
|
||||
{
|
||||
Logger.log(getUser());
|
||||
carimboValue = pegarCarimbo(SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()) ;
|
||||
if(!isNaN(parseFloat(carimboValue)) ) {
|
||||
var mesAtual = Utilities.formatDate(carimboValue,timeZone, "MM");
|
||||
Logger.log("Carimbo lido: " + mesAtual + ".");
|
||||
}
|
||||
else {
|
||||
mesAtual = Utilities.formatDate(new Date(),timeZone, "MM") ;
|
||||
Logger.log("Carimbo vazio, mês atual: " + mesAtual + ".");
|
||||
}
|
||||
|
||||
voltaAoTopo();
|
||||
}
|
||||
}
|
||||
/// FUNCTIONS BELOW
|
||||
|
||||
|
||||
|
||||
/// SEND RF
|
||||
function enviaCR() {
|
||||
var ss = SpreadsheetApp.getActiveSpreadsheet(); // cria o objeto do arquivo da planilha
|
||||
var sheet = ss.getActiveSheet(); // cria objeto da Sheet ativa agora
|
||||
var curName = ss.getActiveSheet().getName() ; // pega nome da Sheet
|
||||
|
||||
// validar contas
|
||||
if (validar(sheet))
|
||||
{
|
||||
// subir dados na planilha de controle
|
||||
var resultadoEnvio = enviando(curName,sheet,ss);
|
||||
if (resultadoEnvio == "Enviado" )
|
||||
{SpreadsheetApp.getUi().alert('Relatório Enviado!');}
|
||||
else
|
||||
{SpreadsheetApp.getUi().alert('ERRO: ' + resultadoEnvio );}
|
||||
} return resultadoEnvio;
|
||||
}
|
||||
|
||||
|
||||
// VALIDAR VALORES TODO: ADIOCIONAR NOVAS
|
||||
function validar(sheet){
|
||||
// trocar vendas por centralizado
|
||||
var celulaDepositos = sheet.getRange(enddepositos);
|
||||
var depositos = sheet.setCurrentCell(celulaDepositos).getValue();
|
||||
var celulaVendas = sheet.getRange(endvendas);
|
||||
var vendas = sheet.setCurrentCell(celulaVendas).getValue();
|
||||
if ( vendas === depositos )
|
||||
{ return true;}
|
||||
else
|
||||
{ SpreadsheetApp.getUi().alert('Centralizado ' + vendas + ' não bate com Depósitos ' + depositos ); return false ;}
|
||||
}
|
||||
|
||||
|
||||
function enviando(curName,sheet,ss) {
|
||||
valorCotas = pegarTotalCota(curName, ss); // TOTAL das cotas
|
||||
marcaCarimbos(curName, valorCotas, sheet); // SALVA TOTAL DAS COTAS ETC
|
||||
novaAba = renomearAba(curName, ss); // Renomeia Aba e coloca nomero da nova aba no numero do relatorio
|
||||
limpaEntradas(novaAba) ; // limpa carimbo e entradas
|
||||
|
||||
if (travar(curName, ss) === "Travada"){
|
||||
ss.setActiveSheet(novaAba); // coloca novo em evidencia
|
||||
return "Enviado";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function pegarTotalCota(curName, ss){
|
||||
var sheet = ss.getSheetByName(curName);
|
||||
var valorNovaAvulso = Number(sheet.setCurrentCell(sheet.getRange(celulaValorTotalCotas)).getValue());
|
||||
Logger.log(" valorNovaAvulso: " + valorNovaAvulso + ".");
|
||||
return valorNovaAvulso;
|
||||
}
|
||||
|
||||
function marcaCarimbos(curName,totalCota,sheet){
|
||||
var gravarTempo = Utilities.formatDate(new Date(),timeZone, "yyyyMMddHHmmssSSS");
|
||||
var celulaTempo = 'D900';
|
||||
var celulaTotalCotas = 'D901';
|
||||
var celulaResponsavel = 'D902';
|
||||
var celulaNomeContagem = 'D902';
|
||||
var celulaResponsavelCel = 'H2';
|
||||
var username = getUser();
|
||||
sheet.setCurrentCell(sheet.getRange(celulaTempo)).setValue(gravarTempo);
|
||||
sheet.setCurrentCell(sheet.getRange(celulaResponsavel)).setValue(username);
|
||||
sheet.setCurrentCell(sheet.getRange(celulaNomeContagem)).setValue(curName);
|
||||
sheet.setCurrentCell(sheet.getRange(celulaResponsavelCel)).setValue(username);
|
||||
sheet.setCurrentCell(sheet.getRange(celulaTotalCotas)).setValue(totalCota);
|
||||
|
||||
}
|
||||
|
||||
function pegarCarimbo(sheet)
|
||||
{
|
||||
new Date(sheet.setCurrentCell(sheet.getRange(carimbo)).getValue())
|
||||
}
|
||||
|
||||
|
||||
function renomearAba(curName,ss){
|
||||
|
||||
var newName = Number(curName) + 1 ; // cria nome da nova
|
||||
ss.moveActiveSheet(ss.getNumSheets() - 1); // move a atual para a ultima posicao antes da Validacao que é escondida
|
||||
ss.duplicateActiveSheet(); // duplica ativa
|
||||
ss.renameActiveSheet(newName); // renomeia nova
|
||||
ss.moveActiveSheet(1); // move para a primeira posicao
|
||||
var sheet = ss.getSheetByName(newName); // torna a nova ativa usando nome
|
||||
sheet.getRange(contagemRF).setValue(newName); //altera contagem do relatorio usando numero da aba
|
||||
return sheet;
|
||||
}
|
||||
|
||||
function limpaEntradas(sheet)
|
||||
{
|
||||
function limpaTudo(value){
|
||||
sheet.getRange(value).clearContent();
|
||||
}
|
||||
var limpeza = [ cotas, contribuintes, brochuras, campanha , outras, assinantes, jornal , despesaCE, depositos, carimbo ];
|
||||
limpeza.forEach(limpaTudo) ;
|
||||
|
||||
let range = sheet.getRange("I:Y");
|
||||
sheet.hideColumn(range);
|
||||
range = sheet.getRange("A258:A999");
|
||||
sheet.hideRow(range);
|
||||
|
||||
SpreadsheetApp.getActiveSheet().setCurrentCell(SpreadsheetApp.getActiveSheet().getRange(celulaPrincipal)) ;
|
||||
|
||||
}
|
||||
|
||||
function travar(curName, ss){
|
||||
var sheet = ss.getSheetByName(curName);
|
||||
var areaProtegida = false ;
|
||||
var abaProtegida = false ;
|
||||
var userName = getUser();
|
||||
var protections = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET);
|
||||
|
||||
for (var i = 0; i < protections.length; i++) {
|
||||
var desc = protections[i].getDescription();
|
||||
Logger.log("protection desc: " + desc);
|
||||
if ( desc === 'Area protegida' ){ areaProtegida = true ; }
|
||||
if ( desc === 'Aba protegida') { abaProtegida = true ; }
|
||||
}
|
||||
|
||||
|
||||
// Protege area, e remove todos da lista de editores.
|
||||
var range = sheet.getRange(areaAProteger);
|
||||
|
||||
if (areaProtegida === false && userName != CRSP ) {
|
||||
proteRange = range.protect().setDescription('Area protegida') ;
|
||||
areaProtegida = true ;
|
||||
proteRange.removeEditor(userName);
|
||||
if (proteRange.canDomainEdit()) {
|
||||
proteRange.setDomainEdit(false);
|
||||
}
|
||||
}
|
||||
|
||||
Logger.log(userName);
|
||||
|
||||
if (abaProtegida === false && userName != CRSP ) {
|
||||
var proteSheet = sheet.protect().setDescription('Aba protegida');
|
||||
abaProtegida = true ;
|
||||
Logger.log("Removendo: " + userName);
|
||||
proteSheet.removeEditor(userName);
|
||||
if (proteSheet.canDomainEdit()) {
|
||||
proteSheet.setDomainEdit(false);
|
||||
}
|
||||
|
||||
}
|
||||
if (abaProtegida === true && areaProtegida === true ) { return "Travada" ;}
|
||||
}
|
||||
|
||||
function efetuarRotinaMadrugada(){
|
||||
travaNoturna();
|
||||
totalizar();
|
||||
}
|
||||
|
||||
function travaNoturna(){
|
||||
var ss = SpreadsheetApp.openById(planilhaID);
|
||||
var trava = 0 ;
|
||||
console.log( getUser());
|
||||
|
||||
// Protects the sheet.
|
||||
const sampleProtectedSheet = sheet.protect();
|
||||
// Logs whether domain users have permission to edit the protected sheet to the console.
|
||||
console.log(sampleProtectedSheet.canDomainEdit());
|
||||
|
||||
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
|
||||
for (var cadaSheet = 0 ; cadaSheet < sheets.length ; cadaSheet++){
|
||||
var nomeSheet = sheets[cadaSheet].getName();
|
||||
Logger.log(" TravaNoturna nomeSheet: " + nomeSheet);
|
||||
if (!isNaN(parseFloat(nomeSheet)) && isFinite(nomeSheet) && nomeSheet === anterior) {
|
||||
SpreadsheetApp.setActiveSheet(sheets[cadaSheet]);
|
||||
var protections = sheets[cadaSheet].getProtections(SpreadsheetApp.ProtectionType.SHEET);
|
||||
for (var i = 0; i < protections.length; i++) {
|
||||
var desc = protections[i].getDescription();
|
||||
Logger.log("trava desc: " + desc);
|
||||
if ( desc === 'Area protegida' || desc === 'Aba protegida' ) {
|
||||
trava = trava + 1 ;
|
||||
}
|
||||
}
|
||||
if ( trava == 2 ){
|
||||
const protection = sheets[cadaSheet].protect();
|
||||
// Logs whether domain users have permission to edit the protected sheet to the console.
|
||||
console.log(protection.canDomainEdit());
|
||||
protection.removeEditors(protection.getEditors());
|
||||
if (protection.canDomainEdit()) {
|
||||
protection.setDomainEdit(false);
|
||||
}
|
||||
console.log(protection.canDomainEdit());
|
||||
protection.setDescription('Trava Noturna');
|
||||
}
|
||||
}
|
||||
var sheet = ss.getSheetByName(anterior);
|
||||
sheet.setCurrentCell(sheet.getRange(celulaPrincipal)) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function totalizar(curName){
|
||||
var anterior = curName ;
|
||||
Logger.log("anterior: " + anterior + ".");
|
||||
|
||||
var ss = SpreadsheetApp.getActiveSpreadsheet() ;
|
||||
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
|
||||
var gravou = 0;
|
||||
|
||||
function enviarTotal() {
|
||||
var sheet = ss.getSheetByName(anterior);
|
||||
|
||||
var brochuras = sheet.setCurrentCell(sheet.getRange('D66')).getValue() ;
|
||||
var campanha = sheet.setCurrentCell(sheet.getRange('D71')).getValue();
|
||||
var campanhaCCCE = sheet.setCurrentCell(sheet.getRange('D85')).getValue();
|
||||
|
||||
var outras = sheet.setCurrentCell(sheet.getRange('D95')).getValue();
|
||||
var assinantes = sheet.setCurrentCell(sheet.getRange('D115')).getValue();
|
||||
var jornal = sheet.setCurrentCell(sheet.getRange('D127')).getValue();
|
||||
var carimboValue = pegarCarimbo() ;
|
||||
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
|
||||
// ABA TOTAL COLUNAS DE VALORES TOTALIZADOS
|
||||
var cotascol = 'C'; // 0
|
||||
var contribuintescol = 'E'; // 1
|
||||
var brochurascol = 'H' ; // 2
|
||||
var cfcol = 'J'; // 3
|
||||
var outrascol = 'L'; // 4
|
||||
var asscol = 'P'; // 5
|
||||
var jornalcol ='R'; // 6
|
||||
var varJaneiro = 3 ;
|
||||
var varFevereiro = 4 ;
|
||||
var varMarço = 5 ;
|
||||
var varAbril = 6 ;
|
||||
var varMaio = 7 ;
|
||||
var varJunho = 8 ;
|
||||
var varJulho = 9 ;
|
||||
var varAgosto = 10 ;
|
||||
var varSetembro = 11 ;
|
||||
var varOutubro = 12 ;
|
||||
var varNovembro = 13 ;
|
||||
var varDezembro = 14 ;
|
||||
var decimoTerceiro = 15 ;
|
||||
var decimoQuarto = 16 ;
|
||||
var decimoQuinto = 17 ;
|
||||
var colunas = [ cotascol, contribuintescol , brochurascol , cfcol , outrascol , asscol , jornalcol ] ;
|
||||
var linhas = [varJaneiro , varFevereiro ,varMarço ,varAbril ,varMaio ,varJunho ,varJulho ,varAgosto ,varSetembro ,varOutubro ,varNovembro ,varDezembro, decimoTerceiro, decimoQuarto, decimoQuinto] ;
|
||||
// TERMINOU TABELA TOTAL /\
|
||||
|
||||
|
||||
// PEGAR MES ATUAL
|
||||
|
||||
if(!isNaN(parseFloat(carimboValue)) ) {var mesAtual = Utilities.formatDate(carimboValue,timeZone, "MM");}
|
||||
else { mesAtual = Utilities.formatDate(new Date(),timeZone, "MM") }
|
||||
|
||||
// Para cada Coluna de TOTAL executar totalização:
|
||||
colunas.forEach(function(letra,coluna,tudo) {
|
||||
Logger.log("letra: " + letra );
|
||||
// começa com cota, checa se é o mes e coloca no switch.
|
||||
switch (letra){
|
||||
case cotascol:
|
||||
// mes igual mes da primeira linha
|
||||
for (var cadaMesdeCota = 5 ; cadaMesdeCota <=40 ; cadaMesdeCota++ ){
|
||||
var celulaMilitante = 'B' + cadaMesdeCota ;
|
||||
var celulaAno = 'C' + cadaMesdeCota ;
|
||||
var celulaMes = 'D' + cadaMesdeCota ;
|
||||
var celulaValor = 'E' + cadaMesdeCota ;
|
||||
|
||||
|
||||
// Vai pra Anterior pra pegar cota de cadaMesdeCota ++++++++++++++++++++++++++++++++++++++++++++++
|
||||
var sheet = ss.getSheetByName(anterior);
|
||||
|
||||
valorCelula = sheet.setCurrentCell(sheet.getRange(celulaValor)).getValue() ;
|
||||
|
||||
// if (!isNaN(parseFloat(mesCelula)) && !isNaN(parseFloat(valorCelula)))
|
||||
if (!isNaN(parseFloat(valorCelula)))
|
||||
{
|
||||
var mesCelula = sheet.setCurrentCell(sheet.getRange(celulaMes)).getValue();
|
||||
var retornoMes = checkMonth(mesCelula);
|
||||
militanteCota = sheet.setCurrentCell(sheet.getRange(celulaMilitante)).getValue();
|
||||
anoCota = sheet.setCurrentCell(sheet.getRange(celulaAno)).getValue();
|
||||
Logger.log( " COTA valorCelula: " + valorCelula + " militanteCota " + militanteCota + "retornoMes" + retornoMes);
|
||||
|
||||
if ( !isNaN(parseFloat(retornoMes)) ) {
|
||||
var mesNovaCota = new Date(retornoMes) ;
|
||||
var mesNCemN = Number(Utilities.formatDate(mesNovaCota,timeZone, "MM")) - 1;
|
||||
var valorNovaCota = valorCelula ;
|
||||
|
||||
if (!isNaN(parseFloat(valorNovaCota))){
|
||||
// ENVIA PARA TOTAL:
|
||||
Logger.log( " COTA valorNovaCota: " + valorNovaCota + ".");
|
||||
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
var celulaObjetivo = letra + linhas[mesNCemN] ;
|
||||
Logger.log( " COTA celulaObjetivo: " + celulaObjetivo + ".");
|
||||
|
||||
|
||||
var valorAntigoCota = sheet.setCurrentCell(sheet.getRange(celulaObjetivo)).getValue() ;
|
||||
if (!isNaN(parseFloat(valorAntigoCota))){
|
||||
Logger.log( " COTA valorAntigoCota: " + valorAntigoCota + ".");
|
||||
var gravar = valorAntigoCota + valorNovaCota ;
|
||||
}
|
||||
else { var gravar = valorNovaCota ; }
|
||||
sheet.setCurrentCell(sheet.getRange(celulaObjetivo)).setValue(gravar);
|
||||
Logger.log( " COTA Gravou: " + gravar + ".");
|
||||
// ENVIOU PARA TOTAL /\
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// segunda iteração contribuintes, checa se é o mes e coloca no switch.
|
||||
case contribuintescol:
|
||||
// mes igual mes da primeira linha
|
||||
for (var cadaMesContrib = 43 ; cadaMesContrib <=57 ; cadaMesContrib++ ){
|
||||
var celulaContribuinte = 'B' + cadaMesContrib ;
|
||||
var celulaAno = 'C' + cadaMesContrib ;
|
||||
var celulaMes = 'D' + cadaMesContrib ;
|
||||
var celulaValor = 'E' + cadaMesContrib ;
|
||||
var celulaResponsavel = 'F' + cadaMesContrib ;
|
||||
|
||||
// Vai pra Anterior pra pegar Contribuição de cadaMesdeCota
|
||||
var sheet = ss.getSheetByName(anterior);
|
||||
var retornoMes = sheet.setCurrentCell(sheet.getRange(celulaMes)).getValue();
|
||||
|
||||
if ( !isNaN(parseFloat(retornoMes)) ) {
|
||||
var mesNovaContrib = new Date(checkMonth(retornoMes)) ;
|
||||
var mesNCemN = Number(Utilities.formatDate(mesNovaContrib,timeZone, "MM")) - 1;
|
||||
var valorNovaContr = Number(sheet.setCurrentCell(sheet.getRange(celulaValor)).getValue());
|
||||
if (!isNaN(parseFloat(valorNovaContr))){
|
||||
Logger.log( " CONTRIB valorNovaContr: " + valorNovaContr + ".");
|
||||
var celulaObjetivo = letra + linhas[mesNCemN] ;
|
||||
Logger.log( " CONTRIB celulaObjetivo: " + celulaObjetivo + ".");
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
var valorAntigoContr = sheet.setCurrentCell(sheet.getRange(celulaObjetivo)).getValue() ;
|
||||
Logger.log( " CONTRIB valorAntigoContr: " + valorAntigoContr + ".");
|
||||
if (!isNaN(parseFloat(valorAntigoContr)) ){
|
||||
var gravar = valorNovaContr + valorAntigoContr ; }
|
||||
else {
|
||||
gravar = valorNovaContr ;
|
||||
}
|
||||
Logger.log( " CONTRIB celulaMes: " + celulaMes + " celulaValor: " + celulaValor + ".");
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
sheet.setCurrentCell(sheet.getRange(celulaObjetivo)).setValue(gravar);
|
||||
Logger.log( " CONTRIB Gravou: " + gravar + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// FALTA TERMINAR BROCHURAS
|
||||
case brochurascol:
|
||||
for (var linhaBro = 60 ; linhaBro <=65 ; linhaBro++ ){
|
||||
// var celulaNome = 'B' +linhaBro ;
|
||||
var celulaQuantidade = 'C' + linhaBro ;
|
||||
var celulaValor = 'D' + linhaBro ;
|
||||
var celulaCodigo = 'E' + linhaBro ;
|
||||
// Vai pra Anterior pra pegar dados acima
|
||||
var sheet = ss.getSheetByName(anterior);
|
||||
var difLinBro = 2 ;
|
||||
var quantidadeBro = sheet.setCurrentCell(sheet.getRange(celulaQuantidade)).getValue();
|
||||
if ( !isNaN(parseFloat(quantidadeBro)) ) {
|
||||
var valorNovaBro = Number(sheet.setCurrentCell(sheet.getRange(celulaValor)).getValue());
|
||||
var codigoNovaBro = Number(sheet.setCurrentCell(sheet.getRange(celulaCodigo)).getValue()) + difLinBro ;
|
||||
Logger.log(" BROCHURAS valorNovaBro: " + valorNovaBro + " codigoNovaBro: " + codigoNovaBro);
|
||||
if (!isNaN(parseFloat(valorNovaBro))){
|
||||
var celulaObjetivo = letra + codigoNovaBro ;
|
||||
var qtdObjetivo = 'G' + codigoNovaBro ;
|
||||
var qtdAntigoBro = sheet.setCurrentCell(sheet.getRange(qtdObjetivo)).getValue() ;
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
var valorAntigoBro = sheet.setCurrentCell(sheet.getRange(celulaObjetivo)).getValue() ;
|
||||
if (!isNaN(parseFloat(valorAntigoBro)) ){
|
||||
var gravar = valorNovaBro + valorAntigoBro ; }
|
||||
else {
|
||||
gravar = valorNovaBro ;
|
||||
}
|
||||
Logger.log(" BROCHURAS celulaQuantidade: " + celulaQuantidade + " celulaValor: " + celulaValor + " gravar: " + gravar );
|
||||
|
||||
if (!isNaN(parseFloat(qtdAntigoBro)) ){
|
||||
var gravarQtd = quantidadeBro + qtdAntigoBro ; }
|
||||
else {
|
||||
var gravarQtd = quantidadeBro ;
|
||||
}
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
// Grava Valor
|
||||
Logger.log(" BROCHURAS celulaValorObjetivo: " + celulaObjetivo + " gravar: " + gravar );
|
||||
sheet.setCurrentCell(sheet.getRange(celulaObjetivo)).setValue(gravar);
|
||||
Logger.log( " BROCHURAS Gravou Valor: " + gravar + ".");
|
||||
// Grava quantidade
|
||||
sheet.setCurrentCell(sheet.getRange(qtdObjetivo)).setValue(gravarQtd);
|
||||
Logger.log( " BROCHURAS Gravou Qtd: " + gravarQtd + ".")
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case cfcol:
|
||||
for (var linhaCF = 68 ; linhaCF <=84 ; linhaCF++ ){
|
||||
var celulaNome = 'B' + linhaCF ;
|
||||
var celulaQuantidade = 'C' + linhaCF ;
|
||||
var celulaValor = 'D' + linhaCF ;
|
||||
var celulaCodigo = 'F' + linhaCF ;
|
||||
var sheet = ss.getSheetByName(anterior);
|
||||
var valorCF = sheet.setCurrentCell(sheet.getRange(celulaValor)).getValue();
|
||||
if ( !isNaN(parseFloat(valorCF)) ) {
|
||||
var militanteNovaCF = sheet.setCurrentCell(sheet.getRange(celulaNome)).getValue();
|
||||
// VAI PRA TOTAL
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
var linhaSalvar = sheet.getRange('I3:J22').createTextFinder(militanteNovaCF).findNext();
|
||||
if (linhaSalvar){
|
||||
var valorAntigoCF = linhaSalvar.offset(0,1).getValue();
|
||||
Logger.log(" CF linhaSalvar.getA1Notation(): " + linhaSalvar.getA1Notation() + " militanteNovaCF: " + militanteNovaCF + " valorCF: " + valorCF + " valorAntigoCF: " + valorAntigoCF );
|
||||
if (!isNaN(parseFloat(valorAntigoCF)) ){ var gravar = valorCF + valorAntigoCF ; }
|
||||
else { gravar = valorCF ; }
|
||||
// Grava Valor
|
||||
linhaSalvar.offset(0,1).setValue(gravar);
|
||||
Logger.log( " CF Gravou Valor: " + gravar + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case outrascol:
|
||||
for (var linhaOutros = 87 ; linhaOutros <=94 ; linhaOutros++ ){
|
||||
var celulaQuantidade = 'C' + linhaOutros ;
|
||||
var celulaValor = 'D' + linhaOutros ;
|
||||
var celulaCodigo = 'E' + linhaOutros ;
|
||||
|
||||
// Vai pra Anterior pra pegar dados acima
|
||||
var sheet = ss.getSheetByName(anterior);
|
||||
|
||||
var quantidadeOutro = sheet.setCurrentCell(sheet.getRange(celulaQuantidade)).getValue();
|
||||
if ( !isNaN(parseFloat(quantidadeOutro)) ) {
|
||||
var valorNovaOutro = Number(sheet.setCurrentCell(sheet.getRange(celulaValor)).getValue());
|
||||
var difLinOut = 2 ;
|
||||
var codigoNovaOutro = Number(sheet.setCurrentCell(sheet.getRange(celulaCodigo)).getValue()) + difLinOut ;
|
||||
if (!isNaN(parseFloat(valorNovaOutro))){
|
||||
var celulaObjetivo = letra + codigoNovaOutro ;
|
||||
var qtdObjetivo = 'K' + codigoNovaOutro ;
|
||||
var qtdAntigoOutro = sheet.setCurrentCell(sheet.getRange(qtdObjetivo)).getValue() ;
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
var valorAntigoOutro = sheet.setCurrentCell(sheet.getRange(celulaObjetivo)).getValue() ;
|
||||
if (!isNaN(parseFloat(valorAntigoOutro)) ){
|
||||
var gravar = valorNovaOutro + valorAntigoOutro ; }
|
||||
else {
|
||||
gravar = valorNovaOutro ;
|
||||
}
|
||||
Logger.log( " OUTRAS celulaQuantidade: " + celulaQuantidade + " celulaValor: " + celulaValor + " gravar: " + gravar );
|
||||
|
||||
if (!isNaN(parseFloat(qtdAntigoOutro)) ){
|
||||
var gravarQtd = quantidadeOutro + qtdAntigoOutro ; }
|
||||
else {
|
||||
var gravarQtd = quantidadeOutro ;
|
||||
}
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
// Grava Valor
|
||||
Logger.log( " OUTRAS celulaValorObjetivo: " + celulaObjetivo + " gravar: " + gravar );
|
||||
sheet.setCurrentCell(sheet.getRange(celulaObjetivo)).setValue(gravar);
|
||||
Logger.log( " OUTRAS Gravou Valor: " + gravar + ".");
|
||||
// Grava quantidade
|
||||
sheet.setCurrentCell(sheet.getRange(qtdObjetivo)).setValue(gravarQtd);
|
||||
Logger.log( " OUTRAS Gravou Qtd: " + gravarQtd + ".")
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case asscol:
|
||||
// ARRUMAR ASSINATURAS
|
||||
var linha = mesAtual - 1 ;
|
||||
Logger.log(" ASSINATURA linhas[linha]: " + linhas[linha] + " linha: " + linha + " mesAtual: " + mesAtual + ".");
|
||||
var celula = letra + linhas[linha] ;
|
||||
|
||||
// PEGAR TOTAL ATUAL
|
||||
var sheet = ss.getSheetByName(anterior);
|
||||
var totalatual = sheet.setCurrentCell(sheet.getRange(celula)).getValue() ;
|
||||
if ( !isNaN(parseFloat(outras)) && assinantes > 0 ){
|
||||
var gravar = totalatual + assinantes ;
|
||||
// GRAVAR
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
sheet.setCurrentCell(sheet.getRange(celula)).setValue(gravar);
|
||||
}
|
||||
break ;
|
||||
case jornalcol:
|
||||
for (var linhaAvulso = 112 ; linhaAvulso <=126 ; linhaAvulso++ ){
|
||||
var celulaQuantidade = 'C' + linhaAvulso ;
|
||||
var celulaValor = 'D' + linhaAvulso ;
|
||||
var celulaEdicao = 'B' + linhaAvulso ;
|
||||
|
||||
// Vai pra Anterior pra pegar dados acima
|
||||
var sheet = ss.getSheetByName(anterior);
|
||||
var difLinEdicao = 11
|
||||
var quantidadeAvulso = sheet.setCurrentCell(sheet.getRange(celulaQuantidade)).getValue();
|
||||
if ( !isNaN(parseFloat(quantidadeAvulso)) ) {
|
||||
var valorNovaAvulso = Number(sheet.setCurrentCell(sheet.getRange(celulaValor)).getValue());
|
||||
var edicaoNovaAvulso = Number(sheet.setCurrentCell(sheet.getRange(celulaEdicao)).getValue()) - difLinEdicao ;
|
||||
Logger.log( " JORNALA. edicaoNovaAvulso: " + edicaoNovaAvulso + "valorNovaAvulso: " + valorNovaAvulso + "Quantidade: " + quantidadeAvulso );
|
||||
if (!isNaN(parseFloat(valorNovaAvulso))){
|
||||
var celulaValorObjetivo = letra + edicaoNovaAvulso ;
|
||||
var qtdVendido = 'T' + edicaoNovaAvulso ;
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
var valorAntigoAvulso = sheet.setCurrentCell(sheet.getRange(celulaValorObjetivo)).getValue() ;
|
||||
var qtdAntigoAvulso = sheet.setCurrentCell(sheet.getRange(qtdVendido)).getValue() ;
|
||||
if (!isNaN(parseFloat(valorAntigoAvulso)) ){
|
||||
var gravar = valorNovaAvulso + valorAntigoAvulso ; }
|
||||
else {
|
||||
var gravar = valorNovaAvulso ;
|
||||
}
|
||||
if (!isNaN(parseFloat(qtdAntigoAvulso)) ){
|
||||
var gravarQtd = quantidadeAvulso + qtdAntigoAvulso ; }
|
||||
else {
|
||||
var gravarQtd = quantidadeAvulso ;
|
||||
}
|
||||
var sheet = ss.getSheetByName("TOTAL");
|
||||
// Grava Valor
|
||||
sheet.setCurrentCell(sheet.getRange(celulaValorObjetivo)).setValue(gravar);
|
||||
Logger.log( " JORNALA. Gravou Valor: " + gravar );
|
||||
// Grava quantidade
|
||||
sheet.setCurrentCell(sheet.getRange(qtdVendido)).setValue(gravarQtd);
|
||||
Logger.log( " JORNALA. Gravou Qtd: " + gravarQtd );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
} )
|
||||
}
|
||||
|
||||
if (sheets.length > 1) {
|
||||
for (var cadaSheet = 0 ; cadaSheet < sheets.length ; cadaSheet++)
|
||||
{
|
||||
var nomeSheet = sheets[cadaSheet].getName();
|
||||
Logger.log("nomeSheet: " + nomeSheet);
|
||||
if (!isNaN(parseFloat(nomeSheet)) && isFinite(nomeSheet) && nomeSheet === anterior) {
|
||||
SpreadsheetApp.setActiveSheet(sheets[cadaSheet]);
|
||||
var protections = sheets[cadaSheet].getProtections(SpreadsheetApp.ProtectionType.SHEET);
|
||||
for (var i = 0; i < protections.length; i++) {
|
||||
var desc = protections[i].getDescription();
|
||||
Logger.log("protection desc: " + desc);
|
||||
if ( desc === 'Aba protegida') {
|
||||
enviarTotal();
|
||||
gravou = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
var sheet = ss.getSheetByName(anterior);
|
||||
sheet.setCurrentCell(sheet.getRange(celulaPrincipal)) ;
|
||||
}
|
||||
}
|
||||
if (gravou === 1 ) { return "Totalizado";}
|
||||
Logger.log("gravou: " + gravou + ".");
|
||||
|
||||
}
|
||||
|
||||
|
||||
function checkMonth(nomedoMes)
|
||||
{
|
||||
Logger.log(" checkMonth nomedoMes: " + nomedoMes + ".");
|
||||
switch (nomedoMes){
|
||||
case 1:
|
||||
case "Janeiro" :
|
||||
return "1";
|
||||
break;
|
||||
case 2:
|
||||
case "Fevereiro":
|
||||
return "2";
|
||||
break;
|
||||
case 3:
|
||||
case "Março":
|
||||
return "3";
|
||||
break;
|
||||
case 4:
|
||||
case "Abril":
|
||||
return "4";
|
||||
break;
|
||||
case 5:
|
||||
case "Maio":
|
||||
return "5";
|
||||
break;
|
||||
case 6:
|
||||
case "Junho":
|
||||
return "6";
|
||||
break;
|
||||
case 7:
|
||||
case "Julho":
|
||||
return "7";
|
||||
break;
|
||||
case 8:
|
||||
case "Agosto":
|
||||
return "8";
|
||||
break;
|
||||
case 9:
|
||||
case "Setembro":
|
||||
return "9";
|
||||
break;
|
||||
case 10:
|
||||
case "Outubro":
|
||||
return "10";
|
||||
break;
|
||||
case 11:
|
||||
case "Novembro":
|
||||
return "11";
|
||||
break;
|
||||
case 12:
|
||||
case "Dezembro":
|
||||
return "12";
|
||||
break;
|
||||
default:
|
||||
return nomedoMes;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user