NEW We can now link membership contributions to invoices, orders, proposals (#37712)

* One can now link membership contributions to invoices (tested) and others (not tested)

* PHAN error undeclare property

* PHAN fix wrong type

* API for get subscriptions of a member will now include object links if they are there

* Attempt to fix PHAN that still complains about line 10484 undeclared property

* circumventing PHAN complaints by creating a new subscription object which is the same as the , and from that get the member id, which then is used to create a member object, and from that fetch the thirdparty id

* Fetch linked objects before showing links to members

* Remove fetchObjectLinked call from subscription

* Clean logs

Added logging for debugging in multiple functions.

* Avoid too verbose log on non signiticative functions

* Fix formatting in commonobject.class.php

---------

Co-authored-by: Jon Bendtsen <jonbendtsen@jonb.dk>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Jon Bendtsen 2026-04-09 02:09:47 +02:00 committed by GitHub
parent 6cd6acabfe
commit ecd286cdb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 7 deletions

View file

@ -403,9 +403,19 @@ if ($rowid && $action != 'edit') {
$somethingshown = $formfile->numoffiles;
*/
// Show links to link elements
//$tmparray = $form->showLinkToObjectBlock($object, null, array('subscription'), 1);
$somethingshown = $form->showLinkedObjectBlock($object, '');
$object->fetchObjectLinked();
print '<!-- Show links to link members thirdpartys elements -->';
$tmparray = $form->showLinkToObjectBlock($object, array(), array('societe'), 1);
$linktoelem = $tmparray['linktoelem'];
$htmltoenteralink = $tmparray['htmltoenteralink'];
print $htmltoenteralink;
$compatibleImportElementsList = array();
$id = $object->fk_adherent;
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
// without that include PHP Warning: Undefined variable $id in /var/www/html/core/actions_dellink.inc.php on line 47
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
print '</div><div class="fichehalfright">';

View file

@ -4373,6 +4373,7 @@ abstract class CommonObject
{
// phpcs:enable
global $user, $hookmanager, $action;
dol_syslog(__METHOD__, LOG_DEBUG);
if (empty($this->origin_type) && !empty($this->origin)) {
$this->origin_type = $this->origin;
@ -4646,6 +4647,7 @@ abstract class CommonObject
$sql .= " ORDER BY ".$orderby;
dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
@ -4739,6 +4741,7 @@ abstract class CommonObject
$updatesource = false;
$updatetarget = false;
$f_user = isset($f_user) ? $f_user : $user;
dol_syslog(__METHOD__, LOG_DEBUG);
if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
$updatesource = true;

View file

@ -10284,6 +10284,8 @@ class Form
global $action;
global $db, $user; // Will be used into tpl
dol_syslog(__METHOD__, LOG_DEBUG);
$object->fetchObjectLinked();
// Bypass the default method
@ -10458,6 +10460,8 @@ class Form
global $conf, $langs, $hookmanager, $form;
global $action;
dol_syslog(__METHOD__, LOG_DEBUG);
if (empty($form)) {
$form = new Form($this->db);
}
@ -10467,23 +10471,34 @@ class Form
$listofidcompanytoscan = '';
if (!is_object($object->thirdparty)) {
$object->fetch_thirdparty();
if ($object->element == 'subscription' && isset($object->fk_adherent)) {
$subby = new Subscription($object->db);
$subby->fetch($object->id);
$adh = new Adherent($object->db);
//$fk_adherent = $object->fk_adherent;
// creating new subscription object only to fetch the adherent which obviously exists given the if statement above are Inefficient, but else phan complains
$fk_adherent = $subby->fk_adherent;
$adh->fetch($fk_adherent);
$thirdparty_id = $adh->fetch_thirdparty();
}
} else {
$thirdparty_id = $object->thirdparty->id;
}
$possiblelinks = array();
$dontIncludeCompletedItems = getDolGlobalString('DONT_INCLUDE_COMPLETED_ELEMENTS_LINKS');
if (is_object($object->thirdparty) && !empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
$listofidcompanytoscan = (int) $object->thirdparty->id;
if (($object->thirdparty->parent > 0) && getDolGlobalString('THIRDPARTY_INCLUDE_PARENT_IN_LINKTO')) {
if (!empty($thirdparty_id) && $thirdparty_id > 0) {
$listofidcompanytoscan = (int) $thirdparty_id;
if (is_object($object->thirdparty) && ($object->thirdparty->parent > 0) && getDolGlobalString('THIRDPARTY_INCLUDE_PARENT_IN_LINKTO')) {
$listofidcompanytoscan .= ',' . (int) $object->thirdparty->parent;
}
if (($object->fk_project > 0) && getDolGlobalString('THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO')) {
include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
$tmpproject = new Project($this->db);
$tmpproject->fetch((int) $object->fk_project);
if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) {
if ($tmpproject->socid > 0 && ($tmpproject->socid != $thirdparty_id)) {
$listofidcompanytoscan .= ',' . (int) $tmpproject->socid;
}
unset($tmpproject);