Location: PHPKode > projects > Prolawyer > etude/facture.php
<?
session_start();
require("./fonctions.php");
require("./connection_data.php");
require("./externe/pclzip.lib.php");

$rep_act=getcwd();
if(!is_dir("./temp")) mkdir("./temp", 0775);
$now=time();
$testzip["nomrep"]=$_POST["session_utilisateur"].$now;
if(!is_dir("./temp/{$testzip["nomrep"]}")) $m=mkdir("./temp/{$testzip["nomrep"]}", 0777);
if(is_file("./config_files/facture.stw")){
$mode="zip";
$testzip["file"]="./content.xml";
$testzip["lastfile"]="./facture.sxw";
copy( "./config_files/facture.stw", "./temp/{$testzip["nomrep"]}/facture.sxw");
$path=chdir("./temp/{$testzip["nomrep"]}");
$archive=new PclZip('facture.sxw');
$archive->extract(PCLZIP_OPT_BY_NAME, "content.xml");
}
elseif(is_file("./config_files/facture.rtf")){
$mode="rtf";
$testzip["file"]="facture.rtf";
$testzip["lastfile"]="facture.rtf";
copy( "./config_files/facture.rtf", "./temp/{$testzip["nomrep"]}/facture.rtf");
$path=chdir("./temp/{$testzip["nomrep"]}");
}

if(isset($mode)){
header("Content-type: application/vnd.sun.xml.writer");
header('Content-Disposition: attachment; filename="facture.sxw"');
$file=file_get_contents("./{$testzip["file"]}");

$val_dossier=mysql_query("select * from {$_POST["session_avdb"]} where nodossier like '{$_POST["nodossier"]}'");
while($ligne=mysql_fetch_array($val_dossier)){
$noadresse=$ligne["noadresse"];
$nopa=$ligne["nopa"];
}
$requete_calcul_datas="select titre, nom, prenom, fonction, adresse, cp, zip, ville, pays, prixhoraire, naturemandat from adresses, {$_POST["session_avdb"]} where noadresse like id and nodossier like {$_POST["nodossier"]}";
$requete_calcul_theorique="select time_format(sec_to_time(SUM(time_to_sec(tempsop))), \"%k:%i\") as 'total', SUM(time_to_sec(tempsop)) as 'totalsec' from {$_POST["session_opdb"]} where (nodossier like '{$_POST["nodossier"]}' and dateop <> 0)";
$requete_calcul_recette="select (SUM(encaissement) - SUM(avfrais)) as total_resultat, SUM(encaissement) as 'total_recette', SUM(avfrais) as 'total_avance', SUM(demande) as total_demande from {$_POST["session_opdb"]} where (nodossier like '{$_POST["nodossier"]}' and dateac <> 0)";

$calcul_datas=mysql_query("$requete_calcul_datas");
while($row=mysql_fetch_array($calcul_datas, MYSQL_ASSOC)){ //affichage des rentrées effectives
foreach($row as $val1 => $val2) {
$val2=utf8_encode(html_entity_decode($val2));
$val2=ereg_replace("'", "`", "$val2");
$$val1=$val2;
}
$change["val_titre"]=$titre;
if($prenom) $nom="$prenom $nom";
$change["val_nom"]=$nom;
$change["val_fonction"]=$fonction;
$change["val_adresse"]=$adresse;
$change["val_cp"]=$cp;
if($zip<>0) $ville="$zip $ville";
$change["val_ville"]=$ville;
$change["val_pays"]=$pays;
$change["val_naturemandat"]=$naturemandat;
}

$calcul_recette=mysql_query("$requete_calcul_recette");
while($row=mysql_fetch_array($calcul_recette)){ //affichage des rentrées effectives
foreach($row as $val1 => $val2) $$val1=$val2;
$deb_pr_TVA=$row["total_avance"];
$change["val_rentrees"]=number_format($row["total_recette"], 2, '.', '\'');
$change["val_avances"]=number_format($row["total_avance"], 2, '.', '\'');
$total_resultat=$row["total_resultat"];
}

$calcul_theorique=mysql_query($requete_calcul_theorique);
while($row=mysql_fetch_array($calcul_theorique)){
foreach($row as $val1 => $val2) $$val1=$val2;
$prixseconde=$prixhoraire/3600;
$totalseconde=$row["totalsec"];
$gain=round($totalseconde*$prixseconde*20)/20;
$tva=round($gain*$option_gen["tx_tva"]*0.2)/20;
if($settings["tva_deb"]=="on") {
$tva_sur_deb=round($deb_pr_TVA*$option_gen["tx_tva"]*0.2)/20;
$tva += $tva_sur_deb;
}
$change["val_hono_theorique"]=number_format($gain, 2, '.', '\'');
$change["val_tva"]=number_format($tva, 2, '.', '\'');
$change["val_total_intermediaire"]=number_format(($tva+$gain), 2, '.', '\'');
$change["val_total"]=number_format(($gain + $tva - $total_resultat), 2, '.', '\'');
}

foreach($change as $nomchange => $valchange){
$file=ereg_replace("$nomchange", "$valchange", $file);
}
$op=fopen($testzip["file"], "w+");
fwrite($op, "$file");
$cl=fclose($op);
if($mode=="zip") $archive->add($testzip["file"]);

$dir=opendir("..");
$path=chdir("..");
$verification=getcwd();
//echo $verification;
if($verification != $getroot AND ereg("temp", $verification)) while ($arr=readdir($dir)) {
if(time() - filectime("./$arr") >100 AND $arr!="." AND $arr!=".." AND is_dir($arr)){
$dir2=opendir("./$arr");
while ($arr2=readdir($dir2)) {
if($arr2!="." AND $arr2!="..") unlink("./$arr/$arr2");
}
$close=closedir($dir2);
rmdir("./$arr");
}
}

echo readfile("./{$testzip["nomrep"]}/{$testzip["lastfile"]}");
$cdir=closedir($dir);
// $exec3=popen("pwd", "r");
// while($line=fgets($exec3)) $openfich=trim($line)."/{$testzip["nomrep"]}/facture.sxw";
// $close3=pclose($exec3);

}
else{
require("title.php");
echo "</title>";
body();
echo liste_erreur("100-004", TRUE);
echo "<br><br>$facture_ligne1";
echo "<br><br>$facture_ligne2";
echo "<br><br>$facture_ligne3";
}
?>
Return current item: Prolawyer