浏览代码

Merge branch 'dev'

prodstable
Guillaume 4 年前
父节点
当前提交
2068d7b15b
共有 11 个文件被更改,包括 318 次插入87 次删除
  1. +78
    -34
      backend/views/producer/update.php
  2. +42
    -0
      common/models/Distribution.php
  3. +63
    -20
      common/models/Producer.php
  4. +2
    -1
      common/models/Subscription.php
  5. +43
    -0
      console/migrations/m200206_102436_champs_delais_commande_par_jour_semaine.php
  6. +2
    -2
      producer/controllers/OrderController.php
  7. +7
    -5
      producer/views/layouts/main.php
  8. +51
    -9
      producer/views/order/order.php
  9. +2
    -2
      producer/web/css/screen.css
  10. +21
    -13
      producer/web/js/vuejs/order-order.js
  11. +7
    -1
      producer/web/sass/order/_order.scss

+ 78
- 34
backend/views/producer/update.php 查看文件

@@ -109,40 +109,84 @@ $this->addBreadcrumb($this->getTitle()) ;
<h3 class="panel-title">Prise de commande</h3>
</div>
<div class="panel-body">
<?= $form->field($model, 'order_delay')
->dropDownList([
1 => '1 jour',
2 => '2 jours',
3 => '3 jours',
4 => '4 jours',
5 => '5 jours',
6 => '6 jours',
7 => '7 jours',
], [])
->hint('Si <strong>1 jour</strong> est sélectionné, le client pourra commander jusqu\'à la veille de la production.<br />'
. 'Si <strong>2 jours</strong> est sélectionné, le client pourra commander jusqu\'à l\'avant-veille de la production, etc.') ; ?>
<?= $form->field($model, 'order_deadline')
->dropDownList([
24 => 'Minuit',
23 => '23h',
22 => '22h',
21 => '21h',
20 => '20h',
19 => '19h',
18 => '18h',
17 => '17h',
16 => '16h',
15 => '15h',
14 => '14h',
13 => '13h',
12 => '12h',
11 => '11h',
10 => '10h',
9 => '9h',
8 => '8h',
], [])
->hint('Heure limite jusqu\'à laquelle les clients peuvent commander pour satisfaire le délai de commande.<br />'
. 'Par exemple, si <strong>2 jours</strong> est sélectionné dans le délai de commande, le client devra commander l\'avant-veille de la production avant l\'heure précisée ici.') ; ?>

<?php

$delaysArray = [
1 => '1 jour',
2 => '2 jours',
3 => '3 jours',
4 => '4 jours',
5 => '5 jours',
6 => '6 jours',
7 => '7 jours',
] ;

$deadlinesArray = [
23 => '23h',
22 => '22h',
21 => '21h',
20 => '20h',
19 => '19h',
18 => '18h',
17 => '17h',
16 => '16h',
15 => '15h',
14 => '14h',
13 => '13h',
12 => '12h',
11 => '11h',
10 => '10h',
9 => '9h',
8 => '8h',
] ;

$daysArray = [
'monday' => 'Lundi',
'tuesday' => 'Mardi',
'wednesday' => 'Mercredi',
'thursday' => 'Jeudi',
'friday' => 'Vendredi',
'saturday' => 'Samedi',
'sunday' => 'Dimanche'
] ;
?>

<div class="row">
<div class="col-md-2">
<strong>Par défaut</strong>
</div>
<div class="col-md-5">
<?= $form->field($model, 'order_delay')
->dropDownList($delaysArray, ['prompt' => '--'])
->hint('Si <strong>1 jour</strong> est sélectionné, le client pourra commander jusqu\'à la veille de la production.<br />'
. 'Si <strong>2 jours</strong> est sélectionné, le client pourra commander jusqu\'à l\'avant-veille de la production, etc.') ; ?>
</div>
<div class="col-md-5">
<?= $form->field($model, 'order_deadline')
->dropDownList($deadlinesArray, ['prompt' => '--'])
->hint('Heure limite jusqu\'à laquelle les clients peuvent commander pour satisfaire le délai de commande.<br />'
. 'Par exemple, si <strong>2 jours</strong> est sélectionné dans le délai de commande, le client devra commander l\'avant-veille de la production avant l\'heure précisée ici.') ; ?>
</div>
</div>
<?php foreach($daysArray as $day => $labelDay): ?>
<div class="row">
<div class="col-md-2">
<strong><?= $labelDay ?></strong>
</div>
<div class="col-md-5">
<?= $form->field($model, 'order_delay_'.$day, [
'template' => '{input}',
])->dropDownList($delaysArray, ['prompt' => '--'])->label(''); ?>
</div>
<div class="col-md-5">
<?= $form->field($model, 'order_deadline_'.$day, [
'template' => '{input}',
])->dropDownList($deadlinesArray, ['prompt' => '--'])->label(''); ?>
</div>
</div>
<?php endforeach; ?>

<?= $form->field($model, 'order_infos')
->textarea(['rows' => 6])

+ 42
- 0
common/models/Distribution.php 查看文件

@@ -222,6 +222,48 @@ class Distribution extends ActiveRecordCommon
return $distributionsArray;
}

public static function filterDistributionsByDateDelay($distributionsArray)
{
$producer = GlobalParam::getCurrentProducer() ;
$dateToday = date('Y-m-d') ;

foreach($distributionsArray as $keyDistribution => $distribution) {

$dateDistribution = $distribution->date ;
$dayDistribution = strtolower(date('l', strtotime($dateDistribution))) ;
$fieldDayDistributionDelay = 'order_delay_'.$dayDistribution ;
$fieldDayDistributionDeadline = 'order_deadline_'.$dayDistribution ;

$delay = $producer->order_delay ;
$deadline = $producer->order_deadline ;

if($producer->$fieldDayDistributionDelay) {
$delay = $producer->$fieldDayDistributionDelay ;
}

if($producer->$fieldDayDistributionDeadline) {
$deadline = $producer->$fieldDayDistributionDeadline ;
}

$countDaysTodayDistribution = number_format((strtotime($dateDistribution) - strtotime($dateToday)) / (24 * 60 * 60) , 0);

if(date('H') >= $deadline) {
$countDaysTodayDistribution -- ;
}

if($countDaysTodayDistribution < $delay) {
unset($distributionsArray[$keyDistribution]) ;
}
}

$newDistributionsArray = [] ;
foreach($distributionsArray as $distribution) {
$newDistributionsArray[] = $distribution ;
}

return $newDistributionsArray ;
}

