<?php

/* 
 * ROMAN DIGITAL - Autor: Américo Patetta
 */
set_include_path("../../");
include_once("server/class/Delivery.php");
include_once("server/class/SessionManager.php");
include_once("server/class/PedidosManager.php");

@session_start();

$jsonParams = file_get_contents('php://input');
$paramObj = json_decode($jsonParams);

$pedidos = null;

if(isset($paramObj->token)){
    
    $delivery = new Delivery(-1);
    $delivery->retrieveFromToken($paramObj->token);
    $soloActivos = isset($paramObj->soloActivos)?$paramObj->soloActivos:0;
    //$sessionManager = new SessionManager($paramObj->token);
    if($idDelivery = $delivery->getId()){
        $idLocal = $delivery->getLocalActual();
        $pedidosManager = new PedidosManager();
        $pedidos = $pedidosManager->getPedidosPendientes($idDelivery,$idLocal,$soloActivos);
        $errorCode = 0;
    } else {
        $errorCode = -2;
    }
} else {
    $errorCode = -1;
}

$ack['error'] = $errorCode;
$ack['pedidos'] = $pedidos;

header('Content-Type: application/json; charset=utf-8');
echo json_encode($ack);