Browse Source

[Administration] Tableau de bord : afficher les derniers abonnements ajoutés #1243

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
da727bcf8d
12 changed files with 240 additions and 78 deletions
  1. +1
    -0
      backend/controllers/DashboardController.php
  2. +53
    -0
      backend/views/dashboard/index.php
  3. +7
    -48
      backend/views/subscription/index.php
  4. +1
    -1
      common/components/BusinessLogic.php
  5. +4
    -1
      common/forms/SubscriptionForm.php
  6. +30
    -5
      common/logic/Subscription/Subscription/Model/Subscription.php
  7. +8
    -0
      common/logic/Subscription/Subscription/Repository/SubscriptionRepository.php
  8. +14
    -0
      common/logic/Subscription/Subscription/Repository/SubscriptionRepositoryQuery.php
  9. +6
    -4
      common/logic/Subscription/Subscription/Service/SubscriptionBuilder.php
  10. +80
    -0
      common/logic/Subscription/Subscription/Service/SubscriptionSolver.php
  11. +32
    -0
      console/migrations/m231006_084312_add_columns_subscription_created_updated.php
  12. +4
    -19
      producer/views/subscription/index.php

+ 1
- 0
backend/controllers/DashboardController.php View File

'pointsSaleCount' => $this->getPointSaleContainer()->getRepository()->countPointSales(), 'pointsSaleCount' => $this->getPointSaleContainer()->getRepository()->countPointSales(),
'distributionsArray' => $this->getDistributionContainer()->getRepository()->findDistributionsDashboard(), 'distributionsArray' => $this->getDistributionContainer()->getRepository()->findDistributionsDashboard(),
'ordersArray' => $this->getOrderContainer()->getRepository()->findOrdersDashboard(), 'ordersArray' => $this->getOrderContainer()->getRepository()->findOrdersDashboard(),
'subscriptionsLatestAddedArray' => $this->getSubscriptionContainer()->getRepository()->findSubscriptionsLatestAdded()
]); ]);
} }
} }

+ 53
- 0
backend/views/dashboard/index.php View File

termes. termes.
*/ */


use common\helpers\GlobalParam;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Wrapper\OrderManager; use common\logic\Order\Order\Wrapper\OrderManager;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use common\logic\Subscription\Subscription\Wrapper\SubscriptionManager;
use common\logic\User\User\Wrapper\UserManager;
use yii\helpers\Html ; use yii\helpers\Html ;


$userManager = UserManager::getInstance();
$orderManager = OrderManager::getInstance(); $orderManager = OrderManager::getInstance();
$subscriptionManager = SubscriptionManager::getInstance();
$producerManager = ProducerManager::getInstance();


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




<div class="clr"></div> <div class="clr"></div>


<?php if(is_array($subscriptionsLatestAddedArray) && count($subscriptionsLatestAddedArray)): ?>

<div id="last-subscriptions">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Derniers abonnements créés
</h3>
</div>
<div class="panel-body">
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Client</th>
<th>Point de vente</th>
<th>Produits</th>
<th>Jours</th>
<th>Période</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach($subscriptionsLatestAddedArray as $subscription): ?>
<tr>
<td><?= date('d/m/Y à H:i', strtotime($subscription->created_at)); ?></td>
<td><?= $userManager->getUsername($subscription->user); ?></td>
<td><?= Html::encode($subscription->pointSale->name); ?></td>
<td><?= $subscriptionManager->getProductsListAsHtml($subscription); ?></td>
<td><?= $subscriptionManager->getDaysAsHtml($subscription); ?></td>
<td><?= $subscriptionManager->getPeriodAsHtml($subscription); ?></td>
<td>
<a href="<?= $this->getUrlManager()->createUrl(['subscription/update', 'id' => $subscription->id]) ?>" class="btn btn-default">
<span class="glyphicon glyphicon-pencil"></span>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<div class="clr"></div>
<?php endif; ?>

