Skip to content

Instantly share code, notes, and snippets.

@malipetek
Created December 1, 2022 08:08
Show Gist options
  • Save malipetek/f8c6b1d8cf73301e4db4e4061405a36c to your computer and use it in GitHub Desktop.
Save malipetek/f8c6b1d8cf73301e4db4e4061405a36c to your computer and use it in GitHub Desktop.
(() => {
Array.from(document.querySelectorAll('.description textarea')).forEach(tx => {
tx.value = tx.value.replace(/(.+)petek:(.+)/, '$2 $1petek')
.replace(/^\s*([^\[\s]+)\s/, '[$1] ');
});
const spaces = {};
let total = 0;
Array.from(document.querySelectorAll('#invoice_item_rows>tr')).forEach(row => {
const description = row.querySelector('textarea').value;
const identifier = description.match(/\[[^\]]+\]/)[0].split('-')[0].replace('[', '');
const price = row.querySelector('td>span.amount').innerText;
console.log('replaced ', price.replace(/[^\d]/g, ''));
spaces[identifier] = (spaces[identifier] || 0) + parseInt(price.replace(/[^\d\.]/g, ''), 10);
total += parseInt(price.replace(/[^\d\.]/g, ''), 10);
});
console.log('spaces ', spaces, total);
document.querySelector('#invoice_notes').value = Object.keys(spaces).map(k => `${k}: $${(spaces[k]/100).toFixed(2)}\n`)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment