use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\BuilderInterface; | use common\logic\BuilderInterface; | ||||
use common\services\CreditHistory\CreditHistorySolver; | |||||
class CreditHistoryBuilder extends BaseService implements BuilderInterface | class CreditHistoryBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
$this->creditHistorySolver = $this->loadService(CreditHistorySolver::class); | $this->creditHistorySolver = $this->loadService(CreditHistorySolver::class); | ||||
} | } | ||||
public function save(CreditHistory $creditHistory): bool | public function save(CreditHistoryModel $creditHistory): bool | ||||
{ | { | ||||
if ($creditHistory->getAmount() > -0.01 && $creditHistory->getAmount() < 0.01) { | if ($creditHistory->getAmount() > -0.01 && $creditHistory->getAmount() < 0.01) { | ||||
return false; | return false; |
namespace common\logic\CreditHistory; | namespace common\logic\CreditHistory; | ||||
use common\logic\ContainerInterface; | use common\logic\ContainerInterface; | ||||
use common\logic\CreditHistory\CreditHistoryBuilder; | |||||
use common\logic\CreditHistory\CreditHistoryFactory; | |||||
use common\logic\CreditHistory\CreditHistoryRepository; | |||||
use common\logic\CreditHistory\CreditHistorySolver; | |||||
class CreditHistoryContainer implements ContainerInterface | class CreditHistoryContainer implements ContainerInterface | ||||
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return CreditHistory::class; | return CreditHistoryModel::class; | ||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
{ | { | ||||
public function create() | public function create() | ||||
{ | { | ||||
$creditHistory = new CreditHistory(); | $creditHistory = new CreditHistoryModel(); | ||||
return $creditHistory; | return $creditHistory; | ||||
} | } |
return [ | return [ | ||||
'with' => [], | 'with' => [], | ||||
'join_with' => [], | 'join_with' => [], | ||||
'orderby' => CreditHistory::tableName() . '.date ASc', | 'orderby' => CreditHistoryModel::tableName() . '.date ASc', | ||||
'attribute_id_producer' => CreditHistory::tableName() . '.id_producer' | 'attribute_id_producer' => CreditHistoryModel::tableName() . '.id_producer' | ||||
]; | ]; | ||||
} | } | ||||
} | } |
public function isTypeDebit(CreditHistoryModel $creditHistory): bool | public function isTypeDebit(CreditHistoryModel $creditHistory): bool | ||||
{ | { | ||||
return in_array($creditHistory->type, [ | return in_array($creditHistory->type, [ | ||||
CreditHistory::TYPE_DEBIT, | CreditHistoryModel::TYPE_DEBIT, | ||||
CreditHistory::TYPE_PAYMENT, | CreditHistoryModel::TYPE_PAYMENT, | ||||
]); | ]); | ||||
} | } | ||||
<?php | <?php | ||||
namespace common\services\Producer; | namespace common\logic\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\ServiceInterface; | |||||
use common\models\Producer; | |||||
use common\logic\UserProducer\UserProducerModel; | use common\logic\UserProducer\UserProducerModel; | ||||
use common\repositories\ProducerRepository; | |||||
class ProducerBuilder extends BaseService implements BuilderInterface | class ProducerBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
$this->producerRepository = $this->loadService(ProducerRepository::class); | $this->producerRepository = $this->loadService(ProducerRepository::class); | ||||
} | } | ||||
public function init(Producer $producer): void | public function init(ProducerModel $producer): void | ||||
{ | { | ||||
$this->initSlug($producer); | $this->initSlug($producer); | ||||
$this->initCode($producer); | $this->initCode($producer); | ||||
} | } | ||||
public function initSlug(Producer $producer): void | public function initSlug(ProducerModel $producer): void | ||||
{ | { | ||||
$cptSlug = 0 ; | $cptSlug = 0 ; | ||||
do { | do { | ||||
} while($this->producerRepository->getOneBySlug($producer->slug)) ; | } while($this->producerRepository->getOneBySlug($producer->slug)) ; | ||||
} | } | ||||
public function initCode(Producer $producer): void | public function initCode(ProducerModel $producer): void | ||||
{ | { | ||||
$producer->code = Password::generate(); | $producer->code = Password::generate(); | ||||
} | } |
namespace common\logic\Producer; | namespace common\logic\Producer; | ||||
use common\logic\ContainerInterface; | use common\logic\ContainerInterface; | ||||
use common\services\Producer\ProducerBuilder; | |||||
use common\services\Producer\ProducerFactory; | |||||
use common\services\Producer\ProducerUtils; | use common\services\Producer\ProducerUtils; | ||||
class ProducerContainer implements ContainerInterface | class ProducerContainer implements ContainerInterface |
<?php | <?php | ||||
namespace common\services\Producer; | namespace common\logic\Producer; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\models\Producer; | |||||
use common\logic\FactoryInterface; | use common\logic\FactoryInterface; | ||||
class ProducerFactory extends BaseService implements FactoryInterface | class ProducerFactory extends BaseService implements FactoryInterface | ||||
{ | { | ||||
public function create() | public function create() | ||||
{ | { | ||||
$producer = new Producer; | $producer = new ProducerModel(); | ||||
$producer->order_deadline = 20; | $producer->order_deadline = 20; | ||||
$producer->order_delay = 1; | $producer->order_delay = 1; |
namespace common\services\Producer; | namespace common\services\Producer; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Producer\ProducerModel; | |||||
use common\logic\UtilsInterface; | use common\logic\UtilsInterface; | ||||
use common\models\Producer; | |||||
class ProducerUtils extends BaseService implements UtilsInterface | class ProducerUtils extends BaseService implements UtilsInterface | ||||
{ | { | ||||
public function sendEmailNewProducer(Producer $producer) | public function sendEmailNewProducer(ProducerModel $producer) | ||||
{ | { | ||||
\Yii::$app->mailer->compose( | \Yii::$app->mailer->compose( | ||||
[ | [ |
namespace common\logic\ProducerPriceRange; | namespace common\logic\ProducerPriceRange; | ||||
use common\logic\ContainerInterface; | use common\logic\ContainerInterface; | ||||
use common\models\ProducerPriceRange; | |||||
class ProducerPriceRangeContainer implements ContainerInterface | class ProducerPriceRangeContainer implements ContainerInterface | ||||
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return ProducerPriceRange::class; | return ProducerPriceRangeModel::class; | ||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
use common\models\ProducerPriceRange; | |||||
class ProducerPriceRangeRepository extends BaseService implements RepositoryInterface | class ProducerPriceRangeRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
public function query() | public function query() | ||||
{ | { | ||||
return ProducerPriceRange::find()->orderBy('range_begin ASC'); | return ProducerPriceRangeModel::find()->orderBy('range_begin ASC'); | ||||
} | } | ||||
} | } |
<?php | <?php | ||||
namespace common\services\User; | namespace common\logic\User; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\BuilderInterface; | use common\logic\BuilderInterface; | ||||
use common\models\UserModel; | |||||
class UserBuilder extends BaseService implements BuilderInterface | class UserBuilder extends BaseService implements BuilderInterface | ||||
{ | { |
namespace common\logic\User; | namespace common\logic\User; | ||||
use common\logic\ContainerInterface; | use common\logic\ContainerInterface; | ||||
use common\logic\User\UserModel; | |||||
use common\services\User\UserBuilder; | |||||
use common\services\User\UserFactory; | use common\services\User\UserFactory; | ||||
use common\services\User\UserUtils; | use common\services\User\UserUtils; | ||||
<?php | <?php | ||||
namespace common\services\User; | namespace common\logic\User; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\FactoryInterface; | use common\logic\FactoryInterface; | ||||
use common\models\UserModel; | |||||
class UserFactory extends BaseService implements FactoryInterface | class UserFactory extends BaseService implements FactoryInterface | ||||
{ | { |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Producer\ProducerModel; | use common\logic\Producer\ProducerModel; | ||||
use common\logic\User\UserModel; | |||||
use common\logic\UtilsInterface; | use common\logic\UtilsInterface; | ||||
use common\models\UserModel; | |||||
class UserUtils extends BaseService implements UtilsInterface | class UserUtils extends BaseService implements UtilsInterface | ||||
{ | { |
use common\logic\CreditHistory\CreditHistoryModel; | use common\logic\CreditHistory\CreditHistoryModel; | ||||
use common\logic\CreditHistory\CreditHistorySolver; | use common\logic\CreditHistory\CreditHistorySolver; | ||||
use common\logic\Producer\ProducerModel; | use common\logic\Producer\ProducerModel; | ||||
use common\logic\UserProducer\UserProducerRepository; | |||||
use common\models\Order; | use common\models\Order; | ||||
use common\logic\UserProducer\UserProducerModel; | use common\logic\UserProducer\UserProducerModel; | ||||
use common\repositories\UserProducerRepository; | |||||
class UserProducerBuilder extends BaseService implements BuilderInterface | class UserProducerBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
public function sendCreditLimitReminder($userProducer, $creditHistory, $oldCredit) | public function sendCreditLimitReminder($userProducer, $creditHistory, $oldCredit) | ||||
{ | { | ||||
$userRepository = Yii::$app->logic->getUserContainer()->getRepository(); | $userRepository = \Yii::$app->logic->getUserContainer()->getRepository(); | ||||
$producerRepository = Yii::$app->logic->getProducerContainer()->getRepository(); | $producerRepository = \Yii::$app->logic->getProducerContainer()->getRepository(); | ||||
$newCredit = $userProducer->credit; | $newCredit = $userProducer->credit; | ||||
if ($this->isCreditLimitCrossed($oldCredit, $newCredit)) { | if ($this->isCreditLimitCrossed($oldCredit, $newCredit)) { | ||||
$user = $userRepository->getOneById($creditHistory->id_user); | $user = $userRepository->getOneById($creditHistory->id_user); | ||||
$producer = $producerRepository->getOneById($creditHistory->id_producer); | $producer = $producerRepository->getOneById($creditHistory->id_producer); | ||||
Yii::$app->mailer->compose( | \Yii::$app->mailer->compose( | ||||
[ | [ | ||||
'html' => 'creditLimitReminder-html', | 'html' => 'creditLimitReminder-html', | ||||
'text' => 'creditLimitReminder-text' | 'text' => 'creditLimitReminder-text' |
use common\logic\ContainerInterface; | use common\logic\ContainerInterface; | ||||
use common\logic\UserProducer\UserProducerModel; | use common\logic\UserProducer\UserProducerModel; | ||||
use common\repositories\UserProducerRepository; | use common\logic\UserProducer\UserProducerRepository; | ||||
class UserProducerContainer implements ContainerInterface | class UserProducerContainer implements ContainerInterface | ||||
{ | { | ||||
} | } | ||||
public function getRepository() | public function getRepository(): UserProducerRepository | ||||
{ | { | ||||
return new UserProducerRepository(); | return new UserProducerRepository(); | ||||
} | } |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
use common\logic\UserProducer\UserProducerModel; | |||||
class UserProducerRepository extends BaseService implements RepositoryInterface | class UserProducerRepository extends BaseService implements RepositoryInterface | ||||
{ | { |
<?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\models; | |||||
use common\components\ActiveRecordCommon; | |||||
/** | |||||
* This is the model class for table "producer_price_range". | |||||
* | |||||
* @property integer $id | |||||
*/ | |||||
class ProducerPriceRange extends ActiveRecordCommon | |||||
{ | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public static function tableName() | |||||
{ | |||||
return 'producer_price_range'; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['range_begin', 'range_end', 'price'], 'double'], | |||||
]; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
'range_begin' => 'Début', | |||||
'range_end' => 'Fin', | |||||
'price' => 'Tarif (HT)', | |||||
]; | |||||
} | |||||
/** | |||||
* Retourne les options de base nécessaires à la fonction de recherche. | |||||
* | |||||
* @return array | |||||
*/ | |||||
public static function defaultOptionsSearch() | |||||
{ | |||||
return [ | |||||
'with' => [], | |||||
'join_with' => [], | |||||
'orderby' => '', | |||||
'attribute_id_producer' => '' | |||||
]; | |||||
} | |||||
} |