index.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  4. * Copyright (C) 2013-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
  5. * Copyright (C) 2014 Ari Elbaz (elarifr) <github@accedinfo.com>
  6. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  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/index.php
  26. * \ingroup Accounting Expert
  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. $langs->load("compta");
  34. $langs->load("bills");
  35. $langs->load("admin");
  36. $langs->load("accountancy");
  37. // Security check
  38. if (!$user->admin)
  39. accessforbidden();
  40. $action = GETPOST('action', 'alpha');
  41. // Other parameters ACCOUNTING_*
  42. $list = array (
  43. 'ACCOUNTING_LIMIT_LIST_VENTILATION',
  44. 'ACCOUNTING_LENGTH_GACCOUNT',
  45. 'ACCOUNTING_LENGTH_AACCOUNT',
  46. 'ACCOUNTING_ACCOUNT_CUSTOMER',
  47. 'ACCOUNTING_ACCOUNT_SUPPLIER',
  48. 'ACCOUNTING_PRODUCT_BUY_ACCOUNT',
  49. 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT',
  50. 'ACCOUNTING_SERVICE_BUY_ACCOUNT',
  51. 'ACCOUNTING_SERVICE_SOLD_ACCOUNT',
  52. 'ACCOUNTING_ACCOUNT_SUSPENSE',
  53. 'ACCOUNTING_ACCOUNT_TRANSFER_CASH'
  54. );
  55. /*
  56. * Actions
  57. */
  58. $accounting_mode = defined('ACCOUNTING_MODE')?ACCOUNTING_MODE:'RECETTES-DEPENSES';
  59. if ($action == 'update')
  60. {
  61. $error = 0;
  62. $accounting_modes = array(
  63. 'RECETTES-DEPENSES',
  64. 'CREANCES-DETTES'
  65. );
  66. $accounting_mode = GETPOST('accounting_mode','alpha');
  67. if (in_array($accounting_mode,$accounting_modes)) {
  68. if (!dolibarr_set_const($db, 'ACCOUNTING_MODE', $accounting_mode, 'chaine', 0, '', $conf->entity)) {
  69. $error++;
  70. }
  71. } else {
  72. $error++;
  73. }
  74. $chartofaccounts = GETPOST('chartofaccounts', 'int');
  75. if (! empty($chartofaccounts)) {
  76. if (! dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
  77. $error ++;
  78. }
  79. } else {
  80. $error ++;
  81. }
  82. foreach ($list as $constname) {
  83. $constvalue = GETPOST($constname, 'alpha');
  84. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  85. $error++;
  86. }
  87. }
  88. if (! $error)
  89. {
  90. setEventMessage($langs->trans("SetupSaved"));
  91. }
  92. else
  93. {
  94. setEventMessage($langs->trans("Error"),'errors');
  95. }
  96. }
  97. if ($action == 'setlistsorttodo') {
  98. $setlistsorttodo = GETPOST('value', 'int');
  99. $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_TODO", $setlistsorttodo, 'yesno', 0, '', $conf->entity);
  100. if (! $res > 0)
  101. $error ++;
  102. if (! $error) {
  103. setEventMessage($langs->trans("SetupSaved"), 'mesgs');
  104. } else {
  105. setEventMessage($langs->trans("Error"), 'mesgs');
  106. }
  107. }
  108. if ($action == 'setlistsortdone') {
  109. $setlistsortdone = GETPOST('value', 'int');
  110. $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_DONE", $setlistsortdone, 'yesno', 0, '', $conf->entity);
  111. if (! $res > 0)
  112. $error ++;
  113. if (! $error) {
  114. setEventMessage($langs->trans("SetupSaved"), 'mesgs');
  115. } else {
  116. setEventMessage($langs->trans("Error"), 'mesgs');
  117. }
  118. }
  119. /*
  120. * View
  121. */
  122. llxHeader();
  123. $form = new Form($db);
  124. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  125. print_fiche_titre($langs->trans('ConfigAccountingExpert'),$linkback,'title_setup');
  126. $head = admin_accounting_prepare_head($accounting);
  127. dol_fiche_head($head, 'general', $langs->trans("Configuration"), 0, 'cron');
  128. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  129. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  130. print '<input type="hidden" name="action" value="update">';
  131. print '<table class="noborder" width="100%">';
  132. // Cas du parametre ACCOUNTING_MODE
  133. print '<tr class="liste_titre">';
  134. print '<td>'.$langs->trans('OptionMode').'</td><td>'.$langs->trans('Description').'</td>';
  135. print "</tr>\n";
  136. print '<tr '.$bc[false].'><td width="200"><input type="radio" name="accounting_mode" value="RECETTES-DEPENSES"'.($accounting_mode != 'CREANCES-DETTES' ? ' checked' : '').'> '.$langs->trans('OptionModeTrue').'</td>';
  137. print '<td colspan="2">'.nl2br($langs->trans('OptionModeTrueDesc'));
  138. // Write info on way to count VAT
  139. //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE))
  140. //{
  141. // // print "<br>\n";
  142. // // print nl2br($langs->trans('OptionModeTrueInfoModuleComptabilite'));
  143. //}
  144. //else
  145. //{
  146. // // print "<br>\n";
  147. // // print nl2br($langs->trans('OptionModeTrueInfoExpert'));
  148. //}
  149. print "</td></tr>\n";
  150. print '<tr '.$bc[true].'><td width="200"><input type="radio" name="accounting_mode" value="CREANCES-DETTES"'.($accounting_mode == 'CREANCES-DETTES' ? ' checked' : '').'> '.$langs->trans('OptionModeVirtual').'</td>';
  151. print '<td colspan="2">'.nl2br($langs->trans('OptionModeVirtualDesc'))."</td></tr>\n";
  152. print "</table>\n";
  153. print "<br>\n";
  154. /*
  155. * Define Chart of accounts
  156. */
  157. print '<table class="noborder" width="100%">';
  158. $var = true;
  159. print '<tr class="liste_titre">';
  160. print '<td colspan="3">';
  161. print $langs->trans("Chartofaccounts") . '</td>';
  162. print "</tr>\n";
  163. $var = ! $var;
  164. print '<tr ' . $bc[$var] . '>';
  165. print "<td>" . $langs->trans("Selectchartofaccounts") . "</td>";
  166. print "<td>";
  167. print '<select class="flat" name="chartofaccounts" id="chartofaccounts">';
  168. $sql = "SELECT rowid, pcg_version, fk_pays, label, active";
  169. $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_system";
  170. $sql .= " WHERE active = 1";
  171. $sql .= " AND fk_pays = " . $mysoc->country_id;
  172. dol_syslog('accountancy/admin/index.php:: $sql=' . $sql);
  173. $resql = $db->query($sql);
  174. $var = true;
  175. if ($resql) {
  176. $num = $db->num_rows($resql);
  177. $i = 0;
  178. while ( $i < $num ) {
  179. $var = ! $var;
  180. $row = $db->fetch_row($resql);
  181. print '<option value="' . $row[0] . '"';
  182. print $conf->global->CHARTOFACCOUNTS == $row[0] ? ' selected="selected"' : '';
  183. print '>' . $row[1] . ' - ' . $row[3] . '</option>';
  184. $i ++;
  185. }
  186. }
  187. print "</select>";
  188. print "</td></tr>";
  189. print "</table>";
  190. print "<br>\n";
  191. /*
  192. * Others params
  193. */
  194. print '<table class="noborder" width="100%">';
  195. print '<tr class="liste_titre">';
  196. print '<td colspan="3">' . $langs->trans('OtherOptions') . '</td>';
  197. print "</tr>\n";
  198. foreach ($list as $key)
  199. {
  200. $var=!$var;
  201. print '<tr '.$bc[$var].' class="value">';
  202. // Param
  203. $label = $langs->trans($key);
  204. print '<td><label for="'.$key.'">'.$label.'</label></td>';
  205. // Value
  206. print '<td>';
  207. print '<input type="text" size="20" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
  208. print '</td></tr>';
  209. }
  210. $var = ! $var;
  211. print "<tr " . $bc[$var] . ">";
  212. print '<td width="80%">' . $langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_TODO") . '</td>';
  213. if (! empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO)) {
  214. print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsorttodo&value=0">';
  215. print img_picto($langs->trans("Activated"), 'switch_on');
  216. print '</a></td>';
  217. } else {
  218. print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsorttodo&value=1">';
  219. print img_picto($langs->trans("Disabled"), 'switch_off');
  220. print '</a></td>';
  221. }
  222. print '</tr>';
  223. $var = ! $var;
  224. print "<tr " . $bc[$var] . ">";
  225. print '<td width="80%">' . $langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_DONE") . '</td>';
  226. if (! empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE)) {
  227. print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsortdone&value=0">';
  228. print img_picto($langs->trans("Activated"), 'switch_on');
  229. print '</a></td>';
  230. } else {
  231. print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsortdone&value=1">';
  232. print img_picto($langs->trans("Disabled"), 'switch_off');
  233. print '</a></td>';
  234. }
  235. print '</tr>';
  236. print "</table>\n";
  237. print '<br /><br /><div style="text-align:center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
  238. print '</form>';
  239. llxFooter();
  240. $db->close();