diff --git a/htdocs/core/lib/intracommreport.lib.php b/htdocs/core/lib/intracommreport.lib.php index 55a7d9ea9be..425e53f3bcf 100644 --- a/htdocs/core/lib/intracommreport.lib.php +++ b/htdocs/core/lib/intracommreport.lib.php @@ -36,7 +36,7 @@ function intracommReportAdminPrepareHead() $h = 0; $head = array(); - $head[$h][0] = dol_buildpath("/intracommreport/admin/intracommreport.php", 1); + $head[$h][0] = DOL_URL_ROOT.'/intracommreport/admin/intracommreport.php'; $head[$h][1] = $langs->trans("Parameters"); $head[$h][2] = 'general'; $h++; @@ -50,3 +50,32 @@ function intracommReportAdminPrepareHead() complete_head_from_modules($conf, $langs, null, $head, $h, 'intracommreport_admin', 'remove'); return $head; } + +/** + * Prepare array with list of tabs + * + * @return array Array of tabs to show + */ +function intracommReportPrepareHead() +{ + global $langs, $conf; + + $langs->load("intracommreport"); + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/intracommreport/card.php?rowid='.$object->id; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname); to remove a tab + complete_head_from_modules($conf, $langs, null, $head, $h, 'intracommreport'); + + complete_head_from_modules($conf, $langs, null, $head, $h, 'intracommreport', 'remove'); + return $head; +} diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 895162cadd2..8a6ecd770b9 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1369,11 +1369,11 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM // Intracomm report if (! empty($conf->intracommreport->enabled)) { - $newmenu->add("/intracommreport/list.php?leftmenu=intracommreport", $langs->trans("MenuDeclaration"), 0, $user->rights->intracommreport->read, '', $mainmenu, 'intracommreport', 1); + $newmenu->add("/intracommreport/list.php?leftmenu=intracommreport", $langs->trans("MenuIntracommReport"), 0, $user->rights->intracommreport->read, '', $mainmenu, 'intracommreport', 1); if ($usemenuhider || empty($leftmenu) || preg_match('/intracommreport/', $leftmenu)) { // DEB / DES - $newmenu->add("/intracommreport/card.php?action=create&leftmenu=intracommreport", $langs->trans("MenuDeclarationNew"), 1, $user->rights->intracommreport->write, '', $mainmenu, 'intracommreport', 1); - $newmenu->add("/intracommreport/list.php?leftmenu=intracommreport", $langs->trans("MenuDeclarationList"), 1, $user->rights->intracommreport->read, '', $mainmenu, 'intracommreport', 1); + $newmenu->add("/intracommreport/card.php?action=create&leftmenu=intracommreport", $langs->trans("MenuIntracommReportNew"), 1, $user->rights->intracommreport->write, '', $mainmenu, 'intracommreport', 1); + $newmenu->add("/intracommreport/list.php?leftmenu=intracommreport", $langs->trans("MenuIntracommReportList"), 1, $user->rights->intracommreport->read, '', $mainmenu, 'intracommreport', 1); } } diff --git a/htdocs/intracommreport/card.php b/htdocs/intracommreport/card.php index 7a5914c3044..5c13a25257f 100644 --- a/htdocs/intracommreport/card.php +++ b/htdocs/intracommreport/card.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2015 ATM Consulting + * Copyright (C) 2019 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 @@ -16,7 +17,7 @@ */ /** - * \file htdocs/intracommreport/export.php + * \file htdocs/intracommreport/card.php * \ingroup Intracomm report * \brief Page to manage intracomm report export */ @@ -36,13 +37,91 @@ $formother = new FormOther($db); $year = GETPOST('year'); $month = GETPOST('month'); $type_declaration = GETPOST('type'); +$backtopage=GETPOST('backtopage', 'alpha'); -// Mode creation +/* + * Actions + */ + +if ($user->rights->intracommreport->delete && $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' && $user->rights->intracommreport->write) { + $object->label = trim($label); + $object->type = trim($type); + $object->type_declaration = (int) $statut; + $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 libelle FROM ".MAIN_DB_PREFIX."adherent_type WHERE libelle='".$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"]); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'create'; + } + } + else + { + $action = 'create'; + } +} + +/* + * View + */ + +// Creation mode if ($action == 'create') { - $title = $langs->trans("IntracommReportDEBTitle"); + $title = $langs->trans("IntracommReportTitle"); llxHeader("", $title); - print load_fiche_titre($langs->trans("IntracommReportDEBTitle")); + print load_fiche_titre($langs->trans("IntracommReportTitle")); print '
'; print ''; @@ -52,137 +131,204 @@ if ($action == 'create') print ''; + // Label + print ''; + + // Declaration + $declaration["deb"] = $langs->trans("DEB"); + $declaration["des"] = $langs->trans("DES"); + print '\n"; + // Analysis period print ''; print ''; print ''; print ''; // Type of declaration - print ''; - print ''; - print ''; - print ''; + $typeOfDeclaration["introduction"] = $langs->trans("Introduction"); + $typeOfDeclaration["expedition"] = $langs->trans("Expedition"); + 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 ''; - $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->select_month(empty($month) ? date('M') : $month,'month',0, 1); - print $formother->select_year(empty($year) ? date('Y') : $year,'year',0, 3, 3); + print $formother->select_month($month ? date('M') : $month,'month',0, 1, 'widthauto valignmiddle '); + print $formother->select_year($year ? date('Y') : $year,'year',0, 3, 3); print '
'; - print $langs->trans("TypeOfDeclaration"); - print ''; - //print $ATMform->combo('','type', array('introduction'=>'Introduction', 'expedition'=>'Expédition'), $type_declaration); - print $form->selectarray('type', $type, $type_declaration); - print '
'.$langs->trans("TypeOfDeclaration")."\n"; + print $form->selectarray("type_declaration", $typeOfDeclaration, GETPOST('type_declaration', 'alpha')?GETPOST('type_declaration', 'alpha'):$object->type_declaration, 0); + print "
'; dol_fiche_end(); - print '
'; - print ''; + print '
'; + print '     '; print '
'; print ''; } -/* -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; +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); + + dol_fiche_head($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=" . $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 '
'; + + dol_fiche_end(); } -function _print_form_des() -{ - global $langs, $formother, $year, $month, $type_declaration; + /* + 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; + } - $title = $langs->trans("IntracommReportDESTitle"); - llxHeader("", $title); - print load_fiche_titre($langs->trans("IntracommReportDESTitle")); + function _print_form_des() + { + global $langs, $formother, $year, $month, $type_declaration; - dol_fiche_head(); + $title = $langs->trans("IntracommReportDESTitle"); + llxHeader("", $title); + print load_fiche_titre($langs->trans("IntracommReportDESTitle")); - print '
'; - print ''; - print ''; - print ''; - print ''; // Permet d'utiliser le bon select de la requête sql + dol_fiche_head(); - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; // Permet d'utiliser le bon select de la requête sql - print ''; + print '
'; - print 'Paramètres de l\'export'; - print '
'; - print ''; - print ''; - print ''; - print ''; + print ''; - 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 'Paramètres de l\'export'; + print '
'; + print ''; + print 'Période d\'analyse'; + print ''; + $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 '
'; + print ''; - print '
'; -} + print '
'; + print ''; + print '
'; -function _export_xml_deb($type_declaration, $period_year, $period_month) { + print ''; + } - global $db, $conf; + function _export_xml_deb($type_declaration, $period_year, $period_month) { - $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'); -} + global $db, $conf; -function _export_xml_des($type_declaration, $period_year, $period_month) { + $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'); + } - global $PDOdb, $conf; + function _export_xml_des($type_declaration, $period_year, $period_month) { - $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'); -} -*/ + 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(); diff --git a/htdocs/langs/en_US/intracommreport.lang b/htdocs/langs/en_US/intracommreport.lang index 42c3f175c14..51d8ec0fdba 100644 --- a/htdocs/langs/en_US/intracommreport.lang +++ b/htdocs/langs/en_US/intracommreport.lang @@ -7,28 +7,29 @@ IntracommReportAbout = About intracommreport INTRACOMMREPORT_NUM_AGREMENT=Numéro d'agrément (délivré par le CISD de rattachement) INTRACOMMREPORT_TYPE_ACTEUR=Type d'acteur INTRACOMMREPORT_ROLE_ACTEUR=Rôle joué par l'acteur -INTRACOMMREPORT_NIV_OBLIGATION_INTRODUCTION=Niveau d'oligation sur les introductions +INTRACOMMREPORT_NIV_OBLIGATION_INTRODUCTION=Niveau d'obligation sur les introductions INTRACOMMREPORT_NIV_OBLIGATION_EXPEDITION=Niveau d'obligation sur les expéditions INTRACOMMREPORT_CATEG_FRAISDEPORT=Catégorie de services de type "Frais de port" INTRACOMMREPORT_NUM_DECLARATION=Numéro de déclarant #Menu -MenuDeclaration=Export Pro-Douane -MenuDeclarationNew=Nouvelle déclaration -MenuDeclarationList=Liste +MenuIntracommReport=Intracomm report +MenuIntracommReportNew=New declaration +MenuIntracommReportList=List # View +Declaration=Declaration AnalysisPeriod=Analysis period TypeOfDeclaration=Type of declaration +DEB=Goods exchange declaration (DEB) +DES=Services exchange declaration (DES) #Page d'export -IntracommReportDEBTitle=Export d'un fichier XML au format ProDouane - DEB -IntracommReportDESTitle=Export d'un fichier XML au format ProDouane - DES +IntracommReportTitle=Preparation of an XML file in ProDouane format #Liste -IntracommReportListDEB=Liste des déclarations générées (DEB) -IntracommReportListDES=Liste des déclarations générées (DES) +IntracommReportList=List of generated declarations IntracommReportNumber=Numéro déclaration IntracommReportPeriod=Période d'analyse IntracommReportTypeDeclaration=Type de déclaration