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)
{ {
// Cas des factures liees directement for ($i = 0; $i<sizeof($objectid);$i++)
if ($object['type'] == 'facture')
{ {
$linkedInvoices[] = $object['linkid']; // Cas des factures liees directement
} if ($object == 'facture')
// Cas des factures liees via la commande
else
{
$this->load_object_linked($object['linkid'],$object['type']);
foreach($this->linked_object as $key => $object)
{ {
$linkedInvoices[] = $object['linkid']; $linkedInvoices[] = $object[$i];
}
// Cas des factures liees via la commande
else
{
$this->load_object_linked($object[$i],$object);
foreach($this->linked_object as $object => $objectid)
{
for ($j = 0; $j<sizeof($objectid);$j++)
{
$linkedInvoices[] = $object[$j];
}
}
} }
} }
} }

View File

@ -2357,11 +2357,48 @@ class Commande extends CommonObject
return -1; return -1;
} }
} }
/**
*
*
*/
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>';
}
}
} }
/** /**
* \class OrderLine * \class OrderLine
* \brief Classe de gestion des lignes de commande * \brief Classe de gestion des lignes de commande

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++;
} }
@ -1013,6 +1013,17 @@ class CommonObject
print $sql; print $sql;
} }
} }
/**
*
*/
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,18 +402,21 @@ 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')
{ {
$newobject=new Commande($this->db); for ($i = 0; $i<sizeof($val);$i++)
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{ {
$Yoff = $Yoff+4; $newobject=new Commande($this->db);
$pdf->SetXY($Xoff,$Yoff); $result=$newobject->fetch($val[$i]);
$pdf->SetFont('Arial','',8); if ($result >= 0)
$text=$newobject->ref; {
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')'; $Yoff = $Yoff+4;
$pdf->MultiCell(0, 3, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R'); $pdf->SetXY($Xoff,$Yoff);
$pdf->SetFont('Arial','',8);
$text=$newobject->ref;
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')';
$pdf->MultiCell(0, 3, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
}
} }
} }
} }

View File

@ -195,19 +195,22 @@ 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')
{ {
$newobject=new Commande($this->db); for ($i = 0; $i<sizeof($val);$i++)
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{ {
$Yoff = $Yoff+8; $newobject=new Commande($this->db);
$pdf->SetXY($Xoff,$Yoff); $result=$newobject->fetch($val[$i]);
$pdf->SetFont('Arial','',8); if ($result >= 0)
$text=$newobject->ref; {
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')'; $Yoff = $Yoff+8;
$pdf->Text($posx, $Yoff, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text)); $pdf->SetXY($Xoff,$Yoff);
$pdf->Text($posx, $Yoff+4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->commande->date,"%d %b %Y",false,$outputlangs,true)); $pdf->SetFont('Arial','',8);
$text=$newobject->ref;
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')';
$pdf->Text($posx, $Yoff, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text));
$pdf->Text($posx, $Yoff+4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->commande->date,"%d %b %Y",false,$outputlangs,true));
}
} }
} }
} }

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,38 +1017,45 @@ 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')
{ {
$newobject=new Propal($this->db); for ($i = 0; $i<sizeof($val);$i++)
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{ {
$posy+=4; $newobject=new Propal($this->db);
$pdf->SetXY(100,$posy); $result=$newobject->fetch($val[$i]);
$pdf->SetFont('Arial','',9); if ($result >= 0)
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefProposal")." : ".$outputlangs->transnoentities($newobject->ref), '', 'R'); {
$posy+=4;
$pdf->SetXY(100,$posy);
$pdf->SetFont('Arial','',9);
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefProposal")." : ".$outputlangs->transnoentities($newobject->ref), '', 'R');
}
} }
} }
} }
} }
if ($conf->commande->enabled) // TODO mutualiser
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')
{ {
$newobject=new Commande($this->db); for ($i = 0; $i<sizeof($val);$i++)
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{ {
$posy+=4; $newobject=new Commande($this->db);
$pdf->SetXY(100,$posy); $result=$newobject->fetch($val[$i]);
$pdf->SetFont('Arial','',9); if ($result >= 0)
$text=$newobject->ref; {
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')'; $posy+=4;
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R'); $pdf->SetXY(100,$posy);
$pdf->SetFont('Arial','',9);
$text=$newobject->ref;
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')';
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
}
} }
} }
} }

