mirror of https://github.com/itflow-org/itflow
Merge pull request #654 from wrongecho/dynamic-modals
Convert quote edit modal to be dynamically populated
This commit is contained in:
commit
21fc20645b
38
ajax.php
38
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,42 @@ 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
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editQuoteModal<?php echo $quote_id; ?>">
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" onclick="populateQuoteEditModal(<?php echo $quote_id ?>)" data-target="#editQuoteModal">
|
||||
<i class="fas fa-fw fa-edit mr-2"></i>Edit
|
||||
</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addQuoteCopyModal<?php echo $quote_id; ?>">
|
||||
|
|
@ -143,7 +143,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||
|
||||
<?php
|
||||
|
||||
require("quote_edit_modal.php");
|
||||
require("quote_copy_modal.php");
|
||||
}
|
||||
|
||||
|
|
@ -158,4 +157,5 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||
|
||||
<?php
|
||||
require_once("quote_add_modal.php");
|
||||
require_once("quote_edit_modal.php");
|
||||
require_once("footer.php");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
function populateQuoteEditModal(quote_id) {
|
||||
|
||||
// Send a GET request to ajax.php as ajax.php?quote_get_json_details=true"e_id=NUM
|
||||
jQuery.get(
|
||||
"ajax.php",
|
||||
{quote_get_json_details: 'true', quote_id: quote_id},
|
||||
function(data) {
|
||||
|
||||
// If we get a response from ajax.php, parse it as JSON
|
||||
const response = JSON.parse(data);
|
||||
|
||||
// Access the quote info (one) and categories (multiple)
|
||||
const quote = response.quote[0];
|
||||
const categories = response.categories;
|
||||
|
||||
// Populate the quote modal fields
|
||||
document.getElementById("editQuoteHeaderID").innerText = quote.quote_prefix + quote.quote_number;
|
||||
document.getElementById("editQuoteHeaderClient").innerText = quote.client_name;
|
||||
document.getElementById("editQuoteID").value = quote.quote_id;
|
||||
document.getElementById("editQuoteDate").value = quote.quote_date;
|
||||
document.getElementById("editQuoteScope").value = quote.quote_scope;
|
||||
|
||||
/* DROPDOWNS */
|
||||
|
||||
// Category dropdown
|
||||
var categoryDropdown = document.getElementById("editQuoteCategory");
|
||||
|
||||
// Clear Category dropdown
|
||||
var i, L = categoryDropdown.options.length -1;
|
||||
for (i = L; i >= 0; i--) {
|
||||
categoryDropdown.remove(i);
|
||||
}
|
||||
categoryDropdown[categoryDropdown.length] = new Option('- Category -', '0');
|
||||
|
||||
// Populate dropdown
|
||||
categories.forEach(category => {
|
||||
if (parseInt(category.category_id) == parseInt(quote.quote_category_id)) {
|
||||
// Selected quote
|
||||
categoryDropdown[categoryDropdown.length] = new Option(category.category_name, category.category_id, true, true);
|
||||
}
|
||||
else{
|
||||
categoryDropdown[categoryDropdown.length] = new Option(category.category_name, category.category_id);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ if (isset($_GET['quote_id'])) {
|
|||
if ($client_net_terms == 0) {
|
||||
$client_net_terms = $config_default_net_terms;
|
||||
}
|
||||
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM companies, settings WHERE companies.company_id = settings.company_id AND companies.company_id = 1");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ if (isset($_GET['quote_id'])) {
|
|||
<i class="fas fa-ellipsis-v"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editQuoteModal<?php echo $quote_id ?>">
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" onclick="populateQuoteEditModal(<?php echo $quote_id ?>)" data-target="#editQuoteModal">
|
||||
<i class="fa fa-fw fa-edit text-secondary mr-2"></i>Edit
|
||||
</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addQuoteCopyModal<?php echo $quote_id; ?>">
|
||||
|
|
@ -163,7 +163,7 @@ if (isset($_GET['quote_id'])) {
|
|||
<a class="dropdown-item" href="#" onclick="window.print();">
|
||||
<i class="fa fa-fw fa-print text-secondary mr-2"></i>Print
|
||||
</a>
|
||||
<a class="dropdown-item" href="#"
|
||||
<a class="dropdown-item" href="#"
|
||||
onclick="pdfMake.createPdf(docDefinition).download('<?php echo strtoAZaz09(html_entity_decode("$quote_date-$company_name-$client_name-Quote-$quote_prefix$quote_number")); ?>');">
|
||||
<i class="fa fa-fw fa-download text-secondary mr-2"></i>Download PDF
|
||||
</a>
|
||||
|
|
@ -289,7 +289,7 @@ if (isset($_GET['quote_id'])) {
|
|||
<i class="fa fa-fw fa-times mr-2"></i>Remove
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td><?php echo $item_name; ?></td>
|
||||
|
|
|
|||
|
|
@ -1,70 +1,58 @@
|
|||
<div class="modal" id="editQuoteModal<?php echo $quote_id; ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title text-white"><i class="fas fa-fw fa-file mr-2"></i>Editing quote: <strong><?php echo "$quote_prefix$quote_number"; ?></strong> - <?php echo $client_name; ?></h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="quote_id" value="<?php echo $quote_id; ?>">
|
||||
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Quote Date</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control" name="date" max="2999-12-31" value="<?php echo $quote_date; ?>" required>
|
||||
<script src="js/quote_edit_modal.js"></script>
|
||||
<div class="modal" id="editQuoteModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title text-white"><i class="fas fa-fw fa-file mr-2"></i>Editing quote: <span class="text-bold" id="editQuoteHeaderID"></span> - <span class="text" id="editQuoteHeaderClient"></span></h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="quote_id" id="editQuoteID" value="">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Income Category</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="category" required>
|
||||
<option value="">- Category -</option>
|
||||
<?php
|
||||
|
||||
$sql_income_category = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' AND (category_archived_at > '$quote_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC");
|
||||
while ($row = mysqli_fetch_array($sql_income_category)) {
|
||||
$category_id_select = intval($row['category_id']);
|
||||
$category_name_select = htmlentities($row['category_name']);
|
||||
?>
|
||||
<option <?php if ($category_id_select == $category_id) { echo "selected"; } ?> value="<?php echo $category_id_select; ?>"><?php echo $category_name_select; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<div class="input-group-append">
|
||||
<button type="button" class="btn btn-secondary" data-toggle="modal" data-target="#addQuickCategoryIncomeModal"><i class="fas fa-fw fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Scope</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-comment"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="scope" placeholder="Quick description" value="<?php echo $quote_scope; ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Quote Date</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control" name="date" id="editQuoteDate" max="2999-12-31" value="" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Income Category</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="category" id="editQuoteCategory" required>
|
||||
</select>
|
||||
<div class="input-group-append">
|
||||
<button type="button" class="btn btn-secondary" data-toggle="modal" data-target="#addQuickCategoryIncomeModal"><i class="fas fa-fw fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Scope</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-comment"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="scope" id="editQuoteScope" placeholder="Quick description" value="">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="submit" name="edit_quote" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Save</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fas fa-times mr-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="submit" name="edit_quote" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Save</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fas fa-times mr-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editQuoteModal<?php echo $quote_id; ?>">
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" onclick="populateQuoteEditModal(<?php echo $quote_id ?>)" data-target="#editQuoteModal">
|
||||
<i class="fas fa-fw fa-edit mr-2"></i>Edit
|
||||
</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addQuoteCopyModal<?php echo $quote_id; ?>">
|
||||
|
|
@ -176,7 +176,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||
|
||||
<?php
|
||||
|
||||
require("quote_edit_modal.php");
|
||||
require("quote_copy_modal.php");
|
||||
|
||||
}
|
||||
|
|
@ -193,5 +192,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||
<?php
|
||||
|
||||
require_once("quote_add_modal.php");
|
||||
require_once("quote_edit_modal.php");
|
||||
require_once("category_quick_add_modal.php");
|
||||
require_once("footer.php");
|
||||
|
|
|
|||
Loading…
Reference in New Issue