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 (0705) :  /home/logmcpe/www/MC/test/../

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/logmcpe/www/MC/test/../nv-attestations_mcg.php
<?php
// lllk
include 'includes/config_tmcpro2.php' ;
include 'includes/stable_functions_tmcpro.php' ;


// la mise ajour de inter pour résoudre le probléme de iner de 2023
// $query_migration = "SELECT * FROM fiscalll_migration";
// $result_migration = dbi_query($query_migration);

// while ($row_migration = dbi_fetch_row($result_migration)) {
    // $date_prestation_mig = $row_migration['date_prestation'];
    // $client_id_mig = $row_migration['client_id'];
    // $dateprest_mig = $row_migration['dateprest'];
    // $dateee_mig = $row_migration['dateee'];
    // $taux_mig = $row_migration['taux'];
    // $duree_mig = $row_migration['duree'];
    // $inter_mig = $row_migration['inter']; 

    // $query_fiscalll = "SELECT * FROM fiscalll 
                        // WHERE date_prestation = '$date_prestation_mig' 
              
                        // AND dateprest = '$dateprest_mig' 
                        // AND dateee = '$dateee_mig'
                        // AND taux = '$taux_mig'
                        // AND duree = '$duree_mig'";
    // $result_fiscalll = dbi_query($query_fiscalll);

    // while ($row_fiscalll = dbi_fetch_row($result_fiscalll)) {
        // if ($row_fiscalll['inter'] == 0) {
            // $id_fiscalll = $row_fiscalll['id'];
            // $update_query = "UPDATE fiscalll 
                             // SET inter = '$inter_mig' 
                             // WHERE id = '$id_fiscalll'";
            // dbi_query($update_query);
        // }
    // }
// }


// exit() ; 

// error_reporting(E_ALL);
// ini_set("display_errors", 1);

// echo "<pre>" ; 
// print_r($_POST) ; 
// echo "</pre>" ; 
function count_week_days($__date_from, $__date_to, $__holidays_between=array(), $__weekend_days=array()) {
   $total_days_count = $__date_to > $__date_from ? round(($__date_to - $__date_from)/(24*3600)) : 0;
   $full_weeks_count = floor($total_days_count/7);
   $weekend_days_count = $full_weeks_count*count($__weekend_days);
   $days_left_uncovered = $total_days_count - $full_weeks_count*7;
   for($i = 0; $i < $days_left_uncovered; $i++) {
      $date_to_check = $i ? strtotime("+{$i} day", $__date_from) : $__date_from;
      if(in_array(date('N', $date_to_check), $__weekend_days)) {
         $weekend_days_count++;
      }
   }
   $week_days_count = $total_days_count - $weekend_days_count - count($__holidays_between);
   return $week_days_count;
}
function daysfr ($value = 0)
{
$tab = array(0 => 'Dimanche', 1 => 'Lundi',  2 => 'Mardi', 3 => 'Mercredi', 4 => 'Jeudi', 5 => 'Vendredi', 6 => 'Samedi');
	 return $tab[$value];
}

