Example #1
0
 function departa()
 {
     $this->load->library('Graph');
     $data = $titu = array();
     $mes = $this->uri->segment(4);
     $anio = $this->uri->segment(5);
     if (empty($mes) and empty($anio)) {
         return;
     }
     $fechai = $anio . $mes . '01';
     $fechaf = $anio . $mes . '31';
     //8471.49.00.00
     $mSQL = "SELECT f.descrip etiqueta, sum(b.importe) total\n\t\t\tFROM itscst b JOIN scst a ON a.control=b.control \n\t\t\tJOIN sinv c ON b.codigo=c.codigo\n\t\t\tJOIN grup d ON d.grupo=c.grupo\n\t\t\tJOIN line e ON d.linea=e.linea \n\t\t\tJOIN dpto f ON e.depto=f.depto \n\t\t\tWHERE a.tipo_doc IN ('FC', 'NC','NE') AND a.fecha>={$fechai} AND a.fecha<={$fechaf}\n\t\t\tGROUP BY f.depto";
     //echo $mSQL;
     $maxval = 0;
     $query = $this->db->query($mSQL);
     foreach ($query->result() as $row) {
         if ($row->total > $maxval) {
             $maxval = $row->total;
         }
         $data[] = $row->total;
         $titu[] = $row->etiqueta;
     }
     $i = 1;
     while (1) {
         if ($maxval / $i <= 100) {
             break;
         }
         $i = $i * 10;
     }
     $om = $i;
     $i = 0;
     //$om=1;
     for ($i = 0; $i < count($data); $i++) {
         $data[$i] = $data[$i] / $om;
     }
     $g = new Graph();
     if ($maxval > 0) {
         $g->title('COMPRAS DEL ' . $mes . '/' . $anio, '{font-size:18px; color: #d01f3c}');
         $g->set_data($data);
         $g->bar_glass(55, '#5E83BF', '#424581', 'Compras', 10);
         $g->set_y_max(ceil($maxval / $om));
         $g->y_label_steps(5);
         $g->set_x_labels($titu);
         $ejey = number_format($om, 0, '', ' ');
         $g->set_y_legend('Compras X ' . $ejey . ' (Bs)', 14, '0x639F45');
         $g->set_x_legend('Grupos ' . $mes, 14, '0x639F45');
         //$g->pie(60,'#505050','#000000');
         //$g->pie_values( $data, $titu );
         //$g->pie_slice_colours( array('#d01f3c','#356aa0','#C79810','#5E83BF'));
         $g->set_tool_tip('#key#<br>Departamento: #x_label# <br>Monto: #val# x ' . $ejey);
     } else {
         $g->title('NO EXISTEN VENTAS EN LA FECHA SELECCIONADA', '{font-size:18px; color: #d01f3c}');
     }
     $g->bg_colour = '#FFFFFF';
     //$g->set_bg_image(site_url('/images/ventafon.png'), 'center', 'middle' );
     echo $g->render();
     $query->free_result();
 }