create.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2010-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
  7. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  8. * Copyright (C) 2019 Markus Welters <markus@welters.de>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/compta/prelevement/create.php
  25. * \ingroup prelevement
  26. * \brief Page to create a direct debit order or a credit transfer order
  27. */
  28. // Load Dolibarr environment
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  38. // Load translation files required by the page
  39. $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies', 'bills'));
  40. $type = GETPOST('type', 'aZ09');
  41. // Get supervariables
  42. $action = GETPOST('action', 'aZ09');
  43. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  44. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  45. $mode = GETPOST('mode', 'alpha') ?GETPOST('mode', 'alpha') : 'real';
  46. $format = GETPOST('format', 'aZ09');
  47. $id_bankaccount = GETPOST('id_bankaccount', 'int');
  48. $executiondate = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  49. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  50. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  51. if (empty($page) || $page == -1) {
  52. $page = 0;
  53. } // If $page is not defined, or '' or -1
  54. $offset = $limit * $page;
  55. $hookmanager->initHooks(array('directdebitcreatecard', 'globalcard'));
  56. // Security check
  57. $socid = GETPOST('socid', 'int');
  58. if ($user->socid) {
  59. $socid = $user->socid;
  60. }
  61. if ($type == 'bank-transfer') {
  62. $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
  63. } else {
  64. $result = restrictedArea($user, 'prelevement', '', '', 'bons');
  65. }
  66. $error = 0;
  67. $option = "";
  68. /*
  69. * Actions
  70. */
  71. if (GETPOST('cancel', 'alpha')) {
  72. $massaction = '';
  73. }
  74. $parameters = array('mode' => $mode, 'format' => $format, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
  75. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  76. if ($reshook < 0) {
  77. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  78. }
  79. if (empty($reshook)) {
  80. // Change customer bank information to withdraw
  81. if ($action == 'modify') {
  82. for ($i = 1; $i < 9; $i++) {
  83. dolibarr_set_const($db, GETPOST("nom$i"), GETPOST("value$i"), 'chaine', 0, '', $conf->entity);
  84. }
  85. }
  86. if ($action == 'create') {
  87. $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT');
  88. //var_dump($default_account);var_dump($conf->global->$default_account);var_dump($id_bankaccount);exit;
  89. if ($id_bankaccount != $conf->global->$default_account) {
  90. $res = dolibarr_set_const($db, $default_account, $id_bankaccount, 'chaine', 0, '', $conf->entity); // Set as default
  91. }
  92. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  93. $bank = new Account($db);
  94. $bank->fetch($conf->global->{$default_account});
  95. // ICS is not mandatory with payment by bank transfer
  96. /*if ((empty($bank->ics) && $type !== 'bank-transfer')
  97. || (empty($bank->ics_transfer) && $type === 'bank-transfer')
  98. ) {*/
  99. if (empty($bank->ics) && $type !== 'bank-transfer') {
  100. $errormessage = str_replace('{url}', $bank->getNomUrl(1, '', '', -1, 1), $langs->trans("ErrorICSmissing", '{url}'));
  101. setEventMessages($errormessage, null, 'errors');
  102. $action = '';
  103. $error++;
  104. }
  105. $bprev = new BonPrelevement($db);
  106. if (!$error) {
  107. // $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty (we don't use them anymore)
  108. $result = $bprev->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $mode, $format, $executiondate, 0, $type);
  109. if ($result < 0) {
  110. setEventMessages($bprev->error, $bprev->errors, 'errors');
  111. } elseif ($result == 0) {
  112. $mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format);
  113. setEventMessages($mesg, null, 'errors');
  114. $mesg .= '<br>'."\n";
  115. foreach ($bprev->invoice_in_error as $key => $val) {
  116. $mesg .= '<span class="warning">'.$val."</span><br>\n";
  117. }
  118. } else {
  119. if ($type != 'bank-transfer') {
  120. $texttoshow = $langs->trans("DirectDebitOrderCreated", '{s}');
  121. $texttoshow = str_replace('{s}', $bprev->getNomUrl(1), $texttoshow);
  122. setEventMessages($texttoshow, null);
  123. } else {
  124. $texttoshow = $langs->trans("CreditTransferOrderCreated", '{s}');
  125. $texttoshow = str_replace('{s}', $bprev->getNomUrl(1), $texttoshow);
  126. setEventMessages($texttoshow, null);
  127. }
  128. header("Location: ".DOL_URL_ROOT.'/compta/prelevement/card.php?id='.urlencode($bprev->id).'&type='.urlencode($type));
  129. exit;
  130. }
  131. }
  132. }
  133. $objectclass = "BonPrelevement";
  134. if ($type == 'bank-transfer') {
  135. $uploaddir = $conf->paymentbybanktransfer->dir_output;
  136. } else {
  137. $uploaddir = $conf->prelevement->dir_output;
  138. }
  139. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  140. }
  141. /*
  142. * View
  143. */
  144. $form = new Form($db);
  145. $thirdpartystatic = new Societe($db);
  146. if ($type != 'bank-transfer') {
  147. $invoicestatic = new Facture($db);
  148. } else {
  149. $invoicestatic = new FactureFournisseur($db);
  150. }
  151. $bprev = new BonPrelevement($db);
  152. $arrayofselected = is_array($toselect) ? $toselect : array();
  153. // List of mass actions available
  154. $arrayofmassactions = array(
  155. );
  156. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  157. $arrayofmassactions = array();
  158. }
  159. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  160. llxHeader('', $langs->trans("NewStandingOrder"));
  161. if (prelevement_check_config($type) < 0) {
  162. $langs->load("errors");
  163. $modulenametoshow = "Withdraw";
  164. if ($type == 'bank-transfer') {
  165. $modulenametoshow = "PaymentByBankTransfer";
  166. }
  167. setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv($modulenametoshow)), null, 'errors');
  168. }
  169. /*$h=0;
  170. $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/create.php';
  171. $head[$h][1] = $langs->trans("NewStandingOrder");
  172. $head[$h][2] = 'payment';
  173. $hselected = 'payment';
  174. $h++;
  175. print dol_get_fiche_head($head, $hselected, $langs->trans("StandingOrders"), 0, 'payment');
  176. */
  177. $title = $langs->trans("NewStandingOrder");
  178. if ($type == 'bank-transfer') {
  179. $title = $langs->trans("NewPaymentByBankTransfer");
  180. }
  181. print load_fiche_titre($title);
  182. print dol_get_fiche_head();
  183. $nb = $bprev->nbOfInvoiceToPay($type);
  184. $pricetowithdraw = $bprev->SommeAPrelever($type);
  185. if ($nb < 0) {
  186. dol_print_error($bprev->error);
  187. }
  188. print '<table class="border centpercent tableforfield">';
  189. $title = $langs->trans("NbOfInvoiceToWithdraw");
  190. if ($type == 'bank-transfer') {
  191. $title = $langs->trans("NbOfInvoiceToPayByBankTransfer");
  192. }
  193. print '<tr><td class="titlefieldcreate">'.$title.'</td>';
  194. print '<td>';
  195. print $nb;
  196. print '</td></tr>';
  197. print '<tr><td>'.$langs->trans("AmountTotal").'</td>';
  198. print '<td class="amount">';
  199. print price($pricetowithdraw);
  200. print '</td>';
  201. print '</tr>';
  202. print '</table>';
  203. print '</div>';
  204. if ($mesg) {
  205. print $mesg;
  206. }
  207. print '<div class="tabsAction">'."\n";
  208. print '<form action="'.$_SERVER['PHP_SELF'].'?action=create" method="POST">';
  209. print '<input type="hidden" name="token" value="'.newToken().'">';
  210. print '<input type="hidden" name="type" value="'.$type.'">';
  211. if ($nb) {
  212. if ($pricetowithdraw) {
  213. $title = $langs->trans('BankToReceiveWithdraw').': ';
  214. if ($type == 'bank-transfer') {
  215. $title = $langs->trans('BankToPayCreditTransfer').': ';
  216. }
  217. print $title;
  218. print img_picto('', 'bank_account');
  219. $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT');
  220. print $form->select_comptes($conf->global->$default_account, 'id_bankaccount', 0, "courant=1", 0, '', 0, '', 1);
  221. print ' - ';
  222. if (empty($executiondate)) {
  223. $delayindays = 0;
  224. if ($type != 'bank-transfer') {
  225. $delayindays = $conf->global->PRELEVEMENT_ADDDAYS;
  226. } else {
  227. $delayindays = $conf->global->PAYMENTBYBANKTRANSFER_ADDDAYS;
  228. }
  229. $executiondate = dol_time_plus_duree(dol_now(), $delayindays, 'd');
  230. }
  231. print $langs->trans('ExecutionDate').' ';
  232. $datere = $executiondate;
  233. print $form->selectDate($datere, 're');
  234. if ($mysoc->isInEEC()) {
  235. $title = $langs->trans("CreateForSepa");
  236. if ($type == 'bank-transfer') {
  237. $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
  238. }
  239. if ($type != 'bank-transfer') {
  240. print '<select name="format">';
  241. print '<option value="FRST"'.($format == 'FRST' ? ' selected="selected"' : '').'>'.$langs->trans('SEPAFRST').'</option>';
  242. print '<option value="RCUR"'.($format == 'RCUR' ? ' selected="selected"' : '').'>'.$langs->trans('SEPARCUR').'</option>';
  243. print '</select>';
  244. }
  245. print '<input type="submit" class="butAction" value="'.$title.'"/>';
  246. } else {
  247. $title = $langs->trans("CreateAll");
  248. if ($type == 'bank-transfer') {
  249. $title = $langs->trans("CreateFileForPaymentByBankTransfer");
  250. }
  251. print '<input type="hidden" name="format" value="ALL">'."\n";
  252. print '<input type="submit" class="butAction" value="'.$title.'">'."\n";
  253. }
  254. } else {
  255. if ($mysoc->isInEEC()) {
  256. $title = $langs->trans("CreateForSepaFRST");
  257. if ($type == 'bank-transfer') {
  258. $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
  259. }
  260. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
  261. if ($type != 'bank-transfer') {
  262. $title = $langs->trans("CreateForSepaRCUR");
  263. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
  264. }
  265. } else {
  266. $title = $langs->trans("CreateAll");
  267. if ($type == 'bank-transfer') {
  268. $title = $langs->trans("CreateFileForPaymentByBankTransfer");
  269. }
  270. print '<a class="butActionRefused classfortooltip" href="#">'.$title."</a>\n";
  271. }
  272. }
  273. } else {
  274. $titlefortab = $langs->transnoentitiesnoconv("StandingOrders");
  275. $title = $langs->trans("CreateAll");
  276. if ($type == 'bank-transfer') {
  277. $titlefortab = $langs->transnoentitiesnoconv("PaymentByBankTransfers");
  278. $title = $langs->trans("CreateFileForPaymentByBankTransfer");
  279. }
  280. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoInvoiceToWithdraw", $titlefortab, $titlefortab)).'">'.$title."</a>\n";
  281. }
  282. print "</form>\n";
  283. print "</div>\n";
  284. print '</form>';
  285. print '<br>';
  286. /*
  287. * Invoices waiting for withdraw
  288. */
  289. $sql = "SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
  290. $sql .= " pfd.rowid as request_row_id, pfd.date_demande, pfd.amount";
  291. if ($type == 'bank-transfer') {
  292. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
  293. } else {
  294. $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
  295. }
  296. $sql .= " ".MAIN_DB_PREFIX."societe as s,";
  297. $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pfd";
  298. $sql .= " WHERE s.rowid = f.fk_soc";
  299. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  300. if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
  301. $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
  302. }
  303. //$sql .= " AND pfd.amount > 0";
  304. $sql .= " AND f.total_ttc > 0"; // Avoid credit notes
  305. $sql .= " AND pfd.traite = 0";
  306. $sql .= " AND pfd.ext_payment_id IS NULL";
  307. if ($type == 'bank-transfer') {
  308. $sql .= " AND pfd.fk_facture_fourn = f.rowid";
  309. } else {
  310. $sql .= " AND pfd.fk_facture = f.rowid";
  311. }
  312. if ($socid > 0) {
  313. $sql .= " AND f.fk_soc = ".((int) $socid);
  314. }
  315. $nbtotalofrecords = '';
  316. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  317. $result = $db->query($sql);
  318. $nbtotalofrecords = $db->num_rows($result);
  319. if (($page * $limit) > $nbtotalofrecords) {
  320. // if total resultset is smaller then paging size (filtering), goto and load page 0
  321. $page = 0;
  322. $offset = 0;
  323. }
  324. }
  325. $sql .= $db->plimit($limit + 1, $offset);
  326. $resql = $db->query($sql);
  327. if ($resql) {
  328. $num = $db->num_rows($resql);
  329. $i = 0;
  330. $param = '';
  331. if ($limit > 0 && $limit != $conf->liste_limit) {
  332. $param .= '&limit='.urlencode($limit);
  333. }
  334. if ($socid) {
  335. $param .= '&socid='.urlencode($socid);
  336. }
  337. if ($option) {
  338. $param .= "&option=".urlencode($option);
  339. }
  340. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  341. print '<input type="hidden" name="token" value="'.newToken().'">';
  342. print '<input type="hidden" name="page" value="'.$page.'">';
  343. if (!empty($limit)) {
  344. print '<input type="hidden" name="limit" value="'.$limit.'"/>';
  345. }
  346. if ($type != '') {
  347. print '<input type="hidden" name="type" value="'.$type.'">';
  348. }
  349. $title = $langs->trans("InvoiceWaitingWithdraw");
  350. if ($type == 'bank-transfer') {
  351. $title = $langs->trans("InvoiceWaitingPaymentByBankTransfer");
  352. }
  353. print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, '', '', $massactionbutton, $num, $nbtotalofrecords, 'bill', 0, '', '', $limit);
  354. $tradinvoice = "Invoice";
  355. if ($type == 'bank-transfer') {
  356. $tradinvoice = "SupplierInvoice";
  357. }
  358. print '<table class="noborder centpercent">';
  359. print '<tr class="liste_titre">';
  360. print '<td>'.$langs->trans($tradinvoice).'</td>';
  361. print '<td>'.$langs->trans("ThirdParty").'</td>';
  362. print '<td>'.$langs->trans("RIB").'</td>';
  363. print '<td>'.$langs->trans("RUM").'</td>';
  364. print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
  365. print '<td class="right">'.$langs->trans("DateRequest").'</td>';
  366. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  367. print '<td align="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
  368. }
  369. print '</tr>';
  370. if ($num) {
  371. require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
  372. $bac = new CompanyBankAccount($db);
  373. while ($i < $num && $i < $limit) {
  374. $obj = $db->fetch_object($resql);
  375. $bac->fetch(0, $obj->socid);
  376. print '<tr class="oddeven">';
  377. // Ref invoice
  378. print '<td>';
  379. $invoicestatic->id = $obj->rowid;
  380. $invoicestatic->ref = $obj->ref;
  381. print $invoicestatic->getNomUrl(1, 'withdraw');
  382. print '</td>';
  383. // Thirdparty
  384. print '<td>';
  385. $thirdpartystatic->fetch($obj->socid);
  386. print $thirdpartystatic->getNomUrl(1, 'ban');
  387. print '</td>';
  388. // RIB
  389. print '<td>';
  390. if ($bac->id > 0) {
  391. if (!empty($bac->iban) || !empty($bac->bic)) {
  392. print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
  393. if ($bac->verif() <= 0) {
  394. print img_warning('Error on default bank number for IBAN : '.$langs->trans($bac->error_message));
  395. }
  396. } else {
  397. print img_warning($langs->trans("IBANNotDefined"));
  398. }
  399. } else {
  400. print img_warning($langs->trans("NoBankAccountDefined"));
  401. }
  402. print '</td>';
  403. // RUM
  404. print '<td>';
  405. $rumtoshow = $thirdpartystatic->display_rib('rum');
  406. if ($rumtoshow) {
  407. print $rumtoshow;
  408. $format = $thirdpartystatic->display_rib('format');
  409. if ($type != 'bank-transfer') {
  410. if ($format) {
  411. print ' ('.$format.')';
  412. }
  413. }
  414. } else {
  415. print img_warning($langs->trans("NoBankAccountDefined"));
  416. }
  417. print '</td>';
  418. // Amount
  419. print '<td class="right amount">';
  420. print price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);
  421. print '</td>';
  422. // Date
  423. print '<td class="right">';
  424. print dol_print_date($db->jdate($obj->date_demande), 'day');
  425. print '</td>';
  426. // Action column
  427. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  428. print '<td class="nowrap center">';
  429. $selected = 0;
  430. if (in_array($obj->request_row_id, $arrayofselected)) {
  431. $selected = 1;
  432. }
  433. print '<input id="cb'.$obj->request_row_id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.'"'.($selected ? ' checked="checked"' : '').'>';
  434. print '</td>';
  435. }
  436. print '</tr>';
  437. $i++;
  438. }
  439. } else {
  440. print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  441. }
  442. print "</table>";
  443. print "</form>";
  444. print "<br>\n";
  445. } else {
  446. dol_print_error($db);
  447. }
  448. /*
  449. * List of latest withdraws
  450. */
  451. /*
  452. $limit=5;
  453. print load_fiche_titre($langs->trans("LastWithdrawalReceipts",$limit),'','');
  454. $sql = "SELECT p.rowid, p.ref, p.amount, p.statut";
  455. $sql.= ", p.datec";
  456. $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  457. $sql.= " WHERE p.entity IN (".getEntity('invoice').")";
  458. $sql.= " ORDER BY datec DESC";
  459. $sql.=$db->plimit($limit);
  460. $result = $db->query($sql);
  461. if ($result)
  462. {
  463. $num = $db->num_rows($result);
  464. $i = 0;
  465. print"\n<!-- debut table -->\n";
  466. print '<table class="noborder centpercent">';
  467. print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td>';
  468. print '<td class="center">'.$langs->trans("Date").'</td><td class="right">'.$langs->trans("Amount").'</td>';
  469. print '</tr>';
  470. while ($i < min($num,$limit))
  471. {
  472. $obj = $db->fetch_object($result);
  473. print '<tr class="oddeven">';
  474. print "<td>";
  475. $bprev->id=$obj->rowid;
  476. $bprev->ref=$obj->ref;
  477. print $bprev->getNomUrl(1);
  478. print "</td>\n";
  479. print '<td class="center">'.dol_print_date($db->jdate($obj->datec),'day')."</td>\n";
  480. print '<td class="right"><span class="amount">'.price($obj->amount,0,$langs,0,0,-1,$conf->currency)."</span></td>\n";
  481. print "</tr>\n";
  482. $i++;
  483. }
  484. print "</table><br>";
  485. $db->free($result);
  486. }
  487. else
  488. {
  489. dol_print_error($db);
  490. }
  491. */
  492. // End of page
  493. llxFooter();
  494. $db->close();