Browse Source

Merge branch 'dev'

prodstable
Guillaume Bourgeois 5 years ago
parent
commit
9c9330a57b
15 changed files with 282 additions and 35 deletions
  1. +5
    -0
      backend/controllers/OrderController.php
  2. +79
    -13
      backend/controllers/UserController.php
  3. +2
    -1
      backend/views/subscription/_form.php
  4. +12
    -0
      backend/views/user/_form.php
  5. +1
    -0
      backend/views/user/create.php
  6. +1
    -0
      backend/views/user/update.php
  7. +18
    -0
      backend/web/css/screen.css
  8. +1
    -0
      backend/web/sass/screen.scss
  9. +20
    -0
      backend/web/sass/user/_form.scss
  10. +23
    -0
      common/models/PointSale.php
  11. +30
    -1
      common/models/Subscription.php
  12. +8
    -1
      common/models/User.php
  13. +28
    -19
      common/models/UserSearch.php
  14. +51
    -0
      console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php
  15. +3
    -0
      producer/controllers/OrderController.php

+ 5
- 0
backend/controllers/OrderController.php View File

if($order && $processCredit) { if($order && $processCredit) {
$order->processCredit() ; $order->processCredit() ;
} }
// lien utilisateur / point de vente
if($idUser && $pointSale) {
$pointSale->linkUser($idUser) ;
}
} }
return ['success'] ; return ['success'] ;

+ 79
- 13
backend/controllers/UserController.php View File

use common\models\Distribution ; use common\models\Distribution ;
use backend\models\MailForm ; use backend\models\MailForm ;
use common\models\UserProducer ; use common\models\UserProducer ;
use common\models\UserPointSale ;
use common\models\PointSale ;


/** /**
* UserController implements the CRUD actions for User model. * UserController implements the CRUD actions for User model.
]); ]);
} }
public function initForm($model)
{
// init points de vente sélectionnés
if($model->id) {
$userPointSaleArray = UserPointSale::searchAll([
'id_user' => $model->id
]) ;
if($userPointSaleArray && count($userPointSaleArray) > 0) {
foreach($userPointSaleArray as $userPointSaleArray) {
$model->points_sale[] = $userPointSaleArray->id_point_sale ;
}
}
}
// points de vente
$pointsSaleArray = PointSale::find()
->where([
'id_producer' => Producer::getId(),
])
->joinWith(['userPointSale' => function($query) use($model) {
if($model->id) {
$query->andOnCondition('user_point_sale.id_user = '.$model->id) ;
}
}])
->all();
return [
'pointsSaleArray' => $pointsSaleArray
] ;
}
/** /**
* Creates a new User model. * Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page. * If creation is successful, the browser will be redirected to the 'view' page.
$useProducer->save(); $useProducer->save();


$model->sendMailWelcome($password) ; $model->sendMailWelcome($password) ;

return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
$this->processLinkPointSale($model) ;
Yii::$app->getSession()->setFlash('success', 'Utilisateur créé.');
$model = new User();
} }
return $this->render('create', array_merge($this->initForm($model),[
'model' => $model,
]));
} }


/** /**
$model->username = $model->email; $model->username = $model->email;
$model->sendMailWelcome($password) ; $model->sendMailWelcome($password) ;
} }
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
$this->processLinkPointSale($model) ;
Yii::$app->getSession()->setFlash('success', 'Utilisateur modifié.');
} }
} else {
}
else {
throw new UserException("Vous ne pouvez pas modifier cet utilisateur, soit parce qu'il appartient à plusieurs établissements, soit parce qu'il n'est pas lié au votre."); throw new UserException("Vous ne pouvez pas modifier cet utilisateur, soit parce qu'il appartient à plusieurs établissements, soit parce qu'il n'est pas lié au votre.");
} }
return $this->render('update', array_merge($this->initForm($model),[
'model' => $model,
]));
}
/**
* Lie un utilisateur aux points de vente sélectionnés.
*
* @param User $modelUser
*/
public function processLinkPointSale($modelUser)
{
$posts = Yii::$app->request->post() ;
UserPointSale::deleteAll([
'id_user' => $modelUser->id
]) ;
if(is_array($modelUser->points_sale) && count($modelUser->points_sale) > 0) {
foreach($modelUser->points_sale as $pointSaleId) {
$userPointSale = UserPointSale::searchOne([
'id_user' => $modelUser->id,
'id_point_sale' => $pointSaleId
]) ;
if(!$userPointSale) {
$userPointSale = new UserPointSale ;
$userPointSale->id_user = $modelUser->id ;
$userPointSale->id_point_sale = $pointSaleId ;
$userPointSale->comment = isset($posts['User']['comment_point_sale_'.$pointSaleId]) ? $posts['User']['comment_point_sale_'.$pointSaleId] : '' ;
$userPointSale->save() ;
}
}
}
} }
/** /**

+ 2
- 1
backend/views/subscription/_form.php View File

<?= $form->field($model, 'auto_payment') <?= $form->field($model, 'auto_payment')
->checkbox() ->checkbox()
->hint('Cochez cette case si vous souhaitez que le crédit pain du client soit automatiquement débité lors de la création de la commande.<br />' ->hint('Cochez cette case si vous souhaitez que le crédit pain du client soit automatiquement débité lors de la création de la commande.<br />'
. 'Attention, un compte client existant doit être spécifié en haut de ce formulaire.') ?>
. 'Attention, un compte client existant doit être spécifié en haut de ce formulaire.'
. '<br /><strong>Pris en compte uniquement dans le cas d\'un Crédit défini comme optionnel au niveau du point de vente. Dans les autres cas, il sera automatiquement déduit.</strong>') ?>
<div class="products"> <div class="products">
<h2>Produits</h2> <h2>Produits</h2>

+ 12
- 0
backend/views/user/_form.php View File

<?= $form->field($model, 'phone')->textInput() ?> <?= $form->field($model, 'phone')->textInput() ?>
<?= $form->field($model, 'email')->textInput() ?> <?= $form->field($model, 'email')->textInput() ?>
<?= $form->field($model, 'address')->textarea() ?> <?= $form->field($model, 'address')->textarea() ?>
<?= $form->field($model, 'points_sale')->checkboxlist(
ArrayHelper::map($pointsSaleArray, 'id',function($pointSale) use ($model) {
$commentUserPointSale = isset($pointSale->userPointSale[0]) ? $pointSale->userPointSale[0]->comment : '' ;
$html = Html::encode($pointSale->name);
if($pointSale->restricted_access) {
$html .= '<input type="text" placeholder="Commentaire" class="form-control" name="User[comment_point_sale_'.$pointSale->id.']" value="'.(($model->id) ? Html::encode($commentUserPointSale) : '').'" />' ;
}
return $html ;
}), [
'encode' => false
]);
?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> <?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

+ 1
- 0
backend/views/user/create.php View File

<?php else: ?> <?php else: ?>
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'pointsSaleArray' => $pointsSaleArray
]) ?> ]) ?>
<?php endif; ?> <?php endif; ?>
</div> </div>

+ 1
- 0
backend/views/user/update.php View File

<div class="user-update"> <div class="user-update">
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'pointsSaleArray' => $pointsSaleArray
]) ?> ]) ?>
</div> </div>

+ 18
- 0
backend/web/css/screen.css View File

float: right; float: right;
} }


/* line 5, ../sass/user/_form.scss */
.user-create #user-points_sale label,
.user-update #user-points_sale label {
font-weight: normal;
margin-right: 10px;
cursor: pointer;
background-color: white;
padding: 5px 10px;
border: solid 1px #e0e0e0;
}
/* line 13, ../sass/user/_form.scss */
.user-create #user-points_sale label .form-control,
.user-update #user-points_sale label .form-control {
display: inline;
width: 200px;
margin-left: 15px;
}

/* line 4, ../sass/producer/_update.scss */ /* line 4, ../sass/producer/_update.scss */
.producer-update #nav-params { .producer-update #nav-params {
margin-bottom: 30px; margin-bottom: 30px;

+ 1
- 0
backend/web/sass/screen.scss View File

@import "distribution/_index.scss" ; @import "distribution/_index.scss" ;
@import "user/_emails.scss" ; @import "user/_emails.scss" ;
@import "user/_credit.scss" ; @import "user/_credit.scss" ;
@import "user/_form.scss" ;
@import "producer/_update.scss" ; @import "producer/_update.scss" ;
@import "point_sale/_index.scss" ; @import "point_sale/_index.scss" ;

+ 20
- 0
backend/web/sass/user/_form.scss View File


