Browse Source

Adaptations producer/subscription

dev
Guillaume Bourgeois 6 years ago
parent
commit
731edb9e1c
5 changed files with 29 additions and 14 deletions
  1. +5
    -5
      backend/controllers/SubscriptionController.php
  2. +2
    -2
      backend/views/subscription/_form.php
  3. +1
    -1
      backend/web/js/lechatdesnoisettes.js
  4. +19
    -4
      common/models/ProductSubscription.php
  5. +2
    -2
      common/models/SubscriptionForm.php

+ 5
- 5
backend/controllers/SubscriptionController.php View File

{ {
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => Subscription::find() 'query' => Subscription::find()
->with(['user', 'etablissement', 'pointVente', 'commandeAutoProduit'])
->with(['user', 'producer', 'pointSale', 'productSubscription'])
->joinWith(['user']) ->joinWith(['user'])
->where(['subscription.id_producer' => Producer::getId()]) ->where(['subscription.id_producer' => Producer::getId()])
->orderBy('subscription.id_point_sale ASC, CASE `subscription`.`username` WHEN "" THEN `user`.`name` ELSE `subscription`.`username` END ASC'), ->orderBy('subscription.id_point_sale ASC, CASE `subscription`.`username` WHEN "" THEN `user`.`name` ELSE `subscription`.`username` END ASC'),
$model->id_producer = Producer::getId(); $model->id_producer = Producer::getId();


// produits // produits
$products = Product::searchAll() ;
$productsArray = Product::searchAll() ;
if ($model->load(Yii::$app->request->post()) && $model->validate() if ($model->load(Yii::$app->request->post()) && $model->validate()
&& $model->save()) && $model->save())


return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
'products' => $products
'productsArray' => $productsArray
]); ]);
} }


} }


// produits // produits
$products = Product::searchAll() ;
$productsArray = Product::searchAll() ;


if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if (!strlen($model->date_end)) { if (!strlen($model->date_end)) {


return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
'products' => $products
'productsArray' => $productsArray
]); ]);
} }



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

<td> <td>
<div class="input-group"> <div class="input-group">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-default btn-minus" type="button"><span class="glyphicon glyphicon-minus"></span></button>
<button class="btn btn-default btn-moins" type="button"><span class="glyphicon glyphicon-minus"></span></button>
</span> </span>
<?= Html::input('text', 'SubscriptionForm[products][product_'.$p->id.']', (isset($model->products['product_'.$p->id])) ? $model->products['product_'.$p->id] : '', ['class' => 'form-control quantity']) ?> <?= Html::input('text', 'SubscriptionForm[products][product_'.$p->id.']', (isset($model->products['product_'.$p->id])) ? $model->products['product_'.$p->id] : '', ['class' => 'form-control quantity']) ?>
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-default btn-more" type="button"><span class="glyphicon glyphicon-plus"></span></button>
<button class="btn btn-default btn-plus" type="button"><span class="glyphicon glyphicon-plus"></span></button>
</span> </span>
</div> </div>
</td> </td>

+ 1
- 1
backend/web/js/lechatdesnoisettes.js View File

function chat_commandeauto() { function chat_commandeauto() {
// dates // dates
$('#commandeautoform-date_debut, #commandeautoform-date_fin').datepicker() ;
$('#subscriptionform-date_begin, #subscriptionform-date_end').datepicker() ;
} }



+ 19
- 4
common/models/ProductSubscription.php View File



use Yii; use Yii;
use common\models\Product; use common\models\Product;
use common\components\ActiveRecordCommon ;


/** /**
* This is the model class for table "commande_auto_produit". * This is the model class for table "commande_auto_produit".
* *
* @property integer $id * @property integer $id
* @property integer $id_commande_auto
* @property integer $id_produit
* @property double $quantite
* @property integer $id_subscription
* @property integer $id_product
* @property double $quantity
*/ */
class ProductSubscription extends \yii\db\ActiveRecord
class ProductSubscription extends ActiveRecordCommon
{ {


/** /**
{ {
return $this->hasOne(Product::className(), ['id' => 'id_product']); return $this->hasOne(Product::className(), ['id' => 'id_product']);
} }
/**
* Retourne les options de base nécessaires à la fonction de recherche.
*
* @return array
*/
public static function defaultOptionsSearch() {
return [
'with' => ['product'],
'join_with' => [],
'orderby' => '',
'attribute_id_producer' => ''
] ;
}


} }

+ 2
- 2
common/models/SubscriptionForm.php View File



foreach ($this->products as $nameInput => $quantity) { foreach ($this->products as $nameInput => $quantity) {
if ($quantity) { if ($quantity) {
$idProduct = str_replace('produit_', '', $nameInput);
$idProduct = str_replace('product_', '', $nameInput);
$subscriptionProduct = new ProductSubscription; $subscriptionProduct = new ProductSubscription;
$subscriptionProduct->id_subscription = $subscription->id; $subscriptionProduct->id_subscription = $subscription->id;
$subscriptionProduct->id_product = $id_product;
$subscriptionProduct->id_product = $idProduct;
$subscriptionProduct->quantity = $quantity; $subscriptionProduct->quantity = $quantity;
$subscriptionProduct->save(); $subscriptionProduct->save();
} }

Loading…
Cancel
Save