<!-- dernières commandes --> <!-- dernières commandes -->
<?php if(is_array($ordersArray) && count($ordersArray)): ?> <?php if(is_array($ordersArray) && count($ordersArray)): ?>
<div id="last-orders" class=""> <div id="last-orders" class="">

+ 7
- 48
backend/views/subscription/index.php View File

termes. termes.
*/ */


use common\logic\Subscription\Subscription\Wrapper\SubscriptionManager;
use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
use common\helpers\GlobalParam ; use common\helpers\GlobalParam ;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use common\logic\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;


$subscriptionManager = SubscriptionManager::getInstance();

$this->setTitle('Abonnements') ; $this->setTitle('Abonnements') ;
$this->addBreadcrumb($this->getTitle()) ; $this->addBreadcrumb($this->getTitle()) ;
$this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon-plus"></span>', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ; $this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon-plus"></span>', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ;
'headerOptions' => ['class' => 'column-hide-on-mobile'], 'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'], 'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'], 'contentOptions' => ['class' => 'column-hide-on-mobile'],
'value' => function($model) {
$html = '<small>' ;
if($model->date_end) {
$html .= 'Du&nbsp;' ;
}
else {
$html .= 'À partir du ' ;
}
$html .= '</small>' ;
$html .= date('d/m/Y',strtotime($model->date_begin)) ;
if($model->date_end) {
$html .= '<br />au&nbsp;'.date('d/m/Y',strtotime($model->date_end)) ;
if(date('Y-m-d') > $model->date_end) {
$html .= ' <span class="label label-danger">Terminé</span>' ;
}
}

return $html ;
'value' => function($model) use ($subscriptionManager) {
return $subscriptionManager->getPeriodAsHtml($model);
} }
], ],
[ [
'headerOptions' => ['class' => 'column-hide-on-mobile'], 'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'], 'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'text-small column-hide-on-mobile'], 'contentOptions' => ['class' => 'text-small column-hide-on-mobile'],
'value' => function($model) {
$html = '' ;
if($model->monday) {
$html .= 'lundi, ' ;
}
if($model->tuesday) {
$html .= 'mardi, ' ;
}
if($model->wednesday) {
$html .= 'mercredi, ' ;
}
if($model->thursday) {
$html .= 'jeudi, ' ;
}
if($model->friday) {
$html .= 'vendredi, ' ;
}
if($model->saturday) {
$html .= 'samedi, ' ;
}
if($model->sunday) {
$html .= 'dimanche, ' ;
}
if(strlen($html)) {
return substr ($html, 0, strlen($html) - 2) ;
}
else {
return '<span class="glyphicon glyphicon-warning-sign"></span> Aucun jour' ;
}
'value' => function($model) use ($subscriptionManager) {
return $subscriptionManager->getDaysAsHtml($model);
} }
], ],
[ [

+ 1
- 1
common/components/BusinessLogic.php View File

$this->getDeliveryNoteContainer(), $this->getDeliveryNoteContainer(),
$this->getDocumentContainer(), $this->getDocumentContainer(),
$this->getPointSaleContainer(), $this->getPointSaleContainer(),
$this->getSubscriptionContainer(),
$this->getProductContainer(), $this->getProductContainer(),
$this->getSubscriptionContainer(),
$this->getDistributionContainer(), $this->getDistributionContainer(),
$this->getProducerContainer(), $this->getProducerContainer(),
$this->getOrderContainer(), $this->getOrderContainer(),

+ 4
- 1
common/forms/SubscriptionForm.php View File

use common\logic\Subscription\ProductSubscription\Model\ProductSubscription; use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\Subscription\Subscription\Model\Subscription; use common\logic\Subscription\Subscription\Model\Subscription;
use common\logic\Subscription\Subscription\Wrapper\SubscriptionManager; use common\logic\Subscription\Subscription\Wrapper\SubscriptionManager;
use common\logic\User\User\Wrapper\UserManager;
use Yii; use Yii;
use yii\base\Model; use yii\base\Model;


*/ */
public function save() public function save()
{ {
$userManager = UserManager::getInstance();
$subscriptionManager = SubscriptionManager::getInstance(); $subscriptionManager = SubscriptionManager::getInstance();


if ($this->id) { if ($this->id) {
$subscription = Subscription::searchOne(['id' => $this->id]) ; $subscription = Subscription::searchOne(['id' => $this->id]) ;
$subscription->populateUpdatedBy($userManager->getCurrent());
} }
else { else {
$subscription = $subscriptionManager->instanciateSubscription() ;
$subscription = $subscriptionManager->instanciateSubscription($userManager->getCurrent()) ;
} }


if ($subscription) { if ($subscription) {

+ 30
- 5
common/logic/Subscription/Subscription/Model/Subscription.php View File

use common\logic\Subscription\ProductSubscription\Model\ProductSubscription; use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\User\User\Model\User; use common\logic\User\User\Model\User;


/**
* This is the model class for table "subscription".
*/
class Subscription extends ActiveRecordCommon class Subscription extends ActiveRecordCommon
{ {
const AUTO_PAYMENT_DEDUCTED = 1; const AUTO_PAYMENT_DEDUCTED = 1;
return [ return [
[['id_producer', 'id_point_sale'], 'required'], [['id_producer', 'id_point_sale'], 'required'],
[['id_user', 'id_producer', 'id_point_sale', 'monday', 'tuesday', [['id_user', 'id_producer', 'id_point_sale', 'monday', 'tuesday',
'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'week_frequency', 'auto_payment'], 'integer'],
'wednesday', 'thursday', 'friday', 'saturday', 'sunday',
'week_frequency', 'auto_payment', 'id_created_by', 'id_updated_by'], 'integer'],
[['created_at', 'updated_at'], 'datetime', 'format' => 'php:Y-m-d H:i:s'],
[['username', 'comment', 'date_begin', 'date_end'], 'safe'], [['username', 'comment', 'date_begin', 'date_end'], 'safe'],
]; ];
} }
'sunday' => 'Dimanche', 'sunday' => 'Dimanche',
'week_frequency' => 'Périodicité', 'week_frequency' => 'Périodicité',
'auto_payment' => 'Débit automatique', 'auto_payment' => 'Débit automatique',
'comment' => 'Commentaire'
'comment' => 'Commentaire',
'created_at' => 'Création',
'updated_at' => 'Modification',
'created_by' => 'Créé par',
'updated_by' => 'Modifié par',
]; ];
} }


return $this->hasMany(ProductSubscription::class, ['id_subscription' => 'id']) return $this->hasMany(ProductSubscription::class, ['id_subscription' => 'id'])
->with('product'); ->with('product');
} }

public function getCreatedBy()
{
return $this->hasOne(User::class, ['id' => 'id_created_by']);
}

public function populateCreatedBy(User $createdBy): void
{
$this->populateFieldObject('id_created_by', 'createdBy', $createdBy);
$this->created_at = date('Y-m-d H:i:s');
}

public function getUpdatedBy()
{
return $this->hasOne(User::class, ['id' => 'id_updated_by']);
}

public function populateUpdatedBy(User $updatedBy): void
{
$this->populateFieldObject('id_updated_by', 'updatedBy', $updatedBy);
$this->updated_at = date('Y-m-d H:i:s');
}
} }

