New: Add ref to linked objects on PDF

This commit is contained in:
Laurent Destailleur 2009-06-04 19:42:34 +00:00
parent c39a1e4008
commit bdd943d6e8
5 changed files with 194 additions and 24 deletions

View File

@ -811,6 +811,109 @@ class CommonObject
return -1;
}
}
/**
* Load array of objects linked to current object. Links are loaded into this->linked_object array.
*/
function load_object_linked()
{
$this->linked_object=array();
// Links beetween objects are stored in this table
$sql = 'SELECT sourceid, sourcetype, targetid, targettype';
$sql.= ' FROM '.MAIN_DB_PREFIX.'element_element';
$sql.= " WHERE (source_id = '.$this->id.' AND source_type = 'invoice')";
$sql.= " OR (target_id = '.$this->id.' AND target_id = 'invoice')";
dol_syslog("CommonObject::load_object_linked sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if ($obj->sourceid == $this->id)
{
$this->linked_object[]=array('linkid'=>$obj->targetid, 'type'=>$obj->targettype);
}
if ($obj->targetid == $this->id)
{
$this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>$obj->sourcetype);
}
$i++;
}
}
// For backward compatibility, read other old link tables co_fa (will be moved later)
if ($this->element == 'facture' || $this->element == 'commande')
{
if ($this->element == 'facture') $sql = "SELECT fk_commande as sourceid";
if ($this->element == 'commande') $sql = "SELECT fk_facture as sourceid";
$sql.= ' FROM '.MAIN_DB_PREFIX.'co_fa';
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
dol_syslog("CommonObject::load_object_linked sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if ($this->element == 'facture') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'order');
if ($this->element == 'commande') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'invoice');
$i++;
}
}
}
// For backward compatibility, read other old link tables fa_pr (will be moved later)
if ($this->element == 'facture' || $this->element == 'propal')
{
if ($this->element == 'facture') $sql = "SELECT fk_propal as sourceid";
if ($this->element == 'propal') $sql = "SELECT fk_facture as sourceid";
$sql.= ' FROM '.MAIN_DB_PREFIX.'fa_pr';
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
dol_syslog("CommonObject::load_object_linked sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if ($this->element == 'facture') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'propal');
if ($this->element == 'propal') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'invoice');
$i++;
}
}
}
// For backward compatibility, read other old link tables co_pr (will be moved later)
if ($this->element == 'commande' || $this->element == 'propal')
{
if ($this->element == 'commande') $sql = "SELECT fk_propale as sourceid";
if ($this->element == 'propal') $sql = "SELECT fk_commande as sourceid";
$sql.= ' FROM '.MAIN_DB_PREFIX.'co_pr';
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
dol_syslog("CommonObject::load_object_linked sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if ($this->element == 'commande') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'propal');
if ($this->element == 'propal') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'order');
$i++;
}
}
}
}
}
?>

View File

@ -3369,7 +3369,7 @@ else
print '<td width="150">'.$langs->trans('Ref').'</td>';
print '<td>'.$langs->trans('RefCustomer').'</td>';
print '<td align="center">'.$langs->trans('Date').'</td>';
print '<td align="right">'.$langs->trans('AmountHT').'</td>';
print '<td align="right">'.$langs->trans('AmountHTShort').'</td>';
print '</tr>';
$var=True;
@ -3423,7 +3423,7 @@ else
print '<td width="150">'.$langs->trans('Ref').'</td>';
print '<td>'.$langs->trans('RefCustomerOrderShort').'</td>';
print '<td align="center">'.$langs->trans('Date').'</td>';
print '<td align="right">'.$langs->trans('AmountHT').'</td>';
print '<td align="right">'.$langs->trans('AmountHTShort').'</td>';
print '</tr>';
$var=true;
while ($i < $num)

View File

@ -333,10 +333,10 @@ if ($chid > 0)
$sql.= " AND p.fk_typepaiement = c.id";
$sql.= " ORDER BY dp DESC";
$result = $db->query($sql);
if ($result)
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($result);
$num = $db->num_rows($resql);
$i = 0; $total = 0;
echo '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
@ -346,7 +346,7 @@ if ($chid > 0)
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object($result);
$objp = $db->fetch_object($resql);
$var=!$var;
print "<tr $bc[$var]><td>";
print img_object($langs->trans("Payment"),"payment").' ';
@ -369,7 +369,7 @@ if ($chid > 0)
print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($resteapayer)."</b></td><td bgcolor=\"#f0f0f0\">".$langs->trans("Currency".$conf->monnaie)."</td></tr>\n";
}
print "</table>";
$db->free();
$db->free($resql);
}
else
{

View File

@ -124,13 +124,14 @@ class pdf_crabe extends ModelePDFFactures
if ($conf->facture->dir_output)
{
// D<EFBFBD>finition de l'objet $fac (pour compatibilite ascendante)
// Definition de l'objet $fac (pour compatibilite ascendante)
if (! is_object($fac))
{
$id = $fac;
$fac = new Facture($this->db,"",$id);
$ret=$fac->fetch($id);
}
$fac->fetch_client();
$deja_regle = $fac->getSommePaiement();
@ -1010,6 +1011,51 @@ class pdf_crabe extends ModelePDFFactures
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->client->code_client), '', 'R');
}
// Add list of linked orders and proposals
$object->load_object_linked();
if ($conf->propal->enabled)
{
$outputlangs->load('propal');
foreach($object->linked_object as $key => $val)
{
if ($val['type'] == 'propal')
{
$newobject=new Propal($this->db);
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{
$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)
{
$outputlangs->load('orders');
foreach($object->linked_object as $key => $val)
{
if ($val['type'] == 'order')
{
$newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{
$posy+=4;
$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');
}
}
}
}
if ($showadress)
{
// Emetteur

View File

@ -774,7 +774,7 @@ class pdf_oursin extends ModelePDFFactures
{
$pdf->Text($this->marges['g']+163, $tab_top + 5,$outputlangs->transnoentities("Note"));
}
$pdf->Text($this->marges['g']+175, $tab_top + 5, $outputlangs->transnoentities("TotalHT"));
$pdf->Text($this->marges['g']+175, $tab_top + 5, $outputlangs->transnoentities("TotalHTShort"));
return $pdf->GetY();
}
@ -1015,26 +1015,47 @@ class pdf_oursin extends ModelePDFFactures
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->client->code_client), '', 'L');
}
// Add list of linked orders and proposals
$object->load_object_linked();
/*
* ref propal
*/
if ($conf->propal->enabled)
if ($conf->propal->enabled)
{
$outputlangs->load('propal');
$sql = "SELECT ".$object->db->pdate("p.datep")." as dp, p.ref, p.rowid as propalid";
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $object->id";
$result = $object->db->query($sql);
if ($result)
foreach($object->linked_object as $key => $val)
{
$objp = $object->db->fetch_object();
if ($objp->ref)
if ($val['type'] == 'propal')
{
$posy+=4;
$pdf->SetXY($this->marges['g'],$posy);
$pdf->SetFont('Arial','',9);
$pdf->MultiCell(60, 3, $outputlangs->transnoentities("RefProposal")." : ".$objp->ref);
$newobject=new Propal($this->db);
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{
$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)
{
$outputlangs->load('orders');
foreach($object->linked_object as $key => $val)
{
if ($val['type'] == 'order')
{
$newobject=new Propal($this->db);
$result=$newobject->fetch($val['linkid']);
if ($result >= 0)
{
$posy+=4;
$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));
}
}
}
}