Skip to content

Commit

Permalink
Allow use of parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Vítězslav Dvořák committed Oct 17, 2023
1 parent 891e140 commit 11d1769
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 37 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,51 @@ INSPECTION_DEFECTS_COMMUNAL_AREA, INSPECTION_DEFECTS_COMBINED.
The last column contains the unique defect ID from the Realpad database. The second column
is the relevant deal ID.

```php
$client = new \SpojeNet\Realpad\ApiClient();
$defects = $client->listDefects('DEAL_DEFECTS');
print_r($defects);
```

<pre>
Array
(
[2] => Array
(
[Projekt] => Nove Sidliste
[Obchodní případ] => 12323234
[Typ kontroly] => Technická přejímka
[Typ položky technické přejímky] => Podlahy
[Jednotka] => TEST TECHNICKÁ PŘEJÍMKA
[Zákazník] => REALPAD TEST
[Telefon] =>
[E-mail] => [email protected]
[Číslo vady] => 25456542
[Problémová vada] => Ne
[Číslo vady dle zákazníka] =>
[Popis] => prasklá dlažba
[Lokace (např. místnost)] =>
[Poslední vyjádření developera] =>
[Odesláno zákazníkovi] =>
[Poslední vyjádření dodavatele] =>
[Přijato dne] => 7/7/2023
[Termín pro odstranění vady] => 8/6/2023
[Plánovaný termín opravy] =>
[Odstraněna dne] =>
[Poznámka] =>
[Odpovědná osoba] =>
[Speciální záruční lhůta] => Ne
[Stav] => Přijato do evidence
[Část bytu které sa vada týká] =>
[Běžný problém] =>
[Místnost, které se vada týká] => Koupelna/WC
[Dodavatel] =>
[Generální dodavatel] =>
[Reklamace ID] => 25654654
)

</pre>

**list-excel-tasks**
The last columns contain the task ID, customer ID, and sales agent ID from the Realpad
database.
Expand Down Expand Up @@ -209,6 +254,7 @@ data of its Lines.
## Appendix

Unit status enumeration

● 0 - free.

● 1 - pre-reserved.
Expand Down
11 changes: 11 additions & 0 deletions examples/listdefectsdeal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

\Ease\Shared::init(['REALPAD_USERNAME', 'REALPAD_PASSWORD'], '../.env');

$client = new \SpojeNet\Realpad\ApiClient();

$projects = $client->listDefects('DEAL_DEFECTS');

print_r($projects);
145 changes: 108 additions & 37 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,56 @@ class ApiClient extends \Ease\Sand
*/
private $lastResponseCode;

/**
* @var array Unit status enumeration
*/
public $unitStatus = [
0 => 'free',
1 => 'pre-reserved',
2 => 'reserved',
3 => 'sold',
4 => 'not for sale',
5 => 'delayed'
];

/**
* @var array Unit type enumeration
*/
public $unitType = [
1 => 'flat',
2 => 'parking',
3 => 'cellar',
4 => 'outdoor parking',
5 => 'garage',
6 => 'commercial space',
7 => 'family house',
8 => 'land',
9 => 'atelier',
10 => 'office',
11 => 'art workshop',
12 => 'non-residential unit',
13 => 'motorbike parking',
14 => 'creative workshop',
15 => 'townhouse',
16 => 'utility room',
17 => 'condominium',
18 => 'storage',
19 => 'apartment',
20 => 'accommodation unit',
21 => 'bike stand',
22 => 'communal area'
];

/**
* RealPad Data obtainer
*
* @var string $username - leave empty to use Environment or constant REALPAD_USERNAME
* @var string $password - leave empty to use Environment or constant REALPAD_PASSWORD
*/
public function __construct()
public function __construct($username = '', $password = '')
{
$this->apiUsername = \Ease\Shared::cfg('REALPAD_USERNAME');
$this->apiPassword = \Ease\Shared::cfg('REALPAD_PASSWORD');
$this->apiUsername = strlen($username) ? $username : \Ease\Shared::cfg('REALPAD_USERNAME');
$this->apiPassword = strlen($password) ? $password : \Ease\Shared::cfg('REALPAD_PASSWORD');
$this->curlInit();
$this->setObjectName();
}
Expand Down Expand Up @@ -117,11 +160,6 @@ public function curlInit()
CURLOPT_USERAGENT,
'RealpadTakeout v' . \Ease\Shared::appVersion() . ' https://github.com/Spoje-NET/Realpad-Takeout'
);
\curl_setopt(
$this->curl,
CURLOPT_POSTFIELDS,
'login=' . $this->apiUsername . '&password=' . $this->apiPassword
);
return $this->curl;
}

