demandes.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/prelevement/demandes.php
  22. * \ingroup prelevement
  23. * \brief Page to list withdraw requests
  24. */
  25. require('../../main.inc.php');
  26. require_once DOL_DOCUMENT_ROOT.'/core/modules/modPrelevement.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  30. $langs->load("banks");
  31. $langs->load("categories");
  32. $langs->load("withdrawals");
  33. $langs->load("companies");
  34. // Security check
  35. $socid = GETPOST('socid','int');
  36. if ($user->societe_id) $socid=$user->societe_id;
  37. $result = restrictedArea($user, 'prelevement','','','bons');
  38. // Get supervariables
  39. $page = GETPOST('page','int');
  40. $sortorder = GETPOST('sortorder','alpha');
  41. $sortfield = GETPOST('sortfield','alpha');
  42. $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
  43. $sortfield = GETPOST("sortfield",'alpha');
  44. $sortorder = GETPOST("sortorder",'alpha');
  45. $page = GETPOST("page",'int');
  46. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  47. $offset = $limit * $page;
  48. $pageprev = $page - 1;
  49. $pagenext = $page + 1;
  50. if (! $sortorder) $sortorder="DESC";
  51. if (! $sortfield) $sortfield="f.facnumber";
  52. /*
  53. * View
  54. */
  55. llxHeader();
  56. $thirdpartystatic=new Societe($db);
  57. $invoicestatic=new Facture($db);
  58. // List of requests
  59. $sql= "SELECT f.facnumber, f.rowid, f.total_ttc,";
  60. $sql.= " s.nom as name, s.rowid as socid,";
  61. $sql.= " pfd.date_demande as date_demande,";
  62. $sql.= " pfd.fk_user_demande";
  63. $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
  64. $sql.= " ".MAIN_DB_PREFIX."societe as s,";
  65. $sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
  66. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  67. $sql.= " WHERE s.rowid = f.fk_soc";
  68. $sql.= " AND f.entity = ".$conf->entity;
  69. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  70. if ($socid) $sql.= " AND f.fk_soc = ".$socid;
  71. if (!$statut) $sql.= " AND pfd.traite = 0";
  72. if ($statut) $sql.= " AND pfd.traite = ".$statut;
  73. $sql.= " AND pfd.fk_facture = f.rowid";
  74. if (dol_strlen(trim(GETPOST('search_societe','alpha'))))
  75. {
  76. $sql.= natural_search("s.nom", 'search_societe');
  77. }
  78. $sql.= " ORDER BY $sortfield $sortorder ";
  79. $sql.= $db->plimit($limit+1, $offset);
  80. $resql=$db->query($sql);
  81. if ($resql)
  82. {
  83. $num = $db->num_rows($resql);
  84. $i = 0;
  85. if (!$statut)
  86. {
  87. print_barre_liste($langs->trans("RequestStandingOrderToTreat"), $page, "demandes.php", $urladd, $sortfield, $sortorder, '', $num);
  88. }
  89. else
  90. {
  91. print_barre_liste($langs->trans("RequestStandingOrderTreated"), $page, "demandes.php", $urladd, $sortfield, $sortorder, '', $num);
  92. }
  93. print '<form action="'.$_SERVER["PHP_SELF"].'" method="GET">';
  94. print '<table class="liste" width="100%">';
  95. print '<tr class="liste_titre">';
  96. print_liste_field_titre($langs->trans("Bill"), $_SERVER["PHP_SELF"]);
  97. print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"]);
  98. print_liste_field_titre($langs->trans("Amount"), $_SERVER["PHP_SELF"], "", "", $param, 'align="right"');
  99. print_liste_field_titre($langs->trans("DateRequest"), $_SERVER["PHP_SELF"], "", "", $param, 'align="center"');
  100. print_liste_field_titre('');
  101. print '</tr>';
  102. print '<tr class="liste_titre">';
  103. print '<td class="liste_titre"><input type="text" class="flat" name="search_facture" size="12" value="'.dol_escape_htmltag(GETPOST('search_facture','alpha')).'"></td>';
  104. print '<td class="liste_titre"><input type="text" class="flat" name="search_societe" size="18" value="'.dol_escape_htmltag(GETPOST('search_societe','alpha')).'"></td>';
  105. print '<td class="liste_titre"></td>';
  106. print '<td class="liste_titre"></td>';
  107. // Action column
  108. print '<td class="liste_titre" align="middle">';
  109. $searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1);
  110. print $searchpicto;
  111. print '</td>';
  112. print '</tr>';
  113. $var = True;
  114. $users = array();
  115. while ($i < min($num,$limit))
  116. {
  117. $obj = $db->fetch_object($resql);
  118. print '<tr class="oddeven">';
  119. // Ref facture
  120. print '<td>';
  121. $invoicestatic->id=$obj->rowid;
  122. $invoicestatic->ref=$obj->facnumber;
  123. print $invoicestatic->getNomUrl(1,'withdraw');
  124. print '</td>';
  125. print '<td>';
  126. $thirdpartystatic->id=$obj->socid;
  127. $thirdpartystatic->name=$obj->name;
  128. print $thirdpartystatic->getNomUrl(1,'customer');
  129. print '</td>';
  130. print '<td align="right">'.price($obj->total_ttc).'</td>';
  131. print '<td align="center">'.dol_print_date($db->jdate($obj->date_demande),'day').'</td>';
  132. print '<td align="right"></td>';
  133. print '</tr>';
  134. $i++;
  135. }
  136. print "</table><br>";
  137. print '</form>';
  138. }
  139. else
  140. {
  141. dol_print_error($db);
  142. }
  143. llxFooter();
  144. $db->close();