[ Index ]

PHP Cross Reference of IEUF

title

Body

[close]

/gestion/ -> paiement.php (source)

   1  <?php
   2  require  'inc/autorisation.inc.php';
   3  if (NonBureau()) include  'inc/404.php';
   4  header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
   5  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé
   6  include  "../inclus/connect_bd.inc.php";
   7  
   8  $an_adh = date("n")<9 ? date("Y")-1 : date("Y");
   9  $date_deb = $an_adh."-09-01";
  10  ?>
  11  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  12  "http://www.w3.org/TR/html4/loose.dtd">
  13  <html>
  14    <head>
  15      <meta name="generator" content="HTML Tidy for Windows (vers 12 April 2005), see www.w3.org">
  16      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
  17      <title>
  18        Paiement
  19      </title>
  20      <?php
  21      if (isset($_POST['valide'])) {
  22        echo "<pre>";
  23        print_r($_POST);
  24        echo "</pre>";
  25  
  26        // Mise à jour adhesion
  27        foreach ($_POST as $i => $val)  {
  28          if (substr($i,0,3) == 'adh') {
  29             $id_adh = substr($i,3,strlen($i)-3);
  30             $requete = "UPDATE adhesion SET cout='".$val."', mod_du=".$_POST["mod_du"].", commentaire='".$_POST["com$id_adh"]."' WHERE id=$id_adh";
  31             $res= mysql_query($requete); if ($res === false) die(mysql_error());
  32             }
  33          else if (substr($i,0,2) == 'at' && substr($i,strlen($i)-1,1) == "1") {
  34             $a = explode("_", $i);
  35             $id_at = substr($a[0],2);
  36             $id_adh = $a[1];
  37             $requete = "UPDATE participe SET cout_1='".$val."', cout_2='".$_POST["at$id_at"."_$id_adh"."_2"]."', cout_3='".$_POST["at$id_at"."_$id_adh"."_3"]."'
  38                         WHERE id_adh=$id_adh AND id_atelier=$id_at";
  39             $res= mysql_query($requete); if ($res === false) die(mysql_error());
  40             }
  41        }
  42        // Mise a jour reglement
  43        $id_payeur=$_POST['id_payeur'];
  44        $requete = "DELETE FROM reglement WHERE id_payeur=$id_payeur AND date>='$date_deb'";
  45        $res= mysql_query($requete); if ($res === false) die(mysql_error());
  46        $ind=1;
  47        while (isset($_POST['paye'.$ind])) {
  48          $majdate= "date= NULL";
  49          $t_date= explode('-', $_POST['date'.$ind]);
  50          if (count($t_date) == 3 && $_POST['paye'.$ind] != 0) {
  51            $majdate= "date='".implode('-', array_reverse($t_date))."'";
  52            $requete = "INSERT reglement SET id_payeur='".$id_payeur."', nature='".$_POST["nature".$ind]."', ident_paiement='".$_POST["ident".$ind]."',
  53                        $majdate, montant='".$_POST['paye'.$ind]."'";
  54            $res= mysql_query($requete); if ($res === false) die(mysql_error());
  55          }
  56          $ind++;
  57        }
  58  //     exit;
  59      echo "<script type='text/JavaScript'>
  60          if (opener && opener.document.parametres) opener.document.parametres.submit();
  61          window.close();
  62          </script>";
  63  
  64      exit;
  65     }
  66  
  67      ?>
  68      <link rel="stylesheet" href="formulaire.css" type="text/css">
  69      <style type="text/css">
  70      h2 {
  71        font-size: 20pt;
  72        line-height: 6pt;
  73      }
  74      h3 {
  75        font-size: 14pt;
  76        line-height: 0;
  77        margin-top: 12px;
  78        margin-bottom: 8px;
  79      }
  80      h4 {
  81        font-size: 12pt;
  82        line-height: 0;
  83        margin-bottom: 8px;
  84        margin-top: 8px;
  85      }
  86      #a_jour{
  87        border: 4px inset #cc0000;
  88        font-family: "Courier New",Courier,monospace;
  89        background-color: #ff6666;
  90        color: #ff6666;
  91        font-size: 25px;
  92        font-weight: bold;
  93        margin-right: 10px;
  94        cursor: pointer;
  95      }
  96      </style>
  97      <script type="text/javascript">
  98  <!--
  99        function Ctrl_number(elt) {
 100          elt.value=elt.value.replace(/,/, ".");
 101          var num=Number(elt.value);
 102          if (num != elt.value) {
 103            alert ("Touche non numérique");
 104            //elt.value=elt.value.replace(/\D/, "");
 105            elt.value=parseFloat(elt.value).toFixed(2);
 106          }
 107        }
 108  
 109        function Tot_gen() {
 110          var tab_input=document.getElementsByTagName('input');
 111          var tot_du = 0;
 112          var tot_paye=0;
 113          for (var i= 0; i <tab_input.length; i++) {
 114            var nom_input= tab_input.item(i).name;
 115            if (nom_input) {
 116              if (nom_input.substr(0,3) == "adh" || nom_input.substr(0,2) == "at")
 117                tot_du += parseFloat(tab_input.item(i).value);
 118              else if (nom_input.substr(0,4) == "paye")
 119                tot_paye += parseFloat(tab_input.item(i).value);
 120            }
 121          }
 122         document.getElementById('tot_du').innerHTML=tot_du.toFixed(2);
 123         document.getElementById('tot_paye').innerHTML=tot_paye.toFixed(2);
 124         var reste = tot_du - tot_paye;
 125         document.getElementById('reste').innerHTML=reste.toFixed(2);
 126        }
 127        
 128        function Ajout_reg() {
 129          ce_jour=new Date();
 130          numreg++;
 131          elt_tr=document.createElement('tr');
 132          elt_td1=document.createElement('td');
 133          elt_inp1=document.createElement('input');
 134          elt_inp1.setAttribute('name', 'paye'+numreg);
 135          elt_inp1.setAttribute('onchange', 'Tot_gen();');
 136          elt_inp1.setAttribute('onkeyup', 'Ctrl_number(this);');
 137          elt_td1.appendChild(elt_inp1);
 138          elt_tr.appendChild(elt_td1);
 139  
 140          elt_td2=document.createElement('td');
 141          elt_inp2=document.createElement('select');
 142          elt_inp2.setAttribute('name', 'nature'+numreg);
 143          elt_nature=document.createElement("option");
 144          elt_nature.setAttribute("value", "ch");
 145          elt_txt=document.createTextNode("chèque");
 146          elt_nature.appendChild(elt_txt);
 147          elt_inp2.appendChild(elt_nature);
 148          elt_nature=document.createElement("option");
 149          elt_nature.setAttribute("value", "esp");
 150          elt_txt=document.createTextNode("espèces");
 151          elt_nature.appendChild(elt_txt);
 152          elt_inp2.appendChild(elt_nature);
 153          elt_nature=document.createElement("option");
 154          elt_nature.setAttribute("value", "pc");
 155          elt_txt=document.createTextNode("participation collectivité");
 156          elt_nature.appendChild(elt_txt);
 157          elt_inp2.appendChild(elt_nature);
 158          elt_nature=document.createElement("option");
 159          elt_nature.setAttribute("value", "au");
 160          elt_txt=document.createTextNode("autres");
 161          elt_nature.appendChild(elt_txt);
 162          elt_inp2.appendChild(elt_nature);
 163          elt_td2.appendChild(elt_inp2);
 164          elt_tr.appendChild(elt_td2);
 165  
 166          elt_td3=document.createElement('td');
 167          elt_inp3=document.createElement('input');
 168          elt_inp3.setAttribute('name', 'ident'+numreg);
 169          elt_td3.appendChild(elt_inp3);
 170          elt_tr.appendChild(elt_td3);
 171  
 172          elt_td4=document.createElement('td');
 173          elt_inp4=document.createElement('input');
 174          elt_inp4.setAttribute('name', 'date'+numreg);
 175          elt_inp4.setAttribute('onblur',"VerifDate(this);");
 176          elt_inp4.setAttribute('value', ce_jour.getDate()+"-"+(ce_jour.getMonth()+1)+"-"+ce_jour.getFullYear());
 177          elt_td4.appendChild(elt_inp4);
 178          elt_tr.appendChild(elt_td4);
 179          
 180          document.getElementById('tab_reg').appendChild(elt_tr);
 181          elt_inp1.focus();
 182        }
 183        
 184        function CocheAJour() {
 185          if (document.getElementById('mod_du').value != '0') {
 186            document.getElementById('mod_du').value= '0';
 187            document.getElementById('a_jour').style.color= 'black';
 188          }
 189          else {
 190            document.getElementById('mod_du').value= '1';
 191            document.getElementById('a_jour').style.color= '';        
 192          }
 193        }
 194  
 195        function FocusTempo(elt, mesg) {
 196          element= elt;
 197          msg= mesg;
 198          setTimeout("element.focus()", 1000);
 199          setTimeout("alert(msg)", 2000);
 200        }
 201  
 202        function TestDate(val_date) {
 203           var msg= "";
 204           if (val_date!='') {
 205            var date_pas_sure = val_date;
 206            var format = /^(\d{1,2}\-){2}\d{4}$/;
 207            if (!format.test(date_pas_sure)){
 208              msg= " n'est pas une date !";
 209            }
 210            else {
 211              var date_temp = date_pas_sure.split('-');
 212              date_temp[1] -=1;        // On rectifie le mois !!!
 213              var date_deb = '<?php echo $date_deb; ?>'; // Récupération de la date de référence PHP (texte) en javascript(texte)
 214              var ma_date= new Date(); // Objets javascript
 215              var aujourdhui= new Date(); // Objets javascript
 216              ma_date.setFullYear(date_temp[2]);
 217              ma_date.setMonth(date_temp[1]);
 218              ma_date.setDate(date_temp[0]);
 219              var num_j= date_temp[0]; if (num_j.length < 2) num_j= "0"+num_j;
 220              var num_m= date_temp[1]+1; num_m= num_m.toString(); if (num_m.length < 2) num_m= "0"+num_m;
 221              var ma_date_txt= date_temp[2]+"-"+num_m+"-"+num_j;
 222              if (ma_date.getFullYear()!=date_temp[2] || ma_date.getMonth()!=date_temp[1] || ma_date.getDate()!=date_temp[0]) {
 223                msg= " est une date non valable !";     
 224              }
 225              else if (ma_date_txt < date_deb || ma_date > aujourdhui) {
 226                msg= " doit être comprise entre le 1° septembre dernier et aujourd'hui";
 227              }
 228            }
 229          }
 230         return msg;
 231        }
 232        
 233        function VerifDate(elt) {
 234           var msg= TestDate(elt.value);         
 235           if (msg != "") {
 236             FocusTempo(elt, elt.value+msg);
 237             elt.value='';
 238           }
 239        }
 240  
 241        
 242        function Initialise() {
 243          Tot_gen();
 244          CocheAJour();
 245          CocheAJour();
 246        }
 247        
 248        function Ctrl_Gen() {
 249          msg='';
 250          tab_inp=document.getElementsByTagName('input');
 251          for (var elt_inp in tab_inp) {
 252                      if (!tab_inp[elt_inp].name) continue;
 253            if (tab_inp[elt_inp].name.substr(0,3) == 'adh') {
 254              val= tab_inp[elt_inp].value;
 255              if (parseFloat(val) != val) msg +="Ce montant d'adhésion n'est pas valide : "+tab_inp[elt_inp].value+"\r\n";
 256            }
 257            else if (tab_inp[elt_inp].name.substr(0,2) == 'at') {
 258              val= tab_inp[elt_inp].value;
 259              if (parseFloat(val) != val) msg +="Ce montant d'atelier n'est pas valide : "+tab_inp[elt_inp].value+"\r\n";
 260            }         
 261            else if (tab_inp[elt_inp].name.substr(0,4) == 'paye') {
 262              val= tab_inp[elt_inp].value;
 263                          if (val == "") continue;
 264              if (parseFloat(val) != val) msg +="Ce montant payé n'est pas valide : "+tab_inp[elt_inp].value+"\r\n";
 265            }
 266            else if (tab_inp[elt_inp].name.substr(0,4) == 'date') {
 267              val= tab_inp[elt_inp].value;
 268              if (val == "") msg += "Une date de payement est vide\r\n";
 269              else {
 270                var mes_date= TestDate(val);
 271                if (mes_date != "") msg +="Cette date : "+tab_inp[elt_inp].value+ mes_date +"\r\n";
 272              }
 273            }
 274          }
 275          if (msg != '') {
 276            alert (msg);
 277            return false;
 278          }
 279          return true;
 280        }
 281        
 282        // -->
 283      </script>
 284    </head>
 285    <body onload="Initialise()">
 286     <?php
 287     if (isset($_POST['id_payeur'])) { //2° appel : validation
 288         exit;
 289     }
 290     //1° appel : formulaire
 291     $cout=0;
 292  
 293     if (isset($_GET['idb'])) {
 294         $requete= "SELECT id_payeur FROM adhesion WHERE id='".$_GET['idb']."'";
 295         $recherche=mysql_query($requete); if ($recherche === false) echo mysql_error();
 296         if (($col= mysql_fetch_assoc($recherche)) === false) exit ("ID inconnu");
 297         $id_payeur= $col['id_payeur'];
 298     }
 299     else exit ("Erreur d'appel");
 300     $requete= "SELECT nom, prenom, DATE_FORMAT(DateNaiss, '%d-%m-%Y') as DateNaiss FROM personne, payeur WHERE payeur.id='$id_payeur' AND id_perso_p=personne.id";
 301     $recherche=mysql_query($requete); if ($recherche === false) echo mysql_error();
 302     if (($col= mysql_fetch_assoc($recherche)) === false) exit ("ID inconnu");
 303     extract($col);
 304  
 305     ?>
 306      <h2>
 307        Payeur : <?php echo "$nom $prenom, <span style='font-size: 12pt;'>date de naissance : $DateNaiss</span>"; ?>
 308      </h2>
 309      <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="paiement" id="paiement" onsubmit="return Ctrl_Gen()">
 310        <input type="hidden" name="id_payeur" value="<?php echo $id_payeur; ?>">
 311        <?php
 312         $requete= "SELECT adhesion.id as id_adhesion, id_perso, cout, nom, prenom, mod_du,
 313                            DATE_FORMAT(DateNaiss, '%d-%m-%Y') as DateNaiss, commentaire
 314                      FROM adhesion, personne
 315                      WHERE id_payeur='$id_payeur' AND personne.id=id_perso AND date_adhesion>'$date_deb'";
 316         $recherche_p=mysql_query($requete); if ($recherche_p === false) echo mysql_error();
 317         while (($col_p= mysql_fetch_assoc($recherche_p))) {
 318             extract($col_p);
 319        ?>
 320        <table border="1" cellpadding="2" cellspacing="2" width="100%">
 321          <tbody>
 322            <tr>
 323              <td colspan="5" rowspan="1">
 324                <h3>
 325                  Bénéficiaire : <?php echo $nom." ".$prenom." (".$DateNaiss.")"; ?>
 326                </h3>
 327                  Commentaire <input type="text" name="com<?php echo "$id_adhesion";?>" value="<?php echo "$commentaire";?>" size="100" maxlength="255">
 328              </td>
 329            </tr>
 330            <tr>
 331              <td width="100">
 332                <h3>
 333                  Adhésion
 334                </h3>
 335              </td>
 336              <td colspan="4" rowspan="1">
 337                <input name="adh<?php echo "$id_adhesion";?>" onchange="Tot_gen();" onkeyup="Ctrl_number(this)" value="<?php echo $cout;?>">
 338              </td>
 339            </tr>
 340            <tr>
 341              <td width="100">
 342                <h3>
 343                  Ateliers
 344                </h3>
 345              </td>
 346              <td></td>
 347              <td>
 348                <h4>
 349                  1° trimestre
 350                </h4>
 351              </td>
 352              <td>
 353                <h4>
 354                  2° trimestre
 355                </h4>
 356              </td>
 357              <td>
 358                <h4>
 359                  3° trimestre
 360                </h4>
 361              </td>
 362            </tr>
 363            <?php
 364            $requete="SELECT id_atelier, cout_1, cout_2,cout_3, lettre FROM participe, atelier WHERE id_adh='$id_adhesion' AND atelier.id=id_atelier";
 365            $recherche=mysql_query($requete); if ($recherche === false) echo mysql_error();
 366            while (($col= mysql_fetch_assoc($recherche))) {
 367                extract($col);
 368            ?>
 369            <tr>
 370              <td width="100"></td>
 371              <td>
 372                <?php echo $lettre;?>
 373              </td>
 374              <td>
 375                <input name="at<?php echo "{$id_atelier}_{$id_adhesion}_1";?>" onchange="Tot_gen();" onkeyup="Ctrl_number(this)" value="<?php echo $cout_1;?>">
 376              </td>
 377              <td>
 378                <input name="at<?php echo "{$id_atelier}_{$id_adhesion}_2";?>" onchange="Tot_gen();"  onkeyup="Ctrl_number(this)" value="<?php echo $cout_2;?>">
 379              </td>
 380              <td>
 381                <input name="at<?php echo "{$id_atelier}_{$id_adhesion}_3";?>" onchange="Tot_gen();"  onkeyup="Ctrl_number(this)" value="<?php echo $cout_3;?>">
 382              </td>
 383            </tr>
 384            <?php }?>
 385  
 386          </tbody>
 387        </table>
 388        <?php
 389        }
 390        ?>
 391        <h3>
 392          Total à payer : <span id="tot_du"> </span>
 393        </h3>
 394        <p>&nbsp;</p>
 395        <table style="background-color: rgb(102, 102, 102); color: white;" border="1" cellpadding="2" cellspacing="2"
 396        width="100%">
 397          <tbody id="tab_reg">
 398            <tr>
 399              <td>
 400                <h4>
 401                  Payé
 402                </h4>
 403                <p style="font-size: 8pt; font-weight: lighter; margin:0pt">(vide ou 0 pour supprimer le payement)</p>
 404              </td>
 405              <td>
 406                <h4>
 407                  Nature
 408                </h4>
 409              </td>
 410              <td>
 411                <h4>
 412                  Identification paiement
 413                </h4>
 414              </td>
 415              <td>
 416                <h4>
 417                  Date
 418                </h4>
 419              </td>
 420            </tr>
 421            <?php
 422            $numreg=0;
 423            $montant=0;
 424            $nature=$ident_paiement=$DatePai="";
 425            $requete="SELECT nature, ident_paiement, DATE_FORMAT(date, '%d-%m-%Y') as DatePai, montant FROM reglement
 426                      WHERE id_payeur='$id_payeur' AND date>='$date_deb' ORDER BY id";
 427            $recherche=mysql_query($requete); if ($recherche === false) echo mysql_error();
 428            while (($col= mysql_fetch_assoc($recherche))) {
 429                $numreg++;
 430                extract($col);
 431                ?>
 432                <tr>
 433                  <td>
 434                    <input name="paye<?php echo $numreg;?>" value="<?php echo $montant;?>" onchange="Tot_gen();" onKeyup="Ctrl_number(this)">
 435                  </td>
 436                  <td>
 437                    <select name="nature<?php echo $numreg;?>">
 438                      <option value="ch" <?php if ($nature == 'ch') echo "selected='selected'" ?>>chèque</option>
 439                      <option value="esp" <?php if ($nature == 'esp') echo "selected='selected'" ?>>espèces</option>
 440                      <option value="pc" <?php if ($nature == 'pc') echo "selected='selected'" ?>>participation collectivité</option>
 441                      <option value="au" <?php if ($nature == 'au') echo "selected='selected'" ?>>autres</option>
 442                    </select>
 443                  </td>
 444                  <td>
 445                    <input name="ident<?php echo $numreg;?>" value="<?php echo $ident_paiement;?>">
 446                  </td>
 447                  <td>
 448                    <input id="date<?php echo $numreg;?>" name="date<?php echo $numreg;?>" onblur="VerifDate(this);" value="<?php echo $DatePai;?>">
 449                  </td>
 450                </tr>
 451            <?php }
 452            ?>
 453          </tbody>
 454        </table>
 455        <script type='text/javascript'>
 456           numreg= <?php echo $numreg; ?>;
 457        </script>
 458        <input type="button" value="Ajouter un règlement" onclick="Ajout_reg();"><br>
 459        <table style="background-color: white;" border="0" cellpadding="0" cellspacing="0" width="100%">
 460          <tbody>
 461            <tr>
 462              <td>
 463                <h2>
 464                  Total payé : <span id='tot_paye'> </span>
 465                </h2>
 466                <h2>
 467                  Reste à payer : <span id='reste'> </span>
 468                </h2>
 469              </td>
 470              <td>
 471                <?php if (Troika()) { ?>
 472                <input type="hidden" name="mod_du" id="mod_du" value="<?php echo $mod_du; ?>">
 473                  <span id="a_jour" onclick="CocheAJour()">X</span>Adhérent à jour <br>
 474                  <!-- <input  type="checkbox" name="mod_du"> Adhérent à jour <br> -->
 475                  <input style="font-size: 18pt;" name="valide" value="Valider" type="submit"> &nbsp; &nbsp;
 476                <?php }?>
 477                  <input style="font-size: 12pt;" name="abandon" value="Abandonner" type="button" onclick="self.close();">
 478              </td>
 479            </tr>
 480          </tbody>
 481        </table>
 482        <br>
 483      </form>
 484    </body>
 485  </html>


Generated: Fri Jan 31 19:59:00 2014 Cross-referenced by PHPXref 0.7.1