Expand All @@ -133,8 +171,16 @@ public function curlInit()
*
* @return int HTTP Response CODE
*/
public function doCurlRequest($url, $method = 'GET')
public function doCurlRequest($url, $method = 'GET', $postParams = [])
{
\curl_setopt(
$this->curl,
CURLOPT_POSTFIELDS,
array_merge(
['login' => $this->apiUsername, 'password' => $this->apiPassword],
$postParams
)
);
curl_setopt($this->curl, CURLOPT_URL, $url);

curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
Expand Down Expand Up @@ -256,9 +302,9 @@ public function __destruct()
*
* @return array
*/
public function getExcelData($endpoint)
public function getExcelData($endpoint, $params = [])
{
$responseCode = $this->doCurlRequest($this->baseEndpoint . 'ws/v10/' . $endpoint, 'POST');
$responseCode = $this->doCurlRequest($this->baseEndpoint . 'ws/v10/' . $endpoint, 'POST', $params);
$excelData = [];
if ($responseCode == 200) {
$xls = sys_get_temp_dir() . '/' . $endpoint . '_' . \Ease\Functions::randomString() . '.xls';
Expand Down Expand Up @@ -379,21 +425,36 @@ public function listInspections()
* Accepts an additional optional parameter mode. By default all the Deal
* Warranty Claim Defects are returned. Certain developers will also see the
* Communal Areas Defects here by default. If mode is specified, other
* Defects can be returned. Available modes are:
* DEAL_DEFECTS, DEAL_DEFECTS_COMMUNAL_AREA, DEAL_DEFECTS_COMBINED,
* INSPECTION_DEFECTS, INSPECTION_DEFECTS_COMMUNAL_AREA,
* INSPECTION_DEFECTS_COMBINED.
* Defects can be returned.
*
* The last column contains the unique defect ID from the Realpad database.
* The second column is the relevant deal ID.
*
* @todo Implement Modes
*
* @var string mode none or one from: DEAL_DEFECTS,
* DEAL_DEFECTS_COMMUNAL_AREA,
* DEAL_DEFECTS_COMBINED,
* INSPECTION_DEFECTS,
* INSPECTION_DEFECTS_COMMUNAL_AREA,
* INSPECTION_DEFECTS_COMBINED.
*
* @return array
*/
public function listDefects()
public function listDefects($mode = '')
{
return $this->getExcelData('list-excel-defects');
$modesAvailble = [
'DEAL_DEFECTS',
'DEAL_DEFECTS_COMMUNAL_AREA',
'DEAL_DEFECTS_COMBINED',
'INSPECTION_DEFECTS',
'INSPECTION_DEFECTS_COMMUNAL_AREA',
'INSPECTION_DEFECTS_COMBINED'
];
if (strlen($mode) && (array_search($mode, $modesAvailble) === false)) {
throw new \SpojeNet\Realpad\Exception('Iillegal inspection Mode ' . $mode);
}
return $this->getExcelData('list-excel-defects', ['mode' => $mode]);
}

/**
Expand Down Expand Up @@ -429,43 +490,53 @@ public function listSalesStatus()
}

/**
* Accepts an additional required parameter unitid, which has to be a valid
* unit Realpad database ID obtained from some other endpoint.
* The first column contains the timestamp of when the given unit started
* containing the data on the given row. The second column contains the name
* of the user who caused that data to be recorded.
*
* @var int $unitID Required parameter unitid, which has to be a valid unit
* Realpad database ID obtained from some other endpoint.
*
* @return array
*/
public function listUnitHistory()
public function listUnitHistory(int $unitID)
{
return $this->getExcelData('list-excel-unit-history');
return $this->getExcelData('list-excel-unit-history', ['unitid' => $unitID]);
}

/**
* Accepts several additional optional parameters:
* ● `filter_status` - if left empty, invoices in all statuses are sent. 1 - new invoices. 2 -
* invoices in Review #1. 3 - invoices in Review #2. 4 - invoices in approval. 5 - fully
* approved invoices. 6 - fully rejected invoices.
* Listing of Invoices. The initial set of columns describes the Invoice
* itself, and the last set of columns contains the data of its Lines.
*
* @var array $options ● `filter_status` - if left empty, invoices in all statuses are sent. 1 - new invoices. 2 -
* invoices in Review #1. 3 - invoices in Review #2. 4 - invoices in approval. 5 - fully
* approved invoices. 6 - fully rejected invoices.
*
* ● `filter_groupcompany` - if left empty, invoices from all the group companies are sent. If
* Realpad database IDs of group companies are provided (as a comma-separated list),
* then only invoices from these companies are sent.
* ● `filter_groupcompany` - if left empty, invoices from all the group companies are sent. If
* Realpad database IDs of group companies are provided (as a comma-separated list),
* then only invoices from these companies are sent.
*
* ● `filter_issued_from`` - specify a date in the 2019-12-31 format to only send invoices
* issues after that date.
* ● `filter_issued_from` - specify a date in the 2019-12-31 format to only send invoices
* issues after that date.
*
* ● `filter_issued_to` - specify a date in the 2019-12-31 format to only send invoices issues
* before that date.
* The initial set of columns describes the Invoice itself, and the last set of columns contains the
* data of its Lines.
* ● `filter_issued_to` - specify a date in the 2019-12-31 format to only send invoices issues before that date.
*
* @todo Implement Filters
*
* @return array
*/
public function listInvoices()
public function listInvoices($options = [])
{
return $this->getExcelData('list-excel-invoices');
$colsAvailble = [
'filter_status',
'filter_groupcompany',
'filter_issued_from',
'filter_issued_to'
];
foreach ($options as $key => $value) {
if (array_search($key, $colsAvailble) === false) {
throw new \SpojeNet\Realpad\Exception('Iillegal Invoice option ' . $key);
}
}
return $this->getExcelData('list-excel-invoices', $options);
}
}

0 comments on commit 11d1769

Please sign in to comment.