No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

ProducerInvoiceController.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }