Tri des utilisateurs par ordre alphabétique, Possibilité de mettre un utilisateur non inscrit.prodstable
->where(['id_etablissement' => $model->id_etablissement]) | ->where(['id_etablissement' => $model->id_etablissement]) | ||||
->orderBy('order ASC') | ->orderBy('order ASC') | ||||
->all(); | ->all(); | ||||
if($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) | if($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) | ||||
{ | { | ||||
$model->id = $id ; | $model->id = $id ; | ||||
$model->id_etablissement = $commandeauto->id_etablissement ; | $model->id_etablissement = $commandeauto->id_etablissement ; | ||||
$model->id_user = $commandeauto->id_user ; | $model->id_user = $commandeauto->id_user ; | ||||
$model->username = $commandeauto->username ; | |||||
$model->id_point_vente = $commandeauto->id_point_vente ; | $model->id_point_vente = $commandeauto->id_point_vente ; | ||||
$model->date_debut = date('d/m/Y',strtotime($commandeauto->date_debut)) ; | $model->date_debut = date('d/m/Y',strtotime($commandeauto->date_debut)) ; | ||||
if(strlen($model->date_fin)) | if(strlen($model->date_fin)) |
<span class="user"> | <span class="user"> | ||||
<?php if(isset($c->user)): ?> | <?php if(isset($c->user)): ?> | ||||
<?= Html::encode($c->user->nom.' '.$c->user->prenom); ?> | <?= Html::encode($c->user->nom.' '.$c->user->prenom); ?> | ||||
<?php if($c->type): ?> | |||||
<?php if($c->type == Commande::TYPE_ADMIN): ?> | |||||
<span class="label label-warning">vous</span> | |||||
<?php elseif($c->type == Commande::TYPE_AUTO): ?> | |||||
<span class="label label-default">auto</span> | |||||
<?php elseif($c->type == Commande::TYPE_USER): ?> | |||||
<span class="label label-success">client</span> | |||||
<?php endif; ?> | |||||
<?php endif; ?> | |||||
<?php else: ?> | <?php else: ?> | ||||
<?= Html::encode($c->username); ?> | <?= Html::encode($c->username); ?> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<?php if($c->type): ?> | |||||
<?php if($c->type == Commande::TYPE_ADMIN): ?> | |||||
<span class="label label-warning">vous</span> | |||||
<?php elseif($c->type == Commande::TYPE_AUTO): ?> | |||||
<span class="label label-default">auto</span> | |||||
<?php elseif($c->type == Commande::TYPE_USER): ?> | |||||
<span class="label label-success">client</span> | |||||
<?php endif; ?> | |||||
<?php endif; ?> | |||||
</span> | </span> | ||||
<?php if (strlen($c->commentaire)): ?> | <?php if (strlen($c->commentaire)): ?> | ||||
<span class="glyphicon glyphicon-comment"></span> | <span class="glyphicon glyphicon-comment"></span> |
?> | ?> | ||||
<div class="commandeauto-form"> | <div class="commandeauto-form"> | ||||
<?php $form = ActiveForm::begin(); ?> | |||||
<?= $form->field($model, 'id_user')->dropDownList( ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->all(), 'id', function($model, $defaultValue) { | |||||
return $model['nom'].' '.$model['prenom']; | |||||
}), ['prompt' => '--','class' => 'form-control user-id', ]) ?> | |||||
<?php $form = ActiveForm::begin(['enableClientValidation' => false]); ?> | |||||
<div class="col-md-5" id="bloc-select-user"> | |||||
<?= $form->field($model, 'id_user')->dropDownList( ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->orderBy('nom ASC, prenom ASC')->all(), 'id', function($model, $defaultValue) { | |||||
return $model['nom'].' '.$model['prenom']; | |||||
}), ['prompt' => '--','class' => 'form-control user-id', ]) ?> | |||||
</div> | |||||
<div class="col-md-1" id="or-user"> | |||||
<span>OU</span> | |||||
</div> | |||||
<div class="col-md-6"> | |||||
<?= $form->field($model, 'username')->textInput() ?> | |||||
</div> | |||||
<div class="clr"></div> | |||||
<?= $form->field($model, 'id_etablissement')->hiddenInput() ?> | <?= $form->field($model, 'id_etablissement')->hiddenInput() ?> | ||||
<?= $form->field($model, 'id_point_vente')->dropDownList( ArrayHelper::map(PointVente::find()->where('id_etablissement = '.Yii::$app->user->identity->id_etablissement)->all(), 'id', function($model, $defaultValue) { | <?= $form->field($model, 'id_point_vente')->dropDownList( ArrayHelper::map(PointVente::find()->where('id_etablissement = '.Yii::$app->user->identity->id_etablissement)->all(), 'id', function($model, $defaultValue) { | ||||
return $model['nom']; | return $model['nom']; |
<?= GridView::widget([ | <?= GridView::widget([ | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'columns' => [ | 'columns' => [ | ||||
[ | [ | ||||
'attribute' => 'id_user', | 'attribute' => 'id_user', | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function($model) { | 'value' => function($model) { | ||||
return Html::encode($model->user->nom.' '.$model->user->prenom) ; | |||||
if(strlen($model->username)) | |||||
{ | |||||
return Html::encode($model->username) ; | |||||
} | |||||
else { | |||||
return Html::encode($model->user->nom.' '.$model->user->prenom) ; | |||||
} | |||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
return 'indéterminée' ; | return 'indéterminée' ; | ||||
} | } | ||||
], | ], | ||||
[ | |||||
'attribute' => 'lundi', | |||||
'label' => 'Jours', | |||||
'value' => function($model) { | |||||
$html = '' ; | |||||
if($model->lundi) | |||||
$html .= 'lundi, ' ; | |||||
if($model->mardi) | |||||
$html .= 'mardi, ' ; | |||||
if($model->mercredi) | |||||
$html .= 'mercredi, ' ; | |||||
if($model->jeudi) | |||||
$html .= 'jeudi, ' ; | |||||
if($model->vendredi) | |||||
$html .= 'vendredi, ' ; | |||||
if($model->samedi) | |||||
$html .= 'samedi, ' ; | |||||
if($model->dimanche) | |||||
$html .= 'dimanche, ' ; | |||||
if(strlen($html)) | |||||
return substr ($html, 0, strlen($html) - 2) ; | |||||
else | |||||
return '' ; | |||||
} | |||||
], | |||||
[ | [ | ||||
'attribute' => 'periodicite_semaine', | 'attribute' => 'periodicite_semaine', | ||||
'value' => function($model) { | 'value' => function($model) { |
} | } | ||||
/* commandes auto */ | /* commandes auto */ | ||||
/* line 860, ../sass/screen.scss */ | |||||
/* line 861, ../sass/screen.scss */ | |||||
.commandeauto-form #bloc-select-user { | |||||
padding-left: 0px; | |||||
} | |||||
/* line 865, ../sass/screen.scss */ | |||||
.commandeauto-form #or-user { | |||||
font-size: 20px; | |||||
text-align: center; | |||||
} | |||||
/* line 868, ../sass/screen.scss */ | |||||
.commandeauto-form #or-user span { | |||||
position: relative; | |||||
top: 24px; | |||||
} | |||||
/* line 874, ../sass/screen.scss */ | |||||
.commandeauto-form .field-commandeautoform-id_etablissement { | .commandeauto-form .field-commandeautoform-id_etablissement { | ||||
display: none; | display: none; | ||||
} | } | ||||
/* line 864, ../sass/screen.scss */ | |||||
/* line 878, ../sass/screen.scss */ | |||||
.commandeauto-form .jours .form-group { | .commandeauto-form .jours .form-group { | ||||
float: left; | float: left; | ||||
margin-right: 20px; | margin-right: 20px; | ||||
} | } | ||||
/* line 871, ../sass/screen.scss */ | |||||
/* line 885, ../sass/screen.scss */ | |||||
.commandeauto-form .produits .table { | .commandeauto-form .produits .table { | ||||
width: 500px; | width: 500px; | ||||
} | } | ||||
/* line 874, ../sass/screen.scss */ | |||||
/* line 888, ../sass/screen.scss */ | |||||
.commandeauto-form .produits .quantite { | .commandeauto-form .produits .quantite { | ||||
text-align: center; | text-align: center; | ||||
} | } | ||||
/* points de vente */ | /* points de vente */ | ||||
/* line 883, ../sass/screen.scss */ | |||||
/* line 897, ../sass/screen.scss */ | |||||
.point-vente-form #pointvente-users { | .point-vente-form #pointvente-users { | ||||
display: none; | display: none; | ||||
height: 500px; | height: 500px; | ||||
overflow-y: scroll; | overflow-y: scroll; | ||||
} | } | ||||
/* line 887, ../sass/screen.scss */ | |||||
/* line 901, ../sass/screen.scss */ | |||||
.point-vente-form #pointvente-users label { | .point-vente-form #pointvente-users label { | ||||
font-weight: normal; | font-weight: normal; | ||||
display: block; | display: block; |
/* commandes auto */ | /* commandes auto */ | ||||
.commandeauto-form { | .commandeauto-form { | ||||
#bloc-select-user { | |||||
padding-left: 0px ; | |||||
} | |||||
#or-user { | |||||
font-size: 20px ; | |||||
text-align: center ; | |||||
span { | |||||
position: relative ; | |||||
top: 24px ; | |||||
} | |||||
} | |||||
.field-commandeautoform-id_etablissement { | .field-commandeautoform-id_etablissement { | ||||
display: none ; | display: none ; | ||||
} | } |
* @property integer $samedi | * @property integer $samedi | ||||
* @property integer $dimanche | * @property integer $dimanche | ||||
* @property integer $periodicite_semaine | * @property integer $periodicite_semaine | ||||
* @property string $username | |||||
*/ | */ | ||||
class CommandeAuto extends \yii\db\ActiveRecord | class CommandeAuto extends \yii\db\ActiveRecord | ||||
{ | { | ||||
public function rules() | public function rules() | ||||
{ | { | ||||
return [ | return [ | ||||
[['id_user', 'id_etablissement', 'id_point_vente'], 'required'], | |||||
[['id_etablissement', 'id_point_vente'], 'required'], | |||||
[['id_user', 'id_etablissement', 'id_point_vente', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'periodicite_semaine'], 'integer'], | [['id_user', 'id_etablissement', 'id_point_vente', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'periodicite_semaine'], 'integer'], | ||||
[['date_debut', 'date_fin'], 'safe'], | |||||
[['date_debut', 'date_fin','username'], 'safe'], | |||||
]; | ]; | ||||
} | } | ||||
$jour = date('N', strtotime($date)) ; | $jour = date('N', strtotime($date)) ; | ||||
switch($jour) | switch($jour) | ||||
{ | { | ||||
case 1 : $jour = 'lundi' ; | |||||
case 2 : $jour = 'mardi' ; | |||||
case 3 : $jour = 'mercredi' ; | |||||
case 4 : $jour = 'jeudi' ; | |||||
case 5 : $jour = 'vendredi' ; | |||||
case 6 : $jour = 'samedi' ; | |||||
case 7 : $jour = 'dimanche' ; | |||||
case 1 : $jour = 'lundi' ; break ; | |||||
case 2 : $jour = 'mardi' ; break ; | |||||
case 3 : $jour = 'mercredi' ; break ; | |||||
case 4 : $jour = 'jeudi' ; break ; | |||||
case 5 : $jour = 'vendredi' ; break ; | |||||
case 6 : $jour = 'samedi' ; break ; | |||||
case 7 : $jour = 'dimanche' ; break ; | |||||
} | } | ||||
if($c->$jour) | if($c->$jour) | ||||
{ | { | ||||
$arr_commandes_auto[] = $c ; | $arr_commandes_auto[] = $c ; | ||||
{ | { | ||||
// commande | // commande | ||||
$commande = new Commande ; | $commande = new Commande ; | ||||
$commande->id_user = $this->id_user ; | |||||
if(strlen($this->username)) | |||||
{ | |||||
$commande->username = $this->username ; | |||||
$commande->id_user = 0 ; | |||||
} | |||||
else { | |||||
$commande->id_user = $this->id_user ; | |||||
} | |||||
$commande->date = date('Y-m-d H:i:s') ; | $commande->date = date('Y-m-d H:i:s') ; | ||||
$commande->type = Commande::TYPE_AUTO ; | $commande->type = Commande::TYPE_AUTO ; | ||||
$commande->id_point_vente = $this->id_point_vente ; | $commande->id_point_vente = $this->id_point_vente ; |
{ | { | ||||
public $id ; | public $id ; | ||||
public $id_user ; | public $id_user ; | ||||
public $username ; | |||||
public $id_etablissement ; | public $id_etablissement ; | ||||
public $id_point_vente ; | public $id_point_vente ; | ||||
public $date_debut; | public $date_debut; | ||||
public function rules() | public function rules() | ||||
{ | { | ||||
return [ | return [ | ||||
[['id_user', 'id_etablissement', 'periodicite_semaine', 'id_point_vente'], 'integer'], | |||||
[['id_etablissement', 'periodicite_semaine', 'id_point_vente'], 'integer'], | |||||
[['date_debut', 'date_fin'], 'date', 'format' => 'php:d/m/Y'], | [['date_debut', 'date_fin'], 'date', 'format' => 'php:d/m/Y'], | ||||
[['lundi','mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'], 'boolean'], | [['lundi','mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'], 'boolean'], | ||||
[['id_user','id_point_vente', 'id_etablissement', 'date_debut'],'required', 'message' => 'Champs obligatoire'], | |||||
['produits' , 'safe'], | |||||
[['id_point_vente', 'id_etablissement', 'date_debut'],'required', 'message' => 'Champs obligatoire'], | |||||
[['produits','id_user','username'], 'safe'], | |||||
['id_user', function ($attribute, $params) { | |||||
if(!$this->id_user && !strlen($this->username)) | |||||
{ | |||||
$this->addError($attribute,'Vous devez sélectionner ou saisir un utilisateur.') ; | |||||
} | |||||
},'skipOnEmpty' => false], | |||||
['produits', function($attribute, $params) { | ['produits', function($attribute, $params) { | ||||
$produits = $this->produits ; | $produits = $this->produits ; | ||||
$quantite = 0 ; | $quantite = 0 ; | ||||
if(count($produits)) | if(count($produits)) | ||||
{ | { | ||||
foreach($produits as $name_input => $quantite_produit) { | foreach($produits as $name_input => $quantite_produit) { | ||||
if(!$quantite) | if(!$quantite) | ||||
{ | { | ||||
$this->addError($attribute, 'Vous devez saisir au moins un produit'); | $this->addError($attribute, 'Vous devez saisir au moins un produit'); | ||||
} | |||||
}] | |||||
} | |||||
}], | |||||
]; | ]; | ||||
} | |||||
} | |||||
public function attributeLabels() | public function attributeLabels() | ||||
{ | { | ||||
'samedi' => 'Samedi', | 'samedi' => 'Samedi', | ||||
'dimanche' => 'Dimanche', | 'dimanche' => 'Dimanche', | ||||
'periodicite_semaine' => 'Périodicité (semaines)', | 'periodicite_semaine' => 'Périodicité (semaines)', | ||||
'username' => 'Nom d\'utilisateur', | |||||
]; | ]; | ||||
} | } | ||||
if($commandeauto) | if($commandeauto) | ||||
{ | { | ||||
$commandeauto->id_user = $this->id_user ; | $commandeauto->id_user = $this->id_user ; | ||||
$commandeauto->username = $this->username ; | |||||
$commandeauto->id_etablissement = $this->id_etablissement ; | $commandeauto->id_etablissement = $this->id_etablissement ; | ||||
$commandeauto->id_point_vente = $this->id_point_vente ; | $commandeauto->id_point_vente = $this->id_point_vente ; | ||||
$commandeauto->date_debut = date('Y-m-d',strtotime(str_replace('/','-',$this->date_debut))) ; | $commandeauto->date_debut = date('Y-m-d',strtotime(str_replace('/','-',$this->date_debut))) ; | ||||
$commandeauto->dimanche = $this->dimanche ; | $commandeauto->dimanche = $this->dimanche ; | ||||
$commandeauto->periodicite_semaine = $this->periodicite_semaine ; | $commandeauto->periodicite_semaine = $this->periodicite_semaine ; | ||||
$commandeauto->save() ; | $commandeauto->save() ; | ||||
// produits | // produits |
{ | { | ||||
$this->createTable('commande_auto', [ | $this->createTable('commande_auto', [ | ||||
'id' => 'pk', | 'id' => 'pk', | ||||
'id_user' => Schema::TYPE_INTEGER . ' NOT NULL', | |||||
'id_user' => Schema::TYPE_INTEGER , | |||||
'id_etablissement' => Schema::TYPE_INTEGER. ' NOT NULL', | 'id_etablissement' => Schema::TYPE_INTEGER. ' NOT NULL', | ||||
'date_debut' => Schema::TYPE_DATE, | 'date_debut' => Schema::TYPE_DATE, | ||||
'date_fin' => Schema::TYPE_DATE, | 'date_fin' => Schema::TYPE_DATE, |
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\Schema; | |||||
class m161206_080722_add_champs_username_commandeauto extends Migration | |||||
{ | |||||
public function up() | |||||
{ | |||||
$this->addColumn('commande_auto', 'username', Schema::TYPE_STRING) ; | |||||
} | |||||
public function down() | |||||
{ | |||||
$this->dropColumn('commande_auto', 'username') ; | |||||
} | |||||
} |