Customer Account Balance at New Invoice creation

@romangarg Yes you can, I use this myself. But it’s on you to figure out the placement.
Edit: I was getting the username instead of the account name in my original code. so if you just want the account name the code could be simpler.

// Get Username
    var currentUser = document.querySelector("body > div.overflow-x-auto.lg\\:overflow-visible.no-scrollbar.print\\:hidden.font-bold.bg-gradient-to-b.from-white.to-neutral-100.shadow.shadow-neutral-400.dark\\:bg-none.dark\\:bg-slate-700.dark\\:shadow-none > div > div.flex.justify-end > a:nth-child(1)").textContent;

// Placement of the Username
	var placement1 = document.querySelector("#printable-content > table > thead > tr:nth-child(1) > td > table:nth-child(2) > tbody > tr");
	var placement1cell1 = placement1.insertCell(1);
	placement1cell1.innerHTML = currentUser;
	
1 Like

Thank you so much for sharing. Will give it a try…

Hello everyone,
with the implementation of new sticky columns I am unable to successfully fetch & parse through node list. Please help.

What?

With the above code for extension, iterating through tables in different tabs & fetching text content of each cell is not working anymore.

I have updated the table path in ‘var y’ to new batchviewTable path, & also replaced ‘span’ with ‘td’ in " const nodeList = y.querySelectorAll(“span”); " as text in each cell of table no longer seems to be inside span.
I have also updated the “const url” link according to latest customer tab link.

But still not working. Please help me out if I am doing anything wrong.
@BawarYassin are you still able to fetch customer balance using extension after all the updates?

1 Like

I was hoping someone would reply…

Hi romangarg this is beyond my expertise - sorry.

Maybe some of the more experienced member of this forum or the developer can shed some light…

@romangarg I’m Sorry, I can’t help you further as this goes a long way toward programming and debugging. If you still want to do this yourself try using ChatGPT just paste your code there and gradually ask it to modify your code as needed.

These were well implemented before you started experimenting with code so advise to always make a backup then update Manager, make another backup and implement such code.

Secondly, I wish you success finding some-one on this forum that has similar needs and code now that @BawarYassin explains that:

@BawarYassin
I have already tried everything from my end. If only you could share the code with which you have replaced above code, rest i can figure out from there. I am really thankful and grateful to you for addressing all my queries till now. Please consider this to be my last in regard to this topic. Thanks once again

I’m sorry but I can’t help you with programming issues you should hire a dev for that. That said,
I don’t think that approach works anymore (to be honest I don’t remember very well).
I made the whole thing again later using Extensions. The code I share below is what I’m using myself and it works as intended but as I said earlier it is on you to make it work for you.

// add the id="last-content" to the last element in custom theme
const lastContent = document.getElementById('last-content');

//////////////////////////
// Create the table element
let table = document.createElement('table');
table.id = 'debtTable';
// Add styles to the table element
table.style.width = '40%';
table.style.fontFamily = 'Noto Naskh Arabic';
table.style.textAlign = 'right';
table.style.borderColor = '#AF0000';
table.style.borderWidth = '1px';
table.style.fontWeight = 'bold';
table.style.fontSize = '16px';
table.style.borderRadius = '5px 5px 5px 5px';
table.style.padding = '0px';
table.style.float = "left";
table.style.marginTop = 'auto';
table.style.marginBottom = '30px';
// Create the table body element
const tbody = document.createElement('tbody');

// Create the first row and cell
const row1 = document.createElement('tr');
const cell1 = document.createElement('td');
cell1.style.borderBottom = 'thin solid #AF0000';
cell1.style.fontSize = '16px';
cell1.style.fontWeight = 'bold';
cell1.style.color = '#810000';
cell1.textContent = 'previous debt';
cell1.style.padding = '10px';

// Create the second row and cell
const row2 = document.createElement('tr');
const cell2 = document.createElement('td');
cell2.style.fontSize = '16px';
cell2.style.fontWeight = 'bold';
cell2.style.color = '#810000';
cell2.textContent = 'current debt';
cell2.style.padding = '10px';

// Append the cells to their respective rows
row1.appendChild(cell1);
row2.appendChild(cell2);

// Append the rows to the table body
tbody.appendChild(row1);
tbody.appendChild(row2);


table.style.width = '40%'
// Append the table body to the table
table.appendChild(tbody);
 
lastContent.insertAdjacentElement('afterend', table);


const url = 'http://127.0.0.1:55667/customers?ogYl2qnYp9ix2q_blduMINio25XZh9in2LEgQmFoYXIgRmFjdG9yefALAMAMAJANAJgN9AO4DQDoDQC4DgDQDwDwEAA'
var CustomerID = document.querySelector("#MainTable > thead > tr:nth-child(1) > td > table:nth-child(2) > tbody > tr > td:nth-child(1) > div:nth-child(1) > b:nth-child(1)").textContent;

fetch(url).then(function (response) {
  return response.text();
}).then(function (html) {
 // START HERE >
  // get data from spans
  var tdSpans = [];
  const spanList = $(html).find(" tr > td");
  for (let i = 0; i < spanList.length; i++) {
    tdSpans.push(spanList[i].textContent);
  }

  // get header names
  var headerSpans = [];
  const headerList = $(html).find("th > span > a");
  for (let i = 0; i < headerList.length; i++) {
    headerSpans.push(headerList[i].textContent);
  }
  // find debt header index
  var debtHeaderIndex = headerSpans.indexOf("Accounts receivable"); // must be changed as per language 
  // find customer ID index
  var customerIDIndex = tdSpans.indexOf(CustomerID);
  
  // Get prevoiusdept at matched index
    var currentdept = tdSpans.at(customerIDIndex+debtHeaderIndex).replaceAll("IQD ", "").replaceAll(",", "").replaceAll('NaN', 0.00 ).replaceAll(' ', '');
 
    var invoicetotal = document.querySelector("#last-content > tbody > tr:nth-last-child(1) td:last-child").textContent.replaceAll("IQD ", "").replaceAll(",", "");
    
    var debt = Number(currentdept) - Number(invoicetotal)
    var prevoiusdept = debt.toLocaleString('en-US').replaceAll('NaN', 0.00 ).replaceAll(' ', '');
	
	var row1 = document.querySelector("#debtTable > tbody > tr:nth-child(1)");
	row1.style.fontSize = "medium";
	var row2 = document.querySelector("#debtTable > tbody > tr:nth-child(2)");
	row2.style.fontSize = "medium";
		
	var row1cell2 = row1.insertCell(1);
	row1cell2.innerHTML = prevoiusdept + '   IQD';
	row1cell2.style.textAlign = "left";
	row1cell2.style.fontWeight  = "bold";
	row1cell2.style.color = "#AF0000";
	row1cell2.style.borderBottom = "thin solid #AF0000";
	row1cell2.style.padding = '10px';
	
	var row2cell2 = row2.insertCell(1);
	row2cell2.innerHTML = String(Number(currentdept).toLocaleString('en-US')).replaceAll('NaN', 0.00 ) + '   IQD';
	row2cell2.style.textAlign = "left";
	row2cell2.style.fontWeight  = "bold";
	row2cell2.style.color = "#AF0000";
	row2cell2.style.padding = '10px';
	
}).catch(function (err) {
	// There was an error
	alert('Something went wrong.', err);
});
1 Like

Thank you so much. Really appreciate you doing this much. Thanks again.