ソースを参照

Merge branch 'dev'

prodstable
Guillaume 2年前
コミット
760124f079
12個のファイルの変更343行の追加23行の削除
  1. +6
    -4
      backend/controllers/DistributionController.php
  2. +32
    -0
      backend/controllers/ProductController.php
  3. +3
    -1
      backend/views/distribution/index.php
  4. +15
    -1
      backend/views/product/_form.php
  5. +32
    -4
      backend/web/css/screen.css
  6. +13
    -0
      backend/web/js/backend.js
  7. +8
    -1
      backend/web/js/vuejs/distribution-index.js
  8. +31
    -1
      backend/web/sass/product/_form.scss
  9. +40
    -5
      common/models/Product.php
  10. +111
    -0
      common/models/ProductPointSale.php
  11. +33
    -0
      console/migrations/m220209_095208_product_availability_point_sale.php
  12. +19
    -6
      producer/controllers/OrderController.php

+ 6
- 4
backend/controllers/DistributionController.php ファイルの表示

'quantity' => 0, 'quantity' => 0,
'unit' => $product->unit, 'unit' => $product->unit,
'price' => $product->getPriceWithTax([ 'price' => $product->getPriceWithTax([
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $pointSale
]),
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $pointSale
]),
'active' => $product->productDistribution[0]->active
&& (!$pointSale || $product->isAvailableOnPointSale($pointSale))
]; ];
} }



+ 32
- 0
backend/controllers/ProductController.php ファイルの表示

Upload::uploadFile($model, 'photo'); Upload::uploadFile($model, 'photo');
$model->save(); $model->save();


// availability on points sale
$this->processAvailabilityPointsSale($model);

// link product / distribution // link product / distribution
Distribution::linkProductIncomingDistributions($model) ; Distribution::linkProductIncomingDistributions($model) ;


$request = Yii::$app->request; $request = Yii::$app->request;


$model = $this->findModel($id); $model = $this->findModel($id);

foreach ($model->productPointSale as $productPointSale) {
$model->pointsSale[] = $productPointSale->id_point_sale;
}

$photoFilenameOld = $model->photo; $photoFilenameOld = $model->photo;


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


// availability on points sale
$this->processAvailabilityPointsSale($model);

if ($model->apply_distributions) { if ($model->apply_distributions) {
// link product / distribution // link product / distribution
Distribution::linkProductIncomingDistributions($model); Distribution::linkProductIncomingDistributions($model);
]); ]);
} }


/**
* Traite les accès restreints d'un point de vente.
*/
public function processAvailabilityPointsSale($model)
{
ProductPointSale::deleteAll(['id_product' => $model->id]);

if (is_array($model->pointsSale) && count($model->pointsSale)) {
foreach ($model->pointsSale as $key => $val) {
$pointSale = PointSale::findOne($val);
if ($pointSale) {
$productPointSale = new ProductPointSale;
$productPointSale->id_product = $model->id;
$productPointSale->id_point_sale = $pointSale->id;
$productPointSale->available = ($model->available_on_points_sale) ? 0 : 1;
$productPointSale->save();
}
}
}
}

public function actionPricesList($id) public function actionPricesList($id)
{ {
$request = Yii::$app->request; $request = Yii::$app->request;

+ 3
- 1
backend/views/distribution/index.php ファイルの表示

:users="users" :users="users"
:products="products" :products="products"
:producer="producer" :producer="producer"
:loading-update-product-order="loadingUpdateProductOrder"
@close="showModalFormOrderCreate = false" @close="showModalFormOrderCreate = false"
@ordercreatedupdated="orderCreatedUpdated" @ordercreatedupdated="orderCreatedUpdated"
@updateproductorderprices="updateProductOrderPrices" @updateproductorderprices="updateProductOrderPrices"
:products="products" :products="products"
:order="ordersUpdate[key]" :order="ordersUpdate[key]"
:producer="producer" :producer="producer"
:loading-update-product-order="loadingUpdateProductOrder"
@close="showModalFormOrderUpdate = false" @close="showModalFormOrderUpdate = false"
@ordercreatedupdated="orderCreatedUpdated" @ordercreatedupdated="orderCreatedUpdated"
@updateproductorderprices="updateProductOrderPrices" @updateproductorderprices="updateProductOrderPrices"
<tbody> <tbody>
<tr v-for="product in products" :class="(order.productOrder[product.id] > 0) ? 'product-ordered' : ''"> <tr v-for="product in products" :class="(order.productOrder[product.id] > 0) ? 'product-ordered' : ''">
<td> <td>
<span class="label label-success" v-if="product.productDistribution[0].active == 1">Actif</span>
<span class="label label-success" v-if="loadingUpdateProductOrder || order.productOrder[product.id].active">Actif</span>
<span class="label label-danger" v-else>Inactif</span> <span class="label label-danger" v-else>Inactif</span>
</td> </td>
<td>{{ product.name }}</td> <td>{{ product.name }}</td>

+ 15
- 1
backend/views/product/_form.php ファイルの表示

$url = Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $model->photo; $url = Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $model->photo;
$url = str_replace('//uploads','/uploads', $url) ; $url = str_replace('//uploads','/uploads', $url) ;
echo '<img class="photo-product" src="' . $url . '" width="200px" /><br />'; echo '<img class="photo-product" src="' . $url . '" width="200px" /><br />';
echo '<input type="checkbox" name="delete_photo" id="delete_photo" /> <label for="delete_photo">Supprimer la photo</label><br /><br />';
echo '<input type="checkbox" name="delete_photo" id="delete_photo" /> <label for="delete_photo">Supprimer la photo</label>';
} }
?> ?>


