PageRenderTime 48ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/paiement/liste.php

http://github.com/Dolibarr/dolibarr
PHP | 240 lines | 176 code | 29 blank | 35 comment | 33 complexity | b22ad7028fa2bb0f694fc238ae7d6ae0 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/compta/paiement/liste.php
  21. * \ingroup compta
  22. * \brief Page liste des paiements des factures clients
  23. */
  24. require("../../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php');
  26. require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
  27. $langs->load("bills");
  28. // Security check
  29. $facid =GETPOST('facid','int');
  30. $socid =GETPOST('socid','int');
  31. $userid=GETPOST('userid','int');
  32. if ($user->societe_id) $socid=$user->societe_id;
  33. $result = restrictedArea($user, 'facture',$facid,'');
  34. $paymentstatic=new Paiement($db);
  35. $accountstatic=new Account($db);
  36. $companystatic=new Societe($db);
  37. $sortfield = GETPOST("sortfield",'alpha');
  38. $sortorder = GETPOST("sortorder",'alpha');
  39. $page = GETPOST("page",'int');
  40. if ($page == -1) { $page = 0; }
  41. $offset = $conf->liste_limit * $page;
  42. $pageprev = $page - 1;
  43. $pagenext = $page + 1;
  44. $limit = $conf->liste_limit;
  45. if (! $sortorder) $sortorder="DESC";
  46. if (! $sortfield) $sortfield="p.rowid";
  47. /*
  48. * View
  49. */
  50. llxHeader('',$langs->trans("ListPayment"));
  51. $form=new Form($db);
  52. if (GETPOST("orphelins"))
  53. {
  54. // Paiements lies a aucune facture (pour aide au diagnostic)
  55. $sql = "SELECT p.rowid, p.datep as dp, p.amount,";
  56. $sql.= " p.statut, p.num_paiement,";
  57. //$sql.= " c.libelle as paiement_type";
  58. $sql.= " c.code as paiement_code";
  59. $sql.= " FROM (".MAIN_DB_PREFIX."paiement as p,";
  60. $sql.= " ".MAIN_DB_PREFIX."c_paiement as c)";
  61. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
  62. $sql.= " WHERE p.fk_paiement = c.id";
  63. $sql.= " AND p.entity = ".$conf->entity;
  64. $sql.= " AND pf.fk_facture IS NULL";
  65. }
  66. else
  67. {
  68. $sql = "SELECT DISTINCT p.rowid, p.datep as dp, p.amount,"; // DISTINCT is to avoid duplicate when there is a link to sales representatives
  69. $sql.= " p.statut, p.num_paiement,";
  70. //$sql.= " c.libelle as paiement_type,";
  71. $sql.= " c.code as paiement_code,";
  72. $sql.= " ba.rowid as bid, ba.label,";
  73. $sql.= " s.rowid as socid, s.nom";
  74. //$sql.= " f.facnumber";
  75. $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement as p)";
  76. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
  77. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  78. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
  79. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid";
  80. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
  81. if (!$user->rights->societe->client->voir && !$socid)
  82. {
  83. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  84. }
  85. $sql.= " WHERE p.fk_paiement = c.id";
  86. $sql.= " AND p.entity = ".$conf->entity;
  87. if (! $user->rights->societe->client->voir && ! $socid)
  88. {
  89. $sql.= " AND sc.fk_user = " .$user->id;
  90. }
  91. if ($socid > 0) $sql.= " AND f.fk_soc = ".$socid;
  92. if ($userid)
  93. {
  94. if ($userid == -1) $sql.= " AND f.fk_user_author IS NULL";
  95. else $sql.= " AND f.fk_user_author = ".$userid;
  96. }
  97. // Search criteria
  98. if ($_REQUEST["search_ref"]) $sql .=" AND p.rowid=".$_REQUEST["search_ref"];
  99. if ($_REQUEST["search_account"]) $sql .=" AND b.fk_account=".$_REQUEST["search_account"];
  100. if ($_REQUEST["search_paymenttype"]) $sql .=" AND c.code='".$_REQUEST["search_paymenttype"]."'";
  101. if ($_REQUEST["search_amount"]) $sql .=" AND p.amount=".price2num($_REQUEST["search_amount"]);
  102. if ($_REQUEST["search_company"]) $sql .=" AND s.nom LIKE '%".$db->escape($_REQUEST["search_company"])."%'";
  103. }
  104. $sql.= $db->order($sortfield,$sortorder);
  105. $sql.= $db->plimit($limit+1, $offset);
  106. //print "$sql";
  107. $resql = $db->query($sql);
  108. if ($resql)
  109. {
  110. $num = $db->num_rows($resql);
  111. $i = 0;
  112. $paramlist='';
  113. $paramlist.=(GETPOST("orphelins")?"&orphelins=1":"");
  114. $paramlist.=($_REQUEST["search_ref"]?"&search_ref=".$_REQUEST["search_ref"]:"");
  115. $paramlist.=($_REQUEST["search_company"]?"&search_company=".$_REQUEST["search_company"]:"");
  116. $paramlist.=($_REQUEST["search_amount"]?"&search_amount=".$_REQUEST["search_amount"]:"");
  117. print_barre_liste($langs->trans("ReceivedCustomersPayments"), $page, $_SERVER["PHP_SELF"],$paramlist,$sortfield,$sortorder,'',$num);
  118. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
  119. print '<table class="noborder" width="100%">';
  120. print '<tr class="liste_titre">';
  121. print_liste_field_titre($langs->trans("RefPayment"),$_SERVER["PHP_SELF"],"p.rowid","",$paramlist,"",$sortfield,$sortorder);
  122. print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"dp","",$paramlist,'align="center"',$sortfield,$sortorder);
  123. print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"s.nom","",$paramlist,"",$sortfield,$sortorder);
  124. print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"c.libelle","",$paramlist,"",$sortfield,$sortorder);
  125. print_liste_field_titre($langs->trans("Account"),$_SERVER["PHP_SELF"],"ba.label","",$paramlist,"",$sortfield,$sortorder);
  126. print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"p.amount","",$paramlist,'align="right"',$sortfield,$sortorder);
  127. //print_liste_field_titre($langs->trans("Invoices"),"","","",$paramlist,'align="left"',$sortfield,$sortorder);
  128. if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
  129. {
  130. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.statut","",$paramlist,'align="right"',$sortfield,$sortorder);
  131. }
  132. print "</tr>\n";
  133. // Lines for filters fields
  134. print '<tr class="liste_titre">';
  135. print '<td align="left">';
  136. print '<input class="fat" type="text" size="4" name="search_ref" value="'.$_REQUEST["search_ref"].'">';
  137. print '</td>';
  138. print '<td>&nbsp;</td>';
  139. print '<td align="left">';
  140. print '<input class="fat" type="text" size="6" name="search_company" value="'.$_REQUEST["search_company"].'">';
  141. print '</td>';
  142. print '<td>';
  143. $form->select_types_paiements($_REQUEST["search_paymenttype"],'search_paymenttype','',2,1,1);
  144. print '</td>';
  145. print '<td>';
  146. $form->select_comptes($_REQUEST["search_account"],'search_account',0,'',1);
  147. print '</td>';
  148. print '<td align="right">';
  149. print '<input class="fat" type="text" size="4" name="search_amount" value="'.$_REQUEST["search_amount"].'">';
  150. print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  151. print '</td>';
  152. if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
  153. {
  154. print '<td align="right">';
  155. print '</td>';
  156. }
  157. print "</tr>\n";
  158. $var=true;
  159. while ($i < min($num,$limit))
  160. {
  161. $objp = $db->fetch_object($resql);
  162. $var=!$var;
  163. print "<tr $bc[$var]>";
  164. print '<td width="40">';
  165. $paymentstatic->id=$objp->rowid;
  166. $paymentstatic->ref=$objp->rowid;
  167. print $paymentstatic->getNomUrl(1);
  168. print '</td>';
  169. print '<td align="center">'.dol_print_date($db->jdate($objp->dp),'day').'</td>';
  170. // Company
  171. print '<td>';
  172. if ($objp->socid)
  173. {
  174. $companystatic->id=$objp->socid;
  175. $companystatic->nom=$objp->nom;
  176. print $companystatic->getNomUrl(1,'',24);
  177. }
  178. else print '&nbsp;';
  179. print '</td>';
  180. print '<td>'.$langs->trans("PaymentTypeShort".$objp->paiement_code).' '.$objp->num_paiement.'</td>';
  181. print '<td>';
  182. if ($objp->bid)
  183. {
  184. $accountstatic->id=$objp->bid;
  185. $accountstatic->label=$objp->label;
  186. print $accountstatic->getNomUrl(1);
  187. }
  188. else print '&nbsp;';
  189. print '</td>';
  190. print '<td align="right">'.price($objp->amount).'</td>';
  191. if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
  192. {
  193. print '<td align="right">';
  194. if ($objp->statut == 0) print '<a href="fiche.php?id='.$objp->rowid.'&amp;action=valide">';
  195. print $paymentstatic->LibStatut($objp->statut,5);
  196. if ($objp->statut == 0) print '</a>';
  197. print '</td>';
  198. }
  199. print '</tr>';
  200. $i++;
  201. }
  202. print "</table>\n";
  203. print "</form>\n";
  204. }
  205. else
  206. {
  207. dol_print_error($db);
  208. }
  209. $db->close();
  210. llxFooter();
  211. ?>