Click here to Skip to main content
15,917,456 members

Comments by Member 15205573 (Top 1 by date)

Member 15205573 31-Dec-21 17:05pm View    
hey CHILL60
Thank you for your effort
i will try to learn more about this string builder and see if your solution will work or not


however i managed to get this code from the software i wanted to copy this fusion feature from it's a php desktop application

what do you think about this code
//var fusionMode = 1;


function fusion(){
var fusionner = [];
var selectedTr = document.querySelectorAll('tr.current');

if (selectedTr.length > 1) {
var printServer = document.querySelector('tr.current').getAttribute('ds');
var fPrice = 0;
var fName = [];
var fId = [];
var biggestPrice = 0;

for (var i = 0; i < selectedTr.length; i++) {

var tid = selectedTr[i].getAttribute('rel');
var idInFood = findID(foodList , tid);
if (parseFloat(foodList[idInFood][3]) > biggestPrice ) biggestPrice = parseFloat(foodList[idInFood][3]);
fPrice += parseFloat(foodList[idInFood][3]);
fName.push( foodList[idInFood][2] ) ;
fId.push(tid);
document.querySelector('input[name="p_'+tid+'"]').remove();
}
fId = fId.join();
//fId = fName.join('/');
fName = fName.mergenames();
var MiddlePrice = Math.round (fPrice / selectedTr.length );
var MiddlePrice =(fusionMode == 1 ?MiddlePrice : biggestPrice );
var tableCont = "1"+fName+""+ MiddlePrice +"";
var inputContent = "";
$('#salesTable').append(tableCont);
//document.getElementById('salesTable').innerHTML = tableCont + document.getElementById('salesTable').innerHTML;
$('#salesForm').append(inputContent);


for (var i = 0; i < selectedTr.length; i++) {
selectedTr[i].remove();
}
} else {
document.getElementsByClassName('fusionBtn')[0].classList.add('blinkerror');
window.setTimeout(function(){document.getElementsByClassName('fusionBtn')[0].classList.remove('blinkerror');},500);
// alert('erreur !');
}
countAmount();
selectingTr();
}


Array.prototype.mergenames = function(){
var ar = this;
var m = this[0].split(' ')[0];
//console.log(m);
for (var i = 0; i < ar.length; i++) {
if (ar[i].split(' ').length > 1 && ar[i].indexOf(m)) ar[i] = ar[i].trim().replace(m, "");
}
return m+'('+ar.join(' - ')+')';
}






function findID(fl , x) {
var ret ='';
for (var i = 0; i < fl.length; i++) {
if (fl[i][0] == x) {ret =i; break;}
}
return ret
}