Mariusz Muszyński 8 лет назад
Родитель
Сommit
a4c95f318e
1 измененных файлов с 21 добавлено и 5 удалено
  1. 21 5
      SE/se-lib/VAT.php

+ 21 - 5
SE/se-lib/VAT.php

@@ -70,6 +70,19 @@ Class VAT {
 	private $cookies = "php://memory";
 	private $message = [];
 	private $initialized = false;
+	private $messages = [
+		"Podmiot o podanym identyfikatorze podatkowym NIP jest zarejestrowany jako podatnik VAT czynny" => [
+			"active" => true,
+			"shortMessage" => "Czynny",
+		],
+		"Podmiot o podanym identyfikatorze podatkowym NIP nie jest zarejestrowany jako podatnik VAT" => [
+			"active" => false,
+			"shortMessage" => "Niezarejestrowany",
+		],
+		"Podmiot o podanym identyfikatorze podatkowym NIP jest zarejestrowany jako podatnik VAT zwolniony" => [
+			"active" => true,
+			"shortMessage" => "Zwolniony"
+	];
 
 	private function getHeaders($ch, $header) {
 		$len = strlen($header);
@@ -152,11 +165,8 @@ Class VAT {
 		$this->dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
 		$this->message = array_map("trim", array_values(array_diff(explode("|", $this->dom->getElementById("caption2_b-3")->textContent), [''])));
 		if (!$this->message) throw new Exception("Błąd danych ze strony Ministerstwa Finansów");
-		switch ($this->message[0]) {
-			case "Podmiot o podanym identyfikatorze podatkowym NIP jest zarejestrowany jako podatnik VAT czynny" : return true;
-			case "Podmiot o podanym identyfikatorze podatkowym NIP nie jest zarejestrowany jako podatnik VAT" : return false;
-			default: throw new Exception("Nieznany rezultat");
-		}
+		if (in_array($this->message[0], $this->messages)) return $this->messages[$this->message[0]]['active'];
+		else throw new Exception("Nieznany rezultat");
 	}
 
 	public function getMessage($whole = false) {
@@ -165,6 +175,12 @@ Class VAT {
 		else return $this->message[0];
 	}
 
+	public function getShortMessage() {
+		if (!$this->message) return "Brak wyniku";
+		if (!in_array($this->message, $this->messages)) return "Nieznany rezultat";
+		return $this->messages[$this->message]['shortMessage'];
+	}
+
 	public function isActiveVatPayer($nip) {
 		$this->message = [];
 		$nip = str_replace("-", "", trim($nip));