Skip to content

Commit

Permalink
Merge pull request #699 from RamonSilva20/fix/financial-postings
Browse files Browse the repository at this point in the history
Fix/financial postings
  • Loading branch information
Pr3d4dor authored Apr 30, 2020
2 parents ebea359 + 3ed86ba commit 9d7b9b4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 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.6.2] - 2020-04-29

### Fixed
- Corrigido total de receitas, despesas e saldo em lançamentos financeiros. [@Pr3d4dor](https://github.com/Pr3d4dor)

## [4.6.1] - 2020-04-28

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

/**
* Nome do sistema
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Financeiro.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function lancamentos()
$this->pagination->initialize($this->data['configuration']);

$this->data['results'] = $this->financeiro_model->get('lancamentos', '*', $where, $this->data['configuration']['per_page'], $this->input->get('per_page'));
$this->data['totals'] = $this->financeiro_model->getTotals($where);

$this->data['view'] = 'financeiro/lancamentos';
return $this->layout();
Expand Down
39 changes: 27 additions & 12 deletions application/models/Financeiro_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

class Financeiro_model extends CI_Model
{

/**
* author: Ramon Silva
* email: silva018-mg@yahoo.com.br
*
*/

public function __construct()
{
parent::__construct();
}


public function get($table, $fields, $where = '', $perpage = 0, $start = 0, $one = false, $array = 'array')
{
$this->db->select($fields);
Expand All @@ -26,31 +26,46 @@ public function get($table, $fields, $where = '', $perpage = 0, $start = 0, $one
if ($where) {
$this->db->where($where);
}

$query = $this->db->get();

$result = !$one ? $query->result() : $query->row();

$result = !$one ? $query->result() : $query->row();

return $result;
}

public function getTotals($where = '')
{
$this->db->select("
SUM(case when tipo = 'despesa' then valor end) as despesas,
SUM(case when tipo = 'receita' then valor end) as receitas
");
$this->db->from('lancamentos');

if ($where) {
$this->db->where($where);
}

return (array) $this->db->get()->row();
}

public function getById($id)
{
$this->db->where('idClientes', $id);
$this->db->limit(1);
return $this->db->get('clientes')->row();
}

public function add($table, $data)
{
$this->db->insert($table, $data);
if ($this->db->affected_rows() == '1') {
return true;
}

return false;
}

public function edit($table, $data, $fieldID, $ID)
{
$this->db->where($fieldID, $ID);
Expand All @@ -59,18 +74,18 @@ public function edit($table, $data, $fieldID, $ID)
if ($this->db->affected_rows() >= 0) {
return true;
}

return false;
}

public function delete($table, $fieldID, $ID)
{
$this->db->where($fieldID, $ID);
$this->db->delete($table);
if ($this->db->affected_rows() == '1') {
return true;
}

return false;
}

Expand Down
11 changes: 3 additions & 8 deletions application/views/financeiro/lancamentos.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@
<td colspan="8" >Nenhum lançamento encontrado</td>
</tr>';
}
$totalReceita = 0;
$totalDespesa = 0;
$saldo = 0;
foreach ($results as $r) {
$vencimento = date(('d/m/Y'), strtotime($r->data_vencimento));
if ($r->baixado == 0) {
Expand All @@ -121,10 +118,8 @@
};
if ($r->tipo == 'receita') {
$label = 'success';
$totalReceita += $r->valor;
} else {
$label = 'important';
$totalDespesa += $r->valor;
}
echo '<tr>';
echo '<td>' . $r->idLancamentos . '</td>';
Expand Down Expand Up @@ -153,15 +148,15 @@
<tfoot>
<tr>
<td colspan="6" style="text-align: right; color: green"> <strong>Total Receitas:</strong></td>
<td colspan="3" style="text-align: left; color: green"><strong>R$ <?php echo number_format($totalReceita, 2, ',', '.') ?></strong></td>
<td colspan="3" style="text-align: left; color: green"><strong>R$ <?php echo number_format($totals['receitas'], 2, ',', '.') ?></strong></td>
</tr>
<tr>
<td colspan="6" style="text-align: right; color: red"> <strong>Total Despesas:</strong></td>
<td colspan="3" style="text-align: left; color: red"><strong>R$ <?php echo number_format($totalDespesa, 2, ',', '.') ?></strong></td>
<td colspan="3" style="text-align: left; color: red"><strong>R$ <?php echo number_format($totals['despesas'], 2, ',', '.') ?></strong></td>
</tr>
<tr>
<td colspan="6" style="text-align: right"> <strong>Saldo:</strong></td>
<td colspan="3" style="text-align: left;"><strong>R$ <?php echo number_format($totalReceita - $totalDespesa, 2, ',', '.') ?></strong></td>
<td colspan="3" style="text-align: left;"><strong>R$ <?php echo number_format($totals['receitas'] - $totals['despesas'], 2, ',', '.') ?></strong></td>
</tr>
</tfoot>
</table>
Expand Down

0 comments on commit 9d7b9b4

Please sign in to comment.