paymentmodes.php 93 KB

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