journal.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
  4. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  5. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  6. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  8. * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
  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. /**
  25. * \file htdocs/accountancy/admin/journal.php
  26. * \ingroup Advanced accountancy
  27. * \brief Setup page to configure accounting expert module
  28. */
  29. require '../../main.inc.php';
  30. // Class
  31. require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
  34. require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
  35. $langs->load("compta");
  36. $langs->load("bills");
  37. $langs->load("admin");
  38. $langs->load("accountancy");
  39. $langs->load("salaries");
  40. // Security check
  41. if (empty($user->admin) || ! empty($user->rights->accountancy->chartofaccount))
  42. {
  43. accessforbidden();
  44. }
  45. $action = GETPOST('action', 'alpha');
  46. // Other parameters ACCOUNTING_*
  47. $list = array (
  48. 'ACCOUNTING_SELL_JOURNAL',
  49. 'ACCOUNTING_PURCHASE_JOURNAL',
  50. 'ACCOUNTING_SOCIAL_JOURNAL',
  51. 'ACCOUNTING_MISCELLANEOUS_JOURNAL',
  52. 'ACCOUNTING_EXPENSEREPORT_JOURNAL'
  53. );
  54. /*
  55. * Actions
  56. */
  57. if ($action == 'update') {
  58. $error = 0;
  59. // Save vars
  60. foreach ($list as $constname)
  61. {
  62. $constvalue = GETPOST($constname, 'alpha');
  63. if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  64. $error ++;
  65. }
  66. }
  67. // Save bank account journals
  68. $arrayofbankaccount = GETPOST('bank_account', 'array');
  69. foreach($arrayofbankaccount as $key => $code)
  70. {
  71. $bankaccount = new Account($db);
  72. $res = $bankaccount->fetch($key);
  73. if ($res > 0)
  74. {
  75. $bankaccount->accountancy_journal = $code;
  76. $bankaccount->update($user);
  77. }
  78. else
  79. {
  80. $error++;
  81. break;
  82. }
  83. }
  84. if (! $error) {
  85. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  86. } else {
  87. setEventMessages($langs->trans("Error"), null, 'errors');
  88. }
  89. }
  90. /*
  91. * View
  92. */
  93. llxHeader();
  94. $form = new Form($db);
  95. $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
  96. print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'title_setup');
  97. $head = admin_accounting_prepare_head(null);
  98. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
  99. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  100. print '<input type="hidden" name="action" value="update">';
  101. dol_fiche_head($head, 'journal', $langs->trans("Configuration"), 0, 'cron');
  102. print '<table class="noborder" width="100%">';
  103. print '<tr class="liste_titre">';
  104. print '<td colspan="2">' . $langs->trans('Journaux') . '</td>';
  105. print "</tr>\n";
  106. foreach ( $list as $key ) {
  107. print '<tr class="oddeven value">';
  108. // Param
  109. $label = $langs->trans($key);
  110. print '<td width="50%"><label for="' . $key . '">' . $label . '</label></td>';
  111. // Value
  112. print '<td>';
  113. print '<input type="text" size="20" id="' . $key . '" name="' . $key . '" value="' . $conf->global->$key . '">';
  114. print '</td></tr>';
  115. }
  116. print "</table>\n";
  117. print '<br>';
  118. print '<table class="noborder" width="100%">';
  119. print '<tr class="liste_titre">';
  120. print '<td colspan="2">' . $langs->trans('JournalFinancial') . ' ('.$langs->trans('Opened').')</td>';
  121. print "</tr>\n";
  122. // Bank account
  123. $sql = "SELECT rowid, ref, label, number, account_number, accountancy_journal";
  124. $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account";
  125. $sql .= " WHERE entity = " . $conf->entity;
  126. $sql .= " AND clos = 0";
  127. $sql .= " ORDER BY label";
  128. $resql = $db->query($sql);
  129. if ($resql) {
  130. $numr = $db->num_rows($resql);
  131. $i = 0;
  132. if ($numr > 0)
  133. $bankaccountstatic = new Account($db);
  134. while ( $i < $numr ) {
  135. $objp = $db->fetch_object($resql);
  136. $bankaccountstatic->rowid = $objp->rowid;
  137. $bankaccountstatic->id = $objp->rowid;
  138. $bankaccountstatic->ref = $objp->ref;
  139. $bankaccountstatic->label = $objp->label;
  140. $bankaccountstatic->number = $objp->number;
  141. $bankaccountstatic->account_number = $objp->account_number;
  142. $bankaccountstatic->accountancy_journal = $objp->accountancy_journal;
  143. print '<tr class="oddeven value">';
  144. // Param
  145. print '<td width="50%"><label for="' . $objp->rowid . '">' . $langs->trans("Journal");
  146. print ' - '.$bankaccountstatic->getNomUrl(1);
  147. print '</label></td>';
  148. // Value
  149. print '<td>';
  150. print '<input type="text" size="20" id="' . $objp->rowid . '" name="bank_account['.$objp->rowid.']" value="' . $objp->accountancy_journal . '">';
  151. print '</td></tr>';
  152. $i ++;
  153. }
  154. $db->free($resql);
  155. }
  156. else
  157. {
  158. dol_print_error($db);
  159. }
  160. print "</table>\n";
  161. dol_fiche_end();
  162. print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('Modify') . '" name="button"></div>';
  163. print '</form>';
  164. llxFooter();
  165. $db->close();