2
0
forked from Wavyzz/dolibarr

Merge pull request #8504 from ATM-Nicolas/develop

NEW : Add link between credit note invoice and origin
This commit is contained in:
Laurent Destailleur
2018-04-06 09:15:02 +02:00
committed by GitHub

View File

@@ -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);
}
}
}