From 83286d99be429a53eaf116d69efc3308ca860bd1 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Wed, 9 Dec 2020 13:31:14 +0100 Subject: [PATCH 01/25] funnel horizontal bar --- .../core/boxes/box_funnel_of_prospection.php | 18 +- htdocs/core/class/dolgraph.class.php | 401 +++++++++--------- 2 files changed, 215 insertions(+), 204 deletions(-) diff --git a/htdocs/core/boxes/box_funnel_of_prospection.php b/htdocs/core/boxes/box_funnel_of_prospection.php index c4cebfcf68a..34b892d142b 100644 --- a/htdocs/core/boxes/box_funnel_of_prospection.php +++ b/htdocs/core/boxes/box_funnel_of_prospection.php @@ -81,6 +81,8 @@ class box_funnel_of_prospection extends ModeleBoxes $sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_lead_status as cls"; $sql .= " WHERE active=1"; + $sql .= " Order by cls.rowid"; + $sql .= " AND cls.code != 'LOST'"; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -108,7 +110,6 @@ class box_funnel_of_prospection extends ModeleBoxes $colorseriesstat[$objp->rowid] = $badgeStatus6; break; default: - $colorseriesstat[$objp->rowid] = $badgeStatus2; break; } $i++; @@ -167,14 +168,16 @@ class box_funnel_of_prospection extends ModeleBoxes $stringtoprint = ''; $stringtoprint .= '
'; $listofstatus = array_keys($listofoppstatus); + $liststatus = array(); + $data = array(''); foreach ($listofstatus as $status) { $labelStatus = ''; if ($status != 7) { $code = dol_getIdFromCode($this->db, $status, 'c_lead_status', 'rowid', 'code'); if ($code) $labelStatus = $langs->transnoentitiesnoconv("OppStatus" . $code); if (empty($labelStatus)) $labelStatus = $listofopplabel[$status]; - - $dataseries[] = array($labelStatus,(isset($valsamount[$status]) ? (float) $valsamount[$status] : 0)); + $liststatus[] = $labelStatus; + $data[] = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0); if (!$conf->use_javascript_ajax) { $stringtoprint .= ''; $stringtoprint .= '' . $labelStatus . ''; @@ -183,16 +186,21 @@ class box_funnel_of_prospection extends ModeleBoxes } } } + $dataseries[] = $data; if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php'; $dolgraph = new DolGraph(); + $dolgraph->SetMinValue(0); $dolgraph->SetData($dataseries); + $dolgraph->SetLegend($liststatus); $dolgraph->SetDataColor(array_values($colorseriesstat)); - //$dolgraph->SetLegend(array('PROSP',$dataseries['PROSP'])); $dolgraph->setShowLegend(2); $dolgraph->setShowPercent(1); - $dolgraph->SetType(array('pie')); + $dolgraph->setTitle('FunnelOfProspection'); + $dolgraph->SetType(array('horizontalbars')); $dolgraph->SetHeight('200'); + $dolgraph->SetWidth('600'); + $dolgraph->mode='depth'; $dolgraph->draw('idgraphstatus'); $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1); } diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 80314bcf9ed..ccce9cb1e12 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -103,9 +103,8 @@ class DolGraph $this->datacolor = array(array(120, 130, 150), array(160, 160, 180), array(190, 190, 220)); $this->bgcolor = array(235, 235, 224); - $color_file = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; - if (is_readable($color_file)) - { + $color_file = DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php'; + if (is_readable($color_file)) { include_once $color_file; if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor; if (isset($theme_datacolor)) $this->datacolor = $theme_datacolor; @@ -261,7 +260,7 @@ class DolGraph * Set type * * @param array $type Array with type for each serie. Example: array('type1', 'type2', ...) where type can be: - * 'pie', 'piesemicircle', 'polar', 'lines', 'linesnopoint', 'bars', 'horirontalbars'... + * 'pie', 'piesemicircle', 'polar', 'lines', 'linesnopoint', 'bars', 'horizontalbars'... * @return void */ public function SetType($type) @@ -466,10 +465,8 @@ class DolGraph // phpcs:enable global $theme_bgcolor, $theme_bgcoloronglet; - if (!is_array($bg_color)) - { - if ($bg_color == 'onglet') - { + if (!is_array($bg_color)) { + if ($bg_color == 'onglet') { //print 'ee'.join(',',$theme_bgcoloronglet); $this->bgcolor = $theme_bgcoloronglet; } else { @@ -492,10 +489,8 @@ class DolGraph // phpcs:enable global $theme_bgcolor, $theme_bgcoloronglet; - if (!is_array($bg_colorgrid)) - { - if ($bg_colorgrid == 'onglet') - { + if (!is_array($bg_colorgrid)) { + if ($bg_colorgrid == 'onglet') { //print 'ee'.join(',',$theme_bgcoloronglet); $this->bgcolorgrid = $theme_bgcoloronglet; } else { @@ -535,10 +530,8 @@ class DolGraph $nblines = count($this->data); $nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1); - for ($j = 0; $j < $nblines; $j++) - { - for ($i = 0; $i < $nbvalues; $i++) - { + for ($j = 0; $j < $nblines; $j++) { + for ($i = 0; $i < $nbvalues; $i++) { $vals[$k] = $this->data[$j][$i + 1]; $k++; } @@ -564,10 +557,8 @@ class DolGraph $nblines = count($this->data); $nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1); - for ($j = 0; $j < $nblines; $j++) - { - for ($i = 0; $i < $nbvalues; $i++) - { + for ($j = 0; $j < $nblines; $j++) { + for ($i = 0; $i < $nbvalues; $i++) { $vals[$k] = $this->data[$j][$i + 1]; $k++; } @@ -589,8 +580,7 @@ class DolGraph if ($max != 0) $max++; $size = dol_strlen(abs(ceil($max))); $factor = 1; - for ($i = 0; $i < ($size - 1); $i++) - { + for ($i = 0; $i < ($size - 1); $i++) { $factor *= 10; } @@ -615,8 +605,7 @@ class DolGraph if ($min != 0) $min--; $size = dol_strlen(abs(floor($min))); $factor = 1; - for ($i = 0; $i < ($size - 1); $i++) - { + for ($i = 0; $i < ($size - 1); $i++) { $factor *= 10; } @@ -635,24 +624,21 @@ class DolGraph */ public function draw($file, $fileurl = '') { - if (empty($file)) - { + if (empty($file)) { $this->error = "Call to draw method was made with empty value for parameter file."; - dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR); + dol_syslog(get_class($this) . "::draw " . $this->error, LOG_ERR); return -2; } - if (!is_array($this->data)) - { + if (!is_array($this->data)) { $this->error = "Call to draw method was made but SetData was not called or called with an empty dataset for parameters"; - dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR); + dol_syslog(get_class($this) . "::draw " . $this->error, LOG_ERR); return -1; } - if (count($this->data) < 1) - { + if (count($this->data) < 1) { $this->error = "Call to draw method was made but SetData was is an empty dataset"; - dol_syslog(get_class($this)."::draw ".$this->error, LOG_WARNING); + dol_syslog(get_class($this) . "::draw " . $this->error, LOG_WARNING); } - $call = "draw_".$this->_library; + $call = "draw_" . $this->_library; call_user_func_array(array($this, $call), array($file, $fileurl)); } @@ -678,10 +664,9 @@ class DolGraph // phpcs:enable global $conf, $langs; - dol_syslog(get_class($this)."::draw_jflot this->type=".join(',', $this->type)." this->MaxValue=".$this->MaxValue); + dol_syslog(get_class($this) . "::draw_jflot this->type=" . join(',', $this->type) . " this->MaxValue=" . $this->MaxValue); - if (empty($this->width) && empty($this->height)) - { + if (empty($this->width) && empty($this->height)) { print 'Error width or height not set'; return; } @@ -701,7 +686,7 @@ class DolGraph while ($i < $nblot) // Loop on each serie { $values = array(); // Array with horizontal y values (specific values of a serie) for each abscisse x - $serie[$i] = "var d".$i." = [];\n"; + $serie[$i] = "var d" . $i . " = [];\n"; // Fill array $values $x = 0; @@ -712,14 +697,13 @@ class DolGraph $x++; } - if (isset($this->type[$firstlot]) && in_array($this->type[$firstlot], array('pie', 'piesemicircle', 'polar'))) - { + if (isset($this->type[$firstlot]) && in_array($this->type[$firstlot], array('pie', 'piesemicircle', 'polar'))) { foreach ($values as $x => $y) { - if (isset($y)) $serie[$i] .= 'd'.$i.'.push({"label":"'.dol_escape_js($legends[$x]).'", "data":'.$y.'});'."\n"; + if (isset($y)) $serie[$i] .= 'd' . $i . '.push({"label":"' . dol_escape_js($legends[$x]) . '", "data":' . $y . '});' . "\n"; } } else { foreach ($values as $x => $y) { - if (isset($y)) $serie[$i] .= 'd'.$i.'.push(['.$x.', '.$y.']);'."\n"; + if (isset($y)) $serie[$i] .= 'd' . $i . '.push([' . $x . ', ' . $y . ']);' . "\n"; } } @@ -728,43 +712,39 @@ class DolGraph } $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); - $this->stringtoshow = ''."\n"; - if (!empty($this->title)) $this->stringtoshow .= '
'.$this->title.'
'; - if (!empty($this->shownographyet)) - { - $this->stringtoshow .= '
'; - $this->stringtoshow .= '
'.$langs->trans("NotEnoughDataYet").'...
'; + $this->stringtoshow = '' . "\n"; + if (!empty($this->title)) $this->stringtoshow .= '
' . $this->title . '
'; + if (!empty($this->shownographyet)) { + $this->stringtoshow .= '
'; + $this->stringtoshow .= '
' . $langs->trans("NotEnoughDataYet") . '...
'; return; } // Start the div that will contains all the graph $dolxaxisvertical = ''; if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical'; - $this->stringtoshow .= '
'."\n"; + $this->stringtoshow .= '
' . "\n"; - $this->stringtoshow .= ''."\n"; + $this->stringtoshow .= 'plotWithOptions_' . $tag . '();' . "\n"; + $this->stringtoshow .= '});' . "\n"; + $this->stringtoshow .= '' . "\n"; } @@ -947,10 +924,9 @@ class DolGraph // phpcs:enable global $conf, $langs; - dol_syslog(get_class($this)."::draw_chart this->type=".join(',', $this->type)." this->MaxValue=".$this->MaxValue); + dol_syslog(get_class($this) . "::draw_chart this->type=" . join(',', $this->type) . " this->MaxValue=" . $this->MaxValue); - if (empty($this->width) && empty($this->height)) - { + if (empty($this->width) && empty($this->height)) { print 'Error width or height not set'; return; } @@ -971,7 +947,8 @@ class DolGraph // Works with line but not with bars //if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x - $serie = array(); $arrayofgroupslegend = array(); + $serie = array(); + $arrayofgroupslegend = array(); //var_dump($this->data); $i = $firstlot; @@ -989,15 +966,15 @@ class DolGraph $alabelexists = 1; $tmpykey = explode('_', ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3); if (!empty($tmpykey[2]) || $tmpykey[2] == '0') { // This is a 'Group by' array - $tmpvalue = (array_key_exists('y_'.$tmpykey[1].'_'.$tmpykey[2], $valarray) ? $valarray['y_'.$tmpykey[1].'_'.$tmpykey[2]] : $valarray[$i + 1]); + $tmpvalue = (array_key_exists('y_' . $tmpykey[1] . '_' . $tmpykey[2], $valarray) ? $valarray['y_' . $tmpykey[1] . '_' . $tmpykey[2]] : $valarray[$i + 1]); $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); $arrayofgroupslegend[$i] = array( - 'stacknum'=> $tmpykey[1], + 'stacknum' => $tmpykey[1], 'legend' => $this->Legend[$tmpykey[1]], - 'legendwithgroup' => $this->Legend[$tmpykey[1]].' - '.$tmpykey[2] + 'legendwithgroup' => $this->Legend[$tmpykey[1]] . ' - ' . $tmpykey[2] ); } else { - $tmpvalue = (array_key_exists('y_'.$i, $valarray) ? $valarray['y_'.$i] : $valarray[$i + 1]); + $tmpvalue = (array_key_exists('y_' . $i, $valarray) ? $valarray['y_' . $i] : $valarray[$i + 1]); //var_dump($i.'_'.$x.'_'.$tmpvalue); $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); } @@ -1007,9 +984,9 @@ class DolGraph $j = 0; foreach ($values as $x => $y) { if (isset($y)) { - $serie[$i] .= ($j > 0 ? ", " : "").$y; + $serie[$i] .= ($j > 0 ? ", " : "") . $y; } else { - $serie[$i] .= ($j > 0 ? ", " : "").'null'; + $serie[$i] .= ($j > 0 ? ", " : "") . 'null'; } $j++; } @@ -1022,12 +999,11 @@ class DolGraph $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); - $this->stringtoshow = ''."\n"; - if (!empty($this->title)) $this->stringtoshow .= '
'.$this->title.'
'; - if (!empty($this->shownographyet)) - { - $this->stringtoshow .= '
'; - $this->stringtoshow .= '
'.$langs->trans("NotEnoughDataYet").'...
'; + $this->stringtoshow = '' . "\n"; + if (!empty($this->title)&&$this->title!='FunnelOfProspection') $this->stringtoshow .= '
' . $this->title . '
'; + if (!empty($this->shownographyet)) { + $this->stringtoshow .= '
'; + $this->stringtoshow .= '
' . $langs->trans("NotEnoughDataYet") . '...
'; return; } @@ -1036,17 +1012,15 @@ class DolGraph if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical'; // No height for the pie grah $cssfordiv = 'dolgraphchart'; - if (isset($this->type[$firstlot])) $cssfordiv .= ' dolgraphchar'.$this->type[$firstlot]; - $this->stringtoshow .= '
'."\n"; + if (isset($this->type[$firstlot])) $cssfordiv .= ' dolgraphchar' . $this->type[$firstlot]; + $this->stringtoshow .= '
' . "\n"; - $this->stringtoshow .= ''."\n"; + $this->stringtoshow .= '' . "\n"; } @@ -1301,14 +1305,13 @@ class DolGraph { global $langs; - if ($shownographyet) - { - $s = '
'; + if ($shownographyet) { + $s = '
'; $s .= '
'; if (is_numeric($shownographyet)) { - $s .= $langs->trans("NotEnoughDataYet").'...'; + $s .= $langs->trans("NotEnoughDataYet") . '...'; } else { - $s .= $shownographyet.'...'; + $s .= $shownographyet . '...'; } $s .= '
'; return $s; From b3ca58d2d0ae2f5fb38b7328664e7869a8b1ac3d Mon Sep 17 00:00:00 2001 From: zuiko Date: Wed, 9 Dec 2020 21:16:25 +0100 Subject: [PATCH 02/25] Update html.form.class.php Complete the Fix to #15565 Enhanced behaviour to select product on customer/supplier order to be able to use barcode reader efficiently. Answer to Eldy, https://github.com/Dolibarr/dolibarr/pull/15704#discussion_r538763166 In fact the change alone to htdocs/core/lib/ajax.lib.php is not, for me, sufficient to fix the issue. if $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, the combo remains even if the product is alone. So I recommend that the code is $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, (wihout combo) for product selection only for customer order filling because for this usage the the probability is higher to use a barcode scanner. It is less relevant for filling supplier orders (which are not usually entered by barcode scanner), because the combo gives verification information which then disappears. (This is especially true for the purchase price, which is not pre-filled in the box for the moment I tested(?). --- htdocs/core/class/html.form.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 8faad1f92e9..8c4d24c64cf 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1995,7 +1995,7 @@ class Form if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { $urloption .= '&socid='.$socid; } - $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); + $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions); if (!empty($conf->variants->enabled)) { $out .= ' From ecd642e46529d3225ffa7db723bedd716ba083d6 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Thu, 10 Dec 2020 10:58:07 +0100 Subject: [PATCH 03/25] Close #15383 : New format for funnel of prospection --- htdocs/core/class/dolgraph.class.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index ccce9cb1e12..832047b3c65 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -1154,6 +1154,18 @@ class DolGraph $this->stringtoshow .= ', yAxes: [{ stacked: true }]'; } $this->stringtoshow .= ' }'; + if ($isfunnel) { + $this->stringtoshow .= ', tooltips: {mode: \'nearest\', + callbacks: { + title: function(tooltipItem, data) { + return data.datasets[tooltipItem[0].datasetIndex].label; + }, + label: function(tooltipItem, data) { + return data.datasets[tooltipItem.datasetIndex].data[0][1]; + } + } + },'; + } $this->stringtoshow .= '};'; $this->stringtoshow .= ' var ctx = document.getElementById("canvas_' . $tag . '").getContext("2d"); @@ -1265,7 +1277,14 @@ class DolGraph $this->stringtoshow .= 'borderColor: \'' . $bordercolor . '\', '; $this->stringtoshow .= 'backgroundColor: \'' . $color . '\', '; if ($arrayofgroupslegend[$i]) $this->stringtoshow .= 'stack: \'' . $arrayofgroupslegend[$i]['stacknum'] . '\', '; - $this->stringtoshow .= 'data: [' . $serie[$i] . ']'; + $this->stringtoshow .='data: ['; + if($isfunnel){ + $this->stringtoshow .= '['.-$serie[$i].','.$serie[$i].']'; + + }else{ + $this->stringtoshow .= $serie[$i]; + } + $this->stringtoshow .=']'; $this->stringtoshow .= '}' . "\n"; $i++; From 38e03778dcb1498225e207a2fc054b97b0767c7a Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 10 Dec 2020 10:07:09 +0000 Subject: [PATCH 04/25] Fixing style errors. --- htdocs/core/class/dolgraph.class.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 832047b3c65..3c34668ecd2 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -1142,7 +1142,6 @@ class DolGraph $this->stringtoshow .= 'scales: { xAxes: [{ '; if ($isfunnel) { $this->stringtoshow .= ' ticks: { beginAtZero: true}, display: false,'; - } //$this->stringtoshow .= 'type: \'time\', '; // Need Moment.js $this->stringtoshow .= 'distribution: \'linear\''; @@ -1179,12 +1178,12 @@ class DolGraph $i = 0; if (!$isfunnel);{ - foreach ($legends as $val) // Loop on each serie + foreach ($legends as $val) // Loop on each serie { - if ($i > 0) $this->stringtoshow .= ', '; - $this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'"; - $i++; - } + if ($i > 0) $this->stringtoshow .= ', '; + $this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'"; + $i++; + } } //var_dump($arrayofgroupslegend); @@ -1271,17 +1270,16 @@ class DolGraph if ($isfunnel){ $this->stringtoshow .= 'borderWidth: \'2\', '; } - else if ($type == 'bar' || $type == 'horizontalBar') { + elseif ($type == 'bar' || $type == 'horizontalBar') { $this->stringtoshow .= 'borderWidth: \'1\', '; } $this->stringtoshow .= 'borderColor: \'' . $bordercolor . '\', '; $this->stringtoshow .= 'backgroundColor: \'' . $color . '\', '; if ($arrayofgroupslegend[$i]) $this->stringtoshow .= 'stack: \'' . $arrayofgroupslegend[$i]['stacknum'] . '\', '; $this->stringtoshow .='data: ['; - if($isfunnel){ + if ($isfunnel){ $this->stringtoshow .= '['.-$serie[$i].','.$serie[$i].']'; - - }else{ + }else { $this->stringtoshow .= $serie[$i]; } $this->stringtoshow .=']'; From 492715811c454f816f81913683933e7ba0e0f97e Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 10 Dec 2020 10:10:12 +0000 Subject: [PATCH 05/25] Fixing style errors. --- htdocs/core/boxes/box_funnel_of_prospection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/boxes/box_funnel_of_prospection.php b/htdocs/core/boxes/box_funnel_of_prospection.php index fd91b8c317f..6fd2795ccdb 100644 --- a/htdocs/core/boxes/box_funnel_of_prospection.php +++ b/htdocs/core/boxes/box_funnel_of_prospection.php @@ -135,7 +135,7 @@ class box_funnel_of_prospection extends ModeleBoxes } global $conf, $user, $langs; -data + data $this->max = $max; $this->info_box_head = array( From a57b01e9bafa7fb467727a4bced9f587630f9de8 Mon Sep 17 00:00:00 2001 From: Hystepik <45882981+Hystepik@users.noreply.github.com> Date: Thu, 10 Dec 2020 11:12:33 +0100 Subject: [PATCH 06/25] Update box_funnel_of_prospection.php --- htdocs/core/boxes/box_funnel_of_prospection.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/boxes/box_funnel_of_prospection.php b/htdocs/core/boxes/box_funnel_of_prospection.php index 6fd2795ccdb..5669fab7fe5 100644 --- a/htdocs/core/boxes/box_funnel_of_prospection.php +++ b/htdocs/core/boxes/box_funnel_of_prospection.php @@ -135,7 +135,6 @@ class box_funnel_of_prospection extends ModeleBoxes } global $conf, $user, $langs; - data $this->max = $max; $this->info_box_head = array( From 7360fcd03eff59eaa8bb4541ef23f5acf39237c0 Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Thu, 10 Dec 2020 13:11:55 +0100 Subject: [PATCH 07/25] FIX: Bad rigths to send contract --- htdocs/contrat/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index dbdba874dda..368e09d8ccd 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -6,7 +6,7 @@ * Copyright (C) 2010-2017 Juanjo Menent * Copyright (C) 2013 Christophe Battarel * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2014-2018 Ferran Marcet + * Copyright (C) 2014-2020 Ferran Marcet * Copyright (C) 2014-2016 Marcos García * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2018-2020 Frédéric France @@ -2108,7 +2108,7 @@ else // Send if (empty($user->socid)) { if ($object->statut == 1) { - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) { + if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->contrat->creer)) { print ''; } else print ''; From 4f6923442a14da233b0554437d3add737cb155e0 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Thu, 10 Dec 2020 13:19:10 +0100 Subject: [PATCH 08/25] fix merge and sql synthax --- htdocs/core/boxes/box_funnel_of_prospection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/boxes/box_funnel_of_prospection.php b/htdocs/core/boxes/box_funnel_of_prospection.php index 5669fab7fe5..50b61f8de0e 100644 --- a/htdocs/core/boxes/box_funnel_of_prospection.php +++ b/htdocs/core/boxes/box_funnel_of_prospection.php @@ -97,8 +97,8 @@ class box_funnel_of_prospection extends ModeleBoxes $sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_lead_status as cls"; $sql .= " WHERE active=1"; - $sql .= " Order by cls.rowid"; - $sql .= " AND cls.code != 'LOST'"; + $sql .= " AND cls.code <> 'LOST'"; + $sql .= $this->db->order('cls.rowid','ASC'); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -201,7 +201,7 @@ class box_funnel_of_prospection extends ModeleBoxes } $data[] = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0); - + $liststatus[] = $labelStatus; if (!$conf->use_javascript_ajax) { $stringtoprint .= ''; $stringtoprint .= '' . $labelStatus . ''; From 0a2f6561377697b1ecf1a0f5f54589de5e9e1aa1 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 10 Dec 2020 12:19:43 +0000 Subject: [PATCH 09/25] Fixing style errors. --- htdocs/core/boxes/box_funnel_of_prospection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/boxes/box_funnel_of_prospection.php b/htdocs/core/boxes/box_funnel_of_prospection.php index 50b61f8de0e..44b2bd9a90d 100644 --- a/htdocs/core/boxes/box_funnel_of_prospection.php +++ b/htdocs/core/boxes/box_funnel_of_prospection.php @@ -98,7 +98,7 @@ class box_funnel_of_prospection extends ModeleBoxes $sql .= " FROM " . MAIN_DB_PREFIX . "c_lead_status as cls"; $sql .= " WHERE active=1"; $sql .= " AND cls.code <> 'LOST'"; - $sql .= $this->db->order('cls.rowid','ASC'); + $sql .= $this->db->order('cls.rowid', 'ASC'); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); From 2a2b372ba9cefc09fcd21a29ea4784fc16c60b28 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 10 Dec 2020 15:08:36 +0100 Subject: [PATCH 10/25] fix: manage price min for PRICE PER CUSTOMER --- htdocs/comm/propal/card.php | 1 + htdocs/commande/card.php | 1 + 2 files changed, 2 insertions(+) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index db64dd65fe9..12146179db0 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -911,6 +911,7 @@ if (empty($reshook)) if (count($prodcustprice->lines) > 0) { $pu_ht = price($prodcustprice->lines[0]->price); $pu_ttc = price($prodcustprice->lines[0]->price_ttc); + $price_min = price($prodcustprice->lines[0]->price_min); $price_base_type = $prodcustprice->lines[0]->price_base_type; $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx); if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 80ff2180801..e72ddbf8818 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -749,6 +749,7 @@ if (empty($reshook)) { $pu_ht = price($prodcustprice->lines[0]->price); $pu_ttc = price($prodcustprice->lines[0]->price_ttc); + $price_min = price($prodcustprice->lines[0]->price_min); $price_base_type = $prodcustprice->lines[0]->price_base_type; $tva_tx = $prodcustprice->lines[0]->tva_tx; if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; From 716bb433e8e576edd730f379176b7342eab7a1e5 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Thu, 10 Dec 2020 15:50:18 +0100 Subject: [PATCH 11/25] ajout pictogramme graph dans info box head --- htdocs/core/boxes/box_funnel_of_prospection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/boxes/box_funnel_of_prospection.php b/htdocs/core/boxes/box_funnel_of_prospection.php index 44b2bd9a90d..e75e8959a03 100644 --- a/htdocs/core/boxes/box_funnel_of_prospection.php +++ b/htdocs/core/boxes/box_funnel_of_prospection.php @@ -139,7 +139,7 @@ class box_funnel_of_prospection extends ModeleBoxes $this->info_box_head = array( 'text' => $langs->trans("Statistics") . ' - ' . $langs->trans("OpportunitiesStatusForOpenedProjects"), - $max + 'graph' => '1' ); if ($user->rights->projet->lire || !empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { @@ -224,7 +224,7 @@ class box_funnel_of_prospection extends ModeleBoxes $dolgraph->SetType(array('horizontalbars')); $dolgraph->SetHeight('200'); $dolgraph->SetWidth('600'); - $dolgraph->mode='depth'; + $dolgraph->mode = 'depth'; $dolgraph->draw('idgraphstatus'); $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1); } From dca48e4fb67654ac7923963360ccf47c92c71ef8 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 11 Dec 2020 10:21:10 +0100 Subject: [PATCH 12/25] NEW : add ECM files table info into API document entry GET --- htdocs/api/class/api_documents.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 92404b81a35..da9545aa248 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -497,6 +497,17 @@ class Documents extends DolibarrApi $filearray = dol_dir_list($upload_dir, $type, $recursive, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); if (empty($filearray)) { throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(!empty($object->ref) ? ' or Ref '.$object->ref : '').' does not return any document.'); + } else { + if (($object->id) > 0 && !empty($modulepart)) { + require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmfiles.class.php'; + $ecmfile = new EcmFiles($this->db); + $result = $ecmfile->fetchAll('', '', 0, 0, array('t.src_object_type' => $modulepart, 't.src_object_id' => $object->id)); + if ($result < 0) { + throw new RestException(503, 'Error when retrieve ecm list : ' . $this->db->lasterror()); + } elseif (is_array($ecmfile->lines) && count($ecmfile->lines) > 0) { + $filearray['ecmfiles_infos'] = $ecmfile->lines; + } + } } return $filearray; From eb2d7fa657968379d2f3daae0787aa89dc823170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 11 Dec 2020 13:43:03 +0100 Subject: [PATCH 13/25] fix phpcs --- htdocs/core/class/html.form.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 24b3a5c2bbf..8a928aeeb34 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5930,24 +5930,24 @@ class Form * * @param string $prefix Prefix * @param string $selected Selected duration type - * @param array|null $ecludetypes Array of duration types to exclude. Example array('y', 'm') + * @param array|null $excludetypes Array of duration types to exclude. Example array('y', 'm') * @return string HTML select string */ - public function selectTypeDuration($prefix, $selected = 'i', $excludtypes = null) + public function selectTypeDuration($prefix, $selected = 'i', $excludetypes = null) { global $langs; $TDurationTypes = array('y'=>$langs->trans('Years'), 'm'=>$langs->trans('Month'), 'w'=>$langs->trans('Weeks'), 'd'=>$langs->trans('Days'), 'h'=>$langs->trans('Hours'), 'i'=>$langs->trans('Minutes')); // Removed undesired duration types - if (is_array($excludtypes)) { - foreach($excludtypes as $value) { + if (is_array($excludetypes)) { + foreach($excludetypes as $value) { unset($TDurationTypes[$value]); } } $retstring = ''; From 2adbd29b498e6a7d83180df7a2d1c6048c848d05 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 11 Dec 2020 14:22:36 +0100 Subject: [PATCH 15/25] Debug generation of doc from modulebuilder --- htdocs/admin/supplier_invoice.php | 3 +- htdocs/core/actions_addupdatedelete.inc.php | 8 +- htdocs/core/class/commonobject.class.php | 5 ++ htdocs/langs/en_US/admin.lang | 2 +- htdocs/modulebuilder/template/admin/setup.php | 87 ++++++++++--------- .../template/class/myobject.class.php | 4 +- htdocs/recruitment/admin/setup.php | 85 +++++++++--------- .../recruitment/admin/setup_candidatures.php | 60 +++++++------ .../class/recruitmentcandidature.class.php | 2 +- .../class/recruitmentjobposition.class.php | 5 +- ...ric_recruitmentjobposition_odt.modules.php | 2 +- 11 files changed, 146 insertions(+), 117 deletions(-) diff --git a/htdocs/admin/supplier_invoice.php b/htdocs/admin/supplier_invoice.php index 8df357df07e..86faa655687 100644 --- a/htdocs/admin/supplier_invoice.php +++ b/htdocs/admin/supplier_invoice.php @@ -146,8 +146,7 @@ elseif ($action == 'setdoc') { $ret = addDocumentModel($value, $type, $label, $scandir); } -} elseif ($action == 'unsetdoc') -{ +} elseif ($action == 'unsetdoc') { dolibarr_del_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $conf->entity); } diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 80f16cb037d..5a93a6ded0b 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -315,11 +315,15 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - $model = $object->model_pdf; $ret = $object->fetch($id); // Reload to get new records - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + $model = $object->model_pdf; + + $retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($retgen < 0) { + setEventMessages($object->error, $object->errors, 'warnings'); + } } } } else { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index ef1bd4eb7b7..dec15e4db83 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4557,6 +4557,11 @@ abstract class CommonObject { dol_syslog("commonGenerateDocument modele=".$modele." outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null')); + if (empty($modele)) { + $this->error = 'BadValueForParameterModele'; + return -1; + } + // Increase limit for PDF build $err = error_reporting(); error_reporting(0); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 23b3b5462c9..b0a302fb80e 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -375,7 +375,7 @@ ExamplesWithCurrentSetup=Examples with current configuration ListOfDirectories=List of OpenDocument templates directories ListOfDirectoriesForModelGenODT=List of directories containing templates files with OpenDocument format.

