fiscalyear_card.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. /* Copyright (C) 2014-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/accountancy/admin/fiscalyear_card.php
  20. * \ingroup Advanced accountancy
  21. * \brief Page to show a fiscal year
  22. */
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT . '/core/lib/fiscalyear.lib.php';
  25. require_once DOL_DOCUMENT_ROOT . '/core/class/fiscalyear.class.php';
  26. // Load translation files required by the page
  27. $langs->loadLangs(array("admin","compta"));
  28. // Security check
  29. if ($user->societe_id > 0)
  30. accessforbidden();
  31. if (empty($user->rights->accounting->fiscalyear))
  32. accessforbidden();
  33. $error = 0;
  34. $action = GETPOST('action', 'aZ09');
  35. $confirm = GETPOST('confirm', 'alpha');
  36. $id = GETPOST('id', 'int');
  37. // List of statut
  38. static $tmpstatut2label = array (
  39. '0' => 'OpenFiscalYear',
  40. '1' => 'CloseFiscalYear'
  41. );
  42. $statut2label = array (
  43. ''
  44. );
  45. foreach ( $tmpstatut2label as $key => $val )
  46. $statut2label[$key] = $langs->trans($val);
  47. $object = new Fiscalyear($db);
  48. $date_start = dol_mktime(0, 0, 0, GETPOST('fiscalyearmonth', 'int'), GETPOST('fiscalyearday', 'int'), GETPOST('fiscalyearyear', 'int'));
  49. $date_end = dol_mktime(0, 0, 0, GETPOST('fiscalyearendmonth', 'int'), GETPOST('fiscalyearendday', 'int'), GETPOST('fiscalyearendyear', 'int'));
  50. /*
  51. * Actions
  52. */
  53. if ($action == 'confirm_delete' && $confirm == "yes") {
  54. $result = $object->delete($id);
  55. if ($result >= 0) {
  56. header("Location: fiscalyear.php");
  57. exit();
  58. } else {
  59. setEventMessages($object->error, $object->errors, 'errors');
  60. }
  61. }
  62. elseif ($action == 'add') {
  63. if (! GETPOST('cancel', 'alpha')) {
  64. $error = 0;
  65. $object->date_start = $date_start;
  66. $object->date_end = $date_end;
  67. $object->label = GETPOST('label', 'alpha');
  68. $object->statut = GETPOST('statut', 'int');
  69. $object->datec = dol_now();
  70. if (empty($object->date_start) && empty($object->date_end)) {
  71. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  72. $error ++;
  73. }
  74. if (empty($object->label)) {
  75. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
  76. $error ++;
  77. }
  78. if (! $error) {
  79. $db->begin();
  80. $id = $object->create($user);
  81. if ($id > 0) {
  82. $db->commit();
  83. header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
  84. exit();
  85. } else {
  86. $db->rollback();
  87. setEventMessages($object->error, $object->errors, 'errors');
  88. $action = 'create';
  89. }
  90. } else {
  91. $action = 'create';
  92. }
  93. } else {
  94. header("Location: ./fiscalyear.php");
  95. exit();
  96. }
  97. }
  98. // Update record
  99. elseif ($action == 'update') {
  100. if (! GETPOST('cancel', 'alpha')) {
  101. $result = $object->fetch($id);
  102. $object->date_start = empty($_POST["fiscalyear"]) ? '' : $date_start;
  103. $object->date_end = empty($_POST["fiscalyearend"]) ? '' : $date_end;
  104. $object->label = GETPOST('label', 'alpha');
  105. $object->statut = GETPOST('statut', 'int');
  106. $result = $object->update($user);
  107. if ($result > 0) {
  108. header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
  109. exit();
  110. } else {
  111. setEventMessages($object->error, $object->errors, 'errors');
  112. }
  113. } else {
  114. header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
  115. exit();
  116. }
  117. }
  118. /*
  119. * View
  120. */
  121. $form = new Form($db);
  122. $title = $langs->trans("Fiscalyear") . " - " . $langs->trans("Card");
  123. $helpurl = "";
  124. llxHeader("",$title,$helpurl);
  125. if ($action == 'create')
  126. {
  127. print load_fiche_titre($langs->trans("NewFiscalYear"));
  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="add">';
  131. dol_fiche_head();
  132. print '<table class="border" width="100%">';
  133. // Label
  134. print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans("Label") . '</td><td><input name="label" size="32" value="' . GETPOST('label', 'alpha') . '"></td></tr>';
  135. // Date start
  136. print '<tr><td class="fieldrequired">' . $langs->trans("DateStart") . '</td><td>';
  137. print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
  138. print '</td></tr>';
  139. // Date end
  140. print '<tr><td class="fieldrequired">' . $langs->trans("DateEnd") . '</td><td>';
  141. print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
  142. print '</td></tr>';
  143. /*
  144. // Statut
  145. print '<tr>';
  146. print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
  147. print '<td class="valeur">';
  148. print $form->selectarray('statut', $statut2label, GETPOST('statut', 'int'));
  149. print '</td></tr>';
  150. */
  151. print '</table>';
  152. dol_fiche_end();
  153. print '<div class="center">';
  154. print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
  155. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  156. print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
  157. print '</div>';
  158. print '</form>';
  159. } elseif ($id) {
  160. $result = $object->fetch($id);
  161. if ($result > 0) {
  162. $head = fiscalyear_prepare_head($object);
  163. if ($action == 'edit') {
  164. dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
  165. print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
  166. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  167. print '<input type="hidden" name="action" value="update">';
  168. print '<input type="hidden" name="id" value="' . $id . '">';
  169. print '<table class="border" width="100%">';
  170. // Ref
  171. print "<tr>";
  172. print '<td class="titlefieldcreate titlefield">' . $langs->trans("Ref") . '</td><td>';
  173. print $object->ref;
  174. print '</td></tr>';
  175. // Label
  176. print '<tr><td class="fieldrequired">' . $langs->trans("Label") . '</td><td>';
  177. print '<input name="label" class="flat" size="32" value="' . $object->label . '">';
  178. print '</td></tr>';
  179. // Date start
  180. print '<tr><td class="fieldrequired">' . $langs->trans("DateStart") . '</td><td>';
  181. print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
  182. print '</td></tr>';
  183. // Date end
  184. print '<tr><td class="fieldrequired">' . $langs->trans("DateEnd") . '</td><td>';
  185. print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
  186. print '</td></tr>';
  187. // Statut
  188. print '<tr><td>' . $langs->trans("Statut") . '</td><td>';
  189. // print $form->selectarray('statut', $statut2label, $object->statut);
  190. print $object->getLibStatut(4);
  191. print '</td></tr>';
  192. print '</table>';
  193. print '<br><div class="center">';
  194. print '<input type="submit" class="button" value="' . $langs->trans("Save") . '">';
  195. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  196. print '<input type="submit" name="cancel" class="button" value="' . $langs->trans("Cancel") . '">';
  197. print '</div>';
  198. print '</form>';
  199. dol_fiche_end();
  200. } else {
  201. /*
  202. * Confirm delete
  203. */
  204. if ($action == 'delete') {
  205. print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete");
  206. }
  207. dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
  208. print '<table class="border" width="100%">';
  209. $linkback = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/fiscalyear.php">' . $langs->trans("BackToList") . '</a>';
  210. // Ref
  211. print '<tr><td class="titlefield">' . $langs->trans("Ref") . '</td><td width="50%">';
  212. print $object->ref;
  213. print '</td><td>';
  214. print $linkback;
  215. print '</td></tr>';
  216. // Label
  217. print '<tr><td class="tdtop">';
  218. print $form->editfieldkey("Label", 'label', $object->label, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'alpha:32');
  219. print '</td><td colspan="2">';
  220. print $form->editfieldval("Label", 'label', $object->label, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'alpha:32');
  221. print "</td></tr>";
  222. // Date start
  223. print '<tr><td>';
  224. print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
  225. print '</td><td colspan="2">';
  226. print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
  227. print '</td></tr>';
  228. // Date end
  229. print '<tr><td>';
  230. print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
  231. print '</td><td colspan="2">';
  232. print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
  233. print '</td></tr>';
  234. // Statut
  235. print '<tr><td>' . $langs->trans("Status") . '</td><td colspan="2">' . $object->getLibStatut(4) . '</td></tr>';
  236. print "</table>";
  237. dol_fiche_end();
  238. if (! empty($user->rights->accounting->fiscalyear))
  239. {
  240. /*
  241. * Barre d'actions
  242. */
  243. print '<div class="tabsAction">';
  244. print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=edit&id=' . $id . '">' . $langs->trans('Modify') . '</a>';
  245. // print '<a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?action=delete&id=' . $id . '">' . $langs->trans('Delete') . '</a>';
  246. print '</div>';
  247. }
  248. }
  249. } else {
  250. dol_print_error($db);
  251. }
  252. }
  253. // End of page
  254. llxFooter();
  255. $db->close();