Merge branch '3.2' of git+ssh://git@github.com/Dolibarr/dolibarr.git into 3.2.1

This commit is contained in:
Regis Houssin 2012-06-29 09:37:46 +02:00
commit 87f2ec663d
5 changed files with 141 additions and 6 deletions

View File

@ -78,7 +78,8 @@ class mod_codecompta_panicum extends ModeleAccountancyCode
function get_code($db, $societe, $type='')
{
// Renvoie toujours ok
$this->code = $societe->code_compta;
if ($type == 'supplier') $this->code = $societe->code_compta_fournisseur;
else $this->code = $societe->code_compta;
return 0;
}
}

View File

@ -0,0 +1,108 @@
<?php
/* Copyright (C) 2012 Regis Houssin <regis@dolibarr.fr>
*
* 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 <http://www.gnu.org/licenses/>.
* 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).')<br>';
else $out.= '('.$langs->trans('NothingToDelete').')<br>';
return $out;
}
?>

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
*
* 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 "</td><td>".checkLinkedElements('propal', 'commande')."</td></tr>\n";
// propal => invoice
print "</td><td>".checkLinkedElements('propal', 'facture')."</td></tr>\n";
// order => invoice
print "</td><td>".checkLinkedElements('commande', 'facture')."</td></tr>\n";
// order => shipping
print "</td><td>".checkLinkedElements('commande', 'shipping')."</td></tr>\n";
// shipping => delivery
print "</td><td>".checkLinkedElements('shipping', 'delivery')."</td></tr>\n";
// order_supplier => invoice_supplier
print "</td><td>".checkLinkedElements('order_supplier', 'invoice_supplier')."</td></tr>\n";
}
// Run purge of directory
if (GETPOST('purge'))
{

View File

@ -155,7 +155,10 @@ MigrationShippingDelivery2=Mise à jour stockage des expéditions 2
MigrationFinished=Migration terminée
LastStepDesc=<strong>Dernière étape</strong>: 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=<b>%s</b> liaisons invalides ont été supprimées
NothingToDelete=Aucune liaison invalide trouvée
SourceType=Source
TargetType=Cible
#########
# upgrade

View File

@ -126,7 +126,7 @@ if (empty($reshook))
$action="";
}
if ($action == 'setaccountancy_code_buy')
if ($action == 'setaccountancy_code_sell')
{
$object->fetch($id,$ref);
$result = $object->setValueFrom('accountancy_code_sell', $_POST['accountancy_code_sell']);