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; |
$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"><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> |
} | } | ||||
/* 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 32, ../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; | |||||
} | |||||
/* line 38, ../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) |
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 ?')) { |
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; | |||||
} | |||||
.field-product-available_on_points_sale { | |||||
label.control-label { | |||||
margin-bottom: 0px; | |||||
} | |||||
} | |||||
#product-pointssale { | |||||
label { | |||||
display: block; | |||||
font-weight: normal; | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
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' |
<?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' => '' | |||||
] ; | |||||
} | |||||
} |
<?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'); | |||||
} | |||||
} |