ソースを参照

Refactoring/traduction modèle PointVente > PointSale

dev
コミット
47e8e9357e
1個のファイルの変更104行の追加95行の削除
  1. +104
    -95
      common/models/PointSale.php

+ 104
- 95
common/models/PointSale.php ファイルの表示

@@ -40,25 +40,25 @@ namespace common\models;

use Yii;
use yii\helpers\Html;
use common\models\PointVenteUser;
use common\models\ProductionPointVente;
use common\models\PointSaleUser;
use common\models\ProductionPointSale;

/**
* This is the model class for table "point_vente".
*
* @property integer $id
* @property string $nom
* @property string $adresse
* @property integer $id_boulangerie
* @property string $name
* @property string $address
* @property integer $id_producer
*/
class PointSale extends \yii\db\ActiveRecord
{
var $commandes = [];
var $recettes = 0;
var $data_select_commandes;
var $data_options_commandes;
var $orders = [];
var $revenues = 0;
var $data_select_orders;
var $data_options_orders;
var $users = [];
var $users_commentaire = [];
var $users_comment = [];

/**
* @inheritdoc
@@ -74,15 +74,19 @@ class PointSale extends \yii\db\ActiveRecord
public function rules()
{
return [
[['nom'], 'required'],
[['acces_restreint'], 'boolean'],
[['nom', 'code'], 'string', 'max' => 255],
[['adresse', 'localite', 'horaires_lundi', 'horaires_mardi', 'horaires_mercredi', 'horaires_jeudi', 'horaires_vendredi', 'horaires_samedi', 'horaires_dimanche'], 'string'],
[['point_fabrication', 'vrac', 'pain', 'credit_pain', 'livraison_lundi', 'livraison_mardi', 'livraison_mercredi', 'livraison_jeudi', 'livraison_vendredi', 'livraison_samedi', 'livraison_dimanche'], 'boolean'],
['point_fabrication', 'default', 'value' => 0],
['id_etablissement', 'integer'],
['id_etablissement', 'required'],
[['users', 'users_commentaire', 'code'], 'safe']
[['name'], 'required'],
[['restricted_access'], 'boolean'],
[['name', 'code'], 'string', 'max' => 255],
[['address', 'locality', 'infos_monday', 'infos_tuesday',
'infos_wednesday', 'infos_thursday', 'infos_friday',
'infos_saterday', 'infos_sunday'], 'string'],
[['point_production', 'credit', 'delivery_monday', 'delivery_tuesday',
'delivery_wednesday', 'delivery_thursday', 'delivery_friday',
'delivery_saterday', 'delivery_sunday'], 'boolean'],
['point_production', 'default', 'value' => 0],
['id_producer', 'integer'],
['id_producer', 'required'],
[['users', 'users_comment', 'code'], 'safe']
];
}

@@ -93,28 +97,26 @@ class PointSale extends \yii\db\ActiveRecord
{
return [
'id' => 'ID',
'nom' => 'Nom',
'adresse' => 'Adresse',
'localite' => 'Localité',
'point_fabrication' => 'Point de fabrication',
'horaires_lundi' => 'Lundi',
'horaires_mardi' => 'Mardi',
'horaires_mercredi' => 'Mercredi',
'horaires_jeudi' => 'Jeudi',
'horaires_vendredi' => 'Vendredi',
'horaires_samedi' => 'Samedi',
'horaires_dimanche' => 'Dimanche',
'vrac' => 'Livraison de vrac',
'pain' => 'Livraison de pain',
'acces_restreint' => 'Accès restreint',
'credit_pain' => 'Activer le Crédit Pain',
'livraison_lundi' => 'Lundi',
'livraison_mardi' => 'Mardi',
'livraison_mercredi' => 'Mercredi',
'livraison_jeudi' => 'Jeudi',
'livraison_vendredi' => 'Vendredi',
'livraison_samedi' => 'Samedi',
'livraison_dimanche' => 'Dimanche',
'name' => 'Nom',
'address' => 'Adresse',
'locality' => 'Localité',
'point_production' => 'Point de production',
'infos_monday' => 'Lundi',
'infos_tuesday' => 'Mardi',
'infos_wednesday' => 'Mercredi',
'infos_thursday' => 'Jeudi',
'infos_friday' => 'Vendredi',
'infos_saturday' => 'Samedi',
'infos_sunday' => 'Dimanche',
'restricted_access' => 'Accès restreint',
'credit' => 'Activer le Crédit Pain',
'delivery_monday' => 'Lundi',
'delivery_tuesday' => 'Mardi',
'delivery_wednesday' => 'Mercredi',
'delivery_thursday' => 'Jeudi',
'delivery_friday' => 'Vendredi',
'delivery_saturday' => 'Samedi',
'delivery_sunday' => 'Dimanche',
'code' => 'Code',
];
}
@@ -125,12 +127,18 @@ class PointSale extends \yii\db\ActiveRecord
public function getPointSaleUser()
{
return $this->hasMany(PointSaleUser::className(), ['id_point_sale' => 'id']);
return $this->hasMany(
PointSaleUser::className(),
['id_point_sale' => 'id']
);
}

public function getProductionPointVente()
{
return $this->hasMany(ProductionPointVente::className(), ['id_point_sale' => 'id']);
return $this->hasMany(
ProductionPointVente::className(),
['id_point_sale' => 'id']
);
}

/**
@@ -138,17 +146,17 @@ class PointSale extends \yii\db\ActiveRecord
*
* @param array $commandes
*/
public function initCommandes($commandes)
public function initOrders($orders)
{
$this->commandes = [];
$this->recettes = 0;
$this->orders = [];
$this->revenues = 0;

foreach ($commandes as $c) {
if ($this->id == $c->id_point_vente) {
$this->commandes[] = $c;
foreach ($orders as $o) {
if ($this->id == $c->id_point_sale) {
$this->orders[] = $o;

if(is_null($c->date_delete)) {
$this->recettes += (float) $c->montant;
if(is_null($o->date_delete)) {
$this->revenues += (float) $o->amount;
}
}
}
@@ -159,9 +167,9 @@ class PointSale extends \yii\db\ActiveRecord
*
* @return array
*/
public function getCommandes()
public function getOrders()
{
return $this->commandes;
return $this->orders;
}
/**
@@ -173,21 +181,21 @@ class PointSale extends \yii\db\ActiveRecord
*/
public function save($runValidation = true, $attributeNames = NULL)
{
$this->id_etablissement = Yii::$app->user->identity->id_etablissement;
$this->pain = 1;
$this->id_producer = Producer::getCurrent();
return parent::save($runValidation, $attributeNames);
}

/**
* Traite la mise à jour de l'attribut 'point_fabrication'.
* Traite la mise à jour de l'attribut 'point_production'.
*/
public function gestionPointFabrication()
public function processPointProduction()
{
if ($this->point_fabrication) {
PointVente::updateAll(
['point_fabrication' => 0], ['id_etablissement' => $this->id_etablissement]
if ($this->point_production) {
PointSale::updateAll(
['point_production' => 0],
['id_producer' => $this->id_producer]
);
$this->point_fabrication = 1;
$this->point_production = 1;
$this->save();
}
}
@@ -195,21 +203,21 @@ class PointSale extends \yii\db\ActiveRecord
/**
* Traite les accès restreints d'un point de vente.
*/
public function gestionAccesRestreint()
public function processRestrictedAccess()
{
PointVenteUser::deleteAll(['id_point_vente' => $this->id]);
PointSaleUser::deleteAll(['id_point_sale' => $this->id]);

if (is_array($this->users) && count($this->users)) {
foreach ($this->users as $key => $val) {
$user = User::findOne($val);
if ($user) {
$point_vente_user = new PointVenteUser;
$point_vente_user->id_user = $val;
$point_vente_user->id_point_vente = $this->id;
if (isset($this->users_commentaire[$val]) && strlen($this->users_commentaire[$val])) {
$point_vente_user->commentaire = $this->users_commentaire[$val];
$pointSaleUser = new PointSaleUser;
$pointSaleUser->id_user = $val;
$pointSaleUser->id_point_sale = $this->id;
if (isset($this->users_comment[$val]) && strlen($this->users_comment[$val])) {
$point_sale_user->comment = $this->users_comment[$val];
}
$point_vente_user->save();
$point_sale_user->save();
}
}
}
@@ -220,12 +228,12 @@ class PointSale extends \yii\db\ActiveRecord
*
* @return string|null
*/
public function getCommentaire()
public function getComment()
{
if (isset($this->pointVenteUser)) {
foreach ($this->pointVenteUser as $pvu) {
if ($pvu->id_user == Yii::$app->user->identity->id) {
return $pvu->commentaire;
if (isset($this->pointSaleUser)) {
foreach ($this->pointSaleUser as $pointSaleUser) {
if ($pointSaleUser->id_user == Yii::$app->user->identity->id) {
return $pointSaleUser->comment;
}
}
}
@@ -239,11 +247,7 @@ class PointSale extends \yii\db\ActiveRecord
*/
public static function count()
{
return PointVente::find()
->where([
'id_etablissement' => Yii::$app->user->identity->id_etablissement
])
->count();
return self::searchCount(['id_producer' => Producer::getCurrent()]) ;
}

/**
@@ -252,7 +256,7 @@ class PointSale extends \yii\db\ActiveRecord
* @param string $code
* @return boolean
*/
public function verifCode($code)
public function validateCode($code)
{
if (strlen($this->code)) {
if (trim(strtolower($code)) == trim(strtolower($this->code))) {
@@ -260,9 +264,9 @@ class PointSale extends \yii\db\ActiveRecord
} else {
return false;
}
} else {
return true;
}
return true;
}
/**
@@ -271,20 +275,24 @@ class PointSale extends \yii\db\ActiveRecord
*
* @return string
*/
public function strJoursLivraison() {
public function getStrDeliveryDays()
{
$str = '' ;
if($this->livraison_lundi) $str .= 'lundi, ' ;
if($this->livraison_mardi) $str .= 'mardi, ' ;
if($this->livraison_mercredi) $str .= 'mercredi, ' ;
if($this->livraison_jeudi) $str .= 'jeudi, ' ;
if($this->livraison_vendredi) $str .= 'vendredi, ' ;
if($this->livraison_samedi) $str .= 'samedi, ' ;
if($this->livraison_dimanche) $str .= 'dimanche, ' ;
if($this->delivery_monday) $str .= 'lundi, ' ;
if($this->delivery_tuesday) $str .= 'mardi, ' ;
if($this->delivery_wednesday) $str .= 'mercredi, ' ;
if($this->delivery_thursday) $str .= 'jeudi, ' ;
if($this->delivery_friday) $str .= 'vendredi, ' ;
if($this->delivery_saterday) $str .= 'samedi, ' ;
if($this->delivery_sunday) $str .= 'dimanche, ' ;

if(strlen($str))
if(strlen($str)) {
return substr($str, 0, strlen($str)-2) ;
else
}
else {
return '' ;
}
}
/**
@@ -294,11 +302,12 @@ class PointSale extends \yii\db\ActiveRecord
* @param string $jour
* @return string
*/
public function strInfos($jour) {
public function getStrInfos($day)
{
$str = '' ;
$champs = 'horaires_'.$jour ;
$field = 'infos_'.$day ;
if(strlen($this->$champs)) {
if(strlen($this->$field)) {
$str = nl2br(Html::encode($this->$champs)) ;
$str = preg_replace('/\[select_previous_day\](.*?)\[\/select_previous_day\]/', '<a href="javascript:void(0);" class="select-previous-day">$1</a>' , $str) ;
}

読み込み中…
キャンセル
保存