Sfoglia il codice sorgente

[Administration] Tableau de bord administrateur

feature/souke
Guillaume Bourgeois 9 mesi fa
parent
commit
49dbc8922d
10 ha cambiato i file con 261 aggiunte e 170 eliminazioni
  1. +38
    -4
      backend/controllers/DashboardAdminController.php
  2. +1
    -1
      backend/controllers/ProducerAdminController.php
  3. +17
    -0
      backend/views/_include/small_box.php
  4. +94
    -0
      backend/views/dashboard-admin/_statistics.php
  5. +27
    -147
      backend/views/dashboard-admin/index.php
  6. +9
    -1
      backend/views/layouts/header.php
  7. +4
    -8
      backend/web/js/backend.js
  8. +27
    -0
      common/helpers/AdminLTE.php
  9. +19
    -2
      domain/Order/Order/OrderRepository.php
  10. +25
    -7
      domain/Producer/Producer/ProducerRepository.php

+ 38
- 4
backend/controllers/DashboardAdminController.php Vedi File

@@ -67,19 +67,53 @@ class DashboardAdminController extends BackendController
];
}


public function actionIndex()
{
return $this->render('index', [
'supportOnline' => $this->getSettingModule()->getAdminSettingBag()->get('supportOnline'),
'countUsersOnline' => $this->getUserModule()->getRepository()->countUsersOnline(),
'countTicketsAdminOpen' => $this->getTicketModule()->getRepository()->countTicketsAdminStatusOpen(),
'countTicketsAdminUnread' => $this->getTicketModule()->getRepository()->countTicketsAdminUnreadByUser($this->getUserCurrent()),
'amountProducerUnpaidInvoices' => '--',
'statisticsCacheHtml' => \Yii::$app->cache->get('dashboard_statistics') ?: ''
]);
}

public function actionAjaxAmountProducerInvoicesUnpaid()
public function actionSupportOnlineToggle(int $active)
{
$this->getSettingModule()->getAdminSettingBag()->set('supportOnline', $active);
return $this->redirect('index');
}

public function actionAjaxStatisticsHtml()
{
return Price::format($this->getProducerModule()->getDolibarrUtils()->getAmountProducerInvoicesUnpaid());
return \Yii::$app->cache->getOrSet('dashboard_statistics', function () {
$producerModule = $this->getProducerModule();
$pointSaleModule = $this->getPointSaleModule();
$userModule = $this->getUserModule();
$orderModule = $this->getOrderModule();

$countProducersActive = $producerModule->getRepository()->countProducersActiveWithTurnover();
$countPointSalesActive = $pointSaleModule->countPointSalesActiveLastThreeMonths();
$countUsersActive = $userModule->countUsersActiveLastThreeMonths();
$averageOrdersPerDay = $orderModule->countGlobalUserOrdersAverageLastSevenDays();
$turnoverLastThirtyDays = $orderModule->getRepository()->getTurnoverLastThirtyDays();
$resultMatomoApiVisitSummary = json_decode(file_get_contents(\Yii::$app->parameterBag->get('matomoApiVisitSummaryUrl')));
$numberVisitsDay = $resultMatomoApiVisitSummary->nb_uniq_visitors / 30;
$amountBilledLastMonth = $producerModule->getRepository()->getAmountBilledLastMonth();
$amountToBillCurrentMonth = $producerModule->getRepository()->getAmountToBillCurrentMonth();
$amountProducerUnpaidInvoices = $producerModule->getDolibarrUtils()->getAmountProducerInvoicesUnpaid();

return $this->renderPartial('_statistics', [
'amountBilledLastMonth' => $amountBilledLastMonth,
'amountToBillCurrentMonth' => $amountToBillCurrentMonth,
'amountProducerUnpaidInvoices' => $amountProducerUnpaidInvoices,
'countProducersActive' => $countProducersActive,
'countPointSalesActive' => $countPointSalesActive,
'countUsersActive' => $countUsersActive,
'averageOrdersPerDay' => $averageOrdersPerDay,
'turnoverLastThirtyDays' => $turnoverLastThirtyDays,
'numberVisitsDay' => $numberVisitsDay
]);
}, 60 * 60 * 24);
}
}

+ 1
- 1
backend/controllers/ProducerAdminController.php Vedi File

@@ -99,7 +99,7 @@ class ProducerAdminController extends BackendController
$producersArray = $producerModule->findProducersActive();
$sumPrices = 0;
foreach ($producersArray as $producer) {
$sumPrices += $producerModule->getAmountBilledLastMonth($producer);
$sumPrices += $producerModule->getAmountBilledLastMonthByProducer($producer);
}

