A small package to communicate with Microsoft Navision. You can fetch collections and single records.
Run following commands:
composer require volldigital/laravel-navision
php artisan vendor:publish --provider="VOLLdigital\LaravelNavision\LaravelNavisionServiceProvider"
Edit your "config/ntlm.php" file or use the ENV variables.
After setting up your config, load the client via:
$client = app(VOLLdigital\LaravelNavision\Client::class);
Now you are ready to recieve data from your Navision.
Examples:
$client = app(VOLLdigital\LaravelNavision\Client::class);
$data = $client->fetchCollection("Events");
$event = $client->fetchOne("Events", 'Key', 'Number');
You can also pull data chunk-wise. The data will be written in a text file and after the request finished, it will be parsed and deleted.
$client = app(VOLLdigital\LaravelNavision\Client::class);
// file will be stored in /storage/app/temp/curl_uniqueid.temp
$data = $client->fetchCollection("Events", true);
You want to check if your connection to UNITOP is established? You can use the ping function and check it :)
$client = app(VOLLdigital\LaravelNavision\Client::class);
if ($client->ping() === false) {
throw new RunTimeException('No connection available');
}
Use $client->writeData(string $url, array $data);
to write data into navision.
Example:
$client->writeData(
'Items',
[
'Item_Code' => 'VD',
'Item_Description' => 'Test data'
]
);
Use $client->countCollection("YourCollection")
to recieve the amount of items in this collection.
Example:
dd($client->countCollection('Events')); // Outputs: 100293
- $skip=XXXX - Skip X amount of itmes
$temp = $this->client->fetchCollection('Events?$skip=10000');
- $top=XXXX - Recieve X amount of items
$temp = $this->client->fetchCollection('Events?$top=10');
protected function fetchData(string $uri, $key, bool $chunk = false, ?callable $filter = null)
{
$temp = $this->client->fetchCollection($uri, $chunk);
$data = [];
foreach($temp as $ts) {
if (!is_null($filter) && $filter($ts) === false) {
continue;
}
$data[$ts[$key]] = $ts;
}
return collect($data);
}
protected function fetchAll()
{
$number = $this->client->countCollection('Events');
$pageLimit = 10000;
$pages = (int)ceil($number / $pageLimit);
$events = [];
for ($i = 0; $i < $pages; $i++) {
$skip = $i * $pageLimit;
$temp = $this->fetchData('Events?$skip='.$skip, 'Number');
$events = array_merge($events, $temp->toArray());
}
return collect($events);
}