dolibarr  7.0.0-beta
card.php
Go to the documentation of this file.
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 
30 require('../../main.inc.php');
31 require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
32 require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
34 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formbank.class.php';
35 require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
36 require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
37 if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
38 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
39 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
40 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
41 
42 $langs->loadLangs(array("banks","bills","categories","companies","compta"));
43 
44 $action = GETPOST('action','aZ09');
45 $cancel = GETPOST('cancel', 'alpha');
46 
47 // Security check
48 if (isset($_GET["id"]) || isset($_GET["ref"]))
49 {
50  $id = isset($_GET["id"])?GETPOST("id"):(isset($_GET["ref"])?GETPOST("ref"):'');
51 }
52 $fieldid = isset($_GET["ref"])?'ref':'rowid';
53 if ($user->societe_id) $socid=$user->societe_id;
54 $result=restrictedArea($user,'banque',$id,'bank_account&bank_account','','',$fieldid);
55 
56 $object = new Account($db);
57 $extrafields = new ExtraFields($db);
58 // fetch optionals attributes and labels
59 $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
60 
61 
62 
63 /*
64  * Actions
65  */
66 
67 if ($cancel) $action='';
68 
69 if ($action == 'add')
70 {
71  $error=0;
72 
73  $db->begin();
74 
75  // Create account
76  $object = new Account($db);
77 
78  $object->ref = dol_sanitizeFileName(trim($_POST["ref"]));
79  $object->label = trim($_POST["label"]);
80  $object->courant = $_POST["type"];
81  $object->clos = $_POST["clos"];
82  $object->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1;
83  $object->url = $_POST["url"];
84 
85  $object->bank = trim($_POST["bank"]);
86  $object->code_banque = trim($_POST["code_banque"]);
87  $object->code_guichet = trim($_POST["code_guichet"]);
88  $object->number = trim($_POST["number"]);
89  $object->cle_rib = trim($_POST["cle_rib"]);
90  $object->bic = trim($_POST["bic"]);
91  $object->iban = trim($_POST["iban"]);
92  $object->domiciliation = trim($_POST["domiciliation"]);
93 
94  $object->proprio = trim($_POST["proprio"]);
95  $object->owner_address = trim($_POST["owner_address"]);
96 
97  $account_number = GETPOST('account_number','alpha');
98  if (empty($account_number) || $account_number == '-1') { $object->account_number = ''; } else { $object->account_number = $account_number; }
99  $fk_accountancy_journal = GETPOST('fk_accountancy_journal','int');
100  if ($fk_accountancy_journal <= 0) { $object->fk_accountancy_journal = ''; } else { $object->fk_accountancy_journal = $fk_accountancy_journal; }
101 
102  $object->solde = $_POST["solde"];
103  $object->date_solde = dol_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
104 
105  $object->currency_code = trim($_POST["account_currency_code"]);
106 
107  $object->state_id = $_POST["account_state_id"];
108  $object->country_id = $_POST["account_country_id"];
109 
110  $object->min_allowed = GETPOST("account_min_allowed",'int');
111  $object->min_desired = GETPOST("account_min_desired",'int');
112  $object->comment = trim(GETPOST("account_comment"));
113 
114  $object->fk_user_author = $user->id;
115 
116  if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number))
117  {
118  setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), null, 'errors');
119  $action='create'; // Force chargement page en mode creation
120  $error++;
121  }
122  if (empty($object->ref))
123  {
124  setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors');
125  $action='create'; // Force chargement page en mode creation
126  $error++;
127  }
128  if (empty($object->label))
129  {
130  setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("LabelBankCashAccount")), null, 'errors');
131  $action='create'; // Force chargement page en mode creation
132  $error++;
133  }
134 
135  // Fill array 'array_options' with data from add form
136  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
137 
138  if (! $error)
139  {
140  $id = $object->create($user);
141  if ($id > 0)
142  {
143  // Category association
144  $categories = GETPOST('categories', 'array');
145  $object->setCategories($categories);
146 
147  $_GET["id"]=$id; // Force chargement page en mode visu
148 
149  $action='';
150  }
151  else {
152  $error++;
153  setEventMessages($object->error, $object->errors, 'errors');
154 
155  $action='create'; // Force chargement page en mode creation
156  }
157  }
158 
159  if (! $error)
160  {
161  $db->commit();
162  }
163  else
164  {
165  $db->rollback();
166  }
167 }
168 
169 if ($action == 'update')
170 {
171  $error=0;
172 
173  // Update account
174  $object = new Account($db);
175  $object->fetch(GETPOST("id"));
176 
177  $object->ref = dol_string_nospecial(trim($_POST["ref"]));
178  $object->label = trim($_POST["label"]);
179  $object->courant = $_POST["type"];
180  $object->clos = $_POST["clos"];
181  $object->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1;
182  $object->url = trim($_POST["url"]);
183 
184  $object->bank = trim($_POST["bank"]);
185  $object->code_banque = trim($_POST["code_banque"]);
186  $object->code_guichet = trim($_POST["code_guichet"]);
187  $object->number = trim($_POST["number"]);
188  $object->cle_rib = trim($_POST["cle_rib"]);
189  $object->bic = trim($_POST["bic"]);
190  $object->iban = trim($_POST["iban"]);
191  $object->domiciliation = trim($_POST["domiciliation"]);
192 
193  $object->proprio = trim($_POST["proprio"]);
194  $object->owner_address = trim($_POST["owner_address"]);
195 
196  $account_number = GETPOST('account_number', 'alpha');
197  if (empty($account_number) || $account_number == '-1')
198  {
199  $object->account_number = '';
200  }
201  else
202  {
203  $object->account_number = $account_number;
204  }
205  $fk_accountancy_journal = GETPOST('fk_accountancy_journal','int');
206  if ($fk_accountancy_journal <= 0) { $object->fk_accountancy_journal = ''; } else { $object->fk_accountancy_journal = $fk_accountancy_journal; }
207 
208  $object->currency_code = trim($_POST["account_currency_code"]);
209 
210  $object->state_id = $_POST["account_state_id"];
211  $object->country_id = $_POST["account_country_id"];
212 
213  $object->min_allowed = GETPOST("account_min_allowed",'int');
214  $object->min_desired = GETPOST("account_min_desired",'int');
215  $object->comment = trim(GETPOST("account_comment"));
216 
217  if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number))
218  {
219  setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), null, 'errors');
220  $action='edit'; // Force chargement page en mode creation
221  $error++;
222  }
223  if (empty($object->ref))
224  {
225  setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors');
226  $action='edit'; // Force chargement page en mode creation
227  $error++;
228  }
229  if (empty($object->label))
230  {
231  setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("LabelBankCashAccount")), null, 'errors');
232  $action='edit'; // Force chargement page en mode creation
233  $error++;
234  }
235 
236  // Fill array 'array_options' with data from add form
237  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
238 
239  if (! $error)
240  {
241  $result = $object->update($user);
242  if ($result >= 0)
243  {
244  // Category association
245  $categories = GETPOST('categories', 'array');
246  $object->setCategories($categories);
247 
248  $_GET["id"]=$_POST["id"]; // Force chargement page en mode visu
249  }
250  else
251  {
252  setEventMessages($object->error, $object->errors, 'errors');
253  $action='edit'; // Force chargement page edition
254  }
255  }
256 }
257 
258 if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer)
259 {
260  // Delete
261  $object = new Account($db);
262  $object->fetch(GETPOST("id","int"));
263  $result = $object->delete($user);
264 
265  if ($result > 0)
266  {
267  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
268  header("Location: ".DOL_URL_ROOT."/compta/bank/list.php");
269  exit;
270  }
271  else
272  {
273  setEventMessages($account->error, $account->errors, 'errors');
274  $action='';
275  }
276 }
277 
278 
279 /*
280  * View
281  */
282 
283 $form = new Form($db);
284 $formbank = new FormBank($db);
285 $formcompany = new FormCompany($db);
286 if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
287 
288 $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
289 
290 $title = $langs->trans("FinancialAccount") . " - " . $langs->trans("Card");
291 $helpurl = "";
292 llxHeader("",$title,$helpurl);
293 
294 
295 // Creation
296 
297 if ($action == 'create')
298 {
299  $object=new Account($db);
300 
301  print load_fiche_titre($langs->trans("NewFinancialAccount"), '', 'title_bank.png');
302 
303  if ($conf->use_javascript_ajax)
304  {
305  print "\n".'<script type="text/javascript" language="javascript">';
306  print 'jQuery(document).ready(function () {
307  jQuery("#selecttype").change(function() {
308  document.formsoc.action.value="create";
309  document.formsoc.submit();
310  });
311  jQuery("#selectaccount_country_id").change(function() {
312  document.formsoc.action.value="create";
313  document.formsoc.submit();
314  });
315  })';
316  print '</script>'."\n";
317  }
318 
319  print '<form action="'.$_SERVER["PHP_SELF"].'" name="formsoc" method="post">';
320  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
321  print '<input type="hidden" name="action" value="add">';
322  print '<input type="hidden" name="clos" value="0">';
323 
324  dol_fiche_head('');
325 
326  print '<table class="border" width="100%">';
327 
328  // Ref
329  print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Ref").'</td>';
330  print '<td><input size="8" type="text" class="flat" name="ref" value="'.dol_escape_htmltag(GETPOST("ref")?GETPOST("ref",'alpha'):$object->ref).'" maxlength="12" autofocus></td></tr>';
331 
332  // Label
333  print '<tr><td class="fieldrequired">'.$langs->trans("LabelBankCashAccount").'</td>';
334  print '<td><input size="30" type="text" class="flat" name="label" value="'.dol_escape_htmltag(GETPOST("label", 'alpha')).'"></td></tr>';
335 
336  // Type
337  print '<tr><td class="fieldrequired">'.$langs->trans("AccountType").'</td>';
338  print '<td>';
339  $formbank->selectTypeOfBankAccount(isset($_POST["type"])?$_POST["type"]: Account::TYPE_CURRENT,"type");
340  print '</td></tr>';
341 
342  // Currency
343  print '<tr><td class="fieldrequired">'.$langs->trans("Currency").'</td>';
344  print '<td>';
345  $selectedcode=$object->currency_code;
346  if (! $selectedcode) $selectedcode=$conf->currency;
347  print $form->selectCurrency((isset($_POST["account_currency_code"])?$_POST["account_currency_code"]:$selectedcode), 'account_currency_code');
348  //print $langs->trans("Currency".$conf->currency);
349  //print '<input type="hidden" name="account_currency_code" value="'.$conf->currency.'">';
350  print '</td></tr>';
351 
352  // Status
353  print '<tr><td class="fieldrequired">'.$langs->trans("Status").'</td>';
354  print '<td>';
355  print $form->selectarray("clos", $object->status,(GETPOST("clos",'int')!=''?GETPOST("clos",'int'):$object->clos));
356  print '</td></tr>';
357 
358  // Country
359  $selectedcode='';
360  if (isset($_POST["account_country_id"]))
361  {
362  $selectedcode=$_POST["account_country_id"]?$_POST["account_country_id"]:$object->country_code;
363  }
364  else if (empty($selectedcode)) $selectedcode=$mysoc->country_code;
365  $object->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
366 
367  print '<tr><td class="fieldrequired">'.$langs->trans("BankAccountCountry").'</td>';
368  print '<td>';
369  print $form->select_country($selectedcode,'account_country_id');
370  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
371  print '</td></tr>';
372 
373  // State
374  print '<tr><td>'.$langs->trans('State').'</td><td>';
375  if ($selectedcode)
376  {
377  $formcompany->select_departement(isset($_POST["account_state_id"])?$_POST["account_state_id"]:'',$selectedcode,'account_state_id');
378  }
379  else
380  {
381  print $countrynotdefined;
382  }
383  print '</td></tr>';
384 
385  // Web
386  print '<tr><td>'.$langs->trans("Web").'</td>';
387  print '<td><input class="minwidth300" type="text" class="flat" name="url" value="'.GETPOST("url").'"></td></tr>';
388 
389  // Tags-Categories
390  if ($conf->categorie->enabled)
391  {
392  print '<tr><td class="tdtop">'.$langs->trans("Categories").'</td><td>';
393  $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1);
394  $c = new Categorie($db);
395  $cats = $c->containing($object->id,Categorie::TYPE_ACCOUNT);
396  foreach($cats as $cat) {
397  $arrayselected[] = $cat->id;
398  }
399  print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
400  print "</td></tr>";
401  }
402 
403  // Comment
404  print '<tr><td class="tdtop">'.$langs->trans("Comment").'</td>';
405  print '<td>';
406  // Editor wysiwyg
407  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
408  $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%');
409  $doleditor->Create();
410  print '</td></tr>';
411 
412  // Other attributes
413  $parameters=array();
414  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
415  print $hookmanager->resPrint;
416  if (empty($reshook) && ! empty($extrafields->attribute_label))
417  {
418  print $object->showOptionals($extrafields,'edit',$parameters);
419  }
420 
421  print '</table>';
422 
423  print '<br>';
424 
425  print '<table class="border" width="100%">';
426 
427  // Sold
428  print '<tr><td class="titlefieldcreate">'.$langs->trans("InitialBankBalance").'</td>';
429  print '<td><input size="12" type="text" class="flat" name="solde" value="'.(GETPOST("solde")?GETPOST("solde"):price2num($object->solde)).'"></td></tr>';
430 
431  print '<tr><td>'.$langs->trans("Date").'</td>';
432  print '<td>';
433  $form->select_date('', 're', 0, 0, 0, 'formsoc');
434  print '</td></tr>';
435 
436  print '<tr><td>'.$langs->trans("BalanceMinimalAllowed").'</td>';
437  print '<td><input size="12" type="text" class="flat" name="account_min_allowed" value="'.(GETPOST("account_min_allowed")?GETPOST("account_min_allowed"):$object->min_allowed).'"></td></tr>';
438 
439  print '<tr><td>'.$langs->trans("BalanceMinimalDesired").'</td>';
440  print '<td><input size="12" type="text" class="flat" name="account_min_desired" value="'.(GETPOST("account_min_desired")?GETPOST("account_min_desired"):$object->min_desired).'"></td></tr>';
441 
442  print '</table>';
443  print '<br>';
444 
445  if ($_POST["type"] == Account::TYPE_SAVINGS || $_POST["type"] == Account::TYPE_CURRENT)
446  {
447  print '<table class="border" width="100%">';
448 
449  // If bank account
450  print '<tr><td class="titlefieldcreate">'.$langs->trans("BankName").'</td>';
451  print '<td><input size="30" type="text" class="flat" name="bank" value="'.(GETPOST('bank')?GETPOST('bank','alpha'):$object->bank).'"></td>';
452  print '</tr>';
453 
454  // Show fields of bank account
455  foreach ($object->getFieldsToShow() as $val) {
456  if ($val == 'BankCode') {
457  $name = 'code_banque';
458  $size = 8;
459  $content = $object->code_banque;
460  } elseif ($val == 'DeskCode') {
461  $name = 'code_guichet';
462  $size = 8;
463  $content = $object->code_guichet;
464  } elseif ($val == 'BankAccountNumber') {
465  $name = 'number';
466  $size = 18;
467  $content = $object->number;
468  } elseif ($val == 'BankAccountNumberKey') {
469  $name = 'cle_rib';
470  $size = 3;
471  $content = $object->cle_rib;
472  }
473 
474  print '<td>'.$langs->trans($val).'</td>';
475  print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.(GETPOST($name)?GETPOST($name,'alpha'):$content).'"></td>';
476  print '</tr>';
477  }
478  $ibankey = FormBank::getIBANLabel($object);
479  $bickey="BICNumber";
480  if ($object->getCountryCode() == 'IN') $bickey="SWIFT";
481 
482  // IBAN
483  print '<tr><td>'.$langs->trans($ibankey).'</td>';
484  print '<td><input size="34" maxlength="34" type="text" class="flat" name="iban" value="'.(GETPOST('iban')?GETPOST('iban','alpha'):$object->iban).'"></td></tr>';
485 
486  print '<tr><td>'.$langs->trans($bickey).'</td>';
487  print '<td><input size="11" maxlength="11" type="text" class="flat" name="bic" value="'.(GETPOST('bic')?GETPOST('bic','alpha'):$object->bic).'"></td></tr>';
488 
489  print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
490  print "<textarea class=\"flat\" name=\"domiciliation\" rows=\"2\" cols=\"40\">";
491  print (GETPOST('domiciliation')?GETPOST('domiciliation'):$object->domiciliation);
492  print "</textarea></td></tr>";
493 
494  print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
495  print '<td><input size="30" type="text" class="flat" name="proprio" value="'.(GETPOST('proprio')?GETPOST('proprio','alpha'):$object->proprio).'">';
496  print '</td></tr>';
497 
498  print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
499  print "<textarea class=\"flat\" name=\"owner_address\" rows=\"2\" cols=\"40\">";
500  print (GETPOST('owner_address')?GETPOST('owner_address','alpha'):$object->owner_address);
501  print "</textarea></td></tr>";
502 
503  print '</table>';
504  print '<br>';
505  }
506 
507  print '<table class="border" width="100%">';
508  // Accountancy code
509  $fieldrequired='';
510  if (! empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED)) $fieldrequired='fieldrequired ';
511 
512  if (! empty($conf->accounting->enabled))
513  {
514  print '<tr><td class="'.$fieldrequired.'titlefieldcreate">'.$langs->trans("AccountancyCode").'</td>';
515  print '<td>';
516  print $formaccounting->select_account($object->account_number, 'account_number', 1, '', 1, 1);
517  print '</td></tr>';
518  }
519  else
520  {
521  print '<tr><td class="'.$fieldrequired.'titlefieldcreate">'.$langs->trans("AccountancyCode").'</td>';
522  print '<td><input type="text" name="account_number" value="'.(GETPOST("account_number")?GETPOST('account_number', 'alpha'):$object->account_number).'"></td></tr>';
523  }
524 
525  // Accountancy journal
526  if (! empty($conf->accounting->enabled))
527  {
528  print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
529  print '<td>';
530  print $formaccounting->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, 0, 0);
531  print '</td></tr>';
532  }
533 
534  print '</table>';
535 
536  dol_fiche_end();
537 
538  print '<div class="center">';
539  print '<input type="submit" class="button" value="' . $langs->trans("CreateAccount") . '">';
540  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
541  print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
542  print '</div>';
543 
544  print '</form>';
545 }
546 /* ************************************************************************** */
547 /* */
548 /* Visu et edition */
549 /* */
550 /* ************************************************************************** */
551 else
552 {
553  if (($_GET["id"] || $_GET["ref"]) && $action != 'edit')
554  {
555  $object = new Account($db);
556  if ($_GET["id"])
557  {
558  $object->fetch($_GET["id"]);
559  }
560  if ($_GET["ref"])
561  {
562  $object->fetch(0,$_GET["ref"]);
563  $_GET["id"]=$object->id;
564  }
565 
566  // Show tabs
567  $head=bank_prepare_head($object);
568  dol_fiche_head($head, 'bankname', $langs->trans("FinancialAccount"), -1, 'account');
569 
570  $formconfirm = '';
571 
572  // Confirmation to delete
573  if ($action == 'delete')
574  {
575  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans("DeleteAccount"),$langs->trans("ConfirmDeleteAccount"),"confirm_delete");
576 
577  }
578 
579  // Print form confirm
580  print $formconfirm;
581 
582  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
583 
584  $morehtmlref='';
585  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
586 
587 
588  print '<div class="fichecenter">';
589  print '<div class="fichehalfleft">';
590  print '<div class="underbanner clearboth"></div>';
591 
592  print '<table class="border" width="100%">';
593 
594  // Type
595  print '<tr><td class="titlefield">'.$langs->trans("AccountType").'</td>';
596  print '<td>'.$object->type_lib[$object->type].'</td></tr>';
597 
598  // Currency
599  print '<tr><td>'.$langs->trans("Currency").'</td>';
600  print '<td>';
601  $selectedcode=$object->currency_code;
602  if (! $selectedcode) $selectedcode=$conf->currency;
603  print $langs->trans("Currency".$selectedcode);
604  print '</td></tr>';
605 
606  // Conciliate
607  print '<tr><td>'.$langs->trans("Conciliable").'</td>';
608  print '<td>';
609  $conciliate=$object->canBeConciliated();
610  if ($conciliate == -2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')';
611  else if ($conciliate == -3) print $langs->trans("No").' ('.$langs->trans("Closed").')';
612  else print ($object->rappro==1 ? $langs->trans("Yes") : ($langs->trans("No").' ('.$langs->trans("ConciliationDisabled").')'));
613  print '</td></tr>';
614 
615  print '<tr><td>'.$langs->trans("BalanceMinimalAllowed").'</td>';
616  print '<td>'.$object->min_allowed.'</td></tr>';
617 
618  print '<tr><td>'.$langs->trans("BalanceMinimalDesired").'</td>';
619  print '<td>'.$object->min_desired.'</td></tr>';
620 
621  // Accountancy code
622  print '<tr class="liste_titre_add"><td class="titlefield">'.$langs->trans("AccountancyCode").'</td>';
623  print '<td>';
624  if (! empty($conf->accounting->enabled)) {
625  $accountingaccount = new AccountingAccount($db);
626  $accountingaccount->fetch('',$object->account_number, 1);
627 
628  print $accountingaccount->getNomUrl(0,1,1,'',1);
629  } else {
630  print $object->account_number;
631  }
632  print '</td></tr>';
633 
634  // Accountancy journal
635  if (! empty($conf->accounting->enabled))
636  {
637  print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
638  print '<td>';
639 
640  $accountingjournal = new AccountingJournal($db);
641  $accountingjournal->fetch($object->fk_accountancy_journal);
642 
643  print $accountingjournal->getNomUrl(0,1,1,'',1);
644 
645  print '</td></tr>';
646  }
647 
648  // Other attributes
649  $cols = 2;
650  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
651 
652  print '</table>';
653 
654  print '</div>';
655  print '<div class="fichehalfright">';
656  print '<div class="ficheaddleft">';
657  print '<div class="underbanner clearboth"></div>';
658 
659  print '<table class="border centpercent">';
660 
661  // Categories
662  if ($conf->categorie->enabled) {
663  print '<tr><td class="titlefield">'.$langs->trans("Categories").'</td><td>';
664  print $form->showCategories($object->id,'bank_account',1);
665  print "</td></tr>";
666  }
667 
668  print '<tr><td class="tdtop titlefield">'.$langs->trans("Comment").'</td>';
669  print '<td>'.dol_htmlentitiesbr($object->comment).'</td></tr>';
670 
671  print '</table>';
672 
673  if ($object->type == Account::TYPE_SAVINGS || $object->type == Account::TYPE_CURRENT)
674  {
675 
676  print '<div class="underbanner clearboth"></div>';
677 
678  print '<table class="border centpercent">';
679 
680  print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("BankName").'</td>';
681  print '<td>'.$object->bank.'</td></tr>';
682 
683  // Show fields of bank account
684  foreach ($object->getFieldsToShow() as $val) {
685  if ($val == 'BankCode') {
686  $content = $object->code_banque;
687  } elseif ($val == 'DeskCode') {
688  $content = $object->code_guichet;
689  } elseif ($val == 'BankAccountNumber') {
690  $content = $object->number;
691  } elseif ($val == 'BankAccountNumberKey') {
692  $content = $object->cle_rib;
693  }
694 
695  print '<tr><td>'.$langs->trans($val).'</td>';
696  print '<td>'.$content.'</td>';
697  print '</tr>';
698  }
699 
700  $ibankey = FormBank::getIBANLabel($object);
701  $bickey="BICNumber";
702  if ($object->getCountryCode() == 'IN') $bickey="SWIFT";
703 
704  print '<tr><td>'.$langs->trans($ibankey).'</td>';
705  print '<td>'.$object->iban.'&nbsp;';
706  if (! empty($object->iban)) {
707  if (! checkIbanForAccount($object)) {
708  print img_picto($langs->trans("IbanNotValid"),'warning');
709  } else {
710  print img_picto($langs->trans("IbanValid"),'info');
711  }
712  }
713  print '</td></tr>';
714 
715  print '<tr><td>'.$langs->trans($bickey).'</td>';
716  print '<td>'.$object->bic.'&nbsp;';
717  if (! empty($object->bic)) {
718  if (! checkSwiftForAccount($object)) {
719  print img_picto($langs->trans("SwiftNotValid"),'warning');
720  } else {
721  print img_picto($langs->trans("SwiftValid"),'info');
722  }
723  }
724  print '</td></tr>';
725 
726  print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
727  print nl2br($object->domiciliation);
728  print "</td></tr>\n";
729 
730  print '<tr><td>'.$langs->trans("BankAccountOwner").'</td><td>';
731  print $object->proprio;
732  print "</td></tr>\n";
733 
734  print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
735  print nl2br($object->owner_address);
736  print "</td></tr>\n";
737 
738  print '</table>';
739  }
740 
741  print '</div>';
742  print '</div>';
743  print '</div>';
744 
745  print '<div class="clearboth"></div>';
746 
747  dol_fiche_end();
748 
749  /*
750  * Barre d'actions
751  */
752  print '<div class="tabsAction">';
753 
754  if ($user->rights->banque->configurer)
755  {
756  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$object->id.'">'.$langs->trans("Modify").'</a>';
757  }
758 
759  $canbedeleted=$object->can_be_deleted(); // Renvoi vrai si compte sans mouvements
760  if ($user->rights->banque->configurer && $canbedeleted)
761  {
762  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$object->id.'">'.$langs->trans("Delete").'</a>';
763  }
764 
765  print '</div>';
766 
767  }
768 
769  /* ************************************************************************** */
770  /* */
771  /* Edition */
772  /* */
773  /* ************************************************************************** */
774 
775  if (GETPOST('id','int') && $action == 'edit' && $user->rights->banque->configurer)
776  {
777  $object = new Account($db);
778  $object->fetch(GETPOST('id','int'));
779 
780  print load_fiche_titre($langs->trans("EditFinancialAccount"), '', 'title_bank.png');
781 
782  if ($conf->use_javascript_ajax)
783  {
784  print "\n".'<script type="text/javascript" language="javascript">';
785  print 'jQuery(document).ready(function () {
786  jQuery("#selecttype").change(function() {
787  document.formsoc.action.value="edit";
788  document.formsoc.submit();
789  });
790  })'."\n";
791 
792  print 'jQuery(document).ready(function () {
793  jQuery("#selectaccount_country_id").change(function() {
794  document.formsoc.action.value="edit";
795  document.formsoc.submit();
796  });
797  })';
798  print '</script>'."\n";
799  }
800 
801  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post" name="formsoc">';
802  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
803  print '<input type="hidden" name="action" value="update">';
804  print '<input type="hidden" name="id" value="'.$_REQUEST["id"].'">'."\n\n";
805 
806  dol_fiche_head('');
807 
808  print '<div class="underbanner clearboth"></div>';
809 
810  print '<table class="border" width="100%">';
811 
812  // Ref
813  print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Ref").'</td>';
814  print '<td><input size="8" type="text" class="flat" name="ref" value="'.(isset($_POST["ref"])?GETPOST("ref"):$object->ref).'"></td></tr>';
815 
816  // Label
817  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td>';
818  print '<td><input type="text" class="flat minwidth300" name="label" value="'.(isset($_POST["label"])?GETPOST("label"):$object->label).'"></td></tr>';
819 
820  // Type
821  print '<tr><td class="fieldrequired">'.$langs->trans("AccountType").'</td>';
822  print '<td class="maxwidth200onsmartphone">';
823  $formbank->selectTypeOfBankAccount((isset($_POST["type"])?$_POST["type"]:$object->type),"type");
824  print '</td></tr>';
825 
826  // Currency
827  print '<tr><td class="fieldrequired">'.$langs->trans("Currency");
828  print '<input type="hidden" value="'.$object->currency_code.'">';
829  print '</td>';
830  print '<td class="maxwidth200onsmartphone">';
831  $selectedcode=$object->currency_code;
832  if (! $selectedcode) $selectedcode=$conf->currency;
833  print $form->selectCurrency((isset($_POST["account_currency_code"])?$_POST["account_currency_code"]:$selectedcode), 'account_currency_code');
834  //print $langs->trans("Currency".$conf->currency);
835  //print '<input type="hidden" name="account_currency_code" value="'.$conf->currency.'">';
836  print '</td></tr>';
837 
838  // Status
839  print '<tr><td class="fieldrequired">'.$langs->trans("Status").'</td>';
840  print '<td class="maxwidth200onsmartphone">';
841  print $form->selectarray("clos", $object->status, (isset($_POST["clos"])?$_POST["clos"]:$object->clos));
842  print '</td></tr>';
843 
844  // Country
845  $object->country_id=$object->country_id?$object->country_id:$mysoc->country_id;
846  $selectedcode=$object->country_code;
847  if (isset($_POST["account_country_id"])) $selectedcode=$_POST["account_country_id"];
848  else if (empty($selectedcode)) $selectedcode=$mysoc->country_code;
849  $object->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
850 
851  print '<tr><td class="fieldrequired">'.$langs->trans("Country").'</td>';
852  print '<td class="maxwidth200onsmartphone">';
853  print $form->select_country($selectedcode,'account_country_id');
854  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
855  print '</td></tr>';
856 
857  // State
858  print '<tr><td>'.$langs->trans('State').'</td><td class="maxwidth200onsmartphone">';
859  if ($selectedcode)
860  {
861  print $formcompany->select_state(isset($_POST["account_state_id"])?$_POST["account_state_id"]:$object->state_id,$selectedcode,'account_state_id');
862  }
863  else
864  {
865  print $countrynotdefined;
866  }
867  print '</td></tr>';
868 
869  // Conciliable
870  print '<tr><td>'.$langs->trans("Conciliable").'</td>';
871  print '<td>';
872  $conciliate=$object->canBeConciliated();
873  if ($conciliate == -2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')';
874  else if ($conciliate == -3) print $langs->trans("No").' ('.$langs->trans("Closed").')';
875  else print '<input type="checkbox" class="flat" name="norappro"'.(($conciliate > 0)?'':' checked="checked"').'"> '.$langs->trans("DisableConciliation");
876  print '</td></tr>';
877 
878  // Balance
879  print '<tr><td>'.$langs->trans("BalanceMinimalAllowed").'</td>';
880  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>';
881 
882  print '<tr><td>'.$langs->trans("BalanceMinimalDesired").'</td>';
883  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>';
884 
885  // Web
886  print '<tr><td>'.$langs->trans("Web").'</td>';
887  print '<td><input class="maxwidth200onsmartphone" type="text" class="flat" name="url" value="'.(isset($_POST["url"])?GETPOST("url"):$object->url).'">';
888  print '</td></tr>';
889 
890  // Tags-Categories
891  if ($conf->categorie->enabled)
892  {
893  print '<tr><td class="tdtop">'.$langs->trans("Categories").'</td><td>';
894  $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1);
895  $c = new Categorie($db);
896  $cats = $c->containing($object->id,Categorie::TYPE_ACCOUNT);
897  foreach($cats as $cat) {
898  $arrayselected[] = $cat->id;
899  }
900  print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
901  print "</td></tr>";
902  }
903 
904  // Comment
905  print '<tr><td class="tdtop">'.$langs->trans("Comment").'</td>';
906  print '<td>';
907  // Editor wysiwyg
908  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
909  $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%');
910  $doleditor->Create();
911  print '</td></tr>';
912 
913  // Other attributes
914  $parameters=array();
915  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
916  print $hookmanager->resPrint;
917  if (empty($reshook) && ! empty($extrafields->attribute_label))
918  {
919  print $object->showOptionals($extrafields,'edit');
920  }
921 
922  print '</table>';
923  print '<br>';
924 
925 
926  //print '<div class="underbanner clearboth"></div>';
927 
928  print '<table class="border" width="100%">';
929 
930  // Accountancy code
931  $tdextra = ' class="titlefieldcreate"';
932 
933  if (!empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED)) {
934  $tdextra = ' class="fieldrequired titlefieldcreate"';
935  }
936 
937  print '<tr class="liste_titre_add"><td'.$tdextra.'>'.$langs->trans("AccountancyCode").'</td>';
938  print '<td>';
939  if (!empty($conf->accounting->enabled)) {
940  print $formaccounting->select_account($object->account_number, 'account_number', 1, '', 1, 1);
941  } else {
942  print '<input type="text" name="account_number" value="'.(GETPOST("account_number") ? GETPOST("account_number") : $object->account_number).'">';
943  }
944  print '</td></tr>';
945 
946  // Accountancy journal
947  if (! empty($conf->accounting->enabled))
948  {
949  print '<tr><td class="fieldrequired">'.$langs->trans("AccountancyJournal").'</td>';
950  print '<td>';
951  print $formaccounting->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, 0, 0);
952  print '</td></tr>';
953  }
954 
955  print '</table>';
956 
957  if ($_POST["type"] == Account::TYPE_SAVINGS || $_POST["type"] == Account::TYPE_CURRENT)
958  {
959  print '<br>';
960 
961  //print '<div class="underbanner clearboth"></div>';
962 
963  print '<table class="border" width="100%">';
964 
965  // If bank account
966  print '<tr class="liste_titre_add"><td class="titlefieldcreate">'.$langs->trans("BankName").'</td>';
967  print '<td><input size="30" type="text" class="flat" name="bank" value="'.$object->bank.'"></td>';
968  print '</tr>';
969 
970  // Show fields of bank account
971  foreach ($object->getFieldsToShow() as $val) {
972  if ($val == 'BankCode') {
973  $name = 'code_banque';
974  $size = 8;
975  $content = $object->code_banque;
976  } elseif ($val == 'DeskCode') {
977  $name = 'code_guichet';
978  $size = 8;
979  $content = $object->code_guichet;
980  } elseif ($val == 'BankAccountNumber') {
981  $name = 'number';
982  $size = 18;
983  $content = $object->number;
984  } elseif ($val == 'BankAccountNumberKey') {
985  $name = 'cle_rib';
986  $size = 3;
987  $content = $object->cle_rib;
988  }
989 
990  print '<tr><td>'.$langs->trans($val).'</td>';
991  print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.$content.'"></td>';
992  print '</tr>';
993  }
994 
995  $ibankey = FormBank::getIBANLabel($object);
996  $bickey="BICNumber";
997  if ($object->getCountryCode() == 'IN') $bickey="SWIFT";
998 
999  // IBAN
1000  print '<tr><td>'.$langs->trans($ibankey).'</td>';
1001  print '<td><input class="minwidth300 maxwidth200onsmartphone" maxlength="34" type="text" class="flat" name="iban" value="'.$object->iban.'"></td></tr>';
1002 
1003  print '<tr><td>'.$langs->trans($bickey).'</td>';
1004  print '<td><input class="minwidth150 maxwidth200onsmartphone" maxlength="11" type="text" class="flat" name="bic" value="'.$object->bic.'"></td></tr>';
1005 
1006  print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
1007  print '<textarea class="flat quatrevingtpercent" name="domiciliation" rows="'.ROWS_2.'">';
1008  print $object->domiciliation;
1009  print "</textarea></td></tr>";
1010 
1011  print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
1012  print '<td><input class="maxwidth200onsmartphone" type="text" class="flat" name="proprio" value="'.$object->proprio.'"></td>';
1013  print '</tr>';
1014 
1015  print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
1016  print '<textarea class="flat quatrevingtpercent" name="owner_address" rows="'.ROWS_2.'">';
1017  print $object->owner_address;
1018  print "</textarea></td></tr>";
1019 
1020  print '</table>';
1021  }
1022 
1023  dol_fiche_end();
1024 
1025  print '<div class="center">';
1026  print '<input value="'.$langs->trans("Modify").'" type="submit" class="button">';
1027  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1028  print '<input name="cancel" value="'.$langs->trans("Cancel").'" type="submit" class="button">';
1029  print '</div>';
1030 
1031  print '</form>';
1032  }
1033 
1034 }
1035 
1036 llxFooter();
1037 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition: bank.lib.php:34
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
const TYPE_CURRENT
Current account.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
checkSwiftForAccount($account)
Check SWIFT informations for a bank account.
Definition: bank.lib.php:209
if(empty($reshook)) $form
View.
Definition: perms.php:103
Class to manage bank accounts.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
static getIBANLabel(Account $account)
Returns the name of the Iban label.
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1')
Show information for admin users or standard users.
Class to manage categories.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91
checkIbanForAccount($account)
Check IBAN number informations for a bank account.
Definition: bank.lib.php:226
Class to manage generation of HTML components for accounting management.
Class to manage a WYSIWYG editor.
const TYPE_SAVINGS
Savings account.
Class to manage accounting accounts.
Class to manage accounting accounts.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='')
Clean a string from all punctuation characters to use it as a ref or login.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.
$parameters
Actions.
Definition: card.php:112
Class to manage generation of HTML components for bank module.