Skip to content

Commit 11d1769

Browse files
author
Vítězslav Dvořák
committed
Allow use of parameters
1 parent 891e140 commit 11d1769

File tree

3 files changed

+165
-37
lines changed

3 files changed

+165
-37
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,51 @@ INSPECTION_DEFECTS_COMMUNAL_AREA, INSPECTION_DEFECTS_COMBINED.
170170
The last column contains the unique defect ID from the Realpad database. The second column
171171
is the relevant deal ID.
172172

173+
```php
174+
$client = new \SpojeNet\Realpad\ApiClient();
175+
$defects = $client->listDefects('DEAL_DEFECTS');
176+
print_r($defects);
177+
```
178+
179+
<pre>
180+
Array
181+
(
182+
[2] => Array
183+
(
184+
[Projekt] => Nove Sidliste
185+
[Obchodní případ] => 12323234
186+
[Typ kontroly] => Technická přejímka
187+
[Typ položky technické přejímky] => Podlahy
188+
[Jednotka] => TEST TECHNICKÁ PŘEJÍMKA
189+
[Zákazník] => REALPAD TEST
190+
[Telefon] =>
191+
[E-mail] => [email protected]
192+
[Číslo vady] => 25456542
193+
[Problémová vada] => Ne
194+
[Číslo vady dle zákazníka] =>
195+
[Popis] => prasklá dlažba
196+
[Lokace (např. místnost)] =>
197+
[Poslední vyjádření developera] =>
198+
[Odesláno zákazníkovi] =>
199+
[Poslední vyjádření dodavatele] =>
200+
[Přijato dne] => 7/7/2023
201+
[Termín pro odstranění vady] => 8/6/2023
202+
[Plánovaný termín opravy] =>
203+
[Odstraněna dne] =>
204+
[Poznámka] =>
205+
[Odpovědná osoba] =>
206+
[Speciální záruční lhůta] => Ne
207+
[Stav] => Přijato do evidence
208+
[Část bytu které sa vada týká] =>
209+
[Běžný problém] =>
210+
[Místnost, které se vada týká] => Koupelna/WC
211+
[Dodavatel] =>
212+
[Generální dodavatel] =>
213+
[Reklamace ID] => 25654654
214+
)
215+
216+
</pre>
217+
173218
**list-excel-tasks**
174219
The last columns contain the task ID, customer ID, and sales agent ID from the Realpad
175220
database.
@@ -209,6 +254,7 @@ data of its Lines.
209254
## Appendix
210255

211256
Unit status enumeration
257+
212258
● 0 - free.
213259

214260
● 1 - pre-reserved.

examples/listdefectsdeal.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
\Ease\Shared::init(['REALPAD_USERNAME', 'REALPAD_PASSWORD'], '../.env');
6+
7+
$client = new \SpojeNet\Realpad\ApiClient();
8+
9+
$projects = $client->listDefects('DEAL_DEFECTS');
10+
11+
print_r($projects);

src/ApiClient.php

Lines changed: 108 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,56 @@ class ApiClient extends \Ease\Sand
8080
*/
8181
private $lastResponseCode;
8282

83+
/**
84+
* @var array Unit status enumeration
85+
*/
86+
public $unitStatus = [
87+
0 => 'free',
88+
1 => 'pre-reserved',
89+
2 => 'reserved',
90+
3 => 'sold',
91+
4 => 'not for sale',
92+
5 => 'delayed'
93+
];
94+
95+
/**
96+
* @var array Unit type enumeration
97+
*/
98+
public $unitType = [
99+
1 => 'flat',
100+
2 => 'parking',
101+
3 => 'cellar',
102+
4 => 'outdoor parking',
103+
5 => 'garage',
104+
6 => 'commercial space',
105+
7 => 'family house',
106+
8 => 'land',
107+
9 => 'atelier',
108+
10 => 'office',
109+
11 => 'art workshop',
110+
12 => 'non-residential unit',
111+
13 => 'motorbike parking',
112+
14 => 'creative workshop',
113+
15 => 'townhouse',
114+
16 => 'utility room',
115+
17 => 'condominium',
116+
18 => 'storage',
117+
19 => 'apartment',
118+
20 => 'accommodation unit',
119+
21 => 'bike stand',
120+
22 => 'communal area'
121+
];
122+
83123
/**
84124
* RealPad Data obtainer
125+
*
126+
* @var string $username - leave empty to use Environment or constant REALPAD_USERNAME
127+
* @var string $password - leave empty to use Environment or constant REALPAD_PASSWORD
85128
*/
86-
public function __construct()
129+
public function __construct($username = '', $password = '')
87130
{
88-
$this->apiUsername = \Ease\Shared::cfg('REALPAD_USERNAME');
89-
$this->apiPassword = \Ease\Shared::cfg('REALPAD_PASSWORD');
131+
$this->apiUsername = strlen($username) ? $username : \Ease\Shared::cfg('REALPAD_USERNAME');
132+
$this->apiPassword = strlen($password) ? $password : \Ease\Shared::cfg('REALPAD_PASSWORD');
90133
$this->curlInit();
91134
$this->setObjectName();
92135
}
@@ -117,11 +160,6 @@ public function curlInit()
117160
CURLOPT_USERAGENT,
118161
'RealpadTakeout v' . \Ease\Shared::appVersion() . ' https://github.com/Spoje-NET/Realpad-Takeout'
119162
);
120-
\curl_setopt(
121-
$this->curl,
122-
CURLOPT_POSTFIELDS,
123-
'login=' . $this->apiUsername . '&password=' . $this->apiPassword
124-
);
125163
return $this->curl;
126164
}
127165

