card.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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 Frédéric France <frederic.france@netlogic.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/compta/bank/card.php
  26. * \ingroup bank
  27. * \brief Page to create/view a bank account
  28. */
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
  31. require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formbank.class.php';
  34. require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
  35. require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
  36. if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  37. if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  38. if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
  39. if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
  40. // Load translation files required by the page
  41. $langs->loadLangs(array("banks","bills","categories","companies","compta"));
  42. $action = GETPOST('action','aZ09');
  43. $cancel = GETPOST('cancel', 'alpha');
  44. // Security check
  45. if (isset($_GET["id"]) || isset($_GET["ref"]))
  46. {
  47. $id = isset($_GET["id"])?GETPOST("id"):(isset($_GET["ref"])?GETPOST("ref"):'');
  48. }
  49. $fieldid = isset($_GET["ref"])?'ref':'rowid';
  50. if ($user->societe_id) $socid=$user->societe_id;
  51. $result=restrictedArea($user,'banque',$id,'bank_account&bank_account','','',$fieldid);
  52. $object = new Account($db);
  53. $extrafields = new ExtraFields($db);
  54. // fetch optionals attributes and labels
  55. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  56. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  57. $hookmanager->initHooks(array('bankcard','globalcard'));
  58. /*
  59. * Actions
  60. */
  61. if ($cancel) $action='';
  62. if ($action == 'add')
  63. {
  64. $error=0;
  65. $db->begin();
  66. // Create account
  67. $object = new Account($db);
  68. $object->ref = dol_sanitizeFileName(trim($_POST["ref"]));
  69. $object->label = trim($_POST["label"]);
  70. $object->courant = $_POST["type"];
  71. $object->clos = $_POST["clos"];
  72. $object->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1;
  73. $object->url = $_POST["url"];
  74. $object->bank = trim($_POST["bank"]);
  75. $object->code_banque = trim($_POST["code_banque"]);
  76. $object->code_guichet = trim($_POST["code_guichet"]);
  77. $object->number = trim($_POST["number"]);
  78. $object->cle_rib = trim($_POST["cle_rib"]);
  79. $object->bic = trim($_POST["bic"]);
  80. $object->iban = trim($_POST["iban"]);
  81. $object->domiciliation = trim($_POST["domiciliation"]);
  82. $object->proprio = trim($_POST["proprio"]);
  83. $object->owner_address = trim($_POST["owner_address"]);
  84. $account_number = GETPOST('account_number','alpha');
  85. if (empty($account_number) || $account_number == '-1') { $object->account_number = ''; } else { $object->account_number = $account_number; }
  86. $fk_accountancy_journal = GETPOST('fk_accountancy_journal','int');
  87. if ($fk_accountancy_journal <= 0) { $object->fk_accountancy_journal = ''; } else { $object->fk_accountancy_journal = $fk_accountancy_journal; }
  88. $object->solde = $_POST["solde"];
  89. $object->date_solde = dol_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
  90. $object->currency_code = trim($_POST["account_currency_code"]);
  91. $object->state_id = $_POST["account_state_id"];
  92. $object->country_id = $_POST["account_country_id"];
  93. $object->min_allowed = GETPOST("account_min_allowed",'int');
  94. $object->min_desired = GETPOST("account_min_desired",'int');
  95. $object->comment = trim(GETPOST("account_comment"));
  96. $object->fk_user_author = $user->id;
  97. if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number))
  98. {
  99. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), null, 'errors');
  100. $action='create'; // Force chargement page en mode creation
  101. $error++;
  102. }
  103. if (empty($object->ref))
  104. {
  105. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors');
  106. $action='create'; // Force chargement page en mode creation
  107. $error++;
  108. }
  109. if (empty($object->label))
  110. {
  111. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("LabelBankCashAccount")), null, 'errors');
  112. $action='create'; // Force chargement page en mode creation
  113. $error++;
  114. }
  115. // Fill array 'array_options' with data from add form
  116. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  117. if (! $error)
  118. {
  119. $id = $object->create($user);
  120. if ($id > 0)
  121. {
  122. // Category association
  123. $categories = GETPOST('categories', 'array');
  124. $object->setCategories($categories);
  125. $_GET["id"]=$id; // Force chargement page en mode visu
  126. $action='';
  127. }
  128. else {
  129. $error++;
  130. setEventMessages($object->error, $object->errors, 'errors');
  131. $action='create'; // Force chargement page en mode creation
  132. }
  133. }
  134. if (! $error)
  135. {
  136. $db->commit();
  137. }
  138. else
  139. {
  140. $db->rollback();
  141. }
  142. }
  143. if ($action == 'update')
  144. {
  145. $error=0;
  146. // Update account
  147. $object = new Account($db);
  148. $object->fetch(GETPOST("id"));
  149. $object->ref = dol_string_nospecial(trim($_POST["ref"]));
  150. $object->label = trim($_POST["label"]);
  151. $object->courant = $_POST["type"];
  152. $object->clos = $_POST["clos"];
  153. $object->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1;
  154. $object->url = trim($_POST["url"]);
  155. $object->bank = trim($_POST["bank"]);
  156. $object->code_banque = trim($_POST["code_banque"]);
  157. $object->code_guichet = trim($_POST["code_guichet"]);
  158. $object->number = trim($_POST["number"]);
  159. $object->cle_rib = trim($_POST["cle_rib"]);
  160. $object->bic = trim($_POST["bic"]);
  161. $object->iban = trim($_POST["iban"]);
  162. $object->domiciliation = trim($_POST["domiciliation"]);
  163. $object->proprio = trim($_POST["proprio"]);
  164. $object->owner_address = trim($_POST["owner_address"]);
  165. $account_number = GETPOST('account_number', 'alpha');
  166. if (empty($account_number) || $account_number == '-1')
  167. {
  168. $object->account_number = '';
  169. }
  170. else
  171. {
  172. $object->account_number = $account_number;
  173. }
  174. $fk_accountancy_journal = GETPOST('fk_accountancy_journal','int');
  175. if ($fk_accountancy_journal <= 0) { $object->fk_accountancy_journal = ''; } else { $object->fk_accountancy_journal = $fk_accountancy_journal; }
  176. $object->currency_code = trim($_POST["account_currency_code"]);
  177. $object->state_id = $_POST["account_state_id"];
  178. $object->country_id = $_POST["account_country_id"];
  179. $object->min_allowed = GETPOST("account_min_allowed",'int');
  180. $object->min_desired = GETPOST("account_min_desired",'int');
  181. $object->comment = trim(GETPOST("account_comment"));
  182. if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number))
  183. {
  184. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), null, 'errors');
  185. $action='edit'; // Force chargement page en mode creation
  186. $error++;
  187. }
  188. if (empty($object->ref))
  189. {
  190. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors');
  191. $action='edit'; // Force chargement page en mode creation
  192. $error++;
  193. }
  194. if (empty($object->label))
  195. {
  196. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("LabelBankCashAccount")), null, 'errors');
  197. $action='edit'; // Force chargement page en mode creation
  198. $error++;
  199. }
  200. // Fill array 'array_options' with data from add form
  201. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  202. if (! $error)
  203. {
  204. $result = $object->update($user);
  205. if ($result >= 0)
  206. {
  207. // Category association
  208. $categories = GETPOST('categories', 'array');
  209. $object->setCategories($categories);
  210. $_GET["id"]=$_POST["id"]; // Force chargement page en mode visu
  211. }
  212. else
  213. {
  214. setEventMessages($object->error, $object->errors, 'errors');
  215. $action='edit'; // Force chargement page edition
  216. }
  217. }
  218. }
  219. if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer)
  220. {
  221. // Delete
  222. $object = new Account($db);
  223. $object->fetch(GETPOST("id","int"));
  224. $result = $object->delete($user);
  225. if ($result > 0)
  226. {
  227. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  228. header("Location: ".DOL_URL_ROOT."/compta/bank/list.php");
  229. exit;
  230. }
  231. else
  232. {
  233. setEventMessages($account->error, $account->errors, 'errors');
  234. $action='';
  235. }
  236. }
  237. /*
  238. * View
  239. */
  240. $form = new Form($db);
  241. $formbank = new FormBank($db);
  242. $formcompany = new FormCompany($db);
  243. if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
  244. $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  245. $title = $langs->trans("FinancialAccount") . " - " . $langs->trans("Card");
  246. $helpurl = "";
  247. llxHeader("",$title,$helpurl);
  248. // Creation
  249. if ($action == 'create')
  250. {
  251. $object=new Account($db);
  252. print load_fiche_titre($langs->trans("NewFinancialAccount"), '', 'title_bank.png');
  253. if ($conf->use_javascript_ajax)
  254. {
  255. print "\n".'<script type="text/javascript" language="javascript">';
  256. print 'jQuery(document).ready(function () {
  257. jQuery("#selecttype").change(function() {
  258. document.formsoc.action.value="create";
  259. document.formsoc.submit();
  260. });
  261. jQuery("#selectaccount_country_id").change(function() {
  262. document.formsoc.action.value="create";
  263. document.formsoc.submit();
  264. });
  265. })';
  266. print '</script>'."\n";
  267. }
  268. print '<form action="'.$_SERVER["PHP_SELF"].'" name="formsoc" method="post">';
  269. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  270. print '<input type="hidden" name="action" value="add">';
  271. print '<input type="hidden" name="clos" value="0">';
  272. dol_fiche_head('');
  273. print '<table class="border" width="100%">';
  274. // Ref
  275. print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Ref").'</td>';
  276. print '<td><input size="8" type="text" class="flat" name="ref" value="'.dol_escape_htmltag(GETPOST("ref")?GETPOST("ref",'alpha'):$object->ref).'" maxlength="12" autofocus></td></tr>';
  277. // Label
  278. print '<tr><td class="fieldrequired">'.$langs->trans("LabelBankCashAccount").'</td>';
  279. print '<td><input size="30" type="text" class="flat" name="label" value="'.dol_escape_htmltag(GETPOST("label", 'alpha')).'"></td></tr>';
  280. // Type
  281. print '<tr><td class="fieldrequired">'.$langs->trans("AccountType").'</td>';
  282. print '<td>';
  283. $formbank->selectTypeOfBankAccount(isset($_POST["type"])?$_POST["type"]: Account::TYPE_CURRENT,"type");
  284. print '</td></tr>';
  285. // Currency
  286. print '<tr><td class="fieldrequired">'.$langs->trans("Currency").'</td>';
  287. print '<td>';
  288. $selectedcode=$object->currency_code;
  289. if (! $selectedcode) $selectedcode=$conf->currency;
  290. print $form->selectCurrency((isset($_POST["account_currency_code"])?$_POST["account_currency_code"]:$selectedcode), 'account_currency_code');
  291. //print $langs->trans("Currency".$conf->currency);
  292. //print '<input type="hidden" name="account_currency_code" value="'.$conf->currency.'">';
  293. print '</td></tr>';
  294. // Status
  295. print '<tr><td class="fieldrequired">'.$langs->trans("Status").'</td>';
  296. print '<td>';
  297. print $form->selectarray("clos", $object->status,(GETPOST("clos",'int')!=''?GETPOST("clos",'int'):$object->clos));
  298. print '</td></tr>';
  299. // Country
  300. $selectedcode='';
  301. if (isset($_POST["account_country_id"]))
  302. {
  303. $selectedcode=$_POST["account_country_id"]?$_POST["account_country_id"]:$object->country_code;
  304. }
  305. elseif (empty($selectedcode)) $selectedcode=$mysoc->country_code;
  306. $object->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
  307. print '<tr><td class="fieldrequired">'.$langs->trans("BankAccountCountry").'</td>';
  308. print '<td>';
  309. print $form->select_country($selectedcode,'account_country_id');
  310. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  311. print '</td></tr>';
  312. // State
  313. print '<tr><td>'.$langs->trans('State').'</td><td>';
  314. if ($selectedcode)
  315. {
  316. $formcompany->select_departement(isset($_POST["account_state_id"])?$_POST["account_state_id"]:'',$selectedcode,'account_state_id');
  317. }
  318. else
  319. {
  320. print $countrynotdefined;
  321. }
  322. print '</td></tr>';
  323. // Web
  324. print '<tr><td>'.$langs->trans("Web").'</td>';
  325. print '<td><input class="minwidth300" type="text" class="flat" name="url" value="'.GETPOST("url").'"></td></tr>';
  326. // Tags-Categories
  327. if ($conf->categorie->enabled)
  328. {
  329. print '<tr><td class="tdtop">'.$langs->trans("Categories").'</td><td>';
  330. $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1);
  331. $c = new Categorie($db);
  332. $cats = $c->containing($object->id,Categorie::TYPE_ACCOUNT);
  333. foreach($cats as $cat) {
  334. $arrayselected[] = $cat->id;
  335. }
  336. print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
  337. print "</td></tr>";
  338. }
  339. // Comment
  340. print '<tr><td class="tdtop">'.$langs->trans("Comment").'</td>';
  341. print '<td>';
  342. // Editor wysiwyg
  343. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  344. $doleditor=new DolEditor('account_comment',(GETPOST("account_comment")?GETPOST("account_comment"):$object->comment),'',90,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_4,'90%');
  345. $doleditor->Create();
  346. print '</td></tr>';
  347. // Other attributes
  348. $parameters=array();
  349. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  350. print $hookmanager->resPrint;
  351. if (empty($reshook))
  352. {
  353. print $object->showOptionals($extrafields,'edit',$parameters);
  354. }
  355. print '</table>';
  356. print '<br>';
  357. print '<table class="border" width="100%">';
  358. // Sold
  359. print '<tr><td class="titlefieldcreate">'.$langs->trans("InitialBankBalance").'</td>';
  360. print '<td><input size="12" type="text" class="flat" name="solde" value="'.(GETPOST("solde")?GETPOST("solde"):price2num($object->solde)).'"></td></tr>';
  361. print '<tr><td>'.$langs->trans("Date").'</td>';
  362. print '<td>';
  363. print $form->selectDate('', 're', 0, 0, 0, 'formsoc');
  364. print '</td></tr>';
  365. print '<tr><td>'.$langs->trans("BalanceMinimalAllowed").'</td>';
  366. 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>';
  367. print '<tr><td>'.$langs->trans("BalanceMinimalDesired").'</td>';
  368. 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>';
  369. print '</table>';
  370. print '<br>';
  371. if ($_POST["type"] == Account::TYPE_SAVINGS || $_POST["type"] == Account::TYPE_CURRENT)
  372. {
  373. print '<table class="border" width="100%">';
  374. // If bank account
  375. print '<tr><td class="titlefieldcreate">'.$langs->trans("BankName").'</td>';
  376. print '<td><input size="30" type="text" class="flat" name="bank" value="'.(GETPOST('bank')?GETPOST('bank','alpha'):$object->bank).'"></td>';
  377. print '</tr>';
  378. // Show fields of bank account
  379. foreach ($object->getFieldsToShow() as $val) {
  380. if ($val == 'BankCode') {
  381. $name = 'code_banque';
  382. $size = 8;
  383. $content = $object->code_banque;
  384. } elseif ($val == 'DeskCode') {
  385. $name = 'code_guichet';
  386. $size = 8;
  387. $content = $object->code_guichet;
  388. } elseif ($val == 'BankAccountNumber') {
  389. $name = 'number';
  390. $size = 18;
  391. $content = $object->number;
  392. } elseif ($val == 'BankAccountNumberKey') {
  393. $name = 'cle_rib';
  394. $size = 3;
  395. $content = $object->cle_rib;
  396. }
  397. print '<td>'.$langs->trans($val).'</td>';
  398. print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.(GETPOST($name)?GETPOST($name,'alpha'):$content).'"></td>';
  399. print '</tr>';
  400. }
  401. $ibankey = FormBank::getIBANLabel($object);
  402. $bickey="BICNumber";
  403. if ($object->getCountryCode() == 'IN') $bickey="SWIFT";
  404. // IBAN
  405. print '<tr><td>'.$langs->trans($ibankey).'</td>';
  406. print '<td><input size="34" maxlength="34" type="text" class="flat" name="iban" value="'.(GETPOST('iban')?GETPOST('iban','alpha'):$object->iban).'"></td></tr>';
  407. print '<tr><td>'.$langs->trans($bickey).'</td>';
  408. print '<td><input size="11" maxlength="11" type="text" class="flat" name="bic" value="'.(GETPOST('bic')?GETPOST('bic','alpha'):$object->bic).'"></td></tr>';
  409. print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
  410. print "<textarea class=\"flat\" name=\"domiciliation\" rows=\"2\" cols=\"40\">";
  411. print (GETPOST('domiciliation')?GETPOST('domiciliation'):$object->domiciliation);
  412. print "</textarea></td></tr>";
  413. print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
  414. print '<td><input size="30" type="text" class="flat" name="proprio" value="'.(GETPOST('proprio')?GETPOST('proprio','alpha'):$object->proprio).'">';
  415. print '</td></tr>';
  416. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
  417. print "<textarea class=\"flat\" name=\"owner_address\" rows=\"2\" cols=\"40\">";
  418. print (GETPOST('owner_address')?GETPOST('owner_address','alpha'):$object->owner_address);
  419. print "</textarea></td></tr>";
  420. print '</table>';
  421. print '<br>';
  422. }
  423. print '<table class="border" width="100%">';
  424. // Accountancy code
  425. $fieldrequired='';
  426. if (! empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED)) $fieldrequired='fieldrequired ';
  427. if (! empty($conf->accounting->enabled))
  428. {
  429. print '<tr><td class="'.$fieldrequired.'titlefieldcreate">'.$langs->trans("AccountancyCode").'</td>';
  430. print '<td>';
  431. print $formaccounting->select_account($object->account_number, 'account_number', 1, '', 1, 1);
  432. print '</td></tr>';
  433. }
  434. else
  435. {
  436. print '<tr><td class="'.$fieldrequired.'titlefieldcreate">'.$langs->trans("AccountancyCode").'</td>';
  437. print '<td><input type="text" name="account_number" value="'.(GETPOST("account_number")?GETPOST('account_number', 'alpha'):$object->account_number).'"></td></tr>';
  438. }
  439. // Accountancy journal
  440. if (! empty($conf->accounting->enabled))
  441. {
  442. print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
  443. print '<td>';
  444. print $formaccounting->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, 0, 0);
  445. print '</td></tr>';
  446. }
  447. print '</table>';
  448. dol_fiche_end();
  449. print '<div class="center">';
  450. print '<input type="submit" class="button" value="' . $langs->trans("CreateAccount") . '">';
  451. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  452. print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
  453. print '</div>';
  454. print '</form>';
  455. }
  456. /* ************************************************************************** */
  457. /* */
  458. /* Visu et edition */
  459. /* */
  460. /* ************************************************************************** */
  461. else
  462. {
  463. if (($_GET["id"] || $_GET["ref"]) && $action != 'edit')
  464. {
  465. $object = new Account($db);
  466. if ($_GET["id"])
  467. {
  468. $object->fetch($_GET["id"]);
  469. }
  470. if ($_GET["ref"])
  471. {
  472. $object->fetch(0,$_GET["ref"]);
  473. $_GET["id"]=$object->id;
  474. }
  475. // Show tabs
  476. $head=bank_prepare_head($object);
  477. dol_fiche_head($head, 'bankname', $langs->trans("FinancialAccount"), -1, 'account');
  478. $formconfirm = '';
  479. // Confirmation to delete
  480. if ($action == 'delete')
  481. {
  482. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans("DeleteAccount"),$langs->trans("ConfirmDeleteAccount"),"confirm_delete");
  483. }
  484. // Print form confirm
  485. print $formconfirm;
  486. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  487. $morehtmlref='';
  488. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  489. print '<div class="fichecenter">';
  490. print '<div class="fichehalfleft">';
  491. print '<div class="underbanner clearboth"></div>';
  492. print '<table class="border tableforfield" width="100%">';
  493. // Type
  494. print '<tr><td class="titlefield">'.$langs->trans("AccountType").'</td>';
  495. print '<td>'.$object->type_lib[$object->type].'</td></tr>';
  496. // Currency
  497. print '<tr><td>'.$langs->trans("Currency").'</td>';
  498. print '<td>';
  499. $selectedcode=$object->currency_code;
  500. if (! $selectedcode) $selectedcode=$conf->currency;
  501. print $langs->trans("Currency".$selectedcode);
  502. print '</td></tr>';
  503. // Conciliate
  504. print '<tr><td>'.$langs->trans("Conciliable").'</td>';
  505. print '<td>';
  506. $conciliate=$object->canBeConciliated();
  507. if ($conciliate == -2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')';
  508. elseif ($conciliate == -3) print $langs->trans("No").' ('.$langs->trans("Closed").')';
  509. else print ($object->rappro==1 ? $langs->trans("Yes") : ($langs->trans("No").' ('.$langs->trans("ConciliationDisabled").')'));
  510. print '</td></tr>';
  511. print '<tr><td>'.$langs->trans("BalanceMinimalAllowed").'</td>';
  512. print '<td>'.$object->min_allowed.'</td></tr>';
  513. print '<tr><td>'.$langs->trans("BalanceMinimalDesired").'</td>';
  514. print '<td>'.$object->min_desired.'</td></tr>';
  515. // Accountancy code
  516. print '<tr class="liste_titre_add"><td class="titlefield">'.$langs->trans("AccountancyCode").'</td>';
  517. print '<td>';
  518. if (! empty($conf->accounting->enabled)) {
  519. $accountingaccount = new AccountingAccount($db);
  520. $accountingaccount->fetch('',$object->account_number, 1);
  521. print $accountingaccount->getNomUrl(0,1,1,'',1);
  522. } else {
  523. print $object->account_number;
  524. }
  525. print '</td></tr>';
  526. // Accountancy journal
  527. if (! empty($conf->accounting->enabled))
  528. {
  529. print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
  530. print '<td>';
  531. $accountingjournal = new AccountingJournal($db);
  532. $accountingjournal->fetch($object->fk_accountancy_journal);
  533. print $accountingjournal->getNomUrl(0,1,1,'',1);
  534. print '</td></tr>';
  535. }
  536. // Other attributes
  537. $cols = 2;
  538. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  539. print '</table>';
  540. print '</div>';
  541. print '<div class="fichehalfright">';
  542. print '<div class="ficheaddleft">';
  543. print '<div class="underbanner clearboth"></div>';
  544. print '<table class="border tableforfield centpercent">';
  545. // Categories
  546. if ($conf->categorie->enabled) {
  547. print '<tr><td class="titlefield">'.$langs->trans("Categories").'</td><td>';
  548. print $form->showCategories($object->id,'bank_account',1);
  549. print "</td></tr>";
  550. }
  551. print '<tr><td class="tdtop titlefield">'.$langs->trans("Comment").'</td>';
  552. print '<td>'.dol_htmlentitiesbr($object->comment).'</td></tr>';
  553. print '</table>';
  554. if ($object->type == Account::TYPE_SAVINGS || $object->type == Account::TYPE_CURRENT)
  555. {
  556. print '<div class="underbanner clearboth"></div>';
  557. print '<table class="border tableforfield centpercent">';
  558. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("BankName").'</td>';
  559. print '<td>'.$object->bank.'</td></tr>';
  560. // Show fields of bank account
  561. foreach ($object->getFieldsToShow() as $val) {
  562. if ($val == 'BankCode') {
  563. $content = $object->code_banque;
  564. } elseif ($val == 'DeskCode') {
  565. $content = $object->code_guichet;
  566. } elseif ($val == 'BankAccountNumber') {
  567. $content = $object->number;
  568. } elseif ($val == 'BankAccountNumberKey') {
  569. $content = $object->cle_rib;
  570. }
  571. print '<tr><td>'.$langs->trans($val).'</td>';
  572. print '<td>'.$content.'</td>';
  573. print '</tr>';
  574. }
  575. $ibankey = FormBank::getIBANLabel($object);
  576. $bickey="BICNumber";
  577. if ($object->getCountryCode() == 'IN') $bickey="SWIFT";
  578. print '<tr><td>'.$langs->trans($ibankey).'</td>';
  579. print '<td>'.$object->iban.'&nbsp;';
  580. if (! empty($object->iban)) {
  581. if (! checkIbanForAccount($object)) {
  582. print img_picto($langs->trans("IbanNotValid"),'warning');
  583. } else {
  584. print img_picto($langs->trans("IbanValid"),'info');
  585. }
  586. }
  587. print '</td></tr>';
  588. print '<tr><td>'.$langs->trans($bickey).'</td>';
  589. print '<td>'.$object->bic.'&nbsp;';
  590. if (! empty($object->bic)) {
  591. if (! checkSwiftForAccount($object)) {
  592. print img_picto($langs->trans("SwiftNotValid"),'warning');
  593. } else {
  594. print img_picto($langs->trans("SwiftValid"),'info');
  595. }
  596. }
  597. print '</td></tr>';
  598. print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
  599. print nl2br($object->domiciliation);
  600. print "</td></tr>\n";
  601. print '<tr><td>'.$langs->trans("BankAccountOwner").'</td><td>';
  602. print $object->proprio;
  603. print "</td></tr>\n";
  604. print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
  605. print nl2br($object->owner_address);
  606. print "</td></tr>\n";
  607. print '</table>';
  608. }
  609. print '</div>';
  610. print '</div>';
  611. print '</div>';
  612. print '<div class="clearboth"></div>';
  613. dol_fiche_end();
  614. /*
  615. * Barre d'actions
  616. */
  617. print '<div class="tabsAction">';
  618. if ($user->rights->banque->configurer)
  619. {
  620. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$object->id.'">'.$langs->trans("Modify").'</a>';
  621. }
  622. $canbedeleted=$object->can_be_deleted(); // Renvoi vrai si compte sans mouvements
  623. if ($user->rights->banque->configurer && $canbedeleted)
  624. {
  625. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$object->id.'">'.$langs->trans("Delete").'</a>';
  626. }
  627. print '</div>';
  628. }
  629. /* ************************************************************************** */
  630. /* */
  631. /* Edition */
  632. /* */
  633. /* ************************************************************************** */
  634. if (GETPOST('id','int') && $action == 'edit' && $user->rights->banque->configurer)
  635. {
  636. $object = new Account($db);
  637. $object->fetch(GETPOST('id','int'));
  638. print load_fiche_titre($langs->trans("EditFinancialAccount"), '', 'title_bank.png');
  639. if ($conf->use_javascript_ajax)
  640. {
  641. print "\n".'<script type="text/javascript" language="javascript">';
  642. print 'jQuery(document).ready(function () {
  643. jQuery("#selecttype").change(function() {
  644. document.formsoc.action.value="edit";
  645. document.formsoc.submit();
  646. });
  647. })'."\n";
  648. print 'jQuery(document).ready(function () {
  649. jQuery("#selectaccount_country_id").change(function() {
  650. document.formsoc.action.value="edit";
  651. document.formsoc.submit();
  652. });
  653. })';
  654. print '</script>'."\n";
  655. }
  656. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post" name="formsoc">';
  657. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  658. print '<input type="hidden" name="action" value="update">';
  659. print '<input type="hidden" name="id" value="'.$_REQUEST["id"].'">'."\n\n";
  660. dol_fiche_head(array(), 0, '', 0);
  661. //print '<div class="underbanner clearboth"></div>';
  662. print '<table class="border" width="100%">';
  663. // Ref
  664. print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Ref").'</td>';
  665. print '<td><input type="text" class="flat maxwidth200" name="ref" value="'.dol_escape_htmltag(isset($_POST["ref"])?GETPOST("ref"):$object->ref).'"></td></tr>';
  666. // Label
  667. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td>';
  668. print '<td><input type="text" class="flat minwidth300" name="label" value="'.dol_escape_htmltag(isset($_POST["label"])?GETPOST("label"):$object->label).'"></td></tr>';
  669. // Type
  670. print '<tr><td class="fieldrequired">'.$langs->trans("AccountType").'</td>';
  671. print '<td class="maxwidth200onsmartphone">';
  672. $formbank->selectTypeOfBankAccount((isset($_POST["type"])?$_POST["type"]:$object->type),"type");
  673. print '</td></tr>';
  674. // Currency
  675. print '<tr><td class="fieldrequired">'.$langs->trans("Currency");
  676. print '<input type="hidden" value="'.$object->currency_code.'">';
  677. print '</td>';
  678. print '<td class="maxwidth200onsmartphone">';
  679. $selectedcode=$object->currency_code;
  680. if (! $selectedcode) $selectedcode=$conf->currency;
  681. print $form->selectCurrency((isset($_POST["account_currency_code"])?$_POST["account_currency_code"]:$selectedcode), 'account_currency_code');
  682. //print $langs->trans("Currency".$conf->currency);
  683. //print '<input type="hidden" name="account_currency_code" value="'.$conf->currency.'">';
  684. print '</td></tr>';
  685. // Status
  686. print '<tr><td class="fieldrequired">'.$langs->trans("Status").'</td>';
  687. print '<td class="maxwidth200onsmartphone">';
  688. print $form->selectarray("clos", $object->status, (isset($_POST["clos"])?$_POST["clos"]:$object->clos));
  689. print '</td></tr>';
  690. // Country
  691. $object->country_id=$object->country_id?$object->country_id:$mysoc->country_id;
  692. $selectedcode=$object->country_code;
  693. if (isset($_POST["account_country_id"])) $selectedcode=$_POST["account_country_id"];
  694. elseif (empty($selectedcode)) $selectedcode=$mysoc->country_code;
  695. $object->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
  696. print '<tr><td class="fieldrequired">'.$langs->trans("Country").'</td>';
  697. print '<td class="maxwidth200onsmartphone">';
  698. print $form->select_country($selectedcode,'account_country_id');
  699. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  700. print '</td></tr>';
  701. // State
  702. print '<tr><td>'.$langs->trans('State').'</td><td class="maxwidth200onsmartphone">';
  703. if ($selectedcode)
  704. {
  705. print $formcompany->select_state(isset($_POST["account_state_id"])?$_POST["account_state_id"]:$object->state_id,$selectedcode,'account_state_id');
  706. }
  707. else
  708. {
  709. print $countrynotdefined;
  710. }
  711. print '</td></tr>';
  712. // Conciliable
  713. print '<tr><td>'.$langs->trans("Conciliable").'</td>';
  714. print '<td>';
  715. $conciliate=$object->canBeConciliated();
  716. if ($conciliate == -2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')';
  717. elseif ($conciliate == -3) print $langs->trans("No").' ('.$langs->trans("Closed").')';
  718. else print '<input type="checkbox" class="flat" name="norappro"'.(($conciliate > 0)?'':' checked="checked"').'"> '.$langs->trans("DisableConciliation");
  719. print '</td></tr>';
  720. // Balance
  721. print '<tr><td>'.$langs->trans("BalanceMinimalAllowed").'</td>';
  722. print '<td><input size="12" type="text" class="flat" name="account_min_allowed" value="'.(isset($_POST["account_min_allowed"])?GETPOST("account_min_allowed"):$object->min_allowed).'"></td></tr>';
  723. print '<tr><td>'.$langs->trans("BalanceMinimalDesired").'</td>';
  724. print '<td ><input size="12" type="text" class="flat" name="account_min_desired" value="'.(isset($_POST["account_min_desired"])?GETPOST("account_min_desired"):$object->min_desired).'"></td></tr>';
  725. // Web
  726. print '<tr><td>'.$langs->trans("Web").'</td>';
  727. print '<td><input class="maxwidth200onsmartphone" type="text" class="flat" name="url" value="'.(isset($_POST["url"])?GETPOST("url"):$object->url).'">';
  728. print '</td></tr>';
  729. // Tags-Categories
  730. if ($conf->categorie->enabled)
  731. {
  732. print '<tr><td class="tdtop">'.$langs->trans("Categories").'</td><td>';
  733. $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1);
  734. $c = new Categorie($db);
  735. $cats = $c->containing($object->id,Categorie::TYPE_ACCOUNT);
  736. foreach($cats as $cat) {
  737. $arrayselected[] = $cat->id;
  738. }
  739. print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
  740. print "</td></tr>";
  741. }
  742. // Comment
  743. print '<tr><td class="tdtop">'.$langs->trans("Comment").'</td>';
  744. print '<td>';
  745. // Editor wysiwyg
  746. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  747. $doleditor=new DolEditor('account_comment',(GETPOST("account_comment")?GETPOST("account_comment"):$object->comment),'',90,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_4,'95%');
  748. $doleditor->Create();
  749. print '</td></tr>';
  750. // Other attributes
  751. $parameters=array();
  752. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  753. print $hookmanager->resPrint;
  754. if (empty($reshook))
  755. {
  756. print $object->showOptionals($extrafields,'edit');
  757. }
  758. print '</table>';
  759. print '<br>';
  760. //print '<div class="underbanner clearboth"></div>';
  761. print '<table class="border" width="100%">';
  762. // Accountancy code
  763. $tdextra = ' class="titlefieldcreate"';
  764. if (!empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED)) {
  765. $tdextra = ' class="fieldrequired titlefieldcreate"';
  766. }
  767. print '<tr class="liste_titre_add"><td'.$tdextra.'>'.$langs->trans("AccountancyCode").'</td>';
  768. print '<td>';
  769. if (!empty($conf->accounting->enabled)) {
  770. print $formaccounting->select_account($object->account_number, 'account_number', 1, '', 1, 1);
  771. } else {
  772. print '<input type="text" name="account_number" value="'.(GETPOST("account_number") ? GETPOST("account_number") : $object->account_number).'">';
  773. }
  774. print '</td></tr>';
  775. // Accountancy journal
  776. if (! empty($conf->accounting->enabled))
  777. {
  778. print '<tr><td class="fieldrequired">'.$langs->trans("AccountancyJournal").'</td>';
  779. print '<td>';
  780. print $formaccounting->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, 0, 0);
  781. print '</td></tr>';
  782. }
  783. print '</table>';
  784. if ($_POST["type"] == Account::TYPE_SAVINGS || $_POST["type"] == Account::TYPE_CURRENT)
  785. {
  786. print '<br>';
  787. //print '<div class="underbanner clearboth"></div>';
  788. print '<table class="border" width="100%">';
  789. // If bank account
  790. print '<tr class="liste_titre_add"><td class="titlefieldcreate">'.$langs->trans("BankName").'</td>';
  791. print '<td><input size="30" type="text" class="flat" name="bank" value="'.$object->bank.'"></td>';
  792. print '</tr>';
  793. // Show fields of bank account
  794. foreach ($object->getFieldsToShow() as $val) {
  795. if ($val == 'BankCode') {
  796. $name = 'code_banque';
  797. $size = 8;
  798. $content = $object->code_banque;
  799. } elseif ($val == 'DeskCode') {
  800. $name = 'code_guichet';
  801. $size = 8;
  802. $content = $object->code_guichet;
  803. } elseif ($val == 'BankAccountNumber') {
  804. $name = 'number';
  805. $size = 18;
  806. $content = $object->number;
  807. } elseif ($val == 'BankAccountNumberKey') {
  808. $name = 'cle_rib';
  809. $size = 3;
  810. $content = $object->cle_rib;
  811. }
  812. print '<tr><td>'.$langs->trans($val).'</td>';
  813. print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.$content.'"></td>';
  814. print '</tr>';
  815. }
  816. $ibankey = FormBank::getIBANLabel($object);
  817. $bickey="BICNumber";
  818. if ($object->getCountryCode() == 'IN') $bickey="SWIFT";
  819. // IBAN
  820. print '<tr><td>'.$langs->trans($ibankey).'</td>';
  821. print '<td><input class="minwidth300 maxwidth200onsmartphone" maxlength="34" type="text" class="flat" name="iban" value="'.$object->iban.'"></td></tr>';
  822. print '<tr><td>'.$langs->trans($bickey).'</td>';
  823. print '<td><input class="minwidth150 maxwidth200onsmartphone" maxlength="11" type="text" class="flat" name="bic" value="'.$object->bic.'"></td></tr>';
  824. print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
  825. print '<textarea class="flat quatrevingtpercent" name="domiciliation" rows="'.ROWS_2.'">';
  826. print $object->domiciliation;
  827. print "</textarea></td></tr>";
  828. print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
  829. print '<td><input class="maxwidth200onsmartphone" type="text" class="flat" name="proprio" value="'.$object->proprio.'"></td>';
  830. print '</tr>';
  831. print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
  832. print '<textarea class="flat quatrevingtpercent" name="owner_address" rows="'.ROWS_2.'">';
  833. print $object->owner_address;
  834. print "</textarea></td></tr>";
  835. print '</table>';
  836. }
  837. dol_fiche_end();
  838. print '<div class="center">';
  839. print '<input value="'.$langs->trans("Modify").'" type="submit" class="button">';
  840. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  841. print '<input name="cancel" value="'.$langs->trans("Cancel").'" type="submit" class="button">';
  842. print '</div>';
  843. print '</form>';
  844. }
  845. }
  846. // End of page
  847. llxFooter();
  848. $db->close();