namespace backend\controllers; | namespace backend\controllers; | ||||
class BackendController extends \common\controllers\CommonController | |||||
use common\logic\PointSale\PointSale\PointSale; | |||||
use common\logic\Product\Product\Product; | |||||
use common\controllers\CommonController; | |||||
class BackendController extends CommonController | |||||
{ | { | ||||
/** | /** | ||||
* Vérifie si l'utilisateur a au moins saisi un produit et un point de vente. | * Vérifie si l'utilisateur a au moins saisi un produit et un point de vente. | ||||
*/ | */ | ||||
public function checkProductsPointsSale() | public function checkProductsPointsSale() | ||||
{ | { | ||||
if (!ProductModel::searchCount() || !PointSaleModel::searchCount()) { | |||||
if (!Product::searchCount() || !PointSale::searchCount()) { | |||||
$this->redirect(['site/index', 'error_products_points_sale' => 1]); | $this->redirect(['site/index', 'error_products_points_sale' => 1]); | ||||
} | } | ||||
} | } |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\logic\Config\TaxRate\TaxRate; | |||||
use Yii; | use Yii; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
*/ | */ | ||||
class TaxRateAdminController extends BackendController | class TaxRateAdminController extends BackendController | ||||
{ | { | ||||
public function behaviors() | |||||
{ | |||||
return [ | |||||
'verbs' => [ | |||||
'class' => VerbFilter::className(), | |||||
'actions' => [ | |||||
'delete' => ['post'], | |||||
], | |||||
], | |||||
'access' => [ | |||||
'class' => AccessControl::className(), | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN; | |||||
} | |||||
] | |||||
], | |||||
], | |||||
]; | |||||
} | |||||
/** | |||||
* Liste les taxes. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function actionIndex() | |||||
{ | |||||
$dataProviderTaxRate = new ActiveDataProvider([ | |||||
'query' => TaxRateModel::find() | |||||
]); | |||||
return $this->render('index', [ | |||||
'dataProviderTaxRate' => $dataProviderTaxRate, | |||||
]); | |||||
} | |||||
/** | |||||
* Crée une taxe. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function actionCreate() | |||||
{ | |||||
$model = new TaxRate(); | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||||
Yii::$app->getSession()->setFlash('success', 'Taxe créé.'); | |||||
return $this->redirect(['index']); | |||||
} else { | |||||
return $this->render('create', [ | |||||
'model' => $model, | |||||
]); | |||||
} | |||||
} | |||||
/** | |||||
* Édition d'une taxe. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function actionUpdate($id) | |||||
{ | |||||
$model = $this->findModel($id); | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||||
Yii::$app->getSession()->setFlash('success', 'Taxe édité.'); | |||||
return $this->redirect(['index']); | |||||
} else { | |||||
return $this->render('update', [ | |||||
'model' => $model, | |||||
]); | |||||
} | |||||
public function behaviors() | |||||
{ | |||||
return [ | |||||
'verbs' => [ | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | |||||
'delete' => ['post'], | |||||
], | |||||
], | |||||
'access' => [ | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | |||||
[ | |||||
'allow' => true, | |||||
'roles' => ['@'], | |||||
'matchCallback' => function ($rule, $action) { | |||||
return $this->isUserCurrentAdmin(); | |||||
} | |||||
] | |||||
], | |||||
], | |||||
]; | |||||
} | |||||
public function actionIndex() | |||||
{ | |||||
$dataProviderTaxRate = new ActiveDataProvider([ | |||||
'query' => TaxRate::find() | |||||
]); | |||||
return $this->render('index', [ | |||||
'dataProviderTaxRate' => $dataProviderTaxRate, | |||||
]); | |||||
} | |||||
public function actionCreate() | |||||
{ | |||||
$model = $this->getLogic()->getTaxRateContainer()->getFactory()->create(); | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||||
$this->setFlash('success', 'Taxe créé.'); | |||||
return $this->redirect(['index']); | |||||
} else { | |||||
return $this->render('create', [ | |||||
'model' => $model, | |||||
]); | |||||
} | } | ||||
/** | |||||
* Supprime une commande récurrente. | |||||
* | |||||
* @param integer $id | |||||
*/ | |||||
public function actionDelete($id) | |||||
{ | |||||
$taxeRate = TaxRateModel::searchOne([ | |||||
'id' => $id | |||||
]) ; | |||||
$taxeRate->delete(); | |||||
Yii::$app->getSession()->setFlash('success', 'Taxe supprimé'); | |||||
return $this->redirect(['tax-rate-admin/index']); | |||||
} | |||||
public function actionUpdate($id) | |||||
{ | |||||
$model = $this->findModel($id); | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||||
$this->setFlash('success', 'Taxe édité.'); | |||||
return $this->redirect(['index']); | |||||
} else { | |||||
return $this->render('update', [ | |||||
'model' => $model, | |||||
]); | |||||
} | } | ||||
/** | |||||
* Finds the Developpement model based on its primary key value. | |||||
* If the model is not found, a 404 HTTP exception will be thrown. | |||||
* @param integer $id | |||||
* @return Developpement the loaded model | |||||
* @throws NotFoundHttpException if the model cannot be found | |||||
*/ | |||||
protected function findModel($id) | |||||
{ | |||||
if (($model = TaxRateModel::findOne($id)) !== null) { | |||||
return $model; | |||||
} else { | |||||
throw new NotFoundHttpException('The requested page does not exist.'); | |||||
} | |||||
} | |||||
public function actionDelete(int $id) | |||||
{ | |||||
$taxeRate = TaxRate::searchOne([ | |||||
'id' => $id | |||||
]); | |||||
$taxeRate->delete(); | |||||
Yii::$app->getSession()->setFlash('success', 'Taxe supprimé'); | |||||
return $this->redirect(['tax-rate-admin/index']); | |||||
} | |||||
protected function findModel($id) | |||||
{ | |||||
if (($model = TaxRate::findOne($id)) !== null) { | |||||
return $model; | |||||
} else { | |||||
throw new NotFoundHttpException('The requested page does not exist.'); | |||||
} | } | ||||
} | |||||
} | } |
<div class="panel-body"> | <div class="panel-body"> | ||||
<h4>Facturation</h4> | <h4>Facturation</h4> | ||||
<?= $form->field($model, 'id_tax_rate_default') | <?= $form->field($model, 'id_tax_rate_default') | ||||
->dropDownList(ArrayHelper::map(TaxRateModel::find()->all(), 'id', function ($model) { | |||||
->dropDownList(ArrayHelper::map(TaxRate::find()->all(), 'id', function ($model) { | |||||
return $model->name; | return $model->name; | ||||
})) | })) | ||||
->label('TVA à appliquer par défaut'); ?> | ->label('TVA à appliquer par défaut'); ?> |
$producer = \common\helpers\GlobalParam::getCurrentProducer(); | $producer = \common\helpers\GlobalParam::getCurrentProducer(); | ||||
$taxRateDefault = $producer->taxRate; | $taxRateDefault = $producer->taxRate; | ||||
$taxRateNamesArray = array_merge(array(0 => 'Tva par défaut'), ArrayHelper::map(TaxRateModel::find()->all(), 'id', function ($model) { | |||||
$taxRateNamesArray = array_merge(array(0 => 'Tva par défaut'), ArrayHelper::map(TaxRate::find()->all(), 'id', function ($model) { | |||||
return $model->name; | return $model->name; | ||||
})); | })); | ||||
$taxRateValuesArray = array_merge(array(0 => $taxRateDefault->value), ArrayHelper::map(TaxRateModel::find()->all(), 'id', function ($model) { | |||||
$taxRateValuesArray = array_merge(array(0 => $taxRateDefault->value), ArrayHelper::map(TaxRate::find()->all(), 'id', function ($model) { | |||||
return $model->value; | return $model->value; | ||||
})); | })); | ||||
foreach ($taxRateValuesArray as $key => $taxRateValue) { | foreach ($taxRateValuesArray as $key => $taxRateValue) { |
use common\logic\Config\TaxRate\TaxRateContainer; | use common\logic\Config\TaxRate\TaxRateContainer; | ||||
use common\logic\Distribution\Distribution\DistributionContainer; | use common\logic\Distribution\Distribution\DistributionContainer; | ||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContainer; | |||||
use common\logic\Distribution\ProductDistribution\ProductDistributionContainer; | |||||
use common\logic\Document\Document\DocumentContainer; | use common\logic\Document\Document\DocumentContainer; | ||||
use common\logic\Order\Order\OrderContainer; | use common\logic\Order\Order\OrderContainer; | ||||
use common\logic\Order\OrderStatusHistory\OrderStatusHistoryContainer; | use common\logic\Order\OrderStatusHistory\OrderStatusHistoryContainer; | ||||
$this->getProducerPriceRangeContainer(), | $this->getProducerPriceRangeContainer(), | ||||
$this->getUserProducerContainer(), | $this->getUserProducerContainer(), | ||||
$this->getOrderSatusHistoryContainer(), | $this->getOrderSatusHistoryContainer(), | ||||
$this->getPointSaleDistributionContainer(), | |||||
$this->getProductDistributionContainer(), | |||||
$this->getProductCategoryContainer(), | $this->getProductCategoryContainer(), | ||||
$this->getProductPointSaleContainer(), | $this->getProductPointSaleContainer(), | ||||
$this->getProductOrderContainer(), | $this->getProductOrderContainer(), | ||||
return new ProductSubscriptionContainer(); | return new ProductSubscriptionContainer(); | ||||
} | } | ||||
public function getPointSaleDistributionContainer(): PointSaleDistributionContainer | |||||
{ | |||||
return new PointSaleDistributionContainer(); | |||||
} | |||||
public function getProductDistributionContainer(): ProductDistributionContainer | |||||
{ | |||||
return new ProductDistributionContainer(); | |||||
} | |||||
/* | /* | ||||
* Hiérarchie des apps | * Hiérarchie des apps | ||||
*/ | */ |
namespace common\controllers; | namespace common\controllers; | ||||
use common\components\BusinessLogic; | use common\components\BusinessLogic; | ||||
use common\logic\User\User\UserModel; | |||||
use yii; | use yii; | ||||
class CommonController extends \yii\web\Controller | class CommonController extends \yii\web\Controller | ||||
return Yii::$app->urlManagerBackend; | return Yii::$app->urlManagerBackend; | ||||
} | } | ||||
public function getUser() | |||||
public function getUserCurrent() | |||||
{ | { | ||||
return Yii::$app->getUser(); | return Yii::$app->getUser(); | ||||
} | } | ||||
public function isUserCurrentAdmin() | |||||
{ | |||||
return $this->getLogic()->getUserContainer()->getSolver()->isAdmin($this->getUserCurrent()); | |||||
} | |||||
public function getRequest() | public function getRequest() | ||||
{ | { | ||||
return Yii::$app->request; | return Yii::$app->request; |
namespace common\forms; | namespace common\forms; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\User\User\UserModel; | 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 = ProducerModel::findOne($this->id_producer); | |||||
$producer = Producer::findOne($this->id_producer); | |||||
if (!$producer) { | if (!$producer) { | ||||
$this->addError($attribute, 'Ce producteur n\'existe pas.'); | $this->addError($attribute, 'Ce producteur n\'existe pas.'); | ||||
} | } |
namespace common\helpers; | namespace common\helpers; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
class CSV | class CSV | ||||
{ | { | ||||
public static function array2csv(array &$array) | public static function array2csv(array &$array) | ||||
{ | { | ||||
$separator = ProducerModel::getConfig('option_csv_separator') ?: ';'; | |||||
$separator = Producer::getConfig('option_csv_separator') ?: ';'; | |||||
if (count($array) == 0) { | if (count($array) == 0) { | ||||
return null; | return null; |
namespace common\helpers; | namespace common\helpers; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
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'] = ProducerModel::searchOne(); | |||||
\Yii::$app->params['producer'] = Producer::searchOne(); | |||||
} | } | ||||
return \Yii::$app->params['producer']; | return \Yii::$app->params['producer']; | ||||
} | } |
namespace common\helpers; | namespace common\helpers; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
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 = ProducerModel::getConfig('tiller'); | |||||
$this->provider_token = ProducerModel::getConfig('tiller_provider_token'); | |||||
$this->restaurant_token = ProducerModel::getConfig('tiller_restaurant_token'); | |||||
$this->producer_tiller = Producer::getConfig('tiller'); | |||||
$this->provider_token = Producer::getConfig('tiller_provider_token'); | |||||
$this->restaurant_token = Producer::getConfig('tiller_restaurant_token'); | |||||
} | } | ||||
public function getOrders($date) | public function getOrders($date) |
* This is the model class for table "tax_rate". | * This is the model class for table "tax_rate". | ||||
* | * | ||||
*/ | */ | ||||
class TaxRateModel extends ActiveRecordCommon | |||||
class TaxRate extends ActiveRecordCommon | |||||
{ | { | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc |
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return TaxRateModel::class; | |||||
return TaxRate::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\FactoryInterface; | use common\logic\FactoryInterface; | ||||
use Stripe\TaxRate; | |||||
class TaxRateFactory extends BaseService implements FactoryInterface | class TaxRateFactory extends BaseService implements FactoryInterface | ||||
{ | { |
public function getAsArray(): array | public function getAsArray(): array | ||||
{ | { | ||||
$taxRateArrayReturn = []; | $taxRateArrayReturn = []; | ||||
$taxRateArray = TaxRateModel::find()->all(); | |||||
$taxRateArray = TaxRate::find()->all(); | |||||
foreach($taxRateArray as $taxRate) { | foreach($taxRateArray as $taxRate) { | ||||
$taxRateArrayReturn[$taxRate->id] = $taxRate; | $taxRateArrayReturn[$taxRate->id] = $taxRate; |
namespace common\logic\Development\DevelopmentPriority; | namespace common\logic\Development\DevelopmentPriority; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\components\ActiveRecordCommon ; | use common\components\ActiveRecordCommon ; | ||||
/** | /** | ||||
public function getProducer() | public function getProducer() | ||||
{ | { | ||||
return $this->hasOne(ProducerModel::class, ['id' => 'id_producer']); | |||||
return $this->hasOne(Producer::class, ['id' => 'id_producer']); | |||||
} | } | ||||
/** | /** |
<?php | |||||
/** | |||||
* Copyright distrib (2018) | |||||
* | |||||
* contact@opendistrib.net | |||||
* | |||||
* Ce logiciel est un programme informatique servant à aider les producteurs | |||||
* à distribuer leur production en circuits courts. | |||||
* | |||||
* Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||||
* respectant les principes de diffusion des logiciels libres. Vous pouvez | |||||
* utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||||
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||||
* sur le site "http://www.cecill.info". | |||||
* | |||||
* En contrepartie de l'accessibilité au code source et des droits de copie, | |||||
* de modification et de redistribution accordés par cette licence, il n'est | |||||
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||||
* seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||||
* titulaire des droits patrimoniaux et les concédants successifs. | |||||
* | |||||
* A cet égard l'attention de l'utilisateur est attirée sur les risques | |||||
* associés au chargement, à l'utilisation, à la modification et/ou au | |||||
* développement et à la reproduction du logiciel par l'utilisateur étant | |||||
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||||
* manipuler et qui le réserve donc à des développeurs et des professionnels | |||||
* avertis possédant des connaissances informatiques approfondies. Les | |||||
* utilisateurs sont donc invités à charger et tester l'adéquation du | |||||
* logiciel à leurs besoins dans des conditions permettant d'assurer la | |||||
* sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||||
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||||
* | |||||
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||||
* pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||||
* termes. | |||||
*/ | |||||
namespace common\logic\Distribution\Distribution; | |||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; | |||||
use common\logic\Distribution\ProductDistribution\ProductDistribution; | |||||
use common\logic\Order\Order\OrderModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\helpers\GlobalParam; | |||||
use common\components\ActiveRecordCommon; | |||||
use common\logic\Product\Product\Product; | |||||
/** | |||||
* This is the model class for table "distribution". | |||||
* | |||||
*/ | |||||
class Distribution extends ActiveRecordCommon | |||||
{ | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public static function tableName() | |||||
{ | |||||
return 'distribution'; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['date'], 'required'], | |||||
[['date'], 'safe'], | |||||
[['active'], 'integer'] | |||||
]; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
'date' => 'Date', | |||||
'active' => 'Actif', | |||||
]; | |||||
} | |||||
/* | |||||
* Relations | |||||
*/ | |||||
public function getProducer() | |||||
{ | |||||
return $this->hasOne(Producer::class, ['id' => 'id_producer']); | |||||
} | |||||
public function getOrder() | |||||
{ | |||||
return $this->hasMany(OrderModel::class, ['id_distribution' => 'id']); | |||||
} | |||||
public function getProductDistribution() | |||||
{ | |||||
return $this->hasMany(ProductDistribution::class, ['id_distribution' => 'id']); | |||||
} | |||||
public function getPointSaleDistribution() | |||||
{ | |||||
return $this->hasMany(PointSaleDistribution::class, ['id_distribution' => 'id']); | |||||
} | |||||
/** | |||||
* Lie un produit aux jours de distribution futurs. | |||||
* | |||||
* @param Product $product | |||||
*/ | |||||
public static function linkProductIncomingDistributions($product) | |||||
{ | |||||
$distributionsArray = self::getIncomingDistributions(); | |||||
foreach ($distributionsArray as $distribution) { | |||||
$distribution->linkProduct($product); | |||||
} | |||||
} | |||||
/** | |||||
* Lie un point de vente aux jours de distribution futurs. | |||||
* | |||||
* @param PointSale $pointSale | |||||
*/ | |||||
public static function linkPointSaleIncomingDistributions($pointSale) | |||||
{ | |||||
$distributionsArray = self::getIncomingDistributions(); | |||||
foreach ($distributionsArray as $distribution) { | |||||
$distribution->linkPointSale($pointSale); | |||||
} | |||||
} | |||||
/** | |||||
* | |||||
* @param type $pointSale | |||||
*/ | |||||
public function linkPointSale($pointSale) | |||||
{ | |||||
$pointSaleDistribution = PointSaleDistribution::searchOne([ | |||||
'id_distribution' => $this->id, | |||||
'id_point_sale' => $pointSale->id | |||||
]); | |||||
if (!$pointSaleDistribution) { | |||||
$pointSaleDistribution = new PointSaleDistribution(); | |||||
$pointSaleDistribution->id_distribution = $this->id; | |||||
$pointSaleDistribution->id_point_sale = $pointSale->id; | |||||
} | |||||
$dayDistribution = date('N', strtotime($this->date)); | |||||
$daysArray = [ | |||||
1 => 'monday', | |||||
2 => 'tuesday', | |||||
3 => 'wednesday', | |||||
4 => 'thursday', | |||||
5 => 'friday', | |||||
6 => 'saturday', | |||||
7 => 'sunday', | |||||
]; | |||||
$pointSaleDistribution->delivery = 0; | |||||
$deliveryDay = 'delivery_' . $daysArray[$dayDistribution]; | |||||
if ($pointSale->$deliveryDay) { | |||||
$pointSaleDistribution->delivery = 1; | |||||
} | |||||
$pointSaleDistribution->save(); | |||||
} | |||||
public function isPointSaleActive($distribution, $pointSaleId) | |||||
{ | |||||
$pointSaleActive = false; | |||||
if ($distribution->pointSaleDistribution) { | |||||
foreach ($distribution->pointSaleDistribution as $pointSaleDistribution) { | |||||
if ($pointSaleDistribution->id_point_sale == $pointSaleId && $pointSaleDistribution->delivery) { | |||||
$pointSaleActive = true; | |||||
} | |||||
} | |||||
} | |||||
return $pointSaleActive; | |||||
} | |||||
/** | |||||
* Active ou désactive la distribution. | |||||
*/ | |||||
public function active($active = true) | |||||
{ | |||||
PointSaleDistribution::setAll($this->id, true); | |||||
$this->active = (int)$active; | |||||
$this->save(); | |||||
if ($active) { | |||||
// ajout des abonnements | |||||
SubscriptionModel::addAll($this->date); | |||||
} | |||||
} | |||||
} |
namespace common\logic\Distribution\Distribution; | namespace common\logic\Distribution\Distribution; | ||||
use common\helpers\GlobalParam; | |||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\BuilderInterface; | use common\logic\BuilderInterface; | ||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; | |||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionBuilder; | |||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionRepository; | |||||
use common\logic\Distribution\ProductDistribution\ProductDistribution; | |||||
use common\logic\Order\Order\OrderModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\Product\Product\Product; | |||||
class DistributionBuilder extends BaseService implements BuilderInterface | class DistributionBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
protected DistributionRepository $distributionRepository; | |||||
protected PointSaleDistributionRepository $pointSaleDistributionRepository; | |||||
protected PointSaleDistributionBuilder $pointSaleDistributionBuilder; | |||||
public function __construct() | |||||
{ | |||||
$this->distributionRepository = $this->loadService(DistributionRepository::class); | |||||
$this->pointSaleDistributionRepository = $this->loadService(PointSaleDistributionRepository::class); | |||||
$this->pointSaleDistributionBuilder = $this->loadService(PointSaleDistributionBuilder::class); | |||||
} | |||||
public function instanciate(Producer $producer, string $date, bool $delivery = true): Distribution | |||||
{ | |||||
$distribution = new Distribution(); | |||||
$distribution->id_producer = $producer->id; | |||||
$distribution->date = $date; | |||||
$distribution->delivery = (int) $delivery; | |||||
return $distribution; | |||||
} | |||||
public function create(Producer $producer, string $date, int $delivery = 1): Distribution | |||||
{ | |||||
$distribution = $this->instanciate($producer, $date, 1); | |||||
$distribution->save(); | |||||
return $distribution; | |||||
} | |||||
public function createIfNotExist(Producer $producer, string $date, int $delivery = 1) | |||||
{ | |||||
$distribution = $this->distributionRepository->getOne($producer, $date); | |||||
if (!$distribution) { | |||||
$distribution = $this->create($producer, $date, 1); | |||||
} | |||||
return $distribution; | |||||
} | |||||
/** | |||||
* Initialise un jour de production. | |||||
*/ | |||||
// initDistribution | |||||
public function init(string $date, Producer $producer = null): Distribution | |||||
{ | |||||
$distribution = null; | |||||
if ($date != '') { | |||||
if (!$producer) { | |||||
$producer = GlobalParam::getCurrentProducer(); | |||||
} | |||||
$distribution = $this->createIfNotExist($producer, $date, 1); | |||||
} | |||||
if ($distribution) { | |||||
$this->initPointSaleDistribution($distribution); | |||||
$this->initProductDistribution($distribution); | |||||
} | |||||
return $distribution; | |||||
} | |||||
public function initPointSaleDistribution(Distribution $distribution): void | |||||
{ | |||||
$countPointSaleDistribution = $this->pointSaleDistributionRepository->countByDistribution($distribution); | |||||
if (!$countPointSaleDistribution) { | |||||
$this->pointSaleDistributionBuilder->initAll($distribution, true); | |||||
} | |||||
} | |||||
public function initProductDistribution(Distribution $distribution) | |||||
{ | |||||
$products = Product::searchAll(); | |||||
$productsDistribution = ProductDistribution::searchAll([ | |||||
'id_distribution' => $distribution->id | |||||
]); | |||||
if (!count($productsDistribution)) { | |||||
foreach ($products as $product) { | |||||
$this->linkProduct($distribution, $product); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Lie un produit à la distribution. | |||||
*/ | |||||
public function linkProduct(Distribution $distribution, Product $product): ProductDistribution | |||||
{ | |||||
$productDistribution = ProductDistribution::searchOne([ | |||||
'id_distribution' => $this->id, | |||||
'id_product' => $product->id | |||||
]); | |||||
if (!$productDistribution) { | |||||
$productDistribution = new ProductDistribution(); | |||||
$productDistribution->id_distribution = $this->id; | |||||
$productDistribution->id_product = $product->id; | |||||
} | |||||
$dayDistribution = date('N', strtotime($this->date)); | |||||
$daysArray = [ | |||||
1 => 'monday', | |||||
2 => 'tuesday', | |||||
3 => 'wednesday', | |||||
4 => 'thursday', | |||||
5 => 'friday', | |||||
6 => 'saturday', | |||||
7 => 'sunday', | |||||
]; | |||||
$productDistribution->active = 0; | |||||
$day = $daysArray[$dayDistribution]; | |||||
if ($product->active && $product->$day) { | |||||
$productDistribution->active = 1; | |||||
} | |||||
$productDistribution->quantity_max = $product->quantity_max; | |||||
$fieldQuantityMax = 'quantity_max_' . $day; | |||||
if (isset($product->$fieldQuantityMax) && $product->$fieldQuantityMax > 0) { | |||||
$productDistribution->quantity_max = $product->$fieldQuantityMax; | |||||
} | |||||
$productDistribution->save(); | |||||
// update prices product order | |||||
$ordersArray = OrderModel::searchAll([ | |||||
'distribution.date' => $this->date, | |||||
'distribution.id_producer' => $this->id_producer | |||||
], | |||||
[ | |||||
'conditions' => 'date_delete IS NULL AND origin != "user"' | |||||
]); | |||||
if ($ordersArray) { | |||||
foreach ($ordersArray as $order) { | |||||
foreach ($order->productOrder as $productOrder) { | |||||
if ($productOrder->id_product == $product->id) { | |||||
$productOrder->price = $product->price; | |||||
$user = false; | |||||
$userProducer = false; | |||||
if (isset($order->user) && $order->user) { | |||||
$user = $order->user; | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $user->id, | |||||
'id_producer' => $order->distribution->id_producer | |||||
]); | |||||
} | |||||
$productOrder->price = $product->getPrice([ | |||||
'user' => $user, | |||||
'user_producer' => $userProducer, | |||||
'point_sale' => $order->pointSale, | |||||
'quantity' => $productOrder->quantity | |||||
]); | |||||
$productOrder->save(); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
return $productDistribution; | |||||
} | |||||
} | } |
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return DistributionModel::class; | |||||
return Distribution::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array | ||||
{ | { | ||||
return [ | return [ | ||||
DistributionFactory::class, | |||||
DistributionSolver::class, | DistributionSolver::class, | ||||
DistributionRepository::class, | DistributionRepository::class, | ||||
DistributionBuilder::class | DistributionBuilder::class | ||||
]; | ]; | ||||
} | } | ||||
public function getFactory(): DistributionFactory | |||||
{ | |||||
return new DistributionFactory(); | |||||
} | |||||
public function getSolver(): DistributionSolver | public function getSolver(): DistributionSolver | ||||
{ | { | ||||
return new DistributionSolver(); | return new DistributionSolver(); |
<?php | |||||
namespace common\logic\Distribution\Distribution; | |||||
use common\logic\BaseService; | |||||
use common\logic\FactoryInterface; | |||||
class DistributionFactory extends BaseService implements FactoryInterface | |||||
{ | |||||
public function create(): DistributionModel | |||||
{ | |||||
$distribution = new DistributionModel(); | |||||
return $distribution; | |||||
} | |||||
} |
<?php | |||||
/** | |||||
* Copyright distrib (2018) | |||||
* | |||||
* contact@opendistrib.net | |||||
* | |||||
* Ce logiciel est un programme informatique servant à aider les producteurs | |||||
* à distribuer leur production en circuits courts. | |||||
* | |||||
* Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||||
* respectant les principes de diffusion des logiciels libres. Vous pouvez | |||||
* utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||||
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||||
* sur le site "http://www.cecill.info". | |||||
* | |||||
* En contrepartie de l'accessibilité au code source et des droits de copie, | |||||
* de modification et de redistribution accordés par cette licence, il n'est | |||||
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||||
* seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||||
* titulaire des droits patrimoniaux et les concédants successifs. | |||||
* | |||||
* A cet égard l'attention de l'utilisateur est attirée sur les risques | |||||
* associés au chargement, à l'utilisation, à la modification et/ou au | |||||
* développement et à la reproduction du logiciel par l'utilisateur étant | |||||
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||||
* manipuler et qui le réserve donc à des développeurs et des professionnels | |||||
* avertis possédant des connaissances informatiques approfondies. Les | |||||
* utilisateurs sont donc invités à charger et tester l'adéquation du | |||||
* logiciel à leurs besoins dans des conditions permettant d'assurer la | |||||
* sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||||
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||||
* | |||||
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||||
* pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||||
* termes. | |||||
*/ | |||||
namespace common\logic\Distribution\Distribution; | |||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\helpers\GlobalParam; | |||||
use common\components\ActiveRecordCommon; | |||||
/** | |||||
* This is the model class for table "production". | |||||
* | |||||
* @property integer $id | |||||
* @property string $date | |||||
* @property integer $active | |||||
*/ | |||||
class DistributionModel extends ActiveRecordCommon | |||||
{ | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public static function tableName() | |||||
{ | |||||
return 'distribution'; | |||||
} | |||||
public function getProducer() | |||||
{ | |||||
return $this->hasOne(ProducerModel::class, ['id' => 'id_producer']); | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['date'], 'required'], | |||||
[['date'], 'safe'], | |||||
[['active'], 'integer'] | |||||
]; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
'date' => 'Date', | |||||
'active' => 'Actif', | |||||
]; | |||||
} | |||||
/* | |||||
* Relations | |||||
*/ | |||||
public function getOrder() | |||||
{ | |||||
return $this->hasMany(OrderModel::className(), ['id_distribution' => 'id']); | |||||
} | |||||
public function getProductDistribution() | |||||
{ | |||||
return $this->hasMany(ProductDistributionModel::className(), ['id_distribution' => 'id']); | |||||
} | |||||
public function getPointSaleDistribution() | |||||
{ | |||||
return $this->hasMany(PointSaleDistributionModel::className(), ['id_distribution' => 'id']) ; | |||||
} | |||||
/** | |||||
* Retourne les options de base nécessaires à la fonction de recherche. | |||||
* | |||||
* @return array | |||||
*/ | |||||
public static function defaultOptionsSearch() | |||||
{ | |||||
return [ | |||||
'with' => [], | |||||
'join_with' => [], | |||||
'orderby' => 'date ASC', | |||||
'attribute_id_producer' => 'distribution.id_producer' | |||||
]; | |||||
} | |||||
public function getDate(): string | |||||
{ | |||||
return $this->date; | |||||
} | |||||
/** | |||||
* Retourne si un produit est actif ou non. | |||||
* | |||||
* @param integer $idProduit | |||||
* @return boolean | |||||
*/ | |||||
public function isActiveProduct($idProduit) | |||||
{ | |||||
if ($idProduit && | |||||
isset($this->productDistribution) && | |||||
count($this->productDistribution) > 0) { | |||||
foreach ($this->productDistribution as $productDistribution) { | |||||
if ($productDistribution['id_product'] == $idProduit && | |||||
$productDistribution['active']) { | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
/** | |||||
* Initialise un jour de production. | |||||
* | |||||
* @param string $date | |||||
* @return Production | |||||
*/ | |||||
public static function initDistribution($date, $idProducer = 0) | |||||
{ | |||||
$distribution = null; | |||||
if ($date != '') { | |||||
$paramsDistribution = [ | |||||
'date' => $date | |||||
]; | |||||
if ($idProducer) { | |||||
$paramsDistribution['distribution.id_producer'] = (int)$idProducer; | |||||
} else { | |||||
$idProducer = GlobalParam::getCurrentProducerId(); | |||||
} | |||||
$distribution = DistributionModel::searchOne($paramsDistribution); | |||||
if (!$distribution) { | |||||
$distribution = new Distribution; | |||||
$distribution->date = $date; | |||||
$distribution->delivery = 1; | |||||
$distribution->id_producer = $idProducer; | |||||
$distribution->save(); | |||||
} | |||||
} | |||||
// point_sale_distribution à définir s'ils ne sont pas initialisés | |||||
if ($distribution) { | |||||
$countPointSaleDistribution = PointSaleDistributionModel::searchCount([ | |||||
'id_distribution' => $distribution->id | |||||
]); | |||||
if (!$countPointSaleDistribution) { | |||||
PointSaleDistributionModel::setAll($distribution->id, true); | |||||
} | |||||
} | |||||
// init produits sélectionnés pour cette production | |||||
$products = ProductModel::searchAll(); | |||||
if ($distribution) { | |||||
$productsDistribution = ProductDistributionModel::searchAll([ | |||||
'id_distribution' => $distribution->id | |||||
]); | |||||
if (!count($productsDistribution)) { | |||||
foreach ($products as $product) { | |||||
$distribution->linkProduct($product); | |||||
} | |||||
} | |||||
$distribution->linkProductGift(); | |||||
} | |||||
return $distribution; | |||||
} | |||||
/** | |||||
* Retourne les distributions futures. | |||||
* | |||||
* @return array | |||||
*/ | |||||
public static function getIncomingDistributions() | |||||
{ | |||||
$distributionsArray = DistributionModel::find() | |||||
->where('date > \'' . date('Y-m-d') . '\'') | |||||
->andWhere([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | |||||
'active' => 1 | |||||
]) | |||||
->orderBy('date ASC') | |||||
->all(); | |||||
return $distributionsArray; | |||||
} | |||||
public static function filterDistributionsByDateDelay($distributionsArray) | |||||
{ | |||||
$producer = GlobalParam::getCurrentProducer() ; | |||||
$dateToday = date('Y-m-d') ; | |||||
foreach($distributionsArray as $keyDistribution => $distribution) { | |||||
$dateDistribution = $distribution->date ; | |||||
$dayDistribution = strtolower(date('l', strtotime($dateDistribution))) ; | |||||
$fieldDayDistributionDelay = 'order_delay_'.$dayDistribution ; | |||||
$fieldDayDistributionDeadline = 'order_deadline_'.$dayDistribution ; | |||||
$delay = $producer->order_delay ; | |||||
$deadline = $producer->order_deadline ; | |||||
if($producer->$fieldDayDistributionDelay) { | |||||
$delay = $producer->$fieldDayDistributionDelay ; | |||||
} | |||||
if($producer->$fieldDayDistributionDeadline) { | |||||
$deadline = $producer->$fieldDayDistributionDeadline ; | |||||
} | |||||
$countDaysTodayDistribution = number_format((strtotime($dateDistribution) - strtotime($dateToday)) / (24 * 60 * 60) , 0); | |||||
if(date('H') >= $deadline) { | |||||
$countDaysTodayDistribution -- ; | |||||
} | |||||
if($countDaysTodayDistribution < $delay) { | |||||
unset($distributionsArray[$keyDistribution]) ; | |||||
} | |||||
} | |||||
$newDistributionsArray = [] ; | |||||
foreach($distributionsArray as $distribution) { | |||||
$newDistributionsArray[] = $distribution ; | |||||
} | |||||
return $newDistributionsArray ; | |||||
} | |||||
/** | |||||
* Lie un produit aux jours de distribution futurs. | |||||
* | |||||
* @param Product $product | |||||
*/ | |||||
public static function linkProductIncomingDistributions($product) | |||||
{ | |||||
$distributionsArray = self::getIncomingDistributions(); | |||||
foreach ($distributionsArray as $distribution) { | |||||
$distribution->linkProduct($product); | |||||
} | |||||
} | |||||
/** | |||||
* Lie un produit à la distribution. | |||||
* | |||||
* @param Product $product | |||||
*/ | |||||
public function linkProduct($product) | |||||
{ | |||||
$productDistribution = ProductDistributionModel::searchOne([ | |||||
'id_distribution' => $this->id, | |||||
'id_product' => $product->id | |||||
]); | |||||
if (!$productDistribution) { | |||||
$productDistribution = new ProductDistribution(); | |||||
$productDistribution->id_distribution = $this->id; | |||||
$productDistribution->id_product = $product->id; | |||||
} | |||||
$dayDistribution = date('N', strtotime($this->date)); | |||||
$daysArray = [ | |||||
1 => 'monday', | |||||
2 => 'tuesday', | |||||
3 => 'wednesday', | |||||
4 => 'thursday', | |||||
5 => 'friday', | |||||
6 => 'saturday', | |||||
7 => 'sunday', | |||||
]; | |||||
$productDistribution->active = 0; | |||||
$day = $daysArray[$dayDistribution]; | |||||
if ($product->active && $product->$day) { | |||||
$productDistribution->active = 1; | |||||
} | |||||
$productDistribution->quantity_max = $product->quantity_max; | |||||
$fieldQuantityMax = 'quantity_max_'.$day ; | |||||
if(isset($product->$fieldQuantityMax) && $product->$fieldQuantityMax > 0) { | |||||
$productDistribution->quantity_max = $product->$fieldQuantityMax ; | |||||
} | |||||
$productDistribution->save(); | |||||
// update prices product order | |||||
$ordersArray = OrderModel::searchAll([ | |||||
'distribution.date' => $this->date, | |||||
'distribution.id_producer' => $this->id_producer | |||||
], | |||||
[ | |||||
'conditions' => 'date_delete IS NULL AND origin != "user"' | |||||
]); | |||||
if($ordersArray) { | |||||
foreach($ordersArray as $order) { | |||||
foreach($order->productOrder as $productOrder) { | |||||
if($productOrder->id_product == $product->id) { | |||||
$productOrder->price = $product->price ; | |||||
$user = false; | |||||
$userProducer = false; | |||||
if(isset($order->user) && $order->user) { | |||||
$user = $order->user; | |||||
$userProducer = UserProducerModel::searchOne([ | |||||
'id_user' => $user->id, | |||||
'id_producer' => $order->distribution->id_producer | |||||
]) ; | |||||
} | |||||
$productOrder->price = $product->getPrice([ | |||||
'user' => $user, | |||||
'user_producer' => $userProducer, | |||||
'point_sale' => $order->pointSale, | |||||
'quantity' => $productOrder->quantity | |||||
]); | |||||
$productOrder->save() ; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
return $productDistribution; | |||||
} | |||||
/** | |||||
* Lie le produit "Don" à la distribution | |||||
*/ | |||||
public function linkProductGift() | |||||
{ | |||||
$productGift = ProductModel::getProductGift(); | |||||
if ($productGift) { | |||||
$productDistribution = ProductDistributionModel::searchOne([ | |||||
'id_distribution' => $this->id, | |||||
'id_product' => $productGift->id | |||||
]); | |||||
if (!$productDistribution) { | |||||
$productDistribution = new ProductDistribution(); | |||||
$productDistribution->id_distribution = $this->id; | |||||
$productDistribution->id_product = $productGift->id; | |||||
$productDistribution->active = 1; | |||||
$productDistribution->save(); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Lie un point de vente aux jours de distribution futurs. | |||||
* | |||||
* @param PointSale $pointSale | |||||
*/ | |||||
public static function linkPointSaleIncomingDistributions($pointSale) | |||||
{ | |||||
$distributionsArray = self::getIncomingDistributions(); | |||||
foreach ($distributionsArray as $distribution) { | |||||
$distribution->linkPointSale($pointSale); | |||||
} | |||||
} | |||||
/** | |||||
* | |||||
* @param type $pointSale | |||||
*/ | |||||
public function linkPointSale($pointSale) | |||||
{ | |||||
$pointSaleDistribution = PointSaleDistributionModel::searchOne([ | |||||
'id_distribution' => $this->id, | |||||
'id_point_sale' => $pointSale->id | |||||
]); | |||||
if (!$pointSaleDistribution) { | |||||
$pointSaleDistribution = new PointSaleDistribution(); | |||||
$pointSaleDistribution->id_distribution = $this->id; | |||||
$pointSaleDistribution->id_point_sale = $pointSale->id; | |||||
} | |||||
$dayDistribution = date('N', strtotime($this->date)); | |||||
$daysArray = [ | |||||
1 => 'monday', | |||||
2 => 'tuesday', | |||||
3 => 'wednesday', | |||||
4 => 'thursday', | |||||
5 => 'friday', | |||||
6 => 'saturday', | |||||
7 => 'sunday', | |||||
]; | |||||
$pointSaleDistribution->delivery = 0; | |||||
$deliveryDay = 'delivery_' . $daysArray[$dayDistribution]; | |||||
if ($pointSale->$deliveryDay) { | |||||
$pointSaleDistribution->delivery = 1; | |||||
} | |||||
$pointSaleDistribution->save(); | |||||
} | |||||
public function isPointSaleActive($distribution, $pointSaleId) | |||||
{ | |||||
$pointSaleActive = false ; | |||||
if($distribution->pointSaleDistribution) { | |||||
foreach($distribution->pointSaleDistribution as $pointSaleDistribution) { | |||||
if($pointSaleDistribution->id_point_sale == $pointSaleId && $pointSaleDistribution->delivery) { | |||||
$pointSaleActive = true ; | |||||
} | |||||
} | |||||
} | |||||
return $pointSaleActive ; | |||||
} | |||||
/** | |||||
* Active ou désactive la distribution. | |||||
*/ | |||||
public function active($active = true) | |||||
{ | |||||
PointSaleDistributionModel::setAll($this->id, true); | |||||
$this->active = (int)$active; | |||||
$this->save(); | |||||
if ($active) { | |||||
// ajout des abonnements | |||||
SubscriptionModel::addAll($this->date); | |||||
} | |||||
} | |||||
} |
namespace common\logic\Distribution\Distribution; | namespace common\logic\Distribution\Distribution; | ||||
use common\helpers\GlobalParam; | |||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
class DistributionRepository extends BaseService implements RepositoryInterface | class DistributionRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
/** | |||||
* Retourne les options de base nécessaires à la fonction de recherche. | |||||
*/ | |||||
public function defaultOptionsSearch(): array | |||||
{ | |||||
return [ | |||||
'with' => [], | |||||
'join_with' => [], | |||||
'orderby' => 'date ASC', | |||||
'attribute_id_producer' => 'distribution.id_producer' | |||||
]; | |||||
} | |||||
public function getOne(Producer $producer, string $date) | |||||
{ | |||||
$paramsDistribution = [ | |||||
'date' => $date, | |||||
'distribution.id_producer' => $producer->id | |||||
]; | |||||
return Distribution::searchOne($paramsDistribution); | |||||
} | |||||
/** | |||||
* Récupère les distributions futures. | |||||
*/ | |||||
public function getIncomingDistributions(): array | |||||
{ | |||||
$distributionsArray = Distribution::find() | |||||
->where('date > \'' . date('Y-m-d') . '\'') | |||||
->andWhere([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | |||||
'active' => 1 | |||||
]) | |||||
->orderBy('date ASC') | |||||
->all(); | |||||
return $distributionsArray; | |||||
} | |||||
} | } |
namespace common\logic\Distribution\Distribution; | namespace common\logic\Distribution\Distribution; | ||||
use common\helpers\GlobalParam; | |||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Product\Product\Product; | |||||
use common\logic\SolverInterface; | use common\logic\SolverInterface; | ||||
class DistributionSolver extends BaseService implements SolverInterface | class DistributionSolver extends BaseService implements SolverInterface | ||||
{ | { | ||||
/** | |||||
* Déduit si un produit est actif ou non | |||||
*/ | |||||
public function isActiveProduct(Distribution $distribution, Product $product): bool | |||||
{ | |||||
if ($product->id | |||||
&& isset($distribution->productDistribution) | |||||
&& count($distribution->productDistribution) > 0) { | |||||
foreach ($distribution->productDistribution as $productDistribution) { | |||||
if ($productDistribution['id_product'] == $product->id | |||||
&& $productDistribution['active']) { | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
/* | |||||
* Filtre les distributions par délai de commande. | |||||
*/ | |||||
public function filterDistributionsByDateDelay(array $distributionsArray): array | |||||
{ | |||||
$producer = GlobalParam::getCurrentProducer(); | |||||
$dateToday = date('Y-m-d'); | |||||
foreach ($distributionsArray as $keyDistribution => $distribution) { | |||||
$dateDistribution = $distribution->date; | |||||
$dayDistribution = strtolower(date('l', strtotime($dateDistribution))); | |||||
$fieldDayDistributionDelay = 'order_delay_' . $dayDistribution; | |||||
$fieldDayDistributionDeadline = 'order_deadline_' . $dayDistribution; | |||||
$delay = $producer->order_delay; | |||||
$deadline = $producer->order_deadline; | |||||
if ($producer->$fieldDayDistributionDelay) { | |||||
$delay = $producer->$fieldDayDistributionDelay; | |||||
} | |||||
if ($producer->$fieldDayDistributionDeadline) { | |||||
$deadline = $producer->$fieldDayDistributionDeadline; | |||||
} | |||||
$countDaysTodayDistribution = number_format((strtotime($dateDistribution) - strtotime($dateToday)) / (24 * 60 * 60), 0); | |||||
if (date('H') >= $deadline) { | |||||
$countDaysTodayDistribution--; | |||||
} | |||||
if ($countDaysTodayDistribution < $delay) { | |||||
unset($distributionsArray[$keyDistribution]); | |||||
} | |||||
} | |||||
$newDistributionsArray = []; | |||||
foreach ($distributionsArray as $distribution) { | |||||
$newDistributionsArray[] = $distribution; | |||||
} | |||||
return $newDistributionsArray; | |||||
} | |||||
} | } |
use common\components\ActiveRecordCommon ; | use common\components\ActiveRecordCommon ; | ||||
/** | /** | ||||
* This is the model class for table "production_point_vente". | |||||
* This is the model class for table "point_sale_distribution". | |||||
* | * | ||||
* @property integer $id_distribution | |||||
* @property integer $id_point_sale | |||||
* @property integer $delivery | |||||
*/ | */ | ||||
class PointSaleDistributionModel extends ActiveRecordCommon | |||||
class PointSaleDistribution extends ActiveRecordCommon | |||||
{ | { | ||||
var $points_sale_distribution; | var $points_sale_distribution; | ||||
/** | /** | ||||
] ; | ] ; | ||||
} | } | ||||
/** | |||||
* Définit les jours de livraisons des points de vente pour un jour de | |||||
* production donné. | |||||
* | |||||
* @param integer $id_production | |||||
* @param boolean $bool_livraison | |||||
*/ | |||||
public static function setAll($idDistribution, $boolDelivery) | |||||
{ | |||||
// liaison PointSale / Distribution | |||||
$arrPointsSale = PointSaleModel::find() | |||||
->with(['pointSaleDistribution' => function($q) use ($idDistribution) { | |||||
$q->where(['id_distribution' => $idDistribution]); | |||||
}]) | |||||
->where([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | |||||
]) | |||||
->all(); | |||||
foreach ($arrPointsSale as $pointSale) { | |||||
if(!$pointSale->pointSaleDistribution) { | |||||
$pointSaleDistribution = new PointSaleDistribution(); | |||||
$pointSaleDistribution->id_distribution = $idDistribution; | |||||
$pointSaleDistribution->id_point_sale = $pointSale->id; | |||||
$pointSaleDistribution->save(); | |||||
} | |||||
} | |||||
$distribution = DistributionModel::findOne($idDistribution); | |||||
if ($distribution) { | |||||
$day = date('N', strtotime($distribution->date)); | |||||
$arrPointsSaleDistribution = self::searchAll([ | |||||
'id_distribution' => $idDistribution | |||||
]) ; | |||||
foreach ($arrPointsSaleDistribution as $pointSaleDistribution) { | |||||
if ($boolDelivery && | |||||
(($day == 1 && $pointSaleDistribution->pointSale->delivery_monday) || | |||||
($day == 2 && $pointSaleDistribution->pointSale->delivery_tuesday) || | |||||
($day == 3 && $pointSaleDistribution->pointSale->delivery_wednesday) || | |||||
($day == 4 && $pointSaleDistribution->pointSale->delivery_thursday) || | |||||
($day == 5 && $pointSaleDistribution->pointSale->delivery_friday) || | |||||
($day == 6 && $pointSaleDistribution->pointSale->delivery_saturday) || | |||||
($day == 7 && $pointSaleDistribution->pointSale->delivery_sunday) | |||||
)) { | |||||
$pointSaleDistribution->delivery = 1; | |||||
} else { | |||||
$pointSaleDistribution->delivery = 0; | |||||
} | |||||
$pointSaleDistribution->save(); | |||||
} | |||||
} | |||||
} | |||||
} | } |
<?php | |||||
namespace common\logic\Distribution\PointSaleDistribution; | |||||
use common\helpers\GlobalParam; | |||||
use common\logic\BaseService; | |||||
use common\logic\BuilderInterface; | |||||
use common\logic\Distribution\Distribution\Distribution; | |||||
use common\logic\PointSale\PointSale\PointSale; | |||||
class PointSaleDistributionBuilder extends BaseService implements BuilderInterface | |||||
{ | |||||
/* | |||||
* Instancie un PointSaleDistribution. | |||||
*/ | |||||
public function instanciate(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||||
{ | |||||
$pointSaleDistribution = new PointSaleDistribution(); | |||||
$pointSaleDistribution->id_distribution = $distribution->id; | |||||
$pointSaleDistribution->id_point_sale = $pointSale->id; | |||||
return $pointSaleDistribution; | |||||
} | |||||
/* | |||||
* Crée un PointSaleDistribution. | |||||
*/ | |||||
public function create(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||||
{ | |||||
$pointSaleDistribution = $this->instanciate($distribution, $pointSale); | |||||
$pointSaleDistribution->save(); | |||||
return $pointSaleDistribution; | |||||
} | |||||
/** | |||||
* Initialise les PointSaleDistribution pour une distribution donnée. | |||||
*/ | |||||
// setAll | |||||
public function initAll(Distribution $distribution, bool $delivery): void | |||||
{ | |||||
$arrPointsSale = PointSale::find() | |||||
->with(['pointSaleDistribution' => function($q) use ($distribution) { | |||||
$q->where(['id_distribution' => $distribution->id]); | |||||
}]) | |||||
->where([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | |||||
]) | |||||
->all(); | |||||
foreach ($arrPointsSale as $pointSale) { | |||||
if(!$pointSale->pointSaleDistribution) { | |||||
$this->create($distribution, $pointSale); | |||||
} | |||||
} | |||||
$distribution = Distribution::findOne($distribution->id); | |||||
if ($distribution) { | |||||
$arrPointsSaleDistribution = PointSaleDistribution::searchAll([ | |||||
'id_distribution' => $distribution->id | |||||
]) ; | |||||
foreach ($arrPointsSaleDistribution as $pointSaleDistribution) { | |||||
$this->initDelivery($pointSaleDistribution, $delivery); | |||||
} | |||||
} | |||||
} | |||||
public function initDelivery(PointSaleDistribution $pointSaleDistribution, bool $delivery) | |||||
{ | |||||
$day = date('N', strtotime($pointSaleDistribution->distribution->date)); | |||||
if ($delivery && | |||||
(($day == 1 && $pointSaleDistribution->pointSale->delivery_monday) || | |||||
($day == 2 && $pointSaleDistribution->pointSale->delivery_tuesday) || | |||||
($day == 3 && $pointSaleDistribution->pointSale->delivery_wednesday) || | |||||
($day == 4 && $pointSaleDistribution->pointSale->delivery_thursday) || | |||||
($day == 5 && $pointSaleDistribution->pointSale->delivery_friday) || | |||||
($day == 6 && $pointSaleDistribution->pointSale->delivery_saturday) || | |||||
($day == 7 && $pointSaleDistribution->pointSale->delivery_sunday) | |||||
)) { | |||||
$pointSaleDistribution->delivery = 1; | |||||
} else { | |||||
$pointSaleDistribution->delivery = 0; | |||||
} | |||||
$pointSaleDistribution->save(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Distribution\PointSaleDistribution; | |||||
use common\logic\ContainerInterface; | |||||
class PointSaleDistributionContainer implements ContainerInterface | |||||
{ | |||||
public function getEntityFqcn(): string | |||||
{ | |||||
return PointSaleDistribution::class; | |||||
} | |||||
public function getServices(): array | |||||
{ | |||||
return [ | |||||
PointSaleDistributionRepository::class, | |||||
PointSaleDistributionBuilder::class, | |||||
]; | |||||
} | |||||
public function getRepository(): PointSaleDistributionRepository | |||||
{ | |||||
return new PointSaleDistributionRepository(); | |||||
} | |||||
public function getBuilder(): PointSaleDistributionBuilder | |||||
{ | |||||
return new PointSaleDistributionBuilder(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Distribution\PointSaleDistribution; | |||||
use common\logic\BaseService; | |||||
use common\logic\FactoryInterface; | |||||
class PointSaleDistributionFactory extends BaseService implements FactoryInterface | |||||
{ | |||||
public function create(): PointSaleDistributionModel | |||||
{ | |||||
$pointSaleDistribution = new PointSaleDistributionModel(); | |||||
return $pointSaleDistribution; | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Distribution\PointSaleDistribution; | |||||
use common\logic\BaseService; | |||||
use common\logic\Distribution\Distribution\Distribution; | |||||
use common\logic\RepositoryInterface; | |||||
class PointSaleDistributionRepository extends BaseService implements RepositoryInterface | |||||
{ | |||||
public function countByDistribution(Distribution $distribution): int | |||||
{ | |||||
return PointSaleDistribution::searchCount([ | |||||
'id_distribution' => $distribution->id | |||||
]); | |||||
} | |||||
} |
* @property integer $id_product | * @property integer $id_product | ||||
* @property integer $active | * @property integer $active | ||||
*/ | */ | ||||
class ProductDistributionModel extends ActiveRecordCommon | |||||
class ProductDistribution extends ActiveRecordCommon | |||||
{ | { | ||||
/** | /** | ||||
*/ | */ | ||||
public static function searchByDistribution($idDistribution) | public static function searchByDistribution($idDistribution) | ||||
{ | { | ||||
$arrayProductsDistribution = ProductDistributionModel::searchAll([ | |||||
$arrayProductsDistribution = ProductDistribution::searchAll([ | |||||
'id_distribution' => $idDistribution | 'id_distribution' => $idDistribution | ||||
]) ; | ]) ; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\FactoryInterface; | use common\logic\FactoryInterface; | ||||
class ProductDistributionFactory extends BaseService implements FactoryInterface | |||||
class ProductDistributionBuilder extends BaseService implements FactoryInterface | |||||
{ | { | ||||
public function create(): ProductDistributionModel | |||||
public function create(): ProductDistribution | |||||
{ | { | ||||
$productDistribution = new ProductDistributionModel(); | |||||
$productDistribution = new ProductDistribution(); | |||||
return $productDistribution; | return $productDistribution; | ||||
} | } |
<?php | |||||
namespace common\logic\Distribution\ProductDistribution; | |||||
use common\logic\ContainerInterface; | |||||
class ProductDistributionContainer implements ContainerInterface | |||||
{ | |||||
public function getEntityFqcn(): string | |||||
{ | |||||
return ProductDistribution::class; | |||||
} | |||||
public function getServices(): array | |||||
{ | |||||
return [ | |||||
ProductDistributionRepository::class, | |||||
ProductDistributionBuilder::class, | |||||
]; | |||||
} | |||||
public function getRepository(): ProductDistributionRepository | |||||
{ | |||||
return new ProductDistributionRepository(); | |||||
} | |||||
public function getBuilder(): ProductDistributionBuilder | |||||
{ | |||||
return new ProductDistributionBuilder(); | |||||
} | |||||
} |
<?php | |||||
namespace common\logic\Distribution\ProductDistribution; | |||||
use common\logic\BaseService; | |||||
use common\logic\RepositoryInterface; | |||||
class ProductDistributionRepository extends BaseService implements RepositoryInterface | |||||
{ | |||||
} |
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use kartik\mpdf\Pdf; | use kartik\mpdf\Pdf; | ||||
use yii\base\ErrorException; | use yii\base\ErrorException; | ||||
public function getProducer() | public function getProducer() | ||||
{ | { | ||||
return $this->hasOne(ProducerModel::class, ['id' => 'id_producer']); | |||||
return $this->hasOne(Producer::class, ['id' => 'id_producer']); | |||||
} | } | ||||
public function relationOrders($fieldIdDocument) | public function relationOrders($fieldIdDocument) | ||||
$classLower = 'delivery_note'; | $classLower = 'delivery_note'; | ||||
} | } | ||||
$prefix = ProducerModel::getConfig('document_' . $classLower . '_prefix'); | |||||
$prefix = Producer::getConfig('document_' . $classLower . '_prefix'); | |||||
$oneDocumentExist = $class::searchOne(['status' => DocumentModel::STATUS_VALID], ['orderby' => 'reference DESC']); | $oneDocumentExist = $class::searchOne(['status' => DocumentModel::STATUS_VALID], ['orderby' => 'reference DESC']); | ||||
if ($oneDocumentExist) { | if ($oneDocumentExist) { | ||||
return $prefix . $numReference; | return $prefix . $numReference; | ||||
} else { | } else { | ||||
$firstReference = ProducerModel::getConfig('document_' . $classLower . '_first_reference'); | |||||
$firstReference = Producer::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(ProducerModel::getConfig('document_infos_bottom')) > 0) { | |||||
if (strlen(Producer::getConfig('document_infos_bottom')) > 0) { | |||||
$marginBottom = 40; | $marginBottom = 40; | ||||
} | } | ||||
public function isDisplayOrders() | public function isDisplayOrders() | ||||
{ | { | ||||
$displayOrders = ($this->getClass() == 'Invoice') ? | $displayOrders = ($this->getClass() == 'Invoice') ? | ||||
ProducerModel::getConfig('document_display_orders_invoice') : | |||||
ProducerModel::getConfig('document_display_orders_delivery_note'); | |||||
Producer::getConfig('document_display_orders_invoice') : | |||||
Producer::getConfig('document_display_orders_delivery_note'); | |||||
return $displayOrders; | return $displayOrders; | ||||
} | } | ||||
public function initTaxCalculationMethod() | public function initTaxCalculationMethod() | ||||
{ | { | ||||
$producerTaxCalculationMethod = ProducerModel::getConfig('option_tax_calculation_method'); | |||||
$producerTaxCalculationMethod = Producer::getConfig('option_tax_calculation_method'); | |||||
if ($producerTaxCalculationMethod) { | if ($producerTaxCalculationMethod) { | ||||
$this->tax_calculation_method = $producerTaxCalculationMethod; | $this->tax_calculation_method = $producerTaxCalculationMethod; |
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\Producer\Producer\Producer; | |||||
use common\logic\User\CreditHistory\CreditHistoryModel; | use common\logic\User\CreditHistory\CreditHistoryModel; | ||||
use common\logic\User\User\UserModel; | use common\logic\User\User\UserModel; | ||||
use Yii; | use Yii; | ||||
} | } | ||||
// delete | // delete | ||||
if (ProducerModel::getConfig('option_behavior_cancel_order') == ProducerModel::BEHAVIOR_DELETE_ORDER_DELETE || | |||||
(ProducerModel::getConfig( | |||||
if (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_DELETE || | |||||
(Producer::getConfig( | |||||
'option_behavior_cancel_order' | 'option_behavior_cancel_order' | ||||
) == ProducerModel::BEHAVIOR_DELETE_ORDER_STATUS && strlen($this->date_delete)) || | |||||
) == Producer::BEHAVIOR_DELETE_ORDER_STATUS && strlen($this->date_delete)) || | |||||
$force) { | $force) { | ||||
ProductOrderModel::deleteAll(['id_order' => $this->id]); | ProductOrderModel::deleteAll(['id_order' => $this->id]); | ||||
return parent::delete(); | return parent::delete(); | ||||
} // status 'delete' | } // status 'delete' | ||||
elseif (ProducerModel::getConfig('option_behavior_cancel_order') == ProducerModel::BEHAVIOR_DELETE_ORDER_STATUS) { | |||||
elseif (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS) { | |||||
$this->date_delete = date('Y-m-d H:i:s'); | $this->date_delete = date('Y-m-d H:i:s'); | ||||
return $this->save(); | return $this->save(); | ||||
} | } | ||||
{ | { | ||||
$html = ''; | $html = ''; | ||||
$creditActive = ProducerModel::getConfig('credit'); | |||||
$creditActive = Producer::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 = ProducerModel::getConfig( | |||||
$orderDelay = Producer::getConfig( | |||||
'order_delay', | 'order_delay', | ||||
$this->distribution->id_producer | $this->distribution->id_producer | ||||
); | ); | ||||
$orderDelaySpecific = ProducerModel::getConfig( | |||||
$orderDelaySpecific = Producer::getConfig( | |||||
'order_delay_' . $dayDistribution, | 'order_delay_' . $dayDistribution, | ||||
$this->distribution->id_producer | $this->distribution->id_producer | ||||
); | ); | ||||
$orderDelay = $orderDelaySpecific; | $orderDelay = $orderDelaySpecific; | ||||
} | } | ||||
$orderDeadline = ProducerModel::getConfig( | |||||
$orderDeadline = Producer::getConfig( | |||||
'order_deadline', | 'order_deadline', | ||||
$this->distribution->id_producer | $this->distribution->id_producer | ||||
); | ); | ||||
$orderDeadlineSpecific = ProducerModel::getConfig( | |||||
$orderDeadlineSpecific = Producer::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 = ProducerModel::findOne($idProducer); | |||||
$producer = Producer::findOne($idProducer); | |||||
if (!$this->reference && $producer->option_order_reference_type == ProducerModel::ORDER_REFERENCE_TYPE_YEARLY) { | |||||
if (!$this->reference && $producer->option_order_reference_type == Producer::ORDER_REFERENCE_TYPE_YEARLY) { | |||||
$lastOrder = OrderModel::find()->innerJoinWith('distribution', true) | $lastOrder = OrderModel::find()->innerJoinWith('distribution', true) | ||||
->where(['>=', 'distribution.date', date('Y') . '-01-01']) | ->where(['>=', 'distribution.date', date('Y') . '-01-01']) | ||||
->andWhere([ | ->andWhere([ |
public function getTaxRate() | public function getTaxRate() | ||||
{ | { | ||||
return $this->hasOne(TaxRateModel::className(), ['id' => 'id_tax_rate']); | |||||
return $this->hasOne(TaxRate::className(), ['id' => 'id_tax_rate']); | |||||
} | } | ||||
/** | /** |
namespace common\logic\PointSale\PointSale; | namespace common\logic\PointSale\PointSale; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
* @property integer $id_producer | * @property integer $id_producer | ||||
* @property integer $default | * @property integer $default | ||||
*/ | */ | ||||
class PointSaleModel extends ActiveRecordCommon | |||||
class PointSale extends ActiveRecordCommon | |||||
{ | { | ||||
var $orders = []; | var $orders = []; | ||||
var $revenues = 0; | var $revenues = 0; | ||||
public function processPointProduction() | public function processPointProduction() | ||||
{ | { | ||||
if ($this->point_production) { | if ($this->point_production) { | ||||
PointSaleModel::updateAll( | |||||
PointSale::updateAll( | |||||
['point_production' => 0], | ['point_production' => 0], | ||||
['id_producer' => $this->id_producer] | ['id_producer' => $this->id_producer] | ||||
); | ); | ||||
{ | { | ||||
return strlen($this->credit_functioning) > 0 ? | return strlen($this->credit_functioning) > 0 ? | ||||
$this->credit_functioning : | $this->credit_functioning : | ||||
ProducerModel::getConfig('credit_functioning'); | |||||
Producer::getConfig('credit_functioning'); | |||||
} | } | ||||
/** | /** | ||||
public static function populateDropdownList() | public static function populateDropdownList() | ||||
{ | { | ||||
$pointSalesArrayDropdown = ['' => '--'] ; | $pointSalesArrayDropdown = ['' => '--'] ; | ||||
$pointSalesArray = PointSaleModel::find()->where('id_producer = ' . GlobalParam::getCurrentProducerId())->all() ; | |||||
$pointSalesArray = PointSale::find()->where('id_producer = ' . GlobalParam::getCurrentProducerId())->all() ; | |||||
foreach($pointSalesArray as $pointSale) { | foreach($pointSalesArray as $pointSale) { | ||||
$pointSalesArrayDropdown[$pointSale['id']] = $pointSale['name'] ; | $pointSalesArrayDropdown[$pointSale['id']] = $pointSale['name'] ; |
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return PointSaleModel::class; | |||||
return PointSale::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
class PointSaleFactory extends BaseService implements FactoryInterface | class PointSaleFactory extends BaseService implements FactoryInterface | ||||
{ | { | ||||
public function create(): PointSaleModel | |||||
public function create(): PointSale | |||||
{ | { | ||||
$pointSale = new PointSaleModel(); | |||||
$pointSale = new PointSale(); | |||||
return $pointSale; | return $pointSale; | ||||
} | } |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
class PointSaleSearch extends PointSaleModel | |||||
class PointSaleSearch extends PointSale | |||||
{ | { | ||||
var $delivery ; | var $delivery ; | ||||
var $access_type ; | var $access_type ; | ||||
{ | { | ||||
$optionsSearch = self::defaultOptionsSearch() ; | $optionsSearch = self::defaultOptionsSearch() ; | ||||
$query = PointSaleModel::find() | |||||
$query = PointSale::find() | |||||
->with($optionsSearch['with']) | ->with($optionsSearch['with']) | ||||
->innerJoinWith($optionsSearch['join_with'], true) | ->innerJoinWith($optionsSearch['join_with'], true) | ||||
->where([ | ->where([ |
namespace common\logic\Producer\Producer; | namespace common\logic\Producer\Producer; | ||||
use common\logic\User\User\UserModel; | use common\logic\User\User\UserModel; | ||||
use common\logic\Config\TaxRate\TaxRateModel; | |||||
use common\logic\Config\TaxRate\TaxRate; | |||||
use common\logic\User\UserProducer\UserProducerModel; | use common\logic\User\UserProducer\UserProducerModel; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
* This is the model class for table "producer". | * This is the model class for table "producer". | ||||
* | * | ||||
*/ | */ | ||||
class ProducerModel extends ActiveRecordCommon | |||||
class Producer extends ActiveRecordCommon | |||||
{ | { | ||||
const CREDIT_FUNCTIONING_MANDATORY = 'mandatory'; | const CREDIT_FUNCTIONING_MANDATORY = 'mandatory'; | ||||
const CREDIT_FUNCTIONING_OPTIONAL = 'optional'; | const CREDIT_FUNCTIONING_OPTIONAL = 'optional'; | ||||
'code', | 'code', | ||||
function ($attribute, $params) { | function ($attribute, $params) { | ||||
$code = $this->$attribute; | $code = $this->$attribute; | ||||
$producer = ProducerModel::findOne(['code' => $code]); | |||||
$producer = Producer::findOne(['code' => $code]); | |||||
if ($producer && $producer->id != $this->id) { | if ($producer && $producer->id != $this->id) { | ||||
$this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.'); | $this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.'); | ||||
} | } | ||||
public function getTaxRate() | public function getTaxRate() | ||||
{ | { | ||||
return $this->hasOne(TaxRateModel::class, ['id' => 'id_tax_rate_default']); | |||||
return $this->hasOne(TaxRate::class, ['id' => 'id_tax_rate_default']); | |||||
} | } | ||||
// --- | // --- |
$this->producerSolver = $this->loadService(ProducerSolver::class); | $this->producerSolver = $this->loadService(ProducerSolver::class); | ||||
} | } | ||||
public function init(ProducerModel $producer): void | |||||
public function init(Producer $producer): void | |||||
{ | { | ||||
$this->initSlug($producer); | $this->initSlug($producer); | ||||
$this->initCode($producer); | $this->initCode($producer); | ||||
} | } | ||||
public function initSlug(ProducerModel $producer): void | |||||
public function initSlug(Producer $producer): void | |||||
{ | { | ||||
$cptSlug = 0 ; | $cptSlug = 0 ; | ||||
do { | do { | ||||
} while($this->producerRepository->getOneBySlug($producer->slug)) ; | } while($this->producerRepository->getOneBySlug($producer->slug)) ; | ||||
} | } | ||||
public function initCode(ProducerModel $producer): void | |||||
public function initCode(Producer $producer): void | |||||
{ | { | ||||
$producer->code = Password::generate(); | $producer->code = Password::generate(); | ||||
} | } | ||||
return $userProducer; | return $userProducer; | ||||
} | } | ||||
public function updateOpendistribVersion(ProducerModel $producer) | |||||
public function updateOpendistribVersion(Producer $producer) | |||||
{ | { | ||||
$versionsArray = Opendistrib::getVersions(); | $versionsArray = Opendistrib::getVersions(); | ||||
$producer->latest_version_opendistrib = array_values($versionsArray)[0]; | $producer->latest_version_opendistrib = array_values($versionsArray)[0]; | ||||
} | } | ||||
} | } | ||||
public function savePrivateKeyApiStripe(ProducerModel $producer): void | |||||
public function savePrivateKeyApiStripe(Producer $producer): void | |||||
{ | { | ||||
$this->savePrivateKeyStripe( | $this->savePrivateKeyStripe( | ||||
$this->producerSolver->getFilenamePrivateKeyApiStripe($producer), | $this->producerSolver->getFilenamePrivateKeyApiStripe($producer), | ||||
); | ); | ||||
} | } | ||||
public function savePrivateKeyEndpointStripe(ProducerModel $producer): bool | |||||
public function savePrivateKeyEndpointStripe(Producer $producer): bool | |||||
{ | { | ||||
$this->savePrivateKeyStripe( | $this->savePrivateKeyStripe( | ||||
$this->producerSolver->getFilenamePrivateKeyEndpointStripe($producer), | $this->producerSolver->getFilenamePrivateKeyEndpointStripe($producer), |
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return ProducerModel::class; | |||||
return Producer::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
{ | { | ||||
public function create() | public function create() | ||||
{ | { | ||||
$producer = new ProducerModel(); | |||||
$producer = new Producer(); | |||||
$producer->order_deadline = ProducerModel::ORDER_DEADLINE_DEFAULT; | |||||
$producer->order_delay = ProducerModel::ORDER_DELAY_DEFAULT; | |||||
$producer->order_deadline = Producer::ORDER_DEADLINE_DEFAULT; | |||||
$producer->order_delay = Producer::ORDER_DELAY_DEFAULT; | |||||
return $producer; | return $producer; | ||||
} | } |
public function getOneById($id) | public function getOneById($id) | ||||
{ | { | ||||
return ProducerModel::searchOne(['id' => $id]); | |||||
return Producer::searchOne(['id' => $id]); | |||||
} | } | ||||
public function getOneBySlug($slug) | public function getOneBySlug($slug) | ||||
{ | { | ||||
return ProducerModel::searchOne(['slug' => $slug]); | |||||
return Producer::searchOne(['slug' => $slug]); | |||||
} | } | ||||
public function queryActive() | public function queryActive() | ||||
{ | { | ||||
return ProducerModel::find() | |||||
return Producer::find() | |||||
->where([ | ->where([ | ||||
'active' => true, | 'active' => true, | ||||
]) | ]) | ||||
*/ | */ | ||||
public function getOneDemoAccount() | public function getOneDemoAccount() | ||||
{ | { | ||||
return ProducerModel::find()->where('name LIKE \'Démo\'')->one(); | |||||
return Producer::find()->where('name LIKE \'Démo\'')->one(); | |||||
} | } | ||||
/** | /** | ||||
*/ | */ | ||||
public static function getPopulateDropdown() | public static function getPopulateDropdown() | ||||
{ | { | ||||
$producers = ProducerModel::find() | |||||
$producers = Producer::find() | |||||
->where([ | ->where([ | ||||
'active' => true, | 'active' => true, | ||||
]) | ]) | ||||
/** | /** | ||||
* Retourne le CA du producteur pour un mois donné | * Retourne le CA du producteur pour un mois donné | ||||
*/ | */ | ||||
public function getTurnover(ProducerModel $producer, string $period = '', bool $format = false) | |||||
public function getTurnover(Producer $producer, string $period = '', bool $format = false) | |||||
{ | { | ||||
if (!$period) { | if (!$period) { | ||||
$period = date('Y-m'); | $period = date('Y-m'); | ||||
} | } | ||||
} | } | ||||
public function getAmountToBeBilledByMonth(ProducerModel $producer, $month, $format = false) | |||||
public function getAmountToBeBilledByMonth(Producer $producer, $month, $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(ProducerModel $producer, $label, $numberOfMonths = 1) | |||||
public function getSummaryAmountsToBeBilled(Producer $producer, $label, $numberOfMonths = 1) | |||||
{ | { | ||||
$text = ''; | $text = ''; | ||||
$numMonthCurrent = date('m'); | $numMonthCurrent = date('m'); | ||||
return $text; | return $text; | ||||
} | } | ||||
public function getAmountBilledLastMonth(ProducerModel $producer) | |||||
public function getAmountBilledLastMonth(Producer $producer) | |||||
{ | { | ||||
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(ProducerModel $producer) | |||||
public function getOnlinePaymentMinimumAmount(Producer $producer) | |||||
{ | { | ||||
$onlinePaymentMinimumAmount = $this->getConfig('option_online_payment_minimum_amount'); | $onlinePaymentMinimumAmount = $this->getConfig('option_online_payment_minimum_amount'); | ||||
if (!$onlinePaymentMinimumAmount) { | if (!$onlinePaymentMinimumAmount) { | ||||
$onlinePaymentMinimumAmount = ProducerModel::ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT; | |||||
$onlinePaymentMinimumAmount = Producer::ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT; | |||||
} | } | ||||
return $onlinePaymentMinimumAmount; | return $onlinePaymentMinimumAmount; |
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. | ||||
* | |||||
*/ | */ | ||||
public function isDemo(ProducerModel $producer): bool | |||||
public function isDemo(Producer $producer): bool | |||||
{ | { | ||||
if (strpos($producer->name, 'Démo') !== false) { | if (strpos($producer->name, 'Démo') !== false) { | ||||
return true; | return true; | ||||
return false; | return false; | ||||
} | } | ||||
public function getFullAddress(ProducerModel $producer, $nl2br = false) | |||||
public function getFullAddress(Producer $producer, $nl2br = false) | |||||
{ | { | ||||
$address = ''; | $address = ''; | ||||
$address .= $producer->name . "\n"; | $address .= $producer->name . "\n"; | ||||
return $address; | return $address; | ||||
} | } | ||||
public function getHtmlLogo(ProducerModel $producer) | |||||
public function getHtmlLogo(Producer $producer) | |||||
{ | { | ||||
$html = ''; | $html = ''; | ||||
return $html; | return $html; | ||||
} | } | ||||
public function getUrlLogo(ProducerModel $producer): string | |||||
public function getUrlLogo(Producer $producer): string | |||||
{ | { | ||||
return \Yii::$app->urlManagerProducer->getHostInfo() . '/' . \Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $producer->logo; | return \Yii::$app->urlManagerProducer->getHostInfo() . '/' . \Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $producer->logo; | ||||
} | } | ||||
public function getEmailOpendistrib(ProducerModel $producer): string | |||||
public function getEmailOpendistrib(Producer $producer): string | |||||
{ | { | ||||
return $producer->slug . '@opendistrib.net'; | return $producer->slug . '@opendistrib.net'; | ||||
} | } | ||||
public function getMainContact(ProducerModel $producer): ?UserModel | |||||
public function getMainContact(Producer $producer): ?UserModel | |||||
{ | { | ||||
if ($producer->contact) { | if ($producer->contact) { | ||||
foreach ($producer->contact as $contact) { | foreach ($producer->contact as $contact) { | ||||
return null; | return null; | ||||
} | } | ||||
public function isUpToDateWithOpendistribVersion(ProducerModel $producer): bool | |||||
public function isUpToDateWithOpendistribVersion(Producer $producer): bool | |||||
{ | { | ||||
return $producer->latest_version_opendistrib == GlobalParam::getOpendistribVersion(); | return $producer->latest_version_opendistrib == GlobalParam::getOpendistribVersion(); | ||||
} | } | ||||
public function isBillingTypeClassic(ProducerModel $producer): bool | |||||
public function isBillingTypeClassic(Producer $producer): bool | |||||
{ | { | ||||
return $producer->option_billing_type == ProducerModel::BILLING_TYPE_CLASSIC; | |||||
return $producer->option_billing_type == Producer::BILLING_TYPE_CLASSIC; | |||||
} | } | ||||
public function isBillingTypeFreePrice(ProducerModel $producer) | |||||
public function isBillingTypeFreePrice(Producer $producer) | |||||
{ | { | ||||
return $producer->option_billing_type == ProducerModel::BILLING_TYPE_FREE_PRICE; | |||||
return $producer->option_billing_type == Producer::BILLING_TYPE_FREE_PRICE; | |||||
} | } | ||||
/** | /** | ||||
* le producteur. | * le producteur. | ||||
* | * | ||||
*/ | */ | ||||
public function getFreePrice(ProducerModel $producer, $format = true) | |||||
public function getFreePrice(Producer $producer, $format = true) | |||||
{ | { | ||||
if (!is_null($producer->free_price)) { | if (!is_null($producer->free_price)) { | ||||
if ($format) { | if ($format) { | ||||
} | } | ||||
} | } | ||||
public function getSpecificDelays(ProducerModel $producer): array | |||||
public function getSpecificDelays(Producer $producer): array | |||||
{ | { | ||||
$array = []; | $array = []; | ||||
$daysArray = [ | $daysArray = [ | ||||
return $array; | return $array; | ||||
} | } | ||||
public function hasSpecificDelays(ProducerModel $producer): bool | |||||
public function hasSpecificDelays(Producer $producer): bool | |||||
{ | { | ||||
$daysArray = [ | $daysArray = [ | ||||
'monday', | 'monday', | ||||
return false; | return false; | ||||
} | } | ||||
public function getFilenamePrivateKeyApiStripe(ProducerModel $producer) | |||||
public function getFilenamePrivateKeyApiStripe(Producer $producer) | |||||
{ | { | ||||
return '../../common/config/stripe/api-' . $producer->id . '.key'; | return '../../common/config/stripe/api-' . $producer->id . '.key'; | ||||
} | } | ||||
public function getFilenamePrivateKeyEndpointStripe(ProducerModel $producer) | |||||
public function getFilenamePrivateKeyEndpointStripe(Producer $producer) | |||||
{ | { | ||||
return '../../common/config/stripe/endpoint-' . $producer->id . '.key'; | return '../../common/config/stripe/endpoint-' . $producer->id . '.key'; | ||||
} | } | ||||
return ''; | return ''; | ||||
} | } | ||||
public function getPrivateKeyApiStripe(ProducerModel $producer) | |||||
public function getPrivateKeyApiStripe(Producer $producer) | |||||
{ | { | ||||
return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyApiStripe($producer)); | return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyApiStripe($producer)); | ||||
} | } | ||||
public function getPrivateKeyEndpointStripe(ProducerModel $producer) | |||||
public function getPrivateKeyEndpointStripe(Producer $producer) | |||||
{ | { | ||||
return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyEndpointStripe($producer)); | return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyEndpointStripe($producer)); | ||||
} | } | ||||
public function isOnlinePaymentActive(ProducerModel $producer) | |||||
public function isOnlinePaymentActive(Producer $producer) | |||||
{ | { | ||||
return $producer->online_payment | return $producer->online_payment | ||||
|| ($producer->option_stripe_mode_test | || ($producer->option_stripe_mode_test | ||||
&& \Yii::$app->user->identity->status > 10); | && \Yii::$app->user->identity->status > 10); | ||||
} | } | ||||
public function isOnlinePaymentActiveAndTypeOrder(ProducerModel $producer): bool | |||||
public function isOnlinePaymentActiveAndTypeOrder(Producer $producer): bool | |||||
{ | { | ||||
return $this->isOnlinePaymentActive($producer) | return $this->isOnlinePaymentActive($producer) | ||||
&& $producer->option_online_payment_type == 'order'; | && $producer->option_online_payment_type == 'order'; | ||||
} | } | ||||
public function isBillingFrequencyMonthly(ProducerModel $producer): bool | |||||
public function isBillingFrequencyMonthly(Producer $producer): bool | |||||
{ | { | ||||
return $producer->option_billing_frequency == ProducerModel::BILLING_FREQUENCY_MONTHLY; | |||||
return $producer->option_billing_frequency == Producer::BILLING_FREQUENCY_MONTHLY; | |||||
} | } | ||||
public function isBillingFrequencyQuarterly(ProducerModel $producer): bool | |||||
public function isBillingFrequencyQuarterly(Producer $producer): bool | |||||
{ | { | ||||
return $producer->option_billing_frequency == ProducerModel::BILLING_FREQUENCY_QUARTERLY; | |||||
return $producer->option_billing_frequency == Producer::BILLING_FREQUENCY_QUARTERLY; | |||||
} | } | ||||
public function isBillingFrequencyBiannual(ProducerModel $producer): bool | |||||
public function isBillingFrequencyBiannual(Producer $producer): bool | |||||
{ | { | ||||
return $producer->option_billing_frequency == ProducerModel::BILLING_FREQUENCY_BIANNUAL; | |||||
return $producer->option_billing_frequency == Producer::BILLING_FREQUENCY_BIANNUAL; | |||||
} | } | ||||
} | } |
class ProducerUtils extends BaseService implements UtilsInterface | class ProducerUtils extends BaseService implements UtilsInterface | ||||
{ | { | ||||
public function sendEmailNewProducer(ProducerModel $producer) | |||||
public function sendEmailNewProducer(Producer $producer) | |||||
{ | { | ||||
\Yii::$app->mailer->compose( | \Yii::$app->mailer->compose( | ||||
[ | [ |
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\Producer\Producer\Producer; | |||||
use Yii; | use Yii; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
* This is the model class for table "product". | * This is the model class for table "product". | ||||
* | * | ||||
*/ | */ | ||||
class ProductModel extends ActiveRecordCommon | |||||
class Product extends ActiveRecordCommon | |||||
{ | { | ||||
public $total = 0; | public $total = 0; | ||||
public $apply_distributions = true; | public $apply_distributions = true; | ||||
public function afterFind() | public function afterFind() | ||||
{ | { | ||||
if ($this->taxRate == null) { | if ($this->taxRate == null) { | ||||
$producer = ProducerModel::searchOne(['id' => GlobalParam::getCurrentProducerId()]); | |||||
$producer = Producer::searchOne(['id' => GlobalParam::getCurrentProducerId()]); | |||||
if ($producer) { | if ($producer) { | ||||
$this->populateRelation('taxRate', $producer->taxRate); | $this->populateRelation('taxRate', $producer->taxRate); | ||||
} | } | ||||
} | } | ||||
$this->wording_unit = ProductModel::strUnit($this->unit); | |||||
$this->wording_unit = Product::strUnit($this->unit); | |||||
$this->price_with_tax = $this->getPriceWithTax(); | $this->price_with_tax = $this->getPriceWithTax(); | ||||
parent::afterFind(); | parent::afterFind(); | ||||
public function getTaxRate() | public function getTaxRate() | ||||
{ | { | ||||
return $this->hasOne(TaxRateModel::className(), ['id' => 'id_tax_rate']); | |||||
return $this->hasOne(TaxRate::className(), ['id' => 'id_tax_rate']); | |||||
} | } | ||||
public function getProductPrice() | public function getProductPrice() | ||||
*/ | */ | ||||
public static function searchByDistribution($idDistribution) | public static function searchByDistribution($idDistribution) | ||||
{ | { | ||||
return ProductModel::find() | |||||
return Product::find() | |||||
->leftJoin('product_distribution', 'product.id = product_distribution.id_product') | ->leftJoin('product_distribution', 'product.id = product_distribution.id_product') | ||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
*/ | */ | ||||
public static function getProductGift() | public static function getProductGift() | ||||
{ | { | ||||
$productGift = ProductModel::find() | |||||
$productGift = Product::find() | |||||
->where([ | ->where([ | ||||
'product.id_producer' => 0 | 'product.id_producer' => 0 | ||||
]) | ]) |
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return ProductModel::class; | |||||
return Product::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
class ProductFactory extends BaseService implements FactoryInterface | class ProductFactory extends BaseService implements FactoryInterface | ||||
{ | { | ||||
public function create(): ProductModel | |||||
public function create(): Product | |||||
{ | { | ||||
$product = new ProductModel(); | |||||
$product = new Product(); | |||||
return $product; | return $product; | ||||
} | } |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
class ProductSearch extends ProductModel | |||||
class ProductSearch extends Product | |||||
{ | { | ||||
public function rules() | public function rules() | ||||
{ | { | ||||
{ | { | ||||
$optionsSearch = self::defaultOptionsSearch() ; | $optionsSearch = self::defaultOptionsSearch() ; | ||||
$query = ProductModel::find() | |||||
$query = Product::find() | |||||
->with($optionsSearch['with']) | ->with($optionsSearch['with']) | ||||
->innerJoinWith($optionsSearch['join_with'], true) | ->innerJoinWith($optionsSearch['join_with'], true) | ||||
->where(['product.id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['product.id_producer' => GlobalParam::getCurrentProducerId()]) |
namespace common\logic\Subscription\Subscription; | namespace common\logic\Subscription\Subscription; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\User\CreditHistory\CreditHistoryModel; | use common\logic\User\CreditHistory\CreditHistoryModel; | ||||
use common\logic\User\UserProducer\UserProducerModel; | use common\logic\User\UserProducer\UserProducerModel; | ||||
use Yii; | use Yii; | ||||
public function getProducer() | public function getProducer() | ||||
{ | { | ||||
return $this->hasOne( | return $this->hasOne( | ||||
ProducerModel::class, | |||||
Producer::class, | |||||
['id' => 'id_producer'] | ['id' => 'id_producer'] | ||||
); | ); | ||||
} | } | ||||
$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 && ProducerModel::getConfig('credit') && $pointSale->credit) { | |||||
if ($creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_OPTIONAL) { | |||||
if ($order->id_user && Producer::getConfig('credit') && $pointSale->credit) { | |||||
if ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { | |||||
$order->auto_payment = 0; | $order->auto_payment = 0; | ||||
} elseif ($creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_MANDATORY) { | |||||
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) { | |||||
$order->auto_payment = 1; | $order->auto_payment = 1; | ||||
} elseif ($creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_USER) { | |||||
} elseif ($creditFunctioning == Producer::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 = ProducerModel::getConfig('order_deadline'); | |||||
$orderDeadline = Producer::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 = ProducerModel::getConfig('credit'); | |||||
$configCredit = Producer::getConfig('credit'); | |||||
$countOrdersDeleted = 0; | $countOrdersDeleted = 0; | ||||
if ($ordersArray && count($ordersArray)) { | if ($ordersArray && count($ordersArray)) { |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\BuilderInterface; | use common\logic\BuilderInterface; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
class UserBuilder extends BaseService implements BuilderInterface | class UserBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
$user->generateAuthKey(); | $user->generateAuthKey(); | ||||
} | } | ||||
public function initProducer(UserModel $user, ProducerModel $producer) | |||||
public function initProducer(UserModel $user, Producer $producer) | |||||
{ | { | ||||
$user->id_producer = $producer->id; | $user->id_producer = $producer->id; | ||||
$user->status = UserModel::STATUS_PRODUCER; | $user->status = UserModel::STATUS_PRODUCER; |
{ | { | ||||
return [ | return [ | ||||
UserFactory::class, | UserFactory::class, | ||||
UserSolver::class, | |||||
UserRepository::class, | UserRepository::class, | ||||
UserBuilder::class, | UserBuilder::class, | ||||
UserUtils::class, | UserUtils::class, | ||||
return new UserFactory(); | return new UserFactory(); | ||||
} | } | ||||
public function getSolver(): UserSolver | |||||
{ | |||||
return new UserSolver(); | |||||
} | |||||
public function getRepository(): UserRepository | public function getRepository(): UserRepository | ||||
{ | { | ||||
return new UserRepository(); | return new UserRepository(); |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
use common\logic\User\UserProducer\UserProducerRepository; | use common\logic\User\UserProducer\UserProducerRepository; | ||||
use yii\db\Query; | use yii\db\Query; | ||||
* Retourne le crédit de l'utilisateur pour un producteur donné. | * Retourne le crédit de l'utilisateur pour un producteur donné. | ||||
* | * | ||||
*/ | */ | ||||
public function getCredit(UserModel $user, ProducerModel $producer): float | |||||
public function getCredit(UserModel $user, Producer $producer): float | |||||
{ | { | ||||
$userProducer = $this->userProducerRepository->getOne($user, $producer); | $userProducer = $this->userProducerRepository->getOne($user, $producer); | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\UtilsInterface; | use common\logic\UtilsInterface; | ||||
class UserUtils extends BaseService implements UtilsInterface | class UserUtils extends BaseService implements UtilsInterface | ||||
{ | { | ||||
public function sendEmailSignup(UserModel $user, ProducerModel $producer) | |||||
public function sendEmailSignup(UserModel $user, Producer $producer) | |||||
{ | { | ||||
\Yii::$app->mailer->compose( | \Yii::$app->mailer->compose( | ||||
[ | [ | ||||
public function sendMailWelcome(UserModel $user, string $password): void | public function sendMailWelcome(UserModel $user, string $password): void | ||||
{ | { | ||||
if (strlen($user->email)) { | if (strlen($user->email)) { | ||||
$producer = ProducerModel::findOne(GlobalParam::getCurrentProducerId()); | |||||
$producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | |||||
\Yii::$app->mailer->compose(); | \Yii::$app->mailer->compose(); | ||||
$mail = \Yii::$app->mailer->compose( | $mail = \Yii::$app->mailer->compose( | ||||
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $user, 'producer' => $producer, 'password' => $password] | ['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $user, 'producer' => $producer, 'password' => $password] |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\BuilderInterface; | use common\logic\BuilderInterface; | ||||
use common\logic\Order\Order\OrderModel; | use common\logic\Order\Order\OrderModel; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\User\CreditHistory\CreditHistoryModel; | use common\logic\User\CreditHistory\CreditHistoryModel; | ||||
use common\logic\User\CreditHistory\CreditHistorySolver; | use common\logic\User\CreditHistory\CreditHistorySolver; | ||||
public function isCreditLimitCrossed($oldCredit, $newCredit) | public function isCreditLimitCrossed($oldCredit, $newCredit) | ||||
{ | { | ||||
$creditLimitReminder = ProducerModel::getConfig('credit_limit_reminder'); | |||||
$creditLimitReminder = Producer::getConfig('credit_limit_reminder'); | |||||
return !is_null($creditLimitReminder) && | return !is_null($creditLimitReminder) && | ||||
$oldCredit > $creditLimitReminder | $oldCredit > $creditLimitReminder |
namespace common\logic\User\UserProducer; | namespace common\logic\User\UserProducer; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\User\User\UserModel; | use common\logic\User\User\UserModel; | ||||
use Yii; | use Yii; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
public function getProducer() | public function getProducer() | ||||
{ | { | ||||
return $this->hasOne(ProducerModel::class, ['id' => 'id_producer']); | |||||
return $this->hasOne(Producer::class, ['id' => 'id_producer']); | |||||
} | } | ||||
public function getUser() | public function getUser() |
namespace common\logic\User\UserProducer; | namespace common\logic\User\UserProducer; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
use common\logic\User\User\UserModel; | use common\logic\User\User\UserModel; | ||||
class UserProducerRepository extends BaseService implements RepositoryInterface | class UserProducerRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
public function getOne(UserModel $user, ProducerModel $producer) | |||||
public function getOne(UserModel $user, Producer $producer) | |||||
{ | { | ||||
return UserProducerModel::searchOne([ | return UserProducerModel::searchOne([ | ||||
'id_user' => $user->id, | 'id_user' => $user->id, |
use common\helpers\GlobalParam ; | use common\helpers\GlobalParam ; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\models\Order; | 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 = ProducerModel::getConfig('option_payment_info') ; ?> | |||||
<?php $payment_infos = Producer::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 = ProducerModel::getConfig('order_infos') ; ?> | |||||
<?php $order_infos = Producer::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> |
*/ | */ | ||||
use common\helpers\GlobalParam ; | use common\helpers\GlobalParam ; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
$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 = ProducerModel::getConfig('option_payment_info') ; ?> | |||||
<?php $payment_infos = Producer::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 = ProducerModel::getConfig('order_infos') ; ?> | |||||
<?php $order_infos = Producer::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 ?> |
*/ | */ | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
?> | ?> | ||||
<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 = ProducerModel::getConfig('option_payment_info') ; ?> | |||||
<?php $payment_infos = Producer::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 = ProducerModel::getConfig('order_infos') ; ?> | |||||
<?php $order_infos = Producer::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> |
class m190205_164612_ajout_produit_don_aux_distributions_existantes extends Migration { | class m190205_164612_ajout_produit_don_aux_distributions_existantes extends Migration { | ||||
public function up() { | public function up() { | ||||
$distributionsArray = common\logic\Distribution\Distribution\DistributionModel::find()->all() ; | |||||
$distributionsArray = common\logic\Distribution\Distribution\Distribution::find()->all() ; | |||||
foreach($distributionsArray as $distribution) { | foreach($distributionsArray as $distribution) { | ||||
$distribution->linkProductGift() ; | |||||
} | } | ||||
} | } | ||||
use yii\db\Migration; | use yii\db\Migration; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\PointSale\PointSale\PointSaleModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\PointSale\PointSale\PointSale; | |||||
use common\logic\PointSale\UserPointSale\UserPointSaleModel; | use common\logic\PointSale\UserPointSale\UserPointSaleModel; | ||||
class m190226_084104_lien_utilisateur_point_de_vente extends Migration | class m190226_084104_lien_utilisateur_point_de_vente extends Migration | ||||
{ | { | ||||
public function up() | public function up() | ||||
{ | { | ||||
$producersArray = ProducerModel::find()->all() ; | |||||
$producersArray = Producer::find()->all() ; | |||||
foreach($producersArray as $producer) { | foreach($producersArray as $producer) { | ||||
$pointsSaleArray = PointSaleModel::find() | |||||
$pointsSaleArray = PointSale::find() | |||||
->where([ | ->where([ | ||||
'id_producer' => $producer->id | 'id_producer' => $producer->id | ||||
]) | ]) |
use yii\db\Migration; | use yii\db\Migration; | ||||
use yii\db\mysql\Schema; | use yii\db\mysql\Schema; | ||||
use common\logic\Subscription\ProductSubscription\ProductSubscriptionModel; | use common\logic\Subscription\ProductSubscription\ProductSubscriptionModel; | ||||
use common\logic\Product\Product\ProductModel; | |||||
use common\logic\Product\Product\Product; | |||||
class m190515_122438_ajout_champs_price_product_subscription extends Migration { | class m190515_122438_ajout_champs_price_product_subscription extends Migration { | ||||
$this->addColumn('product_subscription', 'price', Schema::TYPE_FLOAT. ' DEFAULT 0') ; | $this->addColumn('product_subscription', 'price', Schema::TYPE_FLOAT. ' DEFAULT 0') ; | ||||
$productsSubscriptionsArray = ProductSubscriptionModel::find()->all() ; | $productsSubscriptionsArray = ProductSubscriptionModel::find()->all() ; | ||||
$productsArray = ProductModel::find()->all() ; | |||||
$productsArray = Product::find()->all() ; | |||||
foreach($productsSubscriptionsArray as $productSubscription) { | foreach($productsSubscriptionsArray as $productSubscription) { | ||||
foreach($productsArray as $product) { | foreach($productsArray as $product) { |
use yii\db\Migration; | use yii\db\Migration; | ||||
use yii\db\mysql\Schema; | use yii\db\mysql\Schema; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
class m190522_091006_option_comportement_annulation_commande extends Migration { | class m190522_091006_option_comportement_annulation_commande extends Migration { | ||||
public function up() { | public function up() { | ||||
$this->addColumn('producer', 'option_behavior_cancel_order', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::BEHAVIOR_DELETE_ORDER_STATUS.'\'') ; | |||||
$this->addColumn('producer', 'option_behavior_cancel_order', Schema::TYPE_STRING.' DEFAULT \''.Producer::BEHAVIOR_DELETE_ORDER_STATUS.'\'') ; | |||||
} | } | ||||
public function down() { | public function down() { |
use yii\db\Migration; | use yii\db\Migration; | ||||
use yii\db\Schema; | use yii\db\Schema; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
class m200601_073309_add_producer_options extends Migration | class m200601_073309_add_producer_options extends Migration | ||||
{ | { | ||||
public function safeUp() | public function safeUp() | ||||
{ | { | ||||
$this->addColumn('producer', 'behavior_home_point_sale_day_list', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK.'\''); | |||||
$this->addColumn('producer', 'behavior_order_select_distribution', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_CALENDAR.'\''); | |||||
$this->addColumn('producer', 'behavior_home_point_sale_day_list', Schema::TYPE_STRING.' DEFAULT \''.Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK.'\''); | |||||
$this->addColumn('producer', 'behavior_order_select_distribution', Schema::TYPE_STRING.' DEFAULT \''.Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_CALENDAR.'\''); | |||||
} | } | ||||
public function safeDown() | public function safeDown() |
use yii\db\Migration; | use yii\db\Migration; | ||||
use yii\db\Schema; | use yii\db\Schema; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
/** | /** | ||||
* Class m220915_072309_producer_add_option_billing_frequency | * Class m220915_072309_producer_add_option_billing_frequency | ||||
*/ | */ | ||||
public function safeUp() | public function safeUp() | ||||
{ | { | ||||
$this->addColumn('producer', 'option_billing_frequency', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::BILLING_FREQUENCY_MONTHLY.'\''); | |||||
$this->addColumn('producer', 'option_billing_frequency', Schema::TYPE_STRING.' DEFAULT \''.Producer::BILLING_FREQUENCY_MONTHLY.'\''); | |||||
} | } | ||||
/** | /** |
use yii\db\Migration; | use yii\db\Migration; | ||||
use yii\db\Schema; | use yii\db\Schema; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
/** | /** | ||||
* Class m220915_083713_producer_add_options_billing | * Class m220915_083713_producer_add_options_billing | ||||
*/ | */ | ||||
public function safeUp() | public function safeUp() | ||||
{ | { | ||||
$this->addColumn('producer', 'option_billing_type', Schema::TYPE_STRING.' DEFAULT \''.ProducerModel::BILLING_TYPE_CLASSIC.'\''); | |||||
$this->addColumn('producer', 'option_billing_type', Schema::TYPE_STRING.' DEFAULT \''.Producer::BILLING_TYPE_CLASSIC.'\''); | |||||
$this->addColumn('producer', 'option_billing_reduction', Schema::TYPE_BOOLEAN.' DEFAULT 0'); | $this->addColumn('producer', 'option_billing_reduction', Schema::TYPE_BOOLEAN.' DEFAULT 0'); | ||||
} | } | ||||
namespace frontend\forms; | namespace frontend\forms; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\User\User\UserModel; | use common\logic\User\User\UserModel; | ||||
use common\logic\Config\TaxRate\TaxRateModel; | |||||
use common\logic\Config\TaxRate\TaxRate; | |||||
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 = ProducerModel::findOne($this->id_producer); | |||||
$producer = Producer::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 = ProducerModel::findOne($this->id_producer); | |||||
$producer = Producer::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 = ProducerModel::findOne($this->id_producer); | |||||
$producer = Producer::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'); | ||||
}], | }], | ||||
// ['free_price', 'number'], | // ['free_price', 'number'], | ||||
['id_tax_rate_default', 'exist', | ['id_tax_rate_default', 'exist', | ||||
'targetClass' => TaxRateModel::className(), | |||||
'targetClass' => TaxRate::className(), | |||||
'targetAttribute' => ['id_tax_rate_default' => 'id']], | 'targetAttribute' => ['id_tax_rate_default' => 'id']], | ||||
['verifyCode', 'captcha', 'message' => 'Veuillez recopier le code de vérification'], | ['verifyCode', 'captcha', 'message' => 'Veuillez recopier le code de vérification'], | ||||
]; | ]; |
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\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\User\User\UserModel; | use common\logic\User\User\UserModel; | ||||
/* @var $this \yii\web\View */ | /* @var $this \yii\web\View */ | ||||
$producer = null; | $producer = null; | ||||
if (!Yii::$app->user->isGuest && \Yii::$app->user->identity->id_producer > 0) { | if (!Yii::$app->user->isGuest && \Yii::$app->user->identity->id_producer > 0) { | ||||
$producer = ProducerModel::searchOne(['id' => \Yii::$app->user->identity->id_producer]); | |||||
$producer = Producer::searchOne(['id' => \Yii::$app->user->identity->id_producer]); | |||||
} | } | ||||
?> | ?> | ||||
<div class="container"> | <div class="container"> | ||||
<?php | <?php | ||||
$producersArray = ProducerModel::find() | |||||
$producersArray = Producer::find() | |||||
->joinWith(['userProducer user_producer']) | ->joinWith(['userProducer user_producer']) | ||||
->where([ | ->where([ | ||||
'user_producer.id_user' => UserModel::getCurrentId(), | 'user_producer.id_user' => UserModel::getCurrentId(), |
<?= $form->field($model, 'postcode') ?> | <?= $form->field($model, 'postcode') ?> | ||||
<?= $form->field($model, 'city') ?> | <?= $form->field($model, 'city') ?> | ||||
<?= $form->field($model, 'id_tax_rate_default') | <?= $form->field($model, 'id_tax_rate_default') | ||||
->dropDownList(ArrayHelper::map(TaxRateModel::find()->all(), 'id', function($model) { return $model->name; }), [ | |||||
->dropDownList(ArrayHelper::map(TaxRate::find()->all(), 'id', function($model) { return $model->name; }), [ | |||||
'prompt' => '--', | 'prompt' => '--', | ||||
]) | ]) | ||||
->label('TVA à appliquer par défaut'); ?> | ->label('TVA à appliquer par défaut'); ?> |
namespace producer\controllers; | namespace producer\controllers; | ||||
use common\helpers\Mailjet; | use common\helpers\Mailjet; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\User\CreditHistory\CreditHistoryModel; | use common\logic\User\CreditHistory\CreditHistoryModel; | ||||
use common\logic\User\User\UserModel; | use common\logic\User\User\UserModel; | ||||
use common\logic\User\UserProducer\UserProducerModel; | use common\logic\User\UserProducer\UserProducerModel; | ||||
*/ | */ | ||||
public function _verifyProducerActive($idProducer) | public function _verifyProducerActive($idProducer) | ||||
{ | { | ||||
$producer = ProducerModel::findOne($idProducer); | |||||
$producer = Producer::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 | ||||
ProducerModel::addUser($user->id, $distribution->id_producer); | |||||
Producer::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 = ProducerModel::getConfig('credit'); | |||||
$creditLimit = ProducerModel::getConfig('credit_limit'); | |||||
$credit = Producer::getConfig('credit'); | |||||
$creditLimit = Producer::getConfig('credit_limit'); | |||||
$creditFunctioning = $pointSale->getCreditFunctioning(); | $creditFunctioning = $pointSale->getCreditFunctioning(); | ||||
$creditUser = $user->getCredit($distribution->id_producer); | $creditUser = $user->getCredit($distribution->id_producer); | ||||
$order = OrderModel::searchOne([ | $order = OrderModel::searchOne([ | ||||
$amountRemaining = $order->getAmount(OrderModel::AMOUNT_REMAINING); | $amountRemaining = $order->getAmount(OrderModel::AMOUNT_REMAINING); | ||||
if ($credit && $pointSale->credit && | if ($credit && $pointSale->credit && | ||||
(($creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_OPTIONAL && $posts['use_credit']) || | |||||
$creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_MANDATORY || | |||||
($creditFunctioning == ProducerModel::CREDIT_FUNCTIONING_USER && $userProducer->credit_active) | |||||
(($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL && $posts['use_credit']) || | |||||
$creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY || | |||||
($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER && $userProducer->credit_active) | |||||
)) { | )) { | ||||
$order->changeOrderStatus('waiting-paiement-by-credit', 'user'); | $order->changeOrderStatus('waiting-paiement-by-credit', 'user'); | ||||
*/ | */ | ||||
if ($isNewOrder) { | if ($isNewOrder) { | ||||
// au client | // au client | ||||
if (ProducerModel::getConfig('option_email_confirm')) { | |||||
if (Producer::getConfig('option_email_confirm')) { | |||||
Mailjet::sendMail($paramsEmail); | Mailjet::sendMail($paramsEmail); | ||||
} | } | ||||
// au producteur | // au producteur | ||||
$contactProducer = $producer->getMainContact(); | $contactProducer = $producer->getMainContact(); | ||||
if (ProducerModel::getConfig('option_email_confirm_producer') && $contactProducer && strlen( | |||||
if (Producer::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 = ProducerModel::searchOne([ | |||||
$producer = Producer::searchOne([ | |||||
'id' => $this->getProducer()->id | 'id' => $this->getProducer()->id | ||||
]); | ]); | ||||
$json['producer'] = [ | $json['producer'] = [ | ||||
$distributionsArray = DistributionModel::filterDistributionsByDateDelay($distributionsArray); | $distributionsArray = DistributionModel::filterDistributionsByDateDelay($distributionsArray); | ||||
// Filtre par point de vente | // Filtre par point de vente | ||||
if ($pointSaleId && $producer->option_order_entry_point == ProducerModel::ORDER_ENTRY_POINT_POINT_SALE) { | |||||
if ($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) { | |||||
$distributionsArrayFilterPointSale = []; | $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 == ProducerModel::ORDER_ENTRY_POINT_POINT_SALE) { | |||||
if ($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) { | |||||
$conditionsOrdersUser[] = 'order.id_point_sale = :id_point_sale'; | $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 = ProducerModel::addUser($user->id, $producer->id); | |||||
$userProducer = Producer::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 = ProducerModel::getConfig('credit_functioning'); | |||||
$creditFunctioningProducer = Producer::getConfig('credit_functioning'); | |||||
$position = 0; | $position = 0; | ||||
foreach ($pointsSaleArray as &$pointSale) { | foreach ($pointsSaleArray as &$pointSale) { |
namespace producer\controllers; | namespace producer\controllers; | ||||
use common\controllers\CommonController; | use common\controllers\CommonController; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\User\User\UserModel; | use common\logic\User\User\UserModel; | ||||
use common\logic\User\UserProducer\UserProducerModel; | use common\logic\User\UserProducer\UserProducerModel; | ||||
return $this->producer ; | return $this->producer ; | ||||
} | } | ||||
else { | else { | ||||
$producer = ProducerModel::find() | |||||
$producer = Producer::find() | |||||
->with('contact') | ->with('contact') | ||||
->where(['slug' => \Yii::$app->getRequest()->getQueryParam('slug_producer')]) | ->where(['slug' => \Yii::$app->getRequest()->getQueryParam('slug_producer')]) | ||||
->one() ; | ->one() ; |
namespace producer\models; | namespace producer\models; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use Yii; | use Yii; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
{ | { | ||||
return [ | return [ | ||||
[['amount'], 'required'], | [['amount'], 'required'], | ||||
[['amount'], 'double', 'min' => ProducerModel::getOnlinePaymentMinimumAmount()], | |||||
[['amount'], 'double', 'min' => Producer::getOnlinePaymentMinimumAmount()], | |||||
]; | ]; | ||||
} | } | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
$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 : '.ProducerModel::getOnlinePaymentMinimumAmount().' €'); ?> | |||||
->hint('Montant minimum : '.Producer::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'] |
*/ | */ | ||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
?> | ?> | ||||
<div class="order-form"> | <div class="order-form"> | ||||
<?php if($idProducer): ?> | <?php if($idProducer): ?> | ||||
<?php | <?php | ||||
$producer = ProducerModel::findOne($idProducer); | |||||
$producer = Producer::findOne($idProducer); | |||||
?> | ?> | ||||
<div id="bar-fixed" class="<?php if($producer->credit): ?>credit<?php else: ?>no-credit<?php endif; ?>"> | <div id="bar-fixed" class="<?php if($producer->credit): ?>credit<?php else: ?>no-credit<?php endif; ?>"> | ||||
<div class="container"> | <div class="container"> |
*/ | */ | ||||
use common\helpers\GlobalParam ; | use common\helpers\GlobalParam ; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
\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 == ProducerModel::ORDER_ENTRY_POINT_DATE): ?> | |||||
<?php if($producer->option_order_entry_point == Producer::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 == ProducerModel::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?> | |||||
<?php if($producer->behavior_order_select_distribution == Producer::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 == ProducerModel::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?> | |||||
<?php if($producer->behavior_order_select_distribution == Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?> | |||||
</div> | </div> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<?php if($producer->behavior_order_select_distribution == ProducerModel::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?> | |||||
<?php if($producer->behavior_order_select_distribution == Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?> | |||||
<div id="distributions-list"> | <div id="distributions-list"> | ||||
<?php $incomingDistributions = DistributionModel::getIncomingDistributions(); ?> | <?php $incomingDistributions = DistributionModel::getIncomingDistributions(); ?> | ||||
<?php foreach($incomingDistributions as $distribution): ?> | <?php foreach($incomingDistributions as $distribution): ?> |
termes. | termes. | ||||
*/ | */ | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
$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 == ProducerModel::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK) { | |||||
if($producer->behavior_home_point_sale_day_list == Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK) { | |||||
$arrayDays = [ | $arrayDays = [ | ||||
'monday' => 'Lundi', | 'monday' => 'Lundi', | ||||
'tuesday' => 'Mardi', | 'tuesday' => 'Mardi', | ||||
return $html ; | return $html ; | ||||
} | } | ||||
elseif($producer->behavior_home_point_sale_day_list == ProducerModel::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_INCOMING_DISTRIBUTIONS) { | |||||
elseif($producer->behavior_home_point_sale_day_list == Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_INCOMING_DISTRIBUTIONS) { | |||||
$html = '' ; | $html = '' ; | ||||
$incomingDistributions = DistributionModel::getIncomingDistributions(); | $incomingDistributions = DistributionModel::getIncomingDistributions(); | ||||
$cpt = 0 ; | $cpt = 0 ; |
termes. | termes. | ||||
*/ | */ | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
\producer\assets\VuejsSubscriptionFormAsset::register($this) ; | \producer\assets\VuejsSubscriptionFormAsset::register($this) ; | ||||
<h3><span>Paiement</span></h3> | <h3><span>Paiement</span></h3> | ||||
<?php if(ProducerModel::getConfig('credit')): ?> | |||||
<?php if(Producer::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> |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Producer\Producer\ProducerModel; | |||||
use common\logic\Producer\Producer\Producer; | |||||
$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(ProducerModel::getConfig('credit')) { | |||||
if(Producer::getConfig('credit')) { | |||||
$columns[] = [ | $columns[] = [ | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'label' => 'Paiement automatique', | 'label' => 'Paiement automatique', |