function count_item_that_needs_time($criteria)
{
    $item_that_takes_time = 0;
    $cart_max_item = get_cart_max_item();
    $var_count = 1;
    while ($var_count <= $cart_max_item) {
        if (!empty($_SESSION["item_{$var_count}"])) {
            $current_item = $_SESSION["item_{$var_count}"];
            $food_id = clean_input($current_item["cart_item_id"]);
            if (get_food_single_info($food_id, "need_time_to_prepare") == 1) {
                $item_that_takes_time++;
            }
        }
        // end if
        $var_count++;
    }
    // end while loop
    return $item_that_takes_time;
}
function send_pickup_slip_to_restaurant($cust_invoice_number)
{
    require_once "global_functions.php";
    require_once "mysql_functions.php";
    global $restaurant_email_username;
    global $restaurant_email_password;
    global $email_endpoint;
    //////////// QUERY FOR ALL NECCESSARY INFO ////////////
    $bill_info = get_bill_info_by_invoice_number($cust_invoice_number);
    $cust_info = get_cust_info_by_id($bill_info["placed_by_cust_id"]);
    $order_info = get_order_info_by_invoice_number($cust_invoice_number);
    //////////// SETTING UP VARIABLES //////////////
    date_default_timezone_set('America/Los_Angeles');
    $subtotal = $bill_info["subtotal"];
    $tax = $bill_info["tax"];
    $tip = $bill_info["tip"];
    if ($tip == 0) {
        $tip = "No Tip";
    }
    $order_time = date("g:i a", $bill_info["time_placed"]);
    $order_date = date("l. F jS, Y", $bill_info["time_placed"]);
    $cust_phone = "(" . substr($cust_info["phone"], 0, 3) . ")" . substr($cust_info["phone"], 3, 3) . "-" . substr($cust_info["phone"], 6, 4);
    if (!empty($cust_info["alt_phone"])) {
        $cust_alt_phone = "(" . substr($cust_info["alt_phone"], 0, 3) . ") " . substr($cust_info["alt_phone"], 3, 3) . "-" . substr($cust_info["alt_phone"], 6, 4);
    } else {
        $cust_alt_phone = NULL;
    }
    //////////// CHECK IF THERE'S ANY ADDITIONAL WAIT TIME /////////////
    $temp_order_info = $order_info;
    $item_that_needs_preparation_time = 0;
    while ($temp_order_info) {
        $temp_single_order_info = array_shift($temp_order_info);
        $temp_food_id = $temp_single_order_info["food_id"];
        if (get_food_single_info($temp_food_id, "need_time_to_prepare") == 1) {
            $item_that_needs_preparation_time++;
        }
    }
    // end while
    if ($item_that_needs_preparation_time > get_server_value("additional_wait_time_treshold")) {
        $additional_wait_time = ($item_that_needs_preparation_time - get_server_value("additional_wait_time_treshold")) * get_server_value("additional_wait_time_increment");
    } else {
        $additional_wait_time = 0;
        $additional_wait_time_en = 0;
        $additional_wait_time_th = 0;
    }
    //////////// ESTIMATE THE PICK-UP TIME ////////////
    $estimated_pickup_time = $bill_info["time_placed"] + ($bill_info["wait_time"] + $additional_wait_time) * 60;
    $estimated_pickup_time = date("g:i a", $estimated_pickup_time);
    //////////// FORMAT THE ADDITIONAL WAIT TIME ////////////////
    if ($additional_wait_time != 0) {
        $additional_wait_time_en = "+ " . $additional_wait_time . " minutes due to the size of the order";
    }
    $mail = new PHPMailer();
    $mail->CharSet = 'UTF-8';
    // Set charset
    $mail->isSMTP();
    // Set mailer to use SMTP
    $mail->Host = 'smtp.live.com';
    // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;
    // Enable SMTP authentication
    $mail->Username = $restaurant_email_username;
    // SMTP username
    $mail->Password = $restaurant_email_password;
    // SMTP password
    $mail->SMTPSecure = 'tls';
    // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;
    // TCP port to connect to
    $mail->From = $restaurant_email_username;
    $mail->FromName = 'Nayada Thai Cuisine';
    $mail->addAddress($email_endpoint, "Nayada Thai Cuisine");
    // Add a recipient
    //$mail->addBCC($restaurant_email_username);
    //$mail->addAttachment('/var/tmp/file.tar.gz');       // Add attachments
    $mail->isHTML(true);
    // Set email format to HTML
    $mail->Subject = 'Pick-up Slip (' . $cust_invoice_number . ')';
    ///////////////////////////// PICK-UP SLIP BODY //////////////////////////////
    $mail->Body = '<p style="text-align: center; width: 900px; background-color: #000; color: #FFF; font-size: 120%; margin: 0 0 20px 0; padding: 5px 0 5px 0;"><strong>Pick-up Slip - Order # ' . $cust_invoice_number . '</strong></p>';
    // FOOD LIST AREA
    $mail->Body .= '	  <p style="font-size: 70%; margin: 0;">Payment Method         : ' . $bill_info["payment_method"] . '</p>
						  <p style="font-size: 70%; margin: 0;">Transaction ID         : ' . $bill_info["transaction_id"] . '</p>
						  <p style="font-size: 70%; margin: 0;">Transaction Type       : ' . $bill_info["transaction_type"] . '</p>
						  <p style="font-size: 70%; margin: 0;">Subtotal               : ' . $bill_info["subtotal"] . '</p>
						  <p style="font-size: 70%; margin: 0;">Tax (' . $bill_info["tax_rate"] . ' %) : $ ' . $tax . '</p>
						  <p style="font-size: 70%; margin: 0;">Tip					: $ ' . $tip . '</p>
						  <p style="margin: 0;">Amount Charged         : $ ' . $bill_info["amount_charged"] . '</p>
						  <p style="font-size: 70%; margin: 0;">Order Date             : ' . $order_date . '</p>
						  <p style="font-size: 70%; margin: 0;">Order Time             : ' . $order_time . '</p>
						  <p style="font-size: 70%; margin: 0;">Wait Time              : ' . $bill_info["wait_time"] . '</p>
						  <p style="font-size: 70%; margin: 0;">Additional Wait Time   : ' . $additional_wait_time_en . '</p>
						  <p style="margin: 0;">Estimated Pick-up Time : ' . $estimated_pickup_time . '</p>
						  <p style="margin: 0; text-align: center;">---------------------------------------------</p>
						  <p style="margin: 0;">Customer ID : ' . $bill_info["placed_by_cust_id"] . '</p>
						  <p style="margin: 0;">' . $cust_phone . ' ( primary # )</p>';
    if (!empty($cust_alt_phone)) {
        $mail->Body .= '<p style="margin: 0;">' . $cust_alt_phone . ' ( alternate # )</p>';
    }
    $mail->Body .= '<p style="margin: 0; text-align: center;">---------------------------------------------</p>
						  <p style="font-size: 90%; text-align: center; margin-bottom: 300px;">I certify that I have received<br />all item(s) from order #' . $cust_invoice_number . '</p>
						  <p>&nbsp;</p>
						  <p style="text-align: center; margin: 0;">__________________________</p>
						  <p style="margin: 0; font-size: 90%; text-align: center;">' . $cust_info["name_first"] . ' ' . $cust_info["name_last"] . '</p>
						  <p style="text-align: center;">THANK YOU</p>';
    // if test mode is on
    if ($bill_info["transaction_mode"] === "test_mode") {
        $mail->Body .= '<p style="text-align: center; width: 900px; background-color: #000; color: #FFF; font-size: 150%; margin: 50px 0 0 0; padding: 5px 0 5px 0;"><strong>TEST MODE</strong></p>';
    }
    // end if test mode
    $mail->AltBody = '';
    if (!$mail->send()) {
        //		echo 'Message could not be sent.';
        //		echo 'Mailer Error: ' . $mail->ErrorInfo;
        return false;
    } else {
        //		echo 'Message has been sent';
        return true;
    }
}