<?= $form->field($model, 'sunday')->checkbox() ?> <?= $form->field($model, 'sunday')->checkbox() ?>
</div> </div>
<div class="clr"></div> <div class="clr"></div>

<div id="availability-points-sale">
<h2>Disponibilité points de vente</h2>
<?= $form->field($model, 'available_on_points_sale')->radioList([1 => 'Disponible', 0 => 'Indisponible']) ?>

<strong id="label-availability-points-sale">Et <span><?php if($model->available_on_points_sale): ?>indisponible<?php else: ?>disponible<?php endif; ?></span> sur les points de vente</strong>
<?php $pointSaleArray = PointSale::find()
->where(['id_producer' => GlobalParam::getCurrentProducerId()])
->orderBy('is_bread_box ASC, name ASC')
->all(); ?>
<?= Html::activeCheckboxList($model, 'pointsSale', ArrayHelper::map($pointSaleArray, 'id', function ($pointSale, $defaultValue) use ($model) {
return Html::encode($pointSale->name) ;
}), ['encode' => false, 'class' => '']) ?>
</div>
</div> </div>
<div class="clr"></div> <div class="clr"></div>
</div> </div>

+ 32
- 4
backend/web/css/screen.css ファイルの表示

} }
/* line 10, ../sass/product/_form.scss */ /* line 10, ../sass/product/_form.scss */
.product-create #days-production, .product-create #days-production,
.product-update #days-production {
.product-create #availability-points-sale,
.product-update #days-production,
.product-update #availability-points-sale {
margin-top: 30px; margin-top: 30px;
} }
/* line 13, ../sass/product/_form.scss */
/* line 14, ../sass/product/_form.scss */
.product-create #days-production h2, .product-create #days-production h2,
.product-update #days-production h2 {
.product-create #availability-points-sale h2,
.product-update #days-production h2,
.product-update #availability-points-sale h2 {
font-size: 20px; font-size: 20px;
} }
/* line 16, ../sass/product/_form.scss */
/* line 20, ../sass/product/_form.scss */
.product-create #days-production label, .product-create #days-production label,
.product-update #days-production label { .product-update #days-production label {
font-weight: normal; font-weight: normal;
} }
/* line 26, ../sass/product/_form.scss */
.product-create #availability-points-sale #label-availability-points-sale,
.product-update #availability-points-sale #label-availability-points-sale {
display: block;
margin-bottom: 6px;
}
/* line 30, ../sass/product/_form.scss */
.product-create #availability-points-sale #label-availability-points-sale span,
.product-update #availability-points-sale #label-availability-points-sale span {
border-bottom: dotted 1px black;
}
/* line 36, ../sass/product/_form.scss */
.product-create #availability-points-sale .field-product-available_on_points_sale label.control-label,
.product-update #availability-points-sale .field-product-available_on_points_sale label.control-label {
margin-bottom: 0px;
position: relative;
top: 3px;
}
/* line 44, ../sass/product/_form.scss */
.product-create #availability-points-sale #product-pointssale label,
.product-update #availability-points-sale #product-pointssale label {
display: block;
font-weight: normal;
}


