From 63493a6d1f23470e6fcadb9610695b83d4c18123 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Thu, 21 Jun 2012 12:30:22 +0300 Subject: [PATCH 1/3] Update develop --- htdocs/compta/facture/impayees.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/impayees.php b/htdocs/compta/facture/impayees.php index 272096348f9..5b7d0694aa2 100644 --- a/htdocs/compta/facture/impayees.php +++ b/htdocs/compta/facture/impayees.php @@ -268,6 +268,7 @@ if ($resql) print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Received"),$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Rest"),$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"fk_statut,paye,am","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Merge"),$_SERVER["PHP_SELF"],"","",$param,'align="center"',$sortfield,$sortorder); print "\n"; @@ -286,7 +287,7 @@ if ($resql) print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -354,6 +355,10 @@ if ($resql) print ''.price($objp->total_ht).''; print ''.price($objp->total_ttc).''; print ''.price($objp->am).''; + if ($objp->am==0) + { print ''; } + else + { print ''.price($objp->total_ttc-$objp->am).''; } // Affiche statut de la facture print ''; From a26e03367b37ee64f187815b6f53b9a98372f6e6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 29 Jun 2012 09:30:24 +0200 Subject: [PATCH 2/3] New: remove linked elements invalid --- htdocs/install/lib/repair.lib.php | 108 ++++++++++++++++++++++++++++++ htdocs/install/repair.php | 29 +++++++- htdocs/langs/fr_FR/install.lang | 5 +- 3 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 htdocs/install/lib/repair.lib.php diff --git a/htdocs/install/lib/repair.lib.php b/htdocs/install/lib/repair.lib.php new file mode 100644 index 00000000000..d71dd5d7380 --- /dev/null +++ b/htdocs/install/lib/repair.lib.php @@ -0,0 +1,108 @@ + + * + * 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 2 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 . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/install/lib/repair.lib.php + * \brief Library of repair functions + */ + +/** + * Check if an element exist + * + * @param int $id Element id + * @param string $table Table of Element + */ +function checkElementExist($id, $table) +{ + global $db; + + $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . $table; + $sql.= ' WHERE rowid = '.$id; + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num > 0) return true; + else return false; + } +} + +/** + * Check linked elements and delete if invalid + * + * @param string $sourcetype Source element type + * @param string $targettype Target element type + * @return string + */ +function checkLinkedElements($sourcetype, $targettype) +{ + global $db, $langs; + + $elements=array(); + $deleted=0; + + if ($sourcetype == 'shipping') $sourcetable = 'expedition'; + else if ($targettype == 'shipping') $targettable = 'expedition'; + if ($sourcetype == 'delivery') $sourcetable = 'livraison'; + else if ($targettype == 'delivery') $targettable = 'livraison'; + if ($sourcetype == 'order_supplier') $sourcetable = 'commande_fournisseur'; + else if ($targettype == 'order_supplier') $targettable = 'commande_fournisseur'; + if ($sourcetype == 'invoice_supplier') $sourcetable = 'facture_fourn'; + else if ($targettype == 'invoice_supplier') $targettable = 'facture_fourn'; + + $out = $langs->trans('SourceType').': '.$sourcetype.' => '.$langs->trans('TargetType').': '.$targettype.' '; + + $sql = 'SELECT * FROM '.MAIN_DB_PREFIX .'element_element'; + $sql.= ' WHERE sourcetype="'.$sourcetype.'" AND targettype="'.$targettype.'"'; + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num) + { + $i = 0; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + $elements[$obj->rowid]=array($sourcetype => $obj->fk_source, $targettype => $obj->fk_target); + $i++; + } + } + } + + if (! empty($elements)) + { + foreach($elements as $key => $element) + { + if (! checkElementExist($element[$sourcetype], $sourcetable) || ! checkElementExist($element[$targettype], $targettable)) + { + $sql = 'DELETE FROM '.MAIN_DB_PREFIX .'element_element'; + $sql.= ' WHERE rowid = '.$key; + $resql=$db->query($sql); + $deleted++; + } + } + } + + if ($deleted) $out.= '('.$langs->trans('LinkedElementsInvalidDeleted', $deleted).')
'; + else $out.= '('.$langs->trans('NothingToDelete').')
'; + + return $out; +} + +?> diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 7179f94efc1..6c50888399f 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -1,7 +1,7 @@ - * Copyright (C) 2004-2009 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin * * 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 @@ -26,7 +26,7 @@ include_once("./inc.php"); if (file_exists($conffile)) include_once($conffile); require_once($dolibarr_main_document_root."/core/lib/admin.lib.php"); require_once($dolibarr_main_document_root."/core/class/extrafields.class.php"); - +require_once("lib/repair.lib.php"); $grant_query=''; $etape = 2; @@ -262,6 +262,29 @@ foreach($listofmodulesextra as $tablename => $elementtype) } +// Check and clean linked elements +if (GETPOST('clean_linked_elements')) +{ + // propal => order + print "".checkLinkedElements('propal', 'commande')."\n"; + + // propal => invoice + print "".checkLinkedElements('propal', 'facture')."\n"; + + // order => invoice + print "".checkLinkedElements('commande', 'facture')."\n"; + + // order => shipping + print "".checkLinkedElements('commande', 'shipping')."\n"; + + // shipping => delivery + print "".checkLinkedElements('shipping', 'delivery')."\n"; + + // order_supplier => invoice_supplier + print "".checkLinkedElements('order_supplier', 'invoice_supplier')."\n"; +} + + // Run purge of directory if (GETPOST('purge')) { diff --git a/htdocs/langs/fr_FR/install.lang b/htdocs/langs/fr_FR/install.lang index 74e18ff8822..83553a53b5b 100644 --- a/htdocs/langs/fr_FR/install.lang +++ b/htdocs/langs/fr_FR/install.lang @@ -155,7 +155,10 @@ MigrationShippingDelivery2=Mise à jour stockage des expéditions 2 MigrationFinished=Migration terminée LastStepDesc=Dernière étape: Définissez ici le compte et mot de passe du premier utilisateur que vous allez utiliser pour vous connecter à l'application. Ne perdez pas ces identifiants, il s'agit du compte permettant d'administrer les autres. ActivateModule=Activation du module %s - +LinkedElementsInvalidDeleted=%s liaisons invalides ont été supprimées +NothingToDelete=Aucune liaison invalide trouvée +SourceType=Source +TargetType=Cible ######### # upgrade From a96ab9a5871e0e27b3c8ad1fad5c810a53a54cbb Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 29 Jun 2012 10:07:11 +0200 Subject: [PATCH 3/3] Fix: missing parameters ! --- htdocs/install/lib/repair.lib.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/install/lib/repair.lib.php b/htdocs/install/lib/repair.lib.php index d71dd5d7380..c51cf7ec281 100644 --- a/htdocs/install/lib/repair.lib.php +++ b/htdocs/install/lib/repair.lib.php @@ -39,7 +39,8 @@ function checkElementExist($id, $table) $num = $db->num_rows($resql); if ($num > 0) return true; else return false; - } + } + else return true; // for security } /** @@ -56,6 +57,9 @@ function checkLinkedElements($sourcetype, $targettype) $elements=array(); $deleted=0; + $sourcetable=$sourcetype; + $targettable=$targettype; + if ($sourcetype == 'shipping') $sourcetable = 'expedition'; else if ($targettype == 'shipping') $targettable = 'expedition'; if ($sourcetype == 'delivery') $sourcetable = 'livraison'; @@ -88,7 +92,7 @@ function checkLinkedElements($sourcetype, $targettype) if (! empty($elements)) { foreach($elements as $key => $element) - { + { if (! checkElementExist($element[$sourcetype], $sourcetable) || ! checkElementExist($element[$targettype], $targettable)) { $sql = 'DELETE FROM '.MAIN_DB_PREFIX .'element_element';