Ver código fonte

[backend] Tableau de bord : date de début / date de fin

dev
Guillaume 4 anos atrás
pai
commit
90798cdcf3
6 arquivos alterados com 387 adições e 285 exclusões
  1. +139
    -117
      backend/controllers/ProducerController.php
  2. +190
    -154
      backend/controllers/SiteController.php
  3. +29
    -14
      backend/views/producer/update.php
  4. +4
    -0
      backend/web/js/vuejs/producer-update.js
  5. +4
    -0
      common/models/Producer.php
  6. +21
    -0
      console/migrations/m201126_090613_option_dashboard_date_start_end.php

+ 139
- 117
backend/controllers/ProducerController.php Ver arquivo

@@ -1,6 +1,6 @@
<?php

/**
/**
Copyright distrib (2018)

contact@opendistrib.net
@@ -34,7 +34,7 @@ sécurité de leurs systèmes et ou de leurs données et, plus généralement,
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;

@@ -54,127 +54,149 @@ use common\models\Invoice;
/**
* UserController implements the CRUD actions for User model.
*/
class ProducerController extends BackendController
class ProducerController extends BackendController
{

public $enableCsrfValidation = false;
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
public $enableCsrfValidation = false;

public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend();
}
]
],
],
];
}

/**
* Modifie un producteur.
*
* @return mixed
*/
public function actionUpdate()
{
$request = Yii::$app->request;
$model = $this->findModel(GlobalParam::getCurrentProducerId());
$model->secret_key_payplug = $model->getSecretKeyPayplug() ;
$logoFilenameOld = $model->logo;
$photoFilenameOld = $model->photo;
if (strlen($model->option_dashboard_date_start)) {
$model->option_dashboard_date_start = date('d/m/Y', strtotime($model->option_dashboard_date_start));
}
if (strlen($model->option_dashboard_date_end)) {
$model->option_dashboard_date_end = date('d/m/Y', strtotime($model->option_dashboard_date_end));
}

if ($model->load(Yii::$app->request->post()) && $model->save()) {

if(strlen($model->option_dashboard_date_start)) {
$model->option_dashboard_date_start = date(
'Y-m-d',
strtotime(str_replace('/', '-', $model->option_dashboard_date_start)
));
$model->save() ;
}

if(strlen($model->option_dashboard_date_end)) {
$model->option_dashboard_date_end = date(
'Y-m-d',
strtotime(str_replace('/', '-', $model->option_dashboard_date_end))
);
$model->save() ;
}

Upload::uploadFile($model, 'logo', $logoFilenameOld);
Upload::uploadFile($model, 'photo', $photoFilenameOld);

$deleteLogo = $request->post('delete_logo', 0);
if ($deleteLogo) {
$model->logo = '';
$model->save();
}
]
],
],
];
}

/**
* Modifie un producteur.
*
* @return mixed
*/
public function actionUpdate()
{
$request = Yii::$app->request;
$model = $this->findModel(GlobalParam::getCurrentProducerId());
$model->secret_key_payplug = $model->getSecretKeyPayplug() ;
$logoFilenameOld = $model->logo;
$photoFilenameOld = $model->photo;

if ($model->load(Yii::$app->request->post()) && $model->save()) {
Upload::uploadFile($model, 'logo', $logoFilenameOld);
Upload::uploadFile($model, 'photo', $photoFilenameOld);

$deleteLogo = $request->post('delete_logo', 0);
if ($deleteLogo) {
$model->logo = '';
$model->save();
}

$deletePhoto = $request->post('delete_photo', 0);
if ($deletePhoto) {
$model->photo = '';
$model->save();
}
$model->saveSecretKeyPayplug() ;
Yii::$app->getSession()->setFlash('success', 'Paramètres mis à jour.');
return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]);
} else {
if($model->load(Yii::$app->request->post())) {
Yii::$app->getSession()->setFlash('error', 'Le formulaire comporte des erreurs.');
}
return $this->render('update', [
'model' => $model,
]);

$deletePhoto = $request->post('delete_photo', 0);
if ($deletePhoto) {
$model->photo = '';
$model->save();
}

$model->saveSecretKeyPayplug() ;

Yii::$app->getSession()->setFlash('success', 'Paramètres mis à jour.');
return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]);
} else {
if($model->load(Yii::$app->request->post())) {
Yii::$app->getSession()->setFlash('error', 'Le formulaire comporte des erreurs.');
}
return $this->render('update', [
'model' => $model,
]);
}
}
}

/**
* Affiche le formulaire permettant au producteur de définir le montant
* de son abonnement.
*
* @return mixed
*/
public function actionBilling()
{
$datasInvoices = new ActiveDataProvider([
'query' => Invoice::find()
->where(['id_producer' => GlobalParam::getCurrentProducerId()])
->orderBy('reference DESC'),
'pagination' => [
'pageSize' => 1000,
],
]);

$producer = Producer::findOne(GlobalParam::getCurrentProducerId());

if ($producer->load(Yii::$app->request->post())) {
$producer->save();

if (!is_null($producer->free_price)) {
$alertFreeprice = true;
}

/**
* Affiche le formulaire permettant au producteur de définir le montant
* de son abonnement.
*
* @return mixed
*/
public function actionBilling()
{
$datasInvoices = new ActiveDataProvider([
'query' => Invoice::find()
->where(['id_producer' => GlobalParam::getCurrentProducerId()])
->orderBy('reference DESC'),
'pagination' => [
'pageSize' => 1000,
],
]);

$producer = Producer::findOne(GlobalParam::getCurrentProducerId());

if ($producer->load(Yii::$app->request->post())) {
$producer->save();

if (!is_null($producer->free_price)) {
$alertFreeprice = true;
}
}

return $this->render('billing', [
'datasInvoices' => $datasInvoices,
'producer' => $producer,
'alertFreePrice' => (isset($alertFreeprice)) ? true : false
]);
}

return $this->render('billing', [
'datasInvoices' => $datasInvoices,
'producer' => $producer,
'alertFreePrice' => (isset($alertFreeprice)) ? true : false
]);
}

/**
* Recherche un établissement via son ID.
*
* @param integer $id
* @return Etablissement
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = Producer::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
/**
* Recherche un établissement via son ID.
*
* @param integer $id
* @return Etablissement
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = Producer::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

}

+ 190
- 154
backend/controllers/SiteController.php Ver arquivo

@@ -1,6 +1,6 @@
<?php

/**
/**
Copyright distrib (2018)

contact@opendistrib.net
@@ -34,7 +34,7 @@ sécurité de leurs systèmes et ou de leurs données et, plus généralement,
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;

@@ -54,164 +54,200 @@ use common\models\Order;
/**
* Site controller
*/
class SiteController extends BackendController
class SiteController extends BackendController
{

/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend() ;
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::hasAccessBackend() ;
}
],
[
'actions' => ['change-producer'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == User::STATUS_ADMIN ;
}
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
],
],
];
}

/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}

/**
* Affiche le tableau de bord du backend avec les dernières commandes
* réalisée, les dernières inscriptions, la liste des clients ayant un crédit
* négatif etc.
*
* @return mixed
*/
public function actionIndex()
{
// commandes
$optionDashboardNumberDistributions = Producer::getConfig('option_dashboard_number_distributions') ;
$dashboardNumberDistributions = $optionDashboardNumberDistributions ? $optionDashboardNumberDistributions : 3 ;

$optionDashboardDateStart = Producer::getConfig('option_dashboard_date_start') ;
$optionDashboardDateEnd = Producer::getConfig('option_dashboard_date_end') ;

$queryDistributions = Distribution::find()->with('order') ;

if($optionDashboardDateStart || $optionDashboardDateEnd) {
if($optionDashboardDateStart) {
$queryDistributions->andWhere(['>=', 'distribution.date', $optionDashboardDateStart]) ;
}
if($optionDashboardDateEnd) {
$queryDistributions->andWhere(['<=', 'distribution.date', $optionDashboardDateEnd]) ;
}
],
[
'actions' => ['change-producer'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == User::STATUS_ADMIN ;
}
else {
$queryDistributions->andWhere(['>=', 'distribution.date', date('Y-m-d')]) ;
}


$distributionsArray = $queryDistributions->andWhere([
'distribution.id_producer' => GlobalParam::getCurrentProducerId(),
'distribution.active' => 1
])
->orderBy('date ASC')
->limit($dashboardNumberDistributions)
->all();

// dernières commandes
$paramsOrders = [] ;
if($optionDashboardDateStart || $optionDashboardDateEnd) {
$conditionsOrders = '' ;
if($optionDashboardDateStart) {
$conditionsOrders .= 'distribution.date >= :date_start' ;
$paramsOrders[':date_start'] = $optionDashboardDateStart;
}
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
],
],
];
}

