Fix new generic substitution system

This commit is contained in:
Laurent Destailleur 2017-06-01 13:32:20 +02:00
parent 733d1caac6
commit 7ad92c3a4d
5 changed files with 47 additions and 42 deletions

View File

@ -474,7 +474,7 @@ print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
print "</tr>\n"; print "</tr>\n";
$var=true; $var=true;
$substitutionarray=pdf_getSubstitutionArray($langs); $substitutionarray=pdf_getSubstitutionArray($langs, array('objectamount'));
$substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation"); $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>'; $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>'; foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';

View File

@ -46,7 +46,7 @@ class Contrat extends CommonObject
public $fk_element='fk_contrat'; public $fk_element='fk_contrat';
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $picto='contract'; public $picto='contract';
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -530,7 +530,7 @@ class Contrat extends CommonObject
$this->fin_validite = $this->db->jdate($result["fin_validite"]); $this->fin_validite = $this->db->jdate($result["fin_validite"]);
$this->date_cloture = $this->db->jdate($result["date_cloture"]); $this->date_cloture = $this->db->jdate($result["date_cloture"]);
$this->user_author_id = $result["fk_user_author"]; $this->user_author_id = $result["fk_user_author"];
$this->commercial_signature_id = $result["fk_commercial_signature"]; $this->commercial_signature_id = $result["fk_commercial_signature"];
@ -613,7 +613,7 @@ class Contrat extends CommonObject
$this->lines=array(); $this->lines=array();
$pos = 0; $pos = 0;
// Selectionne les lignes contrats liees a un produit // Selectionne les lignes contrats liees a un produit
$sql = "SELECT p.label as product_label, p.description as product_desc, p.ref as product_ref,"; $sql = "SELECT p.label as product_label, p.description as product_desc, p.ref as product_ref,";
$sql.= " d.rowid, d.fk_contrat, d.statut, d.description, d.price_ht, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.remise_percent, d.subprice, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht,"; $sql.= " d.rowid, d.fk_contrat, d.statut, d.description, d.price_ht, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.remise_percent, d.subprice, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht,";
@ -1858,7 +1858,7 @@ class Contrat extends CommonObject
$url = DOL_URL_ROOT.'/contrat/card.php?id='.$this->id; $url = DOL_URL_ROOT.'/contrat/card.php?id='.$this->id;
$picto = 'contract'; $picto = 'contract';
$label = ''; $label = '';
if ($user->rights->contrat->lire) { if ($user->rights->contrat->lire) {
$label = '<u>'.$langs->trans("ShowContract").'</u>'; $label = '<u>'.$langs->trans("ShowContract").'</u>';
$label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref; $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
@ -1874,7 +1874,7 @@ class Contrat extends CommonObject
$label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); $label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
} }
} }
$linkclose=''; $linkclose='';
if (empty($notooltip) && $user->rights->contrat->lire) if (empty($notooltip) && $user->rights->contrat->lire)
{ {
@ -1890,7 +1890,7 @@ class Contrat extends CommonObject
$linkstart = '<a href="'.$url.'"'; $linkstart = '<a href="'.$url.'"';
$linkstart.=$linkclose.'>'; $linkstart.=$linkclose.'>';
$linkend='</a>'; $linkend='</a>';
if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend); if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
if ($withpicto && $withpicto != 2) $result.=' '; if ($withpicto && $withpicto != 2) $result.=' ';
$result.=$linkstart.$this->ref.$linkend; $result.=$linkstart.$this->ref.$linkend;
@ -2225,7 +2225,11 @@ class Contrat extends CommonObject
$line->total_ht=90; $line->total_ht=90;
$line->total_ttc=107.64; // 90 * 1.196 $line->total_ttc=107.64; // 90 * 1.196
$line->total_tva=17.64; $line->total_tva=17.64;
if ($num_prods > 0) $line->date_ouverture = dol_now() - 200000;
$line->date_ouverture_prevue = dol_now() - 500000;
$line->date_fin_validite = dol_now() + 500000;
$line->date_cloture = dol_now() - 100000;
if ($num_prods > 0)
{ {
$prodid = mt_rand(1, $num_prods); $prodid = mt_rand(1, $num_prods);
$line->fk_product=$prodids[$prodid]; $line->fk_product=$prodids[$prodid];
@ -2233,11 +2237,6 @@ class Contrat extends CommonObject
$this->lines[$xnbp]=$line; $this->lines[$xnbp]=$line;
$xnbp++; $xnbp++;
} }
$this->amount_ht = $xnbp*100;
$this->total_ht = $xnbp*100;
$this->total_tva = $xnbp*19.6;
$this->total_ttc = $xnbp*119.6;
} }
/** /**

View File

@ -239,7 +239,7 @@ function dol_shutdown()
/** /**
* Return value of a param into GET or POST supervariable. * Return value of a param into GET or POST supervariable.
* Use the property $user->default_values[path]['creatform'] and/or $user->default_values[path]['filters'] and/or $user->default_values[path]['sortorder'] * Use the property $user->default_values[path]['creatform'] and/or $user->default_values[path]['filters'] and/or $user->default_values[path]['sortorder']
* Note: The property $user->default_values is loaded by the main when loading the user. * Note: The property $user->default_values is loaded by main.php when loading the user.
* *
* @param string $paramname Name of parameter to found * @param string $paramname Name of parameter to found
* @param string $check Type of check * @param string $check Type of check
@ -359,32 +359,34 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
if (! empty($check)) if (! empty($check))
{ {
// Replace vars like __DAY__, __MONTH__, __YEAR__, __MYCOUNTRYID__, __USERID__, __ENTITYID__, ... // Substitution variables for GETPOST (used to get final url with variable parameters or final default value with variable paramaters)
if (! is_array($out)) // Example of variables: __DAY__, __MONTH__, __YEAR__, __MYCOUNTRYID__, __USERID__, __ENTITYID__, ...
// We do this only if var is a GET. If it is a POST, may be we want to post the text with vars as the setup text.
if (! is_array($out) && empty($_POST[$paramname]))
{ {
$maxloop=20; $loopnb=0; // Protection against infinite loop $maxloop=20; $loopnb=0; // Protection against infinite loop
while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) // Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side. while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) // Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side.
{ {
$loopnb++; $newout = ''; $loopnb++; $newout = '';
if ($reg[1] == 'DAY') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mday']; } if ($reg[1] == 'DAY') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mday']; }
elseif ($reg[1] == 'MONTH') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mon']; } elseif ($reg[1] == 'MONTH') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mon']; }
elseif ($reg[1] == 'YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['year']; } elseif ($reg[1] == 'YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['year']; }
elseif ($reg[1] == 'PREVIOUS_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; } elseif ($reg[1] == 'PREVIOUS_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
elseif ($reg[1] == 'PREVIOUS_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; } elseif ($reg[1] == 'PREVIOUS_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
elseif ($reg[1] == 'PREVIOUS_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] - 1); } elseif ($reg[1] == 'PREVIOUS_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] - 1); }
elseif ($reg[1] == 'NEXT_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; } elseif ($reg[1] == 'NEXT_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
elseif ($reg[1] == 'NEXT_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; } elseif ($reg[1] == 'NEXT_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
elseif ($reg[1] == 'NEXT_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); } elseif ($reg[1] == 'NEXT_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); }
elseif ($reg[1] == 'MYCOUNTRYID') elseif ($reg[1] == 'MYCOUNTRY_ID' || $reg[1] == 'MYCOUNTRYID')
{ {
$newout = $mysoc->country_id; $newout = $mysoc->country_id;
} }
elseif ($reg[1] == 'USERID') elseif ($reg[1] == 'USER_ID' || $reg[1] == 'USERID')
{ {
$newout = $user->id; $newout = $user->id;
} }
elseif ($reg[1] == 'SUPERVISORID') elseif ($reg[1] == 'SUPERVISOR_ID' || $reg[1] == 'SUPERVISORID')
{ {
$newout = $user->fk_user; $newout = $user->fk_user;
} }
@ -5020,7 +5022,7 @@ function dol_concatdesc($text1,$text2,$forxml=false)
* *
* @param Translate $outputlangs Output language * @param Translate $outputlangs Output language
* @param int $onlykey Do not calculate heavy values of keys (performance enhancement when we need only the keys) * @param int $onlykey Do not calculate heavy values of keys (performance enhancement when we need only the keys)
* @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'object', 'date', 'user', ...) * @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'objectamount', 'date', 'user', ...)
* @param Object $object Object for keys on object * @param Object $object Object for keys on object
* @return array Array of substitutions * @return array Array of substitutions
*/ */
@ -5045,7 +5047,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob
'__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id '__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id
)); ));
} }
if (empty($exclude) || ! in_array('object', $exclude)) if (empty($exclude) || ! in_array('objectamount', $exclude))
{ {
if (is_object($object)) // For backward compatibility if (is_object($object)) // For backward compatibility
{ {

View File

@ -591,12 +591,13 @@ function pdf_pagehead(&$pdf,$outputlangs,$page_height)
* Return array of possible substitutions for PDF content (without external module substitutions). * Return array of possible substitutions for PDF content (without external module substitutions).
* *
* @param Translate $outputlangs Output language * @param Translate $outputlangs Output language
* @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'object', 'date', 'user', ...)
* @param Object $object Object * @param Object $object Object
* @return array Array of substitutions * @return array Array of substitutions
*/ */
function pdf_getSubstitutionArray($outputlangs, $object=null) function pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null)
{ {
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $exclude, $object);
$substitutionarray['__FROM_NAME__']='__FROM_NAME__'; $substitutionarray['__FROM_NAME__']='__FROM_NAME__';
$substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__'; $substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__';
return $substitutionarray; return $substitutionarray;
@ -625,9 +626,9 @@ function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
elseif ($unit=='in') $k=72; elseif ($unit=='in') $k=72;
// Make substitution // Make substitution
$substitutionarray=pdf_getSubstitutionArray($outputlangs,null); $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, null);
complete_substitutions_array($substitutionarray,$outputlangs,null); complete_substitutions_array($substitutionarray, $outputlangs, null);
$text=make_substitutions($text,$substitutionarray,$outputlangs); $text=make_substitutions($text, $substitutionarray, $outputlangs);
$text=$outputlangs->convToOutputCharset($text); $text=$outputlangs->convToOutputCharset($text);
$savx=$pdf->getX(); $savy=$pdf->getY(); $savx=$pdf->getX(); $savy=$pdf->getY();
@ -854,12 +855,12 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass
// Line of free text // Line of free text
if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext)) if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext))
{ {
$substitutionarray=pdf_getSubstitutionArray($outputlangs, $object); $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
// More substitution keys // More substitution keys
$substitutionarray['__FROM_NAME__']=$fromcompany->name; $substitutionarray['__FROM_NAME__']=$fromcompany->name;
$substitutionarray['__FROM_EMAIL__']=$fromcompany->email; $substitutionarray['__FROM_EMAIL__']=$fromcompany->email;
complete_substitutions_array($substitutionarray,$outputlangs,$object); complete_substitutions_array($substitutionarray, $outputlangs, $object);
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs); $newfreetext=make_substitutions($conf->global->$paramfreetext, $substitutionarray, $outputlangs);
$line.=$outputlangs->convToOutputCharset($newfreetext); $line.=$outputlangs->convToOutputCharset($newfreetext);
} }

