Quellcode durchsuchen

Refactoring services #885

refactoring
Guillaume Bourgeois vor 1 Jahr
Ursprung
Commit
79ee58e33e
79 geänderte Dateien mit 992 neuen und 902 gelöschten Zeilen
  1. +6
    -2
      backend/controllers/BackendController.php
  2. +80
    -110
      backend/controllers/TaxRateAdminController.php
  3. +1
    -1
      backend/views/producer/update.php
  4. +2
    -2
      backend/views/product/_form.php
  5. +14
    -0
      common/components/BusinessLogic.php
  6. +7
    -1
      common/controllers/CommonController.php
  7. +2
    -2
      common/forms/LoginForm.php
  8. +2
    -2
      common/helpers/CSV.php
  9. +2
    -2
      common/helpers/GlobalParam.php
  10. +4
    -4
      common/helpers/Tiller.php
  11. +1
    -1
      common/logic/Config/TaxRate/TaxRate.php
  12. +1
    -1
      common/logic/Config/TaxRate/TaxRateContainer.php
  13. +0
    -1
      common/logic/Config/TaxRate/TaxRateFactory.php
  14. +1
    -1
      common/logic/Config/TaxRate/TaxRateRepository.php
  15. +2
    -2
      common/logic/Development/DevelopmentPriority/DevelopmentPriorityModel.php
  16. +204
    -0
      common/logic/Distribution/Distribution/Distribution.php
  17. +171
    -0
      common/logic/Distribution/Distribution/DistributionBuilder.php
  18. +1
    -7
      common/logic/Distribution/Distribution/DistributionContainer.php
  19. +0
    -16
      common/logic/Distribution/Distribution/DistributionFactory.php
  20. +0
    -475
      common/logic/Distribution/Distribution/DistributionModel.php
  21. +40
    -0
      common/logic/Distribution/Distribution/DistributionRepository.php
  22. +65
    -0
      common/logic/Distribution/Distribution/DistributionSolver.php
  23. +2
    -63
      common/logic/Distribution/PointSaleDistribution/PointSaleDistribution.php
  24. +90
    -0
      common/logic/Distribution/PointSaleDistribution/PointSaleDistributionBuilder.php
  25. +31
    -0
      common/logic/Distribution/PointSaleDistribution/PointSaleDistributionContainer.php
  26. +0
    -16
      common/logic/Distribution/PointSaleDistribution/PointSaleDistributionFactory.php
  27. +18
    -0
      common/logic/Distribution/PointSaleDistribution/PointSaleDistributionRepository.php
  28. +2
    -2
      common/logic/Distribution/ProductDistribution/ProductDistribution.php
  29. +3
    -3
      common/logic/Distribution/ProductDistribution/ProductDistributionBuilder.php
  30. +31
    -0
      common/logic/Distribution/ProductDistribution/ProductDistributionContainer.php
  31. +11
    -0
      common/logic/Distribution/ProductDistribution/ProductDistributionRepository.php
  32. +8
    -8
      common/logic/Document/Document/DocumentModel.php
  33. +12
    -12
      common/logic/Order/Order/OrderModel.php
  34. +1
    -1
      common/logic/Order/ProductOrder/ProductOrderModel.php
  35. +5
    -5
      common/logic/PointSale/PointSale/PointSale.php
  36. +1
    -1
      common/logic/PointSale/PointSale/PointSaleContainer.php
  37. +2
    -2
      common/logic/PointSale/PointSale/PointSaleFactory.php
  38. +2
    -2
      common/logic/PointSale/PointSale/PointSaleSearch.php
  39. +4
    -4
      common/logic/Producer/Producer/Producer.php
  40. +6
    -6
      common/logic/Producer/Producer/ProducerBuilder.php
  41. +1
    -1
      common/logic/Producer/Producer/ProducerContainer.php
  42. +3
    -3
      common/logic/Producer/Producer/ProducerFactory.php
  43. +11
    -11
      common/logic/Producer/Producer/ProducerRepository.php
  44. +31
    -27
      common/logic/Producer/Producer/ProducerSolver.php
  45. +1
    -1
      common/logic/Producer/Producer/ProducerUtils.php
  46. +7
    -7
      common/logic/Product/Product/Product.php
  47. +1
    -1
      common/logic/Product/Product/ProductContainer.php
  48. +2
    -2
      common/logic/Product/Product/ProductFactory.php
  49. +2
    -2
      common/logic/Product/Product/ProductSearch.php
  50. +8
    -8
      common/logic/Subscription/Subscription/SubscriptionModel.php
  51. +2
    -2
      common/logic/User/User/UserBuilder.php
  52. +6
    -0
      common/logic/User/User/UserContainer.php
  53. +2
    -2
      common/logic/User/User/UserRepository.php
  54. +3
    -3
      common/logic/User/User/UserUtils.php
  55. +2
    -2
      common/logic/User/UserProducer/UserProducerBuilder.php
  56. +2
    -2
      common/logic/User/UserProducer/UserProducerModel.php
  57. +2
    -2
      common/logic/User/UserProducer/UserProducerRepository.php
  58. +3
    -3
      common/mail/orderConfirm-html.php
  59. +3
    -3
      common/mail/orderConfirm-text.php
  60. +3
    -3
      common/mail/paymentError-html.php
  61. +2
    -2
      console/migrations/m190205_164612_ajout_produit_don_aux_distributions_existantes.php
  62. +4
    -4
      console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php
  63. +2
    -2
      console/migrations/m190515_122438_ajout_champs_price_product_subscription.php
  64. +2
    -2
      console/migrations/m190522_091006_option_comportement_annulation_commande.php
  65. +3
    -3
      console/migrations/m200601_073309_add_producer_options.php
  66. +2
    -2
      console/migrations/m220915_072309_producer_add_option_billing_frequency.php
  67. +2
    -2
      console/migrations/m220915_083713_producer_add_options_billing.php
  68. +6
    -6
      frontend/forms/SignupForm.php
  69. +3
    -3
      frontend/views/layouts/main.php
  70. +1
    -1
      frontend/views/site/signup.php
  71. +15
    -15
      producer/controllers/OrderController.php
  72. +2
    -2
      producer/controllers/ProducerBaseController.php
  73. +2
    -2
      producer/models/CreditForm.php
  74. +2
    -2
      producer/views/credit/add.php
  75. +2
    -2
      producer/views/order/_form.php
  76. +5
    -5
      producer/views/order/order.php
  77. +3
    -3
      producer/views/site/index.php
  78. +2
    -2
      producer/views/subscription/_form.php
  79. +2
    -2
      producer/views/subscription/index.php

+ 6
- 2
backend/controllers/BackendController.php Datei anzeigen

@@ -38,7 +38,11 @@ termes.

namespace backend\controllers;

class BackendController extends \common\controllers\CommonController
use common\logic\PointSale\PointSale\PointSale;
use common\logic\Product\Product\Product;
use common\controllers\CommonController;

class BackendController extends CommonController
{
/**
* Vérifie si l'utilisateur a au moins saisi un produit et un point de vente.
@@ -46,7 +50,7 @@ class BackendController extends \common\controllers\CommonController
*/
public function checkProductsPointsSale()
{
if (!ProductModel::searchCount() || !PointSaleModel::searchCount()) {
if (!Product::searchCount() || !PointSale::searchCount()) {
$this->redirect(['site/index', 'error_products_points_sale' => 1]);
}
}

+ 80
- 110
backend/controllers/TaxRateAdminController.php Datei anzeigen

@@ -38,6 +38,7 @@

namespace backend\controllers;

use common\logic\Config\TaxRate\TaxRate;
use Yii;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
@@ -49,118 +50,87 @@ use yii\data\ActiveDataProvider;
*/
class TaxRateAdminController extends BackendController
{

public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN;
}
]
],
],
];
}

/**
* Liste les taxes.
*
* @return mixed
*/
public function actionIndex()
{
$dataProviderTaxRate = new ActiveDataProvider([
'query' => TaxRateModel::find()
]);

return $this->render('index', [
'dataProviderTaxRate' => $dataProviderTaxRate,
]);
}

/**
* Crée une taxe.
*
* @return mixed
*/
public function actionCreate()
{
$model = new TaxRate();

if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('success', 'Taxe créé.');
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}

/**
* Édition d'une taxe.
*
* @return mixed
*/
public function actionUpdate($id)
{


$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('success', 'Taxe édité.');
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
}
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return $this->isUserCurrentAdmin();
}
]
],
],
];
}

public function actionIndex()
{
$dataProviderTaxRate = new ActiveDataProvider([
'query' => TaxRate::find()
]);

return $this->render('index', [
'dataProviderTaxRate' => $dataProviderTaxRate,
]);
}

public function actionCreate()
{
$model = $this->getLogic()->getTaxRateContainer()->getFactory()->create();

if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->setFlash('success', 'Taxe créé.');
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}

/**
* Supprime une commande récurrente.
*
* @param integer $id
*/
public function actionDelete($id)
{
$taxeRate = TaxRateModel::searchOne([
'id' => $id
]) ;
$taxeRate->delete();

Yii::$app->getSession()->setFlash('success', 'Taxe supprimé');
return $this->redirect(['tax-rate-admin/index']);
}

public function actionUpdate($id)
{
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->setFlash('success', 'Taxe édité.');
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
}


/**
* Finds the Developpement model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Developpement the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = TaxRateModel::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}

public function actionDelete(int $id)
{
$taxeRate = TaxRate::searchOne([
'id' => $id
]);
$taxeRate->delete();

Yii::$app->getSession()->setFlash('success', 'Taxe supprimé');
return $this->redirect(['tax-rate-admin/index']);
}

protected function findModel($id)
{
if (($model = TaxRate::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}

}

+ 1
- 1
backend/views/producer/update.php Datei anzeigen

@@ -430,7 +430,7 @@ $this->addBreadcrumb($this->getTitle());
<div class="panel-body">
<h4>Facturation</h4>
<?= $form->field($model, 'id_tax_rate_default')
->dropDownList(ArrayHelper::map(TaxRateModel::find()->all(), 'id', function ($model) {
->dropDownList(ArrayHelper::map(TaxRate::find()->all(), 'id', function ($model) {
return $model->name;
}))
->label('TVA à appliquer par défaut'); ?>

+ 2
- 2
backend/views/product/_form.php Datei anzeigen

@@ -37,10 +37,10 @@ use common\helpers\GlobalParam;
$producer = \common\helpers\GlobalParam::getCurrentProducer();
$taxRateDefault = $producer->taxRate;

$taxRateNamesArray = array_merge(array(0 => 'Tva par défaut'), ArrayHelper::map(TaxRateModel::find()->all(), 'id', function ($model) {
$taxRateNamesArray = array_merge(array(0 => 'Tva par défaut'), ArrayHelper::map(TaxRate::find()->all(), 'id', function ($model) {
return $model->name;
}));
$taxRateValuesArray = array_merge(array(0 => $taxRateDefault->value), ArrayHelper::map(TaxRateModel::find()->all(), 'id', function ($model) {
$taxRateValuesArray = array_merge(array(0 => $taxRateDefault->value), ArrayHelper::map(TaxRate::find()->all(), 'id', function ($model) {
return $model->value;
}));
foreach ($taxRateValuesArray as $key => $taxRateValue) {

+ 14
- 0
common/components/BusinessLogic.php Datei anzeigen

@@ -4,6 +4,8 @@ namespace common\components;

use common\logic\Config\TaxRate\TaxRateContainer;
use common\logic\Distribution\Distribution\DistributionContainer;
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContainer;
use common\logic\Distribution\ProductDistribution\ProductDistributionContainer;
use common\logic\Document\Document\DocumentContainer;
use common\logic\Order\Order\OrderContainer;
use common\logic\Order\OrderStatusHistory\OrderStatusHistoryContainer;
@@ -37,6 +39,8 @@ class BusinessLogic
$this->getProducerPriceRangeContainer(),
$this->getUserProducerContainer(),
$this->getOrderSatusHistoryContainer(),
$this->getPointSaleDistributionContainer(),
$this->getProductDistributionContainer(),
$this->getProductCategoryContainer(),
$this->getProductPointSaleContainer(),
$this->getProductOrderContainer(),
@@ -151,6 +155,16 @@ class BusinessLogic
return new ProductSubscriptionContainer();
}

public function getPointSaleDistributionContainer(): PointSaleDistributionContainer
{
return new PointSaleDistributionContainer();
}

public function getProductDistributionContainer(): ProductDistributionContainer
{
return new ProductDistributionContainer();
}

/*
* Hiérarchie des apps
*/

+ 7
- 1
common/controllers/CommonController.php Datei anzeigen

@@ -39,6 +39,7 @@ termes.
namespace common\controllers;

use common\components\BusinessLogic;
use common\logic\User\User\UserModel;
use yii;

class CommonController extends \yii\web\Controller
@@ -72,11 +73,16 @@ class CommonController extends \yii\web\Controller
return Yii::$app->urlManagerBackend;
}

public function getUser()
public function getUserCurrent()
{
return Yii::$app->getUser();
}

public function isUserCurrentAdmin()
{
return $this->getLogic()->getUserContainer()->getSolver()->isAdmin($this->getUserCurrent());
}

