Skip to content

Commit

Permalink
Feature/filtros lancamentos (#982)
Browse files Browse the repository at this point in the history
* Modificado filtros de lançamentos para permitir período arbitrário de data e adicionado filtro de status

* Adicionado dayjs
  • Loading branch information
Pr3d4dor authored Oct 4, 2020
1 parent c28ce2b commit de6006b
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 130 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.17.0] - 2020-10-04

## Added
- Modificado filtros de lançamentos para permitir período arbitrário de data e adicionado filtro de status. [@Pr3d4dor](https://github.com/Pr3d4dor)

## [4.16.0] - 2020-10-04

## Added
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.16.0-blue.svg?longCache=true&style=flat-square)
![version](https://img.shields.io/badge/version-4.17.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.16.0';
$config['app_version'] = '4.17.0';

/**
* Nome do sistema
Expand Down
124 changes: 28 additions & 96 deletions application/controllers/Financeiro.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,106 +31,38 @@ public function lancamentos()
}

$where = '';
$periodo = $this->input->get('periodo');
$situacao = $this->input->get('situacao');
$vencimento_de = $this->input->get('vencimento_de') ?: date('d/m/Y');
$vencimento_ate = $this->input->get('vencimento_ate') ?: date('d/m/Y');
$cliente = $this->input->get('cliente');
$tipo = $this->input->get('tipo');
$status = $this->input->get('status');
$periodo = $this->input->get('periodo');

// busca todos os lançamentos
if ($periodo == 'todos') {
if ($situacao == 'previsto') {
$where = 'data_vencimento > "' . date('Y-m-d') . '" AND baixado = "0"';
if (! empty($vencimento_de)) {
$date = DateTime::createFromFormat('d/m/Y', $vencimento_de)->format('Y-m-d');

if (empty($where)) {
$where = "data_vencimento >= '$date'";
} else {
if ($situacao == 'atrasado') {
$where = 'data_vencimento < "' . date('Y-m-d') . '" AND baixado = "0"';
} else {
if ($situacao == 'realizado') {
$where = 'baixado = "1"';
}

if ($situacao == 'pendente') {
$where = 'baixado = "0"';
}
}
$where .= " AND data_vencimento >= '$date'";
}
} else {
}

if (! empty($vencimento_ate)) {
$date = DateTime::createFromFormat('d/m/Y', $vencimento_ate)->format('Y-m-d');

// busca lançamentos do dia
if ($periodo == null || $periodo == 'dia') {
$where = 'data_vencimento = "' . date('Y-m-d' . '"');
} // fim lançamentos dia

else {

// busca lançamentos da semana
if ($periodo == 'semana') {
$semana = $this->getThisWeek();

if (!isset($situacao) || $situacao == 'todos') {
$where = 'data_vencimento BETWEEN "' . $semana[0] . '" AND "' . $semana[1] . '"';
} else {
if ($situacao == 'previsto') {
$where = 'data_vencimento BETWEEN "' . date('Y-m-d') . '" AND "' . $semana[1] . '" AND baixado = "0"';
} else {
if ($situacao == 'atrasado') {
$where = 'data_vencimento BETWEEN "' . $semana[0] . '" AND "' . date('Y-m-d') . '" AND baixado = "0"';
} else {
if ($situacao == 'realizado') {
$where = 'data_vencimento BETWEEN "' . $semana[0] . '" AND "' . $semana[1] . '" AND baixado = "1"';
} else {
$where = 'data_vencimento BETWEEN "' . $semana[0] . '" AND "' . $semana[1] . '" AND baixado = "0"';
}
}
}
}
} // fim lançamentos dia
else {

// busca lançamento do mês

if ($periodo == 'mes') {
$mes = $this->getThisMonth();

if (!isset($situacao) || $situacao == 'todos') {
$where = 'data_vencimento BETWEEN "' . $mes[0] . '" AND "' . $mes[1] . '"';
} else {
if ($situacao == 'previsto') {
$where = 'data_vencimento BETWEEN "' . date('Y-m-d') . '" AND "' . $mes[1] . '" AND baixado = "0"';
} else {
if ($situacao == 'atrasado') {
$where = 'data_vencimento BETWEEN "' . $mes[0] . '" AND "' . date('Y-m-d') . '" AND baixado = "0"';
} else {
if ($situacao == 'realizado') {
$where = 'data_vencimento BETWEEN "' . $mes[0] . '" AND "' . $mes[1] . '" AND baixado = "1"';
} else {
$where = 'data_vencimento BETWEEN "' . $mes[0] . '" AND "' . $mes[1] . '" AND baixado = "0"';
}
}
}
}
} // busca lançamentos do ano
else {
$ano = $this->getThisYear();

if (!isset($situacao) || $situacao == 'todos') {
$where = 'data_vencimento BETWEEN "' . $ano[0] . '" AND "' . $ano[1] . '"';
} else {
if ($situacao == 'previsto') {
$where = 'data_vencimento BETWEEN "' . date('Y-m-d') . '" AND "' . $ano[1] . '" AND baixado = "0"';
} else {
if ($situacao == 'atrasado') {
$where = 'data_vencimento BETWEEN "' . $ano[0] . '" AND "' . date('Y-m-d') . '" AND baixado = "0"';
} else {
if ($situacao == 'realizado') {
$where = 'data_vencimento BETWEEN "' . $ano[0] . '" AND "' . $ano[1] . '" AND baixado = "1"';
} else {
$where = 'data_vencimento BETWEEN "' . $ano[0] . '" AND "' . $ano[1] . '" AND baixado = "0"';
}
}
}
}
}
}
if (empty($where)) {
$where = "data_vencimento <= '$date'";
} else {
$where .= " AND data_vencimento <= '$date'";
}
}

if (! empty($status)) {
if (empty($where)) {
$where = "baixado = '$status'";
} else {
$where .= " AND baixado = '$status'";
}
}

Expand All @@ -142,7 +74,7 @@ public function lancamentos()
}
}

if (!empty($tipo)) {
if (! empty($tipo)) {
if (empty($where)) {
$where = "tipo = '$tipo'";
} else {
Expand All @@ -152,7 +84,7 @@ public function lancamentos()

$this->load->library('pagination');

$this->data['configuration']['base_url'] = site_url("financeiro/lancamentos/?periodo=$periodo&situacao=$situacao&cliente=$cliente&tipo=$tipo");
$this->data['configuration']['base_url'] = site_url("financeiro/lancamentos/?vencimento_de=$vencimento_de&vencimento_ate=$vencimento_ate&cliente=$cliente&tipo=$tipo&status=$status&periodo=$periodo");
$this->data['configuration']['total_rows'] = $this->financeiro_model->count('lancamentos', $where);
$this->data['configuration']['page_query_string'] = true;

Expand Down
78 changes: 46 additions & 32 deletions application/views/financeiro/lancamentos.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/js/jquery-ui/css/smoothness/jquery-ui-1.9.2.custom.css" />
<script type="text/javascript" src="<?php echo base_url() ?>assets/js/jquery-ui/js/jquery-ui-1.9.2.custom.js"></script>
<script src="<?php echo base_url() ?>assets/js/sweetalert2.all.min.js"></script>
<script src="<?php echo base_url() ?>assets/js/dayjs.min.js"></script>

<?php $situacao = $this->input->get('situacao');
$periodo = $this->input->get('periodo');
Expand Down Expand Up @@ -32,40 +33,22 @@
<form action="<?php echo current_url(); ?>" method="get">
<div class="span2" style="margin-left: 0">
<label>Período <i class="fas fa-calendar-day tip-top" title="Lançamentos com vencimento no período."></i></label>
<select name="periodo" class="span12">
<option value="dia">Dia</option>
<option value="semana" <?php if ($periodo == 'semana') {
echo 'selected';
} ?>>Semana</option>
<option value="mes" <?php if ($periodo == 'mes') {
echo 'selected';
} ?>>Mês</option>
<option value="ano" <?php if ($periodo == 'ano') {
echo 'selected';
} ?>>Ano</option>
<option value="todos" <?php if ($periodo == 'todos') {
echo 'selected';
} ?>>Todos</option>
<select id="periodo" name="periodo" class="span12">
<option value="dia" <?= $this->input->get('periodo') === 'dia' ? 'selected' : '' ?>>Dia</option>
<option value="semana" <?= $this->input->get('periodo') === 'semana' ? 'selected' : '' ?>>Semana</option>
<option value="mes" <?= $this->input->get('periodo') === 'mes' ? 'selected' : '' ?>>Mês</option>
<option value="ano" <?= $this->input->get('periodo') === 'ano' ? 'selected' : '' ?>>Ano</option>
</select>
</div>

<div class="span2">
<label>Situação <i class="fas fa-sign tip-top" title="Lançamentos com situação específica ou todos."></i></label>
<select name="situacao" class="span12">
<option value="todos">Todos</option>
<option value="previsto" <?php if ($situacao == 'previsto') {
echo 'selected';
} ?>>Previsto</option>
<option value="atrasado" <?php if ($situacao == 'atrasado') {
echo 'selected';
} ?>>Atrasado</option>
<option value="realizado" <?php if ($situacao == 'realizado') {
echo 'selected';
} ?>>Realizado</option>
<option value="pendente" <?php if ($situacao == 'pendente') {
echo 'selected';
} ?>>Pendente</option>
</select>
<label>Vencimento (de) <i class="fas fa-calendar-day tip-top" title="Vencimento (de)"></i></label>
<input id="vencimento_de" type="text" class="span12 datepicker" name="vencimento_de" value="<?= $this->input->get('vencimento_de') ? $this->input->get('vencimento_de') : date('d/m/Y') ?>">
</div>

<div class="span2">
<label>Vencimento (até) <i class="fas fa-calendar-day tip-top" title="Vencimento (até)"></i></label>
<input id="vencimento_ate" type="text" class="span12 datepicker" name="vencimento_ate" value="<?= $this->input->get('vencimento_ate') ? $this->input->get('vencimento_ate') : date('d/m/Y') ?>">
</div>

<div class="span2">
Expand All @@ -77,6 +60,15 @@
</select>
</div>

<div class="span2">
<label>Status <i class="fa fa-file-signature tip-top" title="Tipo."></i></label>
<select name="status" class="span12">
<option value="">Todos</option>
<option value="0" <?= $this->input->get('status') === '0' ? 'selected' : '' ?>>Pendente</option>
<option value="1" <?= $this->input->get('status') === '1' ? 'selected' : '' ?>>Pago</option>
</select>
</div>

<div class="span2">
<label>Cliente <i class="fas fa-user tip-top" title="Cliente."></i></label>
<input type="text" class="span12" name="cliente" value="<?= $this->input->get('cliente') ?>">
Expand Down Expand Up @@ -120,8 +112,8 @@

if (!$results) {
echo '<tr>
<td colspan="8" >Nenhum lançamento encontrado</td>
</tr>';
<td colspan="8" >Nenhum lançamento encontrado</td>
</tr>';
}
foreach ($results as $r) {
$vencimento = date(('d/m/Y'), strtotime($r->data_vencimento));
Expand Down Expand Up @@ -582,5 +574,27 @@
dateFormat: 'dd/mm/yy'
});

$('#periodo').on('change', function(event) {
const period = $('#periodo').val();

switch (period) {
case 'dia':
$('#vencimento_de').val(dayjs().locale('pt-br').format('DD/MM/YYYY'));
$('#vencimento_ate').val(dayjs().locale('pt-br').format('DD/MM/YYYY'));
break;
case 'semana':
$('#vencimento_de').val(dayjs().startOf('week').locale('pt-br').format('DD/MM/YYYY'));
$('#vencimento_ate').val(dayjs().endOf('week').locale('pt-br').format('DD/MM/YYYY'));
break;
case 'mes':
$('#vencimento_de').val(dayjs().startOf('month').locale('pt-br').format('DD/MM/YYYY'));
$('#vencimento_ate').val(dayjs().endOf('month').locale('pt-br').format('DD/MM/YYYY'));
break;
case 'ano':
$('#vencimento_de').val(dayjs().startOf('year').locale('pt-br').format('DD/MM/YYYY'));
$('#vencimento_ate').val(dayjs().endOf('year').locale('pt-br').format('DD/MM/YYYY'));
break;
}
});
});
</script>
1 change: 1 addition & 0 deletions assets/js/dayjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de6006b

Please sign in to comment.