card.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. /* Copyright (C) 2015 ATM Consulting <support@atm-consulting.fr>
  3. * Copyright (C) 2019-2020 Open-DSI <support@open-dsi.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/intracommreport/card.php
  20. * \ingroup Intracomm report
  21. * \brief Page to manage intracomm report export
  22. */
  23. /**
  24. * Terms
  25. *
  26. * DEB = Declaration d'Exchanges de Biens (FR) = Declaration of Exchange of Goods (EN)
  27. * DES = Déclaration Européenne de Services (FR) = European Declaration of Services (EN)
  28. *
  29. * INTRACOMM: Douanes françaises (FR) = french customs (EN) - https://www.douane.gouv.fr/professionnels/commerce-international/import-export
  30. *
  31. */
  32. // Load Dolibarr environment
  33. require '../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/intracommreport/class/intracommreport.class.php';
  37. // Load translation files required by the page
  38. $langs->loadLangs(array("intracommreport"));
  39. // Get Parameters
  40. $id = GETPOST('id', 'int');
  41. $action = GETPOST('action');
  42. $year = GETPOSTINT('year');
  43. $month = GETPOSTINT('month');
  44. $label = (string) GETPOST('label', 'alphanohtml');
  45. $exporttype = GETPOSTISSET('exporttype') ? GETPOST('exporttype', 'alphanohtml') : 'deb'; // DEB or DES
  46. $type_declaration = (string) GETPOST('type_declaration', 'alphanohtml'); // 'introduction' or 'expedition'
  47. $backtopage = GETPOST('backtopage', 'alpha');
  48. $declaration = array(
  49. "deb" => $langs->trans("DEB"),
  50. "des" => $langs->trans("DES"),
  51. );
  52. $typeOfDeclaration = array(
  53. "introduction" => $langs->trans("Introduction"),
  54. "expedition" => $langs->trans("Expedition"),
  55. );
  56. // Initialize technical objects
  57. $object = new IntracommReport($db);
  58. if ($id > 0) {
  59. $object->fetch($id);
  60. }
  61. $form = new Form($db);
  62. $formother = new FormOther($db);
  63. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  64. $hookmanager->initHooks(array('intracommcard', 'globalcard'));
  65. $error = 0;
  66. // Permissions
  67. $permissiontoread = $user->rights->intracommreport->read;
  68. $permissiontoadd = $user->rights->intracommreport->write;
  69. $permissiontodelete = $user->rights->intracommreport->delete;
  70. // Security check (enable the most restrictive one)
  71. //if ($user->socid > 0) accessforbidden();
  72. //if ($user->socid > 0) $socid = $user->socid;
  73. //$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  74. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  75. if (empty($conf->intracommreport->enabled)) {
  76. accessforbidden();
  77. }
  78. if (!$permissiontoread) {
  79. accessforbidden();
  80. }
  81. /*
  82. * Actions
  83. */
  84. $parameters = array('id' => $id);
  85. // Note that $action and $object may have been modified by some hooks
  86. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  87. if ($reshook < 0) {
  88. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  89. }
  90. if ($permissiontodelete && $action == 'confirm_delete' && $confirm == 'yes') {
  91. $result = $object->delete($id, $user);
  92. if ($result > 0) {
  93. if (!empty($backtopage)) {
  94. header("Location: ".$backtopage);
  95. exit;
  96. } else {
  97. header("Location: list.php");
  98. exit;
  99. }
  100. } else {
  101. $errmesg = $object->error;
  102. }
  103. }
  104. if ($action == 'add' && $permissiontoadd) {
  105. $object->label = trim($label);
  106. $object->exporttype = trim($exporttype); // 'des' or 'deb'
  107. $object->type_declaration = $type_declaration; // 'introduction' or 'expedition'
  108. //$object->subscription = (int) $subscription;
  109. // Fill array 'array_options' with data from add form
  110. // $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
  111. // if ($ret < 0) {
  112. // $error++;
  113. // }
  114. if (empty($object->label)) {
  115. $error++;
  116. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  117. } else {
  118. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."intracommreport WHERE ref='".$db->escape($object->label)."'";
  119. $result = $db->query($sql);
  120. if ($result) {
  121. $num = $db->num_rows($result);
  122. }
  123. if ($num) {
  124. $error++;
  125. $langs->load("errors");
  126. setEventMessages($langs->trans("ErrorLabelAlreadyExists", $login), null, 'errors');
  127. }
  128. }
  129. if (!$error) {
  130. $id = $object->create($user);
  131. if ($id > 0) {
  132. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id);
  133. exit;
  134. } else {
  135. setEventMessages($object->error, $object->errors, 'errors');
  136. $action = 'create';
  137. }
  138. } else {
  139. $action = 'create';
  140. }
  141. }
  142. /*
  143. * View
  144. */
  145. $title = $langs->trans("IntracommReportTitle");
  146. llxHeader("", $title);
  147. // Creation mode
  148. if ($action == 'create') {
  149. print load_fiche_titre($langs->trans("IntracommReportTitle"));
  150. print '<form name="charge" method="post" action="'.$_SERVER["PHP_SELF"].'">';
  151. print '<input type="hidden" name="token" value="'.newToken().'">';
  152. print '<input type="hidden" name="action" value="add" />';
  153. print dol_get_fiche_head();
  154. print '<table class="border" width="100%">';
  155. // Label
  156. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" class="minwidth200" name="label" autofocus="autofocus"></td></tr>';
  157. // Declaration
  158. print '<tr><td class="fieldrequired">'.$langs->trans("Declaration")."</td><td>\n";
  159. print $form->selectarray("declaration", $declaration, GETPOST('declaration', 'alpha') ? GETPOST('declaration', 'alpha') : $object->declaration, 0);
  160. print "</td>\n";
  161. // Analysis period
  162. print '<tr>';
  163. print '<td class="titlefieldcreate fieldrequired">';
  164. print $langs->trans("AnalysisPeriod");
  165. print '</td>';
  166. print '<td>';
  167. print $formother->select_month($month ? date('M') : $month, 'month', 0, 1, 'widthauto valignmiddle ', true);
  168. print $formother->selectyear($year ? date('Y') : $year, 'year', 0, 3, 3, 0, 0, '', '', true);
  169. print '</td>';
  170. print '</tr>';
  171. // Type of declaration
  172. print '<tr><td class="fieldrequired">'.$langs->trans("TypeOfDeclaration")."</td><td>\n";
  173. print $form->selectarray("type_declaration", $typeOfDeclaration, GETPOST('type_declaration', 'alpha') ? GETPOST('type_declaration', 'alpha') : $object->type_declaration, 0);
  174. print "</td>\n";
  175. print '</table>';
  176. print dol_get_fiche_end();
  177. print $form->buttonsSaveCancel();
  178. print '</form>';
  179. }
  180. if ($id > 0 && $action != 'edit') {
  181. /* ************************************************************************** */
  182. /* */
  183. /* View mode */
  184. /* */
  185. /* ************************************************************************** */
  186. $res = $object->fetch($id);
  187. if ($res < 0) {
  188. dol_print_error($db, $object->error);
  189. exit;
  190. }
  191. /*
  192. * Show tabs
  193. */
  194. //$head = intracommreport_prepare_head($object);
  195. print dol_get_fiche_head("", 'general', $langs->trans("IntracommReport"), -1, 'user');
  196. // Confirm remove report
  197. if ($action == 'delete') {
  198. $formquestion = array();
  199. if ($backtopage) {
  200. $formquestion[] = array(
  201. 'type' => 'hidden',
  202. 'name' => 'backtopage',
  203. 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"])
  204. );
  205. }
  206. print $form->formconfirm(
  207. "card.php?rowid=".urlencode($id),
  208. $langs->trans("DeleteReport"),
  209. $langs->trans("ConfirmDeleteReport"),
  210. "confirm_delete",
  211. $formquestion,
  212. 'no',
  213. 1
  214. );
  215. }
  216. $linkback = '<a href="'.DOL_URL_ROOT.'/intracommreport/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  217. dol_banner_tab($object, 'rowid', $linkback);
  218. print '<div class="fichecenter">';
  219. print '<div class="fichehalfleft">';
  220. print '<div class="underbanner clearboth"></div>';
  221. print '<table class="border tableforfield centpercent">';
  222. // Type
  223. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$object->declaration."</td></tr>\n";
  224. // Analysis period
  225. print '<tr><td>'.$langs->trans("AnalysisPeriod").'</td><td class="valeur">'.$object->period.'</td>';
  226. print '</tr>';
  227. // Type of Declaration
  228. print '<tr><td>'.$langs->trans("TypeOfDeclaration").'</td><td class="valeur">'.$object->exporttype.'</td>';
  229. print '</tr>';
  230. print "</table>\n";
  231. print "</div></div></div>\n";
  232. print '<div class="clearboth"></div>';
  233. print dol_get_fiche_end();
  234. }
  235. // End of page
  236. llxFooter();
  237. $db->close();