journals_list.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. <?php
  2. /* Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. *
  17. */
  18. /**
  19. * \file htdocs/accountancy/admin/journals_list.php
  20. * \ingroup Accountancy (Double entries)
  21. * \brief Setup page to configure journals
  22. */
  23. if (!defined('CSRFCHECK_WITH_TOKEN')) {
  24. define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
  25. }
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("admin", "compta", "accountancy"));
  36. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view';
  37. $confirm = GETPOST('confirm', 'alpha');
  38. $id = 35;
  39. $rowid = GETPOST('rowid', 'alpha');
  40. $code = GETPOST('code', 'alpha');
  41. // Security access
  42. if (empty($user->rights->accounting->chartofaccount)) {
  43. accessforbidden();
  44. }
  45. $acts[0] = "activate";
  46. $acts[1] = "disable";
  47. $actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
  48. $actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
  49. $listoffset = GETPOST('listoffset', 'alpha');
  50. $listlimit = GETPOST('listlimit', 'int') > 0 ?GETPOST('listlimit', 'int') : 1000;
  51. $active = 1;
  52. $sortfield = GETPOST('sortfield', 'aZ09comma');
  53. $sortorder = GETPOST('sortorder', 'aZ09comma');
  54. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  55. if (empty($page) || $page == -1) {
  56. $page = 0;
  57. } // If $page is not defined, or '' or -1
  58. $offset = $listlimit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. if (empty($sortfield)) {
  62. $sortfield = 'code';
  63. }
  64. if (empty($sortorder)) {
  65. $sortorder = 'ASC';
  66. }
  67. $error = 0;
  68. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  69. $hookmanager->initHooks(array('admin'));
  70. // This page is a generic page to edit dictionaries
  71. // Put here declaration of dictionaries properties
  72. // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
  73. $taborder = array(35);
  74. // Name of SQL tables of dictionaries
  75. $tabname = array();
  76. $tabname[35] = MAIN_DB_PREFIX."accounting_journal";
  77. // Dictionary labels
  78. $tablib = array();
  79. $tablib[35] = "DictionaryAccountancyJournal";
  80. // Requests to extract data
  81. $tabsql = array();
  82. $tabsql[35] = "SELECT a.rowid as rowid, a.code as code, a.label, a.nature, a.active FROM ".MAIN_DB_PREFIX."accounting_journal as a";
  83. // Criteria to sort dictionaries
  84. $tabsqlsort = array();
  85. $tabsqlsort[35] = "code ASC";
  86. // Nom des champs en resultat de select pour affichage du dictionnaire
  87. $tabfield = array();
  88. $tabfield[35] = "code,label,nature";
  89. // Nom des champs d'edition pour modification d'un enregistrement
  90. $tabfieldvalue = array();
  91. $tabfieldvalue[35] = "code,label,nature";
  92. // Nom des champs dans la table pour insertion d'un enregistrement
  93. $tabfieldinsert = array();
  94. $tabfieldinsert[35] = "code,label,nature";
  95. // Nom du rowid si le champ n'est pas de type autoincrement
  96. // Example: "" if id field is "rowid" and has autoincrement on
  97. // "nameoffield" if id field is not "rowid" or has not autoincrement on
  98. $tabrowid = array();
  99. $tabrowid[35] = "";
  100. // Condition to show dictionary in setup page
  101. $tabcond = array();
  102. $tabcond[35] = !empty($conf->accounting->enabled);
  103. // List of help for fields
  104. $tabhelp = array();
  105. $tabhelp[35] = array('code'=>$langs->trans("EnterAnyCode"));
  106. // List of check for fields (NOT USED YET)
  107. $tabfieldcheck = array();
  108. $tabfieldcheck[35] = array();
  109. // Complete all arrays with entries found into modules
  110. complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
  111. // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
  112. $elementList = array();
  113. // Must match ids defined into eldy.lib.php
  114. $sourceList = array(
  115. '1' => $langs->trans('AccountingJournalType1'),
  116. '2' => $langs->trans('AccountingJournalType2'),
  117. '3' => $langs->trans('AccountingJournalType3'),
  118. '4' => $langs->trans('AccountingJournalType4'),
  119. '5' => $langs->trans('AccountingJournalType5'),
  120. '8' => $langs->trans('AccountingJournalType8'),
  121. '9' => $langs->trans('AccountingJournalType9'),
  122. );
  123. /*
  124. * Actions
  125. */
  126. if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
  127. $search_country_id = '';
  128. }
  129. // Actions add or modify an entry into a dictionary
  130. if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) {
  131. $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
  132. $listfieldinsert = explode(',', $tabfieldinsert[$id]);
  133. $listfieldmodify = explode(',', $tabfieldinsert[$id]);
  134. $listfieldvalue = explode(',', $tabfieldvalue[$id]);
  135. // Check that all fields are filled
  136. $ok = 1;
  137. foreach ($listfield as $f => $value) {
  138. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
  139. $fieldnamekey = 'Label';
  140. }
  141. if ($fieldnamekey == 'code') {
  142. $fieldnamekey = 'Code';
  143. }
  144. if ($fieldnamekey == 'nature') {
  145. $fieldnamekey = 'NatureOfJournal';
  146. }
  147. }
  148. // Other checks
  149. if (GETPOSTISSET("code")) {
  150. if (GETPOST("code") == '0') {
  151. $ok = 0;
  152. setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
  153. }
  154. /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
  155. {
  156. $ok = 0;
  157. $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br>';
  158. }*/
  159. }
  160. if (!GETPOST('label', 'alpha')) {
  161. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
  162. $ok = 0;
  163. }
  164. // Clean some parameters
  165. if ($_POST["accountancy_code"] <= 0) {
  166. $_POST["accountancy_code"] = ''; // If empty, we force to null
  167. }
  168. if ($_POST["accountancy_code_sell"] <= 0) {
  169. $_POST["accountancy_code_sell"] = ''; // If empty, we force to null
  170. }
  171. if ($_POST["accountancy_code_buy"] <= 0) {
  172. $_POST["accountancy_code_buy"] = ''; // If empty, we force to null
  173. }
  174. // Si verif ok et action add, on ajoute la ligne
  175. if ($ok && GETPOST('actionadd', 'alpha')) {
  176. if ($tabrowid[$id]) {
  177. // Recupere id libre pour insertion
  178. $newid = 0;
  179. $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
  180. $result = $db->query($sql);
  181. if ($result) {
  182. $obj = $db->fetch_object($result);
  183. $newid = ($obj->newid + 1);
  184. } else {
  185. dol_print_error($db);
  186. }
  187. }
  188. // Add new entry
  189. $sql = "INSERT INTO ".$tabname[$id]." (";
  190. // List of fields
  191. if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
  192. $sql .= $tabrowid[$id].",";
  193. }
  194. $sql .= $tabfieldinsert[$id];
  195. $sql .= ",active,entity)";
  196. $sql .= " VALUES(";
  197. // List of values
  198. if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
  199. $sql .= $newid.",";
  200. }
  201. $i = 0;
  202. foreach ($listfieldinsert as $f => $value) {
  203. if ($value == 'entity') {
  204. $_POST[$listfieldvalue[$i]] = $conf->entity;
  205. }
  206. if ($i) {
  207. $sql .= ",";
  208. }
  209. if ($_POST[$listfieldvalue[$i]] == '') {
  210. $sql .= "null"; // For vat, we want/accept code = ''
  211. } else {
  212. $sql .= "'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  213. }
  214. $i++;
  215. }
  216. $sql .= ",1,".$conf->entity.")";
  217. dol_syslog("actionadd", LOG_DEBUG);
  218. $result = $db->query($sql);
  219. if ($result) { // Add is ok
  220. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  221. $_POST = array('id'=>$id); // Clean $_POST array, we keep only
  222. } else {
  223. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  224. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  225. } else {
  226. dol_print_error($db);
  227. }
  228. }
  229. }
  230. // Si verif ok et action modify, on modifie la ligne
  231. if ($ok && GETPOST('actionmodify', 'alpha')) {
  232. if ($tabrowid[$id]) {
  233. $rowidcol = $tabrowid[$id];
  234. } else {
  235. $rowidcol = "rowid";
  236. }
  237. // Modify entry
  238. $sql = "UPDATE ".$tabname[$id]." SET ";
  239. // Modifie valeur des champs
  240. if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
  241. $sql .= $tabrowid[$id]."=";
  242. $sql .= "'".$db->escape($rowid)."', ";
  243. }
  244. $i = 0;
  245. foreach ($listfieldmodify as $field) {
  246. if ($field == 'price' || preg_match('/^amount/i', $field) || $field == 'taux') {
  247. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]], 'MU');
  248. } elseif ($field == 'entity') {
  249. $_POST[$listfieldvalue[$i]] = $conf->entity;
  250. }
  251. if ($i) {
  252. $sql .= ",";
  253. }
  254. $sql .= $field."=";
  255. if ($_POST[$listfieldvalue[$i]] == '' && !($listfieldvalue[$i] == 'code' && $id == 10)) {
  256. $sql .= "null"; // For vat, we want/accept code = ''
  257. } else {
  258. $sql .= "'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  259. }
  260. $i++;
  261. }
  262. $sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
  263. $sql .= " AND entity = ".$conf->entity;
  264. dol_syslog("actionmodify", LOG_DEBUG);
  265. //print $sql;
  266. $resql = $db->query($sql);
  267. if (!$resql) {
  268. setEventMessages($db->error(), null, 'errors');
  269. }
  270. }
  271. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  272. }
  273. //if (GETPOST('actioncancel', 'alpha'))
  274. //{
  275. // $_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  276. //}
  277. if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
  278. if ($tabrowid[$id]) {
  279. $rowidcol = $tabrowid[$id];
  280. } else {
  281. $rowidcol = "rowid";
  282. }
  283. $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol." = ".((int) $rowid);
  284. $sql .= " AND entity = ".$conf->entity;
  285. dol_syslog("delete", LOG_DEBUG);
  286. $result = $db->query($sql);
  287. if (!$result) {
  288. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
  289. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  290. } else {
  291. dol_print_error($db);
  292. }
  293. }
  294. }
  295. // activate
  296. if ($action == $acts[0]) {
  297. if ($tabrowid[$id]) {
  298. $rowidcol = $tabrowid[$id];
  299. } else {
  300. $rowidcol = "rowid";
  301. }
  302. if ($rowid) {
  303. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol." = ".((int) $rowid);
  304. } elseif ($code) {
  305. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$db->escape($code)."'";
  306. }
  307. $sql .= " AND entity = ".$conf->entity;
  308. $result = $db->query($sql);
  309. if (!$result) {
  310. dol_print_error($db);
  311. }
  312. }
  313. // disable
  314. if ($action == $acts[1]) {
  315. if ($tabrowid[$id]) {
  316. $rowidcol = $tabrowid[$id];
  317. } else {
  318. $rowidcol = "rowid";
  319. }
  320. if ($rowid) {
  321. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol." = ".((int) $rowid);
  322. } elseif ($code) {
  323. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$db->escape($code)."'";
  324. }
  325. $sql .= " AND entity = ".$conf->entity;
  326. $result = $db->query($sql);
  327. if (!$result) {
  328. dol_print_error($db);
  329. }
  330. }
  331. /*
  332. * View
  333. */
  334. $form = new Form($db);
  335. $formadmin = new FormAdmin($db);
  336. llxHeader();
  337. $titre = $langs->trans("DictionarySetup");
  338. $linkback = '';
  339. if ($id) {
  340. $titre .= ' - '.$langs->trans($tablib[$id]);
  341. $titlepicto = 'title_accountancy';
  342. }
  343. print load_fiche_titre($titre, $linkback, $titlepicto);
  344. // Confirmation de la suppression de la ligne
  345. if ($action == 'delete') {
  346. print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
  347. }
  348. //var_dump($elementList);
  349. /*
  350. * Show a dictionary
  351. */
  352. if ($id) {
  353. // Complete requete recherche valeurs avec critere de tri
  354. $sql = $tabsql[$id];
  355. $sql .= " WHERE a.entity = ".$conf->entity;
  356. // If sort order is "country", we use country_code instead
  357. if ($sortfield == 'country') {
  358. $sortfield = 'country_code';
  359. }
  360. $sql .= $db->order($sortfield, $sortorder);
  361. $sql .= $db->plimit($listlimit + 1, $offset);
  362. $fieldlist = explode(',', $tabfield[$id]);
  363. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  364. print '<input type="hidden" name="token" value="'.newToken().'">';
  365. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
  366. print '<div class="div-table-responsive">';
  367. print '<table class="noborder centpercent">';
  368. // Form to add a new line
  369. if ($tabname[$id]) {
  370. $fieldlist = explode(',', $tabfield[$id]);
  371. // Line for title
  372. print '<tr class="liste_titre">';
  373. foreach ($fieldlist as $field => $value) {
  374. // Determine le nom du champ par rapport aux noms possibles
  375. // dans les dictionnaires de donnees
  376. $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
  377. $valuetoshow = $langs->trans($valuetoshow); // try to translate
  378. $class = "left";
  379. if ($fieldlist[$field] == 'code') {
  380. $valuetoshow = $langs->trans("Code");
  381. }
  382. if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
  383. $valuetoshow = $langs->trans("Label");
  384. }
  385. if ($fieldlist[$field] == 'nature') {
  386. $valuetoshow = $langs->trans("NatureOfJournal");
  387. }
  388. if ($valuetoshow != '') {
  389. print '<td class="'.$class.'">';
  390. if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
  391. print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
  392. } elseif (!empty($tabhelp[$id][$value])) {
  393. print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
  394. } else {
  395. print $valuetoshow;
  396. }
  397. print '</td>';
  398. }
  399. }
  400. print '<td>';
  401. print '<input type="hidden" name="id" value="'.$id.'">';
  402. print '</td>';
  403. print '<td style="min-width: 26px;"></td>';
  404. print '<td style="min-width: 26px;"></td>';
  405. print '<td style="min-width: 26px;"></td>';
  406. print '</tr>';
  407. // Line to enter new values
  408. print '<tr class="oddeven nodrag nodrap nohover">';
  409. $obj = new stdClass();
  410. // If data was already input, we define them in obj to populate input fields.
  411. if (GETPOST('actionadd', 'alpha')) {
  412. foreach ($fieldlist as $key => $val) {
  413. if (GETPOST($val) != '') {
  414. $obj->$val = GETPOST($val);
  415. }
  416. }
  417. }
  418. $tmpaction = 'create';
  419. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  420. $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  421. $error = $hookmanager->error; $errors = $hookmanager->errors;
  422. if (empty($reshook)) {
  423. fieldListJournal($fieldlist, $obj, $tabname[$id], 'add');
  424. }
  425. print '<td colspan="4" class="right">';
  426. print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
  427. print '</td>';
  428. print "</tr>";
  429. print '<tr><td colspan="7">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
  430. }
  431. // List of available record in database
  432. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  433. $resql = $db->query($sql);
  434. if ($resql) {
  435. $num = $db->num_rows($resql);
  436. $i = 0;
  437. $param = '&id='.$id;
  438. if ($search_country_id > 0) {
  439. $param .= '&search_country_id='.urlencode($search_country_id);
  440. }
  441. $paramwithsearch = $param;
  442. if ($sortorder) {
  443. $paramwithsearch .= '&sortorder='.$sortorder;
  444. }
  445. if ($sortfield) {
  446. $paramwithsearch .= '&sortfield='.$sortfield;
  447. }
  448. if (GETPOST('from', 'alpha')) {
  449. $paramwithsearch .= '&from='.GETPOST('from', 'alpha');
  450. }
  451. // There is several pages
  452. if ($num > $listlimit) {
  453. print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
  454. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
  455. print '</td></tr>';
  456. }
  457. // Title line with search boxes
  458. /*print '<tr class="liste_titre_filter liste_titre_add">';
  459. print '<td class="liste_titre"></td>';
  460. print '<td class="liste_titre"></td>';
  461. print '<td class="liste_titre"></td>';
  462. print '<td class="liste_titre"></td>';
  463. print '<td class="liste_titre"></td>';
  464. print '<td class="liste_titre"></td>';
  465. print '<td class="liste_titre center">';
  466. $searchpicto=$form->showFilterButtons();
  467. print $searchpicto;
  468. print '</td>';
  469. print '</tr>';
  470. */
  471. // Title of lines
  472. print '<tr class="liste_titre liste_titre_add">';
  473. foreach ($fieldlist as $field => $value) {
  474. // Determine le nom du champ par rapport aux noms possibles
  475. // dans les dictionnaires de donnees
  476. $showfield = 1; // By defaut
  477. $class = "left";
  478. $sortable = 1;
  479. $valuetoshow = '';
  480. /*
  481. $tmparray=getLabelOfField($fieldlist[$field]);
  482. $showfield=$tmp['showfield'];
  483. $valuetoshow=$tmp['valuetoshow'];
  484. $align=$tmp['align'];
  485. $sortable=$tmp['sortable'];
  486. */
  487. $valuetoshow = ucfirst($fieldlist[$field]); // By defaut
  488. $valuetoshow = $langs->trans($valuetoshow); // try to translate
  489. if ($fieldlist[$field] == 'code') {
  490. $valuetoshow = $langs->trans("Code");
  491. }
  492. if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
  493. $valuetoshow = $langs->trans("Label");
  494. }
  495. if ($fieldlist[$field] == 'nature') {
  496. $valuetoshow = $langs->trans("NatureOfJournal");
  497. }
  498. // Affiche nom du champ
  499. if ($showfield) {
  500. print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, "", $sortfield, $sortorder, $class.' ');
  501. }
  502. }
  503. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
  504. print getTitleFieldOfList('');
  505. print getTitleFieldOfList('');
  506. print getTitleFieldOfList('');
  507. print '</tr>';
  508. if ($num) {
  509. // Lines with values
  510. while ($i < $num) {
  511. $obj = $db->fetch_object($resql);
  512. //print_r($obj);
  513. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  514. if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
  515. $tmpaction = 'edit';
  516. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  517. $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  518. $error = $hookmanager->error; $errors = $hookmanager->errors;
  519. // Show fields
  520. if (empty($reshook)) {
  521. fieldListJournal($fieldlist, $obj, $tabname[$id], 'edit');
  522. }
  523. print '<td class="center" colspan="4">';
  524. print '<input type="hidden" name="page" value="'.$page.'">';
  525. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  526. print '<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans("Modify").'">';
  527. print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  528. print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
  529. print '</td>';
  530. } else {
  531. $tmpaction = 'view';
  532. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  533. $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  534. $error = $hookmanager->error; $errors = $hookmanager->errors;
  535. if (empty($reshook)) {
  536. $langs->load("accountancy");
  537. foreach ($fieldlist as $field => $value) {
  538. $showfield = 1;
  539. $class = "left";
  540. $valuetoshow = $obj->{$fieldlist[$field]};
  541. if ($valuetoshow == 'all') {
  542. $valuetoshow = $langs->trans('All');
  543. } elseif ($fieldlist[$field] == 'nature' && $tabname[$id] == MAIN_DB_PREFIX.'accounting_journal') {
  544. $key = $langs->trans("AccountingJournalType".strtoupper($obj->nature));
  545. $valuetoshow = ($obj->nature && $key != "AccountingJournalType".strtoupper($langs->trans($obj->nature)) ? $key : $obj->{$fieldlist[$field]});
  546. } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'accounting_journal') {
  547. $valuetoshow = $langs->trans($obj->label);
  548. }
  549. $class = 'tddict';
  550. // Show value for field
  551. if ($showfield) {
  552. print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.$valuetoshow.'</td>';
  553. }
  554. }
  555. }
  556. // Can an entry be erased or disabled ?
  557. $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default
  558. if (isset($obj->code) && $id != 10) {
  559. if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
  560. $iserasable = 0;
  561. $canbedisabled = 0;
  562. } elseif ($obj->code == 'RECEP') {
  563. $iserasable = 0;
  564. $canbedisabled = 0;
  565. } elseif ($obj->code == 'EF0') {
  566. $iserasable = 0;
  567. $canbedisabled = 0;
  568. }
  569. }
  570. $canbemodified = $iserasable;
  571. $url = $_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(!empty($obj->rowid) ? $obj->rowid : (!empty($obj->code) ? $obj->code : '')).'&code='.(!empty($obj->code) ?urlencode($obj->code) : '');
  572. if ($param) {
  573. $url .= '&'.$param;
  574. }
  575. $url .= '&';
  576. // Active
  577. print '<td class="nowrap center">';
  578. if ($canbedisabled) {
  579. print '<a href="'.$url.'action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
  580. } else {
  581. print $langs->trans("AlwaysActive");
  582. }
  583. print "</td>";
  584. // Modify link
  585. if ($canbemodified) {
  586. print '<td class="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
  587. } else {
  588. print '<td>&nbsp;</td>';
  589. }
  590. // Delete link
  591. if ($iserasable) {
  592. print '<td class="center">';
  593. if ($user->admin) {
  594. print '<a href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
  595. }
  596. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  597. print '</td>';
  598. } else {
  599. print '<td>&nbsp;</td>';
  600. }
  601. print '<td></td>';
  602. print '</td>';
  603. }
  604. print "</tr>\n";
  605. $i++;
  606. }
  607. }
  608. } else {
  609. dol_print_error($db);
  610. }
  611. print '</table>';
  612. print '</div>';
  613. print '</form>';
  614. }
  615. print '<br>';
  616. // End of page
  617. llxFooter();
  618. $db->close();
  619. /**
  620. * Show fields in insert/edit mode
  621. *
  622. * @param array $fieldlist Array of fields
  623. * @param Object $obj If we show a particular record, obj is filled with record fields
  624. * @param string $tabname Name of SQL table
  625. * @param string $context 'add'=Output field for the "add form", 'edit'=Output field for the "edit form", 'hide'=Output field for the "add form" but we dont want it to be rendered
  626. * @return void
  627. */
  628. function fieldListJournal($fieldlist, $obj = '', $tabname = '', $context = '')
  629. {
  630. global $conf, $langs, $db;
  631. global $form, $mysoc;
  632. global $region_id;
  633. global $elementList, $sourceList, $localtax_typeList;
  634. global $bc;
  635. $formadmin = new FormAdmin($db);
  636. $formcompany = new FormCompany($db);
  637. foreach ($fieldlist as $field => $value) {
  638. if ($fieldlist[$field] == 'nature') {
  639. print '<td>';
  640. print $form->selectarray('nature', $sourceList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''));
  641. print '</td>';
  642. } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
  643. print '<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
  644. } else {
  645. print '<td>';
  646. $size = ''; $class = '';
  647. if ($fieldlist[$field] == 'code') {
  648. $class = 'maxwidth100';
  649. }
  650. if ($fieldlist[$field] == 'label') {
  651. $class = 'quatrevingtpercent';
  652. }
  653. if ($fieldlist[$field] == 'sortorder' || $fieldlist[$field] == 'sens' || $fieldlist[$field] == 'category_type') {
  654. $size = 'size="2" ';
  655. }
  656. print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
  657. print '</td>';
  658. }
  659. }
  660. }