.user-create,
.user-update {
#user-points_sale {
label {
font-weight: normal ;
margin-right: 10px ;
cursor: pointer ;
background-color: white ;
padding: 5px 10px ;
border: solid 1px #e0e0e0 ;
.form-control {
display: inline ;
width: 200px;
margin-left: 15px ;
}
}
}
}

+ 23
- 0
common/models/PointSale.php View File

{ {
return $this->credit_functioning ? $this->credit_functioning : Producer::getConfig('credit_functioning') ; return $this->credit_functioning ? $this->credit_functioning : Producer::getConfig('credit_functioning') ;
} }
/**
* Lie un utilisateur au point de vente.
*
* @param integer $idUser
*/
public function linkUser($idUser)
{
if($idUser) {
$userPointSale = UserPointSale::find()
->where([
'id_user' => $idUser,
'id_point_sale' => $this->id
])->one() ;

if(!$userPointSale) {
$userPointSale = new UserPointSale ;
$userPointSale->id_user = $idUser ;
$userPointSale->id_point_sale = $this->id ;
$userPointSale->save() ;
}
}
}
} }

+ 30
- 1
common/models/Subscription.php View File

use common\models\UserPointSale; use common\models\UserPointSale;
use common\models\Order; use common\models\Order;
use common\models\ProductOrder; use common\models\ProductOrder;
use common\models\User ;


