<?php
include("config.php");
if (!loggedin()) {
    header("Location: login.php");
    exit();
}if (($_SESSION['reports'] != '1')) {
    header("Location: error.php");
    exit();
}
?>
<!DOCtype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="Emcan">
        <link rel="shortcut icon" href="assets/images/favicon_1.ico">
        <title>   Report </title>
        <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/core.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/components.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/icons.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/pages.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/responsive.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/custom.css" rel="stylesheet" type="text/css" />
        <!-- HTML5 Shiv and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
        <![endif]-->
        <script src="assets/js/modernizr.min.js"></script>
    </head>
    <style>
        body{
            background-color:#FFFFFF;
            direction:rtl;
            text-align:right;
            height:100vh;
        }
        .content-page > .content {
            padding: 30px !important;
            margin:0 !important;
        }
        .rightCon {
            display: block;
            float: right;
        }
        .rightCon > h3 {
            display: block;
            font-family: tahoma;
            font-size: 15px;
            font-weight: bold;
            line-height: 16px;
            text-align: right;
        }
        .leftCon {
            display: block;
            text-align: left;
            direction:ltr;
        }
        .leftCon > h3 {
            display: block;
            font-family: tahoma;
            font-size: 15px;
            font-weight: bold;
            line-height: 16px;
            text-align: left;
        }
        h1 {
            color: red;
            display: block;
            font-family: tahoma;
            font-size: 25px;
            font-weight: bold;
            line-height: 46px;
            margin: 30px 0;
            text-align: center;
        }
        h2 {
            font-family: tahoma;
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 30px;
            margin-top: -30px;
            text-align: center;
        }
        table {
            width: 100%;
            text-align:right;
        }
        table,
        th,
        td {
            border: 1px solid black;
            border-collapse: collapse;
            text-align:right;
        }
        th, td {
            border-right: medium none;
            padding: 10px 5px;
            text-align: right;
        }
        button {
            display: block;
            font-size: 20px;
            height: 70px;
            margin: auto;
            text-align: center;
            width: 150px;
            position:absolute;
            bottom:0;
            left:50%;
        }
    </style>
