Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Tenho a seguinte tabela:
-- phpMyAdmin SQL Dump
-- version 3.3.9
-- http://www.phpmyadmin.net
--
-- Servidor: localhost
-- Tempo de Geração: Jul 09, 2013 as 12:48 AM
-- Versão do Servidor: 5.5.8
-- Versão do PHP: 5.3.5
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Banco de Dados: base
--
-- --------------------------------------------------------
--
-- Estrutura da tabela horas
--
DROP TABLE IF EXISTS `horas`;
CREATE TABLE IF NOT EXISTS `horas` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nrfunc` int(7) NOT NULL,
`data` date NOT NULL,
`diames` int(2) NOT NULL,
`semana` int(2) NOT NULL,
`hi` datetime NOT NULL,
`ht` datetime NOT NULL,
`total` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ;
--
-- Extraindo dados da tabela horas
--
INSERT INTO horas (id, nrfunc, data, diames, semana, hi, ht, total) VALUES
(1, 9288, '2013-06-01', 1, 22, '2013-06-01 08:30:00', '2013-06-01 13:00:00', '4.5'),
(2, 9288, '2013-06-02', 2, 23, '2013-06-02 08:30:00', '2013-06-02 18:00:00', '9.5'),
(3, 9288, '2013-06-19', 19, 25, '2013-06-19 08:30:00', '2013-06-19 18:00:00', '9.5'),
(4, 9288, '2013-06-04', 4, 23, '2013-06-04 08:30:00', '2013-06-04 18:00:00', '9.5'),
(5, 9288, '2013-06-05', 5, 23, '2013-06-05 08:30:00', '2013-06-05 18:00:00', '9.5'),
(6, 9288, '2013-06-06', 6, 23, '2013-06-06 08:30:00', '2013-06-06 18:00:00', '9.5'),
(7, 9288, '2013-06-07', 7, 23, '2013-06-07 08:30:00', '2013-06-07 18:00:00', '9.5'),
(8, 9288, '2013-06-08', 8, 23, '2013-06-08 08:30:00', '2013-06-08 18:00:00', '9.5'),
(9, 9288, '2013-06-09', 9, 24, '2013-06-09 08:30:00', '2013-06-09 18:00:00', '9.5'),
(10, 9288, '2013-06-10', 10, 24, '2013-06-10 08:30:00', '2013-06-10 18:00:00', '9.5'),
(11, 9288, '2013-06-11', 11, 24, '2013-06-11 08:30:00', '2013-06-11 18:00:00', '9.5'),
(12, 9288, '2013-06-15', 15, 24, '2013-06-15 08:30:00', '2013-06-15 18:00:00', '9.5'),
(13, 9288, '2013-06-16', 16, 25, '2013-06-16 14:00:00', '2013-06-16 20:00:00', '6'),
(14, 9288, '2013-06-16', 16, 25, '2013-06-16 14:00:00', '2013-06-16 20:00:00', '6'),
(15, 9288, '2013-06-18', 18, 25, '2013-06-18 14:00:00', '2013-06-18 20:00:00', '6'),
(16, 9288, '2013-06-19', 19, 25, '2013-06-19 14:00:00', '2013-06-19 20:00:00', '6'),
(17, 9288, '2013-06-20', 20, 25, '2013-06-20 14:00:00', '2013-06-20 20:00:00', '6'),
(18, 9288, '2013-06-22', 22, 25, '2013-06-22 14:00:00', '2013-06-22 20:00:00', '6'),
(19, 9288, '2013-06-23', 23, 25, '2013-06-23 14:00:00', '2013-06-23 20:00:00', '6'),
(20, 9288, '2013-06-24', 24, 25, '2013-06-24 14:00:00', '2013-06-24 20:00:00', '6'),
(21, 1955, '2013-06-02', 2, 23, '2013-06-02 07:00:00', '2013-06-02 19:00:00', '12'),
(22, 1955, '2013-06-03', 3, 23, '2013-06-03 19:00:00', '2013-06-04 07:00:00', '12'),
(23, 1955, '2013-06-06', 6, 23, '2013-06-06 07:00:00', '2013-06-06 19:00:00', '12'),
(24, 1955, '2013-06-07', 7, 23, '2013-06-07 19:00:00', '2013-06-08 07:00:00', '12'),
(25, 1955, '2013-06-10', 10, 24, '2013-06-10 07:00:00', '2013-06-10 19:00:00', '12'),
(26, 1955, '2013-06-11', 11, 24, '2013-06-11 19:00:00', '2013-06-12 07:00:00', '12'),
(27, 1955, '2013-06-14', 14, 24, '2013-06-14 07:00:00', '2013-06-14 19:00:00', '12'),
(28, 1955, '2013-06-15', 15, 24, '2013-06-15 19:00:00', '2013-06-16 07:00:00', '12'),
(29, 1955, '2013-06-18', 18, 25, '2013-06-18 07:00:00', '2013-06-18 19:00:00', '12'),
(30, 1955, '2013-06-19', 19, 25, '2013-06-19 19:00:00', '2013-06-20 07:00:00', '12'),
(33, 5181, '2013-06-07', 7, 23, '2013-06-07 08:30:00', '2013-06-07 18:00:00', '9.5'),
(34, 9288, '2013-06-25', 25, 25, '2013-06-25 14:00:00', '2013-06-25 20:00:00', '6');
É possível com base na tabela acima montar um relatório igual ao da imagem abaixo:
/applications/core/interface/imageproxy/imageproxy.php?img=http://imageshack.us/a/img15/9045/n0gc.png&key=a648e8652aced0d132619fda3715f557389032b91bf6c87150b30b2d6551bd67" alt="n0gc.png" />
A idéia é mostrar as horas trabalhadas por dia durante o mes com subtotal por semana de todos os funcionários.
Com o código abaixo eu tenho parte do resultado que preciso. Será que tem como adaptar?
nrfunc AS FUNCIONARIO, SUM(IF(diames = '1',total,0)) AS '1', SUM(IF(diames = '2',total,0)) AS '2', SUM(IF(diames = '3',total,0)) AS '3', SUM(IF(diames = '4',total,0)) AS '4', SUM(IF(diames = '5',total,0)) AS '5', SUM(IF(diames = '6',total,0)) AS '6', SUM(IF(diames = '7',total,0)) AS '7', SUM(IF(diames = '8',total,0)) AS '8', SUM(IF(diames = '9',total,0)) AS '9', SUM(IF(diames = '10',total,0)) AS '10', SUM(IF(diames = '11',total,0)) AS '11', SUM(IF(diames = '12',total,0)) AS '12', SUM(IF(diames = '13',total,0)) AS '13', SUM(IF(diames = '14',total,0)) AS '14', SUM(IF(diames = '15',total,0)) AS '15', SUM(IF(diames = '16',total,0)) AS '16', SUM(IF(diames = '17',total,0)) AS '17', SUM(IF(diames = '18',total,0)) AS '18', SUM(IF(diames = '19',total,0)) AS '19', SUM(IF(diames = '20',total,0)) AS '20', SUM(IF(diames = '21',total,0)) AS '21', SUM(IF(diames = '22',total,0)) AS '22', SUM(IF(diames = '23',total,0)) AS '23', SUM(IF(diames = '24',total,0)) AS '24', SUM(IF(diames = '25',total,0)) AS '25', SUM(IF(diames = '26',total,0)) AS '26', SUM(IF(diames = '27',total,0)) AS '27', SUM(IF(diames = '28',total,0)) AS '28', SUM(IF(diames = '29',total,0)) AS '29', SUM(IF(diames = '30',total,0)) AS '30', SUM(IF(diames = '31',total,0)) AS '31', SUM(COALESCE(total,0)) as 'TOTAL' FROM horas GROUP BY 1// montando o header da tabela
$header = array();
for($i=0, $total=mysql_num_fields($rs); $i<$total; $i++){
// montando as demais linhas da tabela
$html = '';
while($row = mysql_fetch_assoc($rs)){
if($key == 'FUNCIONARIO' && is_null($value)){
}else{
// exibindo a tabela final
Créditos de hufersil
Dando um up só pra não cair no esquecimento...
Dá pra aproveitar o código acima? Alguém tem alguma dica?