瀏覽代碼

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

feature/souke
Guillaume Bourgeois 1 年之前
父節點
當前提交
da727bcf8d
共有 12 個文件被更改,包括 240 次插入78 次删除
  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 查看文件

@@ -83,6 +83,7 @@ class DashboardController extends BackendController
'pointsSaleCount' => $this->getPointSaleContainer()->getRepository()->countPointSales(),
'distributionsArray' => $this->getDistributionContainer()->getRepository()->findDistributionsDashboard(),
'ordersArray' => $this->getOrderContainer()->getRepository()->findOrdersDashboard(),
'subscriptionsLatestAddedArray' => $this->getSubscriptionContainer()->getRepository()->findSubscriptionsLatestAdded()
]);
}
}

+ 53
- 0
backend/views/dashboard/index.php 查看文件

@@ -36,11 +36,18 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

use common\helpers\GlobalParam;
use common\logic\Order\Order\Model\Order;
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 ;

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

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

@@ -125,6 +132,52 @@ $this->setTitle('Tableau de bord');

<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 -->
<?php if(is_array($ordersArray) && count($ordersArray)): ?>
<div id="last-orders" class="">

+ 7
- 48
backend/views/subscription/index.php 查看文件

@@ -36,6 +36,7 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

use common\logic\Subscription\Subscription\Wrapper\SubscriptionManager;
use yii\helpers\Html;
use yii\grid\GridView;
use common\helpers\GlobalParam ;
@@ -45,6 +46,8 @@ use common\logic\Product\Product\Wrapper\ProductManager;
use yii\helpers\ArrayHelper;
use common\logic\Product\Product\Model\Product;

$subscriptionManager = SubscriptionManager::getInstance();

$this->setTitle('Abonnements') ;
$this->addBreadcrumb($this->getTitle()) ;
$this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon-plus"></span>', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ;
@@ -122,24 +125,8 @@ $subscriptionsArray = Subscription::searchAll() ;
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['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);
}
],
[
@@ -158,36 +145,8 @@ $subscriptionsArray = Subscription::searchAll() ;
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => '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 查看文件

@@ -35,8 +35,8 @@ class BusinessLogic
$this->getDeliveryNoteContainer(),
$this->getDocumentContainer(),
$this->getPointSaleContainer(),
$this->getSubscriptionContainer(),
$this->getProductContainer(),
$this->getSubscriptionContainer(),
$this->getDistributionContainer(),
$this->getProducerContainer(),
$this->getOrderContainer(),

+ 4
- 1
common/forms/SubscriptionForm.php 查看文件

@@ -42,6 +42,7 @@ use common\logic\Product\Product\Model\Product;
use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\Subscription\Subscription\Model\Subscription;
use common\logic\Subscription\Subscription\Wrapper\SubscriptionManager;
use common\logic\User\User\Wrapper\UserManager;
use Yii;
use yii\base\Model;

@@ -116,13 +117,15 @@ class SubscriptionForm extends Model
*/
public function save()
{
$userManager = UserManager::getInstance();
$subscriptionManager = SubscriptionManager::getInstance();

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

if ($subscription) {

+ 30
- 5
common/logic/Subscription/Subscription/Model/Subscription.php 查看文件

@@ -44,9 +44,6 @@ use common\logic\Producer\Producer\Model\Producer;
use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\User\User\Model\User;

/**
* This is the model class for table "subscription".
*/
class Subscription extends ActiveRecordCommon
{
const AUTO_PAYMENT_DEDUCTED = 1;
@@ -69,7 +66,9 @@ class Subscription extends ActiveRecordCommon
return [
[['id_producer', 'id_point_sale'], 'required'],
[['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'],
];
}
@@ -95,7 +94,11 @@ class Subscription extends ActiveRecordCommon
'sunday' => 'Dimanche',
'week_frequency' => 'Périodicité',
'auto_payment' => 'Débit automatique',
'comment' => 'Commentaire'
'comment' => 'Commentaire',
'created_at' => 'Création',
'updated_at' => 'Modification',
'created_by' => 'Créé par',
'updated_by' => 'Modifié par',
];
}

@@ -138,4 +141,26 @@ class Subscription extends ActiveRecordCommon
return $this->hasMany(ProductSubscription::class, ['id_subscription' => 'id'])
->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 查看文件

@@ -67,4 +67,12 @@ class SubscriptionRepository extends AbstractRepository
->filterByUser($user)
->count();
}

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

+ 14
- 0
common/logic/Subscription/Subscription/Repository/SubscriptionRepositoryQuery.php 查看文件

@@ -20,4 +20,18 @@ class SubscriptionRepositoryQuery extends AbstractRepositoryQuery
$this->andWhere(['subscription.id_user' => $user->id]);
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 查看文件

@@ -6,6 +6,7 @@ use common\logic\AbstractBuilder;
use common\logic\Distribution\Distribution\Repository\DistributionRepository;
use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\Subscription\Subscription\Model\Subscription;
use common\logic\User\User\Model\User;

class SubscriptionBuilder extends AbstractBuilder
{
@@ -16,18 +17,19 @@ class SubscriptionBuilder extends AbstractBuilder
$this->distributionRepository = $this->loadService(DistributionRepository::class);
}

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

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;
}

+ 80
- 0
common/logic/Subscription/Subscription/Service/SubscriptionSolver.php 查看文件

@@ -3,17 +3,22 @@
namespace common\logic\Subscription\Subscription\Service;

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\Subscription\Subscription\Model\Subscription;
use common\logic\User\User\Service\UserSolver;
use yii\helpers\Html;

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

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

/**
@@ -69,4 +74,79 @@ class SubscriptionSolver extends AbstractService implements SolverInterface

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 查看文件

@@ -0,0 +1,32 @@
<?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 查看文件

@@ -40,6 +40,7 @@ use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Wrapper\ProductManager;
use common\logic\Subscription\Subscription\Wrapper\SubscriptionManager;
use yii\helpers\Html;
use yii\grid\GridView;
use common\helpers\GlobalParam;
@@ -47,6 +48,7 @@ use yii\helpers\ArrayHelper;

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

$this->setTitle('Abonnements') ;
$this->addButton(['label' => '<span class="glyphicon glyphicon-plus"></span> Ajouter', 'url' => 'subscription/form', 'class' => 'btn btn-primary']) ;
@@ -56,25 +58,8 @@ $columns = [
'attribute' => 'product_name',
'label' => 'Produits',
'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…
取消
儲存