Browse Source

[Backend] Documents : pouvoir regénérer PDF #798

refactoring
Guillaume Bourgeois 1 year ago
parent
commit
7e1aca7092
3 changed files with 17 additions and 3 deletions
  1. +8
    -0
      backend/controllers/DocumentController.php
  2. +7
    -1
      backend/views/document/_form.php
  3. +2
    -2
      common/models/Document.php

+ 8
- 0
backend/controllers/DocumentController.php View File

return $document->downloadPdf(); return $document->downloadPdf();
} }


public function actionRegenerate($id)
{
$document = $this->findModel($id);
$document->downloadPdf(true);
Yii::$app->getSession()->setFlash('success', 'Le document PDF a bien été regénéré.');
return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]);
}

public function actionSend($id, $backUpdateForm = false) public function actionSend($id, $backUpdateForm = false)
{ {
$document = $this->findModel($id); $document = $this->findModel($id);

+ 7
- 1
backend/views/document/_form.php View File

<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([Yii::$app->controller->getControllerUrl() . '/download', 'id' => $model->id]) ?>" <a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/download', 'id' => $model->id]) ?>"
class="btn btn-sm btn-default"><span class="glyphicon glyphicon-download-alt"></span> Télécharger (PDF)</a>
class="btn btn-sm btn-default"><span class="glyphicon glyphicon-download-alt"></span> Télécharger</a>

<?php if($model->isStatusValid()): ?>
<a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/regenerate', 'id' => $model->id]) ?>"
class="btn btn-sm btn-default"><span class="glyphicon glyphicon-repeat"></span> Regénérer</a>
<?php endif; ?>

<?php if ($model->getClass() == 'Invoice' && Producer::getConfig('option_export_evoliz')): ?> <?php if ($model->getClass() == 'Invoice' && Producer::getConfig('option_export_evoliz')): ?>
<a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/export-csv-evoliz', 'id' => $model->id]) ?>" <a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/export-csv-evoliz', 'id' => $model->id]) ?>"
class="btn btn-sm btn-default"><span class="glyphicon glyphicon-save-file"></span> Export Evoliz class="btn btn-sm btn-default"><span class="glyphicon glyphicon-save-file"></span> Export Evoliz

+ 2
- 2
common/models/Document.php View File

} }
} }


public function downloadPdf()
public function downloadPdf($regenerate = false)
{ {
$filenameComplete = $this->getFilenameComplete(); $filenameComplete = $this->getFilenameComplete();


if (!file_exists($filenameComplete) || $this->isStatusDraft()) {
if (!file_exists($filenameComplete) || $this->isStatusDraft() || $regenerate) {
$this->generatePdf(Pdf::DEST_FILE); $this->generatePdf(Pdf::DEST_FILE);
} }



Loading…
Cancel
Save