Feature: Vendors can now be linked to documents

This commit is contained in:
johnnyq 2023-08-24 17:03:45 -04:00
parent 6325301a00
commit 6858d1f293
5 changed files with 221 additions and 2 deletions

View File

@ -0,0 +1,48 @@
<div class="modal" id="associateFileToDocumentModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content bg-dark">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-fw fa-paperclip mr-2"></i>Associate File to <strong><?php echo $document_name; ?></strong></h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
<input type="hidden" name="document_id" value="<?php echo $document_id; ?>">
<div class="modal-body bg-white">
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-paperclip"></i></span>
</div>
<select class="form-control select2" name="file_id">
<option value="">- Select a File -</option>
<?php
$sql_files_select = mysqli_query($mysqli, "SELECT * FROM files
LEFT JOIN folders ON folder_id = file_folder_id
WHERE file_client_id = $client_id ORDER BY folder_name ASC, file_name ASC");
while ($row = mysqli_fetch_array($sql_files_select)) {
$file_id = intval($row['file_id']);
$file_name = nullable_htmlentities($row['file_name']);
$folder_name = nullable_htmlentities($row['folder_name']);
?>
<option value="<?php echo $file_id ?>"><?php echo "$folder_name/$file_name"; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="modal-footer bg-white">
<button type="submit" name="associate_file_to_document" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Associate</button>
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
</div>
</form>
</div>
</div>
</div>

View File

@ -0,0 +1,48 @@
<div class="modal" id="associateFileToDocumentModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content bg-dark">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-fw fa-paperclip mr-2"></i>Associate File to <strong><?php echo $document_name; ?></strong></h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
<input type="hidden" name="document_id" value="<?php echo $document_id; ?>">
<div class="modal-body bg-white">
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-paperclip"></i></span>
</div>
<select class="form-control select2" name="file_id">
<option value="">- Select a File -</option>
<?php
$sql_files_select = mysqli_query($mysqli, "SELECT * FROM files
LEFT JOIN folders ON folder_id = file_folder_id
WHERE file_client_id = $client_id ORDER BY folder_name ASC, file_name ASC");
while ($row = mysqli_fetch_array($sql_files_select)) {
$file_id = intval($row['file_id']);
$file_name = nullable_htmlentities($row['file_name']);
$folder_name = nullable_htmlentities($row['folder_name']);
?>
<option value="<?php echo $file_id ?>"><?php echo "$folder_name/$file_name"; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="modal-footer bg-white">
<button type="submit" name="associate_file_to_document" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Associate</button>
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
</div>
</form>
</div>
</div>
</div>

View File

@ -0,0 +1,58 @@
<div class="modal" id="associateVendorToDocumentModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content bg-dark">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-fw fa-building mr-2"></i>Associate Vendor to <strong><?php echo $document_name; ?></strong></h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
<input type="hidden" name="document_id" value="<?php echo $document_id; ?>">
<div class="modal-body bg-white">
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-building"></i></span>
</div>
<select class="form-control select2" name="vendor_id">
<option value="">- Select a Vendor -</option>
<?php
// Check if there are any associated vendors
if (!empty($associated_vendors)) {
$excluded_vendor_ids = implode(",", $associated_vendors);
$exclude_condition = "AND vendor_id NOT IN ($excluded_vendor_ids)";
} else {
$exclude_condition = ""; // No condition if there are no displayed vendors
}
$sql_vendors_select = mysqli_query($mysqli, "SELECT * FROM vendors
WHERE vendor_client_id = $client_id
AND vendor_archived_at IS NULL
$exclude_condition
ORDER BY vendor_name ASC"
);
while ($row = mysqli_fetch_array($sql_vendors_select)) {
$vendor_id = intval($row['vendor_id']);
$vendor_name = nullable_htmlentities($row['vendor_name']);
?>
<option value="<?php echo $vendor_id ?>"><?php echo $vendor_name; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="modal-footer bg-white">
<button type="submit" name="associate_vendor_to_document" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Associate</button>
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
</div>
</form>
</div>
</div>
</div>

View File

@ -63,7 +63,7 @@ $document_folder_id = intval($row['document_folder_id']);
<h5>Related</h5>
<h6>
<i class="fas fa-fw fa-paperclip text-secondary mr-2"></i>Files
<button type="button" class="btn btn-link btn-sm">
<button type="button" class="btn btn-link btn-sm" data-toggle="modal" data-target="#associateFileToDocumentModal">
<i class="fas fa-fw fa-plus"></i>
</button>
</h6>
@ -93,11 +93,37 @@ $document_folder_id = intval($row['document_folder_id']);
</h6>
<h6>
<i class="fas fa-fw fa-building text-secondary mr-2"></i>Vendors
<button type="button" class="btn btn-link btn-sm">
<button type="button" class="btn btn-link btn-sm" data-toggle="modal" data-target="#associateVendorToDocumentModal">
<i class="fas fa-fw fa-plus"></i>
</button>
</h6>
<ul>
<?php
$sql_vendors = mysqli_query($mysqli, "SELECT * FROM vendors, vendor_documents
WHERE vendors.vendor_id = vendor_documents.vendor_id
AND vendor_documents.document_id = $document_id
ORDER BY vendor_name ASC"
);
$associated_vendors = array();
while ($row = mysqli_fetch_array($sql_vendors)) {
$vendor_id = intval($row['vendor_id']);
$vendor_name = nullable_htmlentities($row['vendor_name']);
$associated_vendors[] = $vendor_id;
?>
<li>
<?php echo $vendor_name; ?>
<a href="post.php?unassociate_vendor_from_document&vendor_id=<?php echo $vendor_id; ?>&document_id=<?php echo $document_id; ?>">
<i class="fas fa-fw fa-times text-secondary ml-2"></i>
</a>
</li>
<?php
}
?>
</ul>
</div>
</div>
@ -108,6 +134,8 @@ $document_folder_id = intval($row['document_folder_id']);
<?php
require_once("client_document_edit_modal.php");
require_once("client_document_associate_file_modal.php");
require_once("client_document_associate_vendor_modal.php");
require_once("share_modal.php");
require_once("footer.php");

View File

@ -132,6 +132,43 @@ if (isset($_POST['move_document'])) {
}
if (isset($_POST['associate_vendor_to_document'])) {
validateTechRole();
$client_id = intval($_POST['client_id']);
$document_id = intval($_POST['document_id']);
$vendor_id = intval($_POST['vendor_id']);
// Document add query
mysqli_query($mysqli,"INSERT INTO vendor_documents SET vendor_id = $vendor_id, document_id = $document_id");
// Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document', log_action = 'Create', log_description = 'Created Document Vendor Relation', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id");
$_SESSION['alert_message'] = "Vendor associated with Document";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if (isset($_GET['unassociate_vendor_from_document'])) {
validateTechRole();
$vendor_id = intval($_GET['vendor_id']);
$document_id = intval($_GET['document_id']);
mysqli_query($mysqli,"DELETE FROM vendor_documents WHERE vendor_id = $vendor_id AND document_id = $document_id");
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document', log_action = 'Delete', log_description = 'Document Vendor relationship removed', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
$_SESSION['alert_message'] = "Vendor has been unassciated";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if (isset($_POST['edit_document_template'])) {
validateTechRole();