Coder Social home page Coder Social logo

volldigital / laravel-navision Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 4.0 136 KB

Fetch any data from navision using ntlm

License: MIT License

PHP 100.00%
laravel unitop microsoft navision ntlm package laravel-navision laravel-ntlm laravel6 laravel5 laravel-framework laravel-5-package laravel-6-package

laravel-navision's Introduction

Laravel Navision Package (For Laravel V5.8 & 6.X)

A small package to communicate with Microsoft Navision. You can fetch collections and single records.

Install

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.

Usage

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');
}

Write data

Use $client->writeData(string $url, array $data); to write data into navision.

Example:

$client->writeData(
    'Items',
    [
        'Item_Code' => 'VD',
        'Item_Description' => 'Test data'
    ]
);

Count items

Use $client->countCollection("YourCollection") to recieve the amount of items in this collection.

Example:

dd($client->countCollection('Events')); // Outputs: 100293

Examples

Query params

  • $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');

Fetching data

    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);
    }

Pagination

    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);
    }

laravel-navision's People

Contributors

dependabot[bot] avatar saiik avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.