function get_prest_sem( $IN,$from ,$to)
{
		$end   =  $to ;
		$date  = $from;
		$p = array();

		while ($date <= $end )
			{
				// $q = dbi_query("SELECT * FROM PRESTATIONS p where p.client_id  ".$IN." AND presta_date_debut <= $date AND (p.presta_date_fin >= $date OR p.presta_date_fin IS NULL) ");
				$q = dbi_query("SELECT * FROM PRESTATIONS p where p.client_id  = ".$IN." AND presta_date_debut <= $date AND (p.presta_date_fin >= $date OR p.presta_date_fin IS NULL) AND ( p.presta_recur IS NULL OR p.presta_recur NOT IN ( SELECT presta_id FROM PRESTATIONS where client_id  =   ".$IN." AND presta_date_fin < $date ) ) ");
				
				// echo "SELECT * FROM PRESTATIONS p where p.client_id  = ".$IN." AND presta_date_debut <= $date AND (p.presta_date_fin >= $date OR p.presta_date_fin IS NULL) AND ( p.presta_recur IS NULL OR p.presta_recur NOT IN ( SELECT presta_id FROM PRESTATIONS where client_id  =   ".$IN." AND presta_date_fin < $date ) ) <br/>" ;
				while($prest = dbi_fetch_row($q))
					{
						 
						$date_presta_sem = $prest['presta_date_debut'] ;
						$q1 = dbi_query("SELECT * FROM PRESTATIONS_MODIF WHERE presta_id = ".$prest['presta_id']." AND start <= ".$date."  order by start, modif_id ") ;
						while ( $m = dbi_fetch_row($q1) )
						{
							if( $m['presta_sem'] != NULL ) $date_presta_sem = $m['start'];

							$prest['presta_sem'] = $m['presta_sem'] === NULL ? $prest['presta_sem'] : $m['presta_sem'] ;
							$prest['presta_jour'] = $m['presta_jour'] === NULL ? $prest['presta_jour'] : $m['presta_jour'] ;
							$prest['presta_Hdeb'] = $m['presta_Hdeb'] === NULL ? $prest['presta_Hdeb'] : $m['presta_Hdeb'] ;
							$prest['presta_Hduree'] = $m['presta_Hduree'] === NULL ? $prest['presta_Hduree'] : $m['presta_Hduree'] ;
							$prest['salarie_id'] = $m['salarie_id'] === NULL ? $prest['salarie_id'] : $m['salarie_id'] ;
							$prest['chantier_id'] = $m['chantier_id'] === NULL ? $prest['chantier_id'] : $m['chantier_id'] ;
							$prest['presta_forfait'] = $m['presta_forfait'] === NULL ? $prest['presta_forfait'] : $m['presta_forfait'] ;
						}
						// echo "<pre>" ;
						// print_r($p) ;
						// echo "</pre>" ;
						// echo "===========+++++++++++++++++++++++++++++++++++++++++++++++++++++======================== <br/>" ; 
						$day = date("w", strtotime( int2date_autre_format($date)));
							if( $day == $prest['presta_jour'] OR  ( $date == $prest['presta_date_debut'] &&  $prest['presta_date_debut']	== $prest['presta_date_fin'] ) ){
								// echo "SELECT date_presta FROM EXCEPTIONS WHERE presta_id = ".$prest['presta_id']." AND date_presta = ".$date." <br>";
								$EXP = dbi_fetch_row(dbi_query("SELECT * FROM EXCEPTIONS WHERE presta_id = ".$prest['presta_id']." AND date_presta = ".$date." " )) ;	   ;
								
									if($EXP ){
										$heurefin = addDuree($prest['presta_Hdeb'], $prest['presta_Hduree']);
										// echo $EXP." ^D^^^^";
											if( $EXP['new_presta_id'] != NULL	&& $EXP['en_cours'] == '1')
										{
											// if($EXP['ad'] == '1')
												// echo $EXP['presta_id']." +++++++++++ ";
											// elseif($EXP['ded'] == '1')
												// echo $EXP['presta_id']." ------- ";
											// echo '<br>'.$date.' <> '.$EXP['facture']." ++++ ".$EXP['ad']."<br>";
											// echo $EXP['facture']." ------- ".$EXP['des'];
												if($EXP['ad'] == '1' && $EXP['facture'] == '1')
														$p[] = array('id' => $prest['presta_id'],'excpt_id' => $EXP['excpt_id'],'idchantier' => $prest['chantier_id'],'idclient' => $prest['client_id'],'nbH' => '','taux' => $prest['presta_forfait'],'tauxHT' => '','type' => 'add','date' => $date,'jour' => $prest['presta_jour'],'deb' => $prest['presta_Hdeb'],'duree' => $EXP['Hduree'],'change' => 1,'fin' => $heurefin) ;
												elseif($EXP['ded'] == '1' &&  $EXP['facture'] == '1')
														$p[] = array('id' => $prest['presta_id'],'excpt_id' => $EXP['excpt_id'],'idchantier' => $prest['chantier_id'],'idclient' => $prest['client_id'],'nbH' => '','taux' => $prest['presta_forfait'],'tauxHT' => '','type' => 'ded','date' => $date,'jour' => $prest['presta_jour'],'deb' => $prest['presta_Hdeb'],'duree' => $EXP['Hduree'],'change' => 1,'fin' => $heurefin) ;
												elseif($EXP['ded'] == '1' &&  $EXP['facture'] == "")
														$p[] = array('id' => $prest['presta_id'],'excpt_id' => $EXP['excpt_id'],'idchantier' => $prest['chantier_id'],'idclient' => $prest['client_id'],'nbH' => '','taux' => $prest['presta_forfait'],'tauxHT' => '','type' => 'ded','date' => $date,'jour' => $prest['presta_jour'],'deb' => $prest['presta_Hdeb'],'duree' => $EXP['Hduree'],'change' => 1,'fin' => $heurefin ,'deduire' => 'non') ;


										}
											// elseif ( $EXP['new_presta_id'] == NULL && $EXP['facture'] != '1') j'ai(DSI) commenté ce code pour je puisse affiche les deux exceprtion (prstation) factuté et non facturé 
											elseif ( $EXP['new_presta_id'] == NULL)
										{
											// echo " $date >= $from  && $date <= $to " ;
											// if( $date >= $from  && $date <= $to )
												$p[] = array(
												'id' => $prest['presta_id'],
												'excpt_id' => $EXP['excpt_id'],
												'idchantier' => $prest['chantier_id'],
												'idclient' => $prest['client_id'],
												'nbH' => '',
												'taux' => $prest['presta_forfait'],
												'tauxHT' => '',
												'type' => 'e2',
												'date' => $date,
												'jour' => $prest['presta_jour'],
													'inter' => $prest['salarie_id'],
												'deb' => $prest['presta_Hdeb'],
												'duree' => $prest['presta_Hduree'],
												'facture' => $EXP['facture'],
												'fin' => $heurefin) ;
										}
										// elseif( $EXP['new_presta_id'] == NULL){

												// $p[] = array('id' => $prest['presta_id'],'excpt_id' => $EXP['excpt_id'],'idchantier' => $prest['chantier_id'],'idclient' => $prest['client_id'],'nbH' => '','taux' => $prest['presta_forfait'],'tauxHT' => '','type' => 'e2','date' => $date,'jour' => $prest['presta_jour'],'deb' => $prest['presta_Hdeb'],'duree' => $EXP['Hduree'],'change' => 1,'fin' => $heurefin) ;

										// }






									} else {
                                       // echo "babaa <br/> " ; 
										if( $prest['presta_sem'] == 1 )
										{
											
											                                       // echo "mama <br/> " ; 
											$heurefin = addDuree($prest['presta_Hdeb'], $prest['presta_Hduree']);
												$p[] = array(
												'id' => $prest['presta_id'],
												'idchantier' => $prest['chantier_id'],
												'idclient' => $prest['client_id'],
												'nbH' => '',
												'taux' => $prest['presta_forfait'],
												'tauxHT' => '',
												'type' => 'p',
												'date' => $date,
												'jour' => $prest['presta_jour'],
												'inter' => $prest['salarie_id'],
												'deb' => $prest['presta_Hdeb'],
												'duree' => $prest['presta_Hduree'],
												'fin' => $heurefin) ;
										} elseif( $prest['presta_sem'] >0 ) {
											// echo "caca <br/> " ; 
										$nbre =count_week_days(strtotime(int2date_autre_format($date_presta_sem,'d.m.Y')), strtotime(int2date_autre_format($date,'d.m.Y')));
										$modolo = $nbre % $prest['presta_sem'] ;
										if( $modolo == 0)
										{
											$heurefin = addDuree($prest['presta_Hdeb'], $prest['presta_Hduree']);
												$p[] = array(
												'id' => $prest['presta_id'],
												'idchantier' => $prest['chantier_id'],
												'idclient' => $prest['client_id'],
												'nbH' => '',
												'taux' => $prest['presta_forfait'],
												'tauxHT' => '',
												'type' => 'p',
												'date' => $date,
												'jour' => $prest['presta_jour'],
												'inter' => $prest['salarie_id'],
												'deb' => $prest['presta_Hdeb'],
												'duree' => $prest['presta_Hduree'],
												'fin' => $heurefin) ;
										}
										}
									}
							}
					}
				$date =  date("Ymd", strtotime("+1 day", strtotime($date)));
			}


	return $p;
}
$_POST['type']='attestation' ; 
if (isset($_POST['duyear'], $_POST['client_id'], $_POST['type'])&&($_POST['type']=='attestation'))
{
	
	$reglement = 0;
	$avoir = 0;
	$attestation = 0;
	$cpt = 0;

	if (isset($_POST['duyear']))
	{
		$client_id = $_POST['client_id'] ;
		$annee = $_POST['duyear'];

		$du = sprintf("%04d%02d%02d", $_POST['duyear'], 01, 01) ;
		$au = sprintf("%04d%02d%02d", $_POST['duyear'], 12, 31) ;
	}
	else
		$annee = date("Y") ;
	

	$fromyear = $_POST['fromyear'] ;
	$emission = $_POST['emission'] ;

	$factures = array() ;
	include 'includes/nvattestation3_2024.php' ;

		  
		   list($decm) = dbi_fetch_row(dbi_query("SELECT SUM(p.montant) FROM ".TABLE_PAIEMENT." p INNER JOIN ".TABLE_FACT." f ON f.fact_id = p.fact_id WHERE p.client_id='$client_id' AND p.agence_id=$agence and p.date >= '20231231' and p.date <= '20240130'")) ;
	   // echo "===>".$decm."<br/>" ; 
	   // exit() ; 
	   
	   
	foreach($_POST['client_id'] as $client_id)
	{
		
		
		 list($tst) = dbi_fetch_row(dbi_query("SELECT validite FROM `fiscal_valide` WHERE client_id=$client_id limit 1")) ;
		 
		 
	   list($decm , $num_fact) = dbi_fetch_row(dbi_query("SELECT SUM(p.montant) , num_fact FROM ".TABLE_PAIEMENT." p INNER JOIN ".TABLE_FACT." f ON f.fact_id = p.fact_id WHERE p.client_id='$client_id' AND p.agence_id=$agence and p.date >= '20231231' and p.date <= '20240130'")) ;
	   
	   
	
	   	  $duu = "20250101" ; 
	  $auu ="20251231" ; 
	 list($reglement) = dbi_fetch_row(dbi_query("SELECT SUM(p.montant) FROM ".TABLE_PAIEMENT." p INNER JOIN ".TABLE_FACT." f ON f.fact_id = p.fact_id WHERE p.client_id='$client_id' AND p.agence_id=47 and p.date >= '$duu' and p.date <= '$auu'")) ;
	 
	 
	  // list( $total )= dbi_fetch_row(dbi_query(" SELECT sum(total) FROM `nouveau_fiscal` WHERE `client_id` = ".$client_id)) ; 
	    // list ($client_nom) =dbi_fetch_row(dbi_query("SELECT client_nom FROM `client` WHERE `client_id` = ".$client_id)) ; 
	   

	   // if($reglement != $total){
		   
		   // echo "le montant des factures effectivement acquittées représente une somme totale de ' ".$reglement." ' total de tableau = ' ".$total."  '  -------le nom de client => ".$client_nom."<br/>" ; 
	   // }
	
	   
	   
	 
       // echo "<pre>" ; 
	  // print_r( $data_fact)  ; 
	  // echo "</pre>" 	  ;  
		
	  $du = "20250101" ; 
	  $au ="20251231" ; 
	 
	  		
	  
	  $agence = 47 ;
	  $cId = $client_id ; 
	  
    $maxau= dbi_fetch_row(dbi_query("SELECT max(f.date_fin) FROM ".TABLE_FACT." f INNER JOIN ".TABLE_PAIEMENT." p ON f.fact_id=p.fact_id WHERE p.client_id='$cId' and p.agence_id=$agence and p.date>='$du' and p.date<='$au'"));
    $mindu=dbi_fetch_row(dbi_query("SELECT min(f.date_debut) FROM ".TABLE_FACT." f INNER JOIN ".TABLE_PAIEMENT." p ON f.fact_id=p.fact_id WHERE p.client_id='$cId' and p.agence_id=$agence and p.date>='$du' and p.date<='$au'"));
     
	 // echo "SELECT max(f.date_fin) FROM ".TABLE_FACT." f INNER JOIN ".TABLE_PAIEMENT." p ON f.fact_id=p.fact_id WHERE p.client_id='$cId' and p.agence_id=$agence and p.date>='$du' and p.date<='$au' <br/>" ;
	 // echo "====>".$maxau[0]."<br/>" ; 
	// echo "====>".$mindu[0]."<br/>" ; 
	 
	 // if (!empty($mindu[0]) && !empty($maxau[0])) {


	  $info_presta = get_prest_sem( $client_id, $mindu[0], $maxau[0]) ; 
	  
	  // echo "<pre>" ; 
	  // print_r($info_presta) ; 
	  // echo "</pre>" ; 
	foreach ($info_presta as $presta) {
		
					if ($presta['type'] == 'add' || $presta['type'] == 'ded') {
				continue; // Passe à l'élément suivant du tableau sans exécuter la suite
			}

    $inter = $presta['inter'];
    $duree = $presta['duree'];
    $taux = $presta['taux'];
    
    $date = $presta['date'];
    $mois = substr($date, 4, 2); // Extraction des caractères 5 et 6 (YYYYMMDD)
    $aaaaaa = '';
    $do = $date;
    $query = "INSERT INTO fiscal VALUES ('', '$inter', '$duree', '$taux', '$mois', '$aaaaaa', '$do','$client_id')";
    dbi_query($query);
}

// }

	$rr = dbi_query("SELECT * ,COUNT( p.fact_id ) AS kk FROM ".TABLE_PAIEMENT." p , ".TABLE_FACT." f   WHERE f.fact_id = p.fact_id and p.client_id='$cId' AND p.agence_id=$agence AND p.date >= '$du' AND p.date <= '$au' GROUP BY p.fact_id HAVING COUNT( p.fact_id ) =1") ;
    $rro = dbi_query("SELECT * ,COUNT( p.fact_id ) AS kk FROM ".TABLE_PAIEMENT." p , ".TABLE_FACT." f   WHERE f.fact_id = p.fact_id and p.client_id='$cId' AND p.agence_id=$agence AND p.date >= '$du' AND p.date <= '$au' GROUP BY p.fact_id HAVING COUNT( p.fact_id ) >1") ;
 
               list($conteur)= dbi_fetch_row(dbi_query("select count(*) from fiscalll where client_id= $cId")) ; 
			   // echo "---$conteur " ; 
              if($conteur <1)
			  {
			while($ppp = dbi_fetch_row($rr))
			 {
				  
				 $k = 0 ;
				 // list($dataa, $factures, $acompte, $attdataa, $option) = unserialize($ppp['data']) ;
				 
				 			 	list($dataa, $factures, $acompte, $attdataa, $option) = unserialize($ppp['data']) ;
								
								
	
								if (empty($dataa)) {
								$data = utf8_decode($ppp['data']);
									list($dataa, $factures, $acompte, $attdataa, $option) = unserialize($data) ;
								  
								}
								
		 // echo "<pre>" ; 
	  // print_r( $dataa)  ; 
	  // echo "</pre>" 	  ;  
		
		// exit() ;
								
													foreach ($dataa as $data) {
														
														// echo "--oooooooooooooo  <br/>" ; 
						// Définition des variables
						$intrr = ''; // Toujours vide
						$duree = $data['nbH']; // Valeur commune dans les deux formats

						// Détection du format
						if (isset($data['date'])) { // Format 1
							$taux = $data['taux'];
							$mois = substr($data['date'], 4, 2); // Extraction du mois (AAAA**MM**JJ)
							$annee = substr($data['date'], 0, 4); // Extraction de l'année (**AAAA**MMJJ)
							$date_prestation = $data['date']; // Date complète YYYYMMDD
						} elseif ( (isset($data['des'])) && (trim($data['des']) != 'TOTAL'))  { // Format 2
							if (preg_match('/(\d{2})\/(\d{2})\/(\d{4})/', $data['des'], $matches)) {
								$mois = $matches[2]; // MM
								$annee = $matches[3]; // YYYY
								$date_prestation = $annee . $mois . $matches[1]; // YYYYMMDD
							} else {
								$mois = $annee = $date_prestation = ''; // Valeur vide si extraction échoue
							}
							$taux = ($data['nbH'] > 0) ? $data['somme'] / $data['nbH'] : 0; // Évite division par zéro
						} else {
							continue; // Ignore les entrées non reconnues
						}

						// Calcul de $aaaaaa
						$aaaaaa = $taux * $duree;

						// Requête d'insertion
						if($date_prestation >0){
							list($intrr)=dbi_fetch_row(dbi_query(" select inter from fiscal where dateprest= $date_prestation and client_id = $cId "));
						$query = "INSERT INTO fiscalll VALUES ('', '$intrr', '$duree', '$taux', '$mois', '$aaaaaa', '$annee', '$cId', '$date_prestation')";
						}
						// Exécution de la requête
						dbi_query($query);
					}

					
			}
			
			unset($ppp) ;


			
					while($ppp = dbi_fetch_row($rro))
			 {
				  // echo "--ffffff  <br/>" ; 
				 $k = 0 ;
				 // list($dataa, $factures, $acompte, $attdataa, $option) = unserialize($ppp['data']) ;
				 
				 			 	list($dataa, $factures, $acompte, $attdataa, $option) = unserialize($ppp['data']) ;
	
								if (empty($dataa)) {
								$data = utf8_decode($ppp['data']);
									list($dataa, $factures, $acompte, $attdataa, $option) = unserialize($data) ;
								  
								}
								
	 // echo "<pre>" ; 
	  // print_r( $dataa)  ; 
	  // echo "</pre>" 	  ;  
								
													foreach ($dataa as $data) {
						// Définition des variables
						$intrr = ''; // Toujours vide
						$duree = $data['nbH']; // Valeur commune dans les deux formats

						// Détection du format
						if (isset($data['date'])) { // Format 1
							$taux = $data['taux'];
							$mois = substr($data['date'], 4, 2); // Extraction du mois (AAAA**MM**JJ)
							$annee = substr($data['date'], 0, 4); // Extraction de l'année (**AAAA**MMJJ)
							$date_prestation = $data['date']; // Date complète YYYYMMDD
						} elseif ( (isset($data['des'])) && (trim($data['des']) != 'TOTAL'))  { // Format 2
							if (preg_match('/(\d{2})\/(\d{2})\/(\d{4})/', $data['des'], $matches)) {
								$mois = $matches[2]; // MM
								$annee = $matches[3]; // YYYY
								$date_prestation = $annee . $mois . $matches[1]; // YYYYMMDD
							} else {
								$mois = $annee = $date_prestation = ''; // Valeur vide si extraction échoue
							}
							$taux = ($data['nbH'] > 0) ? $data['somme'] / $data['nbH'] : 0; // Évite division par zéro
						} else {
							continue; // Ignore les entrées non reconnues
						}

						// Calcul de $aaaaaa
						$aaaaaa = $taux * $duree;
                        // echo "$date_prestation <br/>" ; 
						// Requête d'insertion
						if($date_prestation >0){
						list($intrr)=dbi_fetch_row(dbi_query(" select inter from fiscal where dateprest= $date_prestation and client_id = $cId "));
						// echo " select inter from fiscal where dateprest= $date_prestation and client_id = $cId <br/> " ; 
						// echo "$intrr -- $date_prestation <br/>" ; 
						$query = "INSERT INTO fiscalll VALUES ('', '$intrr', '$duree', '$taux', '$mois', '$aaaaaa', '$annee', '$cId', '$date_prestation')";
						}
						// Exécution de la requête
						dbi_query($query);
					}

					
			}
			  }
			  
	
 //************** daba*****************************	
 	// $b=dbi_query(" SELECT inter,date,taux,dateprest,sum(duree) as tt FROM fiscalll where dateee != 200 and client_id = $cId group by inter,date,taux   ORDER BY  date; ") ;	 
	
     			// while($aa=dbi_fetch_row($b))
			// {
				
				 // $client_id = $cId ; 
				 // $inter_id = $aa['inter']; 
				 // $mois=  $aa['date']  ; 
				 // $annee=  $aa['dateprest']  ; 
				 // $nbh_mois= $aa['tt'] ; 
				 // $taux=  $aa['taux']  ;
				 // $totale= $aa['taux']*$aa['tt'] ;
				 // $validite= 1 ;
				

// $resq = "INSERT INTO `nouveau_fiscal_nouveau` (`id_nouveau_fiscal`, `mois`, `anne`, `nbr_heure`, `total`, `inter`, `taux`, `client_id`) VALUES 
// ('', '$mois', '$annee', '$nbh_mois', '$totale', '$inter_id', '$taux', '$client_id')";

			// dbi_query($resq ) ; 
			// }
			
 //************** daba*****************************
			
			
     // echo "<pre>" ; 
	  // print_r( $info_presta)  ; 
	  // echo "</pre>" 	  ;  
	  
	  
	  // [type] => ded

// $data_par_mois = [];

// foreach ($info_presta as $presta) {
    // if ($presta['type'] === 'e2' OR $presta['type'] === 'ded') {
        // continue; 
    // }

    // $anne = substr($presta['date'], 0, 4);
    // $mois = substr($presta['date'], 4, 2);
    // $inter = $presta['inter']; 
    // $taux = (float) $presta['taux']; 
    // $nbr_heure = $presta['duree'] / 60; 

  
    // $key = $anne . '-' . $mois . '-' . $inter;

    // if (!isset($data_par_mois[$key])) {
        // $data_par_mois[$key] = [
            // 'anne' => $anne,
            // 'mois' => $mois,
            // 'nbr_heure' => 0,
            // 'total' => 0,
            // 'inter' => $inter,
            // 'taux' => $taux
        // ];
    // }

 
    // $data_par_mois[$key]['nbr_heure'] += $nbr_heure;
    // $data_par_mois[$key]['total'] = $data_par_mois[$key]['nbr_heure'] * $taux;
// }


foreach ($data_par_mois as $data) {
    $anne = $data['anne'];
    $mois = $data['mois'];
    $nbr_heure = $data['nbr_heure'];
    $total = $data['total'];
    $inter = $data['inter'];
    $taux = $data['taux'];

    $sql = "INSERT INTO nouveau_fiscal (anne, mois, nbr_heure, total, inter, taux, client_id) 
            VALUES ('$anne', '$mois', '$nbr_heure', '$total', '$inter', '$taux', '$client_id')";

   dbi_query($sql);
}
  if(!empty($num_fact)){
      list ($tauxx , $nbr_heuree) =  dbi_fetch_row( dbi_query("SELECT taux , nbr_heure FROM `fact_fiscal` WHERE `num_fact` = ".$num_fact)) ; 
   $sql = "INSERT INTO nouveau_fiscal (anne, mois, nbr_heure, total, inter, taux, client_id) 
            VALUES ('2023', '12', '$nbr_heuree', '$decm', '$inter', '$tauxx', '$client_id')";

   dbi_query($sql);

  }
  
 // dbi_query(' TRUNCATE table `fiscal`');


		 // if($tst!=0)
		 // {
	if (!is_dir("attestations"))
		{
			mkdir("attestations", 0755) ;
			chmod("attestations", 0755) ;
		}
		if (!is_dir("attestations/$client_id"))
		{
			mkdir("attestations/$client_id", 0755) ;
			chmod("attestations/$client_id", 0755) ;
		}
		if(($fact_id = creerAttestation($client_id, $du, $au, $f, $fromyear, $emission)) && ($fact_id!='')) {
			$f->Output("attestations/$client_id/$annee-$fact_id.pdf", 'F') ;
			$factures[] = "attestations/$client_id/$annee-$fact_id.pdf" ;
			$cpt++;
		} else {
			//echo "<!--Erreur facture fact=$fact_id-->" ;
		}
		
	// }
	}
	$fichier_pdf = "attestations/$agence-".date('d-m-Y-H:i').".pdf";
	pdf_concatene($factures, $fichier_pdf) ;

print_header ();
	$i = 0 ;
	if ($cpt) {
	?>

<fieldset>
<legend>Attestations fiscales cr&eacute;&eacute;s</legend>
<table class="td_normal">
  <?
		foreach($factures as $f)
			printf('<tr><td class="td_listing%2$d"><a href="%1$s" target="_blank">%1$s</a></td></tr>', $f, $i++%2) ;
		printf('<tr><td class="td_listing%2$d"><a href="%1$s" target="_blank">%3$s</a></td></tr>', $fichier_pdf, $i++%2, 'Toutes les attestations g&eacute;n&eacute;r&eacute;es') ;
		echo '</table></fieldset>';
	} else echo '<h3 style="color:red">Aucune attestation générée</h3>';
}


