Browse Source

Intégration dernières modifs de la prod

Gestion des commandes annulées, bouton payer/rembourser désactivé lors du clic, montant du crédit débité arrondi lors de l'affichage au client.
refactoring
Guillaume Bourgeois 6 years ago
parent
commit
f165b67878
6 changed files with 78 additions and 58 deletions
  1. +37
    -32
      backend/controllers/OrderController.php
  2. +1
    -0
      backend/web/js/lechatdesnoisettes.js
  3. +7
    -6
      producer/controllers/OrderController.php
  4. +3
    -2
      producer/views/order/_form.php
  5. +28
    -16
      producer/views/order/history.php
  6. +2
    -2
      producer/web/js/lechatdesnoisettes.js

+ 37
- 32
backend/controllers/OrderController.php View File

@@ -164,36 +164,6 @@ class OrderController extends BackendController
return null ;
}

/**
* Supprime une commande.
*
* @param string $date
* @param integer $id_commande
*/
public function actionDeleteOrder($date, $idOrder)
{
$order = Order::searchOne(['id' =>$idOrder]) ;

if ($order) {

// remboursement de la commande
if ($order->id_user && $order->getAmount(Order::AMOUNT_PAID) && Producer::getConfig('credit')) {
$order->saveCreditHistory(
CreditHistory::TYPE_REFUND,
$order->getAmount(Order::AMOUNT_PAID),
$order->distribution->id_producer,
$order->id_user,
User::getCurrentId()
);
}

$order->delete();
ProductOrder::deleteAll(['id_order' => $idOrder]);
}

$this->redirect(['index', 'date' => $date]);
}

/**
* Traite le formulaire d'ajout/modification de commande.
*
@@ -322,8 +292,6 @@ class OrderController extends BackendController
// commandes
$arrayOrders = Order::searchAll([
'distribution.date' => $date,
], [
'conditions' => 'date_delete IS NULL'
]);
$revenues = 0;
@@ -936,6 +904,8 @@ class OrderController extends BackendController
$pointSale = PointSale::findOne($order->id_point_sale);
$orders = Order::searchAll([
'distribution.date' => $date
], [
'conditions' => 'date_delete IS NULL'
]) ;
$pointSale->initOrders($orders);
@@ -983,6 +953,8 @@ class OrderController extends BackendController
$pointSale = PointSale::findOne($order->id_point_sale);
$orders = Order::searchAll([
'distribution.date' => $date,
], [
'conditions' => 'date_delete IS NULL'
]) ;
$pointSale->initOrders($orders);
@@ -993,6 +965,37 @@ class OrderController extends BackendController

die();
}
/**
* Supprime une commande.
*
* @param string $date
* @param integer $idOrder
*/
public function actionDeleteOrder($date, $idOrder)
{
$order = Order::searchOne(['id' =>$idOrder]) ;

if ($order) {

// remboursement de la commande
if ($order->id_user && $order->getAmount(Order::AMOUNT_PAID) && Producer::getConfig('credit')) {
$order->saveCreditHistory(
CreditHistory::TYPE_REFUND,
$order->getAmount(Order::AMOUNT_PAID),
$order->distribution->id_producer,
$order->id_user,
User::getCurrentId()
);
}

$order->delete();
ProductOrder::deleteAll(['id_order' => $idOrder]);
}

$this->redirect(['index', 'date' => $date]);
}

/**
* Crée une commande via une requête AJAX.
@@ -1060,6 +1063,8 @@ class OrderController extends BackendController
$pointSale = PointSale::findOne($order->id_point_sale);
$orders = Order::searchAll([
'distribution.date' => $date
], [
'conditions' => 'date_delete IS NULL'
]) ;
$pointSale->initOrders($orders);

+ 1
- 0
backend/web/js/lechatdesnoisettes.js View File

@@ -583,6 +583,7 @@ function chat_index_commandes_affiche_commande(id_pv, id_commande) {
function chat_index_commandes_boutons_paiement(id_pv, id_commande) {
// boutons paiement/remboursement
$('#point-vente-'+id_pv+' .payer, #point-vente-'+id_pv+' .rembourser').click(function() {
$(this).attr('disabled','disabled') ;
$.get(UrlManager.getBaseUrl()+'order/payment',{
idOrder: id_commande,
type: $(this).data('type'),

+ 7
- 6
producer/controllers/OrderController.php View File

@@ -234,7 +234,6 @@ class OrderController extends ProducerBaseController
'id_user' => Yii::$app->user->id,
'distribution.id_producer' => $this->getProducer()->id
])
->andWhere('date_delete IS NULL')
->orderBy('distribution.date DESC'),
'pagination' => [
'pageSize' => 10,
@@ -416,11 +415,13 @@ class OrderController extends ProducerBaseController
'id' => $order->id_point_sale
]) ;
if ($pointSale && strlen($pointSale->getComment()))
$order->comment_point_sale = $pv->getComment();
else
$order->comment_point_sale = '';

$order->comment_point_sale = ($pointSale && strlen($pointSale->getComment())) ?
$pv->getComment() : '' ;
// la commande est automatiquement réactivée lors d'une modification
$order->date_delete = null ;
// sauvegarde de la commande
$order->save();

+ 3
- 2
producer/views/order/_form.php View File

@@ -258,7 +258,7 @@ use yii\widgets\ActiveForm;
?>
<div id="bar-fixed" class="<?php if($producer->credit): ?>credit<?php else: ?>no-credit<?php endif; ?>">
<div class="container">
<?php if (isset($model->id)): ?>
<?php if (isset($model->id) && !$model->date_delete): ?>
<a href="<?php echo Yii::$app->urlManager->createUrl(['order/cancel', 'id' => $model->id]); ?>" class="btn btn-danger cancel-order">Annuler ma commande</a>
<?php endif; ?>
<span id="total-order-bottom"><span></span> €</span>
@@ -285,7 +285,8 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'comment')->textarea(['rows' => 3, 'placeholder' => 'Un commentaire ?'])->label(''); ?>
<div id="block-confirm-order">
<?= Html::submitButton('<span class="glyphicon glyphicon-ok"></span> Valider ma commande', ['class' => 'btn btn-primary confirm-order']) ?>
<?php if($model->date_delete): $strButtonConfirmOrder = 'Réactiver ma commande' ; else: $strButtonConfirmOrder = 'Valider ma commande' ; endif; ?>
<?= Html::submitButton('<span class="glyphicon glyphicon-ok"></span> '.$strButtonConfirmOrder, ['class' => 'btn btn-primary confirm-order']) ?>
</div>
<?php endif; ?>
</div>

+ 28
- 16
producer/views/order/history.php View File

@@ -97,24 +97,36 @@ GridView::widget([
'label' => 'Statut',
'format' => 'raw',
'value' => function($c) {
if($c->getState() == Order::STATE_DELIVERED) {
return 'Livrée' ;
$html = '' ;
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>' ;
}
}
elseif($c->getState() == Order::STATE_PREPARATION) {
return 'En préparation' ;
}
elseif($c->getState() == Order::STATE_OPEN) {
return '<div class="btn-group">
<a href="'.Yii::$app->urlManager->createUrl(['order/update','id'=>$c->id, 'id_producer'=>$c->distribution->producer->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>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="'.Yii::$app->urlManager->createUrl(['order/cancel','id'=>$c->id]).'"><span class="glyphicon glyphicon-trash"></span> Annuler la commande</a></li>
</ul>
</div>' ;
else {
if($c->getState() == Order::STATE_DELIVERED) {
$html .= 'Livrée' ;
}
elseif($c->getState() == Order::STATE_PREPARATION) {
$html .= 'En préparation' ;
}
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>
<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>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="'.Yii::$app->urlManager->createUrl(['order/cancel','id'=>$c->id]).'"><span class="glyphicon glyphicon-trash"></span> Annuler la commande</a></li>
</ul>
</div>' ;
}
}
return $html ;
}
],
]

+ 2
- 2
producer/web/js/lechatdesnoisettes.js View File

@@ -573,7 +573,7 @@ function chat_systeme_commande_credit_pain_event(prix_global) {
if(montant_paye) {
html += '<span class="amount-paid">'+montant_paye+' € déjà payé</span><br />' ;
}
html += '<strong>'+credit_pain+' €</strong> seront débités<br />' ;
html += '<strong>'+credit_pain.toFixed(2)+' €</strong> seront débités<br />' ;
html += 'Restera <strong>'+reste_payer+' €</strong> à payer à la boulangerie' ;
$('#checkbox-credit .info').html(html) ;
}
@@ -594,7 +594,7 @@ function chat_systeme_commande_credit_pain_event(prix_global) {
if(montant_paye) {
html += '<span class="amount-paid">'+montant_paye+' € déjà payé</span><br />' ;
}
html += '<strong>'+montant+' €</strong> seront débités' ;
html += '<strong>'+montant.toFixed(2)+' €</strong> seront débités' ;
$('#checkbox-credit .info').html(html) ;
}
// remboursé

Loading…
Cancel
Save