From 8bb4b3f33926b37a28d3599e08ab960075a441c4 Mon Sep 17 00:00:00 2001 From: Lionel VESSILLER Date: Mon, 6 May 2019 11:12:56 +0200 Subject: [PATCH] Fix contact address substitution before sending by mail in shipment card --- htdocs/core/tpl/card_presend.tpl.php | 49 ++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php index 27d6b8ca913..a8594ec1b62 100644 --- a/htdocs/core/tpl/card_presend.tpl.php +++ b/htdocs/core/tpl/card_presend.tpl.php @@ -210,10 +210,55 @@ if ($action == 'presend') ); complete_substitutions_array($substitutionarray, $outputlangs, $object, $parameters); - // Find the good contact adress + // Find the good contact address + $tmpobject = $object; + if (($object->element == 'shipping'|| $object->element == 'reception')) { + $origin = $object->origin; + $origin_id = $object->origin_id; + + if (!empty($origin) && !empty($origin_id)) { + $element = $subelement = $origin; + if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) { + $element = $regs[1]; + $subelement = $regs[2]; + } + // For compatibility + if ($element == 'order') { + $element = $subelement = 'commande'; + } + if ($element == 'propal') { + $element = 'comm/propal'; + $subelement = 'propal'; + } + if ($element == 'contract') { + $element = $subelement = 'contrat'; + } + if ($element == 'inter') { + $element = $subelement = 'ficheinter'; + } + if ($element == 'shipping') { + $element = $subelement = 'expedition'; + } + if ($element == 'order_supplier') { + $element = 'fourn'; + $subelement = 'fournisseur.commande'; + } + if ($element == 'project') { + $element = 'projet'; + } + + dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); + $classname = ucfirst($origin); + $objectsrc = new $classname($db); + $objectsrc->fetch($origin_id); + + $tmpobject = $objectsrc; + } + } + $custcontact = ''; $contactarr = array(); - $contactarr = $object->liste_contact(- 1, 'external'); + $contactarr = $tmpobject->liste_contact(- 1, 'external'); if (is_array($contactarr) && count($contactarr) > 0) { require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';