|
|
|
|
|
|
|
|
* @property integer $id_production |
|
|
* @property integer $id_production |
|
|
* @property boolean $paiement_automatique |
|
|
* @property boolean $paiement_automatique |
|
|
*/ |
|
|
*/ |
|
|
class Commande extends \yii\db\ActiveRecord { |
|
|
|
|
|
|
|
|
|
|
|
var $montant = 0; |
|
|
|
|
|
var $montant_pain = 0; |
|
|
|
|
|
var $montant_vrac = 0; |
|
|
|
|
|
var $montant_paye = 0; |
|
|
|
|
|
var $poids_pain = 0; |
|
|
|
|
|
var $poids_vrac = 0; |
|
|
|
|
|
|
|
|
class Commande extends \yii\db\ActiveRecord |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
var $montant = 0 ; |
|
|
|
|
|
var $montant_paye = 0 ; |
|
|
|
|
|
var $poids = 0 ; |
|
|
|
|
|
|
|
|
const TYPE_AUTO = 'auto'; |
|
|
const TYPE_AUTO = 'auto'; |
|
|
const TYPE_USER = 'user'; |
|
|
const TYPE_USER = 'user'; |
|
|
const TYPE_ADMIN = 'admin'; |
|
|
const TYPE_ADMIN = 'admin'; |
|
|
|
|
|
|
|
|
const STATUT_PAYEE = 'payee'; |
|
|
const STATUT_PAYEE = 'payee'; |
|
|
const STATUT_IMPAYEE = 'impayee'; |
|
|
const STATUT_IMPAYEE = 'impayee'; |
|
|
const STATUT_SURPLUS = 'surplus'; |
|
|
const STATUT_SURPLUS = 'surplus'; |
|
|
|
|
|
|
|
|
const ETAT_MODIFIABLE = 'ouverte'; |
|
|
const ETAT_MODIFIABLE = 'ouverte'; |
|
|
const ETAT_PREPARATION = 'preparation'; |
|
|
const ETAT_PREPARATION = 'preparation'; |
|
|
const ETAT_LIVREE = 'livree'; |
|
|
const ETAT_LIVREE = 'livree'; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public static function tableName() { |
|
|
|
|
|
|
|
|
public static function tableName() |
|
|
|
|
|
{ |
|
|
return 'commande'; |
|
|
return 'commande'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function init() { |
|
|
|
|
|
if (isset($this->commandeProduits)) { |
|
|
|
|
|
foreach ($this->commandeProduits as $p) { |
|
|
|
|
|
if ($p->mode_vente == 'unite') { |
|
|
|
|
|
$this->montant_pain += $p->prix * $p->quantite; |
|
|
|
|
|
if(isset($p->produit)) |
|
|
|
|
|
$this->poids_pain += ($p->quantite * $p->produit->poids) / 1000 ; |
|
|
|
|
|
} elseif ($p->mode_vente == 'poids') { |
|
|
|
|
|
$this->montant_pain += $p->prix * $p->quantite / 1000; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->montant = $this->montant_vrac + $this->montant_pain; |
|
|
|
|
|
} |
|
|
|
|
|
if (isset($this->creditHistorique) && !$this->montant_paye) { |
|
|
|
|
|
foreach ($this->creditHistorique as $ch) { |
|
|
|
|
|
if ($ch->type == CreditHistorique::TYPE_PAIEMENT) |
|
|
|
|
|
$this->montant_paye += $ch->montant; |
|
|
|
|
|
elseif ($ch->type == CreditHistorique::TYPE_REMBOURSEMENT) |
|
|
|
|
|
$this->montant_paye -= $ch->montant; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static function getQuantiteProduit($id_produit, $commandes) { |
|
|
|
|
|
|
|
|
|
|
|
$quantite = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (isset($commandes) && is_array($commandes) && count($commandes)) { |
|
|
|
|
|
foreach ($commandes as $c) { |
|
|
|
|
|
if(is_null($c->date_delete)) { |
|
|
|
|
|
foreach ($c->commandeProduits as $cp) { |
|
|
|
|
|
if ($cp->id_produit == $id_produit) |
|
|
|
|
|
$quantite += $cp->quantite; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $quantite; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* relations |
|
|
* relations |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
public function getUser() { |
|
|
|
|
|
|
|
|
public function getUser() |
|
|
|
|
|
{ |
|
|
return $this->hasOne(User::className(), ['id' => 'id_user']); |
|
|
return $this->hasOne(User::className(), ['id' => 'id_user']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getCommandeProduits() { |
|
|
|
|
|
return $this->hasMany(CommandeProduit::className(), ['id_commande' => 'id'])->with('produit'); |
|
|
|
|
|
|
|
|
public function getCommandeProduits() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasMany(CommandeProduit::className(),['id_commande' => 'id']) |
|
|
|
|
|
->with('produit'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getProduction() { |
|
|
|
|
|
return $this->hasOne(Production::className(), ['id' => 'id_production'])->with('etablissement'); |
|
|
|
|
|
|
|
|
public function getProduction() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasOne(Production::className(), ['id' => 'id_production']) |
|
|
|
|
|
->with('etablissement'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getPointVente() { |
|
|
|
|
|
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente'])->with('pointVenteUser'); |
|
|
|
|
|
|
|
|
public function getPointVente() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->hasOne(PointVente::className(), ['id' => 'id_point_vente']) |
|
|
|
|
|
->with('pointVenteUser'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getCreditHistorique() { |
|
|
|
|
|
|
|
|
public function getCreditHistorique() |
|
|
|
|
|
{ |
|
|
return $this->hasMany(CreditHistorique::className(), ['id_commande' => 'id']); |
|
|
return $this->hasMany(CreditHistorique::className(), ['id_commande' => 'id']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public function rules() { |
|
|
|
|
|
|
|
|
public function rules() |
|
|
|
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
[['id_user', 'date', 'id_point_vente', 'id_production'], 'required', 'message' => ''], |
|
|
[['id_user', 'date', 'id_point_vente', 'id_production'], 'required', 'message' => ''], |
|
|
[['id_user', 'id_point_vente', 'id_production'], 'integer'], |
|
|
[['id_user', 'id_point_vente', 'id_production'], 'integer'], |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public function attributeLabels() { |
|
|
|
|
|
|
|
|
public function attributeLabels() |
|
|
|
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
'id' => 'ID', |
|
|
'id' => 'ID', |
|
|
'id_user' => 'Id User', |
|
|
'id_user' => 'Id User', |
|
|
|
|
|
|
|
|
'id_production' => 'Date de production', |
|
|
'id_production' => 'Date de production', |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function strListeVrac() { |
|
|
|
|
|
$str = ''; |
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->commandeProduits as $cp) { |
|
|
|
|
|
if ($cp->produit->vrac) { |
|
|
|
|
|
$str .= $cp->quantite . ' ' . Html::encode($cp->produit->diminutif) . ', '; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Initialise le montant total, le montant déjà payé et le poids de la |
|
|
|
|
|
* commande |
|
|
|
|
|
*/ |
|
|
|
|
|
public function init() |
|
|
|
|
|
{ |
|
|
|
|
|
// Montant |
|
|
|
|
|
if (isset($this->commandeProduits)) { |
|
|
|
|
|
foreach ($this->commandeProduits as $p) { |
|
|
|
|
|
if ($p->mode_vente == 'unite') { |
|
|
|
|
|
$this->montant += $p->prix * $p->quantite; |
|
|
|
|
|
if(isset($p->produit)) { |
|
|
|
|
|
$this->poids += ($p->quantite * $p->produit->poids) / 1000 ; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
elseif ($p->mode_vente == 'poids') { |
|
|
|
|
|
$this->montant += $p->prix * $p->quantite / 1000; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
// Montant payé |
|
|
|
|
|
if (isset($this->creditHistorique) && !$this->montant_paye) { |
|
|
|
|
|
foreach ($this->creditHistorique as $ch) { |
|
|
|
|
|
if ($ch->type == CreditHistorique::TYPE_PAIEMENT) { |
|
|
|
|
|
$this->montant_paye += $ch->montant; |
|
|
|
|
|
} |
|
|
|
|
|
elseif ($ch->type == CreditHistorique::TYPE_REMBOURSEMENT) { |
|
|
|
|
|
$this->montant_paye -= $ch->montant; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return substr($str, 0, strlen($str) - 2); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne la quantité d'un produit donné de plusieurs commandes. |
|
|
|
|
|
* |
|
|
|
|
|
* @param integer $id_produit |
|
|
|
|
|
* @param array $commandes |
|
|
|
|
|
* |
|
|
|
|
|
* @return integer |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function getQuantiteProduit($id_produit, $commandes) |
|
|
|
|
|
{ |
|
|
|
|
|
$quantite = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (isset($commandes) && is_array($commandes) && count($commandes)) { |
|
|
|
|
|
foreach ($commandes as $c) { |
|
|
|
|
|
if(is_null($c->date_delete)) { |
|
|
|
|
|
foreach ($c->commandeProduits as $cp) { |
|
|
|
|
|
if ($cp->id_produit == $id_produit) { |
|
|
|
|
|
$quantite += $cp->quantite; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function getMontantPaye() { |
|
|
|
|
|
|
|
|
return $quantite; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le montant payé de la commande. |
|
|
|
|
|
* |
|
|
|
|
|
* @return float |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getMontantPaye() |
|
|
|
|
|
{ |
|
|
if ($this->montant_paye) { |
|
|
if ($this->montant_paye) { |
|
|
return $this->montant_paye; |
|
|
return $this->montant_paye; |
|
|
} else { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
$historique = CreditHistorique::find() |
|
|
$historique = CreditHistorique::find() |
|
|
->where(['id_commande' => $this->id]) |
|
|
->where(['id_commande' => $this->id]) |
|
|
->all(); |
|
|
->all(); |
|
|
|
|
|
|
|
|
$montant = 0; |
|
|
$montant = 0; |
|
|
|
|
|
|
|
|
foreach ($historique as $ch) { |
|
|
foreach ($historique as $ch) { |
|
|
if ($ch->type == CreditHistorique::TYPE_PAIEMENT) |
|
|
|
|
|
|
|
|
if ($ch->type == CreditHistorique::TYPE_PAIEMENT) { |
|
|
$montant += $ch->montant; |
|
|
$montant += $ch->montant; |
|
|
elseif ($ch->type == CreditHistorique::TYPE_REMBOURSEMENT) |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
elseif ($ch->type == CreditHistorique::TYPE_REMBOURSEMENT) { |
|
|
$montant -= $ch->montant; |
|
|
$montant -= $ch->montant; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $montant; |
|
|
return $montant; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getMontant($format = false) { |
|
|
|
|
|
if ($format) |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le montant de la commande. |
|
|
|
|
|
* |
|
|
|
|
|
* @param boolean $format |
|
|
|
|
|
* @return float |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getMontant($format = false) |
|
|
|
|
|
{ |
|
|
|
|
|
if ($format) { |
|
|
return number_format($this->getMontant(), 2) . ' €'; |
|
|
return number_format($this->getMontant(), 2) . ' €'; |
|
|
else |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
return $this->montant; |
|
|
return $this->montant; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getMontantFormat() { |
|
|
|
|
|
return number_format($this->getMontant(), 2) . ' €'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getMontantRestant($format = false) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le montant restant à payer. |
|
|
|
|
|
* |
|
|
|
|
|
* @param boolean $format |
|
|
|
|
|
* @return float |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getMontantRestant($format = false) |
|
|
|
|
|
{ |
|
|
$montant_restant = $this->getMontant() - $this->getMontantPaye(); |
|
|
$montant_restant = $this->getMontant() - $this->getMontantPaye(); |
|
|
if ($format) |
|
|
|
|
|
|
|
|
if ($format) { |
|
|
return number_format($montant_restant, 2) . ' €'; |
|
|
return number_format($montant_restant, 2) . ' €'; |
|
|
else |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
return $montant_restant; |
|
|
return $montant_restant; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getMontantSurplus($format = false) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le montant payé en surplus. |
|
|
|
|
|
* |
|
|
|
|
|
* @param boolean $format |
|
|
|
|
|
* @return float |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getMontantSurplus($format = false) |
|
|
|
|
|
{ |
|
|
$montant_surplus = $this->getMontantPaye() - $this->getMontant(); |
|
|
$montant_surplus = $this->getMontantPaye() - $this->getMontant(); |
|
|
if ($format) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($format) { |
|
|
return number_format($montant_surplus, 2) . ' €'; |
|
|
return number_format($montant_surplus, 2) . ' €'; |
|
|
else |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
return $montant_surplus; |
|
|
return $montant_surplus; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getDataJson() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne les informations relatives à la commande au format JSON. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getDataJson() |
|
|
|
|
|
{ |
|
|
$commande = Commande::find()->with('commandeProduits')->where(['id' => $this->id])->one(); |
|
|
$commande = Commande::find()->with('commandeProduits')->where(['id' => $this->id])->one(); |
|
|
|
|
|
|
|
|
$commande->init(); |
|
|
$commande->init(); |
|
|
|
|
|
|
|
|
$json_commande = [ |
|
|
$json_commande = [ |
|
|
|
|
|
|
|
|
'str_montant' => $commande->getMontantFormat(), |
|
|
'str_montant' => $commande->getMontantFormat(), |
|
|
'montant_paye' => $commande->getMontantPaye(), |
|
|
'montant_paye' => $commande->getMontantPaye(), |
|
|
'commentaire' => $commande->commentaire, |
|
|
'commentaire' => $commande->commentaire, |
|
|
]; |
|
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
foreach ($commande->commandeProduits as $commande_produit) { |
|
|
foreach ($commande->commandeProduits as $commande_produit) { |
|
|
$json_commande['produits'][$commande_produit->id_produit] = $commande_produit->quantite; |
|
|
$json_commande['produits'][$commande_produit->id_produit] = $commande_produit->quantite; |
|
|
|
|
|
|
|
|
return json_encode($json_commande); |
|
|
return json_encode($json_commande); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function creditHistorique($type, $montant, $id_etablissement, $id_user, $id_user_action) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Enregistre un modèle de type CreditHistorique. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $type |
|
|
|
|
|
* @param float $montant |
|
|
|
|
|
* @param integer $id_etablissement |
|
|
|
|
|
* @param integer $id_user |
|
|
|
|
|
* @param integer $id_user_action |
|
|
|
|
|
*/ |
|
|
|
|
|
public function creditHistorique($type, $montant, $id_etablissement, $id_user, $id_user_action) |
|
|
|
|
|
{ |
|
|
$credit_historique = new CreditHistorique; |
|
|
$credit_historique = new CreditHistorique; |
|
|
$credit_historique->id_user = $this->id_user; |
|
|
$credit_historique->id_user = $this->id_user; |
|
|
$credit_historique->id_commande = $this->id; |
|
|
$credit_historique->id_commande = $this->id; |
|
|
|
|
|
|
|
|
$credit_historique->save(); |
|
|
$credit_historique->save(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getStatutPaiement() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le statut de paiement de la commande (payée, surplus, ou impayée). |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getStatutPaiement() |
|
|
|
|
|
{ |
|
|
// payé |
|
|
// payé |
|
|
if ($this->getMontant() - $this->getMontantPaye() < 0.01 && |
|
|
if ($this->getMontant() - $this->getMontantPaye() < 0.01 && |
|
|
$this->getMontant() - $this->getMontantPaye() >= 0) { |
|
|
|
|
|
|
|
|
$this->getMontant() - $this->getMontantPaye() >= 0) |
|
|
|
|
|
{ |
|
|
return self::STATUT_PAYEE; |
|
|
return self::STATUT_PAYEE; |
|
|
} |
|
|
} |
|
|
// à rembourser |
|
|
// à rembourser |
|
|
|
|
|
|
|
|
return self::STATUT_IMPAYEE; |
|
|
return self::STATUT_IMPAYEE; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getResumePanier() { |
|
|
|
|
|
if (!isset($this->commandeProduits)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le résumé du panier au format HTML. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getResumePanier() |
|
|
|
|
|
{ |
|
|
|
|
|
if (!isset($this->commandeProduits)) { |
|
|
$this->commandeProduits = CommandeProduit::find()->where(['id_commande' => $this->id])->all(); |
|
|
$this->commandeProduits = CommandeProduit::find()->where(['id_commande' => $this->id])->all(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$html = ''; |
|
|
$html = ''; |
|
|
$count = count($this->commandeProduits); |
|
|
$count = count($this->commandeProduits); |
|
|
$i = 0; |
|
|
$i = 0; |
|
|
foreach ($this->commandeProduits as $p) { |
|
|
foreach ($this->commandeProduits as $p) { |
|
|
if (isset($p->produit)) { |
|
|
if (isset($p->produit)) { |
|
|
$html .= $p->quantite . ' x ' . Html::encode($p->produit->nom); |
|
|
$html .= $p->quantite . ' x ' . Html::encode($p->produit->nom); |
|
|
if (++$i != $count) |
|
|
|
|
|
|
|
|
if (++$i != $count) { |
|
|
$html .= '<br />'; |
|
|
$html .= '<br />'; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $html; |
|
|
return $html; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getResumePointVente() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le résumé du point de vente lié à la commande au format HTML. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getResumePointVente() |
|
|
|
|
|
{ |
|
|
$html = ''; |
|
|
$html = ''; |
|
|
|
|
|
|
|
|
if (isset($this->pointVente)) { |
|
|
if (isset($this->pointVente)) { |
|
|
|
|
|
|
|
|
return $html; |
|
|
return $html; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getStrMontant() { |
|
|
|
|
|
return number_format($this->montant, 2) . ' €'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getResumeMontant() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le résumé du paiement (montant, statut). |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getResumeMontant() |
|
|
|
|
|
{ |
|
|
$html = ''; |
|
|
$html = ''; |
|
|
|
|
|
|
|
|
$html .= $this->getStrMontant() . '<br />'; |
|
|
|
|
|
|
|
|
$html .= $this->getMontant(true) . '<br />'; |
|
|
|
|
|
|
|
|
if ($this->montant_paye) { |
|
|
if ($this->montant_paye) { |
|
|
if ($this->getStatutPaiement() == Commande::STATUT_PAYEE) { |
|
|
if ($this->getStatutPaiement() == Commande::STATUT_PAYEE) { |
|
|
|
|
|
|
|
|
} elseif ($this->getStatutPaiement() == Commande::STATUT_SURPLUS) { |
|
|
} elseif ($this->getStatutPaiement() == Commande::STATUT_SURPLUS) { |
|
|
$html .= '<span class="label label-success">Payée</span>'; |
|
|
$html .= '<span class="label label-success">Payée</span>'; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
$html .= '<span class="label label-default">À régler sur place</span>'; |
|
|
$html .= '<span class="label label-default">À régler sur place</span>'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $html; |
|
|
return $html; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getStrUser() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne une chaine de caractère décrivant l'utilisateur lié à la commande. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getStrUser() |
|
|
|
|
|
{ |
|
|
if (isset($this->user)) { |
|
|
if (isset($this->user)) { |
|
|
return Html::encode($this->user->prenom . ' ' . $this->user->nom); |
|
|
return Html::encode($this->user->prenom . ' ' . $this->user->nom); |
|
|
} elseif (strlen($this->username)) { |
|
|
} elseif (strlen($this->username)) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static function findBy($params = []) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Recherche dans les commandes suivant les paramètres suivants : |
|
|
|
|
|
* - id_etablissement |
|
|
|
|
|
* - condition |
|
|
|
|
|
* - date |
|
|
|
|
|
* - type |
|
|
|
|
|
* - orderby |
|
|
|
|
|
* - limit |
|
|
|
|
|
* |
|
|
|
|
|
* @param array $params |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function findBy($params = []) |
|
|
|
|
|
{ |
|
|
if (!isset($params['id_etablissement'])) |
|
|
if (!isset($params['id_etablissement'])) |
|
|
$params['id_etablissement'] = Yii::$app->user->identity->id_etablissement; |
|
|
$params['id_etablissement'] = Yii::$app->user->identity->id_etablissement; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $commandes; |
|
|
return $commandes; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getEtat() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne l'état de la commande (livrée, modifiable ou en préparation) |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getEtat() |
|
|
|
|
|
{ |
|
|
$delai_commande = Etablissement::getConfig('delai_commande', $this->production->id_etablissement); |
|
|
$delai_commande = Etablissement::getConfig('delai_commande', $this->production->id_etablissement); |
|
|
$heure_limite = Etablissement::getConfig('heure_limite_commande', $this->production->id_etablissement); |
|
|
$heure_limite = Etablissement::getConfig('heure_limite_commande', $this->production->id_etablissement); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($nb_jours <= 0) { |
|
|
if ($nb_jours <= 0) { |
|
|
return self::ETAT_LIVREE; |
|
|
return self::ETAT_LIVREE; |
|
|
} elseif ($nb_jours >= $delai_commande && |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
elseif ($nb_jours >= $delai_commande && |
|
|
($nb_jours != $delai_commande || |
|
|
($nb_jours != $delai_commande || |
|
|
($nb_jours == $delai_commande && $heure_today < $heure_limite))) { |
|
|
|
|
|
|
|
|
($nb_jours == $delai_commande && $heure_today < $heure_limite))) |
|
|
|
|
|
{ |
|
|
return self::ETAT_MODIFIABLE; |
|
|
return self::ETAT_MODIFIABLE; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return self::ETAT_PREPARATION; |
|
|
return self::ETAT_PREPARATION; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le type de la commande (client, automatique ou admin) sous forme |
|
|
|
|
|
* texte ou HTML. |
|
|
|
|
|
* |
|
|
|
|
|
* @param boolean $with_label |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
public function getStrType($with_label = false) { |
|
|
public function getStrType($with_label = false) { |
|
|
$class_label = ''; |
|
|
$class_label = ''; |
|
|
$str = ''; |
|
|
$str = ''; |
|
|
|
|
|
|
|
|
return $str; |
|
|
return $str; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getStrHistorique() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne l'historique de la commande (ajoutée, modifiée, supprimée) au format |
|
|
|
|
|
* HTML. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getStrHistorique() |
|
|
|
|
|
{ |
|
|
$arr = [ |
|
|
$arr = [ |
|
|
'class' => 'create', |
|
|
'class' => 'create', |
|
|
'glyphicon' => 'plus', |
|
|
'glyphicon' => 'plus', |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $html ; |
|
|
return $html ; |
|
|
} |
|
|
} |
|
|
public function getClassHistorique() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne une classe identifiant l'historique de la commande (ajoutée, |
|
|
|
|
|
* modifiée, supprimée). |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getClassHistorique() |
|
|
|
|
|
{ |
|
|
if(!is_null($this->date_delete)) { |
|
|
if(!is_null($this->date_delete)) { |
|
|
return 'commande-delete' ; |
|
|
return 'commande-delete' ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return 'commande-create' ; |
|
|
return 'commande-create' ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |