Debug merge thirdparty feature.

This commit is contained in:
Laurent Destailleur 2015-06-05 15:15:05 +02:00
parent a33241f487
commit ee986b1a2b
2 changed files with 30 additions and 23 deletions

View File

@ -414,6 +414,6 @@ SearchThirdparty=Search third party
SearchContact=Search contact SearchContact=Search contact
MergeOriginThirdparty=Duplicate third party (third party you want to delete) MergeOriginThirdparty=Duplicate third party (third party you want to delete)
MergeThirdparties=Merge third parties MergeThirdparties=Merge third parties
ConfirmMergeThirdparties=Are you sure you want to merge this third party into the current one ? All linked objects (invoices, orders, ...) will be linked with the current third party so you will be able to delete the duplicate one. ConfirmMergeThirdparties=Are you sure you want to merge this third party into the current one ? All linked objects (invoices, orders, ...) will be moved to current third party so you will be able to delete the duplicate one.
ThirdpartiesMergeSuccess=Thirdparties have been merged ThirdpartiesMergeSuccess=Thirdparties have been merged
ErrorThirdpartiesMerge=There was an error when deleting the thirdparties. Please check the log. Changes have been reverted. ErrorThirdpartiesMerge=There was an error when deleting the thirdparties. Please check the log. Changes have been reverted.

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Brian Fraval <brian@fraval.org> * Copyright (C) 2003 Brian Fraval <brian@fraval.org>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net> * Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
@ -98,6 +98,8 @@ if (empty($reshook))
{ {
if ($action == 'confirm_merge' && $confirm == 'yes') if ($action == 'confirm_merge' && $confirm == 'yes')
{ {
$object->fetch($socid);
$errors = 0; $errors = 0;
$soc_origin_id = GETPOST('soc_origin', 'int'); $soc_origin_id = GETPOST('soc_origin', 'int');
$soc_origin = new Societe($db); $soc_origin = new Societe($db);
@ -150,9 +152,9 @@ if (empty($reshook))
{ {
require_once DOL_DOCUMENT_ROOT.$object_file; require_once DOL_DOCUMENT_ROOT.$object_file;
if (!$errors && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) { if (!$errors && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id))
{
$errors++; $errors++;
$db->rollback();
} }
} }
@ -161,32 +163,37 @@ if (empty($reshook))
'mergethirds' 'mergethirds'
)); ));
if (!$errors) { if (!$errors)
{
$reshook = $hookmanager->executeHooks('replaceThirdparty', array( $reshook = $hookmanager->executeHooks('replaceThirdparty', array(
'soc_origin' => $soc_origin->id, 'soc_origin' => $soc_origin->id,
'soc_dest' => $object->id 'soc_dest' => $object->id
), $soc_dest, $action); ), $soc_dest, $action);
if ($reshook < 0) { if ($reshook < 0)
{
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
$errors++; $errors++;
} }
} }
if (!$errors) { if (!$errors)
{
//We finally remove the old thirdparty //We finally remove the old thirdparty
if ($soc_origin->delete($soc_origin->id, $user) < 1) { if ($soc_origin->delete($soc_origin->id, $user) < 1)
$db->rollback(); {
$errors++; $errors++;
} }
} }
}
if (!$errors) { if (!$errors)
{
setEventMessage($langs->trans('ThirdpartiesMergeSuccess')); setEventMessage($langs->trans('ThirdpartiesMergeSuccess'));
$db->commit(); $db->commit();
} else { } else {
setEventMessage($langs->trans('ErrorsThirdpartyMerge'), 'errors'); setEventMessage($langs->trans('ErrorsThirdpartyMerge'), 'errors');
$db->rollback();
}
} }
} }
} }
@ -1835,18 +1842,18 @@ else
print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete"); print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
} }
if ($action == 'merge') { if ($action == 'merge')
$form = new Form($db); {
$formquestion = array(
$options = array(
array( array(
'name' => 'soc_origin',
'label' => $langs->trans('MergeOriginThirdparty'), 'label' => $langs->trans('MergeOriginThirdparty'),
'type' => 'other', 'type' => 'other',
'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 1) 'value' => $form->select_thirdparty('', 'soc_origin', 's.rowid != '.$object->id)
) )
); );
print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id,$langs->trans("MergeThirdparties"),$langs->trans("ConfirmMergeThirdparties"),"confirm_merge",$options,'',1); print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1);
} }
dol_htmloutput_errors($error,$errors); dol_htmloutput_errors($error,$errors);