Add possibility to add linked object block in object card for external module

This commit is contained in:
Regis Houssin 2010-04-08 19:44:45 +00:00
parent e104888ceb
commit 9b2f724ea7
12 changed files with 208 additions and 108 deletions

View File

@ -1959,8 +1959,19 @@ if ($id > 0 || ! empty($ref))
/* /*
* Commandes rattachees * Linked object block
*/ */
$propal->load_object_linked($propal->id,$propal->element);
foreach($propal->linked_object as $object => $objectid)
{
// TODO en attendant que tout soit correct
if($conf->$object->enabled && $object == 'commande')
{
$propal->showLinkedObjectBlock($object,$objectid,$somethingshown);
}
}
/*
if($conf->commande->enabled) if($conf->commande->enabled)
{ {
$propal->loadOrders(); $propal->loadOrders();
@ -1990,7 +2001,7 @@ if ($id > 0 || ! empty($ref))
print '</table>'; print '</table>';
} }
} }
*/
print '</td><td valign="top" width="50%">'; print '</td><td valign="top" width="50%">';
// List of actions on element // List of actions on element

View File

@ -1506,20 +1506,26 @@ class Propal extends CommonObject
$linkedInvoices = array(); $linkedInvoices = array();
$this->load_object_linked($id,$this->element); $this->load_object_linked($id,$this->element);
foreach($this->linked_object as $key => $object) foreach($this->linked_object as $object => $objectid)
{
for ($i = 0; $i<sizeof($objectid);$i++)
{ {
// Cas des factures liees directement // Cas des factures liees directement
if ($object['type'] == 'facture') if ($object == 'facture')
{ {
$linkedInvoices[] = $object['linkid']; $linkedInvoices[] = $object[$i];
} }
// Cas des factures liees via la commande // Cas des factures liees via la commande
else else
{ {
$this->load_object_linked($object['linkid'],$object['type']); $this->load_object_linked($object[$i],$object);
foreach($this->linked_object as $key => $object) foreach($this->linked_object as $object => $objectid)
{ {
$linkedInvoices[] = $object['linkid']; for ($j = 0; $j<sizeof($objectid);$j++)
{
$linkedInvoices[] = $object[$j];
}
}
} }
} }
} }

View File

@ -2358,8 +2358,45 @@ class Commande extends CommonObject
} }
} }
} /**
*
*
*/
function getLinkedObjectBlock($object,$objectid,$somethingshown=0)
{
global $langs;
$num = sizeof($objectid);
if ($num > 0)
{
if ($somethingshown) { print '<br>'; $somethingshown=1; }
print_titre($langs->trans('RelatedOrders'));
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Ref").'</td>';
print '<td align="center">'.$langs->trans("Date").'</td>';
print '<td align="right">'.$langs->trans("Price").'</td>';
print '<td align="right">'.$langs->trans("Status").'</td>';
print '</tr>';
$var=true;
for ($i = 0 ; $i < $num ; $i++)
{
$this->fetch($objectid[$i]);
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$this->id.'">'.img_object($langs->trans("ShowOrder"),"order").' '.$this->ref."</a></td>\n";
print '<td align="center">'.dol_print_date($this->date,'day').'</td>';
print '<td align="right">'.price($this->total_ttc).'</td>';
print '<td align="right">'.$this->getLibStatut(3).'</td>';
print "</tr>\n";
}
print '</table>';
}
}
}
/** /**

View File

@ -922,11 +922,11 @@ class CommonObject
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($obj->fk_source == $sourceid) if ($obj->fk_source == $sourceid)
{ {
$this->linked_object[]=array('linkid'=>$obj->fk_target, 'type'=>$obj->targettype); $this->linked_object[$obj->targettype][]=$obj->fk_target;
} }
if ($obj->fk_target == $targetid) if ($obj->fk_target == $targetid)
{ {
$this->linked_object[]=array('linkid'=>$obj->fk_source, 'type'=>$obj->sourcetype); $this->linked_object[$obj->sourcetype][]=$obj->fk_source;
} }
$i++; $i++;
} }
@ -1014,6 +1014,17 @@ class CommonObject
} }
} }
/**
*
*/
function showLinkedObjectBlock($object,$objectid,$somethingshown=0)
{
$class = ucfirst($object);
if(!class_exists($class)) require(DOL_DOCUMENT_ROOT."/".$object."/class/".$object.".class.php");
$linkedObjectBlock = new $class($this->db);
$linkedObjectBlock->getLinkedObjectBlock($object,$objectid,$somethingshown);
}
} }
?> ?>

