Browse Source

Merge branch 'feature/gestion_dons_utilisateur' into dev

refactoring
Guillaume Bourgeois 5 years ago
parent
commit
52bdd77400
10 changed files with 155 additions and 13 deletions
  1. +2
    -3
      backend/controllers/DistributionController.php
  2. +22
    -4
      backend/views/producer-admin/index.php
  3. +6
    -0
      backend/views/producer/update.php
  4. +24
    -0
      common/models/Distribution.php
  5. +3
    -1
      common/models/Producer.php
  6. +17
    -0
      common/models/Product.php
  7. +33
    -0
      console/migrations/m190205_160337_produit_don_distrib.php
  8. +17
    -0
      console/migrations/m190205_164612_ajout_produit_don_aux_distributions_existantes.php
  9. +15
    -0
      console/migrations/m190205_170712_ajout_option_autoriser_don_plateforme.php
  10. +16
    -5
      producer/controllers/OrderController.php

+ 2
- 3
backend/controllers/DistributionController.php View File

// products // products
$productsArray = Product::find() $productsArray = Product::find()
->where([
'id_producer' => Producer::getId(),
])
->orWhere(['id_producer' => Producer::getId(),])
->orWhere(['id_producer' => 0,]) // produit "Don"
->joinWith(['productDistribution' => function($query) use($distribution) { ->joinWith(['productDistribution' => function($query) use($distribution) {
$query->andOnCondition('product_distribution.id_distribution = '.$distribution->id) ; $query->andOnCondition('product_distribution.id_distribution = '.$distribution->id) ;
}]) }])

+ 22
- 4
backend/views/producer-admin/index.php View File

use yii\grid\GridView; use yii\grid\GridView;
use common\models\User ; use common\models\User ;
use common\models\Producer ; use common\models\Producer ;
use common\models\Distribution ;


$this->setTitle('Producteurs') ; $this->setTitle('Producteurs') ;
$this->addBreadcrumb($this->getTitle()) ; $this->addBreadcrumb($this->getTitle()) ;
} }
], ],
[ [
'attribute' => 'Cours',
'label' => 'CA mois en cours',
'label' => 'Dons (mois précédent)',
'format' => 'raw', 'format' => 'raw',
'value' => function($model) { 'value' => function($model) {
$turnover = $model->getTurnover(date('Y-m')) ;
return 'CA : '.number_format($turnover,2).' €<br />' ;
$productGift = Product::getProductGift() ;
$distributionsArray = Distribution::find()
->where(['>=', 'distribution.date', date('Y-m-01', strtotime("-1 month"))])
->andWhere(['<=', 'distribution.date', date('Y-m-31', strtotime("-1 month"))])
->andWhere(['distribution.id_producer' => $model->id])
->with(['order','order.productOrder'])
->all() ;
$gifts = 0 ;
foreach($distributionsArray as $distribution) {
foreach($distribution->order as $order) {
foreach($order->productOrder as $productOrder) {
if($productOrder->id_product == $productGift->id) {
$gifts += $productOrder->quantity * $productGift->price ;
}
}
}
}
return Price::format($gifts) ;
} }
], ],
], ],

+ 6
- 0
backend/views/producer/update.php View File

<?= $form->field($model, 'order_infos') <?= $form->field($model, 'order_infos')
->textarea(['rows' => 6]) ->textarea(['rows' => 6])
->hint('Affichées au client lors de sa commande')?> ->hint('Affichées au client lors de sa commande')?>
<?= $form->field($model, 'option_allow_user_gift')
->dropDownList([
0 => 'Non',
1 => 'Oui',
], []) ; ?>
</div> </div>
</div> </div>



+ 24
- 0
common/models/Distribution.php View File

$distribution->linkProduct($product) ; $distribution->linkProduct($product) ;
} }
} }
$distribution->linkProductGift() ;
} }
return $distribution ; return $distribution ;
$productDistribution->save(); $productDistribution->save();
} }
/**
* Lie le produit "Don" à la distribution
*/
public function linkProductGift()
{
$productGift = Product::getProductGift() ;
if($productGift) {
$productDistribution = ProductDistribution::searchOne([
'id_distribution' => $this->id,
'id_product' => $productGift->id
]) ;

if(!$productDistribution) {
$productDistribution = new ProductDistribution();
$productDistribution->id_distribution = $this->id;
$productDistribution->id_product = $productGift->id;
$productDistribution->active = 1;
$productDistribution->save() ;
}
}
}
/** /**
* Lie un point de vente aux jours de distribution futurs. * Lie un point de vente aux jours de distribution futurs.
* *

+ 3
- 1
common/models/Producer.php View File

* @property boolean online_payment * @property boolean online_payment
* @property string mentions * @property string mentions
* @property string gcs * @property string gcs
* @property boolean option_allow_user_gift
*/ */
class Producer extends ActiveRecordCommon class Producer extends ActiveRecordCommon
{ {
} }
}], }],
[['description','mentions','gcs','order_infos','slug','secret_key_payplug'], 'string'], [['description','mentions','gcs','order_infos','slug','secret_key_payplug'], 'string'],
[['negative_balance', 'credit', 'active','online_payment','user_manage_subscription'], 'boolean'],
[['negative_balance', 'credit', 'active','online_payment','user_manage_subscription', 'option_allow_user_gift'], 'boolean'],
[['name', 'siret', 'logo', 'photo', 'postcode', 'city', 'code','type'], 'string', 'max' => 255], [['name', 'siret', 'logo', 'photo', 'postcode', 'city', 'code','type'], 'string', 'max' => 255],
[['free_price', 'credit_limit_reminder'], 'double'], [['free_price', 'credit_limit_reminder'], 'double'],
['free_price', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'], ['free_price', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'],
'user_manage_subscription' => 'Autoriser les utilisateurs à gérer leurs abonnements', 'user_manage_subscription' => 'Autoriser les utilisateurs à gérer leurs abonnements',
'mentions' => 'Mentions légales', 'mentions' => 'Mentions légales',
'gcs' => 'Conditions générales de vente', 'gcs' => 'Conditions générales de vente',
'option_allow_user_gift' => 'Autoriser les utilisateurs à effectuer un don à la plateforme lors de leur commande',
]; ];
} }