</head>
<body>
    <div class="content-page" style="margin-right:15px;">
        <!-- Start content -->
        <div class="content">



            <?php
            if ((isset($_GET['report']) && $_GET['report'] == "daily")) {
                $report = $_GET['report'];
                ?>
                <h1>Report Daily</h1>
                <h3 style="text-align:center;font-size:15px;">   Date
                    <?php echo date("Y-m-d"); ?>
                </h3>
                <?php
                if (($_GET['branche_id'] != '')) {
                    ?>
                    <h1 style="text-align:center;font-size:15px;">  Branch  <?php echo get_branche_Name($_GET['branche_id']); ?>
                    </h1>
                <?php }
                ?>
                <table class="table table-striped ">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Order id </th>
                            <th> Branch </th>
                            <th>Client Name</th>
                            <th>phone number</th>
                            <th> charge cost</th>
                            <th>  discount percentage</th>
                            <th> Total</th>
                            <th> payment method</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $x = 1;
                        global $con;
                        $showRecordPerPage = 10;
                        if (isset($_GET['page']) && !empty($_GET['page'])) {
                            $currentPage = $_GET['page'];
                        } else {
                            $currentPage = 1;
                        }
                        $startFrom = ($currentPage * $showRecordPerPage) - $showRecordPerPage;

                        if ($_SESSION['user_type'] == 1) {
                            if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                                $query = $con->query("SELECT * FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and  `order_follow`=3  and `branch_id`='" . $_GET['branche_id'] . "'");
                            } else {
                                $query = $con->query("SELECT * FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and  `order_follow`=3    ");
                            }
                        } else {
                            $query = $con->query("SELECT * FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and `order_follow`=3  and `branch_id`='" . $_SESSION['branch_id'] . "'  ");
                        }
                        $orders_count = mysqli_num_rows($query);

                        while ($row = mysqli_fetch_assoc($query)) {
                            $order_id = $row['order_id'];
                            $payment = $row['payment'];
                            $client_id = $row['client_id'];
                            $client_address_id = $row['client_address_id'];
                            $date = $row['date'];
                            $branch_id = $row['branch_id'];
                            $get_region_id = get_region_by_client_address($client_id, $client_address_id);
                            $discount_percentage = $row['discount_percentage'];
                            $net_price = $row['net_price'];
                            $getCharge = $row['charge_cost'];
                            $order_price = totalPrice($order_id);
                            ?>
                            <tr class="gradeX <?php echo $order_id; ?>">
                                <td><?php echo $x; ?></td>
                                <td><?php echo $order_id; ?></td>
                                <td><?php echo get_branche_Name($branch_id); ?></td>
                                <td><?php echo get_client_name_by_id($client_id); ?></td>
                                <td class="customFont"><?php echo get_client_phone_by_id($client_id); ?></td>
                                <td style="text-align:center;"> <?php echo $getCharge; ?> B.D </td>
                                <td style="text-align:center;"> <?php echo $discount_percentage; ?> %</td>
                                <td style="text-align:center;"> <?php echo $net_price; ?> B.D </td>

                                <td class="customFont"><?php echo $payment; ?></td>
                                <td class="customFont"><?php echo $date; ?></td>

                            </tr>
                        <?php } ?>
                        <?php if ($orders_count == 0) { ?>
                            <tr class="selectable" >
                                <td colspan="10" class="center uniformjs" style="text-align: center"> There are no items </td>
                            </tr>
                            <?php
                            $x++;
                        }
                        ?>
                    </tbody>

                </table>	

                <h1>Total Report Daily</h1>

                <table>
                    <tr>
                        <th>Number Clients</th>
                        <th>Number Orders</th>
                        <th>Total Orders Cost</th>
                        <th>Total charge cost</th>
                    </tr>
                    <?php
                    $x = 1;
                    global $con;
                    if ($_SESSION['user_type'] == 1) {
                        if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                            $sql = "SELECT count(order_id) as order_count  FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and `order_follow`=3  and `branch_id`='" . $_GET['branche_id'] . "'  ";
                        } else {
                            $sql = "SELECT count(order_id) as order_count  FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and `order_follow`=3 ";
                        }
                    } else {
                        $sql = "SELECT count(order_id) as order_count  FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and `order_follow`=3  and `branch_id`='" . $_SESSION['branch_id'] . "'   ";
                    }

                    $querya = $con->query($sql);
                    $order_count = mysqli_fetch_row($querya);
//                    echo $order_count[0];
//Number Clients
                    if ($_SESSION['user_type'] == 1) {
                        if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                            $sqlc = "SELECT DISTINCT client_id  FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and `order_follow`=3  and `branch_id`='" . $_GET['branche_id'] . "'  ";
                        } else {
                            $sqlc = "SELECT DISTINCT client_id  FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and `order_follow`=3 ";
                        }
                    } else {
                        $sqlc = "SELECT DISTINCT client_id  FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and `order_follow`=3  and `branch_id`='" . $_SESSION['branch_id'] . "'   ";
                    }
                    $queryc = $con->query($sqlc);
                    $client_count = mysqli_num_rows($queryc);

                    //Total التكلفة

                    if ($_SESSION['user_type'] == 1) {
                        if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                            $sqlx = "SELECT *  FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and `order_follow`=3 and `branch_id`='" . $_GET['branche_id'] . "'  ";
                        } else {
                            $sqlx = "SELECT *  FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and `order_follow`=3 ";
                        }
                    } else {
                        $sqlx = "SELECT *  FROM `orders` WHERE date(date) = '" . date("Y-m-d") . "' and `order_status`=1 and `order_follow`=3  and `branch_id`='" . $_SESSION['branch_id'] . "'   ";
                    }
                    $queryx = $con->query($sqlx);
                    $price = 0;
                    $charge = 0;
                    $discount = 0;
                    while ($row_select = mysqli_fetch_assoc($queryx)) {

                        $client_id = $row_select['client_id'];
                        $discount_percentage = $row_select['discount_percentage'];
                        $net_price = $row_select['net_price'];
                        $getCharge = $row_select['charge_cost'];

                        $charge +=$getCharge;
                        $price+=$net_price;
                        $discount+= $discount_percentage;
                    }
//                    echo 'price=' . $price;
                    $financial_report[] = array("client_count" => $client_count, "charge" => $charge, "discount" => $discount, "order_count" => $order_count[0], "price" => $price);
                    foreach ($financial_report as $value) {
                        ?>				  
                        <tr>
                            <td><?php echo $value["client_count"]; ?></td>						
                            <td><?php echo $value["order_count"]; ?></td>						
                            <td><?php echo $value["price"]; ?> B.D </td>						
                            <td><?php echo $value["charge"]; ?> B.D </td>						
                        </tr>
                        <?php
                    }
                    ?>
                </table>
                <?php
            } elseif ((isset($_GET['report']) && $_GET['report'] == "week")) {
                $report = $_GET['report'];
                ?>
                <h1>Report الأسبوع</h1>
                <h3 style="text-align:center;font-size:15px;">   From Date
                    <?php echo date('Y-m-d', strtotime('-6 days')); ?>
                </h3>
                <h3 style="text-align:center;font-size:15px;">   To Date Daily
                    <?php echo date("Y-m-d"); ?>
                </h3>
                <table class="table table-striped ">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Order id </th>
                            <th> Branch </th>
                            <th>Client Name</th>
                            <th>Phone number</th>
                            <th> Charge cost</th>
                            <th> Discount percentage </th>
                            <th>Total</th>
                            <th> Payment method</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $x = 1;
                        global $con;
                        $showRecordPerPage = 10;
                        if (isset($_GET['page']) && !empty($_GET['page'])) {
                            $currentPage = $_GET['page'];
                        } else {
                            $currentPage = 1;
                        }
                        $startFrom = ($currentPage * $showRecordPerPage) - $showRecordPerPage;

                        if ($_SESSION['user_type'] == 1) {
                            if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                                $query = $con->query("SELECT * FROM `orders` where  (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and  `order_follow`=3 and `branch_id`='" . $_GET['branche_id'] . "' ");
                            } else {
                                $query = $con->query("SELECT * FROM `orders` where  (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and  `order_follow`=3");
                            }
                        } else {
                            $query = $con->query("SELECT * FROM `orders` where  (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and  `order_follow`=3 and `branch_id`='" . $_SESSION['branch_id'] . "' ");
                        }
                        $orders_count = mysqli_num_rows($query);


                        while ($row = mysqli_fetch_assoc($query)) {
                            $order_id = $row['order_id'];
                            $payment = $row['payment'];
                            $client_id = $row['client_id'];
                            $client_address_id = $row['client_address_id'];
                            $date = $row['date'];
                            $discount_percentage = $row['discount_percentage'];
                            $net_price = $row['net_price'];
                            $getCharge = $row['charge_cost'];
                            $branch_id = $row['branch_id'];
                            ?>
                            <tr class="gradeX <?php echo $order_id; ?>">
                                <td><?php echo $x; ?></td>
                                <td><?php echo $order_id; ?></td>
                                <td><?php echo get_branche_Name($branch_id); ?></td>
                                <td><?php echo get_client_name_by_id($client_id); ?></td>
                                <td class="customFont"><?php echo get_client_phone_by_id($client_id); ?></td>
                                <td style="text-align:center;"> <?php echo $getCharge; ?> B.D </td>
                                <td style="text-align:center;"> <?php echo $discount_percentage; ?> %</td>
                                <td style="text-align:center;"> <?php echo $net_price; ?> B.D </td>
                                <td class="customFont"><?php echo $payment; ?></td>
                                <td class="customFont"><?php echo $date; ?></td>

                            </tr>
                            <?php
                            $x++;
                        }
                        ?>
                        <?php if ($orders_count == 0) { ?>
                            <tr class="selectable" >
                                <td colspan="10" class="center uniformjs" style="text-align: center"> There are no items </td>
                            </tr>
                        <?php } ?>
                    </tbody>

                </table>	

                <h1>Total Week Report </h1>

                <table>
                    <tr>
                        <th>Number Clients</th>
                        <th>Number Orders</th>
                        <th>Total Orders</th>
                        <th>Total charge cost</th>
                    </tr>
                    <?php
                    $x = 1;
                    global $con;
                    if ($_SESSION['user_type'] == 1) {
                        if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                            $sql = "SELECT count(order_id) as order_count  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 and `branch_id`='" . $_GET['branche_id'] . "'  ";
                        } else {
                            $sql = "SELECT count(order_id) as order_count  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 ";
                        }
                    } else {
                        $sql = "SELECT count(order_id) as order_count  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3  and `branch_id`='" . $_SESSION['branch_id'] . "'   ";
                    }
                    $querya = $con->query($sql);
                    $order_count = mysqli_fetch_row($querya);
