Browse Source

Refactoring getControllerUrlPath()

refactoring
Guillaume Bourgeois 4 years ago
parent
commit
d5d27ccdf1
5 changed files with 26 additions and 16 deletions
  1. +12
    -5
      backend/controllers/DocumentController.php
  2. +2
    -2
      backend/views/document/_form.php
  3. +6
    -1
      backend/views/invoice/index.php
  4. +6
    -1
      backend/views/quotation/index.php
  5. +0
    -7
      common/models/Document.php

+ 12
- 5
backend/controllers/DocumentController.php View File

$this->processInvoiceViaDeliveryNotes($model) ; $this->processInvoiceViaDeliveryNotes($model) ;


Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('create', $model)); Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('create', $model));
return $this->redirect(['/' . $model->getControllerUrlPath() . '/update', 'id' => $model->id]);
return $this->redirect(['/' . $this->getControllerUrl() . '/update', 'id' => $model->id]);
} else { } else {
Yii::$app->getSession()->setFlash('error', 'Un problème est survenu lors de la création du document.'); Yii::$app->getSession()->setFlash('error', 'Un problème est survenu lors de la création du document.');
} }
]); ]);


Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('delete', $model)); Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('delete', $model));
$this->redirect([$model->getControllerUrlPath().'/index']);
$this->redirect([$this->getControllerUrl().'/index']);
} }


public function actionDownload($id) public function actionDownload($id)
else { else {
Yii::$app->getSession()->setFlash('danger', $this->getFlashMessage('send', $document)); Yii::$app->getSession()->setFlash('danger', $this->getFlashMessage('send', $document));
} }
$this->redirect([$document->getControllerUrlPath().'/index']);
$this->redirect([$this->getControllerUrl().'/index']);
} }


public function actionAjaxUserInfos($typeAction, $idUser, $classDocument, $idDocument = false) public function actionAjaxUserInfos($typeAction, $idUser, $classDocument, $idDocument = false)
$document->changeStatus(Document::STATUS_VALID); $document->changeStatus(Document::STATUS_VALID);
$document->save(); $document->save();
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('validate', $document)); Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('validate', $document));
return $this->redirect(['delivery-note/index']);
return $this->redirect([$this->getControllerUrl().'/index']);
} }
} }


Yii::$app->getSession()->setFlash('danger', 'Une erreur est survenue lors de la validation du document.'); Yii::$app->getSession()->setFlash('danger', 'Une erreur est survenue lors de la validation du document.');
return $this->redirect(['delivery-note/index']);
return $this->redirect([$this->getControllerUrl().'/index']);
} }


public function actionAjaxValidateDocument($idDocument, $classDocument) public function actionAjaxValidateDocument($idDocument, $classDocument)
return $title; return $title;
} }


public function getControllerUrl()
{
$path = strtolower($this->getClass());
$path = str_replace('deliverynote', 'delivery-note', $path);
return $path;
}

/** /**
* Recherche un Document en fonction de son ID. * Recherche un Document en fonction de son ID.
* *

+ 2
- 2
backend/views/document/_form.php View File

<div id="" class="info-box"> <div id="" class="info-box">
<span class="info-box-icon bg-blue"><i class="fa fa-download"></i></span> <span class="info-box-icon bg-blue"><i class="fa fa-download"></i></span>
<div class="info-box-content"> <div class="info-box-content">
<a href="<?= Yii::$app->urlManager->createUrl([$model->getControllerUrlPath().'/download', 'id' => $model->id]) ?>" class="btn btn-default">Télécharger (PDF)</a>
<a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl().'/download', 'id' => $model->id]) ?>" class="btn btn-default"><span class="glyphicon glyphicon-download-alt"></span> Télécharger (PDF)</a>
</div> </div>
</div> </div>
<div id="" class="info-box"> <div id="" class="info-box">
<span class="info-box-icon bg-red"><i class="fa fa-flash"></i></span> <span class="info-box-icon bg-red"><i class="fa fa-flash"></i></span>
<div class="info-box-content"> <div class="info-box-content">
<a v-if="document.status == 'draft'" class="btn btn-default" @click="validateDocument">Valider le document</a>
<a v-if="document.status == 'draft'" class="btn btn-default" @click="validateDocument"><span class="glyphicon glyphicon-ok"></span> Valider le document</a>
</div> </div>
</div> </div>
</div> </div>

+ 6
- 1
backend/views/invoice/index.php View File

], ],
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete} {send} {download}',
'template' => '{validate} {update} {delete} {send} {download}',
'headerOptions' => ['class' => 'column-actions'], 'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'], 'contentOptions' => ['class' => 'column-actions'],
'buttons' => [ 'buttons' => [
'validate' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, [
'title' => Yii::t('app', 'Valider'), 'class' => 'btn btn-default'
]) : '');
},
'send' => function($url, $model) { 'send' => function($url, $model) {
return (!$model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [ return (!$model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [
'title' => Yii::t('app', 'Envoyer'), 'class' => 'btn btn-default' 'title' => Yii::t('app', 'Envoyer'), 'class' => 'btn btn-default'

+ 6
- 1
backend/views/quotation/index.php View File

], ],
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete} {send} {download}',
'template' => '{validate} {update} {delete} {send} {download}',
'headerOptions' => ['class' => 'column-actions'], 'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'], 'contentOptions' => ['class' => 'column-actions'],
'buttons' => [ 'buttons' => [
'validate' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, [
'title' => Yii::t('app', 'Valider'), 'class' => 'btn btn-default'
]) : '');
},
'send' => function($url, $model) { 'send' => function($url, $model) {
return (!$model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [ return (!$model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [
'title' => Yii::t('app', 'Envoyer'), 'class' => 'btn btn-default' 'title' => Yii::t('app', 'Envoyer'), 'class' => 'btn btn-default'

+ 0
- 7
common/models/Document.php View File

return ''; return '';
} }


public function getControllerUrlPath()
{
$path = strtolower($this->getClass());
$path = str_replace('deliverynote', 'delivery-note', $path);
return $path;
}

public function isValidClass($typeDocument) public function isValidClass($typeDocument)
{ {
return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']); return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']);

Loading…
Cancel
Save