From 22d92c05408bb42b0b85f2ebe3c36837b69f9fc2 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Mon, 8 Jan 2018 15:25:18 +0100 Subject: [PATCH] Fix wrong address used into PDF model of supplier payment --- .../compta/paiement/class/paiement.class.php | 26 +++++++++++++++++++ .../doc/pdf_standard.modules.php | 4 +-- htdocs/fourn/class/paiementfourn.class.php | 26 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 7c5b99e2945..729700093e6 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -1114,5 +1114,31 @@ class Paiement extends CommonObject }*/ return ''; } + + /** + * Load the third party of object, from id into this->thirdparty + * + * @param int $force_thirdparty_id Force thirdparty id + * @return int <0 if KO, >0 if OK + */ + function fetch_thirdparty($force_thirdparty_id=0) + { + require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; + + if (empty($force_thirdparty_id)) + { + $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first invoice to get him + if (!empty($billsarray)) + { + $supplier_invoice = new FactureFournisseur($this->db); + if ($supplier_invoice->fetch($billsarray[0]) > 0) + { + $force_thirdparty_id = $supplier_invoice->fk_soc; + } + } + } + + return parent::fetch_thirdparty($force_thirdparty_id); + } } diff --git a/htdocs/core/modules/supplier_payment/doc/pdf_standard.modules.php b/htdocs/core/modules/supplier_payment/doc/pdf_standard.modules.php index 6fbfb4b1bf4..7d0772f272c 100644 --- a/htdocs/core/modules/supplier_payment/doc/pdf_standard.modules.php +++ b/htdocs/core/modules/supplier_payment/doc/pdf_standard.modules.php @@ -723,12 +723,12 @@ class pdf_standard extends ModelePDFSuppliersPayments if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) { $thirdparty = $object->contact; } else { - $thirdparty = $mysoc; + $thirdparty = $object->thirdparty; } $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs); - $carac_client=pdf_build_address($outputlangs,$this->emetteur,$mysoc,((!empty($object->contact))?$object->contact:null),$usecontact,'target',$object); + $carac_client=pdf_build_address($outputlangs,$this->emetteur,$thirdparty,((!empty($object->contact))?$object->contact:null),$usecontact,'target',$object); // Show recipient $widthrecbox=90; diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index 7a709bbce94..c2c98b9f00d 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -734,4 +734,30 @@ class PaiementFourn extends Paiement return $way; } + + /** + * Load the third party of object, from id into this->thirdparty + * + * @param int $force_thirdparty_id Force thirdparty id + * @return int <0 if KO, >0 if OK + */ + function fetch_thirdparty($force_thirdparty_id=0) + { + require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; + + if (empty($force_thirdparty_id)) + { + $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him + if (!empty($billsarray)) + { + $supplier_invoice = new FactureFournisseur($this->db); + if ($supplier_invoice->fetch($billsarray[0]) > 0) + { + $force_thirdparty_id = $supplier_invoice->fk_soc; + } + } + } + + return parent::fetch_thirdparty($force_thirdparty_id); + } }