PluginProbe
Moloni / 5.0.09
Moloni v5.0.09
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 / Exceptions / DocumentError.php

DocumentError.php in Moloni 5.0.09, at src/Exceptions/DocumentError.php

79 lines 2.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\Exceptions;
4
5 use Moloni\Curl;
6 use Moloni\Exceptions\Core\MoloniException;
7
8 class DocumentError extends MoloniException
9 {
10 /**
11 * Throws a new error with a message
12 *
13 * @param string|null $message Exception message
14 * @param array|null $data Exception data
15 *
16 * @return void
17 */
18 public function __construct($message = '', $data = [])
19 {
20 if (empty($data)) {
21 $data = Curl::getLog();
22 }
23
24 parent::__construct($message, $data);
25 }
26
27 // Overrides //
28
29 public function showError()
30 {
31 $message = $this->getDecodedMessage();
32
33 $url = $this->data['url'] ?? '';
34 $sent = $this->data['sent'] ?? [];
35 $received = $this->data['received'] ?? [];
36
37 include MOLONI_TEMPLATE_DIR . 'Exceptions/DocumentError.php';
38 }
39
40 public function getDecodedMessage(): string
41 {
42 $errorMessage = '<b>' . $this->getMessage() . '</b>';
43
44 if (isset($this->data['received']) && is_array($this->data['received'])) {
45 foreach ($this->data['received'] as $line) {
46 $message = $line['description'] ?? $line[0]['description'] ?? '';
47
48 if (!empty($message)) {
49 $errorMessage .= '<br>' . $this->translateError($message);
50 }
51 }
52 }
53
54 return $errorMessage;
55 }
56
57 // Privates //
58
59 protected function translateError(string $message): string
60 {
61 switch ($message) {
62 case 'Field \'exemption_reason\' is required':
63 $message = __('Um dos artigos não tem uma taxa de IVA associada e como tal, tem que selecionar uma razão de isenção');
64 break;
65 case "Field 'category_id' must be integer, greater than 0":
66 $message = __('Verifique por favor se o artigo tem uma categoria associada');
67 break;
68 case "Field 'document_set_wsat_id' must be valid":
69 $message = __('Série de documento não está registada na AT');
70 $message .= ' ';
71 $message .= '(<a href="https://www.moloni.pt/suporte/guia-para-a-comunicacao-de-series" target="_blank">Ver FAQ</a>)';
72
73 break;
74 }
75
76 return $message;
77 }
78 }
79