]; | ]; | ||||
} | } | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'supportOnline' => $this->getSettingModule()->getAdminSettingBag()->get('supportOnline'), | |||||
'countUsersOnline' => $this->getUserModule()->getRepository()->countUsersOnline(), | 'countUsersOnline' => $this->getUserModule()->getRepository()->countUsersOnline(), | ||||
'countTicketsAdminOpen' => $this->getTicketModule()->getRepository()->countTicketsAdminStatusOpen(), | 'countTicketsAdminOpen' => $this->getTicketModule()->getRepository()->countTicketsAdminStatusOpen(), | ||||
'countTicketsAdminUnread' => $this->getTicketModule()->getRepository()->countTicketsAdminUnreadByUser($this->getUserCurrent()), | '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); | |||||
} | } | ||||
} | } |
$producersArray = $producerModule->findProducersActive(); | $producersArray = $producerModule->findProducersActive(); | ||||
$sumPrices = 0; | $sumPrices = 0; | ||||
foreach ($producersArray as $producer) { | foreach ($producersArray as $producer) { | ||||
$sumPrices += $producerModule->getAmountBilledLastMonth($producer); | |||||
$sumPrices += $producerModule->getAmountBilledLastMonthByProducer($producer); | |||||
} | } | ||||
return $this->render('index', [ | return $this->render('index', [ |
<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"> </div> | |||||
<?php endif; ?> | |||||
</div> |
<?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> |
<?php | <?php | ||||
use common\helpers\AdminLTE; | |||||
$this->setTitle('Tableau de bord'); | $this->setTitle('Tableau de bord'); | ||||
?> | ?> | ||||
<div class="dashboard-admin-index"> | <div class="dashboard-admin-index"> | ||||
<div class="row"> | <div class="row"> | ||||
<div class="col-lg-6 col-xs-6"> | <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> | </div> | ||||
<div class="row"> | <div class="row"> | ||||
<div class="col-lg-6 col-xs-6"> | <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> | ||||
<div class="col-lg-6 col-xs-6"> | <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> | </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"> </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"> </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"> </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"> </div> | |||||
</div> | |||||
</div> | |||||
<div id="dashboard-admin-statistics-html"> | |||||
<?= $statisticsCacheHtml ?> | |||||
</div> | </div> | ||||
</div> | </div> |
<header class="main-header"> | <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('<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"> | <nav class="navbar navbar-static-top" role="navigation"> | ||||
opendistrib_features_index(); | opendistrib_features_index(); | ||||
opendistrib_point_sale_form(); | opendistrib_point_sale_form(); | ||||
opendistrib_check_all_checkboxes(); | opendistrib_check_all_checkboxes(); | ||||
opendistrib_dashboard_admin_invoices_unpaid(); | |||||
opendistrib_dashboard_admin_statistics(); | |||||
}); | }); | ||||
var UrlManager = { | 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); | |||||
}); | }); | ||||
} | } | ||||
<?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 | |||||
]); | |||||
} | |||||
} |
} | } | ||||
public function getTurnoverByDate(\DateTime $date) | 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 | $res = \Yii::$app->db->createCommand("SELECT SUM(product_order.price * product_order.quantity) AS total | ||||
FROM `order`, product_order, distribution | FROM `order`, product_order, distribution | ||||
AND distribution.date >= :date_start | AND distribution.date >= :date_start | ||||
AND distribution.date <= :date_end | 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(); | ->queryOne(); | ||||
if ($res['total']) { | if ($res['total']) { |
return $text; | 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 | public function getOnlinePaymentMinimumAmount(): float |