|
|
|
|
|
|
|
|
|
|
|
|
|
|
use common\models\Etablissement ; |
|
|
use common\models\Etablissement ; |
|
|
use common\models\PointVente ; |
|
|
use common\models\PointVente ; |
|
|
|
|
|
use common\models\Commande ; |
|
|
|
|
|
use common\models\CommandeProduit ; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* This is the model class for table "commande_auto". |
|
|
* This is the model class for table "commande_auto". |
|
|
|
|
|
|
|
|
* @property integer $id |
|
|
* @property integer $id |
|
|
* @property integer $id_user |
|
|
* @property integer $id_user |
|
|
* @property integer $id_etablissement |
|
|
* @property integer $id_etablissement |
|
|
|
|
|
* @property integer $id_point_vente |
|
|
* @property string $date_debut |
|
|
* @property string $date_debut |
|
|
* @property string $date_fin |
|
|
* @property string $date_fin |
|
|
* @property integer $lundi |
|
|
* @property integer $lundi |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
return $this->hasMany(CommandeAutoProduit::className(), ['id_commande_auto'=>'id'])->with('produit') ; |
|
|
return $this->hasMany(CommandeAutoProduit::className(), ['id_commande_auto'=>'id'])->with('produit') ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static function getAll($date) |
|
|
|
|
|
{ |
|
|
|
|
|
$date = date('Y-m-d', strtotime($date)) ; |
|
|
|
|
|
|
|
|
|
|
|
// commandes auto |
|
|
|
|
|
$commandes_auto = self::find() |
|
|
|
|
|
->with('commandeAutoProduit') |
|
|
|
|
|
->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) |
|
|
|
|
|
->all() ; |
|
|
|
|
|
|
|
|
|
|
|
$arr_commandes_auto = [] ; |
|
|
|
|
|
|
|
|
|
|
|
foreach($commandes_auto as $c) |
|
|
|
|
|
{ |
|
|
|
|
|
// vérif dates |
|
|
|
|
|
if($date >= $c->date_debut && |
|
|
|
|
|
(!$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 ) |
|
|
|
|
|
{ |
|
|
|
|
|
// jour de la semaine |
|
|
|
|
|
$jour = date('N', strtotime($date)) ; |
|
|
|
|
|
switch($jour) |
|
|
|
|
|
{ |
|
|
|
|
|
case 1 : $jour = 'lundi' ; |
|
|
|
|
|
case 2 : $jour = 'mardi' ; |
|
|
|
|
|
case 3 : $jour = 'mercredi' ; |
|
|
|
|
|
case 4 : $jour = 'jeudi' ; |
|
|
|
|
|
case 5 : $jour = 'vendredi' ; |
|
|
|
|
|
case 6 : $jour = 'samedi' ; |
|
|
|
|
|
case 7 : $jour = 'dimanche' ; |
|
|
|
|
|
} |
|
|
|
|
|
if($c->$jour) |
|
|
|
|
|
{ |
|
|
|
|
|
$arr_commandes_auto[] = $c ; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $arr_commandes_auto ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static function addAll($date) |
|
|
|
|
|
{ |
|
|
|
|
|
// production |
|
|
|
|
|
$production = Production::findOne(['date' => date('Y-m-d',strtotime($date))]) ; |
|
|
|
|
|
|
|
|
|
|
|
if($production) |
|
|
|
|
|
{ |
|
|
|
|
|
$count_commandes_prod = Commande::find() |
|
|
|
|
|
->where(['id_production' => $production->id]) |
|
|
|
|
|
->count() ; |
|
|
|
|
|
|
|
|
|
|
|
if(!$count_commandes_prod) |
|
|
|
|
|
{ |
|
|
|
|
|
$commandes_auto = self::getAll($date) ; |
|
|
|
|
|
foreach($commandes_auto as $c) |
|
|
|
|
|
{ |
|
|
|
|
|
$c->add($date) ; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function add($date) |
|
|
|
|
|
{ |
|
|
|
|
|
// production |
|
|
|
|
|
$production = Production::findOne(['date' => date('Y-m-d',strtotime($date))]) ; |
|
|
|
|
|
|
|
|
|
|
|
if($production) |
|
|
|
|
|
{ |
|
|
|
|
|
// commande |
|
|
|
|
|
$commande = new Commande ; |
|
|
|
|
|
$commande->id_user = $this->id_user ; |
|
|
|
|
|
$commande->date = date('Y-m-d H:i:s') ; |
|
|
|
|
|
$commande->type = Commande::TYPE_AUTO ; |
|
|
|
|
|
$commande->id_point_vente = $this->id_point_vente ; |
|
|
|
|
|
$commande->id_production = $production->id ; |
|
|
|
|
|
$commande->save() ; |
|
|
|
|
|
|
|
|
|
|
|
// produits |
|
|
|
|
|
foreach($this->commandeAutoProduit as $commande_auto_produit) |
|
|
|
|
|
{ |
|
|
|
|
|
$commande_produit = new CommandeProduit ; |
|
|
|
|
|
$commande_produit->id_commande = $commande->id ; |
|
|
|
|
|
$commande_produit->id_produit = $commande_auto_produit->produit->id ; |
|
|
|
|
|
$commande_produit->quantite = $commande_auto_produit->quantite ; |
|
|
|
|
|
$commande_produit->prix = $commande_auto_produit->produit->prix ; |
|
|
|
|
|
$commande_produit->save() ; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |