NEW Add hook pdf_build_address

NEW Add option MAIN_PUBLIC_NOTE_IN_ADDRESS
This commit is contained in:
Laurent Destailleur 2016-02-25 20:54:37 +01:00
parent 54034ea852
commit 4b4de22a54
2 changed files with 153 additions and 122 deletions

View File

@ -143,6 +143,7 @@ class HookManager
'formattachOptions', 'formattachOptions',
'formBuilddocLineOptions', 'formBuilddocLineOptions',
'moveUploadedFile', 'moveUploadedFile',
'pdf_build_address',
'pdf_writelinedesc', 'pdf_writelinedesc',
'pdf_getlinenum', 'pdf_getlinenum',
'pdf_getlineref', 'pdf_getlineref',

View File

@ -366,7 +366,7 @@ function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includeali
/** /**
* Return a string with full address formated * Return a string with full address formated for output on documents
* *
* @param Translate $outputlangs Output langs object * @param Translate $outputlangs Output langs object
* @param Societe $sourcecompany Source company object * @param Societe $sourcecompany Source company object
@ -379,17 +379,27 @@ function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includeali
*/ */
function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source',$object=null) function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source',$object=null)
{ {
global $conf; global $conf, $hookmanager;
$stringaddress = '';
if ($mode == 'source' && ! is_object($sourcecompany)) return -1; if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
if ($mode == 'target' && ! is_object($targetcompany)) return -1; if ($mode == 'target' && ! is_object($targetcompany)) return -1;
if (! empty($sourcecompany->state_id) && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id); //TODO: Deprecated if (! empty($sourcecompany->state_id) && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id); //TODO deprecated
if (! empty($sourcecompany->state_id) && empty($sourcecompany->state)) $sourcecompany->state=getState($sourcecompany->state_id); if (! empty($sourcecompany->state_id) && empty($sourcecompany->state)) $sourcecompany->state=getState($sourcecompany->state_id);
if (! empty($targetcompany->state_id) && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id); if (! empty($targetcompany->state_id) && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id); //TODO deprecated
if (! empty($targetcompany->state_id) && empty($targetcompany->state)) $targetcompany->state=getState($targetcompany->state_id);
$reshook=0;
$stringaddress = '';
if (is_object($hookmanager))
{
$parameters = array('sourcecompany'=>&$sourcecompany,'targetcompany'=>&$targetcompany,'targetcontact'=>$targetcontact,'outputlangs'=>$outputlangs,'mode'=>$mode,'usecontact'=>$usecontact);
$action='';
$reshook = $hookmanager->executeHooks('pdf_build_address',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
$stringaddress.=$hookmanager->resPrint;
}
if (empty($reshook))
{
if ($mode == 'source') if ($mode == 'source')
{ {
$withCountry = 0; $withCountry = 0;
@ -497,6 +507,20 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1]; if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
$stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4); $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
} }
// Public note
if (! empty($conf->global->MAIN_PUBLIC_NOTE_IN_ADDRESS))
{
if ($mode == 'source' && ! empty($sourcecompany->note_public))
{
$stringaddress.="\n".$sourcecompany->note_public;
}
if (($mode == 'target' || $mode == 'targetwithdetails') && ! empty($targetcompany->note_public))
{
$stringaddress.="\n".$targetcompany->note_public;
}
}
}
} }
return $stringaddress; return $stringaddress;
@ -1046,6 +1070,7 @@ function pdf_writelinedesc(&$pdf,$object,$i,$outputlangs,$w,$h,$posx,$posy,$hide
global $db, $conf, $langs, $hookmanager; global $db, $conf, $langs, $hookmanager;
$reshook=0; $reshook=0;
$result='';
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) ) //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if (is_object($hookmanager)) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run if (is_object($hookmanager)) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
{ {
@ -1055,16 +1080,16 @@ function pdf_writelinedesc(&$pdf,$object,$i,$outputlangs,$w,$h,$posx,$posy,$hide
$action=''; $action='';
$reshook=$hookmanager->executeHooks('pdf_writelinedesc',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('pdf_writelinedesc',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (!empty($hookmanager->resPrint)) return $hookmanager->resPrint; if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
} }
if (empty($reshook)) if (empty($reshook))
{ {
$labelproductservice=pdf_getlinedesc($object,$i,$outputlangs,$hideref,$hidedesc,$issupplierline); $labelproductservice=pdf_getlinedesc($object,$i,$outputlangs,$hideref,$hidedesc,$issupplierline);
// Description // Description
$pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J',true); $pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J',true);
return $labelproductservice; $result.=$labelproductservice;
} }
return ''; return $result;
} }
/** /**
@ -1763,6 +1788,7 @@ function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0)
global $hookmanager; global $hookmanager;
$reshook=0; $reshook=0;
$result='';
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) ) //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if (is_object($hookmanager)) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run if (is_object($hookmanager)) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
{ {
@ -1778,9 +1804,9 @@ function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0)
{ {
if ($object->lines[$i]->special_code == 3) if ($object->lines[$i]->special_code == 3)
{ {
return $outputlangs->transnoentities("Option"); $result.=$outputlangs->transnoentities("Option");
} }
if (empty($hidedetails) || $hidedetails > 1) $result.=price(($object->lines[$i]->total_ht) + ($object->lines[$i]->total_ht)*($object->lines[$i]->tva_tx)/100, 0, $outputlangs); elseif (empty($hidedetails) || $hidedetails > 1) $result.=price(($object->lines[$i]->total_ht) + ($object->lines[$i]->total_ht)*($object->lines[$i]->tva_tx)/100, 0, $outputlangs);
} }
return $result; return $result;
} }
@ -1833,8 +1859,8 @@ function pdf_getTotalQty($object,$type,$outputlangs)
} }
/** /**
* Return linked objects * Return linked objects to use for document generation.
* FIXME This function returns only one link per link type instead of all links. If we fix this, we must also fix function pdf_writeLinkedObjects * Warning: To save space, this function returns only one link per link type (all links are concated on same record string). This function is used by pdf_writeLinkedObjects
* *
* @param object $object Object * @param object $object Object
* @param Translate $outputlangs Object lang for output * @param Translate $outputlangs Object lang for output
@ -1850,7 +1876,11 @@ function pdf_getLinkedObjects($object,$outputlangs)
foreach($object->linkedObjects as $objecttype => $objects) foreach($object->linkedObjects as $objecttype => $objects)
{ {
if ($objecttype == 'propal') if ($objecttype == 'facture')
{
// For invoice, we don't want to have a reference line on document. Image we are using recuring invoice, we will have a line longer than document width.
}
elseif ($objecttype == 'propal' || $objecttype == 'supplier_proposal')
{ {
$outputlangs->load('propal'); $outputlangs->load('propal');
@ -1862,13 +1892,13 @@ function pdf_getLinkedObjects($object,$outputlangs)
$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs); $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs);
} }
} }
else if ($objecttype == 'commande') else if ($objecttype == 'commande' || $objecttype == 'supplier_order')
{ {
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($objects as $elementobject) foreach($objects as $elementobject)
{ {
$linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder"); $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder");
$linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref) . ($elementobject->ref_client ? ' ('.$elementobject->ref_client.')' : ''); $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref) . ($elementobject->ref_client ? ' ('.$elementobject->ref_client.')' : '') . ($elementobject->ref_supplier ? ' ('.$elementobject->ref_supplier.')' : '');
$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate"); $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate");
$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs); $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs);
} }
@ -1892,7 +1922,7 @@ function pdf_getLinkedObjects($object,$outputlangs)
{ {
$elementobject->fetchObjectLinked(); $elementobject->fetchObjectLinked();
$order = reset($elementobject->linkedObjects['commande']); $order = reset($elementobject->linkedObjects['commande']); // Get first order
if (! empty($object->linkedObjects['commande'])) // There is already a link to order so we show only info of shipment if (! empty($object->linkedObjects['commande'])) // There is already a link to order so we show only info of shipment
{ {