fiscalyear_card.php 9.4 KB

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