paymentmodes.php 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144
  1. <?php
  2. /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
  7. * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
  8. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  9. * Copyright (C) 2018-2023 Thibault FOUCART <support@ptibogxiv.net>
  10. * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/societe/paymentmodes.php
  27. * \ingroup societe
  28. * \brief Tab of payment modes for the customer
  29. */
  30. // Load Dolibarr environment
  31. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/societe/class/companypaymentmode.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
  41. // Load translation files required by the page
  42. $langs->loadLangs(array("companies", "commercial", "banks", "bills", 'paypal', 'stripe', 'withdrawals'));
  43. // Security check
  44. $socid = GETPOST("socid", "int");
  45. if ($user->socid) {
  46. $socid = $user->socid;
  47. }
  48. $result = restrictedArea($user, 'societe', '', '');
  49. // Get parameters
  50. $id = GETPOST("id", "int");
  51. $source = GETPOST("source", "alpha"); // source can be a source or a paymentmode
  52. $ribid = GETPOST("ribid", "int");
  53. $action = GETPOST("action", 'alpha', 3);
  54. $cancel = GETPOST('cancel', 'alpha');
  55. // Initialize objects
  56. $object = new Societe($db);
  57. $object->fetch($socid);
  58. $companybankaccount = new CompanyBankAccount($db);
  59. $companypaymentmode = new CompanyPaymentMode($db);
  60. $prelevement = new BonPrelevement($db);
  61. $extrafields = new ExtraFields($db);
  62. // fetch optionals attributes and labels
  63. $extrafields->fetch_name_optionals_label($object->table_element);
  64. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  65. $hookmanager->initHooks(array('thirdpartybancard', 'globalcard'));
  66. // Permissions
  67. $permissiontoread = $user->hasRight('societe', 'lire');
  68. $permissiontoadd = $user->hasRight('societe', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_builddoc.inc.php
  69. $permissiontoaddupdatepaymentinformation = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $permissiontoadd) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->societe->thirdparty_paymentinformation_advance->write)));
  70. if (isModEnabled('stripe')) {
  71. $service = 'StripeTest';
  72. $servicestatus = 0;
  73. if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) {
  74. $service = 'StripeLive';
  75. $servicestatus = 1;
  76. }
  77. // Force to use the correct API key
  78. global $stripearrayofkeysbyenv;
  79. $site_account = $stripearrayofkeysbyenv[$servicestatus]['publishable_key'];
  80. $stripe = new Stripe($db);
  81. $stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account (no remote access to Stripe here)
  82. $stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus, $site_account); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here)
  83. }
  84. /*
  85. * Actions
  86. */
  87. if ($cancel) {
  88. $action = '';
  89. }
  90. $morehtmlright = '';
  91. $parameters = array('id'=>$socid);
  92. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  93. if ($reshook < 0) {
  94. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  95. }
  96. if (empty($reshook)) {
  97. if ($cancel) {
  98. $action = '';
  99. if (!empty($backtopage)) {
  100. header("Location: ".$backtopage);
  101. exit;
  102. }
  103. }
  104. if ($action == 'update') {
  105. // Modification
  106. if (!GETPOST('label', 'alpha') || !GETPOST('bank', 'alpha')) {
  107. if (!GETPOST('label', 'alpha')) {
  108. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
  109. }
  110. if (!GETPOST('bank', 'alpha')) {
  111. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors');
  112. }
  113. $action = 'edit';
  114. $error++;
  115. }
  116. $companybankaccount->fetch($id);
  117. if ($companybankaccount->needIBAN() == 1) {
  118. if (!GETPOST('iban')) {
  119. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("IBAN")), null, 'errors');
  120. $action = 'edit';
  121. $error++;
  122. }
  123. if (!GETPOST('bic')) {
  124. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BIC")), null, 'errors');
  125. $action = 'edit';
  126. $error++;
  127. }
  128. }
  129. if (!$error) {
  130. $companybankaccount->socid = $object->id;
  131. $companybankaccount->bank = GETPOST('bank', 'alpha');
  132. $companybankaccount->label = GETPOST('label', 'alpha');
  133. $companybankaccount->courant = GETPOST('courant', 'alpha');
  134. $companybankaccount->clos = GETPOST('clos', 'alpha');
  135. $companybankaccount->code_banque = GETPOST('code_banque', 'alpha');
  136. $companybankaccount->code_guichet = GETPOST('code_guichet', 'alpha');
  137. $companybankaccount->number = GETPOST('number', 'alpha');
  138. $companybankaccount->cle_rib = GETPOST('cle_rib', 'alpha');
  139. $companybankaccount->bic = GETPOST('bic', 'alpha');
  140. $companybankaccount->iban = GETPOST('iban', 'alpha');
  141. $companybankaccount->domiciliation = GETPOST('domiciliation', 'alpha');
  142. $companybankaccount->proprio = GETPOST('proprio', 'alpha');
  143. $companybankaccount->owner_address = GETPOST('owner_address', 'alpha');
  144. $companybankaccount->frstrecur = GETPOST('frstrecur', 'alpha');
  145. $companybankaccount->rum = GETPOST('rum', 'alpha');
  146. $companybankaccount->date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth'), GETPOST('date_rumday'), GETPOST('date_rumyear'));
  147. if (empty($companybankaccount->rum)) {
  148. $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
  149. }
  150. if (GETPOST('stripe_card_ref', 'alpha') && GETPOST('stripe_card_ref', 'alpha') != $companypaymentmode->stripe_card_ref) {
  151. // If we set a stripe value that is different than previous one, we also set the stripe account
  152. $companypaymentmode->stripe_account = $stripecu.'@'.$site_account;
  153. }
  154. $companybankaccount->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha');
  155. $result = $companybankaccount->update($user);
  156. if ($result <= 0) {
  157. // Display error message and get back to edit mode
  158. setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
  159. $action = 'edit';
  160. } else {
  161. // If this account is the default bank account, we disable others
  162. if ($companybankaccount->default_rib) {
  163. $companybankaccount->setAsDefault($id); // This will make sure there is only one default rib
  164. }
  165. $url = $_SERVER["PHP_SELF"].'?socid='.$object->id;
  166. header('Location: '.$url);
  167. exit;
  168. }
  169. }
  170. }
  171. if ($action == 'updatecard') {
  172. // Modification
  173. if (!GETPOST('label', 'alpha') || !GETPOST('proprio', 'alpha') || !GETPOST('exp_date_month', 'alpha') || !GETPOST('exp_date_year', 'alpha')) {
  174. if (!GETPOST('label', 'alpha')) {
  175. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
  176. }
  177. if (!GETPOST('proprio', 'alpha')) {
  178. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors');
  179. }
  180. //if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors');
  181. if (!(GETPOST('exp_date_month', 'alpha') > 0) || !(GETPOST('exp_date_year', 'alpha') > 0)) {
  182. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors');
  183. }
  184. //if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors');
  185. $action = 'createcard';
  186. $error++;
  187. }
  188. $companypaymentmode->fetch($id);
  189. if (!$error) {
  190. $companypaymentmode->fk_soc = $object->id;
  191. $companypaymentmode->bank = GETPOST('bank', 'alpha');
  192. $companypaymentmode->label = GETPOST('label', 'alpha');
  193. $companypaymentmode->number = GETPOST('cardnumber', 'alpha');
  194. $companypaymentmode->last_four = substr(GETPOST('cardnumber', 'alpha'), -4);
  195. $companypaymentmode->proprio = GETPOST('proprio', 'alpha');
  196. $companypaymentmode->exp_date_month = GETPOST('exp_date_month', 'int');
  197. $companypaymentmode->exp_date_year = GETPOST('exp_date_year', 'int');
  198. $companypaymentmode->cvn = GETPOST('cvn', 'alpha');
  199. $companypaymentmode->country_code = $object->country_code;
  200. if (GETPOST('stripe_card_ref', 'alpha') && GETPOST('stripe_card_ref', 'alpha') != $companypaymentmode->stripe_card_ref) {
  201. // If we set a stripe value that is different than previous one, we also set the stripe account
  202. $companypaymentmode->stripe_account = $stripecu.'@'.$site_account;
  203. }
  204. $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha');
  205. $result = $companypaymentmode->update($user);
  206. if (!$result) {
  207. setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
  208. } else {
  209. // If this account is the default bank account, we disable others
  210. if ($companypaymentmode->default_rib) {
  211. $companypaymentmode->setAsDefault($id); // This will make sure there is only one default rib
  212. }
  213. $url = $_SERVER["PHP_SELF"].'?socid='.$object->id;
  214. header('Location: '.$url);
  215. exit;
  216. }
  217. }
  218. }
  219. if ($action == 'add') {
  220. $error = 0;
  221. if (!GETPOST('label', 'alpha') || !GETPOST('bank', 'alpha')) {
  222. if (!GETPOST('label', 'alpha')) {
  223. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
  224. }
  225. if (!GETPOST('bank', 'alpha')) {
  226. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors');
  227. }
  228. $action = 'create';
  229. $error++;
  230. }
  231. if (!$error) {
  232. // Ajout
  233. $companybankaccount = new CompanyBankAccount($db);
  234. $companybankaccount->socid = $object->id;
  235. $companybankaccount->bank = GETPOST('bank', 'alpha');
  236. $companybankaccount->label = GETPOST('label', 'alpha');
  237. $companybankaccount->courant = GETPOST('courant', 'alpha');
  238. $companybankaccount->clos = GETPOST('clos', 'alpha');
  239. $companybankaccount->code_banque = GETPOST('code_banque', 'alpha');
  240. $companybankaccount->code_guichet = GETPOST('code_guichet', 'alpha');
  241. $companybankaccount->number = GETPOST('number', 'alpha');
  242. $companybankaccount->cle_rib = GETPOST('cle_rib', 'alpha');
  243. $companybankaccount->bic = GETPOST('bic', 'alpha');
  244. $companybankaccount->iban = GETPOST('iban', 'alpha');
  245. $companybankaccount->domiciliation = GETPOST('domiciliation', 'alpha');
  246. $companybankaccount->proprio = GETPOST('proprio', 'alpha');
  247. $companybankaccount->owner_address = GETPOST('owner_address', 'alpha');
  248. $companybankaccount->frstrecur = GETPOST('frstrecur', 'alpha');
  249. $companybankaccount->rum = GETPOST('rum', 'alpha');
  250. $companybankaccount->date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth', 'int'), GETPOST('date_rumday', 'int'), GETPOST('date_rumyear', 'int'));
  251. $companybankaccount->datec = dol_now();
  252. $companybankaccount->status = 1;
  253. $db->begin();
  254. // This test can be done only once properties were set
  255. if ($companybankaccount->needIBAN() == 1) {
  256. if (!GETPOST('iban')) {
  257. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("IBAN")), null, 'errors');
  258. $action = 'create';
  259. $error++;
  260. }
  261. if (!GETPOST('bic')) {
  262. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BIC")), null, 'errors');
  263. $action = 'create';
  264. $error++;
  265. }
  266. }
  267. if (!$error) {
  268. $result = $companybankaccount->create($user);
  269. if ($result < 0) {
  270. $error++;
  271. setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
  272. $action = 'create'; // Force chargement page création
  273. }
  274. if (empty($companybankaccount->rum)) {
  275. $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
  276. }
  277. }
  278. if (!$error) {
  279. $result = $companybankaccount->update($user); // This will set the UMR number.
  280. if ($result < 0) {
  281. $error++;
  282. setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
  283. $action = 'create';
  284. }
  285. }
  286. if (!$error) {
  287. $db->commit();
  288. $url = $_SERVER["PHP_SELF"].'?socid='.$object->id;
  289. header('Location: '.$url);
  290. exit;
  291. } else {
  292. $db->rollback();
  293. }
  294. }
  295. }
  296. if ($action == 'addcard') {
  297. $error = 0;
  298. if (!GETPOST('label', 'alpha') || !GETPOST('proprio', 'alpha') || !GETPOST('exp_date_month', 'alpha') || !GETPOST('exp_date_year', 'alpha')) {
  299. if (!GETPOST('label', 'alpha')) {
  300. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
  301. }
  302. if (!GETPOST('proprio', 'alpha')) {
  303. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors');
  304. }
  305. //if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors');
  306. if (!(GETPOST('exp_date_month', 'alpha') > 0) || !(GETPOST('exp_date_year', 'alpha') > 0)) {
  307. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors');
  308. }
  309. //if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors');
  310. $action = 'createcard';
  311. $error++;
  312. }
  313. if (!$error) {
  314. // Ajout
  315. $companypaymentmode = new CompanyPaymentMode($db);
  316. $companypaymentmode->fk_soc = $object->id;
  317. $companypaymentmode->bank = GETPOST('bank', 'alpha');
  318. $companypaymentmode->label = GETPOST('label', 'alpha');
  319. $companypaymentmode->number = GETPOST('cardnumber', 'alpha');
  320. $companypaymentmode->last_four = substr(GETPOST('cardnumber', 'alpha'), -4);
  321. $companypaymentmode->proprio = GETPOST('proprio', 'alpha');
  322. $companypaymentmode->exp_date_month = GETPOST('exp_date_month', 'int');
  323. $companypaymentmode->exp_date_year = GETPOST('exp_date_year', 'int');
  324. $companypaymentmode->cvn = GETPOST('cvn', 'alpha');
  325. $companypaymentmode->datec = dol_now();
  326. $companypaymentmode->default_rib = 0;
  327. $companypaymentmode->type = 'card';
  328. $companypaymentmode->country_code = $object->country_code;
  329. $companypaymentmode->status = $servicestatus;
  330. if (GETPOST('stripe_card_ref', 'alpha')) {
  331. // If we set a stripe value, we also set the stripe account
  332. $companypaymentmode->stripe_account = $stripecu.'@'.$site_account;
  333. }
  334. $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha');
  335. $db->begin();
  336. if (!$error) {
  337. $result = $companypaymentmode->create($user);
  338. if ($result < 0) {
  339. $error++;
  340. setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
  341. $action = 'createcard'; // Force chargement page création
  342. }
  343. }
  344. if (!$error) {
  345. $db->commit();
  346. $url = $_SERVER["PHP_SELF"].'?socid='.$object->id;
  347. header('Location: '.$url);
  348. exit;
  349. } else {
  350. $db->rollback();
  351. }
  352. }
  353. }
  354. if ($action == 'setasbankdefault' && GETPOST('ribid', 'int') > 0) {
  355. $companybankaccount = new CompanyBankAccount($db);
  356. $res = $companybankaccount->setAsDefault(GETPOST('ribid', 'int'));
  357. if ($res) {
  358. $url = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
  359. header('Location: '.$url);
  360. exit;
  361. } else {
  362. setEventMessages($db->lasterror, null, 'errors');
  363. }
  364. }
  365. if ($action == 'confirm_deletecard' && GETPOST('confirm', 'alpha') == 'yes') {
  366. $companypaymentmode = new CompanyPaymentMode($db);
  367. if ($companypaymentmode->fetch($ribid ? $ribid : $id)) {
  368. // TODO This is currently done at bottom of page instead of asking confirm
  369. /*if ($companypaymentmode->stripe_card_ref && preg_match('/pm_/', $companypaymentmode->stripe_card_ref))
  370. {
  371. $payment_method = \Stripe\PaymentMethod::retrieve($companypaymentmode->stripe_card_ref);
  372. if ($payment_method)
  373. {
  374. $payment_method->detach();
  375. }
  376. }*/
  377. $result = $companypaymentmode->delete($user);
  378. if ($result > 0) {
  379. $url = $_SERVER['PHP_SELF']."?socid=".$object->id;
  380. header('Location: '.$url);
  381. exit;
  382. } else {
  383. setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
  384. }
  385. } else {
  386. setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
  387. }
  388. }
  389. if ($action == 'confirm_delete' && GETPOST('confirm', 'alpha') == 'yes') {
  390. $companybankaccount = new CompanyBankAccount($db);
  391. if ($companybankaccount->fetch($ribid ? $ribid : $id)) {
  392. // TODO This is currently done at bottom of page instead of asking confirm
  393. /*if ($companypaymentmode->stripe_card_ref && preg_match('/pm_/', $companypaymentmode->stripe_card_ref))
  394. {
  395. $payment_method = \Stripe\PaymentMethod::retrieve($companypaymentmode->stripe_card_ref);
  396. if ($payment_method)
  397. {
  398. $payment_method->detach();
  399. }
  400. }*/
  401. $result = $companybankaccount->delete($user);
  402. if ($result > 0) {
  403. $url = $_SERVER['PHP_SELF']."?socid=".$object->id;
  404. header('Location: '.$url);
  405. exit;
  406. } else {
  407. setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
  408. }
  409. } else {
  410. setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
  411. }
  412. }
  413. $savid = $id;
  414. // Actions to build doc
  415. if ($action == 'builddocrib') {
  416. $action = 'builddoc';
  417. $moreparams = array(
  418. 'use_companybankid'=>GETPOST('companybankid'),
  419. 'force_dir_output'=>$conf->societe->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->id)
  420. );
  421. $_POST['lang_id'] = GETPOST('lang_idrib'.GETPOST('companybankid', 'int'), 'alpha');
  422. $_POST['model'] = GETPOST('modelrib'.GETPOST('companybankid', 'int'), 'alpha');
  423. }
  424. $id = $socid;
  425. $upload_dir = $conf->societe->multidir_output[$object->entity];
  426. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  427. $id = $savid;
  428. // Action for stripe
  429. if (isModEnabled('stripe') && class_exists('Stripe')) {
  430. if ($action == 'synccustomertostripe') {
  431. if ($object->client == 0) {
  432. $error++;
  433. setEventMessages('ThisThirdpartyIsNotACustomer', null, 'errors');
  434. } else {
  435. // Creation of Stripe customer + update of societe_account
  436. $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus, 1);
  437. if (!$cu) {
  438. $error++;
  439. setEventMessages($stripe->error, $stripe->errors, 'errors');
  440. } else {
  441. $stripecu = $cu->id;
  442. }
  443. }
  444. }
  445. if ($action == 'synccardtostripe') {
  446. $companypaymentmode = new CompanyPaymentMode($db);
  447. $companypaymentmode->fetch($id);
  448. if ($companypaymentmode->type != 'card') {
  449. $error++;
  450. setEventMessages('ThisPaymentModeIsNotACard', null, 'errors');
  451. } else {
  452. // Get the Stripe customer
  453. $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
  454. if (!$cu) {
  455. $error++;
  456. setEventMessages($stripe->error, $stripe->errors, 'errors');
  457. }
  458. if (!$error) {
  459. // Creation of Stripe card + update of llx_societe_rib
  460. // Note that with the new Stripe API, option to create a card is no more available, instead an error message will be returned to
  461. // ask to create the crdit card from Stripe backoffice.
  462. $card = $stripe->cardStripe($cu, $companypaymentmode, $stripeacc, $servicestatus, 1);
  463. if (!$card) {
  464. $error++;
  465. setEventMessages($stripe->error, $stripe->errors, 'errors');
  466. }
  467. }
  468. }
  469. }
  470. if ($action == 'syncsepatostripe') {
  471. $companypaymentmode = new CompanyPaymentMode($db); // Get record in llx_societe_rib
  472. $companypaymentmode->fetch($id);
  473. if ($companypaymentmode->type != 'ban') {
  474. $error++;
  475. $langs->load("errors");
  476. setEventMessages('ThisPaymentModeIsNotABan', null, 'errors');
  477. } else {
  478. // Get the Stripe customer
  479. $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
  480. // print json_encode($cu);
  481. if (empty($cu)) {
  482. $error++;
  483. $langs->load("errors");
  484. setEventMessages($langs->trans("ErrorStripeCustomerNotFoundCreateFirst"), null, 'errors');
  485. }
  486. if (!$error) {
  487. // Creation of Stripe SEPA + update of llx_societe_rib
  488. $card = $stripe->sepaStripe($cu, $companypaymentmode, $stripeacc, $servicestatus, 1);
  489. if (!$card) {
  490. $error++;
  491. setEventMessages($stripe->error, $stripe->errors, 'errors');
  492. } else {
  493. setEventMessages("", array("Bank Account on Stripe", "BAN is now linked to the Stripe customer account !"));
  494. }
  495. }
  496. }
  497. }
  498. if ($action == 'setkey_account') {
  499. $error = 0;
  500. $newcu = GETPOST('key_account', 'alpha');
  501. $db->begin();
  502. if (empty($newcu)) {
  503. $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_account WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '".$db->escape($site_account)."') AND fk_soc = ".$object->id." AND status = ".((int) $servicestatus)." AND entity = ".$conf->entity;
  504. } else {
  505. $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX."societe_account";
  506. $sql .= " WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '".$db->escape($site_account)."') AND fk_soc = ".((int) $object->id)." AND status = ".((int) $servicestatus)." AND entity = ".$conf->entity; // Keep = here for entity. Only 1 record must be modified !
  507. }
  508. $resql = $db->query($sql);
  509. $num = $db->num_rows($resql); // Note: $num is always 0 on an update and delete, it is defined for select only.
  510. if (!empty($newcu)) {
  511. if (empty($num)) {
  512. $societeaccount = new SocieteAccount($db);
  513. $societeaccount->fk_soc = $object->id;
  514. $societeaccount->login = '';
  515. $societeaccount->pass_encoding = '';
  516. $societeaccount->site = 'stripe';
  517. $societeaccount->status = $servicestatus;
  518. $societeaccount->key_account = $newcu;
  519. $societeaccount->site_account = $site_account;
  520. $result = $societeaccount->create($user);
  521. if ($result < 0) {
  522. $error++;
  523. }
  524. } else {
  525. $sql = 'UPDATE '.MAIN_DB_PREFIX."societe_account";
  526. $sql .= " SET key_account = '".$db->escape(GETPOST('key_account', 'alpha'))."', site_account = '".$db->escape($site_account)."'";
  527. $sql .= " WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '".$db->escape($site_account)."') AND fk_soc = ".((int) $object->id)." AND status = ".((int) $servicestatus)." AND entity = ".$conf->entity; // Keep = here for entity. Only 1 record must be modified !
  528. $resql = $db->query($sql);
  529. }
  530. }
  531. //var_dump($sql);
  532. //var_dump($newcu);
  533. //var_dump($num); exit;
  534. if (!$error) {
  535. $stripecu = $newcu;
  536. $db->commit();
  537. } else {
  538. $db->rollback();
  539. }
  540. }
  541. if ($action == 'setkey_account_supplier') {
  542. $error = 0;
  543. $newsup = GETPOST('key_account_supplier', 'alpha');
  544. $db->begin();
  545. if (empty($newsup)) {
  546. $sql = "DELETE FROM ".MAIN_DB_PREFIX."oauth_token WHERE fk_soc = ".$object->id." AND service = '".$db->escape($service)."' AND entity = ".$conf->entity;
  547. // TODO Add site and site_account on oauth_token table
  548. //$sql = "DELETE FROM ".MAIN_DB_PREFIX."oauth_token WHERE site = 'stripe' AND (site_account IS NULL or site_account = '".$db->escape($site_account)."') AND fk_soc = ".((int) $object->id)." AND service = '".$db->escape($service)."' AND entity = ".$conf->entity;
  549. } else {
  550. try {
  551. $stripesup = \Stripe\Account::retrieve($db->escape(GETPOST('key_account_supplier', 'alpha')));
  552. $tokenstring['stripe_user_id'] = $stripesup->id;
  553. $tokenstring['type'] = $stripesup->type;
  554. $sql = "UPDATE ".MAIN_DB_PREFIX."oauth_token";
  555. $sql .= " SET tokenstring = '".$db->escape(json_encode($tokenstring))."'";
  556. $sql .= " WHERE site = 'stripe' AND (site_account IS NULL or site_account = '".$db->escape($site_account)."') AND fk_soc = ".((int) $object->id)." AND service = '".$db->escape($service)."' AND entity = ".$conf->entity; // Keep = here for entity. Only 1 record must be modified !
  557. // TODO Add site and site_account on oauth_token table
  558. $sql .= " WHERE fk_soc = ".$object->id." AND service = '".$db->escape($service)."' AND entity = ".$conf->entity; // Keep = here for entity. Only 1 record must be modified !
  559. } catch (Exception $e) {
  560. $error++;
  561. setEventMessages($e->getMessage(), null, 'errors');
  562. }
  563. }
  564. $resql = $db->query($sql);
  565. $num = $db->num_rows($resql);
  566. if (empty($num) && !empty($newsup)) {
  567. try {
  568. $stripesup = \Stripe\Account::retrieve($db->escape(GETPOST('key_account_supplier', 'alpha')));
  569. $tokenstring['stripe_user_id'] = $stripesup->id;
  570. $tokenstring['type'] = $stripesup->type;
  571. $sql = "INSERT INTO ".MAIN_DB_PREFIX."oauth_token (service, fk_soc, entity, tokenstring)";
  572. $sql .= " VALUES ('".$db->escape($service)."', ".((int) $object->id).", ".((int) $conf->entity).", '".$db->escape(json_encode($tokenstring))."')";
  573. // TODO Add site and site_account on oauth_token table
  574. } catch (Exception $e) {
  575. $error++;
  576. setEventMessages($e->getMessage(), null, 'errors');
  577. }
  578. $resql = $db->query($sql);
  579. }
  580. if (!$error) {
  581. $stripesupplieracc = $newsup;
  582. $db->commit();
  583. } else {
  584. $db->rollback();
  585. }
  586. }
  587. if ($action == 'setlocalassourcedefault') { // Set as default when payment mode defined locally (and may be also remotely)
  588. try {
  589. $companypaymentmode->setAsDefault($id);
  590. $url = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
  591. header('Location: '.$url);
  592. exit;
  593. } catch (Exception $e) {
  594. $error++;
  595. setEventMessages($e->getMessage(), null, 'errors');
  596. }
  597. } elseif ($action == 'setassourcedefault') { // Set as default when payment mode defined remotely only
  598. try {
  599. $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
  600. if (preg_match('/pm_|src_/', $source)) {
  601. $cu->invoice_settings->default_payment_method = (string) $source; // New
  602. } else {
  603. $cu->default_source = (string) $source; // Old
  604. }
  605. $result = $cu->save();
  606. $url = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
  607. header('Location: '.$url);
  608. exit;
  609. } catch (Exception $e) {
  610. $error++;
  611. setEventMessages($e->getMessage(), null, 'errors');
  612. }
  613. } elseif ($action == 'deletecard' && $source) {
  614. try {
  615. if (preg_match('/pm_/', $source)) {
  616. $payment_method = \Stripe\PaymentMethod::retrieve($source, array("stripe_account" => $stripeacc));
  617. if ($payment_method) {
  618. $payment_method->detach();
  619. }
  620. } else {
  621. $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
  622. $card = $cu->sources->retrieve("$source");
  623. if ($card) {
  624. // $card->detach(); Does not work with card_, only with src_
  625. if (method_exists($card, 'detach')) {
  626. $card->detach();
  627. $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib as sr ";
  628. $sql .= " SET stripe_card_ref = null";
  629. $sql .= " WHERE sr.stripe_card_ref = '".$db->escape($source)."'";
  630. $resql = $db->query($sql);
  631. } else {
  632. $card->delete();
  633. }
  634. }
  635. }
  636. $url = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
  637. header('Location: '.$url);
  638. exit;
  639. } catch (Exception $e) {
  640. $error++;
  641. setEventMessages($e->getMessage(), null, 'errors');
  642. }
  643. } elseif ($action == 'delete' && $source) {
  644. try {
  645. if (preg_match('/pm_/', $source)) {
  646. $payment_method = \Stripe\PaymentMethod::retrieve($source, array("stripe_account" => $stripeacc));
  647. if ($payment_method) {
  648. $payment_method->detach();
  649. }
  650. } else {
  651. $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
  652. $card = $cu->sources->retrieve("$source");
  653. if ($card) {
  654. // $card->detach(); Does not work with card_, only with src_
  655. if (method_exists($card, 'detach')) {
  656. $card->detach();
  657. $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib as sr ";
  658. $sql .= " SET stripe_card_ref = null";
  659. $sql .= " WHERE sr.stripe_card_ref = '".$db->escape($source)."'";
  660. $resql = $db->query($sql);
  661. } else {
  662. $card->delete();
  663. }
  664. }
  665. }
  666. $url = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
  667. header('Location: '.$url);
  668. exit;
  669. } catch (Exception $e) {
  670. $error++;
  671. setEventMessages($e->getMessage(), null, 'errors');
  672. }
  673. }
  674. }
  675. }
  676. /*
  677. * View
  678. */
  679. $form = new Form($db);
  680. $formother = new FormOther($db);
  681. $formfile = new FormFile($db);
  682. $title = $langs->trans("ThirdParty");
  683. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  684. $title = $object->name." - ".$langs->trans('PaymentInformation');
  685. }
  686. $help_url = '';
  687. llxHeader('', $title, $help_url);
  688. $head = societe_prepare_head($object);
  689. // Show sandbox warning
  690. /*if (isModEnabled('paypal') && (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))) // We can force sand box with param 'forcesandbox'
  691. {
  692. dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Paypal'),'','warning');
  693. }*/
  694. if (isModEnabled('stripe') && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) {
  695. dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
  696. }
  697. // Load Bank account
  698. if (!$id) {
  699. $companybankaccount->fetch(0, $object->id);
  700. $companypaymentmode->fetch(0, null, $object->id, 'card');
  701. } else {
  702. $companybankaccount->fetch($id);
  703. $companypaymentmode->fetch($id);
  704. }
  705. if (empty($companybankaccount->socid)) {
  706. $companybankaccount->socid = $object->id;
  707. }
  708. if ($socid && ($action == 'edit' || $action == 'editcard') && $permissiontoaddupdatepaymentinformation) {
  709. print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post">';
  710. print '<input type="hidden" name="token" value="'.newToken().'">';
  711. $actionforadd = 'update';
  712. if ($action == 'editcard') {
  713. $actionforadd = 'updatecard';
  714. }
  715. print '<input type="hidden" name="action" value="'.$actionforadd.'">';
  716. print '<input type="hidden" name="id" value="'.GETPOST("id", "int").'">';
  717. }
  718. if ($socid && ($action == 'create' || $action == 'createcard') && $permissiontoaddupdatepaymentinformation) {
  719. print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post">';
  720. print '<input type="hidden" name="token" value="'.newToken().'">';
  721. $actionforadd = 'add';
  722. if ($action == 'createcard') {
  723. $actionforadd = 'addcard';
  724. }
  725. print '<input type="hidden" name="action" value="'.$actionforadd.'">';
  726. }
  727. // View
  728. if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' && $action != 'createcard') {
  729. print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company');
  730. // Confirm delete ban
  731. if ($action == 'delete') {
  732. print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid ? $ribid : $id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $companybankaccount->getRibLabel()), "confirm_delete", '', 0, 1);
  733. }
  734. // Confirm delete card
  735. if ($action == 'deletecard') {
  736. print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid ? $ribid : $id), $langs->trans("DeleteACard"), $langs->trans("ConfirmDeleteCard", $companybankaccount->getRibLabel()), "confirm_deletecard", '', 0, 1);
  737. }
  738. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  739. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  740. print '<div class="fichecenter">';
  741. print '<div class="underbanner clearboth"></div>';
  742. print '<table class="border tableforfield centpercent">';
  743. // Type Prospect/Customer/Supplier
  744. print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td colspan="2">';
  745. print $object->getTypeUrl(1);
  746. print '</td></tr>';
  747. if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
  748. print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="2">'.$object->prefix_comm.'</td></tr>';
  749. }
  750. if ($object->client) {
  751. print '<tr><td class="titlefield">';
  752. print $langs->trans('CustomerCode').'</td><td colspan="2">';
  753. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
  754. $tmpcheck = $object->check_codeclient();
  755. if ($tmpcheck != 0 && $tmpcheck != -5) {
  756. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  757. }
  758. print '</td></tr>';
  759. $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".((int) $socid);
  760. $resql = $db->query($sql);
  761. if (!$resql) {
  762. dol_print_error($db);
  763. }
  764. $obj = $db->fetch_object($resql);
  765. $nbFactsClient = $obj->nb;
  766. $thirdTypeArray['customer'] = $langs->trans("customer");
  767. if (isModEnabled("propal") && $user->rights->propal->lire) {
  768. $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
  769. }
  770. if (isModEnabled('commande') && $user->rights->commande->lire) {
  771. $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
  772. }
  773. if (isModEnabled('facture') && $user->rights->facture->lire) {
  774. $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
  775. }
  776. if (isModEnabled('contrat') && $user->rights->contrat->lire) {
  777. $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
  778. }
  779. if (isModEnabled('stripe')) {
  780. // Stripe customer key 'cu_....' stored into llx_societe_account
  781. print '<tr><td class="titlefield">';
  782. print $form->editfieldkey("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontoaddupdatepaymentinformation, 'string', '', 0, 2, 'socid');
  783. print '</td><td>';
  784. print $form->editfieldval("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontoaddupdatepaymentinformation, 'string', '', null, null, '', 2, '', 'socid');
  785. if (isModEnabled('stripe') && $stripecu && $action != 'editkey_account') {
  786. $connect = '';
  787. if (!empty($stripeacc)) {
  788. $connect = $stripeacc.'/';
  789. }
  790. $url = 'https://dashboard.stripe.com/'.$connect.'test/customers/'.$stripecu;
  791. if ($servicestatus) {
  792. $url = 'https://dashboard.stripe.com/'.$connect.'customers/'.$stripecu;
  793. }
  794. print ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe').' - Publishable key = '.$site_account, 'globe').'</a>';
  795. }
  796. print '</td><td class="right">';
  797. if (empty($stripecu)) {
  798. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  799. print '<input type="hidden" name="action" value="synccustomertostripe">';
  800. print '<input type="hidden" name="token" value="'.newToken().'">';
  801. print '<input type="hidden" name="socid" value="'.$object->id.'">';
  802. print img_picto($langs->trans("CreateCustomerOnStripe"), 'stripe');
  803. print '<input type="submit" class="buttonlink nomargintop nomarginbottom noborderbottom nopaddingtopimp nopaddingbottomimp" name="syncstripecustomer" value="'.$langs->trans("CreateCustomerOnStripe").'">';
  804. print '</form>';
  805. }
  806. print '</td></tr>';
  807. }
  808. }
  809. if ($object->fournisseur) {
  810. print '<tr><td class="titlefield">';
  811. print $langs->trans('SupplierCode').'</td><td colspan="2">';
  812. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
  813. $tmpcheck = $object->check_codefournisseur();
  814. if ($tmpcheck != 0 && $tmpcheck != -5) {
  815. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  816. }
  817. print '</td></tr>';
  818. $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".((int) $socid);
  819. $resql = $db->query($sql);
  820. if (!$resql) {
  821. dol_print_error($db);
  822. }
  823. $obj = $db->fetch_object($resql);
  824. $nbFactsClient = $obj->nb;
  825. $thirdTypeArray['customer'] = $langs->trans("customer");
  826. if (isModEnabled('propal') && $user->rights->propal->lire) {
  827. $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
  828. }
  829. if (isModEnabled('commande') && $user->rights->commande->lire) {
  830. $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
  831. }
  832. if (isModEnabled('facture') && $user->rights->facture->lire) {
  833. $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
  834. }
  835. if (isModEnabled('contrat') && $user->rights->contrat->lire) {
  836. $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
  837. }
  838. }
  839. if (isModEnabled('stripe') && !empty($conf->stripeconnect->enabled) && getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
  840. $stripesupplieracc = $stripe->getStripeAccount($service, $object->id); // Get Stripe OAuth connect account (no network access here)
  841. // Stripe customer key 'cu_....' stored into llx_societe_account
  842. print '<tr><td class="titlefield">';
  843. print $form->editfieldkey("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, $permissiontoaddupdatepaymentinformation, 'string', '', 0, 2, 'socid');
  844. print '</td><td>';
  845. print $form->editfieldval("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, $permissiontoaddupdatepaymentinformation, 'string', '', null, null, '', 2, '', 'socid');
  846. if (isModEnabled('stripe') && $stripesupplieracc && $action != 'editkey_account_supplier') {
  847. $connect = '';
  848. $url = 'https://dashboard.stripe.com/test/connect/accounts/'.$stripesupplieracc;
  849. if ($servicestatus) {
  850. $url = 'https://dashboard.stripe.com/connect/accounts/'.$stripesupplieracc;
  851. }
  852. print ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe').' - Publishable key '.$site_account, 'globe').'</a>';
  853. }
  854. print '</td><td class="right">';
  855. if (empty($stripesupplieracc)) {
  856. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  857. print '<input type="hidden" name="action" value="syncsuppliertostripe">';
  858. print '<input type="hidden" name="token" value="'.newToken().'">';
  859. print '<input type="hidden" name="socid" value="'.$object->id.'">';
  860. print '<input type="hidden" name="companybankid" value="'.$rib->id.'">';
  861. //print '<input type="submit" class="button buttongen" name="syncstripecustomer" value="'.$langs->trans("CreateSupplierOnStripe").'">';
  862. print '</form>';
  863. }
  864. print '</td></tr>';
  865. }
  866. print '</table>';
  867. print '</div>';
  868. print dol_get_fiche_end();
  869. print '<br>';
  870. $showcardpaymentmode = 0;
  871. if (isModEnabled('stripe')) {
  872. $showcardpaymentmode++;
  873. }
  874. // Get list of remote payment modes
  875. $listofsources = array();
  876. if (is_object($stripe)) {
  877. try {
  878. $customerstripe = $stripe->customerStripe($object, $stripeacc, $servicestatus);
  879. if (!empty($customerstripe->id)) {
  880. // When using the Charge API architecture
  881. if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) {
  882. $listofsources = $customerstripe->sources->data;
  883. } else {
  884. $service = 'StripeTest';
  885. $servicestatus = 0;
  886. if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) {
  887. $service = 'StripeLive';
  888. $servicestatus = 1;
  889. }
  890. // Force to use the correct API key
  891. global $stripearrayofkeysbyenv;
  892. \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']);
  893. try {
  894. if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
  895. $paymentmethodobjsA = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "card"));
  896. $paymentmethodobjsB = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "sepa_debit"));
  897. } else {
  898. $paymentmethodobjsA = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "card"), array("stripe_account" => $stripeacc));
  899. $paymentmethodobjsB = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "sepa_debit"), array("stripe_account" => $stripeacc));
  900. }
  901. if ($paymentmethodobjsA->data != null && $paymentmethodobjsB->data != null) {
  902. $listofsources = array_merge((array) $paymentmethodobjsA->data, (array) $paymentmethodobjsB->data);
  903. } elseif ($paymentmethodobjsB->data != null) {
  904. $listofsources = $paymentmethodobjsB->data;
  905. } else {
  906. $listofsources = $paymentmethodobjsA->data;
  907. }
  908. } catch (Exception $e) {
  909. $error++;
  910. setEventMessages($e->getMessage(), null, 'errors');
  911. }
  912. }
  913. }
  914. } catch (Exception $e) {
  915. dol_syslog("Error when searching/loading Stripe customer for thirdparty id =".$object->id);
  916. }
  917. }
  918. // List of Card payment modes
  919. if ($showcardpaymentmode && $object->client) {
  920. $morehtmlright = '';
  921. if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) {
  922. $morehtmlright .= dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=createcard');
  923. }
  924. print load_fiche_titre($langs->trans('CreditCard').($stripeacc ? ' (Stripe connection with StripeConnect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)'), $morehtmlright, 'fa-credit-card');
  925. print '<!-- List of card payments -->'."\n";
  926. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  927. print '<table class="liste centpercent">'."\n";
  928. print '<tr class="liste_titre">';
  929. print '<td>'.$langs->trans('Label').'</td>';
  930. print '<td>'.$langs->trans('StripeID').'</td>'; // external system ID
  931. print '<td>'.$langs->trans('Type').'</td>';
  932. print '<td>'.$langs->trans('Informations').'</td>';
  933. print '<td></td>';
  934. print '<td class="center">'.$langs->trans('Default').'</td>';
  935. print '<td>'.$langs->trans('Note').'</td>';
  936. print '<td>'.$langs->trans('DateModification').'</td>';
  937. // Hook fields
  938. $parameters = array('arrayfields'=>array(), 'param'=>'', 'sortfield'=>'', 'sortorder'=>'', 'linetype'=>'stripetitle');
  939. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  940. print $hookmanager->resPrint;
  941. // Action column
  942. print "<td></td>";
  943. print "</tr>\n";
  944. $nbremote = 0;
  945. $nblocal = 0;
  946. $arrayofremotecard = array();
  947. // Show local sources
  948. if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) {
  949. //$societeaccount = new SocieteAccount($db);
  950. $companypaymentmodetemp = new CompanyPaymentMode($db);
  951. $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX."societe_rib";
  952. $sql .= " WHERE type in ('card')";
  953. $sql .= " AND fk_soc = ".((int) $object->id);
  954. $sql .= " AND status = ".((int) $servicestatus);
  955. $resql = $db->query($sql);
  956. if ($resql) {
  957. $num_rows = $db->num_rows($resql);
  958. if ($num_rows) {
  959. $i = 0;
  960. while ($i < $num_rows) {
  961. $nblocal++;
  962. $obj = $db->fetch_object($resql);
  963. if ($obj) {
  964. $companypaymentmodetemp->fetch($obj->rowid);
  965. $arrayofremotecard[$companypaymentmodetemp->stripe_card_ref] = $companypaymentmodetemp->stripe_card_ref;
  966. print '<tr class="oddeven" data-rowid="'.((int) $companypaymentmodetemp->id).'">';
  967. // Label
  968. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companypaymentmodetemp->label).'">';
  969. print dol_escape_htmltag($companypaymentmodetemp->label);
  970. print '</td>';
  971. // External card ID
  972. print '<td class="tdoverflowmax150">';
  973. if (!empty($companypaymentmodetemp->stripe_card_ref)) {
  974. $connect = '';
  975. if (!empty($stripeacc)) {
  976. $connect = $stripeacc.'/';
  977. }
  978. $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$companypaymentmodetemp->stripe_card_ref;
  979. if ($servicestatus) {
  980. $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$companypaymentmodetemp->stripe_card_ref;
  981. }
  982. print '<a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe').' - Customer and Publishable key = '.$companypaymentmodetemp->stripe_account, 'globe').'</a> ';
  983. }
  984. print dol_escape_htmltag($companypaymentmodetemp->stripe_card_ref);
  985. print '</td>';
  986. // Type
  987. print '<td>';
  988. print img_credit_card($companypaymentmodetemp->type);
  989. print '</td>';
  990. // Information (Owner, ...)
  991. print '<td class="minwidth100">';
  992. if ($companypaymentmodetemp->proprio) {
  993. print '<span class="opacitymedium">'.$companypaymentmodetemp->proprio.'</span><br>';
  994. }
  995. if ($companypaymentmodetemp->last_four) {
  996. print '....'.$companypaymentmodetemp->last_four;
  997. }
  998. if ($companypaymentmodetemp->exp_date_month || $companypaymentmodetemp->exp_date_year) {
  999. print ' - '.sprintf("%02d", $companypaymentmodetemp->exp_date_month).'/'.$companypaymentmodetemp->exp_date_year.'';
  1000. }
  1001. print '</td>';
  1002. // Country
  1003. print '<td class="tdoverflowmax100">';
  1004. if ($companypaymentmodetemp->country_code) {
  1005. $img = picto_from_langcode($companypaymentmodetemp->country_code);
  1006. print $img ? $img.' ' : '';
  1007. print getCountry($companypaymentmodetemp->country_code, 1);
  1008. } else {
  1009. print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
  1010. }
  1011. print '</td>';
  1012. // Default
  1013. print '<td class="center">';
  1014. if (empty($companypaymentmodetemp->default_rib)) {
  1015. print '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=setlocalassourcedefault&token='.newToken().'">';
  1016. print img_picto($langs->trans("Default"), 'off');
  1017. print '</a>';
  1018. } else {
  1019. print img_picto($langs->trans("Default"), 'on');
  1020. }
  1021. print '</td>';
  1022. if (empty($companypaymentmodetemp->stripe_card_ref)) {
  1023. $s = $langs->trans("Local");
  1024. } else {
  1025. $s = $langs->trans("LocalAndRemote");
  1026. }
  1027. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
  1028. print $s;
  1029. print '</td>';
  1030. print '<td>';
  1031. print dol_print_date($companypaymentmodetemp->tms, 'dayhour');
  1032. print '</td>';
  1033. // Fields from hook
  1034. $parameters = array('arrayfields'=>array(), 'obj'=>$obj, 'linetype'=>'stripecard');
  1035. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1036. print $hookmanager->resPrint;
  1037. // Action column
  1038. print '<td class="right minwidth50 nowraponall">';
  1039. if ($permissiontoaddupdatepaymentinformation) {
  1040. if ($stripecu && empty($companypaymentmodetemp->stripe_card_ref)) {
  1041. print '<a href="'.$_SERVER['PHP_SELF'].'?action=synccardtostripe&socid='.$object->id.'&id='.$companypaymentmodetemp->id.'" class="paddingrightonly marginrightonly">'.$langs->trans("CreateCardOnStripe").'</a>';
  1042. }
  1043. print '<a class="editfielda marginleftonly marginrightonly" href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=editcard&token='.newToken().'">';
  1044. print img_picto($langs->trans("Modify"), 'edit');
  1045. print '</a>';
  1046. print '<a class="marginleftonly marginrightonly" href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=deletecard&token='.newToken().'">'; // source='.$companypaymentmodetemp->stripe_card_ref.'&
  1047. print img_picto($langs->trans("Delete"), 'delete');
  1048. print '</a>';
  1049. }
  1050. print '</td>';
  1051. print '</tr>';
  1052. }
  1053. $i++;
  1054. }
  1055. }
  1056. } else {
  1057. dol_print_error($db);
  1058. }
  1059. }
  1060. // Show remote sources (not already shown as local source)
  1061. if (is_array($listofsources) && count($listofsources)) {
  1062. foreach ($listofsources as $src) {
  1063. if (!empty($arrayofremotecard[$src->id])) {
  1064. continue; // Already in previous list
  1065. }
  1066. $nbremote++;
  1067. $imgline = '';
  1068. if ($src->object == 'card') {
  1069. $imgline = img_credit_card($src->brand);
  1070. } elseif ($src->object == 'source' && $src->type == 'card') {
  1071. $imgline = img_credit_card($src->card->brand);
  1072. } elseif ($src->object == 'payment_method' && $src->type == 'card') {
  1073. $imgline = img_credit_card($src->card->brand);
  1074. } elseif ($src->object == 'source' && $src->type == 'sepa_debit') {
  1075. continue;
  1076. } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit') {
  1077. continue;
  1078. }
  1079. print '<tr class="oddeven">';
  1080. print '<td>';
  1081. print '</td>';
  1082. // Src ID
  1083. print '<td class="tdoverflowmax150">';
  1084. $connect = '';
  1085. if (!empty($stripeacc)) {
  1086. $connect = $stripeacc.'/';
  1087. }
  1088. //$url='https://dashboard.stripe.com/'.$connect.'test/sources/'.$src->id;
  1089. $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$src->id;
  1090. if ($servicestatus) {
  1091. //$url='https://dashboard.stripe.com/'.$connect.'sources/'.$src->id;
  1092. $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$src->id;
  1093. }
  1094. print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')."</a> ";
  1095. print $src->id;
  1096. print '</td>';
  1097. // Img
  1098. print '<td>';
  1099. print $imgline;
  1100. print'</td>';
  1101. // Information
  1102. print '<td valign="middle">';
  1103. if ($src->object == 'card') {
  1104. print '....'.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.'';
  1105. print '</td><td>';
  1106. if ($src->country) {
  1107. $img = picto_from_langcode($src->country);
  1108. print $img ? $img.' ' : '';
  1109. print getCountry($src->country, 1);
  1110. } else {
  1111. print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
  1112. }
  1113. } elseif ($src->object == 'source' && $src->type == 'card') {
  1114. print '<span class="opacitymedium">'.$src->owner->name.'</span><br>....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.'';
  1115. print '</td><td>';
  1116. if ($src->card->country) {
  1117. $img = picto_from_langcode($src->card->country);
  1118. print $img ? $img.' ' : '';
  1119. print getCountry($src->card->country, 1);
  1120. } else {
  1121. print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
  1122. }
  1123. } elseif ($src->object == 'source' && $src->type == 'sepa_debit') {
  1124. print '<span class="opacitymedium">'.$src->billing_details->name.'</span><br>....'.$src->sepa_debit->last4;
  1125. print '</td><td>';
  1126. if ($src->sepa_debit->country) {
  1127. $img = picto_from_langcode($src->sepa_debit->country);
  1128. print $img ? $img.' ' : '';
  1129. print getCountry($src->sepa_debit->country, 1);
  1130. } else {
  1131. print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
  1132. }
  1133. } elseif ($src->object == 'payment_method' && $src->type == 'card') {
  1134. print '<span class="opacitymedium">'.$src->billing_details->name.'</span><br>....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.'';
  1135. print '</td><td>';
  1136. if ($src->card->country) {
  1137. $img = picto_from_langcode($src->card->country);
  1138. print $img ? $img.' ' : '';
  1139. print getCountry($src->card->country, 1);
  1140. } else {
  1141. print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
  1142. }
  1143. } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit') {
  1144. print '<span class="opacitymedium">'.$src->billing_details->name.'</span><br>....'.$src->sepa_debit->last4;
  1145. print '</td><td>';
  1146. if ($src->sepa_debit->country) {
  1147. $img = picto_from_langcode($src->sepa_debit->country);
  1148. print $img ? $img.' ' : '';
  1149. print getCountry($src->sepa_debit->country, 1);
  1150. } else {
  1151. print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
  1152. }
  1153. } else {
  1154. print '</td><td>';
  1155. }
  1156. print '</td>';
  1157. // Default
  1158. print '<td class="center" width="50">';
  1159. if ((empty($customerstripe->invoice_settings) && $customerstripe->default_source != $src->id) ||
  1160. (!empty($customerstripe->invoice_settings) && $customerstripe->invoice_settings->default_payment_method != $src->id)) {
  1161. print '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=setassourcedefault&token='.newToken().'">';
  1162. print img_picto($langs->trans("Default"), 'off');
  1163. print '</a>';
  1164. } else {
  1165. print img_picto($langs->trans("Default"), 'on');
  1166. }
  1167. print '</td>';
  1168. print '<td>';
  1169. print $langs->trans("Remote");
  1170. //if ($src->cvc_check == 'fail') print ' - CVC check fail';
  1171. print '</td>';
  1172. print '<td>';
  1173. //var_dump($src);
  1174. print '</td>';
  1175. // Fields from hook
  1176. $parameters = array('arrayfields'=>array(), 'stripesource'=>$src, 'linetype'=>'stripecardremoteonly');
  1177. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1178. print $hookmanager->resPrint;
  1179. // Action column
  1180. print '<td class="right nowraponall">';
  1181. if ($permissiontoaddupdatepaymentinformation) {
  1182. print '<a class="marginleftonly marginrightonly" href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=deletecard&token='.newToken().'">';
  1183. print img_picto($langs->trans("Delete"), 'delete');
  1184. print '</a>';
  1185. }
  1186. print '</td>';
  1187. print '</tr>';
  1188. }
  1189. }
  1190. if ($nbremote == 0 && $nblocal == 0) {
  1191. $colspan = (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD) ? 10 : 9);
  1192. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  1193. }
  1194. print "</table>";
  1195. print "</div>";
  1196. print '<br>';
  1197. }
  1198. // List of Stripe connect accounts
  1199. if (isModEnabled('stripe') && !empty($conf->stripeconnect->enabled) && !empty($stripesupplieracc)) {
  1200. print load_fiche_titre($langs->trans('StripeBalance').($stripesupplieracc ? ' (Stripe connection with StripeConnect account '.$stripesupplieracc.')' : ' (Stripe connection with keys from Stripe module setup)'), $morehtmlright, 'stripe-s');
  1201. $balance = \Stripe\Balance::retrieve(array("stripe_account" => $stripesupplieracc));
  1202. print '<table class="liste centpercent">'."\n";
  1203. print '<tr class="liste_titre">';
  1204. print '<td>'.$langs->trans('Currency').'</td>';
  1205. print '<td>'.$langs->trans('Available').'</td>';
  1206. print '<td>'.$langs->trans('Pending').'</td>';
  1207. print '<td>'.$langs->trans('Total').'</td>';
  1208. print '</tr>';
  1209. $currencybalance = array();
  1210. if (is_array($balance->available) && count($balance->available)) {
  1211. foreach ($balance->available as $cpt) {
  1212. $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
  1213. if (!in_array($cpt->currency, $arrayzerounitcurrency)) {
  1214. $currencybalance[$cpt->currency]['available'] = $cpt->amount / 100;
  1215. } else {
  1216. $currencybalance[$cpt->currency]['available'] = $cpt->amount;
  1217. }
  1218. $currencybalance[$cpt->currency]['currency'] = $cpt->currency;
  1219. }
  1220. }
  1221. if (is_array($balance->pending) && count($balance->pending)) {
  1222. foreach ($balance->pending as $cpt) {
  1223. $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
  1224. if (!in_array($cpt->currency, $arrayzerounitcurrency)) {
  1225. $currencybalance[$cpt->currency]['pending'] = $currencybalance[$cpt->currency]['available'] + $cpt->amount / 100;
  1226. } else {
  1227. $currencybalance[$cpt->currency]['pending'] = $currencybalance[$cpt->currency]['available'] + $cpt->amount;
  1228. }
  1229. }
  1230. }
  1231. if (is_array($currencybalance)) {
  1232. foreach ($currencybalance as $cpt) {
  1233. print '<tr><td>'.$langs->trans("Currency".strtoupper($cpt['currency'])).'</td><td>'.price($cpt['available'], 0, '', 1, - 1, - 1, strtoupper($cpt['currency'])).'</td><td>'.price(isset($cpt->pending)?$cpt->pending:0, 0, '', 1, - 1, - 1, strtoupper($cpt['currency'])).'</td><td>'.price($cpt['available'] + (isset($cpt->pending)?$cpt->pending:0), 0, '', 1, - 1, - 1, strtoupper($cpt['currency'])).'</td></tr>';
  1234. }
  1235. }
  1236. print '</table>';
  1237. print '<br>';
  1238. }
  1239. // List of bank accounts
  1240. if ($permissiontoaddupdatepaymentinformation) {
  1241. $morehtmlright = dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&amp;action=create');
  1242. }
  1243. print load_fiche_titre($langs->trans("BankAccounts"), $morehtmlright, 'bank');
  1244. $nblocal = 0; $nbremote = 0;
  1245. $arrayofremoteban = array();
  1246. $rib_list = $object->get_all_rib();
  1247. if (is_array($rib_list)) {
  1248. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
  1249. print '<table class="liste centpercent">';
  1250. print '<tr class="liste_titre">';
  1251. print_liste_field_titre("Label");
  1252. print_liste_field_titre("StripeID"); // external system ID
  1253. print_liste_field_titre("Bank");
  1254. print_liste_field_titre("RIB");
  1255. print_liste_field_titre("IBAN");
  1256. print_liste_field_titre("BIC");
  1257. if (!empty($conf->prelevement->enabled)) {
  1258. print_liste_field_titre("RUM");
  1259. print_liste_field_titre("DateRUM");
  1260. print_liste_field_titre("WithdrawMode");
  1261. }
  1262. print_liste_field_titre("Default", '', '', '', '', '', '', '', 'center ');
  1263. print_liste_field_titre('', '', '', '', '', '', '', '', 'center ');
  1264. // Fields from hook
  1265. $parameters = array('arrayfields'=>array(), 'linetype'=>'stripebantitle');
  1266. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1267. print $hookmanager->resPrint;
  1268. print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
  1269. print "</tr>\n";
  1270. // List of local BAN
  1271. foreach ($rib_list as $rib) {
  1272. $arrayofremoteban[$rib->stripe_card_ref] = $rib->stripe_card_ref;
  1273. $nblocal++;
  1274. print '<tr class="oddeven">';
  1275. // Label
  1276. print '<td>'.dol_escape_htmltag($rib->label).'</td>';
  1277. // Stripe ID
  1278. print '<td class="tdoverflowmax150">';
  1279. if ($rib->stripe_card_ref) {
  1280. $connect = '';
  1281. if (!empty($stripeacc)) {
  1282. $connect = $stripeacc.'/';
  1283. }
  1284. //$url='https://dashboard.stripe.com/'.$connect.'test/sources/'.$src->id;
  1285. $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$rib->stripe_card_ref;
  1286. if ($servicestatus) {
  1287. //$url='https://dashboard.stripe.com/'.$connect.'sources/'.$src->id;
  1288. $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$rib->stripe_card_ref;
  1289. }
  1290. print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')."</a> ";
  1291. }
  1292. print $rib->stripe_card_ref;
  1293. print '</td>';
  1294. // Bank name
  1295. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($rib->bank).'">'.dol_escape_htmltag($rib->bank).'</td>';
  1296. // Account number
  1297. $string = '';
  1298. foreach ($rib->getFieldsToShow() as $val) {
  1299. if ($val == 'BankCode') {
  1300. $string .= $rib->code_banque.' ';
  1301. } elseif ($val == 'BankAccountNumber') {
  1302. $string .= $rib->number.' ';
  1303. } elseif ($val == 'DeskCode') {
  1304. $string .= $rib->code_guichet.' ';
  1305. } elseif ($val == 'BankAccountNumberKey') {
  1306. $string .= $rib->cle_rib.' ';
  1307. }
  1308. // Already output after
  1309. // } elseif ($val == 'BIC') {
  1310. // $string .= $rib->bic.' ';
  1311. // } elseif ($val == 'IBAN') {
  1312. // $string .= $rib->iban.' ';*/
  1313. //}
  1314. }
  1315. if (!empty($rib->label) && $rib->number) {
  1316. if (!checkBanForAccount($rib)) {
  1317. $string .= ' '.img_picto($langs->trans("ValueIsNotValid"), 'warning');
  1318. } else {
  1319. $string .= ' '.img_picto($langs->trans("ValueIsValid"), 'info');
  1320. }
  1321. }
  1322. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($string).'">';
  1323. print $string;
  1324. print '</td>';
  1325. // IBAN
  1326. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($rib->iban).'">';
  1327. if (!empty($rib->iban)) {
  1328. if (!checkIbanForAccount($rib)) {
  1329. print img_picto($langs->trans("IbanNotValid"), 'warning').' ';
  1330. }
  1331. }
  1332. print dol_escape_htmltag($rib->iban);
  1333. print '</td>';
  1334. // BIC
  1335. print '<td>';
  1336. if (!empty($rib->bic)) {
  1337. if (!checkSwiftForAccount($rib)) {
  1338. print img_picto($langs->trans("SwiftNotValid"), 'warning').' ';
  1339. }
  1340. }
  1341. print dol_escape_htmltag($rib->bic);
  1342. print '</td>';
  1343. if (!empty($conf->prelevement->enabled)) {
  1344. // RUM
  1345. //print '<td>'.$prelevement->buildRumNumber($object->code_client, $rib->datec, $rib->id).'</td>';
  1346. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($rib->rum).'">'.dol_escape_htmltag($rib->rum).'</td>';
  1347. print '<td>'.dol_print_date($rib->date_rum, 'day').'</td>';
  1348. // FRSTRECUR
  1349. print '<td>'.$rib->frstrecur.'</td>';
  1350. }
  1351. // Default
  1352. print '<td class="center" width="70">';
  1353. if (!$rib->default_rib) {
  1354. print '<a href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&ribid='.$rib->id.'&action=setasbankdefault&token='.newToken().'">';
  1355. print img_picto($langs->trans("Disabled"), 'off');
  1356. print '</a>';
  1357. } else {
  1358. print img_picto($langs->trans("Enabled"), 'on');
  1359. }
  1360. print '</td>';
  1361. // Generate doc
  1362. print '<td class="center">';
  1363. $buttonlabel = $langs->trans("BuildDoc");
  1364. $forname = 'builddocrib'.$rib->id;
  1365. include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
  1366. $modellist = ModeleBankAccountDoc::liste_modeles($db);
  1367. $out = '';
  1368. if (is_array($modellist) && count($modellist)) {
  1369. $out .= '<form action="'.$_SERVER["PHP_SELF"].(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc').'" name="'.$forname.'" id="'.$forname.'_form" method="post">';
  1370. $out .= '<input type="hidden" name="action" value="builddocrib">';
  1371. $out .= '<input type="hidden" name="token" value="'.newToken().'">';
  1372. $out .= '<input type="hidden" name="socid" value="'.$object->id.'">';
  1373. $out .= '<input type="hidden" name="companybankid" value="'.$rib->id.'">';
  1374. if (is_array($modellist) && count($modellist) == 1) { // If there is only one element
  1375. $arraykeys = array_keys($modellist);
  1376. $modelselected = $arraykeys[0];
  1377. }
  1378. if (!empty($conf->global->BANKADDON_PDF)) {
  1379. $modelselected = $conf->global->BANKADDON_PDF;
  1380. }
  1381. $out .= $form->selectarray('modelrib'.$rib->id, $modellist, $modelselected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100');
  1382. $out .= ajax_combobox('modelrib'.$rib->id);
  1383. $allowgenifempty = 0;
  1384. // Language code (if multilang)
  1385. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  1386. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  1387. $formadmin = new FormAdmin($db);
  1388. $defaultlang = $langs->getDefaultLang();
  1389. $morecss = 'maxwidth150';
  1390. if ($conf->browser->layout == 'phone') {
  1391. $morecss = 'maxwidth100';
  1392. }
  1393. $out .= $formadmin->select_language($defaultlang, 'lang_idrib'.$rib->id, 0, 0, 0, 0, 0, $morecss);
  1394. }
  1395. // Button
  1396. $genbutton = '<input class="button buttongen reposition nomargintop nomarginbottom" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
  1397. $genbutton .= ' type="submit" value="'.$buttonlabel.'"';
  1398. if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) {
  1399. $genbutton .= ' disabled';
  1400. }
  1401. $genbutton .= '>';
  1402. if ($allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') {
  1403. $langs->load("errors");
  1404. $genbutton .= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
  1405. }
  1406. if (!$allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') {
  1407. $genbutton = '';
  1408. }
  1409. if (empty($modellist) && !$showempty && $modulepart != 'unpaid') {
  1410. $genbutton = '';
  1411. }
  1412. $out .= $genbutton;
  1413. $out .= '</form>';
  1414. }
  1415. print $out;
  1416. print '</td>';
  1417. // Fields from hook
  1418. $parameters = array('arrayfields'=>array(), 'stripe_card_ref'=>$rib->stripe_card_ref, 'stripe_account'=>$rib->stripe_account, 'linetype'=>'stripeban');
  1419. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1420. print $hookmanager->resPrint;
  1421. // Edit/Delete
  1422. print '<td class="right nowraponall">';
  1423. if ($permissiontoaddupdatepaymentinformation) {
  1424. if (empty($rib->stripe_card_ref)) {
  1425. // Add link to create BAN on Stripe
  1426. print '<a class="editfielda marginrightonly marginleftonly" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=syncsepatostripe&token='.newToken().'">';
  1427. print img_picto($langs->trans("CreateBANOnStripe"), 'stripe');
  1428. print '</a>';
  1429. }
  1430. print '<a class="editfielda marginrightonly marginleftonly" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=edit">';
  1431. print img_picto($langs->trans("Modify"), 'edit');
  1432. print '</a>';
  1433. print '<a class="marginrightonly marginleftonly" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=delete&token='.newToken().'">';
  1434. print img_picto($langs->trans("Delete"), 'delete');
  1435. print '</a>';
  1436. }
  1437. print '</td>';
  1438. print '</tr>';
  1439. }
  1440. // List of remote BAN (if not already added as local)
  1441. foreach ($listofsources as $src) {
  1442. if (!empty($arrayofremoteban[$src->id])) {
  1443. continue; // Already in previous list
  1444. }
  1445. $imgline = '';
  1446. if ($src->object == 'source' && $src->type == 'sepa_debit') {
  1447. $imgline = '<span class="fa fa-university fa-2x fa-fw"></span>';
  1448. } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit') {
  1449. $imgline = '<span class="fa fa-university fa-2x fa-fw"></span>';
  1450. } else {
  1451. continue;
  1452. }
  1453. $nbremote++;
  1454. print '<tr class="oddeven">';
  1455. print '<td>';
  1456. print '</td>';
  1457. // Src ID
  1458. print '<td class="tdoverflowmax150">';
  1459. $connect = '';
  1460. if (!empty($stripeacc)) {
  1461. $connect = $stripeacc.'/';
  1462. }
  1463. //$url='https://dashboard.stripe.com/'.$connect.'test/sources/'.$src->id;
  1464. $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$src->id;
  1465. if ($servicestatus) {
  1466. //$url='https://dashboard.stripe.com/'.$connect.'sources/'.$src->id;
  1467. $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$src->id;
  1468. }
  1469. print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')."</a> ";
  1470. print $src->id;
  1471. print '</td>';
  1472. // Bank
  1473. print '<td>';
  1474. print'</td>';
  1475. // Account number
  1476. print '<td valign="middle">';
  1477. print '</td>';
  1478. // IBAN
  1479. print '<td valign="middle">';
  1480. //var_dump($src);
  1481. print '</td>';
  1482. // BIC
  1483. print '<td valign="middle">';
  1484. //var_dump($src);
  1485. print '</td>';
  1486. if (!empty($conf->prelevement->enabled)) {
  1487. // RUM
  1488. print '<td valign="middle">';
  1489. //var_dump($src);
  1490. print '</td>';
  1491. // Date
  1492. print '<td valign="middle">';
  1493. //var_dump($src);
  1494. print '</td>';
  1495. // Mode mandate
  1496. print '<td valign="middle">';
  1497. //var_dump($src);
  1498. print '</td>';
  1499. }
  1500. // Default
  1501. print '<td class="center" width="50">';
  1502. if ((empty($customerstripe->invoice_settings) && $customerstripe->default_source != $src->id) ||
  1503. (!empty($customerstripe->invoice_settings) && $customerstripe->invoice_settings->default_payment_method != $src->id)) {
  1504. print '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=setassourcedefault&token='.newToken().'">';
  1505. print img_picto($langs->trans("Default"), 'off');
  1506. print '</a>';
  1507. } else {
  1508. print img_picto($langs->trans("Default"), 'on');
  1509. }
  1510. print '</td>';
  1511. /*
  1512. print '<td>';
  1513. print $langs->trans("Remote");
  1514. //if ($src->cvc_check == 'fail') print ' - CVC check fail';
  1515. print '</td>';
  1516. */
  1517. print '<td>';
  1518. print '</td>';
  1519. // Fields from hook
  1520. $parameters = array('arrayfields'=>array(), 'stripe_card_ref'=>$rib->stripe_card_ref, 'stripe_account'=>$rib->stripe_account, 'linetype'=>'stripebanremoteonly');
  1521. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1522. print $hookmanager->resPrint;
  1523. // Action column
  1524. print '<td class="right nowraponall">';
  1525. if ($permissiontoaddupdatepaymentinformation) {
  1526. print '<a class="marginleftonly marginrightonly" href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=delete&token='.newToken().'">';
  1527. print img_picto($langs->trans("Delete"), 'delete');
  1528. print '</a>';
  1529. }
  1530. print '</td>';
  1531. print '</tr>';
  1532. }
  1533. if ($nbremote == 0 && $nblocal == 0) {
  1534. $colspan = 10;
  1535. if (isModEnabled('prelevement')) {
  1536. $colspan += 3;
  1537. }
  1538. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoBANRecord").'</span></td></tr>';
  1539. }
  1540. print '</table>';
  1541. print '</div>';
  1542. } else {
  1543. dol_print_error($db);
  1544. }
  1545. if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) {
  1546. print '<br>';
  1547. print '<div class="fichecenter"><div class="fichehalfleft">';
  1548. print '<a name="builddoc"></a>'; // ancre
  1549. /*
  1550. * Generated documents
  1551. */
  1552. $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
  1553. $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
  1554. print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $permissiontoread, $permissiontoaddupdatepaymentinformation, $object->model_pdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
  1555. // Show direct download link
  1556. if (!empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) {
  1557. $companybankaccounttemp = new CompanyBankAccount($db);
  1558. $companypaymentmodetemp = new CompanyPaymentMode($db);
  1559. $result = $companypaymentmodetemp->fetch(0, null, $object->id, 'ban');
  1560. include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
  1561. $ecmfile = new EcmFiles($db);
  1562. $result = $ecmfile->fetch(0, '', '', '', '', $companybankaccounttemp->table_element, $companypaymentmodetemp->id);
  1563. if ($result > 0) {
  1564. $companybankaccounttemp->last_main_doc = $ecmfile->filepath.'/'.$ecmfile->filename;
  1565. print '<br><!-- Link to download main doc -->'."\n";
  1566. print showDirectDownloadLink($companybankaccounttemp).'<br>';
  1567. }
  1568. }
  1569. print '</div><div class="fichehalfright">';
  1570. print '</div></div>';
  1571. print '<br>';
  1572. }
  1573. /*
  1574. include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
  1575. $modellist=ModeleBankAccountDoc::liste_modeles($db);
  1576. //print '<td>';
  1577. if (is_array($modellist) && count($modellist) == 1) // If there is only one element
  1578. {
  1579. $arraykeys=array_keys($modellist);
  1580. $modelselected=$arraykeys[0];
  1581. }
  1582. $out.= $form->selectarray('model', $modellist, $modelselected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100');
  1583. $out.= ajax_combobox('model');
  1584. //print $out;
  1585. $buttonlabel=$langs->trans("Generate");
  1586. $genbutton = '<input class="button buttongen reposition nomargintop nomarginbottom" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
  1587. $genbutton.= ' type="submit" value="'.$buttonlabel.'"';
  1588. $genbutton.= '>';
  1589. print $genbutton;
  1590. //print '</td>'; // TODO Add link to generate doc
  1591. */
  1592. }
  1593. // Edit BAN
  1594. if ($socid && $action == 'edit' && $permissiontoaddupdatepaymentinformation) {
  1595. print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
  1596. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1597. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  1598. print '<div class="underbanner clearboth"></div>';
  1599. print '<br>';
  1600. print '<div class="div-table-responsive-no-min">';
  1601. print '<table class="border centpercent">';
  1602. print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Label").'</td>';
  1603. print '<td><input class="minwidth300" type="text" name="label" value="'.$companybankaccount->label.'"></td></tr>';
  1604. print '<tr><td class="fieldrequired">'.$langs->trans("BankName").'</td>';
  1605. print '<td><input class="minwidth200" type="text" name="bank" value="'.$companybankaccount->bank.'"></td></tr>';
  1606. // Show fields of bank account
  1607. foreach ($companybankaccount->getFieldsToShow(1) as $val) {
  1608. $require = false;
  1609. $tooltip = '';
  1610. if ($val == 'BankCode') {
  1611. $name = 'code_banque';
  1612. $size = 8;
  1613. $content = $companybankaccount->code_banque;
  1614. } elseif ($val == 'DeskCode') {
  1615. $name = 'code_guichet';
  1616. $size = 8;
  1617. $content = $companybankaccount->code_guichet;
  1618. } elseif ($val == 'BankAccountNumber') {
  1619. $name = 'number';
  1620. $size = 18;
  1621. $content = $companybankaccount->number;
  1622. } elseif ($val == 'BankAccountNumberKey') {
  1623. $name = 'cle_rib';
  1624. $size = 3;
  1625. $content = $companybankaccount->cle_rib;
  1626. } elseif ($val == 'IBAN') {
  1627. $name = 'iban';
  1628. $size = 30;
  1629. $content = $companybankaccount->iban;
  1630. if ($companybankaccount->needIBAN()) {
  1631. $require = true;
  1632. }
  1633. $tooltip = $langs->trans("Example").':<br>LT12 1000 0111 0100 1000<br>FR14 2004 1010 0505 0001 3M02 606<br>LU28 0019 4006 4475 0000<br>DE89 3704 0044 0532 0130 00';
  1634. } elseif ($val == 'BIC') {
  1635. $name = 'bic';
  1636. $size = 12;
  1637. $content = $companybankaccount->bic;
  1638. if ($companybankaccount->needIBAN()) {
  1639. $require = true;
  1640. }
  1641. $tooltip = $langs->trans("Example").': LIABLT2XXXX';
  1642. }
  1643. print '<tr><td'.($require ? ' class="fieldrequired" ' : '').'>';
  1644. if ($tooltip) {
  1645. print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name);
  1646. } else {
  1647. print $langs->trans($val);
  1648. }
  1649. print '</td>';
  1650. print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.$content.'"></td>';
  1651. print '</tr>';
  1652. }
  1653. print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
  1654. print '<textarea name="domiciliation" rows="4" cols="40" maxlength="255">';
  1655. print $companybankaccount->domiciliation;
  1656. print "</textarea></td></tr>";
  1657. print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
  1658. print '<td><input class="minwidth300" type="text" name="proprio" value="'.$companybankaccount->proprio.'"></td></tr>';
  1659. print "</td></tr>\n";
  1660. print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
  1661. print '<textarea name="owner_address" rows="'.ROWS_4.'" cols="40" maxlength="255">';
  1662. print $companybankaccount->owner_address;
  1663. print "</textarea></td></tr>";
  1664. print '</table>';
  1665. print '</div>';
  1666. if (isModEnabled('prelevement')) {
  1667. print '<br>';
  1668. print '<div class="div-table-responsive-no-min">';
  1669. print '<table class="border centpercent">';
  1670. if (empty($companybankaccount->rum)) {
  1671. $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
  1672. }
  1673. // RUM
  1674. print '<tr><td class="titlefield">'.$langs->trans("RUM").'</td>';
  1675. print '<td><input class="minwidth300" type="text" name="rum" value="'.dol_escape_htmltag($companybankaccount->rum).'"></td></tr>';
  1676. $date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth'), GETPOST('date_rumday'), GETPOST('date_rumyear'));
  1677. print '<tr><td class="titlefield">'.$langs->trans("DateRUM").'</td>';
  1678. print '<td>'.$form->selectDate($date_rum ? $date_rum : $companybankaccount->date_rum, 'date_rum', 0, 0, 1, 'date_rum', 1, 1).'</td></tr>';
  1679. print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
  1680. $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR"));
  1681. print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur', 'alpha') ?GETPOST('frstrecur', 'alpha') : $companybankaccount->frstrecur), 0);
  1682. print '</td></tr>';
  1683. print '<tr><td>'.$langs->trans("StripeID")." ('src_....')</td>";
  1684. print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.$companypaymentmode->stripe_card_ref.'"></td></tr>';
  1685. print '</table>';
  1686. print '</div>';
  1687. }
  1688. print dol_get_fiche_end();
  1689. print $form->buttonsSaveCancel("Modify");
  1690. }
  1691. // Edit Card
  1692. if ($socid && $action == 'editcard' && $permissiontoaddupdatepaymentinformation) {
  1693. print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
  1694. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1695. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  1696. print '<div class="nofichecenter">';
  1697. print '<div class="underbanner clearboth"></div>';
  1698. print '<br>';
  1699. print '<table class="border centpercent">';
  1700. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
  1701. print '<td><input class="minwidth300" type="text" id="label" name="label" value="'.$companypaymentmode->label.'"></td></tr>';
  1702. print '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>';
  1703. print '<td><input class="minwidth200" type="text" name="proprio" value="'.$companypaymentmode->proprio.'"></td></tr>';
  1704. print '<tr><td>'.$langs->trans("CardNumber").'</td>';
  1705. print '<td><input class="minwidth200" type="text" name="cardnumber" value="'.$companypaymentmode->number.'"></td></tr>';
  1706. print '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>';
  1707. print '<td>';
  1708. print $formother->select_month($companypaymentmode->exp_date_month, 'exp_date_month', 1);
  1709. print $formother->selectyear($companypaymentmode->exp_date_year, 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly');
  1710. print '</td></tr>';
  1711. print '<tr><td>'.$langs->trans("CVN").'</td>';
  1712. print '<td><input size="8" type="text" name="cvn" value="'.$companypaymentmode->cvn.'"></td></tr>';
  1713. print '<tr><td>'.$langs->trans("StripeID")." ('card_....')</td>";
  1714. print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.$companypaymentmode->stripe_card_ref.'"></td></tr>';
  1715. print '</table>';
  1716. print '</div>';
  1717. print dol_get_fiche_end();
  1718. print $form->buttonsSaveCancel("Modify");
  1719. }
  1720. // Create BAN
  1721. if ($socid && $action == 'create' && $permissiontoaddupdatepaymentinformation) {
  1722. print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
  1723. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1724. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  1725. print '<div class="nofichecenter">';
  1726. print '<div class="underbanner clearboth"></div>';
  1727. print '<br>';
  1728. print '<table class="border centpercent">';
  1729. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
  1730. print '<td><input class="minwidth200" type="text" id="label" name="label" value="'.(GETPOSTISSET('label') ? GETPOST('label') : $object->name).'"></td></tr>';
  1731. print '<tr><td class="fieldrequired">'.$langs->trans("Bank").'</td>';
  1732. print '<td><input class="minwidth200" type="text" id="bank" name="bank" value="'.GETPOST('bank').'"></td></tr>';
  1733. // Show fields of bank account
  1734. foreach ($companybankaccount->getFieldsToShow(1) as $val) {
  1735. $require = false;
  1736. $tooltip = '';
  1737. if ($val == 'BankCode') {
  1738. $name = 'code_banque';
  1739. $size = 8;
  1740. $content = $companybankaccount->code_banque;
  1741. } elseif ($val == 'DeskCode') {
  1742. $name = 'code_guichet';
  1743. $size = 8;
  1744. $content = $companybankaccount->code_guichet;
  1745. } elseif ($val == 'BankAccountNumber') {
  1746. $name = 'number';
  1747. $size = 18;
  1748. $content = $companybankaccount->number;
  1749. } elseif ($val == 'BankAccountNumberKey') {
  1750. $name = 'cle_rib';
  1751. $size = 3;
  1752. $content = $companybankaccount->cle_rib;
  1753. } elseif ($val == 'IBAN') {
  1754. $name = 'iban';
  1755. $size = 30;
  1756. $content = $companybankaccount->iban;
  1757. if ($companybankaccount->needIBAN()) {
  1758. $require = true;
  1759. }
  1760. $tooltip = $langs->trans("Example").':<br>LT12 1000 0111 0100 1000<br>FR14 2004 1010 0505 0001 3M02 606<br>LU28 0019 4006 4475 0000<br>DE89 3704 0044 0532 0130 00';
  1761. } elseif ($val == 'BIC') {
  1762. $name = 'bic';
  1763. $size = 12;
  1764. $content = $companybankaccount->bic;
  1765. if ($companybankaccount->needIBAN()) {
  1766. $require = true;
  1767. }
  1768. $tooltip = $langs->trans("Example").': LIABLT2XXXX';
  1769. }
  1770. print '<tr><td'.($require ? ' class="fieldrequired" ' : '').'>';
  1771. if ($tooltip) {
  1772. print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name);
  1773. } else {
  1774. print $langs->trans($val);
  1775. }
  1776. print '</td>';
  1777. print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.GETPOST($name).'"></td>';
  1778. print '</tr>';
  1779. }
  1780. print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
  1781. print '<textarea name="domiciliation" rows="'.ROWS_4.'" class="quatrevingtpercent" maxlength="255">';
  1782. print GETPOST('domiciliation');
  1783. print "</textarea></td></tr>";
  1784. print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
  1785. print '<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST('proprio').'"></td></tr>';
  1786. print "</td></tr>\n";
  1787. print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
  1788. print '<textarea name="owner_address" rows="'.ROWS_4.'" class="quatrevingtpercent" maxlength="255">';
  1789. print GETPOST('owner_address');
  1790. print "</textarea></td></tr>";
  1791. print '</table>';
  1792. if (isModEnabled('prelevement')) {
  1793. print '<br>';
  1794. print '<table class="border centpercent">';
  1795. // RUM
  1796. print '<tr><td class="titlefieldcreate">'.$langs->trans("RUM").'</td>';
  1797. print '<td colspan="4"><input type="text" class="minwidth300" name="rum" value="'.GETPOST('rum', 'alpha').'"> <div class="opacitymedium">'.$langs->trans("RUMWillBeGenerated").'</div></td></tr>';
  1798. $date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth'), GETPOST('date_rumday'), GETPOST('date_rumyear'));
  1799. print '<tr><td class="titlefieldcreate">'.$langs->trans("DateRUM").'</td>';
  1800. print '<td colspan="4">'.$form->selectDate($date_rum, 'date_rum', 0, 0, 1, 'date_rum', 1, 1).'</td></tr>';
  1801. print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
  1802. $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR"));
  1803. print $form->selectarray("frstrecur", $tblArraychoice, (GETPOSTISSET('frstrecur') ? GETPOST('frstrecur') : 'FRST'), 0);
  1804. print '</td></tr>';
  1805. print '<tr><td>'.$langs->trans("StripeID")." ('src_....')</td>";
  1806. print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.GETPOST('stripe_card_ref', 'alpha').'"></td></tr>';
  1807. print '</table>';
  1808. }
  1809. print '</div>';
  1810. print dol_get_fiche_end();
  1811. dol_set_focus('#bank');
  1812. print $form->buttonsSaveCancel("Add");
  1813. }
  1814. // Create Card
  1815. if ($socid && $action == 'createcard' && $permissiontoaddupdatepaymentinformation) {
  1816. print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
  1817. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1818. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  1819. print '<div class="nofichecenter">';
  1820. print '<div class="underbanner clearboth"></div>';
  1821. print '<br>';
  1822. print '<table class="border centpercent">';
  1823. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
  1824. print '<td><input class="minwidth200" type="text" id="label" name="label" value="'.GETPOST('label', 'alpha').'"></td></tr>';
  1825. print '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>';
  1826. print '<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST('proprio', 'alpha').'"></td></tr>';
  1827. print '<tr><td>'.$langs->trans("CardNumber").'</td>';
  1828. print '<td><input class="minwidth200" type="text" name="cardnumber" value="'.GETPOST('cardnumber', 'alpha').'"></td></tr>';
  1829. print '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>';
  1830. print '<td>';
  1831. print $formother->select_month(GETPOST('exp_date_month', 'int'), 'exp_date_month', 1);
  1832. print $formother->selectyear(GETPOST('exp_date_year', 'int'), 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly');
  1833. print '</td></tr>';
  1834. print '<tr><td>'.$langs->trans("CVN").'</td>';
  1835. print '<td><input class="width50" type="text" name="cvn" value="'.GETPOST('cvn', 'alpha').'"></td></tr>';
  1836. print '<tr><td>'.$langs->trans("StripeID")." ('card_....')</td>";
  1837. print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.GETPOST('stripe_card_ref', 'alpha').'"></td></tr>';
  1838. print '</table>';
  1839. print '</div>';
  1840. print dol_get_fiche_end();
  1841. dol_set_focus('#label');
  1842. print $form->buttonsSaveCancel("Add");
  1843. }
  1844. if ($socid && ($action == 'edit' || $action == 'editcard') && $permissiontoaddupdatepaymentinformation) {
  1845. print '</form>';
  1846. }
  1847. if ($socid && ($action == 'create' || $action == 'createcard') && $permissiontoaddupdatepaymentinformation) {
  1848. print '</form>';
  1849. }
  1850. // End of page
  1851. llxFooter();
  1852. $db->close();