File: D:/HostingSpaces/MDalebout3/prdct.nl/wwwroot/timesheet/pdf.php
<?php session_start();
date_default_timezone_set('Europe/Amsterdam');
setlocale(LC_ALL, 'nl_NL');
require_once('includes/pdf/fpdf.php');
require_once('includes/adodb5/adodb.inc.php');
require_once('includes/settings.php');
require_once('includes/functions_db.php');
// ********************************
// Open database connection *
// ********************************
$db = ADONewConnection($driver);
$db->debug = FALSE;
$db->Connect($server, $user, $password, $database);
// ********************************
// Check if parameters are set
// ********************************
if(array_key_exists('month', $_SESSION) and array_key_exists('project', $_GET) and array_key_exists('current_user_id', $_SESSION)) {
if(is_numeric($_SESSION['month']) and is_numeric($_GET['project']) and is_numeric($_SESSION['current_user_id'])) {
$maand = $_SESSION['month'];
$project_id = $_GET['project'];
$current_user_id = $_SESSION['current_user_id'];
$sql_project = '
select klantnaam
, bedrijfsonderdeel
, contactpersoon
, project_naam
, project_code
, procuratiehouder
, project_annotatie
from uur_projecten
where project_id = '.$project_id
;
SetLanguage($db);
$sql_uren = '
select p.project_naam
, day(k.datum) as dag
, dayofweek(k.datum) as weekdag
, date_format(k.datum, \'%a\') as dagvdweek
, date_format(k.datum, \'%w\') as dagnr
, u.aantal_uur
from uur_kalender k
left join uur_maandstaat u
on k.kalender_id = u.kalender_id
and u.project_id = '.$project_id.'
and u.gebruikers_id = '.$current_user_id.'
left join uur_projecten p
on u.project_id = p.project_id
where year(k.datum)*100+month(k.datum) = '.$maand.'
order by k.datum
'
;
$sql_gebruikers = '
select gebruikers_naam
from uur_gebruikers
where gebruikers_id = '.$current_user_id
;
SetLanguage($db);
$sql_maand = '
select concat(ucase(substring(date_format(k.datum, \'%M\'), 1, 1)), lower(substring(date_format(k.datum, \'%M\'), 2))) as maandnaam
, date_format(k.datum, \'%Y\') as jaar
from uur_kalender k
where year(k.datum)*100+month(k.datum) = '.$maand.'
group by date_format(k.datum, \'%M\')
, date_format(k.datum, \'%Y\')
'
;
$projecten = ReturnData($sql_project, $db);
$rows = ReturnData($sql_uren, $db);
$gebruiker = ReturnData($sql_gebruikers, $db);
$maand = ReturnData($sql_maand, $db);
$pdf=new FPDF('L','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','',10);
$pdf->SetLineWidth(0.05);
$pdf->Image('style/logo_freefrogs_print.png',15,7,30,17.1186,'png');
$pdf->SetX(250);
$pdf->SetFontSize(14);
$pdf->Cell(100, 17.6,'Maandstaat');
$pdf->Ln();
$pdf->SetFontSize(10);
$pdf->SetDrawColor(150);
// header van de sheet met projectgegevens
$projectnaam=$projecten[0][3];
$pdf->Cell(55,5,'Naam klant: ',0,0,'R');
$pdf->Cell(60,5,$projecten[0][0],0,0,'L');
$pdf->Cell(55,5,'Naam consultant: ',0,0,'R');
$pdf->Cell(60,5,$gebruiker[0][0],0,0,'L');
$pdf->Ln();
$pdf->Cell(55,5,'Onderdeel: ',0,0,'R');
$pdf->Cell(60,5,$projecten[0][1],0,0,'L');
$pdf->Cell(55,5,'Maand: ',0,0,'R');
$pdf->Cell(60,5,$maand[0][0],0,0,'L');
$pdf->Ln();
$pdf->Cell(55,5,'Contactpersoon: ',0,0,'R');
$pdf->Cell(60,5,$projecten[0][2],0,0,'L');
$pdf->Cell(55,5,'Jaar: ',0,0,'R');
$pdf->Cell(60,5,$maand[0][1],0,0,'L');
$pdf->Ln();
$pdf->Cell(55,5,'Projectnaam: ',0,0,'R');
$pdf->Cell(60,5,$projecten[0][3],0,0,'L');
$pdf->Ln();
$pdf->Cell(55,5,'Projectcode: ',0,0,'R');
$pdf->Cell(60,5,$projecten[0][4],0,0,'L');
$pdf->Ln();
$pdf->Cell(55,5,'Procuratiehouder: ',0,0,'R');
$pdf->Cell(60,5,$projecten[0][5],0,0,'L');
$pdf->Ln(20);
// regel met dagen van de week
$pdf->SetX(15);
$pdf->Cell(49,5,'',0,0,'C');
$x = 64;
$pdf->SetTextColor(100);
foreach($rows as $row) {
if($row['dagnr'] == 0 or $row['dagnr'] == 6) {
$pdf->SetFillColor(230);
}
else {
$pdf->SetFillColor(255);
}
$pdf->SetX($x);
$pdf->Cell(6,5,$row['dagvdweek'],1,0,'C',TRUE);
$x = 6+$x;
}
$pdf->SetTextColor(0);
$pdf->Ln();
// regel met dagnummer
$x = 64;
$pdf->SetX(15);
$pdf->Cell(49,5,'',0,0,'C');
foreach($rows as $row) {
if($row['dagnr'] == 0 or $row['dagnr'] == 6) {
$pdf->SetFillColor(230);
}
else {
$pdf->SetFillColor(230);
}
$pdf->SetX($x);
$pdf->Cell(6,5,$row['dag'],1,0,'C',TRUE);
$x = 6+$x;
}
$pdf->SetX($x+1);
$pdf->Cell(30,5,'Totaal',1,0,'C',TRUE);
$pdf->Ln();
// regel met uren
$totaal_uur = 0;
$x = 64;
$pdf->SetX(15);
$pdf->Cell(49,5,$projectnaam,1,0,'L');
foreach($rows as $row) {
if($row['dagnr'] == 0 or $row['dagnr'] == 6) {
$pdf->SetFillColor(230);
}
else {
$pdf->SetFillColor(255);
}
$pdf->SetX($x);
$pdf->Cell(6,5,$row['aantal_uur'],1,0,'C',TRUE);
$x = 6+$x;
$totaal_uur = $totaal_uur + $row['aantal_uur'];
}
$pdf->SetX($x+1);
$pdf->Cell(30,5,$totaal_uur.' uur',1,0,'C');
$pdf->Ln(20);
//regel met handtekeningruimte
$pdf->SetX(15);
$pdf->SetFont('Arial','I');
$pdf->Cell(50,5,'Datum:',1,0,'L');
$pdf->SetX(70);
$pdf->Cell(100,5,'Handtekening Consultant:',1,0,'L');
$pdf->SetX(175);
$pdf->Cell(100,5,'Handtekening Klant:',1,0,'L');
$pdf->Ln();
$pdf->SetX(15);
$pdf->SetFont('');
$datum = strftime("%d %B %Y");
$pdf->Cell(50,25,$datum,1,0,'C');
$pdf->SetX(70);
$pdf->Cell(100,25,'',1,0,'L');
$pdf->SetX(175);
$pdf->Cell(100,25,'',1,0,'L');
$pdf->Output('Timesheet.pdf', 'D');
}
}
?>