$date = date('Y-m-01');
$annee = $year = date('Y');
$mois = $month = date('m');
if(isset($_POST['datefacture']))
$datefacture = $_POST['datefacture'];
else
$datefacture = date('Y-m-d');

$months = array(
     1 => 'Janvier',
     2 => 'Février',
     3 => 'Mars',
     4 => 'Avril',
     5 => 'Mai',
     6 => 'Juin',
     7 => 'Juillet',
     8 => 'Août',
     9=> 'Septembre',
    10=> 'Octobre',
    11 => 'Novembre',
    12 => 'Décembre'
);


if(isset($_POST['mois']) && isset($_POST['annee'])){
	$datecal = $_POST['annee'].'-'.$_POST['mois'].'-01';
	$annee = $_POST['annee'];
	$mois = $_POST['mois'];
}
 // dbi_query('TRUNCATE table nouveau_fiscal_nouveau');
// echo '<pre>';
// print_r($_POST);
// echo '</pre>';
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Edition des Attestations</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- Font Awesome -->
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- daterange picker -->
  <link rel="stylesheet" href="../plugins/daterangepicker/daterangepicker.css">
  <!-- iCheck for checkboxes and radio inputs -->
  <link rel="stylesheet" href="../plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- Bootstrap Color Picker -->
  <link rel="stylesheet" href="../plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css">
  <!-- Tempusdominus Bbootstrap 4 -->
  <link rel="stylesheet" href="../plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
  <!-- Select2 -->
  <link rel="stylesheet" href="../plugins/select2/css/select2.min.css">
  <link rel="stylesheet" href="../plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css">
  <!-- Bootstrap4 Duallistbox -->
  <link rel="stylesheet" href="../plugins/bootstrap4-duallistbox/bootstrap-duallistbox.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../../dist/css/adminlte.min.css">
  <!-- Google Font: Source Sans Pro -->
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<body class="hold-transition sidebar-mini">


