PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/2.071.0/profil_collab/catalogue_articles_service_abo_recherche_result.php

https://github.com/crepeausucre/soothERP
PHP | 297 lines | 287 code | 7 blank | 3 comment | 2 complexity | 021f2adde9607800d05214ba24b0bf40 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0
  1. <?php
  2. // *************************************************************************************************************
  3. // RECHERCHE DES ABONNEMENTS D'UN ARTICLE
  4. // *************************************************************************************************************
  5. require ("_dir.inc.php");
  6. require ("_profil.inc.php");
  7. require ($DIR."_session.inc.php");
  8. if (!isset($_REQUEST['ref_article'])) {
  9. echo "La référence de l'article n'est pas précisée";
  10. exit;
  11. }
  12. $article = new article ($_REQUEST['ref_article']);
  13. if (!$article->getRef_article()) {
  14. echo "La référence de l'article est inconnue";
  15. exit;
  16. }
  17. // *************************************************************************************************************
  18. // TRAITEMENTS
  19. // *************************************************************************************************************
  20. $ANNUAIRE_CATEGORIES = get_categories();
  21. // *************************************************
  22. // Profils ŕ afficher
  23. $profils = array();
  24. foreach ($_SESSION['profils'] as $profil) {
  25. if ($profil->getActif() == 0) { continue; }
  26. $profils[] = $profil;
  27. }
  28. unset ($profil);
  29. // *************************************************
  30. // Données pour le formulaire et la recherche
  31. $form['page_to_show'] = $search['page_to_show'] = 1;
  32. if (isset($_REQUEST['page_to_show'])) {
  33. $form['page_to_show'] = $_REQUEST['page_to_show'];
  34. $search['page_to_show'] = $_REQUEST['page_to_show'];
  35. }
  36. $form['fiches_par_page'] = $search['fiches_par_page'] = $ANNUAIRE_RECHERCHE_SHOWED_FICHES;
  37. if (isset($_REQUEST['fiches_par_page'])) {
  38. $form['fiches_par_page'] = $_REQUEST['fiches_par_page'];
  39. $search['fiches_par_page'] = $_REQUEST['fiches_par_page'];
  40. }
  41. $nb_fiches = 0;
  42. $form['orderby'] = $search['orderby'] = "nom";
  43. if (isset($_REQUEST['orderby'])) {
  44. $form['orderby'] = $_REQUEST['orderby'];
  45. $search['orderby'] = $_REQUEST['orderby'];
  46. }
  47. $form['orderorder'] = $search['orderorder'] = "DESC";
  48. if (isset($_REQUEST['orderorder'])) {
  49. $form['orderorder'] = $_REQUEST['orderorder'];
  50. $search['orderorder'] = $_REQUEST['orderorder'];
  51. }
  52. $form['ref_client'] = "";
  53. if (isset($_REQUEST['ref_client'])){
  54. if ($_REQUEST['ref_client']!="") {
  55. $form['ref_client'] = trim(urldecode($_REQUEST['ref_client']));
  56. $search['ref_client'] = trim(urldecode($_REQUEST['ref_client']));
  57. }else{
  58. $form['ref_client'] = "";
  59. $search['ref_client'] = "";
  60. }
  61. }
  62. $form['etat_abo'] = "";
  63. if (isset($_REQUEST['etat_abo'])) {
  64. $form['etat_abo'] = trim(urldecode($_REQUEST['etat_abo']));
  65. $search['etat_abo'] = trim(urldecode($_REQUEST['etat_abo']));
  66. }
  67. $form['id_client_categ'] = "";
  68. if (isset($_REQUEST['id_client_categ']) && $_REQUEST['id_client_categ']!=0) {
  69. $form['id_client_categ'] = trim(urldecode($_REQUEST['id_client_categ']));
  70. $search['id_client_categ'] = trim(urldecode($_REQUEST['id_client_categ']));
  71. }else{
  72. $form['id_client_categ'] = "";
  73. $search['id_client_categ'] = "";
  74. }
  75. $form['date_souscription_min'] = "";
  76. if (isset($_REQUEST['date_souscription_min'])) {
  77. $form['date_souscription_min'] = trim(urldecode($_REQUEST['date_souscription_min']));
  78. $search['date_souscription_min'] = trim(urldecode($_REQUEST['date_souscription_min']));
  79. }
  80. $form['date_souscription_max'] = "";
  81. if (isset($_REQUEST['date_souscription_max'])) {
  82. $form['date_souscription_max'] = trim(urldecode($_REQUEST['date_souscription_max']));
  83. $search['date_souscription_max'] = trim(urldecode($_REQUEST['date_souscription_max']));
  84. }
  85. $form['date_echeance_min'] = "";
  86. if (isset($_REQUEST['date_echeance_min'])) {
  87. $form['date_echeance_min'] = trim(urldecode($_REQUEST['date_echeance_min']));
  88. $search['date_echeance_min'] = trim(urldecode($_REQUEST['date_echeance_min']));
  89. }
  90. $form['date_echeance_max'] = "";
  91. if (isset($_REQUEST['date_echeance_max'])) {
  92. $form['date_echeance_max'] = trim(urldecode($_REQUEST['date_echeance_max']));
  93. $search['date_echeance_max'] = trim(urldecode($_REQUEST['date_echeance_max']));
  94. }
  95. $form['date_fin_min'] = "";
  96. if (isset($_REQUEST['date_fin_min'])) {
  97. $form['date_fin_min'] = trim(urldecode($_REQUEST['date_fin_min']));
  98. $search['date_fin_min'] = trim(urldecode($_REQUEST['date_fin_min']));
  99. }
  100. $form['date_fin_max'] = "";
  101. if (isset($_REQUEST['date_fin_max'])) {
  102. $form['date_fin_max'] = trim(urldecode($_REQUEST['date_fin_max']));
  103. $search['date_fin_max'] = trim(urldecode($_REQUEST['date_fin_max']));
  104. }
  105. $form['adresse_code'] = "";
  106. if (isset($_REQUEST['adresse_code'])) {
  107. $form['adresse_code'] = trim(urldecode($_REQUEST['adresse_code']));
  108. $search['adresse_code'] = trim(urldecode($_REQUEST['adresse_code']));
  109. }
  110. $form['adresse_ville'] = "";
  111. if (isset($_REQUEST['adresse_ville'])) {
  112. $form['adresse_ville'] = trim(urldecode($_REQUEST['adresse_ville']));
  113. $search['adresse_ville'] = trim(urldecode($_REQUEST['adresse_ville']));
  114. }
  115. $form['adresse_pays'] = "";
  116. if (isset($_REQUEST['adresse_pays'])) {
  117. $form['adresse_pays'] = trim(urldecode($_REQUEST['adresse_pays']));
  118. $search['adresse_pays'] = trim(urldecode($_REQUEST['adresse_pays']));
  119. }
  120. $form['ref_article'] = 0;
  121. if (isset($_REQUEST['ref_article'])) {
  122. $form['ref_article'] = ($_REQUEST['ref_article']);
  123. $search['ref_article'] = ($_REQUEST['ref_article']);
  124. }
  125. // *************************************************
  126. // Résultat de la recherche
  127. $fiches = array();
  128. if (isset($_REQUEST['recherche']) ) {
  129. // Préparation de la requete
  130. $query_select = "";
  131. $query_join = "";
  132. $query_join_count = "";
  133. $query_where = "";
  134. $query_limit = (($search['page_to_show']-1)*$search['fiches_par_page']).", ".$search['fiches_par_page'];
  135. //ref_article
  136. if (isset($search['ref_article'])) {
  137. if ($query_where) { $query_where .= " && "; }
  138. $query_where .= " aa.ref_article = '".($search['ref_article'])."'";
  139. }
  140. //catégorie de clients
  141. if ($search['id_client_categ']) {
  142. if ($query_where) { $query_where .= " && "; }
  143. $query_join .= " LEFT JOIN annu_client ac ON a.ref_contact = ac.ref_contact ";
  144. $query_join_count .= " LEFT JOIN annu_client ac ON a.ref_contact = ac.ref_contact ";
  145. $query_where .= "ac.id_client_categ = '".$search['id_client_categ']."'";
  146. }
  147. //adresse 1
  148. if ($search['adresse_code']) {
  149. if ($query_where) { $query_where .= " && "; }
  150. $query_where .= "ad.code_postal LIKE '".$search['adresse_code']."%'";
  151. }
  152. //adresse 2
  153. if ($search['adresse_ville']) {
  154. if ($query_where) { $query_where .= " && "; }
  155. $query_where .= "ad.ville = '".$search['adresse_ville']."'";
  156. }
  157. //adresse 3
  158. if ($search['adresse_ville'] || $search['adresse_code']) {
  159. $query_join_count .= " LEFT JOIN adresses ad ON a.ref_contact = ad.ref_contact ";
  160. }
  161. //adresse 4
  162. if ($search['adresse_pays']) {
  163. if ((!$search['adresse_ville']) || (!$search['adresse_code'])) {
  164. $query_join_count .= " LEFT JOIN adresses ad ON a.ref_contact = ad.ref_contact ";
  165. }
  166. $query_join .= " LEFT JOIN pays p ON ad.id_pays = p.id_pays ";
  167. $query_join_count .= " LEFT JOIN pays p ON ad.id_pays = p.id_pays ";
  168. if ($query_where) { $query_where .= " && "; }
  169. $query_where .= "p.pays = '".$search['adresse_pays']."'";
  170. }
  171. // etat abonnement :
  172. // 0 : TOUS
  173. // 1 : Abonnements en cours
  174. // 2 : Abonnements échus, ŕ renouveller
  175. // 3 : Abonnements terminés
  176. if ($search['etat_abo']) {
  177. if ($query_where) { $query_where .= " && "; }
  178. // 1 : Abonnements en cours
  179. if ($search['etat_abo'] == 1) { $query_where .= " aa.date_echeance > NOW() ";}
  180. // 2 : Abonnements échus, ŕ renouveller
  181. if ($search['etat_abo'] == 2) { $query_where .= " (aa.fin_abonnement > NOW() || aa.fin_abonnement = '0000-00-00 00:00:00') && aa.date_echeance < NOW() ";}
  182. // 3 : Abonnements terminés
  183. if ($search['etat_abo'] == 3) { $query_where .= " aa.fin_abonnement < NOW() && aa.fin_abonnement != '0000-00-00 00:00:00'";}
  184. }
  185. //date de souscription
  186. if($search['date_souscription_min']){
  187. $query_where .= " && aa.date_souscription > '".date_Fr_to_Us($search['date_souscription_min'])." 00:00:00'";
  188. }
  189. if($search['date_souscription_max']){
  190. $query_where .= " && aa.date_souscription < '".date_Fr_to_Us($search['date_souscription_max'])." 00:00:00'";
  191. }
  192. //date de echeance
  193. if($search['date_echeance_min']){
  194. $query_where .= " && aa.date_echeance > '".date_Fr_to_Us($search['date_echeance_min'])." 00:00:00'";
  195. }
  196. if($search['date_echeance_max']){
  197. $query_where .= " && aa.date_echeance < '".date_Fr_to_Us($search['date_echeance_max'])." 00:00:00'";
  198. }
  199. //date de fin
  200. if($search['date_fin_min']){
  201. $query_where .= " && aa.fin_abonnement > '".date_Fr_to_Us($search['date_fin_min'])." 00:00:00'";
  202. }
  203. if($search['date_fin_max']){
  204. $query_where .= " && aa.fin_abonnement < '".date_Fr_to_Us($search['date_fin_max'])." 00:00:00'";
  205. }
  206. //ref_client
  207. if ($search['ref_client']) {
  208. if ($query_where) { $query_where .= " && "; }
  209. $query_where .= "a.ref_contact = '".addslashes($search['ref_client'])."'";
  210. }
  211. if (!$query_where) {
  212. $query_where = 1;
  213. }
  214. // Recherche
  215. $query = "SELECT a.ref_contact, aa.ref_article, aa.id_abo, aa.date_souscription, aa.date_echeance , aa.date_preavis, aa.fin_engagement, aa.fin_abonnement,
  216. nom, lib_civ_court, id_categorie, amsa.reconduction,ad.text_adresse, ad.code_postal, ad.ville, ad.ordre, tel1, tel2, fax, co.ordre,
  217. email, url, si.ordre
  218. ".$query_select."
  219. FROM articles_abonnes aa
  220. LEFT JOIN articles_modele_service_abo amsa ON amsa.ref_article = aa.ref_article
  221. LEFT JOIN annuaire a ON a.ref_contact = aa.ref_contact
  222. LEFT JOIN civilites c ON a.id_civilite = c.id_civilite
  223. LEFT JOIN coordonnees co ON a.ref_contact = co.ref_contact && co.ordre = 1
  224. LEFT JOIN adresses ad ON a.ref_contact = ad.ref_contact
  225. LEFT JOIN sites_web si ON a.ref_contact = si.ref_contact && si.ordre = 1
  226. ".$query_join."
  227. WHERE ".$query_where."
  228. GROUP BY aa.id_abo
  229. ORDER BY ".$search['orderby']." ".$search['orderorder'].", aa.date_echeance DESC
  230. LIMIT ".$query_limit;
  231. //echo $query;
  232. $resultat = $bdd->query($query);
  233. while ($fiche = $resultat->fetchObject()) { $fiches[] = $fiche; }
  234. //echo nl2br ($query);
  235. unset ($fiche, $resultat, $query);
  236. // Comptage des résultats
  237. $query = "SELECT aa.id_abo
  238. FROM articles_abonnes aa
  239. LEFT JOIN annuaire a ON a.ref_contact = aa.ref_contact
  240. ".$query_join_count."
  241. WHERE ".$query_where."
  242. ";
  243. $resultat = $bdd->query($query);
  244. $result = $resultat->fetchAll();
  245. $nb_fiches = count($result);
  246. //echo "<br><hr>".nl2br ($query);
  247. unset ($result, $resultat, $query);
  248. }
  249. // *************************************************************************************************************
  250. // AFFICHAGE
  251. // *************************************************************************************************************
  252. include ($DIR.$_SESSION['theme']->getDir_theme()."page_catalogue_articles_service_abo_recherche_result.inc.php");
  253. ?>