use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\models\UserModel ; | |||||
use common\models\UserModelSearch ; | |||||
use common\models\ User ; | |||||
use common\models\ UserSearch ; | |||||
use backend\models\AccessUserProducerForm ; | use backend\models\AccessUserProducerForm ; | ||||
/** | /** | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
*/ | */ | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$userSearch = new UserModelSearch ; | |||||
$userSearch = new UserSearch ; | |||||
$usersArray = $userSearch->search()->query->all() ; | $usersArray = $userSearch->search()->query->all() ; | ||||
$modelAccessUserProducerForm = new AccessUserProducerForm ; | $modelAccessUserProducerForm = new AccessUserProducerForm ; | ||||
Yii::$app->getSession()->setFlash('success', 'Droits ajoutés à l\'utilisateur'); | Yii::$app->getSession()->setFlash('success', 'Droits ajoutés à l\'utilisateur'); | ||||
} | } | ||||
$usersAccessArray = UserModel::find() | |||||
$usersAccessArray = User::find() | |||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'status' => UserModel::STATUS_PRODUCER | |||||
'status' => User::STATUS_PRODUCER | |||||
]) | ]) | ||||
->all() ; | ->all() ; | ||||
$producer = ProducerModel::searchOne() ; | |||||
$producer = Producer::searchOne() ; | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'usersArray' => $usersArray, | 'usersArray' => $usersArray, | ||||
*/ | */ | ||||
public function actionDelete($idUser) | public function actionDelete($idUser) | ||||
{ | { | ||||
$user = UserModel::searchOne([ | |||||
$user = User::searchOne([ | |||||
'id' => $idUser | 'id' => $idUser | ||||
]) ; | ]) ; | ||||
if($user) { | if($user) { | ||||
$user->id_producer = 0 ; | $user->id_producer = 0 ; | ||||
$user->status = UserModel::STATUS_ACTIVE ; | |||||
$user->status = User::STATUS_ACTIVE ; | |||||
$user->save() ; | $user->save() ; | ||||
Yii::$app->getSession()->setFlash('success', 'Droits de l\'utilisateur supprimé.'); | Yii::$app->getSession()->setFlash('success', 'Droits de l\'utilisateur supprimé.'); | ||||
} | } |
use backend\models\MailForm ; | use backend\models\MailForm ; | ||||
use yii\web\NotFoundHttpException ; | use yii\web\NotFoundHttpException ; | ||||
use common\models\UserModel ; | |||||
use common\models\ User ; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN; | |||||
return User::getCurrentStatus() == User::STATUS_ADMIN; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
public function actionIndex($section = 'producers') | public function actionIndex($section = 'producers') | ||||
{ | { | ||||
if($section == 'producers') { | if($section == 'producers') { | ||||
$producers = ProducerModel::find()->where(['producer.active' => 1])->with(['contact'])->all() ; | |||||
$producers = Producer::find()->where(['producer.active' => 1])->with(['contact'])->all() ; | |||||
$usersArray = []; | $usersArray = []; | ||||
$users = [] ; | $users = [] ; | ||||
foreach ($producers as $producer) { | foreach ($producers as $producer) { | ||||
} | } | ||||
} | } | ||||
elseif($section == 'users') { | elseif($section == 'users') { | ||||
$users = UserModel::find() | |||||
$users = User::find() | |||||
->where([ | ->where([ | ||||
'user.status' => UserModel::STATUS_ACTIVE | |||||
'user.status' => User::STATUS_ACTIVE | |||||
]) | ]) | ||||
->all() ; | ->all() ; | ||||
$usersArray = []; | $usersArray = []; |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
*/ | */ | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$producer = ProducerModel::searchOne() ; | |||||
$pointsSaleArray = PointSaleModel::searchAll() ; | |||||
$producer = Producer::searchOne() ; | |||||
$pointsSaleArray = PointSale::searchAll() ; | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'producer' => $producer, | 'producer' => $producer, | ||||
*/ | */ | ||||
public function actionInstructions() | public function actionInstructions() | ||||
{ | { | ||||
$producer = ProducerModel::searchOne() ; | |||||
$producer = Producer::searchOne() ; | |||||
// get your HTML raw content without any layouts or scripts | // get your HTML raw content without any layouts or scripts | ||||
$content = $this->renderPartial('instructions_multi', [ | $content = $this->renderPartial('instructions_multi', [ |
$dateTime = strtotime("+7 day"); | $dateTime = strtotime("+7 day"); | ||||
$dayStr = strtolower(date('l', $dateTime)); | $dayStr = strtolower(date('l', $dateTime)); | ||||
$fieldDeliveryDay = 'delivery_' . $dayStr; | $fieldDeliveryDay = 'delivery_' . $dayStr; | ||||
$pointsSaleArray = PointSaleModel::searchAll(['point_sale.id_producer' => $producer->id]); | |||||
$pointsSaleArray = PointSale::searchAll(['point_sale.id_producer' => $producer->id]); | |||||
$activeDistribution = false; | $activeDistribution = false; | ||||
foreach ($pointsSaleArray as $pointSale) { | foreach ($pointsSaleArray as $pointSale) { | ||||
if ($pointSale->$fieldDeliveryDay) { | if ($pointSale->$fieldDeliveryDay) { | ||||
} | } | ||||
} | } | ||||
$arrayProducers = ProducerModel::searchAll(); | |||||
$arrayProducers = Producer::searchAll(); | |||||
foreach ($arrayProducers as $producer) { | foreach ($arrayProducers as $producer) { | ||||
$countOrders = 0; | $countOrders = 0; | ||||
* Paiement des commandes (paiement automatique) | * Paiement des commandes (paiement automatique) | ||||
*/ | */ | ||||
$arrayOrders = OrderModel::searchAll([ | |||||
$arrayOrders = Order::searchAll([ | |||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'distribution.id_producer' => $producer->id | 'distribution.id_producer' => $producer->id | ||||
], [ | ], [ | ||||
'conditions' => 'date_delete IS NULL' | 'conditions' => 'date_delete IS NULL' | ||||
]); | ]); | ||||
$configCredit = ProducerModel::getConfig('credit', $producer->id); | |||||
$configCredit = Producer::getConfig('credit', $producer->id); | |||||
if ($arrayOrders && is_array($arrayOrders)) { | if ($arrayOrders && is_array($arrayOrders)) { | ||||
foreach ($arrayOrders as $order) { | foreach ($arrayOrders as $order) { | ||||
if ($order->auto_payment && $configCredit) { | if ($order->auto_payment && $configCredit) { | ||||
if ($order->getAmount(OrderModel::AMOUNT_REMAINING) > 0) { | |||||
if ($order->getAmount(Order::AMOUNT_REMAINING) > 0) { | |||||
$order->saveCreditHistory( | $order->saveCreditHistory( | ||||
CreditHistoryModel::TYPE_PAYMENT, | |||||
$order->getAmount(OrderModel::AMOUNT_REMAINING), | |||||
CreditHistory::TYPE_PAYMENT, | |||||
$order->getAmount(Order::AMOUNT_REMAINING), | |||||
$order->distribution->id_producer, | $order->distribution->id_producer, | ||||
$order->id_user, | $order->id_user, | ||||
UserModel::ID_USER_SYSTEM | |||||
User::ID_USER_SYSTEM | |||||
); | ); | ||||
$countOrders++; | $countOrders++; | ||||
} | } | ||||
* Envoi des commandes par email au producteur | * Envoi des commandes par email au producteur | ||||
*/ | */ | ||||
if (!strlen($forceDate) && ProducerModel::getConfig('option_notify_producer_order_summary', $producer->id)) { | |||||
$arrayOrders = OrderModel::searchAll([ | |||||
if (!strlen($forceDate) && Producer::getConfig('option_notify_producer_order_summary', $producer->id)) { | |||||
$arrayOrders = Order::searchAll([ | |||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'distribution.id_producer' => $producer->id | 'distribution.id_producer' => $producer->id | ||||
], [ | ], [ | ||||
$mail->setSubject($subject); | $mail->setSubject($subject); | ||||
// envoi des emails à tous les comptes users (statut producer) associés à ce producteur | // envoi des emails à tous les comptes users (statut producer) associés à ce producteur | ||||
$userArray = UserModel::searchAll([ | |||||
$userArray = User::searchAll([ | |||||
'id_producer' => $producer->id, | 'id_producer' => $producer->id, | ||||
'status' => UserModel::STATUS_PRODUCER | |||||
'status' => User::STATUS_PRODUCER | |||||
]); | ]); | ||||
foreach ($userArray as $user) { | foreach ($userArray as $user) { |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend() ; | |||||
return User::hasAccessBackend() ; | |||||
} | } | ||||
] | ] | ||||
], | ], |
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\Order; | use common\models\Order; | ||||
use common\models\ProductCategory; | use common\models\ProductCategory; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use common\models\Subscription; | use common\models\Subscription; | ||||
use common\helpers\Price; | use common\helpers\Price; | ||||
use common\models\PointSaleDistribution; | use common\models\PointSaleDistribution; | ||||
use common\logic\UserProducer\UserProducerModel; | |||||
use common\logic\UserProducer\ UserProducer; | |||||
use DateTime; | use DateTime; | ||||
class DistributionController extends BackendController | class DistributionController extends BackendController | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN | |||||
|| UserModel::getCurrentStatus() == UserModel::STATUS_PRODUCER; | |||||
return User::getCurrentStatus() == User::STATUS_ADMIN | |||||
|| User::getCurrentStatus() == User::STATUS_PRODUCER; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
$orderUpdate = null; | $orderUpdate = null; | ||||
if ($idOrderUpdate) { | if ($idOrderUpdate) { | ||||
$orderUpdate = OrderModel::searchOne(['id' => $idOrderUpdate]); | |||||
$orderUpdate = Order::searchOne(['id' => $idOrderUpdate]); | |||||
} | } | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
]; | ]; | ||||
// commandes | // commandes | ||||
$ordersArray = OrderModel::searchAll([ | |||||
$ordersArray = Order::searchAll([ | |||||
'distribution.id' => $distribution->id, | 'distribution.id' => $distribution->id, | ||||
], [ | ], [ | ||||
'orderby' => 'user.lastname ASC, user.name ASC' | 'orderby' => 'user.lastname ASC, user.name ASC' | ||||
$json['distribution']['weight'] = number_format($weight, 2); | $json['distribution']['weight'] = number_format($weight, 2); | ||||
// products | // products | ||||
$productsQuery = ProductModel::find() | |||||
$productsQuery = Product::find() | |||||
->orWhere(['id_producer' => GlobalParam::getCurrentProducerId(),]) | ->orWhere(['id_producer' => GlobalParam::getCurrentProducerId(),]) | ||||
->joinWith([ | ->joinWith([ | ||||
'taxRate', | 'taxRate', | ||||
$potentialWeight = 0; | $potentialWeight = 0; | ||||
foreach ($productsArray as &$theProduct) { | foreach ($productsArray as &$theProduct) { | ||||
$quantityOrder = OrderModel::getProductQuantity($theProduct['id'], $ordersArray); | |||||
$quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray); | |||||
$theProduct['quantity_ordered'] = $quantityOrder; | $theProduct['quantity_ordered'] = $quantityOrder; | ||||
if (!isset($theProduct['productDistribution'][0])) { | if (!isset($theProduct['productDistribution'][0])) { | ||||
$productOrderArray = []; | $productOrderArray = []; | ||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
$productOrderArray[$productOrder->id_product] = [ | $productOrderArray[$productOrder->id_product] = [ | ||||
'quantity' => $productOrder->quantity * ProductModel::$unitsArray[$productOrder->unit]['coefficient'], | |||||
'quantity' => $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'], | |||||
'unit' => $productOrder->unit, | 'unit' => $productOrder->unit, | ||||
'price' => number_format($productOrder->price, 3), | 'price' => number_format($productOrder->price, 3), | ||||
'invoice_price' => number_format($productOrder->invoice_price, 2), | 'invoice_price' => number_format($productOrder->invoice_price, 2), | ||||
'wording' => $creditHistoryService->getStrWording($creditHistory), | 'wording' => $creditHistoryService->getStrWording($creditHistory), | ||||
'debit' => ($creditHistoryService->isTypeDebit($creditHistory) ? '- ' . $creditHistoryService->getAmount( | 'debit' => ($creditHistoryService->isTypeDebit($creditHistory) ? '- ' . $creditHistoryService->getAmount( | ||||
$creditHistory, | $creditHistory, | ||||
OrderModel::AMOUNT_TOTAL, | |||||
Order::AMOUNT_TOTAL, | |||||
true | true | ||||
) : ''), | ) : ''), | ||||
'credit' => ($creditHistoryService->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryService->getAmount( | 'credit' => ($creditHistoryService->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryService->getAmount( | ||||
$creditHistory, | $creditHistory, | ||||
OrderModel::AMOUNT_TOTAL, | |||||
Order::AMOUNT_TOTAL, | |||||
true | true | ||||
) : '') | ) : '') | ||||
]; | ]; | ||||
$order = array_merge($order->getAttributes(), [ | $order = array_merge($order->getAttributes(), [ | ||||
'selected' => false, | 'selected' => false, | ||||
'weight' => $order->weight, | 'weight' => $order->weight, | ||||
'amount' => Price::numberTwoDecimals($order->getAmountWithTax(OrderModel::AMOUNT_TOTAL)), | |||||
'amount_paid' => Price::numberTwoDecimals($order->getAmount(OrderModel::AMOUNT_PAID)), | |||||
'amount_remaining' => Price::numberTwoDecimals($order->getAmount(OrderModel::AMOUNT_REMAINING)), | |||||
'amount_surplus' => Price::numberTwoDecimals($order->getAmount(OrderModel::AMOUNT_SURPLUS)), | |||||
'amount' => Price::numberTwoDecimals($order->getAmountWithTax(Order::AMOUNT_TOTAL)), | |||||
'amount_paid' => Price::numberTwoDecimals($order->getAmount(Order::AMOUNT_PAID)), | |||||
'amount_remaining' => Price::numberTwoDecimals($order->getAmount(Order::AMOUNT_REMAINING)), | |||||
'amount_surplus' => Price::numberTwoDecimals($order->getAmount(Order::AMOUNT_SURPLUS)), | |||||
'user' => (isset($order->user)) ? array_merge( | 'user' => (isset($order->user)) ? array_merge( | ||||
$order->user->getAttributes(), | $order->user->getAttributes(), | ||||
$arrayCreditUser | $arrayCreditUser | ||||
$json['orders'] = $ordersArray; | $json['orders'] = $ordersArray; | ||||
// points de vente | // points de vente | ||||
$pointsSaleArray = PointSaleModel::find() | |||||
$pointsSaleArray = PointSale::find() | |||||
->joinWith([ | ->joinWith([ | ||||
'pointSaleDistribution' => function ($q) use ($distribution) { | 'pointSaleDistribution' => function ($q) use ($distribution) { | ||||
$q->where(['id_distribution' => $distribution->id]); | $q->where(['id_distribution' => $distribution->id]); | ||||
$json['points_sale'] = $pointsSaleArray; | $json['points_sale'] = $pointsSaleArray; | ||||
// bons de livraison | // bons de livraison | ||||
$deliveryNotesArray = DeliveryNoteModel::searchAll([ | |||||
$deliveryNotesArray = DeliveryNote::searchAll([ | |||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
], [ | ], [ | ||||
'join_with' => ['user AS user_delivery_note', 'orders', 'producer'] | 'join_with' => ['user AS user_delivery_note', 'orders', 'producer'] | ||||
]; | ]; | ||||
// utilisateurs | // utilisateurs | ||||
$usersArray = UserModel::findBy()->all(); | |||||
$usersArray = User::findBy()->all(); | |||||
$json['users'] = $usersArray; | $json['users'] = $usersArray; | ||||
} | } | ||||
// abonnements manquants | // abonnements manquants | ||||
$arraySubscriptions = SubscriptionModel::searchByDate($date); | |||||
$arraySubscriptions = Subscription::searchByDate($date); | |||||
$json['missing_subscriptions'] = []; | $json['missing_subscriptions'] = []; | ||||
if ($distribution->active) { | if ($distribution->active) { | ||||
foreach ($arraySubscriptions as $subscription) { | foreach ($arraySubscriptions as $subscription) { | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$user = UserModel::findOne(['id' => $idUser]); | |||||
$user = User::findOne(['id' => $idUser]); | |||||
$favoritePointSale = $user->getFavoritePointSale(); | $favoritePointSale = $user->getFavoritePointSale(); | ||||
$idFavoritePointSale = 0; | $idFavoritePointSale = 0; | ||||
if ($favoritePointSale) { | if ($favoritePointSale) { | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$order = OrderModel::searchOne(['id' => $idOrder]); | |||||
$order = Order::searchOne(['id' => $idOrder]); | |||||
$distribution = DistributionModel::findOne($idDistribution); | $distribution = DistributionModel::findOne($idDistribution); | ||||
$user = UserModel::findOne($idUser); | |||||
$pointSale = PointSaleModel::findOne($idPointSale); | |||||
$user = User::findOne($idUser); | |||||
$pointSale = PointSale::findOne($idPointSale); | |||||
$productsArray = ProductModel::find() | |||||
$productsArray = Product::find() | |||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
])->joinWith([ | ])->joinWith([ | ||||
$productOrderArray[$product['id']] = [ | $productOrderArray[$product['id']] = [ | ||||
'quantity' => $quantity, | 'quantity' => $quantity, | ||||
'unit' => $product->unit, | 'unit' => $product->unit, | ||||
'unit_coefficient' => ProductModel::$unitsArray[$product->unit]['coefficient'], | |||||
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'], | |||||
'prices' => $priceArray, | 'prices' => $priceArray, | ||||
'active' => $product->productDistribution[0]->active | 'active' => $product->productDistribution[0]->active | ||||
&& (!$pointSale || $product->isAvailableOnPointSale($pointSale)), | && (!$pointSale || $product->isAvailableOnPointSale($pointSale)), | ||||
public function actionAjaxUpdateInvoicePrices($idOrder) | public function actionAjaxUpdateInvoicePrices($idOrder) | ||||
{ | { | ||||
$order = OrderModel::searchOne([ | |||||
$order = Order::searchOne([ | |||||
'id' => (int)$idOrder | 'id' => (int)$idOrder | ||||
]); | ]); | ||||
if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | ||||
$userProducer = null; | $userProducer = null; | ||||
if ($order->id_user) { | if ($order->id_user) { | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $order->id_user, | 'id_user' => $order->id_user, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
$idProducer = GlobalParam::getCurrentProducerId(); | $idProducer = GlobalParam::getCurrentProducerId(); | ||||
} | } | ||||
$ordersArray = OrderModel::searchAll( | |||||
$ordersArray = Order::searchAll( | |||||
[ | [ | ||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'distribution.id_producer' => $idProducer | 'distribution.id_producer' => $idProducer | ||||
if ($distribution) { | if ($distribution) { | ||||
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | $selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | ||||
$pointsSaleArray = PointSaleModel::searchAll([ | |||||
$pointsSaleArray = PointSale::searchAll([ | |||||
'point_sale.id_producer' => $idProducer | 'point_sale.id_producer' => $idProducer | ||||
]); | ]); | ||||
} | } | ||||
// produits | // produits | ||||
$productsArray = ProductModel::find() | |||||
$productsArray = Product::find() | |||||
->joinWith([ | ->joinWith([ | ||||
'productDistribution' => function ($q) use ($distribution) { | 'productDistribution' => function ($q) use ($distribution) { | ||||
$q->where(['id_distribution' => $distribution->id]); | $q->where(['id_distribution' => $distribution->id]); | ||||
'pointsSaleArray' => $pointsSaleArray, | 'pointsSaleArray' => $pointsSaleArray, | ||||
'productsArray' => $productsArray, | 'productsArray' => $productsArray, | ||||
'ordersArray' => $ordersArray, | 'ordersArray' => $ordersArray, | ||||
'producer' => ProducerModel::searchOne(['id' => $idProducer]) | |||||
'producer' => Producer::searchOne(['id' => $idProducer]) | |||||
]); | ]); | ||||
$dateStr = date('d/m/Y', strtotime($date)); | $dateStr = date('d/m/Y', strtotime($date)); | ||||
} elseif ($type == 'csv') { | } elseif ($type == 'csv') { | ||||
$datas = []; | $datas = []; | ||||
$optionCsvExportAllProducts = ProducerModel::getConfig('option_csv_export_all_products'); | |||||
$optionCsvExportByPiece = ProducerModel::getConfig('option_csv_export_by_piece'); | |||||
$optionCsvExportAllProducts = Producer::getConfig('option_csv_export_all_products'); | |||||
$optionCsvExportByPiece = Producer::getConfig('option_csv_export_by_piece'); | |||||
// produits en colonne | // produits en colonne | ||||
$productsNameArray = ['', 'Commentaire']; | $productsNameArray = ['', 'Commentaire']; | ||||
$cpt = 2; | $cpt = 2; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
$productsHasQuantity[$product->id] = 0; | $productsHasQuantity[$product->id] = 0; | ||||
foreach (ProductModel::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = OrderModel::getProductQuantity($product->id, $ordersArray, true, $unit); | |||||
foreach ( Product::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = Order::getProductQuantity($product->id, $ordersArray, true, $unit); | |||||
if ($quantity) { | if ($quantity) { | ||||
$productsHasQuantity[$product->id] += $quantity; | $productsHasQuantity[$product->id] += $quantity; | ||||
} | } | ||||
$productUnit = $product->unit; | $productUnit = $product->unit; | ||||
} | } | ||||
$productName .= ' (' . ProductModel::strUnit($productUnit, 'wording_short', true) . ')'; | |||||
$productName .= ' (' . Product::strUnit($productUnit, 'wording_short', true) . ')'; | |||||
$productsNameArray[] = $productName; | $productsNameArray[] = $productName; | ||||
$productsIndexArray[$product->id] = $cpt++; | $productsIndexArray[$product->id] = $cpt++; | ||||
if ($optionCsvExportByPiece) { | if ($optionCsvExportByPiece) { | ||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
$orderLine[$productsIndexArray[$productOrder->id_product]] = OrderModel::getProductQuantityPieces( | |||||
$orderLine[$productsIndexArray[$productOrder->id_product]] = Order::getProductQuantityPieces( | |||||
$productOrder->id_product, | $productOrder->id_product, | ||||
[$order] | [$order] | ||||
); | ); | ||||
} | } | ||||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity; | $orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity; | ||||
if ($productOrder->product->unit != $productOrder->unit) { | if ($productOrder->product->unit != $productOrder->unit) { | ||||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= ProductModel::strUnit( | |||||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= Product::strUnit( | |||||
$productOrder->unit, | $productOrder->unit, | ||||
'wording_short', | 'wording_short', | ||||
true | true | ||||
]); | ]); | ||||
if ($distribution) { | if ($distribution) { | ||||
$ordersArray = OrderModel::searchAll( | |||||
$ordersArray = Order::searchAll( | |||||
[ | [ | ||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'distribution.id_producer' => $idProducer | 'distribution.id_producer' => $idProducer | ||||
); | ); | ||||
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | $selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | ||||
$pointsSaleArray = PointSaleModel::searchAll([ | |||||
$pointsSaleArray = PointSale::searchAll([ | |||||
'point_sale.id_producer' => $idProducer | 'point_sale.id_producer' => $idProducer | ||||
]); | ]); | ||||
} | } | ||||
// catégories | // catégories | ||||
$categoriesArray = ProductCategoryModel::searchAll( | |||||
$categoriesArray = ProductCategory::searchAll( | |||||
['id_producer' => $idProducer], | ['id_producer' => $idProducer], | ||||
['orderby' => 'product_category.position ASC'] | ['orderby' => 'product_category.position ASC'] | ||||
); | ); | ||||
array_unshift($categoriesArray, null); | array_unshift($categoriesArray, null); | ||||
// produits | // produits | ||||
$productsArray = ProductModel::find() | |||||
$productsArray = Product::find() | |||||
->joinWith([ | ->joinWith([ | ||||
'productDistribution' => function ($q) use ($distribution) { | 'productDistribution' => function ($q) use ($distribution) { | ||||
$q->where(['id_distribution' => $distribution->id]); | $q->where(['id_distribution' => $distribution->id]); | ||||
'categoriesArray' => $categoriesArray, | 'categoriesArray' => $categoriesArray, | ||||
'productsArray' => $productsArray, | 'productsArray' => $productsArray, | ||||
'ordersArray' => $ordersArrayPaged, | 'ordersArray' => $ordersArrayPaged, | ||||
'producer' => ProducerModel::searchOne(['id' => $idProducer]) | |||||
'producer' => Producer::searchOne(['id' => $idProducer]) | |||||
]); | ]); | ||||
$dateStr = date('d/m/Y', strtotime($date)); | $dateStr = date('d/m/Y', strtotime($date)); | ||||
public function actionReportTerredepains($date, $key) | public function actionReportTerredepains($date, $key) | ||||
{ | { | ||||
if ($key == 'ef572cc148c001f0180c4a624189ed30') { | if ($key == 'ef572cc148c001f0180c4a624189ed30') { | ||||
$producer = ProducerModel::searchOne([ | |||||
$producer = Producer::searchOne([ | |||||
'producer.slug' => 'terredepains' | 'producer.slug' => 'terredepains' | ||||
]); | ]); | ||||
$idProducer = $producer->id; | $idProducer = $producer->id; | ||||
$ordersArray = OrderModel::searchAll( | |||||
$ordersArray = Order::searchAll( | |||||
[ | [ | ||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'distribution.id_producer' => $idProducer | 'distribution.id_producer' => $idProducer | ||||
if ($distribution) { | if ($distribution) { | ||||
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | $selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | ||||
$pointsSaleArray = PointSaleModel::searchAll([ | |||||
$pointsSaleArray = PointSale::searchAll([ | |||||
'point_sale.id_producer' => $idProducer | 'point_sale.id_producer' => $idProducer | ||||
]); | ]); | ||||
} | } | ||||
// produits | // produits | ||||
$productsArray = ProductModel::find() | |||||
$productsArray = Product::find() | |||||
->joinWith([ | ->joinWith([ | ||||
'productDistribution' => function ($q) use ($distribution) { | 'productDistribution' => function ($q) use ($distribution) { | ||||
$q->where(['id_distribution' => $distribution->id]); | $q->where(['id_distribution' => $distribution->id]); | ||||
$productsHasQuantity = []; | $productsHasQuantity = []; | ||||
$cpt = 1; | $cpt = 1; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
$theUnit = ProductModel::strUnit($product->unit, 'wording_short', true); | |||||
$theUnit = Product::strUnit($product->unit, 'wording_short', true); | |||||
$theUnit = ($theUnit == 'p.') ? '' : ' (' . $theUnit . ')'; | $theUnit = ($theUnit == 'p.') ? '' : ' (' . $theUnit . ')'; | ||||
$productsNameArray[] = $product->name . $theUnit; | $productsNameArray[] = $product->name . $theUnit; | ||||
$productsIndexArray[$product->id] = $cpt++; | $productsIndexArray[$product->id] = $cpt++; | ||||
} | } | ||||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity; | $orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity; | ||||
if ($productOrder->product->unit != $productOrder->unit) { | if ($productOrder->product->unit != $productOrder->unit) { | ||||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= ProductModel::strUnit($productOrder->unit, 'wording_short', true); | |||||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= Product::strUnit($productOrder->unit, 'wording_short', true); | |||||
} | } | ||||
} | } | ||||
$datas[] = $this->_lineOrderReportCSV($orderLine, $cpt - 1, true); | $datas[] = $this->_lineOrderReportCSV($orderLine, $cpt - 1, true); | ||||
{ | { | ||||
$totalsPointSaleArray = [$label]; | $totalsPointSaleArray = [$label]; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
foreach (ProductModel::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = OrderModel::getProductQuantity($product->id, $ordersArray, false, $unit); | |||||
foreach ( Product::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit); | |||||
if ($quantity) { | if ($quantity) { | ||||
$index = $productsIndexArray[$product->id]; | $index = $productsIndexArray[$product->id]; | ||||
if (!isset($totalsPointSaleArray[$index])) { | if (!isset($totalsPointSaleArray[$index])) { | ||||
$totalsPointSaleArray[$index] .= $quantity; | $totalsPointSaleArray[$index] .= $quantity; | ||||
if ($product->unit != $unit) { | if ($product->unit != $unit) { | ||||
$totalsPointSaleArray[$index] .= '' . ProductModel::strUnit($unit, 'wording_short', true); | |||||
$totalsPointSaleArray[$index] .= '' . Product::strUnit($unit, 'wording_short', true); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
$quantity = 0; | $quantity = 0; | ||||
foreach (ProductModel::$unitsArray as $unit => $dataUnit) { | |||||
$quantityProduct = OrderModel::getProductQuantity($product->id, $ordersArray, false, $unit); | |||||
foreach ( Product::$unitsArray as $unit => $dataUnit) { | |||||
$quantityProduct = Order::getProductQuantity($product->id, $ordersArray, false, $unit); | |||||
if ($unit == 'piece') { | if ($unit == 'piece') { | ||||
$quantity += $quantityProduct; | $quantity += $quantityProduct; | ||||
$dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); | $dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); | ||||
$dateSunday = date('Y-m-d', strtotime('Sunday', $start)); | $dateSunday = date('Y-m-d', strtotime('Sunday', $start)); | ||||
$pointsSaleArray = PointSaleModel::searchAll(); | |||||
$pointsSaleArray = PointSale::searchAll(); | |||||
$activeMonday = false; | $activeMonday = false; | ||||
$activeTuesday = false; | $activeTuesday = false; | ||||
public function actionAjaxProcessAddSubscriptions($date) | public function actionAjaxProcessAddSubscriptions($date) | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
SubscriptionModel::addAll($date, true); | |||||
Subscription::addAll($date, true); | |||||
return ['success']; | return ['success']; | ||||
} | } | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$return = []; | $return = []; | ||||
$producerTiller = ProducerModel::getConfig('tiller'); | |||||
$producerTiller = Producer::getConfig('tiller'); | |||||
if ($producerTiller) { | if ($producerTiller) { | ||||
$tiller = new Tiller(); | $tiller = new Tiller(); | ||||
$isSynchro = $tiller->isSynchro($date); | $isSynchro = $tiller->isSynchro($date); | ||||
if (!$isSynchro) { | if (!$isSynchro) { | ||||
$orders = OrderModel::searchAll([ | |||||
$orders = Order::searchAll([ | |||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'order.tiller_synchronization' => 1 | 'order.tiller_synchronization' => 1 | ||||
], [ | ], [ | ||||
[ | [ | ||||
'type' => $typePaymentTiller, | 'type' => $typePaymentTiller, | ||||
'amount' => $order->getAmountWithTax( | 'amount' => $order->getAmountWithTax( | ||||
OrderModel::AMOUNT_TOTAL | |||||
Order::AMOUNT_TOTAL | |||||
) * 100, | ) * 100, | ||||
'status' => 'ACCEPTED', | 'status' => 'ACCEPTED', | ||||
'date' => $strDate | 'date' => $strDate | ||||
if (is_array($idOrders) && count($idOrders) > 0) { | if (is_array($idOrders) && count($idOrders) > 0) { | ||||
foreach ($idOrders as $idOrder) { | foreach ($idOrders as $idOrder) { | ||||
$order = OrderModel::searchOne([ | |||||
$order = Order::searchOne([ | |||||
'id' => (int)$idOrder | 'id' => (int)$idOrder | ||||
]); | ]); | ||||
if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | ||||
$deliveryNote = DeliveryNoteModel::searchOne([ | |||||
$deliveryNote = DeliveryNote::searchOne([ | |||||
'id' => (int)$order->id_delivery_note | 'id' => (int)$order->id_delivery_note | ||||
]); | ]); | ||||
if (is_array($idOrders) && count($idOrders) > 0) { | if (is_array($idOrders) && count($idOrders) > 0) { | ||||
foreach ($idOrders as $idOrder) { | foreach ($idOrders as $idOrder) { | ||||
$order = OrderModel::searchOne([ | |||||
$order = Order::searchOne([ | |||||
'id' => (int)$idOrder | 'id' => (int)$idOrder | ||||
]); | ]); | ||||
$deliveryNote = null; | $deliveryNote = null; | ||||
$idDeliveryNote = $order->id_delivery_note; | $idDeliveryNote = $order->id_delivery_note; | ||||
if ($idDeliveryNote) { | if ($idDeliveryNote) { | ||||
$deliveryNote = DeliveryNoteModel::searchOne([ | |||||
$deliveryNote = DeliveryNote::searchOne([ | |||||
'id' => (int)$idDeliveryNote | 'id' => (int)$idDeliveryNote | ||||
]); | ]); | ||||
} | } | ||||
$order->save(); | $order->save(); | ||||
// init invoice prices | // init invoice prices | ||||
$user = UserModel::searchOne([ | |||||
$user = User::searchOne([ | |||||
'id' => $deliveryNote->id_user | 'id' => $deliveryNote->id_user | ||||
]); | ]); | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $deliveryNote->id_user, | 'id_user' => $deliveryNote->id_user, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
if (is_array($idOrders) && count($idOrders) > 0) { | if (is_array($idOrders) && count($idOrders) > 0) { | ||||
// récupération première commande pour obtenir des infos | // récupération première commande pour obtenir des infos | ||||
reset($idOrders); | reset($idOrders); | ||||
$firstOrder = OrderModel::searchOne([ | |||||
$firstOrder = Order::searchOne([ | |||||
'id' => (int)$idOrders[key($idOrders)] | 'id' => (int)$idOrders[key($idOrders)] | ||||
]); | ]); | ||||
$deliveryNote = null; | $deliveryNote = null; | ||||
$isUpdate = false; | $isUpdate = false; | ||||
$i = 0; | $i = 0; | ||||
$ordersArray = OrderModel::searchAll([ | |||||
$ordersArray = Order::searchAll([ | |||||
'id' => $idOrders, | 'id' => $idOrders, | ||||
]); | ]); | ||||
do { | do { | ||||
$order = $ordersArray[$i]; | $order = $ordersArray[$i]; | ||||
if ($order->distribution->id_producer == GlobalParam::getCurrentProducerId() && $order->id_delivery_note > 0) { | if ($order->distribution->id_producer == GlobalParam::getCurrentProducerId() && $order->id_delivery_note > 0) { | ||||
$deliveryNote = DeliveryNoteModel::searchOne([ | |||||
$deliveryNote = DeliveryNote::searchOne([ | |||||
'id' => $order->id_delivery_note | 'id' => $order->id_delivery_note | ||||
]); | ]); | ||||
$isUpdate = true; | $isUpdate = true; | ||||
$i++; | $i++; | ||||
} while ($deliveryNote == null && isset($ordersArray[$i])); | } while ($deliveryNote == null && isset($ordersArray[$i])); | ||||
if ($deliveryNote && $deliveryNote->status == DocumentModel::STATUS_VALID) { | |||||
if ($deliveryNote && $deliveryNote->status == Document::STATUS_VALID) { | |||||
return [ | return [ | ||||
'return' => 'error', | 'return' => 'error', | ||||
'alert' => [ | 'alert' => [ | ||||
if ($firstOrder->pointSale->id_user) { | if ($firstOrder->pointSale->id_user) { | ||||
$deliveryNote->id_user = $firstOrder->pointSale->id_user; | $deliveryNote->id_user = $firstOrder->pointSale->id_user; | ||||
$user = UserModel::searchOne([ | |||||
$user = User::searchOne([ | |||||
'id' => $deliveryNote->id_user | 'id' => $deliveryNote->id_user | ||||
]); | ]); | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $deliveryNote->id_user, | 'id_user' => $deliveryNote->id_user, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
} else { | } else { | ||||
$user = new UserModel; | |||||
$user->type = UserModel::TYPE_LEGAL_PERSON; | |||||
$user = new User; | |||||
$user->type = User::TYPE_LEGAL_PERSON; | |||||
$user->name_legal_person = $firstOrder->pointSale->name; | $user->name_legal_person = $firstOrder->pointSale->name; | ||||
$user->address = $firstOrder->pointSale->address; | $user->address = $firstOrder->pointSale->address; | ||||
$user->id_producer = 0; | $user->id_producer = 0; | ||||
} | } | ||||
$user->save(); | $user->save(); | ||||
$userProducer = new UserProducerModel; | |||||
$userProducer = new UserProducer; | |||||
$userProducer->id_user = $user->id; | $userProducer->id_user = $user->id; | ||||
$userProducer->id_producer = GlobalParam::getCurrentProducerId(); | $userProducer->id_producer = GlobalParam::getCurrentProducerId(); | ||||
$userProducer->credit = 0; | $userProducer->credit = 0; | ||||
$deliveryNote->save(); | $deliveryNote->save(); | ||||
} else { | } else { | ||||
// réinitialisation des order.id_delivery_note | // réinitialisation des order.id_delivery_note | ||||
OrderModel::updateAll([ | |||||
Order::updateAll([ | |||||
'id_delivery_note' => null | 'id_delivery_note' => null | ||||
], [ | ], [ | ||||
'id_delivery_note' => $deliveryNote->id | 'id_delivery_note' => $deliveryNote->id | ||||
} | } | ||||
if (!isset($user) || !$user) { | if (!isset($user) || !$user) { | ||||
$user = UserModel::searchOne([ | |||||
$user = User::searchOne([ | |||||
'id' => $deliveryNote->id_user | 'id' => $deliveryNote->id_user | ||||
]); | ]); | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $deliveryNote->id_user, | 'id_user' => $deliveryNote->id_user, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
// affectation du BL aux commandes | // affectation du BL aux commandes | ||||
foreach ($idOrders as $idOrder) { | foreach ($idOrders as $idOrder) { | ||||
$order = OrderModel::searchOne([ | |||||
$order = Order::searchOne([ | |||||
'id' => (int)$idOrder | 'id' => (int)$idOrder | ||||
]); | ]); | ||||
if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | ||||
} | } | ||||
// init invoice price | // init invoice price | ||||
$order = OrderModel::searchOne(['id' => $idOrder]); | |||||
$order = Order::searchOne(['id' => $idOrder]); | |||||
if ($order) { | if ($order) { | ||||
$order->initInvoicePrices([ | $order->initInvoicePrices([ | ||||
'user' => $user, | 'user' => $user, |
use common\models\PointSale; | use common\models\PointSale; | ||||
use common\models\Product; | use common\models\Product; | ||||
use common\models\Quotation; | use common\models\Quotation; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use common\models\Document; | use common\models\Document; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\models\Order; | use common\models\Order; | ||||
use common\logic\UserProducer\UserProducerModel; | |||||
use common\logic\UserProducer\ UserProducer; | |||||
use kartik\mpdf\Pdf; | use kartik\mpdf\Pdf; | ||||
use yii\base\UserException; | use yii\base\UserException; | ||||
use yii; | use yii; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
set_time_limit(0); | set_time_limit(0); | ||||
$validatedDocumentsArray = array_merge( | $validatedDocumentsArray = array_merge( | ||||
QuotationModel::find()->where(['status' => DocumentModel::STATUS_VALID])->all(), | |||||
DeliveryNoteModel::find()->where(['status' => DocumentModel::STATUS_VALID])->all(), | |||||
InvoiceModel::find()->where(['status' => DocumentModel::STATUS_VALID])->all() | |||||
Quotation::find()->where(['status' => Document::STATUS_VALID])->all(), | |||||
DeliveryNote::find()->where(['status' => Document::STATUS_VALID])->all(), | |||||
Invoice::find()->where(['status' => Document::STATUS_VALID])->all() | |||||
); | ); | ||||
foreach($validatedDocumentsArray as $document) { | foreach($validatedDocumentsArray as $document) { | ||||
if ($model->getClass() == 'Invoice') { | if ($model->getClass() == 'Invoice') { | ||||
if ($model->deliveryNotes && is_array($model->deliveryNotes) && count($model->deliveryNotes)) { | if ($model->deliveryNotes && is_array($model->deliveryNotes) && count($model->deliveryNotes)) { | ||||
foreach ($model->deliveryNotes as $key => $idDeliveryNote) { | foreach ($model->deliveryNotes as $key => $idDeliveryNote) { | ||||
OrderModel::updateAll([ | |||||
Order::updateAll([ | |||||
'id_invoice' => $model->id | 'id_invoice' => $model->id | ||||
], [ | ], [ | ||||
'id_delivery_note' => $idDeliveryNote | 'id_delivery_note' => $idDeliveryNote | ||||
$model->delete(); | $model->delete(); | ||||
if ($this->getClass() == 'DeliveryNote') { | if ($this->getClass() == 'DeliveryNote') { | ||||
OrderModel::updateAll([ | |||||
Order::updateAll([ | |||||
'order.id_delivery_note' => null | 'order.id_delivery_note' => null | ||||
], [ | ], [ | ||||
'order.id_delivery_note' => $id | 'order.id_delivery_note' => $id | ||||
} | } | ||||
if ($this->getClass() == 'Quotation') { | if ($this->getClass() == 'Quotation') { | ||||
OrderModel::updateAll([ | |||||
Order::updateAll([ | |||||
'order.id_quotation' => null | 'order.id_quotation' => null | ||||
], [ | ], [ | ||||
'order.id_quotation' => $id | 'order.id_quotation' => $id | ||||
} | } | ||||
if ($this->getClass() == 'Invoice') { | if ($this->getClass() == 'Invoice') { | ||||
OrderModel::updateAll([ | |||||
Order::updateAll([ | |||||
'order.id_invoice' => null | 'order.id_invoice' => null | ||||
], [ | ], [ | ||||
'order.id_invoice' => $id | 'order.id_invoice' => $id | ||||
'', // Réf. | '', // Réf. | ||||
$productOrder->product->name, // Désignation * | $productOrder->product->name, // Désignation * | ||||
$productOrder->quantity, // Qté * | $productOrder->quantity, // Qté * | ||||
'', // ProductModel::strUnit($productOrder->unit, 'wording'), // Unité | |||||
'', // Product::strUnit($productOrder->unit, 'wording'), // Unité | |||||
$price, // PU HT * | $price, // PU HT * | ||||
'', // Remise | '', // Remise | ||||
$productOrder->taxRate->value * 100, // TVA | $productOrder->taxRate->value * 100, // TVA | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
if ($idUser > 0) { | if ($idUser > 0) { | ||||
$user = UserModel::searchOne([ | |||||
$user = User::searchOne([ | |||||
'id' => $idUser | 'id' => $idUser | ||||
]); | ]); | ||||
'orderby' => 'distribution.date ASC', | 'orderby' => 'distribution.date ASC', | ||||
'join_with' => ['user AS user_delivery_note', 'orders', 'producer'] | 'join_with' => ['user AS user_delivery_note', 'orders', 'producer'] | ||||
]; | ]; | ||||
$deliveryNotesCreateArray = DeliveryNoteModel::searchAll([ | |||||
$deliveryNotesCreateArray = DeliveryNote::searchAll([ | |||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'status' => DocumentModel::STATUS_VALID | |||||
'status' => Document::STATUS_VALID | |||||
], $options); | ], $options); | ||||
$deliveryNotesUpdateArray = DeliveryNoteModel::searchAll([ | |||||
$deliveryNotesUpdateArray = DeliveryNote::searchAll([ | |||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'status' => DocumentModel::STATUS_VALID, | |||||
'status' => Document::STATUS_VALID, | |||||
'order.id_invoice' => $idDocument | 'order.id_invoice' => $idDocument | ||||
], $options); | ], $options); | ||||
$json['delivery_note_create_array'] = $this->initDeliveryNoteArray('create', $deliveryNotesCreateArray); | $json['delivery_note_create_array'] = $this->initDeliveryNoteArray('create', $deliveryNotesCreateArray); | ||||
$deliveryNote->getAttributes(), | $deliveryNote->getAttributes(), | ||||
[ | [ | ||||
'url' => Yii::$app->urlManager->createUrl(['delivery-note/update', 'id' => $deliveryNote->id]), | 'url' => Yii::$app->urlManager->createUrl(['delivery-note/update', 'id' => $deliveryNote->id]), | ||||
'total' => $deliveryNote->getAmountWithTax(OrderModel::INVOICE_AMOUNT_TOTAL) | |||||
'total' => $deliveryNote->getAmountWithTax(Order::INVOICE_AMOUNT_TOTAL) | |||||
] | ] | ||||
); | ); | ||||
{ | { | ||||
$classDocument = $this->getClass(); | $classDocument = $this->getClass(); | ||||
if ($id > 0 && DocumentModel::isValidClass($classDocument)) { | |||||
if ($id > 0 && Document::isValidClass($classDocument)) { | |||||
$document = $classDocument::searchOne([ | $document = $classDocument::searchOne([ | ||||
'id' => $id | 'id' => $id | ||||
]); | ]); | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
if ($idDocument > 0 && DocumentModel::isValidClass($classDocument)) { | |||||
if ($idDocument > 0 && Document::isValidClass($classDocument)) { | |||||
$document = $classDocument::searchOne([ | $document = $classDocument::searchOne([ | ||||
'id' => $idDocument | 'id' => $idDocument | ||||
]); | ]); | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
if ($idDocument > 0 && DocumentModel::isValidClass($classDocument)) { | |||||
if ($idDocument > 0 && Document::isValidClass($classDocument)) { | |||||
$document = $classDocument::searchOne([ | $document = $classDocument::searchOne([ | ||||
'id' => $idDocument | 'id' => $idDocument | ||||
]); | ]); | ||||
if ($document) { | if ($document) { | ||||
$productsArray = ProductModel::searchAll([], [ | |||||
$productsArray = Product::searchAll([], [ | |||||
'orderby' => 'product.order ASC' | 'orderby' => 'product.order ASC' | ||||
]); | ]); | ||||
); | ); | ||||
} | } | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $document->user->id, | 'id_user' => $document->user->id, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
$pointSale = PointSaleModel::searchOne([ | |||||
$pointSale = PointSale::searchOne([ | |||||
'id_user' => $document->user->id | 'id_user' => $document->user->id | ||||
]); | ]); | ||||
'order', | 'order', | ||||
function ($product) use ($document, $userProducer, $pointSale) { | function ($product) use ($document, $userProducer, $pointSale) { | ||||
return array_merge($product->getAttributes(), [ | return array_merge($product->getAttributes(), [ | ||||
'unit_coefficient' => ProductModel::$unitsArray[$product->unit]['coefficient'], | |||||
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'], | |||||
'prices' => $product->getPriceArray($userProducer->user, $pointSale), | 'prices' => $product->getPriceArray($userProducer->user, $pointSale), | ||||
'wording_unit' => $product->wording_unit, | 'wording_unit' => $product->wording_unit, | ||||
'tax_rate' => $product->taxRate->value | 'tax_rate' => $product->taxRate->value | ||||
'orders' => $ordersArray, | 'orders' => $ordersArray, | ||||
'total' => ($document->getClass() == 'Invoice' || $document->getClass( | 'total' => ($document->getClass() == 'Invoice' || $document->getClass( | ||||
) == 'DeliveryNote') ? $document->getAmount( | ) == 'DeliveryNote') ? $document->getAmount( | ||||
OrderModel::INVOICE_AMOUNT_TOTAL | |||||
) : $document->getAmount(OrderModel::AMOUNT_TOTAL), | |||||
Order::INVOICE_AMOUNT_TOTAL | |||||
) : $document->getAmount(Order::AMOUNT_TOTAL), | |||||
'total_with_tax' => ($document->getClass() == 'Invoice' || $document->getClass( | 'total_with_tax' => ($document->getClass() == 'Invoice' || $document->getClass( | ||||
) == 'DeliveryNote') ? $document->getAmountWithTax( | ) == 'DeliveryNote') ? $document->getAmountWithTax( | ||||
OrderModel::INVOICE_AMOUNT_TOTAL | |||||
) : $document->getAmountWithTax(OrderModel::AMOUNT_TOTAL), | |||||
Order::INVOICE_AMOUNT_TOTAL | |||||
) : $document->getAmountWithTax(Order::AMOUNT_TOTAL), | |||||
'invoice_url' => ($document->getClass() == 'DeliveryNote' && $document->getInvoice()) ? Yii::$app->urlManager->createUrl(['invoice/update', 'id' => $document->getInvoice()->id]) : null | 'invoice_url' => ($document->getClass() == 'DeliveryNote' && $document->getInvoice()) ? Yii::$app->urlManager->createUrl(['invoice/update', 'id' => $document->getInvoice()->id]) : null | ||||
]; | ]; | ||||
} | } | ||||
$document = $classDocument::searchOne([ | $document = $classDocument::searchOne([ | ||||
'id' => $idDocument | 'id' => $idDocument | ||||
]); | ]); | ||||
$product = ProductModel::searchOne([ | |||||
$product = Product::searchOne([ | |||||
'id' => $idProduct | 'id' => $idProduct | ||||
]); | ]); | ||||
$order->id_point_sale = null; | $order->id_point_sale = null; | ||||
$order->id_distribution = null; | $order->id_distribution = null; | ||||
$order->status = 'tmp-order'; | $order->status = 'tmp-order'; | ||||
$order->origin = OrderModel::ORIGIN_ADMIN; | |||||
$order->origin = Order::ORIGIN_ADMIN; | |||||
$order->date = date('Y-m-d H:i:s'); | $order->date = date('Y-m-d H:i:s'); | ||||
$fieldIdDocument = 'id_' . $classDocument::tableName(); | $fieldIdDocument = 'id_' . $classDocument::tableName(); | ||||
$order->$fieldIdDocument = $document->id; | $order->$fieldIdDocument = $document->id; | ||||
$productOrder = new ProductOrder; | $productOrder = new ProductOrder; | ||||
$productOrder->id_order = $order->id; | $productOrder->id_order = $order->id; | ||||
$productOrder->id_product = $idProduct; | $productOrder->id_product = $idProduct; | ||||
$quantity = $quantity / ProductModel::$unitsArray[$product->unit]['coefficient']; | |||||
$quantity = $quantity / Product::$unitsArray[$product->unit]['coefficient']; | |||||
$productOrder->quantity = $quantity; | $productOrder->quantity = $quantity; | ||||
$productOrder->price = (float)$price; | $productOrder->price = (float)$price; | ||||
$productOrder->unit = $product->unit; | $productOrder->unit = $product->unit; | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$productOrder = ProductOrderModel::searchOne([ | |||||
$productOrder = ProductOrder::searchOne([ | |||||
'id' => $idProductOrder | 'id' => $idProductOrder | ||||
]); | ]); | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$invoice = InvoiceModel::searchOne(['id' => $idInvoice]); | |||||
$invoice = Invoice::searchOne(['id' => $idInvoice]); | |||||
if($invoice && $invoice->isStatusDraft()) { | if($invoice && $invoice->isStatusDraft()) { | ||||
OrderModel::updateAll([ | |||||
Order::updateAll([ | |||||
'id_invoice' => null | 'id_invoice' => null | ||||
], [ | ], [ | ||||
'id_delivery_note' => $idDeliveryNote | 'id_delivery_note' => $idDeliveryNote | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$invoice = InvoiceModel::searchOne(['id' => $idInvoice]); | |||||
$deliveryNote = DeliveryNoteModel::searchOne(['id' => $idDeliveryNote]); | |||||
$invoice = Invoice::searchOne(['id' => $idInvoice]); | |||||
$deliveryNote = DeliveryNote::searchOne(['id' => $idDeliveryNote]); | |||||
if($invoice && $invoice->isStatusDraft() && $deliveryNote) { | if($invoice && $invoice->isStatusDraft() && $deliveryNote) { | ||||
OrderModel::updateAll([ | |||||
Order::updateAll([ | |||||
'id_invoice' => $idInvoice | 'id_invoice' => $idInvoice | ||||
], [ | ], [ | ||||
'id_delivery_note' => $idDeliveryNote | 'id_delivery_note' => $idDeliveryNote |
use common\models\Order; | use common\models\Order; | ||||
use common\models\ProductOrder; | use common\models\ProductOrder; | ||||
use common\models\Product; | use common\models\Product; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use common\models\ProductDistribution; | use common\models\ProductDistribution; | ||||
use common\models\Distribution; | use common\models\Distribution; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\logic\UserProducer\UserProducerModel; | |||||
use common\logic\UserProducer\ UserProducer; | |||||
class OrderController extends BackendController | class OrderController extends BackendController | ||||
{ | { | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN | |||||
|| UserModel::getCurrentStatus() == UserModel::STATUS_PRODUCER; | |||||
return User::getCurrentStatus() == User::STATUS_ADMIN | |||||
|| User::getCurrentStatus() == User::STATUS_PRODUCER; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
{ | { | ||||
if ($date != '') { | if ($date != '') { | ||||
// commandes | // commandes | ||||
$orders = OrderModel::searchAll([ | |||||
$orders = Order::searchAll([ | |||||
'distribution.date' => $date | 'distribution.date' => $date | ||||
]); | ]); | ||||
foreach ($point->orders as $order) { | foreach ($point->orders as $order) { | ||||
// suppression des product_order | // suppression des product_order | ||||
ProductOrderModel::deleteAll(['id_order' => $order->id]); | |||||
ProductOrder::deleteAll(['id_order' => $order->id]); | |||||
// création des commande_produit modifiés | // création des commande_produit modifiés | ||||
foreach ($products as $product) { | foreach ($products as $product) { | ||||
*/ | */ | ||||
public function actionIndex($date = '', $returnData = false) | public function actionIndex($date = '', $returnData = false) | ||||
{ | { | ||||
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]); | ||||
} | } | ||||
// users | // users | ||||
$arrayUsers = [0 => '--']; | $arrayUsers = [0 => '--']; | ||||
$users = UserModel::searchAll([], ['orderby' => 'lastname, name ASC']); | |||||
$users = User::searchAll([], ['orderby' => 'lastname, name ASC']); | |||||
foreach ($users as $user) { | foreach ($users as $user) { | ||||
$arrayUsers[$user->id] = $user->name . ' ' . $user->lastname; | $arrayUsers[$user->id] = $user->name . ' ' . $user->lastname; | ||||
// points de vente | // points de vente | ||||
if ($distribution) { | if ($distribution) { | ||||
$arrayPointsSale = PointSaleModel::find() | |||||
$arrayPointsSale = PointSale::find() | |||||
->joinWith(['pointSaleDistribution' => function ($q) use ($distribution) { | ->joinWith(['pointSaleDistribution' => function ($q) use ($distribution) { | ||||
$q->where(['id_distribution' => $distribution->id]); | $q->where(['id_distribution' => $distribution->id]); | ||||
}]) | }]) | ||||
]) | ]) | ||||
->all(); | ->all(); | ||||
} else { | } else { | ||||
$arrayPointsSale = PointSaleModel::searchAll(); | |||||
$arrayPointsSale = PointSale::searchAll(); | |||||
} | } | ||||
// produits | // produits | ||||
$arrayProducts = ProductModel::searchAll(); | |||||
$arrayProducts = Product::searchAll(); | |||||
// gestion des commandes | // gestion des commandes | ||||
$this->processOrderForm($distribution, $date, $arrayPointsSale, $arrayProducts, $users); | $this->processOrderForm($distribution, $date, $arrayPointsSale, $arrayProducts, $users); | ||||
// commandes | // commandes | ||||
$arrayOrders = OrderModel::searchAll([ | |||||
$arrayOrders = Order::searchAll([ | |||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
]); | ]); | ||||
// produits | // produits | ||||
if ($distribution) { | if ($distribution) { | ||||
$arrayProducts = ProductModel::searchByDistribution($distribution->id); | |||||
$arrayProducts = Product::searchByDistribution($distribution->id); | |||||
} | } | ||||
// poids total de la production et CA potentiel | // poids total de la production et CA potentiel | ||||
public function actionDownload($date = '', $idPointSale = 0, $global = 0) | public function actionDownload($date = '', $idPointSale = 0, $global = 0) | ||||
{ | { | ||||
// commandes | // commandes | ||||
$ordersArray = OrderModel::searchAll([ | |||||
$ordersArray = Order::searchAll([ | |||||
'distribution.date' => $date | 'distribution.date' => $date | ||||
]); | ]); | ||||
// points de vente | // points de vente | ||||
$pointsSaleArray = PointSaleModel::searchAll(); | |||||
$pointsSaleArray = PointSale::searchAll(); | |||||
foreach ($pointsSaleArray as $pointSale) { | foreach ($pointsSaleArray as $pointSale) { | ||||
$pv->initOrders($ordersArray); | $pv->initOrders($ordersArray); | ||||
} | } | ||||
// produits | // produits | ||||
$productsArray = ProductModel::find()->orderBy('order ASC')->all(); | |||||
$productsArray = Product::find()->orderBy('order ASC')->all(); | |||||
$distribution = DistributionModel::find() | $distribution = DistributionModel::find() | ||||
->where('date LIKE \':date\'') | ->where('date LIKE \':date\'') | ||||
$strProducts = ''; | $strProducts = ''; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { | if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { | ||||
$quantity = OrderModel::getProductQuantity($product->id, $pointSale->orders); | |||||
$quantity = Order::getProductQuantity($product->id, $pointSale->orders); | |||||
$strQuantity = ''; | $strQuantity = ''; | ||||
if ($quantity) { | if ($quantity) { | ||||
$strQuantity = $quantity; | $strQuantity = $quantity; | ||||
$strProducts = ''; | $strProducts = ''; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { | if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { | ||||
$quantity = OrderModel::getProductQuantity($product->id, $ordersArray); | |||||
$quantity = Order::getProductQuantity($product->id, $ordersArray); | |||||
$strQuantity = ''; | $strQuantity = ''; | ||||
if ($quantity) { | if ($quantity) { | ||||
$strQuantity = $quantity; | $strQuantity = $quantity; | ||||
$dataAdd = [$pointSale->name]; | $dataAdd = [$pointSale->name]; | ||||
foreach ($products as $product) { | foreach ($products as $product) { | ||||
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { | if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { | ||||
$dataAdd[] = OrderModel::getProductQuantity($product->id, $pointSale->orders); | |||||
$dataAdd[] = Order::getProductQuantity($product->id, $pointSale->orders); | |||||
} | } | ||||
} | } | ||||
$data[] = $dataAdd; | $data[] = $dataAdd; | ||||
$dataAdd = ['Total']; | $dataAdd = ['Total']; | ||||
foreach ($products as $product) { | foreach ($products as $product) { | ||||
if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { | if (isset($selectedProductsArray[$product->id]['active']) && $selectedProductsArray[$product->id]['active']) { | ||||
$dataAdd[] = OrderModel::getProductQuantity($product->id, $orders); | |||||
$dataAdd[] = Order::getProductQuantity($product->id, $orders); | |||||
} | } | ||||
} | } | ||||
$data[] = $dataAdd; | $data[] = $dataAdd; | ||||
if ($active) { | if ($active) { | ||||
// add commandes automatiques | // add commandes automatiques | ||||
SubscriptionModel::addAll($date); | |||||
Subscription::addAll($date); | |||||
} | } | ||||
if ($redirect) { | if ($redirect) { | ||||
$dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); | $dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); | ||||
$dateSunday = date('Y-m-d', strtotime('Sunday', $start)); | $dateSunday = date('Y-m-d', strtotime('Sunday', $start)); | ||||
$pointsSaleArray = PointSaleModel::searchAll(); | |||||
$pointsSaleArray = PointSale::searchAll(); | |||||
$activeMonday = false; | $activeMonday = false; | ||||
$activeTuesday = false; | $activeTuesday = false; | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$order = OrderModel::searchOne([ | |||||
$order = Order::searchOne([ | |||||
'id' => $idOrder | 'id' => $idOrder | ||||
]); | ]); | ||||
*/ | */ | ||||
public function actionDelete($date, $idOrder) | public function actionDelete($date, $idOrder) | ||||
{ | { | ||||
$order = OrderModel::searchOne(['id' => $idOrder]); | |||||
$order = Order::searchOne(['id' => $idOrder]); | |||||
if ($order) { | if ($order) { | ||||
// remboursement de la commande | // remboursement de la commande | ||||
if ($order->id_user && $order->getAmount(OrderModel::AMOUNT_PAID) && ProducerModel::getConfig('credit')) { | |||||
if ($order->id_user && $order->getAmount(Order::AMOUNT_PAID) && Producer::getConfig('credit')) { | |||||
$order->saveCreditHistory( | $order->saveCreditHistory( | ||||
CreditHistoryModel::TYPE_REFUND, | |||||
$order->getAmount(OrderModel::AMOUNT_PAID), | |||||
CreditHistory::TYPE_REFUND, | |||||
$order->getAmount(Order::AMOUNT_PAID), | |||||
$order->distribution->id_producer, | $order->distribution->id_producer, | ||||
$order->id_user, | $order->id_user, | ||||
UserModel::getCurrentId() | |||||
User::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
$order->delete(); | $order->delete(); | ||||
ProductOrderModel::deleteAll(['id_order' => $idOrder]); | |||||
ProductOrder::deleteAll(['id_order' => $idOrder]); | |||||
} | } | ||||
$this->redirect(['index', 'date' => $date]); | $this->redirect(['index', 'date' => $date]); | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$products = json_decode($products); | $products = json_decode($products); | ||||
$pointSale = PointSaleModel::findOne($idPointSale); | |||||
$pointSale = PointSale::findOne($idPointSale); | |||||
$distribution = DistributionModel::searchOne([ | $distribution = DistributionModel::searchOne([ | ||||
'date' => $date | 'date' => $date | ||||
]); | ]); | ||||
$order->id_point_sale = $idPointSale; | $order->id_point_sale = $idPointSale; | ||||
$order->mean_payment = $meanPayment; | $order->mean_payment = $meanPayment; | ||||
$order->id_distribution = $distribution->id; | $order->id_distribution = $distribution->id; | ||||
$order->origin = OrderModel::ORIGIN_ADMIN; | |||||
$order->origin = Order::ORIGIN_ADMIN; | |||||
$order->comment = $comment; | $order->comment = $comment; | ||||
$order->status = 'tmp-order'; | $order->status = 'tmp-order'; | ||||
$order->id_user = $idUser; | $order->id_user = $idUser; | ||||
// commentaire du point de vente | // commentaire du point de vente | ||||
$userPointSale = UserPointSaleModel::searchOne([ | |||||
$userPointSale = UserPointSale::searchOne([ | |||||
'id_point_sale' => $idPointSale, | 'id_point_sale' => $idPointSale, | ||||
'id_user' => $idUser | 'id_user' => $idUser | ||||
]); | ]); | ||||
$userProducer = false; | $userProducer = false; | ||||
if (isset($order->user) && $order->user) { | if (isset($order->user) && $order->user) { | ||||
$user = $order->user; | $user = $order->user; | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'id_producer' => $order->distribution->id_producer | 'id_producer' => $order->distribution->id_producer | ||||
]); | ]); | ||||
} | } | ||||
foreach ($products as $key => $dataProductOrder) { | foreach ($products as $key => $dataProductOrder) { | ||||
$product = ProductModel::findOne($key); | |||||
$quantity = $dataProductOrder->quantity / ProductModel::$unitsArray[$dataProductOrder->unit]['coefficient']; | |||||
$product = Product::findOne($key); | |||||
$quantity = $dataProductOrder->quantity / Product::$unitsArray[$dataProductOrder->unit]['coefficient']; | |||||
if ($product && $quantity) { | if ($product && $quantity) { | ||||
$productOrder = new ProductOrder; | $productOrder = new ProductOrder; | ||||
$productOrder->id_order = $order->id; | $productOrder->id_order = $order->id; | ||||
} | } | ||||
} | } | ||||
$order = OrderModel::searchOne(['id' => $order->id]); | |||||
$order = Order::searchOne(['id' => $order->id]); | |||||
if ($order && $processCredit) { | if ($order && $processCredit) { | ||||
$order->processCredit(); | $order->processCredit(); | ||||
} | } | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$order = OrderModel::searchOne(['id' => $idOrder]); | |||||
$order = Order::searchOne(['id' => $idOrder]); | |||||
if ($order && | if ($order && | ||||
$order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | ||||
$order->id_user = $idUser; | $order->id_user = $idUser; | ||||
// commentaire du point de vente | // commentaire du point de vente | ||||
$userPointSale = UserPointSaleModel::searchOne([ | |||||
$userPointSale = UserPointSale::searchOne([ | |||||
'id_point_sale' => $order->id_point_sale, | 'id_point_sale' => $order->id_point_sale, | ||||
'id_user' => $idUser | 'id_user' => $idUser | ||||
]); | ]); | ||||
$order->id_user = 0; | $order->id_user = 0; | ||||
} | } | ||||
$user = UserModel::searchOne(['id' => $order->id_user]); | |||||
$user = User::searchOne(['id' => $order->id_user]); | |||||
$userProducer = false; | $userProducer = false; | ||||
if ($user) { | if ($user) { | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'id_producer' => $order->distribution->id_producer | 'id_producer' => $order->distribution->id_producer | ||||
]); | ]); | ||||
$products = json_decode($products); | $products = json_decode($products); | ||||
foreach ($products as $key => $dataProductOrder) { | foreach ($products as $key => $dataProductOrder) { | ||||
$productOrder = ProductOrderModel::findOne([ | |||||
$productOrder = ProductOrder::findOne([ | |||||
'id_order' => $idOrder, | 'id_order' => $idOrder, | ||||
'id_product' => $key | 'id_product' => $key | ||||
]); | ]); | ||||
$quantity = $dataProductOrder->quantity | $quantity = $dataProductOrder->quantity | ||||
/ ProductModel::$unitsArray[$dataProductOrder->unit]['coefficient']; | |||||
/ Product::$unitsArray[$dataProductOrder->unit]['coefficient']; | |||||
if ($quantity) { | if ($quantity) { | ||||
if ($productOrder) { | if ($productOrder) { | ||||
$productOrder->quantity = $quantity; | $productOrder->quantity = $quantity; | ||||
$productOrder->price = $dataProductOrder->price; | $productOrder->price = $dataProductOrder->price; | ||||
} else { | } else { | ||||
$product = ProductModel::findOne($key); | |||||
$product = Product::findOne($key); | |||||
if ($product) { | if ($product) { | ||||
$productOrder = new ProductOrder; | $productOrder = new ProductOrder; | ||||
$order->save(); | $order->save(); | ||||
$order = OrderModel::searchOne(['id' => $order->id]); | |||||
$order = Order::searchOne(['id' => $order->id]); | |||||
if ($order && $processCredit) { | if ($order && $processCredit) { | ||||
// Si changement d'user : on rembourse l'ancien user | // Si changement d'user : on rembourse l'ancien user | ||||
$amountPaid = $order->getAmount(OrderModel::AMOUNT_PAID); | |||||
$amountPaid = $order->getAmount(Order::AMOUNT_PAID); | |||||
if($oldIdUser != $idUser && $amountPaid > 0) { | if($oldIdUser != $idUser && $amountPaid > 0) { | ||||
$order->saveCreditHistory( | $order->saveCreditHistory( | ||||
CreditHistoryModel::TYPE_REFUND, | |||||
CreditHistory::TYPE_REFUND, | |||||
$amountPaid, | $amountPaid, | ||||
GlobalParam::getCurrentProducerId(), | GlobalParam::getCurrentProducerId(), | ||||
$oldIdUser, | $oldIdUser, | ||||
UserModel::getCurrentId() | |||||
User::getCurrentId() | |||||
); | ); | ||||
$order = OrderModel::searchOne(['id' => $order->id]); | |||||
$order = Order::searchOne(['id' => $order->id]); | |||||
} | } | ||||
$order->processCredit(); | $order->processCredit(); | ||||
public function actionPaymentStatus($idOrder) | public function actionPaymentStatus($idOrder) | ||||
{ | { | ||||
$creditHistoryService = \Yii::$app->logic->getCreditHistoryContainer()->getService(); | $creditHistoryService = \Yii::$app->logic->getCreditHistoryContainer()->getService(); | ||||
$order = OrderModel::searchOne(['id' => $idOrder]); | |||||
$order = Order::searchOne(['id' => $idOrder]); | |||||
if ($order) { | if ($order) { | ||||
$html = ''; | $html = ''; | ||||
if ($order->id_user) { | if ($order->id_user) { | ||||
$userProducer = UserProducerModel::find() | |||||
$userProducer = UserProducer::find() | |||||
->where([ | ->where([ | ||||
'id_user' => $order->id_user, | 'id_user' => $order->id_user, | ||||
'id_producer' => $order->distribution->id_producer | 'id_producer' => $order->distribution->id_producer | ||||
]) | ]) | ||||
->one(); | ->one(); | ||||
$amountPaid = $order->getAmount(OrderModel::AMOUNT_PAID); | |||||
$amountPaid = $order->getAmount(Order::AMOUNT_PAID); | |||||
if (abs($order->amount - $amountPaid) < 0.0001) { | if (abs($order->amount - $amountPaid) < 0.0001) { | ||||
$html .= '<span class="label label-success">Payé</span>'; | $html .= '<span class="label label-success">Payé</span>'; | ||||
$buttonsCredit = Html::a('Rembourser ' . $order->getAmountWithTax(OrderModel::AMOUNT_TOTAL, true), 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $order->amount, 'data-type' => 'refund']); | |||||
$buttonsCredit = Html::a('Rembourser ' . $order->getAmountWithTax(Order::AMOUNT_TOTAL, true), 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $order->amount, 'data-type' => 'refund']); | |||||
} elseif ($order->amount > $amountPaid) { | } elseif ($order->amount > $amountPaid) { | ||||
$amountToPay = $order->amount - $amountPaid; | $amountToPay = $order->amount - $amountPaid; | ||||
$html .= '<span class="label label-danger">Non payé</span> reste <strong>' . number_format($amountToPay, 2) . ' €</strong> à payer'; | $html .= '<span class="label label-danger">Non payé</span> reste <strong>' . number_format($amountToPay, 2) . ' €</strong> à payer'; | ||||
. '</span>'; | . '</span>'; | ||||
// historique | // historique | ||||
$history = CreditHistoryModel::find() | |||||
$history = CreditHistory::find() | |||||
->with('userAction') | ->with('userAction') | ||||
->where(['id_order' => $idOrder]) | ->where(['id_order' => $idOrder]) | ||||
->all(); | ->all(); | ||||
. '<td>' . date('d/m/Y H:i:s', strtotime($creditHistoryService->getDate($creditHistory))) . '</td>' | . '<td>' . date('d/m/Y H:i:s', strtotime($creditHistoryService->getDate($creditHistory))) . '</td>' | ||||
. '<td>' . Html::encode($creditHistoryService->getStrUserAction($creditHistory)) . '</td>' | . '<td>' . Html::encode($creditHistoryService->getStrUserAction($creditHistory)) . '</td>' | ||||
. '<td>' . $creditHistoryService->getStrWording($creditHistory) . '</td>' | . '<td>' . $creditHistoryService->getStrWording($creditHistory) . '</td>' | ||||
. '<td>' . ($creditHistoryService->isTypeDebit($creditHistory) ? '- ' . $creditHistoryService->getAmountWithTax($creditHistory, OrderModel::AMOUNT_TOTAL, true) : '') . '</td>' | |||||
. '<td>' . ($creditHistoryService->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryService->getAmountWithTax($creditHistory, OrderModel::AMOUNT_TOTAL, true) : '') . '</td>' | |||||
. '<td>' . ($creditHistoryService->isTypeDebit($creditHistory) ? '- ' . $creditHistoryService->getAmountWithTax($creditHistory, Order::AMOUNT_TOTAL, true) : '') . '</td>' | |||||
. '<td>' . ($creditHistoryService->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryService->getAmountWithTax($creditHistory, Order::AMOUNT_TOTAL, true) : '') . '</td>' | |||||
. '</tr>'; | . '</tr>'; | ||||
} | } | ||||
} else { | } else { | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$order = OrderModel::searchOne([ | |||||
$order = Order::searchOne([ | |||||
'id' => $idOrder | 'id' => $idOrder | ||||
]); | ]); | ||||
$amount, | $amount, | ||||
GlobalParam::getCurrentProducerId(), | GlobalParam::getCurrentProducerId(), | ||||
$order->id_user, | $order->id_user, | ||||
UserModel::getCurrentId() | |||||
User::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$order = OrderModel::searchOne([ | |||||
$order = Order::searchOne([ | |||||
'id' => (int)$idOrder | 'id' => (int)$idOrder | ||||
]); | ]); | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
], | ], | ||||
], | ], | ||||
*/ | */ | ||||
public function actionUpdate($id) | public function actionUpdate($id) | ||||
{ | { | ||||
$model = PointSaleModel::find() | |||||
$model = PointSale::find() | |||||
->with('userPointSale') | ->with('userPointSale') | ||||
->where(['id' => $id]) | ->where(['id' => $id]) | ||||
->one(); | ->one(); | ||||
*/ | */ | ||||
public function initForm($id = 0) | public function initForm($id = 0) | ||||
{ | { | ||||
$users = UserModel::findBy() | |||||
$users = User::findBy() | |||||
->leftJoin('user_point_sale', 'user_point_sale.id_user = user.id AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $id]) | ->leftJoin('user_point_sale', 'user_point_sale.id_user = user.id AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $id]) | ||||
->orderBy('user_point_sale.id_point_sale DESC, lastname ASC, name ASC') | ->orderBy('user_point_sale.id_point_sale DESC, lastname ASC, name ASC') | ||||
->all(); | ->all(); | ||||
$pointSale->save(); | $pointSale->save(); | ||||
// Suppression du lien entre les utilisateurs et le point de vente | // Suppression du lien entre les utilisateurs et le point de vente | ||||
UserPointSaleModel::deleteAll(['id_point_sale' => $id]); | |||||
UserPointSale::deleteAll(['id_point_sale' => $id]); | |||||
// Suppression du lien PointSaleDistribution pour toutes les distributions à venir | // Suppression du lien PointSaleDistribution pour toutes les distributions à venir | ||||
$incomingDistributions = DistributionModel::getIncomingDistributions(); | |||||
$incomingDistributions = DistributionModel::getIncoming(); | |||||
foreach ($incomingDistributions as $distribution) { | foreach ($incomingDistributions as $distribution) { | ||||
PointSaleDistributionModel::deleteAll(['id_point_sale' => $id, 'id_distribution' => $distribution->id]); | PointSaleDistributionModel::deleteAll(['id_point_sale' => $id, 'id_distribution' => $distribution->id]); | ||||
} | } | ||||
// Suppression de toutes les commandes à venir de ce point de vente | // Suppression de toutes les commandes à venir de ce point de vente | ||||
$ordersArray = OrderModel::searchAll( | |||||
$ordersArray = Order::searchAll( | |||||
[ | [ | ||||
'id_point_sale' => $id, | 'id_point_sale' => $id, | ||||
], | ], | ||||
{ | { | ||||
$pointSale = $this->findModel($id) ; | $pointSale = $this->findModel($id) ; | ||||
if($pointSale) { | if($pointSale) { | ||||
PointSaleModel::updateAll(['default' => 0], 'id_producer = :id_producer', [':id_producer' => GlobalParam::getCurrentProducerId()]) ; | |||||
PointSale::updateAll(['default' => 0], 'id_producer = :id_producer', [':id_producer' => GlobalParam::getCurrentProducerId()]) ; | |||||
if(!$pointSale->default) { | if(!$pointSale->default) { | ||||
$pointSale->default = 1 ; | $pointSale->default = 1 ; | ||||
$pointSale->save() ; | $pointSale->save() ; | ||||
*/ | */ | ||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = PointSaleModel::findOne($id)) !== null) { | |||||
if (($model = PointSale::findOne($id)) !== null) { | |||||
return $model; | return $model; | ||||
} | } | ||||
else { | else { |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use Yii; | use Yii; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN; | |||||
return User::getCurrentStatus() == User::STATUS_ADMIN; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$dataProviderProducer = new ActiveDataProvider([ | $dataProviderProducer = new ActiveDataProvider([ | ||||
'query' => ProducerModel::find() | |||||
'query' => Producer::find() | |||||
->with('userProducer', 'user') | ->with('userProducer', 'user') | ||||
->orderBy('active DESC, free_price DESC'), | ->orderBy('active DESC, free_price DESC'), | ||||
'pagination' => [ | 'pagination' => [ | ||||
], | ], | ||||
]); | ]); | ||||
$producersArray = ProducerModel::find()->where('active = 1')->all(); | |||||
$producersArray = Producer::find()->where('active = 1')->all(); | |||||
$sumPrices = 0; | $sumPrices = 0; | ||||
foreach($producersArray as $producer) { | foreach($producersArray as $producer) { | ||||
$fromProducerId = (int) $fromProducerId; | $fromProducerId = (int) $fromProducerId; | ||||
$toProducerId = (int) $toProducerId; | $toProducerId = (int) $toProducerId; | ||||
$count = 0; | $count = 0; | ||||
$usersArray = UserModel::findBy(['id_producer' => $fromProducerId])->all(); | |||||
$usersArray = User::findBy(['id_producer' => $fromProducerId])->all(); | |||||
foreach($usersArray as $user) { | foreach($usersArray as $user) { | ||||
$idUser = $user['user_id']; | $idUser = $user['user_id']; | ||||
$countOrders = 0; | $countOrders = 0; | ||||
if($withOrders) { | if($withOrders) { | ||||
$countOrders = OrderModel::searchCount([ | |||||
$countOrders = Order::searchCount([ | |||||
'id_user' => $idUser, | 'id_user' => $idUser, | ||||
'distribution.id_producer' => $fromProducerId | 'distribution.id_producer' => $fromProducerId | ||||
], ['conditions' => 'date_delete IS NULL']); | ], ['conditions' => 'date_delete IS NULL']); | ||||
} | } | ||||
if(($withOrders && $countOrders) || !$withOrders) { | if(($withOrders && $countOrders) || !$withOrders) { | ||||
ProducerModel::addUser($idUser, $toProducerId); | |||||
Producer::addUser($idUser, $toProducerId); | |||||
$count ++; | $count ++; | ||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
public function actionBill($idProducer) | public function actionBill($idProducer) | ||||
{ | { | ||||
$producer = ProducerModel::findOne($idProducer); | |||||
$producer = Producer::findOne($idProducer); | |||||
if ($producer) { | if ($producer) { | ||||
$period = date('Y-m', strtotime('-1 month')); | $period = date('Y-m', strtotime('-1 month')); | ||||
$last_invoice = InvoiceModel::getLastInvoice() ; | |||||
$last_invoice = Invoice::getLastInvoice() ; | |||||
if (!$last_invoice) { | if (!$last_invoice) { | ||||
$reference = 'BAP000001'; | $reference = 'BAP000001'; | ||||
} else { | } else { | ||||
public function actionBilling() | public function actionBilling() | ||||
{ | { | ||||
$dataProviderInvoice = new ActiveDataProvider([ | $dataProviderInvoice = new ActiveDataProvider([ | ||||
'query' => InvoiceModel::find() | |||||
'query' => Invoice::find() | |||||
->with('producer') | ->with('producer') | ||||
->orderBy('reference DESC'), | ->orderBy('reference DESC'), | ||||
'pagination' => [ | 'pagination' => [ | ||||
public function actionProducerInstallTaxUpdatePrices($idProducer) | public function actionProducerInstallTaxUpdatePrices($idProducer) | ||||
{ | { | ||||
// product | // product | ||||
$productsArray = ProductModel::searchAll([ | |||||
$productsArray = Product::searchAll([ | |||||
'id_producer' => $idProducer | 'id_producer' => $idProducer | ||||
]) ; | ]) ; | ||||
* @throws NotFoundHttpException | * @throws NotFoundHttpException | ||||
*/ | */ | ||||
protected function findModel($id) { | protected function findModel($id) { | ||||
if (($model = ProducerModel::findOne($id)) !== null) { | |||||
if (($model = Producer::findOne($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.'); |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
public function actionBilling() | public function actionBilling() | ||||
{ | { | ||||
$datasInvoices = new ActiveDataProvider([ | $datasInvoices = new ActiveDataProvider([ | ||||
'query' => InvoiceModel::find() | |||||
'query' => Invoice::find() | |||||
->where(['id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['id_producer' => GlobalParam::getCurrentProducerId()]) | ||||
->orderBy('reference DESC'), | ->orderBy('reference DESC'), | ||||
'pagination' => [ | 'pagination' => [ | ||||
], | ], | ||||
]); | ]); | ||||
$producer = ProducerModel::findOne(GlobalParam::getCurrentProducerId()); | |||||
$producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | |||||
if ($producer->load(Yii::$app->request->post())) { | if ($producer->load(Yii::$app->request->post())) { | ||||
$producer->save(); | $producer->save(); | ||||
} | } | ||||
$dataProviderPrices = new ActiveDataProvider([ | $dataProviderPrices = new ActiveDataProvider([ | ||||
'query' => ProducerPriceRangeModel::find() | |||||
'query' => ProducerPriceRange::find() | |||||
->orderBy('id ASC'), | ->orderBy('id ASC'), | ||||
'pagination' => [ | 'pagination' => [ | ||||
'pageSize' => 100, | 'pageSize' => 100, | ||||
*/ | */ | ||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = ProducerModel::findOne($id)) !== null) { | |||||
if (($model = Producer::findOne($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.'); |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN; | |||||
return User::getCurrentStatus() == User::STATUS_ADMIN; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => ProducerPriceRangeModel::find()->orderBy('range_begin ASC') | |||||
'query' => ProducerPriceRange::find()->orderBy('range_begin ASC') | |||||
]); | ]); | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
*/ | */ | ||||
public function actionDelete($id) | public function actionDelete($id) | ||||
{ | { | ||||
$producerPriceRange = ProducerPriceRangeModel::searchOne([ | |||||
$producerPriceRange = ProducerPriceRange::searchOne([ | |||||
'id' => $id | 'id' => $id | ||||
]) ; | ]) ; | ||||
$producerPriceRange->delete(); | $producerPriceRange->delete(); | ||||
*/ | */ | ||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = ProducerPriceRangeModel::findOne($id)) !== null) { | |||||
if (($model = ProducerPriceRange::findOne($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.'); |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
], | ], | ||||
], | ], | ||||
$productCategory = $this->findModel($id); | $productCategory = $this->findModel($id); | ||||
$productCategory->delete(); | $productCategory->delete(); | ||||
ProductModel::updateAll(['id_product_category' => null], ['id_product_category' => $id]); | |||||
Product::updateAll(['id_product_category' => null], ['id_product_category' => $id]); | |||||
Yii::$app->getSession()->setFlash('success', 'Catégorie <strong>' . Html::encode($productCategory->name) . '</strong> supprimée.'); | Yii::$app->getSession()->setFlash('success', 'Catégorie <strong>' . Html::encode($productCategory->name) . '</strong> supprimée.'); | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
*/ | */ | ||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = ProductCategoryModel::findOne($id)) !== null) { | |||||
if (($model = ProductCategory::findOne($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.'); |
use common\models\ProductPrice; | use common\models\ProductPrice; | ||||
use common\models\ProductPriceSearch; | use common\models\ProductPriceSearch; | ||||
use common\models\ProductSearch; | use common\models\ProductSearch; | ||||
use common\models\UserModelSearch; | |||||
use common\models\ UserSearch; | |||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\models\Product; | use common\models\Product; | ||||
use common\models\Distribution; | use common\models\Distribution; | ||||
use common\models\UserModel; | |||||
use common\logic\UserProducer\UserProducerModel; | |||||
use common\models\ User; | |||||
use common\logic\UserProducer\ UserProducer; | |||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
use yii\web\Controller; | use yii\web\Controller; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
$lastProductOrder = ProductModel::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) { | ||||
$model->order = ++$lastProductOrder->order; | $model->order = ++$lastProductOrder->order; | ||||
} | } | ||||
*/ | */ | ||||
public function processAvailabilityPointsSale($model) | public function processAvailabilityPointsSale($model) | ||||
{ | { | ||||
ProductPointSaleModel::deleteAll(['id_product' => $model->id]); | |||||
ProductPointSale::deleteAll(['id_product' => $model->id]); | |||||
if (is_array($model->pointsSale) && count($model->pointsSale)) { | if (is_array($model->pointsSale) && count($model->pointsSale)) { | ||||
foreach ($model->pointsSale as $key => $val) { | foreach ($model->pointsSale as $key => $val) { | ||||
$pointSale = PointSaleModel::findOne($val); | |||||
$pointSale = PointSale::findOne($val); | |||||
if ($pointSale) { | if ($pointSale) { | ||||
$productPointSale = new ProductPointSale; | $productPointSale = new ProductPointSale; | ||||
$productPointSale->id_product = $model->id; | $productPointSale->id_product = $model->id; | ||||
'id_product' => $id | 'id_product' => $id | ||||
])); | ])); | ||||
$userProducerWithProductPercent = UserProducerModel::searchAll([], [ | |||||
$userProducerWithProductPercent = UserProducer::searchAll([], [ | |||||
'join_with' => ['user'], | 'join_with' => ['user'], | ||||
'conditions' => 'user_producer.product_price_percent != 0', | 'conditions' => 'user_producer.product_price_percent != 0', | ||||
]); | ]); | ||||
$pointSaleWithProductPercent = PointSaleModel::searchAll([], [ | |||||
$pointSaleWithProductPercent = PointSale::searchAll([], [ | |||||
'conditions' => 'point_sale.product_price_percent != 0' | 'conditions' => 'point_sale.product_price_percent != 0' | ||||
]); | ]); | ||||
'from_quantity' => $model->from_quantity ? $model->from_quantity : null, | 'from_quantity' => $model->from_quantity ? $model->from_quantity : null, | ||||
]; | ]; | ||||
$productPriceExist = ProductPriceModel::findOne($conditionsProductPriceExist); | |||||
$productPriceExist = ProductPrice::findOne($conditionsProductPriceExist); | |||||
if ($productPriceExist) { | if ($productPriceExist) { | ||||
$productPriceExist->delete(); | $productPriceExist->delete(); | ||||
*/ | */ | ||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = ProductModel::findOne($id)) !== null) { | |||||
if (($model = Product::findOne($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.'); | ||||
protected function findModelProductPrice($id) | protected function findModelProductPrice($id) | ||||
{ | { | ||||
if (($model = ProductPriceModel::findOne($id)) !== null) { | |||||
if (($model = ProductPrice::findOne($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.'); |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
$invoice->name = str_replace(['Devis', 'devis'], 'Facture', $quotation->name); | $invoice->name = str_replace(['Devis', 'devis'], 'Facture', $quotation->name); | ||||
$invoice->save() ; | $invoice->save() ; | ||||
OrderModel::updateAll([ | |||||
Order::updateAll([ | |||||
'order.id_invoice' => $invoice->id | 'order.id_invoice' => $invoice->id | ||||
], [ | ], [ | ||||
'order.id_quotation' => $id | 'order.id_quotation' => $id |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend() ; | |||||
return User::hasAccessBackend() ; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$usersArray = UserModel::findBy()->all() ; | |||||
$pointsSaleArray = PointSaleModel::searchAll() ; | |||||
$usersArray = User::findBy()->all() ; | |||||
$pointsSaleArray = PointSale::searchAll() ; | |||||
// distributions | // distributions | ||||
$firstDistribution = DistributionModel::searchOne([], [ | $firstDistribution = DistributionModel::searchOne([], [ |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend() ; | |||||
return User::hasAccessBackend() ; | |||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN ; | |||||
return User::getCurrentStatus() == User::STATUS_ADMIN ; | |||||
} | } | ||||
], | ], | ||||
], | ], | ||||
{ | { | ||||
// commandes | // commandes | ||||
$optionDashboardNumberDistributions = ProducerModel::getConfig('option_dashboard_number_distributions') ; | |||||
$optionDashboardNumberDistributions = Producer::getConfig('option_dashboard_number_distributions') ; | |||||
$dashboardNumberDistributions = $optionDashboardNumberDistributions ? $optionDashboardNumberDistributions : 3 ; | $dashboardNumberDistributions = $optionDashboardNumberDistributions ? $optionDashboardNumberDistributions : 3 ; | ||||
$optionDashboardDateStart = ProducerModel::getConfig('option_dashboard_date_start') ; | |||||
$optionDashboardDateEnd = ProducerModel::getConfig('option_dashboard_date_end') ; | |||||
$optionDashboardDateStart = Producer::getConfig('option_dashboard_date_start') ; | |||||
$optionDashboardDateEnd = Producer::getConfig('option_dashboard_date_end') ; | |||||
$queryDistributions = DistributionModel::find()->with('order') ; | $queryDistributions = DistributionModel::find()->with('order') ; | ||||
$paramsOrders[':date_start'] = date('Y-m-d 00:00:00') ; | $paramsOrders[':date_start'] = date('Y-m-d 00:00:00') ; | ||||
} | } | ||||
$ordersArray = OrderModel::searchAll([],[ | |||||
$ordersArray = Order::searchAll([],[ | |||||
'orderby' => 'date DESC', | 'orderby' => 'date DESC', | ||||
'conditions' => $conditionsOrders.' AND (origin = \'' . OrderModel::ORIGIN_USER . '\' OR origin = \'' . OrderModel::ORIGIN_ADMIN . '\' OR (origin = \'' . OrderModel::ORIGIN_AUTO . '\' AND (date_update IS NOT NULL OR date_delete IS NOT NULL)))', | |||||
'conditions' => $conditionsOrders.' AND (origin = \'' . Order::ORIGIN_USER . '\' OR origin = \'' . Order::ORIGIN_ADMIN . '\' OR (origin = \'' . Order::ORIGIN_AUTO . '\' AND (date_update IS NOT NULL OR date_delete IS NOT NULL)))', | |||||
'params' => $paramsOrders, | 'params' => $paramsOrders, | ||||
]); | ]); | ||||
// clients | // clients | ||||
$usersArray = UserModel::findBy() | |||||
$usersArray = User::findBy() | |||||
->orderBy('created_at DESC') | ->orderBy('created_at DESC') | ||||
->limit(5) | ->limit(5) | ||||
->all(); | ->all(); | ||||
$usersNegativeCredit = UserModel::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
$usersNegativeCredit = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
->andWhere('user_producer.credit < 0') | ->andWhere('user_producer.credit < 0') | ||||
->all(); | ->all(); | ||||
// paramètres | // paramètres | ||||
$producer = GlobalParam::getCurrentProducer(); | $producer = GlobalParam::getCurrentProducer(); | ||||
$productsCount = ProductModel::searchCount() ; | |||||
$pointsSaleCount = PointSaleModel::searchCount() ; | |||||
$productsCount = Product::searchCount() ; | |||||
$pointsSaleCount = PointSale::searchCount() ; | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'distributionsArray' => $distributionsArray, | 'distributionsArray' => $distributionsArray, |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend() ; | |||||
return User::hasAccessBackend() ; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
{ | { | ||||
if(!$year) $year = date('Y') ; | if(!$year) $year = date('Y') ; | ||||
$productsArray = ProductModel::searchAll() ; | |||||
$productsArray = Product::searchAll() ; | |||||
$dataProducts = [] ; | $dataProducts = [] ; | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend() ; | |||||
return User::hasAccessBackend() ; | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
$model->id_producer = GlobalParam::getCurrentProducerId(); | $model->id_producer = GlobalParam::getCurrentProducerId(); | ||||
if($idOrder) { | if($idOrder) { | ||||
$order = OrderModel::searchOne(['id' => $idOrder]); | |||||
$order = Order::searchOne(['id' => $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 && ProducerModel::getConfig('credit')) { | |||||
if($model->id_user && Producer::getConfig('credit')) { | |||||
$model->auto_payment = 1 ; | $model->auto_payment = 1 ; | ||||
} | } | ||||
} | } | ||||
// produits | // produits | ||||
$productsArray = ProductModel::searchAll([], [ | |||||
$productsArray = Product::searchAll([], [ | |||||
'orderby' => 'product.order ASC' | 'orderby' => 'product.order ASC' | ||||
]) ; | ]) ; | ||||
{ | { | ||||
Yii::$app->getSession()->setFlash('success', 'Abonnement ajouté'); | Yii::$app->getSession()->setFlash('success', 'Abonnement ajouté'); | ||||
$subscription = SubscriptionModel::findOne($model->id) ; | |||||
$subscription = Subscription::findOne($model->id) ; | |||||
$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions() ; | $matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions() ; | ||||
if(count($matchedDistributionsArray)) { | if(count($matchedDistributionsArray)) { | ||||
return $this->redirect(['subscription/update-distributions', 'idSubscription' => $subscription->id]); | return $this->redirect(['subscription/update-distributions', 'idSubscription' => $subscription->id]); | ||||
// form | // form | ||||
$model = new SubscriptionForm; | $model = new SubscriptionForm; | ||||
$model->isAdmin = true ; | $model->isAdmin = true ; | ||||
$subscription = SubscriptionModel::findOne($id); | |||||
$subscription = Subscription::findOne($id); | |||||
if ($subscription) { | if ($subscription) { | ||||
$model->id = $id; | $model->id = $id; | ||||
} | } | ||||
// produits | // produits | ||||
$arrayProductsSubscription = ProductSubscriptionModel::searchAll([ | |||||
$arrayProductsSubscription = ProductSubscription::searchAll([ | |||||
'id_subscription' => $model->id | 'id_subscription' => $model->id | ||||
]) ; | ]) ; | ||||
} | } | ||||
// produits | // produits | ||||
$productsArray = ProductModel::searchAll([], [ | |||||
$productsArray = Product::searchAll([], [ | |||||
'orderby' => 'product.order ASC' | 'orderby' => 'product.order ASC' | ||||
]) ; | ]) ; | ||||
if ($model->save()) { | if ($model->save()) { | ||||
$subscription = SubscriptionModel::findOne($model->id) ; | |||||
$subscription = Subscription::findOne($model->id) ; | |||||
$messageOrdersDeleted = ''; | $messageOrdersDeleted = ''; | ||||
if($model->date_end) { | if($model->date_end) { | ||||
*/ | */ | ||||
public function actionDelete($id) | public function actionDelete($id) | ||||
{ | { | ||||
$subscription = SubscriptionModel::searchOne([ | |||||
$subscription = Subscription::searchOne([ | |||||
'subscription.id' => $id | 'subscription.id' => $id | ||||
]) ; | ]) ; | ||||
$subscription->deleteOrdersIncomingDistributions() ; | $subscription->deleteOrdersIncomingDistributions() ; | ||||
$subscription->delete(); | $subscription->delete(); | ||||
ProductSubscriptionModel::deleteAll(['id_subscription' => $id]); | |||||
ProductSubscription::deleteAll(['id_subscription' => $id]); | |||||
Yii::$app->getSession()->setFlash('success', 'Abonnement supprimé'); | Yii::$app->getSession()->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($idSubscription, $generate = false, $update = false) | ||||
{ | { | ||||
$subscription = SubscriptionModel::findOne($idSubscription) ; | |||||
$subscription = Subscription::findOne($idSubscription) ; | |||||
$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions() ; | $matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions() ; | ||||
if($generate) { | if($generate) { | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$productsQuery = ProductModel::find() | |||||
$productsQuery = Product::find() | |||||
->where(['id_producer' => GlobalParam::getCurrentProducerId(),]) ; | ->where(['id_producer' => GlobalParam::getCurrentProducerId(),]) ; | ||||
if($idSubscription) { | if($idSubscription) { | ||||
'price' => $theProduct['price'] | 'price' => $theProduct['price'] | ||||
] ;*/ | ] ;*/ | ||||
$theProduct['wording_unit'] = ProductModel::strUnit($theProduct['unit'], 'wording_short'); | |||||
$theProduct['wording_unit'] = Product::strUnit($theProduct['unit'], 'wording_short'); | |||||
if(isset($theProduct['productSubscription'][0])) { | if(isset($theProduct['productSubscription'][0])) { | ||||
/*if($theProduct['productSubscription'][0]['unit'] != $theProduct['unit']) { | /*if($theProduct['productSubscription'][0]['unit'] != $theProduct['unit']) { | ||||
$theProduct['units'][] = [ | $theProduct['units'][] = [ | ||||
'unit' => $theProduct['productSubscription'][0]['unit'], | 'unit' => $theProduct['productSubscription'][0]['unit'], | ||||
'wording_unit' => ProductModel::strUnit($theProduct['productSubscription'][0]['unit'], 'wording_short'), | |||||
'wording_unit' => Product::strUnit($theProduct['productSubscription'][0]['unit'], 'wording_short'), | |||||
'step' => $theProduct['productSubscription'][0]['step'], | 'step' => $theProduct['productSubscription'][0]['step'], | ||||
'price' => $theProduct['productSubscription'][0]['price'], | 'price' => $theProduct['productSubscription'][0]['price'], | ||||
] ; | ] ; | ||||
$theProduct['step'] = $theProduct['productSubscription'][0]['step'] ; | $theProduct['step'] = $theProduct['productSubscription'][0]['step'] ; | ||||
$theProduct['price'] = $theProduct['productSubscription'][0]['price'] ; | $theProduct['price'] = $theProduct['productSubscription'][0]['price'] ; | ||||
}*/ | }*/ | ||||
$theProduct['quantity'] = $theProduct['productSubscription'][0]['quantity'] * ProductModel::$unitsArray[$theProduct['unit']]['coefficient'] ; | |||||
$theProduct['quantity'] = $theProduct['productSubscription'][0]['quantity'] * Product::$unitsArray[$theProduct['unit']]['coefficient'] ; | |||||
} | } | ||||
else { | else { | ||||
$theProduct['quantity'] = '' ; | $theProduct['quantity'] = '' ; |
use backend\models\CreditForm; | use backend\models\CreditForm; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\Mailjet; | use common\helpers\Mailjet; | ||||
use common\models\UserModel; | |||||
use common\models\Producer; | |||||
use common\models\Distribution; | |||||
use backend\models\MailForm; | use backend\models\MailForm; | ||||
use common\models\UserGroup; | |||||
use common\logic\UserProducer\UserProducerModel; | |||||
use common\models\UserPointSale; | |||||
use common\models\PointSale; | |||||
use common\models\UserUserGroup; | |||||
use common\helpers\Password; | |||||
use common\logic\Distribution\Distribution\Distribution; | |||||
use common\logic\Order\Order\OrderSearch; | |||||
use common\logic\PointSale\PointSale\PointSale; | |||||
use common\logic\PointSale\UserPointSale\UserPointSale; | |||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\User\CreditHistory\CreditHistory; | |||||
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 yii\base\UserException; | |||||
use yii\debug\models\search\User; | |||||
use yii\filters\AccessControl; | |||||
use yii\filters\VerbFilter; | |||||
use \Yii; | |||||
use yii\web\NotFoundHttpException; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return $this->isUserCurrentAdmin(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
public function actionIndex( | public function actionIndex( | ||||
$idPointSale = 0, $sectionSubscribers = false, $sectionInactiveUsers = false) | $idPointSale = 0, $sectionSubscribers = false, $sectionInactiveUsers = false) | ||||
{ | { | ||||
$searchModel = new UserSearch; | |||||
$searchModel = new UserSearch(); | |||||
$dataProvider = $searchModel->search([ | $dataProvider = $searchModel->search([ | ||||
'UserSearch' => array_merge( | 'UserSearch' => array_merge( | ||||
[ | [ | ||||
) | ) | ||||
]); | ]); | ||||
$producer = ProducerModel::searchOne([ | |||||
$producer = Producer::searchOne([ | |||||
'id' => GlobalParam::getCurrentProducerId() | 'id' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
$pointsSaleArray = PointSaleModel::searchAll(); | |||||
$pointsSaleArray = PointSale::searchAll(); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | 'searchModel' => $searchModel, | ||||
if ($model->id) { | if ($model->id) { | ||||
// init points de vente sélectionnés | // init points de vente sélectionnés | ||||
$userPointSaleArray = UserPointSaleModel::searchAll([ | |||||
$userPointSaleArray = UserPointSale::searchAll([ | |||||
'id_user' => $model->id | 'id_user' => $model->id | ||||
]); | ]); | ||||
if ($userPointSaleArray && count($userPointSaleArray) > 0) { | if ($userPointSaleArray && count($userPointSaleArray) > 0) { | ||||
} | } | ||||
// init groupes d'utilisateurs sélectionnés | // init groupes d'utilisateurs sélectionnés | ||||
$userUserGroupsArray = UserUserGroupModel::searchAll([ | |||||
$userUserGroupsArray = UserUserGroup::searchAll([ | |||||
'id_user' => $model->id | 'id_user' => $model->id | ||||
]); | ]); | ||||
if ($userUserGroupsArray && count($userUserGroupsArray) > 0) { | if ($userUserGroupsArray && count($userUserGroupsArray) > 0) { | ||||
} | } | ||||
// product price percent | // product price percent | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'id_user' => $model->id | 'id_user' => $model->id | ||||
]); | ]); | ||||
} | } | ||||
// points de vente | // points de vente | ||||
$pointsSaleArray = PointSaleModel::find() | |||||
$pointsSaleArray = PointSale::find() | |||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'status' => 1 | 'status' => 1 | ||||
->all(); | ->all(); | ||||
// groupes d'utilisateurs | // groupes d'utilisateurs | ||||
$userGroupsArray = UserGroupModel::find() | |||||
$userGroupsArray = UserGroup::find() | |||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
]) | ]) | ||||
*/ | */ | ||||
public function actionCreate() | public function actionCreate() | ||||
{ | { | ||||
$model = new UserModel(); | |||||
$model = new User(); | |||||
$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 = UserModel::searchOne([ | |||||
$userExist = User::searchOne([ | |||||
'email' => $posts['User']['email'] | 'email' => $posts['User']['email'] | ||||
]); | ]); | ||||
} | } | ||||
if ($userExist) { | if ($userExist) { | ||||
ProducerModel::addUser($userExist->id, GlobalParam::getCurrentProducerId()); | |||||
Producer::addUser($userExist->id, GlobalParam::getCurrentProducerId()); | |||||
$this->processLinkPointSale($userExist); | $this->processLinkPointSale($userExist); | ||||
$this->processLinkUserGroup($userExist); | $this->processLinkUserGroup($userExist); | ||||
Yii::$app->getSession()->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."); | Yii::$app->getSession()->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."); | ||||
$model->save(); | $model->save(); | ||||
// liaison etablissement / user | // liaison etablissement / user | ||||
$useProducer = new UserProducerModel(); | |||||
$useProducer = new UserProducer(); | |||||
$useProducer->id_user = $model->id; | $useProducer->id_user = $model->id; | ||||
$useProducer->id_producer = GlobalParam::getCurrentProducerId(); | $useProducer->id_producer = GlobalParam::getCurrentProducerId(); | ||||
$useProducer->credit = 0; | $useProducer->credit = 0; | ||||
$this->processProductPricePercent($model); | $this->processProductPricePercent($model); | ||||
Yii::$app->getSession()->setFlash('success', 'Utilisateur créé.'); | Yii::$app->getSession()->setFlash('success', 'Utilisateur créé.'); | ||||
$model = new UserModel(); | |||||
$model = new User(); | |||||
} | } | ||||
} | } | ||||
// Moodification du profil | // Moodification du profil | ||||
$previousMail = $model->email; | $previousMail = $model->email; | ||||
$user = UserModel::find()->with('userProducer')->where(['id' => $model['id']])->one(); | |||||
$userBelongToProducer = UserProducerModel::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); | |||||
$user = User::find()->with('userProducer')->where(['id' => $model['id']])->one(); | |||||
$userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); | |||||
if ($userBelongToProducer) { | if ($userBelongToProducer) { | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
/** | /** | ||||
* Lie un utilisateur aux points de vente sélectionnés. | * Lie un utilisateur aux points de vente sélectionnés. | ||||
* | * | ||||
* @param UserModel $modelUser | |||||
* @param User $modelUser | |||||
*/ | */ | ||||
public function processLinkPointSale($modelUser) | public function processLinkPointSale($modelUser) | ||||
{ | { | ||||
$posts = Yii::$app->request->post(); | $posts = Yii::$app->request->post(); | ||||
UserPointSaleModel::deleteAll([ | |||||
UserPointSale::deleteAll([ | |||||
'id_user' => $modelUser->id | 'id_user' => $modelUser->id | ||||
]); | ]); | ||||
if (is_array($modelUser->points_sale) && count($modelUser->points_sale) > 0) { | if (is_array($modelUser->points_sale) && count($modelUser->points_sale) > 0) { | ||||
foreach ($modelUser->points_sale as $pointSaleId) { | foreach ($modelUser->points_sale as $pointSaleId) { | ||||
$userPointSale = UserPointSaleModel::searchOne([ | |||||
$userPointSale = UserPointSale::searchOne([ | |||||
'id_user' => $modelUser->id, | 'id_user' => $modelUser->id, | ||||
'id_point_sale' => $pointSaleId | 'id_point_sale' => $pointSaleId | ||||
]); | ]); | ||||
/** | /** | ||||
* Lie un utilisateur aux groupes d'utilisateurs sélectionnés. | * Lie un utilisateur aux groupes d'utilisateurs sélectionnés. | ||||
* | * | ||||
* @param UserModel $modelUser | |||||
* @param User $modelUser | |||||
*/ | */ | ||||
public function processLinkUserGroup($modelUser) | public function processLinkUserGroup($modelUser) | ||||
{ | { | ||||
$posts = Yii::$app->request->post(); | $posts = Yii::$app->request->post(); | ||||
UserUserGroupModel::deleteAll([ | |||||
UserUserGroup::deleteAll([ | |||||
'id_user' => $modelUser->id | 'id_user' => $modelUser->id | ||||
]); | ]); | ||||
if (is_array($modelUser->user_groups) && count($modelUser->user_groups) > 0) { | if (is_array($modelUser->user_groups) && count($modelUser->user_groups) > 0) { | ||||
foreach ($modelUser->user_groups as $userGroupId) { | foreach ($modelUser->user_groups as $userGroupId) { | ||||
$userUserGroup = UserUserGroupModel::searchOne([ | |||||
$userUserGroup = UserUserGroup::searchOne([ | |||||
'id_user' => $modelUser->id, | 'id_user' => $modelUser->id, | ||||
'id_user_group' => $userGroupId | 'id_user_group' => $userGroupId | ||||
]); | ]); | ||||
public function processProductPricePercent($model) | public function processProductPricePercent($model) | ||||
{ | { | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'id_user' => $model->id | 'id_user' => $model->id | ||||
]); | ]); | ||||
*/ | */ | ||||
public function actionDelete($id) | public function actionDelete($id) | ||||
{ | { | ||||
$userProducer = UserProducerModel::findOne([ | |||||
$userProducer = UserProducer::findOne([ | |||||
'id_user' => $id, | 'id_user' => $id, | ||||
'id_producer' => GlobalParam::getCurrentProducerId() | 'id_producer' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
$usersPointSaleLink = 1; | $usersPointSaleLink = 1; | ||||
} | } | ||||
$users = UserModel::findBy([ | |||||
$users = User::findBy([ | |||||
'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, | ||||
$usersArray[] = $user['email']; | $usersArray[] = $user['email']; | ||||
} | } | ||||
$pointsSaleArray = PointSaleModel::find()->where(['id_producer' => GlobalParam::getCurrentProducerId()])->all(); | |||||
$pointsSaleArray = PointSale::find()->where(['id_producer' => GlobalParam::getCurrentProducerId()])->all(); | |||||
$pointSale = null; | $pointSale = null; | ||||
if ($idPointSale) { | if ($idPointSale) { | ||||
$pointSale = PointSaleModel::findOne(['id' => $idPointSale]); | |||||
$pointSale = PointSale::findOne(['id' => $idPointSale]); | |||||
} | } | ||||
$mailForm = new MailForm(); | $mailForm = new MailForm(); | ||||
return $this->redirect(['mail', 'idPointSale' => $idPointSale]); | return $this->redirect(['mail', 'idPointSale' => $idPointSale]); | ||||
} | } | ||||
$incomingDistributions = DistributionModel::getIncomingDistributions(); | |||||
$incomingDistributions = Distribution::getIncoming(); | |||||
$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)); | ||||
*/ | */ | ||||
public function actionCredit($id) | public function actionCredit($id) | ||||
{ | { | ||||
$user = UserModel::find()->with('userProducer')->where(['id' => $id])->one(); | |||||
$userProducer = UserProducerModel::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); | |||||
$user = User::find()->with('userProducer')->where(['id' => $id])->one(); | |||||
$userProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); | |||||
if (($userProducer) || UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN) { | |||||
if (($userProducer) || User::getCurrentStatus() == User::STATUS_ADMIN) { | |||||
$creditForm = new CreditForm(); | $creditForm = new CreditForm(); | ||||
if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) { | if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) { | ||||
$creditForm = new CreditForm; | $creditForm = new CreditForm; | ||||
} | } | ||||
$history = CreditHistoryModel::find() | |||||
$history = CreditHistory::find() | |||||
->with(['order', 'userAction']) | ->with(['order', 'userAction']) | ||||
->where([ | ->where([ | ||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
*/ | */ | ||||
public function actionOrders($id) | public function actionOrders($id) | ||||
{ | { | ||||
$user = UserModel::findOne($id); | |||||
$searchModel = new OrderSearch; | |||||
$user = User::findOne($id); | |||||
$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])); | ||||
return $this->render('orders', [ | return $this->render('orders', [ | ||||
*/ | */ | ||||
public function actionStateCredit($idUser, $state) | public function actionStateCredit($idUser, $state) | ||||
{ | { | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $idUser | 'id_user' => $idUser | ||||
]); | ]); | ||||
/** | /** | ||||
* Finds the User model based on its primary key value. | * Finds the User model based on its primary key value. | ||||
* If the model is not found, a 404 HTTP exception will be thrown. | * If the model is not found, a 404 HTTP exception will be thrown. | ||||
* @param integer $id | |||||
* @return UserModel the loaded model | |||||
* @throws NotFoundHttpException if the model cannot be found | |||||
*/ | */ | ||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = UserModel::findOne($id)) !== null) { | |||||
if (($model = User::findOne($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.'); |
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return UserModel::hasAccessBackend(); | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
], | ], | ||||
], | ], | ||||
$userGroup = $this->findModel($id); | $userGroup = $this->findModel($id); | ||||
$userGroup->delete(); | $userGroup->delete(); | ||||
UserUserGroupModel::deleteAll(['id_user_group' => $id]); | |||||
User UserGroup::deleteAll(['id_user_group' => $id]); | |||||
Yii::$app->getSession()->setFlash('success', 'Groupe d\'utilisateur <strong>' . Html::encode($userGroup->name) . '</strong> supprimé.'); | Yii::$app->getSession()->setFlash('success', 'Groupe d\'utilisateur <strong>' . Html::encode($userGroup->name) . '</strong> supprimé.'); | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
*/ | */ | ||||
protected function findModel($id) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = UserGroupModel::findOne($id)) !== null) { | |||||
if (($model = UserGroup::findOne($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.'); |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use Yii; | use Yii; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use common\models\UserModel ; | |||||
use common\models\ User ; | |||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\logic\UserProducer\UserProducerModel ; | |||||
use common\logic\UserProducer\ UserProducer ; | |||||
/** | /** | ||||
* ContactForm is the model behind the contact form. | * ContactForm is the model behind the contact form. | ||||
public function save() | public function save() | ||||
{ | { | ||||
$user = UserModel::searchOne([ | |||||
$user = User::searchOne([ | |||||
'id' => $this->id_user | 'id' => $this->id_user | ||||
]) ; | ]) ; | ||||
if($user) { | if($user) { | ||||
$user->id_producer = GlobalParam::getCurrentProducerId() ; | $user->id_producer = GlobalParam::getCurrentProducerId() ; | ||||
if($user->status != UserModel::STATUS_PRODUCER && $user->status != UserModel::STATUS_ADMIN) { | |||||
$user->status = UserModel::STATUS_PRODUCER ; | |||||
if($user->status != User::STATUS_PRODUCER && $user->status != User::STATUS_ADMIN) { | |||||
$user->status = User::STATUS_PRODUCER ; | |||||
} | } | ||||
return $user->save(); | return $user->save(); | ||||
} | } |
use Yii; | use Yii; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use common\models\CreditHistory ; | use common\models\CreditHistory ; | ||||
use common\models\UserModel ; | |||||
use common\models\ User ; | |||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\logic\UserProducer\UserProducerModel ; | |||||
use common\logic\UserProducer\ UserProducer ; | |||||
use common\helpers\Mail ; | use common\helpers\Mail ; | ||||
/** | /** | ||||
// on prévient l'utilisateur que son compte vient d'être crédité | // on prévient l'utilisateur que son compte vient d'être crédité | ||||
if($this->send_mail) { | if($this->send_mail) { | ||||
$user = UserModel::findOne($this->id_user) ; | |||||
$user = User::findOne($this->id_user) ; | |||||
$producer = GlobalParam::getCurrentProducer() ; | $producer = GlobalParam::getCurrentProducer() ; | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $this->id_user | 'id_user' => $this->id_user | ||||
]); | ]); | ||||
'.$linkOrder ; | '.$linkOrder ; | ||||
if($this->integrate_product_list) { | if($this->integrate_product_list) { | ||||
$productsArray = ProductModel::find() | |||||
$productsArray = Product::find() | |||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
]) | ]) | ||||
} | } | ||||
if($product->price) { | if($product->price) { | ||||
$productDescription .= ' / '.Price::format($product->getPriceWithTax()) ; | $productDescription .= ' / '.Price::format($product->getPriceWithTax()) ; | ||||
$productDescription .= ' ('.ProductModel::strUnit($product->unit, 'wording_unit').')' ; | |||||
$productDescription .= ' ('. Product::strUnit($product->unit, 'wording_unit').')' ; | |||||
} | } | ||||
$messageAutoText .= '- '.$productDescription.' | $messageAutoText .= '- '.$productDescription.' |
</div> | </div> | ||||
<div class="panel-body"> | <div class="panel-body"> | ||||
<?php $form = ActiveForm::begin(); ?> | <?php $form = ActiveForm::begin(); ?> | ||||
<?= $form->field($modelAccessUserProducerForm, 'id_user')->dropDownList(UserModel::populateDropdownList(), ['class' => 'select2'])->label(''); ?> | |||||
<?= $form->field($modelAccessUserProducerForm, 'id_user')->dropDownList( User::populateDropdownList(), ['class' => 'select2'])->label(''); ?> | |||||
<?= Html::submitButton('Ajouter', ['class' => 'btn btn-success']) ?> | <?= Html::submitButton('Ajouter', ['class' => 'btn btn-success']) ?> | ||||
<?php ActiveForm::end(); ?> | <?php ActiveForm::end(); ?> | ||||
</div> | </div> |
?> | ?> | ||||
<div class="delivery-note-index"> | <div class="delivery-note-index"> | ||||
<?php if(DeliveryNoteModel::searchCount()): ?> | |||||
<?php if(DeliveryNote::searchCount()): ?> | |||||
<?= GridView::widget([ | <?= GridView::widget([ | ||||
'filterModel' => $searchModel, | 'filterModel' => $searchModel, | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
[ | [ | ||||
'attribute' => 'id_point_sale', | 'attribute' => 'id_point_sale', | ||||
'header' => 'Point de vente', | 'header' => 'Point de vente', | ||||
'filter' => ArrayHelper::map(PointSaleModel::searchAll([], ['as_array'=>true]), 'id', 'name'), | |||||
'filter' => ArrayHelper::map(PointSale::searchAll([], ['as_array'=>true]), 'id', 'name'), | |||||
'format' => 'html', | 'format' => 'html', | ||||
'value' => function($model) { | 'value' => function($model) { | ||||
$pointSale = $model->getPointSale() ; | $pointSale = $model->getPointSale() ; | ||||
'attribute' => 'amount', | 'attribute' => 'amount', | ||||
'header' => 'Montant', | 'header' => 'Montant', | ||||
'value' => function($deliveryNote) { | 'value' => function($deliveryNote) { | ||||
return $deliveryNote->getAmountWithTax(OrderModel::INVOICE_AMOUNT_TOTAL, true) ; | |||||
return $deliveryNote->getAmountWithTax(Order::INVOICE_AMOUNT_TOTAL, true) ; | |||||
} | } | ||||
], | ], | ||||
[ | [ |
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\Development; | use common\models\Development; | ||||
use common\models\DevelopmentPriority; | use common\models\DevelopmentPriority; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use common\helpers\Url; | use common\helpers\Url; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
]; | ]; | ||||
if (UserModel::hasAccessBackend()) { | |||||
if ( User::hasAccessBackend()) { | |||||
$columns[] = [ | $columns[] = [ | ||||
'header' => 'Priorité', | 'header' => 'Priorité', | ||||
]; | ]; | ||||
} | } | ||||
if (UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN) { | |||||
if ( User::getCurrentStatus() == User::STATUS_ADMIN) { | |||||
$columns[] = [ | $columns[] = [ | ||||
'class' => 'yii\grid\ActionColumn', | 'class' => 'yii\grid\ActionColumn', | ||||
'template' => '{update}', | 'template' => '{update}', |
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\Development; | use common\models\Development; | ||||
use common\models\DevelopmentPriority; | use common\models\DevelopmentPriority; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use common\helpers\Url; | use common\helpers\Url; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
$add = false; | $add = false; | ||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
if($product->id == $productOrder->id_product) { | if($product->id == $productOrder->id_product) { | ||||
$unit = (ProductModel::strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : ' '.ProductModel::strUnit($productOrder->unit, 'wording_short', true) ; | |||||
$unit = ( Product::strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : ' '. Product::strUnit($productOrder->unit, 'wording_short', true) ; | |||||
$strProducts .= $product->name . ' (' .$productOrder->quantity .$unit.')<br />'; | $strProducts .= $product->name . ' (' .$productOrder->quantity .$unit.')<br />'; | ||||
$add = true; | $add = true; | ||||
} | } | ||||
$credit = '' ; | $credit = '' ; | ||||
if(isset($order->user) && $order->user->id) { | if(isset($order->user) && $order->user->id) { | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $order->user->id | 'id_user' => $order->user->id | ||||
]); | ]); | ||||
$strProducts = ''; | $strProducts = ''; | ||||
$cpt = 0 ; | $cpt = 0 ; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
foreach(ProductModel::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = OrderModel::getProductQuantity($product->id, $pointSale->orders, false, $unit); | |||||
foreach( Product::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit); | |||||
if ($quantity) { | if ($quantity) { | ||||
$theUnit = (ProductModel::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '.ProductModel::strUnit($unit, 'wording_short', true) ; | |||||
$theUnit = ( Product::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. Product::strUnit($unit, 'wording_short', true) ; | |||||
$strProducts .= $product->name . ' (' .$quantity .$theUnit.')<br />'; | $strProducts .= $product->name . ' (' .$quantity .$theUnit.')<br />'; | ||||
} | } | ||||
} | } | ||||
$cpt = 0 ; | $cpt = 0 ; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
foreach(ProductModel::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = OrderModel::getProductQuantity($product->id, $pointSale->orders, false, $unit); | |||||
foreach( Product::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit); | |||||
if ($quantity) { | if ($quantity) { | ||||
$theUnit = (ProductModel::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '.ProductModel::strUnit($unit, 'wording_short', true) ; | |||||
$theUnit = ( Product::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. Product::strUnit($unit, 'wording_short', true) ; | |||||
$html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; | $html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; | ||||
} | } | ||||
} | } | ||||
$cpt = 0 ; | $cpt = 0 ; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
foreach(ProductModel::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = OrderModel::getProductQuantity($product->id, $ordersArray, false, $unit); | |||||
foreach( Product::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit); | |||||
if ($quantity) { | if ($quantity) { | ||||
$theUnit = (ProductModel::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '.ProductModel::strUnit($unit, 'wording_short', true) ; | |||||
$theUnit = ( Product::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. Product::strUnit($unit, 'wording_short', true) ; | |||||
$html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; | $html .= $product->name . ' (' .$quantity .$theUnit.')<br />'; | ||||
} | } | ||||
} | } |
foreach ($orders as $order) { | foreach ($orders as $order) { | ||||
$html .= '<tr>'; | $html .= '<tr>'; | ||||
$strUser = $order->getStrUser(); | $strUser = $order->getStrUser(); | ||||
if ($producer->option_order_reference_type == ProducerModel::ORDER_REFERENCE_TYPE_YEARLY && $order->reference && strlen($order->reference) > 0) { | |||||
if ($producer->option_order_reference_type == Producer::ORDER_REFERENCE_TYPE_YEARLY && $order->reference && strlen($order->reference) > 0) { | |||||
$strUser .= '<br />' . $order->reference; | $strUser .= '<br />' . $order->reference; | ||||
} | } | ||||
$quantity = '' ; | $quantity = '' ; | ||||
foreach($order->productOrder as $productOrder) { | foreach($order->productOrder as $productOrder) { | ||||
if($product->id == $productOrder->id_product) { | if($product->id == $productOrder->id_product) { | ||||
$unit = (ProductModel::strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : ' '.ProductModel::strUnit($productOrder->unit, 'wording_short', true) ; | |||||
$unit = ( Product::strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : ' '. Product::strUnit($productOrder->unit, 'wording_short', true) ; | |||||
$quantity .= $productOrder->quantity .$unit ; | $quantity .= $productOrder->quantity .$unit ; | ||||
if($productOrder->quantity > 1) { | if($productOrder->quantity > 1) { |
} | } | ||||
// référence | // référence | ||||
if($producer->option_order_reference_type == ProducerModel::ORDER_REFERENCE_TYPE_YEARLY && $order->reference && strlen($order->reference) > 0) { | |||||
if($producer->option_order_reference_type == Producer::ORDER_REFERENCE_TYPE_YEARLY && $order->reference && strlen($order->reference) > 0) { | |||||
$strUser .= '<br />'.$order->reference ; | $strUser .= '<br />'.$order->reference ; | ||||
} | } | ||||
$add = false; | $add = false; | ||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
if($product->id == $productOrder->id_product) { | if($product->id == $productOrder->id_product) { | ||||
$unit = (ProductModel::strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : ' '.ProductModel::strUnit($productOrder->unit, 'wording_short', true) ; | |||||
$unit = ( Product::strUnit($productOrder->unit, 'wording_short', true) == 'p.') ? '' : ' '. Product::strUnit($productOrder->unit, 'wording_short', true) ; | |||||
$strProducts .= '('.$productOrder->quantity .$unit.') '.$product->getNameExport() . '<br />'; | $strProducts .= '('.$productOrder->quantity .$unit.') '.$product->getNameExport() . '<br />'; | ||||
$add = true; | $add = true; | ||||
} | } | ||||
$credit = '' ; | $credit = '' ; | ||||
if(isset($order->user) && $order->user->id) { | if(isset($order->user) && $order->user->id) { | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $order->user->id | 'id_user' => $order->user->id | ||||
]); | ]); | ||||
$html .= '<td><strong>'.number_format($order->amount_with_tax, 2) . ' € '; | $html .= '<td><strong>'.number_format($order->amount_with_tax, 2) . ' € '; | ||||
if($order->getPaymentStatus() == OrderModel::PAYMENT_PAID) | |||||
if($order->getPaymentStatus() == Order::PAYMENT_PAID) | |||||
{ | { | ||||
$html .= '(payé)' ; | $html .= '(payé)' ; | ||||
} | } | ||||
elseif($order->getPaymentStatus() == OrderModel::PAYMENT_UNPAID && $order->getAmount(OrderModel::AMOUNT_PAID)) | |||||
elseif($order->getPaymentStatus() == Order::PAYMENT_UNPAID && $order->getAmount(Order::AMOUNT_PAID)) | |||||
{ | { | ||||
$html .= '(reste '.$order->getAmount(OrderModel::AMOUNT_REMAINING, true).' à payer)' ; | |||||
$html .= '(reste '.$order->getAmount(Order::AMOUNT_REMAINING, true).' à payer)' ; | |||||
} | } | ||||
elseif($order->getPaymentStatus() == OrderModel::PAYMENT_SURPLUS) | |||||
elseif($order->getPaymentStatus() == Order::PAYMENT_SURPLUS) | |||||
{ | { | ||||
$html .= '(surplus : '.$order->getAmount(OrderModel::PAYMENT_SURPLUS, true).' à rembourser)' ; | |||||
$html .= '(surplus : '.$order->getAmount(Order::PAYMENT_SURPLUS, true).' à rembourser)' ; | |||||
} | } | ||||
$html .= '</strong></td>' ; | $html .= '</strong></td>' ; | ||||
$strProducts = ''; | $strProducts = ''; | ||||
$cpt = 0 ; | $cpt = 0 ; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
foreach(ProductModel::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = OrderModel::getProductQuantity($product->id, $pointSale->orders, false, $unit); | |||||
foreach( Product::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit); | |||||
if ($quantity) { | if ($quantity) { | ||||
$theUnit = (ProductModel::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '.ProductModel::strUnit($unit, 'wording_short', true) ; | |||||
$theUnit = ( Product::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. Product::strUnit($unit, 'wording_short', true) ; | |||||
$strProducts .= '(' .$quantity .$theUnit.') '.$product->getNameExport() . '<br />'; | $strProducts .= '(' .$quantity .$theUnit.') '.$product->getNameExport() . '<br />'; | ||||
} | } | ||||
} | } | ||||
$cpt = 0 ; | $cpt = 0 ; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
foreach(ProductModel::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = OrderModel::getProductQuantity($product->id, $pointSale->orders, false, $unit); | |||||
foreach( Product::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit); | |||||
if ($quantity) { | if ($quantity) { | ||||
$theUnit = (ProductModel::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '.ProductModel::strUnit($unit, 'wording_short', true) ; | |||||
$theUnit = ( Product::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. Product::strUnit($unit, 'wording_short', true) ; | |||||
$html .= '(' .$quantity .$theUnit.') '.$product->getNameExport() . '<br />'; | $html .= '(' .$quantity .$theUnit.') '.$product->getNameExport() . '<br />'; | ||||
} | } | ||||
} | } | ||||
$cpt = 0 ; | $cpt = 0 ; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
foreach(ProductModel::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = OrderModel::getProductQuantity($product->id, $ordersArray, false, $unit); | |||||
foreach( Product::$unitsArray as $unit => $dataUnit) { | |||||
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit); | |||||
if ($quantity) { | if ($quantity) { | ||||
$theUnit = (ProductModel::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '.ProductModel::strUnit($unit, 'wording_short', true) ; | |||||
$theUnit = ( Product::strUnit($unit, 'wording_short', true) == 'p.') ? '' : ' '. Product::strUnit($unit, 'wording_short', true) ; | |||||
$html .= '(' .$quantity .$theUnit.') '.$product->name . '<br />'; | $html .= '(' .$quantity .$theUnit.') '.$product->name . '<br />'; | ||||
} | } | ||||
} | } |
</td> | </td> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<td class="align-center"> | <td class="align-center"> | ||||
<?= $productOrder->quantity * ProductModel::$unitsArray[$productOrder->unit]['coefficient'] ?> | |||||
<?= $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'] ?> | |||||
</td> | </td> | ||||
<td class="align-center"><?= ProductModel::strUnit($productOrder->unit, 'wording') ?></td> | |||||
<td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td> | |||||
<?php if($displayPrices): ?> | <?php if($displayPrices): ?> | ||||
<?php if($producer->taxRate->value != 0): ?> | <?php if($producer->taxRate->value != 0): ?> | ||||
<td class="align-center"><?= $productOrder->taxRate->value * 100 ?> %</td> | <td class="align-center"><?= $productOrder->taxRate->value * 100 ?> %</td> |
'template' => '{label} <a href="' . Yii::$app->urlManager->createUrl(['user/create']) . '" class="btn btn-xs btn-default">Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span></a><div>{input}</div>{hint}', | 'template' => '{label} <a href="' . Yii::$app->urlManager->createUrl(['user/create']) . '" class="btn btn-xs btn-default">Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span></a><div>{input}</div>{hint}', | ||||
]) | ]) | ||||
->dropDownList( | ->dropDownList( | ||||
UserModel::populateDropdownList(), | |||||
User::populateDropdownList(), | |||||
[ | [ | ||||
'@change' => 'changeUser', | '@change' => 'changeUser', | ||||
'v-model' => 'idUser', | 'v-model' => 'idUser', | ||||
class="btn btn-sm btn-default"><span class="glyphicon glyphicon-repeat"></span> Regénérer (PDF)</a> | class="btn btn-sm btn-default"><span class="glyphicon glyphicon-repeat"></span> Regénérer (PDF)</a> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<?php if ($model->getClass() == 'Invoice' && ProducerModel::getConfig('option_export_evoliz')): ?> | |||||
<?php if ($model->getClass() == 'Invoice' && Producer::getConfig('option_export_evoliz')): ?> | |||||
<a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/export-csv-evoliz', 'id' => $model->id]) ?>" | <a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/export-csv-evoliz', 'id' => $model->id]) ?>" | ||||
class="btn btn-sm btn-default"><span class="glyphicon glyphicon-save-file"></span> Export Evoliz | class="btn btn-sm btn-default"><span class="glyphicon glyphicon-save-file"></span> Export Evoliz | ||||
(CSV)</a> | (CSV)</a> |
<?php | <?php | ||||
$displayPrices = Yii::$app->controller->getClass() != 'DeliveryNote' || (Yii::$app->controller->getClass() == 'DeliveryNote' && ProducerModel::getConfig('document_display_prices_delivery_note')); | |||||
$displayProductDescription = ProducerModel::getConfig('document_display_product_description'); | |||||
$documentPriceDecimals = (int) ProducerModel::getConfig('option_document_price_decimals'); | |||||
$displayPrices = Yii::$app->controller->getClass() != 'DeliveryNote' || (Yii::$app->controller->getClass() == 'DeliveryNote' && Producer::getConfig('document_display_prices_delivery_note')); | |||||
$displayProductDescription = Producer::getConfig('document_display_product_description'); | |||||
$documentPriceDecimals = (int) Producer::getConfig('option_document_price_decimals'); | |||||
?> | ?> | ||||
<?php endforeach; ?> | <?php endforeach; ?> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<?php if ($displayPrices): ?> | <?php if ($displayPrices): ?> | ||||
<?php $typeAmount = $document->isInvoicePrice() ? OrderModel::INVOICE_AMOUNT_TOTAL : OrderModel::AMOUNT_TOTAL; ?> | |||||
<?php $typeAmount = $document->isInvoicePrice() ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL; ?> | |||||
<?php if ($producer->taxRate->value != 0): ?> | <?php if ($producer->taxRate->value != 0): ?> | ||||
<div class="invoice-index"> | <div class="invoice-index"> | ||||
<?php if(InvoiceModel::searchCount()): ?> | |||||
<?php if(Invoice::searchCount()): ?> | |||||
<?= GridView::widget([ | <?= GridView::widget([ | ||||
'filterModel' => $searchModel, | 'filterModel' => $searchModel, | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'attribute' => 'amount', | 'attribute' => 'amount', | ||||
'header' => 'Montant', | 'header' => 'Montant', | ||||
'value' => function($invoice) { | 'value' => function($invoice) { | ||||
return $invoice->getAmountWithTax(OrderModel::INVOICE_AMOUNT_TOTAL, true) ; | |||||
return $invoice->getAmountWithTax(Order::INVOICE_AMOUNT_TOTAL, true) ; | |||||
} | } | ||||
], | ], | ||||
[ | [ |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use yii\helpers\ArrayHelper; | use yii\helpers\ArrayHelper; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
<div class="navbar-custom-menu"> | <div class="navbar-custom-menu"> | ||||
<?php | <?php | ||||
$usersArray = UserModel::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
$usersArray = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
->andWhere('CAST(FROM_UNIXTIME(user.created_at) AS date) > \'' . date("Y-m-d", strtotime("-7 days")) . '\'') | ->andWhere('CAST(FROM_UNIXTIME(user.created_at) AS date) > \'' . date("Y-m-d", strtotime("-7 days")) . '\'') | ||||
->orderBy('created_at DESC') | ->orderBy('created_at DESC') | ||||
->all(); | ->all(); | ||||
<?php | <?php | ||||
$usersNegativeCreditArray = UserModel::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
$usersNegativeCreditArray = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
->andWhere('user_producer.credit < 0') | ->andWhere('user_producer.credit < 0') | ||||
->orderBy('lastname, name ASC') | ->orderBy('lastname, name ASC') | ||||
->all(); | ->all(); | ||||
<?php foreach ($usersNegativeCreditArray as $user): ?> | <?php foreach ($usersNegativeCreditArray as $user): ?> | ||||
<li> | <li> | ||||
<a href="<?= Yii::$app->urlManagerBackend->createUrl(['user/credit', 'id' => $user['user_id']]); ?>"> | <a href="<?= Yii::$app->urlManagerBackend->createUrl(['user/credit', 'id' => $user['user_id']]); ?>"> | ||||
<h5><?= UserModel::getUsernameFromArray($user); ?> | |||||
<h5><?= User::getUsernameFromArray($user); ?> | |||||
<small> | <small> | ||||
<i class="fa fa-euro"></i> <?= Price::format($user['credit']); ?> | <i class="fa fa-euro"></i> <?= Price::format($user['credit']); ?> | ||||
</small> | </small> | ||||
</li> | </li> | ||||
<?php if (UserModel::isCurrentProducer() || UserModel::isCurrentAdmin()): ?> | |||||
<?php if ( User::isCurrentProducer() || User::isCurrentAdmin()): ?> | |||||
<li class="dropdown producer-menu"> | <li class="dropdown producer-menu"> | ||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> | <a href="#" class="dropdown-toggle" data-toggle="dropdown"> | ||||
</a> | </a> | ||||
<ul class="dropdown-menu"> | <ul class="dropdown-menu"> | ||||
<?php if (UserModel::isCurrentAdmin()): ?> | |||||
<?php if ( User::isCurrentAdmin()): ?> | |||||
<li> | <li> | ||||
<a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => GlobalParam::getCurrentProducer()->slug]); ?>"> | <a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => GlobalParam::getCurrentProducer()->slug]); ?>"> | ||||
<i class="fa fa-th-large"></i> | <i class="fa fa-th-large"></i> | ||||
</a> | </a> | ||||
</li> | </li> | ||||
<li class="header"> <strong>Autres producteurs</strong></li> | <li class="header"> <strong>Autres producteurs</strong></li> | ||||
<?php $producersArray = ProducerModel::find()->orderBy('name ASC')->all(); ?> | |||||
<?php $producersArray = Producer::find()->orderBy('name ASC')->all(); ?> | |||||
<?php foreach ($producersArray as $producer): ?> | <?php foreach ($producersArray as $producer): ?> | ||||
<li> | <li> | ||||
<a href="<?= Yii::$app->urlManagerBackend->createUrl(['site/change-producer', 'id' => $producer->id]); ?>"><?= Html::encode($producer->name) ?></a> | <a href="<?= Yii::$app->urlManagerBackend->createUrl(['site/change-producer', 'id' => $producer->id]); ?>"><?= Html::encode($producer->name) ?></a> | ||||
<li class="dropdown user user-menu"> | <li class="dropdown user user-menu"> | ||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> | <a href="#" class="dropdown-toggle" data-toggle="dropdown"> | ||||
<i class="fa fa-user"></i> | <i class="fa fa-user"></i> | ||||
<span class="hidden-xs"><?= Html::encode(UserModel::getCurrent()->name . ' ' . UserModel::getCurrent()->lastname); ?></span> | |||||
<span class="hidden-xs"><?= Html::encode( User::getCurrent()->name . ' ' . User::getCurrent()->lastname); ?></span> | |||||
<i class="fa fa-caret-down"></i> | <i class="fa fa-caret-down"></i> | ||||
</a> | </a> | ||||
<ul class="dropdown-menu"> | <ul class="dropdown-menu"> |
[ | [ | ||||
'options' => ['class' => 'sidebar-menu tree', 'data-widget' => 'tree'], | 'options' => ['class' => 'sidebar-menu tree', 'data-widget' => 'tree'], | ||||
'items' => [ | 'items' => [ | ||||
['label' => 'Tableau de bord', 'icon' => 'dashboard', 'url' => ['/site/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Distributions', 'icon' => 'calendar', 'url' => ['/distribution/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Tableau de bord', 'icon' => 'dashboard', 'url' => ['/site/index'], 'visible' => User::isCurrentProducer()], | |||||
['label' => 'Distributions', 'icon' => 'calendar', 'url' => ['/distribution/index'], 'visible' => User::isCurrentProducer()], | |||||
[ | [ | ||||
'label' => 'Produits', | 'label' => 'Produits', | ||||
'icon' => 'clone', | 'icon' => 'clone', | ||||
'url' => ['/product/index'], | 'url' => ['/product/index'], | ||||
'visible' => UserModel::isCurrentProducer(), | |||||
'visible' => User::isCurrentProducer(), | |||||
'active' => Yii::$app->controller->id == 'product', | 'active' => Yii::$app->controller->id == 'product', | ||||
'items' => [ | 'items' => [ | ||||
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/product/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Catégories', 'icon' => 'book', 'url' => ['/product-category/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/product/index'], 'visible' => User::isCurrentProducer()], | |||||
['label' => 'Catégories', 'icon' => 'book', 'url' => ['/product-category/index'], 'visible' => User::isCurrentProducer()], | |||||
] | ] | ||||
], | ], | ||||
['label' => 'Points de vente', 'icon' => 'map-marker', 'url' => ['/point-sale/index'], 'visible' => UserModel::isCurrentProducer(), 'active' => Yii::$app->controller->id == 'point-sale'], | |||||
['label' => 'Points de vente', 'icon' => 'map-marker', 'url' => ['/point-sale/index'], 'visible' => User::isCurrentProducer(), 'active' => Yii::$app->controller->id == 'point-sale'], | |||||
[ | [ | ||||
'label' => 'Utilisateurs', | 'label' => 'Utilisateurs', | ||||
'icon' => 'users', | 'icon' => 'users', | ||||
'url' => ['/user/index'], | 'url' => ['/user/index'], | ||||
'items' => [ | 'items' => [ | ||||
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/user/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Groupes', 'icon' => 'users', 'url' => ['/user-group/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/user/index'], 'visible' => User::isCurrentProducer()], | |||||
['label' => 'Groupes', 'icon' => 'users', 'url' => ['/user-group/index'], 'visible' => User::isCurrentProducer()], | |||||
], | ], | ||||
], | ], | ||||
['label' => 'Abonnements', 'icon' => 'repeat', 'url' => ['/subscription/index'], 'visible' => UserModel::isCurrentProducer(), 'active' => Yii::$app->controller->id == 'subscription'], | |||||
['label' => 'Communiquer', 'icon' => 'bullhorn', 'url' => ['/communicate/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Abonnements', 'icon' => 'repeat', 'url' => ['/subscription/index'], 'visible' => User::isCurrentProducer(), 'active' => Yii::$app->controller->id == 'subscription'], | |||||
['label' => 'Communiquer', 'icon' => 'bullhorn', 'url' => ['/communicate/index'], 'visible' => User::isCurrentProducer()], | |||||
[ | [ | ||||
'label' => 'Documents', | 'label' => 'Documents', | ||||
'icon' => 'clone', | 'icon' => 'clone', | ||||
'url' => ['/delivery-note/index'], | 'url' => ['/delivery-note/index'], | ||||
'items' => [ | 'items' => [ | ||||
['label' => 'Bons de livraison', 'icon' => 'sticky-note-o', 'url' => ['/delivery-note/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Factures', 'icon' => 'sticky-note-o', 'url' => ['/invoice/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Devis', 'icon' => 'sticky-note-o', 'url' => ['/quotation/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Bons de livraison', 'icon' => 'sticky-note-o', 'url' => ['/delivery-note/index'], 'visible' => User::isCurrentProducer()], | |||||
['label' => 'Factures', 'icon' => 'sticky-note-o', 'url' => ['/invoice/index'], 'visible' => User::isCurrentProducer()], | |||||
['label' => 'Devis', 'icon' => 'sticky-note-o', 'url' => ['/quotation/index'], 'visible' => User::isCurrentProducer()], | |||||
], | ], | ||||
], | ], | ||||
[ | [ | ||||
'icon' => 'line-chart', | 'icon' => 'line-chart', | ||||
'url' => ['/stats/index'], | 'url' => ['/stats/index'], | ||||
'items' => [ | 'items' => [ | ||||
['label' => 'Chiffre d\'affaire', 'icon' => 'line-chart', 'url' => ['/stats/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Rapports', 'icon' => 'pencil-square-o', 'url' => ['/report/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Produits', 'icon' => 'table', 'url' => ['/stats/products'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Chiffre d\'affaire', 'icon' => 'line-chart', 'url' => ['/stats/index'], 'visible' => User::isCurrentProducer()], | |||||
['label' => 'Rapports', 'icon' => 'pencil-square-o', 'url' => ['/report/index'], 'visible' => User::isCurrentProducer()], | |||||
['label' => 'Produits', 'icon' => 'table', 'url' => ['/stats/products'], 'visible' => User::isCurrentProducer()], | |||||
], | ], | ||||
], | ], | ||||
['label' => 'Paramètres', 'icon' => 'cog', 'url' => ['/producer/update'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Accès', 'icon' => 'lock', 'url' => ['/access/index'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Paramètres', 'icon' => 'cog', 'url' => ['/producer/update'], 'visible' => User::isCurrentProducer()], | |||||
['label' => 'Accès', 'icon' => 'lock', 'url' => ['/access/index'], 'visible' => User::isCurrentProducer()], | |||||
[ | [ | ||||
'label' => 'Développement', | 'label' => 'Développement', | ||||
'icon' => 'code', | 'icon' => 'code', | ||||
'url' => ['/development/index'], | 'url' => ['/development/index'], | ||||
'visible' => UserModel::isCurrentProducer(), | |||||
'visible' => User::isCurrentProducer(), | |||||
'active' => Yii::$app->controller->id == 'development', | 'active' => Yii::$app->controller->id == 'development', | ||||
'template'=>'<a href="{url}">{icon} {label}'.$newVersionOpendistribTemplate.'</a>' | 'template'=>'<a href="{url}">{icon} {label}'.$newVersionOpendistribTemplate.'</a>' | ||||
], | ], | ||||
['label' => 'Tarifs', 'icon' => 'euro', 'url' => ['/producer/billing'], 'visible' => UserModel::isCurrentProducer()], | |||||
['label' => 'Tarifs', 'icon' => 'euro', 'url' => ['/producer/billing'], 'visible' => User::isCurrentProducer()], | |||||
['label' => 'Administration', 'options' => ['class' => 'header'], 'visible' => UserModel::isCurrentAdmin()], | |||||
['label' => 'Producteurs', 'icon' => 'th-list', 'url' => ['/producer-admin/index'], 'visible' => UserModel::isCurrentAdmin()], | |||||
['label' => 'Tranches de prix', 'icon' => 'eur', 'url' => ['/producer-price-range-admin/index'], 'visible' => UserModel::isCurrentAdmin()], | |||||
['label' => 'Taxes', 'icon' => 'eur', 'url' => ['/tax-rate-admin/index'], 'visible' => UserModel::isCurrentAdmin()], | |||||
['label' => 'Communiquer', 'icon' => 'bullhorn', 'url' => ['/communicate-admin/index'], 'visible' => UserModel::isCurrentAdmin()], | |||||
['label' => 'Administration', 'options' => ['class' => 'header'], 'visible' => User::isCurrentAdmin()], | |||||
['label' => 'Producteurs', 'icon' => 'th-list', 'url' => ['/producer-admin/index'], 'visible' => User::isCurrentAdmin()], | |||||
['label' => 'Tranches de prix', 'icon' => 'eur', 'url' => ['/producer-price-range-admin/index'], 'visible' => User::isCurrentAdmin()], | |||||
['label' => 'Taxes', 'icon' => 'eur', 'url' => ['/tax-rate-admin/index'], 'visible' => User::isCurrentAdmin()], | |||||
['label' => 'Communiquer', 'icon' => 'bullhorn', 'url' => ['/communicate-admin/index'], 'visible' => User::isCurrentAdmin()], | |||||
['label' => 'Outils', 'options' => ['class' => 'header'], 'visible' => UserModel::isCurrentAdmin()], | |||||
['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii'], 'visible' => UserModel::isCurrentAdmin()], | |||||
['label' => 'Debug', 'icon' => 'dashboard', 'url' => ['/debug'], 'visible' => UserModel::isCurrentAdmin()], | |||||
['label' => 'Login', 'url' => ['site/login'], 'visible' => !UserModel::isCurrentConnected()], | |||||
['label' => 'Outils', 'options' => ['class' => 'header'], 'visible' => User::isCurrentAdmin()], | |||||
['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii'], 'visible' => User::isCurrentAdmin()], | |||||
['label' => 'Debug', 'icon' => 'dashboard', 'url' => ['/debug'], 'visible' => User::isCurrentAdmin()], | |||||
['label' => 'Login', 'url' => ['site/login'], 'visible' => ! User::isCurrentConnected()], | |||||
], | ], | ||||
] | ] | ||||
) ?> | ) ?> |
use yii\bootstrap\NavBar; | use yii\bootstrap\NavBar; | ||||
use yii\widgets\Breadcrumbs; | use yii\widgets\Breadcrumbs; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use yii\helpers\ArrayHelper; | use yii\helpers\ArrayHelper; | ||||
use common\helpers\Url; | use common\helpers\Url; | ||||
$producer = null; | $producer = null; | ||||
if (!Yii::$app->user->isGuest) { | if (!Yii::$app->user->isGuest) { | ||||
$producer = ProducerModel::findOne(GlobalParam::getCurrentProducerId()); | |||||
$producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | |||||
} | } | ||||
?> | ?> | ||||
$menuItems[] = ['label' => 'Connexion', 'url' => ['/site/login']]; | $menuItems[] = ['label' => 'Connexion', 'url' => ['/site/login']]; | ||||
} else { | } else { | ||||
if (Yii::$app->user->identity->status == UserModel::STATUS_ADMIN) { | |||||
if (Yii::$app->user->identity->status == User::STATUS_ADMIN) { | |||||
$menuItems[] = [ | $menuItems[] = [ | ||||
'label' => '<span class="glyphicon glyphicon-asterisk"></span>', | 'label' => '<span class="glyphicon glyphicon-asterisk"></span>', | ||||
'url' => '#', | 'url' => '#', | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<?php if (!Yii::$app->user->isGuest): ?> | <?php if (!Yii::$app->user->isGuest): ?> | ||||
<div class="name-producer"> | <div class="name-producer"> | ||||
<?php if (UserModel::getCurrentStatus() == UserModel::STATUS_PRODUCER): ?> | |||||
<?php if ( User::getCurrentStatus() == User::STATUS_PRODUCER): ?> | |||||
<span><?= Html::encode(Yii::$app->user->identity->getNameProducer()); ?></span> | <span><?= Html::encode(Yii::$app->user->identity->getNameProducer()); ?></span> | ||||
<?php elseif (UserModel::getCurrentStatus() == UserModel::STATUS_ADMIN): ?> | |||||
<?php elseif ( User::getCurrentStatus() == User::STATUS_ADMIN): ?> | |||||
<?php $form = ActiveForm::begin(['id' => 'select-producer']); ?> | <?php $form = ActiveForm::begin(['id' => 'select-producer']); ?> | ||||
<?= | <?= | ||||
Html::dropDownList('select_producer', GlobalParam::getCurrentProducerId(), ArrayHelper::map(ProducerModel::find()->orderBy('name ASC')->all(), 'id', function ($model, $defaultValue) { | Html::dropDownList('select_producer', GlobalParam::getCurrentProducerId(), ArrayHelper::map(ProducerModel::find()->orderBy('name ASC')->all(), 'id', function ($model, $defaultValue) { | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<?php | <?php | ||||
$producer = ProducerModel::findOne(GlobalParam::getCurrentProducerId()); | |||||
$producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | |||||
if (!$producer->active): | if (!$producer->active): | ||||
?> | ?> | ||||
<span class="label label-danger" data-toggle="tooltip" data-placement="bottom" | <span class="label label-danger" data-toggle="tooltip" data-placement="bottom" |
$html .= '<td><strong>'.number_format($order->amount, 2) . ' € '; | $html .= '<td><strong>'.number_format($order->amount, 2) . ' € '; | ||||
if($order->getPaymentStatus() == OrderModel::PAYMENT_PAID) | |||||
if($order->getPaymentStatus() == Order::PAYMENT_PAID) | |||||
{ | { | ||||
$html .= '(payé)' ; | $html .= '(payé)' ; | ||||
} | } | ||||
elseif($order->getPaymentStatus() == OrderModel::PAYMENT_UNPAID && $order->getAmount(OrderModel::AMOUNT_PAID)) | |||||
elseif($order->getPaymentStatus() == Order::PAYMENT_UNPAID && $order->getAmount(Order::AMOUNT_PAID)) | |||||
{ | { | ||||
$html .= '(reste '.$order->getAmount(OrderModel::AMOUNT_REMAINING, true).' à payer)' ; | |||||
$html .= '(reste '.$order->getAmount(Order::AMOUNT_REMAINING, true).' à payer)' ; | |||||
} | } | ||||
elseif($order->getPaymentStatus() == OrderModel::PAYMENT_SURPLUS) | |||||
elseif($order->getPaymentStatus() == Order::PAYMENT_SURPLUS) | |||||
{ | { | ||||
$html .= '(surplus : '.$order->getAmount(OrderModel::PAYMENT_SURPLUS, true).' à rembourser)' ; | |||||
$html .= '(surplus : '.$order->getAmount(Order::PAYMENT_SURPLUS, true).' à rembourser)' ; | |||||
} | } | ||||
$html .= '</strong></td>' ; | $html .= '</strong></td>' ; | ||||
$strProducts = ''; | $strProducts = ''; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
$quantity = OrderModel::getProductQuantity($product->id, $pointSale->orders); | |||||
$quantity = Order::getProductQuantity($product->id, $pointSale->orders); | |||||
$strQuantity = ''; | $strQuantity = ''; | ||||
if ($quantity) { | if ($quantity) { | ||||
$strQuantity = $quantity; | $strQuantity = $quantity; | ||||
{ | { | ||||
$html .= '<tr><td>'.$pointSale->name.'</td><td>' ; | $html .= '<tr><td>'.$pointSale->name.'</td><td>' ; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
$quantity = OrderModel::getProductQuantity($product->id, $pointSale->orders); | |||||
$quantity = Order::getProductQuantity($product->id, $pointSale->orders); | |||||
$strQuantity = ($quantity) ? $quantity : '' ; | $strQuantity = ($quantity) ? $quantity : '' ; | ||||
if(strlen($strQuantity)) { | if(strlen($strQuantity)) { | ||||
// total | // total | ||||
$html .= '<tr><td><strong>Total</strong></td><td>' ; | $html .= '<tr><td><strong>Total</strong></td><td>' ; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
$quantity = OrderModel::getProductQuantity($product->id, $ordersArray); | |||||
$quantity = Order::getProductQuantity($product->id, $ordersArray); | |||||
if($quantity) { | if($quantity) { | ||||
$html .= $quantity . ' '.$product->name.', ' ; | $html .= $quantity . ' '.$product->name.', ' ; | ||||
} | } |
<?= $form->field($model, 'id_user', [ | <?= $form->field($model, 'id_user', [ | ||||
'template' => '{label} <a href="' . Yii::$app->urlManager->createUrl(['user/create']) . '" class="btn btn-xs btn-default">Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span></a><div>{input}</div>{hint}', | 'template' => '{label} <a href="' . Yii::$app->urlManager->createUrl(['user/create']) . '" class="btn btn-xs btn-default">Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span></a><div>{input}</div>{hint}', | ||||
]) | ]) | ||||
->dropDownList(UserModel::populateDropdownList(), ['class' => 'select2']) | |||||
->dropDownList( User::populateDropdownList(), ['class' => 'select2']) | |||||
->hint('Utilisé lors de la facturation'); ?> | ->hint('Utilisé lors de la facturation'); ?> | ||||
<?php | <?php | ||||
<?= $form->field($model, 'credit_functioning') | <?= $form->field($model, 'credit_functioning') | ||||
->dropDownList([ | ->dropDownList([ | ||||
'' => 'Paramètres globaux (' . ProducerModel::$creditFunctioningArray[ProducerModel::getConfig('credit_functioning')] . ')', | |||||
ProducerModel::CREDIT_FUNCTIONING_OPTIONAL => ProducerModel::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_OPTIONAL], | |||||
ProducerModel::CREDIT_FUNCTIONING_MANDATORY => ProducerModel::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_MANDATORY], | |||||
ProducerModel::CREDIT_FUNCTIONING_USER => ProducerModel::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_USER], | |||||
'' => 'Paramètres globaux (' . Producer::$creditFunctioningArray[ProducerModel::getConfig('credit_functioning')] . ')', | |||||
Producer::CREDIT_FUNCTIONING_OPTIONAL => Producer::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_OPTIONAL], | |||||
Producer::CREDIT_FUNCTIONING_MANDATORY => Producer::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_MANDATORY], | |||||
Producer::CREDIT_FUNCTIONING_USER => Producer::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_USER], | |||||
], [])->hint(ProducerModel::HINT_CREDIT_FUNCTIONING); ?> | ], [])->hint(ProducerModel::HINT_CREDIT_FUNCTIONING); ?> | ||||
<?php /*$form->field($model, 'product_price_percent') | <?php /*$form->field($model, 'product_price_percent') | ||||
->dropDownList(ProductPriceModel::percentValues(), [])->hint('Pourcentage appliqué aux prix de chaque produit dans ce point de vente.');*/ ?> | |||||
->dropDownList( ProductPrice::percentValues(), [])->hint('Pourcentage appliqué aux prix de chaque produit dans ce point de vente.');*/ ?> | |||||
<?= $form->field($model, 'maximum_number_orders')->textInput() ?> | <?= $form->field($model, 'maximum_number_orders')->textInput() ?> | ||||
<?= Html::activeCheckboxList($model, 'users', ArrayHelper::map($users, 'user_id', function ($model_user, $defaultValue) use ($model) { | <?= Html::activeCheckboxList($model, 'users', ArrayHelper::map($users, 'user_id', function ($model_user, $defaultValue) use ($model) { | ||||
return Html::encode(UserModel::getUsernameFromArray($model_user)) . '<br />' | |||||
return Html::encode( User::getUsernameFromArray($model_user)) . '<br />' | |||||
. Html::activeTextInput( | . Html::activeTextInput( | ||||
$model, | $model, | ||||
'users_comment[' . $model_user['user_id'] . ']', | 'users_comment[' . $model_user['user_id'] . ']', |
], | ], | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function ($model) { | 'value' => function ($model) { | ||||
$count = UserPointSaleModel::find()->where( | |||||
$count = UserPointSale::find()->where( | |||||
['id_point_sale' => $model->id] | ['id_point_sale' => $model->id] | ||||
)->count(); | )->count(); | ||||
$html = ''; | $html = ''; | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function ($model) { | 'value' => function ($model) { | ||||
if ($model->credit && isset(ProducerModel::$creditFunctioningArray[$model->credit_functioning])) { | if ($model->credit && isset(ProducerModel::$creditFunctioningArray[$model->credit_functioning])) { | ||||
return '<span class="glyphicon glyphicon-euro"></span> ' . ProducerModel::$creditFunctioningArray[$model->credit_functioning]; | |||||
return '<span class="glyphicon glyphicon-euro"></span> ' . Producer::$creditFunctioningArray[$model->credit_functioning]; | |||||
} | } | ||||
return ''; | return ''; |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\UserModel ; | |||||
use common\models\ User ; | |||||
use common\models\Etablissement ; | use common\models\Etablissement ; | ||||
$this->title = 'Facturation'; | $this->title = 'Facturation'; |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\UserModel ; | |||||
use common\models\ User ; | |||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\models\Distribution ; | use common\models\Distribution ; | ||||
else { | else { | ||||
foreach($model->user as $u) | foreach($model->user as $u) | ||||
{ | { | ||||
if($u->status == UserModel::STATUS_PRODUCER) | |||||
if($u->status == User::STATUS_PRODUCER) | |||||
{ | { | ||||
return Html::encode($u->lastname.' '.$u->name) | return Html::encode($u->lastname.' '.$u->name) | ||||
.'<br />'.Html::encode($u->email) | .'<br />'.Html::encode($u->email) |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\Distribution; | use common\models\Distribution; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\UserModel ; | |||||
use common\models\ User ; | |||||
use common\models\Producer ; | use common\models\Producer ; | ||||
use yii\bootstrap\ActiveForm; | use yii\bootstrap\ActiveForm; | ||||
<script> | <script> | ||||
var appInitValues = { | var appInitValues = { | ||||
isAdmin: <?= (int)UserModel::isCurrentAdmin() ?> | |||||
isAdmin: <?= (int) User::isCurrentAdmin() ?> | |||||
}; | }; | ||||
</script> | </script> | ||||
?> | ?> | ||||
<?= $form->field($model, 'behavior_home_point_sale_day_list') | <?= $form->field($model, 'behavior_home_point_sale_day_list') | ||||
->dropDownList([ | ->dropDownList([ | ||||
ProducerModel::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK => 'Jours de la semaine', | |||||
ProducerModel::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_INCOMING_DISTRIBUTIONS => 'Distributions à venir', | |||||
Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_WEEK => 'Jours de la semaine', | |||||
Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_INCOMING_DISTRIBUTIONS => 'Distributions à venir', | |||||
]); ?> | ]); ?> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<h4>Tunnel de commande</h4> | <h4>Tunnel de commande</h4> | ||||
<?= $form->field($model, 'option_order_entry_point') | <?= $form->field($model, 'option_order_entry_point') | ||||
->dropDownList([ | ->dropDownList([ | ||||
ProducerModel::ORDER_ENTRY_POINT_DATE => 'Date', | |||||
ProducerModel::ORDER_ENTRY_POINT_POINT_SALE => 'Point de vente', | |||||
Producer::ORDER_ENTRY_POINT_DATE => 'Date', | |||||
Producer::ORDER_ENTRY_POINT_POINT_SALE => 'Point de vente', | |||||
], []); ?> | ], []); ?> | ||||
<?= $form->field($model, 'behavior_order_select_distribution') | <?= $form->field($model, 'behavior_order_select_distribution') | ||||
->dropDownList([ | ->dropDownList([ | ||||
ProducerModel::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_CALENDAR => 'Calendrier', | |||||
ProducerModel::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST => 'Liste', | |||||
Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_CALENDAR => 'Calendrier', | |||||
Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST => 'Liste', | |||||
]); ?> | ]); ?> | ||||
<?= $form->field($model, 'option_delivery') | <?= $form->field($model, 'option_delivery') | ||||
->dropDownList([ | ->dropDownList([ | ||||
<h4>Divers</h4> | <h4>Divers</h4> | ||||
<?= $form->field($model, 'option_order_reference_type') | <?= $form->field($model, 'option_order_reference_type') | ||||
->dropDownList([ | ->dropDownList([ | ||||
ProducerModel::ORDER_REFERENCE_TYPE_NONE => '--', | |||||
ProducerModel::ORDER_REFERENCE_TYPE_YEARLY => 'Annuelle', | |||||
Producer::ORDER_REFERENCE_TYPE_NONE => '--', | |||||
Producer::ORDER_REFERENCE_TYPE_YEARLY => 'Annuelle', | |||||
], []); ?> | ], []); ?> | ||||
<?= $form->field($model, 'option_behavior_cancel_order') | <?= $form->field($model, 'option_behavior_cancel_order') | ||||
->dropDownList([ | ->dropDownList([ | ||||
ProducerModel::BEHAVIOR_DELETE_ORDER_DELETE => 'Suppression de la commande', | |||||
ProducerModel::BEHAVIOR_DELETE_ORDER_STATUS => 'Passage de la commande en statut "supprimé"', | |||||
Producer::BEHAVIOR_DELETE_ORDER_DELETE => 'Suppression de la commande', | |||||
Producer::BEHAVIOR_DELETE_ORDER_STATUS => 'Passage de la commande en statut "supprimé"', | |||||
], []); ?> | ], []); ?> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<?= $form->field($model, 'credit_functioning') | <?= $form->field($model, 'credit_functioning') | ||||
->dropDownList([ | ->dropDownList([ | ||||
ProducerModel::CREDIT_FUNCTIONING_OPTIONAL => ProducerModel::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_OPTIONAL], | |||||
ProducerModel::CREDIT_FUNCTIONING_MANDATORY => ProducerModel::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_MANDATORY], | |||||
ProducerModel::CREDIT_FUNCTIONING_USER => ProducerModel::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_USER], | |||||
Producer::CREDIT_FUNCTIONING_OPTIONAL => Producer::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_OPTIONAL], | |||||
Producer::CREDIT_FUNCTIONING_MANDATORY => Producer::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_MANDATORY], | |||||
Producer::CREDIT_FUNCTIONING_USER => Producer::$creditFunctioningArray[ProducerModel::CREDIT_FUNCTIONING_USER], | |||||
], [])->hint(ProducerModel::HINT_CREDIT_FUNCTIONING); ?> | ], [])->hint(ProducerModel::HINT_CREDIT_FUNCTIONING); ?> | ||||
<?= $form->field($model, 'use_credit_checked_default') | <?= $form->field($model, 'use_credit_checked_default') |
<?= $form->field($model, 'active')->radioList([1 => 'Oui', 0 => 'Non']) ?> | <?= $form->field($model, 'active')->radioList([1 => 'Oui', 0 => 'Non']) ?> | ||||
<?= $form->field($model, 'name')->textInput(['maxlength' => 255]) ?> | <?= $form->field($model, 'name')->textInput(['maxlength' => 255]) ?> | ||||
<?= $form->field($model, 'reference')->textInput(['maxlength' => 255]) ?> | <?= $form->field($model, 'reference')->textInput(['maxlength' => 255]) ?> | ||||
<?= $form->field($model, 'id_product_category')->dropDownList(ProductCategoryModel::populateDropdownList()); ?> | |||||
<?= $form->field($model, 'id_product_category')->dropDownList( ProductCategory::populateDropdownList()); ?> | |||||
<?= $form->field($model, 'description')->textInput(['maxlength' => 255]) ?> | <?= $form->field($model, 'description')->textInput(['maxlength' => 255]) ?> | ||||
<?= $form->field($model, 'recipe')->textarea()->label('Description longue') ?> | <?= $form->field($model, 'recipe')->textarea()->label('Description longue') ?> | ||||
<?= $form->field($model, 'unit') | <?= $form->field($model, 'unit') | ||||
->dropDownList(ArrayHelper::map(ProductModel::$unitsArray, 'unit', 'wording')) | |||||
->dropDownList(ArrayHelper::map( Product::$unitsArray, 'unit', 'wording')) | |||||
->label('Unité (pièce, poids ou volume)'); ?> | ->label('Unité (pièce, poids ou volume)'); ?> | ||||
<?= $form->field($model, 'available_on_points_sale')->radioList([1 => 'Disponible', 0 => 'Indisponible']) ?> | <?= $form->field($model, 'available_on_points_sale')->radioList([1 => 'Disponible', 0 => 'Indisponible']) ?> | ||||
<strong id="label-availability-points-sale">Et <span><?php if($model->available_on_points_sale): ?>indisponible<?php else: ?>disponible<?php endif; ?></span> sur les points de vente</strong> | <strong id="label-availability-points-sale">Et <span><?php if($model->available_on_points_sale): ?>indisponible<?php else: ?>disponible<?php endif; ?></span> sur les points de vente</strong> | ||||
<?php $pointSaleArray = PointSaleModel::find() | |||||
<?php $pointSaleArray = PointSale::find() | |||||
->where(['id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['id_producer' => GlobalParam::getCurrentProducerId()]) | ||||
->orderBy('is_bread_box ASC, name ASC') | ->orderBy('is_bread_box ASC, name ASC') | ||||
->all(); ?> | ->all(); ?> |
'value' => function ($model) { | 'value' => function ($model) { | ||||
$return = ''; | $return = ''; | ||||
if ($model->price) { | if ($model->price) { | ||||
$return = Price::format($model->getPriceWithTax()) . ' (' . ProductModel::strUnit($model->unit, 'wording_unit', true) . ')'; | |||||
$return = Price::format($model->getPriceWithTax()) . ' (' . Product::strUnit($model->unit, 'wording_unit', true) . ')'; | |||||
} | } | ||||
return $return; | return $return; |
use common\models\TaxRate; | use common\models\TaxRate; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\models\UserModel ; | |||||
use common\models\ User ; | |||||
?> | ?> | ||||
'options' => ['enctype' => 'multipart/form-data'] | 'options' => ['enctype' => 'multipart/form-data'] | ||||
]); ?> | ]); ?> | ||||
<?= $form->field($model, 'id_user')->dropDownList(UserModel::populateDropdownList()); ?> | |||||
<?= $form->field($model, 'id_user_group')->dropDownList(UserGroupModel::populateDropdownList()); ?> | |||||
<?= $form->field($model, 'id_point_sale')->dropDownList(PointSaleModel::populateDropdownList()); ?> | |||||
<?= $form->field($model, 'from_quantity')->label('À partir de la quantité ('.ProductModel::strUnit(ProductModel::getRefUnit($modelProduct->unit), 'wording').')'); ?> | |||||
<?= $form->field($model, 'id_user')->dropDownList( User::populateDropdownList()); ?> | |||||
<?= $form->field($model, 'id_user_group')->dropDownList( UserGroup::populateDropdownList()); ?> | |||||
<?= $form->field($model, 'id_point_sale')->dropDownList(PointSale::populateDropdownList()); ?> | |||||
<?= $form->field($model, 'from_quantity')->label('À partir de la quantité ('. Product::strUnit( Product::getRefUnit($modelProduct->unit), 'wording').')'); ?> | |||||
<?php | <?php | ||||
$producer = GlobalParam::getCurrentProducer(); | $producer = GlobalParam::getCurrentProducer(); | ||||
'template' => ' | 'template' => ' | ||||
<div class="row"> | <div class="row"> | ||||
<div class="col-xs-6"> | <div class="col-xs-6"> | ||||
<label for="product-price" class="control-label without-tax">Prix ('.ProductModel::strUnit(ProductModel::getRefUnit($modelProduct->unit), 'wording_unit').') HT</label> | |||||
<label for="product-price" class="control-label without-tax">Prix ('. Product::strUnit( Product::getRefUnit($modelProduct->unit), 'wording_unit').') HT</label> | |||||
<div class="input-group"> | <div class="input-group"> | ||||
{input} <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span> | {input} <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<div class="col-xs-6"> | <div class="col-xs-6"> | ||||
<label for="productprice-price-with-tax" class="control-label with-tax">Prix ('.ProductModel::strUnit(ProductModel::getRefUnit($modelProduct->unit), 'wording_unit').') TTC</label> | |||||
<label for="productprice-price-with-tax" class="control-label with-tax">Prix ('. Product::strUnit( Product::getRefUnit($modelProduct->unit), 'wording_unit').') TTC</label> | |||||
<div class="input-group"> | <div class="input-group"> | ||||
<input type="text" id="productprice-price-with-tax" class="form-control" name="" value="" data-tax-rate-value="'.$taxRateValue.'"> | <input type="text" id="productprice-price-with-tax" class="form-control" name="" value="" data-tax-rate-value="'.$taxRateValue.'"> | ||||
<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span> | <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span> |
'attribute' => 'from_quantity', | 'attribute' => 'from_quantity', | ||||
'value' => function ($productPrice) { | 'value' => function ($productPrice) { | ||||
if($productPrice->from_quantity) { | if($productPrice->from_quantity) { | ||||
return $productPrice->from_quantity.' '.ProductModel::strUnit(ProductModel::getRefUnit($productPrice->product->unit), 'wording'); | |||||
return $productPrice->from_quantity.' '. Product::strUnit( Product::getRefUnit($productPrice->product->unit), 'wording'); | |||||
} | } | ||||
return '' ; | return '' ; |
?> | ?> | ||||
<div class="quotation-index"> | <div class="quotation-index"> | ||||
<?php if(QuotationModel::searchCount()): ?> | |||||
<?php if(Quotation::searchCount()): ?> | |||||
<?= GridView::widget([ | <?= GridView::widget([ | ||||
'filterModel' => $searchModel, | 'filterModel' => $searchModel, | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'attribute' => 'amount', | 'attribute' => 'amount', | ||||
'header' => 'Montant', | 'header' => 'Montant', | ||||
'value' => function($invoice) { | 'value' => function($invoice) { | ||||
return $invoice->getAmountWithTax(OrderModel::AMOUNT_TOTAL, true) ; | |||||
return $invoice->getAmountWithTax(Order::AMOUNT_TOTAL, true) ; | |||||
} | } | ||||
], | ], | ||||
[ | [ |
</td> | </td> | ||||
<td><?= $order->getCartSummary() ; ?></td> | <td><?= $order->getCartSummary() ; ?></td> | ||||
<td><?= $order->getPointSaleSummary() ; ?></td> | <td><?= $order->getPointSaleSummary() ; ?></td> | ||||
<td><?= $order->getAmountWithTax(OrderModel::AMOUNT_TOTAL, true) ; ?></td> | |||||
<td><?= $order->getAmountWithTax(Order::AMOUNT_TOTAL, true) ; ?></td> | |||||
<td class="history"><?= $order->getStrHistory() ; ?></td> | <td class="history"><?= $order->getStrHistory() ; ?></td> | ||||
</tr> | </tr> | ||||
<?php endforeach; ?> | <?php endforeach; ?> |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use yii\helpers\ArrayHelper ; | use yii\helpers\ArrayHelper ; | ||||
use common\models\UserModel ; | |||||
use common\models\ User ; | |||||
use common\models\PointSale ; | use common\models\PointSale ; | ||||
use common\helpers\GlobalParam ; | use common\helpers\GlobalParam ; | ||||
<?= $form->field($model, 'id')->hiddenInput() ?> | <?= $form->field($model, 'id')->hiddenInput() ?> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<div class="col-md-5" id="bloc-select-user"> | <div class="col-md-5" id="bloc-select-user"> | ||||
<?= $form->field($model, 'id_user')->dropDownList(UserModel::populateDropdownList(), ['class' => 'select2']); ?> | |||||
<?= $form->field($model, 'id_user')->dropDownList( User::populateDropdownList(), ['class' => 'select2']); ?> | |||||
</div> | </div> | ||||
<div class="col-md-1" id="or-user"> | <div class="col-md-1" id="or-user"> | ||||
<span>OU</span> | <span>OU</span> | ||||
<div class="clr"></div> | <div class="clr"></div> | ||||
<?= $form->field($model, 'id_producer')->hiddenInput() ?> | <?= $form->field($model, 'id_producer')->hiddenInput() ?> | ||||
<?= $form->field($model, 'id_point_sale')->dropDownList(ArrayHelper::map(PointSaleModel::searchAll(), 'id', function($model, $defaultValue) { | |||||
<?= $form->field($model, 'id_point_sale')->dropDownList(ArrayHelper::map(PointSale::searchAll(), 'id', function($model, $defaultValue) { | |||||
return $model['name']; | return $model['name']; | ||||
}), ['prompt' => '--','class' => 'form-control user-id']) ?> | }), ['prompt' => '--','class' => 'form-control user-id']) ?> | ||||
<?= $form->field($model, 'date_begin') ?> | <?= $form->field($model, 'date_begin') ?> | ||||
<?= $form->field($model, 'auto_payment') | <?= $form->field($model, 'auto_payment') | ||||
->dropDownList([ | ->dropDownList([ | ||||
SubscriptionModel::AUTO_PAYMENT_DEDUCTED => 'Déduit', | |||||
SubscriptionModel::AUTO_PAYMENT_YES => 'Oui', | |||||
SubscriptionModel::AUTO_PAYMENT_NO => 'Non' | |||||
Subscription::AUTO_PAYMENT_DEDUCTED => 'Déduit', | |||||
Subscription::AUTO_PAYMENT_YES => 'Oui', | |||||
Subscription::AUTO_PAYMENT_NO => 'Non' | |||||
]) | ]) | ||||
->hint('Attention, un compte client existant doit être spécifié en haut de ce formulaire.') ?> | ->hint('Attention, un compte client existant doit être spécifié en haut de ce formulaire.') ?> | ||||
$this->addBreadcrumb($this->getTitle()) ; | $this->addBreadcrumb($this->getTitle()) ; | ||||
$this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon-plus"></span>', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ; | $this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon-plus"></span>', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ; | ||||
$subscriptionsArray = SubscriptionModel::searchAll() ; | |||||
$subscriptionsArray = Subscription::searchAll() ; | |||||
foreach($model->productSubscription as $productSubscription) | foreach($model->productSubscription as $productSubscription) | ||||
{ | { | ||||
if(isset($productSubscription->product)) { | if(isset($productSubscription->product)) { | ||||
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * ProductModel::$unitsArray[$productSubscription->product->unit]['coefficient']).' '.ProductModel::strUnit($productSubscription->product->unit, 'wording_short').')<br />' ; | |||||
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']).' '. Product::strUnit($productSubscription->product->unit, 'wording_short').')<br />' ; | |||||
} | } | ||||
else { | else { | ||||
$html .= 'Produit non défini<br />' ; | $html .= 'Produit non défini<br />' ; | ||||
'attribute' => 'id_point_sale', | 'attribute' => 'id_point_sale', | ||||
'label' => 'Point de vente', | 'label' => 'Point de vente', | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'filter' => ArrayHelper::map(PointSaleModel::find()->where(['id_producer' => GlobalParam::getCurrentProducerId()])->asArray()->all(), 'id', 'name'), | |||||
'filter' => ArrayHelper::map(PointSale::find()->where(['id_producer' => GlobalParam::getCurrentProducerId()])->asArray()->all(), 'id', 'name'), | |||||
'value' => function($model) { | 'value' => function($model) { | ||||
return Html::encode($model->pointSale->name) ; | return Html::encode($model->pointSale->name) ; | ||||
} | } |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\Distribution; | use common\models\Distribution; | ||||
]); ?> | ]); ?> | ||||
<?= $form->field($model, 'type') | <?= $form->field($model, 'type') | ||||
->dropDownList(UserModel::getTypeChoicesArray(), [ | |||||
->dropDownList( User::getTypeChoicesArray(), [ | |||||
'v-model' => 'type' | 'v-model' => 'type' | ||||
]) ; ?> | ]) ; ?> | ||||
<?= $form->field($model, 'name_legal_person', ['options' => ['v-show' => "type == 'legal-person'"]])->textInput() ?> | <?= $form->field($model, 'name_legal_person', ['options' => ['v-show' => "type == 'legal-person'"]])->textInput() ?> | ||||
?> | ?> | ||||
<?php /* $form->field($model, 'product_price_percent') | <?php /* $form->field($model, 'product_price_percent') | ||||
->dropDownList(ProductPriceModel::percentValues(), [])->hint('Pourcentage appliqué aux prix de chaque produit pour cet utilisateur.');*/ ?> | |||||
->dropDownList( ProductPrice::percentValues(), [])->hint('Pourcentage appliqué aux prix de chaque produit pour cet utilisateur.');*/ ?> | |||||
<div class="form-group"> | <div class="form-group"> | ||||
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | <?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
<div class="user-credit"> | <div class="user-credit"> | ||||
<?php | <?php | ||||
$producer = ProducerModel::searchOne([ | |||||
$producer = Producer::searchOne([ | |||||
'id' => GlobalParam::getCurrentProducerId() | 'id' => GlobalParam::getCurrentProducerId() | ||||
]); | ]); | ||||
<div class="panel-body"> | <div class="panel-body"> | ||||
<?php $form = ActiveForm::begin(); ?> | <?php $form = ActiveForm::begin(); ?> | ||||
<?= $form->field($creditForm, 'type')->dropDownList([ | <?= $form->field($creditForm, 'type')->dropDownList([ | ||||
CreditHistoryModel::TYPE_CREDIT => 'Crédit', | |||||
CreditHistoryModel::TYPE_DEBIT => 'Débit', | |||||
CreditHistory::TYPE_CREDIT => 'Crédit', | |||||
CreditHistory::TYPE_DEBIT => 'Débit', | |||||
]) ?> | ]) ?> | ||||
<?= $form->field($creditForm, 'amount')->textInput() ?> | <?= $form->field($creditForm, 'amount')->textInput() ?> | ||||
<?= $form->field($creditForm, 'mean_payment')->dropDownList([ | <?= $form->field($creditForm, 'mean_payment')->dropDownList([ |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\UserModel; | |||||
use common\models\ User; | |||||
use common\models\Order; | use common\models\Order; | ||||
$this->setTitle('Utilisateurs'); | $this->setTitle('Utilisateurs'); | ||||
'attribute' => 'username', | 'attribute' => 'username', | ||||
'label' => 'Nom', | 'label' => 'Nom', | ||||
'value' => function ($model) { | 'value' => function ($model) { | ||||
return UserModel::getUsernameFromArray($model); | |||||
return User::getUsernameFromArray($model); | |||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'type', | 'attribute' => 'type', | ||||
'label' => 'Type', | 'label' => 'Type', | ||||
'value' => function ($model) { | 'value' => function ($model) { | ||||
$typeArray = UserModel::getTypeChoicesArray(); | |||||
$typeArray = User::getTypeChoicesArray(); | |||||
if(isset($typeArray[$model['type']])) { | if(isset($typeArray[$model['type']])) { | ||||
return $typeArray[$model['type']]; | return $typeArray[$model['type']]; | ||||
} | } | ||||
'buttons' => [ | 'buttons' => [ | ||||
'orders' => function ($url, $model) { | 'orders' => function ($url, $model) { | ||||
$url = Yii::$app->urlManager->createUrl(['user/orders', 'id' => $model['id']]); | $url = Yii::$app->urlManager->createUrl(['user/orders', 'id' => $model['id']]); | ||||
$countOrders = OrderModel::searchCount([ | |||||
$countOrders = Order::searchCount([ | |||||
'id_user' => $model['id'], | 'id_user' => $model['id'], | ||||
], ['conditions' => 'date_delete IS NULL']); | ], ['conditions' => 'date_delete IS NULL']); | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function ($model) use ($producer) { | 'value' => function ($model) use ($producer) { | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $model->id | 'id_user' => $model->id | ||||
]); | ]); | ||||
$credit = $userProducer ? $userProducer->credit : 0; | $credit = $userProducer ? $userProducer->credit : 0; | ||||
'buttons' => [ | 'buttons' => [ | ||||
'update' => function ($url, $model) { | 'update' => function ($url, $model) { | ||||
$url = Yii::$app->urlManager->createUrl(['user/update', 'id' => $model->id]); | $url = Yii::$app->urlManager->createUrl(['user/update', 'id' => $model->id]); | ||||
$user = UserModel::find()->with('userProducer')->where(['id' => $model->id])->one(); | |||||
$user = User::find()->with('userProducer')->where(['id' => $model->id])->one(); | |||||
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ | return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ | ||||
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | ||||
]); | ]); |
], | ], | ||||
'user' => [ | 'user' => [ | ||||
'class' => 'yii\web\User', | 'class' => 'yii\web\User', | ||||
'identityClass' => 'common\logic\User\User\UserModel', | |||||
'identityClass' => 'common\logic\User\User\User', | |||||
'enableAutoLogin' => true, | 'enableAutoLogin' => true, | ||||
'identityCookie' => [ | 'identityCookie' => [ | ||||
'name' => 'distrib', | 'name' => 'distrib', |
namespace common\controllers; | namespace common\controllers; | ||||
use common\components\BusinessLogic; | use common\components\BusinessLogic; | ||||
use common\logic\User\User\UserModel; | |||||
use common\logic\User\User\User; | |||||
use yii; | use yii; | ||||
class CommonController extends \yii\web\Controller | class CommonController extends \yii\web\Controller |
namespace common\forms; | namespace common\forms; | ||||
use common\logic\Producer\Producer\Producer; | use common\logic\Producer\Producer\Producer; | ||||
use common\logic\User\User\UserModel; | |||||
use common\logic\User\User\User; | |||||
use Yii; | use Yii; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
* Finds user by [[username]] | * Finds user by [[username]] | ||||
* | * | ||||
*/ | */ | ||||
public function getUser(): UserModel | |||||
public function getUser(): User | |||||
{ | { | ||||
if ($this->_user === false) { | if ($this->_user === false) { | ||||
$this->_user = UserModel::searchOne( | |||||
$this->_user = User::searchOne( | |||||
['email' => $this->email], | ['email' => $this->email], | ||||
[ | [ | ||||
'conditions' => 'type LIKE :type_individual OR type LIKE :type_legal_person', | 'conditions' => 'type LIKE :type_individual OR type LIKE :type_legal_person', | ||||
'params' => [':type_individual' => UserModel::TYPE_INDIVIDUAL, ':type_legal_person' => UserModel::TYPE_LEGAL_PERSON] | |||||
'params' => [':type_individual' => User::TYPE_INDIVIDUAL, ':type_legal_person' => User::TYPE_LEGAL_PERSON] | |||||
] | ] | ||||
); | ); | ||||
} | } |
public function save() | public function save() | ||||
{ | { | ||||
if ($this->id) { | if ($this->id) { | ||||
$subscription = SubscriptionModel::searchOne(['id' => $this->id]) ; | |||||
$subscription = Subscription::searchOne(['id' => $this->id]) ; | |||||
} | } | ||||
else { | else { | ||||
$subscription = new Subscription ; | $subscription = new Subscription ; | ||||
// produits | // produits | ||||
if ($this->id) { | if ($this->id) { | ||||
$productsSubscriptionsArray = ProductSubscriptionModel::findAll(['id_subscription' => $this->id]) ; | |||||
ProductSubscriptionModel::deleteAll(['id_subscription' => $this->id]); | |||||
$productsSubscriptionsArray = ProductSubscription::findAll(['id_subscription' => $this->id]) ; | |||||
ProductSubscription::deleteAll(['id_subscription' => $this->id]); | |||||
} | } | ||||
foreach ($this->products as $nameInput => $quantity) { | foreach ($this->products as $nameInput => $quantity) { | ||||
if ($quantity) { | if ($quantity) { | ||||
$idProduct = (int) str_replace('product_', '', $nameInput); | $idProduct = (int) str_replace('product_', '', $nameInput); | ||||
$product = ProductModel::findOne($idProduct) ; | |||||
$product = Product::findOne($idProduct) ; | |||||
$newProductSubscription = new ProductSubscription; | $newProductSubscription = new ProductSubscription; | ||||
$newProductSubscription->id_subscription = $subscription->id; | $newProductSubscription->id_subscription = $subscription->id; | ||||
$newProductSubscription->id_product = $idProduct; | $newProductSubscription->id_product = $idProduct; | ||||
$newProductSubscription->quantity = $quantity / ProductModel::$unitsArray[$product->unit]['coefficient']; | |||||
$newProductSubscription->quantity = $quantity / Product::$unitsArray[$product->unit]['coefficient']; | |||||
$newProductSubscription->save(); | $newProductSubscription->save(); | ||||
} | } |
return floatval($priceWithTax) / ($taxRate + 1); | return floatval($priceWithTax) / ($taxRate + 1); | ||||
} | } | ||||
public static function getPriceWithTax($priceWithoutTax, $taxRate, $taxCalculationMethod = DocumentModel::TAX_CALCULATION_METHOD_DEFAULT) | |||||
public static function getPriceWithTax($priceWithoutTax, $taxRate, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT) | |||||
{ | { | ||||
$vat = self::getVat($priceWithoutTax, $taxRate, $taxCalculationMethod); | $vat = self::getVat($priceWithoutTax, $taxRate, $taxCalculationMethod); | ||||
return self::numberTwoDecimals(self::round($priceWithoutTax + $vat)); | return self::numberTwoDecimals(self::round($priceWithoutTax + $vat)); | ||||
} | } | ||||
public static function getVat($priceTotalWithoutTax, $taxRate, $taxCalculationMethod = DocumentModel::TAX_CALCULATION_METHOD_DEFAULT) | |||||
public static function getVat($priceTotalWithoutTax, $taxRate, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT) | |||||
{ | { | ||||
$vat = $priceTotalWithoutTax * $taxRate; | $vat = $priceTotalWithoutTax * $taxRate; | ||||
if($taxCalculationMethod == DocumentModel::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS) { | |||||
if($taxCalculationMethod == Document::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS) { | |||||
$vat = self::round($vat); | $vat = self::round($vat); | ||||
} | } | ||||
{ | { | ||||
if ($this->producer_tiller) { | if ($this->producer_tiller) { | ||||
$ordersTiller = $this->getOrders($date); | $ordersTiller = $this->getOrders($date); | ||||
$ordersOpendistrib = OrderModel::searchAll([ | |||||
$ordersOpendistrib = Order::searchAll([ | |||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'order.tiller_synchronization' => 1 | 'order.tiller_synchronization' => 1 | ||||
], [ | ], [ | ||||
foreach ($ordersTiller->orders as $orderTiller) { | foreach ($ordersTiller->orders as $orderTiller) { | ||||
if ($orderOpendistrib->tiller_external_id == $orderTiller->id) { | if ($orderOpendistrib->tiller_external_id == $orderTiller->id) { | ||||
$amountTotalOrderOpendistrib = (int)round( | $amountTotalOrderOpendistrib = (int)round( | ||||
$orderOpendistrib->getAmountWithTax(OrderModel::AMOUNT_TOTAL) * 100 | |||||
$orderOpendistrib->getAmountWithTax(Order::AMOUNT_TOTAL) * 100 | |||||
); | ); | ||||
if ($amountTotalOrderOpendistrib == (int)$orderTiller->currentPayedAmount | if ($amountTotalOrderOpendistrib == (int)$orderTiller->currentPayedAmount | ||||
|| $amountTotalOrderOpendistrib == (int)$orderTiller->currentBill) { | || $amountTotalOrderOpendistrib == (int)$orderTiller->currentBill) { |
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; | use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; | ||||
use common\logic\Distribution\ProductDistribution\ProductDistribution; | use common\logic\Distribution\ProductDistribution\ProductDistribution; | ||||
use common\logic\Order\Order\OrderModel; | |||||
use common\logic\Order\Order\Order; | |||||
use common\logic\Producer\Producer\Producer; | use common\logic\Producer\Producer\Producer; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
{ | { | ||||
return [ | return [ | ||||
[['date'], 'required'], | [['date'], 'required'], | ||||
[['active'], 'integer'], | |||||
[['date'], 'safe'], | [['date'], 'safe'], | ||||
[['active'], 'integer'] | |||||
]; | ]; | ||||
} | } | ||||
public function getOrder() | public function getOrder() | ||||
{ | { | ||||
return $this->hasMany(OrderModel::class, ['id_distribution' => 'id']); | |||||
return $this->hasMany(Order::class, ['id_distribution' => 'id']); | |||||
} | } | ||||
public function getProductDistribution() | public function getProductDistribution() | ||||
*/ | */ | ||||
public static function linkProductIncomingDistributions($product) | public static function linkProductIncomingDistributions($product) | ||||
{ | { | ||||
$distributionsArray = self::getIncomingDistributions(); | |||||
$distributionsArray = self::getIncoming(); | |||||
foreach ($distributionsArray as $distribution) { | foreach ($distributionsArray as $distribution) { | ||||
$distribution->linkProduct($product); | $distribution->linkProduct($product); | ||||
} | } | ||||
*/ | */ | ||||
public static function linkPointSaleIncomingDistributions($pointSale) | public static function linkPointSaleIncomingDistributions($pointSale) | ||||
{ | { | ||||
$distributionsArray = self::getIncomingDistributions(); | |||||
$distributionsArray = self::getIncoming(); | |||||
foreach ($distributionsArray as $distribution) { | foreach ($distributionsArray as $distribution) { | ||||
$distribution->linkPointSale($pointSale); | $distribution->linkPointSale($pointSale); | ||||
} | } | ||||
if ($active) { | if ($active) { | ||||
// ajout des abonnements | // ajout des abonnements | ||||
SubscriptionModel::addAll($this->date); | |||||
Subscription::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\PointSaleDistributionBuilder; | ||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionRepository; | use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionRepository; | ||||
use common\logic\Distribution\ProductDistribution\ProductDistribution; | use common\logic\Distribution\ProductDistribution\ProductDistribution; | ||||
use common\logic\Order\Order\OrderModel; | |||||
use common\logic\Distribution\ProductDistribution\ProductDistributionBuilder; | |||||
use common\logic\Distribution\ProductDistribution\ProductDistributionRepository; | |||||
use common\logic\Order\Order\Order; | |||||
use common\logic\Order\Order\OrderRepository; | |||||
use common\logic\Producer\Producer\Producer; | use common\logic\Producer\Producer\Producer; | ||||
use common\logic\Product\Product\Product; | use common\logic\Product\Product\Product; | ||||
use common\logic\Product\Product\ProductRepository; | |||||
use common\logic\User\UserProducer\UserProducer; | |||||
class DistributionBuilder extends BaseService implements BuilderInterface | class DistributionBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
protected DistributionRepository $distributionRepository; | protected DistributionRepository $distributionRepository; | ||||
protected PointSaleDistributionRepository $pointSaleDistributionRepository; | protected PointSaleDistributionRepository $pointSaleDistributionRepository; | ||||
protected PointSaleDistributionBuilder $pointSaleDistributionBuilder; | protected PointSaleDistributionBuilder $pointSaleDistributionBuilder; | ||||
protected ProductRepository $productRepository; | |||||
protected ProductDistributionRepository $productDistributionRepository; | |||||
protected ProductDistributionBuilder $productDistributionBuilder; | |||||
protected OrderRepository $orderRepository; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->distributionRepository = $this->loadService(DistributionRepository::class); | $this->distributionRepository = $this->loadService(DistributionRepository::class); | ||||
$this->pointSaleDistributionRepository = $this->loadService(PointSaleDistributionRepository::class); | $this->pointSaleDistributionRepository = $this->loadService(PointSaleDistributionRepository::class); | ||||
$this->pointSaleDistributionBuilder = $this->loadService(PointSaleDistributionBuilder::class); | $this->pointSaleDistributionBuilder = $this->loadService(PointSaleDistributionBuilder::class); | ||||
$this->productRepository = $this->loadService(ProductRepository::class); | |||||
$this->productDistributionRepository = $this->loadService(ProductDistributionRepository::class); | |||||
$this->orderRepository = $this->loadService(OrderRepository::class); | |||||
} | } | ||||
public function instanciate(Producer $producer, string $date, bool $delivery = true): Distribution | public function instanciate(Producer $producer, string $date, bool $delivery = true): Distribution | ||||
return $distribution; | return $distribution; | ||||
} | } | ||||
public function create(Producer $producer, string $date, int $delivery = 1): Distribution | |||||
// initDistribution | |||||
public function create(Producer $producer, string $date, bool $delivery = true): Distribution | |||||
{ | { | ||||
$distribution = $this->instanciate($producer, $date, 1); | |||||
$distribution = $this->instanciate($producer, $date, $delivery); | |||||
$distribution->save(); | $distribution->save(); | ||||
$this->initPointSaleDistribution($distribution); | |||||
$this->initProductDistribution($distribution); | |||||
return $distribution; | return $distribution; | ||||
} | } | ||||
return $distribution; | 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 | public function initPointSaleDistribution(Distribution $distribution): void | ||||
{ | { | ||||
$countPointSaleDistribution = $this->pointSaleDistributionRepository->countByDistribution($distribution); | $countPointSaleDistribution = $this->pointSaleDistributionRepository->countByDistribution($distribution); | ||||
if (!$countPointSaleDistribution) { | if (!$countPointSaleDistribution) { | ||||
$this->pointSaleDistributionBuilder->initAll($distribution, true); | |||||
$this->pointSaleDistributionBuilder->createAll($distribution, true); | |||||
} | } | ||||
} | } | ||||
public function initProductDistribution(Distribution $distribution) | |||||
public function initProductDistribution(Distribution $distribution): void | |||||
{ | { | ||||
$products = Product::searchAll(); | |||||
$productArray = $this->productRepository->get(); | |||||
$countProductDistribution = $this->productDistributionRepository->countByDistribution($distribution); | |||||
$productsDistribution = ProductDistribution::searchAll([ | |||||
'id_distribution' => $distribution->id | |||||
]); | |||||
if (!count($productsDistribution)) { | |||||
foreach ($products as $product) { | |||||
if (!$countProductDistribution) { | |||||
foreach ($productArray as $product) { | |||||
$this->linkProduct($distribution, $product); | $this->linkProduct($distribution, $product); | ||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
public function linkProduct(Distribution $distribution, Product $product): ProductDistribution | 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; | |||||
} | |||||
$productDistribution = $this->productDistributionBuilder->createIfNotExist($distribution, $product); | |||||
$this->updateOrderProductPrices($distribution, $product); | |||||
$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; | |||||
} | |||||
return $productDistribution; | |||||
} | |||||
public function updateOrderProductPrices(Distribution $distribution, Product $product): void | |||||
{ | |||||
$ordersArray = $this->orderRepository->getByDistribution($distribution, 'AND origin != "user"'); | |||||
$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) { | if ($ordersArray) { | ||||
foreach ($ordersArray as $order) { | foreach ($ordersArray as $order) { | ||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
$userProducer = false; | $userProducer = false; | ||||
if (isset($order->user) && $order->user) { | if (isset($order->user) && $order->user) { | ||||
$user = $order->user; | $user = $order->user; | ||||
$userProducer = UserProducerModel::searchOne([ | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'id_producer' => $order->distribution->id_producer | 'id_producer' => $order->distribution->id_producer | ||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return $productDistribution; | |||||
} | } | ||||
} | } |
/** | /** | ||||
* Récupère les distributions futures. | * Récupère les distributions futures. | ||||
*/ | */ | ||||
public function getIncomingDistributions(): array | |||||
public function getIncoming(): array | |||||
{ | { | ||||
$distributionsArray = Distribution::find() | $distributionsArray = Distribution::find() | ||||
->where('date > \'' . date('Y-m-d') . '\'') | ->where('date > \'' . date('Y-m-d') . '\'') |
class DistributionSolver extends BaseService implements SolverInterface | class DistributionSolver extends BaseService implements SolverInterface | ||||
{ | { | ||||
public function getDayAsString(Distribution $distribution): string | |||||
{ | |||||
$dayDistribution = date('N', strtotime($distribution->date)); | |||||
$daysArray = [ | |||||
1 => 'monday', | |||||
2 => 'tuesday', | |||||
3 => 'wednesday', | |||||
4 => 'thursday', | |||||
5 => 'friday', | |||||
6 => 'saturday', | |||||
7 => 'sunday', | |||||
]; | |||||
return $daysArray[$dayDistribution]; | |||||
} | |||||
/** | /** | ||||
* Déduit si un produit est actif ou non | * Déduit si un produit est actif ou non | ||||
*/ | */ |
public function getPointSale() | public function getPointSale() | ||||
{ | { | ||||
return $this->hasOne(PointSaleModel::className(), ['id' => 'id_point_sale']); | |||||
return $this->hasOne(PointSale::className(), ['id' => 'id_point_sale']); | |||||
} | } | ||||
/** | /** |
* Initialise les PointSaleDistribution pour une distribution donnée. | * Initialise les PointSaleDistribution pour une distribution donnée. | ||||
*/ | */ | ||||
// setAll | // setAll | ||||
public function initAll(Distribution $distribution, bool $delivery): void | |||||
public function createAll(Distribution $distribution, bool $delivery): void | |||||
{ | { | ||||
$arrPointsSale = PointSale::find() | $arrPointsSale = PointSale::find() | ||||
->with(['pointSaleDistribution' => function($q) use ($distribution) { | ->with(['pointSaleDistribution' => function($q) use ($distribution) { |
public function getProduct() | public function getProduct() | ||||
{ | { | ||||
return $this->hasOne(ProductModel::className(), ['id' => 'id_product']); | |||||
return $this->hasOne( Product::className(), ['id' => 'id_product']); | |||||
} | } | ||||
public function getDistribution() | public function getDistribution() | ||||
'id_distribution' => $idDistribution | 'id_distribution' => $idDistribution | ||||
]) ; | ]) ; | ||||
$orders = OrderModel::searchAll([ | |||||
$orders = Order::searchAll([ | |||||
'distribution.id' => $idDistribution | 'distribution.id' => $idDistribution | ||||
]) ; | ]) ; | ||||
'active' => (int) $productDistribution->active, | 'active' => (int) $productDistribution->active, | ||||
'unavailable' => (int) $productDistribution->product->unavailable, | 'unavailable' => (int) $productDistribution->product->unavailable, | ||||
'quantity_max' => $productDistribution->quantity_max, | 'quantity_max' => $productDistribution->quantity_max, | ||||
'quantity_order' => OrderModel::getProductQuantity($productDistribution->id_product, $orders), | |||||
'quantity_remaining' => $productDistribution->quantity_max - OrderModel::getProductQuantity($productDistribution->id_product, $orders) | |||||
'quantity_order' => Order::getProductQuantity($productDistribution->id_product, $orders), | |||||
'quantity_remaining' => $productDistribution->quantity_max - Order::getProductQuantity($productDistribution->id_product, $orders) | |||||
]; | ]; | ||||
} | } | ||||
} | } |
namespace common\logic\Distribution\ProductDistribution; | namespace common\logic\Distribution\ProductDistribution; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Distribution\Distribution\Distribution; | |||||
use common\logic\Distribution\Distribution\DistributionSolver; | |||||
use common\logic\FactoryInterface; | use common\logic\FactoryInterface; | ||||
use common\logic\Product\Product\Product; | |||||
class ProductDistributionBuilder extends BaseService implements FactoryInterface | class ProductDistributionBuilder extends BaseService implements FactoryInterface | ||||
{ | { | ||||
public function create(): ProductDistribution | |||||
protected ProductDistributionRepository $productDistributionRepository; | |||||
protected DistributionSolver $distributionSolver; | |||||
public function __construct() | |||||
{ | |||||
$this->productDistributionRepository = $this->loadService(ProductDistributionRepository::class); | |||||
$this->distributionSolver = $this->loadService(DistributionSolver::class); | |||||
} | |||||
public function instanciate(Distribution $distribution, Product $product): ProductDistribution | |||||
{ | { | ||||
$productDistribution = new ProductDistribution(); | $productDistribution = new ProductDistribution(); | ||||
$productDistribution->populateRelation('distribution', $distribution); | |||||
$productDistribution->id_distribution = $distribution->id; | |||||
$productDistribution->populateRelation('product', $product); | |||||
$productDistribution->id_product = $product->id; | |||||
return $productDistribution; | return $productDistribution; | ||||
} | } | ||||
public function create(Distribution $distribution, Product $product): ProductDistribution | |||||
{ | |||||
$productDistribution = $this->instanciate($distribution, $product); | |||||
$this | |||||
->initActive($productDistribution) | |||||
->initQuantityMax($productDistribution); | |||||
$productDistribution->save(); | |||||
} | |||||
public function createIfNotExist(Distribution $distribution, Product $product): ProductDistribution | |||||
{ | |||||
$productDistribution = $this->productDistributionRepository->getOne($distribution, $product); | |||||
if(!$productDistribution) { | |||||
$productDistribution = $this->create($distribution, $product); | |||||
} | |||||
return $productDistribution; | |||||
} | |||||
public function initActive(ProductDistribution $productDistribution): ProductDistribution | |||||
{ | |||||
$day = $this->distributionSolver->getDayAsString($productDistribution->distribution); | |||||
$productDistribution->active = 0; | |||||
if ($productDistribution->product->active && $productDistribution->product->$day) { | |||||
$productDistribution->active = 1; | |||||
} | |||||
return $productDistribution; | |||||
} | |||||
public function initQuantityMax(ProductDistribution $productDistribution): ProductDistribution | |||||
{ | |||||
$product = $productDistribution->product; | |||||
$day = $this->distributionSolver->getDayAsString($productDistribution->distribution); | |||||
$productDistribution->quantity_max = $product->quantity_max; | |||||
$fieldQuantityMax = 'quantity_max_' . $day; | |||||
if (isset($product->$fieldQuantityMax) && $product->$fieldQuantityMax > 0) { | |||||
$productDistribution->quantity_max = $product->$fieldQuantityMax; | |||||
} | |||||
return $productDistribution; | |||||
} | |||||
} | } |
namespace common\logic\Distribution\ProductDistribution; | namespace common\logic\Distribution\ProductDistribution; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Distribution\Distribution\Distribution; | |||||
use common\logic\Product\Product\Product; | |||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
class ProductDistributionRepository extends BaseService implements RepositoryInterface | class ProductDistributionRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
public function countByDistribution(Distribution $distribution): int | |||||
{ | |||||
return ProductDistribution::searchCount([ | |||||
'id_distribution' => $distribution->id | |||||
]); | |||||
} | |||||
public function getOne(Distribution $distribution, Product $product): ?ProductDistribution | |||||
{ | |||||
return ProductDistribution::searchOne([ | |||||
'id_distribution' => $distribution->id, | |||||
'id_product' => $product->id | |||||
]); | |||||
} | |||||
} | } |
* @property string $city | * @property string $city | ||||
* @property string $postcode | * @property string $postcode | ||||
*/ | */ | ||||
class DeliveryNoteModel extends Document | |||||
class DeliveryNote extends Document | |||||
{ | { | ||||
/** | /** | ||||
$idInvoice = $this->getInvoiceId(); | $idInvoice = $this->getInvoiceId(); | ||||
if($idInvoice) { | if($idInvoice) { | ||||
$invoice = InvoiceModel::searchOne([ | |||||
$invoice = Invoice::searchOne([ | |||||
'id' => $idInvoice | 'id' => $idInvoice | ||||
]); | ]); | ||||
} | } |
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return DeliveryNoteModel::class; | |||||
return DeliveryNote::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
class DeliveryNoteFactory extends BaseService implements FactoryInterface | class DeliveryNoteFactory extends BaseService implements FactoryInterface | ||||
{ | { | ||||
public function create(): DeliveryNoteModel | |||||
public function create(): DeliveryNote | |||||
{ | { | ||||
$deliveryNote = new DeliveryNoteModel(); | |||||
$deliveryNote = new DeliveryNote(); | |||||
return $deliveryNote; | return $deliveryNote; | ||||
} | } |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
class DeliveryNoteSearch extends DeliveryNoteModel | |||||
class DeliveryNoteSearch extends DeliveryNote | |||||
{ | { | ||||
public $id_point_sale ; | public $id_point_sale ; | ||||
public $date_distribution ; | public $date_distribution ; | ||||
{ | { | ||||
$optionsSearch = self::defaultOptionsSearch(); | $optionsSearch = self::defaultOptionsSearch(); | ||||
$query = DeliveryNoteModel::find() | |||||
$query = DeliveryNote::find() | |||||
->with($optionsSearch['with']) | ->with($optionsSearch['with']) | ||||
->joinWith($optionsSearch['join_with']) | ->joinWith($optionsSearch['join_with']) | ||||
->where(['delivery_note.id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['delivery_note.id_producer' => GlobalParam::getCurrentProducerId()]) |
use kartik\mpdf\Pdf; | use kartik\mpdf\Pdf; | ||||
use yii\base\ErrorException; | use yii\base\ErrorException; | ||||
class DocumentModel extends ActiveRecordCommon | |||||
class Document extends ActiveRecordCommon | |||||
{ | { | ||||
const STATUS_DRAFT = 'draft'; | const STATUS_DRAFT = 'draft'; | ||||
const STATUS_VALID = 'valid'; | const STATUS_VALID = 'valid'; | ||||
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasOne(UserModel::className(), ['id' => 'id_user']); | |||||
return $this->hasOne( User::className(), ['id' => 'id_user']); | |||||
} | } | ||||
public function getProducer() | public function getProducer() | ||||
public function relationOrders($fieldIdDocument) | public function relationOrders($fieldIdDocument) | ||||
{ | { | ||||
$defaultOptionsSearch = OrderModel::defaultOptionsSearch(); | |||||
$defaultOptionsSearch = Order::defaultOptionsSearch(); | |||||
return $this->hasMany(OrderModel::className(), [$fieldIdDocument => 'id']) | |||||
return $this->hasMany(Order::className(), [$fieldIdDocument => 'id']) | |||||
->with($defaultOptionsSearch['with']) | ->with($defaultOptionsSearch['with']) | ||||
->joinWith($defaultOptionsSearch['join_with']) | ->joinWith($defaultOptionsSearch['join_with']) | ||||
->orderBy('distribution.date ASC'); | ->orderBy('distribution.date ASC'); | ||||
* Méthodes | * Méthodes | ||||
*/ | */ | ||||
public function getAmount($type = OrderModel::AMOUNT_TOTAL, $format = false) | |||||
public function getAmount($type = Order::AMOUNT_TOTAL, $format = false) | |||||
{ | { | ||||
return $this->_getAmountGeneric($type, false, $format); | return $this->_getAmountGeneric($type, false, $format); | ||||
} | } | ||||
public function getAmountWithTax($type = OrderModel::AMOUNT_TOTAL, $format = false) | |||||
public function getAmountWithTax($type = Order::AMOUNT_TOTAL, $format = false) | |||||
{ | { | ||||
return $this->_getAmountGeneric($type, true, $format); | return $this->_getAmountGeneric($type, true, $format); | ||||
} | } | ||||
protected function _getAmountGeneric($type = OrderModel::AMOUNT_TOTAL, $withTax = true, $format = false) | |||||
protected function _getAmountGeneric($type = Order::AMOUNT_TOTAL, $withTax = true, $format = false) | |||||
{ | { | ||||
$amount = 0; | $amount = 0; | ||||
$totalVat = 0; | $totalVat = 0; | ||||
} | } | ||||
$prefix = Producer::getConfig('document_' . $classLower . '_prefix'); | $prefix = Producer::getConfig('document_' . $classLower . '_prefix'); | ||||
$oneDocumentExist = $class::searchOne(['status' => DocumentModel::STATUS_VALID], ['orderby' => 'reference DESC']); | |||||
$oneDocumentExist = $class::searchOne(['status' => Document::STATUS_VALID], ['orderby' => 'reference DESC']); | |||||
if ($oneDocumentExist) { | if ($oneDocumentExist) { | ||||
$reference = $oneDocumentExist->reference; | $reference = $oneDocumentExist->reference; | ||||
public function changeStatus($status) | public function changeStatus($status) | ||||
{ | { | ||||
if ($status == DocumentModel::STATUS_VALID) { | |||||
if ($status == Document::STATUS_VALID) { | |||||
$this->status = $status; | $this->status = $status; | ||||
$this->reference = $this->generateReference(); | $this->reference = $this->generateReference(); | ||||
} | } |
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return DocumentModel::class; | |||||
return Document::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
namespace common\logic\Document\Invoice; | namespace common\logic\Document\Invoice; | ||||
use common\logic\Document\Document\DocumentModel; | |||||
use common\logic\Document\Document\Document; | |||||
/** | /** | ||||
* This is the model class for table "invoice". | * This is the model class for table "invoice". | ||||
* @property string $city | * @property string $city | ||||
* @property string $postcode | * @property string $postcode | ||||
*/ | */ | ||||
class InvoiceModel extends DocumentModel | |||||
class Invoice extends Document | |||||
{ | { | ||||
public $deliveryNotes ; | public $deliveryNotes ; |
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return InvoiceModel::class; | |||||
return Invoice::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
class InvoiceFactory extends BaseService implements FactoryInterface | class InvoiceFactory extends BaseService implements FactoryInterface | ||||
{ | { | ||||
public function create(): InvoiceModel | |||||
public function create(): Invoice | |||||
{ | { | ||||
$invoice = new InvoiceModel(); | |||||
$invoice = new Invoice(); | |||||
return $invoice; | return $invoice; | ||||
} | } |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
class InvoiceSearch extends InvoiceModel | |||||
class InvoiceSearch extends Invoice | |||||
{ | { | ||||
var $username; | var $username; | ||||
{ | { | ||||
$optionsSearch = self::defaultOptionsSearch(); | $optionsSearch = self::defaultOptionsSearch(); | ||||
$query = InvoiceModel::find() | |||||
$query = Invoice::find() | |||||
->with($optionsSearch['with']) | ->with($optionsSearch['with']) | ||||
->joinWith($optionsSearch['join_with']) | ->joinWith($optionsSearch['join_with']) | ||||
->where(['invoice.id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['invoice.id_producer' => GlobalParam::getCurrentProducerId()]) |
namespace common\logic\Document\Quotation; | namespace common\logic\Document\Quotation; | ||||
use common\logic\Document\Document\DocumentModel; | |||||
use common\logic\Document\Document\Document; | |||||
/** | /** | ||||
* This is the model class for table "quotation". | * This is the model class for table "quotation". | ||||
* @property string $city | * @property string $city | ||||
* @property string $postcode | * @property string $postcode | ||||
*/ | */ | ||||
class QuotationModel extends DocumentModel | |||||
class Quotation extends Document | |||||
{ | { | ||||
/** | /** |
use common\logic\Document\Document\DocumentBuilder; | use common\logic\Document\Document\DocumentBuilder; | ||||
use common\logic\Document\Document\DocumentSolver; | use common\logic\Document\Document\DocumentSolver; | ||||
use common\logic\Document\Quotation\QuotationFactory; | use common\logic\Document\Quotation\QuotationFactory; | ||||
use common\logic\Document\Quotation\QuotationModel; | |||||
use common\logic\Document\Quotation\Quotation; | |||||
class QuotationContainer implements ContainerInterface | class QuotationContainer implements ContainerInterface | ||||
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return QuotationModel::class; | |||||
return Quotation::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
class QuotationFactory extends BaseService implements FactoryInterface | class QuotationFactory extends BaseService implements FactoryInterface | ||||
{ | { | ||||
public function create(): QuotationModel | |||||
public function create(): Quotation | |||||
{ | { | ||||
$quotation = new QuotationModel(); | |||||
$quotation = new Quotation(); | |||||
return $quotation; | return $quotation; | ||||
} | } |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
class QuotationSearch extends QuotationModel | |||||
class QuotationSearch extends Quotation | |||||
{ | { | ||||
public function rules() | public function rules() | ||||
{ | { | ||||
$optionsSearch = self::defaultOptionsSearch(); | $optionsSearch = self::defaultOptionsSearch(); | ||||
$query = QuotationModel::find() | |||||
$query = Quotation::find() | |||||
->with($optionsSearch['with']) | ->with($optionsSearch['with']) | ||||
->joinWith($optionsSearch['join_with']) | ->joinWith($optionsSearch['join_with']) | ||||
->where(['quotation.id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['quotation.id_producer' => GlobalParam::getCurrentProducerId()]) |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\Price; | use common\helpers\Price; | ||||
use common\logic\Producer\Producer\Producer; | use common\logic\Producer\Producer\Producer; | ||||
use common\logic\User\CreditHistory\CreditHistoryModel; | |||||
use common\logic\User\User\UserModel; | |||||
use common\logic\User\CreditHistory\CreditHistory; | |||||
use common\logic\User\User\User; | |||||
use Yii; | use Yii; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
* This is the model class for table "order". | * This is the model class for table "order". | ||||
* | * | ||||
*/ | */ | ||||
class OrderModel extends ActiveRecordCommon | |||||
class Order extends ActiveRecordCommon | |||||
{ | { | ||||
var $amount = 0; | var $amount = 0; | ||||
var $amount_with_tax = 0; | var $amount_with_tax = 0; | ||||
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasOne(UserModel::className(), ['id' => 'id_user']); | |||||
return $this->hasOne(User::className(), ['id' => 'id_user']); | |||||
} | } | ||||
public function getProductOrder() | public function getProductOrder() | ||||
{ | { | ||||
return $this->hasMany(ProductOrderModel::className(), ['id_order' => 'id']) | |||||
return $this->hasMany(ProductOrder::className(), ['id_order' => 'id']) | |||||
->orderBy(['product.order' => SORT_ASC]) | ->orderBy(['product.order' => SORT_ASC]) | ||||
->joinWith('product'); | ->joinWith('product'); | ||||
} | } | ||||
public function getPointSale() | public function getPointSale() | ||||
{ | { | ||||
return $this->hasOne(PointSaleModel::className(), ['id' => 'id_point_sale']) | |||||
return $this->hasOne(PointSale::className(), ['id' => 'id_point_sale']) | |||||
->with('userPointSale'); | ->with('userPointSale'); | ||||
} | } | ||||
public function getCreditHistory() | public function getCreditHistory() | ||||
{ | { | ||||
return $this->hasMany(CreditHistoryModel::class, ['id_order' => 'id']); | |||||
return $this->hasMany(CreditHistory::class, ['id_order' => 'id']); | |||||
} | } | ||||
public function getSubscription() | public function getSubscription() | ||||
{ | { | ||||
return $this->hasOne(SubscriptionModel::className(), ['id' => 'id_subscription']) | |||||
return $this->hasOne( Subscription::className(), ['id' => 'id_subscription']) | |||||
->with('productSubscription'); | ->with('productSubscription'); | ||||
} | } | ||||
public function getInvoice() | public function getInvoice() | ||||
{ | { | ||||
return $this->hasOne(InvoiceModel::className(), ['id' => 'id_invoice']); | |||||
return $this->hasOne(Invoice::className(), ['id' => 'id_invoice']); | |||||
} | } | ||||
public function getQuotation() | public function getQuotation() | ||||
{ | { | ||||
return $this->hasOne(QuotationModel::className(), ['id' => 'id_quotation']); | |||||
return $this->hasOne(Quotation::className(), ['id' => 'id_quotation']); | |||||
} | } | ||||
public function getDeliveryNote() | public function getDeliveryNote() | ||||
{ | { | ||||
return $this->hasOne(DeliveryNoteModel::className(), ['id' => 'id_delivery_note']); | |||||
return $this->hasOne(DeliveryNote::className(), ['id' => 'id_delivery_note']); | |||||
} | } | ||||
/** | /** | ||||
* Initialise le montant total, le montant déjà payé et le poids de la | * Initialise le montant total, le montant déjà payé et le poids de la | ||||
* commande. | * commande. | ||||
*/ | */ | ||||
public function init($taxCalculationMethod = DocumentModel::TAX_CALCULATION_METHOD_DEFAULT) | |||||
public function init($taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT) | |||||
{ | { | ||||
$this->initAmount($taxCalculationMethod); | $this->initAmount($taxCalculationMethod); | ||||
$this->initPaidAmount(); | $this->initPaidAmount(); | ||||
* Initialise le montant de la commande. | * Initialise le montant de la commande. | ||||
* | * | ||||
*/ | */ | ||||
public function initAmount($taxCalculationMethod = DocumentModel::TAX_CALCULATION_METHOD_DEFAULT) | |||||
public function initAmount($taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT) | |||||
{ | { | ||||
$this->amount = 0; | $this->amount = 0; | ||||
$this->amount_with_tax = 0; | $this->amount_with_tax = 0; | ||||
if (isset($this->creditHistory)) { | if (isset($this->creditHistory)) { | ||||
$history = $this->creditHistory; | $history = $this->creditHistory; | ||||
} else { | } else { | ||||
$history = CreditHistoryModel::find() | |||||
$history = CreditHistory::find() | |||||
->where(['id_order' => $this->id]) | ->where(['id_order' => $this->id]) | ||||
->all(); | ->all(); | ||||
} | } | ||||
if (count($history)) { | if (count($history)) { | ||||
foreach ($history as $ch) { | foreach ($history as $ch) { | ||||
if ($ch->type == CreditHistoryModel::TYPE_PAYMENT) { | |||||
if ($ch->type == CreditHistory::TYPE_PAYMENT) { | |||||
$this->paid_amount += $ch->amount; | $this->paid_amount += $ch->amount; | ||||
} elseif ($ch->type == CreditHistoryModel::TYPE_REFUND) { | |||||
} elseif ($ch->type == CreditHistory::TYPE_REFUND) { | |||||
$this->paid_amount -= $ch->amount; | $this->paid_amount -= $ch->amount; | ||||
} | } | ||||
} | } | ||||
public function delete($force = false) | public function delete($force = false) | ||||
{ | { | ||||
// remboursement si l'utilisateur a payé pour cette commande | // remboursement si l'utilisateur a payé pour cette commande | ||||
$amountPaid = $this->getAmount(OrderModel::AMOUNT_PAID); | |||||
$amountPaid = $this->getAmount(Order::AMOUNT_PAID); | |||||
if ($amountPaid > 0.01) { | if ($amountPaid > 0.01) { | ||||
$this->saveCreditHistory( | $this->saveCreditHistory( | ||||
CreditHistoryModel::TYPE_REFUND, | |||||
CreditHistory::TYPE_REFUND, | |||||
$amountPaid, | $amountPaid, | ||||
GlobalParam::getCurrentProducerId(), | GlobalParam::getCurrentProducerId(), | ||||
$this->id_user, | $this->id_user, | ||||
UserModel::getCurrentId() | |||||
User::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
'option_behavior_cancel_order' | 'option_behavior_cancel_order' | ||||
) == Producer::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]); | |||||
ProductOrder::deleteAll(['id_order' => $this->id]); | |||||
return parent::delete(); | return parent::delete(); | ||||
} // status 'delete' | } // status 'delete' | ||||
elseif (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS) { | elseif (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS) { | ||||
public function addOrderStatusHistory($newStatus, $origin) | public function addOrderStatusHistory($newStatus, $origin) | ||||
{ | { | ||||
$orderStatusHistory = new OrderStatusHistory(); | $orderStatusHistory = new OrderStatusHistory(); | ||||
$orderStatusHistory->id_user = UserModel::getCurrentId(); | |||||
$orderStatusHistory->id_user = User::getCurrentId(); | |||||
$orderStatusHistory->id_order = $this->id; | $orderStatusHistory->id_order = $this->id; | ||||
$orderStatusHistory->status = $newStatus; | $orderStatusHistory->status = $newStatus; | ||||
$orderStatusHistory->origin = $origin; | $orderStatusHistory->origin = $origin; | ||||
*/ | */ | ||||
public function getDataJson() | public function getDataJson() | ||||
{ | { | ||||
$order = OrderModel::searchOne(['order.id' => $this->id]); | |||||
$order = Order::searchOne(['order.id' => $this->id]); | |||||
$jsonOrder = []; | $jsonOrder = []; | ||||
if ($order) { | if ($order) { | ||||
$creditHistory->id_producer = $idProducer; | $creditHistory->id_producer = $idProducer; | ||||
$creditHistory->id_user_action = $idUserAction; | $creditHistory->id_user_action = $idUserAction; | ||||
$creditHistory->populateRelation('order', $this); | $creditHistory->populateRelation('order', $this); | ||||
$creditHistory->populateRelation('user', UserModel::find()->where(['id' => $this->id_user])->one()); | |||||
$creditHistory->populateRelation('user', User::find()->where(['id' => $this->id_user])->one()); | |||||
$creditHistoryService->save($creditHistory); | $creditHistoryService->save($creditHistory); | ||||
} | } | ||||
if ($paymentStatus == self::PAYMENT_PAID) { | if ($paymentStatus == self::PAYMENT_PAID) { | ||||
return true; | return true; | ||||
} elseif ($paymentStatus == self::PAYMENT_SURPLUS) { | } elseif ($paymentStatus == self::PAYMENT_SURPLUS) { | ||||
$type = CreditHistoryModel::TYPE_REFUND; | |||||
$type = CreditHistory::TYPE_REFUND; | |||||
$amount = $this->getAmount(self::AMOUNT_SURPLUS); | $amount = $this->getAmount(self::AMOUNT_SURPLUS); | ||||
} elseif ($paymentStatus == self::PAYMENT_UNPAID) { | } elseif ($paymentStatus == self::PAYMENT_UNPAID) { | ||||
$type = CreditHistoryModel::TYPE_PAYMENT; | |||||
$type = CreditHistory::TYPE_PAYMENT; | |||||
$amount = $this->getAmount(self::AMOUNT_REMAINING); | $amount = $this->getAmount(self::AMOUNT_REMAINING); | ||||
} | } | ||||
$amount, | $amount, | ||||
GlobalParam::getCurrentProducerId(), | GlobalParam::getCurrentProducerId(), | ||||
$this->id_user, | $this->id_user, | ||||
UserModel::getCurrentId() | |||||
User::getCurrentId() | |||||
); | ); | ||||
} | } | ||||
} | } | ||||
public function setTillerSynchronization() | public function setTillerSynchronization() | ||||
{ | { | ||||
$order = OrderModel::searchOne(['id' => $this->id]); | |||||
$order = Order::searchOne(['id' => $this->id]); | |||||
$paymentStatus = $order->getPaymentStatus(); | $paymentStatus = $order->getPaymentStatus(); | ||||
public function getCartSummary($htmlFormat = true) | public function getCartSummary($htmlFormat = true) | ||||
{ | { | ||||
if (!isset($this->productOrder)) { | if (!isset($this->productOrder)) { | ||||
$this->productOrder = ProductOrderModel::find()->where(['id_order' => $this->id])->all(); | |||||
$this->productOrder = ProductOrder::find()->where(['id_order' => $this->id])->all(); | |||||
} | } | ||||
$html = ''; | $html = ''; | ||||
$i = 0; | $i = 0; | ||||
foreach ($this->productOrder as $p) { | foreach ($this->productOrder as $p) { | ||||
if (isset($p->product)) { | if (isset($p->product)) { | ||||
$html .= Html::encode($p->product->name) . ' (' . $p->quantity . ' ' . ProductModel::strUnit( | |||||
$html .= Html::encode($p->product->name) . ' (' . $p->quantity . ' ' . Product::strUnit( | |||||
$p->unit, | $p->unit, | ||||
'wording_short', | 'wording_short', | ||||
true | true | ||||
if ($creditActive) { | if ($creditActive) { | ||||
$html .= '<br />'; | $html .= '<br />'; | ||||
if ($this->paid_amount) { | if ($this->paid_amount) { | ||||
if ($this->getPaymentStatus() == OrderModel::PAYMENT_PAID) { | |||||
if ($this->getPaymentStatus() == Order::PAYMENT_PAID) { | |||||
$html .= '<span class="label label-success">Payée</span>'; | $html .= '<span class="label label-success">Payée</span>'; | ||||
} elseif ($this->getPaymentStatus() == OrderModel::PAYMENT_UNPAID) { | |||||
} elseif ($this->getPaymentStatus() == Order::PAYMENT_UNPAID) { | |||||
$html .= '<span class="label label-danger">Non payée</span><br /> | $html .= '<span class="label label-danger">Non payée</span><br /> | ||||
Reste <strong>' . $this->getAmount( | Reste <strong>' . $this->getAmount( | ||||
OrderModel::AMOUNT_REMAINING, | |||||
Order::AMOUNT_REMAINING, | |||||
true | true | ||||
) . '</strong> à payer'; | ) . '</strong> à payer'; | ||||
} elseif ($this->getPaymentStatus() == OrderModel::PAYMENT_SURPLUS) { | |||||
} elseif ($this->getPaymentStatus() == Order::PAYMENT_SURPLUS) { | |||||
$html .= '<span class="label label-success">Payée</span>'; | $html .= '<span class="label label-success">Payée</span>'; | ||||
} | } | ||||
} else { | } else { | ||||
$quantity += $po->quantity; | $quantity += $po->quantity; | ||||
} else { | } else { | ||||
if (isset($po->product) && $po->product->weight > 0) { | if (isset($po->product) && $po->product->weight > 0) { | ||||
$quantity += ($po->quantity * ProductModel::$unitsArray[$po->unit]['coefficient']) / $po->product->weight; | |||||
$quantity += ($po->quantity * Product::$unitsArray[$po->unit]['coefficient']) / $po->product->weight; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
if (is_array($orders)) { | if (is_array($orders)) { | ||||
if (count($orders)) { | if (count($orders)) { | ||||
foreach ($orders as $order) { | foreach ($orders as $order) { | ||||
if (is_a($order, 'common\logic\Order\Order\OrderModel')) { | |||||
if (is_a($order, 'common\logic\Order\Order\Order')) { | |||||
$order->init(); | $order->init(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
$order = $orders; | $order = $orders; | ||||
if (is_a($order, 'common\logic\Order\Order\OrderModel')) { | |||||
if (is_a($order, 'common\logic\Order\Order\Order')) { | |||||
return $order->init(); | return $order->init(); | ||||
} // count | } // count | ||||
else { | else { | ||||
$producer = Producer::findOne($idProducer); | $producer = Producer::findOne($idProducer); | ||||
if (!$this->reference && $producer->option_order_reference_type == Producer::ORDER_REFERENCE_TYPE_YEARLY) { | if (!$this->reference && $producer->option_order_reference_type == Producer::ORDER_REFERENCE_TYPE_YEARLY) { | ||||
$lastOrder = OrderModel::find()->innerJoinWith('distribution', true) | |||||
$lastOrder = Order::find()->innerJoinWith('distribution', true) | |||||
->where(['>=', 'distribution.date', date('Y') . '-01-01']) | ->where(['>=', 'distribution.date', date('Y') . '-01-01']) | ||||
->andWhere([ | ->andWhere([ | ||||
'distribution.id_producer' => $producer->id | 'distribution.id_producer' => $producer->id |
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return OrderModel::class; | |||||
return Order::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
class OrderFactory extends BaseService implements FactoryInterface | class OrderFactory extends BaseService implements FactoryInterface | ||||
{ | { | ||||
public function create(): OrderModel | |||||
public function create(): Order | |||||
{ | { | ||||
$order = new OrderModel(); | |||||
$order = new Order(); | |||||
return $order; | return $order; | ||||
} | } |
namespace common\logic\Order\Order; | namespace common\logic\Order\Order; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Distribution\Distribution\Distribution; | |||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
class OrderRepository extends BaseService implements RepositoryInterface | class OrderRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
public function getByDistribution(Distribution $distribution, string $conditionAppend = '') | |||||
{ | |||||
return Order::searchAll([ | |||||
'distribution.date' => $distribution->date, | |||||
'distribution.id_producer' => $distribution->id_producer | |||||
], | |||||
[ | |||||
'conditions' => 'date_delete IS NULL ' . $conditionAppend | |||||
]); | |||||
} | |||||
} | } |
namespace common\logic\Order\Order ; | namespace common\logic\Order\Order ; | ||||
class OrderSearch extends OrderModel | |||||
class OrderSearch extends Order | |||||
{ | { | ||||
public function search($params) | public function search($params) | ||||
{ | { | ||||
$paramsSearch['id_user'] = $params['id_user']; | $paramsSearch['id_user'] = $params['id_user']; | ||||
} | } | ||||
$query = OrderModel::searchQuery($paramsSearch, [ | |||||
$query = Order::searchQuery($paramsSearch, [ | |||||
'orderby' => 'distribution.date DESC' | 'orderby' => 'distribution.date DESC' | ||||
]); | ]); | ||||
* @property integer $id_order_status | * @property integer $id_order_status | ||||
* @property string $date | * @property string $date | ||||
*/ | */ | ||||
class OrderStatusHistoryModel extends ActiveRecordCommon | |||||
class OrderStatusHistory extends ActiveRecordCommon | |||||
{ | { | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
public function getOrder() | public function getOrder() | ||||
{ | { | ||||
return $this->hasOne(UserModel::className(), ['id' => 'id_order']); | |||||
return $this->hasOne( User::className(), ['id' => 'id_order']); | |||||
} | } | ||||
public function getUser() | public function getUser() | ||||
{ | { | ||||
return $this->hasOne(UserModel::className(), ['id' => 'id_user']); | |||||
return $this->hasOne( User::className(), ['id' => 'id_user']); | |||||
} | } | ||||
/** | /** |
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return OrderStatusHistoryModel::class; | |||||
return OrderStatusHistory::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
class OrderStatusHistoryFactory extends BaseService implements FactoryInterface | class OrderStatusHistoryFactory extends BaseService implements FactoryInterface | ||||
{ | { | ||||
public function create(): OrderStatusHistoryModel | |||||
public function create(): OrderStatusHistory | |||||
{ | { | ||||
$orderStatusHistory = new OrderStatusHistoryModel(); | |||||
$orderStatusHistory = new OrderStatusHistory(); | |||||
return $orderStatusHistory; | return $orderStatusHistory; | ||||
} | } |
* @property double $quantity | * @property double $quantity | ||||
* @property string $unit | * @property string $unit | ||||
*/ | */ | ||||
class ProductOrderModel extends ActiveRecordCommon | |||||
class ProductOrder extends ActiveRecordCommon | |||||
{ | { | ||||
/** | /** | ||||
public function getProduct() | public function getProduct() | ||||
{ | { | ||||
return $this->hasOne(ProductModel::className(), ['id' => 'id_product']); | |||||
return $this->hasOne( Product::className(), ['id' => 'id_product']); | |||||
} | } | ||||
public function getTaxRate() | public function getTaxRate() | ||||
return Price::getPriceWithTax($this->price, $this->taxRate->value); | return Price::getPriceWithTax($this->price, $this->taxRate->value); | ||||
} | } | ||||
public function getPriceByTypeTotal($typeTotal = OrderModel::AMOUNT_TOTAL) | |||||
public function getPriceByTypeTotal($typeTotal = Order::AMOUNT_TOTAL) | |||||
{ | { | ||||
if($typeTotal == OrderModel::INVOICE_AMOUNT_TOTAL && $this->invoice_price) { | |||||
if($typeTotal == Order::INVOICE_AMOUNT_TOTAL && $this->invoice_price) { | |||||
return $this->invoice_price; | return $this->invoice_price; | ||||
} | } | ||||
{ | { | ||||
public function getEntityFqcn(): string | public function getEntityFqcn(): string | ||||
{ | { | ||||
return ProductOrderModel::class; | |||||
return ProductOrder::class; | |||||
} | } | ||||
public function getServices(): array | public function getServices(): array |
class ProductOrderFactory extends BaseService implements FactoryInterface | class ProductOrderFactory extends BaseService implements FactoryInterface | ||||
{ | { | ||||
public function create(): ProductOrderModel | |||||
public function create(): ProductOrder | |||||
{ | { | ||||
$productOrder = new ProductOrderModel(); | |||||
$productOrder = new ProductOrder(); | |||||
return $productOrder; | return $productOrder; | ||||
} | } |