From b9a91c667faa21dac469093c355aaddd80d4896b Mon Sep 17 00:00:00 2001 From: ATM-Nicolas Date: Tue, 27 Mar 2018 16:04:56 +0200 Subject: [PATCH] NEW : Add link between credit note invoice and origin --- htdocs/compta/facture/card.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index d438c505a8d..2f49526d1cb 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -916,9 +916,9 @@ if (empty($reshook)) $id = $object->create($user); + $facture_source = new Facture($db); // fetch origin object if (GETPOST('invoiceAvoirWithLines', 'int')==1 && $id>0) { - $facture_source = new Facture($db); // fetch origin object if ($facture_source->fetch($object->fk_facture_source)>0) { $fk_parent_line = 0; @@ -969,7 +969,6 @@ if (empty($reshook)) if(GETPOST('invoiceAvoirWithPaymentRestAmount', 'int')==1 && $id>0) { - $facture_source = new Facture($db); // fetch origin object if not previously defined if ($facture_source->fetch($object->fk_facture_source)>0) { $totalpaye = $facture_source->getSommePaiement(); @@ -980,6 +979,20 @@ if (empty($reshook)) $object->addline($langs->trans('invoiceAvoirLineWithPaymentRestAmount'),$remain_to_pay,1,0,0,0,0,0,'','','TTC'); } } + + // Add link between credit note and origin + if(! empty($object->fk_facture_source)) { + $facture_source->fetch($object->fk_facture_source); + } + $facture_source->fetchObjectLinked(); + + if(! empty($facture_source->linkedObjectsIds)) { + $linkedObjectIds = $facture_source->linkedObjectsIds; + $sourcetype = key($linkedObjectIds); + $fk_origin = current($facture_source->linkedObjectsIds[$sourcetype]); + + $object->add_object_linked($sourcetype, $fk_origin); + } } }