//                    echo $order_count[0];
//Number Clients
                    if ($_SESSION['user_type'] == 1) {
                        if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                            $sqlc = "SELECT DISTINCT client_id  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 and `branch_id`='" . $_GET['branche_id'] . "'  ";
                        } else {
                            $sqlc = "SELECT DISTINCT client_id  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 ";
                        }
                    } else {
                        $sqlc = "SELECT DISTINCT client_id  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3  and `branch_id`='" . $_SESSION['branch_id'] . "'   ";
                    }
                    $queryc = $con->query($sqlc);
                    $client_count = mysqli_num_rows($queryc);

                    //Total التكلفة

                    if ($_SESSION['user_type'] == 1) {
                        if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                            $sqlx = "SELECT *  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 and `branch_id`='" . $_GET['branche_id'] . "'  ";
                        } else {
                            $sqlx = "SELECT *  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 ";
                        }
                    } else {
                        $sqlx = "SELECT *  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3  and `branch_id`='" . $_SESSION['branch_id'] . "'   ";
                    }
                    $queryx = $con->query($sqlx);
                    $price = 0;
                    $charge = 0;
                    while ($row_select = mysqli_fetch_assoc($queryx)) {

                        $client_id = $row_select['client_id'];

                        $net_price = $row_select['net_price'];
                        $price +=$net_price;
                        $getCharge = $row_select['charge_cost'];
                        $charge +=$getCharge;
                    }
//                    echo 'price=' . $price;
                    $financial_report[] = array("client_count" => $client_count, "charge" => $charge, "order_count" => $order_count[0], "price" => $price);
                    foreach ($financial_report as $value) {
                        ?>				  
                        <tr>
                            <td><?php echo $value["client_count"]; ?></td>						
                            <td><?php echo $value["order_count"]; ?></td>						
                            <td><?php echo $value["price"]; ?> B.D </td>						
                            <td><?php echo $value["charge"]; ?> B.D </td>						
                        </tr>
                        <?php
                    }
                    ?>
                </table>
                <?php
            } elseif ((isset($_GET['report']) && $_GET['report'] == "month")) {
                $report = $_GET['report'];
                ?>
                <h1>Month Report </h1>
                <h3 style="text-align:center;font-size:15px;">   From Date
                    <?php echo date('Y-m-d', strtotime('-29 days')); ?>
                </h3>
                <h3 style="text-align:center;font-size:15px;">   To Date Daily
                    <?php echo date("Y-m-d"); ?>
                </h3>
                <table class="table table-striped ">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th> Order id</th>
                            <th>  Branch</th>
                            <th>Client Name</th>
                            <th>phone number</th>
                            <th> charge cost</th>
                            <th>  discount percentage</th>
                            <th> Total</th>
                            <th> payment method</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $x = 1;
                        global $con;

                        if ($_SESSION['user_type'] == 1) {
                            if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                                $query = $con->query("SELECT * FROM `orders` where  (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and  `order_follow`=3 and `branch_id`='" . $_GET['branche_id'] . "'  ");
                            } else {
                                $query = $con->query("SELECT * FROM `orders` where  (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and  `order_follow`=3");
                            }
                        } else {
                            $query = $con->query("SELECT * FROM `orders` where  (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and  `order_follow`=3  and `branch_id`='" . $_SESSION['branch_id'] . "'   ");
                        }
                        $orders_count = mysqli_num_rows($query);

                        while ($row = mysqli_fetch_assoc($query)) {
                            $order_id = $row['order_id'];
                            $payment = $row['payment'];
                            $client_id = $row['client_id'];
                            $branch_id = $row['branch_id'];
                            $client_address_id = $row['client_address_id'];
                            $date = $row['date'];
                            $discount_percentage = $row['discount_percentage'];
                            $net_price = $row['net_price'];
                            $getCharge = $row['charge_cost'];
                            ?>
                            <tr class="gradeX <?php echo $order_id; ?>">
                                <td><?php echo $x; ?></td>
                                <td><?php echo $order_id; ?></td>
                                <td><?php echo get_branche_Name($branch_id); ?></td>
                                <td><?php echo get_client_name_by_id($client_id); ?></td>
                                <td class="customFont"><?php echo get_client_phone_by_id($client_id); ?></td>
                                <td style="text-align:center;"> <?php echo $getCharge; ?> B.D </td>
                                <td style="text-align:center;"> <?php echo $discount_percentage; ?> %</td>
                                <td style="text-align:center;"> <?php echo $net_price; ?> B.D </td>

                                <td class="customFont"><?php echo $payment; ?></td>
                                <td class="customFont"><?php echo $date; ?></td>

                            </tr>
                            <?php
                            $x++;
                        }
                        ?>
                        <?php if ($orders_count == 0) { ?>
                            <tr class="selectable" >
                                <td colspan="10" class="center uniformjs" style="text-align: center"> There are no items </td>
                            </tr>
                        <?php } ?>
                    </tbody>

                </table>	

                <h1>Total Month Report </h1>

                <table>
                    <tr>
                        <th>Number Clients</th>
                        <th>Number Orders</th>
                        <th>Total Orders</th>
                        <th>Total charge cost</th>
                    </tr>
                    <?php
                    $x = 1;
                    global $con;
                    if ($_SESSION['user_type'] == 1) {
                        if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                            $sql = "SELECT count(order_id) as order_count  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 and `branch_id`='" . $_GET['branche_id'] . "' ";
                        } else {
                            $sql = "SELECT count(order_id) as order_count  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 ";
                        }
                    } else {
                        $sql = "SELECT count(order_id) as order_count  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 and `branch_id`='" . $_SESSION['branch_id'] . "' ";
                    }
                    $querya = $con->query($sql);
                    $order_count = mysqli_fetch_row($querya);
