Fix: prevent to fault positive
This commit is contained in:
parent
51059bf52b
commit
c721d9362c
@ -1156,11 +1156,17 @@ class CommonObject
|
|||||||
* @param sourcetype
|
* @param sourcetype
|
||||||
* @param targetid
|
* @param targetid
|
||||||
* @param targettype
|
* @param targettype
|
||||||
* @param clause
|
* @param clause OR, AND
|
||||||
*/
|
*/
|
||||||
function load_object_linked($sourceid='',$sourcetype='',$targetid='',$targettype='',$clause='OR')
|
function load_object_linked($sourceid='',$sourcetype='',$targetid='',$targettype='',$clause='OR')
|
||||||
{
|
{
|
||||||
$this->linked_object=array();
|
$this->linked_object=array();
|
||||||
|
|
||||||
|
$justsource=false;
|
||||||
|
$justtarget=false;
|
||||||
|
|
||||||
|
if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $justsource=true;
|
||||||
|
if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $justtarget=true;
|
||||||
|
|
||||||
$sourceid = (!empty($sourceid)?$sourceid:$this->id);
|
$sourceid = (!empty($sourceid)?$sourceid:$this->id);
|
||||||
$targetid = (!empty($targetid)?$targetid:$this->id);
|
$targetid = (!empty($targetid)?$targetid:$this->id);
|
||||||
@ -1170,9 +1176,18 @@ class CommonObject
|
|||||||
// Links beetween objects are stored in this table
|
// Links beetween objects are stored in this table
|
||||||
$sql = 'SELECT fk_source, sourcetype, fk_target, targettype';
|
$sql = 'SELECT fk_source, sourcetype, fk_target, targettype';
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'element_element';
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'element_element';
|
||||||
$sql.= " WHERE (fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."')";
|
$sql.= " WHERE ";
|
||||||
$sql.= " ".$clause." (fk_target = '".$targetid."' AND targettype = '".$targettype."')";
|
if ($justsource || $justtarget)
|
||||||
|
{
|
||||||
|
if ($justsource) $sql.= "fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."'";
|
||||||
|
if ($justtarget) $sql.= "fk_target = '".$targetid."' AND targettype = '".$targettype."'";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sql.= "(fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."')";
|
||||||
|
$sql.= " ".$clause." (fk_target = '".$targetid."' AND targettype = '".$targettype."')";
|
||||||
|
}
|
||||||
|
|
||||||
dol_syslog("CommonObject::load_object_linked sql=".$sql);
|
dol_syslog("CommonObject::load_object_linked sql=".$sql);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
@ -1199,6 +1214,56 @@ class CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch objects linked
|
||||||
|
*/
|
||||||
|
function fetch_object_linked($sourceid='',$sourcetype='',$targetid='',$targettype='',$clause='OR')
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
$this->linkedObjects=array();
|
||||||
|
|
||||||
|
$this->load_object_linked($sourceid,$sourcetype,$targetid,$targettype,$clause);
|
||||||
|
|
||||||
|
foreach($this->linked_object as $key => $value)
|
||||||
|
{
|
||||||
|
// Parse element/subelement (ex: project_task)
|
||||||
|
$element = $subelement = $key;
|
||||||
|
if (preg_match('/^([^_]+)_([^_]+)/i',$key,$regs))
|
||||||
|
{
|
||||||
|
$element = $regs[1];
|
||||||
|
$subelement = $regs[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// For compatibility
|
||||||
|
if ($element == 'facture') { $element = 'compta/facture'; $subelement = 'facture'; }
|
||||||
|
if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; }
|
||||||
|
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
|
||||||
|
if ($element == 'contract') { $element = $subelement = 'contrat'; }
|
||||||
|
if ($element == 'shipping') { $element = $subelement = 'expedition'; }
|
||||||
|
if ($element == 'delivery') { $element = $subelement = 'livraison'; }
|
||||||
|
|
||||||
|
if ($conf->$element->enabled)
|
||||||
|
{
|
||||||
|
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
|
||||||
|
|
||||||
|
$classname = ucfirst($subelement);
|
||||||
|
|
||||||
|
$num=sizeof($value);
|
||||||
|
|
||||||
|
for ($i=0;$i<$num;$i++)
|
||||||
|
{
|
||||||
|
$object = new $classname($this->db);
|
||||||
|
$ret = $object->fetch($value[$i]);
|
||||||
|
if ($ret >= 0)
|
||||||
|
{
|
||||||
|
$this->linkedObjects[$key][$i] = $object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set statut of an object
|
* Set statut of an object
|
||||||
* @param statut Statut to set
|
* @param statut Statut to set
|
||||||
|
|||||||
@ -418,36 +418,34 @@ class pdf_sirocco extends ModelePDFDeliveryOrder
|
|||||||
|
|
||||||
$pdf->SetFont('','B', $default_font_size - 1);
|
$pdf->SetFont('','B', $default_font_size - 1);
|
||||||
|
|
||||||
// Add list of linked orders
|
// Add origin linked objects
|
||||||
// TODO mutualiser
|
// TODO extend to other objects
|
||||||
$object->load_object_linked();
|
$object->fetch_object_linked('','',$object->id,'delivery');
|
||||||
|
|
||||||
if ($conf->commande->enabled)
|
if (! empty($object->linkedObjects))
|
||||||
{
|
{
|
||||||
$outputlangs->load('orders');
|
$outputlangs->load('orders');
|
||||||
foreach($object->linked_object as $key => $val)
|
|
||||||
|
foreach($object->linkedObjects as $elementtype => $objects)
|
||||||
{
|
{
|
||||||
if ($key == 'shipping') // Link to shipment
|
$object->fetch_object_linked('','',$objects[0]->id,$objects[0]->element);
|
||||||
|
|
||||||
|
foreach($object->linkedObjects as $elementtype => $objects)
|
||||||
{
|
{
|
||||||
for ($i = 0; $i<sizeof($val);$i++)
|
$num=sizeof($objects);
|
||||||
|
for ($i=0;$i<$num;$i++)
|
||||||
{
|
{
|
||||||
$newtmp=new Expedition($this->db);
|
$order=new Commande($this->db);
|
||||||
$result=$newtmp->fetch($val[$i]);
|
$result=$order->fetch($objects[$i]->id);
|
||||||
|
if ($result >= 0)
|
||||||
if (($newtmp->origin=='commande' || $newtmp->origin=='order') && $newtmp->origin_id)
|
{
|
||||||
{
|
$posy+=5;
|
||||||
$newobject=new Commande($this->db);
|
$pdf->SetXY(100,$posy);
|
||||||
$result=$newobject->fetch($newtmp->origin_id);
|
$pdf->SetFont('','', $default_font_size - 1);
|
||||||
if ($result >= 0)
|
$text=$order->ref;
|
||||||
{
|
if ($order->ref_client) $text.=' ('.$order->ref_client.')';
|
||||||
$posy+=7;
|
$pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
|
||||||
$pdf->SetXY($this->page_largeur - $this->marge_droite - 100,$posy);
|
}
|
||||||
$pdf->SetFont('','', $default_font_size - 1);
|
|
||||||
$text=$newobject->ref;
|
|
||||||
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')';
|
|
||||||
$pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -547,28 +547,32 @@ class pdf_typhon extends ModelePDFDeliveryOrder
|
|||||||
|
|
||||||
$pdf->SetTextColor(0,0,60);
|
$pdf->SetTextColor(0,0,60);
|
||||||
|
|
||||||
// Add list of linked orders
|
// Add origin linked objects
|
||||||
// TODO mutualiser
|
// TODO extend to other objects
|
||||||
$object->load_object_linked();
|
$object->fetch_object_linked('','',$object->id,'delivery');
|
||||||
|
|
||||||
if ($conf->commande->enabled)
|
if (! empty($object->linkedObjects))
|
||||||
{
|
{
|
||||||
$outputlangs->load('orders');
|
$outputlangs->load('orders');
|
||||||
foreach($object->linked_object as $key => $val)
|
|
||||||
|
foreach($object->linkedObjects as $elementtype => $objects)
|
||||||
{
|
{
|
||||||
if ($key == 'commande' || $key == 'order')
|
$object->fetch_object_linked('','',$objects[0]->id,$objects[0]->element);
|
||||||
|
|
||||||
|
foreach($object->linkedObjects as $elementtype => $objects)
|
||||||
{
|
{
|
||||||
for ($i = 0; $i<sizeof($val);$i++)
|
$num=sizeof($objects);
|
||||||
|
for ($i=0;$i<$num;$i++)
|
||||||
{
|
{
|
||||||
$newobject=new Commande($this->db);
|
$order=new Commande($this->db);
|
||||||
$result=$newobject->fetch($val[$i]);
|
$result=$order->fetch($objects[$i]->id);
|
||||||
if ($result >= 0)
|
if ($result >= 0)
|
||||||
{
|
{
|
||||||
$posy+=4;
|
$posy+=5;
|
||||||
$pdf->SetXY(100,$posy);
|
$pdf->SetXY(100,$posy);
|
||||||
$pdf->SetFont('','', $default_font_size - 1);
|
$pdf->SetFont('','', $default_font_size - 1);
|
||||||
$text=$newobject->ref;
|
$text=$order->ref;
|
||||||
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')';
|
if ($order->ref_client) $text.=' ('.$order->ref_client.')';
|
||||||
$pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
|
$pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user