prelevement.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. <?php
  2. /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  8. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  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/facture/prelevement.php
  25. * \ingroup facture
  26. * \brief Management of direct debit order or credit tranfer of invoices
  27. */
  28. // Load Dolibarr environment
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  39. // Load translation files required by the page
  40. $langs->loadLangs(array('bills', 'banks', 'withdrawals', 'companies'));
  41. $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
  42. $ref = GETPOST('ref', 'alpha');
  43. $socid = GETPOST('socid', 'int');
  44. $action = GETPOST('action', 'aZ09');
  45. $type = GETPOST('type', 'aZ09');
  46. $fieldid = (!empty($ref) ? 'ref' : 'rowid');
  47. if ($user->socid) {
  48. $socid = $user->socid;
  49. }
  50. $moreparam = '';
  51. if ($type == 'bank-transfer') {
  52. $object = new FactureFournisseur($db);
  53. $moreparam = '&type='.$type;
  54. } else {
  55. $object = new Facture($db);
  56. }
  57. // Load object
  58. if ($id > 0 || !empty($ref)) {
  59. $ret = $object->fetch($id, $ref);
  60. $isdraft = (($object->statut == FactureFournisseur::STATUS_DRAFT) ? 1 : 0);
  61. if ($ret > 0) {
  62. $object->fetch_thirdparty();
  63. }
  64. }
  65. $hookmanager->initHooks(array('directdebitcard', 'globalcard'));
  66. if ($type == 'bank-transfer') {
  67. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture', 'fk_soc', $fieldid, $isdraft);
  68. if (!$user->hasRight('fournisseur', 'facture', 'lire')) {
  69. accessforbidden();
  70. }
  71. } else {
  72. $result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid, $isdraft);
  73. if (!$user->hasRight('facture', 'lire')) {
  74. accessforbidden();
  75. }
  76. }
  77. if ($type == 'bank-transfer') {
  78. $usercancreate = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
  79. } else {
  80. $usercancreate = $user->hasRight('facture', 'creer');
  81. }
  82. /*
  83. * Actions
  84. */
  85. $parameters = array('socid' => $socid);
  86. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  87. if ($reshook < 0) {
  88. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  89. }
  90. if (empty($reshook)) {
  91. if ($action == "new" && $usercancreate) {
  92. if ($object->id > 0) {
  93. $db->begin();
  94. $newtype = $type;
  95. $sourcetype = 'facture';
  96. if ($type == 'bank-transfer') {
  97. $sourcetype = 'supplier_invoice';
  98. $newtype = 'bank-transfer';
  99. }
  100. $paymentservice = GETPOST('paymentservice');
  101. $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $sourcetype);
  102. if ($result > 0) {
  103. $db->commit();
  104. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  105. } else {
  106. $db->rollback();
  107. setEventMessages($object->error, $object->errors, 'errors');
  108. }
  109. }
  110. $action = '';
  111. }
  112. if ($action == "delete" && $usercancreate) {
  113. if ($object->id > 0) {
  114. $result = $object->demande_prelevement_delete($user, GETPOST('did', 'int'));
  115. if ($result == 0) {
  116. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id.'&type='.$type);
  117. exit;
  118. }
  119. }
  120. }
  121. // Make payment with Direct Debit Stripe
  122. if ($action == 'sepastripedirectdebit' && $usercancreate) {
  123. $result = $object->makeStripeSepaRequest($user, GETPOST('did', 'int'), 'direct-debit', 'facture');
  124. if ($result < 0) {
  125. setEventMessages($object->error, $object->errors, 'errors');
  126. } else {
  127. // We refresh object data
  128. $ret = $object->fetch($id, $ref);
  129. $isdraft = (($object->statut == Facture::STATUS_DRAFT) ? 1 : 0);
  130. if ($ret > 0) {
  131. $object->fetch_thirdparty();
  132. }
  133. }
  134. }
  135. // Make payment with Direct Debit Stripe
  136. if ($action == 'sepastripecredittransfer' && $usercancreate) {
  137. $result = $object->makeStripeSepaRequest($user, GETPOST('did', 'int'), 'bank-transfer', 'supplier_invoice');
  138. if ($result < 0) {
  139. setEventMessages($object->error, $object->errors, 'errors');
  140. } else {
  141. // We refresh object data
  142. $ret = $object->fetch($id, $ref);
  143. $isdraft = (($object->statut == FactureFournisseur::STATUS_DRAFT) ? 1 : 0);
  144. if ($ret > 0) {
  145. $object->fetch_thirdparty();
  146. }
  147. }
  148. }
  149. // Set payments conditions
  150. if ($action == 'setconditions' && $usercancreate) {
  151. $object->fetch($id);
  152. $object->cond_reglement_code = 0; // To clean property
  153. $object->cond_reglement_id = 0; // To clean property
  154. $error = 0;
  155. $db->begin();
  156. if (!$error) {
  157. $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
  158. if ($result < 0) {
  159. $error++;
  160. setEventMessages($object->error, $object->errors, 'errors');
  161. }
  162. }
  163. if (!$error) {
  164. $old_date_echeance = $object->date_echeance;
  165. $new_date_echeance = $object->calculate_date_lim_reglement();
  166. if ($new_date_echeance > $old_date_echeance) {
  167. $object->date_echeance = $new_date_echeance;
  168. }
  169. if ($object->date_echeance < $object->date) {
  170. $object->date_echeance = $object->date;
  171. }
  172. $result = $object->update($user);
  173. if ($result < 0) {
  174. $error++;
  175. setEventMessages($object->error, $object->errors, 'errors');
  176. }
  177. }
  178. if ($error) {
  179. $db->rollback();
  180. } else {
  181. $db->commit();
  182. }
  183. } elseif ($action == 'setmode' && $usercancreate) {
  184. // payment mode
  185. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
  186. } elseif ($action == 'setdatef' && $usercancreate) {
  187. $newdate = dol_mktime(0, 0, 0, GETPOST('datefmonth', 'int'), GETPOST('datefday', 'int'), GETPOST('datefyear', 'int'), 'tzserver');
  188. if ($newdate > (dol_now('tzuserrel') + (!getDolGlobalString('INVOICE_MAX_FUTURE_DELAY') ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
  189. if (!getDolGlobalString('INVOICE_MAX_FUTURE_DELAY')) {
  190. setEventMessages($langs->trans("WarningInvoiceDateInFuture"), null, 'warnings');
  191. } else {
  192. setEventMessages($langs->trans("WarningInvoiceDateTooFarInFuture"), null, 'warnings');
  193. }
  194. }
  195. $object->date = $newdate;
  196. $date_echence_calc = $object->calculate_date_lim_reglement();
  197. if (!empty($object->date_echeance) && $object->date_echeance < $date_echence_calc) {
  198. $object->date_echeance = $date_echence_calc;
  199. }
  200. if ($object->date_echeance && $object->date_echeance < $object->date) {
  201. $object->date_echeance = $object->date;
  202. }
  203. $result = $object->update($user);
  204. if ($result < 0) {
  205. dol_print_error($db, $object->error);
  206. }
  207. } elseif ($action == 'setdate_lim_reglement' && $usercancreate) {
  208. $object->date_echeance = dol_mktime(12, 0, 0, GETPOST('date_lim_reglementmonth', 'int'), GETPOST('date_lim_reglementday', 'int'), GETPOST('date_lim_reglementyear', 'int'));
  209. if (!empty($object->date_echeance) && $object->date_echeance < $object->date) {
  210. $object->date_echeance = $object->date;
  211. setEventMessages($langs->trans("DatePaymentTermCantBeLowerThanObjectDate"), null, 'warnings');
  212. }
  213. $result = $object->update($user);
  214. if ($result < 0) {
  215. dol_print_error($db, $object->error);
  216. }
  217. }
  218. }
  219. /*
  220. * View
  221. */
  222. $form = new Form($db);
  223. $now = dol_now();
  224. if ($type == 'bank-transfer') {
  225. $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('CreditTransfer');
  226. $helpurl = "";
  227. } else {
  228. $title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('StandingOrders');
  229. $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
  230. }
  231. llxHeader('', $title, $helpurl);
  232. if ($object->id > 0) {
  233. $selleruserevenustamp = $mysoc->useRevenueStamp();
  234. $totalpaid = $object->getSommePaiement();
  235. $totalcreditnotes = $object->getSumCreditNotesUsed();
  236. $totaldeposits = $object->getSumDepositsUsed();
  237. //print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
  238. // We can also use bcadd to avoid pb with floating points
  239. // For example print 239.2 - 229.3 - 9.9; does not return 0.
  240. //$resteapayer=bcadd($object->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT);
  241. //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
  242. $resteapayer = price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
  243. if ($object->paye) {
  244. $resteapayer = 0;
  245. }
  246. $resteapayeraffiche = $resteapayer;
  247. if ($type == 'bank-transfer') {
  248. if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { // Not recommended
  249. $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
  250. $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
  251. } else {
  252. $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
  253. $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
  254. }
  255. $absolute_discount = $object->thirdparty->getAvailableDiscounts('', $filterabsolutediscount, 0, 1);
  256. $absolute_creditnote = $object->thirdparty->getAvailableDiscounts('', $filtercreditnote, 0, 1);
  257. $absolute_discount = price2num($absolute_discount, 'MT');
  258. $absolute_creditnote = price2num($absolute_creditnote, 'MT');
  259. } else {
  260. if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { // Not recommended
  261. $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
  262. $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
  263. } else {
  264. $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
  265. $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
  266. }
  267. $absolute_discount = $object->thirdparty->getAvailableDiscounts('', $filterabsolutediscount);
  268. $absolute_creditnote = $object->thirdparty->getAvailableDiscounts('', $filtercreditnote);
  269. $absolute_discount = price2num($absolute_discount, 'MT');
  270. $absolute_creditnote = price2num($absolute_creditnote, 'MT');
  271. }
  272. $author = new User($db);
  273. if ($object->fk_user_author) {
  274. $author->fetch($object->fk_user_author);
  275. }
  276. if ($type == 'bank-transfer') {
  277. $head = facturefourn_prepare_head($object);
  278. } else {
  279. $head = facture_prepare_head($object);
  280. }
  281. $numopen = 0;
  282. $pending = 0;
  283. $numclosed = 0;
  284. // How many Direct debit or Credit transfer open requests ?
  285. $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
  286. $sql .= " , pfd.date_traite as date_traite";
  287. $sql .= " , pfd.amount";
  288. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
  289. if ($type == 'bank-transfer') {
  290. $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
  291. } else {
  292. $sql .= " WHERE fk_facture = ".((int) $object->id);
  293. }
  294. $sql .= " AND pfd.traite = 0";
  295. $sql .= " AND pfd.type = 'ban'";
  296. $sql .= " ORDER BY pfd.date_demande DESC";
  297. $resql = $db->query($sql);
  298. if ($resql) {
  299. $num = $db->num_rows($resql);
  300. $numopen = $num;
  301. } else {
  302. dol_print_error($db);
  303. }
  304. print dol_get_fiche_head($head, 'standingorders', $title, -1, ($type == 'bank-transfer' ? 'supplier_invoice' : 'bill'));
  305. // Invoice content
  306. if ($type == 'bank-transfer') {
  307. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  308. } else {
  309. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  310. }
  311. $morehtmlref = '<div class="refidno">';
  312. // Ref customer
  313. if ($type == 'bank-transfer') {
  314. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  315. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  316. } else {
  317. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  318. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  319. }
  320. // Thirdparty
  321. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  322. if ($type == 'bank-transfer') {
  323. if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
  324. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
  325. }
  326. } else {
  327. if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
  328. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
  329. }
  330. }
  331. // Project
  332. if (isModEnabled('project')) {
  333. $langs->load("projects");
  334. $morehtmlref .= '<br>';
  335. if (0) {
  336. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  337. if ($action != 'classify') {
  338. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  339. }
  340. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  341. } else {
  342. if (!empty($object->fk_project)) {
  343. $proj = new Project($db);
  344. $proj->fetch($object->fk_project);
  345. $morehtmlref .= $proj->getNomUrl(1);
  346. if ($proj->title) {
  347. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  348. }
  349. }
  350. }
  351. }
  352. $morehtmlref .= '</div>';
  353. $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  354. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $moreparam, 0, '', '');
  355. print '<div class="fichecenter">';
  356. print '<div class="fichehalfleft">';
  357. print '<div class="underbanner clearboth"></div>';
  358. print '<table class="border centpercent tableforfield">';
  359. // Type
  360. print '<tr><td class="titlefield fieldname_type">'.$langs->trans('Type').'</td><td colspan="3">';
  361. print '<span class="badgeneutral">';
  362. print $object->getLibType();
  363. print '</span>';
  364. if (!empty($object->module_source)) {
  365. print ' <span class="opacitymediumbycolor paddingleft">('.$langs->trans("POS").' '.$object->module_source.' - '.$langs->trans("Terminal").' '.$object->pos_source.')</span>';
  366. }
  367. if ($object->type == $object::TYPE_REPLACEMENT) {
  368. if ($type == 'bank-transfer') {
  369. $facreplaced = new FactureFournisseur($db);
  370. } else {
  371. $facreplaced = new Facture($db);
  372. }
  373. $facreplaced->fetch($object->fk_facture_source);
  374. print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).'</span>';
  375. }
  376. if ($object->type == $object::TYPE_CREDIT_NOTE && !empty($object->fk_facture_source)) {
  377. if ($type == 'bank-transfer') {
  378. $facusing = new FactureFournisseur($db);
  379. } else {
  380. $facusing = new Facture($db);
  381. }
  382. $facusing->fetch($object->fk_facture_source);
  383. print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).'</span>';
  384. }
  385. $facidavoir = $object->getListIdAvoirFromInvoice();
  386. if (count($facidavoir) > 0) {
  387. $invoicecredits = array();
  388. foreach ($facidavoir as $facid) {
  389. if ($type == 'bank-transfer') {
  390. $facavoir = new FactureFournisseur($db);
  391. } else {
  392. $facavoir = new Facture($db);
  393. }
  394. $facavoir->fetch($facid);
  395. $invoicecredits[] = $facavoir->getNomUrl(1);
  396. }
  397. print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("InvoiceHasAvoir");
  398. print ' '. (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits);
  399. print '</span>';
  400. }
  401. /*
  402. if ($objectidnext > 0) {
  403. $facthatreplace=new Facture($db);
  404. $facthatreplace->fetch($objectidnext);
  405. print ' <span class="opacitymediumbycolor paddingleft">'.str_replace('{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities("ReplacedByInvoice", '{s1}')).'</span>';
  406. }
  407. */
  408. print '</td></tr>';
  409. // Relative and absolute discounts
  410. print '<!-- Discounts -->'."\n";
  411. print '<tr><td>'.$langs->trans('DiscountStillRemaining').'</td><td colspan="3">';
  412. if ($type == 'bank-transfer') {
  413. //$societe = new Fournisseur($db);
  414. //$result = $societe->fetch($object->socid);
  415. $thirdparty = $object->thirdparty;
  416. $discount_type = 1;
  417. } else {
  418. $thirdparty = $object->thirdparty;
  419. $discount_type = 0;
  420. }
  421. $backtopage = urlencode($_SERVER["PHP_SELF"].'?facid='.$object->id);
  422. $cannotApplyDiscount = 1;
  423. include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
  424. print '</td></tr>';
  425. // Label
  426. if ($type == 'bank-transfer') {
  427. print '<tr>';
  428. print '<td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td>';
  429. print '<td>'.$form->editfieldval("Label", 'label', $object->label, $object, 0).'</td>';
  430. print '</tr>';
  431. }
  432. // Date invoice
  433. print '<tr><td>';
  434. print '<table class="nobordernopadding centpercent"><tr><td>';
  435. print $langs->trans('DateInvoice');
  436. print '</td>';
  437. if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
  438. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editinvoicedate&token='.newToken().'&id='.$object->id.'&type='.urlencode($type).'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
  439. }
  440. print '</tr></table>';
  441. print '</td><td colspan="3">';
  442. if ($object->type != $object::TYPE_CREDIT_NOTE) {
  443. if ($action == 'editinvoicedate') {
  444. print $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $object->date, 'invoicedate', 0, 0, 1, $type);
  445. } else {
  446. print dol_print_date($object->date, 'day');
  447. }
  448. } else {
  449. print dol_print_date($object->date, 'day');
  450. }
  451. print '</td>';
  452. print '</tr>';
  453. // Payment condition
  454. print '<tr><td>';
  455. print '<table class="nobordernopadding centpercent"><tr><td>';
  456. print $langs->trans('PaymentConditionsShort');
  457. print '</td>';
  458. if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editconditions' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
  459. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&token='.newToken().'&id='.$object->id.'&type='.urlencode($type).'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
  460. }
  461. print '</tr></table>';
  462. print '</td><td colspan="3">';
  463. if ($object->type != $object::TYPE_CREDIT_NOTE) {
  464. if ($action == 'editconditions') {
  465. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 0, $type);
  466. } else {
  467. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
  468. }
  469. } else {
  470. print '&nbsp;';
  471. }
  472. print '</td></tr>';
  473. // Date payment term
  474. print '<tr><td>';
  475. print '<table class="nobordernopadding centpercent"><tr><td>';
  476. print $langs->trans('DateMaxPayment');
  477. print '</td>';
  478. if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
  479. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editpaymentterm&token='.newToken().'&id='.$object->id.'&type='.urlencode($type).'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
  480. }
  481. print '</tr></table>';
  482. print '</td><td colspan="3">';
  483. if ($object->type != $object::TYPE_CREDIT_NOTE) {
  484. $duedate = $object->date_lim_reglement;
  485. if ($type == 'bank-transfer') {
  486. $duedate = $object->date_echeance;
  487. }
  488. if ($action == 'editpaymentterm') {
  489. print $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $duedate, 'paymentterm', 0, 0, 1, $type);
  490. } else {
  491. print dol_print_date($duedate, 'day');
  492. if ($object->hasDelay()) {
  493. print img_warning($langs->trans('Late'));
  494. }
  495. }
  496. } else {
  497. print '&nbsp;';
  498. }
  499. print '</td></tr>';
  500. // Payment mode
  501. print '<tr><td>';
  502. print '<table class="nobordernopadding centpercent"><tr><td>';
  503. print $langs->trans('PaymentMode');
  504. print '</td>';
  505. if ($action != 'editmode' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
  506. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'&type='.urlencode($type).'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
  507. }
  508. print '</tr></table>';
  509. print '</td><td colspan="3">';
  510. $filtertype = 'CRDT';
  511. if ($type == 'bank-transfer') {
  512. $filtertype = 'DBIT';
  513. }
  514. if ($action == 'editmode') {
  515. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', $filtertype, 1, 0, $type);
  516. } else {
  517. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
  518. }
  519. print '</td></tr>';
  520. // Bank Account
  521. print '<tr><td class="nowrap">';
  522. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  523. print $langs->trans('BankAccount');
  524. print '<td>';
  525. if (($action != 'editbankaccount') && $user->hasRight('commande', 'creer') && $object->status == $object::STATUS_DRAFT) {
  526. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'&type='.urlencode($type).'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
  527. }
  528. print '</tr></table>';
  529. print '</td><td colspan="3">';
  530. if ($action == 'editbankaccount') {
  531. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
  532. } else {
  533. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
  534. }
  535. print "</td>";
  536. print '</tr>';
  537. // IBAN of seller or supplier
  538. $title = 'CustomerIBAN';
  539. if ($type == 'bank-transfer') {
  540. $title = 'SupplierIBAN';
  541. }
  542. print '<tr><td>'.$langs->trans($title).'</td><td colspan="3">';
  543. $bac = new CompanyBankAccount($db);
  544. $bac->fetch(0, $object->thirdparty->id);
  545. print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
  546. if (!empty($bac->iban)) {
  547. if ($bac->verif() <= 0) {
  548. print img_warning('Error on default bank number for IBAN : '.$bac->error);
  549. }
  550. } else {
  551. if ($numopen || ($type != 'bank-transfer' && $object->mode_reglement_code == 'PRE') || ($type == 'bank-transfer' && $object->mode_reglement_code == 'VIR')) {
  552. print img_warning($langs->trans("NoDefaultIBANFound"));
  553. }
  554. }
  555. print '</td></tr>';
  556. print '</table>';
  557. print '</div>';
  558. print '<div class="fichehalfright">';
  559. print '<div class="underbanner clearboth"></div>';
  560. print '<table class="border centpercent tableforfield">';
  561. if (isModEnabled('multicurrency') && ($object->multicurrency_code != $conf->currency)) {
  562. // Multicurrency Amount HT
  563. print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';
  564. print '<td class="nowrap">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
  565. print '</tr>';
  566. // Multicurrency Amount VAT
  567. print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>';
  568. print '<td class="nowrap">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
  569. print '</tr>';
  570. // Multicurrency Amount TTC
  571. print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>';
  572. print '<td class="nowrap">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
  573. print '</tr>';
  574. }
  575. // Amount
  576. print '<tr><td class="titlefield">'.$langs->trans('AmountHT').'</td>';
  577. print '<td class="nowrap">'.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
  578. // Vat
  579. print '<tr><td>'.$langs->trans('AmountVAT').'</td><td colspan="3" class="nowrap">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
  580. print '</tr>';
  581. // Amount Local Taxes
  582. if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) { // Localtax1
  583. print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
  584. print '<td class="nowrap">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
  585. }
  586. if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) { // Localtax2
  587. print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
  588. print '<td class=nowrap">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
  589. }
  590. // Revenue stamp
  591. if ($selleruserevenustamp) { // Test company use revenue stamp
  592. print '<tr><td>';
  593. print '<table class="nobordernopadding" width="100%"><tr><td>';
  594. print $langs->trans('RevenueStamp');
  595. print '</td>';
  596. if ($action != 'editrevenuestamp' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
  597. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrevenuestamp&token='.newToken().'&facid='.$object->id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'</a></td>';
  598. }
  599. print '</tr></table>';
  600. print '</td><td>';
  601. print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
  602. print '</td></tr>';
  603. }
  604. // Total with tax
  605. print '<tr><td>'.$langs->trans('AmountTTC').'</td><td class="nowrap">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
  606. $resteapayer = price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
  607. // Hook to change amount for other reasons, e.g. apply cash discount for payment before agreed date
  608. $parameters = array('remaintopay' => $resteapayer);
  609. $reshook = $hookmanager->executeHooks('finalizeAmountOfSupplierInvoice', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  610. if ($reshook > 0) {
  611. print $hookmanager->resPrint;
  612. if (!empty($remaintopay = $hookmanager->resArray['remaintopay'])) {
  613. $resteapayer = $remaintopay;
  614. }
  615. }
  616. // TODO Replace this by an include with same code to show already done payment visible in invoice card
  617. print '<tr><td>'.$langs->trans('RemainderToPay').'</td><td class="nowrap">'.price($resteapayer, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
  618. print '</table>';
  619. print '</div>';
  620. print '</div>';
  621. print '<div class="clearboth"></div>';
  622. print dol_get_fiche_end();
  623. // For which amount ?
  624. $sql = "SELECT SUM(pfd.amount) as amount";
  625. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
  626. if ($type == 'bank-transfer') {
  627. $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
  628. } else {
  629. $sql .= " WHERE fk_facture = ".((int) $object->id);
  630. }
  631. $sql .= " AND pfd.traite = 0";
  632. $sql .= " AND pfd.type = 'ban'";
  633. $resql = $db->query($sql);
  634. if ($resql) {
  635. $obj = $db->fetch_object($resql);
  636. if ($obj) {
  637. $pending = $obj->amount;
  638. }
  639. } else {
  640. dol_print_error($db);
  641. }
  642. /*
  643. * Buttons
  644. */
  645. print "\n".'<div class="tabsAction">'."\n";
  646. $buttonlabel = $langs->trans("MakeWithdrawRequest");
  647. $user_perms = $user->hasRight('prelevement', 'bons', 'creer');
  648. if ($type == 'bank-transfer') {
  649. $buttonlabel = $langs->trans("MakeBankTransferOrder");
  650. $user_perms = $user->hasRight('paymentbybanktransfer', 'create');
  651. }
  652. // Add a transfer request
  653. if ($object->statut > $object::STATUS_DRAFT && $object->paye == 0 && $num == 0) {
  654. if ($resteapayer > 0) {
  655. if ($user_perms) {
  656. $remaintopaylesspendingdebit = $resteapayer - $pending;
  657. print '<form method="POST" action="">';
  658. print '<input type="hidden" name="token" value="'.newToken().'" />';
  659. print '<input type="hidden" name="id" value="'.$object->id.'" />';
  660. print '<input type="hidden" name="type" value="'.$type.'" />';
  661. print '<input type="hidden" name="action" value="new" />';
  662. print '<label for="withdraw_request_amount">'.$langs->trans('BankTransferAmount').' </label>';
  663. print '<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="'.$remaintopaylesspendingdebit.'" size="9" />';
  664. print '<input type="submit" class="butAction" value="'.$buttonlabel.'" />';
  665. print '</form>';
  666. if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT_SHOW_OLD_BUTTON')) { // This is hidden, prefer to use mode enabled with STRIPE_SEPA_DIRECT_DEBIT
  667. // TODO Replace this with a checkbox for each payment mode: "Send request to XXX immediatly..."
  668. print "<br>";
  669. //add stripe sepa button
  670. $buttonlabel = $langs->trans("MakeWithdrawRequestStripe");
  671. print '<form method="POST" action="">';
  672. print '<input type="hidden" name="token" value="'.newToken().'" />';
  673. print '<input type="hidden" name="id" value="'.$object->id.'" />';
  674. print '<input type="hidden" name="type" value="'.$type.'" />';
  675. print '<input type="hidden" name="action" value="new" />';
  676. print '<input type="hidden" name="paymenservice" value="stripesepa" />';
  677. print '<label for="withdraw_request_amount">'.$langs->trans('BankTransferAmount').' </label>';
  678. print '<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="'.$remaintopaylesspendingdebit.'" size="9" />';
  679. print '<input type="submit" class="butAction" value="'.$buttonlabel.'" />';
  680. print '</form>';
  681. }
  682. } else {
  683. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$buttonlabel.'</a>';
  684. }
  685. } else {
  686. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$buttonlabel.'</a>';
  687. }
  688. } else {
  689. if ($num == 0) {
  690. if ($object->statut > $object::STATUS_DRAFT) {
  691. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AlreadyPaid")).'">'.$buttonlabel.'</a>';
  692. } else {
  693. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("Draft")).'">'.$buttonlabel.'</a>';
  694. }
  695. } else {
  696. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("RequestAlreadyDone")).'">'.$buttonlabel.'</a>';
  697. }
  698. }
  699. print "</div>\n";
  700. if ($type == 'bank-transfer') {
  701. print '<div class="opacitymedium">'.$langs->trans("DoCreditTransferBeforePayments");
  702. if (isModEnabled('stripe') && getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
  703. print ' '.$langs->trans("DoStandingOrdersBeforePayments2");
  704. }
  705. print ' '.$langs->trans("DoStandingOrdersBeforePayments3");
  706. print '</div><br>';
  707. } else {
  708. print '<div class="opacitymedium">'.$langs->trans("DoStandingOrdersBeforePayments");
  709. if (isModEnabled('stripe') && getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
  710. print ' '.$langs->trans("DoStandingOrdersBeforePayments2");
  711. }
  712. print ' '.$langs->trans("DoStandingOrdersBeforePayments3");
  713. print '</div><br>';
  714. }
  715. /*
  716. * Withdrawals
  717. */
  718. print '<div class="div-table-responsive-no-min">';
  719. print '<table class="noborder centpercent">';
  720. print '<tr class="liste_titre">';
  721. // Action column
  722. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  723. print '<td>&nbsp;</td>';
  724. }
  725. print '<td class="left">'.$langs->trans("DateRequest").'</td>';
  726. print '<td>'.$langs->trans("User").'</td>';
  727. print '<td class="center">'.$langs->trans("Amount").'</td>';
  728. print '<td class="center">'.$langs->trans("DateProcess").'</td>';
  729. if ($type == 'bank-transfer') {
  730. print '<td class="center">'.$langs->trans("BankTransferReceipt").'</td>';
  731. } else {
  732. print '<td class="center">'.$langs->trans("WithdrawalReceipt").'</td>';
  733. }
  734. print '<td>&nbsp;</td>';
  735. // Action column
  736. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  737. print '<td>&nbsp;</td>';
  738. }
  739. print '</tr>';
  740. $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande,";
  741. $sql .= " pfd.date_traite as date_traite, pfd.amount, pfd.fk_prelevement_bons,";
  742. $sql .= " pb.ref, pb.date_trans, pb.method_trans, pb.credite, pb.date_credit, pb.datec, pb.statut as status, pb.amount as pb_amount,";
  743. $sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status";
  744. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
  745. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on pfd.fk_user_demande = u.rowid";
  746. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
  747. if ($type == 'bank-transfer') {
  748. $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
  749. } else {
  750. $sql .= " WHERE fk_facture = ".((int) $object->id);
  751. }
  752. $sql .= " AND pfd.traite = 0";
  753. $sql .= " AND pfd.type = 'ban'";
  754. $sql .= " ORDER BY pfd.date_demande DESC";
  755. $resql = $db->query($sql);
  756. $num = 0;
  757. if ($resql) {
  758. $i = 0;
  759. $tmpuser = new User($db);
  760. $num = $db->num_rows($result);
  761. while ($i < $num) {
  762. $obj = $db->fetch_object($resql);
  763. $tmpuser->id = $obj->user_id;
  764. $tmpuser->login = $obj->login;
  765. $tmpuser->ref = $obj->login;
  766. $tmpuser->email = $obj->email;
  767. $tmpuser->lastname = $obj->lastname;
  768. $tmpuser->firstname = $obj->firstname;
  769. $tmpuser->statut = $obj->user_status;
  770. $tmpuser->status = $obj->user_status;
  771. print '<tr class="oddeven">';
  772. // Action column
  773. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  774. print '<td class="center">';
  775. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'&did='.$obj->rowid.'&type='.urlencode($type).'">';
  776. print img_delete();
  777. print '</a>';
  778. print '</td>';
  779. }
  780. // Date
  781. print '<td class="nowraponall">'.dol_print_date($db->jdate($obj->date_demande), 'dayhour')."</td>\n";
  782. // User
  783. print '<td class="tdoverflowmax125">';
  784. print $tmpuser->getNomUrl(-1, '', 0, 0, 0, 0, 'login');
  785. print '</td>';
  786. // Amount
  787. print '<td class="center"><span class="amount">'.price($obj->amount).'</span></td>';
  788. // Date process
  789. print '<td class="center"><span class="opacitymedium">'.$langs->trans("OrderWaiting").'</span></td>';
  790. // Link to make payment now
  791. print '<td class="minwidth75">';
  792. if ($obj->fk_prelevement_bons > 0) {
  793. $withdrawreceipt = new BonPrelevement($db);
  794. $withdrawreceipt->id = $obj->fk_prelevement_bons;
  795. $withdrawreceipt->ref = $obj->ref;
  796. $withdrawreceipt->date_trans = $db->jdate($obj->date_trans);
  797. $withdrawreceipt->date_credit = $db->jdate($obj->date_credit);
  798. $withdrawreceipt->date_creation = $db->jdate($obj->datec);
  799. $withdrawreceipt->statut = $obj->status;
  800. $withdrawreceipt->status = $obj->status;
  801. $withdrawreceipt->amount = $obj->pb_amount;
  802. //$withdrawreceipt->credite = $db->jdate($obj->credite);
  803. print $withdrawreceipt->getNomUrl(1);
  804. }
  805. if ($type != 'bank-transfer') {
  806. if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
  807. $langs->load("stripe");
  808. if ($obj->fk_prelevement_bons > 0) {
  809. print ' &nbsp; ';
  810. }
  811. print '<a href="'.$_SERVER["PHP_SELF"].'?action=sepastripedirectdebit&paymentservice=stripesepa&token='.newToken().'&did='.$obj->rowid.'&id='.$object->id.'&type='.urlencode($type).'">'.img_picto('', 'stripe', 'class="pictofixedwidth"').$langs->trans("RequestDirectDebitWithStripe").'</a>';
  812. }
  813. } else {
  814. if (getDolGlobalString('STRIPE_SEPA_CREDIT_TRANSFER')) {
  815. $langs->load("stripe");
  816. if ($obj->fk_prelevement_bons > 0) {
  817. print ' &nbsp; ';
  818. }
  819. print '<a href="'.$_SERVER["PHP_SELF"].'?action=sepastripecredittransfer&paymentservice=stripesepa&token='.newToken().'&did='.$obj->rowid.'&id='.$object->id.'&type='.urlencode($type).'">'.img_picto('', 'stripe', 'class="pictofixedwidth"').$langs->trans("RequestDirectDebitWithStripe").'</a>';
  820. }
  821. }
  822. print '</td>';
  823. //
  824. print '<td class="center">-</td>';
  825. // Action column
  826. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  827. print '<td class="center">';
  828. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'&did='.$obj->rowid.'&type='.urlencode($type).'">';
  829. print img_delete();
  830. print '</a></td>';
  831. }
  832. print "</tr>\n";
  833. $i++;
  834. }
  835. $db->free($resql);
  836. } else {
  837. dol_print_error($db);
  838. }
  839. // Past requests
  840. $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande, pfd.date_traite, pfd.fk_prelevement_bons, pfd.amount,";
  841. $sql .= " pb.ref, pb.date_trans, pb.method_trans, pb.credite, pb.date_credit, pb.datec, pb.statut as status, pb.fk_bank_account, pb.amount as pb_amount,";
  842. $sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo as user_photo";
  843. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
  844. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on pfd.fk_user_demande = u.rowid";
  845. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
  846. if ($type == 'bank-transfer') {
  847. $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
  848. } else {
  849. $sql .= " WHERE fk_facture = ".((int) $object->id);
  850. }
  851. $sql .= " AND pfd.traite = 1";
  852. $sql .= " AND pfd.type = 'ban'";
  853. $sql .= " ORDER BY pfd.date_demande DESC";
  854. $resql = $db->query($sql);
  855. if ($resql) {
  856. $num = $db->num_rows($resql);
  857. $numclosed = $num;
  858. $i = 0;
  859. $tmpuser = new User($db);
  860. while ($i < $num) {
  861. $obj = $db->fetch_object($resql);
  862. $tmpuser->id = $obj->user_id;
  863. $tmpuser->login = $obj->login;
  864. $tmpuser->ref = $obj->login;
  865. $tmpuser->email = $obj->email;
  866. $tmpuser->lastname = $obj->lastname;
  867. $tmpuser->firstname = $obj->firstname;
  868. $tmpuser->statut = $obj->user_status;
  869. $tmpuser->status = $obj->user_status;
  870. $tmpuser->photo = $obj->user_photo;
  871. print '<tr class="oddeven">';
  872. // Action column
  873. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  874. print '<td>&nbsp;</td>';
  875. }
  876. // Date
  877. print '<td class="nowraponall">'.dol_print_date($db->jdate($obj->date_demande), 'day')."</td>\n";
  878. // User
  879. print '<td class="tdoverflowmax125">';
  880. print $tmpuser->getNomUrl(-1, '', 0, 0, 0, 0, 'login');
  881. print '</td>';
  882. // Amount
  883. print '<td class="center"><span class="amount">'.price($obj->amount).'</span></td>';
  884. // Date process
  885. print '<td class="center nowraponall">'.dol_print_date($db->jdate($obj->date_traite), 'dayhour', 'tzuserrel')."</td>\n";
  886. // Link to payment request done
  887. print '<td class="center minwidth75">';
  888. if ($obj->fk_prelevement_bons > 0) {
  889. $withdrawreceipt = new BonPrelevement($db);
  890. $withdrawreceipt->id = $obj->fk_prelevement_bons;
  891. $withdrawreceipt->ref = $obj->ref;
  892. $withdrawreceipt->date_trans = $db->jdate($obj->date_trans);
  893. $withdrawreceipt->date_credit = $db->jdate($obj->date_credit);
  894. $withdrawreceipt->date_creation = $db->jdate($obj->datec);
  895. $withdrawreceipt->statut = $obj->status;
  896. $withdrawreceipt->status = $obj->status;
  897. $withdrawreceipt->fk_bank_account = $obj->fk_bank_account;
  898. $withdrawreceipt->amount = $obj->pb_amount;
  899. //$withdrawreceipt->credite = $db->jdate($obj->credite);
  900. print $withdrawreceipt->getNomUrl(1);
  901. print ' ';
  902. print $withdrawreceipt->getLibStatut(2);
  903. // Show the bank account
  904. $fk_bank_account = $withdrawreceipt->fk_bank_account;
  905. if (empty($fk_bank_account)) {
  906. $fk_bank_account = ($object->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
  907. }
  908. if ($fk_bank_account > 0) {
  909. $bankaccount = new Account($db);
  910. $result = $bankaccount->fetch($fk_bank_account);
  911. if ($result > 0) {
  912. print ' - ';
  913. print $bankaccount->getNomUrl(1);
  914. }
  915. }
  916. }
  917. print "</td>\n";
  918. //
  919. print '<td>&nbsp;</td>';
  920. // Action column
  921. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  922. print '<td>&nbsp;</td>';
  923. }
  924. print "</tr>\n";
  925. $i++;
  926. }
  927. if (!$numopen && !$numclosed) {
  928. print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  929. }
  930. $db->free($resql);
  931. } else {
  932. dol_print_error($db);
  933. }
  934. print "</table>";
  935. print '</div>';
  936. }
  937. // End of page
  938. llxFooter();
  939. $db->close();