|
|
@@ -65,19 +65,22 @@ use common\models\CommandeProduit; |
|
|
|
* @property string $username |
|
|
|
* @property string $paiement_automatique |
|
|
|
*/ |
|
|
|
class CommandeAuto extends \yii\db\ActiveRecord { |
|
|
|
class CommandeAuto extends \yii\db\ActiveRecord |
|
|
|
{ |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
|
*/ |
|
|
|
public static function tableName() { |
|
|
|
public static function tableName() |
|
|
|
{ |
|
|
|
return 'commande_auto'; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
|
*/ |
|
|
|
public function rules() { |
|
|
|
public function rules() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
[['id_etablissement', 'id_point_vente'], 'required'], |
|
|
|
[['id_user', 'id_etablissement', 'id_point_vente', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'periodicite_semaine'], 'integer'], |
|
|
@@ -89,7 +92,8 @@ class CommandeAuto extends \yii\db\ActiveRecord { |
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
|
*/ |
|
|
|
public function attributeLabels() { |
|
|
|
public function attributeLabels() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'id' => 'ID', |
|
|
|
'id_user' => 'Utilisateur', |
|
|
@@ -109,23 +113,38 @@ class CommandeAuto extends \yii\db\ActiveRecord { |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function getUser() { |
|
|
|
/* |
|
|
|
* Relations |
|
|
|
*/ |
|
|
|
|
|
|
|
public function getUser() |
|
|
|
{ |
|
|
|
return $this->hasOne(User::className(), ['id' => 'id_user']); |
|
|
|
} |
|
|
|
|
|
|
|
public function getEtablissement() { |
|
|
|
public function getEtablissement() |
|
|
|
{ |
|
|
|
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']); |
|
|
|
} |
|
|
|
|
|
|
|
public function getPointVente() { |
|
|
|
public function getPointVente() |
|
|
|
{ |
|
|
|
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']); |
|
|
|
} |
|
|
|
|
|
|
|
public function getCommandeAutoProduit() { |
|
|
|
public function getCommandeAutoProduit() |
|
|
|
{ |
|
|
|
return $this->hasMany(CommandeAutoProduit::className(), ['id_commande_auto' => 'id'])->with('produit'); |
|
|
|
} |
|
|
|
|
|
|
|
public static function getAll($date) { |
|
|
|
/** |
|
|
|
* Retourne les commandes récurrentes pour une date donnée. |
|
|
|
* |
|
|
|
* @param string $date |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public static function getAll($date) |
|
|
|
{ |
|
|
|
$date = date('Y-m-d', strtotime($date)); |
|
|
|
|
|
|
|
// commandes auto |
|
|
@@ -139,7 +158,8 @@ class CommandeAuto extends \yii\db\ActiveRecord { |
|
|
|
foreach ($commandes_auto as $c) { |
|
|
|
// vérif dates |
|
|
|
if ($date >= $c->date_debut && |
|
|
|
(!$c->date_fin || $date <= $c->date_fin)) { |
|
|
|
(!$c->date_fin || $date <= $c->date_fin)) |
|
|
|
{ |
|
|
|
// périodicite |
|
|
|
$nb_jours = (strtotime($date) - strtotime($c->date_debut)) / (24 * 60 * 60); |
|
|
|
if ($nb_jours % ($c->periodicite_semaine * 7) < 7) { |
|
|
@@ -172,17 +192,25 @@ class CommandeAuto extends \yii\db\ActiveRecord { |
|
|
|
return $arr_commandes_auto; |
|
|
|
} |
|
|
|
|
|
|
|
public static function addAll($date, $force = false) { |
|
|
|
/** |
|
|
|
* Ajoute les commandes pour une date donnée à partir des commnandes |
|
|
|
* récurrentes. |
|
|
|
* |
|
|
|
* @param string $date |
|
|
|
* @param boolean $force |
|
|
|
*/ |
|
|
|
public static function addAll($date, $force = false) |
|
|
|
{ |
|
|
|
// production |
|
|
|
$production = Production::findOne([ |
|
|
|
'date' => date('Y-m-d', strtotime($date)), |
|
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement |
|
|
|
]); |
|
|
|
'date' => date('Y-m-d', strtotime($date)), |
|
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement |
|
|
|
]); |
|
|
|
|
|
|
|
if ($production) { |
|
|
|
$count_commandes_prod = Commande::find() |
|
|
|
->where(['id_production' => $production->id]) |
|
|
|
->count(); |
|
|
|
->where(['id_production' => $production->id]) |
|
|
|
->count(); |
|
|
|
|
|
|
|
if (!$count_commandes_prod || $force) { |
|
|
|
$commandes_auto = self::getAll($date); |
|
|
@@ -193,7 +221,13 @@ class CommandeAuto extends \yii\db\ActiveRecord { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function add($date) { |
|
|
|
/** |
|
|
|
* Ajoute la commande récurrente pour une date donnée. |
|
|
|
* |
|
|
|
* @param string $date |
|
|
|
*/ |
|
|
|
public function add($date) |
|
|
|
{ |
|
|
|
// production |
|
|
|
$production = Production::find() |
|
|
|
->where([ |