foreach($productsArray as &$theProduct) { | foreach($productsArray as &$theProduct) { | ||||
$quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray) ; | $quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray) ; | ||||
$theProduct['quantity_ordered'] = $quantityOrder ; | $theProduct['quantity_ordered'] = $quantityOrder ; | ||||
if(!isset($theProduct['productDistribution'][0])) { | |||||
$theProduct['productDistribution'][0] = $distribution->linkProduct($theProduct) ; | |||||
} | |||||
if(!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { | if(!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { | ||||
$theProduct['quantity_remaining'] = null ; | $theProduct['quantity_remaining'] = null ; | ||||
} | } |
$distribution) { | $distribution) { | ||||
$order = new Order; | $order = new Order; | ||||
$order->date = date('Y-m-d H:i:s', strtotime($date . ' ' . date('H:i:s'))); | |||||
$order->date = date('Y-m-d H:i:s') ; | |||||
$order->id_point_sale = $idPointSale; | $order->id_point_sale = $idPointSale; | ||||
$order->id_distribution = $distribution->id; | $order->id_distribution = $distribution->id; | ||||
$order->origin = Order::ORIGIN_ADMIN; | $order->origin = Order::ORIGIN_ADMIN; |
Yii::$app->getSession()->setFlash('success', 'Produit <strong>'.Html::encode($model->name).'</strong> ajouté'); | Yii::$app->getSession()->setFlash('success', 'Produit <strong>'.Html::encode($model->name).'</strong> ajouté'); | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | |||||
} | |||||
else { | |||||
return $this->render('create', [ | return $this->render('create', [ | ||||
'model' => $model, | 'model' => $model, | ||||
]); | ]); |
*/ | */ | ||||
$dateStart = date('Y-m-d', time() - 60 * 60 * 24 * 365); | $dateStart = date('Y-m-d', time() - 60 * 60 * 24 * 365); | ||||
$dateEnd = date('Y-m-d'); | |||||
$dateEnd = date('Y-m-d', time() + 60 * 60 * 24 * 31); | |||||
$data = []; | $data = []; | ||||
// création d'un tableau sans index car chart.js n'accepte pas les index | // création d'un tableau sans index car chart.js n'accepte pas les index | ||||
$dataNoIndex = []; | $dataNoIndex = []; | ||||
foreach ($data as $key => $val) { | foreach ($data as $key => $val) { | ||||
$dataNoIndex[] = $val; | |||||
$dataNoIndex[] = round($val, 2); | |||||
} | } | ||||
return $this->render('index', [ | return $this->render('index', [ |
<div class="product-form"> | <div class="product-form"> | ||||
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> | |||||
<?php $form = ActiveForm::begin([ | |||||
'enableClientValidation' => false, | |||||
'options' => ['enctype' => 'multipart/form-data'] | |||||
]); ?> | |||||
<div> | <div> | ||||
<div class="col-md-8"> | <div class="col-md-8"> | ||||
if(!$model->isNewRecord) { | if(!$model->isNewRecord) { | ||||
echo $form->field($model, 'apply_distributions') | echo $form->field($model, 'apply_distributions') | ||||
->checkbox() | ->checkbox() | ||||
->hint('Sélectionnez cette option si vous souhaitez que ces modifications soient répercutées dans les distributions à venir déjà initialisées.'); | |||||
->hint('Sélectionnez cette option si vous souhaitez que ces modifications (actif / non actif, quantité max) soient répercutées dans les distributions à venir déjà initialisées.'); | |||||
} | } | ||||
?> | ?> | ||||
</div> | </div> |
} | } | ||||
$productDistribution->save(); | $productDistribution->save(); | ||||
return $productDistribution ; | |||||
} | } | ||||
/** | /** |
class Product extends ActiveRecordCommon | class Product extends ActiveRecordCommon | ||||
{ | { | ||||
var $total = 0; | var $total = 0; | ||||
var $apply_distributions = false ; | |||||
var $apply_distributions = true ; | |||||
public static $unitsArray = [ | public static $unitsArray = [ | ||||
'piece' => [ | 'piece' => [ | ||||
[['name', 'description', 'photo', 'unit'], 'string', 'max' => 255], | [['name', 'description', 'photo', 'unit'], 'string', 'max' => 255], | ||||
[['recipe'], 'string', 'max' => 1000], | [['recipe'], 'string', 'max' => 1000], | ||||
['step', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | ['step', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | ||||
if($model->unit == 'piece') { | |||||
if($model->unit != 'piece') { | |||||
return true ; | return true ; | ||||
} | } | ||||
return false ; | return false ; |
'id' => 'ID', | 'id' => 'ID', | ||||
'name' => 'Prénom', | 'name' => 'Prénom', | ||||
'lastname' => 'Nom', | 'lastname' => 'Nom', | ||||
'phone' => 'Téléphone', | |||||
'address' => 'Adresse', | |||||
'username' => 'Identifiant', | 'username' => 'Identifiant', | ||||
'password' => 'Mot de passe', | 'password' => 'Mot de passe', | ||||
'rememberMe' => 'Se souvenir de moi', | 'rememberMe' => 'Se souvenir de moi', |