/**
* Lie un produit aux jours de distribution futurs.
*

+ 63
- 20
common/models/Producer.php 查看文件

@@ -106,8 +106,13 @@ class Producer extends ActiveRecordCommon
[['tiller_provider_token', 'tiller_restaurant_token'], 'required', 'when' => function ($model) {
return $model->tiller == true;
}],
[['order_deadline', 'order_delay', 'id_tax_rate_default', 'document_quotation_duration'], 'integer'],
['order_deadline', 'in', 'range' => [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]],
[['order_delay', 'order_deadline', 'order_delay_monday', 'order_deadline_monday', 'order_delay_tuesday', 'order_deadline_tuesday',
'order_delay_wednesday', 'order_deadline_wednesday', 'order_delay_thursday', 'order_deadline_thursday', 'order_delay_friday',
'order_deadline_friday', 'order_delay_saturday', 'order_deadline_saturday', 'order_delay_sunday', 'order_deadline_sunday',
'id_tax_rate_default', 'document_quotation_duration'], 'integer'],
[['order_deadline', 'order_deadline_monday', 'order_deadline_tuesday', 'order_deadline_wednesday',
'order_deadline_thursday', 'order_deadline_friday', 'order_deadline_saturday',
'order_deadline_sunday', ], 'in', 'range' => [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]],
['order_delay', 'in', 'range' => [1, 2, 3, 4, 5, 6, 7]],
['code', function ($attribute, $params) {
$code = $this->$attribute;
@@ -145,8 +150,22 @@ class Producer extends ActiveRecordCommon
'postcode' => 'Code postal',
'city' => 'Ville',
'code' => 'Code',
'order_deadline' => 'Heure limite de commande',
'order_delay' => 'Délai de commande',
'order_deadline' => 'Heure limite de commande',
'order_delay_monday' => 'Délai de commande (lundi)',
'order_deadline_monday' => 'Heure limite de commande (lundi)',
'order_delay_tuesday' => 'Délai de commande (mardi)',
'order_deadline_tuesday' => 'Heure limite de commande (mardi)',
'order_delay_wednesday' => 'Délai de commande (mercredi)',
'order_deadline_wednesday' => 'Heure limite de commande (mercredi)',
'order_delay_thursday' => 'Délai de commande (jeudi)',
'order_deadline_thursday' => 'Heure limite de commande (jeudi)',
'order_delay_friday' => 'Délai de commande (vendredi)',
'order_deadline_friday' => 'Heure limite de commande (vendredi)',
'order_delay_saturday' => 'Délai de commande (samedi)',
'order_deadline_saturday' => 'Heure limite de commande (samedi)',
'order_delay_sunday' => 'Délai de commande (dimanche)',
'order_deadline_sunday' => 'Heure limite de commande (dimanche)',
'negative_balance' => 'Solde négatif',
'credit' => 'Crédit pain',
'active' => 'Actif',
@@ -421,28 +440,52 @@ class Producer extends ActiveRecordCommon
return $userProducer;
}

/**
* 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()
public function getSpecificDelays()
{
$deadline = 20;
$earliestDateOrder = date('Y-m-d');
$array = [] ;
$daysArray = [
'monday','tuesday','wednesday','thursday','friday','saturday','sunday'
] ;


foreach($daysArray as $day) {
$fieldDelay = 'order_delay_'.$day ;
$fieldDeadline = 'order_deadline_'.$day ;

if ($this->order_deadline) {
$deadline = $this->order_deadline;
$delay = $this->order_delay ;
$deadline = $this->order_deadline ;
if($this->$fieldDelay) {
$delay = $this->$fieldDelay ;
}
if($this->$fieldDeadline) {
$deadline = $this->$fieldDeadline ;
}

$array[$day] = [
'order_delay' => $delay,
'order_deadline' => $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 $array ;
}

public function hasSpecificDelays()
{
$daysArray = [
'monday','tuesday','wednesday','thursday','friday','saturday','sunday'
] ;

foreach($daysArray as $day) {
$fieldDelay = 'order_delay_'.$day ;
$fieldDeadline = 'order_deadline_'.$day ;

if($this->$fieldDelay || $this->$fieldDeadline) {
return true ;
}
}

return $earliestDateOrder;
return false ;
}

/**

+ 2
- 1
common/models/Subscription.php 查看文件

@@ -371,7 +371,7 @@ class Subscription extends ActiveRecordCommon
{
$producer = GlobalParam::getCurrentProducer();
$params = [
':date_earliest_order' => $producer->getEarliestDateOrder(),
':date_earliest_order' => date('Y-m-d'),
':date_begin' => date('Y-m-d', strtotime($this->date_begin)),
':id_producer' => GlobalParam::getCurrentProducerId()
];
@@ -380,6 +380,7 @@ class Subscription extends ActiveRecordCommon
->where('id_producer = :id_producer')
->andWhere('date >= :date_begin')
->andWhere('date >= :date_earliest_order');
$incomingDistributions = Distribution::filterDistributionsByDateDelay($incomingDistributions) ;

if ($this->date_end) {
$incomingDistributions->andWhere('date < :date_end');

+ 43
- 0
console/migrations/m200206_102436_champs_delais_commande_par_jour_semaine.php 查看文件

@@ -0,0 +1,43 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

class m200206_102436_champs_delais_commande_par_jour_semaine extends Migration
{
public function safeUp()
{
$this->addColumn('producer', 'order_delay_monday', Schema::TYPE_INTEGER) ;
$this->addColumn('producer', 'order_deadline_monday', Schema::TYPE_FLOAT) ;
$this->addColumn('producer', 'order_delay_tuesday', Schema::TYPE_INTEGER) ;
$this->addColumn('producer', 'order_deadline_tuesday', Schema::TYPE_FLOAT) ;
$this->addColumn('producer', 'order_delay_wednesday', Schema::TYPE_INTEGER) ;
$this->addColumn('producer', 'order_deadline_wednesday', Schema::TYPE_FLOAT) ;
$this->addColumn('producer', 'order_delay_thursday', Schema::TYPE_INTEGER) ;
$this->addColumn('producer', 'order_deadline_thursday', Schema::TYPE_FLOAT) ;
$this->addColumn('producer', 'order_delay_friday', Schema::TYPE_INTEGER) ;
$this->addColumn('producer', 'order_deadline_friday', Schema::TYPE_FLOAT) ;
$this->addColumn('producer', 'order_delay_saturday', Schema::TYPE_INTEGER) ;
$this->addColumn('producer', 'order_deadline_saturday', Schema::TYPE_FLOAT) ;
$this->addColumn('producer', 'order_delay_sunday', Schema::TYPE_INTEGER) ;
$this->addColumn('producer', 'order_deadline_sunday', Schema::TYPE_FLOAT) ;
}

public function safeDown()
{
$this->dropColumn('producer', 'order_delay_monday') ;
$this->dropColumn('producer', 'order_deadline_monday') ;
$this->dropColumn('producer', 'order_delay_tuesday') ;
$this->dropColumn('producer', 'order_deadline_tuesday') ;
$this->dropColumn('producer', 'order_delay_wednesday') ;
$this->dropColumn('producer', 'order_deadline_wednesday') ;
$this->dropColumn('producer', 'order_delay_thursday') ;
$this->dropColumn('producer', 'order_deadline_thursday') ;
$this->dropColumn('producer', 'order_delay_friday') ;
$this->dropColumn('producer', 'order_deadline_friday') ;
$this->dropColumn('producer', 'order_delay_saturday') ;
$this->dropColumn('producer', 'order_deadline_saturday') ;
$this->dropColumn('producer', 'order_delay_sunday') ;
$this->dropColumn('producer', 'order_deadline_sunday') ;
}
}

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

@@ -236,7 +236,6 @@ class OrderController extends ProducerBaseController
if (isset($order->id_distribution)) {
// date de commande
$distribution = Distribution::find()->where(['id' => $order->id_distribution])->one();
$date = $this->getProducer()->getEarliestDateOrder();

if ($order->getState() != Order::STATE_OPEN) {
$errorDate = true;
@@ -487,7 +486,7 @@ class OrderController extends ProducerBaseController
];

// Distributions
$dateMini = $producer->getEarliestDateOrder();
$dateMini = date('Y-m-d') ;

$distributionsArray = Distribution::searchAll([
'active' => 1
@@ -495,6 +494,7 @@ class OrderController extends ProducerBaseController
'conditions' => ['date > :date'],
'params' => [':date' => $dateMini],
]);
$distributionsArray = Distribution::filterDistributionsByDateDelay($distributionsArray) ;
$json['distributions'] = $distributionsArray;

// Commandes de l'utilisateur

+ 7
- 5
producer/views/layouts/main.php 查看文件

@@ -234,11 +234,13 @@ if (!Yii::$app->user->isGuest) {
</div>
<?php endif; ?>
<div id="infos-producer">
<span data-toggle="tooltip" data-placement="bottom" title="Heure limite de commande">
<span class="glyphicon glyphicon-time"></span> Commande avant
<strong><?php echo Html::encode($producer->order_deadline) ?> h</strong></span>,
<span data-toggle="tooltip" data-placement="bottom"
title="Exemple : commande le lundi pour le <?php if ($producer->order_delay == 1): ?>mardi<?php elseif ($producer->order_delay == 2): ?>mercredi<?php elseif ($producer->order_delay == 3): ?>jeudi<?php elseif ($producer->order_delay == 4): ?>vendredi<?php elseif ($producer->order_delay == 5): ?>samedi<?php elseif ($producer->order_delay == 6): ?>dimanche<?php elseif ($producer->order_delay == 7): ?>lundi d'après<?php endif; ?>"><strong><?= Html::encode($producer->order_delay) ?> jour<?php if ($producer->order_delay > 1): ?>s<?php endif; ?></strong> à l'avance</span>
<?php if(!$producer->hasSpecificDelays()): ?>
<span data-toggle="tooltip" data-placement="bottom" title="Heure limite de commande">
<span class="glyphicon glyphicon-time"></span> Commande avant
<strong><?php echo Html::encode($producer->order_deadline) ?> h</strong></span>,
<span data-toggle="tooltip" data-placement="bottom"
title="Exemple : commande le lundi pour le <?php if ($producer->order_delay == 1): ?>mardi<?php elseif ($producer->order_delay == 2): ?>mercredi<?php elseif ($producer->order_delay == 3): ?>jeudi<?php elseif ($producer->order_delay == 4): ?>vendredi<?php elseif ($producer->order_delay == 5): ?>samedi<?php elseif ($producer->order_delay == 6): ?>dimanche<?php elseif ($producer->order_delay == 7): ?>lundi d'après<?php endif; ?>"><strong><?= Html::encode($producer->order_delay) ?> jour<?php if ($producer->order_delay > 1): ?>s<?php endif; ?></strong> à l'avance</span>
<?php endif; ?>

<?php if (!Yii::$app->user->isGuest): ?>
<span class="favorite">

+ 51
- 9
producer/views/order/order.php 查看文件

@@ -281,15 +281,57 @@ $this->setTitle('Commander') ;
</transition>
</div>
</div>
<div id="infos" v-if="producer != null && producer.order_infos != null && producer.order_infos.length">
<div class="panel panel-default">
<div class="panel-heading">
Informations
</div>
<div class="panel-body">
{{ producer.order_infos }}
</div>

<div id="infos" v-if="producer != null && producer.order_infos != null && producer.order_infos.length">
<div class="panel panel-default">
<div class="panel-heading">
Informations
</div>
<div class="panel-body">
{{ producer.order_infos }}
</div>
</div>
</div>
</div>

<?php
$producer = GlobalParam::getCurrentProducer() ;
if($producer->hasSpecificDelays()): ?>
<div id="specific-delays" class="panel panel-default">
<div class="panel-heading">
Délais de commande spécifiques
</div>
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr>
<th>Jour</th>
<th>Délai</th>
</tr>
</thead>
<?php foreach($producer->getSpecificDelays() as $day => $delay): ?>
<tr>
<td>
<?php
switch($day) {
case 'monday': echo 'Lundi' ; break;
case 'tuesday': echo 'Mardi' ; break;
case 'wednesday': echo 'Mercredi' ; break;
case 'thursday': echo 'Jeudi' ; break;
case 'friday': echo 'Vendredi' ; break;
case 'saturday': echo 'Samedi' ; break;
case 'sunday': echo 'Dimanche' ; break;
}
?>
</td>
<td>
<span><?= $delay['order_delay'] ?> jour<?= ($delay['order_delay'] > 1) ? 's' : '' ?></span> à l'avance,
avant <span><?= $delay['order_deadline'] ?>h</span>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
<?php endif; ?>
</div>
</div>

+ 2
- 2
producer/web/css/screen.css 查看文件

@@ -1523,11 +1523,11 @@ termes.
.order-order #main #app-order-order #content-step-payment .comment {
margin-bottom: 20px;
}
/* line 267, ../sass/order/_order.scss */
/* line 273, ../sass/order/_order.scss */
.order-order #main #app-order-order #infos {
margin-top: 30px;
}
/* line 269, ../sass/order/_order.scss */
/* line 275, ../sass/order/_order.scss */
.order-order #main #app-order-order #infos .panel-body {
padding-top: 0px;
white-space: pre-line;

