From bdf74e77baa6c66aade4dab6a9f6230a9b7b9253 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Sun, 9 Apr 2023 20:10:19 +0100 Subject: [PATCH] Convert quote edit modal to be dynamically populated --- ajax.php | 37 ++++++++++++- client_quotes.php | 4 +- js/quote_edit_modal.js | 48 +++++++++++++++++ quote.php | 8 +-- quote_edit_modal.php | 116 ++++++++++++++++++----------------------- quotes.php | 4 +- 6 files changed, 144 insertions(+), 73 deletions(-) create mode 100644 js/quote_edit_modal.js diff --git a/ajax.php b/ajax.php index 0ead3ee3..065e7110 100644 --- a/ajax.php +++ b/ajax.php @@ -120,7 +120,7 @@ if (isset($_GET['merge_ticket_get_json_details'])) { } else { //Return ticket, client and contact details for the given ticket number $response = mysqli_fetch_array($sql); - + echo json_encode($response); } } @@ -308,6 +308,41 @@ if (isset($_GET['scheduled_ticket_get_json_details'])) { } +/* + * Looks up info for a given quote ID from the database, used to dynamically populate modal fields + */ +if (isset($_GET['quote_get_json_details'])) { + $quote_id = intval($_GET['quote_id']); + + // Get quote details + $quote_sql = mysqli_query( + $mysqli, + "SELECT * FROM quotes + LEFT JOIN clients ON quote_client_id = client_id + WHERE quote_id = $quote_id LIMIT 1" + ); + + while ($row = mysqli_fetch_array($quote_sql)) { + $response['quote'][] = $row; + } + + + // Get all income-related categories for quoting + $quote_created_at = $response['quote'][0]['quote_created_at']; + $category_sql = mysqli_query( + $mysqli, + "SELECT category_id, category_name FROM categories + WHERE category_type = 'Income' AND (category_archived_at > '$quote_created_at' OR category_archived_at IS NULL) + ORDER BY category_name"); + + while ($row = mysqli_fetch_array($category_sql)) { + $response['categories'][] = $row; + } + + echo json_encode($response); + +} + /* * Dynamic TOTP for client login page * When provided with a TOTP secret, returns a 6-digit code diff --git a/client_quotes.php b/client_quotes.php index 7157c4c5..c13e13fb 100644 --- a/client_quotes.php +++ b/client_quotes.php @@ -120,7 +120,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); + diff --git a/quote_edit_modal.php b/quote_edit_modal.php index d041eac0..cd0e13db 100644 --- a/quote_edit_modal.php +++ b/quote_edit_modal.php @@ -1,70 +1,58 @@ -