paymentmodes.php 75 KB

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