* Copyright (C) 2019-2020 Open-DSI * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/intracommreport/card.php * \ingroup Intracomm report * \brief Page to manage intracomm report export */ /** * Terms * * DEB = Declaration d'Exchanges de Biens (FR) = Declaration of Exchange of Goods (EN) * DES = Déclaration Européenne de Services (FR) = European Declaration of Services (EN) * * INTRACOMM: Douanes françaises (FR) = french customs (EN) - https://www.douane.gouv.fr/professionnels/commerce-international/import-export * */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; require_once DOL_DOCUMENT_ROOT.'/intracommreport/class/intracommreport.class.php'; // Load translation files required by the page $langs->loadLangs(array("intracommreport")); // Get Parameters $id = GETPOST('id', 'int'); $action = GETPOST('action'); $exporttype = GETPOSTISSET('exporttype') ? GETPOST('exporttype', 'alphanohtml') : 'deb'; // DEB or DES $year = GETPOSTINT('year'); $month = GETPOSTINT('month'); $label = (string) GETPOST('label', 'alphanohtml'); $type_declaration = (string) GETPOST('type_declaration', 'alphanohtml'); $backtopage = GETPOST('backtopage', 'alpha'); $declaration = array( "deb" => $langs->trans("DEB"), "des" => $langs->trans("DES"), ); $typeOfDeclaration = array( "introduction" => $langs->trans("Introduction"), "expedition" => $langs->trans("Expedition"), ); // Initialize technical objects $object = new IntracommReport($db); if ($id > 0) { $object->fetch($id); } $form = new Form($db); $formother = new FormOther($db); // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array $hookmanager->initHooks(array('intracommcard', 'globalcard')); $error = 0; // Permissions $permissiontoread = $user->rights->intracommreport->read; $permissiontoadd = $user->rights->intracommreport->write; $permissiontodelete = $user->rights->intracommreport->delete; // Security check (enable the most restrictive one) //if ($user->socid > 0) accessforbidden(); //if ($user->socid > 0) $socid = $user->socid; //$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0); //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft); if (empty($conf->intracommreport->enabled)) accessforbidden(); if (!$permissiontoread) accessforbidden(); /* * Actions */ $parameters = array('id' => $id); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if ($permissiontodelete && $action == 'confirm_delete' && $confirm == 'yes') { $result = $object->delete($id, $user); if ($result > 0) { if (!empty($backtopage)) { header("Location: ".$backtopage); exit; } else { header("Location: list.php"); exit; } } else { $errmesg = $object->error; } } if ($action == 'add' && $permissiontoadd) { $object->label = trim($label); $object->type = trim($exporttype); $object->type_declaration = $type_declaration; //$object->subscription = (int) $subscription; // Fill array 'array_options' with data from add form // $ret = $extrafields->setOptionalsFromPost($extralabels, $object); // if ($ret < 0) { // $error++; // } if (empty($object->label)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); } else { $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."intracommreport WHERE ref='".$db->escape($object->label)."'"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); } if ($num) { $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorLabelAlreadyExists", $login), null, 'errors'); } } if (!$error) { $id = $object->create($user); if ($id > 0) { header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); $action = 'create'; } } else { $action = 'create'; } } /* * View */ $title = $langs->trans("IntracommReportTitle"); llxHeader("", $title); // Creation mode if ($action == 'create') { print load_fiche_titre($langs->trans("IntracommReportTitle")); print '
'; print ''; print ''; print dol_get_fiche_head(); print ''; // Label print ''; // Declaration print '\n"; // Analysis period print ''; print ''; print ''; print ''; // Type of declaration print '\n"; print '
'.$langs->trans("Label").'
'.$langs->trans("Declaration")."\n"; print $form->selectarray("declaration", $declaration, GETPOST('declaration', 'alpha') ? GETPOST('declaration', 'alpha') : $object->declaration, 0); print "
'; print $langs->trans("AnalysisPeriod"); print ''; print $formother->select_month($month ? date('M') : $month, 'month', 0, 1, 'widthauto valignmiddle ', true); print $formother->selectyear($year ? date('Y') : $year, 'year', 0, 3, 3, 0, 0, '', '', true); print '
'.$langs->trans("TypeOfDeclaration")."\n"; print $form->selectarray("type_declaration", $typeOfDeclaration, GETPOST('type_declaration', 'alpha') ? GETPOST('type_declaration', 'alpha') : $object->type_declaration, 0); print "
'; print dol_get_fiche_end(); print $form->buttonsSaveCancel(); print '
'; } if ($id > 0 && $action != 'edit') { /* ************************************************************************** */ /* */ /* View mode */ /* */ /* ************************************************************************** */ $res = $object->fetch($id); if ($res < 0) { dol_print_error($db, $object->error); exit; } /* * Show tabs */ //$head = intracommreport_prepare_head($object); print dol_get_fiche_head("", 'general', $langs->trans("IntracommReport"), -1, 'user'); // Confirm remove report if ($action == 'delete') { $formquestion = array(); if ($backtopage) { $formquestion[] = array( 'type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]) ); } print $form->formconfirm( "card.php?rowid=".urlencode($id), $langs->trans("DeleteReport"), $langs->trans("ConfirmDeleteReport"), "confirm_delete", $formquestion, 'no', 1 ); } $linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'rowid', $linkback); print '
'; print '
'; print '
'; print ''; // Type print '\n"; // Analysis Period print ''; print ''; // Type of Declaration print ''; print ''; print "
'.$langs->trans("Type").''.$object->declaration."
'.$langs->trans("AnalysisPeriod").''.$object->period.'
'.$langs->trans("TypeOfDeclaration").''.$object->type_declaration.'
\n"; print "
\n"; print '
'; print dol_get_fiche_end(); } /* switch($action) { case 'generateXML': $obj = new TDebProdouane($PDOdb); $obj->load($PDOdb, GETPOST('id_declaration')); $obj->generateXMLFile(); break; case 'list': _liste($exporttype); break; case 'export': if ($exporttype == 'deb') _export_xml_deb($type_declaration, $year, str_pad($month, 2, 0, STR_PAD_LEFT)); else _export_xml_des($type_declaration, $year, str_pad($month, 2, 0, STR_PAD_LEFT)); default: if ($exporttype == 'deb') _print_form_deb(); else _print_form_des(); break; } function _print_form_des() { global $langs, $formother, $year, $month, $type_declaration; print load_fiche_titre($langs->trans("IntracommReportDESTitle")); print dol_get_fiche_head(); print '
'; print ''; print ''; print ''; print ''; // Permet d'utiliser le bon select de la requête sql print ''; print ''; print ''; print ''; print ''; print ''; print '
'; print 'Paramètres de l\'export'; print '
Période d\'analyse'; $TabMonth = array(); for($i=1;$i<=12;$i++) $TabMonth[$i] = $langs->trans('Month'.str_pad($i, 2, 0, STR_PAD_LEFT)); //print $ATMform->combo('','month', $TabMonth, empty($month) ? date('m') : $month); print $formother->selectyear(empty($year) ? date('Y') : $year,'year',0, 20, 5); print '
'; print '
'; print ''; print '
'; print '
'; } function _export_xml_deb($type_declaration, $period_year, $period_month) { global $db, $conf; $obj = new TDebProdouane($db); $obj->entity = $conf->entity; $obj->mode = 'O'; $obj->periode = $period_year.'-'.$period_month; $obj->type_declaration = $type_declaration; $obj->numero_declaration = $obj->getNextNumeroDeclaration(); $obj->content_xml = $obj->getXML('O', $type_declaration, $period_year.'-'.$period_month); if(empty($obj->errors)) { $obj->save($PDOdb); $obj->generateXMLFile(); } else setEventMessage($obj->errors, 'warnings'); } function _export_xml_des($type_declaration, $period_year, $period_month) { global $PDOdb, $conf; $obj = new TDebProdouane($PDOdb); $obj->entity = $conf->entity; $obj->periode = $period_year.'-'.$period_month; $obj->type_declaration = $type_declaration; $obj->exporttype = 'des'; $obj->numero_declaration = $obj->getNextNumeroDeclaration(); $obj->content_xml = $obj->getXMLDes($period_year, $period_month, $type_declaration); if(empty($obj->errors)) { $obj->save($PDOdb); $obj->generateXMLFile(); } else setEventMessage($obj->errors, 'warnings'); } */ // End of page llxFooter(); $db->close();