card.php 38 KB

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