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