@@ -0,0 +1,119 @@ | |||
<?php | |||
/** | |||
* Copyright distrib (2018) | |||
* | |||
* contact@opendistrib.net | |||
* | |||
* Ce logiciel est un programme informatique servant à aider les producteurs | |||
* à distribuer leur production en circuits courts. | |||
* | |||
* Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||
* respectant les principes de diffusion des logiciels libres. Vous pouvez | |||
* utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||
* sur le site "http://www.cecill.info". | |||
* | |||
* En contrepartie de l'accessibilité au code source et des droits de copie, | |||
* de modification et de redistribution accordés par cette licence, il n'est | |||
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||
* seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||
* titulaire des droits patrimoniaux et les concédants successifs. | |||
* | |||
* A cet égard l'attention de l'utilisateur est attirée sur les risques | |||
* associés au chargement, à l'utilisation, à la modification et/ou au | |||
* développement et à la reproduction du logiciel par l'utilisateur étant | |||
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||
* manipuler et qui le réserve donc à des développeurs et des professionnels | |||
* avertis possédant des connaissances informatiques approfondies. Les | |||
* utilisateurs sont donc invités à charger et tester l'adéquation du | |||
* logiciel à leurs besoins dans des conditions permettant d'assurer la | |||
* sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||
* | |||
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||
* pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||
* termes. | |||
*/ | |||
namespace backend\controllers; | |||
use common\helpers\Price; | |||
use yii\filters\AccessControl; | |||
use yii\filters\VerbFilter; | |||
class DashboardAdminController extends BackendController | |||
{ | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function behaviors() | |||
{ | |||
return [ | |||
'access' => [ | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserModule() | |||
->getAuthorizationChecker() | |||
->isGrantedAsAdministrator($this->getUserCurrent()); | |||
} | |||
], | |||
], | |||
], | |||
]; | |||
} | |||
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()), | |||
'statisticsCacheHtml' => \Yii::$app->cache->get('dashboard_statistics') ?: '' | |||
]); | |||
} | |||
public function actionSupportOnlineToggle(int $active) | |||
{ | |||
$this->getSettingModule()->getAdminSettingBag()->set('supportOnline', $active); | |||
return $this->redirect('index'); | |||
} | |||
public function actionAjaxStatisticsHtml() | |||
{ | |||
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); | |||
} | |||
} |
@@ -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', [ |
@@ -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"> </div> | |||
<?php endif; ?> | |||
</div> |
@@ -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> |
@@ -0,0 +1,46 @@ | |||
<?php | |||
use common\helpers\AdminLTE; | |||
$this->setTitle('Tableau de bord'); | |||
?> | |||
<div class="dashboard-admin-index"> | |||
<div class="row"> | |||
<div class="col-lg-6 col-xs-6"> | |||
<?= 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"> | |||
<?= 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"> | |||
<?= AdminLTE::smallBox( | |||
$countTicketsAdminOpen, | |||
'Tickets', | |||
$countTicketsAdminUnread ? 'green' : 'blue', | |||
'comments', | |||
Yii::$app->urlManager->createUrl('support-admin/index') | |||
) ?> | |||
</div> | |||
</div> | |||
<div id="dashboard-admin-statistics-html"> | |||
<?= $statisticsCacheHtml ?> | |||
</div> | |||
</div> |
@@ -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"> | |||
@@ -120,6 +120,12 @@ $isUserCurrentGrantedAsProducer = $userModule->getAuthorizationChecker()->isGran | |||
// Administration | |||
['label' => 'Administration', 'options' => ['class' => 'header'], 'visible' => $isUserCurrentGrantedAsAdministrator], | |||
[ | |||
'label' => 'Tableau de bord', | |||
'icon' => 'dashboard', | |||
'url' => ['dashboard-admin/index'], | |||
'visible' => $isUserCurrentGrantedAsAdministrator, | |||
], | |||
[ | |||
'label' => 'En ligne', | |||
'icon' => 'wifi', |
@@ -1829,50 +1829,65 @@ body.skin-black .content-wrapper .alert .close:hover { | |||
opacity: 1; | |||
} | |||
/* line 301, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .small-box h3 { | |||
font-size: 28px; | |||
font-family: 'Source Sans Pro',sans-serif; | |||
} | |||
/* line 306, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .small-box .icon { | |||
top: -2px; | |||
} | |||
/* line 310, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .small-box .small-box-footer { | |||
color: white; | |||
padding-top: 6px; | |||
padding-bottom: 2px; | |||
} | |||
/* line 319, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .callout h4 .fa { | |||
margin-right: 7px; | |||
} | |||
/* line 304, ../sass/_adminlte.scss */ | |||
/* line 322, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .callout a { | |||
color: white; | |||
} | |||
/* line 307, ../sass/_adminlte.scss */ | |||
/* line 325, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .callout .btn { | |||
color: #333; | |||
text-decoration: none; | |||
} | |||
/* line 314, ../sass/_adminlte.scss */ | |||
/* line 332, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .table th { | |||
font-size: 13px; | |||
} | |||
/* line 317, ../sass/_adminlte.scss */ | |||
/* line 335, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .table th.column-actions, body.skin-black .content-wrapper .table td.column-actions { | |||
width: 172px; | |||
text-align: right; | |||
} | |||
/* line 321, ../sass/_adminlte.scss */ | |||
/* line 339, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .table td.text-small, body.skin-black .content-wrapper .table th.text-small { | |||
font-size: 12px; | |||
} | |||
/* line 326, ../sass/_adminlte.scss */ | |||
/* line 344, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .pagination > .active > a, body.skin-black .content-wrapper .pagination > .active > span, body.skin-black .content-wrapper .pagination > .active > a:hover, body.skin-black .content-wrapper .pagination > .active > span:hover, body.skin-black .content-wrapper .pagination > .active > a:focus, body.skin-black .content-wrapper .pagination > .active > span:focus { | |||
background-color: #F39C12; | |||
border: solid 1px #F39C12; | |||
color: white; | |||
} | |||
/* line 332, ../sass/_adminlte.scss */ | |||
/* line 350, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .pagination > li > a, body.skin-black .content-wrapper .pagination > li > span { | |||
color: #F39C12; | |||
} | |||
/* line 334, ../sass/_adminlte.scss */ | |||
/* line 352, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .pagination > li > a:hover, body.skin-black .content-wrapper .pagination > li > span:hover { | |||
color: #c87f0a; | |||
} | |||
/* line 339, ../sass/_adminlte.scss */ | |||
/* line 357, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .submenu { | |||
margin-bottom: 25px; | |||
} | |||
/* line 343, ../sass/_adminlte.scss */ | |||
/* line 361, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .form-actions { | |||
position: fixed; | |||
bottom: 0; | |||
@@ -1886,59 +1901,59 @@ body.skin-black .content-wrapper .form-actions { | |||
z-index: 10; | |||
border-top: solid 1px #e0e0e0; | |||
} | |||
/* line 356, ../sass/_adminlte.scss */ | |||
/* line 374, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .form-actions a, body.skin-black .content-wrapper .form-actions button { | |||
margin-left: 10px; | |||
} | |||
/* line 361, ../sass/_adminlte.scss */ | |||
/* line 379, ../sass/_adminlte.scss */ | |||
body.skin-black .content-wrapper .form-buttons { | |||
margin-top: 25px; | |||
text-align: right; | |||
} | |||
/* line 368, ../sass/_adminlte.scss */ | |||
/* line 386, ../sass/_adminlte.scss */ | |||
body.skin-black .main-footer a { | |||
color: #F39C12; | |||
} | |||
/* line 373, ../sass/_adminlte.scss */ | |||
/* line 391, ../sass/_adminlte.scss */ | |||
body.skin-black .gridview-pagesize { | |||
float: right; | |||
margin-bottom: 8px; | |||
} | |||
/* line 378, ../sass/_adminlte.scss */ | |||
/* line 396, ../sass/_adminlte.scss */ | |||
body.skin-black #yii-debug-toolbar { | |||
bottom: 64px; | |||
} | |||
/* line 383, ../sass/_adminlte.scss */ | |||
/* line 401, ../sass/_adminlte.scss */ | |||
body.login-page { | |||
background: none; | |||
background-color: white; | |||
} | |||
/* line 387, ../sass/_adminlte.scss */ | |||
/* line 405, ../sass/_adminlte.scss */ | |||
body.login-page .login-box .login-logo { | |||
text-align: center; | |||
font-family: 'highvoltageregular'; | |||
} | |||
/* line 391, ../sass/_adminlte.scss */ | |||
/* line 409, ../sass/_adminlte.scss */ | |||
body.login-page .login-box .login-logo img { | |||
width: 50px; | |||
} | |||
/* line 396, ../sass/_adminlte.scss */ | |||
/* line 414, ../sass/_adminlte.scss */ | |||
body.login-page .login-box .login-box-body .btn-primary { | |||
background-color: #F39C12; | |||
border-color: #F39C12; | |||
padding: 5px 10px; | |||
} | |||
/* line 401, ../sass/_adminlte.scss */ | |||
/* line 419, ../sass/_adminlte.scss */ | |||
body.login-page .login-box .login-box-body .btn-primary:active { | |||
background-color: #f4a62a; | |||
border-color: #F39C12; | |||
} | |||
/* line 407, ../sass/_adminlte.scss */ | |||
/* line 425, ../sass/_adminlte.scss */ | |||
body.login-page .login-box .login-box-body a { | |||
color: #F39C12; | |||
} | |||
/* line 409, ../sass/_adminlte.scss */ | |||
/* line 427, ../sass/_adminlte.scss */ | |||
body.login-page .login-box .login-box-body a:hover { | |||
color: #f4a62a; | |||
} |
@@ -57,18 +57,24 @@ $(document).ready(function () { | |||
opendistrib_features_index(); | |||
opendistrib_point_sale_form(); | |||
opendistrib_check_all_checkboxes(); | |||
opendistrib_dashboard_admin_statistics(); | |||
}); | |||
var UrlManager = { | |||
getBaseUrl: function () { | |||
return $('meta[name=baseurl]').attr('content') + '/'; | |||
}, | |||
getBaseUrlAbsolute: function () { | |||
return $('meta[name=baseurl-absolute]').attr('content') + '/'; | |||
} | |||
}; | |||
function opendistrib_dashboard_admin_statistics() { | |||
$.get(UrlManager.getBaseUrl() + 'dashboard-admin/ajax-statistics-html', {}, function(result) { | |||
$('#dashboard-admin-statistics-html').html(result); | |||
}); | |||
} | |||
function opendistrib_check_all_checkboxes() { | |||
$('.check-all-checkboxes').change(function() { | |||
var selector = $(this).data('selector'); |
@@ -296,6 +296,24 @@ body.skin-black { | |||
} | |||
} | |||
} | |||
.small-box { | |||
h3 { | |||
font-size: 28px; | |||
font-family: 'Source Sans Pro',sans-serif; | |||
} | |||
.icon { | |||
top: -2px; | |||
} | |||
.small-box-footer { | |||
color: white; | |||
padding-top: 6px; | |||
padding-bottom: 2px; | |||
} | |||
} | |||
.callout { | |||
h4 .fa { |
@@ -0,0 +1,4 @@ | |||
.dashboard-admin-index { | |||
} |
@@ -1553,4 +1553,5 @@ a.btn, button.btn { | |||
@import "online-admin/_index.scss"; | |||
@import "feature-admin/_index.scss"; | |||
@import "setting/_form.scss"; | |||
@import "dashboard-admin/_index.scss" ; | |||
@import "_responsive.scss" ; |
@@ -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 | |||
]); | |||
} | |||
} |
@@ -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']) { |
@@ -30,17 +30,52 @@ class DolibarrProducerUtils extends AbstractManager | |||
return $invoicesArray; | |||
} | |||
public function countDolibarrProducerInvoicesUnpaid(Producer $producer): int | |||
public function getDolibarrProducerInvoicesUnpaid(Producer $producer): array | |||
{ | |||
$count = 0; | |||
$unpaidInvoicesArray = []; | |||
$invoicesArray = $this->getDolibarrProducerInvoices($producer); | |||
foreach($invoicesArray as $invoice) { | |||
if($invoice['remaintopay'] > 0) { | |||
$count ++; | |||
$unpaidInvoicesArray[] = $invoice; | |||
} | |||
} | |||
return $count; | |||
return $unpaidInvoicesArray; | |||
} | |||
public function countDolibarrProducerInvoicesUnpaid(Producer $producer): int | |||
{ | |||
return count($this->getDolibarrProducerInvoicesUnpaid($producer)); | |||
} | |||
public function getDolibarrInvoicesUnpaid() | |||
{ | |||
$unpaidInvoicesArray = []; | |||
$producersArray = $this->producerRepository->findProducersActive(); | |||
foreach($producersArray as $producer) { | |||
$unpaidInvoicesArray = array_merge( | |||
$unpaidInvoicesArray, | |||
$this->getDolibarrProducerInvoicesUnpaid($producer) | |||
); | |||
} | |||
//die('test : '.count($unpaidInvoicesArray)); | |||
return $unpaidInvoicesArray; | |||
} | |||
public function getAmountProducerInvoicesUnpaid() | |||
{ | |||
$amount = 0; | |||
$unpaidInvoicesArray = $this->getDolibarrInvoicesUnpaid(); | |||
foreach($unpaidInvoicesArray as $unpaidInvoice) { | |||
$amount += $unpaidInvoice['remaintopay']; | |||
} | |||
return $amount; | |||
} | |||
public function generateDolibarrProducerInvoice(Producer $producer) |
@@ -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 |
@@ -291,4 +291,9 @@ class UserRepository extends AbstractRepository | |||
{ | |||
return count($this->findUsersWithStatusUserAndOnline()); | |||
} | |||
public function countUsersOnline(): int | |||
{ | |||
return $this->countUsersStatusUserOnline() + $this->countUsersStatusProducerOnline(); | |||
} | |||
} |