<?php $controller = 'Pos';
    $action = 'print';
    include $_SERVER["DOCUMENT_ROOT"].'/app/include/bootstrap.php';
    $login = new Login();
    
    $station = new EstacionRepository();
    $stationData = $station->getById($login->getIdCaja());
    if($stationData['habilitadaParaAbrir']== NULL || $stationData['habilitadaParaAbrir'] == '0'){
        exit();
    }
?>
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>M&G POS - PrintTicket</title>
    <script type='text/javascript' src='/public/js/lib/StarWebPrint/StarWebPrintBuilder.js'></script>
    <script type='text/javascript' src='/public/js/lib/StarWebPrint/StarWebPrintTrader.js'></script>
    <script type="text/javascript">
        var builder = new StarWebPrintBuilder();
        request = builder.createPeripheralElement({channel:1, on:1, off:1});

        var url = "http://localhost:8001/StarWebPRNT/SendMessage";
        var trader = new StarWebPrintTrader({url:url});

        trader.onReceive = function (response) {

            var msg = '- onReceive -\n\n';
            msg += 'TraderSuccess : [ ' + response.traderSuccess + ' ]\n';
            //msg += 'TraderCode : [ ' + response.traderCode + ' ]\n';
            msg += 'TraderStatus : [ ' + response.traderStatus + ',\n';

            if (trader.isCoverOpen            ({traderStatus:response.traderStatus})) {msg += '\tCoverOpen,\n';}
            if (trader.isOffLine              ({traderStatus:response.traderStatus})) {msg += '\tOffLine,\n';}
            if (trader.isCompulsionSwitchClose({traderStatus:response.traderStatus})) {msg += '\tCompulsionSwitchClose,\n';}
            if (trader.isEtbCommandExecute    ({traderStatus:response.traderStatus})) {msg += '\tEtbCommandExecute,\n';}
            if (trader.isHighTemperatureStop  ({traderStatus:response.traderStatus})) {msg += '\tHighTemperatureStop,\n';}
            if (trader.isNonRecoverableError  ({traderStatus:response.traderStatus})) {msg += '\tNonRecoverableError,\n';}
            if (trader.isAutoCutterError      ({traderStatus:response.traderStatus})) {msg += '\tAutoCutterError,\n';}
            if (trader.isBlackMarkError       ({traderStatus:response.traderStatus})) {msg += '\tBlackMarkError,\n';}
            if (trader.isPaperEnd             ({traderStatus:response.traderStatus})) {msg += '\tPaperEnd,\n';}
            if (trader.isPaperNearEnd         ({traderStatus:response.traderStatus})) {msg += '\tPaperNearEnd,\n';}

            msg += '\tEtbCounter = ' + trader.extractionEtbCounter({traderStatus:response.traderStatus}).toString() + ' ]\n';
            //msg += 'Status : [ ' + response.status + ' ]\n';
            // msg += 'ResponseText : [ ' + response.responseText + ' ]\n';
            //alert(msg);
        };

        //Errores para cuando se manda url: var trader = new StarWebPrintTrader({url:url});
        trader.onError = function (response) {
            var msg = '- onError -\n\n';
            msg += '\tStatus:' + response.status + '\n';
            msg += '\tResponseText:' + response.responseText;
            alert(msg); /*Descomentar para mostrar error cuando no immprime. Seria para development*/
        };

        trader.sendMessage({request:request});
    </script>
</head>
<body>
</body>
</html>