Renamed table field trip_starting_location to just trip_source added export trips as CSV in POST, new DB Dump

This commit is contained in:
johnny@pittpc.com 2021-02-02 19:11:05 -05:00
parent dbf1a90fdb
commit 9d095611fb
43 changed files with 55 additions and 224 deletions

View File

@ -55,7 +55,7 @@
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-map-marker-alt"></i></span>
</div>
<input type="text" class="form-control" name="starting_location" value="<?php echo $trip_starting_location; ?>" required>
<input type="text" class="form-control" name="source" value="<?php echo $trip_starting_location; ?>" required>
</div>
</div>

View File

@ -51,7 +51,7 @@
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-map-marker-alt"></i></span>
</div>
<input type="text" class="form-control" name="starting_location" placeholder="Enter your starting location" required>
<input type="text" class="form-control" name="source" placeholder="Enter your starting location" required>
</div>
</div>
<div class="form-group">

View File

@ -50,7 +50,7 @@ if(isset($_GET['dtf'])){
}
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM trips
WHERE (trip_purpose LIKE '%$q%' OR trip_starting_location LIKE '%$q%' OR trip_destination LIKE '%$q%')
WHERE (trip_purpose LIKE '%$q%' OR trip_source LIKE '%$q%' OR trip_destination LIKE '%$q%')
AND DATE(trip_date) BETWEEN '$dtf' AND '$dtt'
AND company_id = $session_company_id
AND client_id = $client_id
@ -83,7 +83,7 @@ $total_pages = ceil($total_found_rows / 10);
<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=trip_purpose&o=<?php echo $disp; ?>">Purpose</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_starting_location&o=<?php echo $disp; ?>">From</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>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_miles&o=<?php echo $disp; ?>">Miles</a></th>
<th class="text-center">Action</th>
@ -96,7 +96,7 @@ $total_pages = ceil($total_found_rows / 10);
$trip_id = $row['trip_id'];
$trip_date = $row['trip_date'];
$trip_purpose = $row['trip_purpose'];
$trip_starting_location = $row['trip_starting_location'];
$trip_source = $row['trip_source'];
$trip_destination = $row['trip_destination'];
$trip_miles = $row['trip_miles'];
$round_trip = $row['round_trip'];
@ -115,7 +115,7 @@ $total_pages = ceil($total_found_rows / 10);
<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 $trip_purpose; ?></td>
<td><?php echo $trip_starting_location; ?></td>
<td><?php echo $trip_source; ?></td>
<td><?php echo $trip_destination; ?></td>
<td><?php echo "$trip_miles $round_trip_display"; ?></td>
<td>
@ -124,7 +124,7 @@ $total_pages = ceil($total_found_rows / 10);
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="//maps.google.com?q=<?php echo $trip_starting_location; ?> to <?php echo $trip_destination; ?>" target="_blank">Map it</a>
<a class="dropdown-item" href="//maps.google.com?q=<?php echo $trip_source; ?> to <?php echo $trip_destination; ?>" target="_blank">Map it</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editTripModal<?php echo $trip_id; ?>">Edit</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addTripCopyModal<?php echo $trip_id; ?>">Copy</a>

View File

