foreach ($arrayProducers as $producer) { | foreach ($arrayProducers as $producer) { | ||||
$countOrders = 0; | $countOrders = 0; | ||||
$mailOrdersSend = false; | $mailOrdersSend = false; | ||||
$distribution = $distributionManager->findOneDistribution($producer, $date, true); | |||||
$distribution = $distributionManager | |||||
->findOneDistribution($date, true); | |||||
if ($distribution) { | if ($distribution) { | ||||
if ($hour == $producer->order_deadline || strlen($forceDate)) { | if ($hour == $producer->order_deadline || strlen($forceDate)) { |
use common\logic\Order\Order\Model\Order; | use common\logic\Order\Order\Model\Order; | ||||
use common\logic\PointSale\PointSale\Model\PointSale; | use common\logic\PointSale\PointSale\Model\PointSale; | ||||
use common\logic\Product\Product\Model\Product; | use common\logic\Product\Product\Model\Product; | ||||
use common\logic\User\User\Model\User; | |||||
use common\logic\User\UserProducer\Model\UserProducer; | use common\logic\User\UserProducer\Model\UserProducer; | ||||
use DateTime; | use DateTime; | ||||
use kartik\mpdf\Pdf; | use kartik\mpdf\Pdf; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use yii\web\User; | |||||
class DistributionController extends BackendController | class DistributionController extends BackendController | ||||
{ | { | ||||
$weight = 0; | $weight = 0; | ||||
if ($ordersArray) { | if ($ordersArray) { | ||||
foreach ($ordersArray as $order) { | foreach ($ordersArray as $order) { | ||||
$orderManager->initOrder($order); | |||||
if (is_null($order->date_delete)) { | if (is_null($order->date_delete)) { | ||||
$revenues += $orderManager->getOrderAmountWithTax($order); | $revenues += $orderManager->getOrderAmountWithTax($order); | ||||
$weight += $order->weight; | $weight += $order->weight; | ||||
'id' => (int)$order->id_delivery_note | 'id' => (int)$order->id_delivery_note | ||||
]); | ]); | ||||
if ($deliveryNote && $deliveryNote->isStatusDraft()) { | |||||
if ($deliveryNote && $deliveryNoteManager->isStatusDraft($deliveryNote)) { | |||||
$deliveryNoteManager->changeStatus($deliveryNote, Document::STATUS_VALID); | $deliveryNoteManager->changeStatus($deliveryNote, Document::STATUS_VALID); | ||||
$deliveryNoteManager->saveUpdate($deliveryNote); | $deliveryNoteManager->saveUpdate($deliveryNote); | ||||
} | } | ||||
} | } | ||||
// on regénére le document si c'est un brouillon | // on regénére le document si c'est un brouillon | ||||
if ($deliveryNote && $deliveryNote->isStatusDraft()) { | |||||
if ($deliveryNote && $deliveryNoteManager->isStatusDraft($deliveryNote)) { | |||||
$deliveryNote->delete(); | $deliveryNote->delete(); | ||||
$deliveryNote = null; | $deliveryNote = null; | ||||
} | } | ||||
$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->setPassword(Password::generate()); | |||||
$user->generateAuthKey(); | |||||
$userManager->setPassword($user, Password::generate()); | |||||
$userManager->generateAuthKey($user); | |||||
$user->email = ''; | $user->email = ''; | ||||
if (!strlen($user->email)) { | if (!strlen($user->email)) { | ||||
$user->username = 'inconnu@opendistrib.net'; | $user->username = 'inconnu@opendistrib.net'; | ||||
$deliveryNote->id_user = $user->id; | $deliveryNote->id_user = $user->id; | ||||
} | } | ||||
$deliveryNote->address = $user->getFullAddress(); | |||||
$deliveryNote->address = $userManager->getFullAddress($user); | |||||
$deliveryNote->save(); | $deliveryNote->save(); | ||||
} else { | } else { | ||||
// réinitialisation des order.id_delivery_note | // réinitialisation des order.id_delivery_note |
$orderManager = $this->getOrderManager(); | $orderManager = $this->getOrderManager(); | ||||
$order = $orderManager->findOneOrderById($idOrder); | $order = $orderManager->findOneOrderById($idOrder); | ||||
$orderManager->initOrder($order); | |||||
if ($order) { | if ($order) { | ||||
$orderManager->deleteOrder($order); | $orderManager->deleteOrder($order); | ||||
} | } | ||||
} | } | ||||
$order = $orderManager->findOneOrderById($order->id); | $order = $orderManager->findOneOrderById($order->id); | ||||
$orderManager->initOrder($order); | |||||
if ($order && $orderManager->isCreditAutoPayment($order)) { | if ($order && $orderManager->isCreditAutoPayment($order)) { | ||||
$orderManager->processCredit($order); | $orderManager->processCredit($order); | ||||
} | } | ||||
$order->save(); | $order->save(); | ||||
$order = Order::searchOne(['id' => $order->id]); | $order = Order::searchOne(['id' => $order->id]); | ||||
$orderManager->initOrder($order); | |||||
if ($order && $orderManager->isCreditAutoPayment($order)) { | if ($order && $orderManager->isCreditAutoPayment($order)) { | ||||
// Si changement d'user : on rembourse l'ancien user | // Si changement d'user : on rembourse l'ancien user | ||||
$amountPaid = $orderManager->getOrderAmount($order, Order::AMOUNT_PAID); | $amountPaid = $orderManager->getOrderAmount($order, Order::AMOUNT_PAID); | ||||
$this->getUserCurrent() | $this->getUserCurrent() | ||||
); | ); | ||||
$order = Order::searchOne(['id' => $order->id]); | $order = Order::searchOne(['id' => $order->id]); | ||||
$orderManager->initOrder($order); | |||||
} | } | ||||
$orderManager->processCredit($order); | $orderManager->processCredit($order); |
$producerManager = ProducerManager::getInstance(); | $producerManager = ProducerManager::getInstance(); | ||||
if ($this->validate()) { | if ($this->validate()) { | ||||
$creditHistory = new CreditHistory(); | |||||
$creditHistory->id_user = $this->id_user; | |||||
$creditHistory->id_user_action = Yii::$app->user->identity->id; | |||||
$creditHistory->id_producer = GlobalParam::getCurrentProducerId() ; | |||||
$creditHistory->type = $this->type ; | |||||
$creditHistory->comment = $this->comment ; | |||||
$creditHistory->amount = $this->amount ; | |||||
$creditHistory->mean_payment = $this->mean_payment ; | |||||
$creditHistoryManager->saveCreate($creditHistory); | |||||
$user = $userManager->findOneUserById($this->id_user); | |||||
$creditHistoryManager->createCreditHistory( | |||||
$this->type, | |||||
$this->amount, | |||||
GlobalParam::getCurrentProducer(), | |||||
$user, | |||||
Yii::$app->user->identity, | |||||
$this->mean_payment | |||||
); | |||||
// 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) { |
* termes. | * termes. | ||||
*/ | */ | ||||
use common\helpers\Price; | |||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
$this->setTitle("Modifier un groupe d'utilisateur") ; | |||||
$this->addBreadcrumb(['label' => "Groupes d'utilisateurs", 'url' => ['index']]) ; | |||||
$this->setTitle("Modifier une catégorie") ; | |||||
$this->addBreadcrumb(['label' => "Catégories", 'url' => ['index']]) ; | |||||
$this->addBreadcrumb(['label' => Html::encode($model->name), 'url' => ['update', 'id' => $model->id]]) ; | $this->addBreadcrumb(['label' => Html::encode($model->name), 'url' => ['update', 'id' => $model->id]]) ; | ||||
$this->addBreadcrumb('Modifier') ; | $this->addBreadcrumb('Modifier') ; | ||||
* termes. | * termes. | ||||
*/ | */ | ||||
use common\logic\User\User\Wrapper\UserManager; | |||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use common\helpers\Price; | use common\helpers\Price; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\logic\Product\Product\Wrapper\ProductManager; | use common\logic\Product\Product\Wrapper\ProductManager; | ||||
$productManager = $this->getProductManager(); | |||||
$productManager = ProductManager::getInstance(); | |||||
$userManager = UserManager::getInstance(); | |||||
$this->setTitle('Liste des prix (' . Html::encode($model->name) . ')'); | $this->setTitle('Liste des prix (' . Html::encode($model->name) . ')'); | ||||
$this->addBreadcrumb(['label' => 'Produits', 'url' => ['index']]); | $this->addBreadcrumb(['label' => 'Produits', 'url' => ['index']]); | ||||
[ | [ | ||||
'attribute' => 'id_user', | 'attribute' => 'id_user', | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function ($model) { | |||||
'value' => function ($model) use ($userManager) { | |||||
if ($model->user) { | if ($model->user) { | ||||
return $model->user->getUsername(); | |||||
return $userManager->getUsername($model->user); | |||||
} | } | ||||
return '<span class="label label-success">Tous</span>'; | return '<span class="label label-success">Tous</span>'; | ||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'from_quantity', | 'attribute' => 'from_quantity', | ||||
'value' => function ($productPrice) { | |||||
$productManager = ProductManager::getInstance(); | |||||
'value' => function ($productPrice) use ($productManager) { | |||||
if ($productPrice->from_quantity) { | if ($productPrice->from_quantity) { | ||||
return $productPrice->from_quantity . ' ' . $productManager->strUnit($productManager->getRefUnit($productPrice->product->unit), 'wording'); | return $productPrice->from_quantity . ' ' . $productManager->strUnit($productManager->getRefUnit($productPrice->product->unit), 'wording'); | ||||
} | } |
* termes. | * termes. | ||||
*/ | */ | ||||
/* @var $this yii\web\View */ | |||||
/* @var $model app\models\Produit */ | |||||
/* @var $form yii\widgets\ActiveForm */ | |||||
use yii\helpers\Html; | |||||
$this->setTitle('Modifier un produit ('.Html::encode($model->name).')'); | $this->setTitle('Modifier un produit ('.Html::encode($model->name).')'); | ||||
$this->addBreadcrumb(['label' => 'Produits', 'url' => ['index']]); | $this->addBreadcrumb(['label' => 'Produits', 'url' => ['index']]); |
termes. | termes. | ||||
*/ | */ | ||||
use yii\helpers\Html; | |||||
?> | ?> | ||||
<div id="menu-users"> | <div id="menu-users"> |
} | } | ||||
} | } | ||||
ksort($versionsArray); | |||||
krsort($versionsArray); | |||||
return $versionsArray; | return $versionsArray; | ||||
} | } |
} | } | ||||
// isDateAvailable | // isDateAvailable | ||||
public function isDistributionDateAvailable(Producer $producer, string $date = null): bool | |||||
public function isDistributionDateAvailable(string $date = null): bool | |||||
{ | { | ||||
if($date && strlen($date)) { | if($date && strlen($date)) { | ||||
$distribution = $this->findOneDistribution($producer, $date); | |||||
$distribution = $this->findOneDistribution($date); | |||||
if($distribution && $this->distributionSolver->isDistributionAvailable($distribution)) { | if($distribution && $this->distributionSolver->isDistributionAvailable($distribution)) { | ||||
return true; | return true; | ||||
} | } |
public function updateOpendistribVersion(Producer $producer): void | public function updateOpendistribVersion(Producer $producer): void | ||||
{ | { | ||||
$versionsArray = Opendistrib::getVersions(); | $versionsArray = Opendistrib::getVersions(); | ||||
$producer->latest_version_opendistrib = $versionsArray[0]; | |||||
$producer->latest_version_opendistrib = reset($versionsArray); | |||||
$this->saveUpdate($producer); | $this->saveUpdate($producer); | ||||
} | } |
]); | ]); | ||||
} | } | ||||
public function getPriceArray(Product $product, User $user, PointSale $pointSale): array | |||||
public function getPriceArray(Product $product, User $user = null, PointSale $pointSale = null): array | |||||
{ | { | ||||
$priceArray = []; | $priceArray = []; | ||||
$userProducer = null; | $userProducer = null; |
} | } | ||||
} | } | ||||
if ($userProducer && $userProducer->product_price_percent) { | |||||
/*if ($userProducer && $userProducer->product_price_percent) { | |||||
return $product->price * (1 + $userProducer->product_price_percent / 100); | return $product->price * (1 + $userProducer->product_price_percent / 100); | ||||
} | |||||
}*/ | |||||
if ($pointSale && $pointSale->product_price_percent) { | |||||
/*if ($pointSale && $pointSale->product_price_percent) { | |||||
return $product->price * (1 + $pointSale->product_price_percent / 100); | return $product->price * (1 + $pointSale->product_price_percent / 100); | ||||
} | |||||
}*/ | |||||
return $product->price; | return $product->price; | ||||
} | } |
$creditHistoryCreateEvent->creditHistory = $creditHistory; | $creditHistoryCreateEvent->creditHistory = $creditHistory; | ||||
$creditHistory->trigger(CreditHistory::EVENT_CREATE, $creditHistoryCreateEvent); | $creditHistory->trigger(CreditHistory::EVENT_CREATE, $creditHistoryCreateEvent); | ||||
print_r($creditHistory); | |||||
die('#'.$creditHistory->id); | |||||
return $creditHistory; | return $creditHistory; | ||||
} | } | ||||
} | } |
public function actionOrder(int $id = 0, $date = '') | public function actionOrder(int $id = 0, $date = '') | ||||
{ | { | ||||
$orderManager = $this->getOrderManager(); | |||||
$distributionManager = $this->getDistributionManager(); | |||||
$params = []; | $params = []; | ||||
$producer = $this->getProducerCurrent(); | $producer = $this->getProducerCurrent(); | ||||
); | ); | ||||
} | } | ||||
$order = $this->getOrderManager()->findOneOrderById($id); | |||||
if ($order && $this->getOrderManager()->isOrderStateOpen($order)) { | |||||
$order = $orderManager->findOneOrderById($id); | |||||
if ($order && $orderManager->isOrderStateOpen($order)) { | |||||
$params['order'] = $order; | $params['order'] = $order; | ||||
} | } | ||||
if ($this->getDistributionManager()->isDistributionDateAvailable($producer, $date)) { | |||||
if ($distributionManager->isDistributionDateAvailable($date)) { | |||||
$params['date'] = $date; | $params['date'] = $date; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$availableProducts = $productManager->findProductsByDistribution($distribution); | |||||
$availableProducts = $orderManager->findProductDistributionsByDistribution($distribution); | |||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
if (isset($availableProducts[$product->id])) { | if (isset($availableProducts[$product->id])) { | ||||
$productOrder = new ProductOrder(); | $productOrder = new ProductOrder(); | ||||
$creditFunctioning = $producerManager->getPointSaleCreditFunctioning($pointSale); | $creditFunctioning = $producerManager->getPointSaleCreditFunctioning($pointSale); | ||||
$creditUser = $userManager->getCredit($user, $producer); | $creditUser = $userManager->getCredit($user, $producer); | ||||
$order = $orderManager->findOneOrderById($order->id); | $order = $orderManager->findOneOrderById($order->id); | ||||
$orderManager->initOrder($order); | |||||
$amountRemaining = $orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING); | $amountRemaining = $orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING); | ||||
if ($credit && $pointSale->credit && | if ($credit && $pointSale->credit && | ||||
public function ajaxInfosProducts( | public function ajaxInfosProducts( | ||||
Producer $producer, | Producer $producer, | ||||
Distribution $distribution, | Distribution $distribution, | ||||
PointSale $pointSale, | |||||
PointSale $pointSale = null, | |||||
User $user = null, | User $user = null, | ||||
Order $order = null | Order $order = null | ||||
) | ) | ||||
$productsArrayFilter = []; | $productsArrayFilter = []; | ||||
// filtre sur les points de vente | // filtre sur les points de vente | ||||
foreach ($productsArray as $product) { | |||||
if ($productManager->isAvailableOnPointSale($product, $pointSale)) { | |||||
$productsArrayFilter[] = $product; | |||||
if($pointSale) { | |||||
foreach ($productsArray as $product) { | |||||
if ($productManager->isAvailableOnPointSale($product, $pointSale)) { | |||||
$productsArrayFilter[] = $product; | |||||
} | |||||
} | } | ||||
} | } | ||||
$indexProduct = 0; | $indexProduct = 0; | ||||
foreach ($productsArrayFilter as $key => &$product) { | foreach ($productsArrayFilter as $key => &$product) { | ||||
$productObject = $product; | $productObject = $product; |