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

@ -2225,6 +2225,10 @@ 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;
$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) if ($num_prods > 0)
{ {
$prodid = mt_rand(1, $num_prods); $prodid = mt_rand(1, $num_prods);
@ -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,8 +359,10 @@ 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.
@ -376,15 +378,15 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
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

@ -296,20 +296,23 @@ class pdf_strato extends ModelePDFContract
} }
$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();