From be96bf2dd183f300b0fe99a7ad3ec3864fc198d9 Mon Sep 17 00:00:00 2001 From: Hemanoel Date: Thu, 2 May 2024 19:33:27 +0000 Subject: [PATCH] deploy01 --- project/app/preencheFub.py | 16 +- project/app/templates/recibo.html | 41 ++++- project/app/templates/report.html | 44 ++++- project/app/urls.py | 2 +- project/app/views.py | 281 +++++++++++++++--------------- 5 files changed, 228 insertions(+), 156 deletions(-) diff --git a/project/app/preencheFub.py b/project/app/preencheFub.py index 43244a55..48b5c2c5 100644 --- a/project/app/preencheFub.py +++ b/project/app/preencheFub.py @@ -1728,7 +1728,8 @@ def planilhaGeral(planilha,codigo,data1,data2): sheet2.append(linha) #formatar as linhas cinza = "f1f1f1" - variavel_site = f'http://127.0.0.1:2778/' + variavel_site = f'http://automatec.finatec.org.br/' + #variavel_site = f'http://127.0.0.1:2778/' for column in range(ord('A'), ord('Z')+1): column_letter = chr(column) sheet2.column_dimensions[column_letter].width = 25 @@ -1745,13 +1746,13 @@ def planilhaGeral(planilha,codigo,data1,data2): cell.font = Font(name="Arial", size=12, color="000000",bold = True) cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) sheet2.row_dimensions[cell.row].height = 60 - #botão imprime tudo - sheet2['X2'] = f'{variavel_site}download-todos-arquivos/{codigo}_{data1}_{data2}/' - hyperlink_url = f'{variavel_site}download-todos-arquivos/{codigo}_{data1}_{data2}/' - sheet2['X2'].font = Font(name="Arial", size=12, color="0000EE",bold=True) - sheet2['X2'].hyperlink = hyperlink_url + # #botão imprime tudo + # sheet2['X2'] = f'{variavel_site}download-todos-arquivos/{codigo}_{data1}_{data2}/' + # hyperlink_url = f'{variavel_site}download-todos-arquivos/{codigo}_{data1}_{data2}/' + # sheet2['X2'].font = Font(name="Arial", size=12, color="0000EE",bold=True) + # sheet2['X2'].hyperlink = hyperlink_url #printar resultados - for row_num, row_data in enumerate(dfconsultaDadosPorRubrica.itertuples(index=False), start=3):#inicio linha + for row_num, row_data in enumerate(dfconsultaDadosPorRubrica.itertuples(index=False), start=2):#inicio linha for col_num, value in enumerate(row_data, start=1):#inicio coluna value = convert_datetime_to_stringdt(value) if col_num == 24: @@ -1776,6 +1777,7 @@ def planilhaGeral(planilha,codigo,data1,data2): #print(result_string) #print(nota) + # if row_data hyperlink_url = f'{variavel_site}recibos/{value}/' value = hyperlink_url sheet2.cell(row=row_num, column=col_num, value=value).font = Font(name="Arial", size=12, color="0000EE",bold=True) diff --git a/project/app/templates/recibo.html b/project/app/templates/recibo.html index e7f59d32..a0ae941f 100644 --- a/project/app/templates/recibo.html +++ b/project/app/templates/recibo.html @@ -1,9 +1,42 @@ - + - Download PDF + + + Download Falhou + - Download PDF +
+

Download Falhou

+

O download não pôde ser concluído porque o recibo não foi encontrado.

+
- \ No newline at end of file + diff --git a/project/app/templates/report.html b/project/app/templates/report.html index c6461075..ec0c486a 100644 --- a/project/app/templates/report.html +++ b/project/app/templates/report.html @@ -1,12 +1,42 @@ - + - Report + + + Download Falhou + -

Here's your report:

-

Click the link below to open the PDF report:

- View Report (report.pdf) - +
+

Download Falhou

+

O download não pôde ser concluído porque a nota não foi encontrada.

