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