public function getRequest()
{
return Yii::$app->request;

+ 2
- 2
common/forms/LoginForm.php Datei anzeigen

@@ -38,7 +38,7 @@ termes.

namespace common\forms;

use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\User\User\UserModel;
use Yii;
use yii\base\Model;
@@ -74,7 +74,7 @@ class LoginForm extends Model
['id_producer', 'integer'],
['id_producer', function($attribute, $params) {
if ($this->id_producer) {
$producer = ProducerModel::findOne($this->id_producer);
$producer = Producer::findOne($this->id_producer);
if (!$producer) {
$this->addError($attribute, 'Ce producteur n\'existe pas.');
}

+ 2
- 2
common/helpers/CSV.php Datei anzeigen

@@ -39,14 +39,14 @@

namespace common\helpers;

use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

class CSV
{

public static function array2csv(array &$array)
{
$separator = ProducerModel::getConfig('option_csv_separator') ?: ';';
$separator = Producer::getConfig('option_csv_separator') ?: ';';

if (count($array) == 0) {
return null;

+ 2
- 2
common/helpers/GlobalParam.php Datei anzeigen

@@ -38,7 +38,7 @@

namespace common\helpers;

use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\models\Producer;

class GlobalParam
@@ -61,7 +61,7 @@ class GlobalParam
public static function getCurrentProducer()
{
if (\Yii::$app->params['producer'] == false) {
\Yii::$app->params['producer'] = ProducerModel::searchOne();
\Yii::$app->params['producer'] = Producer::searchOne();
}
return \Yii::$app->params['producer'];
}

+ 4
- 4
common/helpers/Tiller.php Datei anzeigen

@@ -38,7 +38,7 @@

namespace common\helpers;

use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use linslin\yii2\curl;

class Tiller
@@ -53,9 +53,9 @@ class Tiller
public function __construct()
{
$this->curl = new curl\Curl();
$this->producer_tiller = ProducerModel::getConfig('tiller');
$this->provider_token = ProducerModel::getConfig('tiller_provider_token');
$this->restaurant_token = ProducerModel::getConfig('tiller_restaurant_token');
$this->producer_tiller = Producer::getConfig('tiller');
$this->provider_token = Producer::getConfig('tiller_provider_token');
$this->restaurant_token = Producer::getConfig('tiller_restaurant_token');
}

public function getOrders($date)

common/logic/Config/TaxRate/TaxRateModel.php → common/logic/Config/TaxRate/TaxRate.php Datei anzeigen

@@ -8,7 +8,7 @@ use common\components\ActiveRecordCommon;
* This is the model class for table "tax_rate".
*
*/
class TaxRateModel extends ActiveRecordCommon
class TaxRate extends ActiveRecordCommon
{
/**
* @inheritdoc

+ 1
- 1
common/logic/Config/TaxRate/TaxRateContainer.php Datei anzeigen

@@ -8,7 +8,7 @@ class TaxRateContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return TaxRateModel::class;
return TaxRate::class;
}

public function getServices(): array

+ 0
- 1
common/logic/Config/TaxRate/TaxRateFactory.php Datei anzeigen

@@ -4,7 +4,6 @@ namespace common\logic\Config\TaxRate;

use common\logic\BaseService;
use common\logic\FactoryInterface;
use Stripe\TaxRate;

class TaxRateFactory extends BaseService implements FactoryInterface
{

+ 1
- 1
common/logic/Config/TaxRate/TaxRateRepository.php Datei anzeigen

@@ -26,7 +26,7 @@ class TaxRateRepository extends BaseService implements RepositoryInterface
public function getAsArray(): array
{
$taxRateArrayReturn = [];
$taxRateArray = TaxRateModel::find()->all();
$taxRateArray = TaxRate::find()->all();

foreach($taxRateArray as $taxRate) {
$taxRateArrayReturn[$taxRate->id] = $taxRate;

+ 2
- 2
common/logic/Development/DevelopmentPriority/DevelopmentPriorityModel.php Datei anzeigen

@@ -38,7 +38,7 @@ termes.

namespace common\logic\Development\DevelopmentPriority;

use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\components\ActiveRecordCommon ;

/**
@@ -78,7 +78,7 @@ class DevelopmentPriorityModel extends ActiveRecordCommon

public function getProducer()
{
return $this->hasOne(ProducerModel::class, ['id' => 'id_producer']);
return $this->hasOne(Producer::class, ['id' => 'id_producer']);
}

/**

+ 204
- 0
common/logic/Distribution/Distribution/Distribution.php Datei anzeigen

@@ -0,0 +1,204 @@
<?php

/**
* Copyright distrib (2018)
*
* contact@opendistrib.net
*
* Ce logiciel est un programme informatique servant à aider les producteurs
* à distribuer leur production en circuits courts.
*
* Ce logiciel est régi par la licence CeCILL soumise au droit français et
* respectant les principes de diffusion des logiciels libres. Vous pouvez
* utiliser, modifier et/ou redistribuer ce programme sous les conditions
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
* sur le site "http://www.cecill.info".
*
* En contrepartie de l'accessibilité au code source et des droits de copie,
* de modification et de redistribution accordés par cette licence, il n'est
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
* seule une responsabilité restreinte pèse sur l'auteur du programme, le
* titulaire des droits patrimoniaux et les concédants successifs.
*
* A cet égard l'attention de l'utilisateur est attirée sur les risques
* associés au chargement, à l'utilisation, à la modification et/ou au
* développement et à la reproduction du logiciel par l'utilisateur étant
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à
* manipuler et qui le réserve donc à des développeurs et des professionnels
* avertis possédant des connaissances informatiques approfondies. Les
* utilisateurs sont donc invités à charger et tester l'adéquation du
* logiciel à leurs besoins dans des conditions permettant d'assurer la
* sécurité de leurs systèmes et ou de leurs données et, plus généralement,
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
*
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
* pris connaissance de la licence CeCILL, et que vous en avez accepté les
* termes.
*/

namespace common\logic\Distribution\Distribution;

use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution;
use common\logic\Distribution\ProductDistribution\ProductDistribution;
use common\logic\Order\Order\OrderModel;
use common\logic\Producer\Producer\Producer;
use common\helpers\GlobalParam;
use common\components\ActiveRecordCommon;
use common\logic\Product\Product\Product;

/**
* This is the model class for table "distribution".
*
*/
class Distribution extends ActiveRecordCommon
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'distribution';
}

/**
* @inheritdoc
*/
public function rules()
{
return [
[['date'], 'required'],
[['date'], 'safe'],
[['active'], 'integer']
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'date' => 'Date',
'active' => 'Actif',
];
}

/*
* Relations
*/

public function getProducer()
{
return $this->hasOne(Producer::class, ['id' => 'id_producer']);
}

public function getOrder()
{
return $this->hasMany(OrderModel::class, ['id_distribution' => 'id']);
}

public function getProductDistribution()
{
return $this->hasMany(ProductDistribution::class, ['id_distribution' => 'id']);
}

public function getPointSaleDistribution()
{
return $this->hasMany(PointSaleDistribution::class, ['id_distribution' => 'id']);
}

/**
* Lie un produit aux jours de distribution futurs.
*
* @param Product $product
*/
public static function linkProductIncomingDistributions($product)
{
$distributionsArray = self::getIncomingDistributions();
foreach ($distributionsArray as $distribution) {
$distribution->linkProduct($product);
}
}

/**
* Lie un point de vente aux jours de distribution futurs.
*
* @param PointSale $pointSale
*/
public static function linkPointSaleIncomingDistributions($pointSale)
{
$distributionsArray = self::getIncomingDistributions();
foreach ($distributionsArray as $distribution) {
$distribution->linkPointSale($pointSale);
}
}

/**
*
* @param type $pointSale
*/
public function linkPointSale($pointSale)
{
$pointSaleDistribution = PointSaleDistribution::searchOne([
'id_distribution' => $this->id,
'id_point_sale' => $pointSale->id
]);

if (!$pointSaleDistribution) {
$pointSaleDistribution = new PointSaleDistribution();
$pointSaleDistribution->id_distribution = $this->id;
$pointSaleDistribution->id_point_sale = $pointSale->id;
}

$dayDistribution = date('N', strtotime($this->date));
$daysArray = [
1 => 'monday',
2 => 'tuesday',
3 => 'wednesday',
4 => 'thursday',
5 => 'friday',
6 => 'saturday',
7 => 'sunday',
];

$pointSaleDistribution->delivery = 0;
$deliveryDay = 'delivery_' . $daysArray[$dayDistribution];
if ($pointSale->$deliveryDay) {
$pointSaleDistribution->delivery = 1;
}

$pointSaleDistribution->save();
}

public function isPointSaleActive($distribution, $pointSaleId)
{
$pointSaleActive = false;

if ($distribution->pointSaleDistribution) {
foreach ($distribution->pointSaleDistribution as $pointSaleDistribution) {
if ($pointSaleDistribution->id_point_sale == $pointSaleId && $pointSaleDistribution->delivery) {
$pointSaleActive = true;
}
}
}

return $pointSaleActive;
}

/**
* Active ou désactive la distribution.
*/
public function active($active = true)
{
PointSaleDistribution::setAll($this->id, true);
$this->active = (int)$active;
$this->save();

if ($active) {
// ajout des abonnements
SubscriptionModel::addAll($this->date);
}
}

}

+ 171
- 0
common/logic/Distribution/Distribution/DistributionBuilder.php Datei anzeigen

@@ -2,10 +2,181 @@

namespace common\logic\Distribution\Distribution;

use common\helpers\GlobalParam;
use common\logic\BaseService;
use common\logic\BuilderInterface;
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution;
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionBuilder;
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionRepository;
use common\logic\Distribution\ProductDistribution\ProductDistribution;
use common\logic\Order\Order\OrderModel;
use common\logic\Producer\Producer\Producer;
use common\logic\Product\Product\Product;

class DistributionBuilder extends BaseService implements BuilderInterface
{
protected DistributionRepository $distributionRepository;
protected PointSaleDistributionRepository $pointSaleDistributionRepository;
protected PointSaleDistributionBuilder $pointSaleDistributionBuilder;

public function __construct()
{
$this->distributionRepository = $this->loadService(DistributionRepository::class);
$this->pointSaleDistributionRepository = $this->loadService(PointSaleDistributionRepository::class);
$this->pointSaleDistributionBuilder = $this->loadService(PointSaleDistributionBuilder::class);
}

public function instanciate(Producer $producer, string $date, bool $delivery = true): Distribution
{
$distribution = new Distribution();

$distribution->id_producer = $producer->id;
$distribution->date = $date;
$distribution->delivery = (int) $delivery;

return $distribution;
}

public function create(Producer $producer, string $date, int $delivery = 1): Distribution
{
$distribution = $this->instanciate($producer, $date, 1);
$distribution->save();

return $distribution;
}

public function createIfNotExist(Producer $producer, string $date, int $delivery = 1)
{
$distribution = $this->distributionRepository->getOne($producer, $date);

if (!$distribution) {
$distribution = $this->create($producer, $date, 1);
}

return $distribution;
}

/**
* Initialise un jour de production.
*/
// initDistribution
public function init(string $date, Producer $producer = null): Distribution
{
$distribution = null;
if ($date != '') {
if (!$producer) {
$producer = GlobalParam::getCurrentProducer();
}
$distribution = $this->createIfNotExist($producer, $date, 1);
}

if ($distribution) {
$this->initPointSaleDistribution($distribution);
$this->initProductDistribution($distribution);
}

return $distribution;
}

public function initPointSaleDistribution(Distribution $distribution): void
{
$countPointSaleDistribution = $this->pointSaleDistributionRepository->countByDistribution($distribution);
if (!$countPointSaleDistribution) {
$this->pointSaleDistributionBuilder->initAll($distribution, true);
}
}

public function initProductDistribution(Distribution $distribution)
{
$products = Product::searchAll();

$productsDistribution = ProductDistribution::searchAll([
'id_distribution' => $distribution->id
]);
if (!count($productsDistribution)) {
foreach ($products as $product) {
$this->linkProduct($distribution, $product);
}
}
}

/**
* Lie un produit à la distribution.
*/
public function linkProduct(Distribution $distribution, Product $product): ProductDistribution
{
$productDistribution = ProductDistribution::searchOne([
'id_distribution' => $this->id,
'id_product' => $product->id
]);

if (!$productDistribution) {
$productDistribution = new ProductDistribution();
$productDistribution->id_distribution = $this->id;
$productDistribution->id_product = $product->id;
}

$dayDistribution = date('N', strtotime($this->date));
$daysArray = [
1 => 'monday',
2 => 'tuesday',
3 => 'wednesday',
4 => 'thursday',
5 => 'friday',
6 => 'saturday',
7 => 'sunday',
];

$productDistribution->active = 0;
$day = $daysArray[$dayDistribution];
if ($product->active && $product->$day) {
$productDistribution->active = 1;
}

$productDistribution->quantity_max = $product->quantity_max;
$fieldQuantityMax = 'quantity_max_' . $day;
if (isset($product->$fieldQuantityMax) && $product->$fieldQuantityMax > 0) {
$productDistribution->quantity_max = $product->$fieldQuantityMax;
}
$productDistribution->save();

// update prices product order
$ordersArray = OrderModel::searchAll([
'distribution.date' => $this->date,
'distribution.id_producer' => $this->id_producer
],
[
'conditions' => 'date_delete IS NULL AND origin != "user"'
]);
if ($ordersArray) {
foreach ($ordersArray as $order) {
foreach ($order->productOrder as $productOrder) {
if ($productOrder->id_product == $product->id) {
$productOrder->price = $product->price;

$user = false;
$userProducer = false;
if (isset($order->user) && $order->user) {
$user = $order->user;
$userProducer = UserProducerModel::searchOne([
'id_user' => $user->id,
'id_producer' => $order->distribution->id_producer
]);
}

$productOrder->price = $product->getPrice([
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $order->pointSale,
'quantity' => $productOrder->quantity
]);

$productOrder->save();
}
}
}
}

return $productDistribution;
}
}

+ 1
- 7
common/logic/Distribution/Distribution/DistributionContainer.php Datei anzeigen

@@ -8,24 +8,18 @@ class DistributionContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return DistributionModel::class;
return Distribution::class;
}

public function getServices(): array
{
return [
DistributionFactory::class,
DistributionSolver::class,
DistributionRepository::class,
DistributionBuilder::class
];
}

public function getFactory(): DistributionFactory
{
return new DistributionFactory();
}

public function getSolver(): DistributionSolver
{
return new DistributionSolver();

+ 0
- 16
common/logic/Distribution/Distribution/DistributionFactory.php Datei anzeigen

@@ -1,16 +0,0 @@
<?php

namespace common\logic\Distribution\Distribution;

use common\logic\BaseService;
use common\logic\FactoryInterface;

class DistributionFactory extends BaseService implements FactoryInterface
{
public function create(): DistributionModel
{
$distribution = new DistributionModel();

return $distribution;
}
}

+ 0
- 475
common/logic/Distribution/Distribution/DistributionModel.php Datei anzeigen

@@ -1,475 +0,0 @@
<?php

/**
* Copyright distrib (2018)
*
* contact@opendistrib.net
*
* Ce logiciel est un programme informatique servant à aider les producteurs
* à distribuer leur production en circuits courts.
*
* Ce logiciel est régi par la licence CeCILL soumise au droit français et
* respectant les principes de diffusion des logiciels libres. Vous pouvez
* utiliser, modifier et/ou redistribuer ce programme sous les conditions
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
* sur le site "http://www.cecill.info".
*
* En contrepartie de l'accessibilité au code source et des droits de copie,
* de modification et de redistribution accordés par cette licence, il n'est
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
* seule une responsabilité restreinte pèse sur l'auteur du programme, le
* titulaire des droits patrimoniaux et les concédants successifs.
*
* A cet égard l'attention de l'utilisateur est attirée sur les risques
* associés au chargement, à l'utilisation, à la modification et/ou au
* développement et à la reproduction du logiciel par l'utilisateur étant
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à
* manipuler et qui le réserve donc à des développeurs et des professionnels
* avertis possédant des connaissances informatiques approfondies. Les
* utilisateurs sont donc invités à charger et tester l'adéquation du
* logiciel à leurs besoins dans des conditions permettant d'assurer la
* sécurité de leurs systèmes et ou de leurs données et, plus généralement,
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
*
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
* pris connaissance de la licence CeCILL, et que vous en avez accepté les
* termes.
*/

namespace common\logic\Distribution\Distribution;

use common\logic\Producer\Producer\ProducerModel;
use common\helpers\GlobalParam;
use common\components\ActiveRecordCommon;

/**
* This is the model class for table "production".
*
* @property integer $id
* @property string $date
* @property integer $active
*/
class DistributionModel extends ActiveRecordCommon
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'distribution';
}

public function getProducer()
{
return $this->hasOne(ProducerModel::class, ['id' => 'id_producer']);
}

/**
* @inheritdoc
*/
public function rules()
{
return [
[['date'], 'required'],
[['date'], 'safe'],
[['active'], 'integer']
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'date' => 'Date',
'active' => 'Actif',
];
}

/*
* Relations
*/

public function getOrder()
{
return $this->hasMany(OrderModel::className(), ['id_distribution' => 'id']);
}

public function getProductDistribution()
{
return $this->hasMany(ProductDistributionModel::className(), ['id_distribution' => 'id']);
}

public function getPointSaleDistribution()
{
return $this->hasMany(PointSaleDistributionModel::className(), ['id_distribution' => 'id']) ;
}

/**
* Retourne les options de base nécessaires à la fonction de recherche.
*
* @return array
*/
public static function defaultOptionsSearch()
{
return [
'with' => [],
'join_with' => [],
'orderby' => 'date ASC',
'attribute_id_producer' => 'distribution.id_producer'
];
}


public function getDate(): string
{
return $this->date;
}


/**
* Retourne si un produit est actif ou non.
*
* @param integer $idProduit
* @return boolean
*/
public function isActiveProduct($idProduit)
{
if ($idProduit &&
isset($this->productDistribution) &&
count($this->productDistribution) > 0) {

foreach ($this->productDistribution as $productDistribution) {
if ($productDistribution['id_product'] == $idProduit &&
$productDistribution['active']) {
return true;
}
}
}

return false;
}

/**
* Initialise un jour de production.
*
* @param string $date
* @return Production
*/
public static function initDistribution($date, $idProducer = 0)
{
$distribution = null;
if ($date != '') {

$paramsDistribution = [
'date' => $date
];
if ($idProducer) {
$paramsDistribution['distribution.id_producer'] = (int)$idProducer;
} else {
$idProducer = GlobalParam::getCurrentProducerId();
}

$distribution = DistributionModel::searchOne($paramsDistribution);

if (!$distribution) {
$distribution = new Distribution;
$distribution->date = $date;
$distribution->delivery = 1;
$distribution->id_producer = $idProducer;
$distribution->save();
}
}

// point_sale_distribution à définir s'ils ne sont pas initialisés
if ($distribution) {

$countPointSaleDistribution = PointSaleDistributionModel::searchCount([
'id_distribution' => $distribution->id
]);

if (!$countPointSaleDistribution) {
PointSaleDistributionModel::setAll($distribution->id, true);
}
}

// init produits sélectionnés pour cette production
$products = ProductModel::searchAll();

if ($distribution) {
$productsDistribution = ProductDistributionModel::searchAll([
'id_distribution' => $distribution->id
]);
if (!count($productsDistribution)) {
foreach ($products as $product) {
$distribution->linkProduct($product);
}
}
$distribution->linkProductGift();
}

return $distribution;
}

/**
* Retourne les distributions futures.
*
* @return array
*/
public static function getIncomingDistributions()
{
$distributionsArray = DistributionModel::find()
->where('date > \'' . date('Y-m-d') . '\'')
->andWhere([
'id_producer' => GlobalParam::getCurrentProducerId(),
'active' => 1
])
->orderBy('date ASC')
->all();

return $distributionsArray;
}

public static function filterDistributionsByDateDelay($distributionsArray)
{
$producer = GlobalParam::getCurrentProducer() ;
$dateToday = date('Y-m-d') ;

foreach($distributionsArray as $keyDistribution => $distribution) {

$dateDistribution = $distribution->date ;
$dayDistribution = strtolower(date('l', strtotime($dateDistribution))) ;
$fieldDayDistributionDelay = 'order_delay_'.$dayDistribution ;
$fieldDayDistributionDeadline = 'order_deadline_'.$dayDistribution ;

$delay = $producer->order_delay ;
$deadline = $producer->order_deadline ;

if($producer->$fieldDayDistributionDelay) {
$delay = $producer->$fieldDayDistributionDelay ;
}

if($producer->$fieldDayDistributionDeadline) {
$deadline = $producer->$fieldDayDistributionDeadline ;
}

$countDaysTodayDistribution = number_format((strtotime($dateDistribution) - strtotime($dateToday)) / (24 * 60 * 60) , 0);

if(date('H') >= $deadline) {
$countDaysTodayDistribution -- ;
}

if($countDaysTodayDistribution < $delay) {
unset($distributionsArray[$keyDistribution]) ;
}
}

$newDistributionsArray = [] ;
foreach($distributionsArray as $distribution) {
$newDistributionsArray[] = $distribution ;
}

return $newDistributionsArray ;
}

/**
* Lie un produit aux jours de distribution futurs.
*
* @param Product $product
*/
public static function linkProductIncomingDistributions($product)
{
$distributionsArray = self::getIncomingDistributions();
foreach ($distributionsArray as $distribution) {
$distribution->linkProduct($product);
}
}

/**
* Lie un produit à la distribution.
*
* @param Product $product
*/
public function linkProduct($product)
{
$productDistribution = ProductDistributionModel::searchOne([
'id_distribution' => $this->id,
'id_product' => $product->id
]);

if (!$productDistribution) {
$productDistribution = new ProductDistribution();
$productDistribution->id_distribution = $this->id;
$productDistribution->id_product = $product->id;
}

$dayDistribution = date('N', strtotime($this->date));
$daysArray = [
1 => 'monday',
2 => 'tuesday',
3 => 'wednesday',
4 => 'thursday',
5 => 'friday',
6 => 'saturday',
7 => 'sunday',
];

$productDistribution->active = 0;
$day = $daysArray[$dayDistribution];
if ($product->active && $product->$day) {
$productDistribution->active = 1;
}

$productDistribution->quantity_max = $product->quantity_max;
$fieldQuantityMax = 'quantity_max_'.$day ;
if(isset($product->$fieldQuantityMax) && $product->$fieldQuantityMax > 0) {
$productDistribution->quantity_max = $product->$fieldQuantityMax ;
}
$productDistribution->save();

// update prices product order
$ordersArray = OrderModel::searchAll([
'distribution.date' => $this->date,
'distribution.id_producer' => $this->id_producer
],
[
'conditions' => 'date_delete IS NULL AND origin != "user"'
]);
if($ordersArray) {
foreach($ordersArray as $order) {
foreach($order->productOrder as $productOrder) {
if($productOrder->id_product == $product->id) {
$productOrder->price = $product->price ;

$user = false;
$userProducer = false;
if(isset($order->user) && $order->user) {
$user = $order->user;
$userProducer = UserProducerModel::searchOne([
'id_user' => $user->id,
'id_producer' => $order->distribution->id_producer
]) ;
}

$productOrder->price = $product->getPrice([
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $order->pointSale,
'quantity' => $productOrder->quantity
]);

$productOrder->save() ;
}
}
}
}

return $productDistribution;
}

/**
* Lie le produit "Don" à la distribution
*/
public function linkProductGift()
{
$productGift = ProductModel::getProductGift();

if ($productGift) {
$productDistribution = ProductDistributionModel::searchOne([
'id_distribution' => $this->id,
'id_product' => $productGift->id
]);

if (!$productDistribution) {
$productDistribution = new ProductDistribution();
$productDistribution->id_distribution = $this->id;
$productDistribution->id_product = $productGift->id;
$productDistribution->active = 1;
$productDistribution->save();
}
}
}

/**
* Lie un point de vente aux jours de distribution futurs.
*
* @param PointSale $pointSale
*/
public static function linkPointSaleIncomingDistributions($pointSale)
{
$distributionsArray = self::getIncomingDistributions();
foreach ($distributionsArray as $distribution) {
$distribution->linkPointSale($pointSale);
}
}

/**
*
* @param type $pointSale
*/
public function linkPointSale($pointSale)
{
$pointSaleDistribution = PointSaleDistributionModel::searchOne([
'id_distribution' => $this->id,
'id_point_sale' => $pointSale->id
]);

if (!$pointSaleDistribution) {
$pointSaleDistribution = new PointSaleDistribution();
$pointSaleDistribution->id_distribution = $this->id;
$pointSaleDistribution->id_point_sale = $pointSale->id;
}

$dayDistribution = date('N', strtotime($this->date));
$daysArray = [
1 => 'monday',
2 => 'tuesday',
3 => 'wednesday',
4 => 'thursday',
5 => 'friday',
6 => 'saturday',
7 => 'sunday',
];

$pointSaleDistribution->delivery = 0;
$deliveryDay = 'delivery_' . $daysArray[$dayDistribution];
if ($pointSale->$deliveryDay) {
$pointSaleDistribution->delivery = 1;
}

$pointSaleDistribution->save();
}

public function isPointSaleActive($distribution, $pointSaleId)
{
$pointSaleActive = false ;

if($distribution->pointSaleDistribution) {
foreach($distribution->pointSaleDistribution as $pointSaleDistribution) {
if($pointSaleDistribution->id_point_sale == $pointSaleId && $pointSaleDistribution->delivery) {
$pointSaleActive = true ;
}
}
}

return $pointSaleActive ;
}

/**
* Active ou désactive la distribution.
*/
public function active($active = true)
{
PointSaleDistributionModel::setAll($this->id, true);
$this->active = (int)$active;
$this->save();

if ($active) {
// ajout des abonnements
SubscriptionModel::addAll($this->date);
}
}

}

+ 40
- 0
common/logic/Distribution/Distribution/DistributionRepository.php Datei anzeigen

@@ -2,10 +2,50 @@

namespace common\logic\Distribution\Distribution;

use common\helpers\GlobalParam;
use common\logic\BaseService;
use common\logic\Producer\Producer\Producer;
use common\logic\RepositoryInterface;

class DistributionRepository extends BaseService implements RepositoryInterface
{
/**
* Retourne les options de base nécessaires à la fonction de recherche.
*/
public function defaultOptionsSearch(): array
{
return [
'with' => [],
'join_with' => [],
'orderby' => 'date ASC',
'attribute_id_producer' => 'distribution.id_producer'
];
}

public function getOne(Producer $producer, string $date)
{
$paramsDistribution = [
'date' => $date,
'distribution.id_producer' => $producer->id
];

return Distribution::searchOne($paramsDistribution);
}

/**
* Récupère les distributions futures.
*/
public function getIncomingDistributions(): array
{
$distributionsArray = Distribution::find()
->where('date > \'' . date('Y-m-d') . '\'')
->andWhere([
'id_producer' => GlobalParam::getCurrentProducerId(),
'active' => 1
])
->orderBy('date ASC')
->all();

return $distributionsArray;
}
}

+ 65
- 0
common/logic/Distribution/Distribution/DistributionSolver.php Datei anzeigen

@@ -2,10 +2,75 @@

namespace common\logic\Distribution\Distribution;

use common\helpers\GlobalParam;
use common\logic\BaseService;
use common\logic\Product\Product\Product;
use common\logic\SolverInterface;

class DistributionSolver extends BaseService implements SolverInterface
{
/**
* Déduit si un produit est actif ou non
*/
public function isActiveProduct(Distribution $distribution, Product $product): bool
{
if ($product->id
&& isset($distribution->productDistribution)
&& count($distribution->productDistribution) > 0) {

foreach ($distribution->productDistribution as $productDistribution) {
if ($productDistribution['id_product'] == $product->id
&& $productDistribution['active']) {
return true;
}
}
}

return false;
}

/*
* Filtre les distributions par délai de commande.
*/
public function filterDistributionsByDateDelay(array $distributionsArray): array
{
$producer = GlobalParam::getCurrentProducer();
$dateToday = date('Y-m-d');

foreach ($distributionsArray as $keyDistribution => $distribution) {

$dateDistribution = $distribution->date;
$dayDistribution = strtolower(date('l', strtotime($dateDistribution)));
$fieldDayDistributionDelay = 'order_delay_' . $dayDistribution;
$fieldDayDistributionDeadline = 'order_deadline_' . $dayDistribution;

$delay = $producer->order_delay;
$deadline = $producer->order_deadline;

if ($producer->$fieldDayDistributionDelay) {
$delay = $producer->$fieldDayDistributionDelay;
}

if ($producer->$fieldDayDistributionDeadline) {
$deadline = $producer->$fieldDayDistributionDeadline;
}

$countDaysTodayDistribution = number_format((strtotime($dateDistribution) - strtotime($dateToday)) / (24 * 60 * 60), 0);

if (date('H') >= $deadline) {
$countDaysTodayDistribution--;
}

if ($countDaysTodayDistribution < $delay) {
unset($distributionsArray[$keyDistribution]);
}
}

$newDistributionsArray = [];
foreach ($distributionsArray as $distribution) {
$newDistributionsArray[] = $distribution;
}

return $newDistributionsArray;
}
}

common/logic/Distribution/PointSaleDistribution/PointSaleDistributionModel.php → common/logic/Distribution/PointSaleDistribution/PointSaleDistribution.php Datei anzeigen

@@ -43,15 +43,11 @@ use Yii;
use common\components\ActiveRecordCommon ;

/**
* This is the model class for table "production_point_vente".
* This is the model class for table "point_sale_distribution".
*
* @property integer $id_distribution
* @property integer $id_point_sale
* @property integer $delivery
*/
class PointSaleDistributionModel extends ActiveRecordCommon
class PointSaleDistribution extends ActiveRecordCommon
{

var $points_sale_distribution;

/**
@@ -113,61 +109,4 @@ class PointSaleDistributionModel extends ActiveRecordCommon
] ;
}

/**
* Définit les jours de livraisons des points de vente pour un jour de
* production donné.
*
* @param integer $id_production
* @param boolean $bool_livraison
*/
public static function setAll($idDistribution, $boolDelivery)
{
// liaison PointSale / Distribution
$arrPointsSale = PointSaleModel::find()
->with(['pointSaleDistribution' => function($q) use ($idDistribution) {
$q->where(['id_distribution' => $idDistribution]);
}])
->where([
'id_producer' => GlobalParam::getCurrentProducerId(),
])
->all();
foreach ($arrPointsSale as $pointSale) {
if(!$pointSale->pointSaleDistribution) {
$pointSaleDistribution = new PointSaleDistribution();
$pointSaleDistribution->id_distribution = $idDistribution;
$pointSaleDistribution->id_point_sale = $pointSale->id;
$pointSaleDistribution->save();
}
}

$distribution = DistributionModel::findOne($idDistribution);

if ($distribution) {
$day = date('N', strtotime($distribution->date));

$arrPointsSaleDistribution = self::searchAll([
'id_distribution' => $idDistribution
]) ;
foreach ($arrPointsSaleDistribution as $pointSaleDistribution) {
if ($boolDelivery &&
(($day == 1 && $pointSaleDistribution->pointSale->delivery_monday) ||
($day == 2 && $pointSaleDistribution->pointSale->delivery_tuesday) ||
($day == 3 && $pointSaleDistribution->pointSale->delivery_wednesday) ||
($day == 4 && $pointSaleDistribution->pointSale->delivery_thursday) ||
($day == 5 && $pointSaleDistribution->pointSale->delivery_friday) ||
($day == 6 && $pointSaleDistribution->pointSale->delivery_saturday) ||
($day == 7 && $pointSaleDistribution->pointSale->delivery_sunday)
)) {
$pointSaleDistribution->delivery = 1;
} else {
$pointSaleDistribution->delivery = 0;
}

$pointSaleDistribution->save();
}
}
}

}

+ 90
- 0
common/logic/Distribution/PointSaleDistribution/PointSaleDistributionBuilder.php Datei anzeigen

@@ -0,0 +1,90 @@
<?php

namespace common\logic\Distribution\PointSaleDistribution;

use common\helpers\GlobalParam;
use common\logic\BaseService;
use common\logic\BuilderInterface;
use common\logic\Distribution\Distribution\Distribution;
use common\logic\PointSale\PointSale\PointSale;

class PointSaleDistributionBuilder extends BaseService implements BuilderInterface
{
/*
* Instancie un PointSaleDistribution.
*/
public function instanciate(Distribution $distribution, PointSale $pointSale): PointSaleDistribution
{
$pointSaleDistribution = new PointSaleDistribution();

$pointSaleDistribution->id_distribution = $distribution->id;
$pointSaleDistribution->id_point_sale = $pointSale->id;

return $pointSaleDistribution;
}

/*
* Crée un PointSaleDistribution.
*/
public function create(Distribution $distribution, PointSale $pointSale): PointSaleDistribution
{
$pointSaleDistribution = $this->instanciate($distribution, $pointSale);
$pointSaleDistribution->save();

return $pointSaleDistribution;
}

/**
* Initialise les PointSaleDistribution pour une distribution donnée.
*/
// setAll
public function initAll(Distribution $distribution, bool $delivery): void
{
$arrPointsSale = PointSale::find()
->with(['pointSaleDistribution' => function($q) use ($distribution) {
$q->where(['id_distribution' => $distribution->id]);
}])
->where([
'id_producer' => GlobalParam::getCurrentProducerId(),
])
->all();

foreach ($arrPointsSale as $pointSale) {
if(!$pointSale->pointSaleDistribution) {
$this->create($distribution, $pointSale);
}
}

$distribution = Distribution::findOne($distribution->id);
if ($distribution) {

$arrPointsSaleDistribution = PointSaleDistribution::searchAll([
'id_distribution' => $distribution->id
]) ;
foreach ($arrPointsSaleDistribution as $pointSaleDistribution) {
$this->initDelivery($pointSaleDistribution, $delivery);
}
}
}

public function initDelivery(PointSaleDistribution $pointSaleDistribution, bool $delivery)
{
$day = date('N', strtotime($pointSaleDistribution->distribution->date));

if ($delivery &&
(($day == 1 && $pointSaleDistribution->pointSale->delivery_monday) ||
($day == 2 && $pointSaleDistribution->pointSale->delivery_tuesday) ||
($day == 3 && $pointSaleDistribution->pointSale->delivery_wednesday) ||
($day == 4 && $pointSaleDistribution->pointSale->delivery_thursday) ||
($day == 5 && $pointSaleDistribution->pointSale->delivery_friday) ||
($day == 6 && $pointSaleDistribution->pointSale->delivery_saturday) ||
($day == 7 && $pointSaleDistribution->pointSale->delivery_sunday)
)) {
$pointSaleDistribution->delivery = 1;
} else {
$pointSaleDistribution->delivery = 0;
}

$pointSaleDistribution->save();
}
}

+ 31
- 0
common/logic/Distribution/PointSaleDistribution/PointSaleDistributionContainer.php Datei anzeigen

@@ -0,0 +1,31 @@
<?php

namespace common\logic\Distribution\PointSaleDistribution;

use common\logic\ContainerInterface;

class PointSaleDistributionContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return PointSaleDistribution::class;
}

public function getServices(): array
{
return [
PointSaleDistributionRepository::class,
PointSaleDistributionBuilder::class,
];
}

public function getRepository(): PointSaleDistributionRepository
{
return new PointSaleDistributionRepository();
}

public function getBuilder(): PointSaleDistributionBuilder
{
return new PointSaleDistributionBuilder();
}
}

+ 0
- 16
common/logic/Distribution/PointSaleDistribution/PointSaleDistributionFactory.php Datei anzeigen

@@ -1,16 +0,0 @@
<?php

namespace common\logic\Distribution\PointSaleDistribution;

use common\logic\BaseService;
use common\logic\FactoryInterface;

class PointSaleDistributionFactory extends BaseService implements FactoryInterface
{
public function create(): PointSaleDistributionModel
{
$pointSaleDistribution = new PointSaleDistributionModel();

return $pointSaleDistribution;
}
}

+ 18
- 0
common/logic/Distribution/PointSaleDistribution/PointSaleDistributionRepository.php Datei anzeigen

@@ -0,0 +1,18 @@
<?php

namespace common\logic\Distribution\PointSaleDistribution;

use common\logic\BaseService;
use common\logic\Distribution\Distribution\Distribution;
use common\logic\RepositoryInterface;

class PointSaleDistributionRepository extends BaseService implements RepositoryInterface
{
public function countByDistribution(Distribution $distribution): int
{
return PointSaleDistribution::searchCount([
'id_distribution' => $distribution->id
]);
}

}

common/logic/Distribution/ProductDistribution/ProductDistributionModel.php → common/logic/Distribution/ProductDistribution/ProductDistribution.php Datei anzeigen

@@ -48,7 +48,7 @@ use common\components\ActiveRecordCommon ;
* @property integer $id_product
* @property integer $active
*/
class ProductDistributionModel extends ActiveRecordCommon
class ProductDistribution extends ActiveRecordCommon
{

/**
@@ -120,7 +120,7 @@ class ProductDistributionModel extends ActiveRecordCommon
*/
public static function searchByDistribution($idDistribution)
{
$arrayProductsDistribution = ProductDistributionModel::searchAll([
$arrayProductsDistribution = ProductDistribution::searchAll([
'id_distribution' => $idDistribution
]) ;

common/logic/Distribution/ProductDistribution/ProductDistributionFactory.php → common/logic/Distribution/ProductDistribution/ProductDistributionBuilder.php Datei anzeigen

@@ -5,11 +5,11 @@ namespace common\logic\Distribution\ProductDistribution;
use common\logic\BaseService;
use common\logic\FactoryInterface;

class ProductDistributionFactory extends BaseService implements FactoryInterface
class ProductDistributionBuilder extends BaseService implements FactoryInterface
{
public function create(): ProductDistributionModel
public function create(): ProductDistribution
{
$productDistribution = new ProductDistributionModel();
$productDistribution = new ProductDistribution();

return $productDistribution;
}

+ 31
- 0
common/logic/Distribution/ProductDistribution/ProductDistributionContainer.php Datei anzeigen

@@ -0,0 +1,31 @@
<?php

namespace common\logic\Distribution\ProductDistribution;

use common\logic\ContainerInterface;

class ProductDistributionContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return ProductDistribution::class;
}

public function getServices(): array
{
return [
ProductDistributionRepository::class,
ProductDistributionBuilder::class,
];
}

public function getRepository(): ProductDistributionRepository
{
return new ProductDistributionRepository();
}

public function getBuilder(): ProductDistributionBuilder
{
return new ProductDistributionBuilder();
}
}

+ 11
- 0
common/logic/Distribution/ProductDistribution/ProductDistributionRepository.php Datei anzeigen

@@ -0,0 +1,11 @@
<?php

namespace common\logic\Distribution\ProductDistribution;

use common\logic\BaseService;
use common\logic\RepositoryInterface;

class ProductDistributionRepository extends BaseService implements RepositoryInterface
{

}

+ 8
- 8
common/logic/Document/Document/DocumentModel.php Datei anzeigen

@@ -40,7 +40,7 @@ namespace common\logic\Document\Document;

use common\components\ActiveRecordCommon;
use common\helpers\GlobalParam;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use kartik\mpdf\Pdf;
use yii\base\ErrorException;

@@ -105,7 +105,7 @@ class DocumentModel extends ActiveRecordCommon

public function getProducer()
{
return $this->hasOne(ProducerModel::class, ['id' => 'id_producer']);
return $this->hasOne(Producer::class, ['id' => 'id_producer']);
}

public function relationOrders($fieldIdDocument)
@@ -261,7 +261,7 @@ class DocumentModel extends ActiveRecordCommon
$classLower = 'delivery_note';
}

$prefix = ProducerModel::getConfig('document_' . $classLower . '_prefix');
$prefix = Producer::getConfig('document_' . $classLower . '_prefix');
$oneDocumentExist = $class::searchOne(['status' => DocumentModel::STATUS_VALID], ['orderby' => 'reference DESC']);

if ($oneDocumentExist) {
@@ -274,7 +274,7 @@ class DocumentModel extends ActiveRecordCommon

return $prefix . $numReference;
} else {
$firstReference = ProducerModel::getConfig('document_' . $classLower . '_first_reference');
$firstReference = Producer::getConfig('document_' . $classLower . '_first_reference');

if (strlen($firstReference) > 0) {
return $firstReference;
@@ -325,7 +325,7 @@ class DocumentModel extends ActiveRecordCommon
$contentFooter .= '</div>';

$marginBottom = 10;
if (strlen(ProducerModel::getConfig('document_infos_bottom')) > 0) {
if (strlen(Producer::getConfig('document_infos_bottom')) > 0) {
$marginBottom = 40;
}

@@ -460,8 +460,8 @@ class DocumentModel extends ActiveRecordCommon
public function isDisplayOrders()
{
$displayOrders = ($this->getClass() == 'Invoice') ?
ProducerModel::getConfig('document_display_orders_invoice') :
ProducerModel::getConfig('document_display_orders_delivery_note');
Producer::getConfig('document_display_orders_invoice') :
Producer::getConfig('document_display_orders_delivery_note');

return $displayOrders;
}
@@ -518,7 +518,7 @@ class DocumentModel extends ActiveRecordCommon

public function initTaxCalculationMethod()
{
$producerTaxCalculationMethod = ProducerModel::getConfig('option_tax_calculation_method');
$producerTaxCalculationMethod = Producer::getConfig('option_tax_calculation_method');

if ($producerTaxCalculationMethod) {
$this->tax_calculation_method = $producerTaxCalculationMethod;

+ 12
- 12
common/logic/Order/Order/OrderModel.php Datei anzeigen

@@ -40,7 +40,7 @@ namespace common\logic\Order\Order;

use common\helpers\GlobalParam;
use common\helpers\Price;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\User\CreditHistory\CreditHistoryModel;
use common\logic\User\User\UserModel;
use Yii;
@@ -362,15 +362,15 @@ class OrderModel extends ActiveRecordCommon
}

// delete
if (ProducerModel::getConfig('option_behavior_cancel_order') == ProducerModel::BEHAVIOR_DELETE_ORDER_DELETE ||
(ProducerModel::getConfig(
if (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_DELETE ||
(Producer::getConfig(
'option_behavior_cancel_order'
) == ProducerModel::BEHAVIOR_DELETE_ORDER_STATUS && strlen($this->date_delete)) ||
) == Producer::BEHAVIOR_DELETE_ORDER_STATUS && strlen($this->date_delete)) ||
$force) {
ProductOrderModel::deleteAll(['id_order' => $this->id]);
return parent::delete();
} // status 'delete'
elseif (ProducerModel::getConfig('option_behavior_cancel_order') == ProducerModel::BEHAVIOR_DELETE_ORDER_STATUS) {
elseif (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS) {
$this->date_delete = date('Y-m-d H:i:s');
return $this->save();
}
@@ -706,7 +706,7 @@ class OrderModel extends ActiveRecordCommon
{
$html = '';

$creditActive = ProducerModel::getConfig('credit');
$creditActive = Producer::getConfig('credit');
$html .= $this->getAmountWithTax(self::AMOUNT_TOTAL, true);

if ($creditActive) {
@@ -768,11 +768,11 @@ class OrderModel extends ActiveRecordCommon
$todayHour = date('G');
$dayDistribution = strtolower(date('l', strtotime($this->distribution->date)));

$orderDelay = ProducerModel::getConfig(
$orderDelay = Producer::getConfig(
'order_delay',
$this->distribution->id_producer
);
$orderDelaySpecific = ProducerModel::getConfig(
$orderDelaySpecific = Producer::getConfig(
'order_delay_' . $dayDistribution,
$this->distribution->id_producer
);
@@ -780,11 +780,11 @@ class OrderModel extends ActiveRecordCommon
$orderDelay = $orderDelaySpecific;
}

$orderDeadline = ProducerModel::getConfig(
$orderDeadline = Producer::getConfig(
'order_deadline',
$this->distribution->id_producer
);
$orderDeadlineSpecific = ProducerModel::getConfig(
$orderDeadlineSpecific = Producer::getConfig(
'order_deadline_' . $dayDistribution,
$this->distribution->id_producer
);
@@ -1046,9 +1046,9 @@ class OrderModel extends ActiveRecordCommon
public function initReference()
{
$idProducer = GlobalParam::getCurrentProducerId();
$producer = ProducerModel::findOne($idProducer);
$producer = Producer::findOne($idProducer);

if (!$this->reference && $producer->option_order_reference_type == ProducerModel::ORDER_REFERENCE_TYPE_YEARLY) {
if (!$this->reference && $producer->option_order_reference_type == Producer::ORDER_REFERENCE_TYPE_YEARLY) {
$lastOrder = OrderModel::find()->innerJoinWith('distribution', true)
->where(['>=', 'distribution.date', date('Y') . '-01-01'])
->andWhere([

+ 1
- 1
common/logic/Order/ProductOrder/ProductOrderModel.php Datei anzeigen

@@ -73,7 +73,7 @@ class ProductOrderModel extends ActiveRecordCommon

public function getTaxRate()
{
return $this->hasOne(TaxRateModel::className(), ['id' => 'id_tax_rate']);
return $this->hasOne(TaxRate::className(), ['id' => 'id_tax_rate']);
}

/**

common/logic/PointSale/PointSale/PointSaleModel.php → common/logic/PointSale/PointSale/PointSale.php Datei anzeigen

@@ -39,7 +39,7 @@
namespace common\logic\PointSale\PointSale;

use common\helpers\GlobalParam;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use yii\helpers\Html;
use common\components\ActiveRecordCommon;

@@ -52,7 +52,7 @@ use common\components\ActiveRecordCommon;
* @property integer $id_producer
* @property integer $default
*/
class PointSaleModel extends ActiveRecordCommon
class PointSale extends ActiveRecordCommon
{
var $orders = [];
var $revenues = 0;
@@ -229,7 +229,7 @@ class PointSaleModel extends ActiveRecordCommon
public function processPointProduction()
{
if ($this->point_production) {
PointSaleModel::updateAll(
PointSale::updateAll(
['point_production' => 0],
['id_producer' => $this->id_producer]
);
@@ -360,7 +360,7 @@ class PointSaleModel extends ActiveRecordCommon
{
return strlen($this->credit_functioning) > 0 ?
$this->credit_functioning :
ProducerModel::getConfig('credit_functioning');
Producer::getConfig('credit_functioning');
}

/**
@@ -389,7 +389,7 @@ class PointSaleModel extends ActiveRecordCommon
public static function populateDropdownList()
{
$pointSalesArrayDropdown = ['' => '--'] ;
$pointSalesArray = PointSaleModel::find()->where('id_producer = ' . GlobalParam::getCurrentProducerId())->all() ;
$pointSalesArray = PointSale::find()->where('id_producer = ' . GlobalParam::getCurrentProducerId())->all() ;

foreach($pointSalesArray as $pointSale) {
$pointSalesArrayDropdown[$pointSale['id']] = $pointSale['name'] ;

+ 1
- 1
common/logic/PointSale/PointSale/PointSaleContainer.php Datei anzeigen

@@ -8,7 +8,7 @@ class PointSaleContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return PointSaleModel::class;
return PointSale::class;
}

public function getServices(): array

+ 2
- 2
common/logic/PointSale/PointSale/PointSaleFactory.php Datei anzeigen

@@ -7,9 +7,9 @@ use common\logic\FactoryInterface;

class PointSaleFactory extends BaseService implements FactoryInterface
{
public function create(): PointSaleModel
public function create(): PointSale
{
$pointSale = new PointSaleModel();
$pointSale = new PointSale();

return $pointSale;
}

+ 2
- 2
common/logic/PointSale/PointSale/PointSaleSearch.php Datei anzeigen

@@ -40,7 +40,7 @@ namespace common\logic\PointSale\PointSale ;

use common\helpers\GlobalParam;

class PointSaleSearch extends PointSaleModel
class PointSaleSearch extends PointSale
{
var $delivery ;
var $access_type ;
@@ -65,7 +65,7 @@ class PointSaleSearch extends PointSaleModel
{
$optionsSearch = self::defaultOptionsSearch() ;
$query = PointSaleModel::find()
$query = PointSale::find()
->with($optionsSearch['with'])
->innerJoinWith($optionsSearch['join_with'], true)
->where([

common/logic/Producer/Producer/ProducerModel.php → common/logic/Producer/Producer/Producer.php Datei anzeigen

@@ -39,7 +39,7 @@
namespace common\logic\Producer\Producer;

use common\logic\User\User\UserModel;
use common\logic\Config\TaxRate\TaxRateModel;
use common\logic\Config\TaxRate\TaxRate;
use common\logic\User\UserProducer\UserProducerModel;
use common\components\ActiveRecordCommon;

@@ -47,7 +47,7 @@ use common\components\ActiveRecordCommon;
* This is the model class for table "producer".
*
*/
class ProducerModel extends ActiveRecordCommon
class Producer extends ActiveRecordCommon
{
const CREDIT_FUNCTIONING_MANDATORY = 'mandatory';
const CREDIT_FUNCTIONING_OPTIONAL = 'optional';
@@ -175,7 +175,7 @@ class ProducerModel extends ActiveRecordCommon
'code',
function ($attribute, $params) {
$code = $this->$attribute;
$producer = ProducerModel::findOne(['code' => $code]);
$producer = Producer::findOne(['code' => $code]);
if ($producer && $producer->id != $this->id) {
$this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.');
}
@@ -423,7 +423,7 @@ class ProducerModel extends ActiveRecordCommon

public function getTaxRate()
{
return $this->hasOne(TaxRateModel::class, ['id' => 'id_tax_rate_default']);
return $this->hasOne(TaxRate::class, ['id' => 'id_tax_rate_default']);
}

// ---

+ 6
- 6
common/logic/Producer/Producer/ProducerBuilder.php Datei anzeigen

@@ -26,13 +26,13 @@ class ProducerBuilder extends BaseService implements BuilderInterface
$this->producerSolver = $this->loadService(ProducerSolver::class);
}

public function init(ProducerModel $producer): void
public function init(Producer $producer): void
{
$this->initSlug($producer);
$this->initCode($producer);
}

public function initSlug(ProducerModel $producer): void
public function initSlug(Producer $producer): void
{
$cptSlug = 0 ;
do {
@@ -45,7 +45,7 @@ class ProducerBuilder extends BaseService implements BuilderInterface
} while($this->producerRepository->getOneBySlug($producer->slug)) ;
}

public function initCode(ProducerModel $producer): void
public function initCode(Producer $producer): void
{
$producer->code = Password::generate();
}
@@ -68,7 +68,7 @@ class ProducerBuilder extends BaseService implements BuilderInterface
return $userProducer;
}

public function updateOpendistribVersion(ProducerModel $producer)
public function updateOpendistribVersion(Producer $producer)
{
$versionsArray = Opendistrib::getVersions();
$producer->latest_version_opendistrib = array_values($versionsArray)[0];
@@ -84,7 +84,7 @@ class ProducerBuilder extends BaseService implements BuilderInterface
}
}

public function savePrivateKeyApiStripe(ProducerModel $producer): void
public function savePrivateKeyApiStripe(Producer $producer): void
{
$this->savePrivateKeyStripe(
$this->producerSolver->getFilenamePrivateKeyApiStripe($producer),
@@ -92,7 +92,7 @@ class ProducerBuilder extends BaseService implements BuilderInterface
);
}

public function savePrivateKeyEndpointStripe(ProducerModel $producer): bool
public function savePrivateKeyEndpointStripe(Producer $producer): bool
{
$this->savePrivateKeyStripe(
$this->producerSolver->getFilenamePrivateKeyEndpointStripe($producer),

+ 1
- 1
common/logic/Producer/Producer/ProducerContainer.php Datei anzeigen

@@ -8,7 +8,7 @@ class ProducerContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return ProducerModel::class;
return Producer::class;
}

public function getServices(): array

+ 3
- 3
common/logic/Producer/Producer/ProducerFactory.php Datei anzeigen

@@ -9,10 +9,10 @@ class ProducerFactory extends BaseService implements FactoryInterface
{
public function create()
{
$producer = new ProducerModel();
$producer = new Producer();

$producer->order_deadline = ProducerModel::ORDER_DEADLINE_DEFAULT;
$producer->order_delay = ProducerModel::ORDER_DELAY_DEFAULT;
$producer->order_deadline = Producer::ORDER_DEADLINE_DEFAULT;
$producer->order_delay = Producer::ORDER_DELAY_DEFAULT;

return $producer;
}

+ 11
- 11
common/logic/Producer/Producer/ProducerRepository.php Datei anzeigen

@@ -39,17 +39,17 @@ class ProducerRepository extends BaseService implements RepositoryInterface

public function getOneById($id)
{
return ProducerModel::searchOne(['id' => $id]);
return Producer::searchOne(['id' => $id]);
}

public function getOneBySlug($slug)
{
return ProducerModel::searchOne(['slug' => $slug]);
return Producer::searchOne(['slug' => $slug]);
}

public function queryActive()
{
return ProducerModel::find()
return Producer::find()
->where([
'active' => true,
])
@@ -62,7 +62,7 @@ class ProducerRepository extends BaseService implements RepositoryInterface
*/
public function getOneDemoAccount()
{
return ProducerModel::find()->where('name LIKE \'Démo\'')->one();
return Producer::find()->where('name LIKE \'Démo\'')->one();
}

/**
@@ -73,7 +73,7 @@ class ProducerRepository extends BaseService implements RepositoryInterface
*/
public static function getPopulateDropdown()
{
$producers = ProducerModel::find()
$producers = Producer::find()
->where([
'active' => true,
])
@@ -111,7 +111,7 @@ class ProducerRepository extends BaseService implements RepositoryInterface
/**
* Retourne le CA du producteur pour un mois donné
*/
public function getTurnover(ProducerModel $producer, string $period = '', bool $format = false)
public function getTurnover(Producer $producer, string $period = '', bool $format = false)
{
if (!$period) {
$period = date('Y-m');
@@ -145,13 +145,13 @@ class ProducerRepository extends BaseService implements RepositoryInterface
}
}

public function getAmountToBeBilledByMonth(ProducerModel $producer, $month, $format = false)
public function getAmountToBeBilledByMonth(Producer $producer, $month, $format = false)
{
$turnover = $this->getTurnover($producer, $month);
return $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, $format);
}

public function getSummaryAmountsToBeBilled(ProducerModel $producer, $label, $numberOfMonths = 1)
public function getSummaryAmountsToBeBilled(Producer $producer, $label, $numberOfMonths = 1)
{
$text = '';
$numMonthCurrent = date('m');
@@ -183,7 +183,7 @@ class ProducerRepository extends BaseService implements RepositoryInterface
return $text;
}

public function getAmountBilledLastMonth(ProducerModel $producer)
public function getAmountBilledLastMonth(Producer $producer)
{
if ($this->producerSolver->isBillingTypeClassic($producer)) {
$month = date('Y-m', strtotime('-1 month'));
@@ -195,11 +195,11 @@ class ProducerRepository extends BaseService implements RepositoryInterface
return 0;
}

public function getOnlinePaymentMinimumAmount(ProducerModel $producer)
public function getOnlinePaymentMinimumAmount(Producer $producer)
{
$onlinePaymentMinimumAmount = $this->getConfig('option_online_payment_minimum_amount');
if (!$onlinePaymentMinimumAmount) {
$onlinePaymentMinimumAmount = ProducerModel::ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT;
$onlinePaymentMinimumAmount = Producer::ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT;
}

return $onlinePaymentMinimumAmount;

+ 31
- 27
common/logic/Producer/Producer/ProducerSolver.php Datei anzeigen

@@ -9,11 +9,15 @@ use common\logic\User\User\UserModel;

class ProducerSolver extends BaseService implements SolverInterface
{
public function getCurrent()
{

}

/**
* Retourne true si le compte est un compte de démo.
*
*/
public function isDemo(ProducerModel $producer): bool
public function isDemo(Producer $producer): bool
{
if (strpos($producer->name, 'Démo') !== false) {
return true;
@@ -22,7 +26,7 @@ class ProducerSolver extends BaseService implements SolverInterface
return false;
}

public function getFullAddress(ProducerModel $producer, $nl2br = false)
public function getFullAddress(Producer $producer, $nl2br = false)
{
$address = '';
$address .= $producer->name . "\n";
@@ -42,7 +46,7 @@ class ProducerSolver extends BaseService implements SolverInterface
return $address;
}

public function getHtmlLogo(ProducerModel $producer)
public function getHtmlLogo(Producer $producer)
{
$html = '';

@@ -53,17 +57,17 @@ class ProducerSolver extends BaseService implements SolverInterface
return $html;
}

public function getUrlLogo(ProducerModel $producer): string
public function getUrlLogo(Producer $producer): string
{
return \Yii::$app->urlManagerProducer->getHostInfo() . '/' . \Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $producer->logo;
}

public function getEmailOpendistrib(ProducerModel $producer): string
public function getEmailOpendistrib(Producer $producer): string
{
return $producer->slug . '@opendistrib.net';
}

public function getMainContact(ProducerModel $producer): ?UserModel
public function getMainContact(Producer $producer): ?UserModel
{
if ($producer->contact) {
foreach ($producer->contact as $contact) {
@@ -76,19 +80,19 @@ class ProducerSolver extends BaseService implements SolverInterface
return null;
}

public function isUpToDateWithOpendistribVersion(ProducerModel $producer): bool
public function isUpToDateWithOpendistribVersion(Producer $producer): bool
{
return $producer->latest_version_opendistrib == GlobalParam::getOpendistribVersion();
}

public function isBillingTypeClassic(ProducerModel $producer): bool
public function isBillingTypeClassic(Producer $producer): bool
{
return $producer->option_billing_type == ProducerModel::BILLING_TYPE_CLASSIC;
return $producer->option_billing_type == Producer::BILLING_TYPE_CLASSIC;
}

public function isBillingTypeFreePrice(ProducerModel $producer)
public function isBillingTypeFreePrice(Producer $producer)
{
return $producer->option_billing_type == ProducerModel::BILLING_TYPE_FREE_PRICE;
return $producer->option_billing_type == Producer::BILLING_TYPE_FREE_PRICE;
}

/**
@@ -96,7 +100,7 @@ class ProducerSolver extends BaseService implements SolverInterface
* le producteur.
*
*/
public function getFreePrice(ProducerModel $producer, $format = true)
public function getFreePrice(Producer $producer, $format = true)
{
if (!is_null($producer->free_price)) {
if ($format) {
@@ -107,7 +111,7 @@ class ProducerSolver extends BaseService implements SolverInterface
}
}

public function getSpecificDelays(ProducerModel $producer): array
public function getSpecificDelays(Producer $producer): array
{
$array = [];
$daysArray = [
@@ -142,7 +146,7 @@ class ProducerSolver extends BaseService implements SolverInterface
return $array;
}

public function hasSpecificDelays(ProducerModel $producer): bool
public function hasSpecificDelays(Producer $producer): bool
{
$daysArray = [
'monday',
@@ -166,12 +170,12 @@ class ProducerSolver extends BaseService implements SolverInterface
return false;
}

public function getFilenamePrivateKeyApiStripe(ProducerModel $producer)
public function getFilenamePrivateKeyApiStripe(Producer $producer)
{
return '../../common/config/stripe/api-' . $producer->id . '.key';
}

public function getFilenamePrivateKeyEndpointStripe(ProducerModel $producer)
public function getFilenamePrivateKeyEndpointStripe(Producer $producer)
{
return '../../common/config/stripe/endpoint-' . $producer->id . '.key';
}
@@ -196,17 +200,17 @@ class ProducerSolver extends BaseService implements SolverInterface
return '';
}

public function getPrivateKeyApiStripe(ProducerModel $producer)
public function getPrivateKeyApiStripe(Producer $producer)
{
return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyApiStripe($producer));
}

public function getPrivateKeyEndpointStripe(ProducerModel $producer)
public function getPrivateKeyEndpointStripe(Producer $producer)
{
return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyEndpointStripe($producer));
}

public function isOnlinePaymentActive(ProducerModel $producer)
public function isOnlinePaymentActive(Producer $producer)
{
return $producer->online_payment
|| ($producer->option_stripe_mode_test
@@ -214,25 +218,25 @@ class ProducerSolver extends BaseService implements SolverInterface
&& \Yii::$app->user->identity->status > 10);
}

public function isOnlinePaymentActiveAndTypeOrder(ProducerModel $producer): bool
public function isOnlinePaymentActiveAndTypeOrder(Producer $producer): bool
{
return $this->isOnlinePaymentActive($producer)
&& $producer->option_online_payment_type == 'order';
}

public function isBillingFrequencyMonthly(ProducerModel $producer): bool
public function isBillingFrequencyMonthly(Producer $producer): bool
{
return $producer->option_billing_frequency == ProducerModel::BILLING_FREQUENCY_MONTHLY;
return $producer->option_billing_frequency == Producer::BILLING_FREQUENCY_MONTHLY;
}

public function isBillingFrequencyQuarterly(ProducerModel $producer): bool
public function isBillingFrequencyQuarterly(Producer $producer): bool
{
return $producer->option_billing_frequency == ProducerModel::BILLING_FREQUENCY_QUARTERLY;
return $producer->option_billing_frequency == Producer::BILLING_FREQUENCY_QUARTERLY;
}

public function isBillingFrequencyBiannual(ProducerModel $producer): bool
public function isBillingFrequencyBiannual(Producer $producer): bool
{
return $producer->option_billing_frequency == ProducerModel::BILLING_FREQUENCY_BIANNUAL;
return $producer->option_billing_frequency == Producer::BILLING_FREQUENCY_BIANNUAL;
}

}

+ 1
- 1
common/logic/Producer/Producer/ProducerUtils.php Datei anzeigen

@@ -7,7 +7,7 @@ use common\logic\UtilsInterface;

class ProducerUtils extends BaseService implements UtilsInterface
{
public function sendEmailNewProducer(ProducerModel $producer)
public function sendEmailNewProducer(Producer $producer)
{
\Yii::$app->mailer->compose(
[

common/logic/Product/Product/ProductModel.php → common/logic/Product/Product/Product.php Datei anzeigen

@@ -41,7 +41,7 @@ namespace common\logic\Product\Product;
use common\helpers\Debug;
use common\helpers\GlobalParam;
use common\helpers\Price;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use Yii;
use common\components\ActiveRecordCommon;

@@ -49,7 +49,7 @@ use common\components\ActiveRecordCommon;
* This is the model class for table "product".
*
*/
class ProductModel extends ActiveRecordCommon
class Product extends ActiveRecordCommon
{
public $total = 0;
public $apply_distributions = true;
@@ -174,13 +174,13 @@ class ProductModel extends ActiveRecordCommon
public function afterFind()
{
if ($this->taxRate == null) {
$producer = ProducerModel::searchOne(['id' => GlobalParam::getCurrentProducerId()]);
$producer = Producer::searchOne(['id' => GlobalParam::getCurrentProducerId()]);
if ($producer) {
$this->populateRelation('taxRate', $producer->taxRate);
}
}

$this->wording_unit = ProductModel::strUnit($this->unit);
$this->wording_unit = Product::strUnit($this->unit);
$this->price_with_tax = $this->getPriceWithTax();

parent::afterFind();
@@ -198,7 +198,7 @@ class ProductModel extends ActiveRecordCommon

public function getTaxRate()
{
return $this->hasOne(TaxRateModel::className(), ['id' => 'id_tax_rate']);
return $this->hasOne(TaxRate::className(), ['id' => 'id_tax_rate']);
}

public function getProductPrice()
@@ -306,7 +306,7 @@ class ProductModel extends ActiveRecordCommon
*/
public static function searchByDistribution($idDistribution)
{
return ProductModel::find()
return Product::find()
->leftJoin('product_distribution', 'product.id = product_distribution.id_product')
->where([
'id_producer' => GlobalParam::getCurrentProducerId(),
@@ -333,7 +333,7 @@ class ProductModel extends ActiveRecordCommon
*/
public static function getProductGift()
{
$productGift = ProductModel::find()
$productGift = Product::find()
->where([
'product.id_producer' => 0
])

+ 1
- 1
common/logic/Product/Product/ProductContainer.php Datei anzeigen

@@ -8,7 +8,7 @@ class ProductContainer implements ContainerInterface
{
public function getEntityFqcn(): string
{
return ProductModel::class;
return Product::class;
}

public function getServices(): array

+ 2
- 2
common/logic/Product/Product/ProductFactory.php Datei anzeigen

@@ -7,9 +7,9 @@ use common\logic\FactoryInterface;

class ProductFactory extends BaseService implements FactoryInterface
{
public function create(): ProductModel
public function create(): Product
{
$product = new ProductModel();
$product = new Product();

return $product;
}

+ 2
- 2
common/logic/Product/Product/ProductSearch.php Datei anzeigen

@@ -41,7 +41,7 @@ namespace common\logic\Product\Product ;
use common\helpers\GlobalParam;
use yii\data\ActiveDataProvider;

class ProductSearch extends ProductModel
class ProductSearch extends Product
{
public function rules()
{
@@ -59,7 +59,7 @@ class ProductSearch extends ProductModel
{
$optionsSearch = self::defaultOptionsSearch() ;
$query = ProductModel::find()
$query = Product::find()
->with($optionsSearch['with'])
->innerJoinWith($optionsSearch['join_with'], true)
->where(['product.id_producer' => GlobalParam::getCurrentProducerId()])

+ 8
- 8
common/logic/Subscription/Subscription/SubscriptionModel.php Datei anzeigen

@@ -39,7 +39,7 @@
namespace common\logic\Subscription\Subscription;

use common\helpers\GlobalParam;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\User\CreditHistory\CreditHistoryModel;
use common\logic\User\UserProducer\UserProducerModel;
use Yii;
@@ -114,7 +114,7 @@ class SubscriptionModel extends ActiveRecordCommon
public function getProducer()
{
return $this->hasOne(
ProducerModel::class,
Producer::class,
['id' => 'id_producer']
);
}
@@ -201,12 +201,12 @@ class SubscriptionModel extends ActiveRecordCommon

$order->auto_payment = 0;
if($this->auto_payment == self::AUTO_PAYMENT_DEDUCTED) {
if ($order->id_user && ProducerModel::getConfig('credit') && $pointSale->credit) {
if ($creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_OPTIONAL) {
if ($order->id_user && Producer::getConfig('credit') && $pointSale->credit) {
if ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) {
$order->auto_payment = 0;
} elseif ($creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_MANDATORY) {
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) {
$order->auto_payment = 1;
} elseif ($creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_USER) {
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) {
$user = UserModel::findOne($order->id_user);
$userProducer = UserProducerModel::searchOne([
'id_user' => $order->id_user,
@@ -430,7 +430,7 @@ class SubscriptionModel extends ActiveRecordCommon
':id_subscription' => $this->id
];

$orderDeadline = ProducerModel::getConfig('order_deadline');
$orderDeadline = Producer::getConfig('order_deadline');
$hour = date('G');

if ($hour >= $orderDeadline) {
@@ -449,7 +449,7 @@ class SubscriptionModel extends ActiveRecordCommon
$orders->params($params);

$ordersArray = $orders->all();
$configCredit = ProducerModel::getConfig('credit');
$configCredit = Producer::getConfig('credit');

$countOrdersDeleted = 0;
if ($ordersArray && count($ordersArray)) {

+ 2
- 2
common/logic/User/User/UserBuilder.php Datei anzeigen

@@ -4,7 +4,7 @@ namespace common\logic\User\User;

use common\logic\BaseService;
use common\logic\BuilderInterface;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

class UserBuilder extends BaseService implements BuilderInterface
{
@@ -14,7 +14,7 @@ class UserBuilder extends BaseService implements BuilderInterface
$user->generateAuthKey();
}

public function initProducer(UserModel $user, ProducerModel $producer)
public function initProducer(UserModel $user, Producer $producer)
{
$user->id_producer = $producer->id;
$user->status = UserModel::STATUS_PRODUCER;

+ 6
- 0
common/logic/User/User/UserContainer.php Datei anzeigen

@@ -15,6 +15,7 @@ class UserContainer implements ContainerInterface
{
return [
UserFactory::class,
UserSolver::class,
UserRepository::class,
UserBuilder::class,
UserUtils::class,
@@ -26,6 +27,11 @@ class UserContainer implements ContainerInterface
return new UserFactory();
}

public function getSolver(): UserSolver
{
return new UserSolver();
}

public function getRepository(): UserRepository
{
return new UserRepository();

+ 2
- 2
common/logic/User/User/UserRepository.php Datei anzeigen

@@ -4,7 +4,7 @@ namespace common\logic\User\User;

use common\helpers\GlobalParam;
use common\logic\BaseService;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\RepositoryInterface;
use common\logic\User\UserProducer\UserProducerRepository;
use yii\db\Query;
@@ -112,7 +112,7 @@ class UserRepository extends BaseService implements RepositoryInterface
* Retourne le crédit de l'utilisateur pour un producteur donné.
*
*/
public function getCredit(UserModel $user, ProducerModel $producer): float
public function getCredit(UserModel $user, Producer $producer): float
{
$userProducer = $this->userProducerRepository->getOne($user, $producer);


+ 3
- 3
common/logic/User/User/UserUtils.php Datei anzeigen

@@ -4,12 +4,12 @@ namespace common\logic\User\User;

use common\helpers\GlobalParam;
use common\logic\BaseService;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\UtilsInterface;

class UserUtils extends BaseService implements UtilsInterface
{
public function sendEmailSignup(UserModel $user, ProducerModel $producer)
public function sendEmailSignup(UserModel $user, Producer $producer)
{
\Yii::$app->mailer->compose(
[
@@ -34,7 +34,7 @@ class UserUtils extends BaseService implements UtilsInterface
public function sendMailWelcome(UserModel $user, string $password): void
{
if (strlen($user->email)) {
$producer = ProducerModel::findOne(GlobalParam::getCurrentProducerId());
$producer = Producer::findOne(GlobalParam::getCurrentProducerId());
\Yii::$app->mailer->compose();
$mail = \Yii::$app->mailer->compose(
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $user, 'producer' => $producer, 'password' => $password]

+ 2
- 2
common/logic/User/UserProducer/UserProducerBuilder.php Datei anzeigen

@@ -6,7 +6,7 @@ use common\helpers\MeanPayment;
use common\logic\BaseService;
use common\logic\BuilderInterface;
use common\logic\Order\Order\OrderModel;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\User\CreditHistory\CreditHistoryModel;
use common\logic\User\CreditHistory\CreditHistorySolver;

@@ -94,7 +94,7 @@ class UserProducerBuilder extends BaseService implements BuilderInterface

public function isCreditLimitCrossed($oldCredit, $newCredit)
{
$creditLimitReminder = ProducerModel::getConfig('credit_limit_reminder');
$creditLimitReminder = Producer::getConfig('credit_limit_reminder');

return !is_null($creditLimitReminder) &&
$oldCredit > $creditLimitReminder

+ 2
- 2
common/logic/User/UserProducer/UserProducerModel.php Datei anzeigen

@@ -38,7 +38,7 @@

namespace common\logic\User\UserProducer;

use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\User\User\UserModel;
use Yii;
use common\components\ActiveRecordCommon;
@@ -86,7 +86,7 @@ class UserProducerModel extends ActiveRecordCommon

public function getProducer()
{
return $this->hasOne(ProducerModel::class, ['id' => 'id_producer']);
return $this->hasOne(Producer::class, ['id' => 'id_producer']);
}

public function getUser()

+ 2
- 2
common/logic/User/UserProducer/UserProducerRepository.php Datei anzeigen

@@ -3,13 +3,13 @@
namespace common\logic\User\UserProducer;

use common\logic\BaseService;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\RepositoryInterface;
use common\logic\User\User\UserModel;

class UserProducerRepository extends BaseService implements RepositoryInterface
{
public function getOne(UserModel $user, ProducerModel $producer)
public function getOne(UserModel $user, Producer $producer)
{
return UserProducerModel::searchOne([
'id_user' => $user->id,

+ 3
- 3
common/mail/orderConfirm-html.php Datei anzeigen

@@ -38,7 +38,7 @@ termes.

use common\helpers\GlobalParam ;
use yii\helpers\Html;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\models\Order;

?>
@@ -57,13 +57,13 @@ use common\models\Order;
<?php endif; ?>
<?php if(strlen($pointSale->locality) > 0): ?> situé à <?= Html::encode($pointSale->locality) ?><?php endif ?>.</p>

<?php $payment_infos = ProducerModel::getConfig('option_payment_info') ; ?>
<?php $payment_infos = Producer::getConfig('option_payment_info') ; ?>
<?php if($payment_infos && strlen($payment_infos) > 0): ?>
<p><strong>Informations de paiement :</strong><br />
<?= nl2br(Html::encode($payment_infos)); ?></p>
<?php endif; ?>

<?php $order_infos = ProducerModel::getConfig('order_infos') ; ?>
<?php $order_infos = Producer::getConfig('order_infos') ; ?>
<?php if($order_infos && strlen($order_infos) > 0): ?>
<p><strong>Informations générales :</strong><br />
<?= nl2br(Html::encode($order_infos)); ?></p>

+ 3
- 3
common/mail/orderConfirm-text.php Datei anzeigen

@@ -37,7 +37,7 @@ termes.
*/

use common\helpers\GlobalParam ;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

$producer = GlobalParam::getCurrentProducer() ;

@@ -52,13 +52,13 @@ Récapitulatif des produits commandés :

Elle sera à retirer le <?= date('d/m/Y',strtotime($distribution->date)) ?> au point de retrait <?= $pointSale->name ?> <?php if($order->pointSale->is_bread_box && $order->pointSale->bread_box_code): ?> (Code : <?= $order->pointSale->bread_box_code; ?>) <?php endif; ?> <?php if(strlen($pointSale->locality) > 0): ?> situé à <?= Html::encode($pointSale->locality) ?><?php endif ?>.

<?php $payment_infos = ProducerModel::getConfig('option_payment_info') ; ?>
<?php $payment_infos = Producer::getConfig('option_payment_info') ; ?>
<?php if($payment_infos && strlen($payment_infos) > 0): ?>
Informations de paiement :
<?= $payment_infos ?>
<?php endif; ?>

<?php $order_infos = ProducerModel::getConfig('order_infos') ; ?>
<?php $order_infos = Producer::getConfig('order_infos') ; ?>
<?php if($order_infos && strlen($order_infos) > 0): ?>
Informations générales :
<?= $order_infos ?>

+ 3
- 3
common/mail/paymentError-html.php Datei anzeigen

@@ -37,7 +37,7 @@ termes.
*/

use yii\helpers\Html;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

?>

@@ -49,13 +49,13 @@ use common\logic\Producer\Producer\ProducerModel;

<p>Vous pouvez retrouver le lien de paiement dans votre <a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history','slug_producer' => $producer->slug]) ?>">historique de commandes</a>.</p>

<?php $payment_infos = ProducerModel::getConfig('option_payment_info') ; ?>
<?php $payment_infos = Producer::getConfig('option_payment_info') ; ?>
<?php if($payment_infos && strlen($payment_infos) > 0): ?>
<p><strong>Informations de paiement :</strong><br />
<?= nl2br(Html::encode($payment_infos)); ?></p>
<?php endif; ?>

<?php $order_infos = ProducerModel::getConfig('order_infos') ; ?>
<?php $order_infos = Producer::getConfig('order_infos') ; ?>
<?php if($order_infos && strlen($order_infos) > 0): ?>
<p><strong>Informations générales :</strong><br />
<?= nl2br(Html::encode($order_infos)); ?></p>

+ 2
- 2
console/migrations/m190205_164612_ajout_produit_don_aux_distributions_existantes.php Datei anzeigen

@@ -5,9 +5,9 @@ use yii\db\Migration;
class m190205_164612_ajout_produit_don_aux_distributions_existantes extends Migration {

public function up() {
$distributionsArray = common\logic\Distribution\Distribution\DistributionModel::find()->all() ;
$distributionsArray = common\logic\Distribution\Distribution\Distribution::find()->all() ;
foreach($distributionsArray as $distribution) {
$distribution->linkProductGift() ;
}
}


+ 4
- 4
console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php Datei anzeigen

@@ -2,18 +2,18 @@

use yii\db\Migration;

use common\logic\Producer\Producer\ProducerModel;
use common\logic\PointSale\PointSale\PointSaleModel;
use common\logic\Producer\Producer\Producer;
use common\logic\PointSale\PointSale\PointSale;
use common\logic\PointSale\UserPointSale\UserPointSaleModel;

class m190226_084104_lien_utilisateur_point_de_vente extends Migration
{
public function up()
{
$producersArray = ProducerModel::find()->all() ;
$producersArray = Producer::find()->all() ;
foreach($producersArray as $producer) {
$pointsSaleArray = PointSaleModel::find()
$pointsSaleArray = PointSale::find()
->where([
'id_producer' => $producer->id
])

+ 2
- 2
console/migrations/m190515_122438_ajout_champs_price_product_subscription.php Datei anzeigen

@@ -3,7 +3,7 @@
use yii\db\Migration;
use yii\db\mysql\Schema;
use common\logic\Subscription\ProductSubscription\ProductSubscriptionModel;
use common\logic\Product\Product\ProductModel;
use common\logic\Product\Product\Product;

class m190515_122438_ajout_champs_price_product_subscription extends Migration {

@@ -11,7 +11,7 @@ class m190515_122438_ajout_champs_price_product_subscription extends Migration {
$this->addColumn('product_subscription', 'price', Schema::TYPE_FLOAT. ' DEFAULT 0') ;
$productsSubscriptionsArray = ProductSubscriptionModel::find()->all() ;
$productsArray = ProductModel::find()->all() ;
$productsArray = Product::find()->all() ;
foreach($productsSubscriptionsArray as $productSubscription) {
foreach($productsArray as $product) {

+ 2
- 2
console/migrations/m190522_091006_option_comportement_annulation_commande.php Datei anzeigen

@@ -2,12 +2,12 @@

use yii\db\Migration;
use yii\db\mysql\Schema;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

class m190522_091006_option_comportement_annulation_commande extends Migration {

public function up() {
$this->addColumn('producer', 'option_behavior_cancel_order', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::BEHAVIOR_DELETE_ORDER_STATUS.'\'') ;
$this->addColumn('producer', 'option_behavior_cancel_order', Schema::TYPE_STRING.' DEFAULT \''.Producer::BEHAVIOR_DELETE_ORDER_STATUS.'\'') ;
}

public function down() {

+ 3
- 3
console/migrations/m200601_073309_add_producer_options.php Datei anzeigen

@@ -2,14 +2,14 @@

use yii\db\Migration;
use yii\db\Schema;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

class m200601_073309_add_producer_options extends Migration
{
public function safeUp()
{
$this->addColumn('producer', 'behavior_home_point_sale_day_list', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK.'\'');
$this->addColumn('producer', 'behavior_order_select_distribution', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_CALENDAR.'\'');
$this->addColumn('producer', 'behavior_home_point_sale_day_list', Schema::TYPE_STRING.' DEFAULT \''.Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK.'\'');
$this->addColumn('producer', 'behavior_order_select_distribution', Schema::TYPE_STRING.' DEFAULT \''.Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_CALENDAR.'\'');
}

public function safeDown()

+ 2
- 2
console/migrations/m220915_072309_producer_add_option_billing_frequency.php Datei anzeigen

@@ -2,7 +2,7 @@

use yii\db\Migration;
use yii\db\Schema;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

/**
* Class m220915_072309_producer_add_option_billing_frequency
@@ -14,7 +14,7 @@ class m220915_072309_producer_add_option_billing_frequency extends Migration
*/
public function safeUp()
{
$this->addColumn('producer', 'option_billing_frequency', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::BILLING_FREQUENCY_MONTHLY.'\'');
$this->addColumn('producer', 'option_billing_frequency', Schema::TYPE_STRING.' DEFAULT \''.Producer::BILLING_FREQUENCY_MONTHLY.'\'');
}

/**

+ 2
- 2
console/migrations/m220915_083713_producer_add_options_billing.php Datei anzeigen

@@ -2,7 +2,7 @@

use yii\db\Migration;
use yii\db\Schema;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

/**
* Class m220915_083713_producer_add_options_billing
@@ -14,7 +14,7 @@ class m220915_083713_producer_add_options_billing extends Migration
*/
public function safeUp()
{
$this->addColumn('producer', 'option_billing_type', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::BILLING_TYPE_CLASSIC.'\'');
$this->addColumn('producer', 'option_billing_type', Schema::TYPE_STRING.' DEFAULT \''.Producer::BILLING_TYPE_CLASSIC.'\'');
$this->addColumn('producer', 'option_billing_reduction', Schema::TYPE_BOOLEAN.' DEFAULT 0');
}


+ 6
- 6
frontend/forms/SignupForm.php Datei anzeigen

@@ -38,9 +38,9 @@

namespace frontend\forms;

use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\User\User\UserModel;
use common\logic\Config\TaxRate\TaxRateModel;
use common\logic\Config\TaxRate\TaxRate;
use yii\base\Model;

/**
@@ -168,7 +168,7 @@ class SignupForm extends Model
['id_producer', 'integer'],
['id_producer', function ($attribute, $params) {
if ($this->id_producer) {
$producer = ProducerModel::findOne($this->id_producer);
$producer = Producer::findOne($this->id_producer);
if (!$producer) {
$this->addError($attribute, 'Ce producteur n\'existe pas.');
}
@@ -178,7 +178,7 @@ class SignupForm extends Model
return $this->option_user_producer == 'user';
}],
['code', 'required', 'message' => 'Champs obligatoire', 'when' => function ($model) {
$producer = ProducerModel::findOne($this->id_producer);
$producer = Producer::findOne($this->id_producer);
if ($producer) {
return strlen($producer->code);
} else {
@@ -187,7 +187,7 @@ class SignupForm extends Model
}],
['code', function ($attribute, $params) {
$code = $this->$attribute;
$producer = ProducerModel::findOne($this->id_producer);
$producer = Producer::findOne($this->id_producer);

if ($producer && strtolower(trim($code)) != strtolower(trim($producer->code))) {
$this->addError($attribute, 'Code incorrect');
@@ -195,7 +195,7 @@ class SignupForm extends Model
}],
// ['free_price', 'number'],
['id_tax_rate_default', 'exist',
'targetClass' => TaxRateModel::className(),
'targetClass' => TaxRate::className(),
'targetAttribute' => ['id_tax_rate_default' => 'id']],
['verifyCode', 'captcha', 'message' => 'Veuillez recopier le code de vérification'],
];

+ 3
- 3
frontend/views/layouts/main.php Datei anzeigen

@@ -42,7 +42,7 @@ use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use common\widgets\Alert;
use common\helpers\Url;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\User\User\UserModel;

/* @var $this \yii\web\View */
@@ -55,7 +55,7 @@ $isHome = (Yii::$app->controller->id == 'site' && \Yii::$app->controller->action

$producer = null;
if (!Yii::$app->user->isGuest && \Yii::$app->user->identity->id_producer > 0) {
$producer = ProducerModel::searchOne(['id' => \Yii::$app->user->identity->id_producer]);
$producer = Producer::searchOne(['id' => \Yii::$app->user->identity->id_producer]);
}

?>
@@ -189,7 +189,7 @@ if (!Yii::$app->user->isGuest && \Yii::$app->user->identity->id_producer > 0) {
<div class="container">
<?php

$producersArray = ProducerModel::find()
$producersArray = Producer::find()
->joinWith(['userProducer user_producer'])
->where([
'user_producer.id_user' => UserModel::getCurrentId(),

+ 1
- 1
frontend/views/site/signup.php Datei anzeigen

@@ -82,7 +82,7 @@ $this->params['breadcrumbs'][] = $this->title;
<?= $form->field($model, 'postcode') ?>
<?= $form->field($model, 'city') ?>
<?= $form->field($model, 'id_tax_rate_default')
->dropDownList(ArrayHelper::map(TaxRateModel::find()->all(), 'id', function($model) { return $model->name; }), [
->dropDownList(ArrayHelper::map(TaxRate::find()->all(), 'id', function($model) { return $model->name; }), [
'prompt' => '--',
])
->label('TVA à appliquer par défaut'); ?>

+ 15
- 15
producer/controllers/OrderController.php Datei anzeigen

@@ -39,7 +39,7 @@
namespace producer\controllers;

use common\helpers\Mailjet;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\User\CreditHistory\CreditHistoryModel;
use common\logic\User\User\UserModel;
use common\logic\User\UserProducer\UserProducerModel;
@@ -329,7 +329,7 @@ class OrderController extends ProducerBaseController
*/
public function _verifyProducerActive($idProducer)
{
$producer = ProducerModel::findOne($idProducer);
$producer = Producer::findOne($idProducer);
if ($producer && !$producer->active) {
throw new NotFoundHttpException('Ce producteur est actuellement hors ligne.');
}
@@ -438,7 +438,7 @@ class OrderController extends ProducerBaseController
$order->changeOrderStatus('new-order', 'user');

// ajout de l'utilisateur à l'établissement
ProducerModel::addUser($user->id, $distribution->id_producer);
Producer::addUser($user->id, $distribution->id_producer);

// suppression de tous les enregistrements ProductOrder
if (!is_null($order)) {
@@ -487,8 +487,8 @@ class OrderController extends ProducerBaseController
$pointSale->linkUser($user->id);

// credit
$credit = ProducerModel::getConfig('credit');
$creditLimit = ProducerModel::getConfig('credit_limit');
$credit = Producer::getConfig('credit');
$creditLimit = Producer::getConfig('credit_limit');
$creditFunctioning = $pointSale->getCreditFunctioning();
$creditUser = $user->getCredit($distribution->id_producer);
$order = OrderModel::searchOne([
@@ -498,9 +498,9 @@ class OrderController extends ProducerBaseController
$amountRemaining = $order->getAmount(OrderModel::AMOUNT_REMAINING);

if ($credit && $pointSale->credit &&
(($creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_OPTIONAL && $posts['use_credit']) ||
$creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_MANDATORY ||
($creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_USER && $userProducer->credit_active)
(($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL && $posts['use_credit']) ||
$creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY ||
($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER && $userProducer->credit_active)
)) {
$order->changeOrderStatus('waiting-paiement-by-credit', 'user');

@@ -559,13 +559,13 @@ class OrderController extends ProducerBaseController
*/
if ($isNewOrder) {
// au client
if (ProducerModel::getConfig('option_email_confirm')) {
if (Producer::getConfig('option_email_confirm')) {
Mailjet::sendMail($paramsEmail);
}

// au producteur
$contactProducer = $producer->getMainContact();
if (ProducerModel::getConfig('option_email_confirm_producer') && $contactProducer && strlen(
if (Producer::getConfig('option_email_confirm_producer') && $contactProducer && strlen(
$contactProducer->email
)) {
$paramsEmail['to_email'] = $contactProducer->email;
@@ -660,7 +660,7 @@ class OrderController extends ProducerBaseController
$orderUser = $this->_getOrderUser($date, $pointSaleId);

// Producteur
$producer = ProducerModel::searchOne([
$producer = Producer::searchOne([
'id' => $this->getProducer()->id
]);
$json['producer'] = [
@@ -690,7 +690,7 @@ class OrderController extends ProducerBaseController
$distributionsArray = DistributionModel::filterDistributionsByDateDelay($distributionsArray);

// Filtre par point de vente
if ($pointSaleId && $producer->option_order_entry_point == ProducerModel::ORDER_ENTRY_POINT_POINT_SALE) {
if ($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) {
$distributionsArrayFilterPointSale = [];
for ($i = 0; $i < count($distributionsArray); $i++) {
$distribution = $distributionsArray[$i];
@@ -725,7 +725,7 @@ class OrderController extends ProducerBaseController
':date' => $dateMini
];

if ($pointSaleId && $producer->option_order_entry_point == ProducerModel::ORDER_ENTRY_POINT_POINT_SALE) {
if ($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) {
$conditionsOrdersUser[] = 'order.id_point_sale = :id_point_sale';
$paramsOrdersUser[':id_point_sale'] = $pointSaleId;
}
@@ -756,7 +756,7 @@ class OrderController extends ProducerBaseController
]);

if($user && !$userProducer) {
$userProducer = ProducerModel::addUser($user->id, $producer->id);
$userProducer = Producer::addUser($user->id, $producer->id);
}

$json['user'] = false;
@@ -956,7 +956,7 @@ class OrderController extends ProducerBaseController
->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC')
->all();

$creditFunctioningProducer = ProducerModel::getConfig('credit_functioning');
$creditFunctioningProducer = Producer::getConfig('credit_functioning');
$position = 0;

foreach ($pointsSaleArray as &$pointSale) {

+ 2
- 2
producer/controllers/ProducerBaseController.php Datei anzeigen

@@ -39,7 +39,7 @@ termes.
namespace producer\controllers;

use common\controllers\CommonController;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use common\logic\User\User\UserModel;
use common\logic\User\UserProducer\UserProducerModel;

@@ -110,7 +110,7 @@ class ProducerBaseController extends CommonController
return $this->producer ;
}
else {
$producer = ProducerModel::find()
$producer = Producer::find()
->with('contact')
->where(['slug' => \Yii::$app->getRequest()->getQueryParam('slug_producer')])
->one() ;

+ 2
- 2
producer/models/CreditForm.php Datei anzeigen

@@ -38,7 +38,7 @@ termes.

namespace producer\models;

use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;
use Yii;
use yii\base\Model;

@@ -54,7 +54,7 @@ class CreditForm extends Model
{
return [
[['amount'], 'required'],
[['amount'], 'double', 'min' => ProducerModel::getOnlinePaymentMinimumAmount()],
[['amount'], 'double', 'min' => Producer::getOnlinePaymentMinimumAmount()],
];
}


+ 2
- 2
producer/views/credit/add.php Datei anzeigen

@@ -38,7 +38,7 @@

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

$this->setTitle('Créditer mon compte');
$this->setPageTitle('Crédit mon compte');
@@ -63,7 +63,7 @@ $this->addButton(
'template' => '{label}<div class="input-group input-group-lg">{input}<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span></div>{hint}',
])
->label('Quel montant souhaitez-vous créditer ?')
->hint('Montant minimum : '.ProducerModel::getOnlinePaymentMinimumAmount().' €'); ?>
->hint('Montant minimum : '.Producer::getOnlinePaymentMinimumAmount().' €'); ?>

<div class="form-group">
<?= Html::submitButton('<span class="glyphicon glyphicon-lock"></span> Payer', ['class' => 'btn btn-primary']

+ 2
- 2
producer/views/order/_form.php Datei anzeigen

@@ -37,7 +37,7 @@ termes.
*/

use yii\widgets\ActiveForm;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

?>
<div class="order-form">
@@ -257,7 +257,7 @@ use common\logic\Producer\Producer\ProducerModel;

<?php if($idProducer): ?>
<?php
$producer = ProducerModel::findOne($idProducer);
$producer = Producer::findOne($idProducer);
?>
<div id="bar-fixed" class="<?php if($producer->credit): ?>credit<?php else: ?>no-credit<?php endif; ?>">
<div class="container">

+ 5
- 5
producer/views/order/order.php Datei anzeigen

@@ -37,7 +37,7 @@ termes.
*/

use common\helpers\GlobalParam ;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

\producer\assets\VuejsOrderOrderAsset::register($this);

@@ -68,7 +68,7 @@ $producer = $this->context->getProducer();
<div>
<div id="steps">
<ul>
<?php if($producer->option_order_entry_point == ProducerModel::ORDER_ENTRY_POINT_DATE): ?>
<?php if($producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_DATE): ?>
<step-date
first="true"
:step="step"
@@ -133,7 +133,7 @@ $producer = $this->context->getProducer();
Chargement ...
</div>
<div v-else>
<?php if($producer->behavior_order_select_distribution == ProducerModel::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?>
<?php if($producer->behavior_order_select_distribution == Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?>
<div style="display:none ;">
<?php endif; ?>
<div id="legend">
@@ -157,11 +157,11 @@ $producer = $this->context->getProducer();
@dayclick='dayClick'
></v-calendar>
</div>
<?php if($producer->behavior_order_select_distribution == ProducerModel::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?>
<?php if($producer->behavior_order_select_distribution == Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?>
</div>
<?php endif; ?>

<?php if($producer->behavior_order_select_distribution == ProducerModel::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?>
<?php if($producer->behavior_order_select_distribution == Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?>
<div id="distributions-list">
<?php $incomingDistributions = DistributionModel::getIncomingDistributions(); ?>
<?php foreach($incomingDistributions as $distribution): ?>

+ 3
- 3
producer/views/site/index.php Datei anzeigen

@@ -36,7 +36,7 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

$producer = $this->context->getProducer() ;
$this->setTitle('Accueil');
@@ -79,7 +79,7 @@ $this->setPageTitle(Html::encode($producer->type.' à '.$producer->city)) ;

$producer = \Yii::$app->controller->getProducer() ;

if($producer->behavior_home_point_sale_day_list == ProducerModel::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK) {
if($producer->behavior_home_point_sale_day_list == Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK) {
$arrayDays = [
'monday' => 'Lundi',
'tuesday' => 'Mardi',
@@ -106,7 +106,7 @@ $this->setPageTitle(Html::encode($producer->type.' à '.$producer->city)) ;

return $html ;
}
elseif($producer->behavior_home_point_sale_day_list == ProducerModel::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_INCOMING_DISTRIBUTIONS) {
elseif($producer->behavior_home_point_sale_day_list == Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_INCOMING_DISTRIBUTIONS) {
$html = '' ;
$incomingDistributions = DistributionModel::getIncomingDistributions();
$cpt = 0 ;

+ 2
- 2
producer/views/subscription/_form.php Datei anzeigen

@@ -36,7 +36,7 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

\producer\assets\VuejsSubscriptionFormAsset::register($this) ;

@@ -130,7 +130,7 @@ use common\logic\Producer\Producer\ProducerModel;
<h3><span>Paiement</span></h3>

<?php if(ProducerModel::getConfig('credit')): ?>
<?php if(Producer::getConfig('credit')): ?>
<div class="form-group field-subscriptionform-auto_payment">
<label><input type="checkbox" id="subscriptionform-auto_payment" name="SubscriptionForm[auto_payment]" v-model="autoPayment"> Paiement automatique</label>
<div class="hint-block">Cochez cette case si vous souhaitez que votre Crédit soit automatiquement débité.</div>

+ 2
- 2
producer/views/subscription/index.php Datei anzeigen

@@ -39,7 +39,7 @@ termes.
use yii\helpers\Html;
use yii\grid\GridView;
use common\helpers\GlobalParam;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\Producer\Producer\Producer;

$this->setTitle('Abonnements') ;
$this->addButton(['label' => '<span class="glyphicon glyphicon-plus"></span> Ajouter', 'url' => 'subscription/form', 'class' => 'btn btn-primary']) ;
@@ -152,7 +152,7 @@ $columns = [
],
] ;
if(ProducerModel::getConfig('credit')) {
if(Producer::getConfig('credit')) {
$columns[] = [
'format' => 'raw',
'label' => 'Paiement automatique',

Laden…
Abbrechen
Speichern