export.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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) 2017-2018 Frédéric France <frederic.france@netlogic.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 <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/accountancy/admin/export.php
  25. * \ingroup Accountancy (Double entries)
  26. * \brief Setup page to configure accounting export module
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("compta", "bills", "admin", "accountancy"));
  34. // Security access
  35. if (empty($user->rights->accounting->chartofaccount)) {
  36. accessforbidden();
  37. }
  38. $action = GETPOST('action', 'aZ09');
  39. // Parameters ACCOUNTING_EXPORT_*
  40. $main_option = array(
  41. 'ACCOUNTING_EXPORT_PREFIX_SPEC',
  42. );
  43. $accountancyexport = new AccountancyExport($db);
  44. $configuration = $accountancyexport->getTypeConfig();
  45. $listparam = $configuration['param'];
  46. $listformat = $configuration['format'];
  47. $listcr = $configuration['cr'];
  48. $model_option = array(
  49. '1' => array(
  50. 'label' => 'ACCOUNTING_EXPORT_FORMAT',
  51. 'param' => $listformat,
  52. ),
  53. '2' => array(
  54. 'label' => 'ACCOUNTING_EXPORT_SEPARATORCSV',
  55. 'param' => '',
  56. ),
  57. '3' => array(
  58. 'label' => 'ACCOUNTING_EXPORT_ENDLINE',
  59. 'param' => $listcr,
  60. ),
  61. '4' => array(
  62. 'label' => 'ACCOUNTING_EXPORT_DATE',
  63. 'param' => '',
  64. ),
  65. );
  66. /*
  67. * Actions
  68. */
  69. if ($action == 'update') {
  70. $error = 0;
  71. $modelcsv = GETPOST('ACCOUNTING_EXPORT_MODELCSV', 'int');
  72. if (!empty($modelcsv)) {
  73. if (!dolibarr_set_const($db, 'ACCOUNTING_EXPORT_MODELCSV', $modelcsv, 'chaine', 0, '', $conf->entity)) {
  74. $error++;
  75. }
  76. //if ($modelcsv==AccountancyExport::$EXPORT_TYPE_QUADRATUS || $modelcsv==AccountancyExport::$EXPORT_TYPE_CIEL) {
  77. // dolibarr_set_const($db, 'ACCOUNTING_EXPORT_FORMAT', 'txt', 'chaine', 0, '', $conf->entity);
  78. //}
  79. } else {
  80. $error++;
  81. }
  82. foreach ($main_option as $constname) {
  83. $constvalue = GETPOST($constname, 'alpha');
  84. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  85. $error++;
  86. }
  87. }
  88. foreach ($listparam[$modelcsv] as $key => $value) {
  89. $constante = $key;
  90. if (strpos($constante, 'ACCOUNTING') !== false) {
  91. $constvalue = GETPOST($key, 'alpha');
  92. if (!dolibarr_set_const($db, $constante, $constvalue, 'chaine', 0, '', $conf->entity)) {
  93. $error++;
  94. }
  95. }
  96. }
  97. if (!$error) {
  98. // reload
  99. $configuration = $accountancyexport->getTypeConfig();
  100. $listparam = $configuration['param'];
  101. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  102. } else {
  103. setEventMessages($langs->trans("Error"), null, 'errors');
  104. }
  105. }
  106. /*
  107. * View
  108. */
  109. $form = new Form($db);
  110. $title = $langs->trans('ExportOptions');
  111. llxHeader('', $title);
  112. $linkback = '';
  113. // $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
  114. print load_fiche_titre($langs->trans('ExportOptions'), $linkback, 'accountancy');
  115. print "\n".'<script type="text/javascript">'."\n";
  116. print 'jQuery(document).ready(function () {'."\n";
  117. print ' function initfields()'."\n";
  118. print ' {'."\n";
  119. foreach ($listparam as $key => $param) {
  120. print ' if (jQuery("#ACCOUNTING_EXPORT_MODELCSV").val()=="'.$key.'")'."\n";
  121. print ' {'."\n";
  122. print ' //console.log("'.$param['label'].'");'."\n";
  123. if (empty($param['ACCOUNTING_EXPORT_FORMAT'])) {
  124. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").val("'.$conf->global->ACCOUNTING_EXPORT_FORMAT.'");'."\n";
  125. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").prop("disabled", true);'."\n";
  126. } else {
  127. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").val("'.$param['ACCOUNTING_EXPORT_FORMAT'].'");'."\n";
  128. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").removeAttr("disabled");'."\n";
  129. }
  130. if (empty($param['ACCOUNTING_EXPORT_SEPARATORCSV'])) {
  131. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").val("");'."\n";
  132. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").prop("disabled", true);'."\n";
  133. } else {
  134. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").val("'.$conf->global->ACCOUNTING_EXPORT_SEPARATORCSV.'");'."\n";
  135. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").removeAttr("disabled");'."\n";
  136. }
  137. if (empty($param['ACCOUNTING_EXPORT_ENDLINE'])) {
  138. print ' jQuery("#ACCOUNTING_EXPORT_ENDLINE").prop("disabled", true);'."\n";
  139. } else {
  140. print ' jQuery("#ACCOUNTING_EXPORT_ENDLINE").removeAttr("disabled");'."\n";
  141. }
  142. if (empty($param['ACCOUNTING_EXPORT_DATE'])) {
  143. print ' jQuery("#ACCOUNTING_EXPORT_DATE").val("");'."\n";
  144. print ' jQuery("#ACCOUNTING_EXPORT_DATE").prop("disabled", true);'."\n";
  145. } else {
  146. print ' jQuery("#ACCOUNTING_EXPORT_DATE").val("'.$conf->global->ACCOUNTING_EXPORT_DATE.'");'."\n";
  147. print ' jQuery("#ACCOUNTING_EXPORT_DATE").removeAttr("disabled");'."\n";
  148. }
  149. print ' }'."\n";
  150. }
  151. print ' }'."\n";
  152. print ' initfields();'."\n";
  153. print ' jQuery("#ACCOUNTING_EXPORT_MODELCSV").change(function() {'."\n";
  154. print ' initfields();'."\n";
  155. print ' });'."\n";
  156. print '})'."\n";
  157. print '</script>'."\n";
  158. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  159. print '<input type="hidden" name="token" value="'.newToken().'">';
  160. print '<input type="hidden" name="action" value="update">';
  161. /*
  162. * Main Options
  163. */
  164. print '<table class="noborder centpercent">';
  165. print '<tr class="liste_titre">';
  166. print '<td colspan="3">'.$langs->trans('Options').'</td>';
  167. print "</tr>\n";
  168. $num = count($main_option);
  169. if ($num) {
  170. foreach ($main_option as $key) {
  171. print '<tr class="oddeven value">';
  172. // Param
  173. $label = $langs->trans($key);
  174. print '<td width="50%">'.$label.'</td>';
  175. // Value
  176. print '<td>';
  177. print '<input type="text" size="20" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
  178. print '</td></tr>';
  179. }
  180. }
  181. print "</table>\n";
  182. print "<br>\n";
  183. /*
  184. * Export model
  185. */
  186. print '<table class="noborder centpercent">';
  187. print '<tr class="liste_titre">';
  188. print '<td colspan="2">'.$langs->trans("Modelcsv").'</td>';
  189. print '</tr>';
  190. print '<tr class="oddeven">';
  191. print '<td width="50%">'.$langs->trans("Selectmodelcsv").'</td>';
  192. if (!$conf->use_javascript_ajax) {
  193. print '<td class="nowrap">';
  194. print $langs->trans("NotAvailableWhenAjaxDisabled");
  195. print "</td>";
  196. } else {
  197. print '<td>';
  198. $listmodelcsv = $accountancyexport->getType();
  199. print $form->selectarray("ACCOUNTING_EXPORT_MODELCSV", $listmodelcsv, $conf->global->ACCOUNTING_EXPORT_MODELCSV, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  200. print '</td>';
  201. }
  202. print "</td></tr>";
  203. print "</table>";
  204. print "<br>\n";
  205. /*
  206. * Parameters
  207. */
  208. $num2 = count($model_option);
  209. if ($num2) {
  210. print '<table class="noborder centpercent">';
  211. print '<tr class="liste_titre">';
  212. print '<td colspan="3">'.$langs->trans('OtherOptions').'</td>';
  213. print "</tr>\n";
  214. foreach ($model_option as $key) {
  215. print '<tr class="oddeven value">';
  216. // Param
  217. $label = $key['label'];
  218. print '<td width="50%">'.$langs->trans($label).'</td>';
  219. // Value
  220. print '<td>';
  221. if (is_array($key['param'])) {
  222. print $form->selectarray($label, $key['param'], $conf->global->$label, 0);
  223. } else {
  224. print '<input type="text" size="20" id="'.$label.'" name="'.$key['label'].'" value="'.$conf->global->$label.'">';
  225. }
  226. print '</td></tr>';
  227. }
  228. print "</table>\n";
  229. }
  230. print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Modify')).'" name="button"></div>';
  231. print '</form>';
  232. // End of page
  233. llxFooter();
  234. $db->close();