-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAdis.php
124 lines (111 loc) · 3.87 KB
/
Adis.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace PYSys\Tools;
/**
* Class Adis
* @package PYSys\Tools
*
* Class for getting data from ADIS Database
*/
class Adis {
const PAYER_FOUND = "found";
const PAYER_NOT_FOUND = "not_found";
/** @var \SoapClient */
protected static $adis = null;
protected static function init()
{
try {
self::$adis = new \SoapClient('http://adisrws.mfcr.cz/adistc/axis2/services/rozhraniCRPDPH.rozhraniCRPDPHSOAP?wsdl');
} catch (\Exception $e) {
throw new AdisException("Cannot connect or parse Adis server");
}
}
/**
* Searching DIC
* @param array|int|string $dic
* @return array
* @throws AdisException
*/
public static function search($dic) {
self::init();
if(!is_array($dic)) {
$dic = array($dic);
}
try {
/** @var \stdClass $list */
$list = self::$adis->__soapCall("getStatusNespolehlivyPlatce",array("dph"=>$dic));
} catch (\Exception $e) {
throw new AdisException("Error in getting list");
}
$payers = array();
if($list->status->statusCode === 0 && isset($list->statusPlatceDPH)) {
if(is_array($list->statusPlatceDPH)) {
foreach($list->statusPlatceDPH as $payer) {
if(isset($payer->nespolehlivyPlatce) && $payer->nespolehlivyPlatce === "NENALEZEN") {
$unreliablePayer = new \stdClass();
$unreliablePayer->dic = $payer->dic;
$unreliablePayer->status = self::PAYER_NOT_FOUND;
$unreliablePayer->unreliable = null;
$unreliablePayer->published = null;
$unreliablePayer->numberFu = null;
$payers[] = $unreliablePayer;
}
$unreliablePayer = new \stdClass();
$unreliablePayer->dic = $payer->dic;
$unreliablePayer->status = self::PAYER_FOUND;
$unreliablePayer->unreliable = $payer->nespolehlivyPlatce == "ANO" ? true : false;
$unreliablePayer->published = $unreliablePayer->unreliable ? $payer->datumZverejneniNespolehlivosti : null;
$unreliablePayer->numberFu = $unreliablePayer->unreliable ? $payer->cisloFu : null;
$payers[] = $unreliablePayer;
}
} else {
if(isset($list->statusPlatceDPH->nespolehlivyPlatce) && $list->statusPlatceDPH->nespolehlivyPlatce === "NENALEZEN") {
$unreliablePayer = new \stdClass();
$unreliablePayer->dic = $list->statusPlatceDPH->dic;
$unreliablePayer->status = self::PAYER_NOT_FOUND;
$unreliablePayer->unreliable = null;
$unreliablePayer->published = null;
$unreliablePayer->numberFu = null;
$payers[] = $unreliablePayer;
} else {
$unreliablePayer = new \stdClass();
$unreliablePayer->dic = $list->statusPlatceDPH->dic;
$unreliablePayer->status = self::PAYER_FOUND;
$unreliablePayer->unreliable = $list->statusPlatceDPH->nespolehlivyPlatce == "ANO" ? true : false;
$unreliablePayer->published = $unreliablePayer->unreliable ? $list->statusPlatceDPH->datumZverejneniNespolehlivosti : null;
$unreliablePayer->numberFu = $unreliablePayer->unreliable ? $list->statusPlatceDPH->cisloFu : null;
$payers[] = $unreliablePayer;
}
}
} else {
throw new AdisException("Bad parameters");
}
return $payers;
}
/**
* Return full list of unreliable payers
* @return array
* @throws AdisException
*/
public static function unreliablePayers() {
self::init();
try {
/** @var \stdClass $list */
$list = self::$adis->getSeznamNespolehlivyPlatce();
} catch (\Exception $e) {
throw new AdisException("Error in getting list");
}
$unreliablePayers = array();
if(isset($list->statusPlatceDPH)) {
foreach($list->statusPlatceDPH as $payer) {
$unreliablePayer = new \stdClass();
$unreliablePayer->dic = $payer->dic;
$unreliablePayer->unreliable = $payer->nespolehlivyPlatce == "ANO" ? true : false;
$unreliablePayer->published = $payer->datumZverejneniNespolehlivosti;
$unreliablePayer->numberFu = $payer->cisloFu;
$unreliablePayers[] = $unreliablePayer;
}
}
return $unreliablePayers;
}
}
class AdisException extends \Exception {}