public function emailExcelReportDayByDayOrder()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idResto = $this->mustCheck($_GET['id_restaurant'], "NO ID Restaurant");
     $range = $_GET['range'] == null || $_GET['range'] == "" ? 30 : $_GET['range'];
     $extraQ = $this->selectTypeOrder($_GET['type_order']);
     $idServer = $_GET['id_user'];
     $extraQ .= $idServer == null || $idServer == "" || $idServer == "0" ? "" : "AND id_server='{$idServer}'";
     $extraQ .= $_GET['voided'] == null || $_GET['voided'] == "" || $_GET['voided'] == "0" ? " AND status_progress='4' " : "AND status_progress='9' AND voided='1'";
     $extraQ .= $_GET['status_payment'] == null || $_GET['status_payment'] == "" || $_GET['status_payment'] == "999" ? "" : "AND status_payment='" . $_GET['status_payment'] . "'";
     ///EXCEL
     $ex = array();
     $resto = new MasterRestaurantModel();
     $resto->getByID($idResto);
     $text = "Report\t" . $resto->name . "\t" . date('Y-m-d H:i:s') . "\n";
     $text .= "Interval\t{$range} day(s)\n";
     $text .= "Server\t";
     if ($idServer == null || $idServer == "" || $idServer == "0") {
         $text .= "All Server\n";
     } else {
         $sr = new RestaurantUserModel();
         $sr->getByID($idServer);
         $text .= $sr->name . "\n";
     }
     $text .= "Type Order\t" . Generic::selectStringTypeOrder($_GET['type_order']) . "\n";
     $text .= "Order Status\t";
     $text .= $_GET['voided'] == null || $_GET['voided'] == "" || $_GET['voided'] == "0" ? "Finished Order\n" : "Voided Order\n";
     $text .= "Payment Method\t" . $this->selectTypePayment($_GET['status_payment']) . "\n\n";
     for ($i = 0; $i <= $range; $i++) {
         $date = date('Y-m-d', strtotime("-{$i} days"));
         $o = new MasterOrderModel();
         if ($range == 999) {
             $arrO = $o->getWhere("id_restaurant='{$idResto}' {$extraQ}");
         } else {
             $arrO = $o->getWhere("id_restaurant='{$idResto}' AND DATE(datetime_order)='{$date}' {$extraQ}");
         }
         if (count($arrO) == 0) {
             continue;
         }
         $text .= "Order ID " . $arrO[0]->id_order . "\n";
         if ($arrO[0]->id_server != null || $arrO[0]->id_server != "" || $arrO[0]->id_server != "0") {
             unset($sr);
             $sr = new RestaurantUserModel();
             $sr->getByID($idServer);
             $text .= "Server\t" . $sr->name . "\n";
         }
         $text .= "Time Order\t" . leap_mysqldate_isi($arrO[0]->id_server) . "\n";
         $text .= "Total\t" . $arrO[0]->total_cost . "\n";
         $text .= $arrO[0]->disc_mr == 0 ? "" : "Disc MR\t" . $arrO[0]->disc_mr . "\n";
         $text .= $arrO[0]->disc_resto == 0 ? "" : "Disc Resto\t" . $arrO[0]->disc_resto . "\n";
         $text .= $arrO[0]->disc_bank == 0 ? "" : "Disc Bank\t" . $arrO[0]->disc_bank . "\n";
         $text .= $arrO[0]->disc_other == 0 ? "" : "Disc Other\t" . $arrO[0]->disc_other . "\n";
         $text .= $arrO[0]->tax_pb1 == 0 ? "" : "Tax PB 1\t" . $arrO[0]->tax_pb1 . "\n";
         $text .= $arrO[0]->service_charge == 0 ? "" : "Service Charge\t" . $arrO[0]->service_charge . "\n";
         $text .= $arrO[0]->other_charge == 0 ? "" : "Other Charge\t" . $arrO[0]->other_charge . "\n";
         $text .= "Grand Total\t" . $arrO[0]->grand_total . "\n";
         $text .= "ID Details\tDish Name\tQuantity\tPrice\tVoided\tNote\n";
         foreach ($arrO as $or) {
             $ex[] = $or;
             $detailsOrder = OrderDetail::getOrderDetailsByIDOrder($or->id_order);
             foreach ($detailsOrder as $dor) {
                 $text .= $dor['id_order_detail'] . "\t";
                 $text .= $dor['name'] . "\t";
                 $text .= $dor['quantity'] . "\t";
                 $text .= $dor['price'] . "\t";
                 $text .= $dor['voided'] == "1" ? "YES\t" : "NO\t";
                 $text .= $dor['note'] . "\t";
                 $text .= "\n";
             }
         }
         $text .= "\n\n";
     }
     if (count($ex) <= 0) {
         //            Generic::errorMsg("Empty Record");
         $text .= "EMPTY RECORD\n\n";
     }
     $title = "Report_" . $resto->name . "_" . 1000 * strtotime(date('Y-m-d H:i:s'));
     header("Content-Disposition: attachment; filename=\"{$title}\".xls");
     header("Content-Type: application/vnd.ms-excel");
     $file = fopen($title, "w+");
     fwrite($file, $text);
     fclose($file);
     die;
 }