paymentmodes.php 75 KB

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