<?php | <?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. | |||||
*/ | |||||
/** | |||||
* 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 backend\controllers; | namespace backend\controllers; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use backend\models\AccessUserProducerForm ; | |||||
use backend\models\AccessUserProducerForm; | |||||
use common\logic\Document\DeliveryNote\DeliveryNoteManager; | |||||
use common\logic\Producer\Producer\ProducerManager; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
*/ | */ | ||||
class AccessController extends BackendController | |||||
class AccessController extends BackendController | |||||
{ | { | ||||
public function behaviors() { | |||||
public function behaviors() | |||||
{ | |||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | 'class' => VerbFilter::className(), | ||||
/** | /** | ||||
* Affiche les utilisateurs ayant accès à l'administration de ce producteur. | * Affiche les utilisateurs ayant accès à l'administration de ce producteur. | ||||
* Gestion du formulaire permettant d'en ajouter de nouveaux. | * Gestion du formulaire permettant d'en ajouter de nouveaux. | ||||
* | |||||
* | |||||
* @return string | * @return string | ||||
*/ | */ | ||||
public function actionIndex() | |||||
public function actionIndex() | |||||
{ | { | ||||
$userSearch = new UserSearch ; | |||||
$usersArray = $userSearch->search()->query->all() ; | |||||
$modelAccessUserProducerForm = new AccessUserProducerForm ; | |||||
if($modelAccessUserProducerForm->load(Yii::$app->request->post()) && $modelAccessUserProducerForm->save()) { | |||||
$userSearch = new UserSearch; | |||||
$usersArray = $userSearch->search()->query->all(); | |||||
$modelAccessUserProducerForm = new AccessUserProducerForm; | |||||
if ($modelAccessUserProducerForm->load(Yii::$app->request->post()) && $modelAccessUserProducerForm->save()) { | |||||
Yii::$app->getSession()->setFlash('success', 'Droits ajoutés à l\'utilisateur'); | Yii::$app->getSession()->setFlash('success', 'Droits ajoutés à l\'utilisateur'); | ||||
} | } | ||||
$usersAccessArray = User::find() | |||||
$usersAccessArray = User::find() | |||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'status' => User::STATUS_PRODUCER | |||||
'status' => User::STATUS_PRODUCER | |||||
]) | ]) | ||||
->all() ; | |||||
$producer = Producer::searchOne() ; | |||||
->all(); | |||||
$producer = Producer::searchOne(); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'usersArray' => $usersArray, | 'usersArray' => $usersArray, | ||||
]); | ]); | ||||
} | } | ||||
public function actionDelete($idUser) | |||||
public function actionDelete($idUser) | |||||
{ | { | ||||
$user = User::searchOne([ | |||||
$user = User::searchOne([ | |||||
'id' => $idUser | 'id' => $idUser | ||||
]) ; | |||||
if($user) { | |||||
$user->id_producer = 0 ; | |||||
$user->status = User::STATUS_ACTIVE ; | |||||
$user->save() ; | |||||
]); | |||||
if ($user) { | |||||
$user->id_producer = 0; | |||||
$user->status = User::STATUS_ACTIVE; | |||||
$user->save(); | |||||
Yii::$app->getSession()->setFlash('success', 'Droits de l\'utilisateur supprimé.'); | Yii::$app->getSession()->setFlash('success', 'Droits de l\'utilisateur supprimé.'); | ||||
} | } | ||||
return $this->redirect(['index']) ; | |||||
return $this->redirect(['index']); | |||||
} | } | ||||
} | } |
use common\logic\Distribution\Distribution\DistributionContainer; | use common\logic\Distribution\Distribution\DistributionContainer; | ||||
use common\logic\Distribution\Distribution\DistributionManager; | use common\logic\Distribution\Distribution\DistributionManager; | ||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContainer; | use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContainer; | ||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionManager; | |||||
use common\logic\Distribution\ProductDistribution\ProductDistributionContainer; | use common\logic\Distribution\ProductDistribution\ProductDistributionContainer; | ||||
use common\logic\Distribution\ProductDistribution\ProductDistributionManager; | |||||
use common\logic\Document\DeliveryNote\DeliveryNoteManager; | |||||
use common\logic\Document\Document\DocumentContainer; | use common\logic\Document\Document\DocumentContainer; | ||||
use common\logic\Document\Document\DocumentManager; | |||||
use common\logic\Document\Invoice\InvoiceManager; | |||||
use common\logic\Document\Invoice\QuotationManager; | |||||
use common\logic\Order\Order\OrderContainer; | use common\logic\Order\Order\OrderContainer; | ||||
use common\logic\Order\Order\OrderManager; | use common\logic\Order\Order\OrderManager; | ||||
use common\logic\Order\OrderStatusHistory\OrderStatusHistoryContainer; | use common\logic\Order\OrderStatusHistory\OrderStatusHistoryContainer; | ||||
use common\logic\Order\OrderStatusHistory\OrderStatusHistoryManager; | |||||
use common\logic\Order\ProductOrder\ProductOrderContainer; | use common\logic\Order\ProductOrder\ProductOrderContainer; | ||||
use common\logic\Order\ProductOrder\ProductOrderManager; | |||||
use common\logic\PointSale\PointSale\PointSaleContainer; | use common\logic\PointSale\PointSale\PointSaleContainer; | ||||
use common\logic\PointSale\PointSale\PointSaleManager; | |||||
use common\logic\PointSale\UserPointSale\UserPointSaleContainer; | use common\logic\PointSale\UserPointSale\UserPointSaleContainer; | ||||
use common\logic\PointSale\UserPointSale\UserPointSaleManager; | |||||
use common\logic\Producer\Producer\ProducerContainer; | use common\logic\Producer\Producer\ProducerContainer; | ||||
use common\logic\Producer\Producer\ProducerManager; | |||||
use common\logic\Producer\ProducerPriceRange\ProducerPriceRangeContainer; | use common\logic\Producer\ProducerPriceRange\ProducerPriceRangeContainer; | ||||
use common\logic\Producer\ProducerPriceRange\ProducerPriceRangeManager; | |||||
use common\logic\Product\Product\ProductContainer; | use common\logic\Product\Product\ProductContainer; | ||||
use common\logic\Product\Product\ProductManager; | |||||
use common\logic\Product\ProductCategory\ProductCategoryContainer; | use common\logic\Product\ProductCategory\ProductCategoryContainer; | ||||
use common\logic\Product\ProductCategory\ProductCategoryManager; | |||||
use common\logic\Product\ProductPointSale\ProductPointSaleContainer; | use common\logic\Product\ProductPointSale\ProductPointSaleContainer; | ||||
use common\logic\Product\ProductPointSale\ProductPointSaleManager; | |||||
use common\logic\Product\ProductPrice\ProductPriceContainer; | use common\logic\Product\ProductPrice\ProductPriceContainer; | ||||
use common\logic\Product\ProductPrice\ProductPriceManager; | |||||
use common\logic\Subscription\ProductSubscription\ProductSubscriptionContainer; | use common\logic\Subscription\ProductSubscription\ProductSubscriptionContainer; | ||||
use common\logic\Subscription\ProductSubscription\ProductSubscriptionManager; | |||||
use common\logic\Subscription\Subscription\SubscriptionContainer; | use common\logic\Subscription\Subscription\SubscriptionContainer; | ||||
use common\logic\Subscription\Subscription\SubscriptionManager; | |||||
use common\logic\User\CreditHistory\CreditHistoryContainer; | use common\logic\User\CreditHistory\CreditHistoryContainer; | ||||
use common\logic\User\CreditHistory\CreditHistoryManager; | |||||
use common\logic\User\User\UserContainer; | use common\logic\User\User\UserContainer; | ||||
use common\logic\User\User\UserManager; | |||||
use common\logic\User\UserGroup\UserGroupContainer; | use common\logic\User\UserGroup\UserGroupContainer; | ||||
use common\logic\User\UserGroup\UserGroupManager; | |||||
use common\logic\User\UserProducer\UserProducerContainer; | use common\logic\User\UserProducer\UserProducerContainer; | ||||
use common\logic\User\UserUserGroup\UserUserGroupContainer; | use common\logic\User\UserUserGroup\UserUserGroupContainer; | ||||
use common\logic\User\UserUserGroup\UserUserGroupManager; | |||||
trait BusinessLogicContainerTrait | trait BusinessLogicContainerTrait | ||||
{ | { | ||||
return new DistributionManager(); | return new DistributionManager(); | ||||
} | } | ||||
public function getPointSaleDistributionManager(): PointSaleDistributionManager | |||||
{ | |||||
return new PointSaleDistributionManager(); | |||||
} | |||||
public function getProductDistributionManager(): ProductDistributionManager | |||||
{ | |||||
return new ProductDistributionManager(); | |||||
} | |||||
public function getDeliveryNoteManager(): DeliveryNoteManager | |||||
{ | |||||
return new DeliveryNoteManager(); | |||||
} | |||||
public function getDocumentManager(): DocumentManager | |||||
{ | |||||
return new DocumentManager(); | |||||
} | |||||
public function getInvoiceManager(): InvoiceManager | |||||
{ | |||||
return new InvoiceManager(); | |||||
} | |||||
public function getQuotationManager(): QuotationManager | |||||
{ | |||||
return new QuotationManager(); | |||||
} | |||||
public function getOrderStatusHistoryManager(): OrderStatusHistoryManager | |||||
{ | |||||
return new OrderStatusHistoryManager(); | |||||
} | |||||
public function getProductOrderManager(): ProductOrderManager | |||||
{ | |||||
return new ProductOrderManager(); | |||||
} | |||||
public function getPointSaleManager(): PointSaleManager | |||||
{ | |||||
return new PointSaleManager(); | |||||
} | |||||
public function getUserPointSaleManager(): UserPointSaleManager | |||||
{ | |||||
return new UserPointSaleManager(); | |||||
} | |||||
public function getProducerManager(): ProducerManager | |||||
{ | |||||
return new ProducerManager(); | |||||
} | |||||
public function getProducerPriceRangeManager(): ProducerPriceRangeManager | |||||
{ | |||||
return new ProducerPriceRangeManager(); | |||||
} | |||||
public function getProductManager(): ProductManager | |||||
{ | |||||
return new ProductManager(); | |||||
} | |||||
public function getProductCategoryManager(): ProductCategoryManager | |||||
{ | |||||
return new ProductCategoryManager(); | |||||
} | |||||
public function getProductPointSaleManager(): ProductPointSaleManager | |||||
{ | |||||
return new ProductPointSaleManager(); | |||||
} | |||||
public function getProductPriceManager(): ProductPriceManager | |||||
{ | |||||
return new ProductPriceManager(); | |||||
} | |||||
public function getProductSubscriptionManager(): ProductSubscriptionManager | |||||
{ | |||||
return new ProductSubscriptionManager(); | |||||
} | |||||
public function getSubscriptionManager(): SubscriptionManager | |||||
{ | |||||
return new SubscriptionManager(); | |||||
} | |||||
public function getCreditHistoryManager(): CreditHistoryManager | |||||
{ | |||||
return new CreditHistoryManager(); | |||||
} | |||||
public function getUserManager(): UserManager | |||||
{ | |||||
return new UserManager(); | |||||
} | |||||
public function getUserGroupManager(): UserGroupManager | |||||
{ | |||||
return new UserGroupManager(); | |||||
} | |||||
public function getUserUserGroupManager(): UserUserGroupManager | |||||
{ | |||||
return new UserUserGroupManager(); | |||||
} | |||||
public function getUserContainer(): UserContainer | public function getUserContainer(): UserContainer | ||||
{ | { | ||||
return new UserContainer(); | return new UserContainer(); |
class BaseService | class BaseService | ||||
{ | { | ||||
public function getHierarchy(): array | |||||
protected function getHierarchy(): array | |||||
{ | { | ||||
return [ | return [ | ||||
SolverInterface::class, | SolverInterface::class, | ||||
]; | ]; | ||||
} | } | ||||
public function loadService(string $serviceClass) | |||||
protected function loadService(string $serviceClass) | |||||
{ | { | ||||
if(!$this->respectHierarchy($serviceClass)) { | if(!$this->respectHierarchy($serviceClass)) { | ||||
throw new ErrorException('Le service '.$serviceClass.' ne peut pas être chargé ici.'); | throw new ErrorException('Le service '.$serviceClass.' ne peut pas être chargé ici.'); | ||||
return new $serviceClass; | return new $serviceClass; | ||||
} | } | ||||
public function respectHierarchy(string $serviceClassAsked): bool | |||||
protected function respectHierarchy(string $serviceClassAsked): bool | |||||
{ | { | ||||
$domain = \Yii::$app->logic; | $domain = \Yii::$app->logic; | ||||
$serviceCurrentClass = get_class($this); | $serviceCurrentClass = get_class($this); | ||||
return false; | return false; | ||||
} | } | ||||
public function getServiceLevelHierarchy(string $serviceClass): int | |||||
protected function getServiceLevelHierarchy(string $serviceClass): int | |||||
{ | { | ||||
$hierarchyArray = $this->getHierarchy(); | $hierarchyArray = $this->getHierarchy(); | ||||
FactoryInterface, SolverInterface ou BuilderInterface au service.'); | FactoryInterface, SolverInterface ou BuilderInterface au service.'); | ||||
} | } | ||||
public function isSolver(): bool | |||||
protected function isSolver(): bool | |||||
{ | { | ||||
return $this->classImplementsInterface(SolverInterface::class); | return $this->classImplementsInterface(SolverInterface::class); | ||||
} | } | ||||
public function isBuilder(): bool | |||||
protected function isBuilder(): bool | |||||
{ | { | ||||
return $this->classImplementsInterface(BuilderInterface::class); | return $this->classImplementsInterface(BuilderInterface::class); | ||||
} | } | ||||
public function isResolver(): bool | |||||
protected function isResolver(): bool | |||||
{ | { | ||||
return $this->classImplementsInterface(ResolverInterface::class); | return $this->classImplementsInterface(ResolverInterface::class); | ||||
} | } | ||||
public function isUtils(): bool | |||||
protected function isUtils(): bool | |||||
{ | { | ||||
return $this->classImplementsInterface(UtilsInterface::class); | return $this->classImplementsInterface(UtilsInterface::class); | ||||
} | } |
use common\logic\BaseManager; | use common\logic\BaseManager; | ||||
/** | /** | ||||
* @see TaxRateRepository | |||||
* @method array getAsArray() | |||||
* | |||||
* @see TaxRateBuilder | |||||
* @method TaxRate instanciateTaxRate() | |||||
* @method TaxRate createTaxRate() | |||||
* @mixin TaxRateRepository | |||||
* @mixin TaxRateBuilder | |||||
*/ | */ | ||||
class TaxRateManager extends BaseManager | class TaxRateManager extends BaseManager | ||||
{ | { |
/** | /** | ||||
* This is the model class for table "development". | * This is the model class for table "development". | ||||
* | |||||
* @property integer $id | |||||
* @property string $subject | |||||
* @property string $description | |||||
* @property string $date | |||||
* @property integer $progress | |||||
* @property string $status | |||||
* @property double $time_estimate | |||||
*/ | */ | ||||
class DevelopmentModel extends ActiveRecordCommon | |||||
class Development extends ActiveRecordCommon | |||||
{ | { | ||||
const STATUS_OPEN = 'open'; | const STATUS_OPEN = 'open'; | ||||
const STATUS_CLOSED = 'closed'; | const STATUS_CLOSED = 'closed'; |
/** | /** | ||||
* This is the model class for table "development_priority". | * This is the model class for table "development_priority". | ||||
* | |||||
*/ | */ | ||||
class DevelopmentPriorityModel extends ActiveRecordCommon | |||||
class DevelopmentPriority extends ActiveRecordCommon | |||||
{ | { | ||||
const PRIORITY_HIGH = 'high'; | const PRIORITY_HIGH = 'high'; | ||||
{ | { | ||||
return [ | return [ | ||||
'id_producer' => 'Producteur', | 'id_producer' => 'Producteur', | ||||
'id_producer' => 'Développement', | |||||
'id_development' => 'Développement', | |||||
'priority' => 'Priorité' | 'priority' => 'Priorité' | ||||
]; | ]; | ||||
} | } |
namespace common\logic\Distribution\Distribution; | namespace common\logic\Distribution\Distribution; | ||||
use common\logic\BaseManager; | use common\logic\BaseManager; | ||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; | |||||
use common\logic\Distribution\ProductDistribution\ProductDistribution; | |||||
use common\logic\PointSale\PointSale\PointSale; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\Product\Product\Product; | |||||
/** | /** | ||||
* @see DistributionSolver | |||||
* @method string getDayAsString(Distribution $distribution) | |||||
* @method bool isActiveProduct(Distribution $distribution, Product $product) | |||||
* @method bool isAvailable(Distribution $distribution) | |||||
* @method array filterDistributionsByDateDelay(array $distributionsArray) | |||||
* @method bool isPointSaleActive(Distribution $distribution, PointSale $pointSale) | |||||
* | |||||
* @see DistributionRepository | |||||
* @method array defaultOptionsSearch() | |||||
* @method Distribution|null getOneById(int $id) | |||||
* @method Distribution|null getOne(Producer $producer, string $date) | |||||
* @method Distribution|null getOneByDate(string $date) | |||||
* @method array getIncoming() | |||||
* @method bool isDateAvailable(Producer $producer, string $date = null) | |||||
* | |||||
* @see DistributionBuilder | |||||
* @method Distribution instanciateDistribution(Producer $producer, string $date, bool $delivery = true) | |||||
* @method Distribution createDistribution(Producer $producer, string $date, bool $delivery = true) | |||||
* @method Distribution createDistributionIfNotExist(Producer $producer, string $date, int $delivery = 1) | |||||
* @method void initPointSaleDistribution(Distribution $distribution) | |||||
* @method void initProductDistribution(Distribution $distribution) | |||||
* @method ProductDistribution linkProduct(Distribution $distribution, Product $product) | |||||
* @method void linkProductIncomingDistributions(Product $product) | |||||
* @method PointSaleDistribution linkPointSale(Distribution $distribution, PointSale $pointSale) | |||||
* @method void linkPointSaleIncomingDistributions(PointSale $pointSale) | |||||
* @method void updateOrderProductPrices(Distribution $distribution, Product $product) | |||||
* @method void active(Distribution $distribution, bool $active = true) | |||||
* @mixin DistributionSolver | |||||
* @mixin DistributionRepository | |||||
* @mixin DistributionBuilder | |||||
*/ | */ | ||||
class DistributionManager extends BaseManager | class DistributionManager extends BaseManager | ||||
{ | { |
/** | /** | ||||
* Instancie un PointSaleDistribution. | * Instancie un PointSaleDistribution. | ||||
*/ | */ | ||||
public function instanciate(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||||
public function instanciatePointSaleDistribution(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||||
{ | { | ||||
$pointSaleDistribution = new PointSaleDistribution(); | $pointSaleDistribution = new PointSaleDistribution(); | ||||
/** | /** | ||||
* Crée un PointSaleDistribution. | * Crée un PointSaleDistribution. | ||||
*/ | */ | ||||
public function create(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||||
public function createPointSaleDistribution(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||||
{ | { | ||||
$pointSaleDistribution = $this->instanciate($distribution, $pointSale); | |||||
$pointSaleDistribution = $this->instanciatePointSaleDistribution($distribution, $pointSale); | |||||
$pointSaleDistribution->save(); | $pointSaleDistribution->save(); | ||||
return $pointSaleDistribution; | return $pointSaleDistribution; | ||||
} | } | ||||
public function createIfNotExist(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||||
public function createPointSaleDistributionIfNotExist(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||||
{ | { | ||||
$pointSaleDistribution = $this->pointSaleDistributionRepository->getOne($distribution, $pointSale); | $pointSaleDistribution = $this->pointSaleDistributionRepository->getOne($distribution, $pointSale); | ||||
if (!$pointSaleDistribution) { | if (!$pointSaleDistribution) { | ||||
$pointSaleDistribution = $this->create($distribution, $pointSale); | |||||
$pointSaleDistribution = $this->createPointSaleDistribution($distribution, $pointSale); | |||||
} | } | ||||
return $pointSaleDistribution; | return $pointSaleDistribution; | ||||
* Crée les PointSaleDistribution pour une distribution donnée. | * Crée les PointSaleDistribution pour une distribution donnée. | ||||
*/ | */ | ||||
// setAll | // setAll | ||||
public function createAll(Distribution $distribution, bool $delivery): void | |||||
public function createAllPointSaleDistribution(Distribution $distribution, bool $delivery): void | |||||
{ | { | ||||
$pointSaleArray = $this->pointSaleRepository->getByDistribution($distribution); | $pointSaleArray = $this->pointSaleRepository->getByDistribution($distribution); | ||||
foreach ($pointSaleArray as $pointSale) { | foreach ($pointSaleArray as $pointSale) { | ||||
} | } | ||||
} | } | ||||
public function initDelivery(PointSaleDistribution $pointSaleDistribution, bool $delivery) | |||||
public function initDelivery(PointSaleDistribution $pointSaleDistribution, bool $delivery): void | |||||
{ | { | ||||
$day = date('N', strtotime($pointSaleDistribution->distribution->date)); | $day = date('N', strtotime($pointSaleDistribution->distribution->date)); | ||||
$pointSale = $pointSaleDistribution->pointSale; | $pointSale = $pointSaleDistribution->pointSale; |
<?php | |||||
namespace common\logic\Distribution\PointSaleDistribution; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin PointSaleDistributionRepository | |||||
* @mixin PointSaleDistributionBuilder | |||||
*/ | |||||
class PointSaleDistributionManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new PointSaleDistributionContainer()); | |||||
} | |||||
} |
class PointSaleDistributionRepository extends BaseService implements RepositoryInterface | class PointSaleDistributionRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
public function defaultOptionsSearch() { | |||||
public function defaultOptionsSearch(): array | |||||
{ | |||||
return [ | return [ | ||||
'with' => ['distribution', 'pointSale'], | 'with' => ['distribution', 'pointSale'], | ||||
'join_with' => [], | 'join_with' => [], |
$this->distributionSolver = $this->loadService(DistributionSolver::class); | $this->distributionSolver = $this->loadService(DistributionSolver::class); | ||||
} | } | ||||
public function instanciate(Distribution $distribution, Product $product): ProductDistribution | |||||
public function instanciateProductDistribution(Distribution $distribution, Product $product): ProductDistribution | |||||
{ | { | ||||
$productDistribution = new ProductDistribution(); | $productDistribution = new ProductDistribution(); | ||||
return $productDistribution; | return $productDistribution; | ||||
} | } | ||||
public function create(Distribution $distribution, Product $product): ProductDistribution | |||||
public function createProductDistribution(Distribution $distribution, Product $product): ProductDistribution | |||||
{ | { | ||||
$productDistribution = $this->instanciate($distribution, $product); | |||||
$productDistribution = $this->instanciateProductDistribution($distribution, $product); | |||||
$this | $this | ||||
->initActive($productDistribution) | ->initActive($productDistribution) | ||||
return $productDistribution; | return $productDistribution; | ||||
} | } | ||||
public function createIfNotExist(Distribution $distribution, Product $product): ProductDistribution | |||||
public function createProductDistributionIfNotExist(Distribution $distribution, Product $product): ProductDistribution | |||||
{ | { | ||||
$productDistribution = $this->productDistributionRepository->getOne($distribution, $product); | $productDistribution = $this->productDistributionRepository->getOne($distribution, $product); | ||||
if(!$productDistribution) { | if(!$productDistribution) { | ||||
$productDistribution = $this->create($distribution, $product); | |||||
$productDistribution = $this->createProductDistribution($distribution, $product); | |||||
} | } | ||||
return $productDistribution; | return $productDistribution; |
<?php | |||||
namespace common\logic\Distribution\ProductDistribution; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin ProductDistributionRepository | |||||
* @mixin ProductDistributionBuilder | |||||
*/ | |||||
class ProductDistributionManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new ProductDistributionContainer()); | |||||
} | |||||
} |
class ProductDistributionRepository extends BaseService implements RepositoryInterface | class ProductDistributionRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
public function defaultOptionsSearch() { | |||||
public function defaultOptionsSearch(): array | |||||
{ | |||||
return [ | return [ | ||||
'with' => ['product','distribution'], | 'with' => ['product','distribution'], | ||||
'join_with' => [], | 'join_with' => [], |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\BuilderInterface; | use common\logic\BuilderInterface; | ||||
use common\logic\Document\Document\DocumentBuilder; | |||||
class DeliveryNoteBuilder extends BaseService implements BuilderInterface | |||||
class DeliveryNoteBuilder extends DocumentBuilder implements BuilderInterface | |||||
{ | { | ||||
public function instanciate(): DeliveryNote | |||||
public function instanciateDeliveryNote(): DeliveryNote | |||||
{ | { | ||||
$deliveryNote = new DeliveryNote(); | $deliveryNote = new DeliveryNote(); | ||||
<?php | |||||
namespace common\logic\Document\DeliveryNote; | |||||
use common\logic\Document\Document\DocumentManager; | |||||
use common\logic\PointSale\PointSale\DeliveryNoteRepository; | |||||
/** | |||||
* @mixin DeliveryNoteSolver | |||||
* @mixin DeliveryNoteRepository | |||||
* @mixin DeliveryNoteBuilder | |||||
*/ | |||||
class DeliveryNoteManager extends DocumentManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new DeliveryNoteContainer()); | |||||
} | |||||
} |
namespace common\logic\Document\DeliveryNote; | namespace common\logic\Document\DeliveryNote; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Document\Document\DocumentSolver; | |||||
use common\logic\Document\Invoice\Invoice; | use common\logic\Document\Invoice\Invoice; | ||||
use common\logic\SolverInterface; | use common\logic\SolverInterface; | ||||
class DeliveryNoteSolver extends BaseService implements SolverInterface | |||||
class DeliveryNoteSolver extends DocumentSolver implements SolverInterface | |||||
{ | { | ||||
public function getInvoiceId(DeliveryNote $deliveryNote): ?int | public function getInvoiceId(DeliveryNote $deliveryNote): ?int | ||||
{ | { |
<?php | |||||
namespace common\logic\Document\Document; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin DocumentSolver | |||||
* @mixin DocumentBuilder | |||||
* @mixin DocumentUtils | |||||
*/ | |||||
class DocumentManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new DocumentContainer()); | |||||
} | |||||
} |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Order\Order\Order; | use common\logic\Order\Order\Order; | ||||
use common\logic\PointSale\PointSale\PointSale; | |||||
use common\logic\Producer\Producer\Producer; | use common\logic\Producer\Producer\Producer; | ||||
use common\logic\SolverInterface; | use common\logic\SolverInterface; | ||||
class DocumentSolver extends BaseService implements SolverInterface | class DocumentSolver extends BaseService implements SolverInterface | ||||
{ | { | ||||
public function getAmount(DocumentInterface $document, $type = Order::AMOUNT_TOTAL, $format = false) | |||||
public function getAmount(DocumentInterface $document, string $type = Order::AMOUNT_TOTAL, bool $format = false) | |||||
{ | { | ||||
return $this->_getAmountGeneric($document, $type, false, $format); | return $this->_getAmountGeneric($document, $type, false, $format); | ||||
} | } | ||||
public function getAmountWithTax(DocumentInterface $document, $type = Order::AMOUNT_TOTAL, $format = false) | |||||
public function getAmountWithTax(DocumentInterface $document, string $type = Order::AMOUNT_TOTAL, bool $format = false) | |||||
{ | { | ||||
return $this->_getAmountGeneric($document, $type, true, $format); | return $this->_getAmountGeneric($document, $type, true, $format); | ||||
} | } | ||||
protected function _getAmountGeneric(DocumentInterface $document, $type = Order::AMOUNT_TOTAL, $withTax = true, $format = false) | |||||
protected function _getAmountGeneric(DocumentInterface $document, string $type = Order::AMOUNT_TOTAL, bool $withTax = true, bool $format = false) | |||||
{ | { | ||||
$amount = 0; | $amount = 0; | ||||
$totalVat = 0; | $totalVat = 0; | ||||
foreach($document->getProductsOrders() as $productOrderArray) { | |||||
foreach($this->getProductsOrders($document) as $productOrderArray) { | |||||
foreach($productOrderArray as $productOrder) { | foreach($productOrderArray as $productOrder) { | ||||
$priceLine = $productOrder->getPriceByTypeTotal($type) * $productOrder->quantity; | $priceLine = $productOrder->getPriceByTypeTotal($type) * $productOrder->quantity; | ||||
$amount += $priceLine; | $amount += $priceLine; | ||||
} | } | ||||
} | } | ||||
if ($this->isTaxCalculationMethodRoundingOfTheSum()) { | |||||
if ($this->isTaxCalculationMethodRoundingOfTheSum($document)) { | |||||
$totalVat = Price::round($totalVat); | $totalVat = Price::round($totalVat); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public function getTotalVatArray($typeTotal) | |||||
public function getTotalVatArray(DocumentInterface $document, string $typeTotal): array | |||||
{ | { | ||||
$totalVatArray = []; | $totalVatArray = []; | ||||
// Méthode de calcul via getProductOrders() | // Méthode de calcul via getProductOrders() | ||||
foreach($this->getProductsOrders() as $productOrderArray) { | |||||
foreach($this->getProductsOrders($document) as $productOrderArray) { | |||||
foreach ($productOrderArray as $productOrder) { | foreach ($productOrderArray as $productOrder) { | ||||
$idTaxRate = $productOrder->taxRate->id; | $idTaxRate = $productOrder->taxRate->id; | ||||
$totalVatArray[$idTaxRate] += Price::getVat( | $totalVatArray[$idTaxRate] += Price::getVat( | ||||
$productOrder->getPriceByTypeTotal($typeTotal) * $productOrder->quantity, | $productOrder->getPriceByTypeTotal($typeTotal) * $productOrder->quantity, | ||||
$productOrder->taxRate->value, | $productOrder->taxRate->value, | ||||
$this->tax_calculation_method | |||||
$document->tax_calculation_method | |||||
); | ); | ||||
} | } | ||||
} | } | ||||
return $totalVatArray; | return $totalVatArray; | ||||
} | } | ||||
public function getPointSale() | |||||
public function getPointSale(DocumentInterface $document): ?PointSale | |||||
{ | { | ||||
if (isset($this->orders) && isset($this->orders[0])) { | |||||
return $this->orders[0]->pointSale; | |||||
} else { | |||||
return ''; | |||||
if (isset($document->orders) && isset($document->orders[0])) { | |||||
return $document->orders[0]->pointSale; | |||||
} | } | ||||
return null; | |||||
} | } | ||||
public function getDistribution() | |||||
public function getDistribution(DocumentInterface $document) | |||||
{ | { | ||||
if (isset($this->orders) && isset($this->orders[0])) { | |||||
return $this->orders[0]->distribution; | |||||
} else { | |||||
return ''; | |||||
if (isset($document->orders) && isset($document->orders[0])) { | |||||
return $document->orders[0]->distribution; | |||||
} | } | ||||
return null; | |||||
} | } | ||||
public function getClass() | |||||
public function getClass(DocumentInterface $document): string | |||||
{ | { | ||||
return str_replace('common\models\\', '', get_class($this)); | |||||
return str_replace('common\models\\', '', get_class($document)); | |||||
} | } | ||||
public function getType() | |||||
public function getType(DocumentInterface $document): string | |||||
{ | { | ||||
$class = $this->getClass(); | |||||
$class = $this->getClass($document); | |||||
if ($class == 'Invoice') { | if ($class == 'Invoice') { | ||||
$documentType = 'Facture'; | $documentType = 'Facture'; | ||||
return ''; | return ''; | ||||
} | } | ||||
public function isValidClass($typeDocument) | |||||
public function isValidClass(string $typeDocument): bool | |||||
{ | { | ||||
return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']); | return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']); | ||||
} | } | ||||
return ($document->status == Document::STATUS_DRAFT) ? 'default' : 'success'; | return ($document->status == Document::STATUS_DRAFT) ? 'default' : 'success'; | ||||
} | } | ||||
public function getHtmlLabel(DocumentInterface $document) | |||||
public function getHtmlLabel(DocumentInterface $document): string | |||||
{ | { | ||||
$label = $this->getStatusWording($document); | $label = $this->getStatusWording($document); | ||||
$classLabel = $this->getStatusCssClass($document); | $classLabel = $this->getStatusCssClass($document); | ||||
public function isInvoicePrice(DocumentInterface $document): bool | public function isInvoicePrice(DocumentInterface $document): bool | ||||
{ | { | ||||
return $this->getClass() == 'Invoice' || $this->getClass() == 'DeliveryNote'; | |||||
return $this->getClass($document) == 'Invoice' || $this->getClass($document) == 'DeliveryNote'; | |||||
} | } | ||||
public function isTaxCalculationMethodSumOfRoundings(DocumentInterface $document): bool | public function isTaxCalculationMethodSumOfRoundings(DocumentInterface $document): bool | ||||
{ | { | ||||
return $document->tax_calculation_method == self::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS; | |||||
return $document->tax_calculation_method == Document::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS; | |||||
} | } | ||||
public function isTaxCalculationMethodRoundingOfTheSum(DocumentInterface $document): bool | public function isTaxCalculationMethodRoundingOfTheSum(DocumentInterface $document): bool | ||||
{ | { | ||||
return $document->tax_calculation_method == self::TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM; | |||||
return $document->tax_calculation_method == Document::TAX_CALCULATION_METHOD_ROUNDING_OF_THE_SUM; | |||||
} | } | ||||
} | } |
} | } | ||||
} | } | ||||
public function downloadPdf(DocumentInterface $document, $regenerate = false) | |||||
public function downloadPdf(DocumentInterface $document, bool $regenerate = false) | |||||
{ | { | ||||
$filenameComplete = $this->documentSolver->getFilenameComplete($document); | $filenameComplete = $this->documentSolver->getFilenameComplete($document); | ||||
} | } | ||||
} | } | ||||
public function send(DocumentInterface $document) | |||||
public function send(DocumentInterface $document): bool | |||||
{ | { | ||||
if (isset($document->user) && strlen($document->user->email) > 0) { | if (isset($document->user) && strlen($document->user->email) > 0) { | ||||
$producer = GlobalParam::getCurrentProducer(); | $producer = GlobalParam::getCurrentProducer(); |
class InvoiceBuilder extends DocumentBuilder implements BuilderInterface | class InvoiceBuilder extends DocumentBuilder implements BuilderInterface | ||||
{ | { | ||||
public function instanciate(): Invoice | |||||
public function instanciateInvoice(): Invoice | |||||
{ | { | ||||
$invoice = new Invoice(); | $invoice = new Invoice(); | ||||
<?php | |||||
namespace common\logic\Document\Invoice; | |||||
use common\logic\Document\Document\DocumentManager; | |||||
use common\logic\PointSale\PointSale\InvoiceRepository; | |||||
/** | |||||
* @mixin InvoiceRepository | |||||
* @mixin InvoiceBuilder | |||||
*/ | |||||
class InvoiceManager extends DocumentManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new InvoiceContainer()); | |||||
} | |||||
} |
class QuotationBuilder extends BaseService implements BuilderInterface | class QuotationBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
public function instanciate(): Quotation | |||||
public function instanciateQuotation(): Quotation | |||||
{ | { | ||||
$quotation = new Quotation(); | $quotation = new Quotation(); | ||||
<?php | |||||
namespace common\logic\Document\Invoice; | |||||
use common\logic\Document\Document\DocumentManager; | |||||
use common\logic\Document\Quotation\QuotationBuilder; | |||||
use common\logic\PointSale\PointSale\QuotationRepository; | |||||
/** | |||||
* @mixin QuotationRepository | |||||
* @mixin QuotationBuilder | |||||
*/ | |||||
class QuotationManager extends DocumentManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new QuotationContainer()); | |||||
} | |||||
} |
use yii\db\Query; | use yii\db\Query; | ||||
/** | /** | ||||
* @see OrderSolver | |||||
* @method string getFieldNameAmount($typeTotal = Order::AMOUNT_TOTAL, string $typeField = '') | |||||
* @method float getOrderTotalVat(Order $order, string $typeTotal = Order::AMOUNT_TOTAL) | |||||
* @method string|null getPaymentStatus(Order $order) | |||||
* @method string getPointSaleSummary(Order $order) | |||||
* @method string getOrderUsername(Order $order) | |||||
* @method bool isLinkedToValidDocument(Order $order) | |||||
* @method string getCommentReport(Order $order) | |||||
* @method string getDateAsHtml(Order $order) | |||||
* @method int countProducts(Order $order) | |||||
* @method int getProductQuantityPieces(Product $product, array $orders) | |||||
* @method int getProductQuantity(Product $product, array $orders, bool $ignoreCancel = false, string $unit = null) | |||||
* @method string getHistoryClass(Order $order) | |||||
* @method string getHistorySummary(Order $order) | |||||
* @method string getLabelOrigin(Order $order, bool $withLabel = false) | |||||
* @method float getOrderAmount(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false) | |||||
* @method float getOrderAmountWithTax(Order $order, string $type = Order::AMOUNT_TOTAL, bool $format = false) | |||||
* @method bool isOrderStateOpen(Order $order) | |||||
* @method bool isOrderStatePreparation(Order $order) | |||||
* @method bool isOrderStateDelivered(Order $order) | |||||
* @method bool isOrderBelongsToUser(Order $order, User $user = null) | |||||
* @method string getDataJson(Order $order) | |||||
* | |||||
* @see OrderRepository | |||||
* @method array defaultOptionsSearch() | |||||
* @method Order|null findOneById(int $id) | |||||
* @method array findBy(array $params = [], array $options = []) | |||||
* @method array findByDistribution(Distribution $distribution, string $conditionAppend = '') | |||||
* @method Order|null findOneLastOfYear(Producer $producer) | |||||
* @method Query queryHistory(Producer $producer, User $user, string $type = 'incoming') | |||||
* @method string getCartSummary(Order $order, $htmlFormat = true) | |||||
* @method string getAmountSummary(Order $order) | |||||
* @method string getState(Order $order) | |||||
* | |||||
* @see OrderBuilder | |||||
* @method Order instanciateOrder(Distribution $distribution) | |||||
* @method Order createOrder(Distribution $distribution) | |||||
* @method Order|null createOrderFromSubscription(Subscription $subscription, string $date, bool $force = false) | |||||
* @method array createAllOrdersFromSubscriptions(string $date, bool $force = false) | |||||
* @method array updateOrdersIncomingDistributionsFromSubscription(Subscription $subscription, bool $update = false) | |||||
* @method int deleteOrdersIncomingDistributionsFromSubscription(Subscription $subscription, bool $deleteAfterDateEnd = false) | |||||
* @method bool addProductOrdersFromSubscription(Order $order, Subscription $subscription) | |||||
* @method void updateOrderFromSubscription(Order $order, Subscription $subscription) | |||||
* @method void initOrderBaseFromSubscription(Order $order, Subscription $subscription) | |||||
* @method void initOrderAutoPaymentFromSubscription(Order $order, Subscription $subscription) | |||||
* @method void createUserPointSale(Order $order) | |||||
* @method void initOrderCommentPointSale(Order $order) | |||||
* @method void initOrder(Order $order, string $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT) | |||||
* @method void initOrderAmount(Order $order, string $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT) | |||||
* @method void addProductOrderWeight(Order $order, ProductOrder $productOrder) | |||||
* @method void addProductOrderAmount(Order $order, string $typeTotal, ProductOrder $productOrder, string $taxCalculationMethod) | |||||
* @method void addProductOrderVat(Order $order, string $typeTotal, float $priceTotalWithoutTax, TaxRate $taxRate, string $taxCalculationMethod) | |||||
* @method void initOrderPaidAmount(Order $order) | |||||
* @method void deleteOrder(Order $order, bool $force = false): bool | |||||
* @method void processCredit(Order $order) | |||||
* @method void updateOrderTillerSynchronization(Order $order) | |||||
* @method void updateOrderStatus(Order $order, string $newStatus, string $origin) | |||||
* @method void generateOrderReference(Order $order) | |||||
* @method void updateOrderInvoicePrices(Order $order, array $params = []) | |||||
* @mixin OrderSolver | |||||
* @mixin OrderRepository | |||||
* @mixin OrderBuilder | |||||
*/ | */ | ||||
class OrderManager extends BaseManager | class OrderManager extends BaseManager | ||||
{ | { |
$this->userSolver = $this->loadService(UserSolver::class); | $this->userSolver = $this->loadService(UserSolver::class); | ||||
} | } | ||||
public function instanciate(Order $order, User $user, string $status, string $origin): OrderStatusHistory | |||||
public function instanciateOrderStatusHistory(Order $order, User $user, string $status, string $origin): OrderStatusHistory | |||||
{ | { | ||||
$orderStatusHistory = new OrderStatusHistory(); | $orderStatusHistory = new OrderStatusHistory(); | ||||
return $orderStatusHistory; | return $orderStatusHistory; | ||||
} | } | ||||
public function create(Order $order, User $user, string $status, string $origin): OrderStatusHistory | |||||
public function createOrderStatusHistory(Order $order, User $user, string $status, string $origin): OrderStatusHistory | |||||
{ | { | ||||
$orderStatusHistory = $this->instanciate($order, $user, $status, $origin); | |||||
$orderStatusHistory = $this->instanciateOrderStatusHistory($order, $user, $status, $origin); | |||||
$orderStatusHistory->save(); | $orderStatusHistory->save(); | ||||
return $orderStatusHistory | |||||
} | } | ||||
} | } |
<?php | |||||
namespace common\logic\Order\OrderStatusHistory; | |||||
use common\logic\BaseManager; | |||||
use common\logic\PointSale\PointSale\OrderStatusHistoryRepository; | |||||
/** | |||||
* @mixin OrderStatusHistoryRepository | |||||
* @mixin OrderStatusHistoryBuilder | |||||
*/ | |||||
class OrderStatusHistoryManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new OrderStatusHistoryContainer()); | |||||
} | |||||
} |
$this->productSolver = $this->loadService(ProductSolver::class); | $this->productSolver = $this->loadService(ProductSolver::class); | ||||
} | } | ||||
public function instanciate(Order $order, Product $product, float $quantity, float $price): ProductOrder | |||||
public function instanciateProductOrder(Order $order, Product $product, float $quantity, float $price): ProductOrder | |||||
{ | { | ||||
$productOrder = new ProductOrder(); | $productOrder = new ProductOrder(); | ||||
return $productOrder; | return $productOrder; | ||||
} | } | ||||
public function create(Order $order, Product $product, float $quantity, float $price): ProductOrder | |||||
public function createProductOrder(Order $order, Product $product, float $quantity, float $price): ProductOrder | |||||
{ | { | ||||
$productOrder = $this->instanciate($order, $product, $quantity, $price); | |||||
$productOrder = $this->instanciateProductOrder($order, $product, $quantity, $price); | |||||
$productOrder->save(); | $productOrder->save(); | ||||
return $productOrder; | return $productOrder; | ||||
} | } |
<?php | |||||
namespace common\logic\Order\ProductOrder; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin ProductOrderSolver | |||||
* @mixin ProductOrderRepository | |||||
* @mixin ProductOrderBuilder | |||||
*/ | |||||
class ProductOrderManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new ProductOrderContainer()); | |||||
} | |||||
} |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\BuilderInterface; | use common\logic\BuilderInterface; | ||||
use common\logic\PointSale\UserPointSale\UserPointSale; | |||||
use common\logic\PointSale\UserPointSale\UserPointSaleBuilder; | use common\logic\PointSale\UserPointSale\UserPointSaleBuilder; | ||||
use common\logic\PointSale\UserPointSale\UserPointSaleRepository; | use common\logic\PointSale\UserPointSale\UserPointSaleRepository; | ||||
use common\logic\Producer\Producer\Producer; | use common\logic\Producer\Producer\Producer; | ||||
$this->userPointSaleRepository = $this->loadService(UserPointSaleRepository::class); | $this->userPointSaleRepository = $this->loadService(UserPointSaleRepository::class); | ||||
} | } | ||||
public function instanciate(): PointSale | |||||
public function instanciatePointSale(): PointSale | |||||
{ | { | ||||
$pointSale = new PointSale(); | $pointSale = new PointSale(); | ||||
* Lie un utilisateur au point de vente. | * Lie un utilisateur au point de vente. | ||||
*/ | */ | ||||
// linkUser | // linkUser | ||||
public function addUser(User $user, PointSale $pointSale) | |||||
public function addUser(User $user, PointSale $pointSale): UserPointSale | |||||
{ | { | ||||
$userPointSale = $this->userPointSaleRepository->getOne($user, $pointSale); | $userPointSale = $this->userPointSaleRepository->getOne($user, $pointSale); | ||||
if (!$userPointSale) { | if (!$userPointSale) { | ||||
$this->userPointSaleBuilder->create($user, $pointSale); | |||||
$userPointSale = $this->userPointSaleBuilder->create($user, $pointSale); | |||||
} | } | ||||
} | |||||
return $userPointSale; | |||||
} | |||||
} | } |
<?php | |||||
namespace common\logic\PointSale\PointSale; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin PointSaleSolver | |||||
* @mixin PointSaleRepository | |||||
* @mixin PointSaleBuilder | |||||
*/ | |||||
class PointSaleManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new PointSaleContainer()); | |||||
} | |||||
} |
); | ); | ||||
} | } | ||||
public function populateDropdownList() | |||||
public function populateDropdownList(): array | |||||
{ | { | ||||
$pointSalesArrayDropdown = ['' => '--']; | $pointSalesArrayDropdown = ['' => '--']; | ||||
$pointSalesArray = $this->get(); | $pointSalesArray = $this->get(); |
class UserPointSaleBuilder extends BaseService implements BuilderInterface | class UserPointSaleBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
public function instanciate(User $user, PointSale $pointSale, string $comment = null): UserPointSale | |||||
public function instanciateUserPointSale(User $user, PointSale $pointSale, string $comment = null): UserPointSale | |||||
{ | { | ||||
$userPointSale = new UserPointSale(); | $userPointSale = new UserPointSale(); | ||||
return $userPointSale; | return $userPointSale; | ||||
} | } | ||||
public function create(User $user, PointSale $pointSale, string $comment = null): UserPointSale | |||||
public function createUserPointSale(User $user, PointSale $pointSale, string $comment = null): UserPointSale | |||||
{ | { | ||||
$userPointSale = $this->instanciate($user, $pointSale, $comment); | |||||
$userPointSale = $this->instanciateUserPointSale($user, $pointSale, $comment); | |||||
$userPointSale->save(); | $userPointSale->save(); | ||||
return $userPointSale; | return $userPointSale; |
<?php | |||||
namespace common\logic\PointSale\UserPointSale; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin UserPointSaleRepository | |||||
* @mixin UserPointSaleBuilder | |||||
*/ | |||||
class UserPointSaleManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new UserPointSaleContainer()); | |||||
} | |||||
} |
$this->producerSolver = $this->loadService(ProducerSolver::class); | $this->producerSolver = $this->loadService(ProducerSolver::class); | ||||
} | } | ||||
public function instanciate(): Producer | |||||
public function instanciateProducer(): Producer | |||||
{ | { | ||||
$producer = new Producer(); | $producer = new Producer(); | ||||
return $userProducer; | return $userProducer; | ||||
} | } | ||||
public function updateOpendistribVersion(Producer $producer) | |||||
public function updateOpendistribVersion(Producer $producer): void | |||||
{ | { | ||||
$versionsArray = Opendistrib::getVersions(); | $versionsArray = Opendistrib::getVersions(); | ||||
$producer->latest_version_opendistrib = array_values($versionsArray)[0]; | $producer->latest_version_opendistrib = array_values($versionsArray)[0]; |
<?php | |||||
namespace common\logic\Producer\Producer; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin ProducerSolver | |||||
* @mixin ProducerRepository | |||||
* @mixin ProducerBuilder | |||||
* @mixin ProducerUtils | |||||
*/ | |||||
class ProducerManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new ProducerContainer()); | |||||
} | |||||
} |
]; | ]; | ||||
} | } | ||||
public function getOneById($id) | |||||
public function getOneById(int $id) | |||||
{ | { | ||||
return Producer::searchOne(['id' => $id]); | return Producer::searchOne(['id' => $id]); | ||||
} | } | ||||
public function getOneBySlug($slug) | |||||
public function getOneBySlug(string $slug) | |||||
{ | { | ||||
return Producer::searchOne(['slug' => $slug]); | return Producer::searchOne(['slug' => $slug]); | ||||
} | } | ||||
* | * | ||||
* @return array | * @return array | ||||
*/ | */ | ||||
public static function getPopulateDropdown() | |||||
public static function getPopulateDropdown(): array | |||||
{ | { | ||||
$producers = Producer::find() | $producers = Producer::find() | ||||
->where([ | ->where([ | ||||
} | } | ||||
} | } | ||||
public function getAmountToBeBilledByMonth(Producer $producer, $month, $format = false) | |||||
public function getAmountToBeBilledByMonth(Producer $producer, $month, bool $format = false) | |||||
{ | { | ||||
$turnover = $this->getTurnover($producer, $month); | $turnover = $this->getTurnover($producer, $month); | ||||
return $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, $format); | return $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, $format); | ||||
} | } | ||||
public function getSummaryAmountsToBeBilled(Producer $producer, $label, $numberOfMonths = 1) | |||||
public function getSummaryAmountsToBeBilled(Producer $producer, string $label, int $numberOfMonths = 1): string | |||||
{ | { | ||||
$text = ''; | $text = ''; | ||||
$numMonthCurrent = date('m'); | $numMonthCurrent = date('m'); | ||||
return $text; | return $text; | ||||
} | } | ||||
public function getAmountBilledLastMonth(Producer $producer) | |||||
public function getAmountBilledLastMonth(Producer $producer): float | |||||
{ | { | ||||
if ($this->producerSolver->isBillingTypeClassic($producer)) { | if ($this->producerSolver->isBillingTypeClassic($producer)) { | ||||
$month = date('Y-m', strtotime('-1 month')); | $month = date('Y-m', strtotime('-1 month')); | ||||
return 0; | return 0; | ||||
} | } | ||||
public function getOnlinePaymentMinimumAmount(Producer $producer) | |||||
public function getOnlinePaymentMinimumAmount(Producer $producer): float | |||||
{ | { | ||||
$onlinePaymentMinimumAmount = $this->getConfig('option_online_payment_minimum_amount'); | $onlinePaymentMinimumAmount = $this->getConfig('option_online_payment_minimum_amount'); | ||||
if (!$onlinePaymentMinimumAmount) { | if (!$onlinePaymentMinimumAmount) { | ||||
* Retourne une configuration d'un producteur donné | * Retourne une configuration d'un producteur donné | ||||
* | * | ||||
*/ | */ | ||||
public function getConfig($config = '', $idProducer = 0) | |||||
public function getConfig(string $config = '', int $idProducer = 0) | |||||
{ | { | ||||
if (strlen($config)) { | if (strlen($config)) { | ||||
if (!$idProducer) { | if (!$idProducer) { | ||||
} | } | ||||
} | } | ||||
return false; | |||||
return null; | |||||
} | } | ||||
/** | /** | ||||
* Retourne les établissements liés à l'utilisateur. | * Retourne les établissements liés à l'utilisateur. | ||||
* | |||||
* @return array | |||||
*/ | */ | ||||
public function getBookmarked(User $user) | |||||
public function getBookmarked(User $user): array | |||||
{ | { | ||||
$producers = (new \yii\db\Query()) | $producers = (new \yii\db\Query()) | ||||
->select('*') | ->select('*') |
class ProducerSolver extends BaseService implements SolverInterface | class ProducerSolver extends BaseService implements SolverInterface | ||||
{ | { | ||||
public function getCurrent() | |||||
{ | |||||
} | |||||
/** | /** | ||||
* Retourne true si le compte est un compte de démo. | * Retourne true si le compte est un compte de démo. | ||||
return false; | return false; | ||||
} | } | ||||
public function getFullAddress(Producer $producer, $nl2br = false) | |||||
public function getFullAddress(Producer $producer, bool $nl2br = false): string | |||||
{ | { | ||||
$address = ''; | $address = ''; | ||||
$address .= $producer->name . "\n"; | $address .= $producer->name . "\n"; | ||||
return $producer->option_billing_type == Producer::BILLING_TYPE_CLASSIC; | return $producer->option_billing_type == Producer::BILLING_TYPE_CLASSIC; | ||||
} | } | ||||
public function isBillingTypeFreePrice(Producer $producer) | |||||
public function isBillingTypeFreePrice(Producer $producer): bool | |||||
{ | { | ||||
return $producer->option_billing_type == Producer::BILLING_TYPE_FREE_PRICE; | return $producer->option_billing_type == Producer::BILLING_TYPE_FREE_PRICE; | ||||
} | } | ||||
/** | /** | ||||
* Retourne le montant de l'abonnement à prix libre définit par | * Retourne le montant de l'abonnement à prix libre définit par | ||||
* le producteur. | * le producteur. | ||||
* | |||||
*/ | */ | ||||
public function getFreePrice(Producer $producer, $format = true) | |||||
public function getFreePrice(Producer $producer, bool $format = true) | |||||
{ | { | ||||
if (!is_null($producer->free_price)) { | if (!is_null($producer->free_price)) { | ||||
if ($format) { | if ($format) { | ||||
return false; | return false; | ||||
} | } | ||||
public function getFilenamePrivateKeyApiStripe(Producer $producer) | |||||
public function getFilenamePrivateKeyApiStripe(Producer $producer): string | |||||
{ | { | ||||
return '../../common/config/stripe/api-' . $producer->id . '.key'; | return '../../common/config/stripe/api-' . $producer->id . '.key'; | ||||
} | } | ||||
public function getFilenamePrivateKeyEndpointStripe(Producer $producer) | |||||
public function getFilenamePrivateKeyEndpointStripe(Producer $producer): string | |||||
{ | { | ||||
return '../../common/config/stripe/endpoint-' . $producer->id . '.key'; | return '../../common/config/stripe/endpoint-' . $producer->id . '.key'; | ||||
} | } | ||||
/** | /** | ||||
* Retourne la clé secrète d'API de Stripe. | * Retourne la clé secrète d'API de Stripe. | ||||
* | |||||
* @return string | |||||
*/ | */ | ||||
public function getPrivateKeyStripe($filename) | |||||
public function getPrivateKeyStripe(string $filename): string | |||||
{ | { | ||||
if (file_exists($filename)) { | if (file_exists($filename)) { | ||||
$handle = fopen($filename, "r"); | $handle = fopen($filename, "r"); | ||||
return ''; | return ''; | ||||
} | } | ||||
public function getPrivateKeyApiStripe(Producer $producer) | |||||
public function getPrivateKeyApiStripe(Producer $producer): string | |||||
{ | { | ||||
return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyApiStripe($producer)); | return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyApiStripe($producer)); | ||||
} | } | ||||
public function getPrivateKeyEndpointStripe(Producer $producer) | |||||
public function getPrivateKeyEndpointStripe(Producer $producer): string | |||||
{ | { | ||||
return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyEndpointStripe($producer)); | return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyEndpointStripe($producer)); | ||||
} | } | ||||
public function isOnlinePaymentActive(Producer $producer) | |||||
public function isOnlinePaymentActive(Producer $producer): bool | |||||
{ | { | ||||
return $producer->online_payment | return $producer->online_payment | ||||
|| ($producer->option_stripe_mode_test | || ($producer->option_stripe_mode_test | ||||
{ | { | ||||
return $producer->option_billing_frequency == Producer::BILLING_FREQUENCY_BIANNUAL; | return $producer->option_billing_frequency == Producer::BILLING_FREQUENCY_BIANNUAL; | ||||
} | } | ||||
} | } |
class ProducerUtils extends BaseService implements UtilsInterface | class ProducerUtils extends BaseService implements UtilsInterface | ||||
{ | { | ||||
public function sendEmailNewProducer(Producer $producer) | |||||
public function sendEmailNewProducer(Producer $producer): void | |||||
{ | { | ||||
\Yii::$app->mailer->compose( | \Yii::$app->mailer->compose( | ||||
[ | [ |
<?php | |||||
namespace common\logic\Producer\ProducerPriceRange; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin ProducerPriceRangeRepository | |||||
*/ | |||||
class ProducerPriceRangeManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new ProducerPriceRangeContainer()); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Product\Product; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin ProductSolver | |||||
* @mixin ProductRepository | |||||
* @mixin ProductBuilder | |||||
*/ | |||||
class ProductManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new ProductContainer()); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Product\ProductCategory; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin ProductCategoryRepository | |||||
* @mixin ProductCategoryBuilder | |||||
*/ | |||||
class ProductCategoryManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new ProductCategoryContainer()); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Product\ProductPointSale; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin ProductPointSaleRepository | |||||
* @mixin ProductPointSaleBuilder | |||||
*/ | |||||
class ProductPointSaleManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new ProductPointSaleContainer()); | |||||
} | |||||
} |
<?php | <?php | ||||
namespace common\logic\Product\ProductPrice; | |||||
namespace common\logic\Product\ProductPointSale; | |||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; |
<?php | |||||
namespace common\logic\Product\ProductPrice; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin ProductPriceRepository | |||||
* @mixin ProductPriceBuilder | |||||
*/ | |||||
class ProductPriceManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new ProductPriceContainer()); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Subscription\ProductSubscription; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin ProductSubscriptionRepository | |||||
* @mixin ProductSubscriptionBuilder | |||||
*/ | |||||
class ProductSubscriptionManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new ProductSubscriptionContainer()); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Subscription\Subscription; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin SubscriptionSolver | |||||
* @mixin SubscriptionRepository | |||||
* @mixin SubscriptionBuilder | |||||
*/ | |||||
class SubscriptionManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new SubscriptionContainer()); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\User\CreditHistory; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin CreditHistorySolver | |||||
* @mixin CreditHistoryRepository | |||||
* @mixin CreditHistoryBuilder | |||||
*/ | |||||
class CreditHistoryManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new CreditHistoryContainer()); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\User\User; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin UserSolver | |||||
* @mixin UserRepository | |||||
* @mixin UserBuilder | |||||
* @mixin UserUtils | |||||
*/ | |||||
class UserManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new UserContainer()); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\User\UserGroup; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin UserGroupRepository | |||||
* @mixin UserGroupBuilder | |||||
*/ | |||||
class UserGroupManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new UserGroupContainer()); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\User\UserProducer; | |||||
use common\logic\BaseManager; | |||||
/** | |||||
* @mixin UserProducerRepository | |||||
* @mixin UserProducerBuilder | |||||
*/ | |||||
class UserProducerManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new UserProducerContainer()); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\User\UserUserGroup; | |||||
use common\logic\BaseManager; | |||||
use common\logic\User\UserGroup\UserUserGroupBuilder; | |||||
/** | |||||
* @mixin UserUserGroupRepository | |||||
* @mixin UserUserGroupBuilder | |||||
*/ | |||||
class UserUserGroupManager extends BaseManager | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->setContainer(new UserUserGroupContainer()); | |||||
} | |||||
} |
<?php | <?php | ||||
namespace common\logic\User\UserProducer; | |||||
namespace common\logic\User\UserUserGroup; | |||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; |