create.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2010-2023 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-2023 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.'/salaries/class/salary.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  39. // Load translation files required by the page
  40. $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies', 'bills'));
  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. $type = GETPOST('type', 'aZ09');
  47. $sourcetype = GETPOST('sourcetype', 'aZ09');
  48. $format = GETPOST('format', 'aZ09');
  49. $id_bankaccount = GETPOST('id_bankaccount', 'int');
  50. $executiondate = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  51. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  52. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  53. if (empty($page) || $page == -1) {
  54. $page = 0;
  55. } // If $page is not defined, or '' or -1
  56. $offset = $limit * $page;
  57. $hookmanager->initHooks(array('directdebitcreatecard', 'globalcard'));
  58. // Security check
  59. $socid = GETPOST('socid', 'int');
  60. if ($user->socid) {
  61. $socid = $user->socid;
  62. }
  63. if ($type == 'bank-transfer') {
  64. $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
  65. $permissiontoread = $user->hasRight('paymentbybanktransfer', 'read');
  66. $permissiontocreate = $user->hasRight('paymentbybanktransfer', 'create');
  67. } else {
  68. $result = restrictedArea($user, 'prelevement', '', '', 'bons');
  69. $permissiontoread = $user->hasRight('prelevement', 'bons', 'lire');
  70. $permissiontocreate = $user->hasRight('prelevement', 'bons', 'creer');
  71. }
  72. $error = 0;
  73. $option = "";
  74. $mesg = '';
  75. /*
  76. * Actions
  77. */
  78. if (GETPOST('cancel', 'alpha')) {
  79. $massaction = '';
  80. }
  81. $parameters = array('mode' => $mode, 'format' => $format, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
  82. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  83. if ($reshook < 0) {
  84. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  85. }
  86. if (empty($reshook)) {
  87. // Change customer bank information to withdraw
  88. /*
  89. if ($action == 'modify') {
  90. for ($i = 1; $i < 9; $i++) {
  91. dolibarr_set_const($db, GETPOST("nom".$i), GETPOST("value".$i), 'chaine', 0, '', $conf->entity);
  92. }
  93. }
  94. */
  95. if ($action == 'create' && $permissiontocreate) {
  96. $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT');
  97. //var_dump($default_account);var_dump(getDolGlobalString($default_account));var_dump($id_bankaccount);exit;
  98. if ($id_bankaccount != getDolGlobalInt($default_account)) {
  99. $res = dolibarr_set_const($db, $default_account, $id_bankaccount, 'chaine', 0, '', $conf->entity); // Set as default
  100. }
  101. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  102. $bank = new Account($db);
  103. $bank->fetch(getDolGlobalInt($default_account));
  104. // ICS is not mandatory with payment by bank transfer
  105. /*if ((empty($bank->ics) && $type !== 'bank-transfer')
  106. || (empty($bank->ics_transfer) && $type === 'bank-transfer')
  107. ) {*/
  108. if (empty($bank->ics) && $type !== 'bank-transfer') {
  109. $errormessage = str_replace('{url}', $bank->getNomUrl(1, '', '', -1, 1), $langs->trans("ErrorICSmissing", '{url}'));
  110. setEventMessages($errormessage, null, 'errors');
  111. $action = '';
  112. $error++;
  113. }
  114. $bprev = new BonPrelevement($db);
  115. if (!$error) {
  116. // getDolGlobalString('PRELEVEMENT_CODE_BANQUE') and getDolGlobalString('PRELEVEMENT_CODE_GUICHET') should be empty (we don't use them anymore)
  117. $result = $bprev->create(getDolGlobalString('PRELEVEMENT_CODE_BANQUE'), getDolGlobalString('PRELEVEMENT_CODE_GUICHET'), $mode, $format, $executiondate, 0, $type, 0, 0, $sourcetype);
  118. if ($result < 0) {
  119. $mesg = '';
  120. if ($bprev->error || !empty($bprev->errors)) {
  121. setEventMessages($bprev->error, $bprev->errors, 'errors');
  122. } else {
  123. $langs->load("errors");
  124. setEventMessages($langs->trans("ErrorsOnXLines", count($bprev->invoice_in_error)), null, 'warnings');
  125. }
  126. if (!empty($bprev->invoice_in_error)) {
  127. foreach ($bprev->invoice_in_error as $key => $val) {
  128. $mesg .= '<span class="warning">'.$val."</span><br>\n";
  129. }
  130. }
  131. } elseif ($result == 0 || !empty($bprev->invoice_in_error)) {
  132. $mesg = '';
  133. if ($result == 0) {
  134. if ($type != 'bank-transfer') {
  135. $mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format);
  136. }
  137. if ($type == 'bank-transfer' && $sourcetype != 'salary') {
  138. $mesg = $langs->trans("NoInvoiceCouldBeWithdrawedSupplier", $format);
  139. }
  140. if ($type == 'bank-transfer' && $sourcetype == 'salary') {
  141. $mesg = $langs->trans("NoSalariesCouldBeWithdrawed", $format);
  142. }
  143. setEventMessages($mesg, null, 'errors');
  144. }
  145. if (!empty($bprev->invoice_in_error)) {
  146. $mesg .= '<br>'."\n";
  147. foreach ($bprev->invoice_in_error as $key => $val) {
  148. $mesg .= '<span class="warning">'.$val."</span><br>\n";
  149. }
  150. }
  151. } else {
  152. if ($type != 'bank-transfer') {
  153. $texttoshow = $langs->trans("DirectDebitOrderCreated", '{s}');
  154. $texttoshow = str_replace('{s}', $bprev->getNomUrl(1), $texttoshow);
  155. setEventMessages($texttoshow, null);
  156. } else {
  157. $texttoshow = $langs->trans("CreditTransferOrderCreated", '{s}');
  158. $texttoshow = str_replace('{s}', $bprev->getNomUrl(1), $texttoshow);
  159. setEventMessages($texttoshow, null);
  160. }
  161. header("Location: ".DOL_URL_ROOT.'/compta/prelevement/card.php?id='.urlencode($bprev->id).'&type='.urlencode($type));
  162. exit;
  163. }
  164. }
  165. }
  166. $objectclass = "BonPrelevement";
  167. if ($type == 'bank-transfer') {
  168. $uploaddir = $conf->paymentbybanktransfer->dir_output;
  169. } else {
  170. $uploaddir = $conf->prelevement->dir_output;
  171. }
  172. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  173. }
  174. /*
  175. * View
  176. */
  177. $form = new Form($db);
  178. $thirdpartystatic = new Societe($db);
  179. if ($type != 'bank-transfer') {
  180. $invoicestatic = new Facture($db);
  181. } else {
  182. $invoicestatic = new FactureFournisseur($db);
  183. }
  184. $bprev = new BonPrelevement($db);
  185. $arrayofselected = is_array($toselect) ? $toselect : array();
  186. // List of mass actions available
  187. $arrayofmassactions = array(
  188. );
  189. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  190. $arrayofmassactions = array();
  191. }
  192. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  193. if (prelevement_check_config($type) < 0) {
  194. $langs->load("errors");
  195. $modulenametoshow = "Withdraw";
  196. if ($type == 'bank-transfer') {
  197. $modulenametoshow = "PaymentByBankTransfer";
  198. }
  199. setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv($modulenametoshow)), null, 'errors');
  200. }
  201. $title = $langs->trans("NewStandingOrder");
  202. if ($type == 'bank-transfer') {
  203. $title = $langs->trans("NewPaymentByBankTransfer");
  204. }
  205. llxHeader('', $title);
  206. $head = bon_prelevement_prepare_head($bprev, $bprev->nbOfInvoiceToPay($type), $bprev->nbOfInvoiceToPay($type, 'salary'));
  207. if ($type) {
  208. print dol_get_fiche_head($head, (!GETPOSTISSET('sourcetype') ? 'invoice' : 'salary'), $langs->trans("Invoices"), -1, $bprev->picto);
  209. } else {
  210. print load_fiche_titre($title);
  211. print dol_get_fiche_head();
  212. }
  213. if ($sourcetype != 'salary') {
  214. $nb = $bprev->nbOfInvoiceToPay($type);
  215. $pricetowithdraw = $bprev->SommeAPrelever($type);
  216. } else {
  217. $nb = $bprev->nbOfInvoiceToPay($type, 'salary');
  218. $pricetowithdraw = $bprev->SommeAPrelever($type, 'salary');
  219. }
  220. if ($nb < 0) {
  221. dol_print_error($bprev->error);
  222. }
  223. print '<table class="border centpercent tableforfield">';
  224. $labeltoshow = $langs->trans("NbOfInvoiceToWithdraw");
  225. if ($type == 'bank-transfer') {
  226. $labeltoshow = $langs->trans("NbOfInvoiceToPayByBankTransfer");
  227. }
  228. if ($sourcetype == 'salary') {
  229. $labeltoshow = $langs->trans("NbOfInvoiceToPayByBankTransferForSalaries");
  230. }
  231. print '<tr><td class="titlefield">'.$labeltoshow.'</td>';
  232. print '<td class="nowraponall">';
  233. print dol_escape_htmltag($nb);
  234. print '</td></tr>';
  235. print '<tr><td>'.$langs->trans("AmountTotal").'</td>';
  236. print '<td class="amount nowraponall">';
  237. print price($pricetowithdraw, 0, $langs, 1, -1, -1, $conf->currency);
  238. print '</td>';
  239. print '</tr>';
  240. print '</table>';
  241. print '</div>';
  242. print '<div class="tabsAction">'."\n";
  243. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  244. print '<input type="hidden" name="action" value="create">';
  245. print '<input type="hidden" name="token" value="'.newToken().'">';
  246. print '<input type="hidden" name="type" value="'.$type.'">';
  247. print '<input type="hidden" name="sourcetype" value="'.$sourcetype.'">';
  248. if ($nb) {
  249. if ($pricetowithdraw) {
  250. $title = $langs->trans('BankToReceiveWithdraw').': ';
  251. if ($type == 'bank-transfer') {
  252. $title = $langs->trans('BankToPayCreditTransfer').': ';
  253. }
  254. print '<span class="hideonsmartphone">'.$title.'</span>';
  255. print img_picto('', 'bank_account');
  256. $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT');
  257. print $form->select_comptes(getDolGlobalInt($default_account), 'id_bankaccount', 0, "courant=1", 0, '', 0, 'widthcentpercentminusx maxwidth300', 1);
  258. print ' &nbsp; &nbsp; ';
  259. if (empty($executiondate)) {
  260. $delayindays = 0;
  261. if ($type != 'bank-transfer') {
  262. $delayindays = getDolGlobalInt('PRELEVEMENT_ADDDAYS');
  263. } else {
  264. $delayindays = getDolGlobalInt('PAYMENTBYBANKTRANSFER_ADDDAYS');
  265. }
  266. $executiondate = dol_time_plus_duree(dol_now(), $delayindays, 'd');
  267. }
  268. print $langs->trans('ExecutionDate').' ';
  269. $datere = $executiondate;
  270. print $form->selectDate($datere, 're');
  271. if ($mysoc->isInEEC()) {
  272. $title = $langs->trans("CreateForSepa");
  273. if ($type == 'bank-transfer') {
  274. $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
  275. }
  276. if ($type != 'bank-transfer') {
  277. print '<select name="format">';
  278. print '<option value="FRST"'.($format == 'FRST' ? ' selected="selected"' : '').'>'.$langs->trans('SEPAFRST').'</option>';
  279. print '<option value="RCUR"'.($format == 'RCUR' ? ' selected="selected"' : '').'>'.$langs->trans('SEPARCUR').'</option>';
  280. print '</select>';
  281. }
  282. print '<input type="submit" class="butAction margintoponly maringbottomonly" value="'.$title.'"/>';
  283. } else {
  284. $title = $langs->trans("CreateAll");
  285. if ($type == 'bank-transfer') {
  286. $title = $langs->trans("CreateFileForPaymentByBankTransfer");
  287. }
  288. print '<input type="hidden" name="format" value="ALL">'."\n";
  289. print '<input type="submit" class="butAction margintoponly maringbottomonly" value="'.$title.'">'."\n";
  290. }
  291. } else {
  292. if ($mysoc->isInEEC()) {
  293. $title = $langs->trans("CreateForSepaFRST");
  294. if ($type == 'bank-transfer') {
  295. $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
  296. }
  297. print '<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
  298. if ($type != 'bank-transfer') {
  299. $title = $langs->trans("CreateForSepaRCUR");
  300. print '<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
  301. }
  302. } else {
  303. $title = $langs->trans("CreateAll");
  304. if ($type == 'bank-transfer') {
  305. $title = $langs->trans("CreateFileForPaymentByBankTransfer");
  306. }
  307. print '<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#">'.$title."</a>\n";
  308. }
  309. }
  310. } else {
  311. $titlefortab = $langs->transnoentitiesnoconv("StandingOrders");
  312. $title = $langs->trans("CreateAll");
  313. if ($type == 'bank-transfer') {
  314. $titlefortab = $langs->transnoentitiesnoconv("PaymentByBankTransfers");
  315. $title = $langs->trans("CreateFileForPaymentByBankTransfer");
  316. }
  317. print '<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoInvoiceToWithdraw", $titlefortab, $titlefortab)).'">';
  318. print $title;
  319. print "</a>\n";
  320. }
  321. print "</form>\n";
  322. print "</div>\n";
  323. // Show errors or warnings
  324. if ($mesg) {
  325. print $mesg;
  326. print '<br>';
  327. }
  328. print '<br>';
  329. /*
  330. * Invoices waiting for withdraw
  331. */
  332. if ($sourcetype != 'salary') {
  333. $sql = "SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
  334. if ($type == 'bank-transfer') {
  335. $sql .= " f.ref_supplier,";
  336. }
  337. $sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount";
  338. if ($type == 'bank-transfer') {
  339. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
  340. } else {
  341. $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
  342. }
  343. $sql .= " ".MAIN_DB_PREFIX."societe as s,";
  344. $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
  345. $sql .= " WHERE s.rowid = f.fk_soc";
  346. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  347. if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
  348. $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
  349. }
  350. //$sql .= " AND pd.amount > 0";
  351. $sql .= " AND f.total_ttc > 0"; // Avoid credit notes
  352. $sql .= " AND pd.traite = 0";
  353. $sql .= " AND pd.ext_payment_id IS NULL";
  354. if ($type == 'bank-transfer') {
  355. $sql .= " AND pd.fk_facture_fourn = f.rowid";
  356. } else {
  357. $sql .= " AND pd.fk_facture = f.rowid";
  358. }
  359. if ($socid > 0) {
  360. $sql .= " AND f.fk_soc = ".((int) $socid);
  361. }
  362. } else {
  363. $sql = "SELECT s.ref, s.rowid, s.amount, CONCAT(u.lastname, ' ', u.firstname) as name, u.rowid as uid,";
  364. $sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount";
  365. $sql .= " FROM ".MAIN_DB_PREFIX."salary as s,";
  366. $sql .= " ".MAIN_DB_PREFIX."user as u,";
  367. $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
  368. $sql .= " WHERE s.fk_user = u.rowid";
  369. $sql .= " AND s.entity IN (".getEntity('salary').")";
  370. /*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
  371. $sql .= " AND s.fk_statut = ".Facture::STATUS_VALIDATED;
  372. }*/
  373. $sql .= " AND s.amount > 0";
  374. $sql .= " AND pd.traite = 0";
  375. $sql .= " AND pd.ext_payment_id IS NULL";
  376. $sql .= " AND s.rowid = pd.fk_salary AND s.paye = ".Salary::STATUS_UNPAID;
  377. $sql .= " AND pd.traite = 0";
  378. }
  379. $nbtotalofrecords = '';
  380. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  381. $result = $db->query($sql);
  382. $nbtotalofrecords = $db->num_rows($result);
  383. if (($page * $limit) > $nbtotalofrecords) {
  384. // if total resultset is smaller then paging size (filtering), goto and load page 0
  385. $page = 0;
  386. $offset = 0;
  387. }
  388. }
  389. $sql .= $db->plimit($limit + 1, $offset);
  390. $resql = $db->query($sql);
  391. if ($resql) {
  392. $num = $db->num_rows($resql);
  393. $i = 0;
  394. $param = '';
  395. if ($limit > 0 && $limit != $conf->liste_limit) {
  396. $param .= '&limit='.((int) $limit);
  397. }
  398. if ($socid) {
  399. $param .= '&socid='.urlencode($socid);
  400. }
  401. if ($option) {
  402. $param .= "&option=".urlencode($option);
  403. }
  404. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  405. print '<input type="hidden" name="token" value="'.newToken().'">';
  406. print '<input type="hidden" name="page" value="'.$page.'">';
  407. if (!empty($limit)) {
  408. print '<input type="hidden" name="limit" value="'.$limit.'"/>';
  409. }
  410. if ($type != '') {
  411. print '<input type="hidden" name="type" value="'.$type.'">';
  412. }
  413. $title = $langs->trans("InvoiceWaitingWithdraw");
  414. $picto = 'bill';
  415. if ($type =='bank-transfer') {
  416. if ($sourcetype != 'salary') {
  417. $title = $langs->trans("InvoiceWaitingPaymentByBankTransfer");
  418. } else {
  419. $title = $langs->trans("SalaryWaitingWithdraw");
  420. $picto = 'salary';
  421. }
  422. }
  423. print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, '', '', $massactionbutton, $num, $nbtotalofrecords, $picto, 0, '', '', $limit);
  424. $tradinvoice = "Invoice";
  425. if ($type == 'bank-transfer') {
  426. if ($sourcetype != 'salary') {
  427. $tradinvoice = "SupplierInvoice";
  428. } else {
  429. $tradinvoice = "RefSalary";
  430. }
  431. }
  432. print '<div class="div-table-responsive-no-min">';
  433. print '<table class="noborder centpercent">';
  434. print '<tr class="liste_titre">';
  435. // Action column
  436. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  437. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  438. print '<td align="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
  439. }
  440. }
  441. // Ref invoice or salary
  442. print '<td>'.$langs->trans($tradinvoice).'</td>';
  443. // Ref supplier
  444. if ($type == 'bank-transfer' && $sourcetype != 'salary') {
  445. print '<td>'.$langs->trans("RefSupplier").'</td>';
  446. }
  447. // Thirdparty or user
  448. if ($sourcetype != 'salary') {
  449. print '<td>'.$langs->trans("ThirdParty").'</td>';
  450. } else {
  451. print '<td>'.$langs->trans("Employee").'</td>';
  452. }
  453. // BAN
  454. print '<td>'.$langs->trans("RIB").'</td>';
  455. // RUM
  456. if (empty($type) || $type == 'direc-debit') {
  457. print '<td>'.$langs->trans("RUM").'</td>';
  458. }
  459. print '<td class="right">';
  460. if ($sourcetype == 'salary') {
  461. print $langs->trans("Amount");
  462. } else {
  463. print $langs->trans("AmountTTC");
  464. }
  465. print '</td>';
  466. print '<td class="right">'.$langs->trans("DateRequest").'</td>';
  467. // Action column
  468. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  469. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  470. print '<td align="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
  471. }
  472. }
  473. print '</tr>';
  474. if ($num) {
  475. if ($sourcetype != 'salary') {
  476. require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
  477. } else {
  478. require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php';
  479. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  480. }
  481. while ($i < $num && $i < $limit) {
  482. $obj = $db->fetch_object($resql);
  483. if ($sourcetype != 'salary') {
  484. $bac = new CompanyBankAccount($db); // Must include the new in loop so the fetch is clean
  485. $bac->fetch(0, $obj->socid);
  486. $invoicestatic->id = $obj->rowid;
  487. $invoicestatic->ref = $obj->ref;
  488. $invoicestatic->ref_supplier = $obj->ref_supplier;
  489. } else {
  490. $bac = new UserBankAccount($db);
  491. $bac->fetch(0, '', $obj->uid);
  492. $salary = new Salary($db);
  493. $salary->fetch($obj->rowid);
  494. }
  495. print '<tr class="oddeven">';
  496. // Action column
  497. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  498. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  499. print '<td class="nowrap center">';
  500. $selected = 0;
  501. if (in_array($obj->request_row_id, $arrayofselected)) {
  502. $selected = 1;
  503. }
  504. print '<input id="cb'.$obj->request_row_id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.'"'.($selected ? ' checked="checked"' : '').'>';
  505. print '</td>';
  506. }
  507. }
  508. // Ref invoice
  509. print '<td class="tdoverflowmax150">';
  510. if ($sourcetype != 'salary') {
  511. print $invoicestatic->getNomUrl(1, 'withdraw');
  512. } else {
  513. print $salary->getNomUrl(1, 'withdraw');
  514. }
  515. print '</td>';
  516. if ($type == 'bank-transfer' && $sourcetype != 'salary') {
  517. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($invoicestatic->ref_supplier).'">';
  518. print dol_escape_htmltag($invoicestatic->ref_supplier);
  519. print '</td>';
  520. }
  521. // Thirdparty
  522. if ($sourcetype != 'salary') {
  523. print '<td class="tdoverflowmax100">';
  524. $thirdpartystatic->fetch($obj->socid);
  525. print $thirdpartystatic->getNomUrl(1, 'ban');
  526. print '</td>';
  527. } else {
  528. print '<td class="tdoverflowmax100">';
  529. $user->fetch($obj->uid);
  530. print $user->getNomUrl(-1);
  531. print '</td>';
  532. }
  533. // BAN
  534. print '<td>';
  535. if ($bac->id > 0) {
  536. if (!empty($bac->iban) || !empty($bac->bic)) {
  537. print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
  538. if ($bac->verif() <= 0) {
  539. print img_warning('Error on default bank number for IBAN : '.$langs->trans($bac->error));
  540. }
  541. } else {
  542. print img_warning($langs->trans("IBANNotDefined"));
  543. }
  544. } else {
  545. print img_warning($langs->trans("NoBankAccountDefined"));
  546. }
  547. print '</td>';
  548. // RUM
  549. if (empty($type) || $type == 'direct-debit') {
  550. print '<td>';
  551. $rumtoshow = $thirdpartystatic->display_rib('rum');
  552. if ($rumtoshow) {
  553. print $rumtoshow;
  554. $format = $thirdpartystatic->display_rib('format');
  555. if ($type != 'bank-transfer') {
  556. if ($format) {
  557. print ' ('.$format.')';
  558. }
  559. }
  560. } else {
  561. print img_warning($langs->trans("NoBankAccountDefined"));
  562. }
  563. print '</td>';
  564. }
  565. // Amount
  566. print '<td class="right amount">';
  567. print price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);
  568. print '</td>';
  569. // Date
  570. print '<td class="right">';
  571. print dol_print_date($db->jdate($obj->date_demande), 'day');
  572. print '</td>';
  573. // Action column
  574. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  575. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  576. print '<td class="nowrap center">';
  577. $selected = 0;
  578. if (in_array($obj->request_row_id, $arrayofselected)) {
  579. $selected = 1;
  580. }
  581. print '<input id="cb'.$obj->request_row_id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.'"'.($selected ? ' checked="checked"' : '').'>';
  582. print '</td>';
  583. }
  584. }
  585. print '</tr>';
  586. $i++;
  587. }
  588. } else {
  589. $colspan = 6;
  590. if ($type == 'bank-transfer') {
  591. $colspan++;
  592. }
  593. if ($massactionbutton || $massaction) {
  594. $colspan++;
  595. }
  596. print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  597. }
  598. print "</table>";
  599. print "</div>";
  600. print "</form>";
  601. print "<br>\n";
  602. } else {
  603. dol_print_error($db);
  604. }
  605. /*
  606. * List of latest withdraws
  607. */
  608. /*
  609. $limit=5;
  610. print load_fiche_titre($langs->trans("LastWithdrawalReceipts",$limit),'','');
  611. $sql = "SELECT p.rowid, p.ref, p.amount, p.statut";
  612. $sql.= ", p.datec";
  613. $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  614. $sql.= " WHERE p.entity IN (".getEntity('invoice').")";
  615. $sql.= " ORDER BY datec DESC";
  616. $sql.=$db->plimit($limit);
  617. $result = $db->query($sql);
  618. if ($result)
  619. {
  620. $num = $db->num_rows($result);
  621. $i = 0;
  622. print"\n<!-- debut table -->\n";
  623. print '<table class="noborder centpercent">';
  624. print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td>';
  625. print '<td class="center">'.$langs->trans("Date").'</td><td class="right">'.$langs->trans("Amount").'</td>';
  626. print '</tr>';
  627. while ($i < min($num,$limit))
  628. {
  629. $obj = $db->fetch_object($result);
  630. print '<tr class="oddeven">';
  631. print "<td>";
  632. $bprev->id=$obj->rowid;
  633. $bprev->ref=$obj->ref;
  634. print $bprev->getNomUrl(1);
  635. print "</td>\n";
  636. print '<td class="center">'.dol_print_date($db->jdate($obj->datec),'day')."</td>\n";
  637. print '<td class="right"><span class="amount">'.price($obj->amount,0,$langs,0,0,-1,$conf->currency)."</span></td>\n";
  638. print "</tr>\n";
  639. $i++;
  640. }
  641. print "</table><br>";
  642. $db->free($result);
  643. }
  644. else
  645. {
  646. dol_print_error($db);
  647. }
  648. */
  649. // End of page
  650. llxFooter();
  651. $db->close();