/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}

/**
* Affiche le tableau de bord du backend avec les dernières commandes
* réalisée, les dernières inscriptions, la liste des clients ayant un crédit
* négatif etc.
*
* @return mixed
*/
public function actionIndex()
{
// commandes
$optionDashboardNumberDistributions = Producer::getConfig('option_dashboard_number_distributions') ;
$dashboardNumberDistributions = $optionDashboardNumberDistributions ? $optionDashboardNumberDistributions : 3 ;
$distributionsArray = Distribution::find()
->with('order')
->where(['>=', 'distribution.date', date('Y-m-d')])
->andWhere([
'distribution.id_producer' => GlobalParam::getCurrentProducerId(),
'distribution.active' => 1
])
->orderBy('date ASC')
->limit($dashboardNumberDistributions)
->all();

// dernières commandes
$ordersArray = Order::searchAll([],[
'orderby' => 'date DESC',
'conditions' => 'distribution.date > :date AND (origin = \'' . Order::ORIGIN_USER . '\' OR origin = \'' . Order::ORIGIN_ADMIN . '\' OR (origin = \'' . Order::ORIGIN_AUTO . '\' AND (date_update IS NOT NULL OR date_delete IS NOT NULL)))',
'params' => [':date' => date('Y-m-d 00:00:00')],
]);

// clients
$nbUsers = User::searchCount();

$usersArray = User::findBy()
->orderBy('created_at DESC')
->limit(5)
->all();

$usersNegativeCredit = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()])
->andWhere('user_producer.credit < 0')
->all();

// paramètres
$producer = GlobalParam::getCurrentProducer();

$productsCount = Product::searchCount() ;
$pointsSaleCount = PointSale::searchCount() ;
return $this->render('index', [
'distributionsArray' => $distributionsArray,
'ordersArray' => $ordersArray,
'usersArray' => $usersArray,
'nbUsers' => $nbUsers,
'usersNegativeCredit' => $usersNegativeCredit,
'producer' => $producer,
'productsCount' => $productsCount,
'pointsSaleCount' => $pointsSaleCount
]);
}

/**
* Affiche la page de connexion.
*
* @return mixed
*/
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
if($optionDashboardDateEnd) {
if($optionDashboardDateStart) {
$conditionsOrders .= ' AND ' ;
}
$conditionsOrders .= 'distribution.date <= :date_end' ;
$paramsOrders[':date_end'] = $optionDashboardDateEnd ;
}
}
else {
$conditionsOrders = 'distribution.date >= :date_start' ;
$paramsOrders[':date_start'] = date('Y-m-d 00:00:00') ;
}

$ordersArray = Order::searchAll([],[
'orderby' => 'date DESC',
'conditions' => $conditionsOrders.' AND (origin = \'' . Order::ORIGIN_USER . '\' OR origin = \'' . Order::ORIGIN_ADMIN . '\' OR (origin = \'' . Order::ORIGIN_AUTO . '\' AND (date_update IS NOT NULL OR date_delete IS NOT NULL)))',
'params' => $paramsOrders,
]);

// clients
$nbUsers = User::searchCount();

$usersArray = User::findBy()
->orderBy('created_at DESC')
->limit(5)
->all();

$usersNegativeCredit = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()])
->andWhere('user_producer.credit < 0')
->all();

// paramètres
$producer = GlobalParam::getCurrentProducer();

$productsCount = Product::searchCount() ;
$pointsSaleCount = PointSale::searchCount() ;

return $this->render('index', [
'distributionsArray' => $distributionsArray,
'ordersArray' => $ordersArray,
'usersArray' => $usersArray,
'nbUsers' => $nbUsers,
'usersNegativeCredit' => $usersNegativeCredit,
'producer' => $producer,
'productsCount' => $productsCount,
'pointsSaleCount' => $pointsSaleCount
]);
}

/**
* Affiche la page de connexion.
*
* @return mixed
*/
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}

$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model,
]);
}
}

/**
* Déconnecte l'utilisateur et le redirige à la page d'accueil.
*
* @return mixed
*/
public function actionLogout()
{
Yii::$app->user->logout();

return $this->goHome();
}

$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model,
]);
/**
* Change le producteur courant de l'utilisateur connecté.
* Permet de passer d'un producteur à un autre en tant qu'administrateur.
*
* @param integer $id
*/
public function actionChangeProducer($id)
{
Yii::$app->user->identity->id_producer = $id;
Yii::$app->user->identity->save();
$this->redirect(['site/index']);
}
}