+ 21
- 13
producer/web/js/vuejs/order-order.js 查看文件

@@ -134,6 +134,7 @@ var app = new Vue({
start: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]),
end: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2])
}) ;

}
}
var orders = [] ;
@@ -142,20 +143,26 @@ var app = new Vue({
}
if(orders.length) {

for(var i= 0; i < orders.length; i++) {
app.calendar.attrs.push({
highlight: {
backgroundColor: '#FF7F00'
},
contentStyle: {
color: 'white'
},
popover: {
label: orders[i].pointSale.name + ' / '+app.formatPrice(orders[i].amount_total),
hideIndicator: true
},
dates: orders[i].date_distribution,
}) ;
arrayDate = orders[i].date_distribution.split('-') ;
var dateOrder = new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]) ;
if(app.isAvailableDate(dateOrder)) {

app.calendar.attrs.push({
highlight: {
backgroundColor: '#FF7F00'
},
contentStyle: {
color: 'white'
},
popover: {
label: orders[i].pointSale.name + ' / '+app.formatPrice(orders[i].amount_total),
hideIndicator: true
},
dates: orders[i].date_distribution,
}) ;
}
}
}
@@ -221,6 +228,7 @@ var app = new Vue({
return true ;
}
}

return false ;
},
pointSaleClick: function(event) {

+ 7
- 1
producer/web/sass/order/_order.scss 查看文件

@@ -263,7 +263,13 @@
margin-bottom: 20px ;
}
}

#specific-delays {
strong {
//text-decoration: underline ;
}
}

#infos {
margin-top: 30px ;
.panel-body {

正在加载...
取消
保存