<?php 
include "functions.php";
use SAPb1\Filters\Equal;
use SAPb1\Filters\InArray;

try 
{   
    session_start();
    if(isset($_POST['ClientS'])){
        $_SESSION['ClientS']=$_POST['ClientS'];
    }
    if(isset($_POST['ProjectS'])){
        $_SESSION['ProjectS']=$_POST['ProjectS'];
    }
    if(isset($_POST['ItemCode'])){
        $_SESSION['ItemCode']=$_POST['ItemCode'];
    }
    //echo  $_SESSION['ProjectS'].'=================>'. $_SESSION['ClientS'];
    // TEST2=================>12152
    //$Groupe = $_GET["Groupe"];
    $sap = Login();
    $ItemsList = $sap->getService("view.svc/B1_BpsSortieB1SLQuery");
    $ItemsList->headers(['Prefer' => 'odata.maxpagesize=777740']);
    $Items_result = $ItemsList->queryBuilder()
    ->select('itemcode,dscription,DistNumber,u_cardcode,u_codeproject,Quantity,WhsCode')
    ->where(new Equal('u_cardcode', $_SESSION['ClientS']))
    ->where(new Equal('u_codeproject',$_SESSION['ProjectS']))
    ->where(new Equal('itemcode',$_SESSION['ItemCode']))
    // ->where(new Equal('u_cardcode', 'C001023'))
    // ->where(new Equal('u_codeproject','TEST2'))
    ->findAll();
    
    $Items = json_decode(json_encode($Items_result), TRUE);
    echo json_encode($Items['value']);
//    header('Content-Type: application/json');
//     // echo $Items_result;

//     echo "project ". $_SESSION['ProjectS'];
//    echo json_encode($Items_result);
} catch (Exception $e) {
    echo $e->getMessage();    
}
