-
Notifications
You must be signed in to change notification settings - Fork 0
/
root_listbills_ctrl.js
80 lines (76 loc) · 2.67 KB
/
root_listbills_ctrl.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function fillTable(){
$('#list-bills').html("<td><img src='img/load.gif' /></td>");
$.post('root_listbills_model.php',{
'q':$('#query').val(),
'bk':$('#bank-select').val(),
's':$('#sta-select').val(),
'cb_dtini':$('#cb-dtp1').is(":checked"),
'dtini':$('#dtp1').val(),
'cb_dtend':$('#cb-dtp2').is(":checked"),
'dtend':$('#dtp2').val()
}, function(data){
$('#list-bills').empty();
console.log(data);
var table = JSON.parse(data);
var somavb = 0;
var somagb = 0;
for(tr in table){
//somatorio
if(table[tr]['estado'] == "3") somagb += parseFloat(table[tr]['premio'].replace(',','.'));
somavb += parseFloat(table[tr]['valor']);
var trO = document.createElement('tr');
var tdHash = document.createElement('td');
$(tdHash).css('font-family','monospace');
tdHash.innerHTML = hashToHuman(table[tr]['hash']);
var tdApos = document.createElement('td');
tdApos.innerHTML = table[tr]['apostador'];
var tdValor = document.createElement('td');
tdValor.innerHTML = 'R$ ' + table[tr]['valor'];
var tdPrem = document.createElement('td');
tdPrem.innerHTML = 'R$ ' + table[tr]['premio'];
var tdData = document.createElement('td');
var tkDt = table[tr]['data_criado'].split(' ');
var tkD = tkDt[0].split('-');
var tkT = tkDt[1].split(':');
tdData.innerHTML = tkD[2]+'/'+tkD[1]+' '+tkT[0]+':'+tkT[1];
var tdBk = document.createElement('td');
tdBk.innerHTML = table[tr]['user'];
var state = getEstadoByCod(table[tr]['estado']);
if(state == 'Ganhou') $(trO).addClass('success');
$(trO).append(tdHash, tdApos, tdValor, tdPrem, tdData, tdBk)
.attr('data-hash',table[tr]['hash']);
$('#list-bills').append(trO);
}
somabank = somavb*0.10;
$("#inf-total").html(table.length);
$("#inf-valor").html(numberToRealcash(somavb));
$("#inf-gain").html(numberToRealcash(somagb));
$("#inf-bank").html(numberToRealcash(somavb*0.10));
$("#inf-site").html(numberToRealcash(somavb-somabank-somagb));
$('#list-bills tr').click(moreInfo);
});
}
function moreInfo(){
window.open('querybill.php?hash='+$(this).attr('data-hash'),'_blank');
}
function loadUsers(){
$.post('root_listusers_model.php',function(data){
var lista = JSON.parse(data);
for(u in lista){
if(lista[u].tipo == 'bank'){
var opt = document.createElement('option');
$(opt).val(lista[u].user);
$(opt).text(lista[u].name);
$("#bank-select").append(opt);
}
}
});
}
$(function(){
$("#nav-item-consulta").addClass('active');
loadUsers();
$('#dtp1').datetimepicker({format:'YYYY-MM-DD HH:mm:ss'}).val(moment().format('YYYY-MM')+"-01"+" 04:00:00");
$('#dtp2').datetimepicker({format:'YYYY-MM-DD HH:mm:ss'});
fillTable();
$('#bt-filtrar').click(fillTable);
});