/** /**
Copyright distrib (2018) Copyright distrib (2018)

+ 13
- 0
backend/web/js/backend.js ファイルの表示

opendistrib_products() ; opendistrib_products() ;
opendistrib_product_prices() ; opendistrib_product_prices() ;
opendistrib_confirm_delete() ; opendistrib_confirm_delete() ;
opendistrib_product_availability_points_sale();
}) ; }) ;


var UrlManager = { var UrlManager = {
} }
}; };


function opendistrib_product_availability_points_sale() {
$('input[name="Product[available_on_points_sale]"]').change(function() {
var available = parseInt($(this).val());
var label = 'disponible';
if(available == 1) {
label = 'indisponible';
}

$('#label-availability-points-sale span').html(label);
});
}

function opendistrib_confirm_delete() { function opendistrib_confirm_delete() {
$('.btn-confirm-delete').click(function(event) { $('.btn-confirm-delete').click(function(event) {
if(!confirm('Souhaitez-vous vraiment supprimer cette entrée ?')) { if(!confirm('Souhaitez-vous vraiment supprimer cette entrée ?')) {

+ 8
- 1
backend/web/js/vuejs/distribution-index.js ファイルの表示

checkboxSelectAllOrders: false, checkboxSelectAllOrders: false,
messageGenerateDeliveryNoteDisplayed: false, messageGenerateDeliveryNoteDisplayed: false,
missingSubscriptions: false, missingSubscriptions: false,
loadingUpdateProductOrder: false,
calendar: { calendar: {
mode: 'single', mode: 'single',
attrs: [], attrs: [],
this.idOrderUpdate = idOrder ; this.idOrderUpdate = idOrder ;
this.showModalFormOrderUpdate = true ; this.showModalFormOrderUpdate = true ;
this.initModalFormOrder() ; this.initModalFormOrder() ;
this.updateProductOrderPrices();
}, },
openModalFormOrderCreate: function() { openModalFormOrderCreate: function() {
this.showModalFormOrderCreate = true ; this.showModalFormOrderCreate = true ;


updateProductOrderPrices: function() { updateProductOrderPrices: function() {
var app = this ; var app = this ;
app.loadingUpdateProductOrder = true;
var order = null ; var order = null ;


if(app.showModalFormOrderCreate) { if(app.showModalFormOrderCreate) {
for (idProduct in response.data) { for (idProduct in response.data) {
if (app.showModalFormOrderCreate) { if (app.showModalFormOrderCreate) {
Vue.set(app.orderCreate.productOrder[idProduct], 'price', response.data[idProduct].price); Vue.set(app.orderCreate.productOrder[idProduct], 'price', response.data[idProduct].price);
Vue.set(app.orderCreate.productOrder[idProduct], 'active', response.data[idProduct].active);
} }


if (app.showModalFormOrderUpdate && app.idOrderUpdate) { if (app.showModalFormOrderUpdate && app.idOrderUpdate) {
for (keyOrderUpdate in app.ordersUpdate) { for (keyOrderUpdate in app.ordersUpdate) {
if (order.id == app.idOrderUpdate) { if (order.id == app.idOrderUpdate) {
Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'price', response.data[idProduct].price); Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'price', response.data[idProduct].price);
Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'active', response.data[idProduct].active);
} }
} }
} }
} }
} }

app.loadingUpdateProductOrder = false;
}); });
} }
} }
}) })


Vue.component('order-form',{ Vue.component('order-form',{
props: ['date', 'pointsSale','meansPayment', 'users', 'products', 'order', 'producer'],
props: ['date', 'pointsSale','meansPayment', 'users', 'products', 'order', 'producer', 'loadingUpdateProductOrder'],
data: function() { data: function() {
return { return {
errors: [], errors: [],

+ 31
- 1
backend/web/sass/product/_form.scss ファイルの表示

margin-right: 15px ; margin-right: 15px ;
} }
} }
#days-production {
#days-production,
#availability-points-sale {
margin-top: 30px ; margin-top: 30px ;
h2 { h2 {
font-size: 20px ; font-size: 20px ;
} }
}

#days-production {
label { label {
font-weight: normal ; font-weight: normal ;
} }
} }

#availability-points-sale {
#label-availability-points-sale {
display: block;
margin-bottom: 6px;

span {
border-bottom: dotted 1px black;
}
}

.field-product-available_on_points_sale {
label.control-label {
margin-bottom: 0px;
position: relative;
top: 3px;
}
}

#product-pointssale {
label {
display: block;
font-weight: normal;
}
}
}
} }



+ 40
- 5
common/models/Product.php ファイルの表示

public $price_with_tax = 0 ; public $price_with_tax = 0 ;
public $wording_unit = '' ; public $wording_unit = '' ;


public $pointsSale;

public static $unitsArray = [ public static $unitsArray = [
'piece' => [ 'piece' => [
'unit' => 'piece', 'unit' => 'piece',
return [ return [
[['name', 'id_producer'], 'required'], [['name', 'id_producer'], 'required'],
[['active', 'order', 'id_producer', 'id_tax_rate', 'id_product_category'], 'integer'], [['active', 'order', 'id_producer', 'id_tax_rate', 'id_product_category'], 'integer'],
[['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'unavailable', 'apply_distributions'], 'boolean'],
[['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'unavailable', 'apply_distributions', 'available_on_points_sale'], 'boolean'],
[['price', 'weight', 'step', 'quantity_max', 'quantity_max_monday', 'quantity_max_tuesday', 'quantity_max_wednesday', 'quantity_max_thursday', 'quantity_max_friday', 'quantity_max_saturday', 'quantity_max_sunday'], 'number'], [['price', 'weight', 'step', 'quantity_max', 'quantity_max_monday', 'quantity_max_tuesday', 'quantity_max_wednesday', 'quantity_max_thursday', 'quantity_max_friday', 'quantity_max_saturday', 'quantity_max_sunday'], 'number'],
[['photo'], 'file'], [['photo'], 'file'],
[['name', 'reference', 'description', 'photo', 'unit'], 'string', 'max' => 255], [['name', 'reference', 'description', 'photo', 'unit'], 'string', 'max' => 255],
} }
return false; return false;
}], }],
[['price_with_tax', 'wording_unit'], 'safe']
[['price_with_tax', 'wording_unit', 'pointsSale'], 'safe']
]; ];
} }


'active' => 'Actif', 'active' => 'Actif',
'photo' => 'Photo', 'photo' => 'Photo',
'price' => 'Prix (€) TTC', 'price' => 'Prix (€) TTC',
'price' => 'Prix (€) TTC',
'weight' => 'Poids', 'weight' => 'Poids',
'recipe' => 'Recette', 'recipe' => 'Recette',
'monday' => 'Lundi', 'monday' => 'Lundi',
'unit' => 'Unité', 'unit' => 'Unité',
'step' => 'Pas', 'step' => 'Pas',
'id_tax_rate' => 'TVA', 'id_tax_rate' => 'TVA',
'id_product_category' => 'Catégorie'
'id_product_category' => 'Catégorie',
'available_on_points_sale' => 'Par défaut'
]; ];
} }


return $this->hasOne(ProductCategory::className(), ['id' => 'id_product_category']) ; return $this->hasOne(ProductCategory::className(), ['id' => 'id_product_category']) ;
} }


public function getProductPointSale()
{
return $this->hasMany(ProductPointSale::className(), ['id_product' => 'id']) ;
}

/** /**
* Retourne les options de base nécessaires à la fonction de recherche. * Retourne les options de base nécessaires à la fonction de recherche.
* *
public static function defaultOptionsSearch() public static function defaultOptionsSearch()
{ {
return [ return [
'with' => ['taxRate'],
'with' => ['taxRate', 'productPointSale'],
'join_with' => [], 'join_with' => [],
'orderby' => 'order ASC', 'orderby' => 'order ASC',
'attribute_id_producer' => 'product.id_producer' 'attribute_id_producer' => 'product.id_producer'
]; ];
} }


public function isAvailableOnPointSale($pointSale)
{
// disponible par défaut
if($this->available_on_points_sale) {
foreach($this->productPointSale as $productPointSale) {
if($pointSale->id == $productPointSale->id_point_sale
//&& $productPointSale->id_product == $this->id
&& !$productPointSale->available) {
return false;
}
}

return true;
}
// indisponible par défaut
else {
foreach($this->productPointSale as $productPointSale) {
if($pointSale->id == $productPointSale->id_point_sale
//&& $productPointSale->id_product == $this->id
&& $productPointSale->available) {
return true;
}
}

return false;
}
}

/** /**
* Retourne la description du produit. * Retourne la description du produit.
* *

+ 111
- 0
common/models/ProductPointSale.php ファイルの表示

<?php

/**
Copyright distrib (2018)

contact@opendistrib.net

Ce logiciel est un programme informatique servant à aider les producteurs
à distribuer leur production en circuits courts.

Ce logiciel est régi par la licence CeCILL soumise au droit français et
respectant les principes de diffusion des logiciels libres. Vous pouvez
utiliser, modifier et/ou redistribuer ce programme sous les conditions
de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
sur le site "http://www.cecill.info".

En contrepartie de l'accessibilité au code source et des droits de copie,
de modification et de redistribution accordés par cette licence, il n'est
offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
seule une responsabilité restreinte pèse sur l'auteur du programme, le
titulaire des droits patrimoniaux et les concédants successifs.

A cet égard l'attention de l'utilisateur est attirée sur les risques
associés au chargement, à l'utilisation, à la modification et/ou au
développement et à la reproduction du logiciel par l'utilisateur étant
donné sa spécificité de logiciel libre, qui peut le rendre complexe à
manipuler et qui le réserve donc à des développeurs et des professionnels
avertis possédant des connaissances informatiques approfondies. Les
utilisateurs sont donc invités à charger et tester l'adéquation du
logiciel à leurs besoins dans des conditions permettant d'assurer la
sécurité de leurs systèmes et ou de leurs données et, plus généralement,
à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.

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 common\models;

use common\components\ActiveRecordCommon ;

/**
* This is the model class for table "product_point_sale".
*
* @property integer $id_product
* @property integer $id_point_sale
* @property boolean $available
*/
class ProductPointSale extends ActiveRecordCommon
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'product_point_sale';
}