return $this->render('index', [

+ 17
- 0
backend/views/_include/small_box.php Vedi File

@@ -0,0 +1,17 @@

<div class="small-box bg-<?= $backgroundColor ?>">
<div class="inner">
<h3><?= $title ?></h3>
<p><?= $description ?></p>
</div>
<div class="icon">
<i class="fa fa-<?= $icon ?>"></i>
</div>
<?php if(isset($footerLinkUrl) && $footerLinkUrl): ?>
<a href="<?= $footerLinkUrl ?>" class="small-box-footer">
<?= $footerLinkLabel ?> <i class="fa fa-<?= $footerLinkIcon ?>"></i>
</a>
<?php else: ?>
<div class="small-box-footer">&nbsp;</div>
<?php endif; ?>
</div>

+ 94
- 0
backend/views/dashboard-admin/_statistics.php Vedi File

@@ -0,0 +1,94 @@
<?php

use common\helpers\AdminLTE;
use common\helpers\Price;

?>

<div class="row">
<div class="col-lg-6 col-xs-6">
<?= AdminLTE::smallBox(
Price::format($turnoverLastThirtyDays, 0),
'CA producteurs sur les 30 derniers jours',
'aqua',
'line-chart',
Yii::$app->urlManager->createUrl('stats-admin/turnover')
) ?>
</div>
<div class="col-lg-6 col-xs-6">
<?= AdminLTE::smallBox(
$averageOrdersPerDay,
'Commandes clients / jour sur les 7 derniers jours',
'aqua',
'shopping-cart',
Yii::$app->urlManager->createUrl('stats-admin/turnover')
) ?>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xs-6">
<?= AdminLTE::smallBox(
$countProducersActive,
'Producteurs actifs sur les 3 derniers mois',
'aqua',
'user'
) ?>
</div>
<div class="col-lg-6 col-xs-6">
<?= AdminLTE::smallBox(
$countUsersActive,
'Clients actifs sur les 3 derniers mois',
'aqua',
'users'
) ?>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xs-6">
<?= AdminLTE::smallBox(
$countPointSalesActive,
'Points de vente actifs sur les 3 derniers mois',
'aqua',
'map-marker'
) ?>
</div>
<div class="col-lg-6 col-xs-6">
<?= AdminLTE::smallBox(
$numberVisitsDay,
'Visites / jour en moyenne sur les 30 derniers jours',
'aqua',
'eye'
) ?>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xs-6">
<?= AdminLTE::smallBox(
Price::format($amountToBillCurrentMonth, 0),
'Total factures producteurs mois en cours',
'green',
'euro',
Yii::$app->urlManager->createUrl('producer-admin/index')
) ?>
</div>
<div class="col-lg-6 col-xs-6">
<?= AdminLTE::smallBox(
Price::format($amountBilledLastMonth, 0),
'Total factures producteurs du mois dernier',
'green',
'euro',
Yii::$app->urlManager->createUrl('producer-admin/index')
) ?>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xs-6">
<?= AdminLTE::smallBox(
Price::format($amountProducerUnpaidInvoices, 0),
'Montant factures producteurs impayées',
'red',
'euro',
Yii::$app->parameterBag->get('dolibarrUrl') . 'compta/facture/list.php?leftmenu=customers_bills_notpaid&search_status=1'
) ?>
</div>
</div>

+ 27
- 147
backend/views/dashboard-admin/index.php Vedi File

@@ -1,5 +1,7 @@
<?php

use common\helpers\AdminLTE;

$this->setTitle('Tableau de bord');

?>
@@ -7,160 +9,38 @@ $this->setTitle('Tableau de bord');
<div class="dashboard-admin-index">
<div class="row">
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-aqua">
<div class="inner">
<h3><?= $countUsersOnline ?></h3>
<p>En ligne</p>
</div>
<div class="icon">
<i class="fa fa-wifi"></i>
</div>
<a href="<?= Yii::$app->urlManager->createUrl('online-admin/index') ?>" class="small-box-footer">
Voir <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-green">
<div class="inner">
<h3><?= 'Oui' ?></h3>
<p>Support activé</p>
</div>
<div class="icon">
<i class="fa fa-phone"></i>
</div>
<a href="<?= Yii::$app->urlManager->createUrl('support-admin/index') ?>" class="small-box-footer">
Désactiver <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-<?= $countTicketsAdminUnread ? 'green' : 'blue' ?>">
<div class="inner">
<h3><?= $countTicketsAdminOpen ?></h3>
<p>Tickets</p>
</div>
<div class="icon">
<i class="fa fa-comments"></i>
</div>
<a href="<?= Yii::$app->urlManager->createUrl('support-admin/index') ?>" class="small-box-footer">
Voir <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-green">
<div class="inner">
<h3><?= '1230 €' ?></h3>
<p>Total factures producteurs mois en cours</p>
</div>
<div class="icon">
<i class="fa fa-euro"></i>
</div>
<a href="<?= Yii::$app->urlManager->createUrl('producer-admin/index') ?>" class="small-box-footer">
Voir <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-red">
<div class="inner">
<h3 id="amount-producer-invoices-unpaid"><?= $amountProducerUnpaidInvoices ?></h3>
<p>Montant factures impayées</p>
</div>
<div class="icon">
<i class="fa fa-euro"></i>
</div>
<a target="_blank" href="<?= Yii::$app->parameterBag->get('dolibarrUrl') ?>compta/facture/list.php?leftmenu=customers_bills_notpaid&search_status=1" class="small-box-footer">
Voir <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
<?= AdminLTE::smallBox(
$countUsersOnline,
'En ligne',
$countUsersOnline ? 'green' : 'blue',
'wifi',
Yii::$app->urlManager->createUrl('online-admin/index')
) ?>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-aqua">
<div class="inner">
<h3><?= '127 000 €' ?></h3>
<p>CA producteurs sur les 30 derniers jours</p>
</div>
<div class="icon">
<i class="fa fa-line-chart"></i>
</div>
<a href="<?= Yii::$app->urlManager->createUrl('stats-admin/turnover') ?>" class="small-box-footer">
Voir <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
<?= AdminLTE::smallBox(
$supportOnline ? 'Oui' : 'Non',
'Support activé',
$supportOnline ? 'green' : 'blue',
'phone',
Yii::$app->urlManager->createUrl(['dashboard-admin/support-online-toggle', 'active' => $supportOnline ? 0 : 1]),
$supportOnline ? 'Désactiver' : 'Activer'
) ?>
</div>
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-aqua">
<div class="inner">
<h3><?= '141' ?></h3>
<p>Commandes clients / jour sur les 7 derniers jours</p>
</div>
<div class="icon">
<i class="fa fa-shopping-cart"></i>
</div>
<a href="<?= Yii::$app->urlManager->createUrl('stats-admin/turnover') ?>" class="small-box-footer">
Voir <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
<?= AdminLTE::smallBox(
$countTicketsAdminOpen,
'Tickets',
$countTicketsAdminUnread ? 'green' : 'blue',
'comments',
Yii::$app->urlManager->createUrl('support-admin/index')
) ?>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-aqua">
<div class="inner">
<h3>43</h3>
<p>Producteurs actifs sur les 3 derniers mois</p>
</div>
<div class="icon">
<i class="fa fa-user"></i>
</div>
<div class="small-box-footer">&nbsp;</div>
</div>
</div>
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-aqua">
<div class="inner">
<h3>3 865</h3>
<p>Clients actifs sur les 3 derniers mois</p>
</div>
<div class="icon">
<i class="fa fa-users"></i>
</div>
<div class="small-box-footer">&nbsp;</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-aqua">
<div class="inner">
<h3>357</h3>
<p>Points de vente actifs sur les 3 derniers mois</p>
</div>
<div class="icon">
<i class="fa fa-map-marker"></i>
</div>
<div class="small-box-footer">&nbsp;</div>
</div>
</div>
<div class="col-lg-6 col-xs-6">
<div class="small-box bg-aqua">
<div class="inner">
<h3>450</h3>
<p>Visites / jour en moyenne sur les 30 derniers jours</p>
</div>
<div class="icon">
<i class="fa fa-eye"></i>
</div>
<div class="small-box-footer">&nbsp;</div>
</div>
</div>

<div id="dashboard-admin-statistics-html">
<?= $statisticsCacheHtml ?>
</div>
</div>

+ 9
- 1
backend/views/layouts/header.php Vedi File

@@ -54,7 +54,15 @@ $userCurrent = GlobalParam::getCurrentUser();

<header class="main-header">
<!-- <?= Html::a('<span class="logo-mini"><img src="' . Yii::$app->urlManagerBackend->getBaseUrl() . '/img/logo-distrib.png" /></span><span class="logo-lg"><img src="' . Yii::$app->urlManagerBackend->getBaseUrl() . '/img/logo-distrib.png" /></span>', Yii::$app->homeUrl, ['class' => 'logo']) ?>-->
<?= Html::a('Opendistrib', Yii::$app->homeUrl, ['class' => 'logo']); ?>


<?= Html::a(
'Opendistrib',
$userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)
? Yii::$app->urlManager->createUrl('dashboard-admin/index')
: Yii::$app->homeUrl,
['class' => 'logo']
); ?>

<nav class="navbar navbar-static-top" role="navigation">


+ 4
- 8
backend/web/js/backend.js Vedi File

@@ -57,7 +57,7 @@ $(document).ready(function () {
opendistrib_features_index();
opendistrib_point_sale_form();
opendistrib_check_all_checkboxes();
opendistrib_dashboard_admin_invoices_unpaid();
opendistrib_dashboard_admin_statistics();
});

var UrlManager = {
@@ -69,13 +69,9 @@ var UrlManager = {
}
};

function opendistrib_dashboard_admin_invoices_unpaid() {
var selector = '#amount-producer-invoices-unpaid';
$(selector).click(function() {
$(this).html('<i class="fa fa-spinner"></i>');
$.get(UrlManager.getBaseUrl() + 'dashboard-admin/ajax-amount-producer-invoices-unpaid', {}, function(result) {
$(selector).html(result);
});
function opendistrib_dashboard_admin_statistics() {
$.get(UrlManager.getBaseUrl() + 'dashboard-admin/ajax-statistics-html', {}, function(result) {
$('#dashboard-admin-statistics-html').html(result);
});
}


+ 27
- 0
common/helpers/AdminLTE.php Vedi File

@@ -0,0 +1,27 @@
<?php

namespace common\helpers;

class AdminLTE
{
public static function smallBox(
string $title,
string $description,
string $backgroundColor,
string $icon,
string $footerLinkUrl = null,
string $footerLinkLabel = 'Voir',
string $footerLinkIcon = 'arrow-circle-right'
)
{
return \Yii::$app->getView()->renderFile('@backend/views/_include/small_box.php', [
'title' => $title,
'description' => $description,
'backgroundColor' => $backgroundColor,
'icon' => $icon,
'footerLinkUrl' => $footerLinkUrl,
'footerLinkLabel' => $footerLinkLabel,
'footerLinkIcon' => $footerLinkIcon
]);
}
}

+ 19
- 2
domain/Order/Order/OrderRepository.php Vedi File

@@ -439,6 +439,23 @@ class OrderRepository extends AbstractRepository
}

public function getTurnoverByDate(\DateTime $date)
{
return $this->getTurnoverByDateStartEnd(
$date->modify('first day of this month'),
$date->modify('last day of this month')
);
}

public function getTurnoverLastThirtyDays()
{
$now = new \DateTime();
return $this->getTurnoverByDateStartEnd(
$now,
$now->modify('-30 days')
);
}

public function getTurnoverByDateStartEnd(\DateTime $dateStart, \DateTime $dateEnd)
{
$res = \Yii::$app->db->createCommand("SELECT SUM(product_order.price * product_order.quantity) AS total
FROM `order`, product_order, distribution
@@ -447,8 +464,8 @@ class OrderRepository extends AbstractRepository
AND distribution.date >= :date_start
AND distribution.date <= :date_end
")
->bindValue(':date_start', date('Y-m-', $date->getTimestamp()) . '01')
->bindValue(':date_end', date('Y-m-', $date->getTimestamp()) . '31')
->bindValue(':date_start', $dateStart->format('Y-m-d'))
->bindValue(':date_end', $dateEnd->format('Y-m-d'))
->queryOne();

if ($res['total']) {

+ 25
- 7
domain/Producer/Producer/ProducerRepository.php Vedi File

@@ -311,16 +311,34 @@ class ProducerRepository extends AbstractRepository
return $text;
}

public function getAmountBilledLastMonth(Producer $producer): float
public function getAmountToBillCurrentMonth()
{
if ($this->producerSolver->isBillingTypeClassic($producer)) {
$month = date('Y-m', strtotime('-1 month'));
return $this->getAmountToBeBilledByMonth($producer, $month);
} elseif ($this->producerSolver->isBillingTypeFreePrice($producer)) {
return $producer->free_price;
$amountToBill = 0;
$producersArray = $this->findProducersActive();
foreach ($producersArray as $producer) {
$amountToBill += $this->getAmountToBillCurrentMonthByProducer($producer);
}
return $amountToBill;
}

return 0;
public function getAmountBilledLastMonth()
{
$amountBilled = 0;
$producersArray = $this->findProducersActive();
foreach ($producersArray as $producer) {
$amountBilled += $this->getAmountBilledLastMonthByProducer($producer);
}
return $amountBilled;
}

public function getAmountToBillCurrentMonthByProducer(Producer $producer): float
{
return $this->getAmountToBeBilledByMonth($producer, date('Y-m'));
}

public function getAmountBilledLastMonthByProducer(Producer $producer): float
{
return $this->getAmountToBeBilledByMonth($producer, date('Y-m', strtotime('-1 month')));
}

public function getOnlinePaymentMinimumAmount(): float

Loading…
Annulla
Salva