card.php 39 KB

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