Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
226 lines (200 loc) · 8.88 KB
/
Copy pathindex.html
File metadata and controls
226 lines (200 loc) · 8.88 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<title>DAF607 | Bauhaus Sistemas</title>
<link rel="icon" type="image/x-icon" href="https://i.imgur.com/o6zfZZr.png">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<style>
body::before {
content: "";
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-image: url('https://i.imgur.com/wHLvvt3.jpeg');
background-repeat: no-repeat;
transform: scaleX(-1);
z-index: -1;
}
.container {
background-color: #1d6fbc;
color: white;
border-radius: 5px;
padding: 30px;
margin-top: 40px;
}
.upload-area {
border-radius: 5px;
color: #999e9d;
padding: 30px;
text-align: center;
cursor: pointer;
background-color: #fff;
}
.upload-area.dragover {
background-color: #f1f1f1;
}
.modal {
color: black;
}
footer {
position: fixed;
bottom: 0;
width: 100%;
background-color: #f8f9fa;
padding: 10px 0;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<h4 class="my-4 text-center title">Informe o exercício e envie o arquivo DAF607 (.ret)</h4>
<form id="uploadForm">
<div class="form-group">
<label for="year">Ano:</label>
<input type="text" name="year" id="year" class="form-control" placeholder="Digite o exercício desejado" required>
</div>
<div class="form-group">
<label for="file">Arquivo .ret:</label>
<div class="upload-area" id="uploadArea">
Arraste o arquivo para cá ou clique para selecionar.
</div>
<input type="file" name="file" id="file" class="form-control-file" accept=".ret" style="display: none;" required>
<div id="fileName" class="mt-2"></div>
</div>
<button type="submit" class="btn btn-success">Enviar</button>
</form>
<!-- Modal -->
<div class="modal fade" id="resultModal" tabindex="-1" role="dialog" aria-labelledby="resultModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="resultModalLabel">Arquivos Gerados</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Processamento concluído. Arquivos gerados:</p>
<div class="d-flex justify-content-around">
<a href="#" id="downloadRet" download class="btn btn-success mx-1">Download RET Corrigido</a>
<a href="#" id="downloadTxt" download class="btn btn-success mx-1">Download TXT</a>
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="bg-transparent text-center py-3">
<div class="text-center my-4">
<img src="https://bauhaussistemas.com.br/wp-content/uploads/2022/07/Ativo-1-8.png" alt="Logo" style="max-width: 200px;">
</div>
© 2024 Bauhaus Sistemas. Todos os direitos reservados.
</footer>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
var uploadArea = document.getElementById('uploadArea');
var fileInput = document.getElementById('file');
var fileNameDisplay = document.getElementById('fileName');
var resultModal = new bootstrap.Modal(document.getElementById('resultModal'));
uploadArea.addEventListener('click', function() {
fileInput.click();
});
uploadArea.addEventListener('dragover', function(e) {
e.preventDefault();
e.stopPropagation();
uploadArea.classList.add('dragover');
});
uploadArea.addEventListener('dragleave', function(e) {
e.preventDefault();
e.stopPropagation();
uploadArea.classList.remove('dragover');
});
uploadArea.addEventListener('drop', function(e) {
e.preventDefault();
e.stopPropagation();
uploadArea.classList.remove('dragover');
fileInput.files = e.dataTransfer.files;
displayFileName(fileInput.files[0]);
});
fileInput.addEventListener('change', function() {
displayFileName(this.files[0]);
});
function displayFileName(file) {
fileNameDisplay.textContent = 'Arquivo selecionado: ' + file.name;
}
document.getElementById('uploadForm').addEventListener('submit', function(e) {
e.preventDefault();
var year = document.getElementById('year').value;
var file = fileInput.files[0];
if (!year || !file) {
alert('Por favor, insira o arquivo e o ano.');
return;
}
var reader = new FileReader();
reader.onload = function(e) {
var content = e.target.result;
var lines = content.split('\n');
var outputLines = [];
var txtLines = [];
function formatDate(date) {
return date.slice(6, 8) + '/' + date.slice(4, 6) + '/' + date.slice(0, 4);
}
function formatCNPJ(cnpj) {
return cnpj.slice(0, 2) + '.' + cnpj.slice(2, 5) + '.' + cnpj.slice(5, 8) + '/' + cnpj.slice(8, 12) + '-' + cnpj.slice(12);
}
function formatPeriodo(periodo) {
return periodo.slice(4, 6) + '/' + periodo.slice(0, 4);
}
function formatValor(valor) {
return 'R$ ' + (valor / 100).toFixed(2).replace('.', ',').replace(/\d(?=(\d{3})+\,)/g, '$&.');
}
lines.forEach(function(line, i) {
if (i === 0 || i === lines.length - 1) {
outputLines.push(line);
} else {
var lDataArreca = line.slice(9, 17);
var lDataVencto = line.slice(17, 25);
var lCNPJ = line.slice(74, 88);
var lPeriodo = line.slice(100, 106);
var lValorPrinc = line.slice(106, 123).trim();
var lValorMulta = line.slice(123, 140).trim();
var lValorJuros = line.slice(140, 157).trim();
var anoPeriodo = lPeriodo.slice(0, 4);
if (anoPeriodo <= year) {
outputLines.push(line);
} else {
var formattedLine = "Data Pagamento: " + formatDate(lDataArreca) + "\n";
formattedLine += "Data Vencimento: " + formatDate(lDataVencto) + "\n";
formattedLine += "CNPJ: " + formatCNPJ(lCNPJ) + "\n";
formattedLine += "Periodo: " + formatPeriodo(lPeriodo) + "\n";
formattedLine += "Valor: " + formatValor(lValorPrinc) + "\n";
formattedLine += "Juros: " + formatValor(lValorJuros) + "\n";
formattedLine += "Multa: " + formatValor(lValorMulta) + "\n";
formattedLine += "\n";
txtLines.push(formattedLine);
}
}
});
var outputBlob = new Blob([outputLines.join('\n')], { type: 'text/plain' });
var txtBlob = new Blob([txtLines.join('\n')], { type: 'text/plain' });
var fileNameBase = file.name.split('.').slice(0, -1).join('.'); // Remove a extensão do arquivo original
var outputUrl = URL.createObjectURL(outputBlob);
var txtUrl = URL.createObjectURL(txtBlob);
document.getElementById('downloadRet').href = outputUrl;
document.getElementById('downloadRet').download = fileNameBase + '_corrigido.ret';
document.getElementById('downloadTxt').href = txtUrl;
document.getElementById('downloadTxt').download = fileNameBase + '.txt';
resultModal.show();
};
reader.readAsText(file);
});
});
</script>
</body>
</html>