Code.
gs
function doGet() {
return [Link]('Index')
.evaluate()
.setTitle('Sistema Muay Thai');
}
function include(f) {
return [Link](f).getContent();
}
/**************** ALUNOS ****************/
function cadastrarAluno(d) {
const sh = [Link]().getSheetByName('Alunos');
const lastRow = [Link]();
// Normaliza CPF (remove tudo que não for número)
const cpfNovo = String([Link]).replace(/\D/g, '');
if (!cpfNovo) {
return { error: true, message: 'CPF inválido' };
}
if (lastRow > 1) {
const cpfs = sh
.getRange(2, 3, lastRow - 1, 1)
.getValues()
.flat()
.map(c => String(c).replace(/\D/g, ''));
if ([Link](cpfNovo)) {
return { error: true, message: 'Aluno já cadastrado com este CPF' };
}
}
const id = lastRow;
[Link]([
id,
[Link],
cpfNovo,
[Link],
[Link],
[Link],
new Date(),
'Ativo'
]);
return { error: false, message: 'Aluno cadastrado com sucesso' };
}
/**************** PAGAMENTOS ****************/
function gerarMensalidades(mes, ano) {
const ss = [Link]();
const shA = [Link]('Alunos');
const shP = [Link]('Pagamentos');
const cfg = getConfig();
const alunos = [Link](2, 1, [Link]() - 1, 2).getValues();
let qtd = 0;
[Link](a => {
[Link]([
a[0], a[1], `${mes}/${ano}`,
[Link], 'Pendente', new Date()
]);
qtd++;
});
return { message: qtd + ' mensalidades geradas' };
}
function listarPagamentos() {
const sh = [Link]().getSheetByName('Pagamentos');
if ([Link]() < 2) return [];
return [Link](2, 1, [Link]() - 1, 6).getValues();
}
/**************** CONFIG ****************/
function getConfig() {
const sh = [Link]().getSheetByName('Config');
const v = [Link](2, 1, [Link]() - 1, 2).getValues();
const cfg = {};
[Link](l => cfg[l[0]] = l[1]);
return cfg;
}
/**************** DASHBOARD ****************/
function getDashboardData() {
const a = [Link]().getSheetByName('Alunos').getLastRow() - 1;
const p = [Link]().getSheetByName('Pagamentos').getLastRow() -
1;
return { alunos: a, pagamentos: p };
}
[Link]
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style><?!= include('Stylesheet') ?></style>
</head>
<body>
<header>
<h1>Sistema Muay Thai</h1>
<nav>
<button class="tab-button" data-tab="dashboard">Dashboard</button>
<button class="tab-button" data-tab="alunos">Alunos</button>
<button class="tab-button" data-tab="pagamentos">Pagamentos</button>
<button class="tab-button" data-tab="config">Config</button>
</nav>
</header>
<main>
<section id="dashboard" class="tab-content"><?!= include('Dashboard')
?></section>
<section id="alunos" class="tab-content"><?!= include('Alunos') ?></section>
<section id="pagamentos" class="tab-content"><?!= include('Pagamentos')
?></section>
<section id="config" class="tab-content"><?!= include('Config') ?></section>
</main>
<script><?!= include('Javascript') ?></script>
</body>
</html>
[Link]
body { font-family: Arial; margin:0 }
header { background:#111; color:#fff; padding:10px }
nav button { margin:5px; padding:8px }
.tab-content { display:none; padding:20px }
.[Link] { display:block }
.[Link] { background:#e63946; color:white }
[Link]
const App = {};
/*********** ABAS ***********/
[Link] = tab => {
[Link]('.tab-content').forEach(c => [Link]('active'));
[Link]('.tab-button').forEach(b => [Link]('active'));
[Link](tab).[Link]('active');
[Link](`[data-tab="${tab}"]`).[Link]('active');
if (tab === 'dashboard') [Link]();
};
/*********** ALUNO ***********/
[Link] = e => {
[Link]();
const f = [Link];
[Link](r => {
[Link]('msgAluno').innerText = [Link];
[Link]();
}).cadastrarAluno({
nome:[Link], cpf:[Link],
telefone:[Link], email:[Link],
horario:[Link]
});
};
/*********** PAGAMENTOS ***********/
[Link] = e => {
[Link]();
const f = [Link];
[Link](r => {
[Link]('msgPagamentos').innerText = [Link];
}).gerarMensalidades([Link], [Link]);
};
/*********** DASHBOARD ***********/
[Link] = () => {
[Link](d => {
[Link]('dashAlunos').innerText = [Link];
[Link]('dashPag').innerText = [Link];
}).getDashboardData();
};
/*********** INIT ***********/
[Link]('DOMContentLoaded', () => {
[Link]('.tab-button')
.forEach(b => [Link]('click', () => [Link]([Link])));
[Link]('formAluno')
?.addEventListener('submit', [Link]);
[Link]('formGerarMensalidades')
?.addEventListener('submit', [Link]);
[Link]('dashboard');
});
[Link]
<h2>Dashboard</h2>
<p>Total de alunos: <b id="dashAlunos">0</b></p>
<p>Total de pagamentos: <b id="dashPag">0</b></p>
[Link]
<h2>Novo Aluno</h2>
<form id="formAluno">
<input name="nome" placeholder="Nome" required>
<input name="cpf" placeholder="CPF">
<input name="telefone" placeholder="Telefone">
<input name="email" placeholder="Email">
<select name="horario" required>
<option value="">Selecione o horário</option>
<option value="Turma Kid – Terças e Quintas – 15:50 às 16:50"> Turma Kids - 15:50 -
16:50</option>
<option value="Adulto – Segunda, Quarta e Sexta – 19:00 às 20:00">Turma Adulto -
19:00 - 20:00</option>
<option value="Adulto – Segunda, Quarta e Sexta – 20:00 às 21:00">Turma Adulto -
20:00 - 21:00</option>
</select>
<button type="submit">Salvar</button>
</form>
<div id="msgAluno"></div>
[Link]
<h2>Gerar Mensalidades</h2>
<form id="formGerarMensalidades">
<input name="mes" placeholder="Mês" required>
<input name="ano" placeholder="Ano" required>
<button>Gerar</button>
</form>
<div id="msgPagamentos"></div>
[Link]
<h2>Configurações</h2>
<p>Mensalidade definida na planilha</p>