<?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 backend\assets; | |||||
use yii\web\AssetBundle; | |||||
use yii ; | |||||
/** | |||||
* @author Qiang Xue <qiang.xue@gmail.com> | |||||
* @since 2.0 | |||||
*/ | |||||
class VuejsSubscriptionFormAsset extends \common\components\MyAssetBundle | |||||
{ | |||||
public $basePath = '@webroot'; | |||||
public $baseUrl = '@web'; | |||||
public $css = []; | |||||
public $js = []; | |||||
public $depends = [ | |||||
'common\assets\CommonAsset' | |||||
]; | |||||
public function __construct() | |||||
{ | |||||
parent::__construct() ; | |||||
$this->addAsset('js','js/vuejs/subscription-form.js') ; | |||||
} | |||||
} |
foreach($pointSale->orders as $order) { | foreach($pointSale->orders as $order) { | ||||
$orderLine = [$order->getStrUser()] ; | $orderLine = [$order->getStrUser()] ; | ||||
foreach($order->productOrder as $productOrder) { | foreach($order->productOrder as $productOrder) { | ||||
$orderLine[$productsIndexArray[$productOrder->id_product]] = $productOrder->quantity . ' '.Product::strUnit($productOrder->unit, 'short', true); | |||||
$orderLine[$productsIndexArray[$productOrder->id_product]] = $productOrder->quantity . ' '.Product::strUnit($productOrder->unit, 'wording_short', true); | |||||
} | } | ||||
$datas[] = $this->_lineOrderReportCSV($orderLine, $cpt) ; | $datas[] = $this->_lineOrderReportCSV($orderLine, $cpt) ; | ||||
} | } | ||||
if(!isset($totalsPointSaleArray[$index])) { | if(!isset($totalsPointSaleArray[$index])) { | ||||
$totalsPointSaleArray[$index] = '' ; | $totalsPointSaleArray[$index] = '' ; | ||||
} | } | ||||
$totalsPointSaleArray[$index] .= $quantity . ' '.Product::strUnit($unit, 'short', true).' '; | |||||
$totalsPointSaleArray[$index] .= $quantity . ' '.Product::strUnit($unit, 'wording_short', true).' '; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
if(!isset($totalsGlobalArray[$index])) { | if(!isset($totalsGlobalArray[$index])) { | ||||
$totalsGlobalArray[$index] = '' ; | $totalsGlobalArray[$index] = '' ; | ||||
} | } | ||||
$totalsGlobalArray[$index] .= $quantity . ' '.Product::strUnit($unit, 'short', true).' '; | |||||
$totalsGlobalArray[$index] .= $quantity . ' '.Product::strUnit($unit, 'wording_short', true).' '; | |||||
} | } | ||||
} | } | ||||
} | } |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\models\Order ; | use common\models\Order ; | ||||
use common\models\Product ; | |||||
class SubscriptionController extends BackendController | class SubscriptionController extends BackendController | ||||
{ | { | ||||
$model->auto_payment = $subscription->auto_payment; | $model->auto_payment = $subscription->auto_payment; | ||||
$model->week_frequency = $subscription->week_frequency; | $model->week_frequency = $subscription->week_frequency; | ||||
// produits | // produits | ||||
$arrayProductsSubscription = ProductSubscription::searchAll([ | $arrayProductsSubscription = ProductSubscription::searchAll([ | ||||
'id_subscription' => $model->id | 'id_subscription' => $model->id | ||||
'update' => $update | 'update' => $update | ||||
]) ; | ]) ; | ||||
} | } | ||||
public function actionAjaxInfos($idSubscription = 0) | |||||
{ | |||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||||
$productsQuery = Product::find() | |||||
->where(['id_producer' => Producer::getId(),]) ; | |||||
if($idSubscription) { | |||||
$productsQuery->joinWith(['productSubscription' => function($query) use($idSubscription) { | |||||
$query->andOnCondition('product_subscription.id_subscription = '.((int) $idSubscription)) ; | |||||
}]) ; | |||||
} | |||||
$productsArray = $productsQuery->asArray()->all() ; | |||||
foreach($productsArray as &$theProduct) { | |||||
$theProduct['unit_save'] = $theProduct['unit'] ; | |||||
$theProduct['units'] = [] ; | |||||
$theProduct['units'][] = [ | |||||
'unit' => $theProduct['unit'], | |||||
'wording_unit' => Product::strUnit($theProduct['unit'], 'wording_short'), | |||||
'step' => $theProduct['step'], | |||||
] ; | |||||
if(isset($theProduct['productSubscription'][0])) { | |||||
if($theProduct['productSubscription'][0]['unit'] != $theProduct['unit']) { | |||||
$theProduct['units'][] = [ | |||||
'unit' => $theProduct['productSubscription'][0]['unit'], | |||||
'wording_unit' => Product::strUnit($theProduct['productSubscription'][0]['unit'], 'wording_short'), | |||||
'step' => $theProduct['productSubscription'][0]['step'], | |||||
] ; | |||||
$theProduct['unit'] = $theProduct['productSubscription'][0]['unit'] ; | |||||
$theProduct['step'] = $theProduct['productSubscription'][0]['step'] ; | |||||
} | |||||
$theProduct['quantity'] = $theProduct['productSubscription'][0]['quantity'] * Product::$unitsArray[$theProduct['unit']]['coefficient'] ; | |||||
} | |||||
else { | |||||
$theProduct['quantity'] = '' ; | |||||
} | |||||
} | |||||
return [ | |||||
'products' => $productsArray | |||||
] ; | |||||
} | |||||
} | } |
$add = false; | $add = false; | ||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
if ($product->id == $productOrder->id_product) { | if ($product->id == $productOrder->id_product) { | ||||
$strProducts .= $product->name . ' (' .$productOrder->quantity . ' '.Product::strUnit($productOrder->unit, 'short', true).'), '; | |||||
$strProducts .= $product->name . ' (' .$productOrder->quantity . ' '.Product::strUnit($productOrder->unit, 'wording_short', true).'), '; | |||||
$add = true; | $add = true; | ||||
} | } | ||||
} | } | ||||
foreach(Product::$unitsArray as $unit => $dataUnit) { | foreach(Product::$unitsArray as $unit => $dataUnit) { | ||||
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit); | $quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit); | ||||
if ($quantity) { | if ($quantity) { | ||||
$strProducts .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'short', true).'), '; | |||||
$strProducts .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'wording_short', true).'), '; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
foreach(Product::$unitsArray as $unit => $dataUnit) { | foreach(Product::$unitsArray as $unit => $dataUnit) { | ||||
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit); | $quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit); | ||||
if ($quantity) { | if ($quantity) { | ||||
$html .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'short', true).'), '; | |||||
$html .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'wording_short', true).'), '; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
foreach(Product::$unitsArray as $unit => $dataUnit) { | foreach(Product::$unitsArray as $unit => $dataUnit) { | ||||
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit); | $quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit); | ||||
if ($quantity) { | if ($quantity) { | ||||
$html .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'short', true).'), '; | |||||
$html .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'wording_short', true).'), '; | |||||
} | } | ||||
} | } | ||||
} | } |
use common\models\User ; | use common\models\User ; | ||||
use common\models\PointSale ; | use common\models\PointSale ; | ||||
\backend\assets\VuejsSubscriptionFormAsset::register($this); | |||||
?> | ?> | ||||
<div class="subscription-form"> | |||||
<div class="subscription-form" id="app-subscription-form"> | |||||
<?php $form = ActiveForm::begin(['enableClientValidation' => false]); ?> | <?php $form = ActiveForm::begin(['enableClientValidation' => false]); ?> | ||||
<?php if($model->id): ?> | |||||
<?= $form->field($model, 'id')->hiddenInput() ?> | |||||
<?php endif; ?> | |||||
<div class="col-md-5" id="bloc-select-user"> | <div class="col-md-5" id="bloc-select-user"> | ||||
<?= $form->field($model, 'id_user')->dropDownList( ArrayHelper::map(User::find()->joinWith('userProducer')->where('user_producer.id_producer = '.Producer::getId())->andWhere('user_producer.active = 1')->orderBy('lastname ASC, name ASC')->all(), 'id', function($model, $defaultValue) { | <?= $form->field($model, 'id_user')->dropDownList( ArrayHelper::map(User::find()->joinWith('userProducer')->where('user_producer.id_producer = '.Producer::getId())->andWhere('user_producer.active = 1')->orderBy('lastname ASC, name ASC')->all(), 'id', function($model, $defaultValue) { | ||||
return $model['lastname'].' '.$model['name']; | return $model['lastname'].' '.$model['name']; | ||||
echo '<div class="alert alert-danger">'.$model->errors['products'][0].'</div>' ; | echo '<div class="alert alert-danger">'.$model->errors['products'][0].'</div>' ; | ||||
} | } | ||||
?> | ?> | ||||
<table class="table table-bordered table-condensed table-hover"> | |||||
<?php foreach ($productsArray as $p) : ?> | |||||
<tr> | |||||
<td><?= Html::encode($p->name) ?></td> | |||||
<table class="table table-bordered table-condensed table-hover" id="products"> | |||||
<tr v-for="product in products"> | |||||
<td>{{ product.name }}</td> | |||||
<td> | <td> | ||||
<input type="hidden" :value="product.step" :name="'product_step_'+product.step" /> | |||||
<div class="input-group"> | <div class="input-group"> | ||||
<span class="input-group-btn"> | <span class="input-group-btn"> | ||||
<button class="btn btn-default btn-moins" type="button"><span class="glyphicon glyphicon-minus"></span></button> | |||||
<button class="btn btn-default" type="button" @click="changeQuantityProductSubscription(false, product)"><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']) ?> | |||||
<input v-model="product.quantity" :name="'SubscriptionForm[products][product_'+product.id+']'" class="form-control input-quantity" /> | |||||
<div class="input-group-addon"> | |||||
<select class="form-control select-unit" :name="'product_unit_'+product.id" v-model="product.unit" v-if="product.units.length > 1" @change="changeUnitProductSubscription" :data-id-product="product.id"> | |||||
<option v-for="unit in product.units" :value="unit.unit">{{ unit.wording_unit }}</option> | |||||
</select> | |||||
<span v-else> | |||||
{{ product.units[0].wording_unit }} | |||||
</span> | |||||
</div> | |||||
<span class="input-group-btn"> | <span class="input-group-btn"> | ||||
<button class="btn btn-default btn-plus" type="button"><span class="glyphicon glyphicon-plus"></span></button> | |||||
<button class="btn btn-default" type="button" @click="changeQuantityProductSubscription(true, product)"><span class="glyphicon glyphicon-plus"></span></button> | |||||
</span> | </span> | ||||
</div> | </div> | ||||
</td> | </td> | ||||
<td> | |||||
<span v-if="product.units.length > 1 && product.unit != product.unit_save" class="glyphicon glyphicon-warning-sign" title="Unité différente du produit"></span> | |||||
</td> | |||||
</tr> | </tr> | ||||
<?php endforeach; ?> | |||||
</table> | </table> | ||||
</div> | </div> | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\Product ; | |||||
$this->setTitle('Abonnements') ; | $this->setTitle('Abonnements') ; | ||||
foreach($model->productSubscription as $productSubscription) | foreach($model->productSubscription as $productSubscription) | ||||
{ | { | ||||
if(isset($productSubscription->product)) { | if(isset($productSubscription->product)) { | ||||
$html .= $productSubscription->quantity . ' x '.Html::encode($productSubscription->product->name).'<br />' ; | |||||
$html .= Html::encode($productSubscription->product->name).' ('.$productSubscription->quantity.' '.Product::strUnit($productSubscription->unit, 'wording_short').')<br />' ; | |||||
} | } | ||||
else { | else { | ||||
$html .= 'Produit non défini<br />' ; | $html .= 'Produit non défini<br />' ; |
width: 50px; | width: 50px; | ||||
} | } | ||||
/* line 3, ../sass/subscription/_form.scss */ | |||||
.subscription-form .field-subscriptionform-id { | |||||
display: none; | |||||
} | |||||
/* line 7, ../sass/subscription/_form.scss */ | |||||
.subscription-form table#products .input-quantity { | |||||
text-align: center; | |||||
border-right: 0px none; | |||||
} | |||||
/* line 11, ../sass/subscription/_form.scss */ | |||||
.subscription-form table#products .input-group-addon { | |||||
padding: 5px; | |||||
padding-left: 0px; | |||||
margin: 0px; | |||||
border-left: 0px none; | |||||
border-right: 0px none; | |||||
} | |||||
/* line 18, ../sass/subscription/_form.scss */ | |||||
.subscription-form table#products .select-unit { | |||||
padding: 0px; | |||||
width: 58px; | |||||
text-align: center; | |||||
height: 22px; | |||||
} | |||||
/* line 24, ../sass/subscription/_form.scss */ | |||||
.subscription-form table#products .glyphicon-warning-sign { | |||||
position: relative; | |||||
top: 10px; | |||||
} | |||||
/* line 3, ../sass/product/_index.scss */ | /* line 3, ../sass/product/_index.scss */ | ||||
.product-index .td-photo { | .product-index .td-photo { | ||||
max-width: 100px; | max-width: 100px; |
/** | |||||
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. | |||||
*/ | |||||
var app = new Vue({ | |||||
el: '#app-subscription-form', | |||||
data: { | |||||
showLoading: false, | |||||
loading: true, | |||||
products: [], | |||||
units: [] | |||||
}, | |||||
mounted: function() { | |||||
this.init() ; | |||||
this.loading = false ; | |||||
}, | |||||
methods: { | |||||
init: function() { | |||||
var app = this ; | |||||
this.showLoading = true ; | |||||
axios.get("ajax-infos",{params: {idSubscription: $('#subscriptionform-id').val()}}) | |||||
.then(function(response) { | |||||
app.products = response.data.products ; | |||||
app.units = response.data.units ; | |||||
app.showLoading = false ; | |||||
}) ; | |||||
}, | |||||
changeUnitProductSubscription: function(event) { | |||||
for(var i = 0; i < this.products.length ; i++) { | |||||
if(this.products[i].id == event.currentTarget.getAttribute('data-id-product')) { | |||||
this.products[i].quantity = '' ; | |||||
for(var j = 0; j < this.products[i].units.length ; j ++) { | |||||
if(this.products[i].unit == this.products[i].units[j].unit) { | |||||
this.products[i].step = this.products[i].units[j].step ; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
}, | |||||
changeQuantityProductSubscription: function(increase, product) { | |||||
var step = parseFloat(product.step) ; | |||||
if(!product.quantity) product.quantity = 0 ; | |||||
var quantity = parseFloat(product.quantity) ; | |||||
if(!increase) { | |||||
step = -step ; | |||||
} | |||||
if(quantity + step >= 0) { | |||||
product.quantity = quantity + step ; | |||||
} | |||||
if(!product.quantity) product.quantity = '' ; | |||||
} | |||||
} | |||||
}); |
@import "_adminlte.scss" ; | @import "_adminlte.scss" ; | ||||
@import "site/_index.scss" ; | @import "site/_index.scss" ; | ||||
@import "subscription/_index.scss" ; | @import "subscription/_index.scss" ; | ||||
@import "subscription/_form.scss" ; | |||||
@import "product/_index.scss" ; | @import "product/_index.scss" ; | ||||
@import "product/_form.scss" ; | @import "product/_form.scss" ; | ||||
@import "stats/_products.scss" ; | @import "stats/_products.scss" ; |
.subscription-form { | |||||
.field-subscriptionform-id { | |||||
display: none; | |||||
} | |||||
table#products { | |||||
.input-quantity { | |||||
text-align: center ; | |||||
border-right: 0px none ; | |||||
} | |||||
.input-group-addon { | |||||
padding: 5px ; | |||||
padding-left: 0px ; | |||||
margin: 0px ; | |||||
border-left: 0px none ; | |||||
border-right: 0px none ; | |||||
} | |||||
.select-unit { | |||||
padding: 0px; | |||||
width: 58px; | |||||
text-align: center; | |||||
height: 22px; | |||||
} | |||||
.glyphicon-warning-sign { | |||||
position: relative; | |||||
top: 10px ; | |||||
} | |||||
} | |||||
} |
$i = 0; | $i = 0; | ||||
foreach ($this->productOrder as $p) { | foreach ($this->productOrder as $p) { | ||||
if (isset($p->product)) { | if (isset($p->product)) { | ||||
$html .= Html::encode($p->product->name) .' ('. $p->quantity .' '.Product::strUnit($p->unit, 'short', true).')'; | |||||
$html .= Html::encode($p->product->name) .' ('. $p->quantity .' '.Product::strUnit($p->unit, 'wording_short', true).')'; | |||||
if (++$i != $count) { | if (++$i != $count) { | ||||
$html .= '<br />'; | $html .= '<br />'; | ||||
} | } |
var $apply_distributions = false ; | var $apply_distributions = false ; | ||||
public static $unitsArray = [ | public static $unitsArray = [ | ||||
'piece' => ['wording_unit' => 'la pièce', 'wording' => 'pièce(s)', 'short' => 'p.', 'coefficient' => 1], | |||||
'g' => ['wording_unit' => 'le g', 'wording' => 'g', 'short' => 'g','coefficient' => 1000], | |||||
'kg' => ['wording_unit' => 'le kg', 'wording' => 'kg', 'short' => 'kg', 'coefficient' => 1], | |||||
'mL' => ['wording_unit' => 'le mL', 'wording' => 'mL', 'short' => 'mL', 'coefficient' => 1000], | |||||
'L' => ['wording_unit' => 'le litre', 'wording' => 'L', 'short' => 'L', 'coefficient' => 1], | |||||
'piece' => [ | |||||
'unit' => 'piece', | |||||
'wording_unit' => 'la pièce', | |||||
'wording' => 'pièce(s)', | |||||
'wording_short' => 'p.', | |||||
'coefficient' => 1 | |||||
], | |||||
'g' => [ | |||||
'unit' => 'g', | |||||
'wording_unit' => 'le g', | |||||
'wording' => 'g', | |||||
'wording_short' => 'g', | |||||
'coefficient' => 1000 | |||||
], | |||||
'kg' => [ | |||||
'unit' => 'kg', | |||||
'wording_unit' => 'le kg', | |||||
'wording' => 'kg', | |||||
'wording_short' => 'kg', | |||||
'coefficient' => 1 | |||||
], | |||||
'mL' => [ | |||||
'unit' => 'mL', | |||||
'wording_unit' => 'le mL', | |||||
'wording' => 'mL', | |||||
'wording_short' => 'mL', | |||||
'coefficient' => 1000 | |||||
], | |||||
'L' => [ | |||||
'unit' => 'L', | |||||
'wording_unit' => 'le litre', | |||||
'wording' => 'L', | |||||
'wording_short' => 'L', | |||||
'coefficient' => 1 | |||||
], | |||||
]; | ]; | ||||
/** | /** | ||||
return $this->hasMany(ProductDistribution::className(), ['id_product' => 'id']); | return $this->hasMany(ProductDistribution::className(), ['id_product' => 'id']); | ||||
} | } | ||||
public function getProductSubscription() | |||||
{ | |||||
return $this->hasMany(ProductSubscription::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. | ||||
* | * | ||||
* @param $unitInDb Unité stockée en base de données (ex: si g > kg, si mL > L) | * @param $unitInDb Unité stockée en base de données (ex: si g > kg, si mL > L) | ||||
* @return $string Libellé de l'unité | * @return $string Libellé de l'unité | ||||
*/ | */ | ||||
public static function strUnit($unit, $format = 'short', $unitInDb = false) | |||||
public static function strUnit($unit, $format = 'wording_short', $unitInDb = false) | |||||
{ | { | ||||
$strUnit = '' ; | $strUnit = '' ; | ||||
$productOrder->id_product = $productSubscription->product->id; | $productOrder->id_product = $productSubscription->product->id; | ||||
$productOrder->quantity = $productSubscription->quantity; | $productOrder->quantity = $productSubscription->quantity; | ||||
$productOrder->price = $productSubscription->product->price; | $productOrder->price = $productSubscription->product->price; | ||||
$productOrder->unit = $productSubscription->product->unit; | |||||
$productOrder->step = $productSubscription->product->step; | |||||
$productOrder->unit = $productSubscription->unit; | |||||
$productOrder->step = $productSubscription->step; | |||||
$productOrder->save(); | $productOrder->save(); | ||||
$productsAdd = true; | $productsAdd = true; | ||||
} | } |
foreach ($this->products as $nameInput => $quantity) { | foreach ($this->products as $nameInput => $quantity) { | ||||
if ($quantity) { | if ($quantity) { | ||||
$idProduct = str_replace('product_', '', $nameInput); | |||||
$idProduct = (int) str_replace('product_', '', $nameInput); | |||||
$product = Product::findOne($idProduct) ; | |||||
$subscriptionProduct = new ProductSubscription; | $subscriptionProduct = new ProductSubscription; | ||||
$subscriptionProduct->id_subscription = $subscription->id; | $subscriptionProduct->id_subscription = $subscription->id; | ||||
$subscriptionProduct->id_product = $idProduct; | $subscriptionProduct->id_product = $idProduct; | ||||
$subscriptionProduct->quantity = $quantity; | |||||
$unit = (Yii::$app->getRequest()->post('product_unit_'.$idProduct)) ? Yii::$app->getRequest()->post('product_unit_'.$idProduct) : $product->unit ; | |||||
$subscriptionProduct->unit = $unit; | |||||
$step = (Yii::$app->getRequest()->post('product_step_'.$idProduct)) ? Yii::$app->getRequest()->post('product_step_'.$idProduct) : $product->step ; | |||||
$subscriptionProduct->step = $step; | |||||
$subscriptionProduct->quantity = $quantity / Product::$unitsArray[$unit]['coefficient']; | |||||
$subscriptionProduct->save(); | $subscriptionProduct->save(); | ||||
} | } | ||||
} | } |
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\mysql\Schema; | |||||
class m190511_061123_ajout_champs_unit_product_subscription extends Migration { | |||||
public function up() { | |||||
$this->addColumn('product_subscription', 'unit', Schema::TYPE_STRING . ' DEFAULT \'piece\''); | |||||
$this->addColumn('product_subscription', 'step', Schema::TYPE_FLOAT . ' DEFAULT 1'); | |||||
} | |||||
public function down() { | |||||
$this->dropColumn('product_subscription', 'unit'); | |||||
$this->dropColumn('product_subscription', 'step'); | |||||
} | |||||
} |