diff --git a/client_assets.php b/client_assets.php index cf22c57e..ffb287da 100644 --- a/client_assets.php +++ b/client_assets.php @@ -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 diff --git a/expenses.php b/expenses.php index 6ba54f7b..f666c57e 100644 --- a/expenses.php +++ b/expenses.php @@ -114,8 +114,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
- - +
diff --git a/export_trips_modal.php b/export_trips_modal.php new file mode 100644 index 00000000..8d7d0bc9 --- /dev/null +++ b/export_trips_modal.php @@ -0,0 +1,29 @@ + \ No newline at end of file diff --git a/post.php b/post.php index 9cbc273d..cc5a59e2 100644 --- a/post.php +++ b/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); } diff --git a/trips.php b/trips.php index ac5b337e..8366f39b 100644 --- a/trips.php +++ b/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 @@
- Export +
@@ -217,6 +220,7 @@ include("add_trip_copy_modal.php"); include("edit_trip_modal.php"); + include("export_trips_modal.php"); }