<?php
namespace classs;
use PDO;
use PDOException;
class FileManager {
    private $conn;

    public function __construct($conn)
    {
        $this->conn = $conn;
    }

    public function addNewNumberIndividuals($reservation_id, $id_persons, $numper, $age_person)
    {
        // $newClientName = $_POST['new_client_name'];
        $insertNumberIndividuals = "INSERT INTO number_individuals (id_file, id_persons, number, age_person) VALUES (:id_file, :id_persons, :number, :age_person)";
        $insertNumberIndividualstStmt = $this->conn->prepare($insertNumberIndividuals);
        $insertNumberIndividualstStmt->bindParam(':id_file', $reservation_id);
        $insertNumberIndividualstStmt->bindParam(':id_persons', $id_persons);
        $insertNumberIndividualstStmt->bindParam(':number', $numper);
        $insertNumberIndividualstStmt->bindParam(':age_person', $age_person);
        // $insertNumberIndividualstStmt->execute();

        return $insertNumberIndividualstStmt->execute();
        // استخراج معرف العميل الجديد الذي تم إضافته
        // return $client_id = $this->conn->lastInsertId();
    }
    public function updateNumberIndividuals($number_individuals_id, $reservation_id, $id_persons, $numper, $age_person)
    {
        $updateQuery = "UPDATE number_individuals 
                        SET id_file = :id_file, 
                            id_persons = :id_persons, 
                            number = :number, 
                            age_person = :age_person 
                        WHERE ID = :number_individuals_id";

        $updateStmt = $this->conn->prepare($updateQuery);
        $updateStmt->bindParam(':id_file', $reservation_id);
        $updateStmt->bindParam(':id_persons', $id_persons);
        $updateStmt->bindParam(':number', $numper);
        $updateStmt->bindParam(':age_person', $age_person);
        $updateStmt->bindParam(':number_individuals_id', $number_individuals_id);

        $result = $updateStmt->execute();

        // يمكنك إرجاع true إذا تم التحديث بنجاح أو false في حالة عدم ذلك
        // أو يمكنك إرجاع عدد الصفوف التي تأثرت بالتحديث
        return $result ;
    }
    public function addNewempM($reservation_id, $id_employees, $id_department_employees)
    {
        try {
            $this->conn->beginTransaction();
            $insertNumberIndividuals = "INSERT INTO employee_booking (id_reservation, id_department_employees, id_employee) VALUES (:id_file, :id_department_employees, :id_employee)";
            $insertNumberIndividualstStmt = $this->conn->prepare($insertNumberIndividuals);
            $insertNumberIndividualstStmt->bindParam(':id_file', $reservation_id);
            $insertNumberIndividualstStmt->bindParam(':id_department_employees', $id_department_employees);
            $insertNumberIndividualstStmt->bindParam(':id_employee', $id_employees);
            $stm = $insertNumberIndividualstStmt->execute();

            $employee_booking_id = $this->conn->lastInsertId();
                $this->conn->commit();
            return $employee_booking_id;
        } catch (PDOException $e) {
            error_log("حدث خطأ فى السيرفر أثناء إضافة: " . $e->getMessage(), 0);
            $this->conn->rollBack();
            return false;
        }
    }
    public function updateEmpM($employee_booking_id, $reservation_id, $id_employees, $id_department_employees)
{
    try {
        $this->conn->beginTransaction();
        
        $updateQuery = "UPDATE employee_booking 
                        SET id_reservation = :id_reservation, 
                            id_department_employees = :id_department_employees, 
                            id_employee = :id_employee 
                        WHERE ID = :employee_booking_id";
        
        $updateStmt = $this->conn->prepare($updateQuery);
        $updateStmt->bindParam(':id_reservation', $reservation_id);
        $updateStmt->bindParam(':id_department_employees', $id_department_employees);
        $updateStmt->bindParam(':id_employee', $id_employees);
        $updateStmt->bindParam(':employee_booking_id', $employee_booking_id);
        
        $success = $updateStmt->execute();
        
        $this->conn->commit();
        
        // يمكنك إرجاع true إذا تم التحديث بنجاح أو false في حالة عدم ذلك
        // أو يمكنك إرجاع عدد الصفوف التي تأثرت بالتحديث
        return $success;
    } catch (PDOException $e) {
        error_log("حدث خطأ فى السيرفر أثناء التحديث: " . $e->getMessage(), 0);
        $this->conn->rollBack();
        return false;
    }
}
    public function addRoomPrice($hotel_id, $id_room_type, $id_meal_system, $id_currency_codes, $amountSold, $amountSold_sale, $currencyExchangeRate, $room_disc, $price, $price_sale)
    {
        // $newClientName = $_POST['new_client_name'];
        $RoomPrice = "INSERT INTO room_prices (hotel_id, id_room_type, id_meal_system, id_currency_codes, amountSold, amountSold_sale, currencyExchangeRate, room_disc, price, price_sale) VALUES (:hotel_id, :id_room_type, :id_meal_system, :id_currency_codes, :amountSold, :amountSold_sale, :currencyExchangeRate, :room_disc, :price, :price_sale)";
        $RoomPriceStmt = $this->conn->prepare($RoomPrice);
        $RoomPriceStmt->bindParam(':hotel_id', $hotel_id);
        $RoomPriceStmt->bindParam(':id_room_type', $id_room_type);
        $RoomPriceStmt->bindParam(':id_meal_system', $id_meal_system);
        $RoomPriceStmt->bindParam(':id_currency_codes', $id_currency_codes);
        $RoomPriceStmt->bindParam(':amountSold', $amountSold);
        $RoomPriceStmt->bindParam(':amountSold_sale', $amountSold_sale);
        $RoomPriceStmt->bindParam(':currencyExchangeRate', $currencyExchangeRate);
        $RoomPriceStmt->bindParam(':room_disc', $room_disc);
        $RoomPriceStmt->bindParam(':price', $price);
        $RoomPriceStmt->bindParam(':price_sale', $price_sale);
        $RoomPriceStmt->execute();

        // return $insertNumberIndividualstStmt->execute();
        return $RoomPrice_id = $this->conn->lastInsertId();
    }
    public function updateRoomPrice($roomPriceId, $hotel_id, $id_room_type, $id_meal_system, $id_currency_codes, $amountSold, $amountSold_sale, $currencyExchangeRate, $room_disc, $price, $price_sale)
{
    $updateQuery = "UPDATE room_prices SET hotel_id = :hotel_id, id_room_type = :id_room_type, id_meal_system = :id_meal_system, id_currency_codes = :id_currency_codes, amountSold = :amountSold, amountSold_sale = :amountSold_sale, currencyExchangeRate = :currencyExchangeRate, room_disc = :room_disc, price = :price, price_sale = :price_sale WHERE ID = :roomPriceId";
    
    $stmt = $this->conn->prepare($updateQuery);
    $stmt->bindParam(':hotel_id', $hotel_id);
    $stmt->bindParam(':id_room_type', $id_room_type);
    $stmt->bindParam(':id_meal_system', $id_meal_system);
    $stmt->bindParam(':id_currency_codes', $id_currency_codes);
    $stmt->bindParam(':amountSold', $amountSold);
    $stmt->bindParam(':amountSold_sale', $amountSold_sale);
    $stmt->bindParam(':currencyExchangeRate', $currencyExchangeRate);
    $stmt->bindParam(':room_disc', $room_disc);
    $stmt->bindParam(':price', $price);
    $stmt->bindParam(':price_sale', $price_sale);
    $stmt->bindParam(':roomPriceId', $roomPriceId);
    
    $stmt->execute();

    // للتحقق من نجاح التحديث، يمكنك إرجاع true أو false
    // أو يمكنك إرجاع عدد الصفوف التي تأثرت بالتحديث
    return $stmt->rowCount() > 0;
}
    public function addHotelBooking($id_reservation, $id_hotel, $id_room_prices, $rooms_number, $check_in_date, $check_out_date, $check_status, $note, $TAX, $invaled_number, $children_number, $cost_children, $free_invaled, $discount_free, $user_id_insert)
    {
        // $newClientName = $_POST['new_client_name'];
        $HotelBooking = "INSERT INTO hotel_bookings (id_reservation, id_hotel, id_room_prices, rooms_number, TAX, invaled_number, children_number, cost_children, free_invaled, discount_free, check_in_date, check_out_date, check_status, note, user_id_insert) 
                                            VALUES (:id_reservation,:id_hotel,:id_room_prices,:rooms_number, :TAX, :invaled_number, :children_number, :cost_children, :free_invaled, :discount_free, :check_in_date, :check_out_date, :check_status, :note, :user_id_insert)";
        $HotelBookingStmt = $this->conn->prepare($HotelBooking);
        $HotelBookingStmt->bindParam(':id_reservation', $id_reservation);
        $HotelBookingStmt->bindParam(':id_hotel', $id_hotel);
        $HotelBookingStmt->bindParam(':id_room_prices', $id_room_prices);
        $HotelBookingStmt->bindParam(':rooms_number', $rooms_number);
        $HotelBookingStmt->bindParam(':TAX', $TAX);
        $HotelBookingStmt->bindParam(':invaled_number', $invaled_number);
        $HotelBookingStmt->bindParam(':children_number', $children_number);
        $HotelBookingStmt->bindParam(':cost_children', $cost_children);
        $HotelBookingStmt->bindParam(':free_invaled', $free_invaled);
        $HotelBookingStmt->bindParam(':discount_free', $discount_free);
        $HotelBookingStmt->bindParam(':check_in_date', $check_in_date);
        $HotelBookingStmt->bindParam(':check_out_date', $check_out_date);
        $HotelBookingStmt->bindParam(':check_status', $check_status);
        $HotelBookingStmt->bindParam(':note', $note);
        $HotelBookingStmt->bindParam(':user_id_insert', $user_id_insert);
        $HotelBookingStmt->execute();
        $hotel_bookings_id = $this->conn->lastInsertId();

        return $hotel_bookings_id;
        // استخراج معرف العميل الجديد الذي تم إضافته
        // return $HotelBooking_id = $this->conn->lastInsertId();
    }
    public function updateHotelBooking($id_hotel_booking, $id_reservation, $id_hotel, $id_room_prices, $rooms_number, $check_in_date, $check_out_date, $check_status, $note, $TAX, $invaled_number, $children_number, $cost_children, $free_invaled, $discount_free, $user_id_update)
{
    $updateQuery = "UPDATE hotel_bookings 
                    SET id_reservation = :id_reservation, 
                        id_hotel = :id_hotel, 
                        id_room_prices = :id_room_prices, 
                        rooms_number = :rooms_number, 
                        TAX = :TAX, 
                        invaled_number = :invaled_number, 
                        children_number = :children_number, 
                        cost_children = :cost_children, 
                        free_invaled = :free_invaled, 
                        discount_free = :discount_free, 
                        check_in_date = :check_in_date, 
                        check_out_date = :check_out_date, 
                        check_status = :check_status, 
                        note = :note,
                        user_id_update = :user_id_update 
                    WHERE ID = :id_hotel_booking";

    $stmt = $this->conn->prepare($updateQuery);
    $stmt->bindParam(':id_reservation', $id_reservation);
    $stmt->bindParam(':id_hotel', $id_hotel);
    $stmt->bindParam(':id_room_prices', $id_room_prices);
    $stmt->bindParam(':rooms_number', $rooms_number);
    $stmt->bindParam(':TAX', $TAX);
    $stmt->bindParam(':invaled_number', $invaled_number);
    $stmt->bindParam(':children_number', $children_number);
    $stmt->bindParam(':cost_children', $cost_children);
    $stmt->bindParam(':free_invaled', $free_invaled);
    $stmt->bindParam(':discount_free', $discount_free);
    $stmt->bindParam(':check_in_date', $check_in_date);
    $stmt->bindParam(':check_out_date', $check_out_date);
    $stmt->bindParam(':check_status', $check_status);
    $stmt->bindParam(':note', $note);
    $stmt->bindParam(':user_id_update', $user_id_update);
    $stmt->bindParam(':id_hotel_booking', $id_hotel_booking);

    $stmt->execute();

    // للتحقق من نجاح التحديث، يمكنك إرجاع true أو false
    // أو يمكنك إرجاع عدد الصفوف التي تأثرت بالتحديث
    return $stmt->rowCount() > 0;
}
    public function addTrainBooking(
        $id_reservation,
        $train_name,
        $arrival_station,
        $departure_station,
        $arrival_time,
        $departure_time,
        $arrival_date,
        $departure_date,
        $number_individuals,
        $id_currency_codes,
        $amountSold,
        $amountSold_sale,
        $currencyExchangeRate,
        $cost_individual,
        $cost_sale_individual,
        $total_cost,
        $total_cost_sale,
        $user_id_insert
    )
    {
        // $newClientName = $_POST['new_client_name'];
        $HotelBooking = "INSERT INTO train_bookings (id_reservation, train_name, arrival_station, departure_station, arrival_time, departure_time, arrival_date, departure_date, number_individuals, id_currency_codes, amountSold, amountSold_sale, currencyExchangeRate, cost_individual, cost_sale_individual, total_cost, total_cost_sale, user_id_insert) 
                                            VALUES (:id_reservation,:train_name,:arrival_station,:departure_station,:arrival_time,:departure_time, :arrival_date, :departure_date,:number_individuals,:id_currency_codes,:amountSold, :amountSold_sale, :currencyExchangeRate,:cost_individual, :cost_sale_individual, :total_cost, :total_cost_sale, :user_id_insert)";
        $HotelBookingStmt = $this->conn->prepare($HotelBooking);
        $HotelBookingStmt->bindParam(':id_reservation', $id_reservation);
        $HotelBookingStmt->bindParam(':train_name', $train_name);
        $HotelBookingStmt->bindParam(':arrival_station', $arrival_station);
        $HotelBookingStmt->bindParam(':departure_station', $departure_station);
        $HotelBookingStmt->bindParam(':arrival_time', $arrival_time);
        $HotelBookingStmt->bindParam(':departure_time', $departure_time);
        $HotelBookingStmt->bindParam(':arrival_date', $arrival_date);
        $HotelBookingStmt->bindParam(':departure_date', $departure_date);
        $HotelBookingStmt->bindParam(':number_individuals', $number_individuals);
        $HotelBookingStmt->bindParam(':id_currency_codes', $id_currency_codes);
        $HotelBookingStmt->bindParam(':amountSold', $amountSold);
        $HotelBookingStmt->bindParam(':amountSold_sale', $amountSold_sale);
        $HotelBookingStmt->bindParam(':currencyExchangeRate', $currencyExchangeRate);
        $HotelBookingStmt->bindParam(':cost_individual', $cost_individual);
        $HotelBookingStmt->bindParam(':cost_sale_individual', $cost_sale_individual);
        $HotelBookingStmt->bindParam(':total_cost', $total_cost);
        $HotelBookingStmt->bindParam(':total_cost_sale', $total_cost_sale);
        $HotelBookingStmt->bindParam(':user_id_insert', $user_id_insert);
        $HotelBookingStmt->execute();
        $hotel_bookings_id = $this->conn->lastInsertId();

        return $hotel_bookings_id;
        // استخراج معرف العميل الجديد الذي تم إضافته
        // return $HotelBooking_id = $this->conn->lastInsertId();
    }
    public function addFlightBooking(
        $id_reservation,
        $id_airline,
        $flight_number,
        $arrival_station,
        $departure_station,
        $arrival_time,
        $departure_time,
        $arrival_date,
        $departure_date,
        $number_individuals,
        $id_currency_codes,
        $amountSold,
        $amountSold_sale,
        $currencyExchangeRate,
        $cost_individual,
        $cost_sale_individual,
        $total_cost,
        $total_cost_sale,
        $user_id_insert
    )
    {
        // $newClientName = $_POST['new_client_name'];
        $HotelBooking = "INSERT INTO flight_bookings (id_reservation, id_airline, flight_number, arrival_airport, departure_airport, arrival_time, departure_time, arrival_date, departure_date, number_individuals, id_currency_codes, amountSold, amountSold_sale, currencyExchangeRate, cost_individual, cost_sale_individual, total_cost, total_cost_sale, user_id_insert) 
                                            VALUES (:id_reservation,:id_airline, :flight_number, :arrival_airport,:departure_airport,:arrival_time,:departure_time, :arrival_date, :departure_date,:number_individuals,:id_currency_codes,:amountSold, :amountSold_sale, :currencyExchangeRate,:cost_individual, :cost_sale_individual, :total_cost, :total_cost_sale, :user_id_insert)";
        $HotelBookingStmt = $this->conn->prepare($HotelBooking);
        $HotelBookingStmt->bindParam(':id_reservation', $id_reservation);
        $HotelBookingStmt->bindParam(':id_airline', $id_airline);
        $HotelBookingStmt->bindParam(':flight_number', $flight_number);
        $HotelBookingStmt->bindParam(':arrival_airport', $arrival_station);
        $HotelBookingStmt->bindParam(':departure_airport', $departure_station);
        $HotelBookingStmt->bindParam(':arrival_time', $arrival_time);
        $HotelBookingStmt->bindParam(':departure_time', $departure_time);
        $HotelBookingStmt->bindParam(':arrival_date', $arrival_date);
        $HotelBookingStmt->bindParam(':departure_date', $departure_date);
        $HotelBookingStmt->bindParam(':number_individuals', $number_individuals);
        $HotelBookingStmt->bindParam(':id_currency_codes', $id_currency_codes);
        $HotelBookingStmt->bindParam(':amountSold', $amountSold);
        $HotelBookingStmt->bindParam(':amountSold_sale', $amountSold_sale);
        $HotelBookingStmt->bindParam(':currencyExchangeRate', $currencyExchangeRate);
        $HotelBookingStmt->bindParam(':cost_individual', $cost_individual);
        $HotelBookingStmt->bindParam(':cost_sale_individual', $cost_sale_individual);
        $HotelBookingStmt->bindParam(':total_cost', $total_cost);
        $HotelBookingStmt->bindParam(':total_cost_sale', $total_cost_sale);
        $HotelBookingStmt->bindParam(':user_id_insert', $user_id_insert);
        $HotelBookingStmt->execute();
        $hotel_bookings_id = $this->conn->lastInsertId();

        return $hotel_bookings_id;
        // استخراج معرف العميل الجديد الذي تم إضافته
        // return $HotelBooking_id = $this->conn->lastInsertId();
    }
    public function addBookingFile(
        $id_reservation,
        $id_line_type,
        $id_line_booking,
        $id_invoicing_type_exp,
        $name_type,
        $mydate,
        $number_individuals,
        $id_currency_codes,
        $amountSold,
        $amountSold_sale,
        $currencyExchangeRate,
        $cost_individual,
        $cost_sale_individual,
        $total_cost,
        $total_cost_sale,
        $user_id_insert
    )
    {
        // $newClientName = $_POST['new_client_name'];
        $HotelBooking = "INSERT INTO booking_file (id_reservation, id_line_type ,id_line_booking , id_invoicing_type_exp, name_type, mydate, number_individuals, id_currency_codes, amountSold, amountSold_sale, currencyExchangeRate, cost_individual, cost_sale_individual, total_cost, total_cost_sale, user_id_insert) 
                                            VALUES (:id_reservation, :id_line_type, :id_line_booking, :id_invoicing_type_exp, :name_type, :mydate, :number_individuals, :id_currency_codes,:amountSold, :amountSold_sale, :currencyExchangeRate, :cost_individual, :cost_sale_individual, :total_cost, :total_cost_sale, :user_id_insert)";
        $HotelBookingStmt = $this->conn->prepare($HotelBooking);
        $HotelBookingStmt->bindParam(':id_reservation', $id_reservation);
        $HotelBookingStmt->bindParam(':id_line_type', $id_line_type);
        $HotelBookingStmt->bindParam(':id_line_booking', $id_line_booking);
        $HotelBookingStmt->bindParam(':id_invoicing_type_exp', $id_invoicing_type_exp);
        $HotelBookingStmt->bindParam(':name_type', $name_type);
        $HotelBookingStmt->bindParam(':mydate', $mydate);
        $HotelBookingStmt->bindParam(':number_individuals', $number_individuals);
        $HotelBookingStmt->bindParam(':id_currency_codes', $id_currency_codes);
        $HotelBookingStmt->bindParam(':amountSold', $amountSold);
        $HotelBookingStmt->bindParam(':amountSold_sale', $amountSold_sale);
        $HotelBookingStmt->bindParam(':currencyExchangeRate', $currencyExchangeRate);
        $HotelBookingStmt->bindParam(':cost_individual', $cost_individual);
        $HotelBookingStmt->bindParam(':cost_sale_individual', $cost_sale_individual);
        $HotelBookingStmt->bindParam(':total_cost', $total_cost);
        $HotelBookingStmt->bindParam(':total_cost_sale', $total_cost_sale);
        $HotelBookingStmt->bindParam(':user_id_insert', $user_id_insert);
        $HotelBookingStmt->execute();
        $hotel_bookings_id = $this->conn->lastInsertId();

        return $hotel_bookings_id;
        // استخراج معرف العميل الجديد الذي تم إضافته
        // return $HotelBooking_id = $this->conn->lastInsertId();
    }
    public function updateBookingFile(
        $id_reservation,
        $id_line_type,
        $id_line_booking,
        $id_invoicing_type_exp,
        $name_type,
        $mydate,
        $number_individuals,
        $id_currency_codes,
        $amountSold,
        $amountSold_sale,
        $currencyExchangeRate,
        $cost_individual,
        $cost_sale_individual,
        $total_cost,
        $total_cost_sale,
        $user_id_insert
    ) {
        $updateQuery = "UPDATE booking_file SET 
                        id_reservation = :id_reservation, 
                        id_invoicing_type_exp = :id_invoicing_type_exp, 
                        name_type = :name_type, 
                        mydate = :mydate, 
                        number_individuals = :number_individuals, 
                        id_currency_codes = :id_currency_codes, 
                        amountSold = :amountSold, 
                        amountSold_sale = :amountSold_sale, 
                        currencyExchangeRate = :currencyExchangeRate, 
                        cost_individual = :cost_individual, 
                        cost_sale_individual = :cost_sale_individual, 
                        total_cost = :total_cost, 
                        total_cost_sale = :total_cost_sale, 
                        user_id_update = :user_id_update 
                        WHERE id_line_type = :id_line_type AND id_line_booking = :id_line_booking";
    
        $stmt = $this->conn->prepare($updateQuery);
        $stmt->bindParam(':id_line_type', $id_line_type);
        $stmt->bindParam(':id_line_booking', $id_line_booking);
        // Bind the rest of the parameters as in addBookingFile
        $stmt->bindParam(':id_reservation', $id_reservation);
        $stmt->bindParam(':id_invoicing_type_exp', $id_invoicing_type_exp);
        $stmt->bindParam(':name_type', $name_type);
        $stmt->bindParam(':mydate', $mydate);
        $stmt->bindParam(':number_individuals', $number_individuals);
        $stmt->bindParam(':id_currency_codes', $id_currency_codes);
        $stmt->bindParam(':amountSold', $amountSold);
        $stmt->bindParam(':amountSold_sale', $amountSold_sale);
        $stmt->bindParam(':currencyExchangeRate', $currencyExchangeRate);
        $stmt->bindParam(':cost_individual', $cost_individual);
        $stmt->bindParam(':cost_sale_individual', $cost_sale_individual);
        $stmt->bindParam(':total_cost', $total_cost);
        $stmt->bindParam(':total_cost_sale', $total_cost_sale);
        $stmt->bindParam(':user_id_update', $user_id_insert);
    
        
    
        // To verify if the update was successful, you can return true or false
        // Or you can return the number of rows that were affected by the update
        return $stmt->execute();
    }
    public function addRunCommandBooking(
        $date_run, 
        $date_out, 
        $id_driver, 
        $name_driver, 
        $id_companies_transportation, 
        $id_vehicles, 
        $no_car, 
        $location_now, 
        $vehicle_capacity, 
        $operation_statement, 
        $client_or_file, 
        $id_operator, 
        $id_employee_M, 
        $number_individuals, 
        $NO_run_command, 
        $hour_doing, 
        $hour_return, 
        $counter_doing, 
        $counter_return, 
        $distance_travelled, 
        $id_employee_mang, 
        $nots_run,
        $id_currency_codes,
        $amountSold,
        $amountSold_sale,
        $currencyExchangeRate,
        $total_cost,
        $total_cost_sale,
        $sessionUser
    )
    {
        // Use generateFileNumber function
        // $file_number = $this->generateFileNumber($departure_date);

        // Add your validation and sanitization here before executing the SQL query
        try {
            $sql = "INSERT INTO run_command (date_run, date_out, id_driver, name_driver, id_companies_transportation, id_vehicles, no_car, location_now, vehicle_capacity, operation_statement, client_or_file, id_operator, id_employee_M, number_individuals, NO_run_command, hour_doing, hour_return, counter_doing, counter_return, distance_travelled, id_employee_mang, nots_run, id_currency_codes, amountSold, amountSold_sale, currencyExchangeRate, total_cost, total_cost_sale, user_id_insert)
                            VALUES (:date_run,
                                    :date_out,
                                    :id_driver,
                                    :name_driver,
                                    :id_companies_transportation,
                                    :id_vehicles,
                                    :no_car,
                                    :location_now,
                                    :vehicle_capacity,
                                    :operation_statement,
                                    :client_or_file,
                                    :id_operator,
                                    :id_employee_M,
                                    :number_individuals,
                                    :NO_run_command,
                                    :hour_doing,
                                    :hour_return,
                                    :counter_doing,
                                    :counter_return,
                                    :distance_travelled,
                                    :id_employee_mang,
                                    :nots_run,
                                    :id_currency_codes,
                                    :amountSold,
                                    :amountSold_sale,
                                    :currencyExchangeRate,
                                    :total_cost,
                                    :total_cost_sale,
                                    :user_id_insert)";

            $stmt = $this->conn->prepare($sql);
            $stmt->bindParam(':date_run', $date_run);
            $stmt->bindParam(':date_out', $date_out);
            $stmt->bindParam(':id_driver', $id_driver);
            $stmt->bindParam(':name_driver', $name_driver);
            $stmt->bindParam(':id_companies_transportation', $id_companies_transportation);
            $stmt->bindParam(':id_vehicles', $id_vehicles);
            $stmt->bindParam(':no_car', $no_car);
            $stmt->bindParam(':location_now', $location_now);
            $stmt->bindParam(':vehicle_capacity', $vehicle_capacity);
            $stmt->bindParam(':operation_statement', $operation_statement);
            $stmt->bindParam(':client_or_file', $client_or_file);
            $stmt->bindParam(':id_operator', $id_operator);
            $stmt->bindParam(':id_employee_M', $id_employee_M);
            $stmt->bindParam(':number_individuals', $number_individuals);
            $stmt->bindParam(':NO_run_command', $NO_run_command);
            $stmt->bindParam(':hour_doing', $hour_doing);
            $stmt->bindParam(':hour_return', $hour_return);
            $stmt->bindParam(':counter_doing', $counter_doing);
            $stmt->bindParam(':counter_return', $counter_return);
            $stmt->bindParam(':distance_travelled', $distance_travelled);
            $stmt->bindParam(':id_employee_mang', $id_employee_mang);
            $stmt->bindParam(':nots_run', $nots_run);
            $stmt->bindParam(':id_currency_codes', $id_currency_codes);
            $stmt->bindParam(':amountSold', $amountSold);
            $stmt->bindParam(':amountSold_sale', $amountSold_sale);
            $stmt->bindParam(':currencyExchangeRate', $currencyExchangeRate);
            $stmt->bindParam(':total_cost', $total_cost);
            $stmt->bindParam(':total_cost_sale', $total_cost_sale);
            $stmt->bindParam(':user_id_insert', $sessionUser);
            $restmt = $stmt->execute();

            $run_command_id = $this->conn->lastInsertId();

            logToHistory('insert', 'run_command', $run_command_id, '', '', 'id');

            
            return $run_command_id;
        } catch (PDOException $e) {
            error_log("حدث خطأ فى السيرفر أثناء إضافة الملف: " . $e->getMessage(), 0);
            return false;
        }
    }
    public function generateNoRunCommand()
    {
        // echo "Formatted Departure Date: $formatted_departure_date<br>";

        $sql_search = "SELECT MAX(NO_run_command) AS max_NO_run
                    FROM run_command ";

        $stmt_search = $this->conn->prepare($sql_search);
        $stmt_search->execute();
        $row_search = $stmt_search->fetch(PDO::FETCH_ASSOC);
        $max_NO_run = $row_search['max_NO_run'];
        // echo "Max File Number: $max_file_number<br>";

        $new_NO_run = ($max_NO_run === null) ? 1 : ($max_NO_run + 1);
        // echo "Generated File Number: $file_number<br>";

        return $new_NO_run;
    }

}