Feature When editing vendor templates you can now update all vendors based off of the template

This commit is contained in:
johnnyq 2023-01-30 17:54:50 -05:00
parent 95067e44b2
commit 463f90a103
8 changed files with 65 additions and 12 deletions

View File

@ -114,6 +114,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
$vendor_sla = htmlentities($row['vendor_sla']);
$vendor_code = htmlentities($row['vendor_code']);
$vendor_notes = htmlentities($row['vendor_notes']);
$vendor_template_id = intval($row['vendor_template_id']);
?>
<tr>

View File

@ -832,11 +832,19 @@ if(LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION){
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.3.9'");
}
//if(CURRENT_DATABASE_VERSION == '0.3.9'){
// Insert queries here required to update to DB version 0.4.0
if(CURRENT_DATABASE_VERSION == '0.3.9'){
mysqli_query($mysqli, "ALTER TABLE `vendors` ADD `vendor_template_id` INT(11) NOT NULL DEFAULT 0 AFTER `vendor_client_id`");
mysqli_query($mysqli, "ALTER TABLE `software` ADD `software_template_id` INT(11) NOT NULL DEFAULT 0 AFTER `software_client_id`");
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.0'");
}
//if(CURRENT_DATABASE_VERSION == '0.4.0'){
// Insert queries here required to update to DB version 0.4.1
// Then, update the database to the next sequential version
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.0'");
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.1'");
//}
} else {

View File

@ -5,4 +5,4 @@
* It is used in conjunction with database_updates.php
*/
DEFINE("LATEST_DATABASE_VERSION", "0.3.9");
DEFINE("LATEST_DATABASE_VERSION", "0.4.0");

4
db.sql
View File

@ -1146,6 +1146,7 @@ CREATE TABLE `software` (
`software_accessed_at` datetime DEFAULT NULL,
`software_login_id` int(11) NOT NULL DEFAULT 0,
`software_client_id` int(11) NOT NULL,
`software_template_id` int(11) NOT NULL DEFAULT 0,
`company_id` int(11) NOT NULL,
PRIMARY KEY (`software_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
@ -1519,6 +1520,7 @@ CREATE TABLE `vendors` (
`vendor_archived_at` datetime DEFAULT NULL,
`vendor_accessed_at` datetime DEFAULT NULL,
`vendor_client_id` int(11) NOT NULL DEFAULT 0,
`vendor_template_id` int(11) NOT NULL DEFAULT 0,
`company_id` int(11) NOT NULL,
PRIMARY KEY (`vendor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
@ -1533,4 +1535,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2023-01-30 15:02:15
-- Dump completed on 2023-01-30 17:53:50

View File

@ -2088,7 +2088,6 @@ if(isset($_POST['edit_vendor_template'])){
$vendor_id = intval($_POST['vendor_id']);
$name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])));
$description = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])));
$account_number = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['account_number'])));
$contact_name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['contact_name'])));
$phone = preg_replace("/[^0-9]/", '',$_POST['phone']);
$extension = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['extension'])));
@ -2096,10 +2095,17 @@ if(isset($_POST['edit_vendor_template'])){
$website = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['website'])));
$hours = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['hours'])));
$sla = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['sla'])));
$code = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['code'])));
$notes = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['notes'])));
$vendor_template_id = intval($_POST['vendor_template_id']);
mysqli_query($mysqli,"UPDATE vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code',vendor_account_number = '$account_number', vendor_notes = '$notes' WHERE vendor_id = $vendor_id AND company_id = $session_company_id");
if($_POST['update_base_vendors'] == 1) {
$sql_update_vendors = "OR vendor_template_id = $vendor_id";
} else{
$sql_update_vendors = "";
}
//Update the exisiting template and all templates bassed of this vendor template
mysqli_query($mysqli,"UPDATE vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code',vendor_account_number = '$account_number', vendor_notes = '$notes' WHERE (vendor_id = $vendor_id $sql_update_vendors) AND company_id = $session_company_id");
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Vendor Template', log_action = 'Modify', log_description = '$session_name modified vendor template $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
@ -2134,7 +2140,7 @@ if(isset($_POST['add_vendor_from_template'])){
$notes = trim(strip_tags(mysqli_real_escape_string($mysqli,$row['vendor_notes'])));
// Vendor add query
mysqli_query($mysqli,"INSERT INTO vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code', vendor_account_number = '$account_number', vendor_notes = '$notes', vendor_client_id = $client_id, company_id = $session_company_id");
mysqli_query($mysqli,"INSERT INTO vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code', vendor_account_number = '$account_number', vendor_notes = '$notes', vendor_client_id = $client_id, vendor_template_id = $vendor_template_id, company_id = $session_company_id");
$vendor_id = mysqli_insert_id($mysqli);
@ -2192,8 +2198,9 @@ if(isset($_POST['edit_vendor'])){
$sla = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['sla'])));
$code = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['code'])));
$notes = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['notes'])));
$vendor_template_id = intval($_POST['vendor_template_id']);
mysqli_query($mysqli,"UPDATE vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code',vendor_account_number = '$account_number', vendor_notes = '$notes' WHERE vendor_id = $vendor_id AND company_id = $session_company_id");
mysqli_query($mysqli,"UPDATE vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code',vendor_account_number = '$account_number', vendor_notes = '$notes', vendor_template_id = $vendor_template_id WHERE vendor_id = $vendor_id AND company_id = $session_company_id");
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Vendor', log_action = 'Modify', log_description = '$session_name modified vendor $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
@ -2228,8 +2235,14 @@ if(isset($_GET['delete_vendor'])){
//Get Vendor Name
$sql = mysqli_query($mysqli,"SELECT * FROM vendors WHERE vendor_id = $vendor_id AND company_id = $session_company_id");
$row = mysqli_fetch_array($sql);
$vendor_name = $row['vendor_name'];
$vendor_name = strip_tags(mysqli_real_escape_string($mysqli, $row['vendor_name']));
$client_id = intval($row['vendor_client_id']);
$vendor_template_id = intval($row['vendor_template_id']);
// If its a template reset all vendors based off this template to no template base
if ($vendor_template_id > 0){
mysqli_query($mysqli,"UPDATE vendors SET vendor_template_id = 0 WHERE vendor_template_id = $vendor_template_id");
}
mysqli_query($mysqli,"DELETE FROM vendors WHERE vendor_id = $vendor_id AND company_id = $session_company_id");

View File

@ -69,6 +69,27 @@
</div>
</div>
<div class="form-group">
<label>Template Base</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-puzzle-piece"></i></span>
</div>
<select class="form-control select2" name="vendor_template_id">
<option value="0">- None -</option>
<?php
$sql_vendor_templates = mysqli_query($mysqli,"SELECT * FROM vendors WHERE vendor_template = 1 AND vendor_archived_at IS NULL ORDER BY vendor_name ASC");
while ($row = mysqli_fetch_array($sql_vendor_templates)) {
$vendor_template_id_select = $row['vendor_id'];
$vendor_template_name_select = htmlentities($row['vendor_name']); ?>
<option <?php if ($vendor_template_id == $vendor_template_id_select) { echo "selected"; } ?> value="<?php echo $vendor_template_id_select; ?>"><?php echo $vendor_template_name_select; ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="tab-pane fade" id="pills-support<?php echo $vendor_id; ?>">

View File

@ -69,6 +69,13 @@
</div>
</div>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="updateVendorsCheckbox<?php echo $vendor_id; ?>" name="update_base_vendors" value="1" >
<label class="custom-control-label" for="updateVendorsCheckbox<?php echo $vendor_id; ?>">Update All Base Vendors</label>
</div>
</div>
</div>
<div class="tab-pane fade" id="pills-support<?php echo $vendor_id; ?>">
@ -155,7 +162,7 @@
</div>
<div class="modal-footer bg-white">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" name="edit_vendor_template" class="btn btn-primary text-bold"><i class="fa fa-fw fa-check"></i> Update Template</button>
<button type="submit" class="btn btn-primary text-bold" name="edit_vendor_template"><i class="fa fa-fw fa-check"></i>Update Template</button>
</div>
</form>
</div>

View File

@ -120,6 +120,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
$vendor_sla = htmlentities($row['vendor_sla']);
$vendor_code = htmlentities($row['vendor_code']);
$vendor_notes = htmlentities($row['vendor_notes']);
$vendor_template_id = intval($row['vendor_template_id']);
?>