/** /**
* This is the model class for table "commande_auto". * This is the model class for table "commande_auto".
$order->id_point_sale = $this->id_point_sale; $order->id_point_sale = $this->id_point_sale;
$order->id_distribution = $distribution->id; $order->id_distribution = $distribution->id;
$order->id_subscription = $this->id; $order->id_subscription = $this->id;
$order->auto_payment = $this->auto_payment ;
$pointSale = PointSale::findOne($this->id_point_sale) ;
$creditFunctioning = $pointSale->getCreditFunctioning() ;
$order->auto_payment = 0 ;
if($order->id_user && Producer::getConfig('credit') && $pointSale->credit) {
if($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) {
$order->auto_payment = $this->auto_payment ;
}
elseif($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) {
$order->auto_payment = 1 ;
}
elseif($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) {
$user = User::findOne($order->id_user) ;
$userProducer = UserProducer::searchOne([
'id_user' => $order->id_user,
'id_producer' => $distribution->id_producer
]) ;
if($userProducer) {
$order->auto_payment = $userProducer->credit_active ;
}
}
}
$userPointSale = UserPointSale::searchOne([ $userPointSale = UserPointSale::searchOne([
'id_point_sale' => $this->id_point_sale, 'id_point_sale' => $this->id_point_sale,


$order->save(); $order->save();


// liaison utilisateur / point de vente
if($order->id_user) {
$pointSale = PointSale::findOne($this->id_point_sale) ;
$pointSale->linkUser($order->id_user) ;
}
// produits // produits
$amountTotal = 0; $amountTotal = 0;
$productsAdd = false; $productsAdd = false;

+ 8
- 1
common/models/User.php View File

var $password_old; var $password_old;
var $password_new; var $password_new;
var $password_new_confirm; var $password_new_confirm;
var $points_sale = [] ;


/** /**
* @inheritdoc * @inheritdoc
['password_old', 'verifyPasswordOld'], ['password_old', 'verifyPasswordOld'],
['password_new', 'verifyPasswordNew'], ['password_new', 'verifyPasswordNew'],
['password_new_confirm', 'verifyPasswordNewConfirm'], ['password_new_confirm', 'verifyPasswordNewConfirm'],
[['date_last_connection', 'password_old', 'password_new', 'password_new_confirm', 'password_hash'], 'safe'],
[['date_last_connection', 'password_old', 'password_new', 'password_new_confirm', 'password_hash','points_sale'], 'safe'],
]; ];
} }
'password_old' => 'Ancien mot de passe', 'password_old' => 'Ancien mot de passe',
'password_new' => 'Nouveau mot de passe', 'password_new' => 'Nouveau mot de passe',
'password_new_confirm' => 'Confirmation du nouveau mot de passe', 'password_new_confirm' => 'Confirmation du nouveau mot de passe',
'points_sale' => 'Points de vente'
]; ];
} }
return $this->hasMany(UserProducer::className(), ['id_user' => 'id']); return $this->hasMany(UserProducer::className(), ['id_user' => 'id']);
} }


public function getOrder()
{
return $this->hasMany(Order::className(), ['id_user' => 'id']) ;
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

+ 28
- 19
common/models/UserSearch.php View File

{ {
$optionsSearch = self::defaultOptionsSearch() ; $optionsSearch = self::defaultOptionsSearch() ;
$query = User::find();
$query = User::find()
->select(
'`user`.id, '
.'`user`.username,'
.'`user`.email, '
.'`user`.status, '
.'`user`.created_at, '
.'`user`.updated_at, '
.'`user`.lastname, '
.'`user`.name, '
.'`user`.phone, '
.'`user`.address, '
.'`user`.no_mail, '
.'`user`.mail_distribution_monday, '
.'`user`.mail_distribution_tuesday, '
.'`user`.mail_distribution_wednesday, '
.'`user`.mail_distribution_thursday, '
.'`user`.mail_distribution_friday, '
.'`user`.mail_distribution_saturday, '
.'`user`.mail_distribution_sunday, '
.'`user`.id_producer, '
.'`user`.date_last_connection, '
. '(SELECT COUNT(*) FROM `order` WHERE `user`.id = `order`.id_user) AS count_orders');
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => $query, 'query' => $query,
return $dataProvider; return $dataProvider;
} }
$active = (isset($this->inactive) && $this->inactive) ? 0 : 1 ;
$query->innerJoin('user_producer','user.id = user_producer.id_user AND user_producer.active = '.$active.' AND user_producer.id_producer = :id_producer', [':id_producer' => Producer::getId()]) ;
$query->innerJoin('user_producer','user.id = user_producer.id_user AND user_producer.id_producer = :id_producer', [':id_producer' => Producer::getId()]) ;
if(isset($this->id_point_sale) && $this->id_point_sale) { if(isset($this->id_point_sale) && $this->id_point_sale) {
$pointSale = PointSale::findOne(['id' => $this->id_point_sale]) ; $pointSale = PointSale::findOne(['id' => $this->id_point_sale]) ;
if($pointSale->restricted_access) {
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $this->id_point_sale]) ;
}
else {
$query->innerJoin(
'order',
'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
[':id_point_sale' => $this->id_point_sale]
)->groupBy('user.id') ;
}
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $this->id_point_sale]) ;
} }
if(isset($this->inactive) && $this->inactive) { if(isset($this->inactive) && $this->inactive) {
$query->innerJoin(
'order',
'user.id = order.id_user'
)
->groupBy('user.id');
$query->having([
'count_orders' => 0
]) ;
} }
$query->andFilterWhere([ $query->andFilterWhere([
['like', 'user.name', $this->username] ['like', 'user.name', $this->username]
]); ]);
return $dataProvider; return $dataProvider;
} }

+ 51
- 0
console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php View File

<?php

use yii\db\Migration;

class m190226_084104_lien_utilisateur_point_de_vente extends Migration
{
public function up()
{
$producersArray = \common\models\Producer::find()->all() ;
foreach($producersArray as $producer) {
$pointsSaleArray = common\models\PointSale::find()
->where([
'id_producer' => $producer->id
])
->all();
foreach($pointsSaleArray as $pointSale) {
$usersArray = common\models\User::find()->innerJoin(
'order',
'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
[':id_point_sale' => $pointSale->id]
)
->groupBy('user.id')
->all();
foreach($usersArray as $user) {
$userPointSale = \common\models\UserPointSale::find()
->where([
'id_user' => $user->id,
'id_point_sale' => $pointSale->id
])->one() ;
if(!$userPointSale) {
$userPointSale = new \common\models\UserPointSale() ;
$userPointSale->id_user = $user->id ;
$userPointSale->id_point_sale = $pointSale->id ;
$userPointSale->save() ;
}
}
}
}
}

public function down()
{
echo "m190226_084104_lien_utilisateur_point_de_vente cannot be reverted.\n";
return false;
}
}

+ 3
- 0
producer/controllers/OrderController.php View File

$productOrder->save(); $productOrder->save();
} }
} }
// lien utilisateur / point de vente
$pointSale->linkUser(User::getCurrentId()) ;


// credit // credit
$credit = Producer::getConfig('credit'); $credit = Producer::getConfig('credit');

Loading…
Cancel
Save