Browse Source

Refactoring services #885

refactoring
Guillaume 1 year ago
parent
commit
24ac35d0d1
66 changed files with 26489 additions and 259 deletions
  1. +5
    -5
      common/components/BusinessLogic.php
  2. +1
    -1
      common/config/main.php
  3. +2
    -1
      common/controllers/CommonController.php
  4. +6
    -5
      common/forms/LoginForm.php
  5. +3
    -1
      common/helpers/CSV.php
  6. +2
    -1
      common/helpers/GlobalParam.php
  7. +4
    -3
      common/helpers/Tiller.php
  8. +6
    -5
      common/logic/BaseService.php
  9. +2
    -2
      common/logic/Producer/Producer/ProducerBuilder.php
  10. +1
    -2
      common/logic/Producer/Producer/ProducerContainer.php
  11. +1
    -1
      common/logic/Producer/Producer/ProducerFactory.php
  12. +6
    -6
      common/logic/Producer/Producer/ProducerModel.php
  13. +1
    -1
      common/logic/Producer/Producer/ProducerRepository.php
  14. +1
    -2
      common/logic/Producer/Producer/ProducerUtils.php
  15. +1
    -1
      common/logic/Producer/ProducerPriceRange/ProducerPriceRangeContainer.php
  16. +1
    -1
      common/logic/Producer/ProducerPriceRange/ProducerPriceRangeModel.php
  17. +1
    -1
      common/logic/Producer/ProducerPriceRange/ProducerPriceRangeRepository.php
  18. +2
    -2
      common/logic/User/CreditHistory/CreditHistoryBuilder.php
  19. +1
    -1
      common/logic/User/CreditHistory/CreditHistoryContainer.php
  20. +1
    -1
      common/logic/User/CreditHistory/CreditHistoryFactory.php
  21. +1
    -1
      common/logic/User/CreditHistory/CreditHistoryModel.php
  22. +1
    -1
      common/logic/User/CreditHistory/CreditHistoryRepository.php
  23. +4
    -4
      common/logic/User/CreditHistory/CreditHistorySolver.php
  24. +1
    -1
      common/logic/User/User/UserBuilder.php
  25. +1
    -3
      common/logic/User/User/UserContainer.php
  26. +1
    -1
      common/logic/User/User/UserFactory.php
  27. +22
    -15
      common/logic/User/User/UserModel.php
  28. +1
    -1
      common/logic/User/User/UserRepository.php
  29. +2
    -3
      common/logic/User/User/UserUtils.php
  30. +1
    -1
      common/logic/User/UserProducer/UserProducerBuilder.php
  31. +3
    -4
      common/logic/User/UserProducer/UserProducerContainer.php
  32. +3
    -3
      common/logic/User/UserProducer/UserProducerModel.php
  33. +1
    -1
      common/logic/User/UserProducer/UserProducerRepository.php
  34. +2
    -2
      common/mail/creditUser-html.php
  35. +1
    -1
      common/mail/creditUser-text.php
  36. +5
    -3
      common/mail/orderConfirm-html.php
  37. +4
    -3
      common/mail/orderConfirm-text.php
  38. +5
    -2
      common/mail/paymentError-html.php
  39. +1
    -1
      common/mail/signup-html.php
  40. +2
    -1
      common/mail/signup-text.php
  41. +5
    -4
      common/models/CreditHistorySearch.php
  42. +2
    -1
      common/models/DevelopmentPriority.php
  43. +2
    -1
      common/models/Distribution.php
  44. +8
    -7
      common/models/Document.php
  45. +21
    -18
      common/models/Order.php
  46. +2
    -1
      common/models/PointSale.php
  47. +2
    -1
      common/models/Product.php
  48. +15
    -17
      common/models/Subscription.php
  49. +3
    -1
      frontend/controllers/SiteController.php
  50. +14
    -15
      frontend/forms/SignupForm.php
  51. +2
    -2
      frontend/views/layouts/main.php
  52. +15
    -16
      producer/controllers/CreditController.php
  53. +21
    -21
      producer/controllers/OrderController.php
  54. +13
    -12
      producer/controllers/ProducerBaseController.php
  55. +5
    -3
      producer/controllers/SiteController.php
  56. +9
    -6
      producer/controllers/SubscriptionController.php
  57. +2
    -1
      producer/models/CreditForm.php
  58. +26203
    -0
      producer/runtime/logs/app.log
  59. +2
    -1
      producer/views/credit/add.php
  60. +15
    -15
      producer/views/credit/history.php
  61. +3
    -3
      producer/views/layouts/main.php
  62. +3
    -3
      producer/views/order/_form.php
  63. +5
    -5
      producer/views/order/order.php
  64. +3
    -3
      producer/views/site/index.php
  65. +2
    -6
      producer/views/subscription/_form.php
  66. +2
    -1
      producer/views/subscription/index.php

+ 5
- 5
common/components/BusinessLogic.php View File



namespace common\components; namespace common\components;


use common\containers\UserProducerContainer;
use common\logic\CreditHistory\CreditHistoryContainer;
use common\logic\Producer\ProducerContainer;
use common\logic\ProducerPriceRange\ProducerPriceRangeContainer;
use common\logic\User\UserContainer;
use common\logic\Producer\Producer\ProducerContainer;
use common\logic\Producer\ProducerPriceRange\ProducerPriceRangeContainer;
use common\logic\User\CreditHistory\CreditHistoryContainer;
use common\logic\User\User\UserContainer;
use common\logic\User\UserProducer\UserProducerContainer;
use yii\base\ErrorException; use yii\base\ErrorException;


class BusinessLogic class BusinessLogic