@@ -133,8 +171,16 @@ public function curlInit()
133171
*
134172
* @return int HTTP Response CODE
135173
*/
136-
public function doCurlRequest($url, $method = 'GET')
174+
public function doCurlRequest($url, $method = 'GET', $postParams = [])
137175
{
176+
\curl_setopt(
177+
$this->curl,
178+
CURLOPT_POSTFIELDS,
179+
array_merge(
180+
['login' => $this->apiUsername, 'password' => $this->apiPassword],
181+
$postParams
182+
)
183+
);
138184
curl_setopt($this->curl, CURLOPT_URL, $url);
139185

140186
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
@@ -256,9 +302,9 @@ public function __destruct()
256302
*
257303
* @return array
258304
*/
259-
public function getExcelData($endpoint)
305+
public function getExcelData($endpoint, $params = [])
260306
{
261-
$responseCode = $this->doCurlRequest($this->baseEndpoint . 'ws/v10/' . $endpoint, 'POST');
307+
$responseCode = $this->doCurlRequest($this->baseEndpoint . 'ws/v10/' . $endpoint, 'POST', $params);
262308
$excelData = [];
263309
if ($responseCode == 200) {
264310
$xls = sys_get_temp_dir() . '/' . $endpoint . '_' . \Ease\Functions::randomString() . '.xls';
@@ -379,21 +425,36 @@ public function listInspections()
379425
* Accepts an additional optional parameter mode. By default all the Deal
380426
* Warranty Claim Defects are returned. Certain developers will also see the
381427
* Communal Areas Defects here by default. If mode is specified, other
382-
* Defects can be returned. Available modes are:
383-
* DEAL_DEFECTS, DEAL_DEFECTS_COMMUNAL_AREA, DEAL_DEFECTS_COMBINED,
384-
* INSPECTION_DEFECTS, INSPECTION_DEFECTS_COMMUNAL_AREA,
385-
* INSPECTION_DEFECTS_COMBINED.
428+
* Defects can be returned.
386429
*
387430
* The last column contains the unique defect ID from the Realpad database.
388431
* The second column is the relevant deal ID.
389432
*
390433
* @todo Implement Modes
391434
*
435+
* @var string mode none or one from: DEAL_DEFECTS,
436+
* DEAL_DEFECTS_COMMUNAL_AREA,
437+
* DEAL_DEFECTS_COMBINED,
438+
* INSPECTION_DEFECTS,
439+
* INSPECTION_DEFECTS_COMMUNAL_AREA,
440+
* INSPECTION_DEFECTS_COMBINED.
441+
*
392442
* @return array
393443
*/
394-
public function listDefects()
444+
public function listDefects($mode = '')
395445
{
396-
return $this->getExcelData('list-excel-defects');
446+
$modesAvailble = [
447+
'DEAL_DEFECTS',
448+
'DEAL_DEFECTS_COMMUNAL_AREA',
449+
'DEAL_DEFECTS_COMBINED',
450+
'INSPECTION_DEFECTS',
451+
'INSPECTION_DEFECTS_COMMUNAL_AREA',
452+
'INSPECTION_DEFECTS_COMBINED'
453+
];
454+
if (strlen($mode) && (array_search($mode, $modesAvailble) === false)) {
455+
throw new \SpojeNet\Realpad\Exception('Iillegal inspection Mode ' . $mode);
456+
}
457+
return $this->getExcelData('list-excel-defects', ['mode' => $mode]);
397458
}
398459

399460
/**
@@ -429,43 +490,53 @@ public function listSalesStatus()
429490
}
430491

431492
/**
432-
* Accepts an additional required parameter unitid, which has to be a valid
433-
* unit Realpad database ID obtained from some other endpoint.
434493
* The first column contains the timestamp of when the given unit started
435494
* containing the data on the given row. The second column contains the name
436495
* of the user who caused that data to be recorded.
437496
*
497+
* @var int $unitID Required parameter unitid, which has to be a valid unit
498+
* Realpad database ID obtained from some other endpoint.
499+
*
438500
* @return array
439501
*/
440-
public function listUnitHistory()
502+
public function listUnitHistory(int $unitID)
441503
{
442-
return $this->getExcelData('list-excel-unit-history');
504+
return $this->getExcelData('list-excel-unit-history', ['unitid' => $unitID]);
443505
}
444506

445507
/**
446-
* Accepts several additional optional parameters:
447-
* ● `filter_status` - if left empty, invoices in all statuses are sent. 1 - new invoices. 2 -
448-
* invoices in Review #1. 3 - invoices in Review #2. 4 - invoices in approval. 5 - fully
449-
* approved invoices. 6 - fully rejected invoices.
508+
* Listing of Invoices. The initial set of columns describes the Invoice
509+
* itself, and the last set of columns contains the data of its Lines.
510+
*
511+
* @var array $options ● `filter_status` - if left empty, invoices in all statuses are sent. 1 - new invoices. 2 -
512+
* invoices in Review #1. 3 - invoices in Review #2. 4 - invoices in approval. 5 - fully
513+
* approved invoices. 6 - fully rejected invoices.
450514
*
451-
* ● `filter_groupcompany` - if left empty, invoices from all the group companies are sent. If
452-
* Realpad database IDs of group companies are provided (as a comma-separated list),
453-
* then only invoices from these companies are sent.
515+
* ● `filter_groupcompany` - if left empty, invoices from all the group companies are sent. If
516+
* Realpad database IDs of group companies are provided (as a comma-separated list),
517+
* then only invoices from these companies are sent.
454518
*
455-
* ● `filter_issued_from`` - specify a date in the 2019-12-31 format to only send invoices
456-
* issues after that date.
519+
* ● `filter_issued_from` - specify a date in the 2019-12-31 format to only send invoices
520+
* issues after that date.
457521
*
458-
* ● `filter_issued_to` - specify a date in the 2019-12-31 format to only send invoices issues
459-
* before that date.
460-
* The initial set of columns describes the Invoice itself, and the last set of columns contains the
461-
* data of its Lines.
522+
* ● `filter_issued_to` - specify a date in the 2019-12-31 format to only send invoices issues before that date.
462523
*
463-
* @todo Implement Filters
464524
*
465525
* @return array
466526
*/
467-
public function listInvoices()
527+
public function listInvoices($options = [])
468528
{
469-
return $this->getExcelData('list-excel-invoices');
529+
$colsAvailble = [
530+
'filter_status',
531+
'filter_groupcompany',
532+
'filter_issued_from',
533+
'filter_issued_to'
534+
];
535+
foreach ($options as $key => $value) {
536+
if (array_search($key, $colsAvailble) === false) {
537+
throw new \SpojeNet\Realpad\Exception('Iillegal Invoice option ' . $key);
538+
}
539+
}
540+
return $this->getExcelData('list-excel-invoices', $options);
470541
}
471542
}

0 commit comments

Comments
 (0)