@ -1,192 +0,0 @@
<?php include("header_new.php");
//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o' => $o)));
//Paging
if(isset($_GET['p'])){
$p = intval($_GET['p']);
$record_from = (($p)-1)*$config_records_per_page;
$record_to = $config_records_per_page;
}else{
$record_from = 0;
$record_to = $config_records_per_page;
$p = 1;
}
if(isset($_GET['q'])){
$q = mysqli_real_escape_string($mysqli,$_GET['q']);
}else{
$q = "";
}
if(!empty($_GET['sb'])){
$sb = mysqli_real_escape_string($mysqli,$_GET['sb']);
}else{
$sb = "client_id";
}
if(isset($_GET['o'])){
if($_GET['o'] == 'ASC'){
$o = "ASC";
$disp = "DESC";
}else{
$o = "DESC";
$disp = "ASC";
}
}else{
$o = "DESC";
$disp = "ASC";
}
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM clients WHERE (client_name LIKE '%$q%' OR client_email LIKE '%$q%' OR client_contact LIKE '%$q%') AND company_id = $session_company_id ORDER BY $sb $o LIMIT $record_from, $record_to");
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
?>
<div class="card mb-3">
<div class="card-header bg-dark text-white">
<h6 class="float-left mt-2"><i class="fa fa-users mr-2"></i>Clients</h6>
<button type="button" class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addClientModal"><i class="fas fa-fw fa-plus"></i></button>
</div>
<div class="card-body">
<form autocomplete="off">
<div class="input-group">
<input type="search" class="form-control col-md-4" name="q" value="<?php if(isset($q)){echo stripslashes($q);} ?>" placeholder="Search Clients">
<div class="input-group-append">
<button class="btn btn-primary"><i class="fa fa-search"></i></button>
</div>
</div>
</form>
<hr>
<div class="table-responsive">
<table class="table table-striped table-borderless table-hover">
<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=client_name&o=<?php echo $disp; ?>">Name <i class="fa fa-sort-alpha<?php if($disp=='ASC'){ echo "-up"; }else{ echo "-down"; }?>"></i></a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=client_type&o=<?php echo $disp; ?>">Type <i class="fa fa-sort"></i></a></th>
<th>Contact</th>
<th class="text-right">Balance</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($sql)){
$client_id = $row['client_id'];
$client_name = $row['client_name'];
$client_type = $row['client_type'];
$client_address = $row['client_address'];
$client_city = $row['client_city'];
$client_state = $row['client_state'];
$client_zip = $row['client_zip'];
$client_contact = $row['client_contact'];
$client_phone = $row['client_phone'];
if(strlen($client_phone)>2){
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
}
$client_mobile = $row['client_mobile'];
if(strlen($client_mobile)>2){
$client_mobile = substr($row['client_mobile'],0,3)."-".substr($row['client_mobile'],3,3)."-".substr($row['client_mobile'],6,4);
}
$client_email = $row['client_email'];
$client_website = $row['client_website'];
$client_net_terms = $row['client_net_terms'];
$client_hours = $row['client_hours'];
//Add up all the payments for the invoice and get the total amount paid to the invoice
$sql_invoice_amounts = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS invoice_amounts FROM invoices WHERE client_id = $client_id AND invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled' ");
$row = mysqli_fetch_array($sql_invoice_amounts);
$invoice_amounts = $row['invoice_amounts'];
$sql_amount_paid = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS amount_paid FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.client_id = $client_id");
$row = mysqli_fetch_array($sql_amount_paid);
$amount_paid = $row['amount_paid'];
$balance = $invoice_amounts - $amount_paid;
//set Text color on balance
if($balance > 0){
$balance_text_color = "text-danger font-weight-bold";
}else{
$balance_text_color = "";
}
?>
<tr>
<td><a href="client.php?client_id=<?php echo $client_id; ?>&tab=contacts"><?php echo $client_name; ?></a></td>
<td><?php echo $client_type; ?></td>
<td>
<?php
if(!empty($client_contact)){
?>
<i class="fa fa-fw fa-user text-secondary mr-2 mb-2"></i><?php echo $client_contact; ?>
<br>
<?php
}
?>
<?php
if(!empty($client_phone)){
?>
<i class="fa fa-fw fa-phone text-secondary mr-2 mb-2"></i><?php echo $client_phone; ?>
<br>
<?php
}
?>
<?php
if(!empty($client_mobile)){
?>
<i class="fa fa-fw fa-mobile-alt text-secondary mr-2 mb-2"></i><?php echo $client_mobile; ?>
<br>
<?php
}
?>
<?php
if(!empty($client_email)){
?>
<i class="fa fa-fw fa-envelope text-secondary mr-2 mb-2"></i><a href="mailto:<?php echo $client_email; ?>"><?php echo $client_email; ?></a>
<?php
}
?>
</td>
<td class="text-right text-monospace <?php echo $balance_text_color; ?>">$<?php echo number_format($balance,2); ?></td>
<td>
<div class="dropdown dropleft text-center">
<button class="btn btn-secondary btn-sm" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editClientModal<?php echo $client_id; ?>">Edit</a>
<a class="dropdown-item" href="post.php?delete_client=<?php echo $client_id; ?>">Delete</a>
</div>
</div>
<?php include("edit_client_modal.php"); ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php include("pagination.php"); ?>
</div>
</div>
</div>
<?php include("add_client_modal.php"); ?>
<?php include("footer_new.php");

4
db.sql
View File

@ -836,7 +836,7 @@ CREATE TABLE `trips` (
`trip_id` int(11) NOT NULL AUTO_INCREMENT,
`trip_date` date NOT NULL,
`trip_purpose` varchar(200) NOT NULL,
`trip_starting_location` varchar(200) NOT NULL,
`trip_source` varchar(200) NOT NULL,
`trip_destination` varchar(200) NOT NULL,
`trip_start_odometer` int(11) DEFAULT NULL,
`trip_end_odmeter` int(11) DEFAULT NULL,
@ -927,4 +927,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2021-01-29 21:26:58
-- Dump completed on 2021-02-02 19:10:13

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

BIN
dist/img/avatar.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

BIN
dist/img/avatar04.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

BIN
dist/img/avatar2.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

BIN
dist/img/avatar3.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

BIN
dist/img/avatar5.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

BIN
dist/img/boxed-bg.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 KiB

BIN
dist/img/boxed-bg.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 373 B

BIN
dist/img/icons.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

BIN
dist/img/photo1.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 658 KiB

BIN
dist/img/photo2.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 414 KiB

BIN
dist/img/photo3.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 KiB

BIN
dist/img/photo4.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

BIN
dist/img/prod-1.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

BIN
dist/img/prod-2.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

BIN
dist/img/prod-3.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

BIN
dist/img/prod-4.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

BIN
dist/img/prod-5.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -56,7 +56,7 @@
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-map-marker-alt"></i></span>
</div>
<input type="text" class="form-control" name="starting_location" value="<?php echo $trip_starting_location; ?>" required>
<input type="text" class="form-control" name="source" value="<?php echo $trip_source; ?>" required>
</div>
</div>

View File

@ -983,14 +983,14 @@ if(isset($_GET['delete_product'])){
if(isset($_POST['add_trip'])){
$date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date']));
$starting_location = strip_tags(mysqli_real_escape_string($mysqli,$_POST['starting_location']));
$source = strip_tags(mysqli_real_escape_string($mysqli,$_POST['source']));
$destination = strip_tags(mysqli_real_escape_string($mysqli,$_POST['destination']));
$miles = floatval($_POST['miles']);
$roundtrip = intval($_POST['roundtrip']);
$purpose = strip_tags(mysqli_real_escape_string($mysqli,$_POST['purpose']));
$client_id = intval($_POST['client']);
mysqli_query($mysqli,"INSERT INTO trips SET trip_date = '$date', trip_starting_location = '$starting_location', trip_destination = '$destination', trip_miles = $miles, round_trip = $roundtrip, trip_purpose = '$purpose', trip_created_at = NOW(), 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(), client_id = $client_id, company_id = $session_company_id");
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Trip', log_action = 'Created', log_description = '$date', log_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id");
@ -1005,14 +1005,14 @@ if(isset($_POST['edit_trip'])){
$trip_id = intval($_POST['trip_id']);
$date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date']));
$starting_location = strip_tags(mysqli_real_escape_string($mysqli,$_POST['starting_location']));
$source = strip_tags(mysqli_real_escape_string($mysqli,$_POST['source']));
$destination = strip_tags(mysqli_real_escape_string($mysqli,$_POST['destination']));
$miles = floatval($_POST['miles']);
$roundtrip = intval($_POST['roundtrip']);
$purpose = strip_tags(mysqli_real_escape_string($mysqli,$_POST['purpose']));
$client_id = intval($_POST['client']);
mysqli_query($mysqli,"UPDATE trips SET trip_date = '$date', trip_starting_location = '$starting_location', trip_destination = '$destination', trip_miles = $miles, trip_purpose = '$purpose', round_trip = $roundtrip, trip_updated_at = NOW(), 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(), 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_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id");
@ -3840,4 +3840,39 @@ if(isset($_GET['force_recurring'])){
} //End Force Recurring
if(isset($_GET['export_trips_csv'])){
//get records from database
$query = $db->query("SELECT * FROM trips ORDER BY trip_date DESC");
if($query->num_rows > 0){
$delimiter = ",";
$filename = "trips_" . date('Y-m-d') . ".csv";
//create a file pointer
$f = fopen('php://memory', 'w');
//set column headers
$fields = array('Date', 'Purpose', 'Source', 'Destination', 'Miles');
fputcsv($f, $fields, $delimiter);
//output each row of the data, format line as csv and write to file pointer
while($row = $query->fetch_assoc()){
$lineData = array($row['trip_date'], $row['trip_purpose'], $row['trip_source'], $row['trip_destination'], $row['trip_miles']);
fputcsv($f, $lineData, $delimiter);
}
//move back to beginning of file
fseek($f, 0);
//set headers to download file rather than displayed
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
//output all remaining data on a file pointer
fpassthru($f);
}
exit;
}
?>

View File

@ -1,12 +0,0 @@
<?php
$phone = ",above// \\5";
$stripped_phone = preg_replace("/[^0-9]/", '',$phone);
echo $phone;
echo "<br>";
echo $stripped_phone;
?>

View File

@ -50,7 +50,7 @@
}
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM trips
WHERE (trip_purpose LIKE '%$q%' OR trip_starting_location LIKE '%$q%' OR trip_destination LIKE '%$q%')
WHERE (trip_purpose LIKE '%$q%' OR trip_source LIKE '%$q%' OR trip_destination LIKE '%$q%')
AND DATE(trip_date) BETWEEN '$dtf' AND '$dtt'
AND company_id = $session_company_id
ORDER BY $sb $o LIMIT $record_from, $record_to");
@ -82,8 +82,8 @@
<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=trip_purpose&o=<?php echo $disp; ?>">Purpose</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_starting_location&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>
<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>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=trip_miles&o=<?php echo $disp; ?>">Miles</a></th>
<th class="text-center">Action</th>
</tr>
@ -95,7 +95,7 @@
$trip_id = $row['trip_id'];
$trip_date = $row['trip_date'];
$trip_purpose = $row['trip_purpose'];
$trip_starting_location = $row['trip_starting_location'];
$trip_source = $row['trip_source'];
$trip_destination = $row['trip_destination'];
$trip_miles = $row['trip_miles'];
$round_trip = $row['round_trip'];
@ -111,7 +111,7 @@
<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 $trip_purpose; ?></td>
<td><?php echo $trip_starting_location; ?></td>
<td><?php echo $trip_source; ?></td>
<td><?php echo $trip_destination; ?></td>
<td><?php echo "$trip_miles $round_trip_display"; ?></td>
<td>
@ -120,7 +120,7 @@
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="//maps.google.com?q=<?php echo $trip_starting_location; ?> to <?php echo $trip_destination; ?>" target="_blank">Map it</a>
<a class="dropdown-item" href="//maps.google.com?q=<?php echo $trip_source; ?> to <?php echo $trip_destination; ?>" target="_blank">Map it</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editTripModal<?php echo $trip_id; ?>">Edit</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addTripCopyModal<?php echo $trip_id; ?>">Copy</a>