View File

@ -402,10 +402,12 @@ Class pdf_expedition_merou extends ModelePdfExpedition
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'commande') if ($key == 'commande')
{
for ($i = 0; $i<sizeof($val);$i++)
{ {
$newobject=new Commande($this->db); $newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val[$i]);
if ($result >= 0) if ($result >= 0)
{ {
$Yoff = $Yoff+4; $Yoff = $Yoff+4;
@ -418,6 +420,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition
} }
} }
} }
}
//$this->Code39($Xoff+43, $Yoff+1, $object->commande->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true); //$this->Code39($Xoff+43, $Yoff+1, $object->commande->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true);
//Definition Emplacement du bloc Societe //Definition Emplacement du bloc Societe

View File

@ -195,10 +195,12 @@ Class pdf_expedition_rouget extends ModelePdfExpedition
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'order') if ($key == 'commande')
{
for ($i = 0; $i<sizeof($val);$i++)
{ {
$newobject=new Commande($this->db); $newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val[$i]);
if ($result >= 0) if ($result >= 0)
{ {
$Yoff = $Yoff+8; $Yoff = $Yoff+8;
@ -212,6 +214,7 @@ Class pdf_expedition_rouget extends ModelePdfExpedition
} }
} }
} }
}
} }

View File

@ -1009,6 +1009,7 @@ class pdf_crabe extends ModelePDFFactures
} }
// Add list of linked orders and proposals // Add list of linked orders and proposals
// TODO mutualiser
$object->load_object_linked(); $object->load_object_linked();
if ($conf->propal->enabled) if ($conf->propal->enabled)
@ -1016,10 +1017,12 @@ class pdf_crabe extends ModelePDFFactures
$outputlangs->load('propal'); $outputlangs->load('propal');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'propal') if ($key == 'propal')
{
for ($i = 0; $i<sizeof($val);$i++)
{ {
$newobject=new Propal($this->db); $newobject=new Propal($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val[$i]);
if ($result >= 0) if ($result >= 0)
{ {
$posy+=4; $posy+=4;
@ -1030,16 +1033,20 @@ class pdf_crabe extends ModelePDFFactures
} }
} }
} }
}
// TODO mutualiser
if ($conf->commande->enabled) if ($conf->commande->enabled)
{ {
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'commande') if ($key == 'commande')
{
for ($i = 0; $i<sizeof($val);$i++)
{ {
$newobject=new Commande($this->db); $newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val[$i]);
if ($result >= 0) if ($result >= 0)
{ {
$posy+=4; $posy+=4;
@ -1052,6 +1059,7 @@ class pdf_crabe extends ModelePDFFactures
} }
} }
} }
}
if ($showaddress) if ($showaddress)
{ {

View File

@ -977,12 +977,15 @@ class pdf_oursin extends ModelePDFFactures
// Add list of linked orders and proposals // Add list of linked orders and proposals
$object->load_object_linked(); $object->load_object_linked();
// TODO mutualiser
if ($conf->propal->enabled) if ($conf->propal->enabled)
{ {
$outputlangs->load('propal'); $outputlangs->load('propal');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'propal') if ($key == 'propal')
{
for ($i = 0; $i<sizeof($val);$i++)
{ {
$newobject=new Propal($this->db); $newobject=new Propal($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val['linkid']);
@ -996,16 +999,20 @@ class pdf_oursin extends ModelePDFFactures
} }
} }
} }
}
// TODO mutualiser
if ($conf->commande->enabled) if ($conf->commande->enabled)
{ {
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'commande') if ($key == 'commande')
{
for ($i = 0; $i<sizeof($val);$i++)
{ {
$newobject=new Propal($this->db); $newobject=new Propal($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val[$i]);
if ($result >= 0) if ($result >= 0)
{ {
$posy+=4; $posy+=4;
@ -1018,6 +1025,7 @@ class pdf_oursin extends ModelePDFFactures
} }
} }
} }
}
// Amount in (at tab_top - 1) // Amount in (at tab_top - 1)
$pdf->SetTextColor(0,0,0); $pdf->SetTextColor(0,0,0);

