Skip to content

Commit

Permalink
Eoxia#5 [CompetitorPrice] add: dashboard getCompetitorPriceByAmountHT
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Sep 11, 2024
1 parent cbbd6ab commit 13641a5
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 1 deletion.
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.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 <[email protected]>
*
* 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;
}
}
3 changes: 2 additions & 1 deletion langs/fr_FR/priseo.lang
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ Competitor = Concurrent
ProductPageURL = URL page produit
ConfirmDeleteProductCompetitorPrice = Confirmer la suppression du prix concurrent
DeleteProductCompetitorPrice = Suppression du prix concurrent
NewCompetitorPrice = Nouveaux prix concurrent
NewCompetitorPrice = Nouveaux 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

0 comments on commit 13641a5

Please sign in to comment.