+ 8
- 0
common/logic/Subscription/Subscription/Repository/SubscriptionRepository.php View File

->filterByUser($user) ->filterByUser($user)
->count(); ->count();
} }

public function findSubscriptionsLatestAdded()
{
return $this->createDefaultQuery()
->filterByCreatedDuringPastWeek()
->filterByCreatedByUser()
->find();
}
} }

+ 14
- 0
common/logic/Subscription/Subscription/Repository/SubscriptionRepositoryQuery.php View File

$this->andWhere(['subscription.id_user' => $user->id]); $this->andWhere(['subscription.id_user' => $user->id]);
return $this; return $this;
} }

public function filterByCreatedDuringPastWeek(): self
{
$datePastWeek = new \DateTime('-7 days');
$this->andWhere('subscription.created_at >= :created_at')
->addParams(['created_at' => $datePastWeek->format('Y-m-d H:i:s')]);
return $this;
}

public function filterByCreatedByUser(): self
{
$this->andWhere('subscription.id_user = subscription.id_created_by');
return $this;
}
} }

+ 6
- 4
common/logic/Subscription/Subscription/Service/SubscriptionBuilder.php View File

use common\logic\Distribution\Distribution\Repository\DistributionRepository; use common\logic\Distribution\Distribution\Repository\DistributionRepository;
use common\logic\Subscription\ProductSubscription\Model\ProductSubscription; use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\Subscription\Subscription\Model\Subscription; use common\logic\Subscription\Subscription\Model\Subscription;
use common\logic\User\User\Model\User;


