
LiLFinger
|
<?php
require('fpdf/fpdf.php');
?>
<?php
include('connect.php') ;
$id_det_aff=$_GET['id_det_aff'] ;
$req_info=mysql_query("select * from detail_affaires where id_det_affaire =$id_det_aff ") or die ('Impossible de recuperer les informations de cette page! ');
$rep_info=mysql_fetch_assoc($req_info) ;
$idaff_=$rep_info['id_affaire'];
$lelast=$rep_info['id_devis'];
$code_devis=$rep_info['code_det_devis'];
$id_fact=$rep_info['id_fact'];
$id_rent=$rep_info['id_rentabilite'];
// $requetes="select * from facture where id_facture=$id_fact and id_devis=$lelast";
//$ok=mysql_query($requetes) ;
$sql2="select * from facture where id_facture=$id_fact and id_devis=$lelast ";
$ok2=mysql_query($sql2) or die (mysql_error());
$data2 = mysql_fetch_assoc($ok2);
$code_facture=$data2["code_facture"];
$id_devis=$data2["id_devis"];
$code_det_devis=$data2["code_det_devis"];
$date_facture=$data2["date_facture"];
$montant_total_htva=$data2["montant_total_htva"];
$remise_comm=$data2["remise_comm"];
$montant_remise=$data2["montant_remise"];
$new_mt_htva=$data2["new_montant_htva"];
$montant_tva=$data2["montant_tva"];
$total_ttc=$data2["total_ttc"];
$tva=$data2["tva"];
$type=$data2["type"];
$id_user=$data2["id_user"];
$date_last_modif=$data2["date_last_modif"];
$sql="select * from devis where id_devis=$lelast";
$ok=mysql_query($sql) or die (mysql_error());
$donnees = mysql_fetch_assoc($ok);
$code_devis=$donnees["code_devis"];
$leclient=$donnees["nom_client"];
$objet_devis=$donnees["objet_devis"];
$date_creation=$donnees["date_creation"];
$date_validite=$donnees["date_validite"];
$delai_livraison=$donnees["delai_livraison"];
$delai_reception=$donnees["delai_reception"];
$condition_reglement=utf8_encode($donnees["condition_reglement"]);
$remarques=$donnees["remarque_devis"];
$a_lattention=$donnees["a_lattention"];
$idaffaire=$donnees["id_affaire"];
$id_user=$donnees["id_user"];
$query_disp="SELECT * FROM affaires where id_affaire=".$idaff_;
$result_disp = mysql_query($query_disp) ;
$query_data = mysql_fetch_assoc($result_disp) or die ('Table Affaire Innaccessible') ;
$code_affaire=$query_data["code_affaire"] ;
$nom_affaire=$query_data["nom_affaire"] ;
$client=$query_data["client"] ;
$date_ouverture=$query_data["date_ouverture"] ;
$etape_real=$query_data["etape_realisation"] ;
$sql1="select * from rentabilite where id_affaire=".$idaff_;
$ok1=mysql_query($sql1) or die (mysql_error());
$data = mysql_fetch_assoc($ok1);
$pourc_vend_acs=$data["pourc_vend_acs"];
$val_vend_acs=$data["val_vend_acs"];
$pourc_vend_arc=$data["pourc_vend_arc"];
$val_vend_arc=$data["val_vend_arc"];
$pourc_arc=$data["pourc_arc"];
$val_comm_arc=$data["val_comm_arc"];
$pourc_marge_avant_comm=$data["pourc_marge_avant_comm"];
$val_marge_avant_comm=$data["val_marge_avant_comm"];
$pourc_marge_finale_acs=$data["pourc_marge_finale_acs"];
$val_marge_final_acs=$data["val_marge_final_acs"];
class PDF extends FPDF
{
var $B;
var $I;
var $U;
var $HREF;
function PDF($orientation='P',$unit='mm',$format='A4')
{
//Call parent constructor
$this->FPDF($orientation,$unit,$format);
//Initialization
$this->B=0;
$this->I=0;
$this->U=0;
$this->HREF='';
}
//***********
function WriteTable($data, $w)
{
$this->SetLineWidth(.3);
$this->SetFillColor(255,255,255);
$this->SetTextColor(0);
$this->SetFont('');
foreach($data as $row)
{
$nb=0;
for($i=0;$i<count($row);$i++)
$nb=max($nb,$this->NbLines($w[$i],trim($row[$i])));
$h=5*$nb;
$this->CheckPageBreak($h);
for($i=0;$i<count($row);$i++)
{
$x=$this->GetX();
$y=$this->GetY();
$this->Rect($x,$y,$w[$i],$h);
$this->MultiCell($w[$i],5,trim($row[$i]),0,'C');
//Put the position to the right of the cell
$this->SetXY($x+$w[$i],$y);
}
$this->Ln($h);
}
}
function CheckPageBreak($h)
{
//If the height h would cause an overflow, add a new page immediately
if($this->GetY()+$h>$this->PageBreakTrigger)
$this->AddPage($this->CurOrientation);
}
function ReplaceHTML($html)
{
$html = str_replace( '<li>', "\n<br> - " , $html );
$html = str_replace( '<LI>', "\n - " , $html );
$html = str_replace( '</ul>', "\n\n" , $html );
$html = str_replace( '<strong>', "<b>" , $html );
$html = str_replace( '</strong>', "</b>" , $html );
$html = str_replace( ' ', "\n" , $html );
$html = str_replace( ' ', " " , $html );
$html = str_replace( '"', "\"" , $html );
$html = str_replace( ''', "'" , $html );
return $html;
}
function ParseTable($Table)
{
$_var='';
$htmlText = $Table;
$parser = new HtmlParser ($htmlText);
while ($parser->parse())
{
if(strtolower($parser->iNodeName)=='table')
{
if($parser->iNodeType == NODE_TYPE_ENDELEMENT)
$_var .='/::';
else
$_var .='::';
}
if(strtolower($parser->iNodeName)=='tr')
{
if($parser->iNodeType == NODE_TYPE_ENDELEMENT)
$_var .='!-:'; //opening row
else
$_var .=':-!'; //closing row
}
if(strtolower($parser->iNodeName)=='td' && $parser->iNodeType == NODE_TYPE_ENDELEMENT)
{
$_var .='#,#';
}
if ($parser->iNodeName=='Text' && isset($parser->iNodeValue))
{
$_var .= $parser->iNodeValue;
}
}
$elems = explode(':-!',str_replace('/','',str_replace('::','',str_replace('!-:','',$_var)))); //opening row
foreach($elems as $key=>$value)
{
if(trim($value)!='')
{
$elems2 = explode('#,#',$value);
array_pop($elems2);
$data[] = $elems2;
}
}
return $data;
}
//**************
function WriteHTML($html)
{
//HTML parser
$html=str_replace("\n",' ',$html);
$a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
foreach($a as $i=>$e)
{
if($i%2==0)
{
//Text
if($this->HREF)
$this->PutLink($this->HREF,$e);
else
$this->Write(5,$e);
}
else
{
//Tag
if($e{0}=='/')
$this->CloseTag(strtoupper(substr($e,1)));
else
{
//Extract attributes
$a2=explode(' ',$e);
$tag=strtoupper(array_shift($a2));
$attr=array();
foreach($a2 as $v)
if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
$attr[strtoupper($a3[1])]=$a3[2];
$this->OpenTag($tag,$attr);
}
}
}
}
function OpenTag($tag,$attr)
{
//Opening tag
if($tag=='B' or $tag=='I' or $tag=='U')
$this->SetStyle($tag,true);
if($tag=='A')
$this->HREF=$attr['HREF'];
if($tag=='BR')
$this->Ln(5);
}
function CloseTag($tag)
{
//Closing tag
if($tag=='B' or $tag=='I' or $tag=='U')
$this->SetStyle($tag,false);
if($tag=='A')
$this->HREF='';
}
function SetStyle($tag,$enable)
{
//Modify style and select corresponding font
$this->$tag+=($enable ? 1 : -1);
$style='';
foreach(array('B','I','U') as $s)
if($this->$s>0)
$style.=$s;
$this->SetFont('',$style);
}
function PutLink($URL,$txt)
{
//Put a hyperlink
$this->SetTextColor(0,0,255);
$this->SetStyle('U',true);
$this->Write(5,$txt,$URL);
$this->SetStyle('U',false);
$this->SetTextColor(0);
}
function Footer()
{
$this->SetTextColor(0,0,0);
$this->SetDrawColor(0,80,180);
//$this->Ln();
//$this->Ln();
//$this->Ln();
//$this->Ln();
$this->Sety(-5);
//$this->Line(00, 190, 300, 190);
$this->SetFont('Arial','',8);
$nbre='{nb}' ;
//$this->Cell(0,5,'Page '.$this->PageNo().' sur {nb}',0,2,'C');
$this->Cell(0,5,'Page '.$this->PageNo().' sur '.$nbre,0,2,'C');
}
//fonction foot
function Pieds()
{
$id_det_aff=$_GET['id_det_aff'] ;
$req_info=mysql_query("select * from detail_affaires where id_det_affaire =$id_det_aff ") or die ('Impossible de recuperer les informations de cette page! ');
$rep_info=mysql_fetch_assoc($req_info) ;
$idaff_=$rep_info['id_affaire'];
$lelast=$rep_info['id_devis'];
$code_devis=$rep_info['code_det_devis'];
$id_fact=$rep_info['id_fact'];
$id_rent=$rep_info['id_rentabilite'];
// $requetes="select * from facture where id_facture=$id_fact and id_devis=$lelast";
//$ok=mysql_query($requetes) ;
$sql2="select * from facture where id_facture=$id_fact and id_devis=$lelast ";
$ok2=mysql_query($sql2) or die (mysql_error());
$data2 = mysql_fetch_assoc($ok2);
$code_facture=$data2["code_facture"];
$id_devis=$data2["id_devis"];
$code_det_devis=$data2["code_det_devis"];
$date_facture=$data2["date_facture"];
$montant_total_htva=$data2["montant_total_htva"];
$remise_comm=$data2["remise_comm"];
$montant_remise=$data2["montant_remise"];
$new_mt_htva=$data2["new_montant_htva"];
$montant_tva=$data2["montant_tva"];
$total_ttc=$data2["total_ttc"];
$tva=$data2["tva"];
$type=$data2["type"];
$id_user=$data2["id_user"];
$date_last_modif=$data2["date_last_modif"];
$sql="select * from devis where id_devis=$lelast";
$ok=mysql_query($sql) or die (mysql_error());
$donnees = mysql_fetch_assoc($ok);
$code_devis=$donnees["code_devis"];
$leclient=$donnees["nom_client"];
$objet_devis=$donnees["objet_devis"];
$date_creation=$donnees["date_creation"];
$date_validite=$donnees["date_validite"];
$delai_livraison=$donnees["delai_livraison"];
$delai_reception=$donnees["delai_reception"];
$condition_reglement=utf8_encode($donnees["condition_reglement"]);
$remarques=$donnees["remarque_devis"];
$a_lattention=$donnees["a_lattention"];
$idaffaire=$donnees["id_affaire"];
$id_user=$donnees["id_user"];
$query_disp="SELECT * FROM affaires where id_affaire=".$idaff_;
$result_disp = mysql_query($query_disp) ;
$query_data = mysql_fetch_assoc($result_disp) or die ('Table Affaire Innaccessible') ;
$code_affaire=$query_data["code_affaire"] ;
$nom_affaire=$query_data["nom_affaire"] ;
$client=$query_data["client"] ;
$date_ouverture=$query_data["date_ouverture"] ;
$etape_real=$query_data["etape_realisation"] ;
$sql1="select * from rentabilite where id_affaire=".$idaff_;
$ok1=mysql_query($sql1) or die (mysql_error());
$data = mysql_fetch_assoc($ok1);
$pourc_vend_acs=$data["pourc_vend_acs"];
$val_vend_acs=$data["val_vend_acs"];
$pourc_vend_arc=$data["pourc_vend_arc"];
$val_vend_arc=$data["val_vend_arc"];
$pourc_arc=$data["pourc_arc"];
$val_comm_arc=$data["val_comm_arc"];
$pourc_marge_avant_comm=$data["pourc_marge_avant_comm"];
$val_marge_avant_comm=$data["val_marge_avant_comm"];
$pourc_marge_finale_acs=$data["pourc_marge_finale_acs"];
$val_marge_final_acs=$data["val_marge_final_acs"];
//$this->SetAutoPageBreak(true, 80);
$this->Sety(193);
$this->SetX(10);
//tableau avec les prix totaux
$this->SetLeftMargin(10);
$this->SetX(10);
$this->Cell(45,8,'Condition de règlement :',1,0,'L');
$this->Cell(75,8,utf8_decode($condition_reglement),1,0,'L');
$this->Cell(5,5,'',0,0,'L');
$this->Cell(35,8,'Total HTVA',1,0,'R');
$this->Cell(35,8,number_format($montant_total_htva ,'0',' ', ' ') .' CFA',1,0,'R');
$this->Ln();
$this->Cell(45,8,'Date Validité du Devis:',1,0,'L');
$this->Cell(75,8,$date_validite,1,0,'L');
$this->Cell(5,8,'',0,0,'L');
$this->Cell(35,8,'REMISE'.'('.$remise_comm .') %:',1,0,'R');
$montant_remise_=number_format($montant_remise,'0',' ', ' ') ;
$this->Cell(35,8,$montant_remise_ .' CFA',1,0,'R');
$this->Ln();
$this->Cell(45,8,'Delai Réception de Materiels :',1,0,'L');
$this->Cell(75,8,$delai_reception,1,0,'L');
$this->Cell(5,5,'',0,0,'L');
$this->Cell(35,8,'TOTAL HTVA:',1,0,'R');
$new_mt_htva_=number_format($new_mt_htva,'0',' ', ' ') ;
$this->Cell(35,8,$new_mt_htva_.' CFA',1,0,'R');
$this->Ln();
$this->Cell(45,8,'Delai de Livraison du Chantier:',1,0,'L');
$this->Cell(75,8,$delai_livraison,1,0,'L');
$this->Cell(5,5,'',0,0,'L');
$montant_tva_=number_format($montant_tva,'0',' ', ' ') ;
$this->Cell(35,8,'TVA('.$tva .')%:',1,0,'R');
$this->Cell(35,8,$montant_tva_ .' CFA',1,0,'R');
$this->Ln();
$this->Cell(45,8,'Remarques:',1,0,'L');
$this->Cell(75,8,$remarques,1,0,'L');
$this->Cell(5,5,'',0,0,'L');
$this->Cell(35,8,'TOTAL TTC :',1,0,'R');
$this->Cell(35,8,number_format($total_ttc,'0',' ', ' ').' CFA',1,0,'R');
$this->Ln();
$this->Ln();
//$pdf->WriteHTML($html2);
$this->SetLeftMargin(10);
$this->SetX(10);
$this->Cell(95,5,'Pour le Client (Lu et approuvé)',1,0,'C');
$this->Cell(100,5,'Pour l\'Entreprise (Signature & cachet )',1,0,'C');
$this->Ln();
$this->Cell(95,25,'',1,0,'L');
$this->Cell(100,25,'',1,0,'L');
$this->Ln();
$this->SetFontSize(7);
$this->Cell(195,5,'ARC CABLING SYSTEMS Point E,rue F x Impasse piscine olympique , DAKAR , au capital de 1 000 000FCFA, NINEA 40338092V2/RC : SN-DKR-2009/B/6146',1,0,'C');
}
//Chargement des données
function LoadData($file)
{
//Lecture des lignes du fichier
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Tableau coloré
function FancyTable($header,$data)
{
//Couleurs, épaisseur du trait et police grasse
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(192,192,192);
$this->SetLineWidth(.2);
$this->SetFont('','B');
//En-tête
$w=array(70,20,25,40,40);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
//$this->SetX(10);
$this->Ln();
//Restauration des couleurs et de la police
$this->SetFillColor(102,204,204);
$this->SetTextColor(0);
$this->SetFont('');
$fill=false;
foreach($data as $row)
{
$ligne_depart = $this->GetY();
$this->MultiCell($w[0],6,utf8_decode($row[0]),0);
$this->SetXY(80,$ligne_depart);
$this->MultiCell($w[1], 6, $row[1],0,'C');
$this->SetXY(100,$ligne_depart);
$this->MultiCell($w[2], 6, $row[2],0,'C');
$this->SetXY(125,$ligne_depart);
$this->MultiCell($w[3], 6, number_format($row[3],0,',',' '),0,'C');
$this->SetXY(165,$ligne_depart);
$this->MultiCell($w[4], 6, number_format($row[4],0,',',' '),0,'C');
$this->Ln();
$this->Ln();
$this->Cell(array_sum($w),0,'','T');
$this->Ln();
$this->Ln();
$fill=!$fill;
}
//$this->Cell(array_sum($w),0,'','T');
}
//***********************************************
}
$html='ARC CABLING SYSTEMS<br>
Point E,rue F x Impasse piscine olympique<br>
TEL: (00221)33 859 85 85<br>
FAX: (00221)33 859 85 84';
$entete2=' Etude et Installations électriques
Cablâge informatique et telephonique
Cablâge fibre optique
Aménagement Technique
Audit réseaux électriques/Informatiques
Video Surveillance';
$html2='<table >
<tr>
<td >Pour le client (lu & approuvé, pour bon accord )</td>
<td>Pour lEntreprise (Signature & cachet )</td>
</tr><br><br>
<tr>
<td></td>
<td ></td>
</tr>
<tr><br>
<td >ARC CABLING SYSTEMS Point E,rue F x Impasse piscine olympique , DAKAR , au capital de 1 000 000FCFA, NINEA 40338092V2/RC :SN-DKR-2009/B/6146</td>
</tr>
</table>';
$pdf=new PDF();
//$pdf->SetAutoPageBreak(true, 40);
$header=array('Désignation','Qte','Unite','Prix Vente','Montant');
$head=array('Désignation','Qte','Unite','Prix Vente','Montant');
//Chargement des données
$data=$pdf->LoadData('ligne_prod.txt');
//First page
/* $pdf->AddPage();
$pdf->Write(5,'To find out what\'s new in this tutorial, click ');
$link=$pdf->AddLink();
$pdf->Write(5,'here',$link); */
$pdf->SetFont('Arial','',20);
$pdf->SetFont('','U');
$pdf->SetFont('');
//Second page
$pdf->AddPage();
$pdf->AliasNbPages();
//$pdf->SetLink($link);
$pdf->Image('logo_acs.jpg',10,10,30,0,'','http://www.acs.sn');
$pdf->SetLeftMargin(40);
$pdf->SetFontSize(9);
$pdf->WriteHTML($html);
$pdf->SetXY(110,8);
//$pdf->Cell(65,10);
//$pdf->Cell(70,30,$html2,1,0,'C');
$txt=$pdf->MultiCell(100,5,$entete2,0,'R',0,4);
//$pdf->WriteHTML($html2);
$pdf->Ln();
$pdf->Ln();
//$lec="SORETOUR";
$pdf->SetLeftMargin(10);
$pdf->SetX(10);
$pdf->Cell(95,15,$leclient,1,0,'C');
$pdf->Cell(100,15,$type.":".$code_devis.", Du: ". $date_last_modif,1,0,'C');
$pdf->Ln();
$pdf->Cell(195,10,'Objet: '.$objet_devis ,1,0,'L');
$pdf->Ln();
$pdf->Cell(195,10,'A lattention de : '.$a_lattention,1,0,'L');
//$pdf->BasicTable($head,$data2) ;
$pdf->Ln();
$pdf->Ln();
$pdf->SetLeftMargin(10);
$pdf->SetX(10);
$pdf->FancyTable($header,$data);
$pdf->Ln();
$pdf->Ln();
//$this->Ln();
//$this->Ln();
$pa=$pdf->PageNo();
$nbr='{nb}';
if($pa/$nbr=1) { ; $pdf->Pieds() ;}
//$pdf->Cell(0,5,'Page '.$this->PageNo().' sur {nb}',0,0,'R');
$pdf->Output();
?>
|