list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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.houssin@capnetworks.com>
  5. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  6. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  7. * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/compta/paiement/list.php
  24. * \ingroup compta
  25. * \brief Page liste des paiements des factures clients
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. $langs->load("bills");
  33. $langs->load("compta");
  34. // Security check
  35. $facid =GETPOST('facid','int');
  36. $socid =GETPOST('socid','int');
  37. $userid=GETPOST('userid','int');
  38. $day = GETPOST('day','int');
  39. $month = GETPOST('month','int');
  40. $year = GETPOST('year','int');
  41. if ($user->societe_id) $socid=$user->societe_id;
  42. $result = restrictedArea($user, 'facture',$facid,'');
  43. $paymentstatic=new Paiement($db);
  44. $accountstatic=new Account($db);
  45. $companystatic=new Societe($db);
  46. $search_ref=GETPOST("search_ref","alpha");
  47. $search_account=GETPOST("search_account","int");
  48. $search_paymenttype=GETPOST("search_paymenttype");
  49. $search_amount=GETPOST("search_amount",'alpha'); // alpha because we must be able to search on "< x"
  50. $search_company=GETPOST("search_company",'alpha');
  51. $search_payment_num=GETPOST('search_payment_num','alpha');
  52. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  53. $sortfield = GETPOST("sortfield",'alpha');
  54. $sortorder = GETPOST("sortorder",'alpha');
  55. $page = GETPOST("page",'int');
  56. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  57. $offset = $limit * $page;
  58. $pageprev = $page - 1;
  59. $pagenext = $page + 1;
  60. if (! $sortorder) $sortorder="DESC";
  61. if (! $sortfield) $sortfield="p.rowid";
  62. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  63. $hookmanager->initHooks(array('paymentlist'));
  64. $extrafields = new ExtraFields($db);
  65. /*
  66. * Actions
  67. */
  68. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  69. {
  70. $search_ref="";
  71. $search_account="";
  72. $search_amount="";
  73. $search_paymenttype="";
  74. $search_payment_num="";
  75. $search_company="";
  76. $day='';
  77. $year='';
  78. $month='';
  79. }
  80. /*
  81. * View
  82. */
  83. llxHeader('', $langs->trans('ListPayment'));
  84. $form=new Form($db);
  85. $formother=new FormOther($db);
  86. if (GETPOST("orphelins"))
  87. {
  88. // Paiements lies a aucune facture (pour aide au diagnostic)
  89. $sql = "SELECT p.rowid, p.ref, p.datep as dp, p.amount,";
  90. $sql.= " p.statut, p.num_paiement,";
  91. $sql.= " c.code as paiement_code";
  92. // Add fields for extrafields
  93. foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key;
  94. // Add fields from hooks
  95. $parameters=array();
  96. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  97. $sql.=$hookmanager->resPrint;
  98. $sql.= " FROM (".MAIN_DB_PREFIX."paiement as p,";
  99. $sql.= " ".MAIN_DB_PREFIX."c_paiement as c)";
  100. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
  101. $sql.= " WHERE p.fk_paiement = c.id";
  102. $sql.= " AND p.entity = ".$conf->entity;
  103. $sql.= " AND pf.fk_facture IS NULL";
  104. // Add where from hooks
  105. $parameters=array();
  106. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  107. $sql.=$hookmanager->resPrint;
  108. }
  109. else
  110. {
  111. $sql = "SELECT DISTINCT p.rowid, p.ref, p.datep as dp, p.amount,"; // DISTINCT is to avoid duplicate when there is a link to sales representatives
  112. $sql.= " p.statut, p.num_paiement,";
  113. $sql.= " c.code as paiement_code,";
  114. $sql.= " ba.rowid as bid, ba.ref as bref, ba.label as blabel, ba.number, ba.account_number as account_number, ba.accountancy_journal as accountancy_journal,";
  115. $sql.= " s.rowid as socid, s.nom as name";
  116. // Add fields for extrafields
  117. foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key;
  118. // Add fields from hooks
  119. $parameters=array();
  120. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  121. $sql.=$hookmanager->resPrint;
  122. $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement as p)";
  123. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
  124. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  125. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
  126. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid";
  127. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
  128. if (!$user->rights->societe->client->voir && !$socid)
  129. {
  130. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  131. }
  132. $sql.= " WHERE p.fk_paiement = c.id";
  133. $sql.= " AND p.entity = ".$conf->entity;
  134. if (! $user->rights->societe->client->voir && ! $socid)
  135. {
  136. $sql.= " AND sc.fk_user = " .$user->id;
  137. }
  138. if ($socid > 0) $sql.= " AND f.fk_soc = ".$socid;
  139. if ($userid)
  140. {
  141. if ($userid == -1) $sql.= " AND f.fk_user_author IS NULL";
  142. else $sql.= " AND f.fk_user_author = ".$userid;
  143. }
  144. // Search criteria
  145. if ($month > 0)
  146. {
  147. if ($year > 0 && empty($day))
  148. $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  149. else if ($year > 0 && ! empty($day))
  150. $sql.= " AND p.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
  151. else
  152. $sql.= " AND date_format(p.datep, '%m') = '".$month."'";
  153. }
  154. else if ($year > 0)
  155. {
  156. $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  157. }
  158. if ($search_ref) $sql .= natural_search('p.ref', $search_ref);
  159. if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
  160. if ($search_paymenttype != "") $sql .=" AND c.code='".$db->escape($search_paymenttype)."'";
  161. if ($search_payment_num != '') $sql .= natural_search('p.num_paiement', $search_payment_num);
  162. if ($search_amount) $sql .= natural_search('p.amount', $search_amount, 1);
  163. if ($search_company) $sql .= natural_search('s.nom', $search_company);
  164. // Add where from hooks
  165. $parameters=array();
  166. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  167. $sql.=$hookmanager->resPrint;
  168. }
  169. $sql.= $db->order($sortfield,$sortorder);
  170. $nbtotalofrecords = '';
  171. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  172. {
  173. $result = $db->query($sql);
  174. $nbtotalofrecords = $db->num_rows($result);
  175. }
  176. $sql.= $db->plimit($limit+1, $offset);
  177. //print "$sql";
  178. $resql = $db->query($sql);
  179. if ($resql)
  180. {
  181. $num = $db->num_rows($resql);
  182. $i = 0;
  183. $param='';
  184. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  185. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  186. $param.=(GETPOST("orphelins")?"&orphelins=1":"");
  187. $param.=($search_ref?"&search_ref=".urlencode($search_ref):"");
  188. $param.=($search_company?"&search_company=".urlencode($search_company):"");
  189. $param.=($search_amount?"&search_amount=".urlencode($search_amount):"");
  190. $param.=($search_payment_num?"&search_payment_num=".urlencode($search_payment_num):"");
  191. if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
  192. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  193. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  194. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  195. print '<input type="hidden" name="action" value="list">';
  196. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  197. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  198. print '<input type="hidden" name="page" value="'.$page.'">';
  199. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  200. print_barre_liste($langs->trans("ReceivedCustomersPayments"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $nbtotalofrecords,'title_accountancy.png', 0, '', '', $limit);
  201. print '<div class="div-table-responsive">';
  202. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  203. // Lines for filters fields
  204. print '<tr class="liste_titre_filter">';
  205. print '<td class="liste_titre" align="left">';
  206. print '<input class="flat" type="text" size="4" name="search_ref" value="'.$search_ref.'">';
  207. print '</td>';
  208. print '<td class="liste_titre" align="center">';
  209. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  210. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  211. $formother->select_year($year?$year:-1,'year',1, 20, 5);
  212. print '</td>';
  213. print '<td class="liste_titre" align="left">';
  214. print '<input class="flat" type="text" size="6" name="search_company" value="'.$search_company.'">';
  215. print '</td>';
  216. print '<td class="liste_titre">';
  217. $form->select_types_paiements($search_paymenttype,'search_paymenttype','',2,1,1);
  218. print '</td>';
  219. print '<td class="liste_titre" align="left">';
  220. print '<input class="flat" type="text" size="4" name="search_payment_num" value="'.$search_payment_num.'">';
  221. print '</td>';
  222. if (! empty($conf->banque->enabled))
  223. {
  224. print '<td class="liste_titre">';
  225. $form->select_comptes($search_account,'search_account',0,'',1);
  226. print '</td>';
  227. }
  228. print '<td class="liste_titre" align="right">';
  229. print '<input class="flat" type="text" size="4" name="search_amount" value="'.$search_amount.'">';
  230. print '</td>';
  231. print '<td class="liste_titre" align="right">';
  232. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  233. print $searchpicto;
  234. print '</td>';
  235. if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
  236. {
  237. print '<td class="liste_titre" align="right">';
  238. print '</td>';
  239. }
  240. print "</tr>\n";
  241. print '<tr class="liste_titre">';
  242. print_liste_field_titre($langs->trans("RefPayment"),$_SERVER["PHP_SELF"],"p.rowid","",$param,"",$sortfield,$sortorder);
  243. print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"dp","",$param,'align="center"',$sortfield,$sortorder);
  244. print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
  245. print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"c.libelle","",$param,"",$sortfield,$sortorder);
  246. print_liste_field_titre($langs->trans("Numero"),$_SERVER["PHP_SELF"],"p.num_paiement","",$param,"",$sortfield,$sortorder);
  247. if (! empty($conf->banque->enabled))
  248. {
  249. print_liste_field_titre($langs->trans("Account"),$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
  250. }
  251. print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"p.amount","",$param,'align="right"',$sortfield,$sortorder);
  252. //print_liste_field_titre($langs->trans("Invoices"),"","","",$param,'align="left"',$sortfield,$sortorder);
  253. $parameters=array();
  254. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  255. print $hookmanager->resPrint;
  256. if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.statut","",$param,'align="right"',$sortfield,$sortorder);
  257. print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
  258. print "</tr>\n";
  259. while ($i < min($num,$limit))
  260. {
  261. $objp = $db->fetch_object($resql);
  262. print '<tr class="oddeven">';
  263. print '<td>';
  264. $paymentstatic->id=$objp->rowid;
  265. $paymentstatic->ref=$objp->ref;
  266. print $paymentstatic->getNomUrl(1);
  267. print '</td>';
  268. // Date
  269. print '<td align="center">'.dol_print_date($db->jdate($objp->dp),'day').'</td>';
  270. // Thirdparty
  271. print '<td>';
  272. if ($objp->socid)
  273. {
  274. $companystatic->id=$objp->socid;
  275. $companystatic->name=$objp->name;
  276. print $companystatic->getNomUrl(1,'',24);
  277. }
  278. else print '&nbsp;';
  279. print '</td>';
  280. // Type
  281. print '<td>'.$langs->trans("PaymentTypeShort".$objp->paiement_code).'</td>';
  282. // Payment number
  283. print '<td>'.$objp->num_paiement.'</td>';
  284. // Account
  285. if (! empty($conf->banque->enabled))
  286. {
  287. print '<td>';
  288. if ($objp->bid > 0)
  289. {
  290. $accountstatic->id=$objp->bid;
  291. $accountstatic->ref=$objp->bref;
  292. $accountstatic->label=$objp->blabel;
  293. $accountstatic->number=$objp->number;
  294. $accountstatic->account_number=$objp->account_number;
  295. $accountstatic->accountancy_journal=$objp->accountancy_journal;
  296. print $accountstatic->getNomUrl(1);
  297. }
  298. else print '&nbsp;';
  299. print '</td>';
  300. }
  301. // Amount
  302. print '<td align="right">'.price($objp->amount).'</td>';
  303. if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
  304. {
  305. print '<td align="right">';
  306. if ($objp->statut == 0) print '<a href="card.php?id='.$objp->rowid.'&amp;action=valide">';
  307. print $paymentstatic->LibStatut($objp->statut,5);
  308. if ($objp->statut == 0) print '</a>';
  309. print '</td>';
  310. }
  311. print '<td>&nbsp;</td>';
  312. print '</tr>';
  313. $i++;
  314. }
  315. print "</table>\n";
  316. print "</div>";
  317. print "</form>\n";
  318. }
  319. else
  320. {
  321. dol_print_error($db);
  322. }
  323. llxFooter();
  324. $db->close();