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.

53 satır
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. 'invoicesArray' => $this->getProducerModule()
  31. ->getDolibarrUtils()
  32. ->getDolibarrProducerInvoices($this->getProducerCurrent())
  33. ]);
  34. }
  35. public function actionDownload(int $idDolibarrInvoice)
  36. {
  37. $documentDownload = \Yii::$app->dolibarrApi->downloadInvoice($idDolibarrInvoice);
  38. if($documentDownload) {
  39. return \Yii::$app->response->sendContentAsFile(base64_decode($documentDownload['content']), $documentDownload['filename'], [
  40. 'mimeType' => $documentDownload['content-type']
  41. ]);
  42. }
  43. else {
  44. $this->addFlash('error', 'Facture introuvable');
  45. return $this->redirectReferer();
  46. }
  47. }
  48. }