Преглед на файлове

Merge branch 'producer/feature/finitions_nouvelle_page_commande' into dev

dev
Guillaume Bourgeois преди 5 години
родител
ревизия
5c2dbd662e
променени са 8 файла, в които са добавени 109 реда и са изтрити 269 реда
  1. +3
    -2
      common/models/Order.php
  2. +24
    -0
      common/models/Producer.php
  3. +16
    -214
      producer/controllers/OrderController.php
  4. +2
    -2
      producer/views/order/history.php
  5. +3
    -0
      producer/views/order/order.php
  6. +53
    -49
      producer/web/css/screen.css
  7. +4
    -2
      producer/web/js/vuejs/order-order.js
  8. +4
    -0
      producer/web/sass/order/_order.scss

+ 3
- 2
common/models/Order.php Целия файл

@@ -562,16 +562,17 @@ class Order extends ActiveRecordCommon
*
* @param integer $idProduct
* @param array $orders
* @param boolean $ignoreCancel
*
* @return integer
*/
public static function getProductQuantity($idProduct, $orders)
public static function getProductQuantity($idProduct, $orders, $ignoreCancel = false)
{
$quantity = 0;
if (isset($orders) && is_array($orders) && count($orders)) {
foreach ($orders as $c) {
if(is_null($c->date_delete)) {
if(is_null($c->date_delete) || $ignoreCancel) {
foreach ($c->productOrder as $po) {
if ($po->id_product == $idProduct) {
$quantity += $po->quantity ;

+ 24
- 0
common/models/Producer.php Целия файл

@@ -376,6 +376,30 @@ class Producer extends ActiveRecordCommon
return false ;
}
/**
* Retourne la date la plus proche où il est possible de commander.
* Attention, cette méthode ne garantit pas qu'une distribution a été initialisée
* à cette date.
*
* @return string
*/
public function getEarliestDateOrder()
{
$deadline = 20;
$earliestDateOrder = date('Y-m-d');
if($this->order_deadline) {
$deadline = $this->order_deadline;
}
if (date('H') >= $deadline) {
$earliestDateOrder = date('Y-m-d', strtotime(date('Y-m-d')) + ($this->order_delay) * (24 * 60 * 60));
} else {
$earliestDateOrder = date('Y-m-d', strtotime(date('Y-m-d')) + ($this->order_delay - 1) * (24 * 60 * 60));
}
return $earliestDateOrder ;
}

}

+ 16
- 214
producer/controllers/OrderController.php Целия файл

@@ -63,171 +63,21 @@ class OrderController extends ProducerBaseController
];
}
public function actionOrder()
public function actionOrder($id = 0)
{
return $this->render('order') ;
}

/**
* 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
$params = [] ;
if($id) {
$order = Order::searchOne([
'id' => $id
]) ;
foreach ($productOrderArray as $productOrder) {
$selectedProducts[$productOrder->id_product] = (int) $productOrder->quantity;
if($order) {
if($order->getState() == Order::STATE_OPEN) {
$params['order'] = $order ;
}
}
}

$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
];
return $this->render('order', $params) ;
}
/**
@@ -237,7 +87,6 @@ class OrderController extends ProducerBaseController
*/
public function actionHistory()
{
$dataProviderOrders = new ActiveDataProvider([
'query' => Order::find()
->with('productOrder', 'pointSale', 'creditHistory')
@@ -321,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.
*
@@ -384,19 +203,17 @@ class OrderController extends ProducerBaseController
$productsArray[] = $product;
}
}
$producer = $this->getProducer() ;

// date
$errorDate = false;
if (isset($order->id_distribution)) {
// date de commande
$distribution = Distribution::find()->where(['id' => $order->id_distribution])->one();
if (date('H') >= 20) {
$date = date('Y-m-d', strtotime(date('Y-m-d')) + 60 * 60 * 24);
} else {
$date = date('Y-m-d');
}
$date = $this->getProducer()->getEarliestDateOrder() ;

if ($distribution->date < $date) {
if($order->getState() != Order::STATE_OPEN) {
$errorDate = true;
}
}
@@ -515,10 +332,6 @@ class OrderController extends ProducerBaseController
);
}
}

// redirection
//$this->redirect(Yii::$app->urlManager->createUrl(['order/history', 'orderOk' => true]));
}
else {
if (!count($productsArray)) {
@@ -615,18 +428,7 @@ class OrderController extends ProducerBaseController
] ;
// Distributions
$deadline = 20;
$dateMini = date('Y-m-d');
if (isset($producer)) {
if($producer->order_deadline) {
$deadline = $producer->order_deadline;
}
if (date('H') >= $deadline) {
$dateMini = date('Y-m-d', strtotime(date('Y-m-d')) + ($producer->order_delay) * (24 * 60 * 60));
} else {
$dateMini = date('Y-m-d', strtotime(date('Y-m-d')) + ($producer->order_delay - 1) * (24 * 60 * 60));
}
}
$dateMini = $producer->getEarliestDateOrder() ;
$distributionsArray = Distribution::searchAll([
'active' => 1
@@ -734,7 +536,7 @@ class OrderController extends ProducerBaseController
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder ;
if($orderUser) {
$quantityOrderUser = Order::getProductQuantity($product['id'], [$orderUser]) ;
$quantityOrderUser = Order::getProductQuantity($product['id'], [$orderUser], true) ;
$product['quantity_ordered'] = $quantityOrder ;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser ;
$product['quantity_form'] = $quantityOrderUser ;

+ 2
- 2
producer/views/order/history.php Целия файл

@@ -102,7 +102,7 @@ GridView::widget([
if($c->date_delete) {
$html .= '<span class="label label-danger">Annulée</span><br />' ;
if($c->getState() == Order::STATE_OPEN) {
$html .= '<a href="'.Yii::$app->urlManager->createUrl(['order/update','id'=>$c->id]).'" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a>' ;
$html .= '<a href="'.Yii::$app->urlManager->createUrl(['order/order','id'=>$c->id]).'" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a>' ;
}
}
else {
@@ -114,7 +114,7 @@ GridView::widget([
}
elseif($c->getState() == Order::STATE_OPEN) {
$html .= '<div class="btn-group">
<a href="'.Yii::$app->urlManager->createUrl(['order/update','id'=>$c->id]).'" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a>
<a href="'.Yii::$app->urlManager->createUrl(['order/order','id'=>$c->id]).'" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>

+ 3
- 0
producer/views/order/order.php Целия файл

@@ -43,6 +43,9 @@ $this->setTitle('Commander') ;
?>

<div id="app-order-order" :class="{'loaded': !loadingInit}">
<?php if(isset($order)): ?>
<span id="order-distribution-date"><?= $order->distribution->date; ?></span>
<?php endif; ?>
<div v-if="orderSuccess" id="order-success">
<div class="alert alert-success">
<span class="glyphicon glyphicon-ok glyphicon-big"></span>

+ 53
- 49
producer/web/css/screen.css Целия файл

@@ -1179,34 +1179,38 @@ termes.
display: block;
}
/* line 11, ../sass/order/_order.scss */
.order-order #app-order-order #order-distribution-date {
display: none;
}
/* line 15, ../sass/order/_order.scss */
.order-order #app-order-order .slide-enter-active {
transition: all .2s ease;
}
/* line 15, ../sass/order/_order.scss */
/* line 19, ../sass/order/_order.scss */
.order-order #app-order-order .slide-leave-active {
transition: all 0s ease;
}
/* line 19, ../sass/order/_order.scss */
/* line 23, ../sass/order/_order.scss */
.order-order #app-order-order .slide-enter, .order-order #app-order-order .slide-leave-to {
transform: translateX(10px);
opacity: 0;
}
/* line 24, ../sass/order/_order.scss */
/* line 28, ../sass/order/_order.scss */
.order-order #app-order-order #steps {
margin-bottom: 20px;
}
/* line 26, ../sass/order/_order.scss */
/* line 30, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul {
margin-top: 30px;
}
/* line 28, ../sass/order/_order.scss */
/* line 32, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li {
text-align: center;
padding-right: 8px;
padding-left: 8px;
position: relative;
}
/* line 34, ../sass/order/_order.scss */
/* line 38, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li .info-step {
position: absolute;
top: -30px;
@@ -1214,26 +1218,26 @@ termes.
width: 100%;
text-transform: normal;
}
/* line 42, ../sass/order/_order.scss */
/* line 46, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li .glyphicon-chevron-right, .order-order #app-order-order #steps ul li.active .glyphicon-chevron-right {
float: right;
color: gray;
position: relative;
top: 10px;
}
/* line 50, ../sass/order/_order.scss */
/* line 54, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li#step-date {
padding-left: 0px;
}
/* line 54, ../sass/order/_order.scss */
/* line 58, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li#step-payment {
padding-right: 0px;
}
/* line 58, ../sass/order/_order.scss */
/* line 62, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li#step-payment .btn::after, .order-order #app-order-order #steps ul li#step-date .btn::before {
display: none;
}
/* line 63, ../sass/order/_order.scss */
/* line 67, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li .btn {
color: #333;
text-transform: uppercase;
@@ -1247,180 +1251,180 @@ termes.
border: 0px none;
text-transform: uppercase;
}
/* line 74, ../sass/order/_order.scss */
/* line 78, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li .btn .button-content {
position: relative;
left: 8px;
}
/* line 79, ../sass/order/_order.scss */
/* line 83, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li .btn.btn-primary {
background-color: #BB8757;
}
/* line 83, ../sass/order/_order.scss */
/* line 87, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li .btn::after, .order-order #app-order-order #steps ul li .btn::before {
content: "";
position: absolute;
top: -1px;
}
/* line 89, ../sass/order/_order.scss */
/* line 93, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li .btn::after {
right: -34px;
border: 17px solid transparent;
border-left: 17px solid #e0e0e0;
background-color: transparent;
}
/* line 96, ../sass/order/_order.scss */
/* line 100, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li .btn::before {
left: 0px;
border: 17px solid transparent;
border-left: 17px solid white;
background-color: transparent;
}
/* line 103, ../sass/order/_order.scss */
/* line 107, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li .btn.btn-primary::after {
border-left: 17px solid #BB8757;
}
/* line 117, ../sass/order/_order.scss */
/* line 121, ../sass/order/_order.scss */
.order-order #app-order-order #steps ul li .btn-primary {
color: white;
}
/* line 125, ../sass/order/_order.scss */
/* line 129, ../sass/order/_order.scss */
.order-order #app-order-order #legend #order-date-color,
.order-order #app-order-order #legend #distribution-date-color {
width: 13px;
height: 13px;
display: inline-block;
}
/* line 132, ../sass/order/_order.scss */
/* line 136, ../sass/order/_order.scss */
.order-order #app-order-order #legend #order-date-color {
background-color: #018548;
}
/* line 135, ../sass/order/_order.scss */
/* line 139, ../sass/order/_order.scss */
.order-order #app-order-order #legend #distribution-date-color {
background-color: #00A65A;
}
/* line 140, ../sass/order/_order.scss */
/* line 144, ../sass/order/_order.scss */
.order-order #app-order-order #calendar {
margin-bottom: 15px;
}
/* line 142, ../sass/order/_order.scss */
/* line 146, ../sass/order/_order.scss */
.order-order #app-order-order #calendar .c-header .c-title-layout .c-title-popover .c-title-anchor .c-title[data-v-2083cb72] {
font-size: 2rem;
}
/* line 145, ../sass/order/_order.scss */
/* line 149, ../sass/order/_order.scss */
.order-order #app-order-order #calendar .c-day-background {
padding: 20px;
}
/* line 150, ../sass/order/_order.scss */
/* line 154, ../sass/order/_order.scss */
.order-order #app-order-order #calendar .c-day:hover .c-day-background {
background-color: #F39C12 !important;
}
/* line 155, ../sass/order/_order.scss */
/* line 159, ../sass/order/_order.scss */
.order-order #app-order-order #calendar .c-day-popover-content {
font-size: 1.3rem;
}
/* line 160, ../sass/order/_order.scss */
/* line 164, ../sass/order/_order.scss */
.order-order #app-order-order .block-actions {
text-align: right;
margin-top: 20px;
}
/* line 167, ../sass/order/_order.scss */
/* line 171, ../sass/order/_order.scss */
.order-order #app-order-order table#points-sale td.name .the-name {
text-transform: uppercase;
font-family: "myriadpro-regular";
color: black;
font-size: 16px;
}
/* line 175, ../sass/order/_order.scss */
/* line 179, ../sass/order/_order.scss */
.order-order #app-order-order table#points-sale td.actions {
width: 150px;
}
/* line 177, ../sass/order/_order.scss */
/* line 181, ../sass/order/_order.scss */
.order-order #app-order-order table#points-sale td.actions button {
width: 100%;
}
/* line 183, ../sass/order/_order.scss */
/* line 187, ../sass/order/_order.scss */
.order-order #app-order-order table#points-sale tr.selected td {
background-color: #F8F1DD;
}
/* line 191, ../sass/order/_order.scss */
/* line 195, ../sass/order/_order.scss */
.order-order #app-order-order table#products td.name .name {
text-transform: uppercase;
font-family: "myriadpro-regular";
color: black;
font-size: 16px;
}
/* line 197, ../sass/order/_order.scss */
/* line 201, ../sass/order/_order.scss */
.order-order #app-order-order table#products td.name .other {
font-size: 14px;
color: #333;
}
/* line 201, ../sass/order/_order.scss */
/* line 205, ../sass/order/_order.scss */
.order-order #app-order-order table#products td.name .recipe {
color: gray;
}
/* line 205, ../sass/order/_order.scss */
/* line 209, ../sass/order/_order.scss */
.order-order #app-order-order table#products .price-unit, .order-order #app-order-order table#products .price-total {
width: 100px;
text-align: center;
}
/* line 209, ../sass/order/_order.scss */
/* line 213, ../sass/order/_order.scss */
.order-order #app-order-order table#products .td-quantity {
width: 150px;
}
/* line 211, ../sass/order/_order.scss */
/* line 215, ../sass/order/_order.scss */
.order-order #app-order-order table#products .td-quantity input.quantity {
text-align: center;
}
/* line 217, ../sass/order/_order.scss */
/* line 221, ../sass/order/_order.scss */
.order-order #app-order-order table#products tr.total .price-total {
font-size: 23px;
}
/* line 224, ../sass/order/_order.scss */
/* line 228, ../sass/order/_order.scss */
.order-order #app-order-order #content-step-payment .credit {
margin-top: 20px;
}
/* line 227, ../sass/order/_order.scss */
/* line 231, ../sass/order/_order.scss */
.order-order #app-order-order #content-step-payment .credit .info {
margin-left: 20px;
color: gray;
}
/* line 234, ../sass/order/_order.scss */
/* line 238, ../sass/order/_order.scss */
.order-order #app-order-order #infos {
margin-top: 30px;
}
/* line 236, ../sass/order/_order.scss */
/* line 240, ../sass/order/_order.scss */
.order-order #app-order-order #infos .panel-body {
padding-top: 0px;
white-space: pre-line;
}
/* line 244, ../sass/order/_order.scss */
/* line 248, ../sass/order/_order.scss */
.order-order #app-order-order #order-success .alert.alert-success .glyphicon-big {
background-color: #00A65A;
}
/* line 250, ../sass/order/_order.scss */
/* line 254, ../sass/order/_order.scss */
.order-order #app-order-order #order-success .alert.alert-info .glyphicon-big {
background-color: #0097BC;
padding: 55px 30px;
}
/* line 256, ../sass/order/_order.scss */
/* line 260, ../sass/order/_order.scss */
.order-order #app-order-order #order-success .alert {
padding: 0px;
}
/* line 258, ../sass/order/_order.scss */
/* line 262, ../sass/order/_order.scss */
.order-order #app-order-order #order-success .alert .glyphicon-big {
font-size: 90px;
color: white;
padding: 30px;
float: left;
}
/* line 265, ../sass/order/_order.scss */
/* line 269, ../sass/order/_order.scss */
.order-order #app-order-order #order-success .alert div.content {
color: #333;
padding: 20px;
margin-left: 151px;
}
/* line 270, ../sass/order/_order.scss */
/* line 274, ../sass/order/_order.scss */
.order-order #app-order-order #order-success .alert div.content h3 {
font-family: "myriadpro-light";
text-transform: uppercase;
@@ -1433,7 +1437,7 @@ termes.
padding-left: 0px;
line-height: 35px;
}
/* line 283, ../sass/order/_order.scss */
/* line 287, ../sass/order/_order.scss */
.order-order #app-order-order #order-success .alert div.content .locality {
color: gray;
}

+ 4
- 2
producer/web/js/vuejs/order-order.js Целия файл

@@ -56,12 +56,14 @@ var app = new Vue({
},
},
mounted: function() {
if($('#distribution-date').size()) {
this.date = new Date($('#distribution-date').html()) ;
if($('#order-distribution-date').size()) {
this.date = new Date($('#order-distribution-date').html()) ;
this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
+ ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
+ this.date.getFullYear() ;
this.changeStep('point-sale') ;
}
this.init() ;
this.loadingInit = false ;
},

+ 4
- 0
producer/web/sass/order/_order.scss Целия файл

@@ -8,6 +8,10 @@
display: block ;
}
#order-distribution-date {
display: none ;
}
.slide-enter-active {
transition: all .2s ease;
}

Loading…
Отказ
Запис