Click or drag to resize

IOBERONServiceGen2Stock_StockCards_List Method

EXALOGIC
Vracia zoznam skladových kariet. Bližší výber je možné určiť pomocou filtrov.

Namespace: Exa.OBERON.ServicesGen2
Assembly: Exa.OBERON.ServicesGen2 (in Exa.OBERON.ServicesGen2.dll) Version: 4.5.0.0 (4.5.0.0)
Syntax
ResultValue<StockCardsListData> Stock_StockCards_List(
	StockCardsListArg stockCardsListArg
)

Parameters

stockCardsListArg  StockCardsListArg
Objekt dodatočných nastavení StockCardListArg pre načítanie údajov skladových kariet, napr. sklad z ktorého majú byť načítané.

Return Value

ResultValueStockCardsListData
Vráti zoznam skladových kariet - vráti pole tried StockCard.
Remarks
V nasledovnom príklade je ukážka jednotlivých volaní - autentifikácia do webovej služby a načítanie zoznamu skladových kariet. Uvedený kód je možné uložiť do html súboru a následne otvoriť v internetovom prehliadači.
Príklad volania API priamo z html stránky pomocou Java skriptov
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Test webovej služby</title>
    <style>*,::after,::before{box-sizing:border-box}html,body{width:100%;font-family:"Segoe UI",Roboto,Arial,Helvetica,sans-serif}input,button{margin:0}.right{text-align:right}.tb td,.tb th{padding:4px}.tb{border:solid 1px gray;border-spacing:0}.tb thead tr{background-color:#e6e6e6;background-image:linear-gradient(top,#eeeeee,#dadada)}.resr,.resrh{margin-bottom:.3em}.resrh{font-size:1.3em}.reserr{color:firebrick}.resok{color:blue}.m3{margin-bottom:1rem!important}.frm,#resDSata{width:33.33%;background-color:#efefef;display:block;padding:1.5rem}#resData{background-color:#fefefe}.flbl{margin-bottom:.5rem;display:inline-block}.fctl{display:block;width:100%;padding:.375rem .75rem;font-size:1rem;line-height:1.5;color:#212529;background-color:#fff;background-clip:padding-box;border:1px solid #ced4da;border-radius:.375rem;transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out}.fctl:focus{color:#212529;background-color:#fff;border-color:#81d4fa;outline:0;box-shadow:0 0 0 .25rem #0d6efd40}.btn{padding:.375rem .75rem;font-size:1rem;line-height:1.5;color:#fff;background-color:#0d6efd;border:1px solid #0d6efd;border-radius:.375rem;box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 1px rgba(0,0,0,.075);display:inline-block;text-align:center;text-decoration:none;vertical-align:middle;cursor:pointer;transition:color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out}</style>
</head>
<body>
    <div class="frm">
        <div class="m3">
            <label for="txtAddress" class="flbl">Adresa url:</label>
            <input type="text" id="tAdd" class="fctl" placeholder="adresa" value="http://localhost:21001/" />        
        </div>
        <div class="m3">
            <label for="txtUserName" class="flbl">Meno používateľa:</label>
            <input type="text" id="tUsrN" class="fctl" placeholder="meno" value="" />
        </div>
        <div class="m3">
            <label for="settPassword" class="flbl">Heslo používateľa:</label>
            <input type="text" id="tUsrP" class="fctl" placeholder="heslo" value="" />
        </div>
        <div class="bPnl">
            <button id="bSbt" class="btn" >Test</button>
        </div>        
    </div>
    <div id="resData"></div>
    <script src="https://my.exalogic.sk/cdn/zepto.min.js" type="text/javascript"></script>
    <script src="https://my.exalogic.sk/cdn/zepto.sha1.min.js" type="text/javascript"></script>

<script type="text/javascript">
    (function ($) {
    var _this = null;
    var Application = function () {
        return new Application.init();
    };
    _this = Application;

    Application.controls = {
        selAddress: '#tAdd',
        selUserName: '#tUsrN',
        selUserPass: '#tUsrP',
        selBtnSubmit: '#bSbt',
        selResultData: '#resData',
        ctlResultData: null
    };
    Application.userData = null;
    Application.userSalt = '';
    Application.token = ''; // overovací token


    Application.init = function () {
        // panel výsledkov
        _this.controls.ctlResultData = $(this.controls.selResultData);
        _this.controls.ctlResultData.empty();
        // tlačítko
        $(_this.controls.selBtnSubmit).on('click', function(){ Application.evhButtonClick(); });        
    };

    Application.evhButtonClick = function() {
        var exc = myException(''),
            baseUrl = getUrl();

        exc = Application.testPing(baseUrl);
        if(!exc.result) return;

        exc = Application.login(baseUrl);
        if(!exc.result) return;

        exc = Application.stockCards(baseUrl);
        if(!exc.result) return;

        exc = Application.logout(baseUrl);
        if(!exc.result) return;
    };


    /* -- Ping -- */
    Application.testPing = function(baseUrl) {
        var exc = myException(''), datah = {html:''}; // musí byť lebo js nie je ref parameter
        loadUrl = baseUrl + 'ping';            
        exc = ajaxHtml(loadUrl, datah);
        if (exc.result == false) { //--- nejaká chyba
            addLogRow('Ping', 1, exc.description);
        } else {
            addLogRow('Ping', 0, datah.html);
        }
        return exc;
    };

    /* -- Login -- */
    Application.login = function(baseUrl) {
        var exc = myException(''), datah, ajaxUrl;

        //načítanie salt pre posilnenie hesla
        data = dataResult();
        post = { userName: $(Application.controls.selUserName).val() };
        ajaxUrl = baseUrl + 'v1/user/login/salt';

        exc = ajaxPost(ajaxUrl, data, post);
        if (exc.result == false) { //--- nejaká chyba
            addLogRow('Salt', 1, exc.description);
            return exc;
        } else {
            Application.userSalt = data.data;
            addLogRow('Salt', 0, data.data);
        }

        //prihlásenie so šifrovaním sha1 a posilnením hesla pomocou salt
        post = { userLoginArg:{ UserName: $(Application.controls.selUserName).val(), Password: Zepto.fn.sha1(Application.userSalt + $(Application.controls.selUserPass).val()) }};
        data = dataResult();
        ajaxUrl = baseUrl + 'v1/user/login';
        exc = ajaxPost(ajaxUrl, data, post);
        if (exc.result == false) { //--- nejaká chyba
            addLogRow('Token', 1, exc.description);
            return exc;
        } else {
            addLogRow('Token', 0, Application.token);
        }

        //test prihlásenia
        data = dataResult();
        ajaxUrl = baseUrl + 'v1/user/login/verify/' + Application.token;            
        exc = ajaxGet(ajaxUrl, data);
        if (exc.result == false) { //--- nejaká chyba
            addLogRow('Login verify', 1, exc.description);
        } else {
            addLogRow('Login verify', 0);
        }
        return exc;
    };

    /* -- Logout -- */
    Application.logout = function(baseUrl) {
        var exc = myException(''),data;
        if(Application.token == null || Application.token.length == 0) {
            addLogRow('Logout', 1, 'No token');
            return exc;
        }
        data = dataResult();
        exc = ajaxGet(baseUrl + 'v1/user/logout/', data);
        if (exc.result == false) { //--- nejaká chyba
            addLogRow('Logout', 1, exc.description);
        } else {
            addLogRow('Logout', 0);
        }
        return exc;
    };

    /* -- Skladové karty -- */
    Application.stockCards = function(baseUrl) {
        _this.controls.ctlResultData.append('<div class="resrh">Skladové karty</div>');
        var exc = myException(''),data;
        if(Application.token == null || Application.token.length == 0) {
            exc.description = "No token."
            return exc;
        }
        //načítanie zoznamu skladov
        var stock = '';
        res = dataResult();
        ajaxUrl = baseUrl + 'v1/stock/list';
        post = {};
        exc = ajaxPost(ajaxUrl, res, post);
        if (exc.result == false) { //--- nejaká chyba
            addLogRow('Sklad', 1, exc.description);
            return exc;
        } else {
            if(res.data==null || res.data.length==0) {
                addLogRow('Sklad', 1, 'Zoznam skladov je prázdny.');
                return exc;
            }
            addLogRow('Sklad', 0, stock);
            var html = '<div class="resr">';
            html += '<table border="0" class="tb"><thead><tr><th>Názov</th></tr></thead><tbody>';
            res.data.forEach(function (item, index) {
                html += '<td>' + item.Name + '</td></tr>';
            });
            html += '</tbody></table></div>';
            _this.controls.ctlResultData.append(html);
            //použijeme prvý sklad
            stock = res.data[0].Name;
        }
        //načítanie dostupných filtrov použiteľných pre načítanie kariet
        res = dataResult();
        ajaxUrl = baseUrl + 'v1/stock/stock-card/list-settings';
        post = { stockCardsListSettingsArg: { StockName: stock } };
        exc = ajaxPost(ajaxUrl, res, post);
        if (exc.result == false) { //--- nejaká chyba
            addLogRow('Filter', 1, exc.description);
            return exc;
        } else {
            addLogRow('Filter', 0);
        }
        //načítanie zoznamu skladových kariet
        res = dataResult();
        ajaxUrl = baseUrl + 'v1/stock/stock-card/list';
        post = { stockCardsListArg: { 
            LoadSettings: {
                PageSize: 10, //počet záznamov na stránku
                PageIndex: 0, //index stránky (tzv. zero based)
                Filters: {}, // prípadné filtre
                Sort: {} // prípadné triedenie
            },
            StockOrStockGroupName: stock,
            } 
        };
        exc = ajaxPost(ajaxUrl, res, post);
        if (exc.result == false) { //--- nejaká chyba
            addLogRow('Karty', 1, exc.description);
            return exc;
        } else {
            if(res.data==null || res.data.Items==null || res.data.Items.length==0){
                addLogRow('Karty', 1, 'Zoznam kariet je prázdny.');
                return exc;
            }
            addLogRow('Karty', 0);
            var html = '<div class="resr">';
            html += '<table border="0" class="tb"><thead><tr><th>IDNum</th><th>Číslo</th><th>Názov</th><th class="right">Cena 1 s DPH</th></tr></thead><tbody>';
            res.data.Items.forEach(function (item, index) {
                html += '<tr><td>' + item.IDNum + '</td>';
                html += '<td>' + item.Number + '</td>';
                html += '<td>' + item.Name + '</td>';
                html += '<td class="right">' + item.PricesInfo.PriceWithVAT1 + '</td></tr>';
            });
            html += '</tbody></table></div>';
            _this.controls.ctlResultData.append(html);
        }
        return exc;
    };

    function addLogRow(header, type, message) {
        var h = header,m = message, c;
        if (type != 0) { 
            c = 'reserr';                
        } else {
            c = 'resok';
            m = m==null || m.length==0 ? 'OK' : m;
        }
        _this.controls.ctlResultData.append('<div class="resr">'+h+': <span class="'+c+'">'+m+'</span></div>');
    }

    function getUrl() {
        var urlBase = $(Application.controls.selAddress).val();
        if ( urlBase == '' || ( !urlBase.startsWith('http:') && ! urlBase.startsWith('https:') ) ) {
            urlBase = 'http://' + urlBase;
        }
        if ( ! urlBase.endsWith('/') ) { urlBase = urlBase + '/'; }
        return urlBase;
    }

    function ajaxGet(ajaxurl, rfResult, jdata, processdata) {
        var exc = myException('');
        if (!processdata) { processdata = false; }
        if (!jdata) { jdata = null; } else { jdata = JSON.stringify(jdata); }
        try {
            $.ajax({ type: 'GET', cache: false, async: false,
                dataType: 'json', contentType: 'application/json; charset=utf-8',
                url: ajaxurl, processData: processdata,
                data: jdata,
                headers: {'userData': Application.token},
                success: function (data, textStatus, xhr) {
                    dataResultGet(data, rfResult);
                    if (rfResult.result == false && rfResult.errNumber === 2) {
                        // chyba užívateľ nie je prihlásený
                    }
                    Application.token = xhr.getResponseHeader('userData');
                    exc.result = true;//--- default je true
                    if (rfResult.result == false) {
                        exc.result = false;
                        exc.errNumber = rfResult.errNumber;
                        exc.description = rfResult.description;
                    }                
                },
                error: function (xhr, exception, errorThrown) {
                    exc = z_GetAjaxException(xhr, exception, errorThrown);
                }
            });
        } catch (error) {            
        }
        return exc;
    }

    function ajaxPost(ajaxurl, rfResult, jdata, processdata) {
        var exc = myException('');
        if (!processdata) { processdata = false; }
        if (!jdata) { jdata = null; }
        try {
            $.ajax({
                type: 'POST', cache: false, async: false,
                dataType: 'json', contentType: 'application/json; charset=utf-8',
                url: ajaxurl, processData: processdata,
                data: JSON.stringify(jdata),
                headers: {'userData': Application.token},
                success: function (data, textStatus, xhr) {
                    dataResultGet(data, rfResult);
                    if (rfResult.result == false && rfResult.errNumber === 2) {
                        // chyba užívateľ nie je prihlásený
                    }
                    Application.token = xhr.getResponseHeader('userData');
                    exc.result = true;//--- default je true
                    if (rfResult.result == false) {
                        exc.result = false;
                        exc.errNumber = rfResult.errNumber;
                        exc.description = rfResult.description;
                    }
                },
                error: function (xhr, exception, errorThrown) {
                    exc = z_GetAjaxException(xhr, exception, errorThrown);
                }
            });
        } catch (error) {            
        }
        return exc;
    }

    function ajaxHtml(ajaxurl, rfResult, callType, jdata) {
        var exc = myException('');
        if (!callType) { callType = 'GET'; }
        try {
            $.ajax({
                type: callType, url: ajaxurl, cache: false, async: false,
                dataType: 'html', contentType: 'text/html; charset=utf-8',
                processData: false, data: JSON.stringify(jdata),
                headers: {'userData': Application.token},
                success: function (data, textStatus, xhr) {
                    rfResult.html = data;
                    Application.token = xhr.getResponseHeader('userData');                    
                    exc.result = true;
                },
                error: function (xhr, exception, errorThrown) {
                    exc = z_GetAjaxException(xhr, exception, errorThrown);
                }
            });
        } catch (error) {
        }
        return exc;
    }

    /* --- Support methods --- */

    function myException(descr, msg, errNum, res) { //exception object
        return { result: !res ? false : res, errNumber: !errNum ? 0 : errNum, message: !msg ? '' : msg, description: !descr ? '' : descr };
    };

    function dataResult() { //data result object
        return { result: false, errNumber: 0, description: '', data: null };
    };
    function dataResultGet(data, rfResult) {//rfResult musí byť inicializovaný pomocou 'dataResult'
        rfResult.result = data.result;
        rfResult.errNumber = data.errNumber;
        rfResult.description = data.description;
        rfResult.data = data.data;
    }

    function z_GetAjaxException(jqXHR, exception, errorThrown) {
        var exc = myException();

        if (jqXHR.status === 0) {
            exc = myException('Server webovej služby je v tejto chvíli nedostupný.', '', 111);
        } else if (jqXHR.status == 404) {
            exc = myException('Metóda pre spracovanie požiadavky nebola nájdená.', '', 404);
        } else if (jqXHR.status == 500) {
            exc = myException('Interná chyba servera webovej služby.', '', 500);
        } else if (exception === 'parsererror') {
            exc = myException('Chyba pre spracovaní JSON dát zo servera.', '', 900);
        } else if (exception === 'timeout') {
            exc = myException('Čas pre spracovanie požiadavky vypršal.', '', 901);
        } else if (exception === 'abort') {
            exc = myException('Asynchrónne volanie bolo prerušené.', '', 902);
        } else {
            exc = myException('Neznáma chyba.<br/>' + jqXHR.statusText, '', 99);
        }
        return exc;
    }


    window.Application = Application;
    window.Application.init();


})(Zepto);
</script>

</body>
</html>
Príklad prihlásenia do webovej služby - zasielané údaje v JSON formáte.
Príklad:  Prihlásenie používateľa do webovej služby
Url:  http://address:port/v1/user/login

Požiadavka:
{
        "userLoginArg": {
                "UserName":"system",
                "Password":"8750320f04a57f4c97edd992d67b8a2d65426abc"
        }
}


Odpoveď:
{
        "data": {
                "BranchName": null,
                "DocumentName": "Systémový používateľ",
                "GUID": "RAUQE3WAEFBR5Z6J7N2ONCXWVCYCJGZZJNL7KPQL",
                "PasswordType": 0,
                "ShortName": null,
                "UserIDNum": 1,
                "UserName": "system"
        },
        "description": "",
        "errNumber": 0,
        "result": true
}
Príklad vyvorenia novej skladovej karty - zasielané údaje v JSON formáte.
{
        "stockCardAddArg": {
                "StockCard": {
                        "Amount": 0,
                        "Availability": 0,
                        "BarCodes": null,
                        "CashRegisterCode": null,
                        "CashRegisterCode_LinkedItem": null,
                        "CashRegisterCommodityGroup": null,
                        "Catalog": null,
                        "DateTime_Created": null,
                        "DateTime_LastUpdate": null,
                        "DateTime_LastUpdateSalePrice": null,
                        "FileRepositoryAttachments": false,
                        "Guarantee_Period_Unit": 0,
                        "Guarantee_Period_Value": 0,
                        "IDNum": 0,
                        "IDNum_Stock": 0,
                        "ItemColor": null,
                        "KP": null,
                        "Location": null,
                        "Name": "Notebook 17', 8GBRAM, 2TB SDD",
                        "Number": "1001",
                        "PricesInfo": {
                                "DiscountApplyMode": 0,
                                "DiscountMaxPercento": 0,
                                "PriceCalculationType": 0,
                                "PriceInActionDiscount": 0,
                                "PriceInActionPriceWithVATWithoutDiscount": 0,
                                "PriceInActionPriceWithoutVATWithoutDiscount": 0,
                                "PriceInActionText": null,
                                "PriceInActionWithVAT": 0,
                                "PriceInActionWithoutVAT": 0,
                                "PriceLastPurchase": 0,
                                "PriceSupply": 800,
                                "PriceWithVAT1": 1200.00,
                                "PriceWithVAT2": 0,
                                "PriceWithVAT3": 0,
                                "PriceWithVAT4": 0,
                                "PriceWithoutVAT1": 1000.00,
                                "PriceWithoutVAT2": 0,
                                "PriceWithoutVAT3": 0,
                                "PriceWithoutVAT4": 0,
                                "PricesRounding": 0,
                                "VATRate": 20
                        },
                        "SaleDescription": null,
                        "SerialNumbersMode": 0,
                        "StockCardType": 0,
                        "StockGroup": "Prenosné počítače",
                        "TextAdditional": "",
                        "TreeCategory": null,
                        "Unit": "l",
                        "UnitOthers": null,
                        "Unit_PriceCompare": null,
                        "Unit_PriceCompare_Coefficient": 0,
                        "Unit_Weight": 0,
                        "Unit_Weight_Unit": null,
                        "UserMarkers": null
                },
                "StockName": "Hlavný sklad"
        }
}
Príklad vyvorenia filtra pri načítaní skladových kariet (položiek) zasielané údaje v JSON formáte.
{
    "stockCardsListArg": {
        "LoadSettings": {
            "PageSize": 200,
            "PageIndex": 0,
            "FiltersMergeTypes": 1,
            "Filters": [
                {
                    "BookColumnID": 93,
                    "ConditionType": 3,
                    "Values": ["2023-11-24T10:31:03"]                
                },
                {
                    "BookColumnID": 94,
                    "ConditionType": 3,
                    "Values": ["2023-11-24T10:31:03"]                
                },
                {
                    "BookColumnID": 95,
                    "ConditionType": 3,
                    "Values": ["2023-11-24T10:31:03"]                
                }
            ],
            "Sort": []
        },
        // tu by som odporučil zadať sklad alebo zoskupenie s ktorým sa pracuje
        "StockOrStockGroupName": "", 
        "GetEShop": true,
        "GetExtendedValues": true,
        "GetFileRepository": true,
        "GetFileRepositoryBinaryDataMode": 0,        
        "GetVariants": true,
        "GetParameters": true,
        "GetSerialNumbers": false,
        "BusinessPartnerIDNum": ""
    }
}
Example
Url: http://address:port/v1/stock/stock-card/list
See Also