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.
dev
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

return null ; 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. * Traite le formulaire d'ajout/modification de commande.
* *
// commandes // commandes
$arrayOrders = Order::searchAll([ $arrayOrders = Order::searchAll([
'distribution.date' => $date, 'distribution.date' => $date,
], [
'conditions' => 'date_delete IS NULL'
]); ]);
$revenues = 0; $revenues = 0;
$pointSale = PointSale::findOne($order->id_point_sale); $pointSale = PointSale::findOne($order->id_point_sale);
$orders = Order::searchAll([ $orders = Order::searchAll([
'distribution.date' => $date 'distribution.date' => $date
], [
'conditions' => 'date_delete IS NULL'
]) ; ]) ;
$pointSale->initOrders($orders); $pointSale->initOrders($orders);
$pointSale = PointSale::findOne($order->id_point_sale); $pointSale = PointSale::findOne($order->id_point_sale);
$orders = Order::searchAll([ $orders = Order::searchAll([
'distribution.date' => $date, 'distribution.date' => $date,
], [
'conditions' => 'date_delete IS NULL'
]) ; ]) ;
$pointSale->initOrders($orders); $pointSale->initOrders($orders);


die(); 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. * Crée une commande via une requête AJAX.
$pointSale = PointSale::findOne($order->id_point_sale); $pointSale = PointSale::findOne($order->id_point_sale);
$orders = Order::searchAll([ $orders = Order::searchAll([
'distribution.date' => $date 'distribution.date' => $date
], [
'conditions' => 'date_delete IS NULL'
]) ; ]) ;
$pointSale->initOrders($orders); $pointSale->initOrders($orders);

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

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

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

'id_user' => Yii::$app->user->id, 'id_user' => Yii::$app->user->id,
'distribution.id_producer' => $this->getProducer()->id 'distribution.id_producer' => $this->getProducer()->id
]) ])
->andWhere('date_delete IS NULL')
->orderBy('distribution.date DESC'), ->orderBy('distribution.date DESC'),
'pagination' => [ 'pagination' => [
'pageSize' => 10, 'pageSize' => 10,
'id' => $order->id_point_sale '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 // sauvegarde de la commande
$order->save(); $order->save();

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

?> ?>
<div id="bar-fixed" class="<?php if($producer->credit): ?>credit<?php else: ?>no-credit<?php endif; ?>"> <div id="bar-fixed" class="<?php if($producer->credit): ?>credit<?php else: ?>no-credit<?php endif; ?>">
<div class="container"> <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> <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; ?> <?php endif; ?>
<span id="total-order-bottom"><span></span> €</span> <span id="total-order-bottom"><span></span> €</span>
<?= $form->field($model, 'comment')->textarea(['rows' => 3, 'placeholder' => 'Un commentaire ?'])->label(''); ?> <?= $form->field($model, 'comment')->textarea(['rows' => 3, 'placeholder' => 'Un commentaire ?'])->label(''); ?>
<div id="block-confirm-order"> <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> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>

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

'label' => 'Statut', 'label' => 'Statut',
'format' => 'raw', 'format' => 'raw',
'value' => function($c) { '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

if(montant_paye) { if(montant_paye) {
html += '<span class="amount-paid">'+montant_paye+' € déjà payé</span><br />' ; 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' ; html += 'Restera <strong>'+reste_payer+' €</strong> à payer à la boulangerie' ;
$('#checkbox-credit .info').html(html) ; $('#checkbox-credit .info').html(html) ;
} }
if(montant_paye) { if(montant_paye) {
html += '<span class="amount-paid">'+montant_paye+' € déjà payé</span><br />' ; 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) ; $('#checkbox-credit .info').html(html) ;
} }
// remboursé // remboursé

Loading…
Cancel
Save