View File

@ -977,43 +977,51 @@ 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')
{ {
$newobject=new Propal($this->db); for ($i = 0; $i<sizeof($val);$i++)
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{ {
$posy+=4; $newobject=new Propal($this->db);
$pdf->SetXY($this->marges['g'],$posy); $result=$newobject->fetch($val['linkid']);
$pdf->SetFont('Arial','',9); if ($result >= 0)
$pdf->MultiCell(60, 3, $outputlangs->transnoentities("RefProposal")." : ".$outputlangs->transnoentities($newobject->ref)); {
$posy+=4;
$pdf->SetXY($this->marges['g'],$posy);
$pdf->SetFont('Arial','',9);
$pdf->MultiCell(60, 3, $outputlangs->transnoentities("RefProposal")." : ".$outputlangs->transnoentities($newobject->ref));
}
} }
} }
} }
} }
if ($conf->commande->enabled) // TODO mutualiser
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')
{ {
$newobject=new Propal($this->db); for ($i = 0; $i<sizeof($val);$i++)
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{ {
$posy+=4; $newobject=new Propal($this->db);
$pdf->SetXY($this->marges['g'],$posy); $result=$newobject->fetch($val[$i]);
$pdf->SetFont('Arial','',9); if ($result >= 0)
$text=$newobject->ref; {
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')'; $posy+=4;
$pdf->MultiCell(60, 3, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text)); $pdf->SetXY($this->marges['g'],$posy);
$pdf->SetFont('Arial','',9);
$text=$newobject->ref;
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')';
$pdf->MultiCell(60, 3, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text));
}
} }
} }
} }

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,18 +433,21 @@ 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')
{ {
$newobject=new Commande($this->db); for ($i = 0; $i<sizeof($val);$i++)
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{ {
$posy+=4; $newobject=new Commande($this->db);
$pdf->SetXY(102,$posy); $result=$newobject->fetch($val[$i]);
$pdf->SetFont('Arial','',9); if ($result >= 0)
$text=$newobject->ref; {
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')'; $posy+=4;
$pdf->Text(11, 94, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R'); $pdf->SetXY(102,$posy);
$pdf->SetFont('Arial','',9);
$text=$newobject->ref;
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')';
$pdf->Text(11, 94, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
}
} }
} }
} }

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,18 +552,21 @@ 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')
{ {
$newobject=new Commande($this->db); for ($i = 0; $i<sizeof($val);$i++)
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{ {
$posy+=4; $newobject=new Commande($this->db);
$pdf->SetXY(100,$posy); $result=$newobject->fetch($val[$i]);
$pdf->SetFont('Arial','',9); if ($result >= 0)
$text=$newobject->ref; {
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')'; $posy+=4;
$pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R'); $pdf->SetXY(100,$posy);
$pdf->SetFont('Arial','',9);
$text=$newobject->ref;
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')';
$pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
}
} }
} }
} }

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,18 +377,21 @@ 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')
{ {
$newobject=new Commande($this->db); for ($i = 0; $i<sizeof($val);$i++)
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{ {
$posy+=4; $newobject=new Commande($this->db);
$pdf->SetXY(100,$posy); $result=$newobject->fetch($val[$i]);
$pdf->SetFont('Arial','',9); if ($result >= 0)
$text=$newobject->ref; {
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')'; $posy+=4;
$pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R'); $pdf->SetXY(100,$posy);
$pdf->SetFont('Arial','',9);
$text=$newobject->ref;
if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')';
$pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
}
} }
} }
} }

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++;