fiscalyear_card.php 9.7 KB

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