class SubscriptionBuilder extends AbstractBuilder class SubscriptionBuilder extends AbstractBuilder
{ {
$this->distributionRepository = $this->loadService(DistributionRepository::class); $this->distributionRepository = $this->loadService(DistributionRepository::class);
} }


public function instanciateSubscription(): Subscription
public function instanciateSubscription(User $createdBy): Subscription
{ {
$subscription = new Subscription(); $subscription = new Subscription();
$subscription->auto_payment = Subscription::AUTO_PAYMENT_DEDUCTED; $subscription->auto_payment = Subscription::AUTO_PAYMENT_DEDUCTED;
$subscription->populateCreatedBy($createdBy);


return $subscription; return $subscription;
} }


public function createSubscription(): Subscription
public function createSubscription(User $createdBy): Subscription
{ {
$subscription = $this->instanciateSubscription();
$this->saveCreate($subscription);
$subscription = $this->instanciateSubscription($createdBy);
$this->create($subscription);


return $subscription; return $subscription;
} }

+ 80
- 0
common/logic/Subscription/Subscription/Service/SubscriptionSolver.php View File

namespace common\logic\Subscription\Subscription\Service; namespace common\logic\Subscription\Subscription\Service;


use common\logic\AbstractService; use common\logic\AbstractService;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Service\ProductSolver;
use common\logic\SolverInterface; use common\logic\SolverInterface;
use common\logic\Subscription\Subscription\Model\Subscription; use common\logic\Subscription\Subscription\Model\Subscription;
use common\logic\User\User\Service\UserSolver; use common\logic\User\User\Service\UserSolver;
use yii\helpers\Html;


class SubscriptionSolver extends AbstractService implements SolverInterface class SubscriptionSolver extends AbstractService implements SolverInterface
{ {
protected UserSolver $userSolver; protected UserSolver $userSolver;
protected ProductSolver $productSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->userSolver = $this->loadService(UserSolver::class); $this->userSolver = $this->loadService(UserSolver::class);
$this->productSolver = $this->loadService(ProductSolver::class);
} }


