fiscalyear_card.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <?php
  2. /* Copyright (C) 2014-2024 Alexandre Spangaro <aspangaro@easya.solutions>
  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. // Get parameters
  30. $id = GETPOST('id', 'int');
  31. $ref = GETPOST('ref', 'alpha');
  32. $action = GETPOST('action', 'aZ09');
  33. $confirm = GETPOST('confirm', 'alpha');
  34. $cancel = GETPOST('cancel', 'aZ09');
  35. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
  36. $backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used
  37. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
  38. $backtopagejsfields = GETPOST('backtopagejsfields', 'alpha');
  39. $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
  40. if (!empty($backtopagejsfields)) {
  41. $tmpbacktopagejsfields = explode(':', $backtopagejsfields);
  42. $dol_openinpopup = $tmpbacktopagejsfields[0];
  43. }
  44. $error = 0;
  45. // Initialize technical objects
  46. $object = new Fiscalyear($db);
  47. $extrafields = new ExtraFields($db);
  48. // Load object
  49. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  50. // List of status
  51. static $tmpstatus2label = array(
  52. '0' => 'OpenFiscalYear',
  53. '1' => 'CloseFiscalYear'
  54. );
  55. $status2label = array(
  56. ''
  57. );
  58. foreach ($tmpstatus2label as $key => $val) {
  59. $status2label[$key] = $langs->trans($val);
  60. }
  61. $date_start = dol_mktime(0, 0, 0, GETPOST('fiscalyearmonth', 'int'), GETPOST('fiscalyearday', 'int'), GETPOST('fiscalyearyear', 'int'));
  62. $date_end = dol_mktime(0, 0, 0, GETPOST('fiscalyearendmonth', 'int'), GETPOST('fiscalyearendday', 'int'), GETPOST('fiscalyearendyear', 'int'));
  63. $permissiontoadd = $user->hasRight('accounting', 'fiscalyear', 'write');
  64. // Security check
  65. if ($user->socid > 0) {
  66. accessforbidden();
  67. }
  68. if (!$permissiontoadd) {
  69. accessforbidden();
  70. }
  71. /*
  72. * Actions
  73. */
  74. $parameters = array();
  75. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  76. if ($reshook < 0) {
  77. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  78. }
  79. if ($action == 'confirm_delete' && $confirm == "yes") {
  80. $result = $object->delete($id);
  81. if ($result >= 0) {
  82. header("Location: fiscalyear.php");
  83. exit();
  84. } else {
  85. setEventMessages($object->error, $object->errors, 'errors');
  86. }
  87. } elseif ($action == 'add') {
  88. if (!GETPOST('cancel', 'alpha')) {
  89. $error = 0;
  90. $object->date_start = $date_start;
  91. $object->date_end = $date_end;
  92. $object->label = GETPOST('label', 'alpha');
  93. $object->status = GETPOST('status', 'int');
  94. $object->datec = dol_now();
  95. if (empty($object->date_start) && empty($object->date_end)) {
  96. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  97. $error++;
  98. }
  99. if (empty($object->label)) {
  100. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
  101. $error++;
  102. }
  103. if (!$error) {
  104. $db->begin();
  105. $id = $object->create($user);
  106. if ($id > 0) {
  107. $db->commit();
  108. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  109. exit();
  110. } else {
  111. $db->rollback();
  112. setEventMessages($object->error, $object->errors, 'errors');
  113. $action = 'create';
  114. }
  115. } else {
  116. $action = 'create';
  117. }
  118. } else {
  119. header("Location: ./fiscalyear.php");
  120. exit();
  121. }
  122. } elseif ($action == 'update') {
  123. // Update record
  124. if (!GETPOST('cancel', 'alpha')) {
  125. $result = $object->fetch($id);
  126. $object->date_start = GETPOST("fiscalyear") ? $date_start : '';
  127. $object->date_end = GETPOST("fiscalyearend") ? $date_end : '';
  128. $object->label = GETPOST('label', 'alpha');
  129. $object->status = GETPOST('status', 'int');
  130. $result = $object->update($user);
  131. if ($result > 0) {
  132. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  133. exit();
  134. } else {
  135. setEventMessages($object->error, $object->errors, 'errors');
  136. }
  137. } else {
  138. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  139. exit();
  140. }
  141. }
  142. /*
  143. * View
  144. */
  145. $form = new Form($db);
  146. $title = $langs->trans("Fiscalyear")." - ".$langs->trans("Card");
  147. if ($action == 'create') {
  148. $title = $langs->trans("NewFiscalYear");
  149. }
  150. $help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
  151. llxHeader('', $title, $help_url);
  152. if ($action == 'create') {
  153. print load_fiche_titre($title, '', 'object_'.$object->picto);
  154. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  155. print '<input type="hidden" name="token" value="'.newToken().'">';
  156. print '<input type="hidden" name="action" value="add">';
  157. print dol_get_fiche_head();
  158. print '<table class="border centpercent">';
  159. // Label
  160. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="32" value="'.GETPOST('label', 'alpha').'"></td></tr>';
  161. // Date start
  162. print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
  163. print $form->selectDate(($date_start ? $date_start : ''), 'fiscalyear');
  164. print '</td></tr>';
  165. // Date end
  166. print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
  167. print $form->selectDate(($date_end ? $date_end : - 1), 'fiscalyearend');
  168. print '</td></tr>';
  169. /*
  170. // Status
  171. print '<tr>';
  172. print '<td class="fieldrequired">' . $langs->trans("Status") . '</td>';
  173. print '<td class="valeur">';
  174. print $form->selectarray('status', $status2label, GETPOST('status', 'int'));
  175. print '</td></tr>';
  176. */
  177. print '</table>';
  178. print dol_get_fiche_end();
  179. print $form->buttonsSaveCancel("Create");
  180. print '</form>';
  181. }
  182. // Part to edit record
  183. if (($id || $ref) && $action == 'edit') {
  184. print load_fiche_titre($langs->trans("Fiscalyear"), '', 'object_'.$object->picto);
  185. print '<form method="POST" name="update" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  186. print '<input type="hidden" name="token" value="'.newToken().'">';
  187. print '<input type="hidden" name="action" value="update">';
  188. print '<input type="hidden" name="id" value="'.$object->id.'">';
  189. if ($backtopage) {
  190. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  191. }
  192. if ($backtopageforcancel) {
  193. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  194. }
  195. print dol_get_fiche_head();
  196. print '<table class="border centpercent tableforfieldedit">'."\n";
  197. // Ref
  198. print "<tr>";
  199. print '<td class="titlefieldcreate titlefield">'.$langs->trans("Ref").'</td><td>';
  200. print $object->ref;
  201. print '</td></tr>';
  202. // Label
  203. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
  204. print '<input name="label" class="flat" size="32" value="'.$object->label.'">';
  205. print '</td></tr>';
  206. // Date start
  207. print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
  208. print $form->selectDate($object->date_start ? $object->date_start : - 1, 'fiscalyear');
  209. print '</td></tr>';
  210. // Date end
  211. print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
  212. print $form->selectDate($object->date_end ? $object->date_end : - 1, 'fiscalyearend');
  213. print '</td></tr>';
  214. // Status
  215. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  216. print $object->getLibStatut(4);
  217. print '</td></tr>';
  218. print '</table>';
  219. print dol_get_fiche_end();
  220. print $form->buttonsSaveCancel();
  221. print '</form>';
  222. }
  223. // Part to show record
  224. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  225. $head = fiscalyear_prepare_head($object);
  226. print dol_get_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'calendar');
  227. $formconfirm = '';
  228. // Confirmation to delete
  229. if ($action == 'delete') {
  230. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete", '', 0, 1);
  231. }
  232. // Print form confirm
  233. print $formconfirm;
  234. // Object card
  235. // ------------------------------------------------------------
  236. $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/fiscalyear.php">'.$langs->trans("BackToList").'</a>';
  237. print '<table class="border centpercent">';
  238. // Ref
  239. print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td width="50%">';
  240. print $object->ref;
  241. print '</td><td>';
  242. print $linkback;
  243. print '</td></tr>';
  244. // Label
  245. print '<tr><td class="tdtop">';
  246. print $form->editfieldkey("Label", 'label', $object->label, $object, 1, 'alpha:32');
  247. print '</td><td colspan="2">';
  248. print $form->editfieldval("Label", 'label', $object->label, $object, 1, 'alpha:32');
  249. print "</td></tr>";
  250. // Date start
  251. print '<tr><td>';
  252. print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, 1, 'datepicker');
  253. print '</td><td colspan="2">';
  254. print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, 1, 'datepicker');
  255. print '</td></tr>';
  256. // Date end
  257. print '<tr><td>';
  258. print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, 1, 'datepicker');
  259. print '</td><td colspan="2">';
  260. print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, 1, 'datepicker');
  261. print '</td></tr>';
  262. // Status
  263. print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">'.$object->getLibStatut(4).'</td></tr>';
  264. print "</table>";
  265. print dol_get_fiche_end();
  266. /*
  267. * Action bar
  268. */
  269. if ($user->hasRight('accounting', 'fiscalyear', 'write')) {
  270. print '<div class="tabsAction">';
  271. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
  272. //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
  273. print '</div>';
  274. }
  275. }
  276. // End of page
  277. llxFooter();
  278. $db->close();