Skip to content

Instantly share code, notes, and snippets.

@kleyber-ribeiro
Last active December 19, 2018 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kleyber-ribeiro/20115847dcd753ac6083f9e17f901f3a to your computer and use it in GitHub Desktop.
Save kleyber-ribeiro/20115847dcd753ac6083f9e17f901f3a to your computer and use it in GitHub Desktop.
sc_include_lib ("tcpdf");
// FORMATAR A DATA
switch (date("m")) {
case "01": $vmes = 'Janeiro'; break;
case "02": $vmes = 'Fevereiro'; break;
case "03": $vmes = 'Março'; break;
case "04": $vmes = 'Abril'; break;
case "05": $vmes = 'Maio'; break;
case "06": $vmes = 'Junho'; break;
case "07": $vmes = 'Julho'; break;
case "08": $vmes = 'Agosto'; break;
case "09": $vmes = 'Setembro'; break;
case "10": $vmes = 'Outubro'; break;
case "11": $vmes = 'Novembro'; break;
case "12": $vmes = 'Dezembro'; break;
}
$local_c = date('d').' de '.$vmes.' de '.date('Y');
sc_lookup(rs, "SELECT contrato FROM parametros");
$html = {rs[0][0]};
if($rs)
{
$cSql = "
SELECT
a.nome AS nome,
a.rg AS rg,
a.cpf AS cpf,
a.data_nascimento AS data_nascimento,
CONCAT(a.endereco, ',', a.bairro, ',', a.complemento) AS endereco,
a.cep AS cep,
a.cidade AS cidade,
a.uf AS uf,
a.responsavel AS responsavel,
a.celular_1 AS celular1,
a.celular_2 AS celular2,
a.celular_3 AS celular3,
c.valor AS valor,
p.valor_desconto_em_dia AS perc_desconto_em_dia,
m.quant_parcelas AS num_parcelas,
x.descricao AS turma,
concat(x.hora_inicio, ' - ', x.hora_fim) AS horario,
c.descricao AS curso,
p.valor_matricula AS valor_matricula
FROM
alunos a
INNER JOIN matriculas m ON (m.id_aluno = a.id_alunos)
LEFT JOIN turmas t ON (t.id_turmas = m.id_turma)
LEFT JOIN salas_x_horarios x ON (x.id_turma = t.id_turmas)
INNER JOIN cursos c ON (c.id_cursos = t.id_curso)
INNER JOIN parametros p ON (p.id_parametros = 1)
WHERE a.id_alunos = ".[naluno];
sc_lookup(ds, $cSql);
$_nome_aluno = {ds[0][0]};
$_rg = {ds[0][1]};
$_cpf = substr({ds[0][2]},0,3).'.'.substr({ds[0][2]},3,3).'.'.substr({ds[0][2]},6,3).'-'.substr({ds[0][2]},9,2);
$_dt_nasc = substr({ds[0][3]},8,2).'/'.substr({ds[0][3]},5,2).'/'.substr({ds[0][3]},0,4);
$_endereco = {ds[0][4]};
$_cep = substr({ds[0][5]},0,2).'.'.substr({ds[0][5]},2,3).'-'.substr({ds[0][5]},5,3);
$_cidade = {ds[0][6]};
$_uf = {ds[0][7]};
$_responsavel = ({ds[0][8]} == {ds[0][0]}) ? 'O(A) MESMO(A)' : {ds[0][8]};
$_celular1 = empty({ds[0][9]}) ? '' : '('.substr({ds[0][9]},0,2).') '.substr({ds[0][9]},2,5).'-'.substr({ds[0][9]},7,4);
$_celular2 = empty({ds[0][10]}) ? '' : '('.substr({ds[0][10]},0,2).') '.substr({ds[0][10]},2,5).'-'.substr({ds[0][10]},7,4);
$_celular3 = empty({ds[0][11]}) ? '' : '('.substr({ds[0][11]},0,2).') '.substr({ds[0][11]},2,5).'-'.substr({ds[0][11]},7,4);
$_valor = {ds[0][12]};
$_valor_desc_em_dia = {ds[0][13]};
$_num_parcelas = {ds[0][14]};
$_turma = {ds[0][15]};
$_horario = {ds[0][16]};
$_curso = {ds[0][17]};
$_valor_matricula = {ds[0][18]};
// -- Dados do Contratante
$html = str_replace('xnome_alunox', $_nome_aluno, $html);
$html = str_replace('xdata_nascx', $_dt_nasc, $html);
$html = str_replace('xrgx', $_rg, $html);
$html = str_replace('xcpfx', $_cpf, $html);
$html = str_replace('xenderecox', $_endereco, $html);
$html = str_replace('xcepx', $_cep, $html);
$html = str_replace('xcidadex', $_cidade, $html);
$html = str_replace('xufx', $_uf, $html);
$html = str_replace('xnome_responsavelx', $_responsavel, $html);
$html = str_replace('xfone_1x', $_celular1, $html);
$html = str_replace('xfone_2x', $_celular2, $html);
$html = str_replace('xfone_3x', $_celular3, $html);
// -- Quadro I - Sobre Pagamento
$html = str_replace('xvalor_cursox', $_valor, $html);
$html = str_replace('xvalor_descontox', $_valor_desc_em_dia, $html);
$html = str_replace('xvalor_matriculax', $_valor_matricula, $html);
$html = str_replace('xnum_parcelasx', $_num_parcelas, $html);
$html = str_replace('xvalor_desconto_pontualidadex', $_valor_desc_em_dia, $html);
// -- Quadro II - Sobre o curso contratado
$html = str_replace('xcursox', $_curso, $html);
$html = str_replace('xturmax', $_turma, $html);
$html = str_replace('xhorariox', $_horario, $html);
// Data
$html = str_replace('xdata_extensox', $local_c, $html);
// Gerando o PDF
$pdf=new TCPDF('P','mm','A4', true, 'UTF-8', false);
$pdf->AddPage();
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('contrato.pdf', 'I');
}
//sc_exit(sel);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment