You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7KB

  1. <?php
  2. namespace backend\controllers;
  3. use yii\filters\AccessControl;
  4. class ProducerInvoiceController extends BackendController
  5. {
  6. public function behaviors()
  7. {
  8. return [
  9. 'access' => [
  10. 'class' => AccessControl::class,
  11. 'rules' => [
  12. [
  13. 'allow' => true,
  14. 'roles' => ['@'],
  15. 'matchCallback' => function ($rule, $action) {
  16. return
  17. $this->getParameterBag()->get('dolibarrApiKey')
  18. && $this->getUserModule()
  19. ->getAuthorizationChecker()
  20. ->isGrantedAsProducer($this->getUserCurrent());
  21. }
  22. ],
  23. ],
  24. ],
  25. ];
  26. }
  27. public function actionIndex()
  28. {
  29. return $this->render('index', [
  30. 'producer' => $this->getProducerCurrent(),
  31. 'invoicesArray' => $this->getProducerModule()
  32. ->getDolibarrUtils()
  33. ->getDolibarrProducerInvoices($this->getProducerCurrent())
  34. ]);
  35. }
  36. public function actionDownload(int $idDolibarrInvoice)
  37. {
  38. $documentDownload = \Yii::$app->dolibarrApi->downloadInvoice($idDolibarrInvoice);
  39. if($documentDownload) {
  40. return \Yii::$app->response->sendContentAsFile(base64_decode($documentDownload['content']), $documentDownload['filename'], [
  41. 'mimeType' => $documentDownload['content-type']
  42. ]);
  43. }
  44. else {
  45. $this->addFlash('error', 'Facture introuvable');
  46. return $this->redirectReferer();
  47. }
  48. }
  49. }