Skip to content

Instantly share code, notes, and snippets.

@mvnp
Created June 30, 2017 12:22
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 mvnp/ae45ca2d3b80eb4db18878dbda7a0fb1 to your computer and use it in GitHub Desktop.
Save mvnp/ae45ca2d3b80eb4db18878dbda7a0fb1 to your computer and use it in GitHub Desktop.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome4 extends CI_Controller {
/**
* Gera a tabela de valores sem os nomes das naturezas e
* foi inserido as colunas de PACOTE e NATUREZA no início
* e implementado a possível ordenação por orden alfabética
* de naturezas ou possível ordenação por ordem alfabética
* de pacotes ...
* @return [type] [description]
*/
public function index(){
$this->load->view('welcome_message');
}
private function QueryValores(){
$sql = "SELECT SUM(LANC_VALOR) AS VALOR, LANC_NAT_ID, natureza.NAT_DESCRICAO AS NAT_DESCRICAO, pacote.PCT_DESCRICAO AS PCT_DESCRICAO FROM meuslancamentos INNER JOIN natureza ON meuslancamentos.LANC_NAT_ID = natureza.NAT_ID INNER JOIN pacote ON pacote.PCT_ID = natureza.NAT_PCT_ID GROUP BY LANC_NAT_ID, LANC_DT_PAGTO ORDER BY PCT_ID ASC, LANC_DT_PAGTO ASC";
$result = $this->db->query($sql)->result_array();
/*echo "<pre>";
print_r($result);
echo "</pre>";*/
return $result;
}
private function GetCats(){
$sql = "SELECT NAT_ID FROM natureza";
$result = $this->db->query($sql)->num_rows();
return $result;
}
public function table(){
$array = $this->QueryValores();
$countRows = count($array);
$countCats = $this->GetCats();
echo "<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<title>Document</title>
<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" />
</head>
<body class=\"container\" style=\"width:120%!important\">
<h1>Tabela de Somatória de Lançamentos</h1>
<table class=\"table table-bordered table-striped\">
<thead>
<tr>
<td>PACOTE</td>
<td>NATUREZA</td>
<td>JAN</td>
<td>FEV</td>
<td>MAR</td>
<td>ABR</td>
<td>MAI</td>
<td>JUN</td>
<td>JUL</td>
<td>AGO</td>
<td>SET</td>
<td>OUT</td>
<td>NOV</td>
<td>DEZ</td>
<td>TOTAL</td>
<td>MEDIA</td>
</tr>
</thead>
<tbody>
<tr>";
$count = 0;
foreach ($array as $indice) {
$count++;
if($count == 0 OR ($count % 12 == 0)){
echo "<td>{$indice['VALOR']}</td></tr>";
} else {
if($count % 12 == 1) { echo "<td>{$indice['PCT_DESCRICAO']}</td>"; }
if($count % 12 == 1) { echo "<td>{$indice['NAT_DESCRICAO']}</td>"; }
echo "<td>{$indice['VALOR']}</td>";
}
}
echo "</tbody>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment