From 112efbc31499940870136494df78f618587e078c Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 26 Feb 2022 11:16:33 -0500 Subject: [PATCH] DB Update tip_user_id added to the trips tables. Updated Trips to include the driver. WIP limit users to the session_company --- client_trips.php | 14 ++++++++++++-- db.sql | 7 ++++--- post.php | 6 ++++-- trip_add_modal.php | 25 +++++++++++++++++++++++++ trip_copy_modal.php | 25 +++++++++++++++++++++++++ trip_edit_modal.php | 25 +++++++++++++++++++++++++ trips.php | 12 +++++++++++- 7 files changed, 106 insertions(+), 8 deletions(-) diff --git a/client_trips.php b/client_trips.php index 9b3a9b8c..38c5a49d 100644 --- a/client_trips.php +++ b/client_trips.php @@ -48,8 +48,9 @@ if(isset($_GET['dtf'])){ //Rebuild URL $url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o' => $o))); -$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM trips - WHERE (trip_purpose LIKE '%$q%' OR trip_source LIKE '%$q%' OR trip_destination LIKE '%$q%') +$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM trips + LEFT JOIN users ON trip_user_id = user_id + WHERE (trip_purpose LIKE '%$q%' OR trip_source LIKE '%$q%' OR trip_destination LIKE '%$q%' OR user_name LIKE '%$q%') AND DATE(trip_date) BETWEEN '$dtf' AND '$dtt' AND company_id = $session_company_id AND trip_client_id = $client_id @@ -96,6 +97,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); "> Date + Driver Purpose From To @@ -113,6 +115,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); $trip_source = $row['trip_source']; $trip_destination = $row['trip_destination']; $trip_miles = $row['trip_miles']; + $trip_user_id = $row['trip_user_id']; $round_trip = $row['round_trip']; $client_id = $row['trip_client_id']; @@ -121,10 +124,17 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); }else{ $round_trip_display = ""; } + $user_name = $row['user_name']; + if(empty($user_name)){ + $user_name_display = "-"; + }else{ + $user_name_display = $user_name; + } ?> + diff --git a/db.sql b/db.sql index e6ab1c3d..785987c9 100644 --- a/db.sql +++ b/db.sql @@ -291,7 +291,7 @@ CREATE TABLE `contacts` ( `contact_email` varchar(200) DEFAULT NULL, `contact_phone` varchar(200) DEFAULT NULL, `contact_extension` varchar(200) DEFAULT NULL, - `contact_mobile` varchar(200) DEFAULT NULL, + `contact_mobile` varchar(200) DEFAULT '''NULL''', `contact_photo` varchar(200) DEFAULT NULL, `contact_notes` text DEFAULT NULL, `contact_created_at` datetime NOT NULL, @@ -1281,7 +1281,7 @@ CREATE TABLE `tickets` ( `ticket_archived_at` datetime DEFAULT NULL, `ticket_closed_at` datetime DEFAULT NULL, `ticket_created_by` int(11) NOT NULL, - `ticket_assigned_to` int(11) NOT NULL DEFAULT '0', + `ticket_assigned_to` int(11) NOT NULL DEFAULT 0, `ticket_closed_by` int(11) DEFAULT NULL, `ticket_vendor_id` int(11) DEFAULT NULL, `ticket_client_id` int(11) DEFAULT NULL, @@ -1333,6 +1333,7 @@ CREATE TABLE `trips` ( `trip_created_at` datetime NOT NULL, `trip_updated_at` datetime DEFAULT NULL, `trip_archived_at` datetime DEFAULT NULL, + `trip_user_id` int(11) NOT NULL DEFAULT 0, `trip_client_id` int(11) DEFAULT NULL, `company_id` int(11) NOT NULL, PRIMARY KEY (`trip_id`) @@ -1450,4 +1451,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-02-22 13:13:37 +-- Dump completed on 2022-02-26 11:15:13 diff --git a/post.php b/post.php index ef99c70d..becd6ed5 100644 --- a/post.php +++ b/post.php @@ -1968,9 +1968,10 @@ if(isset($_POST['add_trip'])){ $miles = floatval($_POST['miles']); $roundtrip = intval($_POST['roundtrip']); $purpose = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['purpose']))); + $user_id = intval($_POST['user']); $client_id = intval($_POST['client']); - mysqli_query($mysqli,"INSERT INTO trips SET trip_date = '$date', trip_source = '$source', trip_destination = '$destination', trip_miles = $miles, round_trip = $roundtrip, trip_purpose = '$purpose', trip_created_at = NOW(), trip_client_id = $client_id, company_id = $session_company_id"); + mysqli_query($mysqli,"INSERT INTO trips SET trip_date = '$date', trip_source = '$source', trip_destination = '$destination', trip_miles = $miles, round_trip = $roundtrip, trip_purpose = '$purpose', trip_created_at = NOW(), trip_user_id = $user_id, trip_client_id = $client_id, company_id = $session_company_id"); //logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Trip', log_action = 'Create', log_description = '$session_name logged trip to $destination', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_created_at = NOW(), log_client_id = $client_id, log_user_id = $session_user_id, company_id = $session_company_id"); @@ -1990,9 +1991,10 @@ if(isset($_POST['edit_trip'])){ $miles = floatval($_POST['miles']); $roundtrip = intval($_POST['roundtrip']); $purpose = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['purpose']))); + $user_id = intval($_POST['user']); $client_id = intval($_POST['client']); - mysqli_query($mysqli,"UPDATE trips SET trip_date = '$date', trip_source = '$source', trip_destination = '$destination', trip_miles = $miles, trip_purpose = '$purpose', round_trip = $roundtrip, trip_updated_at = NOW(), trip_client_id = $client_id WHERE trip_id = $trip_id AND company_id = $session_company_id"); + mysqli_query($mysqli,"UPDATE trips SET trip_date = '$date', trip_source = '$source', trip_destination = '$destination', trip_miles = $miles, trip_purpose = '$purpose', round_trip = $roundtrip, trip_updated_at = NOW(), trip_user_id = $user_id, trip_client_id = $client_id WHERE trip_id = $trip_id AND company_id = $session_company_id"); //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Trip', log_action = 'Modified', log_description = '$date', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_created_at = NOW(), log_client_id = $client_id, log_user_id = $session_user_id, company_id = $session_company_id"); diff --git a/trip_add_modal.php b/trip_add_modal.php index 0b9de413..19d2c62b 100644 --- a/trip_add_modal.php +++ b/trip_add_modal.php @@ -61,6 +61,31 @@ +
+ +
+
+ +
+ +
+
+ diff --git a/trip_copy_modal.php b/trip_copy_modal.php index d7ae1d04..3063843d 100644 --- a/trip_copy_modal.php +++ b/trip_copy_modal.php @@ -63,6 +63,31 @@ +
+ +
+
+ +
+ +
+
+ diff --git a/trip_edit_modal.php b/trip_edit_modal.php index be401a0d..7178aa58 100644 --- a/trip_edit_modal.php +++ b/trip_edit_modal.php @@ -64,6 +64,31 @@ +
+ +
+
+ +
+ +
+
+ diff --git a/trips.php b/trips.php index 9ada00d5..431989ac 100644 --- a/trips.php +++ b/trips.php @@ -82,7 +82,8 @@ $sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM trips LEFT JOIN clients ON trip_client_id = client_id - WHERE (trip_purpose LIKE '%$q%' OR trip_source LIKE '%$q%' OR trip_destination LIKE '%$q%' OR trip_miles LIKE '%$q%' OR client_name LIKE '%$q%') + LEFT JOIN users ON trip_user_id = user_id + WHERE (trip_purpose LIKE '%$q%' OR trip_source LIKE '%$q%' OR trip_destination LIKE '%$q%' OR trip_miles LIKE '%$q%' OR client_name LIKE '%$q%' OR user_name LIKE '%$q%') AND DATE(trip_date) BETWEEN '$dtf' AND '$dtt' AND trips.company_id = $session_company_id ORDER BY $sb $o LIMIT $record_from, $record_to" @@ -160,6 +161,7 @@ Date Client + Driver Purpose Source Destination @@ -177,6 +179,7 @@ $trip_source = $row['trip_source']; $trip_destination = $row['trip_destination']; $trip_miles = $row['trip_miles']; + $trip_user_id = $row['trip_user_id']; $round_trip = $row['round_trip']; $client_id = $row['client_id']; $client_name = $row['client_name']; @@ -190,11 +193,18 @@ }else{ $round_trip_display = ""; } + $user_name = $row['user_name']; + if(empty($user_name)){ + $user_name_display = "-"; + }else{ + $user_name_display = $user_name; + } ?> +