/** /**


return false; return false;
} }

public function getProductsListAsHtml(Subscription $subscription): string
{
$html = '' ;
foreach($subscription->productSubscription as $productSubscription)
{
if(isset($productSubscription->product) && $productSubscription->product) {
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']) . '&nbsp'. $this->productSolver->strUnit($productSubscription->product->unit, 'wording_short').')<br />' ;
}
else {
$html .= 'Produit non défini<br />' ;
}
}

if(!count($subscription->productSubscription))
{
$html .= '<span class="glyphicon glyphicon-warning-sign"></span> Aucun produit' ;
}

return $html ;
}

public function getPeriodAsHtml(Subscription $subscription): string
{
$html = '<small>' ;
if($subscription->date_end) {
$html .= 'Du&nbsp;' ;
}
else {
$html .= 'À partir du ' ;
}
$html .= '</small>' ;
$html .= date('d/m/Y',strtotime($subscription->date_begin)) ;
if($subscription->date_end) {
$html .= '<br />au&nbsp;'.date('d/m/Y',strtotime($subscription->date_end)) ;
if(date('Y-m-d') > $subscription->date_end) {
$html .= ' <span class="label label-danger">Terminé</span>' ;
}
}

return $html ;
}

public function getDaysAsHtml(Subscription $subscription): string
{
$html = '' ;
if($subscription->monday) {
$html .= 'lundi, ' ;
}
if($subscription->tuesday) {
$html .= 'mardi, ' ;
}
if($subscription->wednesday) {
$html .= 'mercredi, ' ;
}
if($subscription->thursday) {
$html .= 'jeudi, ' ;
}
if($subscription->friday) {
$html .= 'vendredi, ' ;
}
if($subscription->saturday) {
$html .= 'samedi, ' ;
}
if($subscription->sunday) {
$html .= 'dimanche, ' ;
}

if(strlen($html)) {
return substr ($html, 0, strlen($html) - 2) ;
}
else {
return '<span class="glyphicon glyphicon-warning-sign"></span> Aucun jour' ;
}
}
} }

+ 32
- 0
console/migrations/m231006_084312_add_columns_subscription_created_updated.php View File

<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m231006_084312_add_columns_subscription_created_updated
*/
class m231006_084312_add_columns_subscription_created_updated extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('subscription', 'id_created_by', Schema::TYPE_INTEGER);
$this->addColumn('subscription', 'created_at', Schema::TYPE_DATETIME);
$this->addColumn('subscription', 'id_updated_by', Schema::TYPE_INTEGER);
$this->addColumn('subscription', 'updated_at', Schema::TYPE_DATETIME);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('subscription', 'id_created_by');
$this->dropColumn('subscription', 'created_at');
$this->dropColumn('subscription', 'id_updated_by');
$this->dropColumn('subscription', 'updated_at');
}
}

+ 4
- 19
producer/views/subscription/index.php View File

use common\logic\Producer\Producer\Wrapper\ProducerManager; use common\logic\Producer\Producer\Wrapper\ProducerManager;
use common\logic\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Wrapper\ProductManager; use common\logic\Product\Product\Wrapper\ProductManager;
use common\logic\Subscription\Subscription\Wrapper\SubscriptionManager;
use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;


$producerManager = ProducerManager::getInstance(); $producerManager = ProducerManager::getInstance();
$productManager = ProductManager::getInstance(); $productManager = ProductManager::getInstance();
$subscriptionManager = SubscriptionManager::getInstance();


$this->setTitle('Abonnements') ; $this->setTitle('Abonnements') ;
$this->addButton(['label' => '<span class="glyphicon glyphicon-plus"></span> Ajouter', 'url' => 'subscription/form', 'class' => 'btn btn-primary']) ; $this->addButton(['label' => '<span class="glyphicon glyphicon-plus"></span> Ajouter', 'url' => 'subscription/form', 'class' => 'btn btn-primary']) ;
'attribute' => 'product_name', 'attribute' => 'product_name',
'label' => 'Produits', 'label' => 'Produits',
'format' => 'raw', 'format' => 'raw',
'value' => function($model) use ($productManager) {
$html = '' ;
foreach($model->productSubscription as $productSubscription)
{
if(isset($productSubscription->product) && $productSubscription->product) {
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']) . '&nbsp'. $productManager->strUnit($productSubscription->product->unit, 'wording_short').')<br />' ;
}
else {
$html .= 'Produit non défini<br />' ;
}
}

// aucun produit
if(!count($model->productSubscription))
{
$html .= '<span class="glyphicon glyphicon-warning-sign"></span> Aucun produit' ;
}

return $html ;
'value' => function($subscription) use ($subscriptionManager) {
return $subscriptionManager->getProductsListAsHtml($subscription);
} }
], ],
[ [

Loading…
Cancel
Save