-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtorres.html
185 lines (159 loc) · 5.94 KB
/
torres.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Torre de Limites - Simulador</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {
background-color: #f8f9fa;
}
h2 {
text-align: center;
margin-top: 20px;
font-weight: bold;
color: #343a40;
}
.chart-container {
max-width: 800px;
margin: auto;
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.form-container {
max-width: 600px;
margin: auto;
padding: 20px;
background: #ffffff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.history-container {
max-width: 800px;
margin: auto;
margin-top: 30px;
background: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
table {
margin-top: 10px;
}
</style>
</head>
<body>
<h2>Torre de Limites - Simulador</h2>
<!-- Formulário para adicionar compras -->
<div class="form-container">
<div class="mb-3">
<label for="purchase-type" class="form-label">Tipo de Compra:</label>
<select id="purchase-type" class="form-select">
<option value="on-us">ON US</option>
<option value="off-us">OFF US</option>
</select>
</div>
<div class="mb-3">
<label for="purchase-value" class="form-label">Valor da Compra:</label>
<input type="number" id="purchase-value" class="form-control" placeholder="R$" />
</div>
<button class="btn btn-primary w-100" onclick="addPurchase()">Adicionar Compra</button>
</div>
<!-- Gráfico -->
<div class="chart-container mt-4">
<h2 class="text-center">Limite de Crédito</h2>
<canvas id="creditLimitChart"></canvas>
</div>
<!-- Histórico de Alterações -->
<div class="history-container">
<h3 class="text-center">Transações</h3>
<table class="table table-striped table-bordered">
<thead class="table-dark">
<tr>
<th>Tipo de Compra</th>
<th>Valor da Compra</th>
<th>Limite Total</th>
<th>Limite Off Us</th>
</tr>
</thead>
<tbody id="history-table">
<!-- Histórico será preenchido dinamicamente -->
</tbody>
</table>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script>
let totalLimit = 1000;
let limite = 1000;
let remainingLimit = totalLimit;
const ctx = document.getElementById('creditLimitChart').getContext('2d');
const creditLimitChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Limite Off-US', 'Limite On Us'],
datasets: [{
label: 'Limite',
data: [remainingLimit,totalLimit],
backgroundColor: ['rgba(54, 162, 235, 0.6)', 'rgba(255, 99, 132, 0.6)'],
borderColor: ['rgba(54, 162, 235, 1)', 'rgba(255, 99, 132, 1)'],
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true,
ticks: {
stepSize: 100 // Define um espaçamento adequado entre os valores do eixo Y
},
suggestedMax: limite
}
}
}
});
function addPurchase() {
const purchaseType = document.getElementById('purchase-type').value;
const purchaseValue = parseFloat(document.getElementById('purchase-value').value);
if (!purchaseValue || purchaseValue <= 0) {
alert('Por favor, insira um valor válido para a compra.');
return;
}
if (remainingLimit - purchaseValue < 0) {
alert('Limite total excedido! Não é possível realizar a compra.');
return;
}
if (purchaseType === 'on-us') {
remainingLimit -= purchaseValue;
totalLimit -= purchaseValue;
} else if (purchaseType === 'off-us') {
remainingLimit -= (purchaseValue);
totalLimit -= (purchaseValue * 2);
}
// Atualiza os dados do gráfico
creditLimitChart.data.datasets[0].data = [totalLimit, remainingLimit];
// Atualiza a escala do eixo Y
// creditLimitChart.options.scales.y.suggestedMax = Math.max(totalLimit, remainingLimit) + 100;
creditLimitChart.update();
addToHistory(purchaseType, purchaseValue);
}
function addToHistory(type, value) {
const tableBody = document.getElementById('history-table');
const row = document.createElement("tr");
row.innerHTML = `
<td>${type === 'on-us' ? 'ON US' : 'OFF US'}</td>
<td>R$ ${value.toFixed(2)}</td>
<td>R$ ${remainingLimit.toFixed(2)}</td>
<td>R$ ${totalLimit.toFixed(2)}</td>
`;
tableBody.appendChild(row);
}
</script>
</body>
</html>