+ 1
- 1
common/config/main.php View File

], ],
'user' => [ 'user' => [
'class' => 'yii\web\User', 'class' => 'yii\web\User',
'identityClass' => 'common\logic\User\UserModel',
'identityClass' => 'common\logic\User\User\UserModel',
'enableAutoLogin' => true, 'enableAutoLogin' => true,
'identityCookie' => [ 'identityCookie' => [
'name' => 'distrib', 'name' => 'distrib',

+ 2
- 1
common/controllers/CommonController.php View File



namespace common\controllers; namespace common\controllers;


use common\components\BusinessLogic;
use yii; use yii;


class CommonController extends \yii\web\Controller class CommonController extends \yii\web\Controller
return parent::beforeAction($event); return parent::beforeAction($event);
} }


public function getLogic()
public function getLogic(): BusinessLogic
{ {
return Yii::$app->logic; return Yii::$app->logic;
} }

+ 6
- 5
common/forms/LoginForm.php View File



namespace common\forms; namespace common\forms;


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


['id_producer', 'integer'], ['id_producer', 'integer'],
['id_producer', function($attribute, $params) { ['id_producer', function($attribute, $params) {
if ($this->id_producer) { if ($this->id_producer) {
$producer = Producer::findOne($this->id_producer);
$producer = ProducerModel::findOne($this->id_producer);
if (!$producer) { if (!$producer) {
$this->addError($attribute, 'Ce producteur n\'existe pas.'); $this->addError($attribute, 'Ce producteur n\'existe pas.');
} }
/** /**
* Finds user by [[username]] * Finds user by [[username]]
* *
* @return User|null
*/ */
public function getUser()
public function getUser(): UserModel
{ {
if ($this->_user === false) { if ($this->_user === false) {
$this->_user = User::searchOne(
$this->_user = UserModel::searchOne(
['email' => $this->email], ['email' => $this->email],
[ [
'conditions' => 'type LIKE :type_individual OR type LIKE :type_legal_person', 'conditions' => 'type LIKE :type_individual OR type LIKE :type_legal_person',
'params' => [':type_individual' => User::TYPE_INDIVIDUAL, ':type_legal_person' => User::TYPE_LEGAL_PERSON]
'params' => [':type_individual' => UserModel::TYPE_INDIVIDUAL, ':type_legal_person' => UserModel::TYPE_LEGAL_PERSON]
] ]
); );
} }

+ 3
- 1
common/helpers/CSV.php View File



namespace common\helpers; namespace common\helpers;


use common\logic\Producer\Producer\ProducerModel;

class CSV class CSV
{ {


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


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

+ 2
- 1
common/helpers/GlobalParam.php View File



namespace common\helpers; namespace common\helpers;


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


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

+ 4
- 3
common/helpers/Tiller.php View File



namespace common\helpers; namespace common\helpers;


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


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


public function getOrders($date) public function getOrders($date)

+ 6
- 5
common/logic/BaseService.php View File

return [ return [
FactoryInterface::class, FactoryInterface::class,
SolverInterface::class, SolverInterface::class,
RepositoryInterface::class,
BuilderInterface::class, BuilderInterface::class,
ServiceInterface::class,
UtilsInterface::class,
]; ];
} }


return $this->classImplementsInterface(BuilderInterface::class); return $this->classImplementsInterface(BuilderInterface::class);
} }


public function isService(): bool
public function isUtils(): bool
{ {
return $this->classImplementsInterface(ServiceInterface::class);
return $this->classImplementsInterface(UtilsInterface::class);
} }


protected function classImplementsInterface(string $interface, $object = null): bool
protected function classImplementsInterface(string $interface, $object = null)
{ {
if(is_null($object)) { if(is_null($object)) {
$object = $this; $object = $this;
} }


return class_implements($object, $interface);
return in_array($interface, class_implements($object));
} }
} }

common/logic/Producer/ProducerBuilder.php → common/logic/Producer/Producer/ProducerBuilder.php View File

<?php <?php


namespace common\logic\Producer;
namespace common\logic\Producer\Producer;


use common\helpers\Password; use common\helpers\Password;
use common\logic\BaseService; use common\logic\BaseService;
use common\logic\BuilderInterface; use common\logic\BuilderInterface;
use common\logic\UserProducer\UserProducerModel;
use common\logic\User\UserProducer\UserProducerModel;


class ProducerBuilder extends BaseService implements BuilderInterface class ProducerBuilder extends BaseService implements BuilderInterface
{ {

common/logic/Producer/ProducerContainer.php → common/logic/Producer/Producer/ProducerContainer.php View File

<?php <?php


namespace common\logic\Producer;
namespace common\logic\Producer\Producer;


use common\logic\ContainerInterface; use common\logic\ContainerInterface;
use common\services\Producer\ProducerUtils;


class ProducerContainer implements ContainerInterface class ProducerContainer implements ContainerInterface
{ {

common/logic/Producer/ProducerFactory.php → common/logic/Producer/Producer/ProducerFactory.php View File

<?php <?php


namespace common\logic\Producer;
namespace common\logic\Producer\Producer;


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

common/logic/Producer/ProducerModel.php → common/logic/Producer/Producer/ProducerModel.php View File

* termes. * termes.
*/ */


namespace common\logic\Producer;
namespace common\logic\Producer\Producer;


use common\logic\User\UserModel;
use common\logic\User\User\UserModel;
use common\models\TaxRate; use common\models\TaxRate;
use common\logic\UserProducer\UserProducerModel;
use common\logic\User\UserProducer\UserProducerModel;
use Yii; use Yii;
use common\components\ActiveRecordCommon; use common\components\ActiveRecordCommon;
use common\helpers\Departments; use common\helpers\Departments;
public function getContact() public function getContact()
{ {
return $this->hasMany(UserModel::className(), ['id_producer' => 'id']) return $this->hasMany(UserModel::className(), ['id_producer' => 'id'])
->where(['status' => User::STATUS_PRODUCER]);
->where(['status' => UserModel::STATUS_PRODUCER]);
} }


public function getTaxRate() public function getTaxRate()


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


public function getEmailOpendistrib() public function getEmailOpendistrib()
$this->save(); $this->save();
} }


public function getOnlinePaymentMinimumAmount()
public static function getOnlinePaymentMinimumAmount()
{ {
$onlinePaymentMinimumAmount = self::getConfig('option_online_payment_minimum_amount'); $onlinePaymentMinimumAmount = self::getConfig('option_online_payment_minimum_amount');
if (!$onlinePaymentMinimumAmount) { if (!$onlinePaymentMinimumAmount) {

common/logic/Producer/ProducerRepository.php → common/logic/Producer/Producer/ProducerRepository.php View File

<?php <?php


namespace common\logic\Producer;
namespace common\logic\Producer\Producer;


use common\helpers\Departments; use common\helpers\Departments;
use common\logic\BaseService; use common\logic\BaseService;

common/logic/Producer/ProducerUtils.php → common/logic/Producer/Producer/ProducerUtils.php View File

<?php <?php


namespace common\services\Producer;
namespace common\logic\Producer\Producer;


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


class ProducerUtils extends BaseService implements UtilsInterface class ProducerUtils extends BaseService implements UtilsInterface

common/logic/ProducerPriceRange/ProducerPriceRangeContainer.php → common/logic/Producer/ProducerPriceRange/ProducerPriceRangeContainer.php View File

<?php <?php


namespace common\logic\ProducerPriceRange;
namespace common\logic\Producer\ProducerPriceRange;


use common\logic\ContainerInterface; use common\logic\ContainerInterface;



common/logic/ProducerPriceRange/ProducerPriceRangeModel.php → common/logic/Producer/ProducerPriceRange/ProducerPriceRangeModel.php View File

* termes. * termes.
*/ */


namespace common\logic\ProducerPriceRange;
namespace common\logic\Producer\ProducerPriceRange;


use common\components\ActiveRecordCommon; use common\components\ActiveRecordCommon;



common/logic/ProducerPriceRange/ProducerPriceRangeRepository.php → common/logic/Producer/ProducerPriceRange/ProducerPriceRangeRepository.php View File

<?php <?php


namespace common\logic\ProducerPriceRange;
namespace common\logic\Producer\ProducerPriceRange;


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

common/logic/CreditHistory/CreditHistoryBuilder.php → common/logic/User/CreditHistory/CreditHistoryBuilder.php View File

<?php <?php


namespace common\logic\CreditHistory;
namespace common\logic\User\CreditHistory;


use common\logic\BaseService; use common\logic\BaseService;
use common\logic\BuilderInterface; use common\logic\BuilderInterface;
use common\services\UserProducer\UserProducerBuilder;
use common\logic\User\UserProducer\UserProducerBuilder;


class CreditHistoryBuilder extends BaseService implements BuilderInterface class CreditHistoryBuilder extends BaseService implements BuilderInterface
{ {

common/logic/CreditHistory/CreditHistoryContainer.php → common/logic/User/CreditHistory/CreditHistoryContainer.php View File

<?php <?php


namespace common\logic\CreditHistory;
namespace common\logic\User\CreditHistory;


use common\logic\ContainerInterface; use common\logic\ContainerInterface;



common/logic/CreditHistory/CreditHistoryFactory.php → common/logic/User/CreditHistory/CreditHistoryFactory.php View File

<?php <?php


namespace common\logic\CreditHistory;
namespace common\logic\User\CreditHistory;


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



common/logic/CreditHistory/CreditHistoryModel.php → common/logic/User/CreditHistory/CreditHistoryModel.php View File

* termes. * termes.
*/ */


namespace common\logic\CreditHistory;
namespace common\logic\User\CreditHistory;


use common\components\ActiveRecordCommon; use common\components\ActiveRecordCommon;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;

common/logic/CreditHistory/CreditHistoryRepository.php → common/logic/User/CreditHistory/CreditHistoryRepository.php View File

<?php <?php


namespace common\logic\CreditHistory;
namespace common\logic\User\CreditHistory;


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

common/logic/CreditHistory/CreditHistorySolver.php → common/logic/User/CreditHistory/CreditHistorySolver.php View File

<?php <?php


namespace common\logic\CreditHistory;
namespace common\logic\User\CreditHistory;


use common\helpers\MeanPayment; use common\helpers\MeanPayment;
use common\logic\SolverInterface; use common\logic\SolverInterface;


$user = $creditHistory->getUserObject(); $user = $creditHistory->getUserObject();
if ($user) { if ($user) {
$str .= '<br />Client : ' . Html::encode($user->getName() . ' ' . $user->getLastname());
$str .= '<br />Client : ' . Html::encode($user->getName() . ' CreditHistorySolver.php' . $user->getLastname());
} }


$userAction = $creditHistory->getUserActionObject(); $userAction = $creditHistory->getUserActionObject();
if ($userAction) { if ($userAction) {
$str .= '<br />Action : ' . Html::encode($userAction->getName() . ' ' . $userAction->getLastname());
$str .= '<br />Action : ' . Html::encode($userAction->getName() . ' CreditHistorySolver.php' . $userAction->getLastname());
} }


return $str; return $str;
$userAction = $creditHistory->getUserActionObject(); $userAction = $creditHistory->getUserActionObject();


if ($userAction) { if ($userAction) {
return $userAction->getName() . ' ' . $userAction->getlastname();
return $userAction->getName() . ' CreditHistorySolver.php' . $userAction->getlastname();
} else { } else {
return 'Système'; return 'Système';
} }

common/logic/User/UserBuilder.php → common/logic/User/User/UserBuilder.php View File

<?php <?php


namespace common\logic\User;
namespace common\logic\User\User;


use common\logic\BaseService; use common\logic\BaseService;
use common\logic\BuilderInterface; use common\logic\BuilderInterface;

common/logic/User/UserContainer.php → common/logic/User/User/UserContainer.php View File

<?php <?php


namespace common\logic\User;
namespace common\logic\User\User;


use common\logic\ContainerInterface; use common\logic\ContainerInterface;
use common\services\User\UserFactory;
use common\services\User\UserUtils;


class UserContainer implements ContainerInterface class UserContainer implements ContainerInterface
{ {

common/logic/User/UserFactory.php → common/logic/User/User/UserFactory.php View File

<?php <?php


namespace common\logic\User;
namespace common\logic\User\User;


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

common/logic/User/UserModel.php → common/logic/User/User/UserModel.php View File

* termes. * termes.
*/ */


namespace common\logic\User;
namespace common\logic\User\User;


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\Producer\ProducerModel;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\User\UserProducer\UserProducerModel;
use common\models\Order;
use common\models\PointSale;
use common\models\UserPointSale;
use common\models\UserUserGroup;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
use yii\web\IdentityInterface; use yii\web\IdentityInterface;
use yii\db\Query; use yii\db\Query;
if (empty($token)) { if (empty($token)) {
return false; return false;
} }
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
$expire = \Yii::$app->params['user.passwordResetTokenExpire'];
$parts = explode('_', $token); $parts = explode('_', $token);
$timestamp = (int)end($parts); $timestamp = (int)end($parts);
return $timestamp + $expire >= time(); return $timestamp + $expire >= time();
*/ */
public function validatePassword($password) public function validatePassword($password)
{ {
return Yii::$app->security->validatePassword($password, $this->password_hash);
return \Yii::$app->security->validatePassword($password, $this->password_hash);
} }


/** /**
*/ */
public function setPassword($password) public function setPassword($password)
{ {
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
$this->password_hash = \Yii::$app->security->generatePasswordHash($password);
} }


/** /**
*/ */
public function generateAuthKey() public function generateAuthKey()
{ {
$this->auth_key = Yii::$app->security->generateRandomString();
$this->auth_key = \Yii::$app->security->generateRandomString();
} }


/** /**
*/ */
public function generatePasswordResetToken() public function generatePasswordResetToken()
{ {
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
$this->password_reset_token = \Yii::$app->security->generateRandomString() . '_' . time();
} }


/** /**
*/ */
public static function getCurrent() public static function getCurrent()
{ {
if (!Yii::$app->user->isGuest) {
return Yii::$app->user->identity;
if (!\Yii::$app->user->isGuest) {
return \Yii::$app->user->identity;
} }


return false; return false;
*/ */
public static function isCurrentConnected() public static function isCurrentConnected()
{ {
return !Yii::$app->user->isGuest;
return !\Yii::$app->user->isGuest;
} }


/** /**
*/ */
public function isProducer() public function isProducer()
{ {
return ($this->status == UserModel::STATUS_ADMIN || $this->status == UserModel::STATUS_PRODUCER) && $this->id_producer;
return ($this->status == UserModel::STATUS_ADMIN
|| $this->status == UserModel::STATUS_PRODUCER) && $this->id_producer;
} }


/** /**
{ {
if (strlen($this->email)) { if (strlen($this->email)) {
$producer = ProducerModel::findOne(GlobalParam::getCurrentProducerId()); $producer = ProducerModel::findOne(GlobalParam::getCurrentProducerId());
Yii::$app->mailer->compose();
$mail = Yii::$app->mailer->compose(
\Yii::$app->mailer->compose();
$mail = \Yii::$app->mailer->compose(
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $this, 'producer' => $producer, 'password' => $password] ['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $this, 'producer' => $producer, 'password' => $password]
) )
->setTo($this->email) ->setTo($this->email)
*/ */
public static function getCurrentStatus() public static function getCurrentStatus()
{ {
if (!Yii::$app->user->isGuest) {
return Yii::$app->user->identity->status;
if (!\Yii::$app->user->isGuest) {
return \Yii::$app->user->identity->status;
} }


return false; return false;

common/logic/User/UserRepository.php → common/logic/User/User/UserRepository.php View File

<?php <?php


namespace common\logic\User;
namespace common\logic\User\User;


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

common/logic/User/UserUtils.php → common/logic/User/User/UserUtils.php View File

<?php <?php


namespace common\services\User;
namespace common\logic\User\User;


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


class UserUtils extends BaseService implements UtilsInterface class UserUtils extends BaseService implements UtilsInterface

common/logic/UserProducer/UserProducerBuilder.php → common/logic/User/UserProducer/UserProducerBuilder.php View File

<?php <?php


namespace common\services\UserProducer;
namespace common\logic\User\UserProducer;


use common\helpers\MeanPayment; use common\helpers\MeanPayment;
use common\logic\BaseService; use common\logic\BaseService;

common/logic/UserProducer/UserProducerContainer.php → common/logic/User/UserProducer/UserProducerContainer.php View File

<?php <?php


namespace common\containers;
namespace common\logic\User\UserProducer;


use common\logic\ContainerInterface; use common\logic\ContainerInterface;
use common\logic\UserProducer\UserProducerModel;
use common\logic\UserProducer\UserProducerRepository;
use common\logic\User\UserProducer\UserProducerModel;
use common\logic\User\UserProducer\UserProducerRepository;


class UserProducerContainer implements ContainerInterface class UserProducerContainer implements ContainerInterface
{ {
]; ];
} }



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

common/logic/UserProducer/UserProducerModel.php → common/logic/User/UserProducer/UserProducerModel.php View File

* termes. * termes.
*/ */


namespace common\logic\UserProducer;
namespace common\logic\User\UserProducer;


use common\logic\Producer\ProducerModel;
use common\logic\User\UserModel;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\User\User\UserModel;
use Yii; use Yii;
use common\components\ActiveRecordCommon; use common\components\ActiveRecordCommon;



common/logic/UserProducer/UserProducerRepository.php → common/logic/User/UserProducer/UserProducerRepository.php View File

<?php <?php


namespace common\logic\UserProducer;
namespace common\logic\User\UserProducer;


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

+ 2
- 2
common/mail/creditUser-html.php View File



use yii\helpers\Html; use yii\helpers\Html;
use common\helpers\Price; use common\helpers\Price;
use common\models\CreditHistorique;
use common\logic\User\CreditHistory\CreditHistoryModel;


?> ?>


<p>Bonjour <?= Html::encode($user->name); ?>,</p> <p>Bonjour <?= Html::encode($user->name); ?>,</p>


<p>Votre producteur <strong><?= Html::encode($producer->name); ?></strong> vient <p>Votre producteur <strong><?= Html::encode($producer->name); ?></strong> vient
de <?php if($creditForm->type == CreditHistory::TYPE_CREDIT): ?>créditer<?php else: ?>débiter<?php endif; ?> votre compte de <strong><?= Price::format($creditForm->amount); ?></strong> sur le site <a href="http://www.opendistrib.net/">Opendistrib</a>.</p>
de <?php if($creditForm->type == CreditHistoryModel::TYPE_CREDIT): ?>créditer<?php else: ?>débiter<?php endif; ?> votre compte de <strong><?= Price::format($creditForm->amount); ?></strong> sur le site <a href="http://www.opendistrib.net/">Opendistrib</a>.</p>


<p>Votre compte est désormais à <strong><?= Price::format($userProducer->credit); ?></strong><br /> <p>Votre compte est désormais à <strong><?= Price::format($userProducer->credit); ?></strong><br />
<a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history','slug_producer' => $producer->slug]) ?>">Cliquez ici</a> pour voir l'historique de votre crédit.</p> <a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history','slug_producer' => $producer->slug]) ?>">Cliquez ici</a> pour voir l'historique de votre crédit.</p>

+ 1
- 1
common/mail/creditUser-text.php View File

?> ?>
Bonjour <?= $user->name; ?>,</p> Bonjour <?= $user->name; ?>,</p>


Votre producteur <?= $producer->name; ?> vient de <?php if($creditForm->type == CreditHistory::TYPE_CREDIT): ?>créditer<?php else: ?>débiter<?php endif; ?> votre compte de <?= Price::format($creditForm->amount); ?> sur le site http://www.laboiteapain.net/
Votre producteur <?= $producer->name; ?> vient de <?php if($creditForm->type == CreditHistoryModel::TYPE_CREDIT): ?>créditer<?php else: ?>débiter<?php endif; ?> votre compte de <?= Price::format($creditForm->amount); ?> sur le site http://www.opendistrib.net/


Votre compte est désormais à : <?= Price::format($userProducer->credit); ?>. Votre compte est désormais à : <?= Price::format($userProducer->credit); ?>.
Suivez ce lien pour voir l'historique de votre crédit : <?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history','slug_producer' => $producer->slug]) ?>"> Suivez ce lien pour voir l'historique de votre crédit : <?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history','slug_producer' => $producer->slug]) ?>">

+ 5
- 3
common/mail/orderConfirm-html.php View File

termes. termes.
*/ */


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


?> ?>


<?php endif; ?> <?php endif; ?>
<?php if(strlen($pointSale->locality) > 0): ?> situé à <?= Html::encode($pointSale->locality) ?><?php endif ?>.</p> <?php if(strlen($pointSale->locality) > 0): ?> situé à <?= Html::encode($pointSale->locality) ?><?php endif ?>.</p>


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


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

+ 4
- 3
common/mail/orderConfirm-text.php View File

termes. termes.
*/ */


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

$producer = GlobalParam::getCurrentProducer() ; $producer = GlobalParam::getCurrentProducer() ;


?> ?>


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 ?>. 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 = Producer::getConfig('option_payment_info') ; ?>
<?php $payment_infos = ProducerModel::getConfig('option_payment_info') ; ?>
<?php if($payment_infos && strlen($payment_infos) > 0): ?> <?php if($payment_infos && strlen($payment_infos) > 0): ?>
Informations de paiement : Informations de paiement :
<?= $payment_infos ?> <?= $payment_infos ?>
<?php endif; ?> <?php endif; ?>


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

+ 5
- 2
common/mail/paymentError-html.php View File

termes. termes.
*/ */


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

?> ?>


<p>Bonjour <?= Html::encode($user->name); ?>,</p> <p>Bonjour <?= Html::encode($user->name); ?>,</p>


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


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

+ 1
- 1
common/mail/signup-html.php View File

*/ */


use yii\helpers\Html; use yii\helpers\Html;
use common\models\UserModel ;
use common\helpers\Url ; use common\helpers\Url ;
use common\logic\User\User\UserModel;


?> ?>



+ 2
- 1
common/mail/signup-text.php View File

termes. termes.
*/ */


use common\models\UserModel ;
use common\helpers\Url ; use common\helpers\Url ;


use common\logic\User\User\UserModel;

?> ?>


Bonjour <?= $user->name ?>, Bonjour <?= $user->name ?>,

+ 5
- 4
common/models/CreditHistorySearch.php View File

namespace common\models ; namespace common\models ;


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\models\CreditHistory ;
use common\repositories\CreditHistoryRepository;
use common\logic\User\CreditHistory\CreditHistoryModel;
use common\logic\User\CreditHistory\CreditHistoryRepository;
use yii\data\ActiveDataProvider;


class CreditHistorySearch extends CreditHistory
class CreditHistorySearch extends CreditHistoryModel
{ {
public function rules(): array public function rules(): array
{ {
$optionsSearch = CreditHistoryRepository::defaultOptionsSearch() ; $optionsSearch = CreditHistoryRepository::defaultOptionsSearch() ;
$query = CreditHistory::find()
$query = CreditHistoryModel::find()
->with($optionsSearch['with']) ->with($optionsSearch['with'])
->innerJoinWith($optionsSearch['join_with'], true) ->innerJoinWith($optionsSearch['join_with'], true)
->where(['credit_history.id_producer' => GlobalParam::getCurrentProducerId()]) ->where(['credit_history.id_producer' => GlobalParam::getCurrentProducerId()])

+ 2
- 1
common/models/DevelopmentPriority.php View File



namespace common\models; namespace common\models;


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


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


/** /**

+ 2
- 1
common/models/Distribution.php View File



namespace common\models; namespace common\models;


use common\logic\Producer\Producer\ProducerModel;
use Yii; use Yii;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\models\Order; use common\models\Order;


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


/** /**

+ 8
- 7
common/models/Document.php View File

namespace common\models; namespace common\models;


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\Producer\Producer\ProducerModel;
use kartik\mpdf\Pdf; use kartik\mpdf\Pdf;
use Symfony\Component\Finder\Exception\DirectoryNotFoundException; use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
use yii\base\ErrorException; use yii\base\ErrorException;


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


public function relationOrders($fieldIdDocument) public function relationOrders($fieldIdDocument)
$classLower = 'delivery_note'; $classLower = 'delivery_note';
} }


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


if ($oneDocumentExist) { if ($oneDocumentExist) {


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


if (strlen($firstReference) > 0) { if (strlen($firstReference) > 0) {
return $firstReference; return $firstReference;
$contentFooter .= '</div>'; $contentFooter .= '</div>';


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


public function isDisplayOrders() public function isDisplayOrders()
{ {
$displayOrders = ($this->getClass() == 'Invoice') ? $displayOrders = ($this->getClass() == 'Invoice') ?
Producer::getConfig('document_display_orders_invoice') :
Producer::getConfig('document_display_orders_delivery_note');
ProducerModel::getConfig('document_display_orders_invoice') :
ProducerModel::getConfig('document_display_orders_delivery_note');


return $displayOrders; return $displayOrders;
} }


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


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

+ 21
- 18
common/models/Order.php View File

use common\helpers\Debug; use common\helpers\Debug;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\Price; use common\helpers\Price;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\User\CreditHistory\CreditHistoryModel;
use common\logic\User\User\UserModel;
use common\models\Producer; use common\models\Producer;
use Yii; use Yii;
use yii\helpers\Html; use yii\helpers\Html;


public function getCreditHistory() public function getCreditHistory()
{ {
return $this->hasMany(CreditHistory::className(), ['id_order' => 'id']);
return $this->hasMany(CreditHistoryModel::class, ['id_order' => 'id']);
} }


public function getSubscription() public function getSubscription()
if (isset($this->creditHistory)) { if (isset($this->creditHistory)) {
$history = $this->creditHistory; $history = $this->creditHistory;
} else { } else {
$history = CreditHistory::find()
$history = CreditHistoryModel::find()
->where(['id_order' => $this->id]) ->where(['id_order' => $this->id])
->all(); ->all();
} }


if (count($history)) { if (count($history)) {
foreach ($history as $ch) { foreach ($history as $ch) {
if ($ch->type == CreditHistory::TYPE_PAYMENT) {
if ($ch->type == CreditHistoryModel::TYPE_PAYMENT) {
$this->paid_amount += $ch->amount; $this->paid_amount += $ch->amount;
} elseif ($ch->type == CreditHistory::TYPE_REFUND) {
} elseif ($ch->type == CreditHistoryModel::TYPE_REFUND) {
$this->paid_amount -= $ch->amount; $this->paid_amount -= $ch->amount;
} }
} }
$amountPaid = $this->getAmount(Order::AMOUNT_PAID); $amountPaid = $this->getAmount(Order::AMOUNT_PAID);
if ($amountPaid > 0.01) { if ($amountPaid > 0.01) {
$this->saveCreditHistory( $this->saveCreditHistory(
CreditHistory::TYPE_REFUND,
CreditHistoryModel::TYPE_REFUND,
$amountPaid, $amountPaid,
GlobalParam::getCurrentProducerId(), GlobalParam::getCurrentProducerId(),
$this->id_user, $this->id_user,
} }


// delete // delete
if (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_DELETE ||
(Producer::getConfig(
if (ProducerModel::getConfig('option_behavior_cancel_order') == ProducerModel::BEHAVIOR_DELETE_ORDER_DELETE ||
(ProducerModel::getConfig(
'option_behavior_cancel_order' 'option_behavior_cancel_order'
) == Producer::BEHAVIOR_DELETE_ORDER_STATUS && strlen($this->date_delete)) ||
) == ProducerModel::BEHAVIOR_DELETE_ORDER_STATUS && strlen($this->date_delete)) ||
$force) { $force) {
ProductOrder::deleteAll(['id_order' => $this->id]); ProductOrder::deleteAll(['id_order' => $this->id]);
return parent::delete(); return parent::delete();
} // status 'delete' } // status 'delete'
elseif (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS) {
elseif (ProducerModel::getConfig('option_behavior_cancel_order') == ProducerModel::BEHAVIOR_DELETE_ORDER_STATUS) {
$this->date_delete = date('Y-m-d H:i:s'); $this->date_delete = date('Y-m-d H:i:s');
return $this->save(); return $this->save();
} }
if ($paymentStatus == self::PAYMENT_PAID) { if ($paymentStatus == self::PAYMENT_PAID) {
return true; return true;
} elseif ($paymentStatus == self::PAYMENT_SURPLUS) { } elseif ($paymentStatus == self::PAYMENT_SURPLUS) {
$type = CreditHistory::TYPE_REFUND;
$type = CreditHistoryModel::TYPE_REFUND;
$amount = $this->getAmount(self::AMOUNT_SURPLUS); $amount = $this->getAmount(self::AMOUNT_SURPLUS);
} elseif ($paymentStatus == self::PAYMENT_UNPAID) { } elseif ($paymentStatus == self::PAYMENT_UNPAID) {
$type = CreditHistory::TYPE_PAYMENT;
$type = CreditHistoryModel::TYPE_PAYMENT;
$amount = $this->getAmount(self::AMOUNT_REMAINING); $amount = $this->getAmount(self::AMOUNT_REMAINING);
} }


{ {
$html = ''; $html = '';


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


if ($creditActive) { if ($creditActive) {
$todayHour = date('G'); $todayHour = date('G');
$dayDistribution = strtolower(date('l', strtotime($this->distribution->date))); $dayDistribution = strtolower(date('l', strtotime($this->distribution->date)));


$orderDelay = Producer::getConfig(
$orderDelay = ProducerModel::getConfig(
'order_delay', 'order_delay',
$this->distribution->id_producer $this->distribution->id_producer
); );
$orderDelaySpecific = Producer::getConfig(
$orderDelaySpecific = ProducerModel::getConfig(
'order_delay_' . $dayDistribution, 'order_delay_' . $dayDistribution,
$this->distribution->id_producer $this->distribution->id_producer
); );
$orderDelay = $orderDelaySpecific; $orderDelay = $orderDelaySpecific;
} }


$orderDeadline = Producer::getConfig(
$orderDeadline = ProducerModel::getConfig(
'order_deadline', 'order_deadline',
$this->distribution->id_producer $this->distribution->id_producer
); );
$orderDeadlineSpecific = Producer::getConfig(
$orderDeadlineSpecific = ProducerModel::getConfig(
'order_deadline_' . $dayDistribution, 'order_deadline_' . $dayDistribution,
$this->distribution->id_producer $this->distribution->id_producer
); );
public function initReference() public function initReference()
{ {
$idProducer = GlobalParam::getCurrentProducerId(); $idProducer = GlobalParam::getCurrentProducerId();
$producer = Producer::findOne($idProducer);
$producer = ProducerModel::findOne($idProducer);


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

+ 2
- 1
common/models/PointSale.php View File

namespace common\models; namespace common\models;


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\Producer\Producer\ProducerModel;
use Yii; use Yii;
use yii\helpers\Html; use yii\helpers\Html;
use common\models\UserPointSale; use common\models\UserPointSale;
{ {
return strlen($this->credit_functioning) > 0 ? return strlen($this->credit_functioning) > 0 ?
$this->credit_functioning : $this->credit_functioning :
Producer::getConfig('credit_functioning');
ProducerModel::getConfig('credit_functioning');
} }


/** /**

+ 2
- 1
common/models/Product.php View File

use common\helpers\Debug; use common\helpers\Debug;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\Price; use common\helpers\Price;
use common\logic\Producer\Producer\ProducerModel;
use Yii; use Yii;
use common\components\ActiveRecordCommon; use common\components\ActiveRecordCommon;


public function afterFind() public function afterFind()
{ {
if ($this->taxRate == null) { if ($this->taxRate == null) {
$producer = Producer::searchOne(['id' => GlobalParam::getCurrentProducerId()]);
$producer = ProducerModel::searchOne(['id' => GlobalParam::getCurrentProducerId()]);
if ($producer) { if ($producer) {
$this->populateRelation('taxRate', $producer->taxRate); $this->populateRelation('taxRate', $producer->taxRate);
} }

+ 15
- 17
common/models/Subscription.php View File

namespace common\models; namespace common\models;


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\models\PointSale;
use common\models\UserModel;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\User\CreditHistory\CreditHistoryModel;
use common\logic\User\UserProducer\UserProducerModel;
use Yii; use Yii;
use common\components\ActiveRecordCommon; use common\components\ActiveRecordCommon;
use common\models\Producer;
use common\models\UserPointSale;
use common\models\Order;
use common\models\ProductOrder;
use common\logic\User\User\UserModel;


/** /**
* This is the model class for table "commande_auto". * This is the model class for table "commande_auto".


public function getUser() public function getUser()
{ {
return $this->hasOne(UserModel::className(), ['id' => 'id_user']);
return $this->hasOne(UserModel::class, ['id' => 'id_user']);
} }


public function getProducer() public function getProducer()
{ {
return $this->hasOne( return $this->hasOne(
Producer::className(),
ProducerModel::class,
['id' => 'id_producer'] ['id' => 'id_producer']
); );
} }
public function getPointSale() public function getPointSale()
{ {
return $this->hasOne( return $this->hasOne(
PointSale::className(),
PointSale::class,
['id' => 'id_point_sale'] ['id' => 'id_point_sale']
); );
} }
public function getProductSubscription() public function getProductSubscription()
{ {
return $this->hasMany( return $this->hasMany(
ProductSubscription::className(),
ProductSubscription::class,
['id_subscription' => 'id'] ['id_subscription' => 'id']
)->with('product'); )->with('product');
} }


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


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


if ($hour >= $orderDeadline) { if ($hour >= $orderDeadline) {
$orders->params($params); $orders->params($params);


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


$countOrdersDeleted = 0; $countOrdersDeleted = 0;
if ($ordersArray && count($ordersArray)) { if ($ordersArray && count($ordersArray)) {
// remboursement de la commande // remboursement de la commande
if ($theOrder->id_user && $theOrder->getAmount(Order::AMOUNT_PAID) && $configCredit) { if ($theOrder->id_user && $theOrder->getAmount(Order::AMOUNT_PAID) && $configCredit) {
$theOrder->saveCreditHistory( $theOrder->saveCreditHistory(
CreditHistory::TYPE_REFUND,
CreditHistoryModel::TYPE_REFUND,
$theOrder->getAmount(Order::AMOUNT_PAID), $theOrder->getAmount(Order::AMOUNT_PAID),
$theOrder->distribution->id_producer, $theOrder->distribution->id_producer,
$theOrder->id_user, $theOrder->id_user,

+ 3
- 1
frontend/controllers/SiteController.php View File



namespace frontend\controllers; namespace frontend\controllers;


use common\models\UserModel;
use common\logic\User\User\UserModel;
use frontend\forms\ProducerCodeForm; use frontend\forms\ProducerCodeForm;
use Yii; use Yii;
use frontend\forms\PasswordResetRequestForm; use frontend\forms\PasswordResetRequestForm;
*/ */
public function actionIndex() public function actionIndex()
{ {
$this->getLogic()->getProducerContainer()->getBuilder();

$producerRepository = $this->getLogic()->getProducerContainer()->getRepository(); $producerRepository = $this->getLogic()->getProducerContainer()->getRepository();


return $this->render('index', [ return $this->render('index', [

+ 14
- 15
frontend/forms/SignupForm.php View File



namespace frontend\forms; namespace frontend\forms;


use common\logic\Producer\Producer\ProducerModel;
use common\logic\User\User\UserModel;
use common\models\TaxRate;
use Yii; use Yii;
use common\models\UserModel;
use common\models\Producer;
use yii\base\Model; use yii\base\Model;
use common\models\UserProducerModel;
use common\helpers\Password;


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


if ($producer && strtolower(trim($code)) != strtolower(trim($producer->code))) { if ($producer && strtolower(trim($code)) != strtolower(trim($producer->code))) {
$this->addError($attribute, 'Code incorrect'); $this->addError($attribute, 'Code incorrect');


if ($this->validate()) { if ($this->validate()) {


$user = $userContainer->getService()->createInstance();
$user = $userContainer->getFactory()->create();
$this->populateUser($user); $this->populateUser($user);


if ($this->isProducer()) { if ($this->isProducer()) {


if ($user->save() && $producer) { if ($user->save() && $producer) {
// Liaison User / Producer // Liaison User / Producer
$producerContainer->getService()->addUser($user->id, $idProducer);
$producerContainer->getBuilder()->addUser($user->id, $idProducer);


// Envoi d'un email de bienvenue à l'utilisateur // Envoi d'un email de bienvenue à l'utilisateur
if ($this->isCustomer()) { if ($this->isCustomer()) {
$userContainer->getService()->sendEmailSignup($user, $producer);
$userContainer->getUtils()->sendEmailSignup($user, $producer);
} }


return $user; return $user;
$producerContainer = \Yii::$app->logic->getProducerContainer(); $producerContainer = \Yii::$app->logic->getProducerContainer();


// Création du producteur // Création du producteur
$producer = $producerContainer->getService()->createInstance();
$producer = $producerContainer->getFactory()->createInstance();
$this->populateProducer($producer); $this->populateProducer($producer);
$producerContainer->getService()->init($producer);
$producerContainer->getBuilder()->init($producer);
$producer->save(); $producer->save();


/* /*
* Envoi d'un email à l'administrateur pour le prévenir * Envoi d'un email à l'administrateur pour le prévenir
* qu'un nouveau producteur s'est inscrit * qu'un nouveau producteur s'est inscrit
*/ */
$producerContainer->getService()->sendEmailNewProducer($producer);
$producerContainer->getUtils()->sendEmailNewProducer($producer);


// Initialisation de l'utilisateur (statut et liaison au producteur) // Initialisation de l'utilisateur (statut et liaison au producteur)
$userContainer->getService()->initProducer($user, $producer);
$userContainer->getBuilder()->initProducer($user, $producer);


return $producer; return $producer;
} }
$user->lastname = $this->lastname; $user->lastname = $this->lastname;
$user->phone = $this->phone; $user->phone = $this->phone;


$userContainer->getService()->initPassword($user, $this->password);
$userContainer->getBuilder()->initPassword($user, $this->password);
} }


public function populateProducer($producer) public function populateProducer($producer)

+ 2
- 2
frontend/views/layouts/main.php View File

use yii\widgets\Breadcrumbs; use yii\widgets\Breadcrumbs;
use common\widgets\Alert; use common\widgets\Alert;
use common\helpers\Url; use common\helpers\Url;
use common\logic\Producer\ProducerModel;
use common\logic\User\UserModel;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\User\User\UserModel;


/* @var $this \yii\web\View */ /* @var $this \yii\web\View */
/* @var $content string */ /* @var $content string */

+ 15
- 16
producer/controllers/CreditController.php View File



namespace producer\controllers; namespace producer\controllers;


use common\helpers\GlobalParam;
use common\helpers\Mailjet; use common\helpers\Mailjet;
use common\helpers\MeanPayment; use common\helpers\MeanPayment;
use common\models\CreditHistory;
use common\logic\User\CreditHistory\CreditHistoryModel;
use common\logic\User\User\UserModel;
use common\logic\User\UserProducer\UserProducerModel;
use common\models\CreditHistorySearch;
use common\models\Distribution; use common\models\Distribution;
use common\models\Order; use common\models\Order;
use common\models\PointSale; use common\models\PointSale;
use common\models\UserProducerModel;
use producer\models\CreditForm; use producer\models\CreditForm;
use common\models\UserModel;
use Stripe\PaymentIntent;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;


class CreditController extends ProducerBaseController class CreditController extends ProducerBaseController


$searchModel = new CreditHistorySearch(); $searchModel = new CreditHistorySearch();
$searchModel->id_user = UserModel::getCurrentId(); $searchModel->id_user = UserModel::getCurrentId();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams);


$userProducer = UserProducerModel::searchOne([ $userProducer = UserProducerModel::searchOne([
'id_producer' => $producer->id, 'id_producer' => $producer->id,


if (strlen($returnPayment)) { if (strlen($returnPayment)) {
if ($returnPayment == 'success') { if ($returnPayment == 'success') {
Yii::$app->getSession()->setFlash('success', "Paiement accepté : votre compte vient d'être crédité.");
\Yii::$app->getSession()->setFlash('success', "Paiement accepté : votre compte vient d'être crédité.");
} }
if ($returnPayment == 'cancel') { if ($returnPayment == 'cancel') {
Yii::$app->getSession()->setFlash('error', 'Paiement annulé.');
\Yii::$app->getSession()->setFlash('error', 'Paiement annulé.');
} }
} }


$producer = $this->getProducer(); $producer = $this->getProducer();


if(\Yii::$app->user->isGuest) { if(\Yii::$app->user->isGuest) {
return $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
return $this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
} }


if ($producer->online_payment || $producer->option_stripe_mode_test) { if ($producer->online_payment || $producer->option_stripe_mode_test) {


$creditForm = new CreditForm; $creditForm = new CreditForm;


if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) {
if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) {
$user = UserModel::getCurrent(); $user = UserModel::getCurrent();


\Stripe\Stripe::setApiKey( \Stripe\Stripe::setApiKey(


public function actionStripeVerification() public function actionStripeVerification()
{ {
$creditHistoryService = $this->getLogic()->getCreditHistoryContainer()->getService();
$creditHistoryBuilder = $this->getLogic()->getCreditHistoryContainer()->getBuilder();
$producer = $this->getProducer(); $producer = $this->getProducer();
$contactProducer = $producer->getMainContact(); $contactProducer = $producer->getMainContact();


switch ($event->type) { switch ($event->type) {
case 'charge.succeeded': case 'charge.succeeded':


$creditHistoryExist = CreditHistory::searchOne([
$creditHistoryExist = CreditHistoryModel::searchOne([
'id_user' => $idUser, 'id_user' => $idUser,
'amount' => $amount, 'amount' => $amount,
], [ ], [
if(!$creditHistoryExist) { if(!$creditHistoryExist) {


// on crédite le crédit du client // on crédite le crédit du client
$creditHistory = new CreditHistory;
$creditHistory = new CreditHistoryModel();
$creditHistory->id_user = $idUser; $creditHistory->id_user = $idUser;
$creditHistory->id_user_action = $idUser; $creditHistory->id_user_action = $idUser;
$creditHistory->id_producer = $idProducer; $creditHistory->id_producer = $idProducer;
$creditHistory->type = CreditHistory::TYPE_CREDIT;
$creditHistory->type = CreditHistoryModel::TYPE_CREDIT;
$creditHistory->comment = null; $creditHistory->comment = null;
$creditHistory->amount = $amount; $creditHistory->amount = $amount;
$creditHistory->mean_payment = MeanPayment::CREDIT_CARD; $creditHistory->mean_payment = MeanPayment::CREDIT_CARD;


$creditHistoryService->save($creditHistory);
$creditHistoryBuilder->save($creditHistory);


if (isset($order) && $order) { if (isset($order) && $order) {
// paiement de la commande // paiement de la commande
$order->saveCreditHistory( $order->saveCreditHistory(
CreditHistory::TYPE_PAYMENT,
CreditHistoryModel::TYPE_PAYMENT,
$amount, $amount,
$idProducer, $idProducer,
$order->id_user, $order->id_user,

+ 21
- 21
producer/controllers/OrderController.php View File



namespace producer\controllers; namespace producer\controllers;


use common\helpers\Debug;
use common\helpers\GlobalParam;
use common\helpers\Mailjet; use common\helpers\Mailjet;
use common\logic\Producer\Producer\ProducerModel;
use common\logic\User\CreditHistory\CreditHistoryModel;
use common\models\ProductCategory; use common\models\ProductCategory;
use common\models\ProductDistribution; use common\models\ProductDistribution;
use common\models\UserModel;
use common\models\Producer;
use common\logic\User\User\UserModel;
use common\models\Order; use common\models\Order;
use common\models\UserPointSale; use common\models\UserPointSale;
use common\models\Product; use common\models\Product;
use common\models\UserProducerModel;
use common\logic\User\UserProducer\UserProducerModel;
use DateTime; use DateTime;
use yii\web\NotFoundHttpException;


class OrderController extends ProducerBaseController class OrderController extends ProducerBaseController
{ {
*/ */
public function _verifyProducerActive($idProducer) public function _verifyProducerActive($idProducer)
{ {
$producer = Producer::findOne($idProducer);
$producer = ProducerModel::findOne($idProducer);
if ($producer && !$producer->active) { if ($producer && !$producer->active) {
throw new NotFoundHttpException('Ce producteur est actuellement hors ligne.'); throw new NotFoundHttpException('Ce producteur est actuellement hors ligne.');
} }
$order->changeOrderStatus('new-order', 'user'); $order->changeOrderStatus('new-order', 'user');


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


// suppression de tous les enregistrements ProductOrder // suppression de tous les enregistrements ProductOrder
if (!is_null($order)) { if (!is_null($order)) {
$pointSale->linkUser($user->id); $pointSale->linkUser($user->id);


// credit // credit
$credit = Producer::getConfig('credit');
$creditLimit = Producer::getConfig('credit_limit');
$credit = ProducerModel::getConfig('credit');
$creditLimit = ProducerModel::getConfig('credit_limit');
$creditFunctioning = $pointSale->getCreditFunctioning(); $creditFunctioning = $pointSale->getCreditFunctioning();
$creditUser = $user->getCredit($distribution->id_producer); $creditUser = $user->getCredit($distribution->id_producer);
$order = Order::searchOne([ $order = Order::searchOne([
$amountRemaining = $order->getAmount(Order::AMOUNT_REMAINING); $amountRemaining = $order->getAmount(Order::AMOUNT_REMAINING);


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




if ($amountRemaining > 0) { if ($amountRemaining > 0) {
$order->saveCreditHistory( $order->saveCreditHistory(
CreditHistory::TYPE_PAYMENT,
CreditHistoryModel::TYPE_PAYMENT,
$amountRemaining, $amountRemaining,
$distribution->id_producer, $distribution->id_producer,
UserModel::getCurrentId(), UserModel::getCurrentId(),
elseif ($order->getPaymentStatus() == Order::PAYMENT_SURPLUS) { elseif ($order->getPaymentStatus() == Order::PAYMENT_SURPLUS) {
$amountSurplus = $order->getAmount(Order::AMOUNT_SURPLUS); $amountSurplus = $order->getAmount(Order::AMOUNT_SURPLUS);
$order->saveCreditHistory( $order->saveCreditHistory(
CreditHistory::TYPE_REFUND,
CreditHistoryModel::TYPE_REFUND,
$amountSurplus, $amountSurplus,
$distribution->id_producer, $distribution->id_producer,
UserModel::getCurrentId(), UserModel::getCurrentId(),
*/ */
if ($isNewOrder) { if ($isNewOrder) {
// au client // au client
if (Producer::getConfig('option_email_confirm')) {
if (ProducerModel::getConfig('option_email_confirm')) {
Mailjet::sendMail($paramsEmail); Mailjet::sendMail($paramsEmail);
} }


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


// Producteur // Producteur
$producer = Producer::searchOne([
$producer = ProducerModel::searchOne([
'id' => $this->getProducer()->id 'id' => $this->getProducer()->id
]); ]);
$json['producer'] = [ $json['producer'] = [
$distributionsArray = Distribution::filterDistributionsByDateDelay($distributionsArray); $distributionsArray = Distribution::filterDistributionsByDateDelay($distributionsArray);


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


if ($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) {
if ($pointSaleId && $producer->option_order_entry_point == ProducerModel::ORDER_ENTRY_POINT_POINT_SALE) {
$conditionsOrdersUser[] = 'order.id_point_sale = :id_point_sale'; $conditionsOrdersUser[] = 'order.id_point_sale = :id_point_sale';
$paramsOrdersUser[':id_point_sale'] = $pointSaleId; $paramsOrdersUser[':id_point_sale'] = $pointSaleId;
} }
]); ]);


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


$json['user'] = false; $json['user'] = false;
->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC') ->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC')
->all(); ->all();


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


foreach ($pointsSaleArray as &$pointSale) { foreach ($pointsSaleArray as &$pointSale) {

+ 13
- 12
producer/controllers/ProducerBaseController.php View File

namespace producer\controllers; namespace producer\controllers;


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


class ProducerBaseController extends CommonController class ProducerBaseController extends CommonController
{ {
{ {
$producer = $this->getProducer() ; $producer = $this->getProducer() ;
$userProducer = UserProducer::find()
$userProducer = UserProducerModel::find()
->where([ ->where([
'id_user' => User::getCurrentId(),
'id_user' => UserModel::getCurrentId(),
'id_producer' => $producer->id 'id_producer' => $producer->id
]) ])
->one() ; ->one() ;
// Si l'utilisateur n'est pas connecté, on le redirige vers une page qui lui permet // Si l'utilisateur n'est pas connecté, on le redirige vers une page qui lui permet
// de se connecter ou de s'inscrire en saisissant le code du producteur // de se connecter ou de s'inscrire en saisissant le code du producteur
if(Yii::$app->user->isGuest) {
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
if(\Yii::$app->user->isGuest) {
$this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
} }
// si l'utilisateur est connecté et qu'il n'a pas encore saisi de code // si l'utilisateur est connecté et qu'il n'a pas encore saisi de code
else { else {
if(!$userProducer || ($userProducer && !$userProducer->active)) { if(!$userProducer || ($userProducer && !$userProducer->active)) {
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ;
$this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ;
} }
} }
} }
/* /*
* Producteur hors ligne * Producteur hors ligne
*/ */
if(!$producer->active && (Yii::$app->user->isGuest || Yii::$app->user->identity->id_producer != $producer->id)) {
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ;
if(!$producer->active && (\Yii::$app->user->isGuest || \Yii::$app->user->identity->id_producer != $producer->id)) {
$this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ;
} }
return parent::beforeAction($event); return parent::beforeAction($event);
/** /**
* Retourne le producteur courant. * Retourne le producteur courant.
*
* @return Etablissement
* @throws \yii\web\HttpException
*
*/ */
public function getProducer() public function getProducer()
{ {
return $this->producer ; return $this->producer ;
} }
else { else {
$producer = Producer::find()
$producer = ProducerModel::find()
->with('contact') ->with('contact')
->where(['slug' => Yii::$app->getRequest()->getQueryParam('slug_producer')])
->where(['slug' => \Yii::$app->getRequest()->getQueryParam('slug_producer')])
->one() ; ->one() ;
if($producer) { if($producer) {

+ 5
- 3
producer/controllers/SiteController.php View File



use common\forms\ContactForm; use common\forms\ContactForm;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\User\User\UserModel;
use common\logic\User\UserProducer\UserProducerModel;
use common\models\ProductCategory; use common\models\ProductCategory;


class SiteController extends ProducerBaseController class SiteController extends ProducerBaseController
public function actionBookmarks($action) public function actionBookmarks($action)
{ {
$producer = $this->getProducer(); $producer = $this->getProducer();
$userProducer = UserProducer::find()
$userProducer = UserProducerModel::find()
->where([ ->where([
'id_user' => User::getCurrentId(),
'id_user' => UserModel::getCurrentId(),
'id_producer' => $producer->id 'id_producer' => $producer->id
]) ])
->one(); ->one();


if (!$userProducer) { if (!$userProducer) {
$userProducer = Producer::addUser(User::getCurrentId(), $producer->id);
$userProducer = $this->getLogic()->getProducerContainer()->getBuilder()->addUser(UserModel::getCurrentId(), $producer->id);
} }


if ($userProducer) { if ($userProducer) {

+ 9
- 6
producer/controllers/SubscriptionController.php View File



use common\helpers\Debug; use common\helpers\Debug;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\User\User\UserModel;
use common\logic\User\UserProducer\UserProducerModel;
use common\models\SubscriptionForm; use common\models\SubscriptionForm;
use common\models\SubscriptionSearch; use common\models\SubscriptionSearch;
use common\models\Product; use common\models\Product;
use yii\base\UserException;


class SubscriptionController extends ProducerBaseController class SubscriptionController extends ProducerBaseController
{ {
} }


$searchModel = new SubscriptionSearch; $searchModel = new SubscriptionSearch;
$searchModel->id_user = User::getCurrentId();
$searchModel->id_user = UserModel::getCurrentId();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);


return $this->render('index', [ return $this->render('index', [
// form // form
$model = new SubscriptionForm; $model = new SubscriptionForm;
$model->id_producer = GlobalParam::getCurrentProducerId(); $model->id_producer = GlobalParam::getCurrentProducerId();
$model->id_user = User::getCurrentId();
$model->id_user = UserModel::getCurrentId();


$posts = Yii::$app->request->post(); $posts = Yii::$app->request->post();


\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$params = []; $params = [];


$user = User::getCurrent();
$userProducer = UserProducer::searchOne([
'id_user' => User::getCurrentId()
$user = UserModel::getCurrent();
$userProducer = UserProducerModel::searchOne([
'id_user' => UserModel::getCurrentId()
]); ]);
$pointSale = false; $pointSale = false;


'id' => $idSubscription 'id' => $idSubscription
]); ]);


if (!$subscription || $subscription->id_user != User::getCurrentId()) {
if (!$subscription || $subscription->id_user != UserModel::getCurrentId()) {
throw new UserException('Abonnement introuvable'); throw new UserException('Abonnement introuvable');
} else { } else {
$params = array_merge($params, $subscription->getAttributes()); $params = array_merge($params, $subscription->getAttributes());

+ 2
- 1
producer/models/CreditForm.php View File



namespace producer\models; namespace producer\models;


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


{ {
return [ return [
[['amount'], 'required'], [['amount'], 'required'],
[['amount'], 'double', 'min' => Producer::getOnlinePaymentMinimumAmount()],
[['amount'], 'double', 'min' => ProducerModel::getOnlinePaymentMinimumAmount()],
]; ];
} }



+ 26203
- 0
producer/runtime/logs/app.log
File diff suppressed because it is too large
View File


+ 2
- 1
producer/views/credit/add.php View File



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


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


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

+ 15
- 15
producer/views/credit/history.php View File

use yii\grid\GridView; use yii\grid\GridView;
use ruskid\stripe\StripeCheckoutCustom; use ruskid\stripe\StripeCheckoutCustom;


$creditHistoryService = \Yii::$app->logic->getCreditHistoryContainer()->getService();
$creditHistorySolver = \Yii::$app->logic->getCreditHistoryContainer()->getSolver();
$producer = $this->context->getProducer(); $producer = $this->context->getProducer();
$this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>'); $this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>');
$this->setPageTitle('Crédit'); $this->setPageTitle('Crédit');
'columns' => [ 'columns' => [
[ [
'attribute' => 'date', 'attribute' => 'date',
'value' => function ($model) use ($creditHistoryService) {
return $creditHistoryService->getDate($model, true);
'value' => function ($model) use ($creditHistorySolver) {
return $creditHistorySolver->getDate($model, true);
} }
], ],
[ [
'attribute' => 'id_user_action', 'attribute' => 'id_user_action',
'value' => function ($model) use ($creditHistoryService) {
return $creditHistoryService->getStrUserAction($model);
'value' => function ($model) use ($creditHistorySolver) {
return $creditHistorySolver->getStrUserAction($model);
} }
], ],
[ [
'label' => 'Type', 'label' => 'Type',
'format' => 'raw', 'format' => 'raw',
'value' => function ($model) use ($creditHistoryService) {
return $creditHistoryService->getStrWording($model);
'value' => function ($model) use ($creditHistorySolver) {
return $creditHistorySolver->getStrWording($model);
} }
], ],
[ [
'attribute' => 'mean_payment', 'attribute' => 'mean_payment',
'value' => function ($model) use ($creditHistoryService) {
return $creditHistoryService->getStrMeanPayment($model);
'value' => function ($model) use ($creditHistorySolver) {
return $creditHistorySolver->getStrMeanPayment($model);
} }
], ],
[ [
'label' => '- Débit', 'label' => '- Débit',
'format' => 'raw', 'format' => 'raw',
'value' => function ($model) use ($creditHistoryService) {
if ($creditHistoryService->isTypeDebit($model)) {
return '-&nbsp;' . $creditHistoryService->getAmount($model, true);
'value' => function ($model) use ($creditHistorySolver) {
if ($creditHistorySolver->isTypeDebit($model)) {
return '-&nbsp;' . $creditHistorySolver->getAmount($model, true);
} }
return ''; return '';
} }
[ [
'label' => '+ Crédit', 'label' => '+ Crédit',
'format' => 'raw', 'format' => 'raw',
'value' => function ($model) use ($creditHistoryService) {
if ($creditHistoryService->isTypeCredit($model)) {
return '+&nbsp;' . $creditHistoryService->getAmount($model, true);
'value' => function ($model) use ($creditHistorySolver) {
if ($creditHistorySolver->isTypeCredit($model)) {
return '+&nbsp;' . $creditHistorySolver->getAmount($model, true);
} }
return ''; return '';
} }

+ 3
- 3
producer/views/layouts/main.php View File

use yii\widgets\Breadcrumbs; use yii\widgets\Breadcrumbs;
use common\widgets\Alert; use common\widgets\Alert;
use common\helpers\Url; use common\helpers\Url;
use common\models\Producer;
use common\models\UserModel;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\User\UserProducer\UserProducerModel;
use common\logic\User\User\UserModel;


\common\assets\CommonAsset::register($this); \common\assets\CommonAsset::register($this);
\producer\assets\AppAsset::register($this); \producer\assets\AppAsset::register($this);


$producer = $this->context->getProducer(); $producer = $this->context->getProducer();
if (!Yii::$app->user->isGuest) { if (!Yii::$app->user->isGuest) {
$userProducer = UserProducer::findOne(['id_user' => UserModel::getCurrentId(), 'id_producer' => $producer->id]);
$userProducer = UserProducerModel::findOne(['id_user' => UserModel::getCurrentId(), 'id_producer' => $producer->id]);
} }


?> ?>

+ 3
- 3
producer/views/order/_form.php View File

*/ */


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


?> ?>
<div class="order-form"> <div class="order-form">
{ {
foreach($pointSale->userPointSale as $userPointSale) foreach($pointSale->userPointSale as $userPointSale)
{ {
if($userPointSale->id_user == User::getCurrentId() && strlen($userPointSale->comment))
if($userPointSale->id_user == UserModel::getCurrentId() && strlen($userPointSale->comment))
{ {
$comment = '<div class="comment"><span>'.Html::encode($userPointSale->comment).'</span></div>' ; $comment = '<div class="comment"><span>'.Html::encode($userPointSale->comment).'</span></div>' ;
} }


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

+ 5
- 5
producer/views/order/order.php View File

*/ */


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


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


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


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

+ 3
- 3
producer/views/site/index.php View File

use common\helpers\GlobalParam ; use common\helpers\GlobalParam ;
use common\models\Distribution; use common\models\Distribution;
use common\models\PointSaleDistribution; use common\models\PointSaleDistribution;
use common\models\Producer ;
use common\logic\Producer\Producer\ProducerModel;


$producer = $this->context->getProducer() ; $producer = $this->context->getProducer() ;
$this->setTitle('Accueil'); $this->setTitle('Accueil');


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


if($producer->behavior_home_point_sale_day_list == Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK) {
if($producer->behavior_home_point_sale_day_list == ProducerModel::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK) {
$arrayDays = [ $arrayDays = [
'monday' => 'Lundi', 'monday' => 'Lundi',
'tuesday' => 'Mardi', 'tuesday' => 'Mardi',


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

+ 2
- 6
producer/views/subscription/_form.php View File

termes. termes.
*/ */


use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper ;
use common\models\UserModel ;
use common\models\PointSale ;
use common\logic\Producer\Producer\ProducerModel;


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


<h3><span>Paiement</span></h3> <h3><span>Paiement</span></h3>


<?php if(Producer::getConfig('credit')): ?>
<?php if(ProducerModel::getConfig('credit')): ?>
<div class="form-group field-subscriptionform-auto_payment"> <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> <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> <div class="hint-block">Cochez cette case si vous souhaitez que votre Crédit soit automatiquement débité.</div>

+ 2
- 1
producer/views/subscription/index.php View File

use yii\grid\GridView; use yii\grid\GridView;
use common\models\Product ; use common\models\Product ;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\Producer\Producer\ProducerModel;


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

Loading…
Cancel
Save