/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_product', 'id_point_sale'], 'required'],
[['id_product', 'id_point_sale'], 'integer'],
[['available'], 'boolean'],
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_product' => 'Produit',
'id_point_sale' => 'Point de vente',
'available' => 'Disponible',
];
}

/*
* Relations
*/
public function getProduct()
{
return $this->hasOne(Product::className(), ['id' => 'id_product']);
}

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

+ 33
- 0
console/migrations/m220209_095208_product_availability_point_sale.php ファイルの表示

<?php

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

/**
* Class m220209_095208_product_availability_point_sale
*/
class m220209_095208_product_availability_point_sale extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('product', 'available_on_points_sale', Schema::TYPE_BOOLEAN.' DEFAULT 1');
$this->createTable('product_point_sale', [
'id' => 'pk',
'id_product' => Schema::TYPE_INTEGER. ' NOT NULL',
'id_point_sale' => Schema::TYPE_INTEGER. ' NOT NULL',
'available' => Schema::TYPE_BOOLEAN.' DEFAULT 1',
]);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('product', 'available_on_points_sale');
$this->dropTable('product_point_sale');
}
}

+ 19
- 6
producer/controllers/OrderController.php ファイルの表示

]); ]);


$productsArray = $productsArray->joinWith([ $productsArray = $productsArray->joinWith([
'productDistribution' => function ($query) use (
$distribution
) {
'productDistribution' => function ($query) use ($distribution) {
$query->andOnCondition( $query->andOnCondition(
'product_distribution.id_distribution = ' . $distribution->id 'product_distribution.id_distribution = ' . $distribution->id
); );
}, },
/*'productPointSale' => function ($query) use ($pointSaleCurrent) {
$query->andOnCondition(
'product_point_sale.id_point_sale = ' . $pointSaleCurrent->id
);
},*/
'productPrice' 'productPrice'
]) ])
->orderBy('product_distribution.active DESC, order ASC') ->orderBy('product_distribution.active DESC, order ASC')
->all(); ->all();


$productsArrayFilter = [];

// filtre sur les points de vente
foreach($productsArray as $product) {
if($product->isAvailableOnPointSale($pointSaleCurrent)) {
$productsArrayFilter[] = $product;
}
}

$indexProduct = 0; $indexProduct = 0;
foreach ($productsArray as &$product) {
foreach ($productsArrayFilter as $key => &$product) {
$product = array_merge( $product = array_merge(
$product->getAttributes(), $product->getAttributes(),
[ [
'user_producer' => $userProducer, 'user_producer' => $userProducer,
'point_sale' => $pointSaleCurrent 'point_sale' => $pointSaleCurrent
]), ]),
'productDistribution' => $product['productDistribution']
'productDistribution' => $product['productDistribution'],
'productPointSale' => $product['productPointSale'],
] ]
); );


$product['index'] = $indexProduct++; $product['index'] = $indexProduct++;
} }


$json['products'] = $productsArray;
$json['products'] = $productsArrayFilter;
} else { } else {
$json['points_sale'] = $this->_initPointsSale($producer->id); $json['points_sale'] = $this->_initPointsSale($producer->id);
} }

読み込み中…
キャンセル
保存