View File

@ -425,6 +425,7 @@ class pdf_sirocco extends ModelePDFDeliveryOrder
$pdf->SetFont('Arial','B',9); $pdf->SetFont('Arial','B',9);
// Add list of linked orders // Add list of linked orders
// TODO mutualiser
$object->load_object_linked(); $object->load_object_linked();
if ($conf->commande->enabled) if ($conf->commande->enabled)
@ -432,10 +433,12 @@ class pdf_sirocco extends ModelePDFDeliveryOrder
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'commande') if ($key == 'commande')
{
for ($i = 0; $i<sizeof($val);$i++)
{ {
$newobject=new Commande($this->db); $newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val[$i]);
if ($result >= 0) if ($result >= 0)
{ {
$posy+=4; $posy+=4;
@ -448,6 +451,7 @@ class pdf_sirocco extends ModelePDFDeliveryOrder
} }
} }
} }
}
} }

View File

@ -358,7 +358,8 @@ class pdf_typhon extends ModelePDFDeliveryOrder
$this->_pagefoot($pdf,$object,$outputlangs); $this->_pagefoot($pdf,$object,$outputlangs);
// Check product remaining to be delivered // Check product remaining to be delivered
$waitingDelivery = $object->getRemainingDelivered(); // TODO doit etre modifie
//$waitingDelivery = $object->getRemainingDelivered();
if (is_array($waitingDelivery) & !empty($waitingDelivery)) if (is_array($waitingDelivery) & !empty($waitingDelivery))
{ {
@ -543,6 +544,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
$pdf->SetTextColor(0,0,60); $pdf->SetTextColor(0,0,60);
// Add list of linked orders // Add list of linked orders
// TODO mutualiser
$object->load_object_linked(); $object->load_object_linked();
if ($conf->commande->enabled) if ($conf->commande->enabled)
@ -550,10 +552,12 @@ class pdf_typhon extends ModelePDFDeliveryOrder
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'commande') if ($key == 'commande')
{
for ($i = 0; $i<sizeof($val);$i++)
{ {
$newobject=new Commande($this->db); $newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val[$i]);
if ($result >= 0) if ($result >= 0)
{ {
$posy+=4; $posy+=4;
@ -566,6 +570,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
} }
} }
} }
}
if ($showadress) if ($showadress)
{ {

View File

@ -369,6 +369,7 @@ class pdf_baleine extends ModelePDFProjects
$pdf->SetTextColor(0,0,60); $pdf->SetTextColor(0,0,60);
// Add list of linked orders // Add list of linked orders
// TODO mutualiser
$object->load_object_linked(); $object->load_object_linked();
if ($conf->commande->enabled) if ($conf->commande->enabled)
@ -376,10 +377,12 @@ class pdf_baleine extends ModelePDFProjects
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'commande') if ($key == 'commande')
{
for ($i = 0; $i<sizeof($val);$i++)
{ {
$newobject=new Commande($this->db); $newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val[$i]);
if ($result >= 0) if ($result >= 0)
{ {
$posy+=4; $posy+=4;
@ -392,6 +395,7 @@ class pdf_baleine extends ModelePDFProjects
} }
} }
} }
}
if ($showadress) if ($showadress)
{ {

View File

@ -40,9 +40,9 @@ function shipping_prepare_head($object)
$head[$h][2] = 'shipping'; $head[$h][2] = 'shipping';
$h++; $h++;
if ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire && $object->linked_object[0]['linkid']) if ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire && $object->linked_object['delivery'][0])
{ {
$head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->linked_object[0]['linkid']; $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->linked_object['delivery'][0];
$head[$h][1] = $langs->trans("DeliveryCard"); $head[$h][1] = $langs->trans("DeliveryCard");
$head[$h][2] = 'delivery'; $head[$h][2] = 'delivery';
$h++; $h++;