Browse Source

Indentation + commentaires modèle CommandeAuto

dev
Guillaume Bourgeois 6 years ago
parent
commit
f52d092ebf
1 changed files with 51 additions and 17 deletions
  1. +51
    -17
      common/models/CommandeAuto.php

+ 51
- 17
common/models/CommandeAuto.php View File

* @property string $username * @property string $username
* @property string $paiement_automatique * @property string $paiement_automatique
*/ */
class CommandeAuto extends \yii\db\ActiveRecord {
class CommandeAuto extends \yii\db\ActiveRecord
{


/** /**
* @inheritdoc * @inheritdoc
*/ */
public static function tableName() {
public static function tableName()
{
return 'commande_auto'; return 'commande_auto';
} }


/** /**
* @inheritdoc * @inheritdoc
*/ */
public function rules() {
public function rules()
{
return [ return [
[['id_etablissement', 'id_point_vente'], 'required'], [['id_etablissement', 'id_point_vente'], 'required'],
[['id_user', 'id_etablissement', 'id_point_vente', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'periodicite_semaine'], 'integer'], [['id_user', 'id_etablissement', 'id_point_vente', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'periodicite_semaine'], 'integer'],
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function attributeLabels() {
public function attributeLabels()
{
return [ return [
'id' => 'ID', 'id' => 'ID',
'id_user' => 'Utilisateur', 'id_user' => 'Utilisateur',
]; ];
} }


public function getUser() {
/*
* Relations
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'id_user']); return $this->hasOne(User::className(), ['id' => 'id_user']);
} }


public function getEtablissement() {
public function getEtablissement()
{
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']); return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']);
} }


public function getPointVente() {
public function getPointVente()
{
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']); 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'); 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)); $date = date('Y-m-d', strtotime($date));


// commandes auto // commandes auto
foreach ($commandes_auto as $c) { foreach ($commandes_auto as $c) {
// vérif dates // vérif dates
if ($date >= $c->date_debut && if ($date >= $c->date_debut &&
(!$c->date_fin || $date <= $c->date_fin)) {
(!$c->date_fin || $date <= $c->date_fin))
{
// périodicite // périodicite
$nb_jours = (strtotime($date) - strtotime($c->date_debut)) / (24 * 60 * 60); $nb_jours = (strtotime($date) - strtotime($c->date_debut)) / (24 * 60 * 60);
if ($nb_jours % ($c->periodicite_semaine * 7) < 7) { if ($nb_jours % ($c->periodicite_semaine * 7) < 7) {
return $arr_commandes_auto; 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 = Production::findOne([ $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) { if ($production) {
$count_commandes_prod = Commande::find() $count_commandes_prod = Commande::find()
->where(['id_production' => $production->id])
->count();
->where(['id_production' => $production->id])
->count();


if (!$count_commandes_prod || $force) { if (!$count_commandes_prod || $force) {
$commandes_auto = self::getAll($date); $commandes_auto = self::getAll($date);
} }
} }


public function add($date) {
/**
* Ajoute la commande récurrente pour une date donnée.
*
* @param string $date
*/
public function add($date)
{
// production // production
$production = Production::find() $production = Production::find()
->where([ ->where([

Loading…
Cancel
Save