PluginProbe
Moloni / trunk
Moloni vtrunk
5.0.10 5.0.09 5.0.08 5.0.07 5.0.06 trunk 0.4.0.00 0.4.8.1 3.0.10 3.0.11 3.0.35 3.0.36 3.0.37 3.0.38 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.0.46 3.0.47 3.0.48 3.0.49 3.0.50 All 98 releases
moloni / src / Services / Documents / OpenDocument.php

OpenDocument.php in Moloni trunk, at src/Services/Documents/OpenDocument.php

57 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Moloni\Services\Documents;
4
5 use Moloni\Curl;
6 use Moloni\Enums\DocumentTypes;
7 use Moloni\Traits\DocumentTypeTrait;
8
9 class OpenDocument
10 {
11 use DocumentTypeTrait;
12
13 private $documentId;
14
15 public function __construct($documentId)
16 {
17 $this->documentId = $documentId;
18
19 $this->run();
20 }
21
22 public function run(): void
23 {
24 $props= [
25 'document_id' => $this->documentId
26 ];
27
28 $invoice = Curl::simple('documents/getOne', $props);
29
30 if (!isset($invoice['document_id'])) {
31 return;
32 }
33
34 if ((int)$invoice['status'] === 1) {
35 $url = Curl::simple('documents/getPDFLink', $props);
36
37 $location = 'Location: ' . $url['url'];
38 } else {
39 $company = Curl::simple('companies/getOne', []);
40 $slug = $company['slug'];
41
42 $location = 'Location: https://moloni.pt/';
43 $location .= $slug . '/' . $this->getDocumentTypeSlug($invoice['document_type']['saft_code']);
44 $location .= '/showDetail/' . $invoice['document_id'];
45 }
46
47 header($location);
48 }
49
50 protected function getDocumentTypeSlug(string $saftcode = ''): string
51 {
52 $typeName = $this->parseTypeNameFromSaftCode($saftcode);
53
54 return DocumentTypes::getDocumentTypeSlug($typeName);
55 }
56 }
57