浏览代码

Suppression code ancienne page de commande

refactoring
父节点
当前提交
518527ae2c
共有 1 个文件被更改,包括 0 次插入197 次删除
  1. +0
    -197
      producer/controllers/OrderController.php

+ 0
- 197
producer/controllers/OrderController.php 查看文件

@@ -79,168 +79,6 @@ class OrderController extends ProducerBaseController
return $this->render('order', $params) ;
}

/**
* Retourne au format JSON toutes les informations relatives à une
* production donnée.
*
* @param integer $idDistribution
* @return mixed
*/
public function actionInfosDistribution($idDistribution)
{
$distribution = Distribution::searchOne([
'id' => $idDistribution
]);

if ($distribution) {
$arr = [];

$productsArray = ProductDistribution::searchByDistribution($distribution->id) ;
$data['products'] = $productsArray;

$pointSaleArray = PointSale::find()
->joinWith(['pointSaleDistribution' => function($q) use ($distribution) {
$q->where(['id_distribution' => $distribution->id]);
}])
->where([
'id_producer' => $distribution->id_producer,
])
->all();

$data['points_sale'] = [];
foreach ($pointSaleArray as $pointSale) {
if (isset($pointSale->pointSaleDistribution) &&
isset($pointSale->pointSaleDistribution[0])) {
$data['points_sale'][$pointSale->id] = $pointSale->pointSaleDistribution[0]->delivery;
} else {
$data['points_sale'][$pointSale->id] = false;
}
}

return json_encode($data);
}

return json_encode([]);
}

/**
* Initialise le formulaire de création/modification de commande.
*
* @param Order $order
* @return array
*/
public function initForm($order = null) {

// Producteurs
$producersArray = Yii::$app->user->identity->getBookmarkedProducers();
$idProducer = $this->getProducer()->id;

// Producteur
$producer = Producer::findOne($idProducer);

// Points de vente
$pointsSaleArray = PointSale::find()
->with('userPointSale')
->where(['id_producer' => $idProducer])
->andWhere('restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0)')
->params([':id_user' => User::getCurrentId()])
->all();

// jours de production
$deadline = 20;
$date = date('Y-m-d');
if (isset($producer)) {
if($producer->order_deadline) {
$deadline = $producer->order_deadline;
}
if (date('H') >= $deadline) {
$date = date('Y-m-d', strtotime(date('Y-m-d')) + ($producer->order_delay) * (24 * 60 * 60));
} else {
$date = date('Y-m-d', strtotime(date('Y-m-d')) + ($producer->order_delay - 1) * (24 * 60 * 60));
}
}

$distributionDays = Distribution::find()
->where(['active' => 1])
->andWhere('date > :date')
->andWhere(['id_producer' => $idProducer])
->addParams([':date' => $date])
->all();

$distributionDaysArray = array('' => '--');
foreach ($distributionDays as $distribution) {
$distributionDaysArray[$distribution->id] = date('d/m/Y', strtotime($distribution->date));
}
// produits
$products = Product::find()
->leftJoin('product_distribution', 'product.id = product_distribution.id_product')
->where(['product.active' => 1, 'id_producer' => $idProducer])
->orderBy('product.order ASC')->all();
$productsArray = [] ;
foreach ($products as $p)
$productsArray[] = $p;
// produits selec
$posts = Yii::$app->request->post();
$selectedProducts = [];
if (isset($posts['Product'])) {
foreach ($posts['Product'] as $key => $quantity) {
$key = (int) str_replace('product_', '', $key);
$product = Product::find()->where(['id' => $key])->one();
if ($product && $quantity)
$selectedProducts[$product->id] = (int) $quantity;
}
}
elseif (!is_null($order)) {
$productOrderArray = ProductOrder::searchAll([
'id_order' => $order->id
]) ;
foreach ($productOrderArray as $productOrder) {
$selectedProducts[$productOrder->id_product] = (int) $productOrder->quantity;
}
}

$availableProducts = [] ;
$distribution = null;
if (!is_null($order) && $order->id_distribution) {
$availableProducts = ProductDistribution::searchByDistribution($order->id_distribution);
$distribution = Distribution::find()->where(['id' => $order->id_distribution])->one();
}

$orders = Order::searchAll([
'id_user' => User::getCurrentId()
]) ;

if ($idProducer) {
$userProducer = UserProducer::searchOne([
'id_producer' => $idProducer,
'id_user' => User::getCurrentId()
]) ;

$credit = $userProducer->credit;
} else {
$credit = 0;
}
return [
'pointsSaleArray' => $pointsSaleArray,
'distributionDaysArray' => $distributionDaysArray,
'productsArray' => $productsArray,
'selectedProducts' => $selectedProducts,
'availableProducts' => $availableProducts,
'distribution' => $distribution,
'ordersArray' => $orders,
'producersArray' => $producersArray,
'idProducer' => $idProducer,
'producer' => $producer,
'credit' => $credit
];
}
/**
* Affiche l'historique des commandes de l'utilisateur
@@ -249,7 +87,6 @@ class OrderController extends ProducerBaseController
*/
public function actionHistory()
{
$dataProviderOrders = new ActiveDataProvider([
'query' => Order::find()
->with('productOrder', 'pointSale', 'creditHistory')
@@ -333,36 +170,6 @@ class OrderController extends ProducerBaseController
return ['status' => 'success'] ;
}

/**
* Modifie une commande.
*
* @param integer $id
* @return mixed
* @throws UserException
*/
public function actionUpdate($id)
{
$order = Order::searchOne([
'id' => $id
]) ;

if ($order->getState() != Order::STATE_OPEN) {
throw new UserException('Cette commande n\'est pas modifiable.');
}

$this->_verifyProducerActive($order->distribution->id_producer);

if ($order && $order->load(Yii::$app->request->post())) {
$order->date_update = date('Y-m-d H:i:s');
$this->processForm($order);
}

return $this->render('update', array_merge($this->initForm($order), [
'model' => $order,
'orderNotfound' => !$order,
]));
}

/**
* Vérifie si un producteur est actif.
*
@@ -525,10 +332,6 @@ class OrderController extends ProducerBaseController
);
}
}

// redirection
//$this->redirect(Yii::$app->urlManager->createUrl(['order/history', 'orderOk' => true]));
}
else {
if (!count($productsArray)) {

正在加载...
取消
保存