(async function () {
var tablePerson = $('#personlist').DataTable({
columnDefs: [ {
orderable: false,
className: 'select-checkbox',
targets: 0
} ],
data: await new function(){
return new Promise(resolve=>{
ipcRenderer.send('message', 'ping');
ipcRenderer.on('reply', (event, arg) => {
resolve(arg);
})
})
}
});
}())
class Component {
constructor(name){
this.init();
}
async init(){
const {data} = await this.query();
this.data = data;
}
query(){
return new Promise(function(resolve, reject){
ipcRenderer.send('message', 'ping');
ipcRenderer.on('reply', (event, arg) => {
resolve(arg);
})
})
}
}
let obj = new Component();
console.log(obj.data);
setInterval(function () {
con.query("SELECT * FROM temp WHERE done<>'ok' ORDER BY iin DESC LIMIT 1", function (err, rowsFromTemp) {
if (err) {throw err;}
if (rowsFromTemp.length != 0) {
con.query("SELECT * FROM balance WHERE iin = " + rowsFromTemp[0].iin + " AND pay_type=" + rowsFromTemp[0].pay_type, function (err, rowsFromBalance) {
if (err) throw err;
if (rowsFromBalance.length != 0) {
console.log("match")
var sum = rowsFromBalance[0].sum + rowsFromTemp[0].amount;
console.log("amount: ", rowsFromTemp[0].amount, " sum: ", rowsFromBalance[0].sum, " total: ", sum);
con.query("UPDATE balance SET iin=" + rowsFromTemp[0].iin + ", sum=" + sum + " WHERE iin=" + rowsFromBalance[0].iin, function (err) {
if (err) throw err;
con.query("UPDATE temp SET done='ok' WHERE uniq_id=" + rowsFromTemp[0].uniq_id, function (err) {
if (err) throw err;
});
});
} else {
con.query("INSERT INTO balance (id, iin, pay_type, sum) VALUES ( NULL, '" + rowsFromTemp[0].iin + "', '" + rowsFromTemp[0].pay_type + "', '" + rowsFromTemp[0].amount + "')", function (err, result) {
con.query("UPDATE temp SET done='ok' WHERE uniq_id=" + rowsFromTemp[0].uniq_id, function (err) {
if (err) throw err;
});
});
}
})
}
});
}, 500);