card.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. <?php
  2. /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2014-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  8. * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
  10. * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
  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/compta/bank/card.php
  27. * \ingroup bank
  28. * \brief Page to create/view a bank account
  29. */
  30. // Load Dolibarr environment
  31. require '../../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbank.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  38. if (isModEnabled('categorie')) {
  39. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  40. }
  41. if (isModEnabled('accounting')) {
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  43. }
  44. if (isModEnabled('accounting')) {
  45. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  46. }
  47. if (isModEnabled('accounting')) {
  48. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  49. }
  50. // Load translation files required by the page
  51. $langs->loadLangs(array("banks", "bills", "categories", "companies", "compta", "withdrawals"));
  52. $action = GETPOST('action', 'aZ09');
  53. $cancel = GETPOST('cancel', 'alpha');
  54. $backtopage = GETPOST('backtopage', 'alpha');
  55. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  56. $object = new Account($db);
  57. $extrafields = new ExtraFields($db);
  58. // fetch optionals attributes and labels
  59. $extrafields->fetch_name_optionals_label($object->table_element);
  60. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  61. $hookmanager->initHooks(array('bankcard', 'globalcard'));
  62. // Security check
  63. $id = GETPOST("id", 'int') ? GETPOST("id", 'int') : GETPOST('ref', 'alpha');
  64. $fieldid = GETPOST("id", 'int') ? 'rowid' : 'ref';
  65. if (GETPOST("id", 'int') || GETPOST("ref")) {
  66. if (GETPOST("id", 'int')) {
  67. $object->fetch(GETPOST("id", 'int'));
  68. }
  69. if (GETPOST("ref")) {
  70. $object->fetch(0, GETPOST("ref"));
  71. }
  72. }
  73. $result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid);
  74. /*
  75. * Actions
  76. */
  77. $parameters = array();
  78. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  79. if ($reshook < 0) {
  80. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  81. }
  82. if (empty($reshook)) {
  83. $backurlforlist = DOL_URL_ROOT.'/compta/bank/list.php';
  84. if (empty($backtopage) || ($cancel && empty($id))) {
  85. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  86. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  87. $backtopage = $backurlforlist;
  88. } else {
  89. $backtopage = DOL_URL_ROOT.'/compta/bank/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  90. }
  91. }
  92. }
  93. if ($cancel) {
  94. if (!empty($backtopageforcancel)) {
  95. header("Location: ".$backtopageforcancel);
  96. exit;
  97. } elseif (!empty($backtopage)) {
  98. header("Location: ".$backtopage);
  99. exit;
  100. }
  101. $action = '';
  102. }
  103. if ($action == 'add') {
  104. $error = 0;
  105. $db->begin();
  106. // Create account
  107. $object = new Account($db);
  108. $object->ref = dol_string_nospecial(trim(GETPOST('ref', 'alpha')));
  109. $object->label = trim(GETPOST("label", 'alphanohtml'));
  110. $object->courant = GETPOST("type");
  111. $object->clos = GETPOST("clos");
  112. $object->rappro = (GETPOST("norappro", 'alpha') ? 0 : 1);
  113. $object->url = trim(GETPOST("url", 'alpha'));
  114. $object->bank = trim(GETPOST("bank"));
  115. $object->code_banque = trim(GETPOST("code_banque"));
  116. $object->code_guichet = trim(GETPOST("code_guichet"));
  117. $object->number = trim(GETPOST("number"));
  118. $object->cle_rib = trim(GETPOST("cle_rib"));
  119. $object->bic = trim(GETPOST("bic"));
  120. $object->iban = trim(GETPOST("iban"));
  121. $object->domiciliation = trim(GETPOST("domiciliation", "alphanohtml"));
  122. $object->pti_in_ctti = empty(GETPOST("pti_in_ctti")) ? 0 : 1;
  123. $object->proprio = trim(GETPOST("proprio", 'alphanohtml'));
  124. $object->owner_address = trim(GETPOST("owner_address", 'alphanohtml'));
  125. $object->owner_zip = trim(GETPOST("owner_zip", 'alphanohtml'));
  126. $object->owner_town = trim(GETPOST("owner_town", 'alphanohtml'));
  127. $object->owner_country_id = GETPOST("owner_country_id", 'int');
  128. $object->ics = trim(GETPOST("ics", 'alpha'));
  129. $object->ics_transfer = trim(GETPOST("ics_transfer", 'alpha'));
  130. $account_number = GETPOST('account_number', 'alphanohtml');
  131. if (empty($account_number) || $account_number == '-1') {
  132. $object->account_number = '';
  133. } else {
  134. $object->account_number = $account_number;
  135. }
  136. $fk_accountancy_journal = GETPOST('fk_accountancy_journal', 'int');
  137. if ($fk_accountancy_journal <= 0) {
  138. $object->fk_accountancy_journal = '';
  139. } else {
  140. $object->fk_accountancy_journal = $fk_accountancy_journal;
  141. }
  142. $object->solde = price2num(GETPOST("solde", 'alpha'));
  143. $object->balance = price2num(GETPOST("solde", 'alpha'));
  144. $object->date_solde = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST('reday', 'int'), GETPOST("reyear", 'int'));
  145. $object->currency_code = trim(GETPOST("account_currency_code"));
  146. $object->state_id = GETPOST("account_state_id", 'int');
  147. $object->country_id = GETPOST("account_country_id", 'int');
  148. $object->min_allowed = GETPOST("account_min_allowed", 'int');
  149. $object->min_desired = GETPOST("account_min_desired", 'int');
  150. $object->comment = trim(GETPOST("account_comment", 'restricthtml'));
  151. $object->fk_user_author = $user->id;
  152. if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number)) {
  153. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountancyCode")), null, 'errors');
  154. $action = 'create'; // Force chargement page en mode creation
  155. $error++;
  156. }
  157. if (empty($object->ref)) {
  158. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
  159. $action = 'create'; // Force chargement page en mode creation
  160. $error++;
  161. }
  162. if (empty($object->label)) {
  163. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("LabelBankCashAccount")), null, 'errors');
  164. $action = 'create'; // Force chargement page en mode creation
  165. $error++;
  166. }
  167. // Fill array 'array_options' with data from add form
  168. $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  169. if (!$error) {
  170. $id = $object->create($user);
  171. if ($id > 0) {
  172. // Category association
  173. $categories = GETPOST('categories', 'array');
  174. $object->setCategories($categories);
  175. $action = '';
  176. } else {
  177. $error++;
  178. setEventMessages($object->error, $object->errors, 'errors');
  179. $action = 'create'; // Force chargement page en mode creation
  180. }
  181. }
  182. if (!$error) {
  183. $noback = 0;
  184. $db->commit();
  185. $urltogo = $backtopage ? str_replace('__ID__', $object->id, $backtopage) : $backurlforlist;
  186. $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
  187. if (empty($noback)) {
  188. header("Location: " . $urltogo);
  189. exit;
  190. }
  191. } else {
  192. $db->rollback();
  193. }
  194. }
  195. if ($action == 'update') {
  196. $error = 0;
  197. // Update account
  198. $object = new Account($db);
  199. $object->fetch(GETPOST("id", 'int'));
  200. $object->ref = dol_string_nospecial(trim(GETPOST('ref', 'alpha')));
  201. $object->label = trim(GETPOST("label", 'alphanohtml'));
  202. $object->courant = GETPOST("type");
  203. $object->clos = GETPOST("clos");
  204. $object->rappro = (GETPOST("norappro", 'alpha') ? 0 : 1);
  205. $object->url = trim(GETPOST("url", 'alpha'));
  206. $object->bank = trim(GETPOST("bank"));
  207. $object->code_banque = trim(GETPOST("code_banque"));
  208. $object->code_guichet = trim(GETPOST("code_guichet"));
  209. $object->number = trim(GETPOST("number"));
  210. $object->cle_rib = trim(GETPOST("cle_rib"));
  211. $object->bic = trim(GETPOST("bic"));
  212. $object->iban = trim(GETPOST("iban"));
  213. $object->domiciliation = trim(GETPOST("domiciliation", "alphanohtml"));
  214. $object->pti_in_ctti = empty(GETPOST("pti_in_ctti")) ? 0 : 1;
  215. $object->proprio = trim(GETPOST("proprio", 'alphanohtml'));
  216. $object->owner_address = trim(GETPOST("owner_address", 'alphanohtml'));
  217. $object->owner_zip = trim(GETPOST("owner_zip", 'alphanohtml'));
  218. $object->owner_town = trim(GETPOST("owner_town", 'alphanohtml'));
  219. $object->owner_country_id = GETPOST("owner_country_id", 'int');
  220. $object->ics = trim(GETPOST("ics", 'alpha'));
  221. $object->ics_transfer = trim(GETPOST("ics_transfer", 'alpha'));
  222. $account_number = GETPOST('account_number', 'alphanohtml');
  223. if (empty($account_number) || $account_number == '-1') {
  224. $object->account_number = '';
  225. } else {
  226. $object->account_number = $account_number;
  227. }
  228. $fk_accountancy_journal = GETPOST('fk_accountancy_journal', 'int');
  229. if ($fk_accountancy_journal <= 0) {
  230. $object->fk_accountancy_journal = '';
  231. } else {
  232. $object->fk_accountancy_journal = $fk_accountancy_journal;
  233. }
  234. $object->currency_code = trim(GETPOST("account_currency_code"));
  235. $object->state_id = GETPOST("account_state_id", 'int');
  236. $object->country_id = GETPOST("account_country_id", 'int');
  237. $object->min_allowed = GETPOST("account_min_allowed", 'int');
  238. $object->min_desired = GETPOST("account_min_desired", 'int');
  239. $object->comment = trim(GETPOST("account_comment", 'restricthtml'));
  240. if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number)) {
  241. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountancyCode")), null, 'errors');
  242. $action = 'edit'; // Force chargement page en mode creation
  243. $error++;
  244. }
  245. if (empty($object->ref)) {
  246. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
  247. $action = 'edit'; // Force chargement page en mode creation
  248. $error++;
  249. }
  250. if (empty($object->label)) {
  251. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("LabelBankCashAccount")), null, 'errors');
  252. $action = 'edit'; // Force chargement page en mode creation
  253. $error++;
  254. }
  255. $db->begin();
  256. if (!$error) {
  257. // Fill array 'array_options' with data from add form
  258. $ret = $extrafields->setOptionalsFromPost(null, $object);
  259. }
  260. if (!$error) {
  261. $result = $object->update($user);
  262. if ($result >= 0) {
  263. // Category association
  264. $categories = GETPOST('categories', 'array');
  265. $object->setCategories($categories);
  266. $_GET["id"] = GETPOST("id", 'int'); // Force chargement page en mode visu
  267. } else {
  268. $error++;
  269. setEventMessages($object->error, $object->errors, 'errors');
  270. $action = 'edit'; // Force chargement page edition
  271. }
  272. }
  273. if (!$error) {
  274. $db->commit();
  275. } else {
  276. $db->rollback();
  277. }
  278. }
  279. if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->hasRight('banque', 'configurer')) {
  280. // Delete
  281. $object = new Account($db);
  282. $object->fetch(GETPOST("id", "int"));
  283. $result = $object->delete($user);
  284. if ($result > 0) {
  285. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  286. header("Location: " . DOL_URL_ROOT . "/compta/bank/list.php");
  287. exit;
  288. } else {
  289. setEventMessages($object->error, $object->errors, 'errors');
  290. $action = '';
  291. }
  292. }
  293. }
  294. /*
  295. * View
  296. */
  297. $form = new Form($db);
  298. $formbank = new FormBank($db);
  299. $formcompany = new FormCompany($db);
  300. if (isModEnabled('accounting')) {
  301. $formaccounting = new FormAccounting($db);
  302. }
  303. $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  304. $help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:Módulo_Bancos_y_Cajas|DE:Modul_Banken_und_Barbestände';
  305. if ($action == 'create') {
  306. $title = $langs->trans("NewFinancialAccount");
  307. } elseif (!empty($object->ref)) {
  308. $title = $object->ref." - ".$langs->trans("Card");
  309. }
  310. llxHeader("", $title, $help_url);
  311. // Creation
  312. if ($action == 'create') {
  313. print load_fiche_titre($langs->trans("NewFinancialAccount"), '', 'bank_account');
  314. if ($conf->use_javascript_ajax) {
  315. print "\n".'<script type="text/javascript">';
  316. print 'jQuery(document).ready(function () {
  317. jQuery("#type").change(function() {
  318. document.formsoc.action.value="create";
  319. document.formsoc.submit();
  320. });
  321. jQuery("#selectaccount_country_id").change(function() {
  322. document.formsoc.action.value="create";
  323. document.formsoc.submit();
  324. });
  325. })';
  326. print '</script>'."\n";
  327. }
  328. print '<form action="'.$_SERVER["PHP_SELF"].'" name="formsoc" method="post">';
  329. print '<input type="hidden" name="token" value="'.newToken().'">';
  330. print '<input type="hidden" name="action" value="add">';
  331. print '<input type="hidden" name="clos" value="0">';
  332. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  333. print dol_get_fiche_head('');
  334. print '<table class="border centpercent tableforfieldcreate">';
  335. // Ref
  336. print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Ref").'</td>';
  337. print '<td><input type="text" class="flat width100" name="ref" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST("ref", 'alpha') : $object->ref).'" maxlength="12" autofocus></td></tr>';
  338. // Label
  339. print '<tr><td class="fieldrequired">'.$langs->trans("LabelBankCashAccount").'</td>';
  340. print '<td><input type="text" class="flat maxwidth150onsmartphone" name="label" value="'.dol_escape_htmltag(GETPOST('label', 'alpha')).'"></td></tr>';
  341. // Type
  342. print '<tr><td class="fieldrequired">'.$langs->trans("AccountType").'</td>';
  343. print '<td>';
  344. $formbank->selectTypeOfBankAccount(GETPOSTISSET("type") ? GETPOST('type', 'int') : Account::TYPE_CURRENT, 'type');
  345. print '</td></tr>';
  346. // Currency
  347. print '<tr><td class="fieldrequired">'.$langs->trans("Currency").'</td>';
  348. print '<td>';
  349. $selectedcode = $object->currency_code;
  350. if (!$selectedcode) {
  351. $selectedcode = $conf->currency;
  352. }
  353. print $form->selectCurrency((GETPOSTISSET("account_currency_code") ? GETPOST("account_currency_code") : $selectedcode), 'account_currency_code');
  354. //print $langs->trans("Currency".$conf->currency);
  355. //print '<input type="hidden" name="account_currency_code" value="'.$conf->currency.'">';
  356. print '</td></tr>';
  357. // Status
  358. print '<tr><td class="fieldrequired">'.$langs->trans("Status").'</td>';
  359. print '<td>';
  360. print $form->selectarray("clos", $object->status, (GETPOST('clos', 'int') != '' ? GETPOST('clos', 'int') : $object->clos), 0, 0, 0, '', 0, 0, 0, '', 'maxwidth150onsmartphone');
  361. print '</td></tr>';
  362. // Country
  363. $selectedcode = '';
  364. if (GETPOSTISSET("account_country_id")) {
  365. $selectedcode = GETPOST("account_country_id") ? GETPOST("account_country_id") : $object->country_code;
  366. } elseif (empty($selectedcode)) {
  367. $selectedcode = $mysoc->country_code;
  368. }
  369. $object->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
  370. print '<tr><td class="fieldrequired">'.$langs->trans("BankAccountCountry").'</td>';
  371. print '<td>';
  372. print img_picto('', 'country', 'class="pictofixedwidth"');
  373. print $form->select_country($selectedcode, 'account_country_id');
  374. if ($user->admin) {
  375. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  376. }
  377. print '</td></tr>';
  378. // State
  379. print '<tr><td>'.$langs->trans('State').'</td><td>';
  380. if ($selectedcode) {
  381. print img_picto('', 'state', 'class="pictofixedwidth"');
  382. print $formcompany->select_state(GETPOSTISSET("account_state_id") ? GETPOST("account_state_id") : '', $selectedcode, 'account_state_id');
  383. } else {
  384. print $countrynotdefined;
  385. }
  386. print '</td></tr>';
  387. $type = (GETPOSTISSET("type") ? GETPOST('type', 'int') : Account::TYPE_CURRENT); // add default value
  388. if ($type == Account::TYPE_SAVINGS || $type == Account::TYPE_CURRENT) {
  389. print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
  390. print '<textarea class="flat quatrevingtpercent" name="domiciliation" rows="'.ROWS_2.'">';
  391. print(GETPOSTISSET('domiciliation') ? GETPOST('domiciliation') : $object->domiciliation);
  392. print "</textarea></td></tr>";
  393. }
  394. // Web
  395. print '<tr><td>'.$langs->trans("Web").'</td>';
  396. print '<td>';
  397. print img_picto('', 'globe', 'class="pictofixedwidth"');
  398. print '<input class="minwidth300 widthcentpercentminusx maxwidth500" type="text" class="flat" name="url" value="'.GETPOST("url").'">';
  399. print '</td></tr>';
  400. // Tags-Categories
  401. if (isModEnabled('categorie')) {
  402. print '<tr><td>'.$langs->trans("Categories").'</td><td>';
  403. $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1);
  404. $arrayselected = array();
  405. $c = new Categorie($db);
  406. $cats = $c->containing($object->id, Categorie::TYPE_ACCOUNT);
  407. if (is_array($cats)) {
  408. foreach ($cats as $cat) {
  409. $arrayselected[] = $cat->id;
  410. }
  411. }
  412. print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  413. print "</td></tr>";
  414. }
  415. // Comment
  416. print '<tr><td>'.$langs->trans("Comment").'</td>';
  417. print '<td>';
  418. // Editor wysiwyg
  419. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  420. $doleditor = new DolEditor('account_comment', (GETPOST("account_comment") ? GETPOST("account_comment") : $object->comment), '', 90, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_4, '90%');
  421. $doleditor->Create();
  422. print '</td></tr>';
  423. // Other attributes
  424. $parameters = array();
  425. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  426. print $hookmanager->resPrint;
  427. if (empty($reshook)) {
  428. print $object->showOptionals($extrafields, 'create', $parameters);
  429. }
  430. print '</table>';
  431. print '<br>';
  432. print '<table class="border centpercent">';
  433. // Sold
  434. print '<tr><td class="titlefieldcreate">'.$langs->trans("InitialBankBalance").'</td>';
  435. print '<td><input size="12" type="text" class="flat" name="solde" value="'.(GETPOST("solde") ? GETPOST("solde") : price2num($object->solde)).'"></td></tr>';
  436. print '<tr><td>'.$langs->trans("Date").'</td>';
  437. print '<td>';
  438. print $form->selectDate('', 're', 0, 0, 0, 'formsoc');
  439. print '</td></tr>';
  440. print '<tr><td>'.$langs->trans("BalanceMinimalAllowed").'</td>';
  441. print '<td><input size="12" type="text" class="flat" name="account_min_allowed" value="'.(GETPOST("account_min_allowed") ? GETPOST("account_min_allowed") : $object->min_allowed).'"></td></tr>';
  442. print '<tr><td>'.$langs->trans("BalanceMinimalDesired").'</td>';
  443. print '<td><input size="12" type="text" class="flat" name="account_min_desired" value="'.(GETPOST("account_min_desired") ? GETPOST("account_min_desired") : $object->min_desired).'"></td></tr>';
  444. print '</table>';
  445. print '<br>';
  446. $type = (GETPOSTISSET("type") ? GETPOST('type', 'int') : Account::TYPE_CURRENT); // add default value
  447. if ($type == Account::TYPE_SAVINGS || $type == Account::TYPE_CURRENT) {
  448. print '<table class="border centpercent">';
  449. // If bank account
  450. print '<tr><td class="titlefieldcreate">'.$langs->trans("BankName").'</td>';
  451. print '<td><input type="text" class="flat minwidth150" name="bank" value="'.(GETPOST('bank') ? GETPOST('bank', 'alpha') : $object->bank).'"></td>';
  452. print '</tr>';
  453. $ibankey = FormBank::getIBANLabel($object);
  454. $bickey = "BICNumber";
  455. if ($object->getCountryCode() == 'IN') {
  456. $bickey = "SWIFT";
  457. }
  458. // IBAN
  459. print '<tr><td>'.$langs->trans($ibankey).'</td>';
  460. print '<td><input maxlength="34" type="text" class="flat minwidth300" name="iban" value="'.(GETPOSTISSET('iban') ? GETPOST('iban', 'alpha') : $object->iban).'"></td></tr>';
  461. // BIC
  462. print '<tr><td>'.$langs->trans($bickey).'</td>';
  463. print '<td><input maxlength="11" type="text" class="flat minwidth150" name="bic" value="'.(GETPOSTISSET('bic') ? GETPOST('bic', 'alpha') : $object->bic).'"></td></tr>';
  464. // Show fields of bank account
  465. $sizecss = '';
  466. foreach ($object->getFieldsToShow() as $val) {
  467. $content = '';
  468. if ($val == 'BankCode') {
  469. $name = 'code_banque';
  470. $sizecss = 'minwidth100';
  471. $content = $object->code_banque;
  472. } elseif ($val == 'DeskCode') {
  473. $name = 'code_guichet';
  474. $sizecss = 'minwidth100';
  475. $content = $object->code_guichet;
  476. } elseif ($val == 'BankAccountNumber') {
  477. $name = 'number';
  478. $sizecss = 'minwidth200';
  479. $content = $object->number;
  480. } elseif ($val == 'BankAccountNumberKey') {
  481. $name = 'cle_rib';
  482. $sizecss = 'minwidth50';
  483. $content = $object->cle_rib;
  484. }
  485. print '<td>'.$langs->trans($val).'</td>';
  486. print '<td><input type="text" class="flat '.$sizecss.'" name="'.$name.'" value="'.(GETPOSTISSET($name) ? GETPOST($name, 'alpha') : $content).'"></td>';
  487. print '</tr>';
  488. }
  489. if (isModEnabled('paymentbybanktransfer')) {
  490. if ($mysoc->isInEEC()) {
  491. print '<tr><td>'.$form->textwithpicto($langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformation"), $langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformationHelp")).'</td>';
  492. print '<td><input type="checkbox" class="flat" name="pti_in_ctti"'. (empty(GETPOST('pti_in_ctti')) ? '' : ' checked ') . '>';
  493. print '</td></tr>';
  494. }
  495. }
  496. print '</table>';
  497. print '<hr>';
  498. print '<table class="border centpercent">';
  499. print '<tr><td class="titlefieldcreate">'.$langs->trans("BankAccountOwner").'</td>';
  500. print '<td><input type="text" class="flat minwidth300" name="proprio" value="'.(GETPOST('proprio') ? GETPOST('proprio', 'alpha') : $object->proprio).'">';
  501. print '</td></tr>';
  502. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
  503. print '<textarea class="flat quatrevingtpercent" name="owner_address" rows="'.ROWS_2.'">';
  504. print(GETPOST('owner_address') ? GETPOST('owner_address', 'alpha') : $object->owner_address);
  505. print "</textarea></td></tr>";
  506. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerZip").'</td>';
  507. print '<td><input type="text" class="flat maxwidth100" name="owner_zip" value="'.(GETPOST('owner_zip') ? GETPOST('owner_zip', 'alpha') : $object->owner_zip).'">';
  508. print '</td></tr>';
  509. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerTown").'</td>';
  510. print '<td><input type="text" class="flat maxwidth200" name="owner_town" value="'.(GETPOST('owner_town') ? GETPOST('owner_town', 'alpha') : $object->owner_town).'">';
  511. print '</td></tr>';
  512. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerCountry").'</td>';
  513. print '<td>';
  514. print img_picto('', 'country', 'class="pictofixedwidth"');
  515. print $form->select_country(GETPOST('owner_country_id') ? GETPOST('owner_country_id', 'alpha') : $object->owner_country_id, 'owner_country_id');
  516. print '</td></tr>';
  517. print '</table>';
  518. print '<hr>';
  519. }
  520. print '<table class="border centpercent">';
  521. // Accountancy code
  522. $fieldrequired = '';
  523. if (getDolGlobalString('MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED')) {
  524. $fieldrequired = 'fieldrequired ';
  525. }
  526. if (isModEnabled('accounting')) {
  527. print '<tr><td class="'.$fieldrequired.'titlefieldcreate">'.$langs->trans("AccountancyCode").'</td>';
  528. print '<td>';
  529. print img_picto('', 'accounting_account', 'class="pictofixedwidth"');
  530. print $formaccounting->select_account($object->account_number, 'account_number', 1, '', 1, 1);
  531. if ($formaccounting->nbaccounts == 0) {
  532. $langs->load("errors");
  533. $htmltext = $langs->transnoentitiesnoconv("WarningGoOnAccountancySetupToAddAccounts", $langs->transnoentitiesnoconv("MenuAccountancy"), $langs->transnoentitiesnoconv("Setup"), $langs->transnoentitiesnoconv("Chartofaccounts"));
  534. print $form->textwithpicto('', $htmltext);
  535. }
  536. print '</td></tr>';
  537. } else {
  538. print '<tr><td class="'.$fieldrequired.'titlefieldcreate">'.$langs->trans("AccountancyCode").'</td>';
  539. print '<td><input type="text" name="account_number" value="'.(GETPOST("account_number") ? GETPOST('account_number', 'alpha') : $object->account_number).'"></td></tr>';
  540. }
  541. // Accountancy journal
  542. if (isModEnabled('accounting')) {
  543. print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
  544. print '<td>';
  545. print $formaccounting->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, 0, 0);
  546. print '</td></tr>';
  547. }
  548. print '</table>';
  549. print dol_get_fiche_end();
  550. print $form->buttonsSaveCancel("CreateAccount");
  551. print '</form>';
  552. } else {
  553. // View and edit mode
  554. if ((GETPOST("id", 'int') || GETPOST("ref")) && $action != 'edit') {
  555. // Show tabs
  556. $head = bank_prepare_head($object);
  557. print dol_get_fiche_head($head, 'bankname', $langs->trans("FinancialAccount"), -1, 'account', 0, '', '', 0, '', 1);
  558. $formconfirm = '';
  559. // Confirmation to delete
  560. if ($action == 'delete') {
  561. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("DeleteAccount"), $langs->trans("ConfirmDeleteAccount"), "confirm_delete");
  562. }
  563. // Print form confirm
  564. print $formconfirm;
  565. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  566. $morehtmlref = '';
  567. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  568. print '<div class="fichecenter">';
  569. print '<div class="fichehalfleft">';
  570. print '<div class="underbanner clearboth"></div>';
  571. print '<table class="border centpercent tableforfield">';
  572. // Type
  573. print '<tr><td class="titlefield">'.$langs->trans("AccountType").'</td>';
  574. print '<td>'.$object->type_lib[$object->type].'</td></tr>';
  575. // Currency
  576. print '<tr><td>'.$langs->trans("Currency").'</td>';
  577. print '<td>';
  578. $selectedcode = $object->currency_code;
  579. if (!$selectedcode) {
  580. $selectedcode = $conf->currency;
  581. }
  582. print $langs->trans("Currency".$selectedcode);
  583. print '</td></tr>';
  584. // Conciliate
  585. print '<tr><td>'.$langs->trans("Conciliable").'</td>';
  586. print '<td>';
  587. $conciliate = $object->canBeConciliated();
  588. if ($conciliate == -2) {
  589. print $langs->trans("No").' <span class="opacitymedium">('.$langs->trans("CashAccount").')</span>';
  590. } elseif ($conciliate == -3) {
  591. print $langs->trans("No").' <span class="opacitymedium">('.$langs->trans("Closed").')</span>';
  592. } else {
  593. print($object->rappro == 1 ? $langs->trans("Yes") : ($langs->trans("No").' <span class="opacitymedium">('.$langs->trans("ConciliationDisabled").')</span>'));
  594. }
  595. print '</td></tr>';
  596. print '<tr><td>'.$langs->trans("BalanceMinimalAllowed").'</td>';
  597. print '<td>'.$object->min_allowed.'</td></tr>';
  598. print '<tr><td>'.$langs->trans("BalanceMinimalDesired").'</td>';
  599. print '<td>'.$object->min_desired.'</td></tr>';
  600. // Accountancy code
  601. print '<tr class="liste_titre_add"><td class="titlefield">'.$langs->trans("AccountancyCode").'</td>';
  602. print '<td>';
  603. if (isModEnabled('accounting')) {
  604. $accountingaccount = new AccountingAccount($db);
  605. $accountingaccount->fetch('', $object->account_number, 1);
  606. print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
  607. } else {
  608. print $object->account_number;
  609. }
  610. print '</td></tr>';
  611. // Accountancy journal
  612. if (isModEnabled('accounting')) {
  613. print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
  614. print '<td>';
  615. if ($object->fk_accountancy_journal > 0) {
  616. $accountingjournal = new AccountingJournal($db);
  617. $accountingjournal->fetch($object->fk_accountancy_journal);
  618. print $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  619. }
  620. print '</td></tr>';
  621. }
  622. // Other attributes
  623. $cols = 2;
  624. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  625. print '</table>';
  626. print '</div>';
  627. print '<div class="fichehalfright">';
  628. print '<div class="underbanner clearboth"></div>';
  629. print '<table class="border tableforfield centpercent">';
  630. // Categories
  631. if (isModEnabled('categorie')) {
  632. print '<tr><td class="titlefield">'.$langs->trans("Categories").'</td><td>';
  633. print $form->showCategories($object->id, Categorie::TYPE_ACCOUNT, 1);
  634. print "</td></tr>";
  635. }
  636. print '<tr><td class="tdtop titlefield">'.$langs->trans("Comment").'</td>';
  637. print '<td>'.dol_htmlentitiesbr($object->comment).'</td></tr>';
  638. print '</table>';
  639. if ($object->type == Account::TYPE_SAVINGS || $object->type == Account::TYPE_CURRENT) {
  640. print '<table class="border tableforfield centpercent">';
  641. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("BankName").'</td>';
  642. print '<td>'.$object->bank.'</td></tr>';
  643. $ibankey = FormBank::getIBANLabel($object);
  644. $bickey = "BICNumber";
  645. if ($object->getCountryCode() == 'IN') {
  646. $bickey = "SWIFT";
  647. }
  648. // IBAN
  649. print '<tr><td>'.$langs->trans($ibankey).'</td>';
  650. print '<td>'.getIbanHumanReadable($object).'&nbsp;';
  651. if (!empty($object->iban)) {
  652. if (!checkIbanForAccount($object)) {
  653. print img_picto($langs->trans("IbanNotValid"), 'warning');
  654. } else {
  655. print img_picto($langs->trans("IbanValid"), 'info');
  656. }
  657. }
  658. print '</td></tr>';
  659. // BIC
  660. print '<tr><td>'.$langs->trans($bickey).'</td>';
  661. print '<td>'.$object->bic.'&nbsp;';
  662. if (!empty($object->bic)) {
  663. if (!checkSwiftForAccount($object)) {
  664. print img_picto($langs->trans("SwiftNotValid"), 'warning');
  665. } else {
  666. print img_picto($langs->trans("SwiftValid"), 'info');
  667. }
  668. }
  669. print '</td></tr>';
  670. // TODO Add a link "Show more..." for all ohter informations.
  671. // Show fields of bank account
  672. foreach ($object->getFieldsToShow() as $val) {
  673. $content = '';
  674. if ($val == 'BankCode') {
  675. $content = $object->code_banque;
  676. } elseif ($val == 'DeskCode') {
  677. $content = $object->code_guichet;
  678. } elseif ($val == 'BankAccountNumber') {
  679. $content = $object->number;
  680. } elseif ($val == 'BankAccountNumberKey') {
  681. $content = $object->cle_rib;
  682. }
  683. print '<tr><td>'.$langs->trans($val).'</td>';
  684. print '<td>'.$content.'</td>';
  685. print '</tr>';
  686. }
  687. if (isModEnabled('prelevement')) {
  688. print '<tr><td>'.$form->textwithpicto($langs->trans("ICS"), $langs->trans("ICS").' ('.$langs->trans("UsedFor", $langs->transnoentitiesnoconv("StandingOrder")).')').'</td>';
  689. print '<td>'.$object->ics.'</td>';
  690. print '</tr>';
  691. }
  692. if (isModEnabled('paymentbybanktransfer')) {
  693. if (getDolGlobalString("SEPA_USE_IDS")) { // ICS is not used with bank transfer !
  694. print '<tr><td>'.$form->textwithpicto($langs->trans("IDS"), $langs->trans("IDS").' ('.$langs->trans("UsedFor", $langs->transnoentitiesnoconv("BankTransfer")).')').'</td>';
  695. print '<td>'.$object->ics_transfer.'</td>';
  696. print '</tr>';
  697. }
  698. if ($mysoc->isInEEC()) {
  699. print '<tr><td>'.$form->textwithpicto($langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformation"), $langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformationHelp")).'</td><td>';
  700. print(empty($object->pti_in_ctti) ? $langs->trans("No") : $langs->trans("Yes"));
  701. print "</td></tr>\n";
  702. }
  703. }
  704. print '<tr><td>'.$langs->trans("BankAccountOwner").'</td><td>';
  705. print $object->proprio;
  706. print "</td></tr>\n";
  707. print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
  708. print nl2br($object->owner_address);
  709. print "</td></tr>\n";
  710. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerZip").'</td>';
  711. print '<td>'.$object->owner_zip;
  712. print '</td></tr>';
  713. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerTown").'</td>';
  714. print '<td>'.$object->owner_town;
  715. print '</td></tr>';
  716. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerCountry").'</td>';
  717. print '<td>';
  718. $object->owner_country_code = dol_getIdFromCode($db, $object->owner_country_id, 'c_country', 'rowid', 'code');
  719. $langs->load("dict");
  720. print(empty($object->owner_country_code) ? '' : $langs->convToOutputCharset($langs->transnoentitiesnoconv("Country".$object->owner_country_code)));
  721. print '</td></tr>';
  722. print '</table>';
  723. }
  724. print '</div>';
  725. print '</div>';
  726. print '<div class="clearboth"></div>';
  727. print dol_get_fiche_end();
  728. /*
  729. * Action bar
  730. */
  731. print '<div class="tabsAction">';
  732. if ($user->hasRight('banque', 'configurer')) {
  733. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Modify").'</a>';
  734. }
  735. $canbedeleted = $object->can_be_deleted(); // Renvoi vrai si compte sans mouvements
  736. if ($user->hasRight('banque', 'configurer') && $canbedeleted) {
  737. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Delete").'</a>';
  738. }
  739. print '</div>';
  740. }
  741. /* ************************************************************************** */
  742. /* */
  743. /* Edition */
  744. /* */
  745. /* ************************************************************************** */
  746. if (GETPOST('id', 'int') && $action == 'edit' && $user->hasRight('banque', 'configurer')) {
  747. print load_fiche_titre($langs->trans("EditFinancialAccount"), '', 'bank_account');
  748. if ($conf->use_javascript_ajax) {
  749. print "\n".'<script type="text/javascript">';
  750. print 'jQuery(document).ready(function () {
  751. jQuery("#type").change(function() {
  752. document.formsoc.action.value="edit";
  753. document.formsoc.submit();
  754. });
  755. })'."\n";
  756. print 'jQuery(document).ready(function () {
  757. jQuery("#selectaccount_country_id").change(function() {
  758. document.formsoc.action.value="edit";
  759. document.formsoc.submit();
  760. });
  761. })';
  762. print '</script>'."\n";
  763. }
  764. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post" name="formsoc">';
  765. print '<input type="hidden" name="token" value="'.newToken().'">';
  766. print '<input type="hidden" name="action" value="update">';
  767. print '<input type="hidden" name="id" value="'.GETPOST("id", 'int').'">'."\n\n";
  768. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  769. print dol_get_fiche_head(array(), 0, '', 0);
  770. //print '<div class="underbanner clearboth"></div>';
  771. print '<table class="border centpercent tableforfieldcreate">';
  772. // Ref
  773. print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Ref").'</td>';
  774. print '<td><input type="text" class="flat maxwidth200" name="ref" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST('ref', 'alpha') : $object->ref).'"></td></tr>';
  775. // Label
  776. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td>';
  777. print '<td><input type="text" class="flat minwidth300" name="label" value="'.dol_escape_htmltag(GETPOSTISSET('label') ? GETPOST('label', 'alpha') : $object->label).'"></td></tr>';
  778. // Type
  779. print '<tr><td class="fieldrequired">'.$langs->trans("AccountType").'</td>';
  780. print '<td class="maxwidth200onsmartphone">';
  781. $formbank->selectTypeOfBankAccount((GETPOSTISSET('type') ? GETPOST('type', 'int') : $object->type), 'type');
  782. print '</td></tr>';
  783. // Currency
  784. print '<tr><td class="fieldrequired">'.$langs->trans("Currency");
  785. print '<input type="hidden" value="'.$object->currency_code.'">';
  786. print '</td>';
  787. print '<td class="maxwidth200onsmartphone">';
  788. $selectedcode = $object->currency_code;
  789. if (!$selectedcode) {
  790. $selectedcode = $conf->currency;
  791. }
  792. print img_picto('', 'multicurrency', 'class="pictofixedwidth"');
  793. print $form->selectCurrency((GETPOSTISSET("account_currency_code") ? GETPOST("account_currency_code") : $selectedcode), 'account_currency_code');
  794. //print $langs->trans("Currency".$conf->currency);
  795. //print '<input type="hidden" name="account_currency_code" value="'.$conf->currency.'">';
  796. print '</td></tr>';
  797. // Status
  798. print '<tr><td class="fieldrequired">'.$langs->trans("Status").'</td>';
  799. print '<td class="maxwidth200onsmartphone">';
  800. print $form->selectarray("clos", $object->status, (GETPOSTISSET("clos") ? GETPOST("clos", "int") : $object->clos));
  801. print '</td></tr>';
  802. // Country
  803. $object->country_id = $object->country_id ? $object->country_id : $mysoc->country_id;
  804. $selectedcode = $object->country_code;
  805. if (GETPOSTISSET("account_country_id")) {
  806. $selectedcode = GETPOST("account_country_id");
  807. } elseif (empty($selectedcode)) {
  808. $selectedcode = $mysoc->country_code;
  809. }
  810. $object->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
  811. print '<tr><td class="fieldrequired">'.$langs->trans("Country").'</td>';
  812. print '<td class="maxwidth200onsmartphone">';
  813. print img_picto('', 'country', 'class="pictofixedwidth"').$form->select_country($selectedcode, 'account_country_id');
  814. if ($user->admin) {
  815. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  816. }
  817. print '</td></tr>';
  818. // State
  819. print '<tr><td>'.$langs->trans('State').'</td><td class="maxwidth200onsmartphone">';
  820. if ($selectedcode) {
  821. print img_picto('', 'state', 'class="pictofixedwidth"');
  822. print $formcompany->select_state(GETPOSTISSET("account_state_id") ? GETPOST("account_state_id") : $object->state_id, $selectedcode, 'account_state_id');
  823. } else {
  824. print $countrynotdefined;
  825. }
  826. print '</td></tr>';
  827. $type = (GETPOSTISSET('type') ? GETPOST('type', 'int') : $object->type); // add default current value
  828. if ($type == Account::TYPE_SAVINGS || $type == Account::TYPE_CURRENT) {
  829. print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
  830. print '<textarea class="flat quatrevingtpercent" name="domiciliation" rows="'.ROWS_2.'">';
  831. print $object->domiciliation;
  832. print "</textarea></td></tr>";
  833. }
  834. // Conciliable
  835. print '<tr><td>'.$langs->trans("Conciliable").'</td>';
  836. print '<td>';
  837. $conciliate = $object->canBeConciliated();
  838. if ($conciliate == -2) {
  839. print $langs->trans("No").' ('.$langs->trans("CashAccount").')';
  840. } elseif ($conciliate == -3) {
  841. print $langs->trans("No").' ('.$langs->trans("Closed").')';
  842. } else {
  843. print '<input type="checkbox" class="flat" id="norappro" name="norappro"'.(($conciliate > 0) ? '' : ' checked="checked"').'"> <label for="norappro" class="opacitymedium">'.$langs->trans("DisableConciliation").'</label>';
  844. }
  845. print '</td></tr>';
  846. // Balance
  847. print '<tr><td>'.$langs->trans("BalanceMinimalAllowed").'</td>';
  848. print '<td><input size="12" type="text" class="flat" name="account_min_allowed" value="'.(GETPOSTISSET("account_min_allowed") ? GETPOST("account_min_allowed") : $object->min_allowed).'"></td></tr>';
  849. print '<tr><td>'.$langs->trans("BalanceMinimalDesired").'</td>';
  850. print '<td><input size="12" type="text" class="flat" name="account_min_desired" value="'.(GETPOSTISSET("account_min_desired") ? GETPOST("account_min_desired") : $object->min_desired).'"></td></tr>';
  851. // Web
  852. print '<tr><td>'.$langs->trans("Web").'</td>';
  853. print '<td>';
  854. print img_picto('', 'globe', 'class="pictofixedwidth"');
  855. print '<input class="maxwidth200onsmartphone" type="text" class="flat" name="url" value="'.(GETPOSTISSET("url") ? GETPOST("url") : $object->url).'">';
  856. print '</td></tr>';
  857. // Tags-Categories
  858. if (isModEnabled('categorie')) {
  859. print '<tr><td>'.$langs->trans("Categories").'</td><td>';
  860. $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1);
  861. $arrayselected = array();
  862. $c = new Categorie($db);
  863. $cats = $c->containing($object->id, Categorie::TYPE_ACCOUNT);
  864. if (is_array($cats)) {
  865. foreach ($cats as $cat) {
  866. $arrayselected[] = $cat->id;
  867. }
  868. }
  869. print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  870. print "</td></tr>";
  871. }
  872. // Comment
  873. print '<tr><td class="tdtop">'.$langs->trans("Comment").'</td>';
  874. print '<td>';
  875. // Editor wysiwyg
  876. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  877. $doleditor = new DolEditor('account_comment', (GETPOST("account_comment") ? GETPOST("account_comment") : $object->comment), '', 90, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_4, '95%');
  878. $doleditor->Create();
  879. print '</td></tr>';
  880. // Other attributes
  881. $parameters = array();
  882. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  883. print $hookmanager->resPrint;
  884. if (empty($reshook)) {
  885. print $object->showOptionals($extrafields, 'edit', $parameters);
  886. }
  887. print '</table>';
  888. print '<hr>';
  889. //print '<div class="underbanner clearboth"></div>';
  890. print '<table class="border centpercent">';
  891. // Accountancy code
  892. $tdextra = ' class="titlefieldcreate"';
  893. if (getDolGlobalString('MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED')) {
  894. $tdextra = ' class="fieldrequired titlefieldcreate"';
  895. }
  896. print '<tr><td'.$tdextra.'>'.$langs->trans("AccountancyCode").'</td>';
  897. print '<td>';
  898. if (isModEnabled('accounting')) {
  899. print img_picto('', 'accounting_account', 'class="pictofixedwidth"');
  900. print $formaccounting->select_account($object->account_number, 'account_number', 1, '', 1, 1);
  901. if ($formaccounting->nbaccounts == 0) {
  902. $langs->load("errors");
  903. $htmltext = $langs->transnoentitiesnoconv("WarningGoOnAccountancySetupToAddAccounts", $langs->transnoentitiesnoconv("MenuAccountancy"), $langs->transnoentitiesnoconv("Setup"), $langs->transnoentitiesnoconv("Chartofaccounts"));
  904. print $form->textwithpicto('', $htmltext);
  905. }
  906. } else {
  907. print '<input type="text" name="account_number" value="'.(GETPOST("account_number") ? GETPOST("account_number") : $object->account_number).'">';
  908. }
  909. print '</td></tr>';
  910. // Accountancy journal
  911. if (isModEnabled('accounting')) {
  912. print '<tr><td class="fieldrequired">'.$langs->trans("AccountancyJournal").'</td>';
  913. print '<td>';
  914. print $formaccounting->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, 0, 0);
  915. print '</td></tr>';
  916. }
  917. print '</table>';
  918. $type = (GETPOSTISSET('type') ? GETPOST('type', 'int') : $object->type); // add default current value
  919. if ($type == Account::TYPE_SAVINGS || $type == Account::TYPE_CURRENT) {
  920. print '<br>';
  921. print '<table class="border centpercent">';
  922. // If bank account
  923. print '<tr class="liste_titre_add"><td class="titlefieldcreate">'.$langs->trans("BankName").'</td>';
  924. print '<td><input type="text" class="flat width300" name="bank" value="'.$object->bank.'"></td>';
  925. print '</tr>';
  926. $ibankey = FormBank::getIBANLabel($object);
  927. $bickey = "BICNumber";
  928. if ($object->getCountryCode() == 'IN') {
  929. $bickey = "SWIFT";
  930. }
  931. // IBAN
  932. print '<tr><td>';
  933. $tooltip = $langs->trans("Example").':<br>CH93 0076 2011 6238 5295 7<br>LT12 1000 0111 0100 1000<br>FR14 2004 1010 0505 0001 3M02 606<br>LU28 0019 4006 4475 0000<br>DE89 3704 0044 0532 0130 00';
  934. print $form->textwithpicto($langs->trans($ibankey), $tooltip, 1, 'help', '', 0, 3, 'iban');
  935. print '</td>';
  936. print '<td><input class="minwidth300 maxwidth200onsmartphone" maxlength="34" type="text" class="flat" name="iban" value="'.(GETPOSTISSET('iban') ? GETPOST('iban', 'alphanohtml') : $object->iban).'"></td></tr>';
  937. // BIC
  938. print '<tr><td>';
  939. $tooltip = $langs->trans("Example").': LIABLT2XXXX';
  940. print $form->textwithpicto($langs->trans($bickey), $tooltip, 1, 'help', '', 0, 3, 'bic');
  941. print '</td>';
  942. print '<td><input class="minwidth150 maxwidth200onsmartphone" maxlength="11" type="text" class="flat" name="bic" value="'.(GETPOSTISSET('bic') ? GETPOST('bic', 'alphanohtml') : $object->bic).'"></td></tr>';
  943. // Show fields of bank account
  944. foreach ($object->getFieldsToShow() as $val) {
  945. $content = '';
  946. if ($val == 'BankCode') {
  947. $name = 'code_banque';
  948. $css = 'with100';
  949. $content = $object->code_banque;
  950. } elseif ($val == 'DeskCode') {
  951. $name = 'code_guichet';
  952. $css = 'with100';
  953. $content = $object->code_guichet;
  954. } elseif ($val == 'BankAccountNumber') {
  955. $name = 'number';
  956. $css = 'with200';
  957. $content = $object->number;
  958. } elseif ($val == 'BankAccountNumberKey') {
  959. $name = 'cle_rib';
  960. $css = 'with50';
  961. $content = $object->cle_rib;
  962. }
  963. print '<tr><td>'.$langs->trans($val).'</td>';
  964. print '<td><input type="text" class="flat '.$css.'" name="'.$name.'" value="'.dol_escape_htmltag($content).'"></td>';
  965. print '</tr>';
  966. }
  967. if (isModEnabled('prelevement')) {
  968. print '<tr><td>'.$form->textwithpicto($langs->trans("ICS"), $langs->trans("ICS").' ('.$langs->trans("UsedFor", $langs->transnoentitiesnoconv("StandingOrder")).')').'</td>';
  969. print '<td><input class="minwidth150 maxwidth200onsmartphone" maxlength="32" type="text" class="flat" name="ics" value="'.(GETPOSTISSET('ics') ? GETPOST('ics', 'alphanohtml') : $object->ics).'"></td></tr>';
  970. }
  971. if (isModEnabled('paymentbybanktransfer')) {
  972. if (getDolGlobalString("SEPA_USE_IDS")) { // ICS is not used with bank transfer !
  973. print '<tr><td>'.$form->textwithpicto($langs->trans("IDS"), $langs->trans("IDS").' ('.$langs->trans("UsedFor", $langs->transnoentitiesnoconv("BankTransfer")).')').'</td>';
  974. print '<td><input class="minwidth150 maxwidth200onsmartphone" maxlength="32" type="text" class="flat" name="ics_transfer" value="'.(GETPOSTISSET('ics_transfer') ? GETPOST('ics_transfer', 'alphanohtml') : $object->ics_transfer).'"></td></tr>';
  975. }
  976. if ($mysoc->isInEEC()) {
  977. print '<tr><td>'.$form->textwithpicto($langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformation"), $langs->trans("SEPAXMLPlacePaymentTypeInformationInCreditTransfertransactionInformationHelp")).'</td>';
  978. print '<td><input type="checkbox" class="flat" name="pti_in_ctti"'. ($object->pti_in_ctti ? ' checked ' : '') . '>';
  979. print '</td></tr>';
  980. }
  981. }
  982. print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
  983. print '<td><input class="maxwidth200onsmartphone" type="text" class="flat" name="proprio" value="'.$object->proprio.'"></td>';
  984. print '</tr>';
  985. print '</table>';
  986. print '<hr>';
  987. print '<table class="border centpercent">';
  988. print '<tr><td class="titlefieldcreate">'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
  989. print '<textarea class="flat quatrevingtpercent" name="owner_address" rows="'.ROWS_2.'">';
  990. print $object->owner_address;
  991. print "</textarea></td></tr>";
  992. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerZip").'</td>';
  993. print '<td><input type="text" class="flat maxwidth100" name="owner_zip" value="'.(GETPOST('owner_zip') ? GETPOST('owner_zip', 'alpha') : $object->owner_zip).'">';
  994. print '</td></tr>';
  995. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerTown").'</td>';
  996. print '<td><input type="text" class="flat maxwidth200" name="owner_town" value="'.(GETPOST('owner_town') ? GETPOST('owner_town', 'alpha') : $object->owner_town).'">';
  997. print '</td></tr>';
  998. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerCountry").'</td>';
  999. print '<td>';
  1000. print img_picto('', 'country', 'class="pictofixedwidth"');
  1001. print $form->select_country(GETPOST('owner_country_id') ? GETPOST('owner_country_id', 'alpha') : $object->owner_country_id, 'owner_country_id');
  1002. print '</td></tr>';
  1003. print '</table>';
  1004. }
  1005. print dol_get_fiche_end();
  1006. print $form->buttonsSaveCancel("Modify");
  1007. print '</form>';
  1008. }
  1009. }
  1010. // End of page
  1011. llxFooter();
  1012. $db->close();