Skip to content

Commit ccec330

Browse files
committed
Migrated project, transfer and quote edit to the new AJAX modal function
1 parent 093fd69 commit ccec330

19 files changed

+734
-673
lines changed

ajax.php

-38
Original file line numberDiff line numberDiff line change
@@ -429,44 +429,6 @@
429429

430430
}
431431

432-
/*
433-
* Looks up info for a given quote ID from the database, used to dynamically populate modal fields
434-
*/
435-
if (isset($_GET['quote_get_json_details'])) {
436-
enforceUserPermission('module_sales');
437-
438-
$quote_id = intval($_GET['quote_id']);
439-
440-
// Get quote details
441-
$quote_sql = mysqli_query(
442-
$mysqli,
443-
"SELECT * FROM quotes
444-
LEFT JOIN clients ON quote_client_id = client_id
445-
WHERE quote_id = $quote_id LIMIT 1"
446-
);
447-
448-
while ($row = mysqli_fetch_array($quote_sql)) {
449-
$response['quote'][] = $row;
450-
}
451-
452-
453-
// Get all income-related categories for quoting
454-
$quote_created_at = $response['quote'][0]['quote_created_at'];
455-
$category_sql = mysqli_query(
456-
$mysqli,
457-
"SELECT category_id, category_name FROM categories
458-
WHERE category_type = 'Income' AND (category_archived_at > '$quote_created_at' OR category_archived_at IS NULL)
459-
ORDER BY category_name"
460-
);
461-
462-
while ($row = mysqli_fetch_array($category_sql)) {
463-
$response['categories'][] = $row;
464-
}
465-
466-
echo json_encode($response);
467-
468-
}
469-
470432
/*
471433
* Returns sorted list of active clients
472434
*/

ajax/ajax_project_edit.php

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
require_once '../includes/ajax_header.php';
4+
5+
$project_id = intval($_GET['id']);
6+
7+
$sql = mysqli_query($mysqli, "SELECT * FROM projects WHERE project_id = $project_id LIMIT 1");
8+
9+
$row = mysqli_fetch_array($sql);
10+
$project_prefix = nullable_htmlentities($row['project_prefix']);
11+
$project_number = intval($row['project_number']);
12+
$project_name = nullable_htmlentities($row['project_name']);
13+
$project_description = nullable_htmlentities($row['project_description']);
14+
$project_due = nullable_htmlentities($row['project_due']);
15+
$project_created_at = nullable_htmlentities($row['project_created_at']);
16+
$project_created_at_display = date("Y-m-d", strtotime($project_created_at));
17+
$project_updated_at = nullable_htmlentities($row['project_updated_at']);
18+
$project_completed_at = nullable_htmlentities($row['project_completed_at']);
19+
$project_completed_at_display = date("Y-m-d", strtotime($project_completed_at));
20+
$project_archived_at = nullable_htmlentities($row['project_archived_at']);
21+
$client_id = intval($row['project_client_id']);
22+
$project_manager = intval($row['project_manager']);
23+
24+
// Generate the HTML form content using output buffering.
25+
ob_start();
26+
?>
27+
28+
<div class="modal-header">
29+
<h5 class="modal-title">
30+
<i class="fas fa-fw fa-project-diagram mr-2"></i>Editing Project: <strong><?php echo $project_name; ?></strong>
31+
</h5>
32+
<button type="button" class="close text-white" data-dismiss="modal">
33+
<span>&times;</span>
34+
</button>
35+
</div>
36+
<form action="post.php" method="post" autocomplete="off">
37+
<input type="hidden" name="project_id" value="<?php echo $project_id; ?>">
38+
<div class="modal-body bg-white">
39+
<div class="form-group">
40+
<label>Project Name <strong class="text-danger">*</strong></label>
41+
<div class="input-group">
42+
<div class="input-group-prepend">
43+
<span class="input-group-text"><i class="fa fa-fw fa-project-diagram"></i></span>
44+
</div>
45+
<input type="text" class="form-control" name="name" placeholder="Project Name" maxlength="255" value="<?php echo $project_name; ?>" required autofocus>
46+
</div>
47+
</div>
48+
<div class="form-group">
49+
<label>Description</label>
50+
<div class="input-group">
51+
<div class="input-group-prepend">
52+
<span class="input-group-text"><i class="fa fa-fw fa-angle-right"></i></span>
53+
</div>
54+
<input type="text" class="form-control" name="description" placeholder="Description" value="<?php echo $project_description; ?>">
55+
</div>
56+
</div>
57+
<div class="form-group">
58+
<label>Date Due <strong class="text-danger">*</strong></label>
59+
<div class="input-group">
60+
<div class="input-group-prepend">
61+
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
62+
</div>
63+
<input type="date" class="form-control" name="due_date" value="<?php echo $project_due; ?>" required>
64+
</div>
65+
</div>
66+
<div class="form-group">
67+
<label>Manager</label>
68+
<div class="input-group">
69+
<div class="input-group-prepend">
70+
<span class="input-group-text"><i class="fa fa-fw fa-user-tie"></i></span>
71+
</div>
72+
<select class="form-control select2" name="project_manager">
73+
<option value="0">No Manager</option>
74+
<?php
75+
$sql_project_managers_select = mysqli_query(
76+
$mysqli,
77+
"SELECT users.user_id, user_name FROM users
78+
LEFT JOIN user_settings on users.user_id = user_settings.user_id
79+
WHERE user_role > 1 AND user_status = 1 AND user_archived_at IS NULL ORDER BY user_name ASC"
80+
);
81+
while ($row = mysqli_fetch_array($sql_project_managers_select)) {
82+
$user_id_select = intval($row['user_id']);
83+
$user_name_select = nullable_htmlentities($row['user_name']); ?>
84+
<option <?php if ($project_manager == $user_id_select) { echo "selected"; } ?> value="<?php echo $user_id_select; ?>"><?php echo $user_name_select; ?></option>
85+
<?php } ?>
86+
</select>
87+
</div>
88+
</div>
89+
</div>
90+
<div class="modal-footer bg-white">
91+
<button type="submit" name="edit_project" class="btn btn-primary text-bold">
92+
<i class="fas fa-check mr-2"></i>Save
93+
</button>
94+
<button type="button" class="btn btn-light" data-dismiss="modal">
95+
<i class="fa fa-times mr-2"></i>Cancel
96+
</button>
97+
</div>
98+
</form>
99+
100+
<?php
101+
102+
require_once "../includes/ajax_footer.php";

