| Current Path : /home/h/a/p/happyrenas/old/huissier-express.fr/administration/panel/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/h/a/p/happyrenas/old/huissier-express.fr/administration/panel/compta_export.php |
<?
session_start();
$page="compta";
include("../../config.php");
$annee_en_cours = date("Y");
$annee = $_REQUEST['annee'];
$myquery = "SELECT * from facture where 1 and statut_paiement=1 order by id";
if ($annee) {$myquery = "SELECT * from facture where 1 and statut_paiement=1 and year(date_creation)= ".$annee." order by id";}
$myquery_calls = $db->get_results($myquery);
if (!empty($myquery_calls))
{
foreach ( $myquery_calls as $factures )
{
$compteur = $compteur+1;
$ladate="";
$ref_commande="";
$compteur=$compteur+1;
$destinataire="";
$montant_facture_ht="";
$montant_tva="";
$montant_ttc="";
$montant_total="";
$montant_total_tva="";
$montant_total_ttc="";
$reverse="";
$pdf_facture="";
if ($factures->constat_id)
{
$myquery="select * from constat where id=".$factures->constat_id;
$constat = $db->get_row($myquery);
$ladate=date("d-m-Y",strtotime($constat->date_creation));
if ($constat->id<=979) {$pourcentage=0.06;} else {$pourcentage=0.09;}
$ref_commande="HE/".date("Y", strtotime($constat->date_creation))."/C/".$constat->id;
$montant_facture_ht = round($constat->tarif/1.2,2);
$montant_tva = round($constat->tarif-$montant_facture_ht,2);
$montant_ttc = round($constat->tarif,2);
$montant_total = round($pourcentage*$montant_facture_ht,2);
$montant_total_tva = round(0.2*$montant_total,2);
$montant_total_ttc = $montant_total+$montant_total_tva;
$reverse=-$montant_total_ttc+$montant_ttc;
$pdf_facture="../fpdfi/facture.php?constat_id=".$factures->constat_id."&facture_id=".$factures->id."&huissier_id=".$factures->huissier_id."&tva=&save=non";
}
if ($factures->impaye_id)
{
$myquery="select * from impaye where id=".$factures->impaye_id;
$impaye = $db->get_row($myquery);
$ladate=date("d-m-Y",strtotime($impaye->date_creation));
$ref_commande="HE/".date("Y", strtotime($impaye->date_creation))."/I/".$impaye->id;
$montant_facture_ht = round(21/1.2,2);
$montant_tva = round(21-$montant_facture_ht,2);
$montant_ttc = round($impaye->tarif,2);
$montant_total = round($montant_facture_ht,2);
$montant_total_tva = round(0.2*$montant_total,2);
$montant_total_ttc = $montant_total+$montant_total_tva;
$reverse=-$montant_total_ttc+$montant_ttc;
$pdf_facture="../fpdfi/facture.php?impaye_id=".$factures->impaye_id."&facture_id=".$factures->id."&huissier_id=".$factures->huissier_id."&tva=&save=non";
}
if ($factures->urgence_id)
{
$myquery="select * from urgence where id=".$factures->urgence_id;
$urgence = $db->get_row($myquery);
$ref_commande="HE/".date("Y", strtotime($urgence->date_creation))."/U/".$urgence->id;
$montant_facture_ht = round(24/1.2,2);
$montant_tva = round(24-$montant_facture_ht,2);
$montant_ttc = round($urgence->tarif,2);
$montant_total = round($montant_facture_ht,2);
$montant_total_tva = round(0.2*$montant_total,2);
$montant_total_ttc = $montant_total+$montant_total_tva;
$reverse=-$montant_total_ttc+$montant_ttc;
$pdf_facture="../fpdfi/facture_urgence.php?urgence_id=".$factures->urgence_id."&facture_id=".$factures->id."&huissier_id=".$factures->huissier_id."&tva=&save=non";
}
if ($factures->huissier_id)
{
$myquery="select * from huissier where id=".$factures->huissier_id;
$huissier = $db->get_row($myquery);
$destinataire=$huissier->huissier;
}
if ($ref_commande=="")
{
$ladate=date("d-m-Y",strtotime($factures->date_creation));
$ref_commande="HE/".date("Y", strtotime($factures->date_creation))."/A/".$huissier->id;
$montant_total = 15;
$montant_total_tva = 3;
$montant_total_ttc = 18;
$pdf_facture="../fpdfi/facture.php?facture_id=".$factures->id."&huissier_id=".$factures->huissier_id."&tva=&save=non";
}
$matrice[$compteur]['REF_FACTURE'] = $factures->facture_numero;
$matrice[$compteur]['LADATE'] = $ladate;
$matrice[$compteur]['REF_COMMANDE'] = $ref_commande;
$matrice[$compteur]['DESTINATAIRE'] = $destinataire;
//$matrice[$compteur]['ENCAISSE_HT_CLIENT'] = money_format('%+n', $montant_facture_ht);
//$matrice[$compteur]['ENCAISSE_TVA'] = money_format('%+n', $montant_tva);
//$matrice[$compteur]['ENCAISSE_TTC'] = money_format('%+n', $montant_ttc);
//$matrice[$compteur]['TTC_REVERSE'] = money_format('%+n', $reverse);
//$matrice[$compteur]['COMM_PRELEVE_HT_CLIENT'] = money_format('%+n', $montant_total);
//$matrice[$compteur]['COMM_PRELEVE_TVA'] = money_format('%+n', $montant_total_tva);
//$matrice[$compteur]['COMM_PRELEVE_TTC'] = money_format('%+n', $montant_total_ttc);
$matrice[$compteur]['ENCAISSE_HT_CLIENT'] = $montant_facture_ht;
$matrice[$compteur]['ENCAISSE_TVA'] = $montant_tva;
$matrice[$compteur]['ENCAISSE_TTC'] = $montant_ttc;
$matrice[$compteur]['TTC_REVERSE'] = $reverse;
$matrice[$compteur]['COMM_PRELEVE_HT_CLIENT'] = $montant_total;
$matrice[$compteur]['COMM_PRELEVE_TVA'] = $montant_total_tva;
$matrice[$compteur]['COMM_PRELEVE_TTC'] = $montant_total_ttc;
}
}
$csv_fields=array();
$csv_fields[0][] = 'REF_FACTURE';
$csv_fields[0][] = 'DATE';
$csv_fields[0][] = 'REF_COMMANDE';
$csv_fields[0][] = 'DESTINATAIRE';
$csv_fields[0][] = 'ENCAISSE_HT_CLIENT';
$csv_fields[0][] = 'ENCAISSE_TVA';
$csv_fields[0][] = 'ENCAISSE_TTC';
$csv_fields[0][] = 'TTC_REVERSE';
$csv_fields[0][] = 'COMM_PRELEVE_HT_CLIENT';
$csv_fields[0][] = 'COMM_PRELEVE_TVA';
$csv_fields[0][] = 'COMM_PRELEVE_TTC';
$filename = 'compta_export';
$filepath = $_SERVER["DOCUMENT_ROOT"] ."/administration/panel/". $filename.'.csv';
$fp = fopen($filename.'.csv', 'w');
foreach ($csv_fields as $fields) {
fputcsv($fp, $fields, ';');
}
if ($matrice) {
foreach ($matrice as $fields) {
fputcsv($fp, $fields, ';');
}
}
fclose($fp);
if (file_exists($filepath)) {
$file = $filepath;
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=\"export.csv\"");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
readfile($filepath);exit;}
?>