//                    echo $order_count[0];
//Number Clients
                    if ($_SESSION['user_type'] == 1) {
                        if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                            $sqlc = "SELECT DISTINCT client_id  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 and `branch_id`='" . $_GET['branche_id'] . "' ";
                        } else {
                            $sqlc = "SELECT DISTINCT client_id  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 ";
                        }
                    } else {
                        $sqlc = "SELECT DISTINCT client_id  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 and `branch_id`='" . $_SESSION['branch_id'] . "' ";
                    }
                    $queryc = $con->query($sqlc);
                    $client_count = mysqli_num_rows($queryc);

                    //Total التكلفة

                    if ($_SESSION['user_type'] == 1) {
                        if (isset($_GET['branche_id']) && $_GET['branche_id'] != '') {
                            $sqlx = "SELECT *  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 and `branch_id`='" . $_GET['branche_id'] . "' ";
                        } else {
                            $sqlx = "SELECT *  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 ";
                        }
                    } else {
                        $sqlx = "SELECT *  FROM `orders` WHERE (date(date) BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date("Y-m-d") . "' ) and `order_status`=1 and `order_follow`=3 and `branch_id`='" . $_SESSION['branch_id'] . "' ";
                    }
                    $queryx = $con->query($sqlx);
                    $price = 0;
                    $charge = 0;
                    while ($row_select = mysqli_fetch_assoc($queryx)) {

                        $client_id = $row_select['client_id'];
                        $net_price = $row_select['net_price'];
                        $price +=$net_price;
                        $getCharge = $row_select['charge_cost'];
                        $charge +=$getCharge;
                    }
//                    echo 'price=' . $price;
                    $financial_report[] = array("client_count" => $client_count, "charge" => $charge, "order_count" => $order_count[0], "price" => $price);
                    foreach ($financial_report as $value) {
                        ?>				  
                        <tr>
                            <td><?php echo $value["client_count"]; ?></td>						
                            <td><?php echo $value["order_count"]; ?></td>						
                            <td><?php echo $value["price"]; ?> B.D</td>						
                            <td><?php echo $value["charge"]; ?> B.D</td>						
                        </tr>
                        <?php
                    }
                    ?>
                </table>
            <?php } ?>

        </div>



    </div>	

    <script src="assets/js/jquery.min.js"></script>
</body>
</html>