+ 17
- 0
common/models/Product.php View File

{ {
return self::searchCount() ; return self::searchCount() ;
} }
/**
* Retourne le produit "Don".
*
* @return Product
*/
public static function getProductGift()
{
$productGift = Product::find()
->where([
'product.id_producer' => 0
])
->andFilterWhere(['like','product.name','Don'])
->one() ;
return $productGift ;
}


} }

+ 33
- 0
console/migrations/m190205_160337_produit_don_distrib.php View File

<?php

use yii\db\Migration;

class m190205_160337_produit_don_distrib extends Migration {

public function up() {
$this->insert('product', [
'name' => 'Don',
'description' => 'Don à la plateforme distrib',
'recipe' => '',
'active' => 1,
'photo' => null,
'price' => 1,
'weight' => null,
'monday' => 1,
'tuesday' => 1,
'wednesday' => 1,
'thursday' => 1,
'friday' => 1,
'saturday' => 1,
'sunday' => 1,
'quantity_max' => null,
'id_producer' => 0,
'sale_mode' => 'unit',
'order' => 1000,
]) ;
}

public function down() {
$this->delete('product', 'name = \'Don\' AND id_producer = 0') ;
}
}

+ 17
- 0
console/migrations/m190205_164612_ajout_produit_don_aux_distributions_existantes.php View File

<?php

use yii\db\Migration;

class m190205_164612_ajout_produit_don_aux_distributions_existantes extends Migration {

public function up() {
$distributionsArray = common\models\Distribution::find()->all() ;
foreach($distributionsArray as $distribution) {
$distribution->linkProductGift() ;
}
}

public function down() {
}
}

+ 15
- 0
console/migrations/m190205_170712_ajout_option_autoriser_don_plateforme.php View File

<?php

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

class m190205_170712_ajout_option_autoriser_don_plateforme extends Migration {

public function up() {
$this->addColumn('producer', 'option_allow_user_gift', Schema::TYPE_BOOLEAN.' DEFAULT 1') ;
}

public function down() {
$this->dropColumn('producer', 'option_allow_user_gift') ;
}
}

+ 16
- 5
producer/controllers/OrderController.php View File

]); ]);
// Produits // Produits
$productsArray = Product::find()
->where([
'id_producer' => $this->getProducer()->id,
])
->joinWith(['productDistribution' => function($query) use($distribution) {
if(Producer::getConfig('option_allow_user_gift')) {
$productsArray = Product::find()
->orWhere(['id_producer' => $this->getProducer()->id,])
->orWhere(['id_producer' => 0,]) ; // produit "Don";
}
else {
$productsArray = Product::find()
->where(['id_producer' => $this->getProducer()->id,]) ;
}
$productsArray = $productsArray->joinWith(['productDistribution' => function($query) use($distribution) {
$query->andOnCondition('product_distribution.id_distribution = '.$distribution->id) ; $query->andOnCondition('product_distribution.id_distribution = '.$distribution->id) ;
}]) }])
->orderBy('product_distribution.active DESC, order ASC') ->orderBy('product_distribution.active DESC, order ASC')
$indexProduct = 0 ; $indexProduct = 0 ;
foreach($productsArray as &$product) { foreach($productsArray as &$product) {
if(is_null($product['photo'])) {
$product['photo'] = '' ;
}
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray) ; $quantityOrder = Order::getProductQuantity($product['id'], $ordersArray) ;
$product['quantity_ordered'] = $quantityOrder ; $product['quantity_ordered'] = $quantityOrder ;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder ; $product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder ;
$product['index'] = $indexProduct ++ ; $product['index'] = $indexProduct ++ ;
} }
$json['products'] = $productsArray; $json['products'] = $productsArray;
} }

Loading…
Cancel
Save