|
|
@@ -56,11 +56,10 @@ use Yii; |
|
|
|
*/ |
|
|
|
class Product extends \yii\db\ActiveRecord |
|
|
|
{ |
|
|
|
var $total = 0; |
|
|
|
|
|
|
|
var $total = 0; |
|
|
|
|
|
|
|
const SALE_MODE_UNIT = 'unit' ; |
|
|
|
const SALE_MODE_WEIGHT = 'weight' ; |
|
|
|
const SALE_MODE_UNIT = 'unit' ; |
|
|
|
const SALE_MODE_WEIGHT = 'weight' ; |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
@@ -76,13 +75,13 @@ class Product extends \yii\db\ActiveRecord |
|
|
|
public function rules() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
[['nom', 'id_etablissement'], 'required'], |
|
|
|
[['actif', 'order', 'quantite_max', 'id_etablissement'], 'integer'], |
|
|
|
[['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'epuise'], 'boolean'], |
|
|
|
[['prix', 'poids'], 'number'], |
|
|
|
[['illustration', 'photo'], 'file'], |
|
|
|
[['nom', 'description', 'illustration', 'photo', 'saison', 'diminutif'], 'string', 'max' => 255], |
|
|
|
[['recette'], 'string', 'max' => 1000], |
|
|
|
[['name', 'id_producer'], 'required'], |
|
|
|
[['active', 'order', 'quantity_max', 'id_producer'], 'integer'], |
|
|
|
[['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saterday', 'sunday', 'unavailable'], 'boolean'], |
|
|
|
[['price', 'weight'], 'number'], |
|
|
|
[[ 'photo'], 'file'], |
|
|
|
[['name', 'description', 'photo'], 'string', 'max' => 255], |
|
|
|
[['recipe'], 'string', 'max' => 1000], |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
@@ -93,27 +92,39 @@ class Product extends \yii\db\ActiveRecord |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'id' => 'ID', |
|
|
|
'nom' => 'Nom', |
|
|
|
'name' => 'Nom', |
|
|
|
'description' => 'Description', |
|
|
|
'actif' => 'Actif', |
|
|
|
'illustration' => 'Illustration', |
|
|
|
'active' => 'Actif', |
|
|
|
'photo' => 'Photo', |
|
|
|
'saison' => 'Saison', |
|
|
|
'prix' => 'Prix', |
|
|
|
'poids' => 'Poids (g)', |
|
|
|
'recette' => 'Recette', |
|
|
|
'lundi' => 'Lundi', |
|
|
|
'mardi' => 'Mardi', |
|
|
|
'mercredi' => 'Mercredi', |
|
|
|
'jeudi' => 'Jeudi', |
|
|
|
'vendredi' => 'Vendredi', |
|
|
|
'samedi' => 'Samedi', |
|
|
|
'dimanche' => 'Dimanche', |
|
|
|
'price' => 'Prix', |
|
|
|
'weight' => 'Poids (g)', |
|
|
|
'recipe' => 'Recette', |
|
|
|
'monday' => 'Lundi', |
|
|
|
'tuesday' => 'Mardi', |
|
|
|
'wednesday' => 'Mercredi', |
|
|
|
'thursday' => 'Jeudi', |
|
|
|
'friday' => 'Vendredi', |
|
|
|
'saterday' => 'Samedi', |
|
|
|
'sunday' => 'Dimanche', |
|
|
|
'order' => 'Ordre', |
|
|
|
'quantite_max' => 'Quantité max par défaut', |
|
|
|
'epuise' => 'Épuisé', |
|
|
|
'quantity_max' => 'Quantité max par défaut', |
|
|
|
'unavailable' => 'Épuisé', |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Retourne les options de base nécessaires à la fonction de recherche. |
|
|
|
* |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public static function defaultOptionsSearch() { |
|
|
|
return [ |
|
|
|
'with' => [], |
|
|
|
'join_with' => [], |
|
|
|
'orderby' => 'order ASC', |
|
|
|
'attribute_id_producer' => 'order.id_producer' |
|
|
|
] ; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Retourne la description du produit. |
|
|
@@ -123,11 +134,11 @@ class Product extends \yii\db\ActiveRecord |
|
|
|
public function getDescription() |
|
|
|
{ |
|
|
|
$description = $this->description; |
|
|
|
if (isset($this->poids) && is_numeric($this->poids) && $this->poids > 0) { |
|
|
|
if ($this->poids >= 1000) { |
|
|
|
$description .= ' (' . ($this->poids / 1000) . 'kg)'; |
|
|
|
if (isset($this->weight) && is_numeric($this->weight) && $this->weight > 0) { |
|
|
|
if ($this->weight >= 1000) { |
|
|
|
$description .= ' (' . ($this->weight / 1000) . 'kg)'; |
|
|
|
} else { |
|
|
|
$description .= ' (' . $this->poids . 'g)'; |
|
|
|
$description .= ' (' . $this->weight . 'g)'; |
|
|
|
} |
|
|
|
} |
|
|
|
return $description; |
|
|
@@ -137,9 +148,9 @@ class Product extends \yii\db\ActiveRecord |
|
|
|
* Retourne le libellé (admin) du produit. |
|
|
|
* @return type |
|
|
|
*/ |
|
|
|
public function getLibelleAdmin() |
|
|
|
public function getStrWordingAdmin() |
|
|
|
{ |
|
|
|
return $this->nom; |
|
|
|
return $this->name; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -151,40 +162,25 @@ class Product extends \yii\db\ActiveRecord |
|
|
|
*/ |
|
|
|
public function save($runValidation = true, $attributeNames = NULL) |
|
|
|
{ |
|
|
|
$this->id_etablissement = Yii::$app->user->identity->id_etablissement; |
|
|
|
$this->id_producer = Producer::getCurrentId(); |
|
|
|
return parent::save($runValidation, $attributeNames); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Retourne les produits de l'établissement courant. |
|
|
|
* |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public function getAll() |
|
|
|
{ |
|
|
|
return Produit::find() |
|
|
|
->where([ |
|
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement, |
|
|
|
]) |
|
|
|
->orderBy('order ASC') |
|
|
|
->all(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Retourne les produits d'une production donnée. |
|
|
|
* |
|
|
|
* @param integer $id_production |
|
|
|
* @param integer $idDistribution |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public function getByProduction($id_production) |
|
|
|
public function searchByDistribution($idDistribution) |
|
|
|
{ |
|
|
|
return Produit::find() |
|
|
|
->leftJoin('production_produit', 'produit.id = production_produit.id_produit') |
|
|
|
return Product::find() |
|
|
|
->leftJoin('product_distribution', 'product.id = product_distribution.id_product') |
|
|
|
->where([ |
|
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement, |
|
|
|
'production_produit.id_production' => $id_production |
|
|
|
'id_producer' => Producer::getCurrentId(), |
|
|
|
'product_distribution.id_distribution' => $idDistribution |
|
|
|
]) |
|
|
|
->orderBy('production_produit.actif DESC, produit.order ASC') |
|
|
|
->orderBy('product_distribution.active DESC, product.order ASC') |
|
|
|
->all(); |
|
|
|
} |
|
|
|
|
|
|
@@ -195,11 +191,7 @@ class Product extends \yii\db\ActiveRecord |
|
|
|
*/ |
|
|
|
public static function count() |
|
|
|
{ |
|
|
|
return Produit::find() |
|
|
|
->where([ |
|
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement |
|
|
|
]) |
|
|
|
->count(); |
|
|
|
return self::searchCount() ; |
|
|
|
} |
|
|
|
|
|
|
|
} |