From 725ef1057d88faa0975d46b2275f0e4a24330bcf Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 6 Jul 2020 04:19:50 +0200 Subject: [PATCH] Some correct --- .../core/modules/modIntracommreport.class.php | 2 +- .../intracommreport/admin/intracommreport.php | 4 +- htdocs/intracommreport/card.php | 2 +- .../class/actions_intracommexport.class.php | 88 ------------------- .../class/intracommreport.class.php | 54 ++++++++---- htdocs/intracommreport/list.php | 16 ++-- 6 files changed, 47 insertions(+), 119 deletions(-) delete mode 100644 htdocs/intracommreport/class/actions_intracommexport.class.php diff --git a/htdocs/core/modules/modIntracommreport.class.php b/htdocs/core/modules/modIntracommreport.class.php index 506b176bfd5..e142490cbd6 100644 --- a/htdocs/core/modules/modIntracommreport.class.php +++ b/htdocs/core/modules/modIntracommreport.class.php @@ -66,7 +66,7 @@ class modIntracommreport extends DolibarrModules $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->conflictwith = array(); // List of modules id this module is in conflict with $this->phpmin = array(5,5); // Minimum version of PHP required by module - $this->need_dolibarr_version = array(9,0); // Minimum version of Dolibarr required by module + $this->need_dolibarr_version = array(10,0); // Minimum version of Dolibarr required by module $this->langfiles = array("intracommreport"); // Constants diff --git a/htdocs/intracommreport/admin/intracommreport.php b/htdocs/intracommreport/admin/intracommreport.php index bcc2c867757..8950839515a 100644 --- a/htdocs/intracommreport/admin/intracommreport.php +++ b/htdocs/intracommreport/admin/intracommreport.php @@ -1,6 +1,6 @@ - * Copyright (C) 2019 Open-DSI + * 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 @@ -34,7 +34,7 @@ if (! $user->admin) accessforbidden(); $action = GETPOST('action', 'aZ09'); -// Parameters ACCOUNTING_* and others +// Parameters INTRACOMMREPORT_* and others $list_DEB = array ( 'INTRACOMMREPORT_NUM_AGREMENT', ); diff --git a/htdocs/intracommreport/card.php b/htdocs/intracommreport/card.php index 4f33c807ffa..79725e81419 100644 --- a/htdocs/intracommreport/card.php +++ b/htdocs/intracommreport/card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2019 Open-DSI + * 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 diff --git a/htdocs/intracommreport/class/actions_intracommexport.class.php b/htdocs/intracommreport/class/actions_intracommexport.class.php deleted file mode 100644 index 49cbffe2cf2..00000000000 --- a/htdocs/intracommreport/class/actions_intracommexport.class.php +++ /dev/null @@ -1,88 +0,0 @@ - - * Copyright (C) 2015 ATM Consulting - * - * 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 class/actions_intracommreport.class.php - * \ingroup intracommreport - * \brief This file is an example hook overload class file - * Put some comments here - */ - -/** - * Class Actionsintracommreport - */ -class Actionsintracommreport -{ - /** - * @var array Hook results. Propagated to $hookmanager->resArray for later reuse - */ - public $results = array(); - - /** - * @var string String displayed by executeHook() immediately after return - */ - public $resprints; - - /** - * @var array Errors - */ - public $errors = array(); - - /** - * Constructor - */ - public function __construct() - { - } - - /** - * Overloading the doActions function : replacing the parent's function with the one below - * - * @param array() $parameters Hook metadatas (context, etc...) - * @param CommonObject &$object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) - * @param string &$action Current action (if set). Generally create or edit or null - * @param HookManager $hookmanager Hook manager propagated to allow calling another hook - * @return int < 0 on error, 0 on success, 1 to replace standard code - */ - function doActions($parameters, &$object, &$action, $hookmanager) - { - $error = 0; // Error counter - $myvalue = 'test'; // A result value - - print_r($parameters); - echo "action: " . $action; - print_r($object); - - if (in_array('somecontext', explode(':', $parameters['context']))) - { - // do something only for the context 'somecontext' - } - - if (! $error) - { - $this->results = array('myreturn' => $myvalue); - $this->resprints = 'A text to show'; - return 0; // or return 1 to replace standard code - } - else - { - $this->errors[] = 'Error message'; - return -1; - } - } -} diff --git a/htdocs/intracommreport/class/intracommreport.class.php b/htdocs/intracommreport/class/intracommreport.class.php index 709269a0747..75c017704c4 100644 --- a/htdocs/intracommreport/class/intracommreport.class.php +++ b/htdocs/intracommreport/class/intracommreport.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2019 Open-DSI + * 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 @@ -45,7 +45,6 @@ class IntracommReport extends CommonObject /** * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe - * * @var int */ public $ismultientitymanaged = 1; @@ -54,6 +53,7 @@ class IntracommReport extends CommonObject * DEB - Product */ const TYPE_DEB = 0; + /** * DES - Service */ @@ -89,10 +89,13 @@ class IntracommReport extends CommonObject } /** - * @param $mode O pour création, R pour régénération (apparemment toujours 0 dans la cadre des échanges XML selon la doc) - * @param $type introduction ou expedition + * Generate XML file + * + * @param int $mode O for create, R for regenerate (Look always 0 ment toujours 0 within the framework of XML exchanges according to documentation) + * @param string $type introduction or expedition + * @param string $period_reference Period of reference */ - function getXML($mode = 'O', $type = 'introduction', $periode_reference = '') + function getXML($mode = 'O', $type = 'introduction', $period_reference = '') { global $db, $conf, $mysoc; @@ -119,7 +122,7 @@ class IntracommReport extends CommonObject $enveloppe->addChild('softwareUsed', 'Dolibarr'); $declaration = $enveloppe->addChild('Declaration'); $declaration->addChild('declarationId', $id_declaration); - $declaration->addChild('referencePeriod', $periode_reference); + $declaration->addChild('referencePeriod', $period_reference); if($conf->global->INTRACOMMREPORT_TYPE_ACTEUR === 'PSI') $psiId = $party_id; else $psiId = 'NA'; $declaration->addChild('PSIId', $psiId); @@ -131,7 +134,7 @@ class IntracommReport extends CommonObject /********************************************************************/ /**************Ajout des lignes de factures**************************/ - $res = self::addItemsFact($declaration, $type, $periode_reference); + $res = self::addItemsFact($declaration, $type, $period_reference); /********************************************************************/ $this->errors = array_unique($this->errors); @@ -148,7 +151,7 @@ class IntracommReport extends CommonObject $e = new SimpleXMLElement(''); $declaration_des = $e->addChild('declaration_des'); - $declaration_des->addChild('num_des', self::getNumeroDeclaration($this->numero_declaration)); + $declaration_des->addChild('num_des', self::getDeclarationNumber($this->numero_declaration)); $declaration_des->addChild('num_tvaFr', $mysoc->tva_intra); // /^FR[a-Z0-9]{2}[0-9]{9}$/ // Doit faire 13 caractères $declaration_des->addChild('mois_des', $period_month); $declaration_des->addChild('an_des', $period_year); @@ -163,14 +166,14 @@ class IntracommReport extends CommonObject else return 0; } - function addItemsFact(&$declaration, $type, $periode_reference, $exporttype = 'deb') + function addItemsFact(&$declaration, $type, $period_reference, $exporttype = 'deb') { global $db, $conf; require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; - $sql = $this->getSQLFactLines($type, $periode_reference, $exporttype); + $sql = $this->getSQLFactLines($type, $period_reference, $exporttype); $resql = $db->query($sql); @@ -216,7 +219,7 @@ class IntracommReport extends CommonObject return 1; } - function getSQLFactLines($type, $periode_reference, $exporttype = 'deb') + function getSQLFactLines($type, $period_reference, $exporttype = 'deb') { global $mysoc, $conf; @@ -250,7 +253,7 @@ class IntracommReport extends CommonObject AND l.product_type = '.($exporttype == 'des' ? 1 : 0).' AND f.entity = '.$conf->entity.' AND (s.fk_pays <> '.$mysoc->country_id.' OR s.fk_pays IS NULL) - AND f.datef BETWEEN "'.$periode_reference.'-01" AND "'.$periode_reference.'-'.date('t').'"'; + AND f.datef BETWEEN "'.$period_reference.'-01" AND "'.$period_reference.'-'.date('t').'"'; return $sql; } @@ -327,7 +330,7 @@ class IntracommReport extends CommonObject SELECT fk_product FROM '.MAIN_DB_PREFIX.'categorie_product WHERE fk_categorie = '.$categ_fraisdeport->id.' - ) + ) )'; $resql = $db->query($sql); @@ -339,23 +342,38 @@ class IntracommReport extends CommonObject } } - function getNextNumeroDeclaration() + /** + * Return next reference of declaration not already used (or last reference) + * + * @return string free ref or last ref + */ + public function getNextDeclarationNumber() { - global $db; + $resql = $db->query('SELECT MAX(numero_declaration) as max_numero_declaration FROM '.$this->get_table().' WHERE exporttype="'.$this->exporttype.'"'); if($resql) $res = $db->fetch_object($resql); return ($res->max_numero_declaration + 1); } + /** + * Verify declaration number. Positive integer of a maximum of 6 characters recommended by the documentation + * + * @param int $number Number to verify / convert + * @return int Number + */ // La doc impose que le numéro soit un entier positif d'un maximum de 6 caractères - static function getNumeroDeclaration($numero) + static function getDeclarationNumber($number) { - - return str_pad($numero, 6, 0, STR_PAD_LEFT); + return str_pad($number, 6, 0, STR_PAD_LEFT); } + /** + * Generate XML file + * + * @return void + */ function generateXMLFile() { diff --git a/htdocs/intracommreport/list.php b/htdocs/intracommreport/list.php index d903ef31287..8145948cc0d 100644 --- a/htdocs/intracommreport/list.php +++ b/htdocs/intracommreport/list.php @@ -1,6 +1,6 @@ - * Copyright (C) 2019 Open-DSI + * 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 @@ -297,11 +297,11 @@ if ($resql) $newcardbutton=''; $rightskey='DEB'; - if($type == IntracommReport::TYPE_DES) $rightskey='DES'; - if($user->rights->{$rightskey}->creer) + if ($type == IntracommReport::TYPE_DES) $rightskey='DES'; + if ($user->rights->{$rightskey}->creer) { $label='NewDEB'; - if($type == IntracommReport::TYPE_DES) $label='NewDES'; + if ($type == IntracommReport::TYPE_DES) $label = 'NewDES'; $newcardbutton.= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/intracommreport/card.php?action=create&type='.$type); } @@ -326,7 +326,7 @@ if ($resql) if ($sall) { - foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); + foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); print '
'.$langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall).'
'; } @@ -539,8 +539,7 @@ if ($resql) print $duration_value; print (! empty($duration_unit) && isset($dur[$duration_unit]) ? ' '.$langs->trans($dur[$duration_unit]) : ''); } - else - { + else { print $obj->duration; } @@ -578,8 +577,7 @@ if ($resql) print ""; print ''; } -else -{ +else { dol_print_error($db); }