PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/invoice_list.php

#
PHP | 260 lines | 204 code | 33 blank | 23 comment | 15 complexity | 2b33224cee77fc93292384915fddf7db MD5 | raw file
Possible License(s): AGPL-3.0, GPL-2.0
  1. <?php
  2. /*
  3. Display invoices so they can be reviewed and modified
  4. Copyright (C) 2005, 2006, 2010 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. require_once('classes/SQLDataGrid.php');
  19. include('templates/header.php');
  20. $requeteInit = "Select id from facture Limit 1;";
  21. $result = mysql_query($requeteInit) or die(mysql_error());
  22. if(mysql_num_rows($result) == 0){
  23. echo "<div style='text-align: center'>" . _("Aucune facture pour le moment.") . "</div>";
  24. echo "<div style='text-align: center'><a href='index.php'>Index</a></div>";
  25. exit();
  26. }
  27. ?>
  28. <form method="get" action="#result">
  29. <table align=center style="border: 1px dotted black;"><tr><td>
  30. <label>Aller à la facture numéro:</label>
  31. <input type="text" name="idFactureRecherche" value="1" size="2"></input>
  32. <input type="submit" value="OK"></input>
  33. <br /><center><span style="font-size: x-small"><a href="rechercherFacture.php">Recherche avancée</a></span></center>
  34. </td></tr></table></form>
  35. <form method="get" action="invoice_delete.php">
  36. <table align="center" style="border: 1px dotted black;">
  37. <tr><td><label>Annuler la facture numéro:</label>
  38. <input type="text" name="id" value="1" size="2" />
  39. <input type="submit" value="OK"></input>
  40. </td></tr>
  41. </table>
  42. </form>
  43. <?php
  44. echo"<center><div id= titre>Factures / <a href='copieFacture.php'>Copies de Factures</a>";
  45. echo "<br/><br/>";
  46. echo "<i style='font-size:10px; font-weight:normal'>";
  47. echo _("Voici les les factures en cours de votre service.");
  48. echo "</i><br/><br/></div></center>";
  49. if ($_SESSION['login'] == 'admin')
  50. {
  51. $requeteFacture = "SELECT facture.id AS idFacture,
  52. facture.histo AS histo,
  53. refFacture AS refFacture,
  54. refuse AS refuse,
  55. montant AS montant,
  56. dateFacture AS dateFacture,
  57. dateFactureOrigine AS dateFactureOrigine,
  58. observation AS observation,
  59. destinataire.nom AS nomFournisseur,
  60. destinataire.id AS idDest,
  61. destinataire.prenom AS prenomFournisseur,
  62. priorite.nbJours AS nbJours,
  63. unix_timestamp(datesaisie) AS internal_timestamp
  64. FROM facture
  65. LEFT JOIN destinataire ON facture.idFournisseur = destinataire.id
  66. LEFT JOIN priorite ON facture.idPriorite = priorite.id
  67. WHERE validite = 0";
  68. }
  69. else
  70. {
  71. $requeteFacture = "SELECT facture.id AS idFacture,
  72. facture.histo AS histo,
  73. refuse AS refuse,
  74. facture.refFacture AS refFacture,
  75. facture.dateFacture AS dateFacture,
  76. facture.dateFactureOrigine AS dateFactureOrigine,
  77. facture.observation AS observation,
  78. facture.montant AS montant,
  79. destinataire.nom AS nomFournisseur,
  80. destinataire.id AS idDest,
  81. destinataire.prenom AS prenomFournisseur,
  82. priorite.nbJours AS nbJours,
  83. unix_timestamp(datesaisie) AS internal_timestamp
  84. FROM facture
  85. LEFT JOIN destinataire ON facture.idFournisseur = destinataire.id
  86. LEFT JOIN priorite ON facture.idPriorite = priorite.id
  87. WHERE facture.validite = 0
  88. AND facture.idServiceCreation = {$_SESSION['idService']}";
  89. }
  90. $sdg = new SQLDataGrid($requeteFacture,
  91. array('No' => array('sqlcol' => 'idFacture',
  92. 'callback' => 'printId'),
  93. 'Fournisseur' => array('sqlcol' => 'nomFournisseur',
  94. 'callback' => 'printProvider'),
  95. 'Ref.' => array('sqlcol' => 'refFacture',
  96. 'callback' => 'printReference'),
  97. 'Mont.' => array('sqlcol' => 'montant',
  98. 'callback' => 'printAmount'),
  99. 'Date Mairie' => array('sqlcol' => 'dateFacture',
  100. 'callback' => 'printArrivalDate'),
  101. 'Date Facture' => array('sqlcol' => 'dateFactureOrigine',
  102. 'callback' => 'printEmissionDate'),
  103. 'Observation' => array('sqlcol' => 'observation',
  104. 'callback' => 'printComments'),
  105. 'Historique' => array('sqlcol' => 'histo',
  106. 'callback' => 'printHistory'),
  107. 'Transmettre' => array('callback' => 'printTransmit'),
  108. 'Archiver' => array('callback' => 'printArchive'),
  109. 'Jours restant' => array('style' => 'text-align: center',
  110. 'callback' => 'printRemainingDays'),
  111. ));
  112. $sdg->setPagerSize($_SESSION['pagersize']);
  113. $sdg->setDefaultSort(array('idFacture' => 'DESC'));
  114. $sdg->setClass('resultats');
  115. if (!empty($_GET['idFactureRecherche']))
  116. $sdg->setDefaultPageWhere(array('idFacture' => $_GET['idFactureRecherche']));
  117. if (!empty($_GET['id']))
  118. $sdg->setDefaultPageWhere(array('idFacture' => $_GET['id']));
  119. $sdg->display();
  120. function printId($params)
  121. {
  122. $row = $params['record'];
  123. if ($row['refuse'] == 1)
  124. return "<span style='background: red'>{$row['idFacture']}</span>";
  125. else
  126. return $row['idFacture'];
  127. }
  128. function printProvider($params)
  129. {
  130. $row = $params['record'];
  131. return "<a href='modifDestinataire.php?idCourrier={$row['idFacture']}'>"
  132. . "{$row['nomFournisseur']}"
  133. . " {$row['prenomFournisseur']}"
  134. . "</a>";
  135. }
  136. function printReference($params)
  137. {
  138. $row = $params['record'];
  139. $ref = $row['refFacture'];
  140. if ($ref == '')
  141. $ref = _('Modifier');
  142. return "<a href='modifRef.php?idCourrier={$row['idFacture']}'>$ref</a>";
  143. }
  144. function printAmount($params)
  145. {
  146. $row = $params['record'];
  147. $amount = $row['montant'];
  148. if ($amount == '')
  149. $amount = _('Modifier');
  150. return "<a href='modifMontant.php?idCourrier={$row['idFacture']}'>$amount</a>";
  151. }
  152. function printArrivalDate($params)
  153. {
  154. $row = $params['record'];
  155. $tmpdateArrivee = $row['dateFacture'];
  156. $dateArrivee = substr($tmpdateArrivee,8,2)
  157. . '/' . substr($tmpdateArrivee,5,2)
  158. . '/' . substr($tmpdateArrivee,0,4);
  159. return
  160. ((time() - $row['internal_timestamp']) < (24 * 60 * 60))
  161. ? "<a href='invoice_edit_date.php?id={$row['idFacture']}'>$dateArrivee</a>"
  162. : $dateArrivee;
  163. }
  164. function printEmissionDate($params)
  165. {
  166. $row = $params['record'];
  167. $emission_date = $row['dateFactureOrigine'];
  168. $emission_date = substr($emission_date, 8, 2)
  169. . '/' . substr($emission_date, 5, 2)
  170. . '/' . substr($emission_date, 0, 4);
  171. return "<a href='invoice_edit_date.php?id={$row['idFacture']}'>$emission_date</a>";
  172. }
  173. function printComments($params)
  174. {
  175. $row = $params['record'];
  176. $comments = $row['observation'];
  177. if ($comments == '')
  178. $comments = _('Modifier');
  179. return "<a href='modifObservationFacture.php?idCourrier={$row['idFacture']}'".
  180. " style='font-size: smaller'>$comments</a>";
  181. }
  182. function printHistory($params)
  183. {
  184. $row = $params['record'];
  185. $histo = $row['histo'];
  186. return "<a href='invoice_history.php?id={$row['idFacture']}'>$histo</a>";
  187. }
  188. function printTransmit($params)
  189. {
  190. $row = $params['record'];
  191. return "<a href='transmettreFacture.php?idCourrier={$row['idFacture']}'>Transmettre</a>";
  192. }
  193. function printArchive($params)
  194. {
  195. $row = $params['record'];
  196. return "<a href='validerFacture.php?idCourrier={$row['idFacture']}'>Archiver</a>";
  197. }
  198. function printRemainingDays($params)
  199. {
  200. // test pour urgence du courrier
  201. $dateActuel = date("Y-m-d");
  202. $jourActuel = substr($dateActuel,8,2);
  203. $moisActuel = substr($dateActuel,5,2);
  204. $anneeActuel= substr($dateActuel,0,4);
  205. $tmpDateArrivee = $params['record']['dateFacture'];
  206. $jourArrivee =substr($tmpDateArrivee,8,2);
  207. $moisArrivee =substr($tmpDateArrivee,5,2);
  208. $anneeArrivee =substr($tmpDateArrivee,0,4);
  209. // echo " feafaoho".$tmpdateArrivee;
  210. $nbJours = $params['record']['nbJours'];
  211. $timestampActuel = mktime(0,0,0,$moisActuel,$jourActuel,$anneeActuel);
  212. $timestampArrivee= mktime(0,0,0,$moisArrivee,$jourArrivee,$anneeArrivee);
  213. $urgence = ($timestampActuel - $timestampArrivee ) / 86400;
  214. // round value to take 'dailight saving time' into account (=> no float)
  215. $nbJoursRestant = (int) ($nbJours - $urgence);
  216. // echo " fze ".$urgence." : ".$nbJours." :: ".$ligne['nbJours']."<br>";
  217. if ($nbJoursRestant >= 5)
  218. $alerte = "green";
  219. else
  220. $alerte = "red";
  221. return "<span style='color:$alerte;font-weight:bold'>$nbJoursRestant</span>";
  222. }
  223. include('templates/footer.php');