paymentmodes.php 87 KB

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