card.php 40 KB

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