Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5 [CompetitorPrice] add: dashboard getCompetitorPriceByAmountHT #52

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions class/competitorprice.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,63 @@ public function initAsSpecimen(): void
{
$this->initAsSpecimenCommon();
}

/**
* Load dashboard info
*
* @return array
* @throws Exception
*/
public function load_dashboard(): array
{
$getCompetitorPriceByAmountHT = $this->getCompetitorPriceByAmountHT();

$array['graphs'] = [$getCompetitorPriceByAmountHT];

return $array;
}

/**
* Get competitor price by amount HT
*
* @return array Graph datas (label/color/type/title/data etc..)
* @throws Exception
*/
public function getCompetitorPriceByAmountHT(): array
{
global $langs;

// Graph Title parameters
$array['title'] = $langs->transnoentities('CompetitorPriceEvolutionOverTime');
$array['picto'] = $this->picto;

// Graph parameters
$array['width'] = '100%';
$array['height'] = 400;
$array['type'] = 'lines';
$array['showlegend'] = 1;
$array['dataset'] = 2;

$array['labels'] = [
0 => [
'label' => $langs->transnoentities('AmountHT'),
],
1 => [
'label' => $langs->transnoentities('Average'),
]
];

$arrayCompetitorPriceByAmountHT = [];
$competitorPrices = $this->fetchAll('', '', 0, 0, ['customsql' => 't.status = ' . self::STATUS_VALIDATED . ' AND t.amount_ht IS NOT NULL AND t.fk_product = ' . GETPOST('id')]);
$averageAmountHT = $this->getAverage(GETPOST('id'));
if (is_array($competitorPrices) && !empty($competitorPrices)) {
foreach ($competitorPrices as $competitorPrice) {
$arrayCompetitorPriceByAmountHT[] = [dol_print_date($competitorPrice->date_creation, 'dayhour', 'tzuser'), $competitorPrice->amount_ht, $averageAmountHT];
}
}

$array['data'] = $arrayCompetitorPriceByAmountHT;

return $array;
}
}
60 changes: 60 additions & 0 deletions class/priseodashboard.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/* Copyright (C) 2024 EVARISK <technique@evarisk.com>
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* \file class/priseodashboard.class.php
* \ingroup priseo
* \brief Class file for manage PriseoDashboard
*/

/**
* Class for PriseoDashboard
*/
class PriseoDashboard
{
/**
* @var DoliDB Database handler
*/
public DoliDB $db;

/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct(DoliDB $db)
{
$this->db = $db;
}

/**
* Load dashboard info
*
* @return array
* @throws Exception
*/
public function load_dashboard(): array
{
require_once __DIR__ . '/competitorprice.class.php';

$competitorPrice = new CompetitorPrice($this->db);

$array['competitorPrice'] = $competitorPrice->load_dashboard();

return $array;
}
}
1 change: 1 addition & 0 deletions langs/fr_FR/priseo.lang
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ ConfirmDeleteProductCompetitorPrice = Confirmer la suppression du prix concurren
DeleteProductCompetitorPrice = Suppression du prix concurrent
NewCompetitorPrice = Nouveaux prix concurrent
ModifyCompetitorPrice = Modifier le prix concurrent
CompetitorPriceEvolutionOverTime = Évolution du prix dans le temps
6 changes: 6 additions & 0 deletions view/competitorprice_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';

// Load Saturne libraries
require_once __DIR__ . '/../../saturne/class/saturnedashboard.class.php';

require_once __DIR__ . '/../class/competitorprice.class.php';
require_once __DIR__ . '/../core/modules/priseo/competitorprice/mod_competitorprice_standard.php';

Expand Down Expand Up @@ -74,6 +77,7 @@
$competitorPrice = new CompetitorPrice($db);
$object = new Product($db);
$extrafields = new ExtraFields($db);
$dashboard = new SaturneDashboard($db, 'priseo');
$refCompetitorPriceMod = new $conf->global->PRISEO_COMPETITORPRICE_ADDON($db);

$hookmanager->initHooks(['competitorpricecard', 'globalcard']); // Note that conf->hooks_modules contains array
Expand Down Expand Up @@ -249,6 +253,8 @@

print dol_get_fiche_end();

$dashboard->show_dashboard();

// Actions buttons
print '<div class="tabsAction">';
if ($action != 'add_competitor_price' && $action != 'update_competitor_price') {
Expand Down