<div class="wrapper">
<!-- TOP MENU -->
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
  <ul class="navbar-nav">
                        <li class="nav-item">
                        <a class="nav-link" data-widget="pushmenu" href="#"></i></a>
                        </li>
                    <!-- liens TOP MENU GAUCHE-->
                        <td>
                     
                        </td>

                        <td>
                       
                        </td>
                        <td>
                    
                        </td>
                        <td>
             
                        </td>
                 </ul>

 <!-- liens TOP MENU DROITE -->
    <ul class="navbar-nav ml-auto">


     <!-- Placer ici l'élément à positionner à droite du TOP MENU -->
    </ul>

  </nav>  <!-- fin du TOP MENU -->

<?php include('menu.php'); ?>
<div  class="modal fade" id="PrestUpt" role="dialog" class="modal fade task-modal-single in" tabindex="-1"  aria-labelledby="myLargeModalLabel" >
					  <div class="modal-dialog modal-lg">
						<div class="modal-content data">
							<div id="jalil" ></div>


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



    <!-- Main content -->
    <section class="content">
		<div class="container-fluid">

	
			<div class="row">
				<!-- /.col -->
				<div class="col-md-12">
					<div class="card card-info" style='border:2px solid #17a2b8;'>
						<div class="card-header">
							<h3 class="card-title">CREATION DES ATTESTATIONS </h3>
						</div>
						<!-- form start -->
						<form role="form" method='POST' action=''>
							<!-- /.card-header -->
							<div class="card-body" >
								<div class="row">
									<div class="col-12">
										<div class="form-group">
											<select class="duallistbox" multiple="multiple" style="height: 150px;" name="client_id[]" id="client_id[]">
														<?php   $req =dbi_query("SELECT * FROM client WHERE (client_statut = '0' or  client_statut = '1')   $where and (client_id !=  11036 and client_id !=  11047 and client_id !=  11143 and client_id !=  11068 and client_id !=  11144 and client_id !=  11071   and client_id !=  11028    and client_id !=  11072   and client_id !=  11073   and client_id !=  11142   and client_id !=  11096  and client_id !=  11063  and client_id !=  11108  and client_id !=  11140   ) ORDER BY client_nom ASC") ;

																while(  $cli=dbi_fetch_row($req)) { ?>
																<option value="<?php echo $cli['client_id'] ; ?>" <?php if(in_array($cli['client_id'] , $_POST['client_id'])) echo 'selected';?>><?php echo utf8_encode($cli['client_nom']); ?></option>
														<?php   }	?>
											</select>
										</div>
									</div>

									<div class="col-sm-3">
									  <div class="form-group">
											<label>Année</label>
											<select name='duyear' id='duyear' class="form-control">
											<?php
												$earliest_year = 2018;
												foreach (range($year+3, $earliest_year) as $x) {
													print '<option value="'.$x.'"'.($x == $annee ? ' selected="selected"' : '').'>'.$x.'</option>';
												}
											?>
											</select>
									  </div>
									</div>
								
									<div class="col-sm-3">
									  <div class="form-group"><label><br/></label>
										<button type="submit" class="btn btn-block bg-gradient-primary">Valider</button>
									  </div>
									</div>
								</div>
							</div>
						</form>
					</div>
				</div> <!-- /.col -->
			</div><!-- /.row -->

		
        <!-- /.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.0.2
    </div>
    <strong>Copyright &copy; 2014-2019 <a href="http://adminlte.io">AdminLTE.io</a>.</strong> All rights
    reserved.
  </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>
