FIX_Lead History
This commit is contained in:
parent
bcaf62c12a
commit
8c4eba72a1
@ -215,8 +215,7 @@ table.dataTable tbody td {
|
|||||||
</a>
|
</a>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<a href="javascript:void(0);"
|
<a class="dropdown-item btnHistory app-text-black"
|
||||||
class="dropdown-item btnHistory app-text-black"
|
|
||||||
data-id="<?= $row['id']; ?>"
|
data-id="<?= $row['id']; ?>"
|
||||||
title="Click to view Mail History">
|
title="Click to view Mail History">
|
||||||
<i class="mdi mdi-history mr-2 text-muted font-18 vertical-middle"></i>Email History
|
<i class="mdi mdi-history mr-2 text-muted font-18 vertical-middle"></i>Email History
|
||||||
@ -344,6 +343,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
// Handle clicks on dropdown items
|
// Handle clicks on dropdown items
|
||||||
customDropdown.querySelectorAll('.dropdown-item').forEach(item => {
|
customDropdown.querySelectorAll('.dropdown-item').forEach(item => {
|
||||||
item.addEventListener('click', function(e) {
|
item.addEventListener('click', function(e) {
|
||||||
|
console.log("##############");
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
@ -358,7 +358,13 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
if (id) {
|
if (id) {
|
||||||
getLeadsDataForEdit(id, lead_form_type);
|
getLeadsDataForEdit(id, lead_form_type);
|
||||||
}
|
}
|
||||||
}else{
|
}else if (this.classList.contains('btnHistory')) {
|
||||||
|
let lead_id = this.getAttribute('data-id');
|
||||||
|
if(lead_id){ console.log("******** Clicked from td lead_id-", lead_id); getLeadsDataForMailHistory(lead_id); }
|
||||||
|
else{ console.log("******** Clicked from td but i don`t have lead_id"); }
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
const onclickAttr = this.getAttribute('onclick');
|
const onclickAttr = this.getAttribute('onclick');
|
||||||
if (onclickAttr) {
|
if (onclickAttr) {
|
||||||
eval(onclickAttr);
|
eval(onclickAttr);
|
||||||
@ -387,6 +393,16 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
activeDropdown = null;
|
activeDropdown = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener("click", function(e) {
|
||||||
|
if (e.target.closest(".btnHistory")) {
|
||||||
|
let lead_id = e.target.closest(".btnHistory").dataset.id;
|
||||||
|
console.log("******** in triple dot id available - " + lead_id);
|
||||||
|
getLeadsDataForMailHistory(lead_id);
|
||||||
|
}
|
||||||
|
else{ console.log("******** in triple dot but id not available"); }
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@ -462,146 +478,141 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
function getLeadsDataForMailHistory(lead_id){
|
||||||
document.addEventListener("click", function(e) {
|
|
||||||
if (e.target.closest(".btnHistory")) {
|
console.log("******** Inside Fnz :", lead_id);
|
||||||
let lead_id = e.target.closest(".btnHistory").dataset.id;
|
let url = '<?= base_url('/util/getLeadEmailHistory/') ?>' + lead_id;
|
||||||
console.log("*********" + lead_id);
|
console.log("******** Fetching:", url);
|
||||||
let url = '<?= base_url('/util/getLeadEmailHistory/') ?>' + lead_id;
|
|
||||||
console.log("*********" + url);
|
fetch(url, {
|
||||||
fetch('<?= base_url('/util/getLeadEmailHistory/') ?>' + lead_id, {
|
method: "GET",
|
||||||
method: "GET",
|
headers: { "Accept": "application/json" }
|
||||||
headers: {
|
})
|
||||||
"Accept": "application/json"
|
.then(response => response.json())
|
||||||
|
.then(response => {
|
||||||
|
let container = document.querySelector(".history-container");
|
||||||
|
container.innerHTML = "";
|
||||||
|
if (response.status === "success" && response.data.length > 0) {
|
||||||
|
console.log("******** 1" + response.status);
|
||||||
|
let table = `
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table data-custom-table-css="table" id="historytable" class="table table-striped mb-0 nowrap" cellspacing="0" id="tickets-table">
|
||||||
|
|
||||||
|
<thead class="bg-light">
|
||||||
|
<tr>
|
||||||
|
<th><div class="column-header">S.No.</div></th>
|
||||||
|
<th><div class="column-header">From Mail</div></th>
|
||||||
|
<th><div class="column-header">To Mail</div></th>
|
||||||
|
<th><div class="column-header">BCC</div></th>
|
||||||
|
<th><div class="column-header">CC</div></th>
|
||||||
|
<th><div class="column-header">Type</div></th>
|
||||||
|
<th><div class="column-header">Status</div></th>
|
||||||
|
<th><div class="column-header">Date/Time</div></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
`;
|
||||||
|
|
||||||
|
response.data.forEach((row, index) => {
|
||||||
|
let formattedDate = "-";
|
||||||
|
let statusValue = "-";
|
||||||
|
if (row.received_message) {
|
||||||
|
if (row.received_message.toLowerCase().includes("error")) {
|
||||||
|
statusValue = "Failed";
|
||||||
|
} else {
|
||||||
|
statusValue = "Success";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (row.created_at) {
|
||||||
|
let dt = new Date(row.created_at);
|
||||||
|
let dateStr = dt.toLocaleDateString("en-GB", {
|
||||||
|
day: "2-digit",
|
||||||
|
month: "long",
|
||||||
|
year: "numeric"
|
||||||
|
});
|
||||||
|
let timeStr = dt.toLocaleTimeString("en-US", {
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: true
|
||||||
|
}).toLowerCase();
|
||||||
|
formattedDate = `${dateStr} ${timeStr}`;
|
||||||
|
}
|
||||||
|
let fromMails = "-";
|
||||||
|
if (row.from_mail) {
|
||||||
|
fromMails = row.from_mail
|
||||||
|
.split(",") // split by comma
|
||||||
|
.map(m => m.trim().replace(/^"|"$/g, "")) // trim + remove quotes at start/end
|
||||||
|
.filter(m => m !== "") // remo
|
||||||
|
.join("<br>"); // join with line break
|
||||||
|
}
|
||||||
|
let toMails = "-";
|
||||||
|
if (row.mail) {
|
||||||
|
toMails = row.mail
|
||||||
|
.split(",")
|
||||||
|
.map(m => m.trim().replace(/^"|"$/g, ""))
|
||||||
|
.filter(m => m !== "")
|
||||||
|
.join("<br>");
|
||||||
|
}
|
||||||
|
let ccMails = "-";
|
||||||
|
if (row.cc && row.cc.trim() !== "") {
|
||||||
|
ccMails = row.cc
|
||||||
|
.split(",")
|
||||||
|
.map(m => m.trim().replace(/^"|"$/g, ""))
|
||||||
|
.filter(m => m !== "")
|
||||||
|
.join("<br>");
|
||||||
|
}
|
||||||
|
let bccMails = "-";
|
||||||
|
if (row.bcc && row.bcc.trim() !== "") {
|
||||||
|
bccMails = row.bcc
|
||||||
|
.split(",")
|
||||||
|
.map(m => m.trim().replace(/^"|"$/g, ""))
|
||||||
|
.filter(m => m !== "")
|
||||||
|
.join("<br>");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
table += `
|
||||||
|
<tr>
|
||||||
|
<td style="white-space: nowrap !important;">${index + 1}</td>
|
||||||
|
<td style="white-space: nowrap !important;">${fromMails}</td>
|
||||||
|
<td style="white-space: nowrap !important;">${toMails}</td>
|
||||||
|
<td style="white-space: nowrap !important;">${bccMails ? bccMails : '-'}</td>
|
||||||
|
<td style="white-space: nowrap !important;">${ccMails ? ccMails : '-'}</td>
|
||||||
|
<td style="white-space: nowrap !important;">${row.mail_type ? row.mail_type.toUpperCase() : '-'}</td>
|
||||||
|
<td style="white-space: nowrap !important;">${statusValue ? statusValue.toUpperCase() : '-'}</td>
|
||||||
|
<td style="white-space: nowrap !important;">${formattedDate}</td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
|
||||||
|
table += `</tbody></table>`;
|
||||||
|
container.innerHTML = table;
|
||||||
|
// show modal (if using Bootstrap 5)
|
||||||
|
} else {
|
||||||
|
|
||||||
|
container.innerHTML = `
|
||||||
|
<div class="d-flex justify-content-center align-items-center" style="height: 50vh; width:100%;">
|
||||||
|
<p class="text-center font-color-black"><i>${response.message ?? "No History Available"}</i></p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
// Show modal always
|
||||||
|
new bootstrap.Modal(document.getElementById("EmailModal")).show();
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.log("******** 3" + error);
|
||||||
|
document.querySelector(".history-container").innerHTML = `
|
||||||
|
<div class="d-flex justify-content-center align-items-center" style="height: 50vh; width:100%;">
|
||||||
|
<p class="text-center font-color-black"><i>No Data Found</i></p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
let EmailModal = new bootstrap.Modal(document.getElementById("EmailModal"));
|
||||||
|
EmailModal.show();
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(response => {
|
|
||||||
let container = document.querySelector(".history-container");
|
|
||||||
container.innerHTML = ""; // clear old content
|
|
||||||
if (response.status === "success" && response.data.length > 0) {
|
|
||||||
console.log("******** 1" + response.status);
|
|
||||||
let table = `
|
|
||||||
<div class="table-responsive">
|
|
||||||
<table data-custom-table-css="table" id="historytable" class="table table-striped mb-0 nowrap" cellspacing="0" id="tickets-table">
|
|
||||||
|
|
||||||
<thead class="bg-light">
|
|
||||||
<tr>
|
|
||||||
<th><div class="column-header">S.No.</div></th>
|
|
||||||
<th><div class="column-header">From Mail</div></th>
|
|
||||||
<th><div class="column-header">To Mail</div></th>
|
|
||||||
<th><div class="column-header">BCC</div></th>
|
|
||||||
<th><div class="column-header">CC</div></th>
|
|
||||||
<th><div class="column-header">Type</div></th>
|
|
||||||
<th><div class="column-header">Status</div></th>
|
|
||||||
<th><div class="column-header">Date/Time</div></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
`;
|
|
||||||
|
|
||||||
response.data.forEach((row, index) => {
|
|
||||||
let formattedDate = "-";
|
|
||||||
let statusValue = "-";
|
|
||||||
if (row.received_message) {
|
|
||||||
if (row.received_message.toLowerCase().includes("error")) {
|
|
||||||
statusValue = "Failed";
|
|
||||||
} else {
|
|
||||||
statusValue = "Success";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (row.created_at) {
|
|
||||||
let dt = new Date(row.created_at);
|
|
||||||
let dateStr = dt.toLocaleDateString("en-GB", {
|
|
||||||
day: "2-digit",
|
|
||||||
month: "long",
|
|
||||||
year: "numeric"
|
|
||||||
});
|
|
||||||
let timeStr = dt.toLocaleTimeString("en-US", {
|
|
||||||
hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
hour12: true
|
|
||||||
}).toLowerCase();
|
|
||||||
formattedDate = `${dateStr} ${timeStr}`;
|
|
||||||
}
|
|
||||||
let fromMails = "-";
|
|
||||||
if (row.from_mail) {
|
|
||||||
fromMails = row.from_mail
|
|
||||||
.split(",") // split by comma
|
|
||||||
.map(m => m.trim().replace(/^"|"$/g, "")) // trim + remove quotes at start/end
|
|
||||||
.filter(m => m !== "") // remo
|
|
||||||
.join("<br>"); // join with line break
|
|
||||||
}
|
|
||||||
let toMails = "-";
|
|
||||||
if (row.mail) {
|
|
||||||
toMails = row.mail
|
|
||||||
.split(",")
|
|
||||||
.map(m => m.trim().replace(/^"|"$/g, ""))
|
|
||||||
.filter(m => m !== "")
|
|
||||||
.join("<br>");
|
|
||||||
}
|
|
||||||
let ccMails = "-";
|
|
||||||
if (row.cc && row.cc.trim() !== "") {
|
|
||||||
ccMails = row.cc
|
|
||||||
.split(",")
|
|
||||||
.map(m => m.trim().replace(/^"|"$/g, ""))
|
|
||||||
.filter(m => m !== "")
|
|
||||||
.join("<br>");
|
|
||||||
}
|
|
||||||
let bccMails = "-";
|
|
||||||
if (row.bcc && row.bcc.trim() !== "") {
|
|
||||||
bccMails = row.bcc
|
|
||||||
.split(",")
|
|
||||||
.map(m => m.trim().replace(/^"|"$/g, ""))
|
|
||||||
.filter(m => m !== "")
|
|
||||||
.join("<br>");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
table += `
|
|
||||||
<tr>
|
|
||||||
<td style="white-space: nowrap !important;">${index + 1}</td>
|
|
||||||
<td style="white-space: nowrap !important;">${fromMails}</td>
|
|
||||||
<td style="white-space: nowrap !important;">${toMails}</td>
|
|
||||||
<td style="white-space: nowrap !important;">${bccMails ? bccMails : '-'}</td>
|
|
||||||
<td style="white-space: nowrap !important;">${ccMails ? ccMails : '-'}</td>
|
|
||||||
<td style="white-space: nowrap !important;">${row.mail_type ? row.mail_type.toUpperCase() : '-'}</td>
|
|
||||||
<td style="white-space: nowrap !important;">${statusValue ? statusValue.toUpperCase() : '-'}</td>
|
|
||||||
<td style="white-space: nowrap !important;">${formattedDate}</td>
|
|
||||||
</tr>
|
|
||||||
`;
|
|
||||||
});
|
|
||||||
|
|
||||||
table += `</tbody></table>`;
|
|
||||||
container.innerHTML = table;
|
|
||||||
} else {
|
|
||||||
console.log("******** 2" + response.status);
|
|
||||||
container.innerHTML = `
|
|
||||||
<div class="d-flex justify-content-center align-items-center" style="height: 50vh; width:100%;">
|
|
||||||
<p class="text-center"><i>${response.message ?? 'No history found'}</i></p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// show modal (if using Bootstrap 5)
|
|
||||||
let EmailModal = new bootstrap.Modal(document.getElementById("EmailModal"));
|
|
||||||
EmailModal.show();
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log("******** 3" + error);
|
|
||||||
document.querySelector(".history-container").innerHTML = `
|
|
||||||
<div class="d-flex justify-content-center align-items-center" style="height: 50vh; width:100%;">
|
|
||||||
<p class="text-center"><i>No Data Found</i></p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
let EmailModal = new bootstrap.Modal(document.getElementById("EmailModal"));
|
|
||||||
EmailModal.show();
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user