<?php
require_once($global['root-model']."Crud.php");
$obj_crud = new Crud();

require_once($global['root-model']."PO.php");
$obj_po = new PO();

require_once($global['root-model']."Access.php");
$obj_access = new Access();

if(!isset($_GET['action'])){ 

    $N_status = isset($_POST['exstatus']) ? $_POST['exstatus'] : "";
    $N_region = isset($_POST['exregion']) ? $_POST['exregion'] : "";
    $N_start_date = isset($_POST['startDate']) ? $_POST['startDate'] : "";
    $N_end_date = isset($_POST['endDate']) ? $_POST['endDate'] : "";
    if($N_start_date != ""){
        $N_start_format = date("Y-m-d", strtotime($N_start_date));
        $start_view = date("d F Y", strtotime($N_start_date));
        $end_view = date("d F Y", strtotime($N_end_date));
        $date_view = "From date ".$start_view." to ".$end_view;
    } else {
        $N_start_format = "";
        $date_view = "";
    }
    if($N_end_date != ""){
        $N_end_format = date("Y-m-d", strtotime($N_end_date)).' 23:59:00';
    } else {
        $N_end_format = "";
    }

    $acsp_admin_region = $obj_access->check_access($obj_cruds,$_SESSION['admin_id'],'show_admin_region');
    $acsp_hide_amount = $obj_access->check_access($obj_cruds,$_SESSION['admin_id'],'hide_amount');

    if($acsp_admin_region == 1){
        $acg_region = $_SESSION['admin_region'];
    } else {
        $acg_region = "";
    }

    if($acsg_show_pic == 1){
        $acg_pic = $_SESSION['admin_id'];
    } else {
        $acg_pic = "";
    }

    if(is_array($N_region)){
        $region_list = "'" . implode ( "', '", $N_region ) . "'";
    }
    // echo $region_list;
    // if($region_list != "'all'"){
    //     echo "gak all region doang";
    // } else {
    //     echo "all reg";
    // }
    // if (strpos($region_list, 'all') === false) {
    //     echo 'true';
    // }
    $datas = $obj_po->get_data_export($obj_crud,$N_status,$region_list,$N_start_format,$N_end_format,$acg_region,$acg_pic);
    //var_dump($datas);
}
?>