public function restoUserLogin()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $id_restaurant = isset($_POST['id_restaurant']) ? addslashes($_POST['id_restaurant']) : "";
     if (!$id_restaurant) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $pin = isset($_POST['pin']) ? addslashes($_POST['pin']) : "";
     if (!$pin) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $json = array();
     $json['status_code'] = 1;
     $objRestoUsers = new RestaurantUserModel();
     $arrRestoUsers = $objRestoUsers->getWhere("id_restaurant = '{$id_restaurant}' AND pin_password='******' AND status='1'");
     MasterDish::checkCount($arrRestoUsers);
     $sem = array();
     foreach ($arrRestoUsers as $val) {
         $sem['user'] = RestaurantUser::getRestaurantUser($val->id_user);
     }
     $json['results'] = $sem;
     echo json_encode($json);
     die;
 }
    public function reportFee()
    {
        $id_restaurant = isset($_GET['id_restaurant']) ? addslashes($_GET['id_restaurant']) : "0";
        $type_order = isset($_GET['type_order']) ? addslashes($_GET['type_order']) : "8";
        $dateVon = isset($_GET['dateVon']) ? addslashes($_GET['dateVon']) : date('Y-m-d', time());
        $dateBis = isset($_GET['dateBis']) ? addslashes($_GET['dateBis']) : date('Y-m-d', time());
        //        $dateBis = isset($_GET['dateBis']) ? addslashes($_GET['dateBis']) : Generic::setCurrentDate();
        $id_server = isset($_GET['id_server']) ? addslashes($_GET['id_server']) : "0";
        $status_payment = isset($_GET['status_payment']) ? addslashes($_GET['status_payment']) : 0;
        $status_progress = isset($_GET['status_progress']) ? addslashes($_GET['status_progress']) : 4;
        $objResto = new MasterRestaurantModel();
        $arrResto = $objResto->getAll();
        $arrRestoIndex[0] = "All";
        foreach ($arrResto as $resto) {
            if ($resto->name != "") {
                $arrRestoIndex[$resto->id_restaurant] = $resto->name;
            }
        }
        $objOrder = new MasterOrderModel();
        $first_key = key($arrRestoIndex);
        $arrOrder = $objOrder->getWhere("id_restaurant='{$id_restaurant}'");
        $arrRestoUserIndex[0] = "All";
        foreach ($arrOrder as $val) {
            $user = RestaurantUser::getRestaurantUserName($val->id_server);
            if ($user != "") {
                $arrRestoUserIndex[$val->id_server] = $user;
            }
        }
        $arrTypeOrder[0] = "Dine In - Manual";
        $arrTypeOrder[1] = "Dine In - Apps";
        $arrTypeOrder[2] = "Take Away - Manual";
        $arrTypeOrder[3] = "Take Away  - Apps";
        $arrTypeOrder[4] = "All Manual Order";
        $arrTypeOrder[5] = "All Apps Order";
        $arrTypeOrder[6] = "All Dine In Order";
        $arrTypeOrder[7] = "All Take Away Order";
        $arrTypeOrder[8] = "All Order Types";
        $arrStatusPaymentMethod[1] = "Cash";
        $arrStatusPaymentMethod[2] = "Credit Card";
        $arrStatusPaymentMethod[3] = "Others";
        $arrStatusPaymentMethod[0] = "All Payment Method";
        $arrStatusProgress[4] = "Done";
        $arrStatusProgress[9] = "Void";
        $t = time();
        $where = " ";
        if ($id_restaurant == 0) {
            $where = $where;
        } else {
            $allResto = false;
            $where = $where . " resto.id_restaurant='{$id_restaurant}' AND ";
        }
        if ($type_order == "8") {
        } else {
            $where = $where . "  o.type_order='{$type_order}' AND ";
        }
        if ($dateVon == "") {
            ?>
            <?php 
            $dateVon = Generic::setCurrentDate();
        } else {
            $date = new DateTime($dateVon);
            //            $dateVon = leap_mysqldate_isi(date('Y-m-d H:i:s'));
            //            pr($dateVon);
            $where = $where . "  o.datetime_order >='{$dateVon}' AND ";
        }
        if ($dateBis == "") {
            $dateBis = Generic::setCurrentDate();
        } else {
            $date = new DateTime($dateVon);
            $where = $where . "  o.datetime_order <= '{$dateBis}' AND ";
        }
        if ($id_server == "0") {
            $where = $where;
        } else {
            $where = $where . "  o.id_server='{$id_server}' AND ";
        }
        if ($status_payment == "" | $status_payment == "0") {
            $where = $where;
        } else {
            $where = $where . "  o.status_payment='{$status_payment}' AND ";
        }
        if ($status_progress == "") {
        } else {
            $where = $where . "  o.status_progress='{$status_progress}'  ";
        }
        $objOrder = new MasterOrderModel();
        $objResto = new MasterRestaurantModel();
        $objOrderDetail = new OrderDetailModel();
        $objDish = new MasterDishModel();
        global $db;
        $q = "SELECT o.datetime_order as dateOrder,o.datetime_order as timeOrder , resto.name,   o.id_order,  o.mr_fee, o.cc_fee, o.mr_fee+o.cc_fee as Total FROM {$objResto->table_name} resto INNER JOIN {$objOrder->table_name} o ON resto.id_restaurant = o.id_restaurant";
        //        $q = $q . " INNER JOIN {$objOrderDetail->table_name} orderdetail ON o.id_order = orderdetail.id_order  ";
        //        $q = $q . " INNER JOIN {$objDish->table_name} dish ON orderdetail.id_dish =  dish.id_dish ";
        $q = $q . " WHERE " . $where;
        //        pr($q);
        $arrQuery = $db->query($q, 2);
        //        pr($arrQuery);
        //        die();
        //        $data = json_encode($arrQuery);
        $data = $arrQuery;
        //        pr($arrRestoIndex);
        ?>

        <div  class="col-md-12">
            <div class="col-sm-12">
                <h1>Reporting Fee</h1>
            </div>

            <div id="formgroup_selected_restaurant" class="form-group">
                <div class='col-sm-6'>
                    <select id = "restoID_<?php 
        echo $t;
        ?>
" class="form-control">
                        <?php 
        foreach ($arrRestoIndex as $key => $val) {
            if ($key == $_GET['id_restaurant']) {
                echo "<option selected='selected' value='" . $key . "'>" . $val . "</option>";
            } else {
                echo "<option value='" . $key . "'>" . $val . "</option>";
            }
        }
        ?>
                    </select>

                </div>
                <div class='col-sm-6'>
                    <select id = "type_order_<?php 
        echo $t;
        ?>
" class="form-control">

                        <?php 
        foreach ($arrTypeOrder as $key => $val) {
            if ($key == $_GET['type_order']) {
                echo "<option selected='selected' value='" . $key . "'>" . $val . "</option>";
            } else {
                echo "<option value='" . $key . "'>" . $val . "</option>";
            }
        }
        ?>
                    </select>
                </div>
                <div class="clearfix"></div>
            </div>

            <div id="formgroup_date" class="form-group">
                <div class='col-sm-6'>
                    <div class="form-group">
                        <div class='input-group date' id='datetimepickerFrom_<?php 
        echo $t;
        ?>
' data-date-format="dd-mm-yyyy">
                            <input type='text' id= "dateVon_<?php 
        echo $t;
        ?>
"class="form-control"
                                   />
                            <span id = "cobaFrom" class="input-group-addon">
                                <span class="glyphicon glyphicon-calendar"></span>
                            </span>

                        </div>
                    </div>
                </div>

                <div class='col-sm-6'>
                    <div class="form-group">
                        <div class='input-group date' id='datetimepickerTo_<?php 
        echo $t;
        ?>
'>
                            <input type='text' id= "dateBis_<?php 
        echo $t;
        ?>
" class="form-control" />
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>

            </div>

            <div id="formgroup_server" class="form-group">
                <div class='col-sm-6'>
                    <select id = "selectServer_<?php 
        echo $t;
        ?>
" class="form-control">
                        <?php 
        foreach ($arrRestoUserIndex as $key => $val) {
            if ($key == $_GET['id_server']) {
                echo "<option selected='selected' value='" . $key . "'>" . $val . "</option>";
            } else {
                echo "<option value='" . $key . "'>" . $val . "</option>";
            }
        }
        ?>

                    </select>
                </div>
                <div class='col-sm-6'>
                    <select id = "status_payment_<?php 
        echo $t;
        ?>
" class="form-control">
                        <?php 
        foreach ($arrStatusPaymentMethod as $key => $val) {
            if ($key == $_GET['status_payment']) {
                echo "<option selected='selected' value='" . $key . "'>" . $val . "</option>";
            } else {
                echo "<option value='" . $key . "'>" . $val . "</option>";
            }
        }
        ?>

                    </select>
                </div>
                <div class="clearfix"></div>

            </div>

            <div id="formgroup_progress" class="form-group">
                <div class='col-sm-6'>
                    <select id = "status_progress_<?php 
        echo $t;
        ?>
" class="form-control">
                        <?php 
        foreach ($arrStatusProgress as $key => $val) {
            if ($key == $_GET['status_progress']) {
                echo "<option selected='selected' value='" . $key . "'>" . $val . "</option>";
            } else {
                echo "<option value='" . $key . "'>" . $val . "</option>";
            }
        }
        ?>

                    </select>
                </div>

                <div class="btn-group col-sm-4" role="group" aria-label="...">
                    <button type="button" class="btn btn-default"  id="export_<?php 
        echo $t;
        ?>
">Export</button>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>




        <script type="text/javascript">
            var dateFrom, dateTo;

            if (dateFrom == null) {
                var now = new Date();
                var day = ("0" + now.getDate()).slice(-2);
                var month = ("0" + (now.getMonth() + 1)).slice(-2);
                var dateFrom = now.getFullYear() + "-" + (month) + "-" + (day);

            }
            if (dateTo == null) {
                var now = new Date();
                var day = ("0" + now.getDate()).slice(-2);
                var month = ("0" + (now.getMonth() + 1)).slice(-2);
                var dateTo = now.getFullYear() + "-" + (month) + "-" + (day);
            }


            $('#restoID_<?php 
        echo $t;
        ?>
').change(function () {
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);

                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?id_server=0" + "&id_restaurant=" + id_restaurant + "&dateVon=" + dateFrom + "&dateBis=" + dateTo, "fade");
            });

            $('#type_order_<?php 
        echo $t;
        ?>
').change(function () {
                var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                console.log("type_order: " + type_order);
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);
                var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                console.log("server: " + server);
                var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo + "&status_progress=" + status_progress, "fade");
            });

            $('#selectServer_<?php 
        echo $t;
        ?>
').change(function () {
                var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                console.log("type_order: " + type_order);
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);
                var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                console.log("server: " + server);
                var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo + "&status_progress=" + status_progress, "fade");
            });


            $('#status_payment_<?php 
        echo $t;
        ?>
').change(function () {
                var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                console.log("type_order: " + type_order);
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);
                var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                console.log("server: " + server);
                var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo + "&status_progress=" + status_progress, "fade");
            });


            $('#status_progress_<?php 
        echo $t;
        ?>
').change(function () {
                var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                console.log("type_order: " + type_order);
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);
                var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                console.log("server: " + server);
                var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo + "&status_progress=" + status_progress, "fade");
            });


            var datetimepickerFrom = $('#datetimepickerFrom_<?php 
        echo $t;
        ?>
');
            var datetimepickerTo = $('#datetimepickerTo_<?php 
        echo $t;
        ?>
');

            $('#dateVon_<?php 
        echo $t;
        ?>
').change(function () {
                var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                console.log("type_order: " + type_order);
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);
                var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                console.log("server: " + server);
                var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                var status_progress = $('#status_progress<?php 
        echo $t;
        ?>
').val();
                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo + "&status_progress=" + status_progress, "fade");
            });


            $('#export_<?php 
        echo $t;
        ?>
').click(function () {
        <?php 
        $_SESSION["data"] = $data;
        ?>
                // initializes and invokes show immediately           
                window.open('<?php 
        echo _SPPATH;
        ?>
Report/exportIt', "_blank ");

            });
            //
            $(function () {
                datetimepickerFrom.datetimepicker({
                    format: 'DD/MM/YYYY',
                    defaultDate: dateFrom
                            //Im,portant! See issue #1075

                });
                datetimepickerTo.datetimepicker({
                    format: 'DD/MM/YYYY',
                    defaultDate: dateTo
                });
                datetimepickerFrom.on("dp.change", function (e) {
                    datetimepickerTo.data("DateTimePicker").minDate(e.date);
                    var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                    console.log("type_order: " + type_order);
                    var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                    console.log("id_restaurant: " + id_restaurant);
                    var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                    console.log("server: " + server);
                    var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                    dateFrom = new Date(e.date);
                    console.log(e);
                    if (e.oldDate != null) {
                        dateFrom = new Date();
                        dateFrom = moment().format('DD/MM/YYYY');
                    }

                    if (e.oldDate != null) {
                        var changed = false;
                        if (e.date != e.oldDate) {
                            changed = true;
                            console.log("olddate: " + e.oldDate.format('Y-M-D'));
                            console.log("Date: " + e.date.format('Y-M-D'));
                            console.log("dateVon_: " + $('#dateVon_<?php 
        echo $t;
        ?>
').val());

                            var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                            console.log("type_order: " + type_order);
                            var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                            console.log("id_restaurant: " + id_restaurant);
                            var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                            console.log("server: " + server);
                            var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                            var tglFrom = e.date.format('Y-M-D');
                            dateFrom = e.date.format('Y-M-D');
                            $('#dateVon_<?php 
        echo $t;
        ?>
').val(dateFrom);
                            var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                            if (changed) {
                                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo, "fade");
                                changed = false;
                            }

                        }

                    }


                });

                datetimepickerTo.on("dp.change", function (e) {
                    datetimepickerFrom.data("DateTimePicker").maxDate(e.date);
                    if (e.oldDate != null) {
                        var changed = false;
                        if (e.date != e.oldDate) {
                            changed = true;
                            console.log("olddate: " + e.oldDate.format('Y-M-D'));
                            console.log("Date: " + e.date.format('Y-M-D'));
                            console.log("dateBis_: " + $('#dateBis_<?php 
        echo $t;
        ?>
').val());

                            var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                            console.log("type_order: " + type_order);
                            var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                            console.log("id_restaurant: " + id_restaurant);
                            var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                            console.log("server: " + server);
                            var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                            var tglFrom = e.date.format('Y-M-D');
                            dateTo = e.date.format('Y-M-D');
                            var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                            $('#dateBis_<?php 
        echo $t;
        ?>
').val(dateTo);
                            if (changed) {
                                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo, "fade");
                                changed = false;
                            }

                        }

                    }
                });
            });
            //            $("[name='status_progress_<?php 
        echo $t;
        ?>
']").bootstrapSwitch('state', true, true);
        </script>

        <div class="col-md-12">
            <div class="table-responsive">
                <table id = "table_report_<?php 
        echo $t;
        ?>
" class="table table-bordered table-striped table-hover crud-table" style="background-color: white;">

                    <tbody><tr>
                            <th id="h_id_date_<?php 
        echo $t;
        ?>
">Date</th>
                            <th id="h_id_time_<?php 
        echo $t;
        ?>
">Time</th>
                            <th id="h_id_restaurant_<?php 
        echo $t;
        ?>
">Restaurant</th>
                            <th id="h_id_order_<?php 
        echo $t;
        ?>
">Order No.</th>
                            <th id="h_total_<?php 
        echo $t;
        ?>
">MR Fee</th>
                            <th id="h_disc_<?php 
        echo $t;
        ?>
">Credit Card Fee</th>
                            <th id="h_charges_<?php 
        echo $t;
        ?>
">Total Fee</th>
                        </tr>

                        <?php 
        foreach ($arrQuery as $key => $val) {
            ?>
                            <tr id="report_<?php 
            echo $t;
            ?>
">
                                <?php 
            $date = new DateTime($val->datetime_order);
            ?>
                                <td id="id_date_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"> <?php 
            echo $date->format('d.m.Y');
            ?>
</td>
                                <td id="id_time_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"> <?php 
            echo $date->format('H:i:s');
            ?>
</td>
                                <td id="id_restaurant_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"> <?php 
            echo $val->name;
            ?>
</td>
                                <td id="id_order_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"><?php 
            echo $val->id_order;
            ?>
</td>
                                <td id="total_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"><?php 
            echo Generic::formatRupiah($val->mr_fee);
            ?>
</td>
                                <td id="disc_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"><?php 
            echo Generic::formatRupiah($val->cc_fee);
            ?>
</td>
                                <td id="charges_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"><?php 
            echo Generic::formatRupiah($val->Total);
            ?>
</td>


                            </tr>
                        <script>
                            $('#id_order_<?php 
            echo $t . "_" . $val->id_order;
            ?>
').click(function () {
                                openLw("order_detail", "<?php 
            echo _SPPATH;
            ?>
Report/viewOrderDetail?id_order=" + <?php 
            echo $val->id_order;
            ?>
, "fade");

                            });

                        </script>
                        <?php 
        }
        ?>

                    </tbody>
                </table>
            </div>




        </div>
        <?php 
    }