|
Server IP : 10.128.40.6 / Your IP : 216.73.216.233 Web Server : Apache System : Linux webd006.cluster128.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : logmcpe ( 111175) PHP Version : 7.3.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/logmcpe/www/TMCPRO/pages/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
include 'includes/config_tmcpro.php' ;
include 'includes/stable_functions_tmcpro.php' ;
$headers = 'From: comptabilite@mc-pro.fr' . "\r\n" .
'Reply-To: comptabilite@mc-pro.fr' . "\r\n" ;
$headers .= "Content-type: text/html; charset= UTF-8\n";
$todayy = date('Ymd') ;
// $headers = 'From: comptabilite@mc-pro.fr' . "\r\n" .
// 'Reply-To: comptabilite@mc-pro.fr' . "\r\n" .
// 'X-Mailer: PHP/' . phpversion();
// $headers .= "Content-type: text/html; charset= UTF-8\n";
// echo "<pre>" ;
// print_r($_POST) ;
// echo "</pre>" ;
// exit() ;
// echo "<pre>" ;
// print_r($_SESSION) ;
// echo "</pre>" ;
$client_id = $_SESSION['client_id'] ;
// exit() ;
$client =dbi_fetch_row(dbi_query("SELECT * FROM `client` WHERE `client_id` = ".$client_id)) ;
$client_facture_mail =$client['client_facture_mail'] ;
// $client_facture_mail ="dsi.pro2000@gmail.com" ;
// exit() ;
$tab['ton_infos'] = "ddd" ;
$contenu = '<table border="1">';
// $rq = mysql_query("TA REQUETTE");
// while($tab = mysql_fetch_array($rq)){
$contenu .= '<tr><td> Numéro </td> <td> Date facture</td> <td> Montant </td> <td> Net à payer</td> <td> Echéance</td></tr>' ;
// $contenu .= '<tr><td>'.$tab['ton_infos'].'</td></tr>';
// }
// echo "test" ;
$cmp = 0 ;
$somme = 0 ;
$numfact ="" ;
$date_relance = date('Ymd');
list($id_relance)=dbi_fetch_row(dbi_query("SELECT MAX(id_relance) FROM `histo_relance`")) ;
$id_relance = $id_relance + 1 ;
if(!empty($_POST['mise_en_demeure']))
{
foreach ($_POST['num_fact'] as $key => $num_fact) {
$numfact = $num_fact ;
list($total,$date_fact,$client_id ,$date_fact_plus_huit) = dbi_fetch_row(dbi_query("SELECT total , date_fact , f.client_id , DATE_ADD(STR_TO_DATE(date_fact, '%Y%m%d'), INTERVAL 8 DAY ) as date_fact_plus_huit FROM `facture` f , client c WHERE f.client_id = c.client_id and `num_fact` = $num_fact")) ;
$query2 = "SELECT
total-if(p.paye is null, 0, p.paye)-if(a.avoir is null, 0, a.avoir) AS paye,
if(a.avoir is null, 0, a.avoir) avoir,
f.date_fact, if(if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) >= total, 'Réglé', if(if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) = 0, 'Pas de règlement', 'Règlement partiel')) statut,
f.relance
FROM ".TABLE_FACT." f
LEFT JOIN (select if(sum(if(montant is null, 0, montant)) is null, 0, sum(if(montant is null, 0, montant))) paye, fact_id FROM ".TABLE_PAIEMENT." where client_id = $client_id group by fact_id) p ON f.fact_id = p.fact_id
LEFT JOIN (select if(sum(if(montant is null, 0, montant)) is null, 0, sum(if(montant is null, 0, montant))) avoir, fact_id FROM ".TABLE_AVOIR." group by fact_id) a ON f.fact_id = a.fact_id
WHERE f.client_id=$client_id
AND f.agence_id=$agence
AND if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) < total AND num_fact = $num_fact
" ;
list($paye)=dbi_fetch_row(dbi_query($query2)) ;
$date_fact_plus_huit=int2date(date2int_DSI($date_fact_plus_huit)) ;
$contenu .= '<tr><td> '.$num_fact.' </td> <td> '.int2date($date_fact).'</td> <td> '.$total.' </td> <td> '.$paye.'</td> <td> '.$date_fact_plus_huit.'</td></tr>';
$cmp ++ ;
$somme = $somme + $paye ;
list($id_r) = dbi_fetch_row(dbi_query(" select id_r from histo_relance where numfact = $numfact ")) ;
echo "==>".$id_r."<br/>" ;
// si on a deja envoyé la relance de la méme type on fait juste une modification de la date
if(empty($id_r))
{
dbi_query("INSERT INTO `histo_relance` (`id_r`, `numfact`, `mise_en_demeure`, `type_relance`, `montant` , `client_id`,id_relance) VALUES (NULL, '$numfact', '$date_relance', '4', '$paye' , '$client_id' , '$id_relance')") ;
}
else{
dbi_query("UPDATE `histo_relance` SET `mise_en_demeure` = '$date_relance' WHERE `histo_relance`.`numfact` = $numfact") ;
}
// exit() ;
dbi_query("UPDATE `relance_programee` SET `date_relance_programee` = DATE_ADD(STR_TO_DATE($todayy, '%Y%m%d'), INTERVAL 10 DAY ) , `type_relance_programmee` = '5' WHERE `relance_programee`.`num_fact` = $numfact") ;
}
// echo "ttttit " ;
// exit() ;
}
if(!empty($_POST['injonction']))
{
foreach ($_POST['num_fact'] as $key => $num_fact) {
$numfact = $num_fact ;
list($total,$date_fact,$client_id ,$date_fact_plus_huit) = dbi_fetch_row(dbi_query("SELECT total , date_fact , f.client_id , DATE_ADD(STR_TO_DATE(date_fact, '%Y%m%d'), INTERVAL 8 DAY ) as date_fact_plus_huit FROM `facture` f , client c WHERE f.client_id = c.client_id and `num_fact` = $num_fact")) ;
$query2 = "SELECT
total-if(p.paye is null, 0, p.paye)-if(a.avoir is null, 0, a.avoir) AS paye,
if(a.avoir is null, 0, a.avoir) avoir,
f.date_fact, if(if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) >= total, 'Réglé', if(if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) = 0, 'Pas de règlement', 'Règlement partiel')) statut,
f.relance
FROM ".TABLE_FACT." f
LEFT JOIN (select if(sum(if(montant is null, 0, montant)) is null, 0, sum(if(montant is null, 0, montant))) paye, fact_id FROM ".TABLE_PAIEMENT." where client_id = $client_id group by fact_id) p ON f.fact_id = p.fact_id
LEFT JOIN (select if(sum(if(montant is null, 0, montant)) is null, 0, sum(if(montant is null, 0, montant))) avoir, fact_id FROM ".TABLE_AVOIR." group by fact_id) a ON f.fact_id = a.fact_id
WHERE f.client_id=$client_id
AND f.agence_id=$agence
AND if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) < total AND num_fact = $num_fact
" ;
list($paye)=dbi_fetch_row(dbi_query($query2)) ;
$date_fact_plus_huit=int2date(date2int_DSI($date_fact_plus_huit)) ;
$contenu .= '<tr><td> '.$num_fact.' </td> <td> '.int2date($date_fact).'</td> <td> '.$total.' </td> <td> '.$paye.'</td> <td> '.$date_fact_plus_huit.'</td></tr>';
$cmp ++ ;
$somme = $somme + $paye ;
list($id_r) = dbi_fetch_row(dbi_query(" select id_r from histo_relance where numfact = $numfact ")) ;
echo "==>".$id_r."<br/>" ;
// si on a deja envoyé la relance de la méme type on fait juste une modification de la date
if(empty($id_r))
{
dbi_query("INSERT INTO `histo_relance` (`id_r`, `numfact`, `injonction`, `type_relance`, `montant` , `client_id`,id_relance) VALUES (NULL, '$numfact', '$date_relance', '5', '$paye' , '$client_id' , '$id_relance')") ;
}
else{
dbi_query("UPDATE `histo_relance` SET `injonction` = '$date_relance' WHERE `histo_relance`.`numfact` = $numfact") ;
}
// exit() ;
// dbi_query("UPDATE `relance_programee` SET `date_relance_programee` = DATE_ADD(STR_TO_DATE($todayy, '%Y%m%d'), INTERVAL 10 DAY ) , `type_relance_programmee` = '5' WHERE `relance_programee`.`num_fact` = $numfact") ;
}
// echo "ttttit " ;
// exit() ;
}
if(!empty($_POST['relance_1']))
{
// echo "aaa" ; exit() ;
foreach ($_POST['num_fact'] as $key => $num_fact) {
$numfact = $num_fact ;
list($total,$date_fact,$client_id ,$date_fact_plus_huit) = dbi_fetch_row(dbi_query("SELECT total , date_fact , f.client_id , DATE_ADD(STR_TO_DATE(date_fact, '%Y%m%d'), INTERVAL 8 DAY ) as date_fact_plus_huit FROM `facture` f , client c WHERE f.client_id = c.client_id and `num_fact` = $num_fact")) ;
$query2 = "SELECT
total-if(p.paye is null, 0, p.paye)-if(a.avoir is null, 0, a.avoir) AS paye,
if(a.avoir is null, 0, a.avoir) avoir,
f.date_fact, if(if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) >= total, 'Réglé', if(if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) = 0, 'Pas de règlement', 'Règlement partiel')) statut,
f.relance
FROM ".TABLE_FACT." f
LEFT JOIN (select if(sum(if(montant is null, 0, montant)) is null, 0, sum(if(montant is null, 0, montant))) paye, fact_id FROM ".TABLE_PAIEMENT." where client_id = $client_id group by fact_id) p ON f.fact_id = p.fact_id
LEFT JOIN (select if(sum(if(montant is null, 0, montant)) is null, 0, sum(if(montant is null, 0, montant))) avoir, fact_id FROM ".TABLE_AVOIR." group by fact_id) a ON f.fact_id = a.fact_id
WHERE f.client_id=$client_id
AND f.agence_id=$agence
AND if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) < total AND num_fact = $num_fact
" ;
list($paye)=dbi_fetch_row(dbi_query($query2)) ;
$date_fact_plus_huit=int2date(date2int_DSI($date_fact_plus_huit)) ;
$contenu .= '<tr><td> '.$num_fact.' </td> <td> '.int2date($date_fact).'</td> <td> '.$total.' </td> <td> '.$paye.'</td> <td> '.$date_fact_plus_huit.'</td></tr>';
$cmp ++ ;
$somme = $somme + $paye ;
list($id_r) = dbi_fetch_row(dbi_query(" select id_r from histo_relance where numfact = $numfact ")) ;
// echo "==>".$id_r."<br/>" ;
// si on a deja envoyé la relance de la méme type on fait juste une modification de la date
if(empty($id_r))
{
dbi_query("INSERT INTO `histo_relance` (`id_r`, `numfact`, `date_relance_1`, `type_relance`, `montant` , `client_id`,id_relance) VALUES (NULL, '$numfact', '$date_relance', '1', '$paye' , '$client_id' , '$id_relance')") ;
}
else{
dbi_query("UPDATE `histo_relance` SET `date_relance_1` = '$date_relance' WHERE `histo_relance`.`numfact` = $numfact") ;
}
// exit() ;
dbi_query("UPDATE `relance_programee` SET `date_relance_programee` = DATE_ADD(STR_TO_DATE($todayy, '%Y%m%d'), INTERVAL 8 DAY ) , `type_relance_programmee` = '2' WHERE `relance_programee`.`num_fact` = $numfact") ;
}
$contenu .= '</table>';
// the message
if($cmp ==1)
{
// $chaine_fact= "la facture" ;
$chaine_fact= "le solde ci-dessous" ;
}else
{
// $chaine_fact= "les factures" ;
$chaine_fact= "le solde ci-dessous" ;
}
$msg = "Bonjour,<br/><br/>
L’examen de votre compte dans notre comptabilité fait apparaître qu’à ce jour, sauf erreur ou omission de notre part, ".$chaine_fact.", pour un montant de $somme €, reste impayé :
<br/><br/>".$contenu." <br/>
Nous vous remercions de bien vouloir régulariser votre situation dans les meilleurs délais.
Certains qu’il s’agit d’un oubli de votre part, nous vous remercions par avance.
<br/><br/>
Cordialement,
<br/> <br/><br/>
Tiffany MAZELLA <br/>
Service comptabilité et recouvrement";
$msg = wordwrap($msg,70);
// mail("info@mc-pro.fr","Relance 1",$msg);
mail($client_facture_mail,"MC PRO facture en attente de règlement",$msg ,$headers);
//******************************relance 1***************************
mail("dsi.pro2000@gmail.com","MC PRO facture en attente de règlement",$msg ,$headers);
}
// ********************************************************Relance 2 *******************************************************************
if(!empty($_POST['relance_2']))
{
// echo "bbb" ; exit() ;
foreach ($_POST['num_fact'] as $key => $num_fact) {
$numfact = $num_fact ;
list($total,$date_fact,$client_id ,$date_fact_plus_huit) = dbi_fetch_row(dbi_query("SELECT total , date_fact , f.client_id , DATE_ADD(STR_TO_DATE(date_fact, '%Y%m%d'), INTERVAL 8 DAY ) as date_fact_plus_huit FROM `facture` f , client c WHERE f.client_id = c.client_id and `num_fact` = $num_fact")) ;
$query2 = "SELECT
total-if(p.paye is null, 0, p.paye)-if(a.avoir is null, 0, a.avoir) AS paye,
if(a.avoir is null, 0, a.avoir) avoir,
f.date_fact, if(if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) >= total, 'Réglé', if(if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) = 0, 'Pas de règlement', 'Règlement partiel')) statut,
f.relance
FROM ".TABLE_FACT." f
LEFT JOIN (select if(sum(if(montant is null, 0, montant)) is null, 0, sum(if(montant is null, 0, montant))) paye, fact_id FROM ".TABLE_PAIEMENT." where client_id = $client_id group by fact_id) p ON f.fact_id = p.fact_id
LEFT JOIN (select if(sum(if(montant is null, 0, montant)) is null, 0, sum(if(montant is null, 0, montant))) avoir, fact_id FROM ".TABLE_AVOIR." group by fact_id) a ON f.fact_id = a.fact_id
WHERE f.client_id=$client_id
AND f.agence_id=$agence
AND if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) < total AND num_fact = $num_fact
" ;
list($paye)=dbi_fetch_row(dbi_query($query2)) ;
$date_fact_plus_huit=int2date(date2int_DSI($date_fact_plus_huit)) ;
$contenu .= '<tr><td> '.$num_fact.' </td> <td> '.int2date($date_fact).'</td> <td> '.$total.' </td> <td> '.$paye.'</td> <td> '.$date_fact_plus_huit.'</td></tr>';
$cmp ++ ;
$somme = $somme + $paye ;
list($id_r) = dbi_fetch_row(dbi_query(" select id_r from histo_relance where numfact = $numfact ")) ;
// echo "==>".$id_r."<br/>" ;
if(empty($id_r))
{
dbi_query("INSERT INTO `histo_relance` (`id_r`, `numfact`, `date_relance_2`, `type_relance`, `montant` , `client_id`,id_relance) VALUES (NULL, '$numfact', '$date_relance', '1', '$paye' , '$client_id' , '$id_relance')") ;
}
else{
dbi_query("UPDATE `histo_relance` SET `date_relance_2` = '$date_relance' WHERE `histo_relance`.`numfact` = $numfact") ;
}
// exit() ;
dbi_query("UPDATE `relance_programee` SET `date_relance_programee` = DATE_ADD(STR_TO_DATE($todayy, '%Y%m%d'), INTERVAL 8 DAY ) , `type_relance_programmee` = '3' WHERE `relance_programee`.`num_fact` = $numfact") ;
}
$contenu .= '</table>';
// the message
if($cmp ==1)
{
$chaine_fact= "la facture" ;
}else
{
$chaine_fact= "les factures" ;
}
$msg = "Bonjour,<br/><br/>
L’examen de votre compte fait apparaître, sauf erreur ou omission de notre part, un solde débiteur de $somme € :
<br/><br/>".$contenu." <br/>
Nous vous demandons de bien vouloir régulariser votre facture arrivée à échéance à réception de la présente relance.<br/>
Nous vous remercions de votre compréhension et restons à votre disposition pour tout complément d’information.
<br/><br/>
Cordialement,
<br/> <br/><br/>
Tiffany MAZELLA <br/>
Service comptabilité et recouvrement" ;
$msg = wordwrap($msg,70);
// mail("info@mc-pro.fr","Relance 1",$msg);
mail($client_facture_mail,"MC PRO facture en attente de règlement",$msg ,$headers);
//*********************************** Relance 2 ********************************
mail("dsi.pro2000@gmail.com","MC PRO facture en attente de règlement",$msg ,$headers);
}
// ********************************************************Relance 3 *******************************************************************
if(!empty($_POST['relance_3']))
{
// echo "bbb" ; exit() ;
foreach ($_POST['num_fact'] as $key => $num_fact) {
$numfact = $num_fact ;
list($total,$date_fact,$client_id ,$date_fact_plus_huit) = dbi_fetch_row(dbi_query("SELECT total , date_fact , f.client_id , DATE_ADD(STR_TO_DATE(date_fact, '%Y%m%d'), INTERVAL 8 DAY ) as date_fact_plus_huit FROM `facture` f , client c WHERE f.client_id = c.client_id and `num_fact` = $num_fact")) ;
$query2 = "SELECT
total-if(p.paye is null, 0, p.paye)-if(a.avoir is null, 0, a.avoir) AS paye,
if(a.avoir is null, 0, a.avoir) avoir,
f.date_fact, if(if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) >= total, 'Réglé', if(if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) = 0, 'Pas de règlement', 'Règlement partiel')) statut,
f.relance
FROM ".TABLE_FACT." f
LEFT JOIN (select if(sum(if(montant is null, 0, montant)) is null, 0, sum(if(montant is null, 0, montant))) paye, fact_id FROM ".TABLE_PAIEMENT." where client_id = $client_id group by fact_id) p ON f.fact_id = p.fact_id
LEFT JOIN (select if(sum(if(montant is null, 0, montant)) is null, 0, sum(if(montant is null, 0, montant))) avoir, fact_id FROM ".TABLE_AVOIR." group by fact_id) a ON f.fact_id = a.fact_id
WHERE f.client_id=$client_id
AND f.agence_id=$agence
AND if(p.paye is null, 0, p.paye)+if(a.avoir is null, 0, a.avoir) < total AND num_fact = $num_fact
" ;
list($paye)=dbi_fetch_row(dbi_query($query2)) ;
$date_fact_plus_huit=int2date(date2int_DSI($date_fact_plus_huit)) ;
$contenu .= '<tr><td> '.$num_fact.' </td> <td> '.int2date($date_fact).'</td> <td> '.$total.' </td> <td> '.$paye.'</td> <td> '.$date_fact_plus_huit.'</td></tr>';
$cmp ++ ;
$somme = $somme + $paye ;
list($id_r) = dbi_fetch_row(dbi_query(" select id_r from histo_relance where numfact = $numfact ")) ;
// echo "==>".$id_r."<br/>" ;
if(empty($id_r))
{
dbi_query("INSERT INTO `histo_relance` (`id_r`, `numfact`, `date_relance_3`, `type_relance`, `montant` , `client_id`,id_relance) VALUES (NULL, '$numfact', '$date_relance', '1', '$paye' , '$client_id' , '$id_relance')") ;
}
else{
dbi_query("UPDATE `histo_relance` SET `date_relance_3` = '$date_relance' WHERE `histo_relance`.`numfact` = $numfact") ;
}
// exit() ;
dbi_query("UPDATE `relance_programee` SET `date_relance_programee` = DATE_ADD(STR_TO_DATE($todayy, '%Y%m%d'), INTERVAL 8 DAY ) , `type_relance_programmee` = '4' WHERE `relance_programee`.`num_fact` = $numfact") ;
}
$contenu .= '</table>';
// the message
if($cmp ==1)
{
// $chaine_fact= "la facture" ;
$chaine_fact= "le solde ci-dessous reste impayé" ;
}else
{
// $chaine_fact= "les factures" ;
$chaine_fact= "le solde ci-dessous reste impayé" ;
}
$msg = "Madame, Monsieur,<br/><br/>
A ce jour et malgré nos précédentes relances, vous nous restez redevable de la somme de $somme €. En effet, ".$chaine_fact." :
<br/><br/>".$contenu." <br/>
Nous vous rappelons vos obligations et vous serions reconnaissants de procéder au règlement de votre solde dès réception de la présente
. En l’absence de réception de règlement de votre part sous 8 jours, nous serions contraints d’engager une procédure de recouvrement.
Vous vous exposez dès lors au calcul des intérêts de retard.
<br/><br/>
Cordialement,
<br/> <br/><br/>
Tiffany MAZELLA <br/>
Service comptabilité et recouvrement";
$msg = wordwrap($msg,70);
// mail("info@mc-pro.fr","Relance 1",$msg);
mail($client_facture_mail,"MC PRO dernière relance avant mise en demeure",$msg ,$headers);
//***************************Relance 3***************************************
mail("dsi.pro2000@gmail.com","MC PRO dernière relance avant mise en demeure",$msg ,$headers);
}
// use wordwrap() if lines are longer than 70 characters
// $date_relance = date('Ymd');
// dbi_query("INSERT INTO `histo_relance` (`id_r`, `numfact`, `date_relance`, `type_relance`, `montant` , `client_id`) VALUES (NULL, '$numfact', '$date_relance', '1', '$somme' , '$client_id')") ;
if(!empty($_POST['mise_en_demeure']))
{
header('Location:cRvouvrement.php?msg= Mise en demeure bien enregistré&color=success');
}
elseif(!empty($_POST['injonction'])){
header('Location:cRvouvrement.php?msg= Injonction bien enregistré&color=success');
}else{
header('Location:cRvouvrement.php?msg= Relance bien envoyé&color=success'); }
?>