<!-- Select2 -->
<script src="../plugins/select2/js/select2.full.min.js"></script>
<!-- Bootstrap4 Duallistbox -->
<script src="../plugins/bootstrap4-duallistbox/jquery.bootstrap-duallistbox.js"></script>
<!-- InputMask -->
<script src="../plugins/moment/moment.min.js"></script>
<script src="../plugins/inputmask/min/jquery.inputmask.bundle.min.js"></script>
<!-- date-range-picker -->
<script src="../plugins/daterangepicker/daterangepicker.js"></script>
<!-- bootstrap color picker -->
<script src="../plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="../plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Bootstrap Switch -->
<script src="../plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<!-- AdminLTE App -->
<script src="../../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
<!-- Page script -->
<script>
  $(function () {
$("#allcheck").click(function(){
    $('input:checkbox').not(this).prop('checked', this.checked);
});
	 var TOTALCA ="<?php echo number_format( $CATTC, 2, ',', ' ').'<sup> € </sup>';?>";
	$('#TOTALCA').html(TOTALCA);
	 var TOTALCAHT ="<?php echo number_format( $CAHT, 2, ',', ' ').'<sup> € </sup>';?>";
	$('#TOTALCAHT').html(TOTALCAHT);
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })

    //Datemask dd/mm/yyyy
    $('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
    //Datemask2 mm/dd/yyyy
    $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
    //Money Euro
    $('[data-mask]').inputmask()

    //Date range picker
    $('#reservation').daterangepicker()
    //Date range picker with time picker
    $('#reservationtime').daterangepicker({
      timePicker: true,
      timePickerIncrement: 30,
      locale: {
        format: 'MM/DD/YYYY hh:mm A'
      }
    })
    //Date range as a button
    $('#daterange-btn').daterangepicker(
      {
        ranges   : {
          'Today'       : [moment(), moment()],
          'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
          'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
          'Last 30 Days': [moment().subtract(29, 'days'), moment()],
          'This Month'  : [moment().startOf('month'), moment().endOf('month')],
          'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        },
        startDate: moment().subtract(29, 'days'),
        endDate  : moment()
      },
      function (start, end) {
        $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
      }
    )

    //Timepicker
    $('#timepicker').datetimepicker({
      format: 'LT'
    })

    //Bootstrap Duallistbox
    $('.duallistbox').bootstrapDualListbox()

    //Colorpicker
    $('.my-colorpicker1').colorpicker()
    //color picker with addon
    $('.my-colorpicker2').colorpicker()

    $('.my-colorpicker2').on('colorpickerChange', function(event) {
      $('.my-colorpicker2 .fa-square').css('color', event.color.toString());
    });

    $("input[data-bootstrap-switch]").each(function(){
      $(this).bootstrapSwitch('state', $(this).prop('checked'));
    });

  })
</script>
</body>


</html>

AnonSec - 2021