export.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2024 Alexandre Spangaro <aspangaro@easya.solutions>
  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 (!$user->hasRight('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. $help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
  111. $title = $langs->trans('ExportOptions');
  112. llxHeader('', $title, $help_url);
  113. $linkback = '';
  114. // $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
  115. print load_fiche_titre($langs->trans('ExportOptions'), $linkback, 'accountancy');
  116. print "\n".'<script type="text/javascript">'."\n";
  117. print 'jQuery(document).ready(function () {'."\n";
  118. print ' function initfields()'."\n";
  119. print ' {'."\n";
  120. foreach ($listparam as $key => $param) {
  121. print ' if (jQuery("#ACCOUNTING_EXPORT_MODELCSV").val()=="'.$key.'")'."\n";
  122. print ' {'."\n";
  123. print ' //console.log("'.$param['label'].'");'."\n";
  124. if (empty($param['ACCOUNTING_EXPORT_FORMAT'])) {
  125. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").val("'.getDolGlobalString('ACCOUNTING_EXPORT_FORMAT').'");'."\n";
  126. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").prop("disabled", true);'."\n";
  127. } else {
  128. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").val("'.$param['ACCOUNTING_EXPORT_FORMAT'].'");'."\n";
  129. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").removeAttr("disabled");'."\n";
  130. }
  131. if (empty($param['ACCOUNTING_EXPORT_SEPARATORCSV'])) {
  132. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").val("");'."\n";
  133. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").prop("disabled", true);'."\n";
  134. } else {
  135. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").val("'.getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV').'");'."\n";
  136. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").removeAttr("disabled");'."\n";
  137. }
  138. if (empty($param['ACCOUNTING_EXPORT_ENDLINE'])) {
  139. print ' jQuery("#ACCOUNTING_EXPORT_ENDLINE").prop("disabled", true);'."\n";
  140. } else {
  141. print ' jQuery("#ACCOUNTING_EXPORT_ENDLINE").removeAttr("disabled");'."\n";
  142. }
  143. if (empty($param['ACCOUNTING_EXPORT_DATE'])) {
  144. print ' jQuery("#ACCOUNTING_EXPORT_DATE").val("");'."\n";
  145. print ' jQuery("#ACCOUNTING_EXPORT_DATE").prop("disabled", true);'."\n";
  146. } else {
  147. print ' jQuery("#ACCOUNTING_EXPORT_DATE").val("'.getDolGlobalString('ACCOUNTING_EXPORT_DATE').'");'."\n";
  148. print ' jQuery("#ACCOUNTING_EXPORT_DATE").removeAttr("disabled");'."\n";
  149. }
  150. print ' }'."\n";
  151. }
  152. print ' }'."\n";
  153. print ' initfields();'."\n";
  154. print ' jQuery("#ACCOUNTING_EXPORT_MODELCSV").change(function() {'."\n";
  155. print ' initfields();'."\n";
  156. print ' });'."\n";
  157. print '})'."\n";
  158. print '</script>'."\n";
  159. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  160. print '<input type="hidden" name="token" value="'.newToken().'">';
  161. print '<input type="hidden" name="action" value="update">';
  162. /*
  163. * Main Options
  164. */
  165. print '<table class="noborder centpercent">';
  166. print '<tr class="liste_titre">';
  167. print '<td colspan="3">'.$langs->trans('Options').'</td>';
  168. print "</tr>\n";
  169. $num = count($main_option);
  170. if ($num) {
  171. foreach ($main_option as $key) {
  172. print '<tr class="oddeven value">';
  173. // Param
  174. $label = $langs->trans($key);
  175. print '<td width="50%">'.$label.'</td>';
  176. // Value
  177. print '<td>';
  178. print '<input type="text" size="20" id="'.$key.'" name="'.$key.'" value="'.getDolGlobalString($key).'">';
  179. print '</td></tr>';
  180. }
  181. }
  182. print "</table>\n";
  183. print "<br>\n";
  184. /*
  185. * Export model
  186. */
  187. print '<table class="noborder centpercent">';
  188. print '<tr class="liste_titre">';
  189. print '<td colspan="2">'.$langs->trans("Modelcsv").'</td>';
  190. print '</tr>';
  191. print '<tr class="oddeven">';
  192. print '<td width="50%">'.$langs->trans("Selectmodelcsv").'</td>';
  193. if (!$conf->use_javascript_ajax) {
  194. print '<td class="nowrap">';
  195. print $langs->trans("NotAvailableWhenAjaxDisabled");
  196. print "</td>";
  197. } else {
  198. print '<td>';
  199. $listmodelcsv = $accountancyexport->getType();
  200. print $form->selectarray("ACCOUNTING_EXPORT_MODELCSV", $listmodelcsv, getDolGlobalString('ACCOUNTING_EXPORT_MODELCSV'), 0, 0, 0, '', 0, 0, 0, '', '', 1);
  201. print '</td>';
  202. }
  203. print "</td></tr>";
  204. print "</table>";
  205. print "<br>\n";
  206. /*
  207. * Parameters
  208. */
  209. $num2 = count($model_option);
  210. if ($num2) {
  211. print '<table class="noborder centpercent">';
  212. print '<tr class="liste_titre">';
  213. print '<td colspan="3">'.$langs->trans('OtherOptions').'</td>';
  214. print "</tr>\n";
  215. foreach ($model_option as $key) {
  216. print '<tr class="oddeven value">';
  217. // Param
  218. $label = $key['label'];
  219. print '<td width="50%">'.$langs->trans($label).'</td>';
  220. // Value
  221. print '<td>';
  222. if (is_array($key['param'])) {
  223. print $form->selectarray($label, $key['param'], getDolGlobalString($label), 0);
  224. } else {
  225. print '<input type="text" size="20" id="'.$label.'" name="'.$key['label'].'" value="'.getDolGlobalString($label).'">';
  226. }
  227. print '</td></tr>';
  228. }
  229. print "</table>\n";
  230. }
  231. print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Modify')).'" name="button"></div>';
  232. print '</form>';
  233. // End of page
  234. llxFooter();
  235. $db->close();