<?php 
 require('../../fpdf/fpdf.php');
 include('../../config.php');

if(isset($_GET['id_ord'])){
date_default_timezone_set('Africa/Algiers');
$d_aj=date('d-m-Y');
$id_ord=$_GET['id_ord'];
$id_patient=$_GET['id_patient'];
  $req_get_p="SELECT *  FROM patients as p where  p.id='$id_patient'";
              $query_get_p=mysqli_query($con,$req_get_p);
              $row_p= mysqli_fetch_array($query_get_p); 
              $nom_patient=$row_p['nom'];
              $prenom_patient=$row_p['prenom'];
              $date_naiss=new DateTimeImmutable($row_p['date_naissance']);
              $date_naissance=date_format($date_naiss,'d-m-Y');
$req_sql_ord= "SELECT o.id_ord,nom_med,quantite,posologie FROM ordonnances as o,medicaments as m, ordonnance_medicament as om  
     WHERE o.id_ord=om.id_ord and  m.id_medicament=om.id_med and o.id_ord='$id_ord'"; 
      $result_ord= mysqli_query($con,$req_sql_ord);
      //$row_ord= mysqli_fetch_array($result_ord);           
              $total = mysqli_num_rows($result_ord);
$pdf = new FPDF('P','mm','A5');
$pdf->AddPage();
$pdf->Image('../../assets/img/logo.png', 20, 10, 40,25);
$X=80;
$Y=10;
$pdf->SetXY($X,$Y);
$pdf->SetFont('Arial','B','18');
$pdf->SetTextColor(27,74,209);
$pdf->Cell('0','10','ALGERMED','0','c');
$pdf->SetFont('Arial','','11');
$pdf->SetTextColor(27,74,209);
$X=90;
$Y=20;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','DR.BENNABES','0','c');
$X=90;
$Y=25;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Cabinet de pediatrie','0','c');
$X=90;
$Y=30;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','C.R.O 8241 / TZO','0','c');
$pdf->SetFont('Arial','','12');
$X=80;
$Y=35;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Cite 1406 logement batiment 25','0','c');
$X=80;
$Y=40;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','35000 Boumerdes, Algerie','0','c');
$X=90;
$Y=45;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','+213 555 199 879','0','c');
$X=90;
$Y=50;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','info@algermed.com','0','c');
$X=90;
$Y=55;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','www.algermed.com','0','c');
$pdf->SetFont('Arial','','12');
$X=10;
$Y=35;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Boumerdes,le:','0');
$X=40;
$Y=35;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10',$d_aj,'0');
$pdf->Ln(3);
$X=10;
$Y=43;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Nom:','0','C');
$X=25;
$Y=43;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10',$nom_patient,'0','C');
$pdf->Ln(1);
$X=10;
$Y=51;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Prenom:','0','C');
$X=30;
$Y=51;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10',$prenom_patient,'0','C');
$pdf->Ln(5);
$X=10;
$Y=58;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Date de naissance:','0','C');
$X=47;
$Y=58;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10',$date_naissance,'0','C');
$pdf->Ln(50);
$X=47;
$Y=80;
$pdf->SetXY($X,$Y);
$pdf->SetFont('Arial','B','25');
$pdf->Cell('0','10','Ordonnance','0','C');
$pdf->Ln(10);
//Initialize the 3 columns and the total
$column_nom_med = "";
$column_quantite = "";
$column_posologie = "";
$pdf->SetFillColor(232,232,232);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',12);
//Create a new PDF file
//Fields Name position
$Y_Fields_Name_position = 100;
//Table position, under Fields Name
$Y_Table_Position = 106;
//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetTextColor(0,0,0);
//Bold Font for Field Name
$pdf->SetFont('Arial','BI',12);
$pdf->SetY($Y_Fields_Name_position);
$pdf->Cell(60,6,'Medicament',1,0,'c',1);
$pdf->Cell(40,6,'Quantite',1,0,'c',1);
$pdf->Cell(30,6,'Posologie',1,0,'R',1);
$pdf->Ln();
$pdf->SetTextColor(0,0,0);
//Bold Font for Field Name
$pdf->SetFont('Arial','I',12);
while($item = mysqli_fetch_array($result_ord)){    
	$pdf->Cell(60	,6,$item['nom_med'],1,0);
    	$pdf->Cell(40	,6,$item['quantite'],1,0);
	
	$pdf->Cell(30	,6,$item['posologie'],1,1,'R');//end of line
}
$pdf->Output();
}
?>

