card.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. $exporttype = GETPOSTISSET('exporttype') ? GETPOST('exporttype', 'alphanohtml') : 'deb'; // DEB or DES
  43. $year = GETPOSTINT('year');
  44. $month = GETPOSTINT('month');
  45. $label = (string) GETPOST('label', 'alphanohtml');
  46. $type_declaration = (string) GETPOST('type_declaration', 'alphanohtml');
  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)) accessforbidden();
  76. if (!$permissiontoread) accessforbidden();
  77. /*
  78. * Actions
  79. */
  80. $parameters = array('id' => $id);
  81. // Note that $action and $object may have been modified by some hooks
  82. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  83. if ($reshook < 0) {
  84. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  85. }
  86. if ($permissiontodelete && $action == 'confirm_delete' && $confirm == 'yes') {
  87. $result = $object->delete($id, $user);
  88. if ($result > 0) {
  89. if (!empty($backtopage)) {
  90. header("Location: ".$backtopage);
  91. exit;
  92. } else {
  93. header("Location: list.php");
  94. exit;
  95. }
  96. } else {
  97. $errmesg = $object->error;
  98. }
  99. }
  100. if ($action == 'add' && $permissiontoadd) {
  101. $object->label = trim($label);
  102. $object->type = trim($exporttype);
  103. $object->type_declaration = $type_declaration;
  104. //$object->subscription = (int) $subscription;
  105. // Fill array 'array_options' with data from add form
  106. // $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
  107. // if ($ret < 0) {
  108. // $error++;
  109. // }
  110. if (empty($object->label)) {
  111. $error++;
  112. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  113. } else {
  114. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."intracommreport WHERE ref='".$db->escape($object->label)."'";
  115. $result = $db->query($sql);
  116. if ($result) {
  117. $num = $db->num_rows($result);
  118. }
  119. if ($num) {
  120. $error++;
  121. $langs->load("errors");
  122. setEventMessages($langs->trans("ErrorLabelAlreadyExists", $login), null, 'errors');
  123. }
  124. }
  125. if (!$error) {
  126. $id = $object->create($user);
  127. if ($id > 0) {
  128. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id);
  129. exit;
  130. } else {
  131. setEventMessages($object->error, $object->errors, 'errors');
  132. $action = 'create';
  133. }
  134. } else {
  135. $action = 'create';
  136. }
  137. }
  138. /*
  139. * View
  140. */
  141. $title = $langs->trans("IntracommReportTitle");
  142. llxHeader("", $title);
  143. // Creation mode
  144. if ($action == 'create') {
  145. print load_fiche_titre($langs->trans("IntracommReportTitle"));
  146. print '<form name="charge" method="post" action="'.$_SERVER["PHP_SELF"].'">';
  147. print '<input type="hidden" name="token" value="'.newToken().'">';
  148. print '<input type="hidden" name="action" value="add" />';
  149. print dol_get_fiche_head();
  150. print '<table class="border" width="100%">';
  151. // Label
  152. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" class="minwidth200" name="label" autofocus="autofocus"></td></tr>';
  153. // Declaration
  154. print '<tr><td class="fieldrequired">'.$langs->trans("Declaration")."</td><td>\n";
  155. print $form->selectarray("declaration", $declaration, GETPOST('declaration', 'alpha') ? GETPOST('declaration', 'alpha') : $object->declaration, 0);
  156. print "</td>\n";
  157. // Analysis period
  158. print '<tr>';
  159. print '<td class="titlefieldcreate fieldrequired">';
  160. print $langs->trans("AnalysisPeriod");
  161. print '</td>';
  162. print '<td>';
  163. print $formother->select_month($month ? date('M') : $month, 'month', 0, 1, 'widthauto valignmiddle ', true);
  164. print $formother->selectyear($year ? date('Y') : $year, 'year', 0, 3, 3, 0, 0, '', '', true);
  165. print '</td>';
  166. print '</tr>';
  167. // Type of declaration
  168. print '<tr><td class="fieldrequired">'.$langs->trans("TypeOfDeclaration")."</td><td>\n";
  169. print $form->selectarray("type_declaration", $typeOfDeclaration, GETPOST('type_declaration', 'alpha') ? GETPOST('type_declaration', 'alpha') : $object->type_declaration, 0);
  170. print "</td>\n";
  171. print '</table>';
  172. print dol_get_fiche_end();
  173. print $form->buttonsSaveCancel();
  174. print '</form>';
  175. }
  176. if ($id > 0 && $action != 'edit') {
  177. /* ************************************************************************** */
  178. /* */
  179. /* View mode */
  180. /* */
  181. /* ************************************************************************** */
  182. $res = $object->fetch($id);
  183. if ($res < 0) {
  184. dol_print_error($db, $object->error);
  185. exit;
  186. }
  187. /*
  188. * Show tabs
  189. */
  190. //$head = intracommreport_prepare_head($object);
  191. print dol_get_fiche_head("", 'general', $langs->trans("IntracommReport"), -1, 'user');
  192. // Confirm remove report
  193. if ($action == 'delete') {
  194. $formquestion = array();
  195. if ($backtopage) {
  196. $formquestion[] = array(
  197. 'type' => 'hidden',
  198. 'name' => 'backtopage',
  199. 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"])
  200. );
  201. }
  202. print $form->formconfirm(
  203. "card.php?rowid=".urlencode($id),
  204. $langs->trans("DeleteReport"),
  205. $langs->trans("ConfirmDeleteReport"),
  206. "confirm_delete",
  207. $formquestion,
  208. 'no',
  209. 1
  210. );
  211. }
  212. $linkback = '<a href="'.DOL_URL_ROOT.'/intracommreport/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  213. dol_banner_tab($object, 'rowid', $linkback);
  214. print '<div class="fichecenter">';
  215. print '<div class="fichehalfleft">';
  216. print '<div class="underbanner clearboth"></div>';
  217. print '<table class="border tableforfield centpercent">';
  218. // Type
  219. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$object->declaration."</td></tr>\n";
  220. // Analysis Period
  221. print '<tr><td>'.$langs->trans("AnalysisPeriod").'</td><td class="valeur">'.$object->period.'</td>';
  222. print '</tr>';
  223. // Type of Declaration
  224. print '<tr><td>'.$langs->trans("TypeOfDeclaration").'</td><td class="valeur">'.$object->type_declaration.'</td>';
  225. print '</tr>';
  226. print "</table>\n";
  227. print "</div></div></div>\n";
  228. print '<div class="clearboth"></div>';
  229. print dol_get_fiche_end();
  230. }
  231. /*
  232. switch($action) {
  233. case 'generateXML':
  234. $obj = new TDebProdouane($PDOdb);
  235. $obj->load($PDOdb, GETPOST('id_declaration'));
  236. $obj->generateXMLFile();
  237. break;
  238. case 'list':
  239. _liste($exporttype);
  240. break;
  241. case 'export':
  242. if ($exporttype == 'deb') _export_xml_deb($type_declaration, $year, str_pad($month, 2, 0, STR_PAD_LEFT));
  243. else _export_xml_des($type_declaration, $year, str_pad($month, 2, 0, STR_PAD_LEFT));
  244. default:
  245. if ($exporttype == 'deb') _print_form_deb();
  246. else _print_form_des();
  247. break;
  248. }
  249. function _print_form_des()
  250. {
  251. global $langs, $formother, $year, $month, $type_declaration;
  252. print load_fiche_titre($langs->trans("IntracommReportDESTitle"));
  253. print dol_get_fiche_head();
  254. print '<form action="'.$_SERVER['PHP_SELF'].'" name="save" method="POST">';
  255. print '<input type="hidden" name="token" value="'.newToken().'">';
  256. print '<input type="hidden" name="action" value="export" />';
  257. print '<input type="hidden" name="exporttype" value="des" />';
  258. print '<input type="hidden" name="type" value="expedition" />'; // Permet d'utiliser le bon select de la requête sql
  259. print '<table width="100%" class="noborder">';
  260. print '<tr class="liste_titre"><td colspan="2">';
  261. print 'Paramètres de l\'export';
  262. print '</td></tr>';
  263. print '<tr>';
  264. print '<td>Période d\'analyse</td>';
  265. print '<td>';
  266. $TabMonth = array();
  267. for($i=1;$i<=12;$i++) $TabMonth[$i] = $langs->trans('Month'.str_pad($i, 2, 0, STR_PAD_LEFT));
  268. //print $ATMform->combo('','month', $TabMonth, empty($month) ? date('m') : $month);
  269. print $formother->selectyear(empty($year) ? date('Y') : $year,'year',0, 20, 5);
  270. print '</td>';
  271. print '</tr>';
  272. print '</table>';
  273. print '<div class="tabsAction">';
  274. print '<input class="butAction" type="submit" value="Exporter XML" />';
  275. print '</div>';
  276. print '</form>';
  277. }
  278. function _export_xml_deb($type_declaration, $period_year, $period_month) {
  279. global $db, $conf;
  280. $obj = new TDebProdouane($db);
  281. $obj->entity = $conf->entity;
  282. $obj->mode = 'O';
  283. $obj->periode = $period_year.'-'.$period_month;
  284. $obj->type_declaration = $type_declaration;
  285. $obj->numero_declaration = $obj->getNextNumeroDeclaration();
  286. $obj->content_xml = $obj->getXML('O', $type_declaration, $period_year.'-'.$period_month);
  287. if(empty($obj->errors)) {
  288. $obj->save($PDOdb);
  289. $obj->generateXMLFile();
  290. }
  291. else setEventMessage($obj->errors, 'warnings');
  292. }
  293. function _export_xml_des($type_declaration, $period_year, $period_month) {
  294. global $PDOdb, $conf;
  295. $obj = new TDebProdouane($PDOdb);
  296. $obj->entity = $conf->entity;
  297. $obj->periode = $period_year.'-'.$period_month;
  298. $obj->type_declaration = $type_declaration;
  299. $obj->exporttype = 'des';
  300. $obj->numero_declaration = $obj->getNextNumeroDeclaration();
  301. $obj->content_xml = $obj->getXMLDes($period_year, $period_month, $type_declaration);
  302. if(empty($obj->errors)) {
  303. $obj->save($PDOdb);
  304. $obj->generateXMLFile();
  305. }
  306. else setEventMessage($obj->errors, 'warnings');
  307. }
  308. */
  309. // End of page
  310. llxFooter();
  311. $db->close();