Skip to content

Commit

Permalink
Implementado relatórios financeiros em XLSX (#908)
Browse files Browse the repository at this point in the history
* Implementado relatórios financeiros em XLSX

* Apply php-cs-fixer changes

Co-authored-by: Pr3d4dor <Pr3d4dor@users.noreply.github.com>
  • Loading branch information
Pr3d4dor and Pr3d4dor authored Aug 15, 2020
1 parent ea289a6 commit a9c82d6
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Todas as alterações serão documentadas neste arquivo
Formato baseado em [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
e [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.12.0] - 2020-08-15

## Added
- Implementado relatório financeiro em XLSX. [@Pr3d4dor](https://github.com/Pr3d4dor)

## [4.11.2] - 2020-07-25

## Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

![MapOS](https://raw.githubusercontent.com/RamonSilva20/mapos/master/assets/img/logo.png)

![version](https://img.shields.io/badge/version-4.11.2-blue.svg?longCache=true&style=flat-square)
![version](https://img.shields.io/badge/version-4.12.0-blue.svg?longCache=true&style=flat-square)
![license](https://img.shields.io/badge/license-MIT-green.svg?longCache=true&style=flat-square)
![theme](https://img.shields.io/badge/theme-Matrix--Admin-lightgrey.svg?longCache=true&style=flat-square)
![issues](https://img.shields.io/github/issues/RamonSilva20/mapos.svg?longCache=true&style=flat-square)
Expand Down
2 changes: 1 addition & 1 deletion application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* App current version
*/
$config['app_version'] = '4.11.2';
$config['app_version'] = '4.12.0';

/**
* Nome do sistema
Expand Down
95 changes: 92 additions & 3 deletions application/controllers/Relatorios.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function clientesRapid()
}

$format = $this->input->get('format');

if ($format == 'xls') {
$clientes = $this->Relatorios_model->clientesRapid($array = true);
$cabecalho = [
Expand All @@ -103,12 +103,12 @@ public function clientesRapid()
];

$writer = new XLSXWriter();

$writer->writeSheetHeader('Sheet1', $cabecalho);
foreach ($clientes as $cliente) {
$writer->writeSheetRow('Sheet1', $cliente);
}

$arquivo = $writer->writeToString();
$this->load->helper('download');
force_download('relatorio_clientes.xlsx', $arquivo);
Expand Down Expand Up @@ -325,6 +325,51 @@ public function financeiroRapid()
redirect(base_url());
}

$format = $this->input->get('format');

if ($format == 'xls') {
$lancamentos = $this->Relatorios_model->financeiroRapid(true);

$lancamentosFormatados = array_map(function ($item) {
return [
'idLancamentos' => $item['idLancamentos'],
'descricao' => $item['descricao'],
'valor' => $item['valor'],
'data_vencimento' => $item['data_vencimento'],
'data_pagamento' => $item['data_pagamento'],
'baixado' => $item['baixado'],
'cliente_fornecedor' => $item['cliente_fornecedor'],
'forma_pgto' => $item['forma_pgto'],
'tipo' => $item['tipo'],
];
}, $lancamentos);

$cabecalho = [
'ID Lançamentos' => 'integer',
'Descricao' => 'string',
'Valor' => 'price',
'Data Vencimento' => 'YYYY-MM-DD',
'Data Pagamento' => 'YYYY-MM-DD',
'Baixado' => 'integer',
'Cliente/Fornecedor' => 'string',
'Forma Pagamento' => 'string',
'Tipo' => 'string',
];

$writer = new XLSXWriter();

$writer->writeSheetHeader('Sheet1', $cabecalho);
foreach ($lancamentosFormatados as $lancamento) {
$writer->writeSheetRow('Sheet1', $lancamento);
}

$arquivo = $writer->writeToString();
$this->load->helper('download');
force_download('relatorio_financeiro.xlsx', $arquivo);

return;
}

$data['lancamentos'] = $this->Relatorios_model->financeiroRapid();
$data['emitente'] = $this->Mapos_model->getEmitente();
$data['title'] = 'Relatório Financeiro';
Expand All @@ -346,6 +391,50 @@ public function financeiroCustom()
$dataFinal = $this->input->get('dataFinal');
$tipo = $this->input->get('tipo');
$situacao = $this->input->get('situacao');
$format = $this->input->get('format');

if ($format == 'xls') {
$lancamentos = $this->Relatorios_model->financeiroCustom($dataInicial, $dataFinal, $tipo, $situacao, true);

$lancamentosFormatados = array_map(function ($item) {
return [
'idLancamentos' => $item['idLancamentos'],
'descricao' => $item['descricao'],
'valor' => $item['valor'],
'data_vencimento' => $item['data_vencimento'],
'data_pagamento' => $item['data_pagamento'],
'baixado' => $item['baixado'],
'cliente_fornecedor' => $item['cliente_fornecedor'],
'forma_pgto' => $item['forma_pgto'],
'tipo' => $item['tipo'],
];
}, $lancamentos);

$cabecalho = [
'ID Lançamentos' => 'integer',
'Descricao' => 'string',
'Valor' => 'price',
'Data Vencimento' => 'YYYY-MM-DD',
'Data Pagamento' => 'YYYY-MM-DD',
'Baixado' => 'integer',
'Cliente/Fornecedor' => 'string',
'Forma Pagamento' => 'string',
'Tipo' => 'string',
];

$writer = new XLSXWriter();

$writer->writeSheetHeader('Sheet1', $cabecalho);
foreach ($lancamentosFormatados as $lancamento) {
$writer->writeSheetRow('Sheet1', $lancamento);
}

$arquivo = $writer->writeToString();
$this->load->helper('download');
force_download('relatorio_financeiro_custom.xlsx', $arquivo);

return;
}

$data['lancamentos'] = $this->Relatorios_model->financeiroCustom($dataInicial, $dataFinal, $tipo, $situacao);
$data['emitente'] = $this->Mapos_model->getEmitente();
Expand Down
18 changes: 14 additions & 4 deletions application/models/Relatorios_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,21 @@ public function osCustom($dataInicial = null, $dataFinal = null, $cliente = null
return $this->db->query($query)->result();
}

public function financeiroRapid()
public function financeiroRapid($array = false)
{
$dataInicial = date('Y-m-01');
$dataFinal = date("Y-m-t");
$query = "SELECT * FROM lancamentos WHERE data_vencimento BETWEEN ? and ? ORDER BY tipo";

return $this->db->query($query, [$dataInicial, $dataFinal])->result();
$result = $this->db->query($query, [$dataInicial, $dataFinal]);
if ($array) {
return $result->result_array();
}

return $result->result();
}

public function financeiroCustom($dataInicial = null, $dataFinal = null, $tipo = null, $situacao = null)
public function financeiroCustom($dataInicial = null, $dataFinal = null, $tipo = null, $situacao = null, $array = false)
{
if ($dataInicial) {
$this->db->where('data_vencimento >=', $dataInicial);
Expand All @@ -232,7 +237,12 @@ public function financeiroCustom($dataInicial = null, $dataFinal = null, $tipo =
}
}

return $this->db->get('lancamentos')->result();
$result = $this->db->get('lancamentos');
if ($array) {
return $result->result_array();
}

return $result->result();
}

public function vendasRapid()
Expand Down
13 changes: 12 additions & 1 deletion application/views/relatorios/rel_financeiro.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</div>
<div class="widget-content">
<ul class="site-stats">
<li><a target="_blank" href="<?php echo base_url() ?>index.php/relatorios/financeiroRapid"><i class="fas fa-hand-holding-usd"></i> <small>Relatório do mês</small></a></li>
<li><a target="_blank" href="<?php echo base_url() ?>index.php/relatorios/financeiroRapid"><i class="fas fa-hand-holding-usd"></i> <small>Relatório do mês - pdf</small></a></li>
<li><a target="_blank" href="<?php echo base_url() ?>index.php/relatorios/financeiroRapid?format=xls"><i class="fas fa-hand-holding-usd"></i> <small>Relatório do mês - xls</small></a></li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -55,8 +56,18 @@
<option value="pendente">Pendente</option>
</select>
</div>
</div>

<div class="span12 well" style="margin-left: 0">
<div class="span12">
<label for="">Tipo de impressão:</label>
<select name="format" class="span12">
<option value="">PDF</option>
<option value="xls">XLS</option>
</select>
</div>
</div>

<div class="span12" style="margin-left: 0; text-align: center">
<input type="reset" class="btn" value="Limpar" />
<button class="btn btn-inverse"><i class="fas fa-print"></i> Imprimir</button>
Expand Down

0 comments on commit a9c82d6

Please sign in to comment.