+
- \ No newline at end of file + diff --git a/project/app/urls.py b/project/app/urls.py index c86773c4..670415bf 100755 --- a/project/app/urls.py +++ b/project/app/urls.py @@ -14,7 +14,7 @@ path('perfil/', views.user_profile, name='user_profile'), path('notas//', views.consultaNotas, name='notas'), path('recibos//', views.download_base64_pdf, name='download_base64_pdf'), - path('download-todos-arquivos//', views.download_todos_arquivos, name='download_todos_arquivos'), + #path('download-todos-arquivos//', views.download_todos_arquivos, name='download_todos_arquivos'), # path('base/', views.base2, name='base'),- # path('login_teste/', views.login_teste, name='login_teste'), diff --git a/project/app/views.py b/project/app/views.py index 20cb49ef..5daae9c3 100755 --- a/project/app/views.py +++ b/project/app/views.py @@ -330,6 +330,8 @@ def user_activity_logs(request): + + def consultaNotas(request, filename): ''' CARREGA PAGINA DAS NOTAS FISCAIS @@ -411,7 +413,7 @@ def consultaNotas(request, filename): pdf_data = item[2] #print(f"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{pdf_data}") if not pdf_data: - return HttpResponse(f"NOTA NÃO CONSTA NO CONVENIAR") + return render(request, 'report.html') filename = item[1] # Write PDF data to temporary file @@ -447,11 +449,18 @@ def consultaNotas(request, filename): except Exception as e: # Handle any exceptions #return HttpResponse(f"An error occurred: {str(e)} NOTA NÃO EXISTE") - return HttpResponse(f"NOTA NÃO CONSTA NO CONVENIAR") + return render(request, 'report.html') + + +# def download_base64(request,filename): +# if request.method == 'GET': +# return download_base64_pdf(request,filename) +# else: +# # projects = [projeto['CODIGO'] for projeto in relevant_data] # Obtendo apenas os códigos dos projetos +# return render(request, 'recibo.html') def download_base64_pdf(request, filename): ''' - CARREGA PAGINA DOS RECIBOS ''' @@ -479,153 +488,151 @@ def download_base64_pdf(request, filename): except Exception as e: # Handle any exceptions #return HttpResponse(f"An error occurred: {str(e)} NOTA NÃO EXISTE") - return HttpResponse(f"Recibo não existe") - - - -def download_todos_arquivos(request,filename): - ''' - CARREGA PAGINA DAS NOTAS FISCAIS - ''' - try: - file_path = pegar_pass("passs.txt") - conStr = '' - with open(file_path, 'r') as file: - conStr = file.readline().strip() - conn = pyodbc.connect(conStr) - cursor = conn.cursor() - name, date1, date2 = split_archive_name(filename) + return render(request, 'recibo.html') + +# def download_todos_arquivos(request,filename): +# ''' +# CARREGA PAGINA DAS NOTAS FISCAIS +# ''' +# try: +# file_path = pegar_pass("passs.txt") +# conStr = '' +# with open(file_path, 'r') as file: +# conStr = file.readline().strip() +# conn = pyodbc.connect(conStr) +# cursor = conn.cursor() +# name, date1, date2 = split_archive_name(filename) - listaPedidos = f""" - SELECT - NumDocFinConvenio +# listaPedidos = f""" +# SELECT +# NumDocFinConvenio - FROM [Conveniar].[dbo].[LisLancamentoConvenio] - WHERE [LisLancamentoConvenio].CodConvenio = {name} AND [LisLancamentoConvenio].CodStatus = 27 - AND [LisLancamentoConvenio].DataPagamento BETWEEN '{date1}' AND '{date2}' and [LisLancamentoConvenio].CodRubrica not in (2,0) - order by DataPagamento +# FROM [Conveniar].[dbo].[LisLancamentoConvenio] +# WHERE [LisLancamentoConvenio].CodConvenio = {name} AND [LisLancamentoConvenio].CodStatus = 27 +# AND [LisLancamentoConvenio].DataPagamento BETWEEN '{date1}' AND '{date2}' and [LisLancamentoConvenio].CodRubrica not in (2,0) +# order by DataPagamento - """ - cursor.execute(listaPedidos) +# """ +# cursor.execute(listaPedidos) - #print(listaPedidos) - - NumDocFinConvenios = cursor.fetchall() - merged_pdf_responses = [] - #print(NumDocFinConvenios) - cwd = os.getcwd() - folder_name = "temp_pdfs" - folder_path = os.path.join(cwd, folder_name) - - if not os.path.exists(folder_path): - os.makedirs(folder_path) - print(f"Folder '{folder_name}' created successfully!") - else: - print(f"Folder '{folder_name}' already exists.") - - for Doc in NumDocFinConvenios: - print(type(Doc)) - row_str = str(Doc[0]) - print(row_str) - queryConsult = f""" - SELECT [Pedido].[CodPedido], - [Pedido].[NumPedido], - [ArquivoBinario].[ArquivoBinario], - [Arquivo].[NomeArquivo] - FROM [Conveniar].[dbo].[Pedido] - LEFT JOIN [Conveniar].[dbo].[Arquivo] - ON [Pedido].[CodPedido] = [Arquivo].[CodSolicitacao] - LEFT JOIN [ConveniarArquivo].[dbo].[ArquivoReferencia] - ON [Arquivo].[CodArquivoReferencia] = [ArquivoReferencia].CodArquivoReferencia - LEFT JOIN [ConveniarArquivo].[dbo].[ArquivoBinario] - ON [ArquivoReferencia].ChaveLocalArmazenamento = [ArquivoBinario].[CodArquivoBinario] - WHERE NumPedido = '{row_str}' - - UNION ALL - - SELECT [OPCompraAF].[CodOPCompraAF], - [OPCompraAF].[NumOPCompraAF], - [ArquivoBinario].[ArquivoBinario], - [ArquivoOpCompraAF].[NomeArquivoOpCompraAF] - FROM [Conveniar].[dbo].[OPCompraAF] - LEFT JOIN [Conveniar].[dbo].[ArquivoOpCompraAF] - ON [OPCompraAF].[CodOPCompraAF] = [ArquivoOpCompraAF].[CodOPCompraAF] - LEFT JOIN [ConveniarArquivo].[dbo].[ArquivoReferencia] - ON [ArquivoOpCompraAF].[CodArquivoReferencia] = [ArquivoReferencia].CodArquivoReferencia - LEFT JOIN [ConveniarArquivo].[dbo].[ArquivoBinario] - ON [ArquivoReferencia].ChaveLocalArmazenamento = [ArquivoBinario].[CodArquivoBinario] - WHERE [OPCompraAF].[NumOPCompraAF] = '{row_str}' - - - """ - #print(queryConsult) - cursor.execute(queryConsult) - items = cursor.fetchall() - #print(items) +# #print(listaPedidos) + +# NumDocFinConvenios = cursor.fetchall() +# merged_pdf_responses = [] +# #print(NumDocFinConvenios) +# cwd = os.getcwd() +# folder_name = "temp_pdfs" +# folder_path = os.path.join(cwd, folder_name) + +# if not os.path.exists(folder_path): +# os.makedirs(folder_path) +# print(f"Folder '{folder_name}' created successfully!") +# else: +# print(f"Folder '{folder_name}' already exists.") + +# for Doc in NumDocFinConvenios: +# print(type(Doc)) +# row_str = str(Doc[0]) +# print(row_str) +# queryConsult = f""" +# SELECT [Pedido].[CodPedido], +# [Pedido].[NumPedido], +# [ArquivoBinario].[ArquivoBinario], +# [Arquivo].[NomeArquivo] +# FROM [Conveniar].[dbo].[Pedido] +# LEFT JOIN [Conveniar].[dbo].[Arquivo] +# ON [Pedido].[CodPedido] = [Arquivo].[CodSolicitacao] +# LEFT JOIN [ConveniarArquivo].[dbo].[ArquivoReferencia] +# ON [Arquivo].[CodArquivoReferencia] = [ArquivoReferencia].CodArquivoReferencia +# LEFT JOIN [ConveniarArquivo].[dbo].[ArquivoBinario] +# ON [ArquivoReferencia].ChaveLocalArmazenamento = [ArquivoBinario].[CodArquivoBinario] +# WHERE NumPedido = '{row_str}' + +# UNION ALL + +# SELECT [OPCompraAF].[CodOPCompraAF], +# [OPCompraAF].[NumOPCompraAF], +# [ArquivoBinario].[ArquivoBinario], +# [ArquivoOpCompraAF].[NomeArquivoOpCompraAF] +# FROM [Conveniar].[dbo].[OPCompraAF] +# LEFT JOIN [Conveniar].[dbo].[ArquivoOpCompraAF] +# ON [OPCompraAF].[CodOPCompraAF] = [ArquivoOpCompraAF].[CodOPCompraAF] +# LEFT JOIN [ConveniarArquivo].[dbo].[ArquivoReferencia] +# ON [ArquivoOpCompraAF].[CodArquivoReferencia] = [ArquivoReferencia].CodArquivoReferencia +# LEFT JOIN [ConveniarArquivo].[dbo].[ArquivoBinario] +# ON [ArquivoReferencia].ChaveLocalArmazenamento = [ArquivoBinario].[CodArquivoBinario] +# WHERE [OPCompraAF].[NumOPCompraAF] = '{row_str}' + + +# """ +# #print(queryConsult) +# cursor.execute(queryConsult) +# items = cursor.fetchall() +# #print(items) - pdf_files = [] - # Merge individual PDFs into one - merger = PdfMerger() - count = 0 - conta = 0 - for item in items: - filename = item[1] - pdf_data = item[2] - #print(f"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{pdf_data}") - if not pdf_data: +# pdf_files = [] +# # Merge individual PDFs into one +# merger = PdfMerger() +# count = 0 +# conta = 0 +# for item in items: +# filename = item[1] +# pdf_data = item[2] +# #print(f"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{pdf_data}") +# if not pdf_data: - nota = acharRecibo("selenabot","finatec@300424",filename) - #print(nota) - string_with_substring = nota - substring_to_remove = "data:application/pdf;base64," - # Remove the substring - result_string = string_with_substring.replace(substring_to_remove, "") - - pdf_content = base64.b64decode(result_string) - pdf_path = os.path.join(folder_name, f'{filename}{conta}.pdf') - print(pdf_path) - with open(pdf_path, 'wb') as pdf_file: - pdf_file.write(pdf_content) +# nota = acharRecibo("selenabot","finatec@300424",filename) +# #print(nota) +# string_with_substring = nota +# substring_to_remove = "data:application/pdf;base64," +# # Remove the substring +# result_string = string_with_substring.replace(substring_to_remove, "") + +# pdf_content = base64.b64decode(result_string) +# pdf_path = os.path.join(folder_name, f'{filename}{conta}.pdf') +# print(pdf_path) +# with open(pdf_path, 'wb') as pdf_file: +# pdf_file.write(pdf_content) - else: - # Write PDF data to temporary file - pdf_path = os.path.join(folder_name, f'{filename}{count}.pdf') - print(pdf_path) - with open(pdf_path, 'wb') as pdf_file: - pdf_file.write(pdf_data) - - # Add PDF to merger +# else: +# # Write PDF data to temporary file +# pdf_path = os.path.join(folder_name, f'{filename}{count}.pdf') +# print(pdf_path) +# with open(pdf_path, 'wb') as pdf_file: +# pdf_file.write(pdf_data) + +# # Add PDF to merger - # Create a temporary file path for the zip file - zip_file_path = os.path.join(cwd, 'temp_pdfs.zip') - - # Create a zip file - with zipfile.ZipFile(zip_file_path, 'w') as zipf: - for root, dirs, files in os.walk(folder_path): - for file in files: - file_path = os.path.join(root, file) - zipf.write(file_path, os.path.relpath(file_path, folder_path)) - - # Open the zip file - with open(zip_file_path, 'rb') as f: - response = HttpResponse(f.read(), content_type='application/zip') - response['Content-Disposition'] = f'attachment; filename={name}_{date1}_{date2}.zip' - - # Clean up: remove the temporary zip file - os.remove(zip_file_path) - if os.path.exists(folder_path): - # Delete the folder and its contents - shutil.rmtree(folder_path) - print(f"The folder '{folder_name}' has been successfully deleted.") - else: - print(f"The folder '{folder_name}' does not exist.") - return response +# # Create a temporary file path for the zip file +# zip_file_path = os.path.join(cwd, 'temp_pdfs.zip') + +# # Create a zip file +# with zipfile.ZipFile(zip_file_path, 'w') as zipf: +# for root, dirs, files in os.walk(folder_path): +# for file in files: +# file_path = os.path.join(root, file) +# zipf.write(file_path, os.path.relpath(file_path, folder_path)) + +# # Open the zip file +# with open(zip_file_path, 'rb') as f: +# response = HttpResponse(f.read(), content_type='application/zip') +# response['Content-Disposition'] = f'attachment; filename={name}_{date1}_{date2}.zip' + +# # Clean up: remove the temporary zip file +# os.remove(zip_file_path) +# if os.path.exists(folder_path): +# # Delete the folder and its contents +# shutil.rmtree(folder_path) +# print(f"The folder '{folder_name}' has been successfully deleted.") +# else: +# print(f"The folder '{folder_name}' does not exist.") +# return response - except Exception as e: +# except Exception as e: # Handle any exceptions return HttpResponse(f"An error occurred: {str(e)}") \ No newline at end of file