mirror of https://github.com/itflow-org/itflow
Added Custom Export Modal to trips
This commit is contained in:
parent
270120c7fc
commit
ee8739c763
|
|
@ -78,7 +78,7 @@ if(isset($_GET['type']) && ($_GET['type']) == 'workstation'){
|
|||
$type_query = "asset_type NOT LIKE 'laptop' AND asset_type NOT LIKE 'desktop' AND asset_type NOT LIKE 'server' AND asset_type NOT LIKE 'virtual machine' AND asset_type NOT LIKE 'firewall/router' AND asset_type NOT LIKE 'switch' AND asset_type NOT LIKE 'access point'";
|
||||
}else{
|
||||
$type_query = "asset_type LIKE '%'";
|
||||
$_GET['type'] = 'all';
|
||||
$_GET['type'] = '';
|
||||
}
|
||||
|
||||
//Rebuild URL
|
||||
|
|
|
|||
|
|
@ -114,8 +114,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||
</div>
|
||||
<div class="col-sm-8">
|
||||
<div class="float-right">
|
||||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#exportExpensesModal"><i class="fa fa-fw fa-download"></i> Export</button>
|
||||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#importExpensesModal"><i class="fa fa-fw fa-upload"></i> Import</button>
|
||||
<button type="button" class="btn btn-default btn-lg" data-toggle="modal" data-target="#exportExpensesModal"><i class="fa fa-fw fa-download"></i> Export</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
<div class="modal" id="exportTripsModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-download"></i> Export Trips to CSV</h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<div class="modal-body bg-white">
|
||||
<div class="form-group">
|
||||
<label>Date From</label>
|
||||
<input type="date" class="form-control" name="date_from" value="<?php echo $dtf; ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Date To</label>
|
||||
<input type="date" class="form-control" name="date_to" value="<?php echo $dtt; ?>">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="submit" name="export_trips_csv" class="btn btn-primary">Download CSV</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
29
post.php
29
post.php
|
|
@ -2399,7 +2399,7 @@ if(isset($_POST['export_expenses_csv'])){
|
|||
$date_to = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['date_to'])));
|
||||
if(!empty($date_from) AND !empty($date_to)){
|
||||
$date_query = "AND DATE(expense_date) BETWEEN '$date_from' AND '$date_to'";
|
||||
$file_name_date = "$date_from-$date_to";
|
||||
$file_name_date = "$date_from-to-$date_to";
|
||||
}else{
|
||||
$date_query = "";
|
||||
$file_name_date = date('Y-m-d');
|
||||
|
|
@ -5776,13 +5776,28 @@ if(isset($_GET['force_recurring'])){
|
|||
|
||||
} //End Force Recurring
|
||||
|
||||
if(isset($_GET['export_trips_csv'])){
|
||||
//get records from database
|
||||
$query = mysqli_query($mysqli,"SELECT * FROM trips WHERE company_id = $session_company_id ORDER BY trip_date DESC");
|
||||
if(isset($_POST['export_trips_csv'])){
|
||||
$date_from = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['date_from'])));
|
||||
$date_to = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['date_to'])));
|
||||
if(!empty($date_from) AND !empty($date_to)){
|
||||
$date_query = "AND DATE(trip_date) BETWEEN '$date_from' AND '$date_to'";
|
||||
$file_name_date = "$date_from-to-$date_to";
|
||||
}else{
|
||||
$date_query = "";
|
||||
$file_name_date = date('Y-m-d');
|
||||
}
|
||||
|
||||
if($query->num_rows > 0){
|
||||
//get records from database
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM trips
|
||||
LEFT JOIN clients ON trip_client_id = client_id
|
||||
WHERE trips.company_id = $session_company_id
|
||||
$date_query
|
||||
ORDER BY trip_date DESC"
|
||||
);
|
||||
|
||||
if(mysqli_num_rows($sql) > 0){
|
||||
$delimiter = ",";
|
||||
$filename = "trips_" . date('Y-m-d') . ".csv";
|
||||
$filename = "$session_company_name-Trips-$file_name_date.csv";
|
||||
|
||||
//create a file pointer
|
||||
$f = fopen('php://memory', 'w');
|
||||
|
|
@ -5792,7 +5807,7 @@ if(isset($_GET['export_trips_csv'])){
|
|||
fputcsv($f, $fields, $delimiter);
|
||||
|
||||
//output each row of the data, format line as csv and write to file pointer
|
||||
while($row = $query->fetch_assoc()){
|
||||
while($row = mysqli_fetch_assoc($sql)){
|
||||
$lineData = array($row['trip_date'], $row['trip_purpose'], $row['trip_source'], $row['trip_destination'], $row['trip_miles']);
|
||||
fputcsv($f, $lineData, $delimiter);
|
||||
}
|
||||
|
|
|
|||
18
trips.php
18
trips.php
|
|
@ -36,6 +36,12 @@
|
|||
$disp = "ASC";
|
||||
}
|
||||
|
||||
if(empty($_GET['canned_date'])){
|
||||
//Prevents lots of undefined variable errors.
|
||||
// $dtf and $dtt will be set by the below else to 0000-00-00 / 9999-00-00
|
||||
$_GET['canned_date'] = 'custom';
|
||||
}
|
||||
|
||||
//Date Filter
|
||||
if($_GET['canned_date'] == "custom" AND !empty($_GET['dtf'])){
|
||||
$dtf = mysqli_real_escape_string($mysqli,$_GET['dtf']);
|
||||
|
|
@ -69,16 +75,13 @@
|
|||
$dtt = "9999-00-00";
|
||||
}
|
||||
|
||||
if(empty($_GET['canned_date'])){
|
||||
//Prevents lots of undefined variable errors.
|
||||
// $dtf and $dtt will be set by the below else to 0000-00-00 / 9999-00-00
|
||||
$_GET['canned_date'] = 'custom';
|
||||
}
|
||||
|
||||
|
||||
//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 LEFT JOIN clients ON trip_client_id = client_id
|
||||
$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%')
|
||||
AND DATE(trip_date) BETWEEN '$dtf' AND '$dtt'
|
||||
AND trips.company_id = $session_company_id
|
||||
|
|
@ -113,7 +116,7 @@
|
|||
</div>
|
||||
<div class="col-sm-8">
|
||||
<div class="float-right">
|
||||
<a href="post.php?export_trips_csv" class="btn btn-default"><i class="fa fa-fw fa-download"></i> Export</a>
|
||||
<button type="button" class="btn btn-default btn-lg" data-toggle="modal" data-target="#exportTripsModal"><i class="fa fa-fw fa-download"></i> Export</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -217,6 +220,7 @@
|
|||
|
||||
include("add_trip_copy_modal.php");
|
||||
include("edit_trip_modal.php");
|
||||
include("export_trips_modal.php");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue