Skip to content

Commit

Permalink
DB Update tip_user_id added to the trips tables. Updated Trips to inc…
Browse files Browse the repository at this point in the history
…lude the driver. WIP limit users to the session_company
  • Loading branch information
johnnyq committed Feb 26, 2022
1 parent 3bd7963 commit 112efbc
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 8 deletions.
14 changes: 12 additions & 2 deletions client_trips.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
//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
Expand Down Expand Up @@ -96,6 +97,7 @@
<thead class="text-dark <?php if($num_rows[0] == 0){ echo "d-none"; } ?>">
<tr>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_date&o=<?php echo $disp; ?>">Date</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=user_name&o=<?php echo $disp; ?>">Driver</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_purpose&o=<?php echo $disp; ?>">Purpose</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_source&o=<?php echo $disp; ?>">From</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_destination&o=<?php echo $disp; ?>">To</a></th>
Expand All @@ -113,6 +115,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['trip_client_id'];

Expand All @@ -121,10 +124,17 @@
}else{
$round_trip_display = "";
}
$user_name = $row['user_name'];
if(empty($user_name)){
$user_name_display = "-";
}else{
$user_name_display = $user_name;
}

?>
<tr>
<td><a class="text-dark" href="#" data-toggle="modal" data-target="#editTripModal<?php echo $trip_id; ?>"><?php echo $trip_date; ?></a></td>
<td><?php echo $user_name_display; ?></td>
<td><?php echo $trip_purpose; ?></td>
<td><?php echo $trip_source; ?></td>
<td><?php echo $trip_destination; ?></td>
Expand Down
7 changes: 4 additions & 3 deletions db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`)
Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1968,9 +1968,10 @@
$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");
Expand All @@ -1990,9 +1991,10 @@
$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");
Expand Down
25 changes: 25 additions & 0 deletions trip_add_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@
<textarea rows="4" class="form-control" placeholder="Enter a purpose" name="purpose" required></textarea>
</div>

<div class="form-group">
<label>Driver</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
</div>
<select class="form-control select2" name="user" required>
<option value="">- Driver -</option>
<?php

// WIP Need to only show users within the session company
$sql = mysqli_query($mysqli,"SELECT * FROM users ORDER BY user_name ASC");
while($row = mysqli_fetch_array($sql)){
$user_id = $row['user_id'];
$user_name = $row['user_name'];
?>
<option <?php if($session_user_id = $user_id){ echo "selected"; } ?> value="<?php echo $user_id; ?>"><?php echo $user_name; ?></option>

<?php
}
?>
</select>
</div>
</div>

<?php if(isset($_GET['client_id'])){ ?>
<input type="hidden" name="client" value="<?php echo $client_id; ?>">
<?php }else{ ?>
Expand Down
25 changes: 25 additions & 0 deletions trip_copy_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@
<textarea rows="4" class="form-control" name="purpose" required><?php echo $trip_purpose; ?></textarea>
</div>

<div class="form-group">
<label>Driver</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
</div>
<select class="form-control select2" name="user" required>
<option value="">- Driver -</option>
<?php

// WIP Need to only show users within the session company
$sql_trips = mysqli_query($mysqli,"SELECT * FROM users ORDER BY user_name ASC");
while($row = mysqli_fetch_array($sql_trips)){
$user_id_select = $row['user_id'];
$user_name_select = $row['user_name'];
?>
<option <?php if($trip_user_id = $user_id_select){ echo "selected"; } ?> value="<?php echo $user_id_select; ?>"><?php echo $user_name_select; ?></option>

<?php
}
?>
</select>
</div>
</div>

<?php if(isset($_GET['client_id'])){ ?>
<input type="hidden" name="client" value="<?php echo $client_id; ?>">
<?php }else{ ?>
Expand Down
25 changes: 25 additions & 0 deletions trip_edit_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@
<textarea rows="4" class="form-control" placeholder="Enter a purpose" name="purpose" required><?php echo $trip_purpose; ?></textarea>
</div>

<div class="form-group">
<label>Driver</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
</div>
<select class="form-control select2" name="user" required>
<option value="">- Driver -</option>
<?php

// WIP Need to only show users within the session company
$sql_trips = mysqli_query($mysqli,"SELECT * FROM users ORDER BY user_name ASC");
while($row = mysqli_fetch_array($sql_trips)){
$user_id_select = $row['user_id'];
$user_name_select = $row['user_name'];
?>
<option <?php if($trip_user_id = $user_id_select){ echo "selected"; } ?> value="<?php echo $user_id_select; ?>"><?php echo $user_name_select; ?></option>

<?php
}
?>
</select>
</div>
</div>

<?php if(isset($_GET['client_id'])){ ?>
<input type="hidden" name="client" value="<?php echo $client_id; ?>">
<?php }else{ ?>
Expand Down
12 changes: 11 additions & 1 deletion trips.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -160,6 +161,7 @@
<tr>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_date&o=<?php echo $disp; ?>">Date</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=client_name&o=<?php echo $disp; ?>">Client</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=user_name&o=<?php echo $disp; ?>">Driver</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_purpose&o=<?php echo $disp; ?>">Purpose</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_source&o=<?php echo $disp; ?>">Source</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_destination&o=<?php echo $disp; ?>">Destination</a></th>
Expand All @@ -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'];
Expand All @@ -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;
}

?>
<tr>
<td><a class="text-dark" href="#" data-toggle="modal" data-target="#editTripModal<?php echo $trip_id; ?>"><?php echo $trip_date; ?></a></td>
<td><?php echo $client_name_display; ?></td>
<td><?php echo $user_name_display; ?></td>
<td><?php echo $trip_purpose; ?></td>
<td><?php echo $trip_source; ?></td>
<td><?php echo $trip_destination; ?></td>
Expand Down

0 comments on commit 112efbc

Please sign in to comment.