View File

@ -294,22 +294,25 @@ class pdf_strato extends ModelePDFContract
} else { } else {
$datere = $langs->trans("Unknown"); $datere = $langs->trans("Unknown");
} }
$txtpredefinedservice=''; $txtpredefinedservice='';
$txtpredefinedservice = $objectligne->product_ref; $txtpredefinedservice = $objectligne->product_label;
if ($objectligne->product_label) if ($objectligne->product_label)
{ {
$txtpredefinedservice .= ' - '; $txtpredefinedservice .= ' - ';
$txtpredefinedservice .= $objectligne->product_label; $txtpredefinedservice .= $objectligne->product_label;
} }
$txt='<strong>'.dol_htmlentitiesbr($outputlangs->transnoentities("DateStartPlannedShort")." : ".$datei." - ".$outputlangs->transnoentities("DateEndPlanned")." : ".$datee,1,$outputlangs->charset_output).'</strong>'; $desc=dol_htmlentitiesbr($objectligne->desc,1); // Desc (not empty for free lines)
$txt='';
$txt.=$outputlangs->transnoentities("Quantity").' : <strong>'.$objectligne->qty.'</strong> - '.$outputlangs->transnoentities("UnitPrice").' : <strong>'.price($objectligne->subprice).'</strong>'; // Desc (not empty for free lines)
$txt.='<br>'; $txt.='<br>';
$txt.='<strong>'.dol_htmlentitiesbr($outputlangs->transnoentities("DateStartRealShort")." : ".$daters,1,$outputlangs->charset_output); $txt.=$outputlangs->transnoentities("DateStartPlannedShort")." : <strong>".$datei."</strong> - ".$outputlangs->transnoentities("DateEndPlanned")." : <strong>".$datee.'</strong>';
if ($objectligne->date_cloture) $txt.=dol_htmlentitiesbr(" - ".$outputlangs->transnoentities("DateEndRealShort")." : ".$datere,1,$outputlangs->charset_output).'</strong>'; $txt.='<br>';
$desc=dol_htmlentitiesbr($objectligne->desc,1); $txt.=$outputlangs->transnoentities("DateStartRealShort")." : <strong>".$daters.'</strong>';
if ($objectligne->date_cloture) $txt.=" - ".$outputlangs->transnoentities("DateEndRealShort")." : '<strong>'".$datere.'</strong>';
$pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt,dol_concatdesc($txtpredefinedservice,$desc)), 0, 1, 0); $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
$nexY = $pdf->GetY() + 2; $nexY = $pdf->GetY() + 2;
$pageposafter=$pdf->getPage(); $pageposafter=$pdf->getPage();