/
ModuloRetornoVisualiza.php
319 lines (239 loc) · 9.7 KB
/
ModuloRetornoVisualiza.php
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
###########
## Módulo para visualizar os dados dos boletos vindos do arquivo de retorno
## Criado: 20/01/2011 - Maycon Edinger
## Alterado:
## Alterações:
###########
//Seta o header do retorno para efetuar a acentuação correta usando o AJAX
if ($_GET["headers"] == 1)
{
header("Content-Type: text/html; charset=ISO-8859-1",true);
}
//Estabelece a conexão com o banco de dados
include "./conexao/ConexaoMySQL.php";
//Inclui o arquivo para manipulação de datas
include "./include/ManipulaDatas.php";
//Inclui o arquivo para manipulação de valor monetário
include './include/ManipulaMoney.php';
$dataProcessa = $_POST["edtDataProcessa"];
?>
<link rel="stylesheet" type="text/css" href="include/workStyle.css">
<form name="frmRetorno" action="sistema.php?ModuloNome=ModuloRetornoProcessa" method="post">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width='440'>
<img src="image/lat_cadastro.gif" /> <span class="TituloModulo">Processamento de Arquivos de Retorno</span>
</td>
</tr>
<tr>
<td>
<img src="image/bt_espacohoriz.gif" width="100%" height="12">
</td>
</tr>
</table>
<?php
function ParseFloat($floatString)
{
$LocaleInfo = localeconv();
$floatString = str_replace("." , "", $floatString);
$floatString = str_replace("," , ".", $floatString);
return floatval($floatString);
}
//Recupera os valores vindos do formulário e armazena nas variaveis
if($_POST["Submit"])
{
//Caso tiver um nome de arquivo, armazena numa variável
$arq = $_FILES['edtAnexo']['name'];
//Caso nao tenha sido informado um arquivo a processar
if(!$arq)
exit("<b><span style='color: #990000'>É necessário selecionar um arquivo de retorno para processar !</span></b><br/><br/><input class='button' value='Voltar' type='button' name='btVoltar' onclick='wdCarregarFormulario(\"ModuloRetorno.php\",\"conteudo\")' style='width: 100px' />");
$arquivo = $_FILES["edtAnexo"];
//Diretório onde a imagem será salva
$pasta = "documentos/". $arq;
//Faz o upload da imagem
move_uploaded_file($arquivo["tmp_name"], $pasta);
//tenta abrir o arquivo de retorno do banco
if(!$arrArquivo = file($pasta, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES))
exit("Não foi possível abrir o arquivo de retorno do banco!<br/><input class='button' value='Voltar' type='button' name='btVoltar' onclick='wdCarregarFormulario(\"ModuloRetorno.php\",\"conteudo\")' style='width: 100px' />");
//linha atual
$i = 0;
$linha = 1;
?>
<table width='100%' cellpadding='0' cellspacing='0' border='0'>
<tr>
<td>
<input name="Submit" type="submit" class="button" title="Processa o retorno" value="Processar Retorno" />
<br/>
<br/>
</td>
</tr>
<tr>
<td>
<span style='font-size: 12px'>Confira atentamente os valores dos boletos listados. Após a conferência, clique em [Processar Boletos].</span><br/>
</td>
</tr>
</table>
<br/>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<table width="100%" id="4" cellpadding="0" cellspacing="0" border="0" class="listView">
<tr height="20">
<td width="40" class="listViewThS1">
<div align="center">Proc.</div>
</td>
<td width="110" class="listViewThS1">
Nro do Boleto
</td>
<td class="listViewThS1">
Sacado
</td>
<td width="90" align="right" class="listViewThS1" style="padding-right: 4px">
Valor Original
</td>
<td width="90" align="center" class="listViewThS1" style="padding-right: 4px">
Valor Retorno
</td>
</tr>
<?php
//retira de um vez as quebras de linhas, retorno de carros e linhas vazias
foreach($arrArquivo as &$linhas)
{
//retira \r
$linhas = str_replace(chr(13), "", $linhas);
//retira \n
$linhas = str_replace(chr(10), "", $linhas);
//apaga as linhas vazias
if(empty($linhas)) unset($arrArquivo[$i]);
//proxima linha
$i++;
if ($linha > 9)
{
$comeco = substr($linhas, 3, 5);
//Veririfica se a linha é um boleto
if ($comeco == "15209")
{
//Monta a string do boleto
$numero_boleto = substr($linhas, 3, 17);
//Monta a string do valor
$valor_float = substr($linhas, 95, 11);
//Converte a string para um decimal
$valor_boleto = number_format(ParseFloat($valor_float), 2,",",".");
//Monta a string do valor dos juros
$valor_juros_float = substr($linhas, 115, 10);
//Converte a string para um decimal
$valor_juros_boleto = number_format(ParseFloat($valor_juros_float), 2,",",".");
//echo $valor_boleto . "<br/>";
//echo $valor_juros_boleto . "<br/>";
$valor_retorno = number_format(ParseFloat($valor_float) + ParseFloat($valor_juros_float), 2,",",".");
$valor_retorno_compara = number_format(ParseFloat($valor_float) + ParseFloat($valor_juros_float), 2,".","");
$total_retorno = $total_retorno + $valor_retorno_compara;
//Busca no banco de dados se existe o boleto
//Monta a query para pegar os dados
$sql_cli = "SELECT * FROM boleto WHERE nosso_numero = '$numero_boleto'";
//Executa a query
$query_cli = mysql_query($sql_cli);
//Conta o numero de registros da query
$registros_cli = mysql_num_rows($query_cli);
//Caso não houver registros
if ($registros_cli == 0)
{
$sacado = "<span style='color: #990000'><b>BOLETO NÃO ENCONTRADO !!!</b></span>";
$cor_celula = "#F0D9D9";
$marca_boleto = '';
$desativa_chk = "disabled='disabled'";
$valor_sacado = "R$ 0,00";
}
else
{
$msg_registros = '';
if ($registros_cli > 1)
{
$msg_registros = "<br/>Existem $registros_cli boletos com a mesma numeração. VERIFICAR...";
}
$marca_boleto = "checked='checked'";
$desativa_chk = '';
//efetua o loop na pesquisa
while ($dados_rec = mysql_fetch_array($query_cli))
{
$sacado = "<span style='color: #990000'><b>$dados_rec[sacado]</b></span>" . $msg_registros;
$valor_boleto_bd = $dados_rec["valor_boleto"];
$total_boleto_bd = $total_boleto_bd + $valor_boleto_bd;
$valor_sacado = "R$ " . number_format($dados_rec["valor_boleto"], 2, ",", ".");
$desc_situacao = $valor_boleto_bd . "<br/>" . $valor_retorno_compara;
//Verifica se o valor do boleto no banco é igual ao valor do boleto do retorno
if ($valor_boleto_bd == $valor_retorno_compara)
{
//Caso for igual, marca como verde
$cor_celula = "#FFFFFF";
}
else
{
//Caso for igual, marca como amarelo para atencao
$cor_celula = "#FFFFCD";
}
}
}
?>
<tr height="24">
<td valign="middle" bgcolor="<?php echo $cor_celula ?>" align="center" style="border-bottom: 1px dashed;">
<input name="<?php echo ++$edtItemChk ?>" value="<?php echo $numero_boleto ?>" type="checkbox" <?php echo $desativa_chk ?> style="border: 0px" title="Clique para marcar ou desmarcar a compensação deste boleto" <?php echo $marca_boleto ?> />
</td>
<td valign="middle" bgcolor="<?php echo $cor_celula ?>" class="oddListRowS1" style="border-bottom: 1px dashed;">
<b><span style="color: #6666CC"><?php echo substr($numero_boleto, 0,7) ?></span><span style="color: #990000"><?php echo substr($numero_boleto, 7,3) ?></span><span style="color: #59AA08"><?php echo substr($numero_boleto, 10,5) ?></span><?php echo substr($numero_boleto, 15,2) ?></b>
</td>
<td valign="middle" bgcolor="<?php echo $cor_celula ?>" class="currentTabList" style="border-bottom: 1px dashed;">
<?php echo $sacado ?>
</td>
<td align="right" bgcolor="<?php echo $cor_celula ?>" bgcolor="#fdfdfd" class="currentTabList" style="border-left: 1px dashed; border-bottom: 1px dashed; padding-right: 4px">
<?php echo $valor_sacado ?>
</td>
<td align="center" bgcolor="<?php echo $cor_celula ?>" valign="middle" class="currentTabList" style="border-left: 1px dashed; border-bottom: 1px dashed; padding-right: 4px">
<?php
//Cria um objeto do tipo WDEdit
$objWDComponente = new WDEditReal();
//Define nome do componente
$objWDComponente->strNome = "edtValor$edtItemChk";
//Define o tamanho do componente
$objWDComponente->intSize = 10;
//Busca valor definido no XML para o componente
$objWDComponente->strValor = $valor_retorno;
//Busca a descrição do XML para o componente
$objWDComponente->strLabel = "";
//Determina um ou mais eventos para o componente
$objWDComponente->strEvento = "";
//Define numero de caracteres no componente
$objWDComponente->intMaxLength = 10;
//Cria o componente edit
$objWDComponente->Criar();
?>
</td>
</tr>
<?php
}
}
//Pula a linha no txt
$linha++;
}
?>
<tr>
<td height="24" colspan="3" align="right">
<b>TOTAL: </b>
</td>
<td align="right" style="border-left: 1px dashed; padding-right: 4px">
<?php echo "R$ " . number_format($total_boleto_bd,2,",",".") ?>
</td>
<td align="right" style="border-left: 1px dashed; padding-right: 4px">
<?php echo "R$ " . number_format($total_retorno,2,",",".") ?>
</td>
</tr>
<?php
echo "</table></td></tr></table></td></tr></table>";
}
?>
<input name="edtTotalChk" type="hidden" value="<?php echo $edtItemChk ?>" />
</form>