Put here full path of directories.
Add a carriage return between eah directory.
To add a directory of the GED module, add here DOL_DATA_ROOT/ecm/yourdirectoryname.

Files in those directories must end with .odt or .ods. NumberOfModelFilesFound=Number of ODT/ODS template files found in these directories -ExampleOfDirectoriesForModelGen=Examples of syntax:
c:\\mydir
/home/mydir
DOL_DATA_ROOT/ecm/ecmdir +ExampleOfDirectoriesForModelGen=Examples of syntax:
c:\\myapp\\mydocumentdir\\mysubdir
/home/myapp/mydocumentdir/mysubdir
DOL_DATA_ROOT/ecm/ecmdir FollowingSubstitutionKeysCanBeUsed=
To know how to create your odt document templates, before storing them in those directories, read wiki documentation: FullListOnOnlineDocumentation=http://wiki.dolibarr.org/index.php/Create_an_ODT_document_template FirstnameNamePosition=Position of Name/Lastname diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index 420eb13940d..c7cc61171a7 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -54,6 +54,9 @@ $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); $value = GETPOST('value', 'alpha'); +$label = GETPOST('label', 'alpha'); +$scandir = GETPOST('scan_dir', 'alpha'); +$type = 'myobject'; $arrayofparameters = array( 'MYMODULE_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1), @@ -130,47 +133,52 @@ if ($action == 'updateMask') } } -// Activate a model -elseif ($action == 'set') -{ - $ret = addDocumentModel($value, $type, $label, $scandir); -} elseif ($action == 'del') -{ +elseif ($action == 'setmod') { + // TODO Check if numbering module chosen can be activated by calling method canBeActivated $tmpobjectkey = GETPOST('object'); - - $ret = delDocumentModel($value, $type); - if ($ret > 0) - { - $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF'; - if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity); + if (!empty($tmpobjectkey)) { + $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey)."_ADDON"; + dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity); } } -// Set default model -elseif ($action == 'setdoc') -{ - $tmpobjectkey = GETPOST('object'); - $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF'; - if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) - { - // The constant that was read before the new set - // We therefore requires a variable to have a coherent view - $conf->global->$constforval = $value; - } - - // On active le modele +// Activate a model +elseif ($action == 'set') { + $ret = addDocumentModel($value, $type, $label, $scandir); +} elseif ($action == 'del') { $ret = delDocumentModel($value, $type); - if ($ret > 0) - { - $ret = addDocumentModel($value, $type, $label, $scandir); + if ($ret > 0) { + $tmpobjectkey = GETPOST('object'); + if (!empty($tmpobjectkey)) { + $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity); + } } -} elseif ($action == 'setmod') -{ - // TODO Check if numbering module chosen can be activated - // by calling method canBeActivated +} + +// Set or unset default model +elseif ($action == 'setdoc') { $tmpobjectkey = GETPOST('object'); - $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey)."_ADDON"; - dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity); + if (!empty($tmpobjectkey)) { + $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) { + // The constant that was read before the new set + // We therefore requires a variable to have a coherent view + $conf->global->$constforval = $value; + } + + // We disable/enable the document template (into llx_document_model table) + $ret = delDocumentModel($value, $type); + if ($ret > 0) { + $ret = addDocumentModel($value, $type, $label, $scandir); + } + } +} elseif ($action == 'unsetdoc') { + $tmpobjectkey = GETPOST('object'); + if (!empty($tmpobjectkey)) { + $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + dolibarr_del_const($db, $constforval, $conf->entity); + } } @@ -459,18 +467,19 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { print ''; } else { print ''."\n"; - print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').''; + print 'scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').''; print ""; } // Default print ''; $constforvar = 'MYMODULE_'.strtoupper($myTmpObjectKey).'_ADDON'; - if ($conf->global->$constforvar == $name) - { - print img_picto($langs->trans("Default"), 'on'); + if ($conf->global->$constforvar == $name) { + //print img_picto($langs->trans("Default"), 'on'); + // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset + print 'scandir.'&label='.urlencode($module->name).'&type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').''; } else { - print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').''; + print 'scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').''; } print ''; diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 76aeabf2c2b..a8bed45c46a 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -1028,7 +1028,7 @@ class MyObject extends CommonObject if (!dol_strlen($modele)) { $modele = 'standard_myobject'; - if ($this->model_pdf) { + if (!empty($this->model_pdf)) { $modele = $this->model_pdf; } elseif (!empty($conf->global->MYOBJECT_ADDON_PDF)) { $modele = $conf->global->MYOBJECT_ADDON_PDF; @@ -1037,7 +1037,7 @@ class MyObject extends CommonObject $modelpath = "core/modules/mymodule/doc/"; - if ($includedocgeneration) { + if ($includedocgeneration && !empty($modele)) { $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); } diff --git a/htdocs/recruitment/admin/setup.php b/htdocs/recruitment/admin/setup.php index fdd4d83e223..342d32840c5 100644 --- a/htdocs/recruitment/admin/setup.php +++ b/htdocs/recruitment/admin/setup.php @@ -54,6 +54,9 @@ $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); $value = GETPOST('value', 'alpha'); +$label = GETPOST('label', 'alpha'); +$scandir = GETPOST('scan_dir', 'alpha'); +$type = 'recruitmentjobposition'; $arrayofparameters = array( // 'RECRUITMENT_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1), @@ -131,47 +134,52 @@ if ($action == 'updateMask') } // Activate a model -elseif ($action == 'set') -{ +elseif ($action == 'set') { $ret = addDocumentModel($value, $type, $label, $scandir); -} elseif ($action == 'del') -{ - $tmpobjectkey = GETPOST('object'); - +} elseif ($action == 'del') { $ret = delDocumentModel($value, $type); - if ($ret > 0) - { - $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF'; - if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity); + if ($ret > 0) { + $tmpobjectkey = GETPOST('object'); + if (!empty($tmpobjectkey)) { + $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity); + } + } +} + +elseif ($action == 'setmod') { + // TODO Check if numbering module chosen can be activated by calling method canBeActivated + $tmpobjectkey = GETPOST('object'); + if (!empty($tmpobjectkey)) { + $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON"; + + dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity); } } // Set default model -elseif ($action == 'setdoc') -{ +elseif ($action == 'setdoc') { $tmpobjectkey = GETPOST('object'); - $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF'; - if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) - { - // The constant that was read before the new set - // We therefore requires a variable to have a coherent view - $conf->global->$constforval = $value; - } + if (!empty($tmpobjectkey)) { + $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) { + // The constant that was read before the new set + // We therefore requires a variable to have a coherent view + $conf->global->$constforval = $value; + } - // On active le modele - $ret = delDocumentModel($value, $type); - if ($ret > 0) - { - $ret = addDocumentModel($value, $type, $label, $scandir); + // We disable/enable the document template (into llx_document_model table) + $ret = delDocumentModel($value, $type); + if ($ret > 0) { + $ret = addDocumentModel($value, $type, $label, $scandir); + } } -} elseif ($action == 'setmod') -{ - // TODO Check if numbering module chosen can be activated - // by calling method canBeActivated +} elseif ($action == 'unsetdoc') { $tmpobjectkey = GETPOST('object'); - $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON"; - - dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity); + if (!empty($tmpobjectkey)) { + $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + dolibarr_del_const($db, $constforval, $conf->entity); + } } @@ -288,7 +296,6 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') { $file = substr($file, 0, dol_strlen($file) - 4); - require_once $dir.'/'.$file.'.php'; $module = new $file($db); @@ -377,8 +384,7 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { $sql .= " WHERE type = '".$db->escape($type)."'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $i = 0; $num_rows = $db->num_rows($resql); while ($i < $num_rows) @@ -464,12 +470,13 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { // Default print ''; - $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON'; - if ($conf->global->$constforvar == $name) - { - print img_picto($langs->trans("Default"), 'on'); + $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON_PDF'; + if ($conf->global->$constforvar == $name) { + //print img_picto($langs->trans("Default"), 'on'); + // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset + print 'scandir.'&label='.urlencode($module->name).'&type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').''; } else { - print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').''; + print 'scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').''; } print ''; diff --git a/htdocs/recruitment/admin/setup_candidatures.php b/htdocs/recruitment/admin/setup_candidatures.php index ef4454974e7..818e1479f0a 100644 --- a/htdocs/recruitment/admin/setup_candidatures.php +++ b/htdocs/recruitment/admin/setup_candidatures.php @@ -54,6 +54,9 @@ $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); $value = GETPOST('value', 'alpha'); +$label = GETPOST('label', 'alpha'); +$scandir = GETPOST('scan_dir', 'alpha'); +$type = 'recruitmentcandidature'; $arrayofparameters = array( // 'RECRUITMENT_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1), @@ -131,47 +134,49 @@ if ($action == 'updateMask') } // Activate a model -elseif ($action == 'set') -{ +elseif ($action == 'set') { $ret = addDocumentModel($value, $type, $label, $scandir); -} elseif ($action == 'del') -{ +} elseif ($action == 'del') { $tmpobjectkey = GETPOST('object'); $ret = delDocumentModel($value, $type); - if ($ret > 0) - { - $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF'; + if ($ret > 0) { + $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity); } } -// Set default model -elseif ($action == 'setdoc') -{ +elseif ($action == 'setmod') { + // TODO Check if numbering module chosen can be activated by calling method canBeActivated $tmpobjectkey = GETPOST('object'); - $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF'; - if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) - { + if (!empty($tmpobjectkey)) { + $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON"; + + dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity); + } +} + +// Set default model +elseif ($action == 'setdoc') { + $tmpobjectkey = GETPOST('object'); + $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) { // The constant that was read before the new set // We therefore requires a variable to have a coherent view $conf->global->$constforval = $value; } - // On active le modele + // We disable/enable the document template (into llx_document_model table) $ret = delDocumentModel($value, $type); - if ($ret > 0) - { + if ($ret > 0) { $ret = addDocumentModel($value, $type, $label, $scandir); } -} elseif ($action == 'setmod') -{ - // TODO Check if numbering module chosen can be activated - // by calling method canBeActivated +} elseif ($action == 'unsetdoc') { $tmpobjectkey = GETPOST('object'); - $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON"; - - dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity); + if (!empty($tmpobjectkey)) { + $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + dolibarr_del_const($db, $constforval, $conf->entity); + } } @@ -465,11 +470,12 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) { // Default print ''; $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON'; - if ($conf->global->$constforvar == $name) - { - print img_picto($langs->trans("Default"), 'on'); + if ($conf->global->$constforvar == $name) { + //print img_picto($langs->trans("Default"), 'on'); + // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset + print 'scandir.'&label='.urlencode($module->name).'&type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').''; } else { - print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').''; + print 'scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').''; } print ''; diff --git a/htdocs/recruitment/class/recruitmentcandidature.class.php b/htdocs/recruitment/class/recruitmentcandidature.class.php index 5dad53212c6..3049f83a053 100644 --- a/htdocs/recruitment/class/recruitmentcandidature.class.php +++ b/htdocs/recruitment/class/recruitmentcandidature.class.php @@ -982,7 +982,7 @@ class RecruitmentCandidature extends CommonObject $modelpath = "core/modules/recruitment/doc/"; - if ($includedocgeneration) { + if ($includedocgeneration && !empty($modele)) { $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); } diff --git a/htdocs/recruitment/class/recruitmentjobposition.class.php b/htdocs/recruitment/class/recruitmentjobposition.class.php index 2421f87ce50..c202a523e58 100644 --- a/htdocs/recruitment/class/recruitmentjobposition.class.php +++ b/htdocs/recruitment/class/recruitmentjobposition.class.php @@ -1059,8 +1059,7 @@ class RecruitmentJobPosition extends CommonObject $langs->load("recruitment"); if (!dol_strlen($modele)) { - if (!empty($conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF)) - { + if (!empty($conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF)) { $modele = $conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF; } else { $modele = ''; // No default value. For job position, we allow to disable all PDF generation @@ -1069,7 +1068,7 @@ class RecruitmentJobPosition extends CommonObject $modelpath = "core/modules/recruitment/doc/"; - if ($includedocgeneration) { + if ($includedocgeneration && !empty($modele)) { $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); } diff --git a/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php b/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php index be36b96682c..59ea51466b6 100644 --- a/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php +++ b/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php @@ -181,7 +181,7 @@ class doc_generic_recruitmentjobposition_odt extends ModelePDFRecruitmentJobPosi $texte .= ''; $texte .= ''; - $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); + $texte .= ''.$langs->trans("ExampleOfDirectoriesForModelGen").''; $texte .= ''; $texte .= ''; From f4b299e530f37d2368b26642a303338c333e63d9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 11 Dec 2020 14:35:13 +0100 Subject: [PATCH 16/25] Fix generation of PDF --- .../doc/pdf_standard_recruitmentjobposition.modules.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php b/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php index cad6888f7c5..5f257f594cf 100644 --- a/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php +++ b/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php @@ -825,7 +825,7 @@ class pdf_standard_recruitmentjobposition extends ModelePDFRecruitmentJobPositio pdf_pagehead($pdf, $outputlangs, $this->page_hauteur); // Show Draft Watermark - if ($object->statut == Facture::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) + if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) { pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK); } @@ -885,7 +885,7 @@ class pdf_standard_recruitmentjobposition extends ModelePDFRecruitmentJobPositio $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref); - if ($object->statut == Facture::STATUS_DRAFT) + if ($object->statut == $object::STATUS_DRAFT) { $pdf->SetTextColor(128, 0, 0); $textref .= ' - '.$outputlangs->transnoentities("NotValidated"); From 4fcd3fe49332baab0e424225ad10b76b47ebcbac Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 11 Dec 2020 15:11:51 +0100 Subject: [PATCH 17/25] =?UTF-8?q?Fix=20disallow=20--=20string=20into=20fil?= =?UTF-8?q?ename=20for=20security=20purpose.=20Vulnerability=20reported=20?= =?UTF-8?q?by=20Y=C4=B1lmaz=20De=C4=9Firmenci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/admin/tools/export_files.php | 2 +- htdocs/core/lib/functions.lib.php | 5 +++-- test/phpunit/SecurityTest.php | 25 ++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/htdocs/admin/tools/export_files.php b/htdocs/admin/tools/export_files.php index de10759c92d..587750d129e 100644 --- a/htdocs/admin/tools/export_files.php +++ b/htdocs/admin/tools/export_files.php @@ -34,7 +34,7 @@ $action = GETPOST('action', 'alpha'); $what = GETPOST('what', 'alpha'); $export_type = GETPOST('export_type', 'alpha'); $file = trim(GETPOST('zipfilename_template', 'alpha')); -$compression = GETPOST('compression'); +$compression = GETPOST('compression', 'aZ09'); $file = dol_sanitizeFileName($file); $file = preg_replace('/(\.zip|\.tar|\.tgz|\.gz|\.tar\.gz|\.bz2)$/i', '', $file); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 5094fad392a..37791d1e72d 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -866,8 +866,9 @@ function dol_sanitizeFileName($str, $newstr = '_', $unaccent = 1) // List of special chars for filenames in windows are defined on page https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file // Char '>' '<' '|' '$' and ';' are special chars for shells. // Char '/' and '\' are file delimiters. - $filesystem_forbidden_chars = array('<', '>', '/', '\\', '?', '*', '|', '"', ':', '°', '$', ';'); - return dol_string_nospecial($unaccent ?dol_string_unaccent($str) : $str, $newstr, $filesystem_forbidden_chars); + // -- car can be used into filename to inject special paramaters like --use-compress-program to make command with file as parameter making remote execution of command + $filesystem_forbidden_chars = array('<', '>', '/', '\\', '?', '*', '|', '"', ':', '°', '$', ';', '--'); + return dol_string_nospecial($unaccent ? dol_string_unaccent($str) : $str, $newstr, $filesystem_forbidden_chars); } /** diff --git a/test/phpunit/SecurityTest.php b/test/phpunit/SecurityTest.php index 5a248006498..6d2a3cf3cd8 100644 --- a/test/phpunit/SecurityTest.php +++ b/test/phpunit/SecurityTest.php @@ -244,7 +244,7 @@ class SecurityTest extends PHPUnit\Framework\TestCase $login=checkLoginPassEntity('admin', 'admin', 1, array('dolibarr')); // Should works because admin/admin exists print __METHOD__." login=".$login."\n"; - $this->assertEquals($login, 'admin'); + $this->assertEquals($login, 'admin', 'The test to check if pass of user "admin" is "admin" has failed'); $login=checkLoginPassEntity('admin', 'admin', 1, array('http','dolibarr')); // Should work because of second authetntication method print __METHOD__." login=".$login."\n"; @@ -326,4 +326,27 @@ class SecurityTest extends PHPUnit\Framework\TestCase $result=restrictedArea($user, 'societe'); $this->assertEquals(1, $result); } + + /** + * testDolSanitizeFileName + * + * @return void + */ + public function testDolSanitizeFileName() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + //$dummyuser=new User($db); + //$result=restrictedArea($dummyuser,'societe'); + + $result=dol_sanitizeFileName('bad file | evilaction'); + $this->assertEquals('bad file _ evilaction', $result); + + $result=dol_sanitizeFileName('bad file --evilparam'); + $this->assertEquals('bad file _evilparam', $result); + } } From 8a0c06516336fbe5c45e80e233a437d5f23369f6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 11 Dec 2020 16:30:45 +0100 Subject: [PATCH 18/25] Debug v13 --- htdocs/core/class/html.form.class.php | 4 ++-- htdocs/core/lib/ajax.lib.php | 2 +- htdocs/product/class/product.class.php | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e1e1fc45228..b487d3f3043 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6197,6 +6197,7 @@ class Form $tmpfieldstoshow = ''; foreach ($objecttmp->fields as $key => $val) { + if (!dol_eval($val['enabled'], 1, 1)) continue; if ($val['showoncombobox']) $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '').'t.'.$key; } if ($tmpfieldstoshow) $fieldstoshow = $tmpfieldstoshow; @@ -6294,8 +6295,7 @@ class Form } if (empty($outputmode)) { - if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) - { + if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) { $out .= ''; } else { $out .= ''; diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 5bcf73ca896..d1c1540cb8a 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -34,7 +34,7 @@ * @param string $url Ajax Url to call for request: /path/page.php. Must return a json array ('key'=>id, 'value'=>String shown into input field once selected, 'label'=>String shown into combo list) * @param string $urloption More parameters on URL request * @param int $minLength Minimum number of chars to trigger that Ajax search - * @param int $autoselect Automatic selection if just one value + * @param int $autoselect Automatic selection if just one value (trigger("change") on field is done is search return only 1 result) * @param array $ajaxoptions Multiple options array * - Ex: array('update'=>array('field1','field2'...)) will reset field1 and field2 once select done * - Ex: array('disabled'=> ) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 6505741d5a2..bcf32cdce26 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -413,6 +413,7 @@ class Product extends CommonObject public $fields = array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), 'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), + 'barcode' =>array('type'=>'varchar(255)', 'label'=>'Barcode', 'enabled'=>'!empty($conf->barcode->enabled)', 'visible'=>-1, 'showoncombobox'=>1), 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20), 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1), 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61), From 4fa1248d15d12818b414ffc0cdb3ccd4c2c01390 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 11 Dec 2020 16:53:03 +0100 Subject: [PATCH 19/25] Fix avoid duplicate rows after double migration --- htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index 1d8c7a37b95..6c3c6e04acb 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -546,9 +546,9 @@ CREATE TABLE llx_session( )ENGINE=innodb; - -INSERT INTO llx_boxes_def(file,entity) VALUES ('box_funnel_of_prospection.php',1); - -INSERT INTO llx_boxes_def(file, entity) VALUES ('box_customers_outstanding_bill_reached.php', 1); +-- VMYSQL4.1 INSERT INTO llx_boxes_def (file, entity) SELECT 'box_funnel_of_prospection.php', 1 FROM DUAL WHERE NOT EXISTS (SELECT * FROM llx_boxes_def WHERE file = 'box_funnel_of_prospection.php' AND entity = 1); +-- VMYSQL4.1 INSERT INTO llx_boxes_def (file, entity) SELECT 'box_customers_outstanding_bill_reached.php', 1 FROM DUAL WHERE NOT EXISTS (SELECT * FROM llx_boxes_def WHERE file = 'box_customers_outstanding_bill_reached.php' AND entity = 1); +--INSERT INTO llx_boxes_def(file, entity) VALUES ('box_funnel_of_prospection.php',1); +--INSERT INTO llx_boxes_def(file, entity) VALUES ('box_customers_outstanding_bill_reached.php', 1); ALTER TABLE llx_product_fournisseur_price ADD COLUMN packaging varchar(64); \ No newline at end of file From 18efbebd02b2411579a74c3b7cecad264b4961d7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 11 Dec 2020 17:11:50 +0100 Subject: [PATCH 20/25] css --- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/class/html.formother.class.php | 11 ++++++----- htdocs/core/customreports.php | 2 +- htdocs/langs/en_US/boxes.lang | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 7851b40543a..fdcdc89e53e 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6772,7 +6772,7 @@ class Form { $out .= ' selected'; } - $out .= ' data-html="'.$newval.'"'; + $out .= ' data-html="'.dol_escape_htmltag($newval).'"'; $out .= '>'; $out .= dol_htmlentitiesbr($newval); $out .= ''."\n"; diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 2973eda7144..c71029769f2 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -1371,9 +1371,10 @@ class FormOther * @param mixed $object Object analyzed * @param array $search_groupby Array of preselected fields * @param array $arrayofgroupby Array of groupby to fill + * @param string $morecss More CSS * @return string HTML string component */ - public function selectGroupByField($object, $search_groupby, &$arrayofgroupby) + public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250') { global $langs, $extrafields, $form; @@ -1395,9 +1396,9 @@ class FormOther if (preg_match('/^pass/', $key)) continue; if (in_array($val['type'], array('html', 'text'))) continue; if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) { - $arrayofgroupby['t.'.$key.'-year'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.')', 'position' => $val['position'].'-y'); - $arrayofgroupby['t.'.$key.'-month'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.')', 'position' => $val['position'].'-m'); - $arrayofgroupby['t.'.$key.'-day'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.'-'.$DD.')', 'position' => $val['position'].'-d'); + $arrayofgroupby['t.'.$key.'-year'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.')', 'position' => $val['position'].'-y'); + $arrayofgroupby['t.'.$key.'-month'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.')', 'position' => $val['position'].'-m'); + $arrayofgroupby['t.'.$key.'-day'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.'-'.$DD.')', 'position' => $val['position'].'-d'); } else { $arrayofgroupby['t.'.$key] = array('label' => $langs->trans($val['label']), 'position' => (int) $val['position']); } @@ -1417,7 +1418,7 @@ class FormOther foreach ($arrayofgroupby as $key => $val) { $arrayofgroupbylabel[$key] = $val['label']; } - $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, 1, 0, 0, '', 0, 0, 0, '', 'minwidth250', 1); + $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, 1, 0, 0, '', 0, 0, 0, '', $morecss, 1); return $result; } diff --git a/htdocs/core/customreports.php b/htdocs/core/customreports.php index 0a7f4ce9826..901a0aa0f59 100644 --- a/htdocs/core/customreports.php +++ b/htdocs/core/customreports.php @@ -377,7 +377,7 @@ if ($object->isextrafieldmanaged) { } } print '
'.$langs->trans("Measures").'
'; -print $form->multiselectarray('search_measures', $arrayofmesures, $search_measures, 0, 0, 'minwidth500', 1); +print $form->multiselectarray('search_measures', $arrayofmesures, $search_measures, 0, 0, 'minwidth400', 1); print '
'; diff --git a/htdocs/langs/en_US/boxes.lang b/htdocs/langs/en_US/boxes.lang index 1e91080962e..11a22879367 100644 --- a/htdocs/langs/en_US/boxes.lang +++ b/htdocs/langs/en_US/boxes.lang @@ -50,7 +50,7 @@ BoxTitleLastOutstandingBillReached=Customers with maximum outstanding exceeded BoxGlobalActivity=Global activity (invoices, proposals, orders) BoxGoodCustomers=Good customers BoxTitleGoodCustomers=%s Good customers -BoxTitleFunnelOfProspection=Amount of prospection by status +BoxTitleFunnelOfProspection=Lead funnel FailedToRefreshDataInfoNotUpToDate=Failed to refresh RSS flux. Latest successful refresh date: %s LastRefreshDate=Latest refresh date NoRecordedBookmarks=No bookmarks defined. From 9100e1410e72da2f15aaf051e4207b6dfcedcaf0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 11 Dec 2020 17:57:57 +0100 Subject: [PATCH 21/25] Fix translation, add comments and clean code, fix also a small regression on colors for graph with lines --- .../core/boxes/box_funnel_of_prospection.php | 6 +- htdocs/core/class/dolgraph.class.php | 76 +++++++++++-------- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/htdocs/core/boxes/box_funnel_of_prospection.php b/htdocs/core/boxes/box_funnel_of_prospection.php index e75e8959a03..a50426e1b29 100644 --- a/htdocs/core/boxes/box_funnel_of_prospection.php +++ b/htdocs/core/boxes/box_funnel_of_prospection.php @@ -138,7 +138,7 @@ class box_funnel_of_prospection extends ModeleBoxes $this->max = $max; $this->info_box_head = array( - 'text' => $langs->trans("Statistics") . ' - ' . $langs->trans("OpportunitiesStatusForOpenedProjects"), + 'text' => $langs->trans("Statistics") . ' - ' . $langs->trans("BoxTitleFunnelOfProspection"), 'graph' => '1' ); @@ -220,12 +220,12 @@ class box_funnel_of_prospection extends ModeleBoxes $dolgraph->SetDataColor(array_values($colorseriesstat)); $dolgraph->setShowLegend(2); $dolgraph->setShowPercent(1); - $dolgraph->setTitle('FunnelOfProspection'); + $dolgraph->setTitle(''); $dolgraph->SetType(array('horizontalbars')); $dolgraph->SetHeight('200'); $dolgraph->SetWidth('600'); $dolgraph->mode = 'depth'; - $dolgraph->draw('idgraphstatus'); + $dolgraph->draw('idgraphleadfunnel'); $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1); } $stringtoprint .= ''; diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 3c34668ecd2..bd350e40991 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -1000,7 +1000,7 @@ class DolGraph $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); $this->stringtoshow = '' . "\n"; - if (!empty($this->title)&&$this->title!='FunnelOfProspection') $this->stringtoshow .= '
' . $this->title . '
'; + if (!empty($this->title)) $this->stringtoshow .= '
' . $this->title . '
'; if (!empty($this->shownographyet)) { $this->stringtoshow .= '
'; $this->stringtoshow .= '
' . $langs->trans("NotEnoughDataYet") . '...
'; @@ -1129,10 +1129,12 @@ class DolGraph // Other cases, graph of type 'bars', 'lines', 'linesnopoint' else { $type = 'bar'; + $isfunnel = false; + if ($file == 'idgraphleadfunnel') $isfunnel = true; + if (!isset($this->type[$firstlot]) || $this->type[$firstlot] == 'bars') $type = 'bar'; if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'horizontalbars') $type = 'horizontalBar'; - if ($this->title == 'FunnelOfProspection') $isfunnel = true; if (isset($this->type[$firstlot]) && ($this->type[$firstlot] == 'lines' || $this->type[$firstlot] == 'linesnopoint')) $type = 'line'; $this->stringtoshow .= 'var options = { maintainAspectRatio: false, aspectRatio: 2.5, '; @@ -1140,8 +1142,8 @@ class DolGraph $this->stringtoshow .= 'legend: { display: false }, '; } $this->stringtoshow .= 'scales: { xAxes: [{ '; - if ($isfunnel) { - $this->stringtoshow .= ' ticks: { beginAtZero: true}, display: false,'; + if ($isfunnel) { // FIXME Remove isfunnel by introducing a method hideXValues() on dolgraph + $this->stringtoshow .= ' ticks: { display: false }, display: true,'; } //$this->stringtoshow .= 'type: \'time\', '; // Need Moment.js $this->stringtoshow .= 'distribution: \'linear\''; @@ -1153,8 +1155,9 @@ class DolGraph $this->stringtoshow .= ', yAxes: [{ stacked: true }]'; } $this->stringtoshow .= ' }'; + // Add a callback to change label to show only positive value if ($isfunnel) { - $this->stringtoshow .= ', tooltips: {mode: \'nearest\', + $this->stringtoshow .= ', tooltips: { mode: \'nearest\', callbacks: { title: function(tooltipItem, data) { return data.datasets[tooltipItem[0].datasetIndex].label; @@ -1177,13 +1180,13 @@ class DolGraph labels: ['; $i = 0; - if (!$isfunnel);{ - foreach ($legends as $val) // Loop on each serie - { - if ($i > 0) $this->stringtoshow .= ', '; - $this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'"; - $i++; - } + if (!$isfunnel) { + foreach ($legends as $val) // Loop on each serie + { + if ($i > 0) $this->stringtoshow .= ', '; + $this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'"; + $i++; + } } //var_dump($arrayofgroupslegend); @@ -1238,25 +1241,33 @@ class DolGraph $color = 'rgb(' . $newcolor[0] . ', ' . $newcolor[1] . ', ' . $newcolor[2] . ', 0.9)'; $bordercolor = 'rgb(' . $newcolor[0] . ', ' . $newcolor[1] . ', ' . $newcolor[2] . ')'; } else { // We do not use a 'group by' - if (is_array($this->datacolor[$i])) $color = 'rgb(' . $this->datacolor[$i][0] . ', ' . $this->datacolor[$i][1] . ', ' . $this->datacolor[$i][2] . ')'; // If datacolor is array(R, G, B) - else { - $tmp = str_replace('#', '', $this->datacolor[$i]); - if (strpos($tmp, '-') !== false) { - $foundnegativecolor++; - $color = '#FFFFFF'; // If $val is '-123' + if ($isfunnel) { + if (is_array($this->datacolor[$i])) { + $color = 'rgb(' . $this->datacolor[$i][0] . ', ' . $this->datacolor[$i][1] . ', ' . $this->datacolor[$i][2] . ', 0.9)'; // If datacolor is array(R, G, B) } else { - $color = "#" . $tmp; // If $val is '123' or '#123' - $bordercolor = $color; - } - if ($foundnegativecolor) { - if (is_array($this->datacolor[$i])) $color = 'null'; // If datacolor is array(R, G, B) - else { - $tmp = str_replace('#', '', $this->datacolor[$i]); - if (strpos($tmp, '-') !== false) $bordercolor = '#' . str_replace('-', '', $tmp); // If $val is '-123' - else $bordercolor = 'null'; // If $val is '123' or '#123' + // TODO FIXME This logic must be in the caller that set $this->datacolor + $tmp = str_replace('#', '', $this->datacolor[$i]); + if (strpos($tmp, '-') !== false) { + $foundnegativecolor++; + $color = '#FFFFFF'; // If $val is '-123' + } else { + $color = "#" . $tmp; // If $val is '123' or '#123' + $bordercolor = $color; + } + if ($foundnegativecolor) { + if (is_array($this->datacolor[$i])) $color = 'null'; // If datacolor is array(R, G, B) + else { + $tmp = str_replace('#', '', $this->datacolor[$i]); + if (strpos($tmp, '-') !== false) $bordercolor = '#' . str_replace('-', '', $tmp); // If $val is '-123' + else $bordercolor = 'null'; // If $val is '123' or '#123' + } + $bordercolor == 'null' ? "'rgba(0,0,0,0.2)'" : "'" . $bordercolor . "'"; } - $bordercolor == 'null' ? "'rgba(0,0,0,0.2)'" : "'" . $bordercolor . "'"; } + } else { + $color = 'rgb('.$this->datacolor[$i][0].', '.$this->datacolor[$i][1].', '.$this->datacolor[$i][2].', 0.9)'; + $bordercolor = $color; + //$color = (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)); } } @@ -1267,19 +1278,18 @@ class DolGraph $this->stringtoshow .= 'label: \'' . dol_escape_js(dol_string_nohtmltag($textoflegend)) . '\', '; $this->stringtoshow .= 'pointStyle: \'' . ($this->type[$i] == 'linesnopoint' ? 'line' : 'circle') . '\', '; $this->stringtoshow .= 'fill: ' . ($type == 'bar' ? 'true' : 'false') . ', '; - if ($isfunnel){ + if ($isfunnel) { $this->stringtoshow .= 'borderWidth: \'2\', '; - } - elseif ($type == 'bar' || $type == 'horizontalBar') { + } elseif ($type == 'bar' || $type == 'horizontalBar') { $this->stringtoshow .= 'borderWidth: \'1\', '; } $this->stringtoshow .= 'borderColor: \'' . $bordercolor . '\', '; $this->stringtoshow .= 'backgroundColor: \'' . $color . '\', '; if ($arrayofgroupslegend[$i]) $this->stringtoshow .= 'stack: \'' . $arrayofgroupslegend[$i]['stacknum'] . '\', '; $this->stringtoshow .='data: ['; - if ($isfunnel){ + if ($isfunnel) { $this->stringtoshow .= '['.-$serie[$i].','.$serie[$i].']'; - }else { + } else { $this->stringtoshow .= $serie[$i]; } $this->stringtoshow .=']'; From 9b2c9899065a55ba0f1521179f7a06b381388387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 11 Dec 2020 20:57:02 +0100 Subject: [PATCH 22/25] thirdparty need to be object --- .../doc/pdf_aurore.modules.php | 488 +++++++++--------- 1 file changed, 239 insertions(+), 249 deletions(-) diff --git a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php index 8c82198999a..a76d014c861 100644 --- a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php @@ -152,15 +152,16 @@ class pdf_aurore extends ModelePDFSupplierProposal // Get source company $this->emetteur = $mysoc; - if (empty($this->emetteur->country_code)) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined + if (empty($this->emetteur->country_code)) { + $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined + } // Define position of columns $this->posxdesc = $this->marge_gauche + 1; $this->posxdiscount = 162; $this->postotalht = 174; - if (!empty($conf->global->PRODUCT_USE_UNITS)) - { + if (!empty($conf->global->PRODUCT_USE_UNITS)) { $this->posxtva = 101; $this->posxup = 118; $this->posxqty = 135; @@ -172,10 +173,11 @@ class pdf_aurore extends ModelePDFSupplierProposal $this->posxunit = 162; } - if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxup = $this->posxtva; + if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) { + $this->posxup = $this->posxtva; + } $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images - if ($this->page_largeur < 210) // To work with US executive format - { + if ($this->page_largeur < 210) { // To work with US executive format $this->posxpicture -= 20; $this->posxtva -= 20; $this->posxup -= 20; @@ -209,9 +211,13 @@ class pdf_aurore extends ModelePDFSupplierProposal // phpcs:enable global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines; - if (!is_object($outputlangs)) $outputlangs = $langs; + if (!is_object($outputlangs)) { + $outputlangs = $langs; + } // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO - if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1'; + if (!empty($conf->global->MAIN_USE_FPDF)) { + $outputlangs->charset_output = 'ISO-8859-1'; + } // Load traductions files required by page $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "supplier_proposal")); @@ -220,17 +226,16 @@ class pdf_aurore extends ModelePDFSupplierProposal // Loop on each lines to detect if there is at least one image to show $realpatharray = array(); - if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_PROPOSAL_WITH_PICTURE)) - { - for ($i = 0; $i < $nblines; $i++) - { - if (empty($object->lines[$i]->fk_product)) continue; + if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_PROPOSAL_WITH_PICTURE)) { + for ($i = 0; $i < $nblines; $i++) { + if (empty($object->lines[$i]->fk_product)) { + continue; + } $objphoto = new Product($this->db); $objphoto->fetch($object->lines[$i]->fk_product); - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) - { + if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/"; $dir = $conf->product->dir_output.'/'.$pdir; } else { @@ -239,28 +244,29 @@ class pdf_aurore extends ModelePDFSupplierProposal } $realpath = ''; - foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) - { + foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) { $filename = $obj['photo']; //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette']; $realpath = $dir.$filename; break; } - if ($realpath) $realpatharray[$i] = $realpath; + if ($realpath) { + $realpatharray[$i] = $realpath; + } } } - if (count($realpatharray) == 0) $this->posxpicture = $this->posxtva; + if (count($realpatharray) == 0) { + $this->posxpicture = $this->posxtva; + } - if ($conf->supplier_proposal->dir_output) - { + if ($conf->supplier_proposal->dir_output) { $object->fetch_thirdparty(); // $deja_regle = 0; // Definition of $dir and $file - if ($object->specimen) - { + if ($object->specimen) { $dir = $conf->supplier_proposal->dir_output; $file = $dir."/SPECIMEN.pdf"; } else { @@ -269,20 +275,16 @@ class pdf_aurore extends ModelePDFSupplierProposal $file = $dir."/".$objectref.".pdf"; } - if (!file_exists($dir)) - { - if (dol_mkdir($dir) < 0) - { + if (!file_exists($dir)) { + if (dol_mkdir($dir) < 0) { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } } - if (file_exists($dir)) - { + if (file_exists($dir)) { // Add pdfgeneration hook - if (!is_object($hookmanager)) - { + if (!is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $hookmanager = new HookManager($this->db); } @@ -297,18 +299,18 @@ class pdf_aurore extends ModelePDFSupplierProposal $heightforinfotot = 50; // Height reserved to output the info and total part $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) - if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) $heightforfooter += 6; + if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) { + $heightforfooter += 6; + } $pdf->SetAutoPageBreak(1, 0); - if (class_exists('TCPDF')) - { + if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); // Set path to the background PDF File - if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) - { + if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } @@ -322,20 +324,19 @@ class pdf_aurore extends ModelePDFSupplierProposal $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("CommercialAsk")." ".$outputlangs->convToOutputCharset($object->thirdparty->name)); - if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); + if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) { + $pdf->SetCompression(false); + } $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right // Positionne $this->atleastonediscount si on a au moins une remise - for ($i = 0; $i < $nblines; $i++) - { - if ($object->lines[$i]->remise_percent) - { + for ($i = 0; $i < $nblines; $i++) { + if ($object->lines[$i]->remise_percent) { $this->atleastonediscount++; } } - if (empty($this->atleastonediscount)) - { + if (empty($this->atleastonediscount)) { $delta = ($this->postotalht - $this->posxdiscount); $this->posxpicture += $delta; $this->posxtva += $delta; @@ -348,7 +349,9 @@ class pdf_aurore extends ModelePDFSupplierProposal // New page $pdf->AddPage(); - if (!empty($tplidx)) $pdf->useTemplate($tplidx); + if (!empty($tplidx)) { + $pdf->useTemplate($tplidx); + } $pagenb++; $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('', '', $default_font_size - 1); @@ -360,19 +363,18 @@ class pdf_aurore extends ModelePDFSupplierProposal // Affiche notes $notetoshow = empty($object->note_public) ? '' : $object->note_public; - if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) - { + if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) { // Get first sale rep - if (is_object($object->thirdparty)) - { + if (is_object($object->thirdparty)) { $salereparray = $object->thirdparty->getSalesRepresentatives($user); $salerepobj = new User($this->db); $salerepobj->fetch($salereparray[0]['id']); - if (!empty($salerepobj->signature)) $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature); + if (!empty($salerepobj->signature)) { + $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature); + } } } - if ($notetoshow) - { + if ($notetoshow) { $tab_top -= 2; $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object); @@ -397,15 +399,16 @@ class pdf_aurore extends ModelePDFSupplierProposal $nexY = $tab_top + 7; // Loop on each lines - for ($i = 0; $i < $nblines; $i++) - { + for ($i = 0; $i < $nblines; $i++) { $curY = $nexY; $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage $pdf->SetTextColor(0, 0, 0); // Define size of image if we need it $imglinesize = array(); - if (!empty($realpatharray[$i])) $imglinesize = pdf_getSizeForImage($realpatharray[$i]); + if (!empty($realpatharray[$i])) { + $imglinesize = pdf_getSizeForImage($realpatharray[$i]); + } $pdf->setTopMargin($tab_top_newpage); $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it. @@ -416,23 +419,27 @@ class pdf_aurore extends ModelePDFSupplierProposal $posYAfterDescription = 0; // We start with Photo of product line - if (!empty($imglinesize['width']) && !empty($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // If photo too high, we moved completely on new page - { + if (!empty($imglinesize['width']) && !empty($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page $pdf->AddPage('', '', true); - if (!empty($tplidx)) $pdf->useTemplate($tplidx); - if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + if (!empty($tplidx)) { + $pdf->useTemplate($tplidx); + } + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) { + $this->_pagehead($pdf, $object, 0, $outputlangs); + } $pdf->setPage($pageposbefore + 1); $curY = $tab_top_newpage; // Allows data in the first page if description is long enough to break in multiples pages - if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) + if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) { $showpricebeforepagebreak = 1; - else $showpricebeforepagebreak = 0; + } else { + $showpricebeforepagebreak = 0; + } } - if (!empty($imglinesize['width']) && !empty($imglinesize['height'])) - { + if (!empty($imglinesize['width']) && !empty($imglinesize['height'])) { $curX = $this->posxpicture - 1; $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi // $pdf->Image does not increase value return by getY, so we save it manually @@ -443,8 +450,7 @@ class pdf_aurore extends ModelePDFSupplierProposal $curX = $this->posxdesc - 1; $pdf->startTransaction(); - if ($posYAfterImage > 0) - { + if ($posYAfterImage > 0) { $descWidth = $this->posxpicture - $curX; } else { $descWidth = $this->posxtva - $curX; @@ -452,8 +458,7 @@ class pdf_aurore extends ModelePDFSupplierProposal pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1); $pageposafter = $pdf->getPage(); - if ($pageposafter > $pageposbefore) // There is a pagebreak - { + if ($pageposafter > $pageposbefore) { // There is a pagebreak $pdf->rollbackTransaction(true); $pageposafter = $pageposbefore; //print $pageposafter.'-'.$pageposbefore;exit; @@ -463,21 +468,25 @@ class pdf_aurore extends ModelePDFSupplierProposal $pageposafter = $pdf->getPage(); $posyafter = $pdf->GetY(); //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; - if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // There is no space left for total+free text - { - if ($i == ($nblines - 1)) // No more lines, and no space left to show total, so we create a new page - { + if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text + if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page $pdf->AddPage('', '', true); - if (!empty($tplidx)) $pdf->useTemplate($tplidx); - if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + if (!empty($tplidx)) { + $pdf->useTemplate($tplidx); + } + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) { + $this->_pagehead($pdf, $object, 0, $outputlangs); + } $pdf->setPage($pageposafter + 1); } } else { // We found a page break // Allows data in the first page if description is long enough to break in multiples pages - if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) + if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) { $showpricebeforepagebreak = 1; - else $showpricebeforepagebreak = 0; + } else { + $showpricebeforepagebreak = 0; + } } } else // No pagebreak { @@ -513,7 +522,7 @@ class pdf_aurore extends ModelePDFSupplierProposal $pdf->SetXY($this->posxup, $curY); if ($up_excl_tax > 0) $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0); - */ + */ // Quantity $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); @@ -521,8 +530,7 @@ class pdf_aurore extends ModelePDFSupplierProposal $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars // Unit - if (!empty($conf->global->PRODUCT_USE_UNITS)) - { + if (!empty($conf->global->PRODUCT_USE_UNITS)) { $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY($this->posxunit, $curY); $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L'); @@ -542,11 +550,14 @@ class pdf_aurore extends ModelePDFSupplierProposal $pdf->SetXY($this->postotalht, $curY); if ($total_excl_tax > 0) $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0); - */ + */ // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva - if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) $tvaligne = $object->lines[$i]->multicurrency_total_tva; - else $tvaligne = $object->lines[$i]->total_tva; + if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) { + $tvaligne = $object->lines[$i]->multicurrency_total_tva; + } else { + $tvaligne = $object->lines[$i]->total_tva; + } $localtax1ligne = $object->lines[$i]->total_localtax1; $localtax2ligne = $object->lines[$i]->total_localtax2; @@ -555,36 +566,48 @@ class pdf_aurore extends ModelePDFSupplierProposal $localtax1_type = $object->lines[$i]->localtax1_type; $localtax2_type = $object->lines[$i]->localtax2_type; - if ($object->remise_percent) $tvaligne -= ($tvaligne * $object->remise_percent) / 100; - if ($object->remise_percent) $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100; - if ($object->remise_percent) $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100; + if ($object->remise_percent) { + $tvaligne -= ($tvaligne * $object->remise_percent) / 100; + } + if ($object->remise_percent) { + $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100; + } + if ($object->remise_percent) { + $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100; + } $vatrate = (string) $object->lines[$i]->tva_tx; // Retrieve type from database for backward compatibility with old records if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined - && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax - { + && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); $localtax1_type = $localtaxtmp_array[0]; $localtax2_type = $localtaxtmp_array[2]; } // retrieve global local tax - if ($localtax1_type && $localtax1ligne != 0) + if ($localtax1_type && $localtax1ligne != 0) { $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne; - if ($localtax2_type && $localtax2ligne != 0) + } + if ($localtax2_type && $localtax2ligne != 0) { $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne; + } - if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate .= '*'; - if (!isset($this->tva[$vatrate])) $this->tva[$vatrate] = 0; + if (($object->lines[$i]->info_bits & 0x01) == 0x01) { + $vatrate .= '*'; + } + if (!isset($this->tva[$vatrate])) { + $this->tva[$vatrate] = 0; + } $this->tva[$vatrate] += $tvaligne; - if ($posYAfterImage > $posYAfterDescription) $nexY = $posYAfterImage; + if ($posYAfterImage > $posYAfterDescription) { + $nexY = $posYAfterImage; + } // Add line - if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) - { + if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) { $pdf->setPage($pageposafter); $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80))); //$pdf->SetDrawColor(190,190,200); @@ -595,11 +618,9 @@ class pdf_aurore extends ModelePDFSupplierProposal $nexY += 2; // Add space between lines // Detect if some page were added automatically and output _tableau for past pages - while ($pagenb < $pageposafter) - { + while ($pagenb < $pageposafter) { $pdf->setPage($pagenb); - if ($pagenb == 1) - { + if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); @@ -608,12 +629,12 @@ class pdf_aurore extends ModelePDFSupplierProposal $pagenb++; $pdf->setPage($pagenb); $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. - if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) { + $this->_pagehead($pdf, $object, 0, $outputlangs); + } } - if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) - { - if ($pagenb == 1) - { + if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { + if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); @@ -621,15 +642,18 @@ class pdf_aurore extends ModelePDFSupplierProposal $this->_pagefoot($pdf, $object, $outputlangs, 1); // New page $pdf->AddPage(); - if (!empty($tplidx)) $pdf->useTemplate($tplidx); + if (!empty($tplidx)) { + $pdf->useTemplate($tplidx); + } $pagenb++; - if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) { + $this->_pagehead($pdf, $object, 0, $outputlangs); + } } } // Show square - if ($pagenb == 1) - { + if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { @@ -653,7 +677,9 @@ class pdf_aurore extends ModelePDFSupplierProposal // Pied de page $this->_pagefoot($pdf, $object, $outputlangs); - if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages(); + if (method_exists($pdf, 'AliasNbPages')) { + $pdf->AliasNbPages(); + } $pdf->Close(); @@ -664,14 +690,14 @@ class pdf_aurore extends ModelePDFSupplierProposal $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); global $action; $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) - { + if ($reshook < 0) { $this->error = $hookmanager->error; $this->errors = $hookmanager->errors; } - if (!empty($conf->global->MAIN_UMASK)) - @chmod($file, octdec($conf->global->MAIN_UMASK)); + if (!empty($conf->global->MAIN_UMASK)) { + @chmod($file, octdec($conf->global->MAIN_UMASK)); + } $this->result = array('fullpath'=>$file); @@ -724,8 +750,7 @@ class pdf_aurore extends ModelePDFSupplierProposal $posxval = 52; // Show shipping date - if (!empty($object->delivery_date)) - { + if (!empty($object->delivery_date)) { $outputlangs->load("sendings"); $pdf->SetFont('', 'B', $default_font_size - 2); $pdf->SetXY($this->marge_gauche, $posy); @@ -768,8 +793,7 @@ class pdf_aurore extends ModelePDFSupplierProposal }*/ // Show payments conditions - if (empty($conf->global->SUPPLIER_PROPOSAL_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement)) - { + if (empty($conf->global->SUPPLIER_PROPOSAL_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement)) { $pdf->SetFont('', 'B', $default_font_size - 2); $pdf->SetXY($this->marge_gauche, $posy); $titre = $outputlangs->transnoentities("PaymentConditions").':'; @@ -784,13 +808,11 @@ class pdf_aurore extends ModelePDFSupplierProposal $posy = $pdf->GetY() + 3; } - if (!empty($conf->global->SUPPLIER_PROPOSAL_PDF_SHOW_PAYMENTTERMMODE)) - { + if (!empty($conf->global->SUPPLIER_PROPOSAL_PDF_SHOW_PAYMENTTERMMODE)) { // Show payment mode if ($object->mode_reglement_code && $object->mode_reglement_code != 'CHQ' - && $object->mode_reglement_code != 'VIR') - { + && $object->mode_reglement_code != 'VIR') { $pdf->SetFont('', 'B', $default_font_size - 2); $pdf->SetXY($this->marge_gauche, $posy - 2); $titre = $outputlangs->transnoentities("PaymentMode").':'; @@ -804,15 +826,12 @@ class pdf_aurore extends ModelePDFSupplierProposal } // Show payment mode CHQ - if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') - { + if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') { // Si mode reglement non force ou si force a CHQ - if (!empty($conf->global->FACTURE_CHQ_NUMBER)) - { + if (!empty($conf->global->FACTURE_CHQ_NUMBER)) { $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE); - if ($conf->global->FACTURE_CHQ_NUMBER > 0) - { + if ($conf->global->FACTURE_CHQ_NUMBER > 0) { $account = new Account($this->db); $account->fetch($conf->global->FACTURE_CHQ_NUMBER); @@ -821,23 +840,20 @@ class pdf_aurore extends ModelePDFSupplierProposal $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0); $posy = $pdf->GetY() + 1; - if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) - { + if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) { $pdf->SetXY($this->marge_gauche, $posy); $pdf->SetFont('', '', $default_font_size - $diffsizetitle); $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0); $posy = $pdf->GetY() + 2; } } - if ($conf->global->FACTURE_CHQ_NUMBER == -1) - { + if ($conf->global->FACTURE_CHQ_NUMBER == -1) { $pdf->SetXY($this->marge_gauche, $posy); $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle); $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0); $posy = $pdf->GetY() + 1; - if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) - { + if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) { $pdf->SetXY($this->marge_gauche, $posy); $pdf->SetFont('', '', $default_font_size - $diffsizetitle); $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0); @@ -848,10 +864,8 @@ class pdf_aurore extends ModelePDFSupplierProposal } // If payment mode not forced or forced to VIR, show payment with BAN - if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') - { - if (!empty($object->fk_bank) || !empty($conf->global->FACTURE_RIB_NUMBER)) - { + if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') { + if (!empty($object->fk_bank) || !empty($conf->global->FACTURE_RIB_NUMBER)) { $bankid = (empty($object->fk_bank) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_bank); $account = new Account($this->db); $account->fetch($bankid); @@ -893,8 +907,7 @@ class pdf_aurore extends ModelePDFSupplierProposal // Tableau total $col1x = 120; $col2x = 170; - if ($this->page_largeur < 210) // To work with US executive format - { + if ($this->page_largeur < 210) { // To work with US executive format $col2x -= 20; } $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x); @@ -914,32 +927,28 @@ class pdf_aurore extends ModelePDFSupplierProposal $pdf->SetFillColor(248, 248, 248); $this->atleastoneratenotnull = 0; - if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) - { + if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) { $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false); - if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) - { + if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) { // Nothing to do } else { //Local tax 1 before VAT //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on') //{ - foreach ($this->localtax1 as $localtax_type => $localtax_rate) - { - if (in_array((string) $localtax_type, array('1', '3', '5'))) continue; + foreach ($this->localtax1 as $localtax_type => $localtax_rate) { + if (in_array((string) $localtax_type, array('1', '3', '5'))) { + continue; + } - foreach ($localtax_rate as $tvakey => $tvaval) - { - if ($tvakey != 0) // On affiche pas taux 0 - { - //$this->atleastoneratenotnull++; + foreach ($localtax_rate as $tvakey => $tvaval) { + if ($tvakey != 0) { // On affiche pas taux 0 + //$this->atleastoneratenotnull++; $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $tvacompl = ''; - if (preg_match('/\*/', $tvakey)) - { + if (preg_match('/\*/', $tvakey)) { $tvakey = str_replace('*', '', $tvakey); $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; } @@ -952,19 +961,18 @@ class pdf_aurore extends ModelePDFSupplierProposal } } } - //} + //} //Local tax 2 before VAT //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on') //{ - foreach ($this->localtax2 as $localtax_type => $localtax_rate) - { - if (in_array((string) $localtax_type, array('1', '3', '5'))) continue; + foreach ($this->localtax2 as $localtax_type => $localtax_rate) { + if (in_array((string) $localtax_type, array('1', '3', '5'))) { + continue; + } - foreach ($localtax_rate as $tvakey => $tvaval) - { - if ($tvakey != 0) // On affiche pas taux 0 - { - //$this->atleastoneratenotnull++; + foreach ($localtax_rate as $tvakey => $tvaval) { + if ($tvakey != 0) { // On affiche pas taux 0 + //$this->atleastoneratenotnull++; @@ -972,8 +980,7 @@ class pdf_aurore extends ModelePDFSupplierProposal $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $tvacompl = ''; - if (preg_match('/\*/', $tvakey)) - { + if (preg_match('/\*/', $tvakey)) { $tvakey = str_replace('*', '', $tvakey); $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; } @@ -988,18 +995,15 @@ class pdf_aurore extends ModelePDFSupplierProposal } //} // VAT - foreach ($this->tva as $tvakey => $tvaval) - { - if ($tvakey > 0) // On affiche pas taux 0 - { + foreach ($this->tva as $tvakey => $tvaval) { + if ($tvakey > 0) { // On affiche pas taux 0 $this->atleastoneratenotnull++; $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $tvacompl = ''; - if (preg_match('/\*/', $tvakey)) - { + if (preg_match('/\*/', $tvakey)) { $tvakey = str_replace('*', '', $tvakey); $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; } @@ -1015,22 +1019,20 @@ class pdf_aurore extends ModelePDFSupplierProposal //Local tax 1 after VAT //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on') //{ - foreach ($this->localtax1 as $localtax_type => $localtax_rate) - { - if (in_array((string) $localtax_type, array('2', '4', '6'))) continue; + foreach ($this->localtax1 as $localtax_type => $localtax_rate) { + if (in_array((string) $localtax_type, array('2', '4', '6'))) { + continue; + } - foreach ($localtax_rate as $tvakey => $tvaval) - { - if ($tvakey != 0) // On affiche pas taux 0 - { - //$this->atleastoneratenotnull++; + foreach ($localtax_rate as $tvakey => $tvaval) { + if ($tvakey != 0) { // On affiche pas taux 0 + //$this->atleastoneratenotnull++; $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $tvacompl = ''; - if (preg_match('/\*/', $tvakey)) - { + if (preg_match('/\*/', $tvakey)) { $tvakey = str_replace('*', '', $tvakey); $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; } @@ -1043,27 +1045,25 @@ class pdf_aurore extends ModelePDFSupplierProposal } } } - //} + //} //Local tax 2 after VAT //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on') //{ - foreach ($this->localtax2 as $localtax_type => $localtax_rate) - { - if (in_array((string) $localtax_type, array('2', '4', '6'))) continue; + foreach ($this->localtax2 as $localtax_type => $localtax_rate) { + if (in_array((string) $localtax_type, array('2', '4', '6'))) { + continue; + } - foreach ($localtax_rate as $tvakey => $tvaval) - { + foreach ($localtax_rate as $tvakey => $tvaval) { // retrieve global local tax - if ($tvakey != 0) // On affiche pas taux 0 - { - //$this->atleastoneratenotnull++; + if ($tvakey != 0) { // On affiche pas taux 0 + //$this->atleastoneratenotnull++; $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $tvacompl = ''; - if (preg_match('/\*/', $tvakey)) - { + if (preg_match('/\*/', $tvakey)) { $tvakey = str_replace('*', '', $tvakey); $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; } @@ -1094,7 +1094,9 @@ class pdf_aurore extends ModelePDFSupplierProposal $pdf->SetTextColor(0, 0, 0); $resteapayer = $object->total_ttc - $deja_regle; - if (!empty($object->paye)) $resteapayer = 0; + if (!empty($object->paye)) { + $resteapayer = 0; + } if ($deja_regle > 0) { $index++; @@ -1158,7 +1160,9 @@ class pdf_aurore extends ModelePDFSupplierProposal // Force to disable hidetop and hidebottom $hidebottom = 0; - if ($hidetop) $hidetop = -1; + if ($hidetop) { + $hidetop = -1; + } $currency = !empty($currency) ? $currency : $conf->currency; $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -1167,14 +1171,15 @@ class pdf_aurore extends ModelePDFSupplierProposal $pdf->SetTextColor(0, 0, 0); $pdf->SetFont('', '', $default_font_size - 2); - if (empty($hidetop)) - { + if (empty($hidetop)) { $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency)); $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4); $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre); //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230'; - if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)); + if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) { + $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)); + } } $pdf->SetDrawColor(128, 128, 128); @@ -1183,35 +1188,30 @@ class pdf_aurore extends ModelePDFSupplierProposal // Output Rect $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect takes a length in 3rd parameter and 4th parameter - if (empty($hidetop)) - { + if (empty($hidetop)) { $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line takes a position y in 2nd parameter and 4th parameter $pdf->SetXY($this->posxdesc - 1, $tab_top + 1); $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L'); } - if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) - { + if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) { $pdf->line($this->posxtva, $tab_top, $this->posxtva, $tab_top + $tab_height); //$pdf->line($this->posxtva-2, $tab_top, $this->posxtva-2, $tab_top + $tab_height); - if (empty($hidetop)) - { + if (empty($hidetop)) { $pdf->SetXY($this->posxtva - 5, $tab_top + 1); $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C'); } } $pdf->line($this->posxup - 3, $tab_top, $this->posxup - 3, $tab_top + $tab_height); - if (empty($hidetop)) - { + if (empty($hidetop)) { $pdf->SetXY($this->posxup - 1, $tab_top + 1); $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C'); } $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height); - if (empty($hidetop)) - { + if (empty($hidetop)) { $pdf->SetXY($this->posxqty - 1, $tab_top + 1); $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C'); } @@ -1225,20 +1225,16 @@ class pdf_aurore extends ModelePDFSupplierProposal } $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height); - if (empty($hidetop)) - { - if ($this->atleastonediscount) - { + if (empty($hidetop)) { + if ($this->atleastonediscount) { $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1); $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C'); } } - if ($this->atleastonediscount) - { + if ($this->atleastonediscount) { $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height); } - if (empty($hidetop)) - { + if (empty($hidetop)) { $pdf->SetXY($this->postotalht - 1, $tab_top + 1); $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHT"), '', 'C'); } @@ -1266,8 +1262,7 @@ class pdf_aurore extends ModelePDFSupplierProposal pdf_pagehead($pdf, $outputlangs, $this->page_hauteur); // Show Draft Watermark - if ($object->statut == 0 && (!empty($conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK))) - { + if ($object->statut == 0 && (!empty($conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK))) { pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK); } @@ -1281,10 +1276,8 @@ class pdf_aurore extends ModelePDFSupplierProposal // Logo $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; - if ($this->emetteur->logo) - { - if (is_readable($logo)) - { + if ($this->emetteur->logo) { + if (is_readable($logo)) { $height = pdf_getHeightForLogo($logo); $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) } else { @@ -1314,8 +1307,7 @@ class pdf_aurore extends ModelePDFSupplierProposal $posy += 1; $pdf->SetFont('', '', $default_font_size - 2); - if ($object->ref_client) - { + if ($object->ref_client) { $posy += 4; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); @@ -1326,10 +1318,9 @@ class pdf_aurore extends ModelePDFSupplierProposal $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierProposalDate")." : " . dol_print_date($object->delivery_date, "day", false, $outputlangs, true), '', 'R'); - */ + */ - if ($object->thirdparty->code_fournisseur) - { + if ($object->thirdparty->code_fournisseur) { $posy += 4; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); @@ -1337,11 +1328,9 @@ class pdf_aurore extends ModelePDFSupplierProposal } // Get contact - if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) - { + if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) { $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL'); - if (count($arrayidcontact) > 0) - { + if (count($arrayidcontact) > 0) { $usertmp = new User($this->db); $usertmp->fetch($arrayidcontact[0]); $posy += 4; @@ -1357,30 +1346,29 @@ class pdf_aurore extends ModelePDFSupplierProposal // Show list of linked objects $current_y = $pdf->getY(); $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size); - if ($current_y < $pdf->getY()) - { + if ($current_y < $pdf->getY()) { $top_shift = $pdf->getY() - $current_y; } - if ($showaddress) - { + if ($showaddress) { // Sender properties $carac_emetteur = ''; - // Add internal contact of proposal if defined + // Add internal contact of proposal if defined $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL'); - if (count($arrayidcontact) > 0) - { - $object->fetch_user($arrayidcontact[0]); - $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name")); - $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n"; - } + if (count($arrayidcontact) > 0) { + $object->fetch_user($arrayidcontact[0]); + $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name")); + $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n"; + } - $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); + $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy = 42 + $top_shift; - $posx = $this->marge_gauche; - if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80; + $posx = $this->marge_gauche; + if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) { + $posx = $this->page_largeur - $this->marge_droite - 80; + } $hautcadre = 40; // Show sender frame @@ -1408,22 +1396,20 @@ class pdf_aurore extends ModelePDFSupplierProposal // If CUSTOMER contact defined, we use it $usecontact = false; $arrayidcontact = $object->getIdContact('external', 'CUSTOMER'); - if (count($arrayidcontact) > 0) - { + if (count($arrayidcontact) > 0) { $usecontact = true; $result = $object->fetch_contact($arrayidcontact[0]); } // Recipient name - if (!empty($usecontact)) - { + if (!empty($usecontact)) { if ($usecontact && ($object->contact->fk_soc != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) { - $socname = $object->contact->socname; + $socname = $object->contact; } else { - $socname = $object->thirdparty->name; + $socname = $object->thirdparty; } } else { - $socname = $object->thirdparty->name; + $socname = $object->thirdparty; } $carac_client_name = pdfBuildThirdpartyName($socname, $outputlangs); @@ -1432,10 +1418,14 @@ class pdf_aurore extends ModelePDFSupplierProposal // Show recipient $widthrecbox = 100; - if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format + if ($this->page_largeur < 210) { + $widthrecbox = 84; // To work with US executive format + } $posy = 42 + $top_shift; $posx = $this->page_largeur - $this->marge_droite - $widthrecbox; - if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche; + if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) { + $posx = $this->marge_gauche; + } // Show recipient frame $pdf->SetTextColor(0, 0, 0); From 87038f953a86f2dce96d6b456cca84575cefe318 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 11 Dec 2020 19:58:05 +0000 Subject: [PATCH 23/25] Fixing style errors. --- .../modules/supplier_proposal/doc/pdf_aurore.modules.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php index a76d014c861..27cfd949ca6 100644 --- a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php @@ -942,7 +942,7 @@ class pdf_aurore extends ModelePDFSupplierProposal foreach ($localtax_rate as $tvakey => $tvaval) { if ($tvakey != 0) { // On affiche pas taux 0 - //$this->atleastoneratenotnull++; + //$this->atleastoneratenotnull++; $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); @@ -972,7 +972,7 @@ class pdf_aurore extends ModelePDFSupplierProposal foreach ($localtax_rate as $tvakey => $tvaval) { if ($tvakey != 0) { // On affiche pas taux 0 - //$this->atleastoneratenotnull++; + //$this->atleastoneratenotnull++; @@ -1026,7 +1026,7 @@ class pdf_aurore extends ModelePDFSupplierProposal foreach ($localtax_rate as $tvakey => $tvaval) { if ($tvakey != 0) { // On affiche pas taux 0 - //$this->atleastoneratenotnull++; + //$this->atleastoneratenotnull++; $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); @@ -1057,7 +1057,7 @@ class pdf_aurore extends ModelePDFSupplierProposal foreach ($localtax_rate as $tvakey => $tvaval) { // retrieve global local tax if ($tvakey != 0) { // On affiche pas taux 0 - //$this->atleastoneratenotnull++; + //$this->atleastoneratenotnull++; $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); From 870f2073adee7e7a1903da1ffb7374419561a3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 11 Dec 2020 22:13:30 +0100 Subject: [PATCH 24/25] fix warning --- htdocs/compta/bank/various_payment/card.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index 191efdc30dc..db539e060d2 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-2020 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,8 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; -if (!empty($conf->projet->enabled)) -{ +if (!empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } @@ -122,8 +121,8 @@ if (empty($reshook)) $object->accountancy_code = GETPOST("accountancy_code") > 0 ? GETPOST("accountancy_code", "alpha") : ""; $object->subledger_account = $subledger_account; - $object->sens = GETPOST('sens', 'int'); - $object->fk_project = GETPOST('fk_project', 'int'); + $object->sens = GETPOSTINT('sens'); + $object->fk_project = GETPOSTINT('fk_project'); if (empty($datep) || empty($datev)) { From 479d709a962f6f2cd06cd35af02b54e390b3008b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 12 Dec 2020 09:39:54 +0100 Subject: [PATCH 25/25] fix warning --- htdocs/core/modules/commande/doc/pdf_proforma.modules.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/commande/doc/pdf_proforma.modules.php b/htdocs/core/modules/commande/doc/pdf_proforma.modules.php index fa555db2ced..954252f8013 100644 --- a/htdocs/core/modules/commande/doc/pdf_proforma.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_proforma.modules.php @@ -66,14 +66,15 @@ class pdf_proforma extends pdf_eratosthene * @param Commande $object Object to show * @param int $showaddress 0=no, 1=yes * @param Translate $outputlangs Object lang for output + * @param Translate $outputlangsbis Object lang for output bis * @param string $titlekey Translation key to show as title of document * @return int Return topshift value */ - protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "InvoiceProForma") + protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "InvoiceProForma") { // phpcs:enable global $conf, $langs, $hookmanager; - return parent::_pagehead($pdf, $object, $showaddress, $outputlangs, $titlekey); + return parent::_pagehead($pdf, $object, $showaddress, $outputlangs, $outputlangsbis, $titlekey); } }