From bdd943d6e8bd11188a9ae4f2d5c897787cb93fa4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 Jun 2009 19:42:34 +0000 Subject: [PATCH] New: Add ref to linked objects on PDF --- htdocs/commonobject.class.php | 103 ++++++++++++++++++ htdocs/compta/facture.php | 4 +- htdocs/compta/sociales/charges.php | 10 +- .../modules/facture/pdf_crabe.modules.php | 48 +++++++- .../modules/facture/pdf_oursin.modules.php | 53 ++++++--- 5 files changed, 194 insertions(+), 24 deletions(-) diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php index c203aa72264..84680bebda1 100644 --- a/htdocs/commonobject.class.php +++ b/htdocs/commonobject.class.php @@ -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++; + } + } + } + } + } ?> diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index b9bde043416..fed51ea23dd 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3369,7 +3369,7 @@ else print ''.$langs->trans('Ref').''; print ''.$langs->trans('RefCustomer').''; print ''.$langs->trans('Date').''; - print ''.$langs->trans('AmountHT').''; + print ''.$langs->trans('AmountHTShort').''; print ''; $var=True; @@ -3423,7 +3423,7 @@ else print ''.$langs->trans('Ref').''; print ''.$langs->trans('RefCustomerOrderShort').''; print ''.$langs->trans('Date').''; - print ''.$langs->trans('AmountHT').''; + print ''.$langs->trans('AmountHTShort').''; print ''; $var=true; while ($i < $num) diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index 8bdae6d72f9..fecd50da690 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -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 ''; print ''; @@ -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 "\n"; } print "
"; print img_object($langs->trans("Payment"),"payment").' '; @@ -369,7 +369,7 @@ if ($chid > 0) print "".price($resteapayer)."".$langs->trans("Currency".$conf->monnaie)."
"; - $db->free(); + $db->free($resql); } else { diff --git a/htdocs/includes/modules/facture/pdf_crabe.modules.php b/htdocs/includes/modules/facture/pdf_crabe.modules.php index 79cad07330c..6def0c5ab4f 100644 --- a/htdocs/includes/modules/facture/pdf_crabe.modules.php +++ b/htdocs/includes/modules/facture/pdf_crabe.modules.php @@ -124,13 +124,14 @@ class pdf_crabe extends ModelePDFFactures if ($conf->facture->dir_output) { - // D�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 diff --git a/htdocs/includes/modules/facture/pdf_oursin.modules.php b/htdocs/includes/modules/facture/pdf_oursin.modules.php index 68b750dda98..33c4f8eb9d2 100644 --- a/htdocs/includes/modules/facture/pdf_oursin.modules.php +++ b/htdocs/includes/modules/facture/pdf_oursin.modules.php @@ -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)); + } } } }