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

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

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

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

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

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

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'])){

    $C_start_date = isset($_GET['csdate']) ? $_GET['csdate'] : "";
    $C_end_date = isset($_GET['cedate']) ? $_GET['cedate'] : "";
    $C_region = isset($_GET['region']) ? $_GET['region'] : "0";
    $C_status = isset($_GET['cstatus']) ? $_GET['cstatus'] : "all";

    $N_start_date = isset($_GET['sdate']) ? $_GET['sdate'] : "";
    $N_end_date = isset($_GET['edate']) ? $_GET['edate'] : "";

    $B_start_date = isset($_GET['bstart']) ? $_GET['bstart'] : "";
    $B_end_date = isset($_GET['bend']) ? $_GET['bend'] : "";
    $B_status = isset($_GET['bstatus']) ? $_GET['bstatus'] : "all";

    $acsr_export = $obj_access->check_access($obj_cruds,$_SESSION['admin_id'],'export_report');
    $acsr_chart = $obj_access->check_access($obj_cruds,$_SESSION['admin_id'],'view_report_chart');
    $acsr_table = $obj_access->check_access($obj_cruds,$_SESSION['admin_id'],'view_report_table');
    $acsr_bar = $obj_access->check_access($obj_cruds,$_SESSION['admin_id'],'show_report_amount');

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

    if($acsg_report != 1){
        header("Location:".$path['dashboard']);
    }


    if($C_start_date != ""){
        $C_start_format = date("Y-m-d", strtotime($C_start_date));
    } else {
        $C_start_format = date('Y-m-d', strtotime('-1 year'));
    }

    if($C_end_date != ""){
        $C_end_format = date("Y-m-d", strtotime($C_end_date)).' 23:59:59';
    } else {
        $C_end_format = date('Y-m-d');
    }

    if($B_start_date != ""){
        $B_start_format = date("Y-m-d", strtotime($B_start_date));
    } else {
        $B_start_format = date('Y-m-d', strtotime('-1 year'));
    }

    if($B_end_date != ""){
        $B_end_format = date("Y-m-d", strtotime($B_end_date)).' 23:59:59';
    } else {
        $B_end_format = date('Y-m-d');
    }


    //Get data chart
    $data_charts = $obj_po->get_report_chart($obj_crud,$C_start_format,$C_end_format,$C_region,$acg_pic,$C_status);
    $data_region = $obj_region->get_data_select($obj_crud);
    $data_bars = $obj_po->get_report_bars($obj_crud,$B_start_format,$B_end_format,$B_status);

    $data_stats = $obj_po->get_total_stat_region($obj_crud,$acg_pic);
    //var_dump($data_charts);
    if(isset($_SESSION['status'])){
        $message = $_SESSION['status'];
        unset($_SESSION['status']);
    } else {
        $message = "";
    }

    if(isset($_SESSION['alert'])){
        $alert = $_SESSION['alert'];
        unset($_SESSION['alert']);
    } else {
        $alert = "";
    }


} else if(isset($_GET['action'])){
    //nothing
}
?>