paymentmodes.php 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304
  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; $nbremote = 0;
  1353. $arrayofremoteban = array();
  1354. $rib_list = $object->get_all_rib();
  1355. if (is_array($rib_list)) {
  1356. 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
  1357. print '<table class="liste centpercent">';
  1358. print '<tr class="liste_titre">';
  1359. print_liste_field_titre("Label");
  1360. print_liste_field_titre($form->textwithpicto($langs->trans('ExternalSystemID'), $langs->trans("IDOfPaymentInAnExternalSystem"))); // external system ID
  1361. print_liste_field_titre("Bank");
  1362. print_liste_field_titre("RIB");
  1363. print_liste_field_titre("IBAN");
  1364. print_liste_field_titre("BIC");
  1365. if (isModEnabled('prelevement')) {
  1366. print_liste_field_titre("RUM");
  1367. print_liste_field_titre("DateRUM");
  1368. print_liste_field_titre("WithdrawMode");
  1369. }
  1370. print_liste_field_titre("Default", '', '', '', '', '', '', '', 'center ');
  1371. if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT') && getDolGlobalInt("SOCIETE_RIB_ALLOW_ONLINESIGN")) {
  1372. print_liste_field_titre('', '', '', '', '', '', '', '', 'center ');
  1373. }
  1374. print_liste_field_titre('', '', '', '', '', '', '', '', 'center ');
  1375. // Fields from hook
  1376. $parameters = array('arrayfields'=>array(), 'linetype'=>'stripebantitle');
  1377. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1378. print $hookmanager->resPrint;
  1379. print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
  1380. print "</tr>\n";
  1381. // List of local BAN
  1382. foreach ($rib_list as $rib) {
  1383. $arrayofremoteban[$rib->stripe_card_ref] = $rib->stripe_card_ref;
  1384. $nblocal++;
  1385. print '<tr class="oddeven">';
  1386. // Label
  1387. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($rib->label).'">'.dol_escape_htmltag($rib->label).'</td>';
  1388. // External system ID
  1389. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($rib->stripe_card_ref.(empty($rib->stripe_account) ? '' : ' - '.$rib->stripe_account)).'">';
  1390. if (!empty($rib->stripe_card_ref) && !empty($rib->ext_payment_site)) {
  1391. if (isModEnabled('stripe') && in_array($rib->ext_payment_site, array('StripeTest', 'StripeLive'))) {
  1392. $connect = '';
  1393. if (!empty($stripeacc)) {
  1394. $connect = $stripeacc.'/';
  1395. }
  1396. if ($rib->ext_payment_site == 'StripeLive') {
  1397. $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$rib->stripe_card_ref;
  1398. } else {
  1399. $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$rib->stripe_card_ref;
  1400. }
  1401. print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')."</a> ";
  1402. }
  1403. // TODO Add hook here for other payment services
  1404. }
  1405. print dol_escape_htmltag($rib->stripe_card_ref);
  1406. print '</td>';
  1407. // Bank name
  1408. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($rib->bank).'">'.dol_escape_htmltag($rib->bank).'</td>';
  1409. // Account number
  1410. $string = '';
  1411. foreach ($rib->getFieldsToShow() as $val) {
  1412. if ($val == 'BankCode') {
  1413. $string .= $rib->code_banque.' ';
  1414. } elseif ($val == 'BankAccountNumber') {
  1415. $string .= $rib->number.' ';
  1416. } elseif ($val == 'DeskCode') {
  1417. $string .= $rib->code_guichet.' ';
  1418. } elseif ($val == 'BankAccountNumberKey') {
  1419. $string .= $rib->cle_rib.' ';
  1420. }
  1421. // Already output after
  1422. // } elseif ($val == 'BIC') {
  1423. // $string .= $rib->bic.' ';
  1424. // } elseif ($val == 'IBAN') {
  1425. // $string .= $rib->iban.' ';*/
  1426. //}
  1427. }
  1428. if (!empty($rib->label) && $rib->number) {
  1429. if (!checkBanForAccount($rib)) {
  1430. $string .= ' '.img_picto($langs->trans("ValueIsNotValid"), 'warning');
  1431. } else {
  1432. $string .= ' '.img_picto($langs->trans("ValueIsValid"), 'info');
  1433. }
  1434. }
  1435. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($string).'">';
  1436. print $string;
  1437. print '</td>';
  1438. // IBAN
  1439. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($rib->iban).'">';
  1440. if (!empty($rib->iban)) {
  1441. if (!checkIbanForAccount($rib)) {
  1442. print img_picto($langs->trans("IbanNotValid"), 'warning').' ';
  1443. }
  1444. }
  1445. print dol_escape_htmltag($rib->iban);
  1446. print '</td>';
  1447. // BIC
  1448. print '<td>';
  1449. if (!empty($rib->bic)) {
  1450. if (!checkSwiftForAccount($rib)) {
  1451. print img_picto($langs->trans("SwiftNotValid"), 'warning').' ';
  1452. }
  1453. }
  1454. print dol_escape_htmltag($rib->bic);
  1455. print '</td>';
  1456. if (isModEnabled('prelevement')) {
  1457. // RUM
  1458. //print '<td>'.$prelevement->buildRumNumber($object->code_client, $rib->datec, $rib->id).'</td>';
  1459. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($rib->rum).'">'.dol_escape_htmltag($rib->rum).'</td>';
  1460. print '<td>'.dol_print_date($rib->date_rum, 'day').'</td>';
  1461. // FRST or RCUR
  1462. print '<td>'.dol_escape_htmltag($rib->frstrecur).'</td>';
  1463. }
  1464. // Default
  1465. print '<td class="center" width="70">';
  1466. if (!$rib->default_rib) {
  1467. print '<a href="'.$_SERVER["PHP_SELF"].'?socid='.((int) $object->id).'&ribid='.((int) $rib->id).'&action=setasbankdefault&token='.newToken().'">';
  1468. print img_picto($langs->trans("Disabled"), 'off');
  1469. print '</a>';
  1470. } else {
  1471. print img_picto($langs->trans("Enabled"), 'on');
  1472. }
  1473. print '</td>';
  1474. // Generate doc
  1475. print '<td class="center">';
  1476. $buttonlabel = $langs->trans("BuildDoc");
  1477. $forname = 'builddocrib'.$rib->id;
  1478. include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
  1479. $modellist = ModeleBankAccountDoc::liste_modeles($db);
  1480. $out = '';
  1481. if (is_array($modellist) && count($modellist)) {
  1482. $out .= '<form action="'.$_SERVER["PHP_SELF"].(!getDolGlobalString('MAIN_JUMP_TAG') ? '' : '#builddoc').'" name="'.$forname.'" id="'.$forname.'_form" method="post">';
  1483. $out .= '<input type="hidden" name="action" value="builddocrib">';
  1484. $out .= '<input type="hidden" name="token" value="'.newToken().'">';
  1485. $out .= '<input type="hidden" name="socid" value="'.$object->id.'">';
  1486. $out .= '<input type="hidden" name="companybankid" value="'.$rib->id.'">';
  1487. if (is_array($modellist) && count($modellist) == 1) { // If there is only one element
  1488. $arraykeys = array_keys($modellist);
  1489. $modelselected = $arraykeys[0];
  1490. }
  1491. if (getDolGlobalString('BANKADDON_PDF')) {
  1492. $modelselected = $conf->global->BANKADDON_PDF;
  1493. }
  1494. $out .= $form->selectarray('modelrib'.$rib->id, $modellist, $modelselected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth125');
  1495. $out .= ajax_combobox('modelrib'.$rib->id);
  1496. $allowgenifempty = 0;
  1497. // Language code (if multilang)
  1498. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  1499. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  1500. $formadmin = new FormAdmin($db);
  1501. $defaultlang = $langs->getDefaultLang();
  1502. $morecss = 'maxwidth150';
  1503. if ($conf->browser->layout == 'phone') {
  1504. $morecss = 'maxwidth100';
  1505. }
  1506. $out .= $formadmin->select_language($defaultlang, 'lang_idrib'.$rib->id, 0, 0, 0, 0, 0, $morecss);
  1507. }
  1508. // Button
  1509. $genbutton = '<input class="button buttongen reposition nomargintop nomarginbottom" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
  1510. $genbutton .= ' type="submit" value="'.$buttonlabel.'"';
  1511. if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) {
  1512. $genbutton .= ' disabled';
  1513. }
  1514. $genbutton .= '>';
  1515. if ($allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') {
  1516. $langs->load("errors");
  1517. $genbutton .= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
  1518. }
  1519. if (!$allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') {
  1520. $genbutton = '';
  1521. }
  1522. if (empty($modellist) && !$showempty && $modulepart != 'unpaid') {
  1523. $genbutton = '';
  1524. }
  1525. $out .= $genbutton;
  1526. $out .= '</form>';
  1527. }
  1528. print $out;
  1529. print '</td>';
  1530. // Fields from hook
  1531. $parameters = array('arrayfields'=>array(), 'stripe_card_ref'=>$rib->stripe_card_ref, 'stripe_account'=>$rib->stripe_account, 'linetype'=>'stripeban');
  1532. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1533. print $hookmanager->resPrint;
  1534. if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT') && getDolGlobalInt("SOCIETE_RIB_ALLOW_ONLINESIGN")) {
  1535. // Show online signature link
  1536. print '<td class="right nowraponall">';
  1537. $useonlinesignature = 1;
  1538. if ($useonlinesignature) {
  1539. require_once DOL_DOCUMENT_ROOT . '/core/lib/signature.lib.php';
  1540. print showOnlineSignatureUrl($companybankaccount->element, $rib->id);
  1541. }
  1542. print '</td>';
  1543. }
  1544. // Edit/Delete
  1545. print '<td class="right nowraponall">';
  1546. if ($permissiontoaddupdatepaymentinformation) {
  1547. if (isModEnabled('stripe')) {
  1548. if (empty($rib->stripe_card_ref)) {
  1549. if ($object->client) {
  1550. // Add link to create BAN on Stripe
  1551. print '<a class="editfielda marginrightonly marginleftonly" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=syncsepatostripe&token='.newToken().'">';
  1552. print img_picto($langs->trans("CreateBANOnStripe"), 'stripe');
  1553. print '</a>';
  1554. } else {
  1555. print '<span class="opacitymedium marginrightonly marginleftonly">';
  1556. print img_picto($langs->trans("ThirdPartyMustBeACustomerToCreateBANOnStripe"), 'stripe');
  1557. print '</span>';
  1558. }
  1559. }
  1560. }
  1561. print '<a class="editfielda marginrightonly marginleftonly" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=edit">';
  1562. print img_picto($langs->trans("Modify"), 'edit');
  1563. print '</a>';
  1564. print '<a class="marginrightonly marginleftonly reposition" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=deletebank&token='.newToken().'">';
  1565. print img_picto($langs->trans("Delete"), 'delete');
  1566. print '</a>';
  1567. }
  1568. print '</td>';
  1569. print '</tr>';
  1570. }
  1571. // List of remote BAN (if not already added as local)
  1572. foreach ($listofsources as $src) {
  1573. if (!empty($arrayofremoteban[$src->id])) {
  1574. continue; // Already in previous list
  1575. }
  1576. $imgline = '';
  1577. if ($src->object == 'source' && $src->type == 'sepa_debit') {
  1578. $imgline = '<span class="fa fa-university fa-2x fa-fw"></span>';
  1579. } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit') {
  1580. $imgline = '<span class="fa fa-university fa-2x fa-fw"></span>';
  1581. } else {
  1582. continue;
  1583. }
  1584. $nbremote++;
  1585. print '<tr class="oddeven">';
  1586. print '<td>';
  1587. print '</td>';
  1588. // Src ID
  1589. print '<td class="tdoverflowmax150">';
  1590. $connect = '';
  1591. if (!empty($stripeacc)) {
  1592. $connect = $stripeacc.'/';
  1593. }
  1594. //$url='https://dashboard.stripe.com/'.$connect.'test/sources/'.$src->id;
  1595. $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$src->id;
  1596. if ($servicestatus) {
  1597. //$url='https://dashboard.stripe.com/'.$connect.'sources/'.$src->id;
  1598. $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$src->id;
  1599. }
  1600. print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')."</a> ";
  1601. print $src->id;
  1602. print '</td>';
  1603. // Bank
  1604. print '<td>';
  1605. print'</td>';
  1606. // Account number
  1607. print '<td valign="middle">';
  1608. print '</td>';
  1609. // IBAN
  1610. print '<td valign="middle">';
  1611. //var_dump($src);
  1612. print '</td>';
  1613. // BIC
  1614. print '<td valign="middle">';
  1615. //var_dump($src);
  1616. print '</td>';
  1617. if (isModEnabled('prelevement')) {
  1618. // RUM
  1619. print '<td valign="middle">';
  1620. //var_dump($src);
  1621. print '</td>';
  1622. // Date
  1623. print '<td valign="middle">';
  1624. //var_dump($src);
  1625. print '</td>';
  1626. // Mode mandate
  1627. print '<td valign="middle">';
  1628. //var_dump($src);
  1629. print '</td>';
  1630. }
  1631. // Default
  1632. print '<td class="center" width="50">';
  1633. if ((empty($customerstripe->invoice_settings) && $customerstripe->default_source != $src->id) ||
  1634. (!empty($customerstripe->invoice_settings) && $customerstripe->invoice_settings->default_payment_method != $src->id)) {
  1635. print '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=setassourcedefault&token='.newToken().'">';
  1636. print img_picto($langs->trans("Default"), 'off');
  1637. print '</a>';
  1638. } else {
  1639. print img_picto($langs->trans("Default"), 'on');
  1640. }
  1641. print '</td>';
  1642. /*
  1643. print '<td>';
  1644. print $langs->trans("Remote");
  1645. //if ($src->cvc_check == 'fail') print ' - CVC check fail';
  1646. print '</td>';
  1647. */
  1648. print '<td>';
  1649. print '</td>';
  1650. // Fields from hook
  1651. $parameters = array('arrayfields'=>array(), 'stripe_card_ref'=>$rib->stripe_card_ref, 'stripe_account'=>$rib->stripe_account, 'linetype'=>'stripebanremoteonly');
  1652. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1653. print $hookmanager->resPrint;
  1654. // Action column
  1655. print '<td class="right nowraponall">';
  1656. if ($permissiontoaddupdatepaymentinformation) {
  1657. print '<a class="marginleftonly marginrightonly reposition" href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=deletebank&token='.newToken().'">';
  1658. print img_picto($langs->trans("Delete"), 'delete');
  1659. print '</a>';
  1660. }
  1661. print '</td>';
  1662. print '</tr>';
  1663. }
  1664. if ($nbremote == 0 && $nblocal == 0) {
  1665. $colspan = 10;
  1666. if (isModEnabled('prelevement')) {
  1667. $colspan += 3;
  1668. }
  1669. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoBANRecord").'</span></td></tr>';
  1670. }
  1671. print '</table>';
  1672. print '</div>';
  1673. } else {
  1674. dol_print_error($db);
  1675. }
  1676. //Hook to display your print listing (list of CB card from Stancer Plugin for example)
  1677. $parameters = array('arrayfields'=>array(), 'param'=>'', 'sortfield'=>'', 'sortorder'=>'', 'linetype'=>'');
  1678. $reshook = $hookmanager->executeHooks('printNewTable', $parameters, $object);
  1679. print $hookmanager->resPrint;
  1680. if (!getDolGlobalString('SOCIETE_DISABLE_BUILDDOC')) {
  1681. print '<br>';
  1682. print '<div class="fichecenter"><div class="fichehalfleft">';
  1683. print '<a name="builddoc"></a>'; // ancre
  1684. /*
  1685. * Generated documents
  1686. */
  1687. $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
  1688. $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
  1689. 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);
  1690. // Show direct download link
  1691. if (getDolGlobalString('BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD')) {
  1692. $companybankaccounttemp = new CompanyBankAccount($db);
  1693. $companypaymentmodetemp = new CompanyPaymentMode($db);
  1694. $result = $companypaymentmodetemp->fetch(0, null, $object->id, 'ban');
  1695. include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
  1696. $ecmfile = new EcmFiles($db);
  1697. $result = $ecmfile->fetch(0, '', '', '', '', $companybankaccounttemp->table_element, $companypaymentmodetemp->id);
  1698. if ($result > 0) {
  1699. $companybankaccounttemp->last_main_doc = $ecmfile->filepath.'/'.$ecmfile->filename;
  1700. print '<br><!-- Link to download main doc -->'."\n";
  1701. print showDirectDownloadLink($companybankaccounttemp).'<br>';
  1702. }
  1703. }
  1704. print '</div><div class="fichehalfright">';
  1705. print '</div></div>';
  1706. print '<br>';
  1707. }
  1708. /*
  1709. include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
  1710. $modellist=ModeleBankAccountDoc::liste_modeles($db);
  1711. //print '<td>';
  1712. if (is_array($modellist) && count($modellist) == 1) // If there is only one element
  1713. {
  1714. $arraykeys=array_keys($modellist);
  1715. $modelselected=$arraykeys[0];
  1716. }
  1717. $out.= $form->selectarray('model', $modellist, $modelselected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100');
  1718. $out.= ajax_combobox('model');
  1719. //print $out;
  1720. $buttonlabel=$langs->trans("Generate");
  1721. $genbutton = '<input class="button buttongen reposition nomargintop nomarginbottom" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
  1722. $genbutton.= ' type="submit" value="'.$buttonlabel.'"';
  1723. $genbutton.= '>';
  1724. print $genbutton;
  1725. //print '</td>'; // TODO Add link to generate doc
  1726. */
  1727. }
  1728. // Edit BAN
  1729. if ($socid && $action == 'edit' && $permissiontoaddupdatepaymentinformation) {
  1730. print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
  1731. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1732. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  1733. print '<div class="underbanner clearboth"></div>';
  1734. print '<br>';
  1735. print '<div class="div-table-responsive-no-min">';
  1736. print '<table class="border centpercent">';
  1737. print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Label").'</td>';
  1738. print '<td><input class="minwidth300" type="text" name="label" value="'.$companybankaccount->label.'"></td></tr>';
  1739. print '<tr><td class="fieldrequired">'.$langs->trans("BankName").'</td>';
  1740. print '<td><input class="minwidth200" type="text" name="bank" value="'.$companybankaccount->bank.'"></td></tr>';
  1741. // Show fields of bank account
  1742. $bankaccount = $companybankaccount;
  1743. // Code here is similare than into bank.php for users
  1744. foreach ($bankaccount->getFieldsToShow(1) as $val) {
  1745. $require = false;
  1746. $tooltip = '';
  1747. if ($val == 'BankCode') {
  1748. $name = 'code_banque';
  1749. $size = 8;
  1750. $content = $bankaccount->code_banque;
  1751. } elseif ($val == 'DeskCode') {
  1752. $name = 'code_guichet';
  1753. $size = 8;
  1754. $content = $bankaccount->code_guichet;
  1755. } elseif ($val == 'BankAccountNumber') {
  1756. $name = 'number';
  1757. $size = 18;
  1758. $content = $bankaccount->number;
  1759. } elseif ($val == 'BankAccountNumberKey') {
  1760. $name = 'cle_rib';
  1761. $size = 3;
  1762. $content = $bankaccount->cle_rib;
  1763. } elseif ($val == 'IBAN') {
  1764. $name = 'iban';
  1765. $size = 30;
  1766. $content = $bankaccount->iban;
  1767. if ($bankaccount->needIBAN()) {
  1768. $require = true;
  1769. }
  1770. $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';
  1771. } elseif ($val == 'BIC') {
  1772. $name = 'bic';
  1773. $size = 12;
  1774. $content = $bankaccount->bic;
  1775. if ($bankaccount->needIBAN()) {
  1776. $require = true;
  1777. }
  1778. $tooltip = $langs->trans("Example").': LIABLT2XXXX';
  1779. }
  1780. print '<tr>';
  1781. print '<td'.($require ? ' class="fieldrequired" ' : '').'>';
  1782. if ($tooltip) {
  1783. print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name);
  1784. } else {
  1785. print $langs->trans($val);
  1786. }
  1787. print '</td>';
  1788. print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.$content.'"></td>';
  1789. print '</tr>';
  1790. }
  1791. print '<tr><td class="tdtop">'.$langs->trans("BankAccountDomiciliation").'</td><td>';
  1792. print '<textarea name="domiciliation" rows="4" cols="40" maxlength="255">';
  1793. print $companybankaccount->domiciliation;
  1794. print "</textarea></td></tr>";
  1795. print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
  1796. print '<td><input class="minwidth300" type="text" name="proprio" value="'.$companybankaccount->proprio.'"></td></tr>';
  1797. print "</td></tr>\n";
  1798. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
  1799. print '<textarea name="owner_address" rows="'.ROWS_4.'" cols="40" maxlength="255">';
  1800. print $companybankaccount->owner_address;
  1801. print "</textarea></td></tr>";
  1802. print '</table>';
  1803. print '</div>';
  1804. if (isModEnabled('prelevement')) {
  1805. print '<br>';
  1806. print '<div class="div-table-responsive-no-min">';
  1807. print '<table class="border centpercent">';
  1808. if (empty($companybankaccount->rum)) {
  1809. $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
  1810. }
  1811. // RUM
  1812. print '<tr><td class="titlefield">'.$langs->trans("RUM").'</td>';
  1813. print '<td><input class="minwidth300" type="text" name="rum" value="'.dol_escape_htmltag($companybankaccount->rum).'"></td></tr>';
  1814. $date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth'), GETPOST('date_rumday'), GETPOST('date_rumyear'));
  1815. print '<tr><td class="titlefield">'.$langs->trans("DateRUM").'</td>';
  1816. print '<td>'.$form->selectDate($date_rum ? $date_rum : $companybankaccount->date_rum, 'date_rum', 0, 0, 1, 'date_rum', 1, 1).'</td></tr>';
  1817. print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
  1818. $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RCUR" => $langs->trans("RECUR"));
  1819. print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur', 'alpha') ?GETPOST('frstrecur', 'alpha') : $companybankaccount->frstrecur), 0);
  1820. print '</td></tr>';
  1821. print '<tr><td>'.$langs->trans("ExternalSystemID")." ('pm_...' or 'src_...')</td>";
  1822. print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.$companypaymentmode->stripe_card_ref.'"></td></tr>';
  1823. print '</table>';
  1824. print '</div>';
  1825. }
  1826. print dol_get_fiche_end();
  1827. print $form->buttonsSaveCancel("Modify");
  1828. }
  1829. // Edit Card
  1830. if ($socid && $action == 'editcard' && $permissiontoaddupdatepaymentinformation) {
  1831. print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
  1832. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1833. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  1834. print '<div class="nofichecenter">';
  1835. print '<div class="underbanner clearboth"></div>';
  1836. print '<br>';
  1837. print '<table class="border centpercent">';
  1838. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
  1839. print '<td><input class="minwidth300" type="text" id="label" name="label" value="'.$companypaymentmode->label.'"></td></tr>';
  1840. print '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>';
  1841. print '<td><input class="minwidth200" type="text" name="proprio" value="'.$companypaymentmode->proprio.'"></td></tr>';
  1842. print '<tr><td>'.$langs->trans("CardNumber").'</td>';
  1843. print '<td><input class="minwidth200" type="text" name="cardnumber" value="'.$companypaymentmode->number.'"></td></tr>';
  1844. print '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>';
  1845. print '<td>';
  1846. print $formother->select_month($companypaymentmode->exp_date_month, 'exp_date_month', 1);
  1847. print $formother->selectyear($companypaymentmode->exp_date_year, 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly');
  1848. print '</td></tr>';
  1849. print '<tr><td>'.$langs->trans("CVN").'</td>';
  1850. print '<td><input size="8" type="text" name="cvn" value="'.$companypaymentmode->cvn.'"></td></tr>';
  1851. print '<tr><td>'.$langs->trans("ExternalSystemID")." ('pm_... ".$langs->trans("or")." card_....')</td>";
  1852. print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.$companypaymentmode->stripe_card_ref.'"></td></tr>';
  1853. print '</table>';
  1854. print '</div>';
  1855. print dol_get_fiche_end();
  1856. print $form->buttonsSaveCancel("Modify");
  1857. }
  1858. // Create BAN
  1859. if ($socid && $action == 'create' && $permissiontoaddupdatepaymentinformation) {
  1860. print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
  1861. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1862. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  1863. print '<div class="nofichecenter">';
  1864. print '<div class="underbanner clearboth"></div>';
  1865. print '<br>';
  1866. print '<table class="border centpercent">';
  1867. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
  1868. print '<td><input class="minwidth200" type="text" id="label" name="label" value="'.(GETPOSTISSET('label') ? GETPOST('label') : $object->name).'"></td></tr>';
  1869. print '<tr><td>'.$langs->trans("Bank").'</td>';
  1870. print '<td><input class="minwidth200" type="text" id="bank" name="bank" value="'.GETPOST('bank').'"></td></tr>';
  1871. // Show fields of bank account
  1872. foreach ($companybankaccount->getFieldsToShow(1) as $val) {
  1873. $require = false;
  1874. $tooltip = '';
  1875. if ($val == 'BankCode') {
  1876. $name = 'code_banque';
  1877. $size = 8;
  1878. $content = $companybankaccount->code_banque;
  1879. } elseif ($val == 'DeskCode') {
  1880. $name = 'code_guichet';
  1881. $size = 8;
  1882. $content = $companybankaccount->code_guichet;
  1883. } elseif ($val == 'BankAccountNumber') {
  1884. $name = 'number';
  1885. $size = 18;
  1886. $content = $companybankaccount->number;
  1887. } elseif ($val == 'BankAccountNumberKey') {
  1888. $name = 'cle_rib';
  1889. $size = 3;
  1890. $content = $companybankaccount->cle_rib;
  1891. } elseif ($val == 'IBAN') {
  1892. $name = 'iban';
  1893. $size = 30;
  1894. $content = $companybankaccount->iban;
  1895. if ($companybankaccount->needIBAN()) {
  1896. $require = true;
  1897. }
  1898. $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';
  1899. } elseif ($val == 'BIC') {
  1900. $name = 'bic';
  1901. $size = 12;
  1902. $content = $companybankaccount->bic;
  1903. if ($companybankaccount->needIBAN()) {
  1904. $require = true;
  1905. }
  1906. $tooltip = $langs->trans("Example").': LIABLT2XXXX';
  1907. }
  1908. print '<tr><td'.($require ? ' class="fieldrequired" ' : '').'>';
  1909. if ($tooltip) {
  1910. print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name);
  1911. } else {
  1912. print $langs->trans($val);
  1913. }
  1914. print '</td>';
  1915. print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.GETPOST($name).'"></td>';
  1916. print '</tr>';
  1917. }
  1918. print '<tr><td class="tdtop">'.$langs->trans("BankAccountDomiciliation").'</td><td>';
  1919. print '<textarea name="domiciliation" rows="'.ROWS_4.'" class="quatrevingtpercent" maxlength="255">';
  1920. print GETPOST('domiciliation');
  1921. print "</textarea></td></tr>";
  1922. print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
  1923. print '<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST('proprio').'"></td></tr>';
  1924. print "</td></tr>\n";
  1925. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
  1926. print '<textarea name="owner_address" rows="'.ROWS_4.'" class="quatrevingtpercent" maxlength="255">';
  1927. print GETPOST('owner_address');
  1928. print "</textarea></td></tr>";
  1929. print '</table>';
  1930. if (isModEnabled('prelevement')) {
  1931. print '<br>';
  1932. print '<table class="border centpercent">';
  1933. // RUM
  1934. print '<tr><td class="titlefieldcreate">'.$form->textwithpicto($langs->trans("RUM"), $langs->trans("RUMLong").'<br>'.$langs->trans("RUMWillBeGenerated")).'</td>';
  1935. print '<td colspan="4"><input type="text" class="minwidth300" name="rum" value="'.GETPOST('rum', 'alpha').'"></td></tr>';
  1936. $date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth'), GETPOST('date_rumday'), GETPOST('date_rumyear'));
  1937. print '<tr><td class="titlefieldcreate">'.$langs->trans("DateRUM").'</td>';
  1938. print '<td colspan="4">'.$form->selectDate($date_rum, 'date_rum', 0, 0, 1, 'date_rum', 1, 1).'</td></tr>';
  1939. print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
  1940. $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RCUR" => $langs->trans("RECUR"));
  1941. print $form->selectarray("frstrecur", $tblArraychoice, (GETPOSTISSET('frstrecur') ? GETPOST('frstrecur') : 'FRST'), 0);
  1942. print '</td></tr>';
  1943. print '<tr><td>'.$langs->trans("ExternalSystemID")." ('src_....')</td>";
  1944. print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.GETPOST('stripe_card_ref', 'alpha').'"></td></tr>';
  1945. print '</table>';
  1946. }
  1947. print '</div>';
  1948. print dol_get_fiche_end();
  1949. dol_set_focus('#bank');
  1950. print $form->buttonsSaveCancel("Add");
  1951. }
  1952. // Create Card
  1953. if ($socid && $action == 'createcard' && $permissiontoaddupdatepaymentinformation) {
  1954. print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
  1955. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1956. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  1957. print '<div class="nofichecenter">';
  1958. print '<div class="underbanner clearboth"></div>';
  1959. print '<br>';
  1960. print '<table class="border centpercent">';
  1961. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
  1962. print '<td><input class="minwidth200" type="text" id="label" name="label" value="'.GETPOST('label', 'alpha').'"></td></tr>';
  1963. print '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>';
  1964. print '<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST('proprio', 'alpha').'"></td></tr>';
  1965. print '<tr><td>'.$langs->trans("CardNumber").'</td>';
  1966. print '<td><input class="minwidth200" type="text" name="cardnumber" value="'.GETPOST('cardnumber', 'alpha').'"></td></tr>';
  1967. print '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>';
  1968. print '<td>';
  1969. print $formother->select_month(GETPOST('exp_date_month', 'int'), 'exp_date_month', 1);
  1970. print $formother->selectyear(GETPOST('exp_date_year', 'int'), 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly');
  1971. print '</td></tr>';
  1972. print '<tr><td>'.$langs->trans("CVN").'</td>';
  1973. print '<td><input class="width50" type="text" name="cvn" value="'.GETPOST('cvn', 'alpha').'"></td></tr>';
  1974. print '<tr><td>'.$langs->trans("ExternalSystemID")." ('card_....')</td>";
  1975. print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.GETPOST('stripe_card_ref', 'alpha').'"></td></tr>';
  1976. print '</table>';
  1977. print '</div>';
  1978. print dol_get_fiche_end();
  1979. dol_set_focus('#label');
  1980. print $form->buttonsSaveCancel("Add");
  1981. }
  1982. if ($socid && ($action == 'edit' || $action == 'editcard') && $permissiontoaddupdatepaymentinformation) {
  1983. print '</form>';
  1984. }
  1985. if ($socid && ($action == 'create' || $action == 'createcard') && $permissiontoaddupdatepaymentinformation) {
  1986. print '</form>';
  1987. }
  1988. // End of page
  1989. llxFooter();
  1990. $db->close();