|
8 | 8 |
|
9 | 9 | class SoapClient
|
10 | 10 | {
|
11 |
| - public $soap; |
12 |
| - protected $secret; |
13 |
| - protected $agreement; |
14 |
| - |
15 |
| - public function __construct( $agreement = '', $secret = null ) { |
16 |
| - $this->agreement = $agreement ?? config( 'economic.agreement' ); |
17 |
| - $this->secret = $secret ?? config( 'economic.secret_token' ); |
18 |
| - |
19 |
| - $this->soap = new SoapWrapper(); |
20 |
| - $this->soap->add( 'economic', function ( Service $service ) { |
21 |
| - $service->wsdl( 'https://api.e-conomic.com/secure/api1/EconomicWebservice.asmx?WSDL' ) |
22 |
| - ->trace( true ) |
23 |
| - ->header( 'X', 'EconomicAppIdentifier', 'e-conomic Soap API' ); |
24 |
| - } ); |
25 |
| - } |
26 |
| - |
27 |
| - public function auth( $agreement = null, $secret = null ) { |
28 |
| - $agreement = $agreement ?? $this->agreement; |
29 |
| - $secret = $secret ?? $this->secret; |
30 |
| - |
31 |
| - $this->soap->call( 'economic.ConnectWithToken', [ |
32 |
| - 'ConnectWithToken' => [ |
33 |
| - 'token' => $agreement, |
34 |
| - 'appSecretToken' => $secret, |
35 |
| - 'appToken' => $secret, |
36 |
| - ], |
37 |
| - ] ); |
38 |
| - |
39 |
| - return $this; |
40 |
| - } |
41 |
| - |
42 |
| - public function getPayments( $toDate = null ) { |
43 |
| - $items = $this->getAllOpenDebtorEntries()->where( 'Type', '=', 'DebtorPayment' ); |
44 |
| - |
45 |
| - if ( $toDate !== null ) { |
46 |
| - $items = $items->where( 'Date', '<=', $toDate ); |
47 |
| - } |
48 |
| - |
49 |
| - return $items; |
50 |
| - } |
51 |
| - |
52 |
| - public function postOrder( Order $order ) { |
53 |
| - return $this->soap->call( 'economic.Order_CreateFromData', [ |
54 |
| - 'Order_CreateFromData' => [ |
55 |
| - 'data' => $order->format(), |
56 |
| - ], |
57 |
| - ] )->Order_CreateFromDataResult; |
58 |
| - } |
59 |
| - |
60 |
| - public function getAllOpenDebtorEntries() { |
61 |
| - $openEntries = $this->soap->call( 'economic.DebtorEntry_GetAllOpenEntries' )->DebtorEntry_GetAllOpenEntriesResult; |
62 |
| - |
63 |
| - $entries = collect( [] ); |
64 |
| - |
65 |
| - if ( ! isset( $openEntries->DebtorEntryHandle ) ) { |
66 |
| - return $entries; |
67 |
| - } |
68 |
| - |
69 |
| - $openEntries = $openEntries->DebtorEntryHandle; |
70 |
| - |
71 |
| - $handles = []; |
72 |
| - foreach ( $openEntries as $openEntry ) { |
73 |
| - if ( ! isset( $openEntry->SerialNumber ) ) { |
74 |
| - continue; |
75 |
| - } |
76 |
| - |
77 |
| - $handles[] = [ 'SerialNumber' => $openEntry->SerialNumber ]; |
78 |
| - } |
79 |
| - |
80 |
| - if ( count( $handles ) > 0 ) { |
81 |
| - try { |
82 |
| - $entryResponse = $this->soap->call( 'economic.DebtorEntry_GetDataArray', [ |
83 |
| - 'DebtorEntry_GetDataArray' => [ |
84 |
| - 'entityHandles' => $handles, |
85 |
| - ], |
86 |
| - ] )->DebtorEntry_GetDataArrayResult; |
87 |
| - } catch ( \SoapFault $exception ) { |
88 |
| - throw $exception; |
89 |
| - } |
90 |
| - |
91 |
| - if ( isset( $entryResponse->DebtorEntryData ) ) { |
92 |
| - foreach ( $entryResponse->DebtorEntryData as $item ) { |
93 |
| - $entries->push( $item ); |
94 |
| - } |
95 |
| - } |
96 |
| - } |
97 |
| - |
98 |
| - return $entries; |
99 |
| - } |
100 |
| - |
101 |
| - public function getAllCashbooksEntries() { |
102 |
| - $cashbooks = $this->soap->call( 'economic.CashBook_GetAll' )->CashBook_GetAllResult; |
103 |
| - |
104 |
| - $entries = collect( [] ); |
105 |
| - |
106 |
| - if ( ! isset( $cashbooks->CashBookHandle ) ) { |
107 |
| - return $entries; |
108 |
| - } |
109 |
| - |
110 |
| - $cashbooks = $cashbooks->CashBookHandle; |
111 |
| - |
112 |
| - $handles = []; |
113 |
| - foreach ( $cashbooks as $cashbook ) { |
114 |
| - if ( ! isset( $cashbook->Number ) ) { |
115 |
| - continue; |
116 |
| - } |
117 |
| - |
118 |
| - $handles[] = [ 'Number' => $cashbook->Number ]; |
119 |
| - } |
120 |
| - |
121 |
| - if ( count( $handles ) > 0 ) { |
122 |
| - try { |
123 |
| - $cashbookResponse = $this->soap->call( 'economic.CashBook_GetDataArray', [ |
124 |
| - 'CashBook_GetDataArray' => [ |
125 |
| - 'entityHandles' => $handles, |
126 |
| - ], |
127 |
| - ] )->CashBook_GetDataArrayResult; |
128 |
| - } catch ( \SoapFault $exception ) { |
129 |
| - throw $exception; |
130 |
| - } |
131 |
| - |
132 |
| - if ( isset( $cashbookResponse->CashBookData ) ) { |
133 |
| - foreach ( $cashbookResponse->CashBookData as $item ) { |
134 |
| - $entries->push( $item ); |
135 |
| - } |
136 |
| - } |
137 |
| - } |
138 |
| - |
139 |
| - return $entries; |
140 |
| - } |
141 |
| - |
142 |
| - public function createCahBookEntryFromData( $data ) { |
143 |
| - return $this->soap->call( 'economic.CashBookEntry_CreateFromData', [ |
144 |
| - 'CashBookEntry_CreateFromData' => [ |
145 |
| - 'data' => $data, |
146 |
| - ], |
147 |
| - ] )->CashBookEntry_CreateFromDataResult; |
148 |
| - } |
149 |
| - |
150 |
| - public function createCashBookEntriesFromArray( $data ) { |
151 |
| - return $this->soap->call( 'economic.CashBookEntry_CreateFromDataArray', [ |
152 |
| - 'CashBookEntry_CreateFromDataArray' => [ |
153 |
| - 'dataArray' => $data, |
154 |
| - ], |
155 |
| - ] )->CashBookEntry_CreateFromDataArrayResult; |
156 |
| - } |
157 |
| - |
158 |
| - public function createProjectsFromArray( $data ) { |
159 |
| - return $this->soap->call( 'economic.Project_CreateFromDataArray', [ |
160 |
| - 'Project_CreateFromDataArray' => [ |
161 |
| - 'dataArray' => $data, |
162 |
| - ], |
163 |
| - ] )->Project_CreateFromDataArrayResult; |
164 |
| - } |
| 11 | + public $soap; |
| 12 | + protected $secret; |
| 13 | + protected $agreement; |
| 14 | + |
| 15 | + public function __construct($agreement = '', $secret = null) |
| 16 | + { |
| 17 | + $this->agreement = $agreement ?? config('economic.agreement'); |
| 18 | + $this->secret = $secret ?? config('economic.secret_token'); |
| 19 | + |
| 20 | + $this->soap = new SoapWrapper(); |
| 21 | + $this->soap->add('economic', function (Service $service) { |
| 22 | + $service->wsdl('https://api.e-conomic.com/secure/api1/EconomicWebservice.asmx?WSDL') |
| 23 | + ->trace(true) |
| 24 | + ->header('X', 'EconomicAppIdentifier', 'e-conomic Soap API'); |
| 25 | + }); |
| 26 | + } |
| 27 | + |
| 28 | + public function auth($agreement = null, $secret = null) |
| 29 | + { |
| 30 | + $agreement = $agreement ?? $this->agreement; |
| 31 | + $secret = $secret ?? $this->secret; |
| 32 | + |
| 33 | + $this->soap->call('economic.ConnectWithToken', [ |
| 34 | + 'ConnectWithToken' => [ |
| 35 | + 'token' => $agreement, |
| 36 | + 'appSecretToken' => $secret, |
| 37 | + 'appToken' => $secret, |
| 38 | + ], |
| 39 | + ]); |
| 40 | + |
| 41 | + return $this; |
| 42 | + } |
| 43 | + |
| 44 | + public function getPayments($toDate = null) |
| 45 | + { |
| 46 | + $items = $this->getAllOpenDebtorEntries()->where('Type', '=', 'DebtorPayment'); |
| 47 | + |
| 48 | + if ($toDate !== null) { |
| 49 | + $items = $items->where('Date', '<=', $toDate); |
| 50 | + } |
| 51 | + |
| 52 | + return $items; |
| 53 | + } |
| 54 | + |
| 55 | + public function postOrder(Order $order) |
| 56 | + { |
| 57 | + return $this->soap->call('economic.Order_CreateFromData', [ |
| 58 | + 'Order_CreateFromData' => [ |
| 59 | + 'data' => $order->format(), |
| 60 | + ], |
| 61 | + ])->Order_CreateFromDataResult; |
| 62 | + } |
| 63 | + |
| 64 | + public function getAllOpenDebtorEntries() |
| 65 | + { |
| 66 | + $openEntries = $this->soap->call('economic.DebtorEntry_GetAllOpenEntries')->DebtorEntry_GetAllOpenEntriesResult; |
| 67 | + |
| 68 | + $entries = collect([]); |
| 69 | + |
| 70 | + if (!isset($openEntries->DebtorEntryHandle)) { |
| 71 | + return $entries; |
| 72 | + } |
| 73 | + |
| 74 | + $openEntries = $openEntries->DebtorEntryHandle; |
| 75 | + |
| 76 | + $handles = []; |
| 77 | + foreach ($openEntries as $openEntry) { |
| 78 | + if (!isset($openEntry->SerialNumber)) { |
| 79 | + continue; |
| 80 | + } |
| 81 | + |
| 82 | + $handles[] = ['SerialNumber' => $openEntry->SerialNumber]; |
| 83 | + } |
| 84 | + |
| 85 | + if (count($handles) > 0) { |
| 86 | + try { |
| 87 | + $entryResponse = $this->soap->call('economic.DebtorEntry_GetDataArray', [ |
| 88 | + 'DebtorEntry_GetDataArray' => [ |
| 89 | + 'entityHandles' => $handles, |
| 90 | + ], |
| 91 | + ])->DebtorEntry_GetDataArrayResult; |
| 92 | + } catch (\SoapFault $exception) { |
| 93 | + throw $exception; |
| 94 | + } |
| 95 | + |
| 96 | + if (isset($entryResponse->DebtorEntryData)) { |
| 97 | + foreach ($entryResponse->DebtorEntryData as $item) { |
| 98 | + $entries->push($item); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + return $entries; |
| 104 | + } |
| 105 | + |
| 106 | + public function getAllCashbooksEntries() |
| 107 | + { |
| 108 | + $cashbooks = $this->soap->call('economic.CashBook_GetAll')->CashBook_GetAllResult; |
| 109 | + |
| 110 | + $entries = collect([]); |
| 111 | + |
| 112 | + if (!isset($cashbooks->CashBookHandle)) { |
| 113 | + return $entries; |
| 114 | + } |
| 115 | + |
| 116 | + $cashbooks = $cashbooks->CashBookHandle; |
| 117 | + |
| 118 | + $handles = []; |
| 119 | + foreach ($cashbooks as $cashbook) { |
| 120 | + if (!isset($cashbook->Number)) { |
| 121 | + continue; |
| 122 | + } |
| 123 | + |
| 124 | + $handles[] = ['Number' => $cashbook->Number]; |
| 125 | + } |
| 126 | + |
| 127 | + if (count($handles) > 0) { |
| 128 | + try { |
| 129 | + $cashbookResponse = $this->soap->call('economic.CashBook_GetDataArray', [ |
| 130 | + 'CashBook_GetDataArray' => [ |
| 131 | + 'entityHandles' => $handles, |
| 132 | + ], |
| 133 | + ])->CashBook_GetDataArrayResult; |
| 134 | + } catch (\SoapFault $exception) { |
| 135 | + throw $exception; |
| 136 | + } |
| 137 | + |
| 138 | + if (isset($cashbookResponse->CashBookData)) { |
| 139 | + foreach ($cashbookResponse->CashBookData as $item) { |
| 140 | + $entries->push($item); |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + return $entries; |
| 146 | + } |
| 147 | + |
| 148 | + public function createCahBookEntryFromData($data) |
| 149 | + { |
| 150 | + return $this->soap->call('economic.CashBookEntry_CreateFromData', [ |
| 151 | + 'CashBookEntry_CreateFromData' => [ |
| 152 | + 'data' => $data, |
| 153 | + ], |
| 154 | + ])->CashBookEntry_CreateFromDataResult; |
| 155 | + } |
| 156 | + |
| 157 | + public function createCashBookEntriesFromArray($data) |
| 158 | + { |
| 159 | + return $this->soap->call('economic.CashBookEntry_CreateFromDataArray', [ |
| 160 | + 'CashBookEntry_CreateFromDataArray' => [ |
| 161 | + 'dataArray' => $data, |
| 162 | + ], |
| 163 | + ])->CashBookEntry_CreateFromDataArrayResult; |
| 164 | + } |
| 165 | + |
| 166 | + public function createProjectsFromArray($data) |
| 167 | + { |
| 168 | + return $this->soap->call('economic.Project_CreateFromDataArray', [ |
| 169 | + 'Project_CreateFromDataArray' => [ |
| 170 | + 'dataArray' => $data, |
| 171 | + ], |
| 172 | + ])->Project_CreateFromDataArrayResult; |
| 173 | + } |
165 | 174 | }
|
0 commit comments