ajax/ajax_quote_edit.php

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
require_once '../includes/ajax_header.php';
4+
5+
$quote_id = intval($_GET['id']);
6+
7+
$sql = mysqli_query($mysqli, "SELECT * FROM quotes LEFT JOIN clients ON quote_client_id = client_id WHERE quote_id = $quote_id LIMIT 1");
8+
9+
$row = mysqli_fetch_array($sql);
10+
$quote_id = intval($row['quote_id']);
11+
$quote_prefix = nullable_htmlentities($row['quote_prefix']);
12+
$quote_number = intval($row['quote_number']);
13+
$quote_scope = nullable_htmlentities($row['quote_scope']);
14+
$quote_date = nullable_htmlentities($row['quote_date']);
15+
$quote_expire = nullable_htmlentities($row['quote_expire']);
16+
$quote_discount = floatval($row['quote_discount_amount']);
17+
$quote_created_at = nullable_htmlentities($row['quote_created_at']);
18+
$quote_category_id = intval($row['quote_category_id']);
19+
$client_name = nullable_htmlentities($row['client_name']);
20+
21+
// Generate the HTML form content using output buffering.
22+
ob_start();
23+
?>
24+
25+
<div class="modal-header">
26+
<h5 class="modal-title text-white"><i class="fas fa-fw fa-comment-dollar mr-2"></i>Editing quote: <span class="text-bold"><?php echo "$quote_prefix$quote_number"; ?></span> - <span class="text"><?php echo $client_name; ?></span></h5>
27+
<button type="button" class="close text-white" data-dismiss="modal">
28+
<span>&times;</span>
29+
</button>
30+
</div>
31+
<form action="post.php" method="post" autocomplete="off">
32+
<input type="hidden" name="quote_id" value="<?php echo $quote_id; ?>">
33+
34+
<div class="modal-body bg-white">
35+
36+
<div class="form-group">
37+
<label>Quote Date</label>
38+
<div class="input-group">
39+
<div class="input-group-prepend">
40+
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
41+
</div>
42+
<input type="date" class="form-control" name="date" max="2999-12-31" value="<?php echo $quote_date; ?>" required>
43+
</div>
44+
</div>
45+
46+
<div class="form-group">
47+
<label>Expire <strong class="text-danger">*</strong></label>
48+
<div class="input-group">
49+
<div class="input-group-prepend">
50+
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
51+
</div>
52+
<input type="date" class="form-control" name="expire" max="2999-12-31" value="<?php echo $quote_expire; ?>" required>
53+
</div>
54+
</div>
55+
56+
<div class="form-group">
57+
<label>Income Category</label>
58+
<div class="input-group">
59+
<div class="input-group-prepend">
60+
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
61+
</div>
62+
<select class="form-control select2" name="category" required>
63+
<?php
64+
65+
$sql = 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");
66+
while ($row = mysqli_fetch_array($sql)) {
67+
$category_id = intval($row['category_id']);
68+
$category_name = nullable_htmlentities($row['category_name']);
69+
?>
70+
<option <?php if ($quote_category_id == $category_id) { echo "selected"; } ?> value="<?php echo $category_id; ?>"><?php echo $category_name; ?></option>
71+
72+
<?php } ?>
73+
74+
</select>
75+
<div class="input-group-append">
76+
<a class="btn btn-secondary" href="admin_category.php?category=Income" target="_blank"><i class="fas fa-fw fa-plus"></i></a>
77+
</div>
78+
</div>
79+
</div>
80+
81+
82+
<div class='form-group'>
83+
<label>Discount Amount</label>
84+
<div class='input-group'>
85+
<div class='input-group-prepend'>
86+
<span class='input-group-text'><i class='fa fa-fw fa-dollar-sign'></i></span>
87+
</div>
88+
<input type='text' class='form-control' inputmode="numeric" pattern="-?[0-9]*\.?[0-9]{0,2}" name='quote_discount' placeholder='0.00' value="<?php echo number_format($quote_discount, 2, '.', ''); ?>">
89+
</div>
90+
</div>
91+
92+
<div class="form-group">
93+
<label>Scope</label>
94+
<div class="input-group">
95+
<div class="input-group-prepend">
96+
<span class="input-group-text"><i class="fa fa-fw fa-comment"></i></span>
97+
</div>
98+
<input type="text" class="form-control" name="scope" placeholder="Quick description" value="<?php echo $quote_scope; ?>" maxlength="255">
99+
</div>
100+
</div>
101+
102+
</div>
103+
<div class="modal-footer bg-white">
104+
<button type="submit" name="edit_quote" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Save</button>
105+
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fas fa-times mr-2"></i>Cancel</button>
106+
</div>
107+
</form>
108+
109+
<?php
110+
111+
require_once "../includes/ajax_footer.php";

0 commit comments

Comments
 (0)