Skip to content

Commit

Permalink
FIX Data lost during merge of thirdparties
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 15, 2017
1 parent 6f25d6d commit deb91ad
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion htdocs/langs/en_US/companies.lang
Expand Up @@ -397,7 +397,7 @@ LeopardNumRefModelDesc=The code is free. This code can be modified at any time.
ManagingDirectors=Manager(s) name (CEO, director, president...)
MergeOriginThirdparty=Duplicate third party (third party you want to delete)
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 moved to 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, then the thirdparty will be deleted.
ThirdpartiesMergeSuccess=Thirdparties have been merged
SaleRepresentativeLogin=Login of sales representative
SaleRepresentativeFirstname=First name of sales representative
Expand Down
43 changes: 40 additions & 3 deletions htdocs/societe/soc.php
Expand Up @@ -123,15 +123,14 @@
$soc_origin_id = GETPOST('soc_origin', 'int');
$soc_origin = new Societe($db);

if ($soc_origin_id < 1)
if ($soc_origin_id <= 0)
{
$langs->load('errors');
$langs->load('companies');
setEventMessages($langs->trans('ErrorProdIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors');
setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors');
}
else
{

if (!$errors && $soc_origin->fetch($soc_origin_id) < 1)
{
setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
Expand All @@ -140,8 +139,44 @@

if (!$errors)
{
// TODO Move the merge function into class of object.

$db->begin();

// Recopy some data
$object->client = $object->client | $soc_origin->client;
$object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
$listofproperties=array(
'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'url', 'barcode', 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency',
'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur',
'model_pdf', 'fk_projet'
);
foreach ($listofproperties as $property)
{
if (empty($object->$property)) $object->$property = $soc_origin->$property;
}

// Concat some data
$listofproperties=array(
'note_public', 'note_private'
);
foreach ($listofproperties as $property)
{
$object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
}

// Merge extrafields
foreach ($soc_origin->array_options as $key => $val)
{
if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
}

// TODO Merge categories
$object->update($object->id, $user);

// Move links
$objects = array(
'Adherent' => '/adherents/class/adherent.class.php',
'Societe' => '/societe/class/societe.class.php',
Expand All @@ -159,6 +194,7 @@
'Fichinter' => '/fichinter/class/fichinter.class.php',
'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
'Livraison' => '/livraison/class/livraison.class.php',
'Product' => '/product/class/product.class.php',
Expand Down Expand Up @@ -451,6 +487,7 @@
if (empty($object->fournisseur)) $object->code_fournisseur='';

$result = $object->create($user);

if ($result >= 0)
{
if ($object->particulier)
Expand Down
18 changes: 18 additions & 0 deletions htdocs/supplier_proposal/class/supplier_proposal.class.php
Expand Up @@ -2532,6 +2532,24 @@ public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedes
return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}


/**
* Function used to replace a thirdparty id with another one.
*
* @param DoliDB $db Database handler
* @param int $origin_id Old thirdparty id
* @param int $dest_id New thirdparty id
* @return bool
*/
public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
{
$tables = array(
'supplier_proposal'
);

return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
}

}


Expand Down

0 comments on commit deb91ad

Please sign in to comment.