PageRenderTime 23ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/rechercherFacture.php

#
PHP | 323 lines | 239 code | 61 blank | 23 comment | 36 complexity | f115aa5d472d3fe989a47e2194a065aa MD5 | raw file
Possible License(s): AGPL-3.0, GPL-2.0
  1. <?php
  2. /*
  3. GCourrier
  4. Copyright (C) 2005, 2006 Cliss XXI
  5. This file is part of GCourrier.
  6. GCourrier is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Affero General Public License as
  8. published by the Free Software Foundation, either version 3 of the
  9. License, or (at your option) any later version.
  10. GCourrier is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Affero General Public License for more details.
  14. You should have received a copy of the GNU Affero General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. require_once('init.php');
  18. include('templates/header.php');
  19. if (!isset($_GET["rechercher"])) {
  20. ?>
  21. <div id =pageTGd><br>
  22. <center><b>RECHERCHE FACTURE</b><br><br>
  23. <form action='rechercherFacture.php'>
  24. <table align = center>
  25. <tr>
  26. <td>Numéro</td>
  27. <td><input type="text" name="numero"></input></td>
  28. </tr>
  29. <tr>
  30. <td>Réf. Facture</td>
  31. <td><input type="text" name="refFacture"></input></td>
  32. </tr>
  33. <tr>
  34. <td>Montant</td>
  35. <td colspan=>
  36. <select name="montant_op">
  37. <option value="<">&lt;</option>
  38. <option value="=">=</option>
  39. <option value=">">&gt;</option>
  40. </select>
  41. <input type="text" name="montant" />
  42. </td>
  43. </td>
  44. <tr>
  45. <td>Observation</td>
  46. <td><input type="text" name="observation"> (contient cette phrase)</td>
  47. </tr>
  48. <tr>
  49. <td>Date arrivée mairie</td>
  50. <td><input type="text" name="dateArrivee" value="jj-mm-aaaa" /></td>
  51. </tr>
  52. <td>Date origine fournisseur</td>
  53. <td><input type="text" name="dateOrigine" value="jj-mm-aaaa" /></td>
  54. </tr>
  55. <tr>
  56. <td>Enregistré entre</td>
  57. <td><input type="text" name="eDate1" value="jj-mm-aaaa" />
  58. et <input type="text" name="eDate2" value="jj-mm-aaaa" /></td>
  59. </tr>
  60. <tr>
  61. <td>Fournisseur</td>
  62. <td><select name="fournisseur">
  63. <option value="rien">(tous)</option>
  64. <?php
  65. $requete = "SELECT * FROM destinataire ORDER BY nom";
  66. $result = mysql_query($requete) or die( mysql_error() );
  67. while( $ligne = mysql_fetch_array( $result ) ){
  68. echo "<option value = '".$ligne['id']."'>".$ligne['nom']." ".$ligne['prenom']."</option>";
  69. }
  70. ?></select></td>
  71. </tr>
  72. <tr>
  73. <td>Service</td>
  74. <td><select name="serviceDest">
  75. <option value="rien">(tous)</option>
  76. <?php
  77. $requete = "SELECT * FROM service WHERE libelle <> 'admin' ORDER BY libelle";
  78. $result = mysql_query($requete) or die ( mysql_error() );
  79. while( $ligne = mysql_fetch_array( $result ) ){
  80. echo "<option value = '".$ligne['id']."'>".$ligne['libelle']." ".$ligne['designation']."</option>";
  81. }
  82. ?>
  83. </td>
  84. </tr>
  85. <td><label>Courrier retard</label></td>
  86. <td><input type="checkbox" name="retard"/></td>
  87. </tr>
  88. </table>
  89. <br><input type="submit" name="rechercher" value="Rechercher" />
  90. </form>
  91. </div>
  92. <?php
  93. } else {
  94. //
  95. // Results
  96. //
  97. echo"<center>";
  98. echo "<div id = titre>RESULTAT DE LA RECHERCHE</div><br></b>";
  99. $serviceDest = $_GET['serviceDest'];
  100. $numero = $_GET['numero'];
  101. $refFacture = $_GET['refFacture'];
  102. $dateArrivee = $_GET['dateArrivee'];
  103. $dateOrigine = $_GET['dateOrigine'];
  104. $eDate1 = $_GET['eDate1'];
  105. $eDate2 = $_GET['eDate2'];
  106. $fournisseur = $_GET['fournisseur'];
  107. $montant = $_GET['montant'];
  108. $montant_op = $_GET['montant_op'];
  109. $observation = $_GET['observation'];
  110. $requetetmp = "SELECT facture.id AS idCourrier,
  111. facture.montant AS montant,
  112. facture.refFacture AS refFacture,
  113. facture.dateFacture AS dateArrivee,
  114. facture.dateFactureOrigine AS dateOrigine,
  115. destinataire.nom AS nomDest,
  116. destinataire.prenom AS prenomDest,
  117. priorite.nbJours AS nbJours,
  118. facture.montant AS montant,
  119. facture.observation AS observation
  120. ";
  121. $from =" FROM facture,destinataire,priorite ";
  122. $where =" WHERE facture.validite = 0 and facture.idServiceCreation=".$_SESSION['idService']." and
  123. priorite.id = facture.idPriorite ";
  124. $requete = '';
  125. if ($numero != "") {
  126. $requete.= " AND facture.id = '".$numero."' ";
  127. }
  128. if ($montant != '' and is_numeric($montant)) {
  129. if ($montant_op == '<')
  130. $requete.= " AND montant < $montant ";
  131. else if ($montant_op == '=')
  132. $requete.= " AND montant = $montant ";
  133. else if ($montant_op == '>')
  134. $requete.= " AND montant > $montant ";
  135. }
  136. if ($observation != '') {
  137. $observation = mysql_real_escape_string($observation);
  138. $requete .= " AND observation LIKE '%$observation%' ";
  139. }
  140. if($refFacture != '') {
  141. $requete.= " AND facture.refFacture = '".$refFacture."' ";
  142. }
  143. if(strcmp($dateArrivee,"jj-mm-aaaa")!=0){
  144. $tmpdatearrivee= substr($dateArrivee, 6,4);
  145. $tmpdatearrivee.='-';
  146. $tmpdatearrivee.=substr($dateArrivee, 3,2);
  147. $tmpdatearrivee.='-';
  148. $tmpdatearrivee.=substr($dateArrivee, 0,2);
  149. $dateArrivee = $tmpdatearrivee;
  150. $requete.= " AND facture.dateFacture = '".$dateArrivee."' ";
  151. }
  152. if(strcmp($dateOrigine,"jj-mm-aaaa")!=0){
  153. $tmpdateorigine= substr($dateOrigine, 6,4);
  154. $tmpdateorigine.='-';
  155. $tmpdateorigine.=substr($dateOrigine, 3,2);
  156. $tmpdateorigine.='-';
  157. $tmpdateorigine.=substr($dateOrigine, 0,2);
  158. $dateOrigine = $tmpdateorigine;
  159. $requete.= " AND facture.dateOrigine = '".$dateOrigine."' ";
  160. }
  161. if($serviceDest != "rien") {
  162. $requete .=" AND facture.id = estTransmisCopie.idFacture AND estTransmisCopie.idService = service.id AND service.id =".$serviceDest." ";
  163. $from.=" ,service,estTransmisCopie ";
  164. }
  165. if ($fournisseur != "rien") {
  166. $requete .= " AND facture.idFournisseur = destinataire.id AND destinataire.id = {$fournisseur}";
  167. } else {
  168. $requete .= " AND facture.idFournisseur = destinataire.id ";
  169. }
  170. if(strcmp($eDate1,"jj-mm-aaaa")!=0 && strcmp($eDate2,"jj-mm-aaaa")!=0){
  171. $tmpdate= substr($eDate1, 6,4);
  172. $tmpdate.='-';
  173. $tmpdate.=substr($eDate1, 3,2);
  174. $tmpdate.='-';
  175. $tmpdate.=substr($eDate1, 0,2);
  176. $eDate1 = $tmpdate;
  177. $tmpdate= substr($eDate2, 6,4);
  178. $tmpdate.='-';
  179. $tmpdate.=substr($eDate2, 3,2);
  180. $tmpdate.='-';
  181. $tmpdate.=substr($eDate2, 0,2);
  182. $eDate2 = $tmpdate;
  183. $requete.=" AND facture.dateFacture >='".$eDate1."' AND facture.dateFacture<='".$eDate2."' ";
  184. }
  185. $requetetmp .= " ".$from." ".$where." ".$requete." ";
  186. $requete = $requetetmp;
  187. $result = mysql_query( $requete ) or die ( mysql_error() ) ;
  188. echo "<table align=center font-color ='white' class='resultats'>";
  189. echo "<tr>";
  190. echo "<td align=center>numero</td>";
  191. echo "<td aling=center>fournisseur</td>";
  192. echo "<td align=center>refFacture</td>";
  193. echo "<td align=center>montant</td>";
  194. echo "<td align=center>date mairie</td>";
  195. echo "<td align=center>date facture</td>";
  196. echo "<td align=center>observation</td>";
  197. echo "<td align=center>historique</td>";
  198. echo "<td align=center>archiver</td>";
  199. echo "<td align=center>Jours restant</td>";
  200. echo "</tr>";
  201. $boul = 0;
  202. while ($ligne = mysql_fetch_array($result)) {
  203. if ($boul == 0) {
  204. $couleur = 'lightblue';
  205. $boul = 1;
  206. } else {
  207. $couleur = 'white';
  208. $boul = 0;
  209. }
  210. # remaining days
  211. $tmpDateArrivee = $ligne['dateArrivee'];
  212. $jourArrivee = substr($tmpDateArrivee,8,2);
  213. $moisArrivee = substr($tmpDateArrivee,5,2);
  214. $anneeArrivee = substr($tmpDateArrivee,0,4);
  215. $nbJours = $ligne['nbJours'];
  216. $timestampActuel = time();
  217. $timestampArrivee= mktime(0, 0, 0, $moisArrivee, $jourArrivee, $anneeArrivee);
  218. $urgence = ($timestampActuel - $timestampArrivee ) / 86400;
  219. $nbJoursRestant = $nbJours - (int)$urgence;
  220. $display_current = true;
  221. if (isset($_GET['retard']) && ($nbJoursRestant > 5))
  222. $display_current = false;
  223. if ($display_current)
  224. {
  225. echo "<tr>";
  226. $id = $ligne['idCourrier'];
  227. $tmp= substr($ligne['dateArrivee'], 8,2);
  228. $tmp.='-';
  229. $tmp.=substr($ligne['dateArrivee'], 5,2);
  230. $tmp.='-';
  231. $tmp.=substr($ligne['dateArrivee'], 0,4);
  232. $tmp2= substr($ligne['dateOrigine'], 8,2);
  233. $tmp2.='-';
  234. $tmp2.=substr($ligne['dateOrigine'], 5,2);
  235. $tmp2.='-';
  236. $tmp2.=substr($ligne['dateOrigine'], 0,4);
  237. if ($ligne['observation'] == '')
  238. $obs = "modifier";
  239. else
  240. $obs = $ligne['observation'];
  241. echo "<td bgcolor='$couleur'>".$ligne['idCourrier']."</td>";
  242. echo "<td bgcolor='$couleur'>".$ligne['nomDest']." ".$ligne['prenomDest']."</td>";
  243. echo "<td bgcolor='$couleur'>".$ligne['refFacture']."</td>";
  244. echo "<td bgcolor='$couleur'>".$ligne['montant']."</td>";
  245. echo "<td bgcolor='$couleur'>".$tmp."</td>";
  246. echo "<td bgcolor='$couleur'>".$tmp2."</td>";
  247. echo "<td bgcolor='$couleur'><a href='modifObservationFacture.php?idCourrier=$id'>{$obs}</a></td>";
  248. echo "<td bgcolor='$couleur'><a href='rechercherFactureHistorique.php?idCourrier=$id'>historique</a></td>";
  249. echo "<td bgcolor='$couleur'><a href='validerFactureRecherche.php?idCourrier=$id'>archiver</a></td>";
  250. echo "<td bgcolor='$couleur'>$nbJoursRestant</td>";
  251. echo "</tr>";
  252. }
  253. } // while
  254. echo "</table>";
  255. echo "<br><a href='rechercherFacture.php'>Nouvelle recherche</a>";
  256. echo "</center>";
  257. } // Results
  258. include('templates/footer.php');