<?php
include_once "../../includes/config.php";
include_once "../../includes/database.php";
include_once "../../includes/validation.php";
include_once "../../includes/Helper.php";
include_once "../../includes/ajax/check_session_ajax.php";
require_once '../../includes/ajax/check_edit_page_ajax.php';

include_once "../../includes/auth.php";
$auth = array('manager');
$authRes = checkAuth($auth, $user);
if(!$authRes)
{
    http_response_code(401);
	echo json_encode(array('error_text' => 'Authntication Error'));
	exit;
}

include_once "../../includes/ajax/check_paid_ajax.php";


if($user['cl_type'] !='manager') 
{
        http_response_code(403);
        echo json_encode(['error_text' => 'Authentication Error']);
        exit;
}

class getItems extends database
{
    public function index($id, $userID, $companyid)
    {
       
        $sql = 'SELECT oi.*,  mi.cl_name FROM  tb_order_item oi INNER JOIN tb_menu mi ON oi.cl_menu_id=mi.cl_id INNER JOIN tb_order o ON oi.cl_order_id=o.cl_id WHERE  oi.deleted_at IS NULL AND oi.cl_order_id=?  AND o.cl_user_id=? AND o.cl_company_id=?';
        return $this->callQuery($sql, [$id, $userID, $companyid]);
        //return $this->fetchAll('order_item', ['id' => $id]);
    }
}

$obj = new getItems();

$items = $obj->index($id, $user['cl_id'], $user['cl_user_id']);
echo json_encode($items);