forked from mohsinalimat/Important-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreal_timesync.js
More file actions
51 lines (40 loc) · 1.94 KB
/
real_timesync.js
File metadata and controls
51 lines (40 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
frappe.ready(async () => {
const currentUser = frappe.session.user; // Get the current logged-in user
// Subscribe to the user-specific event
frappe.realtime.on(`item_selected_${currentUser}`, (data) => {
console.log(data, "Item selected");
// Find the table body element
var tableBody = document.getElementById('custom-items-table-body');
// Check if item code already exists in the table
var existingRow = Array.from(tableBody.children).find(row => {
return row.children[0].textContent === data.item_code;
});
if (existingRow) {
// Update the existing row's quantity
existingRow.children[1].textContent = data.qty;
} else {
// Create a new row
var row = document.createElement('tr');
// Create and insert item code cell
var itemCodeCell = document.createElement('td');
itemCodeCell.textContent = data.item_code;
row.appendChild(itemCodeCell);
// Create and insert quantity cell
var qtyCell = document.createElement('td');
qtyCell.textContent = data.qty;
row.appendChild(qtyCell);
// Insert other cells (Rate, Amount, Actions) as empty or default values
var rateCell = document.createElement('td');
rateCell.textContent = data.rate; // Add default or dynamic value if available
row.appendChild(rateCell);
var amountCell = document.createElement('td');
amountCell.textContent = ''; // Add default or dynamic value if available
row.appendChild(amountCell);
var actionsCell = document.createElement('td');
actionsCell.textContent = ''; // Add default or dynamic value if available
row.appendChild(actionsCell);
// Append the new row to the table body
tableBody.appendChild(row);
}
});
});