namespace backend\controllers; | namespace backend\controllers; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Distribution\ProductDistribution\ProductDistribution; | |||||
use common\logic\PointSale\PointSale\PointSale; | |||||
use common\logic\Product\Product\Product; | |||||
use common\logic\Product\Product\ProductSearch; | |||||
use common\logic\Product\ProductPointSale\ProductPointSale; | |||||
use common\logic\Product\ProductPrice\ProductPrice; | |||||
use common\logic\Product\ProductPrice\ProductPriceSearch; | |||||
use common\logic\User\UserProducer\UserProducer; | |||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use yii\helpers\Html; | |||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use common\helpers\Upload; | use common\helpers\Upload; | ||||
} | } | ||||
/** | /** | ||||
* Crée un modèle Produit. | |||||
* Si la création réussit, le navigateur est redirigé vers la page 'index'. | |||||
* | |||||
* @return mixed | |||||
* Crée un Product. | |||||
*/ | */ | ||||
public function actionCreate() | public function actionCreate() | ||||
{ | { | ||||
$model = new Product(); | |||||
$productManager = $this->getProductManager(); | |||||
$distributionManager = $this->getDistributionManager(); | |||||
$model = $productManager->instanciateProduct(); | |||||
$model->active = 1; | $model->active = 1; | ||||
$model->id_producer = GlobalParam::getCurrentProducerId(); | $model->id_producer = GlobalParam::getCurrentProducerId(); | ||||
$model->monday = 1; | $model->monday = 1; | ||||
$model->tuesday = 1; | $model->tuesday = 1; | ||||
$model->wednesday = 1; | $model->wednesday = 1; | ||||
$model->sunday = 1; | $model->sunday = 1; | ||||
$model->available_on_points_sale = 1; | $model->available_on_points_sale = 1; | ||||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||||
if ($model->load(\Yii::$app->request->post()) && $productManager->saveCreate($model)) { | |||||
$lastProductOrder = Product::find()->where('id_producer = :id_producer')->params([':id_producer' => GlobalParam::getCurrentProducerId()])->orderBy('order DESC')->one(); | $lastProductOrder = Product::find()->where('id_producer = :id_producer')->params([':id_producer' => GlobalParam::getCurrentProducerId()])->orderBy('order DESC')->one(); | ||||
if ($lastProductOrder) { | if ($lastProductOrder) { | ||||
} | } | ||||
Upload::uploadFile($model, 'photo'); | Upload::uploadFile($model, 'photo'); | ||||
$model->save(); | |||||
$productManager->saveUpdate($model); | |||||
// availability on points sale | |||||
$this->processAvailabilityPointsSale($model); | $this->processAvailabilityPointsSale($model); | ||||
// link product / distribution | |||||
DistributionModel::linkProductIncomingDistributions($model); | |||||
$distributionManager->addProductIncomingDistributions($model); | |||||
$this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> ajouté'); | $this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> ajouté'); | ||||
} | } | ||||
/** | /** | ||||
* Modifie un modèle Produit existant. | |||||
* Si la modification réussit, le navigateur est redirigé vers la page 'index'. | |||||
* | |||||
* @param integer $id | |||||
* @return mixed | |||||
* Modifie un Product. | |||||
*/ | */ | ||||
public function actionUpdate($id) | public function actionUpdate($id) | ||||
{ | { | ||||
$request = Yii::$app->request; | |||||
$productManager = $this->getProductManager(); | |||||
$distributionManager = $this->getDistributionManager(); | |||||
$request = Yii::$app->request; | |||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
foreach ($model->productPointSale as $productPointSale) { | foreach ($model->productPointSale as $productPointSale) { | ||||
$photoFilenameOld = $model->photo; | $photoFilenameOld = $model->photo; | ||||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||||
if ($model->load(\Yii::$app->request->post()) && $productManager->saveUpdate($model)) { | |||||
Upload::uploadFile($model, 'photo', $photoFilenameOld); | Upload::uploadFile($model, 'photo', $photoFilenameOld); | ||||
$model->save(); | $model->save(); | ||||
} | } | ||||
// availability on points sale | |||||
$this->processAvailabilityPointsSale($model); | $this->processAvailabilityPointsSale($model); | ||||
if ($model->apply_distributions) { | if ($model->apply_distributions) { | ||||
// link product / distribution | |||||
DistributionModel::linkProductIncomingDistributions($model); | |||||
$distributionManager->addProductIncomingDistributions($model); | |||||
} | } | ||||
$this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> modifié'); | $this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> modifié'); | ||||
/** | /** | ||||
* Traite les accès restreints d'un point de vente. | * Traite les accès restreints d'un point de vente. | ||||
*/ | */ | ||||
public function processAvailabilityPointsSale($model) | |||||
public function processAvailabilityPointsSale($product) | |||||
{ | { | ||||
ProductPointSale::deleteAll(['id_product' => $model->id]); | |||||
$pointSaleManager = $this->getPointSaleManager(); | |||||
$productPointSaleManager = $this->getProductPointSaleManager(); | |||||
ProductPointSale::deleteAll(['id_product' => $product->id]); | |||||
if (is_array($model->pointsSale) && count($model->pointsSale)) { | |||||
foreach ($model->pointsSale as $key => $val) { | |||||
$pointSale = PointSale::findOne($val); | |||||
if (is_array($product->pointsSale) && count($product->pointsSale)) { | |||||
foreach ($product->pointsSale as $key => $idPointSale) { | |||||
$pointSale = $pointSaleManager->findOnePointSaleById($idPointSale); | |||||
if ($pointSale) { | if ($pointSale) { | ||||
$productPointSale = new ProductPointSale; | |||||
$productPointSale->id_product = $model->id; | |||||
$productPointSale->id_point_sale = $pointSale->id; | |||||
$productPointSale->available = ($model->available_on_points_sale) ? 0 : 1; | |||||
$productPointSale->save(); | |||||
$productPointSaleManager->createProductPointSale( | |||||
$product, | |||||
$pointSale, | |||||
($product->available_on_points_sale) ? false : true | |||||
); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public function actionPricesList($id) | |||||
public function actionPricesList(int $id) | |||||
{ | { | ||||
$request = Yii::$app->request; | |||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
$searchModel = new ProductPriceSearch(); | $searchModel = new ProductPriceSearch(); | ||||
$conditionsProductPriceExist = [ | $conditionsProductPriceExist = [ | ||||
'id_product' => $idProduct, | 'id_product' => $idProduct, | ||||
'id_user' => $model->id_user ? $model->id_user : null, | |||||
'id_user_group' => $model->id_user_group ? $model->id_user_group : null, | |||||
'id_point_sale' => $model->id_point_sale ? $model->id_point_sale : null, | |||||
'from_quantity' => $model->from_quantity ? $model->from_quantity : null, | |||||
'id_user' => $model->id_user ?? null, | |||||
'id_user_group' => $model->id_user_group ?? null, | |||||
'id_point_sale' => $model->id_point_sale ?? null, | |||||
'from_quantity' => $model->from_quantity ?? null, | |||||
]; | ]; | ||||
$productPriceExist = ProductPrice::findOne($conditionsProductPriceExist); | $productPriceExist = ProductPrice::findOne($conditionsProductPriceExist); | ||||
public function actionPricesUpdate($id) | public function actionPricesUpdate($id) | ||||
{ | { | ||||
$request = Yii::$app->request; | |||||
$model = $this->findModelProductPrice($id); | $model = $this->findModelProductPrice($id); | ||||
$modelProduct = $this->findModel($model->id_product); | $modelProduct = $this->findModel($model->id_product); | ||||
} | } | ||||
/** | /** | ||||
* Supprime un modèle Produit. | |||||
* Si la suppression réussit, le navigateur est redirigé vers la page | |||||
* 'index'. | |||||
* | |||||
* @param integer $id | |||||
* @return mixed | |||||
* Supprime un Product. | |||||
*/ | */ | ||||
public function actionDelete($id, $confirm = false) | |||||
public function actionDelete(int $id, bool $confirm = false) | |||||
{ | { | ||||
$product = $this->findModel($id); | $product = $this->findModel($id); | ||||
if ($confirm) { | if ($confirm) { | ||||
$product->delete(); | $product->delete(); | ||||
ProductDistributionModel::deleteAll(['id_product' => $id]); | |||||
ProductDistribution::deleteAll(['id_product' => $id]); | |||||
$this->setFlash('success', 'Produit <strong>' . Html::encode($product->name) . '</strong> supprimé'); | $this->setFlash('success', 'Produit <strong>' . Html::encode($product->name) . '</strong> supprimé'); | ||||
} else { | } else { | ||||
$this->setFlash('info', 'Souhaitez-vous vraiment supprimer le produit <strong>' . Html::encode($product->name) . '</strong> ? ' | $this->setFlash('info', 'Souhaitez-vous vraiment supprimer le produit <strong>' . Html::encode($product->name) . '</strong> ? ' | ||||
/** | /** | ||||
* Modifie l'ordre des produits. | * Modifie l'ordre des produits. | ||||
* | |||||
* @param array $array | |||||
*/ | */ | ||||
public function actionOrder() | public function actionOrder() | ||||
{ | { | ||||
public function actionAjaxToggleActive($id, $active) | public function actionAjaxToggleActive($id, $active) | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$distributionManager = $this->getDistributionManager(); | |||||
$product = $this->findModel($id); | $product = $this->findModel($id); | ||||
$product->active = (int)$active; | |||||
$product->active = (int) $active; | |||||
$product->save(); | $product->save(); | ||||
DistributionModel::linkProductIncomingDistributions($product); | |||||
$distributionManager->addProductIncomingDistributions($product); | |||||
return ['success', 'id' => $id, 'active' => $active]; | return ['success', 'id' => $id, 'active' => $active]; | ||||
} | } | ||||
/** | /** | ||||
* Recherche un produit en fonction de son ID. | * Recherche un produit en fonction de son ID. | ||||
* | |||||
* @param integer $id | |||||
* @return Produit | |||||
* @throws NotFoundHttpException si le modèle n'est pas trouvé | |||||
*/ | */ | ||||
protected function findModel($id) | |||||
protected function findModel(int $id) | |||||
{ | { | ||||
if (($model = Product::findOne($id)) !== null) { | |||||
return $model; | |||||
$productManager = $this->getProductManager(); | |||||
if (($product = $productManager->findOneProductById($id)) !== null) { | |||||
return $product; | |||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
protected function findModelProductPrice($id) | protected function findModelProductPrice($id) | ||||
{ | { | ||||
if (($model = ProductPrice::findOne($id)) !== null) { | |||||
return $model; | |||||
$productPriceManager = $this->getProductPriceManager(); | |||||
if (($productPrice = $productPriceManager->findOneProductPriceById($id)) !== null) { | |||||
return $productPrice; | |||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
} | } | ||||
} | } |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Document\Quotation\QuotationSearch; | |||||
use common\logic\Order\Order\Order; | |||||
use Yii; | use Yii; | ||||
use yii\base\UserException; | use yii\base\UserException; | ||||
use yii\filters\AccessControl; | |||||
use yii\filters\VerbFilter; | |||||
use yii\helpers\Html; | |||||
class QuotationController extends DocumentController | class QuotationController extends DocumentController | ||||
{ | { | ||||
public function actionTransform($id) | public function actionTransform($id) | ||||
{ | { | ||||
$quotationManager = $this->getQuotationManager(); | |||||
$invoiceManager = $this->getInvoiceManager(); | |||||
$quotation = $this->findModel($id); | $quotation = $this->findModel($id); | ||||
if ($quotation->isStatusValid()) { | |||||
if ($quotationManager->isStatusValid($quotation)) { | |||||
$invoice = new Invoice; | |||||
$invoice->initTaxCalculationMethod(); | |||||
$invoice = $invoiceManager->instanciateInvoice(); | |||||
$invoiceManager->initTaxCalculationMethod($invoice); | |||||
$invoice->id_producer = GlobalParam::getCurrentProducerId(); | $invoice->id_producer = GlobalParam::getCurrentProducerId(); | ||||
$invoice->id_user = $quotation->id_user; | $invoice->id_user = $quotation->id_user; | ||||
$invoice->address = $quotation->address; | $invoice->address = $quotation->address; | ||||
$invoice->comment = $quotation->comment; | $invoice->comment = $quotation->comment; | ||||
$invoice->name = str_replace(['Devis', 'devis'], 'Facture', $quotation->name); | $invoice->name = str_replace(['Devis', 'devis'], 'Facture', $quotation->name); | ||||
$invoice->save(); | |||||
$invoiceManager->saveCreate($invoice); | |||||
Order::updateAll([ | Order::updateAll([ | ||||
'order.id_invoice' => $invoice->id | 'order.id_invoice' => $invoice->id | ||||
throw new UserException('Vous ne pouvez pas transformer en facture un devis non validé.'); | throw new UserException('Vous ne pouvez pas transformer en facture un devis non validé.'); | ||||
} | } | ||||
} | } | ||||
} | } |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\Price; | |||||
use common\logic\Distribution\Distribution\Distribution; | |||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$usersArray = User::findBy()->all(); | |||||
$pointsSaleArray = PointSale::searchAll(); | |||||
// distributions | |||||
$firstDistribution = DistributionModel::searchOne([], [ | |||||
'orderby' => 'date ASC' | |||||
]); | |||||
$lastDistribution = DistributionModel::searchOne([], [ | |||||
'orderby' => 'date DESC' | |||||
]); | |||||
$userManager = $this->getUserManager(); | |||||
$pointSaleManager = $this->getPointSaleManager(); | |||||
$distributionManager = $this->getDistributionManager(); | |||||
$usersArray = $userManager->findUsers(); | |||||
$pointsSaleArray = $pointSaleManager->findPointSales(); | |||||
$firstDistribution = $distributionManager->findOneFirstDistribution(); | |||||
$lastDistribution = $distributionManager->findOneLastDistribution(); | |||||
$firstYear = date('Y', strtotime($firstDistribution->date)); | $firstYear = date('Y', strtotime($firstDistribution->date)); | ||||
$lastYear = date('Y', strtotime($lastDistribution->date)); | $lastYear = date('Y', strtotime($lastDistribution->date)); | ||||
$distributionYearsArray = []; | $distributionYearsArray = []; | ||||
for ($year = $firstYear; $year <= $lastYear; $year++) { | for ($year = $firstYear; $year <= $lastYear; $year++) { | ||||
$distributionYearsArray[] = $year; | $distributionYearsArray[] = $year; | ||||
} | } | ||||
$distributionsArray = DistributionModel::searchAll([ | |||||
'distribution.active' => 1 | |||||
], [ | |||||
'orderby' => 'date ASC', | |||||
]); | |||||
$distributionsByMonthArray = []; | $distributionsByMonthArray = []; | ||||
$distributionsArray = $distributionManager->findDistributionsActive(); | |||||
foreach ($distributionsArray as $distribution) { | foreach ($distributionsArray as $distribution) { | ||||
$month = date('Y-m', strtotime($distribution->date)); | $month = date('Y-m', strtotime($distribution->date)); | ||||
if (!isset($distributionsByMonthArray[$month])) { | if (!isset($distributionsByMonthArray[$month])) { | ||||
public function actionAjaxReport() | public function actionAjaxReport() | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$posts = Yii::$app->request->post(); | |||||
$posts = Yii::$app->request->post(); | |||||
$resArray = []; | $resArray = []; | ||||
$conditionUsers = $this->_generateConditionSqlReport($posts, 'users', 'id_user'); | $conditionUsers = $this->_generateConditionSqlReport($posts, 'users', 'id_user'); | ||||
$conditionPointsSale = $this->_generateConditionSqlReport($posts, 'pointsSale', 'id_point_sale'); | $conditionPointsSale = $this->_generateConditionSqlReport($posts, 'pointsSale', 'id_point_sale'); | ||||
$conditionDistributions = $this->_generateConditionSqlReport($posts, 'distributions', 'id_distribution'); | $conditionDistributions = $this->_generateConditionSqlReport($posts, 'distributions', 'id_distribution'); |
$userManager = $this->getUserManager(); | $userManager = $this->getUserManager(); | ||||
$producerManager = $this->getProducerManager(); | $producerManager = $this->getProducerManager(); | ||||
// commandes | |||||
$optionDashboardNumberDistributions = $producerManager->getConfig('option_dashboard_number_distributions'); | $optionDashboardNumberDistributions = $producerManager->getConfig('option_dashboard_number_distributions'); | ||||
$dashboardNumberDistributions = $optionDashboardNumberDistributions ? $optionDashboardNumberDistributions : 3; | $dashboardNumberDistributions = $optionDashboardNumberDistributions ? $optionDashboardNumberDistributions : 3; | ||||
->andWhere('user_producer.credit < 0') | ->andWhere('user_producer.credit < 0') | ||||
->all(); | ->all(); | ||||
// paramètres | |||||
$producer = GlobalParam::getCurrentProducer(); | |||||
$producerCurrent = GlobalParam::getCurrentProducer(); | |||||
$productsCount = Product::searchCount(); | $productsCount = Product::searchCount(); | ||||
$pointsSaleCount = PointSale::searchCount(); | $pointsSaleCount = PointSale::searchCount(); | ||||
'ordersArray' => $ordersArray, | 'ordersArray' => $ordersArray, | ||||
'usersArray' => $usersArray, | 'usersArray' => $usersArray, | ||||
'usersNegativeCredit' => $usersNegativeCredit, | 'usersNegativeCredit' => $usersNegativeCredit, | ||||
'producer' => $producer, | |||||
'producer' => $producerCurrent, | |||||
'productsCount' => $productsCount, | 'productsCount' => $productsCount, | ||||
'pointsSaleCount' => $pointsSaleCount | 'pointsSaleCount' => $pointsSaleCount | ||||
]); | ]); | ||||
/** | /** | ||||
* Déconnecte l'utilisateur et le redirige à la page d'accueil. | * Déconnecte l'utilisateur et le redirige à la page d'accueil. | ||||
* | |||||
* @return mixed | |||||
*/ | */ | ||||
public function actionLogout() | public function actionLogout() | ||||
{ | { | ||||
/** | /** | ||||
* Change le producteur courant de l'utilisateur connecté. | * Change le producteur courant de l'utilisateur connecté. | ||||
* Permet de passer d'un producteur à un autre en tant qu'administrateur. | * Permet de passer d'un producteur à un autre en tant qu'administrateur. | ||||
* | |||||
* @param integer $id | |||||
*/ | */ | ||||
public function actionChangeProducer($id) | |||||
public function actionChangeProducer(int $id) | |||||
{ | { | ||||
Yii::$app->user->identity->id_producer = $id; | Yii::$app->user->identity->id_producer = $id; | ||||
Yii::$app->user->identity->save(); | Yii::$app->user->identity->save(); |
/** | /** | ||||
* Affiche les statistiques de l'année avec le CA réalisé par mois. | * Affiche les statistiques de l'année avec le CA réalisé par mois. | ||||
* | |||||
* @return mixed | |||||
*/ | */ | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
/* | /* | ||||
* Volume de commande de l'année passée (par mois) | * Volume de commande de l'année passée (par mois) | ||||
*/ | */ | ||||
$dateStart = date('Y-m-d', time() - 60 * 60 * 24 * 365); | $dateStart = date('Y-m-d', time() - 60 * 60 * 24 * 365); | ||||
$dateEnd = date('Y-m-d', time() + 60 * 60 * 24 * 31); | $dateEnd = date('Y-m-d', time() + 60 * 60 * 24 * 31); | ||||
/** | /** | ||||
* Affiche un tableau avec les totaux (maximums, commandés) de chaque produit | * Affiche un tableau avec les totaux (maximums, commandés) de chaque produit | ||||
* par mois d'une année donnée. | * par mois d'une année donnée. | ||||
* | |||||
* @param integer $year | |||||
* @return mixed | |||||
*/ | */ | ||||
public function actionProducts($year = 0, $section = 1) | |||||
public function actionProducts(int $year = 0, $section = 1) | |||||
{ | { | ||||
if (!$year) $year = date('Y'); | |||||
$productManager = $this->getProductManager(); | |||||
$productsArray = Product::searchAll(); | |||||
if (!$year) { | |||||
$year = date('Y'); | |||||
} | |||||
$productsArray = $productManager->findProducts(); | |||||
$dataProducts = []; | $dataProducts = []; | ||||
$dataProducts[self::TOTALS] = ['max' => [], 'orders' => []]; | $dataProducts[self::TOTALS] = ['max' => [], 'orders' => []]; |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\forms\SubscriptionForm; | |||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\Product\Product\Product; | |||||
use common\logic\Subscription\Subscription\SubscriptionSearch; | |||||
use yii\filters\AccessControl; | |||||
use yii\web\NotFoundHttpException; | |||||
class SubscriptionController extends BackendController | class SubscriptionController extends BackendController | ||||
{ | { | ||||
{ | { | ||||
$this->checkProductsPointsSale(); | $this->checkProductsPointsSale(); | ||||
$searchModel = new SubscriptionSearch; | |||||
$searchModel = new SubscriptionSearch(); | |||||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
/** | /** | ||||
* Crée un abonnement. | * Crée un abonnement. | ||||
* | |||||
* @return string | |||||
*/ | */ | ||||
public function actionCreate($idOrder = 0) | public function actionCreate($idOrder = 0) | ||||
{ | { | ||||
// form | |||||
$model = new SubscriptionForm; | |||||
$orderManager = $this->getOrderManager(); | |||||
$producerManager = $this->getProducerManager(); | |||||
$productManager = $this->getProductManager(); | |||||
$subscriptionManger = $this->getSubscriptionManager(); | |||||
$distributionManager = $this->getDistributionManager(); | |||||
$model = new SubscriptionForm(); | |||||
$model->isAdmin = true; | $model->isAdmin = true; | ||||
$model->id_producer = GlobalParam::getCurrentProducerId(); | $model->id_producer = GlobalParam::getCurrentProducerId(); | ||||
if ($idOrder) { | if ($idOrder) { | ||||
$order = Order::searchOne(['id' => $idOrder]); | |||||
$order = $orderManager->findOneOrderById($idOrder); | |||||
if ($order) { | if ($order) { | ||||
$model->id_user = $order->id_user; | $model->id_user = $order->id_user; | ||||
$model->username = $order->username; | $model->username = $order->username; | ||||
$dateDay = strtolower(date('l', strtotime($order->distribution->date))); | $dateDay = strtolower(date('l', strtotime($order->distribution->date))); | ||||
$model->$dateDay = 1; | $model->$dateDay = 1; | ||||
$model->week_frequency = 1; | $model->week_frequency = 1; | ||||
if ($model->id_user && Producer::getConfig('credit')) { | |||||
if ($model->id_user && $producerManager->getConfig('credit')) { | |||||
$model->auto_payment = 1; | $model->auto_payment = 1; | ||||
} | } | ||||
// produits | |||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
$model->products['product_' . $productOrder->id_product] = $productOrder->quantity; | $model->products['product_' . $productOrder->id_product] = $productOrder->quantity; | ||||
} | } | ||||
} | } | ||||
// produits | // produits | ||||
$productsArray = Product::searchAll([], [ | |||||
'orderby' => 'product.order ASC' | |||||
]); | |||||
$productsArray = $productManager->findProducts(); | |||||
if ($model->load(\Yii::$app->request->post()) && $model->validate() && $model->save()) { | |||||
if ($model->load(\Yii::$app->request->post()) && $model->validate() | |||||
&& $model->save()) { | |||||
$this->setFlash('success', 'Abonnement ajouté'); | $this->setFlash('success', 'Abonnement ajouté'); | ||||
$subscription = Subscription::findOne($model->id); | |||||
$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions(); | |||||
$subscription = $subscriptionManger->findOneSubscriptionById($model->id); | |||||
$matchedDistributionsArray = $distributionManager->findDistributionsIncomingMatchWithSubscrtiption($subscription); | |||||
if (count($matchedDistributionsArray)) { | if (count($matchedDistributionsArray)) { | ||||
return $this->redirect(['subscription/update-distributions', 'idSubscription' => $subscription->id]); | return $this->redirect(['subscription/update-distributions', 'idSubscription' => $subscription->id]); | ||||
} else { | } else { | ||||
/** | /** | ||||
* Modifie un abonnement. | * Modifie un abonnement. | ||||
* | |||||
* @param integer $id | |||||
* @return string | |||||
* @throws NotFoundHttpException | |||||
*/ | */ | ||||
public function actionUpdate($id) | public function actionUpdate($id) | ||||
{ | { | ||||
// form | |||||
$subscriptionManager = $this->getSubscriptionManager(); | |||||
$productSubscriptionManager = $this->getProductSubscriptionManager(); | |||||
$productManager = $this->getProductManager(); | |||||
$orderManager = $this->getOrderManager(); | |||||
$distributionManager = $this->getDistributionManager(); | |||||
$model = new SubscriptionForm; | $model = new SubscriptionForm; | ||||
$model->isAdmin = true; | $model->isAdmin = true; | ||||
$subscription = Subscription::findOne($id); | |||||
$subscription = $subscriptionManager->findOneSubscriptionById($id); | |||||
if ($subscription) { | if ($subscription) { | ||||
$model->id = $id; | $model->id = $id; | ||||
$model->comment = $subscription->comment; | $model->comment = $subscription->comment; | ||||
} | } | ||||
// produits | |||||
$arrayProductsSubscription = ProductSubscription::searchAll([ | |||||
'id_subscription' => $model->id | |||||
]); | |||||
$arrayProductsSubscription = $productSubscriptionManager->findProductSubscriptionsBySubscription($subscription); | |||||
foreach ($arrayProductsSubscription as $productSubscription) { | foreach ($arrayProductsSubscription as $productSubscription) { | ||||
$model->products['product_' . $productSubscription->id_product] = $productSubscription->quantity; | $model->products['product_' . $productSubscription->id_product] = $productSubscription->quantity; | ||||
} | } | ||||
} | } | ||||
// produits | // produits | ||||
$productsArray = Product::searchAll([], [ | |||||
'orderby' => 'product.order ASC' | |||||
]); | |||||
$productsArray = $productManager->findProducts(); | |||||
if ($model->load(\Yii::$app->request->post()) && $model->validate()) { | if ($model->load(\Yii::$app->request->post()) && $model->validate()) { | ||||
if ($model->save()) { | if ($model->save()) { | ||||
$subscription = Subscription::findOne($model->id); | |||||
$subscription = $subscriptionManager->findOneSubscriptionById($model->id); | |||||
$messageOrdersDeleted = ''; | $messageOrdersDeleted = ''; | ||||
if ($model->date_end) { | |||||
$countOrdersDeleted = $subscription->deleteOrdersIncomingDistributions(true); | |||||
if ($model->date_end) { | |||||
$countOrdersDeleted = $orderManager->deleteOrdersIncomingDistributionsFromSubscription($subscription, true); | |||||
if ($countOrdersDeleted) { | if ($countOrdersDeleted) { | ||||
$messageOrdersDeleted = '<br />' . $countOrdersDeleted . ' commandes supprimées'; | $messageOrdersDeleted = '<br />' . $countOrdersDeleted . ' commandes supprimées'; | ||||
} | } | ||||
$this->setFlash('success', 'Abonnement modifié' . $messageOrdersDeleted); | $this->setFlash('success', 'Abonnement modifié' . $messageOrdersDeleted); | ||||
$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions(); | |||||
$matchedDistributionsArray = $distributionManager->findDistributionsIncomingMatchWithSubscrtiption($subscription); | |||||
if (count($matchedDistributionsArray)) { | if (count($matchedDistributionsArray)) { | ||||
return $this->redirect(['subscription/update-distributions', 'idSubscription' => $subscription->id, 'update' => true]); | return $this->redirect(['subscription/update-distributions', 'idSubscription' => $subscription->id, 'update' => true]); | ||||
} else { | } else { | ||||
/** | /** | ||||
* Supprime une commande récurrente. | * Supprime une commande récurrente. | ||||
* | |||||
* @param integer $id | |||||
*/ | */ | ||||
public function actionDelete($id) | |||||
public function actionDelete(int $id) | |||||
{ | { | ||||
$subscription = Subscription::searchOne([ | |||||
'subscription.id' => $id | |||||
]); | |||||
$subscription->deleteOrdersIncomingDistributions(); | |||||
$subscription->delete(); | |||||
ProductSubscription::deleteAll(['id_subscription' => $id]); | |||||
$subscriptionManager = $this->getSubscriptionManager(); | |||||
$orderManager = $this->getOrderManager(); | |||||
$subscription = $subscriptionManager->findOneSubscriptionById($id); | |||||
$orderManager->deleteOrdersIncomingDistributionsFromSubscription($subscription); | |||||
$subscriptionManager->deleteSubscription($subscription); | |||||
$this->setFlash('success', 'Abonnement supprimé'); | $this->setFlash('success', 'Abonnement supprimé'); | ||||
return $this->redirect(['subscription/index']); | return $this->redirect(['subscription/index']); | ||||
} | } | ||||
public function actionUpdateDistributions($idSubscription, $generate = false, $update = false) | |||||
public function actionUpdateDistributions(int $idSubscription, bool $generate = false, bool $update = false) | |||||
{ | { | ||||
$subscription = Subscription::findOne($idSubscription); | |||||
$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions(); | |||||
$subscriptionManager = $this->getSubscriptionManager(); | |||||
$distributionManager = $this->getDistributionManager(); | |||||
$orderManager = $this->getOrderManager(); | |||||
$subscription = $subscriptionManager->findOneSubscriptionById($idSubscription); | |||||
$matchedDistributionsArray = $distributionManager->findDistributionsIncomingMatchWithSubscrtiption($subscription); | |||||
if ($generate) { | if ($generate) { | ||||
if ($update) { | if ($update) { | ||||
$subscription->deleteOrdersIncomingDistributions(); | |||||
$orderManager->deleteOrdersIncomingDistributionsFromSubscription($subscription); | |||||
} | } | ||||
foreach ($matchedDistributionsArray as $distribution) { | foreach ($matchedDistributionsArray as $distribution) { | ||||
$subscription->add($distribution->date); | |||||
$orderManager->createOrderFromSubscription($subscription, $distribution->date); | |||||
} | } | ||||
$this->setFlash('success', 'Commandes ' . ($update ? 're-' : '') . 'générées dans les distributions futures.'); | $this->setFlash('success', 'Commandes ' . ($update ? 're-' : '') . 'générées dans les distributions futures.'); | ||||
return $this->redirect(['subscription/index']); | return $this->redirect(['subscription/index']); | ||||
]); | ]); | ||||
} | } | ||||
public function actionAjaxInfos($idSubscription = 0) | |||||
public function actionAjaxInfos(int $idSubscription = 0) | |||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$productManager = $this->getProductManager(); | |||||
$productsQuery = Product::find() | $productsQuery = Product::find() | ||||
->where(['id_producer' => GlobalParam::getCurrentProducerId(),]); | ->where(['id_producer' => GlobalParam::getCurrentProducerId(),]); | ||||
} | } | ||||
$productsArray = $productsQuery->asArray()->orderBy('order ASC')->all(); | $productsArray = $productsQuery->asArray()->orderBy('order ASC')->all(); | ||||
/*Debug::dump($productsArray);*/ | |||||
foreach ($productsArray as &$theProduct) { | |||||
/*$theProduct['unit_save'] = $theProduct['unit'] ; | |||||
$theProduct['units'] = [] ; | |||||
$theProduct['units'][] = [ | |||||
'unit' => $theProduct['unit'], | |||||
'step' => $theProduct['step'], | |||||
'price' => $theProduct['price'] | |||||
] ;*/ | |||||
$theProduct['wording_unit'] = Product::strUnit($theProduct['unit'], 'wording_short'); | |||||
foreach ($productsArray as &$theProduct) { | |||||
$theProduct['wording_unit'] = $productManager->strUnit($theProduct['unit'], 'wording_short'); | |||||
if (isset($theProduct['productSubscription'][0])) { | if (isset($theProduct['productSubscription'][0])) { | ||||
/*if($theProduct['productSubscription'][0]['unit'] != $theProduct['unit']) { | |||||
$theProduct['units'][] = [ | |||||
'unit' => $theProduct['productSubscription'][0]['unit'], | |||||
'wording_unit' => Product::strUnit($theProduct['productSubscription'][0]['unit'], 'wording_short'), | |||||
'step' => $theProduct['productSubscription'][0]['step'], | |||||
'price' => $theProduct['productSubscription'][0]['price'], | |||||
] ; | |||||
$theProduct['unit'] = $theProduct['productSubscription'][0]['unit'] ; | |||||
$theProduct['step'] = $theProduct['productSubscription'][0]['step'] ; | |||||
$theProduct['price'] = $theProduct['productSubscription'][0]['price'] ; | |||||
}*/ | |||||
$theProduct['quantity'] = $theProduct['productSubscription'][0]['quantity'] * Product::$unitsArray[$theProduct['unit']]['coefficient']; | $theProduct['quantity'] = $theProduct['productSubscription'][0]['quantity'] * Product::$unitsArray[$theProduct['unit']]['coefficient']; | ||||
} else { | } else { | ||||
$theProduct['quantity'] = ''; | $theProduct['quantity'] = ''; | ||||
'products' => $productsArray | 'products' => $productsArray | ||||
]; | ]; | ||||
} | } | ||||
} | } |
public function actionCreate() | public function actionCreate() | ||||
{ | { | ||||
$model = $this->getTaxRateManager()->createTaxRate(); | |||||
$model = $this->getTaxRateManager()->instanciateTaxRate(); | |||||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | if ($model->load(\Yii::$app->request->post()) && $model->save()) { | ||||
$this->setFlash('success', 'Taxe créée.'); | $this->setFlash('success', 'Taxe créée.'); | ||||
public function actionDelete(int $id) | public function actionDelete(int $id) | ||||
{ | { | ||||
$taxeRate = TaxRate::searchOne([ | |||||
'id' => $id | |||||
]); | |||||
$taxeRate->delete(); | |||||
$taxRateManager = $this->getTaxRateManager(); | |||||
$taxRate = $this->findModel($id); | |||||
$taxRateManager->delete($taxRate); | |||||
$this->setFlash('success', 'Taxe supprimé'); | $this->setFlash('success', 'Taxe supprimé'); | ||||
return $this->redirect(['tax-rate-admin/index']); | return $this->redirect(['tax-rate-admin/index']); | ||||
} | } | ||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = TaxRate::findOne($id)) !== null) { | |||||
return $model; | |||||
$taxRateManager = $this->getTaxRateManager(); | |||||
if (($taxRate = $taxRateManager->findOneTaxRateById($id)) !== null) { | |||||
return $taxRate; | |||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } |
use common\logic\Order\Order\OrderSearch; | use common\logic\Order\Order\OrderSearch; | ||||
use common\logic\PointSale\PointSale\PointSale; | use common\logic\PointSale\PointSale\PointSale; | ||||
use common\logic\PointSale\UserPointSale\UserPointSale; | use common\logic\PointSale\UserPointSale\UserPointSale; | ||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\User\CreditHistory\CreditHistory; | use common\logic\User\CreditHistory\CreditHistory; | ||||
use common\logic\User\User\UserSearch; | use common\logic\User\User\UserSearch; | ||||
use common\logic\User\UserGroup\UserGroup; | |||||
use common\logic\User\UserGroup\UserUserGroup; | |||||
use common\logic\User\UserProducer\UserProducer; | use common\logic\User\UserProducer\UserProducer; | ||||
use common\logic\User\UserUserGroup\UserUserGroup; | |||||
use yii\base\UserException; | use yii\base\UserException; | ||||
use yii\debug\models\search\User; | use yii\debug\models\search\User; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
*/ | */ | ||||
class UserController extends BackendController | class UserController extends BackendController | ||||
{ | { | ||||
public function behaviors() | public function behaviors() | ||||
{ | { | ||||
return [ | return [ | ||||
/** | /** | ||||
* Liste les utilisateurs. | * Liste les utilisateurs. | ||||
* | |||||
* @return mixed | |||||
*/ | */ | ||||
public function actionIndex( | public function actionIndex( | ||||
$idPointSale = 0, $sectionSubscribers = false, $sectionInactiveUsers = false) | |||||
int $idPointSale = 0, | |||||
bool $sectionSubscribers = false, | |||||
bool $sectionInactiveUsers = false) | |||||
{ | { | ||||
$pointSaleManager = $this->getPointSaleManager(); | |||||
$searchModel = new UserSearch(); | $searchModel = new UserSearch(); | ||||
$dataProvider = $searchModel->search([ | $dataProvider = $searchModel->search([ | ||||
'UserSearch' => array_merge( | 'UserSearch' => array_merge( | ||||
[ | [ | ||||
'id_point_sale' => $idPointSale, | 'id_point_sale' => $idPointSale, | ||||
'inactive' => (int)$sectionInactiveUsers, | |||||
'subscribers' => (int)$sectionSubscribers | |||||
'inactive' => (int) $sectionInactiveUsers, | |||||
'subscribers' => (int) $sectionSubscribers | |||||
], | ], | ||||
isset(\Yii::$app->request->queryParams['UserSearch']) ? | isset(\Yii::$app->request->queryParams['UserSearch']) ? | ||||
Yii::$app->request->queryParams['UserSearch'] : | Yii::$app->request->queryParams['UserSearch'] : | ||||
) | ) | ||||
]); | ]); | ||||
$producer = Producer::searchOne([ | |||||
'id' => GlobalParam::getCurrentProducerId() | |||||
]); | |||||
$pointsSaleArray = PointSale::searchAll(); | |||||
$producer = $this->getProducerCurrent(); | |||||
$pointsSaleArray = $pointSaleManager->findPointSales(); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | 'searchModel' => $searchModel, | ||||
public function initForm($model) | public function initForm($model) | ||||
{ | { | ||||
$userPointSaleManager = $this->getUserPointSaleManager(); | |||||
$userUserGroupManager = $this->getUserUserGroupManager(); | |||||
$userProducerManager = $this->getUserProducerManager(); | |||||
$userGroupManager = $this->getUserGroupManager(); | |||||
$producerCurrent = $this->getProducerCurrent(); | |||||
if ($model->id) { | if ($model->id) { | ||||
// init points de vente sélectionnés | |||||
$userPointSaleArray = UserPointSale::searchAll([ | |||||
'id_user' => $model->id | |||||
]); | |||||
$userPointSaleArray = $userPointSaleManager->findUserPointSalesByUser($model); | |||||
if ($userPointSaleArray && count($userPointSaleArray) > 0) { | if ($userPointSaleArray && count($userPointSaleArray) > 0) { | ||||
foreach ($userPointSaleArray as $userPointSaleArray) { | |||||
$model->points_sale[] = $userPointSaleArray->id_point_sale; | |||||
foreach ($userPointSaleArray as $userPointSale) { | |||||
$model->points_sale[] = $userPointSale->id_point_sale; | |||||
} | } | ||||
} | } | ||||
// init groupes d'utilisateurs sélectionnés | |||||
$userUserGroupsArray = UserUserGroup::searchAll([ | |||||
'id_user' => $model->id | |||||
]); | |||||
$userUserGroupsArray = $userUserGroupManager->findUserUserGroupsByUser($model); | |||||
if ($userUserGroupsArray && count($userUserGroupsArray) > 0) { | if ($userUserGroupsArray && count($userUserGroupsArray) > 0) { | ||||
foreach ($userUserGroupsArray as $userUserGroup) { | foreach ($userUserGroupsArray as $userUserGroup) { | ||||
$model->user_groups[] = $userUserGroup->id_user_group; | $model->user_groups[] = $userUserGroup->id_user_group; | ||||
} | } | ||||
} | } | ||||
// product price percent | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | |||||
'id_user' => $model->id | |||||
]); | |||||
$userProducer = $userProducerManager->findOneUserProducer($model, $producerCurrent); | |||||
$model->product_price_percent = $userProducer->product_price_percent; | $model->product_price_percent = $userProducer->product_price_percent; | ||||
} | } | ||||
// points de vente | |||||
$pointsSaleArray = PointSale::find() | $pointsSaleArray = PointSale::find() | ||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
}]) | }]) | ||||
->all(); | ->all(); | ||||
// groupes d'utilisateurs | |||||
$userGroupsArray = UserGroup::find() | |||||
->where([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | |||||
]) | |||||
->all(); | |||||
$userGroupsArray = $userGroupManager->findUserGroups(); | |||||
return [ | return [ | ||||
'pointsSaleArray' => $pointsSaleArray, | 'pointsSaleArray' => $pointsSaleArray, | ||||
/** | /** | ||||
* Creates a new User model. | * Creates a new User model. | ||||
* If creation is successful, the browser will be redirected to the 'view' page. | * If creation is successful, the browser will be redirected to the 'view' page. | ||||
* @return mixed | |||||
*/ | */ | ||||
public function actionCreate() | public function actionCreate() | ||||
{ | { | ||||
$model = new User(); | |||||
$userManager = $this->getUserManager(); | |||||
$producerManager = $this->getProducerManager(); | |||||
$producerCurrent = $this->getProducerCurrent(); | |||||
$model = $userManager->instanciateUser(); | |||||
$userExist = false; | $userExist = false; | ||||
$posts = Yii::$app->request->post(); | $posts = Yii::$app->request->post(); | ||||
if ($posts && isset($posts['User']['email']) && strlen($posts['User']['email']) > 0) { | if ($posts && isset($posts['User']['email']) && strlen($posts['User']['email']) > 0) { | ||||
$userExist = User::searchOne([ | |||||
'email' => $posts['User']['email'] | |||||
]); | |||||
$userExist = $userManager->findOneUserByEmail($posts['User']['email']); | |||||
} | } | ||||
if ($userExist) { | if ($userExist) { | ||||
Producer::addUser($userExist->id, GlobalParam::getCurrentProducerId()); | |||||
$producerManager->addUser($userExist, $producerCurrent); | |||||
$this->processLinkPointSale($userExist); | $this->processLinkPointSale($userExist); | ||||
$this->processLinkUserGroup($userExist); | $this->processLinkUserGroup($userExist); | ||||
$this->setFlash('success', "L'utilisateur que vous souhaitez créer possède déjà un compte sur la plateforme. Il vient d'être lié à votre établissement."); | $this->setFlash('success', "L'utilisateur que vous souhaitez créer possède déjà un compte sur la plateforme. Il vient d'être lié à votre établissement."); | ||||
} else { | } else { | ||||
if ($model->load(\Yii::$app->request->post()) && $model->validate() && YII_ENV != 'demo') { | if ($model->load(\Yii::$app->request->post()) && $model->validate() && YII_ENV != 'demo') { | ||||
// save user | |||||
$password = Password::generate(); | |||||
$model->id_producer = 0; | $model->id_producer = 0; | ||||
$model->setPassword($password); | |||||
$model->generateAuthKey(); | |||||
$password = Password::generate(); | |||||
$userManager->setPassword($model, $password); | |||||
$userManager->generateAuthKey($model); | |||||
$model->username = $model->email; | $model->username = $model->email; | ||||
if (!strlen($model->email)) { | if (!strlen($model->email)) { | ||||
$model->username = 'inconnu@opendistrib.net'; | $model->username = 'inconnu@opendistrib.net'; | ||||
$useProducer->active = 1; | $useProducer->active = 1; | ||||
$useProducer->save(); | $useProducer->save(); | ||||
$model->sendMailWelcome($password); | |||||
$userManager->sendMailWelcome($model, $password); | |||||
$this->processLinkPointSale($model); | $this->processLinkPointSale($model); | ||||
$this->processLinkUserGroup($model); | $this->processLinkUserGroup($model); | ||||
$this->processProductPricePercent($model); | $this->processProductPricePercent($model); | ||||
$this->setFlash('success', 'Utilisateur créé.'); | $this->setFlash('success', 'Utilisateur créé.'); | ||||
$model = new User(); | |||||
$model = $userManager->instanciateUser(); | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Updates an existing User model. | * Updates an existing User model. | ||||
* If update is successful, the browser will be redirected to the 'view' page. | * If update is successful, the browser will be redirected to the 'view' page. | ||||
* @param integer $id | |||||
* @return mixed | |||||
*/ | */ | ||||
public function actionUpdate($id) | public function actionUpdate($id) | ||||
{ | { | ||||
$userManager = $this->getUserManager(); | |||||
$producerManager = $this->getProducerManager(); | |||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
// Moodification du profil | // Moodification du profil | ||||
// on envoie le mail de bienvenue si le mail vient d'être défini | // on envoie le mail de bienvenue si le mail vient d'être défini | ||||
if (!strlen($previousMail) && strlen($model->email)) { | if (!strlen($previousMail) && strlen($model->email)) { | ||||
$password = Password::generate(); | $password = Password::generate(); | ||||
$model->setPassword($password); | |||||
$userManager->setPassword($model, $password); | |||||
$model->username = $model->email; | $model->username = $model->email; | ||||
$model->sendMailWelcome($password); | |||||
$userManager->sendMailWelcome($model, $password); | |||||
} | } | ||||
$this->processLinkPointSale($model); | $this->processLinkPointSale($model); | ||||
$this->processLinkUserGroup($model); | $this->processLinkUserGroup($model); | ||||
$this->processProductPricePercent($model); | $this->processProductPricePercent($model); | ||||
$this->setFlash('success', 'Utilisateur modifié.'); | $this->setFlash('success', 'Utilisateur modifié.'); | ||||
} | } | ||||
} else { | } else { | ||||
$model->setPassword($password); | $model->setPassword($password); | ||||
$model->save(); | $model->save(); | ||||
$producer = GlobalParam::getCurrentProducer(); | |||||
$producer = $this->getProducerCurrent(); | |||||
Mailjet::sendMail([ | Mailjet::sendMail([ | ||||
'from_email' => $producer->getEmailOpendistrib(), | |||||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||||
'from_name' => $producer->name, | 'from_name' => $producer->name, | ||||
'to_email' => $model->email, | 'to_email' => $model->email, | ||||
'to_name' => $model->getUsername(), | |||||
'to_name' => $userManager->getUsername($user), | |||||
'subject' => '[' . $producer->name . '] Nouveau mot de passe', | 'subject' => '[' . $producer->name . '] Nouveau mot de passe', | ||||
'content_view_text' => '@common/mail/newPasswordUserAdmin-text.php', | 'content_view_text' => '@common/mail/newPasswordUserAdmin-text.php', | ||||
'content_view_html' => '@common/mail/newPasswordUserAdmin-html.php', | 'content_view_html' => '@common/mail/newPasswordUserAdmin-html.php', | ||||
/** | /** | ||||
* Lie un utilisateur aux points de vente sélectionnés. | * Lie un utilisateur aux points de vente sélectionnés. | ||||
* | |||||
* @param User $modelUser | |||||
*/ | */ | ||||
public function processLinkPointSale($modelUser) | |||||
public function processLinkPointSale(User $modelUser) | |||||
{ | { | ||||
$posts = Yii::$app->request->post(); | $posts = Yii::$app->request->post(); | ||||
UserPointSale::deleteAll([ | UserPointSale::deleteAll([ | ||||
/** | /** | ||||
* Lie un utilisateur aux groupes d'utilisateurs sélectionnés. | * Lie un utilisateur aux groupes d'utilisateurs sélectionnés. | ||||
* | |||||
* @param User $modelUser | |||||
*/ | */ | ||||
public function processLinkUserGroup($modelUser) | public function processLinkUserGroup($modelUser) | ||||
{ | { | ||||
$posts = Yii::$app->request->post(); | |||||
UserUserGroup::deleteAll([ | UserUserGroup::deleteAll([ | ||||
'id_user' => $modelUser->id | 'id_user' => $modelUser->id | ||||
]); | ]); | ||||
/** | /** | ||||
* Désactive l'utilisateur de l'établissement. | * Désactive l'utilisateur de l'établissement. | ||||
* | |||||
* @param integer $id ID de l'utilisateur | |||||
*/ | */ | ||||
public function actionDelete($id) | |||||
public function actionDelete(int $id) | |||||
{ | { | ||||
$userProducer = UserProducer::findOne([ | |||||
'id_user' => $id, | |||||
'id_producer' => GlobalParam::getCurrentProducerId() | |||||
]); | |||||
$userProducerManager = $this->getUserProducerManager(); | |||||
$userProducer = $userProducerManager->findOneUserProducer($userProducer); | |||||
if ($userProducer) { | if ($userProducer) { | ||||
$userProducer->active = 0; | $userProducer->active = 0; | ||||
$userProducer->bookmark = 0; | $userProducer->bookmark = 0; | ||||
$userProducer->save(); | $userProducer->save(); | ||||
$this->setFlash('success', 'L\'utilisateur a bien été supprimé de votre établissement.'); | $this->setFlash('success', 'L\'utilisateur a bien été supprimé de votre établissement.'); | ||||
} else { | } else { | ||||
throw new \yii\web\NotFoundHttpException('L\'enregistrement UserProducer est introuvable', 404); | throw new \yii\web\NotFoundHttpException('L\'enregistrement UserProducer est introuvable', 404); | ||||
} | } | ||||
/** | /** | ||||
* Affiche la liste des emails des utilisateurs liés à un point de vente | |||||
* donné. | |||||
* | |||||
* @param integer $idPointSale | |||||
* @return mixed | |||||
* Affiche la liste des emails des utilisateurs liés à un point de vente donné. | |||||
*/ | */ | ||||
public function actionMail( | public function actionMail( | ||||
$idPointSale = 0, | $idPointSale = 0, | ||||
$usersPointSaleLink = 0, | $usersPointSaleLink = 0, | ||||
$usersPointSaleHasOrder = 0) | $usersPointSaleHasOrder = 0) | ||||
{ | { | ||||
$userManager = $this->getUserManager(); | |||||
$distributionManager = $this->getDistributionManager(); | |||||
if ($idPointSale && !$usersPointSaleLink && !$usersPointSaleHasOrder) { | if ($idPointSale && !$usersPointSaleLink && !$usersPointSaleHasOrder) { | ||||
$usersPointSaleLink = 1; | $usersPointSaleLink = 1; | ||||
} | } | ||||
$users = User::findBy([ | |||||
$users = $userManager->queryUsersBy([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'id_point_sale' => $idPointSale, | 'id_point_sale' => $idPointSale, | ||||
'users_point_sale_link' => $usersPointSaleLink, | 'users_point_sale_link' => $usersPointSaleLink, | ||||
return $this->redirect(['mail', 'idPointSale' => $idPointSale]); | return $this->redirect(['mail', 'idPointSale' => $idPointSale]); | ||||
} | } | ||||
$incomingDistributions = Distribution::getIncoming(); | |||||
$incomingDistributions = $distributionManager->findDistributionsIncoming(); | |||||
$incomingDistributionsArray = ['0' => '--']; | $incomingDistributionsArray = ['0' => '--']; | ||||
foreach ($incomingDistributions as $distribution) { | foreach ($incomingDistributions as $distribution) { | ||||
$incomingDistributionsArray[$distribution->id] = strftime('%A %d %B %Y', strtotime($distribution->date)); | $incomingDistributionsArray[$distribution->id] = strftime('%A %d %B %Y', strtotime($distribution->date)); | ||||
} | } | ||||
/** | /** | ||||
* Affiche les données liées au crédit d'un utilisateur (formulaire, | |||||
* historique). | |||||
* | |||||
* @param integer $id | |||||
* @return mixed | |||||
* @throws UserException | |||||
* Affiche les données liées au crédit d'un utilisateur (formulaire, historique). | |||||
*/ | */ | ||||
public function actionCredit($id) | |||||
public function actionCredit(int $id) | |||||
{ | { | ||||
$user = User::find()->with('userProducer')->where(['id' => $id])->one(); | $user = User::find()->with('userProducer')->where(['id' => $id])->one(); | ||||
$userProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); | $userProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); | ||||
if (($userProducer) || User::getCurrentStatus() == User::STATUS_ADMIN) { | |||||
if (($userProducer) || $this->isUserCurrentAdmin()) { | |||||
$creditForm = new CreditForm(); | $creditForm = new CreditForm(); | ||||
if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) { | if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) { | ||||
*/ | */ | ||||
public function actionOrders($id) | public function actionOrders($id) | ||||
{ | { | ||||
$user = User::findOne($id); | |||||
$userManager = $this->getUserManager(); | |||||
$user = $userManager->findOneUserById($id); | |||||
$searchModel = new OrderSearch(); | $searchModel = new OrderSearch(); | ||||
$dataProvider = $searchModel->search(array_merge(\Yii::$app->request->queryParams, ['id_user' => $id])); | $dataProvider = $searchModel->search(array_merge(\Yii::$app->request->queryParams, ['id_user' => $id])); | ||||
/** | /** | ||||
* Modifie l'option "credit_active" d'un utilisateur pour le producteur courant. | * Modifie l'option "credit_active" d'un utilisateur pour le producteur courant. | ||||
* Redirige vers la page de crédit de l'utilisateur. | * Redirige vers la page de crédit de l'utilisateur. | ||||
* | |||||
* @param integer $idUser | |||||
* @param boolean $state | |||||
*/ | */ | ||||
public function actionStateCredit($idUser, $state) | public function actionStateCredit($idUser, $state) | ||||
{ | { | ||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $idUser | |||||
]); | |||||
$userManager = $this->getUserManager(); | |||||
$userProducerManager = $this->getUserProducerManager(); | |||||
$user = $userManager->findOneUserById($idUser); | |||||
$producerCurrent = $this->getproducerCurrent(); | |||||
$userProducer = $userProducerManager->findOneUserProducer($user,$producerCurrent); | |||||
if ($userProducer) { | if ($userProducer) { | ||||
$userProducer->credit_active = $state; | $userProducer->credit_active = $state; | ||||
*/ | */ | ||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = User::findOne($id)) !== null) { | |||||
return $model; | |||||
$userManager = $this->getUserManager(); | |||||
if (($user = $userManager->findOneUserById($id)) !== null) { | |||||
return $user; | |||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); | ||||
} | } | ||||
} | } | ||||
} | } |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\User\UserGroup\UserGroupSearch; | |||||
use common\logic\User\UserUserGroup\UserUserGroup; | |||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
/** | /** | ||||
* Crée un groupe d'utilisateur. | * Crée un groupe d'utilisateur. | ||||
* | |||||
* @return mixed | |||||
*/ | */ | ||||
public function actionCreate() | public function actionCreate() | ||||
{ | { | ||||
$model = new UserGroup(); | |||||
$userGroupManager = $this->getUserGroupManager(); | |||||
$model = $userGroupManager->instanciateUserGroup(); | |||||
$model->id_producer = GlobalParam::getCurrentProducerId(); | $model->id_producer = GlobalParam::getCurrentProducerId(); | ||||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | if ($model->load(\Yii::$app->request->post()) && $model->save()) { | ||||
/** | /** | ||||
* Modifie un groupe d'utilisateur. | * Modifie un groupe d'utilisateur. | ||||
* | |||||
* @param integer $id | |||||
* @return mixed | |||||
*/ | */ | ||||
public function actionUpdate($id) | |||||
public function actionUpdate(int $id) | |||||
{ | { | ||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
/** | /** | ||||
* Supprime un groupe d'utilisateur. | * Supprime un groupe d'utilisateur. | ||||
* | |||||
* @param integer $id | |||||
* @return mixed | |||||
*/ | */ | ||||
public function actionDelete($id) | |||||
public function actionDelete(int $id) | |||||
{ | { | ||||
$userGroup = $this->findModel($id); | $userGroup = $this->findModel($id); | ||||
$userGroup->delete(); | $userGroup->delete(); | ||||
UserUserGroup::deleteAll(['id_user_group' => $id]); | UserUserGroup::deleteAll(['id_user_group' => $id]); | ||||
$this->setFlash('success', 'Groupe d\'utilisateur <strong>' . Html::encode($userGroup->name) . '</strong> supprimé.'); | $this->setFlash('success', 'Groupe d\'utilisateur <strong>' . Html::encode($userGroup->name) . '</strong> supprimé.'); | ||||
/** | /** | ||||
* Recherche un groupe d'utilisateur en fonction de son ID. | * Recherche un groupe d'utilisateur en fonction de son ID. | ||||
* | |||||
* @param integer $id | |||||
* @return UserGroup | |||||
* @throws NotFoundHttpException si le modèle n'est pas trouvé | |||||
*/ | */ | ||||
protected function findModel($id) | |||||
protected function findModel(int $id) | |||||
{ | { | ||||
if (($model = UserGroup::findOne($id)) !== null) { | |||||
$userGroupManager = $this->getUserGroupManager(); | |||||
if (($model = $userGroupManager->findOneUserGroupById($id)) !== null) { | |||||
return $model; | return $model; | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); |
] ; | ] ; | ||||
} | } | ||||
public function findOneTaxRateById(int $id): ?TaxRate | |||||
{ | |||||
return TaxRate::searchOne(['id' => $id]); | |||||
} | |||||
public function findTaxRates(): array | public function findTaxRates(): array | ||||
{ | { | ||||
return TaxRate::find()->all(); | return TaxRate::find()->all(); |
]); | ]); | ||||
} | } | ||||
public function findOneFirstDistribution(): ?Distribution | |||||
{ | |||||
return Distribution::searchOne([], [ | |||||
'orderby' => 'date ASC' | |||||
]); | |||||
} | |||||
public function findOneLastDistribution(): ?Distribution | |||||
{ | |||||
return Distribution::searchOne([], [ | |||||
'orderby' => 'date DESC' | |||||
]); | |||||
} | |||||
public function findDistributionsActive(): array | public function findDistributionsActive(): array | ||||
{ | { | ||||
return Distribution::searchAll([ | return Distribution::searchAll([ | ||||
'active' => 1 | 'active' => 1 | ||||
], [ | |||||
'orderby' => 'date ASC', | |||||
]); | ]); | ||||
} | } | ||||
namespace common\logic\PointSale\UserPointSale; | namespace common\logic\PointSale\UserPointSale; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\BuilderInterface; | |||||
use common\logic\PointSale\PointSale\PointSale; | use common\logic\PointSale\PointSale\PointSale; | ||||
use common\logic\PointSale\UserPointSale\UserPointSale; | |||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
use common\logic\User\User\User; | use common\logic\User\User\User; | ||||
] ; | ] ; | ||||
} | } | ||||
public function findUserPointSalesByUser(User $user): array | |||||
{ | |||||
return UserPointSale::searchAll([ | |||||
'id_user' => $user->id | |||||
]); | |||||
} | |||||
public function findOneUserPointSale(User $user, PointSale $pointSale) | public function findOneUserPointSale(User $user, PointSale $pointSale) | ||||
{ | { | ||||
return UserPointSale::find() | return UserPointSale::find() |
public function findProducts(): array | public function findProducts(): array | ||||
{ | { | ||||
return Product::searchAll(); | |||||
return Product::searchAll([], [ | |||||
'orderby' => 'product.order ASC' | |||||
]); | |||||
} | } | ||||
/** | /** |
use common\logic\BaseBuilder; | use common\logic\BaseBuilder; | ||||
use common\logic\BuilderInterface; | use common\logic\BuilderInterface; | ||||
use common\logic\PointSale\PointSale\PointSale; | |||||
use common\logic\Product\Product\Product; | |||||
class ProductPointSaleBuilder extends BaseBuilder implements BuilderInterface | class ProductPointSaleBuilder extends BaseBuilder implements BuilderInterface | ||||
{ | { | ||||
return $productPointSale; | return $productPointSale; | ||||
} | } | ||||
public function createProductPointSale(): ProductPointSale | |||||
public function createProductPointSale(Product $product, PointSale $pointSale, bool $available): ProductPointSale | |||||
{ | { | ||||
$productPointSale = $this->instanciateProductPointSale(); | $productPointSale = $this->instanciateProductPointSale(); | ||||
$productPointSale->populateProduct($product); | |||||
$productPointSale->populatePointSale($pointSale); | |||||
$productPointSale->availability = $available; | |||||
$this->saveCreate($productPointSale); | $this->saveCreate($productPointSale); | ||||
return $productPointSale; | return $productPointSale; |
'attribute_id_producer' => 'product.id_producer' | 'attribute_id_producer' => 'product.id_producer' | ||||
]; | ]; | ||||
} | } | ||||
public function findOneProductPriceById(int $id): ?ProductPrice | |||||
{ | |||||
return ProductPrice::searchOne(['id' => $id]); | |||||
} | |||||
} | } |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
use common\logic\Subscription\Subscription\Subscription; | |||||
class ProductSubscriptionRepository extends BaseService implements RepositoryInterface | class ProductSubscriptionRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
'attribute_id_producer' => '' | 'attribute_id_producer' => '' | ||||
]; | ]; | ||||
} | } | ||||
public function findProductSubscriptionsBySubscription(Subscription $subscription): array | |||||
{ | |||||
return ProductSubscription::searchAll([ | |||||
'id_subscription' => $subscription->id | |||||
]); | |||||
} | |||||
} | } |
]; | ]; | ||||
} | } | ||||
public function findOneUserGroupById(int $id) | |||||
{ | |||||
return UserGroup::searchOne(['id' => $id]); | |||||
} | |||||
public function findUserGroups() | public function findUserGroups() | ||||
{ | { | ||||
return UserGroup::find()->where('id_producer = ' . GlobalParam::getCurrentProducerId())->all(); | return UserGroup::find()->where('id_producer = ' . GlobalParam::getCurrentProducerId())->all(); |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
use common\logic\User\User\User; | |||||
class UserUserGroupRepository extends BaseService implements RepositoryInterface | class UserUserGroupRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
'attribute_id_producer' => '' | 'attribute_id_producer' => '' | ||||
] ; | ] ; | ||||
} | } | ||||
public function findUserUserGroupsByUser(User $user) | |||||
{ | |||||
return UserUserGroup::searchAll([ | |||||
'id_user' => $user->id | |||||
]); | |||||
} | |||||
} | } |