/**
* Déconnecte l'utilisateur et le redirige à la page d'accueil.
*
* @return mixed
*/
public function actionLogout()
{
Yii::$app->user->logout();

return $this->goHome();
}

/**
* Change le producteur courant de l'utilisateur connecté.
* Permet de passer d'un producteur à un autre en tant qu'administrateur.
*
* @param integer $id
*/
public function actionChangeProducer($id)
{
Yii::$app->user->identity->id_producer = $id;
Yii::$app->user->identity->save();
$this->redirect(['site/index']);
}

}

+ 29
- 14
backend/views/producer/update.php Ver arquivo

@@ -107,23 +107,38 @@ $this->addBreadcrumb($this->getTitle()) ;
Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK => 'Jours de la semaine',
Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_INCOMING_DISTRIBUTIONS => 'Distributions à venir',
]); ?>
</div>
</div>

<?= $form->field($model, 'option_dashboard_number_distributions')
->dropDownList([
3 => '3',
6 => '6',
9 => '9',
12 => '12',
15 => '15',
18 => '18',
21 => '21',
24 => '24',
27 => '27',
30 => '30',
], []); ?>
<div v-show="currentSection == 'tableau-bord'" class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Tableau de bord</h3>
</div>
<div class="panel-body">

<?= $form->field($model, 'option_dashboard_number_distributions')
->dropDownList([
3 => '3',
6 => '6',
9 => '9',
12 => '12',
15 => '15',
18 => '18',
21 => '21',
24 => '24',
27 => '27',
30 => '30',
], []); ?>

<?= $form->field($model, 'option_dashboard_date_start')->textInput([
'class' => 'datepicker form-control'
]) ; ?>
<?= $form->field($model, 'option_dashboard_date_end')->textInput([
'class' => 'datepicker form-control'
]) ; ?>
</div>
</div>
<div v-show="currentSection == 'prise-commande'" class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Prise de commande</h3>

+ 4
- 0
backend/web/js/vuejs/producer-update.js Ver arquivo

@@ -44,6 +44,10 @@ var app = new Vue({
name: 'general',
nameDisplay: 'Général'
},
{
name: 'tableau-bord',
nameDisplay: 'Tableau de bord'
},
{
name: 'prise-commande',
nameDisplay: 'Prise de commande'

+ 4
- 0
common/models/Producer.php Ver arquivo

@@ -138,6 +138,8 @@ class Producer extends ActiveRecordCommon
[['name', 'siret', 'logo', 'photo', 'postcode', 'city', 'code', 'type', 'credit_functioning', 'option_behavior_cancel_order', 'document_quotation_prefix', 'document_quotation_first_reference', 'document_invoice_prefix', 'document_invoice_first_reference', 'document_delivery_note_prefix', 'document_delivery_note_first_reference'], 'string', 'max' => 255],
[['free_price', 'credit_limit_reminder', 'credit_limit'], 'double'],
['free_price', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'],
//[['option_dashboard_date_start', 'option_dashboard_date_end'], 'date', 'format' => 'php:d/m/Y'],
[['option_dashboard_date_start', 'option_dashboard_date_end'], 'safe'],
];
}

@@ -217,6 +219,8 @@ class Producer extends ActiveRecordCommon
'option_email_confirm' => 'Envoyer un email de confirmation au client',
'option_email_confirm_producer' => 'Envoyer un email de confirmation au producteur',
'option_dashboard_number_distributions' => 'Nombre de distributions affichées sur le tableau de board',
'option_dashboard_date_start' => 'Date de début',
'option_dashboard_date_end' => 'Date de fin',
];
}


+ 21
- 0
console/migrations/m201126_090613_option_dashboard_date_start_end.php Ver arquivo

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

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

class m201126_090613_option_dashboard_date_start_end extends Migration
{
public function safeUp()
{
$this->addColumn('producer', 'option_dashboard_date_start', Schema::TYPE_DATE);
$this->addColumn('producer', 'option_dashboard_date_end', Schema::TYPE_DATE);
}

public function safeDown()
{
$this->dropColumn('producer', 'option_dashboard_date_start');
$this->dropColumn('producer', 'option_dashboard_date_end');

return false;
}
}

Carregando…
Cancelar
Salvar