compta.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/admin/compta.php
  23. * \ingroup compta
  24. * \brief Page to setup accountancy module
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  28. $langs->load('admin');
  29. $langs->load('compta');
  30. if (!$user->admin)
  31. accessforbidden();
  32. $action = GETPOST('action','alpha');
  33. /*
  34. * Actions
  35. */
  36. $compta_mode = defined('COMPTA_MODE')?COMPTA_MODE:'RECETTES-DEPENSES';
  37. if ($action == 'setcomptamode')
  38. {
  39. $compta_mode = GETPOST('compta_mode','alpha');
  40. $res = dolibarr_set_const($db, 'COMPTA_MODE', $compta_mode,'chaine',0,'',$conf->entity);
  41. if (! $res > 0) $error++;
  42. if (! $error)
  43. {
  44. setEventMessage($langs->trans("SetupSaved"));
  45. }
  46. else
  47. {
  48. setEventMessage($langs->trans("Error"),'errors');
  49. }
  50. }
  51. if ($action == 'update' || $action == 'add')
  52. {
  53. $constname = GETPOST('constname','alpha');
  54. $constvalue = GETPOST('constvalue','alpha');
  55. $consttype = GETPOST('consttype','alpha');
  56. $constnote = GETPOST('constnote','alpha');
  57. $res = dolibarr_set_const($db, $constname, $constvalue, $consttype, 0, $constnote, $conf->entity);
  58. if (! $res > 0) $error++;
  59. if (! $error)
  60. {
  61. setEventMessage($langs->trans("SetupSaved"));
  62. }
  63. else
  64. {
  65. setEventMessage($langs->trans("Error"),'errors');
  66. }
  67. }
  68. /*if ($action == 'delete')
  69. {
  70. if (! dolibarr_del_const($db, $_GET['constname'],$conf->entity));
  71. {
  72. print $db->error();
  73. }
  74. }*/
  75. /*
  76. * View
  77. */
  78. llxHeader();
  79. $form=new Form($db);
  80. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  81. print_fiche_titre($langs->trans('ComptaSetup'),$linkback,'setup');
  82. print '<br>';
  83. print '<table class="noborder" width="100%">';
  84. // Cas du parametre COMPTA_MODE
  85. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  86. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  87. print '<input type="hidden" name="action" value="setcomptamode">';
  88. print '<tr class="liste_titre">';
  89. print '<td>'.$langs->trans('OptionMode').'</td><td>'.$langs->trans('Description').'</td>';
  90. print '<td align="right"><input class="button" type="submit" value="'.$langs->trans('Modify').'"></td>';
  91. print "</tr>\n";
  92. print '<tr '.$bc[false].'><td width="200"><input type="radio" name="compta_mode" value="RECETTES-DEPENSES"'.($compta_mode != 'CREANCES-DETTES' ? ' checked' : '').'> '.$langs->trans('OptionModeTrue').'</td>';
  93. print '<td colspan="2">'.nl2br($langs->trans('OptionModeTrueDesc'));
  94. // Write info on way to count VAT
  95. if (! empty($conf->global->MAIN_MODULE_COMPTABILITE))
  96. {
  97. // print "<br>\n";
  98. // print nl2br($langs->trans('OptionModeTrueInfoModuleComptabilite'));
  99. }
  100. else
  101. {
  102. // print "<br>\n";
  103. // print nl2br($langs->trans('OptionModeTrueInfoExpert'));
  104. }
  105. print "</td></tr>\n";
  106. print '<tr '.$bc[true].'><td width="200"><input type="radio" name="compta_mode" value="CREANCES-DETTES"'.($compta_mode == 'CREANCES-DETTES' ? ' checked' : '').'> '.$langs->trans('OptionModeVirtual').'</td>';
  107. print '<td colspan="2">'.nl2br($langs->trans('OptionModeVirtualDesc'))."</td></tr>\n";
  108. print '</form>';
  109. print "</table>\n";
  110. print "<br>\n";
  111. // Cas des autres parametres COMPTA_*
  112. $list=array('COMPTA_PRODUCT_BUY_ACCOUNT','COMPTA_PRODUCT_SOLD_ACCOUNT','COMPTA_SERVICE_BUY_ACCOUNT','COMPTA_SERVICE_SOLD_ACCOUNT',
  113. 'COMPTA_VAT_ACCOUNT','COMPTA_VAT_BUY_ACCOUNT','COMPTA_ACCOUNT_CUSTOMER','COMPTA_ACCOUNT_SUPPLIER'
  114. );
  115. /*$sql = "SELECT rowid, name, value, type, note";
  116. $sql.= " FROM ".MAIN_DB_PREFIX."const";
  117. $sql.= " WHERE name LIKE 'COMPTA_%'";
  118. $sql.= " AND name NOT IN ('COMPTA_MODE')";
  119. $sql.= " AND entity = ".$conf->entity;
  120. $result = $db->query($sql);
  121. if ($result)
  122. {
  123. $num = $db->num_rows($result);
  124. $i = 0;
  125. while ($i < $num)
  126. {
  127. $obj = $db->fetch_object($result);
  128. $var=!$var;
  129. $list[$obj->name]=$obj->value;
  130. $i++;
  131. }
  132. }*/
  133. $num=count($list);
  134. if ($num)
  135. {
  136. print '<table class="noborder" width="100%">';
  137. print '<tr class="liste_titre">';
  138. print '<td colspan="3">'.$langs->trans('OtherOptions').'</td>';
  139. print "</tr>\n";
  140. }
  141. foreach ($list as $key)
  142. {
  143. $var=!$var;
  144. print '<form action="compta.php" method="POST">';
  145. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  146. print '<input type="hidden" name="action" value="update">';
  147. print '<input type="hidden" name="consttype" value="string">';
  148. print '<input type="hidden" name="constname" value="'.$key.'">';
  149. print '<tr '.$bc[$var].' class="value">';
  150. // Param
  151. $libelle = $langs->trans($key);
  152. print '<td>'.$libelle;
  153. //print ' ('.$key.')';
  154. print "</td>\n";
  155. // Value
  156. print '<td>';
  157. print '<input type="text" size="20" name="constvalue" value="'.$conf->global->$key.'">';
  158. print '</td><td>';
  159. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"> &nbsp; ';
  160. print "</td></tr>\n";
  161. print '</form>';
  162. $i++;
  163. }
  164. if ($num)
  165. {
  166. print "</table>\n";
  167. }
  168. $db->close();
  169. llxFooter();
  170. ?>