diff --git a/imagemFap/fapdf.png b/imagemFap/fapdf.png new file mode 100644 index 00000000..00fb89de Binary files /dev/null and b/imagemFap/fapdf.png differ diff --git a/imagemFinep/Finep.png b/imagemFinep/Finep.png new file mode 100644 index 00000000..30f2dabc Binary files /dev/null and b/imagemFinep/Finep.png differ diff --git a/planilhas/ModeloFAP.xlsx b/planilhas/ModeloFAP.xlsx deleted file mode 100755 index 1de9600a..00000000 Binary files a/planilhas/ModeloFAP.xlsx and /dev/null differ diff --git a/planilhas/ModeloFINEP.xlsx b/planilhas/ModeloFINEP.xlsx deleted file mode 100644 index fa19bf15..00000000 Binary files a/planilhas/ModeloFINEP.xlsx and /dev/null differ diff --git a/planilhas/ModeloOPAS.xlsx b/planilhas/ModeloOPAS.xlsx deleted file mode 100755 index 89b22070..00000000 Binary files a/planilhas/ModeloOPAS.xlsx and /dev/null differ diff --git a/planilhas/Modelo_Fub.xlsx b/planilhas/Modelo_Fub.xlsx index fa19bf15..918a3c3d 100644 Binary files a/planilhas/Modelo_Fub.xlsx and b/planilhas/Modelo_Fub.xlsx differ diff --git a/planilhas/modeloFap.xlsx b/planilhas/modeloFap.xlsx new file mode 100644 index 00000000..194798fb Binary files /dev/null and b/planilhas/modeloFap.xlsx differ diff --git a/planilhas/modeloFinep.xlsx b/planilhas/modeloFinep.xlsx new file mode 100644 index 00000000..345931ae Binary files /dev/null and b/planilhas/modeloFinep.xlsx differ diff --git a/project/app/capa.py b/project/app/capaFub.py similarity index 99% rename from project/app/capa.py rename to project/app/capaFub.py index 3dc0d401..5f437101 100755 --- a/project/app/capa.py +++ b/project/app/capaFub.py @@ -314,7 +314,7 @@ def inserir_round_retangulo(planilha,data1,data2,dicionariofin): worksheet.add_image(images[16], "B34")#gerengte worksheet.merge_cells('B34:D36') - worksheet['B34'] = 'COORDENADORA DE GESTÃO DE PROJETOS' + worksheet['B34'] = 'GERENTE DE PROJETOS' worksheet['B34'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) worksheet['B34'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True,shrink_to_fit=True ) worksheet.add_image(images[17], "E34")#gerente diff --git a/project/app/capaGeral.py b/project/app/capaGeral.py new file mode 100644 index 00000000..cb3a54da --- /dev/null +++ b/project/app/capaGeral.py @@ -0,0 +1,332 @@ +import openpyxl +from openpyxl.styles import Font, PatternFill, Alignment,NamedStyle +from openpyxl.drawing.image import Image +from PIL import Image as PILImage +import os + + + + +def pegar_caminho(nome_arquivo): + + # Obter o caminho absoluto do arquivo Python em execução + caminho_script = os.path.abspath(__file__) + + # Obter o diretório da pasta onde o script está localizado + pasta_script = os.path.dirname(caminho_script) + + # Combinar o caminho da pasta com o nome do arquivo Excel + caminho = os.path.join(pasta_script, nome_arquivo) + + return caminho + +def preenche_planilha(planilha, dicionario): + + caminho = pegar_caminho(planilha) + Plan = planilha + # carrega a planilha de acordo com o caminho + workbook = openpyxl.load_workbook(caminho) + + # planilha_preenchida = pegar_caminho('preenchido-' + planilha) + for nomePlanilha, entradaDados in dicionario.items(): + planilhaAtual = workbook[nomePlanilha] + + for intervaloCelula, entradaCelula in entradaDados: + if ":" in intervaloCelula: + inicioCelula, fimCelula = intervaloCelula.split(":") + planilhaAtual = workbook[nomePlanilha] + planilhaAtual[inicioCelula] = entradaCelula + # planilhaAtual[inicioCelula].fill = color <--- teste com cores + else: + planilhaAtual[intervaloCelula] = entradaCelula + # planilhaAtual[intervaloCelula].fill = color <--- teste com cores + + + workbook.save(planilha) + + return planilha + + +def inserir_round_retanguloGeral(planilha,data1,data2,dicionariofin): + + + + + # id_mapeamento + # codigo + # nome + # saldo + # data_assinatura + # data_vigencia + # data_encerramento + # tipo_contrato + # instituicao_executora + # processo + # subprocesso + # cod_proposta + # proposta + # objetivos + # valor_aprovado + # nome_tp_controle_saldo + # grupo_gestores + # gestor_resp + # coordenador + # procedimento_compra + # tab_frete + # tab_diarias + # custo_op + # nome_financiador + # departamento + # situacao + # banco + # agencia_bancaria + # conta_bancaria + # centro_custo + # conta_caixa + # categoria_projeto + # cod_convenio_conta + # cod_status + # ind_sub_projeto + # tipo_custo_op + # projeto_mae + # id_coordenador + # id_financiador + # id_instituicao + # id_departamento + # nome_instituicao + # id_instituicao_executora + # id_tipo + + planilha_local_dados = { + "Capa Finatec":[ + ("E6",'NomePessoaFinanciador'), + ("E9",'NomeConvenio'), + ("E14",'NomePessoaResponsavel'), + ("E17",'SubProcesso'), + ("E19",'CodConvenio'), + ("K17",'NomeBanco'), + ("K19",'Conta'), + ("K21",'Agencia') + + ] + } + + # Create an empty dictionary to store the values from the second dictionary + result_dict = {} + + # Loop pra criar no formato dicionarario por exemplo + # Capa Finatec : [(E3:COORDENADOR)] + for key, value in planilha_local_dados["Capa Finatec"]: + if value in dicionariofin: + result_dict[key] = dicionariofin[value] + print(result_dict) + list_of_tuples = [(key, value) for key, value in result_dict.items()] + + novo_dict = {"Capa Finatec":list_of_tuples} + + preenche_planilha(planilha, novo_dict) + + caminho = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(caminho) + worksheet = workbook['Capa Finatec'] + + + + # List of image names + image_names = [ + 'agencia.png',#0 + 'agencia_branco.png',#1 + 'agente.png',#2 + 'agente_branco.png',#3 + 'analista.png',#4 + 'analista_branco.png',#5 + 'assinaturas_responsaveis.png',#6 + 'assistente.png',#7 + 'assistente_branco.png',#8 + 'banco.png',#9 + 'banco_branco.png',#10 + 'conta_corrente.png',#11 + 'conta_corrente_branco.png',#12 + 'coordenador.png',#13 + 'coordenador_branco.png',#14 + 'dadosdoacordo.png',#15 + 'gerente.png',#16 + 'gerente_branco.png',#17 + 'periodo.png',#18 + 'periodo_branco.png',#19 + 'prestacaodecontaparcial.png',#20 + 'processo.png',#21 + 'processo_branco.png',#22 + 'projeto.png',#23 + 'projeto_branco.png',#24, + 'centrodecusto.png',#25, + 'centrodecusto_branco.png' + ] + + + + # List to hold Image objects + images = [] + + nomePasta = "../../imagensCapa" + diretorio = os.path.dirname(__file__) + + # Loop through the list of image names and create Image objects + for i, name in enumerate(image_names): + caminhoImage = os.path.join(diretorio, nomePasta, name) + pil_image = PILImage.open(caminhoImage) + pil_image.save(caminhoImage) + img = Image(caminhoImage) + images.append(img) + + + #daqui pra cima testado + + #estilo imagem + worksheet.add_image(images[20], "B2")#prestação + worksheet.merge_cells('B2:L2') + worksheet['B2'] = 'PRESTAÇÃO DE CONTAS PARCIAL' + worksheet['B2'].font = Font(name="Tahoma", size=17, color="204c80",bold=True) + worksheet['B2'].alignment = Alignment(horizontal="center",vertical="center") + + worksheet.add_image(images[15], "B4")#dados do acordo + worksheet.merge_cells('B4:L4') + worksheet['B4'] = 'DADOS DO ACORDO' + worksheet['B4'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['B4'].alignment = Alignment(horizontal="center",vertical="center") + + worksheet.add_image(images[2], "B6")#agente + worksheet.merge_cells('B6:D7') + worksheet['B6'] = 'AGENTE FINANCIADOR' + worksheet['B6'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['B6'].alignment = Alignment(horizontal="justify",vertical="center",wrap_text=True) + worksheet.add_image(images[3], "E6") + worksheet.merge_cells('E6:M7') + worksheet['E6'].font = Font(name="Tahoma", size=9, color="204c80",bold=False) + worksheet['E6'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + worksheet.add_image(images[23], "B9")#projeto + worksheet.merge_cells('B9:D13') + worksheet['B9'] = 'PROJETO' + worksheet['B9'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['B9'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.add_image(images[24], "E9") + worksheet.merge_cells('E9:M13') + worksheet['E9'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['E9'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + worksheet.add_image(images[13], "B14")#coordenador + worksheet.merge_cells('B14:D15') + worksheet['B14'] = 'COORDENADOR' + worksheet['B14'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['B14'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.add_image(images[14], "E14") + worksheet.merge_cells('E14:M15') + worksheet['E14'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['E14'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + worksheet.add_image(images[21], "B17")#processo + worksheet.merge_cells('B17:D18') + worksheet['B17'] = 'CONVÊNIO' + worksheet['B17'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['B17'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.add_image(images[22], "E17") + worksheet.merge_cells('E17:G18') + worksheet['E17'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['E17'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + worksheet.add_image(images[9], "H17")#Banco + worksheet.merge_cells('H17:J18') + worksheet['H17'] = 'BANCO' + worksheet['H17'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['H17'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.add_image(images[10], "K17") + worksheet.merge_cells('K17:M18') + worksheet['K17'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['K17'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + worksheet.add_image(images[11], "H19")#CoOtaCorreOte + worksheet.merge_cells('H19:J20') + worksheet['H19'] = 'CONTA CORRENTE' + worksheet['H19'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['H19'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.add_image(images[12], "K19") + worksheet.merge_cells('K19:M20') + worksheet['K19'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['K19'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + worksheet.add_image(images[0], "H21")#Agencia + worksheet.merge_cells('H21:J22') + worksheet['H21'] = 'AGÊNCIA' + worksheet['H21'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['H21'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.add_image(images[1], "K21") + worksheet.merge_cells('K21:M22') + worksheet['K21'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['K21'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #testado + + worksheet.add_image(images[25], "B19")#Centro de custo + worksheet.merge_cells('B19:D20') + worksheet['B19'] = 'CENTRO DE CUSTO' + worksheet['B19'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['B19'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.add_image(images[26], "E19")#Centro de custo + worksheet.merge_cells('E19:G20') + worksheet['E19'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['E19'].alignment = Alignment(horizontal="center",vertical="center") + + + worksheet.add_image(images[18], "B21")#Periodo + worksheet.merge_cells('B21:D22') + worksheet['B21'] = 'PERIODO' + worksheet['B21'].font = Font(name="Tahoma", size=9, color="204c80",bold=True) + worksheet['B21'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.add_image(images[19], "E21")#Periodo + worksheet.merge_cells('E21:G22') + worksheet['E21'] = f"{(data1)} a {(data2)}" + worksheet['E21'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['E21'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #testado + + + worksheet.add_image(images[7], "B30")#Assistente + worksheet.merge_cells('B30:D32') + worksheet['B30'] = 'ASSISTENTE' + worksheet['B30'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['B30'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.add_image(images[8], "E30")#Assistente + worksheet['E30'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['E30'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.add_image(images[4], "B26")#Analista + worksheet.merge_cells('B26:D28') + worksheet['B26'] = 'ANALISTA' + worksheet['B26'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['B26'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.add_image(images[5], "E26")#Analista + worksheet.merge_cells('E26:M28') + worksheet['E26'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['E26'].alignment = Alignment(horizontal="center",vertical="center") + + worksheet.add_image(images[16], "B34")#gerengte + worksheet.merge_cells('B34:D36') + worksheet['B34'] = 'GERENTE DE PROJETOS' + worksheet['B34'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['B34'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True,shrink_to_fit=True ) + worksheet.add_image(images[17], "E34")#gerente + worksheet['E34'].font = Font(name="Tahoma", size=10, color="204c80",bold=False) + worksheet['E34'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.add_image(images[6], "B23")#ASSINATURAS + worksheet.merge_cells('B23:M24') + worksheet['B23'] = 'ASSINATURAS - RESPONSAVEIS PELA PRESTAÇÃO DE CONTAS' + worksheet['B23'].font = Font(name="Tahoma", size=10, color="204c80",bold=True) + worksheet['B23'].alignment = Alignment(horizontal="center",vertical="center") + + # Save the workbook + workbook.save(planilha) + workbook.close() \ No newline at end of file diff --git a/project/app/estiloFINEP.py b/project/app/estiloFINEP.py old mode 100755 new mode 100644 index 9d2dbb58..486b82d7 --- a/project/app/estiloFINEP.py +++ b/project/app/estiloFINEP.py @@ -1,20 +1,10 @@ import openpyxl from openpyxl.styles import Font, PatternFill, Alignment,NamedStyle,Border, Side +from openpyxl.utils import get_column_letter +from openpyxl.drawing.image import Image +from PIL import Image as PILImage import os import random -#pegar o caminho do arquivo -# def pegar_caminho(nome_arquivo): - -# # Obter o caminho absoluto do arquivo Python em execução -# caminho_script = os.path.abspath(__file__) - -# # Obter o diretório da pasta onde o script está localizado -# pasta_script = os.path.dirname(caminho_script) - -# # Combinar o caminho da pasta com o nome do arquivo Excel -# caminho = os.path.join(pasta_script, nome_arquivo) - -# return caminho def pegar_caminho(subdiretorio): # Obtém o caminho do script atual @@ -34,7 +24,7 @@ def pegar_caminho(subdiretorio): return caminho_pipeline -def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): +def estiloRelatorioExecFinanceiroA1(tabela,tamanho,stringTamanho): '''Estilo da Pagina do Relatorio Execução da Receita e Despesa Argumentos: @@ -45,346 +35,360 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): ''' - + + if tamanho == 0: + tamanho = 1 + #Carrregar o arquivo da tabela, e inicia a worksheet com o nome da sheet "Relatório de Exec Financ A.1" caminho = pegar_caminho(tabela) workbook = openpyxl.load_workbook(caminho) - sheet = workbook['Exec. Receita e Despesa'] + sheet = workbook['Relatório de Exec Financ A.1'] - size = tamanho + 16; + #tamanho recebido para alocar o tamanho das linha que e correspondetente ao que vai ser preenchido da consulta do database mais o tamanho do cabecario que e 16 e cores + size = tamanho + 12 size2 = size + 1 - cinza = "f1f1f1" - azul_claro = '1c8cbc' - # sheet.row_dimensions[3] = 28 + + azul = 'ccffff' + cinza = 'bebebf' + + #remover as gridlines + sheet.sheet_view.showGridLines = False - #cabecario - sheet.merge_cells('A1:I2') - sheet['A1'] = f'E X E C U Ç Ã O D A R E C E I T A E D E S P E S A ' - sheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + #cabecario RELATÓRIO DE EXECUÇÃO FINANCEIRA + sheet.merge_cells('A1:I1') + sheet['A1'] = f'ANEXO 1' + sheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) sheet['A1'].alignment = Alignment(horizontal="center",vertical="center") - sheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - sheet.merge_cells('A3:F3') - sheet['A3'] = "='Receita x Despesa'!A3:I3" - sheet['A3'].font = Font(name="Arial", size=12, color="000000") - sheet['A3'].alignment = Alignment(horizontal="left",vertical="center") - - sheet.merge_cells('A4:F4') - sheet['A4'] = "='Receita x Despesa'!A4:I4" - sheet['A4'].font = Font(name="Arial", size=12, color="000000") - sheet['A4'].alignment = Alignment(horizontal="left",vertical="center") - - sheet.merge_cells('A5:F5') - sheet['A5'] = "='Receita x Despesa'!A5:I5" - sheet['A5'].font = Font(name="Arial", size=12, color="000000") - sheet['A5'].alignment = Alignment(horizontal="left",vertical="center") - - sheet.merge_cells('A6:F6') - sheet['A6'] = "='Receita x Despesa'!A6:I6" - sheet['A6'].font = Font(name="Arial", size=12, color="000000") - sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") - - sheet.merge_cells('A7:F7') - sheet['A7'] = "='Receita x Despesa'!A7:I7" - sheet['A7'].font = Font(name="Arial", size=12, color="000000") - sheet['A7'].alignment = Alignment(horizontal="left",vertical="center") - - sheet.merge_cells('A9:I10') - sheet['A9'] = 'E X E C U Ç Ã O D A R E C E I T A E D E S P E S A' - sheet['A9'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - sheet['A9'].alignment = Alignment(horizontal="center",vertical="center") - sheet['A9'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - #aumentao altura - for i in range(1,10): - sheet.row_dimensions[i].height = 20 - - sheet.row_dimensions[1].height = 25 - sheet.row_dimensions[3].height = 35 - sheet.row_dimensions[2].height = 25 - sheet.row_dimensions[9].height = 30 - - - - #esticando coluna A e pintando ela - sheet.merge_cells('A12:A13') - sheet['A12'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - sheet.column_dimensions['a'].width = 55 - sheet.column_dimensions['b'].width = 20 - sheet.column_dimensions['c'].width = 20 - sheet.column_dimensions['d'].width = 20 - sheet.column_dimensions['e'].width = 20 - sheet.column_dimensions['f'].width = 20 - sheet.column_dimensions['g'].width = 20 - sheet.column_dimensions['h'].width = 20 - sheet.column_dimensions['i'].width = 20 - sheet.column_dimensions['j'].width = 1 - #resto do cabecario - sheet.merge_cells('B12:E13') - sheet['B12'] = 'EXECUTADO NO PERÍODO\n(Valores em R$)' - sheet['B12'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - sheet['B12'].alignment = Alignment(horizontal="center",vertical="center") - sheet['B12'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - sheet.merge_cells('F12:I13') - sheet['F12'] = 'ACUMULADO ATÉ O PERÍODO\n(Valores em R$)' - sheet['F12'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - sheet['F12'].alignment = Alignment(horizontal="center",vertical="center") - sheet['F12'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - - #totais - #total espesas correntes linha 15 - - formula = f"=SUM(B16:B{size})" - sheet['B15'] = formula - formula = f"=SUM(C16:C{size})" - sheet['C15'] = formula - formula = f"=SUM(D16:D{size})" - sheet['D15'] = formula - - formula = f"=SUM(F16:F{size})" - sheet['F15'] = formula - formula = f"=SUM(G16:G{size})" - sheet['G15'] = formula - formula = f"=SUM(H16:H{size})" - sheet['H15'] = formula - - #Total Despesas de Capital - formula = f"=SUM(B{size2+2}:B{size2+4})" - sheet[f'B{size2}'] = formula - - formula = f"=SUM(C{size2+2}:C{size2+4})" - sheet[f'C{size2}'] = formula - - formula = f"=SUM(D{size2+2}:D{size2+4})" - sheet[f'D{size2}'] = formula - - formula = f"=SUM(F{size2+2}:F{size2+4})" - sheet[f'F{size2}'] = formula - - formula = f"=SUM(G{size2+2}:G{size2+4})" - sheet[f'G{size2}'] = formula - - formula = f"=SUM(H{size2+2}:H{size2+4})" - sheet[f'H{size2}'] = formula - - - #Total Utilização de rendimentos - - formula = f"=B{size2+6}" - sheet[f'B{size2+5}'] = formula - - formula = f"=C{size2+6}" - sheet[f'C{size2+5}'] = formula - - formula = f"=D{size2+6}" - sheet[f'D{size2+5}'] = formula - - formula = f"=F{size2+6}" - sheet[f'F{size2+5}'] = formula - - formula = f"=G{size2+6})" - sheet[f'G{size2+5}'] = formula - - formula = f"=H{size2+6}" - sheet[f'H{size2+5}'] = formula - - - - - #%porcentagem Despesas correntes - #IFERROR (C16/B16;0) - #%porcentagem Despesas de Capital - #IFERROR (C16/B16;0) - percentage_style = NamedStyle(name='percentage', number_format='0%') - #SALDAO - for row in sheet.iter_rows(min_row=15, max_row=size2+7, min_col=1, max_col=9): - for cell in row: - if cell.column == 4: - stringSaldo = f"=B{cell.row} - C{cell.row}" - cell.value = stringSaldo - if cell.column == 8: - stringSaldo = f"=F{cell.row} - G{cell.row}" - cell.value = stringSaldo - - if cell.column == 5: - stringPorcentagem = f"=IFERROR(C{cell.row}/B{cell.row}, 0)" - cell.value = stringPorcentagem - cell.style = percentage_style - if cell.column == 9: - stringPorcentagem = f"=IFERROR(G{cell.row}/F{cell.row}, 0)" - cell.value = stringPorcentagem - cell.style = percentage_style - - #adicionara mascara do numero - for row in sheet.iter_rows(min_row=15, max_row=size2+7, min_col=1, max_col=9): - for cell in row: - if cell.column != 5 and cell.column != 9: - cell.number_format ='#,##0.00' - - - - - - - - - #adicionar borda em tudo - borda = Border(right=Side(border_style="medium")) - sheet.sheet_view.showGridLines = False - for row in sheet.iter_rows(min_row=1, max_row=size2+12,min_col=9,max_col=9): - for cell in row: - cell.border = borda + - font = Font(name='Arial', size=12) - #Colocar tudo arial 12 - for row in sheet.iter_rows(min_row=16): - for cell in row: - cell.font = font - #preenche a coluna A e F com cinza - for row in sheet.iter_rows(min_row=16, max_row=size2+7,min_col=1,max_col=9): - for cell in row: - if cell.column == 1 or cell.column == 6 or cell.column == 2: - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - if cell.column == 6 or cell.column == 2: - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - cell.font = cell.font = Font(name='Arial', size=12,bold= True) - -###pinta de azul a linha desejada - for row in sheet.iter_rows(min_row=15, max_row=sheet.max_row, min_col=sheet.min_row, max_col= 9): - for cell in row: - if cell.row == 15: - cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro, - fill_type = "solid") - cell.font = Font(name='Arial', size=12,bold= True) + sheet.merge_cells('A2:I2') + sheet['A2'] = f'RELATÓRIO DE EXECUÇÃO FINANCEIRA' + sheet['A2'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['A2'].alignment = Alignment(horizontal="center",vertical="center") + - if cell.row == size2 or cell.row == size2 +5 or cell.row == size2 + 7 : - cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro, - fill_type = "solid") - cell.font = Font(name='Arial', size=12,bold= True) + # sheet.merge_cells('B4:F4') + # sheet['A4'] = "" + # sheet['A4'].font = Font(name="Arial", size=12, color="000000") + # sheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + # sheet.merge_cells('B5:F5') + # sheet['A5'] = "" + # sheet['A5'].font = Font(name="Arial", size=12, color="000000") + # sheet['A5'].alignment = Alignment(horizontal="left",vertical="center") - + # sheet.merge_cells('B6:F6') + # sheet['A6'] = "" + # sheet['A6'].font = Font(name="Arial", size=12, color="000000") + # sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") - #cabecario negrito sem fundo + # sheet.merge_cells('B7:F7') + # sheet['A6'] = "" + # sheet['A6'].font = Font(name="Arial", size=12, color="000000") + # sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") - valores = ["RUBRICA","PREVISTO","REALIZADO","SALDO",'(%)\nREALIZADO',"PREVISTO","REALIZADO","SALDO","(%)\nREALIZADO"] - col = 1 - for a,b in enumerate(valores): - sheet.cell(row=14, column=col, value=b) - col = col + 1 - #coloca em negrito - font = Font(name='Arial', size=12,bold=True) - #Colocar tudo arial 12 - for row in sheet.iter_rows(min_row=14,max_row=14): - for cell in row: - cell.font = font - - - #depsesas e capital - despesasDeCapitalString = f"I. DESPESAS CORRENTES" - despesasDeCapitalStringCelula = f'A{15}' - sheet[despesasDeCapitalStringCelula] = despesasDeCapitalString - cell=sheet[despesasDeCapitalStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) + # sheet.merge_cells('C8:E8') + # sheet['A6'] = "" + # sheet['A6'].font = Font(name="Arial", size=12, color="000000") + # sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + # sheet.merge_cells('B9:E9') + # sheet['B9'] = "" + # sheet['B9'].font = Font(name="Arial", size=12, color="000000") + # sheet['B9'].alignment = Alignment(horizontal="left",vertical="center") + + # sheet.merge_cells('F9:I9') + # sheet['F9'] = "" + # sheet['F9'].font = Font(name="Arial", size=12, color="000000") + # sheet['F9'].alignment = Alignment(horizontal="left",vertical="center") + + #CATEGORIA ECONÔMICA / RUBRICAS + sheet.merge_cells('A9:A10') + sheet['A9'] = "CATEGORIA ECONÔMICA / RUBRICAS" + sheet['A9'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['A9'].alignment = Alignment(horizontal="left",vertical="center") + sheet['A9'].fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + + + #Concedente,Participe1,Participe 2,total b10 e e10 + values = ["Concedente","Partícipe 1","Partícipe 2",'Total'] + coluna = 2 + for a,b in enumerate(values): + sheet.cell(row=10, column=coluna, value=b) + coluna = coluna + 1 + #Concedente,Participe1,Participe 2,total f10 e i10 + values = ["Concedente","Partícipe 1","Partícipe 2",'Total'] + coluna = 6 + for a,b in enumerate(values): + sheet.cell(row=10, column=coluna, value=b) + coluna = coluna + 1 + - - #depsesas e capital - despesasDeCapitalString = f"II. DESPESAS DE CAPITAL" - despesasDeCapitalStringCelula = f'A{size2}' - sheet[despesasDeCapitalStringCelula] = despesasDeCapitalString - cell=sheet[despesasDeCapitalStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) + sheet.merge_cells('B9:E9') + #Executado No Periodo + sheet['B9'] = 'EXECUTADO NO PERÍODO' + sheet['B9'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['B9'].alignment = Alignment(horizontal="center",vertical="center") + sheet['B9'].fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + sheet['B9'].border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + #EXECUTADO ATÉ O PERÍODO + sheet.merge_cells('F9:I9') + sheet['F9'] = 'EXECUTADO ATÉ O PERÍODO' + sheet['F9'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['F9'].alignment = Alignment(horizontal="center",vertical="center") + sheet['F9'].fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + sheet['F9'].border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + #DESPESA CORRENTES + sheet['A11'] = '3.DESPESAS CORRENTES' + sheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['A11'].alignment = Alignment(horizontal="center",vertical="center") + sheet['A11'].border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + #pintar inicio da tabela de azul + for rows in sheet.iter_rows(min_row=9, max_row=10, min_col=1, max_col=9): + for cell in rows: + + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + + sheet['E10'] = "Total" + sheet['E10'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['E10'].alignment = Alignment(horizontal="left",vertical="center") + sheet['E10'].fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + sheet['I10'] = "Total" + sheet['I10'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['I10'].alignment = Alignment(horizontal="left",vertical="center") + sheet['I10'].fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") - obrasEInstalacoeslString = f"Obras e Instalações" - obrasEInstalacoeslStringCelula = f'A{size2+1}' - sheet[obrasEInstalacoeslStringCelula] = obrasEInstalacoeslString + #4.DESPESAS DE CAPITAL + sheet[f'A{size2}'] = '4.DESPESAS DE CAPITAL' + sheet[f'A{size2}'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet[f'A{size2}'].alignment = Alignment(horizontal="left",vertical="center") + sheet[f'A{size2}'].border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") + ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + - equipamentoseMaterialPermanenteString = f"Equipamentos e Material Permanente" - equipamentoseMaterialPermanenteStringCelula = f'A{size2+2}' - sheet[equipamentoseMaterialPermanenteStringCelula] = equipamentoseMaterialPermanenteString - cell=sheet[equipamentoseMaterialPermanenteStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell=sheet[f'B{size2+2}'] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - - - nacionalString = f" a) Nacional" - nacionalStringCelula = f'A{size2+3}' - sheet[nacionalStringCelula] = nacionalString - - + sheet.column_dimensions['a'].width = 55 + sheet.column_dimensions['b'].width = 20 + sheet.column_dimensions['c'].width = 20 + sheet.column_dimensions['d'].width = 20 + sheet.column_dimensions['e'].width = 20 + sheet.column_dimensions['f'].width = 20 + sheet.column_dimensions['g'].width = 20 + sheet.column_dimensions['h'].width = 20 + sheet.column_dimensions['i'].width = 20 - importadoString = f" b) Importado" - importadoStringCelula = f'A{size2+4}' - sheet[importadoStringCelula] = importadoString + + #51- Obras e Instalações + celulasAzul = f"A{size2+1}" + cell = sheet[celulasAzul] + cell.value = f'51 - Obras e Instalações' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + #deiarlinha de obras e instalções em negrito - #depsesas e capital - utilRendimentosString = f"III.UTILIZAÇÃO DE RENDIMENTOS" - utilRendimentosStringCelula = f'A{size2+5}' - sheet[utilRendimentosStringCelula] = utilRendimentosString - cell=sheet[utilRendimentosStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell=sheet[f'B{size2+1}'] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - - - - apliFinString = f"Aplicação Financeira" - apliFinStringCelula = f'A{size2+6}' - sheet[apliFinStringCelula] = apliFinString + #a) Obras + celulasAzul = f"A{size2+2}" + cell = sheet[celulasAzul] + cell.value = f'a) Obras' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000") + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + + #b) Instalações + celulasAzul = f"A{size2+3}" + cell = sheet[celulasAzul] + cell.value = f'b) Instalações' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000") + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) - totalString = f"TOTAL" - totalStringCelula = f'A{size2+7}' - sheet[totalStringCelula] = totalString - cell=sheet[totalStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.fill = PatternFill(start_color='9c9c9c', end_color='9c9c9c',fill_type = "solid") - #total total + #Equipamentos e Material Permantente + celulasAzul = f"A{size2+4}" + cell = sheet[celulasAzul] + cell.value = f'52 - Equipamentos e Material Permanente ' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) - formula = f"=SUM(B{size2}, B15)" - sheet[f'B{size2+7}'] = formula + #a) Nacionais + celulasAzul = f"A{size2+5}" + cell = sheet[celulasAzul] + cell.value = f'a) Nacionais' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000") + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + + #b) Importados + celulasAzul = f"A{size2+6}" + cell = sheet[celulasAzul] + cell.value = f'b) Importados' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000") + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + + #Total + celulasAzul = f"A{size2+7}" + cell = sheet[celulasAzul] + cell.value = f'TOTAL' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000") + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + + #pintar celulas de cinza da celula total + for rows in sheet.iter_rows(min_row=size2+7, max_row=size2+7, min_col=1, max_col=9): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + #fazerborda + for rows in sheet.iter_rows(min_row=9, max_row=size2+7, min_col=1, max_col=9): + for cell in rows: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") + ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + - formula = f"=SUM(C{size2}, C15)" - sheet[f'C{size2+7}'] = formula + #bordasNegrito + for rows in sheet.iter_rows(min_row=1, max_row=size2 + 7, min_col=1, max_col=10): + for cell in rows: + #primeira coluna preta + if cell.column == 1 and cell.row > 8: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") + ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + + #segunda coluna preta + if cell.column == 6 and cell.row > 8: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="medium") + ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + #linha preta do top + if cell.row == 8: + cell.border = Border(bottom=Side(border_style="medium") ) + #linha preta da celula 11 + if cell.row == 11 and cell.column > 1: + cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="hair") + ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + if cell.row == 11 and cell.column == 1: + cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="hair") + ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + + if cell.row == 11 and cell.column == 5: + cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="hair") + ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + #linha preta desepsas de capital + if cell.row == size2 and cell.column > 1: + cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="hair") + ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + if cell.row == size2 and cell.column == 1: + cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="hair") + ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + + if cell.row == size2 and cell.column == 5: + cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="hair") + ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + #linha double total + + if cell.row == size2+7 and cell.column > 1 : + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") + ,right =Side(border_style="hair") ,bottom=Side(border_style="medium") ) + if cell.row == size2+7 and cell.column == 1 : + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") + ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + if cell.row == size2+7 and cell.column == 5 : + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") + ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + + if cell.column == 10: + cell.border = Border(left = Side(border_style="medium") ) + + # + for rows in sheet.iter_rows(min_row=9, max_row=size2 + 7, min_col=1, max_col=10): + for cell in rows: + if cell.column == 10: + cell.border = Border(left =Side(border_style="medium") ) + + for rows in sheet.iter_rows(min_row=1, max_row=8, min_col=1, max_col=10): + for cell in rows: + if cell.column == 10: + cell.border = Border(left =Side(border_style="thin",color='9e9e9e') ) + - formula = f"=SUM(D{size2}, D15)" - sheet[f'D{size2+7}'] = formula - formula = f"=SUM(F{size2}, F15)" - sheet[f'F{size2+7}'] = formula + #mascaramoneytodatabela + for rows in sheet.iter_rows(min_row=1, max_row=size2+7, min_col=1, max_col=9): + for cell in rows: + cell.number_format = 'R$ #,##0.00' + + + #somadespesas correntes ESTILORELATORIO + for col_index in range(2, 10): + for row in sheet.iter_rows(min_row=11 ,max_row=size2, min_col=col_index, max_col=col_index): + column_letter = get_column_letter(col_index) + cell = sheet[f'{column_letter}{11}'] + cell.value = f"=SUM({column_letter}{12}:{column_letter}{size2-1})" + cell.font = Font(name="Arial", size=10, color="000000",bold = True) + + #soma despesas de capital ESTILORELATORIO + for col_index in range(2, 10): + for row in sheet.iter_rows(min_row=size2 ,max_row=size2+7, min_col=col_index, max_col=col_index): + column_letter = get_column_letter(col_index) + cell = sheet[f'{column_letter}{size2}'] + cell.value = f"=SUM({column_letter}{size2+1}:{column_letter}{size2+6})" + cell.font = Font(name="Arial", size=10, color="000000",bold = True) + + #soma TOTAL ESTILORELATORIO + for col_index in range(2, 10): + for row in sheet.iter_rows(min_row=size2 ,max_row=size2+7, min_col=col_index, max_col=col_index): + column_letter = get_column_letter(col_index) + cell = sheet[f'{column_letter}{size2+7}'] + cell.value = f"=SUM({column_letter}{11},{column_letter}{size2})" + cell.font = Font(name="Arial", size=10, color="000000",bold = True) + + + #formulas total coluna E + + for rows in sheet.iter_rows(min_row=12 ,max_row=size2-1 ,min_col=5, max_col=5): + for cell in rows: + cell.value = f"=SUM(B{cell.row}:D{cell.row})" + cell.font = Font(name="Arial", size=10, color="000000") - formula = f"=SUM(G{size2}, G15)" - sheet[f'G{size2+7}'] = formula + for rows in sheet.iter_rows(min_row=size2+1,max_row=size2+6 ,min_col=5, max_col=5): + for cell in rows: + cell.value = f"=SUM(B{cell.row}:D{cell.row})" + cell.font = Font(name="Arial", size=10, color="000000") - formula = f"=SUM(H{size2},H15)" - sheet[f'H{size2+7}'] = formula + #formulas total coluna i + for rows in sheet.iter_rows(min_row=12 ,max_row=size2-1 ,min_col=9, max_col=9): + for cell in rows: + cell.value = f"=SUM(F{cell.row}:H{cell.row})" + cell.font = Font(name="Arial", size=10, color="000000") + for rows in sheet.iter_rows(min_row=size2+1,max_row=size2+6 ,min_col=9, max_col=9): + for cell in rows: + cell.value = f"=SUM(F{cell.row}:H{cell.row})" + cell.font = Font(name="Arial", size=10, color="000000") - + #aumentar o tamanho da celula total + sheet.row_dimensions[size+8].height = 33 #brasilia brasilia_row = size2 + 9 - brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:I{stringTamanho}" + brasilia_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho}" brasilia_merge_cells = f'A{brasilia_row}:I{brasilia_row}' sheet.merge_cells(brasilia_merge_cells) top_left_brasilia_cell_formula = f'A{brasilia_row}' @@ -397,9 +401,9 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): diretor_cargo_row = size2 + 11 diretor_cpf_row = size2 + 12 - diretor_nome_formula = f"Daniel Monteiro Rosa" - diretor_cargo_formula = f"='Diretor-Financeiro" - diretor_cpf_formula = f"450.720.272-87" + diretor_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+3}" + diretor_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+4}" + diretor_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+5}" diretor_merge_cells = f'A{diretor_row}:D{diretor_row}' diretor_cargo_merge_cells = f'A{diretor_cargo_row}:D{diretor_cargo_row}' diretor_cpf_merge_cells = f'A{diretor_cpf_row}:D{diretor_cpf_row}' @@ -423,9 +427,9 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): coordenadora_row = size2 + 10 coordenadora_cargo_row = size2 + 11 coordenadora_cpf_row = size2 + 12 - coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" - coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" - coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" + coordenadora_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+3}" + coordenadora_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+4}" + coordenadora_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+5}" coordenadora_merge_cells = f'F{coordenadora_row}:I{coordenadora_row}' coordenadora_cargo_merge_cells = f'F{coordenadora_cargo_row}:I{coordenadora_cargo_row}' coordenadora_cpf_merge_cells = f'F{coordenadora_cpf_row}:I{coordenadora_cpf_row}' @@ -444,400 +448,526 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") - - # borda = Border(right=Side(border_style="medium")) - # sheet.sheet_view.showGridLines = False - # # - # for row in sheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=10): - # for cell in row: - # cell.border = borda - - + #adicionar borda fo nim do arquivo + for row in sheet.iter_rows(min_row=size2 + 8, max_row=coordenadora_cpf_row,min_col=9,max_col=9): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ) + #adicionar borda fo nim do arquivo for row in sheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=9): for cell in row: if cell.column == 9: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) else: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) - workbook.save(tabela) - workbook.close() - + workbook.save(tabela) + workbook.close() - - return 0 + #retorna a localizaçãao do despesas de capital + return size2 -def estiloReceitaXDespesa(tabela,stringTamanho): +def estiloDEMOSTRRECEITEDESPESAA2(tabela,tamanho): '''Estilo da Pagina do Relatorio Receita e Despesa. Argumentos: tabela : recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo ja foi iniciado e passou pela preencher fub mas ainda esta sem o estilo que sera aplicado nessa função. - stringTamanho : refere-se aonde esta localizado a string Brasilia nessa pagina, ela pega o valor entre o tamanho quantidade de rubricas que o projeto possui salvo algumas exeções - e a entrada de receitas/iss, oque for maior esse ditará tamanho. + tamanho : refere-se ao tamanho do dataframe que recebe ''' + caminho = pegar_caminho(tabela) #Plan = planilha # carrega a planilha de acordo com o caminho workbook = openpyxl.load_workbook(caminho) - sheet = workbook['Receita x Despesa'] - size = stringTamanho + 16; - size2 = size + 5 + sheet = workbook['DEMOSTR. RECEITA E DESPESA A.2'] + size = tamanho + 13 + #tamanaho contando despes decapital, obras e instalaçoes, e euipamentos + size2 = size + 8 cinza = "d9d9d9" - azul_claro = '1c8cbc' - # sheet.row_dimensions[3] = 28 - + azul = 'ccffff' + + #remover as gridlines + sheet.sheet_view.showGridLines = False #cabecario relação de pagamentos - outro servicoes de terceiros - sheet.merge_cells('A1:J2') - sheet['A1'] = f'D E M O N S T R A T I V O D E R E C E I T A E D E S P E S A' - sheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + sheet.merge_cells('A1:E1') + sheet['A1'] = f'ANEXO 2' + sheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) sheet['A1'].alignment = Alignment(horizontal="center",vertical="center") - sheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - sheet.merge_cells('A3:J3') - sheet['A3'] = "" - sheet['A3'].font = Font(name="Arial", size=12, color="000000") - sheet['A3'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) - - sheet.merge_cells('A4:J4') - sheet['A4'] = "" - sheet['A4'].font = Font(name="Arial", size=12, color="000000") - sheet['A4'].alignment = Alignment(horizontal="left",vertical="center") - - sheet.merge_cells('A5:J5') - sheet['A5'] = "" - sheet['A5'].font = Font(name="Arial", size=12, color="000000") - sheet['A5'].alignment = Alignment(horizontal="left",vertical="center") - - sheet.merge_cells('A6:J6') - sheet['A6'] = "" - sheet['A6'].font = Font(name="Arial", size=12, color="000000") - sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") - - sheet.merge_cells('A7:J7') - sheet['A7'] = "" - sheet['A7'].font = Font(name="Arial", size=12, color="000000") - sheet['A7'].alignment = Alignment(horizontal="left",vertical="center") - - sheet.merge_cells('A9:J9') - sheet['A9'] = 'R E C E I T A E D E S P E S A' - sheet['A9'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - sheet['A9'].alignment = Alignment(horizontal="center",vertical="center") - sheet['A9'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + sheet.merge_cells('A2:E2') + sheet['A2'] = f'DEMONSTRATIVO DE RECEITAS E DESPESAS' + sheet['A2'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['A2'].alignment = Alignment(horizontal="center",vertical="center") + + + # sheet.merge_cells('C3:E3') + # sheet['A3'] = "" + # sheet['A3'].font = Font(name="Arial", size=12, color="000000") + # sheet['A3'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + + # sheet.merge_cells('C4:E4') + # sheet['A4'] = "" + # sheet['A4'].font = Font(name="Arial", size=12, color="000000") + # sheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + + # sheet.merge_cells('C5:E5') + # sheet['A5'] = "" + # sheet['A5'].font = Font(name="Arial", size=12, color="000000") + # sheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + + # sheet.merge_cells('C6:E6') + # sheet['A6'] = "" + # sheet['A6'].font = Font(name="Arial", size=12, color="000000") + # sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + # sheet.merge_cells('C7:E7') + # sheet['A6'] = "" + # sheet['A6'].font = Font(name="Arial", size=12, color="000000") + # sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + # sheet.merge_cells('C8:E8') + # sheet['A6'] = "" + # sheet['A6'].font = Font(name="Arial", size=12, color="000000") + # sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + # sheet.merge_cells('C9:E9') + # sheet['A6'] = "" + # sheet['A6'].font = Font(name="Arial", size=12, color="000000") + # sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + + # sheet.merge_cells('A10:E10') + # sheet['A10'] = '' + # sheet['A10'].font = Font(name="Arial", size=12, color="000000",bold=True) + # sheet['A10'].alignment = Alignment(horizontal="center",vertical="center") + + + #configurando alturas da tabela demonstrativo.receita despesa for i in range(1,10): sheet.row_dimensions[i].height = 20 + if i ==10: + sheet.row_dimensions[i].height = 2 + sheet.row_dimensions[1].height = 25 sheet.row_dimensions[3].height = 35 sheet.row_dimensions[2].height = 25 - sheet.row_dimensions[9].height = 30 - sheet.column_dimensions['b'].width = 40 + sheet.row_dimensions[11].height = 30 + sheet.row_dimensions[12].height = 30 + sheet.column_dimensions['a'].width = 55 + sheet.column_dimensions['b'].width = 25 sheet.column_dimensions['c'].width = 30 sheet.column_dimensions['d'].width = 30 sheet.column_dimensions['e'].width = 30 - sheet.column_dimensions['f'].width = 30 - sheet.column_dimensions['i'].width = 30 - sheet.column_dimensions['j'].width = 30 - #barra cinza - - barrazinzaMerge = f"A{11}:J{11}" - sheet.merge_cells(barrazinzaMerge) - barrazinzaStringCelula = f"A{11}" - cell = sheet[barrazinzaStringCelula] - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #mascara real em toda a tabela + for rows in sheet.iter_rows(min_row=13, max_row=size2 +13, min_col=2, max_col=5): + for cell in rows: + cell.number_format = 'R$ #,##0.00' + - #adicionar borda em tudo - borda = Border(right=Side(border_style="medium")) - sheet.sheet_view.showGridLines = False - for row in sheet.iter_rows(min_row=1, max_row=size2+21,min_col=10,max_col=10): + #merge das barras azuis da 11 que leva Valor Realizado e Natureza das despesa + barraMerge1 = f"B{11}:D{11}" + sheet.merge_cells(barraMerge1) + #borda Valor realizado + for row in sheet[barraMerge1]: for cell in row: - cell.border = borda + cell.border = Border(top=Side(border_style="double"), left=Side(border_style="hair"), bottom=Side(border_style="hair"), right=Side(border_style="double")) + #Valor Realizado + celulasAzul = f"B{11}" + cell = sheet[celulasAzul] + cell.value = f'Valor Realizado' + cell.fill = PatternFill(start_color=azul, end_color=azul, + fill_type = "solid") + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="double") ) + #A.Natureza das despesas + sheet['A11'] = 'NATUREZA DAS DESPESAS' + sheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['A11'].alignment = Alignment(horizontal="left",vertical="center") + sheet['A11'].fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + sheet['A11'].border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + #despesas correntes + sheet['A13'] = '3.DESPESAS CORRENTES' + sheet['A13'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['A13'].alignment = Alignment(horizontal="left",vertical="center") + sheet['A13'].border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + for row in sheet.iter_rows(min_row=13,max_row=13,min_col=1,max_col=5): + for cell in row : + cell.font = Font(name='Arial',size=12, color="000000",bold=True) +#Grupo/elemenos de despesas/Ate o periodo Anterior/No periodo deteste balancete total acumaladao, previsão na relação de itens + values = ["Grupos/Elementos de Despesas","Até o período Anterior","No Período deste Balancete",'Total Acumulado',"Previsão na Relação de Itens"] + coluna = 1 + for a,b in enumerate(values): + sheet.cell(row=12, column=coluna, value=b) + coluna = coluna + 1 - #merge das receitas - for i in range(16,size): - sttring = f"C{i}:D{i}" - sheet.merge_cells(sttring) + for row in sheet.iter_rows(min_row=12, max_row=12,min_col=1,max_col=5): + for cell in row: + if cell.column == 5 : + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + cell.font = Font(name='Arial',bold=True,color='000000') + else: + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + - font = Font(name='Arial', size=12) - #Colocar tudo arial 12 - for row in sheet.iter_rows(min_row=16): - for cell in row: - cell.font = font - - #mascara de dinheiro despesas correntes - for row in sheet.iter_rows(min_row=16,max_row=size,min_col=5,max_col=5): + + for row in sheet.iter_rows(min_row=12, max_row=size2,min_col=1,max_col=5): for cell in row: - cell.number_format = 'R$ #,##0.00' + if cell.column == 5 and cell.row == 12: + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + elif cell.column == 5: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + elif cell.row == size2: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="double") ) + + else: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) - #mascara de dinehrio despesas realizadas - for row in sheet.iter_rows(min_row=16,max_row=size,min_col=9,max_col=9): + + for row in sheet.iter_rows(min_row=size2, max_row=size2,min_col=5,max_col=5): for cell in row: - cell.number_format = 'R$ #,##0.00' + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="double") ) - #preenche qualquer linha com cinza - for row in sheet.iter_rows(min_row=16, max_row=sheet.max_row, min_col=sheet.min_row, max_col= sheet.max_column): - for cell in row: - if cell.row == size2+2 or cell.row == size2 +12: - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - + #4.Despesas de Capital + celulasAzul = f"A{size+1}" + cell = sheet[celulasAzul] + cell.value = f'4.DESPESAS DE CAPITAL' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + #deiarlinha de desoesas de capital em negrito + for rows in sheet.iter_rows(min_row=size+1, max_row=size+1, min_col=1, max_col=6): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + + #51- Obras e Instalações + celulasAzul = f"A{size+2}" + cell = sheet[celulasAzul] + cell.value = f'51 - Obras e Instalações' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + #deiarlinha de obras e instalções em negrito + for rows in sheet.iter_rows(min_row=size+2, max_row=size+2, min_col=1, max_col=6): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) - #Receita + #a) Obras + celulasAzul = f"A{size+3}" + cell = sheet[celulasAzul] + cell.value = f'a) Obras' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000") + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + + #b) Instalações + celulasAzul = f"A{size+4}" + cell = sheet[celulasAzul] + cell.value = f'b) Instalações' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000") + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + - rendimentoDeAplicacaoFinanceiraMerge = f"A{size2+2}:E{size2+2}" - sheet.merge_cells(rendimentoDeAplicacaoFinanceiraMerge) - rendimentoDeAplicacaoFinanceiraString= f"Rendimento de Aplicação financeira" - rendimentoDeAplicacaoFinanceiraStringCelula = f"A{size2+2}" - sheet[rendimentoDeAplicacaoFinanceiraStringCelula] = rendimentoDeAplicacaoFinanceiraString - cell=sheet[f'A{size2+2}'] - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - cell.font = Font(name="Arial", size=12, color="000000",bold = True) + #Equipamentos e Material Permantente + celulasAzul = f"A{size+5}" + cell = sheet[celulasAzul] + cell.value = f'52 - Equipamentos e Material Permanente ' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) - #Rendimento de aplicação financeira formula - formula = f"=SUM(E{size2+3}:E{size2+6})" - celula = f'F{size2+2}' - sheet[celula] = formula - cell=sheet[f'F{size2+2}'] - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.number_format = 'R$ #,##0.00' + #deiarlinha do equipamento e materialpermaneten em negrito + for rows in sheet.iter_rows(min_row=size+5, max_row=size+5, min_col=1, max_col=6): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + - #soma despesas realizadas - formula = f"=SUM(I{16}:I{size+5})" - celula = f'J13' - sheet[celula] = formula - #soma saldo conciliado - formula = f'=SUM(I{size2+4}+I{size2+5}+I{size2+6}+I{size2+9})' - celula = f'J{size2+2}' - sheet[celula] = formula - #valores recebidos no periodo - formula = f"=SUM(E{14}:E{size2+1})" - celula = f'F13' - sheet[celula] = formula + #a) Nacionais + celulasAzul = f"A{size+6}" + cell = sheet[celulasAzul] + cell.value = f'a) Nacionais' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000") + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + + #b) Importados + celulasAzul = f"A{size+7}" + cell = sheet[celulasAzul] + cell.value = f'b) Importados' + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000") + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + - #SUM total receita - formula = f'=SUM(F{size2+2}+F13)' - celula = f'F{size2+12}' - sheet[celula] = formula - #SUM total despesa - formula = f'=SUM(J{size2+2}+J13)' - celula = f'J{size2+12}' - sheet[celula] = formula + #Total das Receitas (B1+B2) + celulasAzul = f"A{size2+2}" + cell = sheet[celulasAzul] + cell.value = f"B. TOTAL DAS RECEITAS (B1+B2)" + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + #deiarlinha de total das reeitas em negrito + for rows in sheet.iter_rows(min_row=size2+2, max_row=size2+2, min_col=1, max_col=6): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) - #Despesas realizadas - #depsesas e capital - despesasDeCapitalString = f"II. DESPESAS DE CAPITAL" - despesasDeCapitalStringCelula = f'H{size+1}' - sheet[despesasDeCapitalStringCelula] = despesasDeCapitalString - cell=sheet[despesasDeCapitalStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell=sheet[f'I{size+1}'] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.number_format = 'R$ #,##0.00' - - + #Barra azull total das receitas + + for row in sheet.iter_rows(min_row=size2+2, max_row=size2+2,min_col=2,max_col=4): + for cell in row: + if cell.column == 4 : + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + cell.font = Font(name='Arial',bold=True,color='000000') + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="double") ) - obrasEInstalacoeslString = f"Obras e Instalações" - obrasEInstalacoeslStringCelula = f'H{size+2}' - sheet[obrasEInstalacoeslStringCelula] = obrasEInstalacoeslString - cell=sheet[f'I{size+2}'] - cell.font = Font(name="Arial", size=12, color="000000") - cell.number_format = 'R$ #,##0.00' - + else: + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + cell.font = Font(name='Arial',bold=True,color='000000') + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) - equipamentoseMaterialPermanenteString = f"Equipamentos e Material Permanente" - equipamentoseMaterialPermanenteStringCelula = f'H{size+3}' - sheet[equipamentoseMaterialPermanenteStringCelula] = equipamentoseMaterialPermanenteString - cell=sheet[equipamentoseMaterialPermanenteStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell=sheet[f'I{size+3}'] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.number_format = 'R$ #,##0.00' - + #bordas inferiores + for row in sheet.iter_rows(min_row=size2+3, max_row=size2+4,min_col=2,max_col=4): + for cell in row: + if cell.column == 4 and cell.row == size2+3: + + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="double") ) + elif cell.column == 4 and cell.row == size2+4: + + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="double") ) + elif cell.column != 4 and cell.row == size2+4: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="hair") ) - nacionalString = f" a) Nacional" - nacionalStringCelula = f'H{size+4}' - sheet[nacionalStringCelula] = nacionalString - cell=sheet[f'I{size+4}'] - cell.font = Font(name="Arial", size=12, color="000000") - cell.number_format = 'R$ #,##0.00' - + else: + + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) - importadoString = f" b) Importado" - importadoStringCelula = f'H{size+5}' - sheet[importadoStringCelula] = importadoString - cell=sheet[f'I{size+5}'] - cell.font = Font(name="Arial", size=12, color="000000") - cell.number_format = 'R$ #,##0.00' - #saldo conciliado em: - saldoConciliadoEmString= f"Saldo Conciliado em: " - saldoConciliadoEmStringCelula = f"H{size2+2}" - sheet[saldoConciliadoEmStringCelula] = saldoConciliadoEmString - cell=sheet[saldoConciliadoEmStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - - ##saldo conciliado formula - cell=sheet[f'J{size2+2}'] - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.number_format = 'R$ #,##0.00' - #mergecelulasabaixo de Rendimento de Aplicação financeira - for i in range(size2+3,size2+6): - sttring = f"A{i}:D{i}" - sheet.merge_cells(sttring) - - - - contaCorrenteEmString= f"Conta Corrente" - contaCorrenteEmStringCelula = f"H{size2+4}" - sheet[contaCorrenteEmStringCelula] = contaCorrenteEmString - cell=sheet[f'I{size2+4}'] - cell.font = Font(name="Arial", size=12, color="000000") - cell.number_format = 'R$ #,##0.00' - - devolucaoRecursosEmString= f"Devolução de recursos - GRU SIMPLES" - devolucaoRecursosEmStringCelula = f"H{size2+5}" - sheet[devolucaoRecursosEmStringCelula] = devolucaoRecursosEmString - cell=sheet[f'I{size2+5}'] - cell.font = Font(name="Arial", size=12, color="000000") - cell.number_format = 'R$ #,##0.00' - - tarifaBancariaSaldoEmString= f"Tarifa Bancária - Saldo" - tarifaBancariaSaldoEmStringCelula = f"H{size2+6}" - sheet[tarifaBancariaSaldoEmStringCelula] = tarifaBancariaSaldoEmString - cell=sheet[saldoConciliadoEmStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell=sheet[f'J{size2+6}'] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.number_format = 'R$ #,##0.00' + celulasAzul = f"A{size2+3}" + cell = sheet[celulasAzul] + cell.value = f"B.1 Recursos Recebidos" + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + + celulasAzul = f"A{size2+4}" + cell = sheet[celulasAzul] + cell.value = f"B.2 Rendimento de Aplicações Financeiras" + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="hair") ) + + #saldo + celulasAzul = f"A{size2+6}" + cell = sheet[celulasAzul] + cell.value = f"Saldo" + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="double") ,bottom=Side(border_style="double"),right=Side(border_style="hair") ) + #deiar negrito o saldo + for rows in sheet.iter_rows(min_row=size2+6, max_row=size2+6, min_col=1, max_col=6): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + + + #saldos disponivel para o perido seguinte + celulasAzul = f"A{size2+8}" + cell = sheet[celulasAzul] + cell.value = f"D. Saldo Disponível para o Período Seguinte" + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) - tarifaBancariaDespesaEmString= f"Tarifa Bancária - Despesa (-)" - tarifaBancariaDespesaEmStringCelula = f"H{size2+7}" - sheet[tarifaBancariaDespesaEmStringCelula] = tarifaBancariaDespesaEmString - cell=sheet[f'I{size2+7}'] - cell.font = Font(name="Arial", size=12, color="000000") + #Negrito no numero da frente + celulasAzul = f"B{size2+8}" + cell = sheet[celulasAzul] + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="double") ) cell.number_format = 'R$ #,##0.00' - - TarifaBancariaRestituicaoEmString= f"Tarifa Bancária - Restituição (+)" - TarifaBancariaRestituicaoEmStringCelula = f"H{size2+8}" - sheet[TarifaBancariaRestituicaoEmStringCelula] = TarifaBancariaRestituicaoEmString - cell=sheet[f'I{size2+8}'] + + #d1 borda + celulasAzul = f"B{size2+9}" + cell = sheet[celulasAzul] + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="double") ) cell.number_format = 'R$ #,##0.00' - - aplicacaoFinanceiraEmString= f"Aplicação Financeira" - aplicacaoFinanceiraEmStringCelula = f"H{size2+9}" - sheet[aplicacaoFinanceiraEmStringCelula] = aplicacaoFinanceiraEmString - cell=sheet[aplicacaoFinanceiraEmStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell=sheet[f'I{size2+9}'] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) + + #d2 borda + celulasAzul = f"B{size2+10}" + cell = sheet[celulasAzul] + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="double") ) cell.number_format = 'R$ #,##0.00' - - rendimentoDeaplicacaoEmString= f"Rendimento de aplicação financeira" - rendimentoDeaplicacaoEmStringCelula = f"H{size2+10}" - sheet[rendimentoDeaplicacaoEmStringCelula] = rendimentoDeaplicacaoEmString - cell=sheet[f'I{size2+10}'] + #d3 borda + celulasAzul = f"B{size2+11}" + cell = sheet[celulasAzul] + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="double") ) cell.number_format = 'R$ #,##0.00' - #Total Receita + #Barra azul saldo - totalMerge = f"A{size2+12}:E{size2+12}" - sheet.merge_cells(totalMerge) - totalString= f"TOTAL" - totalStringCelula = f"A{size2+12}" - sheet[totalStringCelula] = totalString - - cell = sheet[totalStringCelula] - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + for row in sheet.iter_rows(min_row=size2+6, max_row=size2+6,min_col=2,max_col=4): + for cell in row: + if cell.column == 3: + cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="hair") ) - #TotalReceitaFormula - cell=sheet[f'F{size2+12}'] - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.number_format = 'R$ #,##0.00' - #Total Despesa - - totalMerge = f"H{size2+12}:I{size2+12}" - sheet.merge_cells(totalMerge) - totalString= f"TOTAL" - totalStringCelula = f"H{size2+12}" - sheet[totalStringCelula] = totalString - cell = sheet[totalStringCelula] - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") + elif cell.column == 4 : + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="double") ) + else: + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="hair") ) + + + + #saldo em conta corrente e aplicação financeira + celulasAzul = f"A{size2+9}" + cell = sheet[celulasAzul] + cell.value = f"D.1. Saldo em Conta corrente e Aplicação Financeira" + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) cell.font = Font(name="Arial", size=12, color="000000",bold=True) - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - #Total Despesa Formula - cell=sheet[f'J{size2+12}'] - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.number_format = 'R$ #,##0.00' + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + #restituições não creditadas + celulasAzul = f"A{size2+10}" + cell = sheet[celulasAzul] + cell.value = f"D.2. Restituições não Creditadas" + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="hair"),right=Side(border_style="hair") ) + #cheques emitido e não descontados + celulasAzul = f"A{size2+11}" + cell = sheet[celulasAzul] + cell.value = f"D.3. Cheques Emitidos e não Descontados" + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="hair") ) + + #saldos devolvido á Finep + celulasAzul = f"A{size2+13}" + cell = sheet[celulasAzul] + cell.value = f"E. Saldo Devolvido à FINEP" + cell.fill = PatternFill(start_color=azul, end_color=azul, fill_type = "solid") + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="double") ,bottom=Side(border_style="double"),right=Side(border_style="hair") ) + #Negrito no numero da frente + celulasAzul = f"B{size2+13}" + cell = sheet[celulasAzul] + cell.fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + cell.alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="double") ) + cell.number_format = 'R$ #,##0.00' + - #Barraazul + #somatorios + + #somatorio desepsas correntes - barrazulMerge = f"A{size2+14}:J{size2+14}" - sheet.merge_cells(barrazulMerge) - barrazulStringCelula = f"A{size2+14}" - cell = sheet[barrazulStringCelula] + for col_index in range(2, 6): + for row in sheet.iter_rows(min_row=13, max_row=13, min_col=col_index, max_col=col_index): + column_letter = get_column_letter(col_index) + cell = sheet[f'{column_letter}13'] + cell.value = f"=SUM({column_letter}14:{column_letter}{size})" + + #somatorio linha final + for col_index in range(2, 6): + for row in sheet.iter_rows(min_row=size+8, max_row=size+8, min_col=col_index, max_col=col_index): + column_letter = get_column_letter(col_index) + cell = sheet[f'{column_letter}{size+8}'] + cell.value = f"={column_letter}13+{column_letter}{size+1}" + + #Somatorio total das receitas(B1+B2) + for col_index in range(2, 5): + for row in sheet.iter_rows(min_row=size2+2, max_row=size2+2, min_col=col_index, max_col=col_index): + column_letter = get_column_letter(col_index) + cell = sheet[f'{column_letter}{size2+2}'] + cell.value = f"=SUM({column_letter}{size2+3}:{column_letter}{size2+4})" - cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro, - fill_type = "solid") - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #somatorio saldo disponivel para o periodo seguinte + formula = f"=SUM(B{size2+9}:B{size2+11})" + celula = f'B{size2+8}' + sheet[celula] = formula + + + #total acumulado somatorio + #Adicionar Soma na coluna E + for rows in sheet.iter_rows(min_row=14, max_row=size+7, min_col=4, max_col=4): + for cell in rows: + cell.value = f"=SUM(B{cell.row}:C{cell.row})" + + + #FORMULA DESPESAS DE CAPITAL + sheet[f'B{size+1}'] = f"=SUM(B{size+2}:B{size+7})" + sheet[f'B{size+1}'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet[f'B{size+1}'].alignment = Alignment(horizontal="right",vertical="center") + + #FORMULA DESPESAS DE CAPITAL + sheet[f'C{size+1}'] = f"=SUM(C{size+2}:C{size+7})" + sheet[f'C{size+1}'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet[f'C{size+1}'].alignment = Alignment(horizontal="right",vertical="center") + + #FORMULA DESPESAS DE CAPITAL + sheet[f'E{size+1}'] = f"=SUM(E{size+2}:E{size+7})" + sheet[f'E{size+1}'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet[f'E{size+1}'].alignment = Alignment(horizontal="right",vertical="center") + + #brasilia brasilia_row = size2 + 16 - brasilia_formula = f"" - brasilia_merge_cells = f'A{brasilia_row}:I{brasilia_row}' + brasilia_formula = f"Brasília, 28 de agosto de 2022." + brasilia_merge_cells = f"A{brasilia_row}:E{brasilia_row}" sheet.merge_cells(brasilia_merge_cells) top_left_brasilia_cell_formula = f'A{brasilia_row}' top_left_brasilia_cell = sheet[top_left_brasilia_cell_formula] @@ -851,9 +981,9 @@ def estiloReceitaXDespesa(tabela,stringTamanho): diretor_nome_formula = f"Daniel Monteiro Rosa" diretor_cargo_formula = f"Diretor-Financeiro" diretor_cpf_formula = f"450.720.272-87" - diretor_merge_cells = f'A{diretor_row}:D{diretor_row}' - diretor_cargo_merge_cells = f'A{diretor_cargo_row}:D{diretor_cargo_row}' - diretor_cpf_merge_cells = f'A{diretor_cpf_row}:D{diretor_cpf_row}' + diretor_merge_cells = f'A{diretor_row}:B{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:B{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:B{diretor_cpf_row}' sheet.merge_cells(diretor_merge_cells) sheet.merge_cells(diretor_cargo_merge_cells) sheet.merge_cells(diretor_cpf_merge_cells) @@ -878,15 +1008,15 @@ def estiloReceitaXDespesa(tabela,stringTamanho): coordenadora_nome_formula = f"teste" coordenadora_cargo_formula = f"Coordenador(a)" coordenadora_cpf_formula = f"teste" - coordenadora_merge_cells = f'H{coordenadora_row}:J{coordenadora_row}' - coordenadora_cargo_merge_cells = f'H{coordenadora_cargo_row}:J{coordenadora_cargo_row}' - coordenadora_cpf_merge_cells = f'H{coordenadora_cpf_row}:J{coordenadora_cpf_row}' + coordenadora_merge_cells = f'C{coordenadora_row}:E{coordenadora_row}' + coordenadora_cargo_merge_cells = f'C{coordenadora_cargo_row}:E{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'C{coordenadora_cpf_row}:E{coordenadora_cpf_row}' sheet.merge_cells(coordenadora_merge_cells) sheet.merge_cells(coordenadora_cargo_merge_cells) sheet.merge_cells(coordenadora_cpf_merge_cells) - top_left_coordenadora_cell_formula = f'H{coordenadora_row}' - top_left_coordenadora_cell_cargo_formula = f'H{coordenadora_cargo_row}' - top_left_coordenadora_cell_cpf_formula = f'H{coordenadora_cpf_row}' + top_left_coordenadora_cell_formula = f'C{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'C{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'C{coordenadora_cpf_row}' top_left_coordenadora_cell = sheet[top_left_coordenadora_cell_formula] top_left_coordenadora_cell_cargo_formula = sheet[top_left_coordenadora_cell_cargo_formula] top_left_coordenadora_cell_cpf_formula = sheet[top_left_coordenadora_cell_cpf_formula] @@ -896,39 +1026,1451 @@ def estiloReceitaXDespesa(tabela,stringTamanho): top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") + + #E melhor fazertodas as bordas no fim pra ter certeza que vao ser aplicadas + + + #borda cabeçario + for row in sheet.iter_rows(min_row=1, max_row=11,min_col=5,max_col=5): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + #borda fim pagina + for row in sheet.iter_rows(min_row=size2+1, max_row=coordenadora_cpf_row+1,min_col=5,max_col=5): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + + + for row in sheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=5): + for cell in row: + if cell.column == 5: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) + + + workbook.save(tabela) + workbook.close() + + + #retorna tamanho de brasilia + return size2 + 16 + +def estiloG(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho,tamanhoestorno): + '''Esse estilo e considerado geral por que todas as tabelas que compõe utilizam das mesma colunas. + + Argumentos: + tabela: recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo ja foi iniciado e passou pela preencher fub mas ainda esta sem o estilo que sera aplicado nessa função. + tamanho: e o tamanho total de linhas que irao ser geradas dinamicamente correspondente as entradas do respectivo projeto. o valor varia dentre o tamanho das rubricas + + nomeVariavel: variável utilizada para criar o nomes das variaveis dinamicamente para não haver sobreposição de estilos com o mesmo nome. Esses estilos ocorrem nesses codigos: + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid"'.... + nomeTabela: variável utilizada para a criação do nome da tabela.Ela deriva das rubricas que são colocadas no input quando essa função e chamada. + stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referencias das formulas. + + ''' + if tamanho == 0: + tamanho = 1 + + + nomeSheet=nomeVariavel + random_number = random.randint(1, 10000) + nomeVariavel = f'{nomeVariavel}{random_number}' + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + worksheet = workbook[nomeTabela] + size = tamanho + 16 + cinza = "d9d9d9" + cinza_escuro = "bfbfbf" + azul = "336394" + azul_claro = 'ccffff' + + # borda = Border(right=Side(border_style="medium")) + worksheet.sheet_view.showGridLines = False + # + # for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda + + + worksheet.column_dimensions['a'].width = 45 + worksheet.column_dimensions['b'].width = 35 + worksheet.column_dimensions['c'].width = 35 + worksheet.column_dimensions['d'].width = 45#descrição + worksheet.column_dimensions['e'].width = 45 #n do recibo ou qeuivalente + worksheet.column_dimensions['f'].width = 35 #data de emissão + worksheet.column_dimensions['g'].width = 35 #data de emissão + worksheet.column_dimensions['h'].width = 35 #data de emissão + worksheet.column_dimensions['i'].width = 35 #data de emissão + worksheet.column_dimensions['j'].width = 35 #data de emissão + + + #cabecario relação de pagamentos - outro servicoes de terceiros + worksheet.merge_cells('A1:I1') + nomeTabela = nomeTabela.upper() + worksheet['A1'] = f'ANEXO 4' + worksheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + #RELAÇÃO DE PAGAMENTOS + worksheet.merge_cells('A2:I2') + + worksheet['A2'] = f'RELAÇÃO DE PAGAMENTOS' + worksheet['A2'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A2'].alignment = Alignment(horizontal="center",vertical="center") + + #ElementosdeDespesa + + + worksheet['A11'] = f'Elemento de Despesa' + worksheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A11'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + #ElementosdeDespesa + + + worksheet['A14'] = f'DESPESAS REALIZADAS' + worksheet['A14'].font = Font(name="Arial", size=12, color="000000",bold=True,italic=True) + worksheet['A14'].alignment = Alignment(horizontal="center",vertical="center") + + + + #cabecario que recebe de referencia as celulas A da planilha DEMOSTR. RECEITA E DESPESA A.2 + + #Convênio nº: 01.14.0032.00 + worksheet['A4'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A4" + worksheet['A4'].font = Font(name="Arial", size=12, color="000000") + worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + #Convenente: + worksheet['A5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A5" + worksheet['A5'].font = Font(name="Arial", size=12, color="000000") + worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + #Período de Execução do Convênio: + worksheet['A6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A6" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000") + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + #Período Abrangido por este Relatório: + worksheet['A7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A7" + worksheet['A7'].font = Font(name="Arial", size=12, color="000000") + worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") + #Fonte de Recursos: + worksheet['A8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A8" + worksheet['A8'].font = Font(name="Arial", size=12, color="000000") + worksheet['A8'].alignment = Alignment(horizontal="left",vertical="center") + #Partícipe (no caso de contrapartida): + worksheet['A9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A9" + worksheet['A9'].font = Font(name="Arial", size=12, color="000000") + worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center") + + + + #cabecario que recebe de referencia as celulas C da planilha DEMOSTR. RECEITA E DESPESA A.2 + + # Fundação de Empreendimentos Científicos e Tecnológicos - FINATEC + worksheet['C5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C5" + worksheet['C5'].font = Font(name="Arial", size=12, color="000000") + worksheet['C5'].alignment = Alignment(horizontal="left",vertical="center") + #de 10/02/2014 a 10/06/2023 + worksheet['C6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C6" + worksheet['C6'].font = Font(name="Arial", size=12, color="000000") + worksheet['C6'].alignment = Alignment(horizontal="left",vertical="center") + #de 10/02/2014 a 31/07/2022 + worksheet['C7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C7" + worksheet['C7'].font = Font(name="Arial", size=12, color="000000") + worksheet['C7'].alignment = Alignment(horizontal="left",vertical="center") + #recursos finep recursos contra partid + worksheet['C8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C8" + worksheet['C8'].font = Font(name="Arial", size=12, color="000000") + worksheet['C8'].alignment = Alignment(horizontal="left",vertical="center") + #xxx + worksheet['C9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C9" + worksheet['C9'].font = Font(name="Arial", size=12, color="000000") + worksheet['C9'].alignment = Alignment(horizontal="left",vertical="center") + + #variavel + + input2=f'rowStyle{nomeVariavel}' + + + #colunas azul cabecario + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="000000",bold=True) + locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input2].border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"), right=Side(border_style="hair"),left=Side(border_style='hair') ) + locals()[input2].height = 20 + + linha_number = 15 + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=9): + for cell in row: + cell.style = locals()[input2] + if cell.column == 9: + cell.border = Border(top=Side(border_style="double") ,bottom=Side(border_style="thin"), right=Side(border_style="double") ) + cell.fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + + + + valores = ["Nº DE ORDEM","CREDOR","CNPJ/CPF",'Equivalência na Relação de Itens Apoiados','Nº DA NOTA FISCAL OU EQUIVALENTE',"DATA DA NOTA FISCAL",'Nº DO CHEQUE OU EQUIVALENTE','DATA DA COMPENSAÇÃO DO CHEQUE','VALOR'] + col = 1 + for a,b in enumerate(valores): + worksheet.cell(row=linha_number, column=col, value=b) + col = col + 1 + + + #Aumentar a altura das celulas + for row in worksheet.iter_rows(min_row=15, max_row=size, min_col=1, max_col=9): + worksheet.row_dimensions[row[0].row].height = 60 + input3 = f'customNumber{nomeVariavel}' + + # MASCARA R$ + + locals()[input3] = NamedStyle(name=f'{input3}') + locals()[input3].number_format = 'R$ #,##0.00' + locals()[input3].font = Font(name="Arial", size=12, color="000000") + locals()[input3].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + value_to_stop = size + start_row = 10 + + #estilo mascara de dinheiro + for row in range(start_row,size+1): + cell = worksheet[f'i{row}'] + cell.style = locals()[input3] + + #estilocinzasimcinzanao + for rows in worksheet.iter_rows(min_row=16, max_row=size, min_col=1, max_col=9): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + + + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + + + if cell.column == 9: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + if cell.row == size: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + + #double em cima double total + + #bordinha double + stringAfinarCelula =size+2 + cellborda = f"I{size+1}" + bordacell = worksheet[cellborda] + bordacell.border = Border(right =Side(border_style="double")) + + + #subtotal + worksheet.row_dimensions[size+2].height = 6 + celulas_mergidas_subtotal = f"A{size+2}:H{size+2}" + worksheet.merge_cells(celulas_mergidas_subtotal) + left_celula_cell = f"A{size+2}" + top_left_cell = worksheet[left_celula_cell] + top_left_cell.value = "Sub Total1" + top_left_cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="double") ) + + worksheet.row_dimensions[size+2].height = 56.25 + + # FORMULATOTAL + formula = f"=SUM(I16:I{size})" + celula = f'I{size+2}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="double") ,bottom=Side(border_style="double") ) + worksheet[celula].number_format = 'R$ #,##0.00' + #restituições creditadas + restituicoes = size + 3 + celula_restituicoes=f'A{restituicoes}' + worksheet[celula_restituicoes].value = "RESTITUIÇÕES CREDITADAS" + worksheet[celula_restituicoes].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet.row_dimensions[restituicoes].height = 30 + + + input4 = f'row_style_diaria_append{nomeVariavel}' + #estilo colunas restitucoes creditadas + locals()[input4] = NamedStyle(name=f'{input4}') + locals()[input4].font = Font(name="Arial", size=12, color="000000",bold=True) + locals()[input4].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + locals()[input4].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input4].height = 30 + locals()[input4].border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"),right=Side(border_style='hair'),left=Side(border_style='hair') ) + + + row_number = size + 4 + + for column in range(1, 10): + cell = worksheet.cell(row=row_number, column=column) + cell.style = locals()[input4] + if cell.column == 9: + cell.border = Border(top=Side(border_style="double") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + + + + values = ["Nº DE ORDEM","RESTITUIDOR","CNPJ/CPF" ,'Equivalência na Relação de Itens Apoiados',"CHEQUE OU EQUIVALENTE ESTORNADO","DATA DO CHEQUE",'Nº DO DEPÓSITO','DATA DO DEPÓSITO','VALOR'] + coluna = 1 + for a,b in enumerate(values): + worksheet.cell(row=row_number, column=coluna, value=b) + coluna = coluna + 1 + + + + + #estorno + + for rows in worksheet.iter_rows(min_row=size+5, max_row=size+4+tamanhoestorno, min_col=1, max_col=9): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + if cell.row == size+4+tamanhoestorno: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + if cell.column == 9: + cell.number_format = 'R$ #,##0.00' + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + if cell.row == size+4+tamanhoestorno: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + #bordas,corsimcornao,money + # Set the height of each row to 60 + for row in worksheet.iter_rows(min_row=size+4, max_row=size+4+tamanhoestorno): + worksheet.row_dimensions[row[0].row].height = 60 + + min_row = size + 4 + max_row = size + 4 + tamanhoestorno + + + + #bordinha double + stringAfinarCelula = size + 6 +tamanhoestorno + cellborda = f"I{size + 5 +tamanhoestorno}" + bordacell = worksheet[cellborda] + bordacell.border = Border(right =Side(border_style="double")) + + #subtotal2 + sub_total2_row = size + 6 +tamanhoestorno + subtotal_merge_cells= f'A{sub_total2_row}:H{sub_total2_row}' + worksheet.merge_cells(subtotal_merge_cells) + top_left_subtotal2_cell_formula = f'A{sub_total2_row}' + top_left_subtotal2_cell = worksheet[top_left_subtotal2_cell_formula] + top_left_subtotal2_cell.value = "Sub Total 2" + top_left_subtotal2_cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + top_left_subtotal2_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_subtotal2_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_subtotal2_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + sub_formula_row_celula = f'I{sub_total2_row}' + worksheet[sub_formula_row_celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[sub_formula_row_celula].value = f'=SUM(I{size+5}:I{sub_total2_row-1})' + worksheet[sub_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[sub_formula_row_celula].number_format = 'R$ #,##0.00' + worksheet[sub_formula_row_celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="double") ,bottom=Side(border_style="thin") ) + + #total1-2 + total12_row = size + 7 + tamanhoestorno + total12_merge_cells = f'A{total12_row}:H{total12_row}' + worksheet.merge_cells(total12_merge_cells) + top_left_total12_cell_formula = f'A{total12_row}' + top_left_total12_cell = worksheet[top_left_total12_cell_formula] + top_left_total12_cell.value = "Total(1-2)" + top_left_total12_cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + top_left_total12_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_total12_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_total12_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="thin") ) + + + #total_formula + total_formula_row = size + 7 + tamanhoestorno + total_formulaa = f'=I{size+2} - I{sub_total2_row }' + total_formula_row_celula = f'I{total_formula_row}' + worksheet[total_formula_row_celula].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet[total_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[total_formula_row_celula].number_format = 'R$ #,##0.00' + worksheet[total_formula_row_celula].border = Border(bottom=Side(border_style="double"),right=Side(border_style="double") ) + + worksheet.row_dimensions[total_formula_row].height = 30 + worksheet[total_formula_row_celula] = total_formulaa + + + + #brasilia + brasilia_row = size + 8 +tamanhoestorno + brasilia_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:I{brasilia_row}' + worksheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.value = brasilia_formula + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + + #DiretorFinanceiro + diretor_row = size + 9 + tamanhoestorno + diretor_cargo_row = size + 10 + tamanhoestorno + diretor_cpf_row = size + 11 + tamanhoestorno + + diretor_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+3}" + diretor_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+4}" + diretor_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+5}" + diretor_merge_cells = f'A{diretor_row}:C{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:C{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:C{diretor_cpf_row}' + worksheet.merge_cells(diretor_merge_cells) + worksheet.merge_cells(diretor_cargo_merge_cells) + worksheet.merge_cells(diretor_cpf_merge_cells) + top_left_diretor_cell_formula = f'A{diretor_row}' + top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' + top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' + top_left_diretor_cell = worksheet[top_left_diretor_cell_formula] + top_left_diretor_cell_cargo_formula = worksheet[top_left_diretor_cell_cargo_formula] + top_left_diretor_cell_cpf_formula = worksheet[top_left_diretor_cell_cpf_formula] + top_left_diretor_cell.value = diretor_nome_formula + top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula + top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula + top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell.font = Font(bold=True) + top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + #Coordenadora + coordenadora_row = size + 9 + tamanhoestorno + coordenadora_cargo_row = size + 10 + tamanhoestorno + coordenadora_cpf_row = size + 11 + tamanhoestorno + coordenadora_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+3}" + coordenadora_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+4}" + coordenadora_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+5}" + coordenadora_merge_cells = f'F{coordenadora_row}:I{coordenadora_row}' + coordenadora_cargo_merge_cells = f'F{coordenadora_cargo_row}:I{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'F{coordenadora_cpf_row}:I{coordenadora_cpf_row}' + worksheet.merge_cells(coordenadora_merge_cells) + worksheet.merge_cells(coordenadora_cargo_merge_cells) + worksheet.merge_cells(coordenadora_cpf_merge_cells) + top_left_coordenadora_cell_formula = f'F{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'F{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'F{coordenadora_cpf_row}' + top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] + top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] + top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] + top_left_coordenadora_cell.value = coordenadora_nome_formula + top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula + top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) + top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") + top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") + + + # borda = Border(right=Side(border_style="medium")) + # worksheet.sheet_view.showGridLines = False + # # + # for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=9): + # for cell in row: + # cell.border = borda + + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=9, max_col=9): + for cell in row: + cell.border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"), right=Side(border_style="double") ) + cell.fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + + cinzaborda = '9e9e9e' + + #borda cabeçario + for row in worksheet.iter_rows(min_row=1, max_row=14,min_col=9,max_col=9): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + #borda fim pagina + for row in worksheet.iter_rows(min_row=brasilia_row, max_row=coordenadora_cpf_row+1,min_col=9,max_col=9): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + + + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=9): + for cell in row: + if cell.column == 9: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) + + workbook.save(tabela) + workbook.close() + + return size+5 + +def estiloPagamentoPessoal(tabela,tamanho,stringTamanho,tamanhoestorno): + '''Esse estilo e considerado geral por que todas as tabelas que compõe utilizam das mesma colunas. + + Argumentos: + tabela: recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo ja foi iniciado e passou pela preencher fub mas ainda esta sem o estilo que sera aplicado nessa função. + tamanho: e o tamanho total de linhas que irao ser geradas dinamicamente correspondente as entradas do respectivo projeto. o valor varia dentre o tamanho das rubricas + + nomeVariavel: variável utilizada para criar o nomes das variaveis dinamicamente para não haver sobreposição de estilos com o mesmo nome. Esses estilos ocorrem nesses codigos: + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid"'.... + nomeTabela: variável utilizada para a criação do nome da tabela.Ela deriva das rubricas que são colocadas no input quando essa função e chamada. + stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referencias das formulas. + + ''' + if tamanho == 0: + tamanho = 1 + + + nomeVariavel = f'PagamentoPessoal' + nomeSheet=nomeVariavel + random_number = random.randint(1, 10000) + nomeVariavel = f'{nomeVariavel}{random_number}' + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + worksheet = workbook['Pagamento de Pessoal'] + size = tamanho + 16 + cinza = "d9d9d9" + cinza_escuro = "bfbfbf" + azul = "336394" + azul_claro = 'ccffff' + + + # borda = Border(right=Side(border_style="medium")) + worksheet.sheet_view.showGridLines = False + # + # for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda + + + worksheet.column_dimensions['a'].width = 45 + worksheet.column_dimensions['b'].width = 35 + worksheet.column_dimensions['c'].width = 35 + worksheet.column_dimensions['d'].width = 45#descrição + worksheet.column_dimensions['e'].width = 45 #n do recibo ou qeuivalente + worksheet.column_dimensions['f'].width = 35 #data de emissão + worksheet.column_dimensions['g'].width = 35 #data de emissão + worksheet.column_dimensions['h'].width = 35 #data de emissão + worksheet.column_dimensions['i'].width = 35 #data de emissão + worksheet.column_dimensions['j'].width = 35 #data de emissão + + + #cabecario relação de pagamentos - outro servicoes de terceiros + worksheet.merge_cells('A1:J1') + worksheet['A1'] = f'ANEXO 4' + worksheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + #RELAÇÃO DE PAGAMENTOS + worksheet.merge_cells('A2:J2') + + worksheet['A2'] = f'RELAÇÃO DE PAGAMENTOS' + worksheet['A2'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A2'].alignment = Alignment(horizontal="center",vertical="center") + + #ElementosdeDespesa + + + worksheet['A11'] = f'Elemento de Despesa' + worksheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A11'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #ElementosdeDespesa + + + worksheet['A14'] = f'DESPESAS REALIZADAS' + worksheet['A14'].font = Font(name="Arial", size=12, color="000000",bold=True,italic=True) + worksheet['A14'].alignment = Alignment(horizontal="center",vertical="center") + + + + #cabecario que recebe de referencia as celulas A da planilha DEMOSTR. RECEITA E DESPESA A.2 + + + worksheet['A4'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A4" + worksheet['A4'].font = Font(name="Arial", size=12, color="000000") + worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A5" + worksheet['A5'].font = Font(name="Arial", size=12, color="000000") + worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A6" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000") + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A7" + worksheet['A7'].font = Font(name="Arial", size=12, color="000000") + worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A8" + worksheet['A8'].font = Font(name="Arial", size=12, color="000000") + worksheet['A8'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A9" + worksheet['A9'].font = Font(name="Arial", size=12, color="000000") + worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center") + + + + #cabecario que recebe de referencia as celulas C da planilha DEMOSTR. RECEITA E DESPESA A.2 + + worksheet['C5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C5" + worksheet['C5'].font = Font(name="Arial", size=12, color="000000") + worksheet['C5'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C6" + worksheet['C6'].font = Font(name="Arial", size=12, color="000000") + worksheet['C6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C7" + worksheet['C7'].font = Font(name="Arial", size=12, color="000000") + worksheet['C7'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C8" + worksheet['C8'].font = Font(name="Arial", size=12, color="000000") + worksheet['C8'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C9" + worksheet['C9'].font = Font(name="Arial", size=12, color="000000") + worksheet['C9'].alignment = Alignment(horizontal="left",vertical="center") + + #variavel + + input2=f'rowStyle{nomeVariavel}' + + + #colunas azul cabecario + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="000000",bold=True) + locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input2].border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"), right=Side(border_style="hair"),left=Side(border_style='hair') ) + locals()[input2].height = 20 + + linha_number = 15 + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=10): + for cell in row: + cell.style = locals()[input2] + if cell.column == 10: + cell.border = Border(top=Side(border_style="double") ,bottom=Side(border_style="thin"), right=Side(border_style="double") ) + cell.fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + + + + valores = ["Nº DE ORDEM","BENEFICIÁRIO","CNPJ/CPF",'Vencimento / Tipo de Obrigação Patronal / Tipo de Benefício ','Equivalência na Relação de Itens Apoiados','Nº DO COMPROVANTE OU EQUIVALENTE',"DATA DO COMPROVANTE",'Nº DO CHEQUE OU EQUIVALENTE','DATA DA COMPENSAÇÃO DO CHEQUE','VALOR'] + col = 1 + for a,b in enumerate(valores): + worksheet.cell(row=linha_number, column=col, value=b) + col = col + 1 + + + #Aumentar a altura das celulas + for row in worksheet.iter_rows(min_row=15, max_row=size, min_col=1, max_col=10): + worksheet.row_dimensions[row[0].row].height = 60 + input3 = f'customNumber{nomeVariavel}' + + # MASCARA R$ + + locals()[input3] = NamedStyle(name=f'{input3}') + locals()[input3].number_format = 'R$ #,##0.00' + locals()[input3].font = Font(name="Arial", size=12, color="000000") + locals()[input3].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + value_to_stop = size + start_row = 10 + + #estilo mascara de dinheiro + for row in range(start_row,size+1): + cell = worksheet[f'j{row}'] + cell.style = locals()[input3] + + #estilocinzasimcinzanao + for rows in worksheet.iter_rows(min_row=16, max_row=size, min_col=1, max_col=10): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + + + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + + + if cell.column == 10: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + if cell.row == size: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + + #double em cima double total + + #bordinha double + stringAfinarCelula =size+2 + cellborda = f"J{size+1}" + bordacell = worksheet[cellborda] + bordacell.border = Border(right =Side(border_style="double")) + + + #subtotal + worksheet.row_dimensions[size+2].height = 6 + celulas_mergidas_subtotal = f"A{size+2}:I{size+2}" + worksheet.merge_cells(celulas_mergidas_subtotal) + left_celula_cell = f"A{size+2}" + top_left_cell = worksheet[left_celula_cell] + top_left_cell.value = "Sub Total1" + top_left_cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="double") ) + + worksheet.row_dimensions[size+2].height = 56.25 + + # FORMULATOTAL + formula = f"=SUM(J16:J{size})" + celula = f'J{size+2}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="double") ,bottom=Side(border_style="double") ) + worksheet[celula].number_format = 'R$ #,##0.00' + #restituições creditadas + restituicoes = size + 3 + celula_restituicoes=f'A{restituicoes}' + worksheet[celula_restituicoes].value = "RESTITUIÇÕES CREDITADAS" + worksheet[celula_restituicoes].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet.row_dimensions[restituicoes].height = 30 + + + input4 = f'row_style_diaria_append{nomeVariavel}' + #estilo colunas restitucoes creditadas + locals()[input4] = NamedStyle(name=f'{input4}') + locals()[input4].font = Font(name="Arial", size=12, color="000000",bold=True) + locals()[input4].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + locals()[input4].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input4].height = 30 + locals()[input4].border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"),right=Side(border_style='hair'),left=Side(border_style='hair') ) + + + row_number = size + 4 + + for column in range(1, 11): + cell = worksheet.cell(row=row_number, column=column) + cell.style = locals()[input4] + if cell.column == 10: + cell.border = Border(top=Side(border_style="double") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + + + + values = ["Nº DE ORDEM","RESTITUIDOR","CNPJ/CPF",'Vencimento / Tipo de Obrigação Patronal / Tipo de Benefício ','Equivalência na Relação de Itens Apoiados','Nº DO COMPROVANTE OU EQUIVALENTE',"DATA DO COMPROVANTE",'Nº DO CHEQUE OU EQUIVALENTE','DATA DA COMPENSAÇÃO DO CHEQUE','VALOR'] + coluna = 1 + for a,b in enumerate(values): + worksheet.cell(row=row_number, column=coluna, value=b) + coluna = coluna + 1 + + + + + #estorno + + for rows in worksheet.iter_rows(min_row=size+5, max_row=size+4+tamanhoestorno, min_col=1, max_col=10): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair")) + if cell.row == size+4+tamanhoestorno: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + if cell.column == 10: + cell.number_format = 'R$ #,##0.00' + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + if cell.row == size+4+tamanhoestorno: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + #bordas,corsimcornao,money + # Set the height of each row to 60 + for row in worksheet.iter_rows(min_row=size+4, max_row=size+4+tamanhoestorno): + worksheet.row_dimensions[row[0].row].height = 60 + + min_row = size + 4 + max_row = size + 4 + tamanhoestorno + + + + #bordinha double + stringAfinarCelula = size + 6 +tamanhoestorno + cellborda = f"J{size + 5 +tamanhoestorno}" + bordacell = worksheet[cellborda] + bordacell.border = Border(right =Side(border_style="double")) + + #subtotal2 + sub_total2_row = size + 6 +tamanhoestorno + subtotal_merge_cells= f'A{sub_total2_row}:I{sub_total2_row}' + worksheet.merge_cells(subtotal_merge_cells) + top_left_subtotal2_cell_formula = f'A{sub_total2_row}' + top_left_subtotal2_cell = worksheet[top_left_subtotal2_cell_formula] + top_left_subtotal2_cell.value = "Sub Total 2" + top_left_subtotal2_cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + top_left_subtotal2_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_subtotal2_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_subtotal2_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + sub_formula_row_celula = f'J{sub_total2_row}' + worksheet[sub_formula_row_celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[sub_formula_row_celula].value = f'=SUM(J{size+5}:J{sub_total2_row-1})' + worksheet[sub_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[sub_formula_row_celula].number_format = 'R$ #,##0.00' + worksheet[sub_formula_row_celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="double") ,bottom=Side(border_style="thin") ) + + #total1-2 + total12_row = size + 7 + tamanhoestorno + total12_merge_cells = f'A{total12_row}:I{total12_row}' + worksheet.merge_cells(total12_merge_cells) + top_left_total12_cell_formula = f'A{total12_row}' + top_left_total12_cell = worksheet[top_left_total12_cell_formula] + top_left_total12_cell.value = "Total(1-2)" + top_left_total12_cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + top_left_total12_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_total12_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_total12_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="thin") ) + + + #total_formula + total_formula_row = size + 7 + tamanhoestorno + total_formulaa = f'=J{size+2} - J{sub_total2_row }' + total_formula_row_celula = f'J{total_formula_row}' + worksheet[total_formula_row_celula].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet[total_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[total_formula_row_celula].number_format = 'R$ #,##0.00' + worksheet[total_formula_row_celula].border = Border(bottom=Side(border_style="double"),right=Side(border_style="double") ) + + worksheet.row_dimensions[total_formula_row].height = 30 + worksheet[total_formula_row_celula] = total_formulaa + + + size = size + 1 + #brasilia + brasilia_row = size + 8 +tamanhoestorno + brasilia_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:J{brasilia_row}' + worksheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.value = brasilia_formula + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_brasilia_cell.font = Font(name="Arial", size=12, color="000000") + #DiretorFinanceiro + diretor_row = size + 9 + tamanhoestorno + diretor_cargo_row = size + 10 + tamanhoestorno + diretor_cpf_row = size + 11 + tamanhoestorno + + diretor_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+3}" + diretor_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+4}" + diretor_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+5}" + diretor_merge_cells = f'A{diretor_row}:C{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:C{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:C{diretor_cpf_row}' + worksheet.merge_cells(diretor_merge_cells) + worksheet.merge_cells(diretor_cargo_merge_cells) + worksheet.merge_cells(diretor_cpf_merge_cells) + top_left_diretor_cell_formula = f'A{diretor_row}' + top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' + top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' + top_left_diretor_cell = worksheet[top_left_diretor_cell_formula] + top_left_diretor_cell_cargo_formula = worksheet[top_left_diretor_cell_cargo_formula] + top_left_diretor_cell_cpf_formula = worksheet[top_left_diretor_cell_cpf_formula] + top_left_diretor_cell.value = diretor_nome_formula + top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula + top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula + top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell.font = Font(bold=True) + top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + #Coordenadora + coordenadora_row = size + 9 + tamanhoestorno + coordenadora_cargo_row = size + 10 + tamanhoestorno + coordenadora_cpf_row = size + 11 + tamanhoestorno + coordenadora_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+3}" + coordenadora_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+4}" + coordenadora_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+5}" + coordenadora_merge_cells = f'F{coordenadora_row}:J{coordenadora_row}' + coordenadora_cargo_merge_cells = f'F{coordenadora_cargo_row}:J{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'F{coordenadora_cpf_row}:J{coordenadora_cpf_row}' + worksheet.merge_cells(coordenadora_merge_cells) + worksheet.merge_cells(coordenadora_cargo_merge_cells) + worksheet.merge_cells(coordenadora_cpf_merge_cells) + top_left_coordenadora_cell_formula = f'F{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'F{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'F{coordenadora_cpf_row}' + top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] + top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] + top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] + top_left_coordenadora_cell.value = coordenadora_nome_formula + top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula + top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) + top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") + top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") + + + # borda = Border(right=Side(border_style="medium")) + # worksheet.sheet_view.showGridLines = False + # # + # for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=9): + # for cell in row: + # cell.border = borda + + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=10, max_col=10): + for cell in row: + cell.border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"), right=Side(border_style="double") ) + cell.fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + + cinzaborda = '9e9e9e' + + #borda cabeçario + for row in worksheet.iter_rows(min_row=1, max_row=14,min_col=10,max_col=10): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + #borda fim pagina + for row in worksheet.iter_rows(min_row=brasilia_row-1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=10): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + + + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=10): + for cell in row: + if cell.column == 10: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) + + workbook.save(tabela) + workbook.close() + + return size+4 + +def estiloElementoDeDespesa1415Diarias(tabela,tamanho,stringTamanho,tamanhoestorno): + '''Esse estilo e considerado geral por que todas as tabelas que compõe utilizam das mesma colunas. + + Argumentos: + tabela: recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo ja foi iniciado e passou pela preencher fub mas ainda esta sem o estilo que sera aplicado nessa função. + tamanho: e o tamanho total de linhas que irao ser geradas dinamicamente correspondente as entradas do respectivo projeto. o valor varia dentre o tamanho das rubricas + + nomeVariavel: variável utilizada para criar o nomes das variaveis dinamicamente para não haver sobreposição de estilos com o mesmo nome. Esses estilos ocorrem nesses codigos: + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid"'.... + nomeTabela: variável utilizada para a criação do nome da tabela.Ela deriva das rubricas que são colocadas no input quando essa função e chamada. + stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referencias das formulas. + + ''' + if tamanho == 0: + tamanho = 1 + + + nomeVariavel = f'Diaria' + nomeSheet=nomeVariavel + random_number = random.randint(1, 10000) + nomeVariavel = f'{nomeVariavel}{random_number}' + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + worksheet = workbook['Elemento de Despesa 14.15'] + size = tamanho + 16 + cinza = "d9d9d9" + cinza_escuro = "bfbfbf" + azul = "336394" + azul_claro = 'ccffff' + + + # borda = Border(right=Side(border_style="medium")) + worksheet.sheet_view.showGridLines = False + # + # for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda + + + worksheet.column_dimensions['a'].width = 45 + worksheet.column_dimensions['b'].width = 35 + worksheet.column_dimensions['c'].width = 35 + worksheet.column_dimensions['d'].width = 45#descrição + worksheet.column_dimensions['e'].width = 45 #n do recibo ou qeuivalente + worksheet.column_dimensions['f'].width = 35 #data de emissão + worksheet.column_dimensions['g'].width = 35 #data de emissão + worksheet.column_dimensions['h'].width = 35 #data de emissão + worksheet.column_dimensions['i'].width = 35 #data de emissão + worksheet.column_dimensions['j'].width = 35 #data de emissão + worksheet.column_dimensions['k'].width = 35 #data de emissão + worksheet.column_dimensions['l'].width = 35 #data de emissão + + + #cabecario relação de pagamentos - outro servicoes de terceiros + worksheet.merge_cells('A1:L1') + worksheet['A1'] = f'ANEXO 4' + worksheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + #RELAÇÃO DE PAGAMENTOS + worksheet.merge_cells('A2:L2') + + worksheet['A2'] = f'RELAÇÃO DE PAGAMENTOS' + worksheet['A2'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A2'].alignment = Alignment(horizontal="center",vertical="center") + + #ElementosdeDespesa + + + worksheet['A11'] = f'Elemento de Despesa' + worksheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A11'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #ElementosdeDespesa + + + worksheet['A14'] = f'DESPESAS REALIZADAS' + worksheet['A14'].font = Font(name="Arial", size=12, color="000000",bold=True,italic=True) + worksheet['A14'].alignment = Alignment(horizontal="center",vertical="center") + + + + #cabecario que recebe de referencia as celulas A da planilha DEMOSTR. RECEITA E DESPESA A.2 + + + worksheet['A4'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A4" + worksheet['A4'].font = Font(name="Arial", size=12, color="000000") + worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A5" + worksheet['A5'].font = Font(name="Arial", size=12, color="000000") + worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A6" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000") + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A7" + worksheet['A7'].font = Font(name="Arial", size=12, color="000000") + worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A8" + worksheet['A8'].font = Font(name="Arial", size=12, color="000000") + worksheet['A8'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A9" + worksheet['A9'].font = Font(name="Arial", size=12, color="000000") + worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center") + + + + #cabecario que recebe de referencia as celulas C da planilha DEMOSTR. RECEITA E DESPESA A.2 + + worksheet['C5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C5" + worksheet['C5'].font = Font(name="Arial", size=12, color="000000") + worksheet['C5'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C6" + worksheet['C6'].font = Font(name="Arial", size=12, color="000000") + worksheet['C6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C7" + worksheet['C7'].font = Font(name="Arial", size=12, color="000000") + worksheet['C7'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C8" + worksheet['C8'].font = Font(name="Arial", size=12, color="000000") + worksheet['C8'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C9" + worksheet['C9'].font = Font(name="Arial", size=12, color="000000") + worksheet['C9'].alignment = Alignment(horizontal="left",vertical="center") + + #variavel + + input2=f'rowStyle{nomeVariavel}' + + + #colunas azul cabecario + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="000000",bold=True) + locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input2].border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"), right=Side(border_style="hair"),left=Side(border_style='hair') ) + locals()[input2].height = 20 + + linha_number = 15 + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=12): + for cell in row: + cell.style = locals()[input2] + if cell.column == 12: + cell.border = Border(top=Side(border_style="double") ,bottom=Side(border_style="thin"), right=Side(border_style="double") ) + cell.fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + + + + valores = ["Nº DE ORDEM","BENEFICIÁRIO","CNPJ/CPF",'Destino','Nº DE DIÁRIAS UTILIZADAS','Evento',"Equivalência na Relação de Itens Apoiados",'Nº DO RECIBO OU EQUIVALENTE','DATA DO RECIBO','Nº DO CHEQUE OU EQUIVALENTE','DATA DA COMPENSAÇÃO DO CHEQUE','VALOR'] + col = 1 + for a,b in enumerate(valores): + worksheet.cell(row=linha_number, column=col, value=b) + col = col + 1 + + + #Aumentar a altura das celulas + for row in worksheet.iter_rows(min_row=15, max_row=size, min_col=1, max_col=12): + worksheet.row_dimensions[row[0].row].height = 60 + input3 = f'customNumber{nomeVariavel}' + + # MASCARA R$ + + locals()[input3] = NamedStyle(name=f'{input3}') + locals()[input3].number_format = 'R$ #,##0.00' + locals()[input3].font = Font(name="Arial", size=12, color="000000") + locals()[input3].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + value_to_stop = size + start_row = 10 + + #estilo mascara de dinheiro + for row in range(start_row,size+1): + cell = worksheet[f'L{row}'] + cell.style = locals()[input3] + + #estilocinzasimcinzanao + for rows in worksheet.iter_rows(min_row=16, max_row=size, min_col=1, max_col=12): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + + + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + + + if cell.column == 12: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + if cell.row == size: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + + #double em cima double total + + #bordinha double + stringAfinarCelula =size+2 + cellborda = f"L{size+1}" + bordacell = worksheet[cellborda] + bordacell.border = Border(right =Side(border_style="double")) + + + #subtotal + worksheet.row_dimensions[size+2].height = 6 + celulas_mergidas_subtotal = f"A{size+2}:K{size+2}" + worksheet.merge_cells(celulas_mergidas_subtotal) + left_celula_cell = f"A{size+2}" + top_left_cell = worksheet[left_celula_cell] + top_left_cell.value = "Sub Total1" + top_left_cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="double") ) + + worksheet.row_dimensions[size+2].height = 56.25 + + # FORMULATOTAL + formula = f"=SUM(L16:L{size})" + celula = f'L{size+2}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="double") ,bottom=Side(border_style="double") ) + worksheet[celula].number_format = 'R$ #,##0.00' + #restituições creditadas + restituicoes = size + 3 + celula_restituicoes=f'A{restituicoes}' + worksheet[celula_restituicoes].value = "RESTITUIÇÕES CREDITADAS" + worksheet[celula_restituicoes].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet.row_dimensions[restituicoes].height = 30 + + + input4 = f'row_style_diaria_append{nomeVariavel}' + #estilo colunas restitucoes creditadas + locals()[input4] = NamedStyle(name=f'{input4}') + locals()[input4].font = Font(name="Arial", size=12, color="000000",bold=True) + locals()[input4].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + locals()[input4].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input4].height = 30 + locals()[input4].border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"),right=Side(border_style='hair'),left=Side(border_style='hair') ) + + + row_number = size + 4 + + for column in range(1, 13): + cell = worksheet.cell(row=row_number, column=column) + cell.style = locals()[input4] + if cell.column == 12: + cell.border = Border(top=Side(border_style="double") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + + + + values = ["Nº DE ORDEM","RESTITUIDOR","CNPJ/CPF","Destino",'Nº DE DIÁRIAS UTILIZADAS','Evento','Equivalência na Relação de Itens Apoiados',"CHEQUE OU EQUIVALENTE ESTORNADO",'DATA DO CHEQUE','Nº DO DEPÓSITO','DATA DO DEPÓSITO','VALOR'] + coluna = 1 + for a,b in enumerate(values): + worksheet.cell(row=row_number, column=coluna, value=b) + coluna = coluna + 1 + + + + + #estorno + + for rows in worksheet.iter_rows(min_row=size+5, max_row=size+4+tamanhoestorno, min_col=1, max_col=12): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair")) + if cell.row == size+4+tamanhoestorno: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + if cell.column == 12: + cell.number_format = 'R$ #,##0.00' + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + if cell.row == size+4+tamanhoestorno: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + #bordas,corsimcornao,money + # Set the height of each row to 60 + for row in worksheet.iter_rows(min_row=size+4, max_row=size+4+tamanhoestorno): + worksheet.row_dimensions[row[0].row].height = 60 + + min_row = size + 4 + max_row = size + 4 + tamanhoestorno + + + + #bordinha double + stringAfinarCelula = size + 6 +tamanhoestorno + cellborda = f"L{size + 5 +tamanhoestorno}" + bordacell = worksheet[cellborda] + bordacell.border = Border(right =Side(border_style="double")) + + #subtotal2 + sub_total2_row = size + 6 +tamanhoestorno + subtotal_merge_cells= f'A{sub_total2_row}:K{sub_total2_row}' + worksheet.merge_cells(subtotal_merge_cells) + top_left_subtotal2_cell_formula = f'A{sub_total2_row}' + top_left_subtotal2_cell = worksheet[top_left_subtotal2_cell_formula] + top_left_subtotal2_cell.value = "Sub Total 2" + top_left_subtotal2_cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + top_left_subtotal2_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_subtotal2_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_subtotal2_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + sub_formula_row_celula = f'L{sub_total2_row}' + worksheet[sub_formula_row_celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[sub_formula_row_celula].value = f'=SUM(L{size+5}:L{sub_total2_row-1})' + worksheet[sub_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[sub_formula_row_celula].number_format = 'R$ #,##0.00' + worksheet[sub_formula_row_celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="double") ,bottom=Side(border_style="thin") ) + + #total1-2 + total12_row = size + 7 + tamanhoestorno + total12_merge_cells = f'A{total12_row}:K{total12_row}' + worksheet.merge_cells(total12_merge_cells) + top_left_total12_cell_formula = f'A{total12_row}' + top_left_total12_cell = worksheet[top_left_total12_cell_formula] + top_left_total12_cell.value = "Total(1-2)" + top_left_total12_cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + top_left_total12_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_total12_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_total12_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="thin") ) + + + #total_formula + total_formula_row = size + 7 + tamanhoestorno + total_formulaa = f'=L{size+2} - L{sub_total2_row }' + total_formula_row_celula = f'L{total_formula_row}' + worksheet[total_formula_row_celula].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet[total_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[total_formula_row_celula].number_format = 'R$ #,##0.00' + worksheet[total_formula_row_celula].border = Border(bottom=Side(border_style="double"),right=Side(border_style="double") ) + + worksheet.row_dimensions[total_formula_row].height = 30 + worksheet[total_formula_row_celula] = total_formulaa + + + size = size + 1 + #brasilia + brasilia_row = size + 8 +tamanhoestorno + brasilia_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:L{brasilia_row}' + worksheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.value = brasilia_formula + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_brasilia_cell.font = Font(name="Arial", size=12, color="000000") + + #DiretorFinanceiro + diretor_row = size + 9 + tamanhoestorno + diretor_cargo_row = size + 10 + tamanhoestorno + diretor_cpf_row = size + 11 + tamanhoestorno + + diretor_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+3}" + diretor_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+4}" + diretor_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+5}" + diretor_merge_cells = f'A{diretor_row}:F{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:F{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:F{diretor_cpf_row}' + worksheet.merge_cells(diretor_merge_cells) + worksheet.merge_cells(diretor_cargo_merge_cells) + worksheet.merge_cells(diretor_cpf_merge_cells) + top_left_diretor_cell_formula = f'A{diretor_row}' + top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' + top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' + top_left_diretor_cell = worksheet[top_left_diretor_cell_formula] + top_left_diretor_cell_cargo_formula = worksheet[top_left_diretor_cell_cargo_formula] + top_left_diretor_cell_cpf_formula = worksheet[top_left_diretor_cell_cpf_formula] + top_left_diretor_cell.value = diretor_nome_formula + top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula + top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula + top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell.font = Font(bold=True) + top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + #Coordenadora + coordenadora_row = size + 9 + tamanhoestorno + coordenadora_cargo_row = size + 10 + tamanhoestorno + coordenadora_cpf_row = size + 11 + tamanhoestorno + coordenadora_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+3}" + coordenadora_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+4}" + coordenadora_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+5}" + coordenadora_merge_cells = f'G{coordenadora_row}:L{coordenadora_row}' + coordenadora_cargo_merge_cells = f'G{coordenadora_cargo_row}:L{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'G{coordenadora_cpf_row}:L{coordenadora_cpf_row}' + worksheet.merge_cells(coordenadora_merge_cells) + worksheet.merge_cells(coordenadora_cargo_merge_cells) + worksheet.merge_cells(coordenadora_cpf_merge_cells) + top_left_coordenadora_cell_formula = f'G{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'G{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'G{coordenadora_cpf_row}' + top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] + top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] + top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] + top_left_coordenadora_cell.value = coordenadora_nome_formula + top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula + top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) + top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") + top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") + + + # borda = Border(right=Side(border_style="medium")) + # worksheet.sheet_view.showGridLines = False + # # + # for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=9): + # for cell in row: + # cell.border = borda + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=12, max_col=12): + for cell in row: + cell.border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"), right=Side(border_style="double") ) + cell.fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + + cinzaborda = '9e9e9e' - for row in sheet.iter_rows(min_row=1,max_row=coordenadora_cpf_row,min_col=10,max_col=10): + #borda cabeçario + for row in worksheet.iter_rows(min_row=1, max_row=14,min_col=12,max_col=12): for cell in row: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="none") ) - - for row in sheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=10): + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + #borda fim pagina + for row in worksheet.iter_rows(min_row=brasilia_row-1, max_row=coordenadora_cpf_row+1,min_col=12,max_col=12): for cell in row: - if cell.column == 10: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) - else: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) - - # #deixar azul a letra de receita - # cell=sheet['E16'] - # cell.font = Font(name="Arial", size=12,color="0000FF") - # #deixar VERMELHO a letra de receita - # cell=sheet[f'E{17}'] - # cell.font = Font(name="Arial", size=12,color="FF0000") + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + - # cell=sheet[f'E{18}'] - # cell.font = Font(name="Arial", size=12,color="FF0000") + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=12): + for cell in row: + if cell.column == 12: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) workbook.save(tabela) workbook.close() - # print(f'printandosize2') - # print(size2) - #retorna tamanho de brasilia e de equipamentos - return size2 + 16,size+3 + return size+4 -def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): +def estiloElementoDeDespesa33PassagensEDespesa(tabela,tamanho,stringTamanho,tamanhoestorno): '''Esse estilo e considerado geral por que todas as tabelas que compõe utilizam das mesma colunas. Argumentos: @@ -943,120 +2485,148 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referencias das formulas. ''' - + if tamanho == 0: + tamanho = 1 + + nomeVariavel = f'Diaria' nomeSheet=nomeVariavel random_number = random.randint(1, 10000) nomeVariavel = f'{nomeVariavel}{random_number}' caminho = pegar_caminho(tabela) workbook = openpyxl.load_workbook(caminho) - worksheet = workbook[nomeTabela] - size = tamanho + 10 + worksheet = workbook['Elemento de Despesa 33'] + size = tamanho + 16 cinza = "d9d9d9" cinza_escuro = "bfbfbf" azul = "336394" azul_claro = 'ccffff' + - borda = Border(right=Side(border_style="medium")) + # borda = Border(right=Side(border_style="medium")) worksheet.sheet_view.showGridLines = False # - for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): - for cell in row: - cell.border = borda + # for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda - worksheet.column_dimensions['a'].width = 25 - worksheet.column_dimensions['b'].width = 25 + worksheet.column_dimensions['a'].width = 45 + worksheet.column_dimensions['b'].width = 35 worksheet.column_dimensions['c'].width = 35 - worksheet.column_dimensions['d'].width = 35#descrição - worksheet.column_dimensions['e'].width = 65 #n do recibo ou qeuivalente - worksheet.column_dimensions['f'].width = 25 #data de emissão - worksheet.column_dimensions['g'].width = 25 #data de emissão - worksheet.column_dimensions['h'].width = 25 #data de emissão - worksheet.column_dimensions['i'].width = 25 #data de emissão - worksheet.column_dimensions['j'].width = 25 #data de emissão + worksheet.column_dimensions['d'].width = 45#descrição + worksheet.column_dimensions['e'].width = 45 #n do recibo ou qeuivalente + worksheet.column_dimensions['f'].width = 35 #data de emissão + worksheet.column_dimensions['g'].width = 35 #data de emissão + worksheet.column_dimensions['h'].width = 35 #data de emissão + worksheet.column_dimensions['i'].width = 35 #data de emissão + worksheet.column_dimensions['j'].width = 35 #data de emissão + worksheet.column_dimensions['k'].width = 35 #data de emissão + worksheet.column_dimensions['l'].width = 35 #data de emissão #cabecario relação de pagamentos - outro servicoes de terceiros - worksheet.merge_cells('A1:J2') - nomeTabela = nomeTabela.upper() - worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - {nomeTabela}' - - # if nomeSheet == "diarias": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - DIÁRIAS' - # elif nomeSheet == "pessoaFisica": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - OUTROS SERVIÇOS DE TERCEIROS - PF' - # elif nomeSheet == "pessoaJuridica": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - OUTROS SERVIÇOS DE TERCEIROS - PESSOA JURÍDICA' - # elif nomeSheet == "passagenDespLocomo": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - PASSAGENS E DESPESAS COM LOCOMOÇÃO' - # elif nomeSheet == "outrosServiçosTerceiros": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - O U T R O S S E R V I Ç O S D E T E R C E I R O S - C E L E T I S T A S' - # elif nomeSheet == "auxilio": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - AUXÍLIO FINANCEIRO A ESTUDANTE E PESQUISADOR' - # elif nomeSheet == "bolsaExtensao": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - BOLSA DE EXTENSÃO' - # elif nomeSheet == "estagiario": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - ESTAGIÁRIO' - # elif nomeSheet == "custosIndiretos": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - CUSTOS INDIRETOS - FUB' - # elif nomeSheet == "materialDeConsumo": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - MATERIAL DE CONSUMO' - # elif nomeSheet == "equipamentoMaterialPermanente": - # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - EQUIPAMENTO E MATERIAL PERMANENTE' - # elif nomeSheet == "isss": - # worksheet['A1'] = f'ISS 5% e ISS 2%' - - - - worksheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet.merge_cells('A1:L1') + worksheet['A1'] = f'ANEXO 4' + worksheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + #RELAÇÃO DE PAGAMENTOS + worksheet.merge_cells('A2:L2') - worksheet.merge_cells('A3:J3') - worksheet['A3'] = "='Receita x Despesa'!A3:J3" - worksheet['A3'].font = Font(name="Arial", size=12, color="000000") - worksheet['A3'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A2'] = f'RELAÇÃO DE PAGAMENTOS' + worksheet['A2'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A2'].alignment = Alignment(horizontal="center",vertical="center") - worksheet.merge_cells('A4:J4') - worksheet['A4'] = "='Receita x Despesa'!A4:J4" + #ElementosdeDespesa + + + worksheet['A11'] = f'Elemento de Despesa' + worksheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A11'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #ElementosdeDespesa + + + worksheet['A14'] = f'DESPESAS REALIZADAS' + worksheet['A14'].font = Font(name="Arial", size=12, color="000000",bold=True,italic=True) + worksheet['A14'].alignment = Alignment(horizontal="center",vertical="center") + + + + #cabecario que recebe de referencia as celulas A da planilha DEMOSTR. RECEITA E DESPESA A.2 + + + worksheet['A4'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A4" worksheet['A4'].font = Font(name="Arial", size=12, color="000000") worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A5:J5') - worksheet['A5'] = "='Receita x Despesa'!A5:J5" + worksheet['A5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A5" worksheet['A5'].font = Font(name="Arial", size=12, color="000000") worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") - - worksheet.merge_cells('A6:J6') - worksheet['A6'] = "='Receita x Despesa'!A6:J6" + + worksheet['A6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A6" worksheet['A6'].font = Font(name="Arial", size=12, color="000000") worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A7:J7') - worksheet['A7'] = "='Receita x Despesa'!A7:J7" + worksheet['A7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A7" worksheet['A7'].font = Font(name="Arial", size=12, color="000000") worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") - #variavel + worksheet['A8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A8" + worksheet['A8'].font = Font(name="Arial", size=12, color="000000") + worksheet['A8'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A9" + worksheet['A9'].font = Font(name="Arial", size=12, color="000000") + worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center") + + + + #cabecario que recebe de referencia as celulas C da planilha DEMOSTR. RECEITA E DESPESA A.2 + + worksheet['C5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C5" + worksheet['C5'].font = Font(name="Arial", size=12, color="000000") + worksheet['C5'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C6" + worksheet['C6'].font = Font(name="Arial", size=12, color="000000") + worksheet['C6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C7" + worksheet['C7'].font = Font(name="Arial", size=12, color="000000") + worksheet['C7'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C8" + worksheet['C8'].font = Font(name="Arial", size=12, color="000000") + worksheet['C8'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C9" + worksheet['C9'].font = Font(name="Arial", size=12, color="000000") + worksheet['C9'].alignment = Alignment(horizontal="left",vertical="center") + + #variavel input2=f'rowStyle{nomeVariavel}' #colunas azul cabecario locals()[input2] = NamedStyle(name=f'{input2}') - locals()[input2].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input2].font = Font(name="Arial", size=12, color="000000",bold=True) locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - locals()[input2].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="thin") ) + locals()[input2].border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"), right=Side(border_style="hair"),left=Side(border_style='hair') ) locals()[input2].height = 20 - linha_number = 9 - for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=10): + + linha_number = 15 + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=12): for cell in row: cell.style = locals()[input2] - if cell.column == 10: - cell.border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="thin"), right=Side(border_style="medium") ) + if cell.column == 12: + cell.border = Border(top=Side(border_style="double") ,bottom=Side(border_style="thin"), right=Side(border_style="double") ) + cell.fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - valores = ["ITEM","NOME","CNPJ/CPF",'ESPECIFICAÇÃO DA DESPESA','DESCRIÇÃO',"Nº DO RECIBO OU EQUIVALENTE","DATA DE EMISSÃO",'CHEQUE / ORDEM BANCÁRIA','DATA DE PGTO','Valor'] + + + valores = ["Nº DE ORDEM","CREDOR","CNPJ/CPF",'BENEFICIÁRIO','CPF DO BENEFICIÁRIO','TRECHO',"Equivalência na Relação de Itens Apoiados",'Nº DA NOTA FISCAL OU EQUIVALENTE','DATA DA NOTA FISCAL','Nº DO CHEQUE OU EQUIVALENTE','DATA DA COMPENSAÇÃO DO CHEQUE','VALOR'] col = 1 for a,b in enumerate(valores): worksheet.cell(row=linha_number, column=col, value=b) @@ -1064,7 +2634,7 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): #Aumentar a altura das celulas - for row in worksheet.iter_rows(min_row=10, max_row=size, min_col=1, max_col=10): + for row in worksheet.iter_rows(min_row=15, max_row=size, min_col=1, max_col=12): worksheet.row_dimensions[row[0].row].height = 60 input3 = f'customNumber{nomeVariavel}' @@ -1075,33 +2645,48 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): locals()[input3].font = Font(name="Arial", size=12, color="000000") locals()[input3].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - #estilocinzasimcinzanao + value_to_stop = size start_row = 10 -# + + #estilo mascara de dinheiro for row in range(start_row,size+1): - cell = worksheet[f'J{row}'] + cell = worksheet[f'L{row}'] cell.style = locals()[input3] - - for rows in worksheet.iter_rows(min_row=9, max_row=size, min_col=1, max_col=10): + + #estilocinzasimcinzanao + for rows in worksheet.iter_rows(min_row=16, max_row=size, min_col=1, max_col=12): for cell in rows: if cell.row % 2: cell.fill = PatternFill(start_color=cinza, end_color=cinza, fill_type = "solid") - if cell.column == 10: - cell.font = Font(name="Arial", size=12, color="000000") - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) - else: + + + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + + + if cell.column == 12: cell.font = Font(name="Arial", size=12, color="000000") cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + if cell.row == size: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) - - #subtotal + #double em cima double total + + #bordinha double stringAfinarCelula =size+2 + cellborda = f"L{size+1}" + bordacell = worksheet[cellborda] + bordacell.border = Border(right =Side(border_style="double")) + + + #subtotal worksheet.row_dimensions[size+2].height = 6 - celulas_mergidas_subtotal = f"A{size+2}:I{size+2}" + celulas_mergidas_subtotal = f"A{size+2}:K{size+2}" worksheet.merge_cells(celulas_mergidas_subtotal) left_celula_cell = f"A{size+2}" top_left_cell = worksheet[left_celula_cell] @@ -1109,17 +2694,17 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): top_left_cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) top_left_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="medium") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + top_left_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="double") ) worksheet.row_dimensions[size+2].height = 56.25 # FORMULATOTAL - formula = f"=SUM(J10:J{size})" - celula = f'J{size+2}' + formula = f"=SUM(L16:L{size})" + celula = f'L{size+2}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet[celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + worksheet[celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="double") ,bottom=Side(border_style="double") ) worksheet[celula].number_format = 'R$ #,##0.00' #restituições creditadas restituicoes = size + 3 @@ -1132,39 +2717,71 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): input4 = f'row_style_diaria_append{nomeVariavel}' #estilo colunas restitucoes creditadas locals()[input4] = NamedStyle(name=f'{input4}') - locals()[input4].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input4].font = Font(name="Arial", size=12, color="000000",bold=True) locals()[input4].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') locals()[input4].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) locals()[input4].height = 30 - locals()[input4].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="medium") ) + locals()[input4].border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"),right=Side(border_style='hair'),left=Side(border_style='hair') ) row_number = size + 4 - for column in range(1, 11): + for column in range(1, 13): cell = worksheet.cell(row=row_number, column=column) cell.style = locals()[input4] - if cell.column == 10: - cell.border = Border(top=Side(border_style="medium") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + if cell.column == 12: + cell.border = Border(top=Side(border_style="double") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) - - values = ["Item","Restituidor","CNPJ/CPF",'Descrição',"Cheque equivalente","Data do Cheque",'Nº do Depósito','Data da Devolução','Valor'] + # A B C D E F G H I J K L + values = ["Nº DE ORDEM","RESTITUIDOR","CNPJ/CPF","BENEFICIÁRIO",'CPF DO BENEFICIÁRIO','TRECHO',"Equivalência na Relação de Itens Apoiados","CHEQUE OU EQUIVALENTE ESTORNADO",'DATA DO CHEQUE','Nº DO DEPÓSITO','DATA DO DEPÓSITO','VALOR'] coluna = 1 for a,b in enumerate(values): worksheet.cell(row=row_number, column=coluna, value=b) - if coluna == 4: - coluna = coluna + 1 coluna = coluna + 1 - merge_formula = f'D{row_number}:E{row_number}' - worksheet.merge_cells(merge_formula) + + + #estorno + + for rows in worksheet.iter_rows(min_row=size+5, max_row=size+4+tamanhoestorno, min_col=1, max_col=12): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair")) + if cell.row == size+4+tamanhoestorno: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair")) + + if cell.column == 12: + cell.number_format = 'R$ #,##0.00' + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair")) + if cell.row == size+4+tamanhoestorno: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair")) + + + + #bordas,corsimcornao,money + # Set the height of each row to 60 + for row in worksheet.iter_rows(min_row=size+4, max_row=size+4+tamanhoestorno): + worksheet.row_dimensions[row[0].row].height = 60 + + min_row = size + 4 + max_row = size + 4 + tamanhoestorno + + + + #bordinha double + stringAfinarCelula = size + 6 +tamanhoestorno + cellborda = f"L{size + 5 +tamanhoestorno}" + bordacell = worksheet[cellborda] + bordacell.border = Border(right =Side(border_style="double")) - #subtotal2 - sub_total2_row = size + 5 - subtotal_merge_cells= f'A{sub_total2_row}:I{sub_total2_row}' + sub_total2_row = size + 6 +tamanhoestorno + subtotal_merge_cells= f'A{sub_total2_row}:K{sub_total2_row}' worksheet.merge_cells(subtotal_merge_cells) top_left_subtotal2_cell_formula = f'A{sub_total2_row}' top_left_subtotal2_cell = worksheet[top_left_subtotal2_cell_formula] @@ -1172,17 +2789,19 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): top_left_subtotal2_cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") top_left_subtotal2_cell.font = Font(name="Arial", size=12, color="000000",bold=True) top_left_subtotal2_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_subtotal2_cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="medium") ,right =Side(border_style="hair") ,bottom=Side(border_style="medium") ) + top_left_subtotal2_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) - sub_formula_row_celula = f'J{sub_total2_row}' + sub_formula_row_celula = f'L{sub_total2_row}' worksheet[sub_formula_row_celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[sub_formula_row_celula].value = f'=SUM(L{size+5}:L{sub_total2_row-1})' + worksheet[sub_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) worksheet[sub_formula_row_celula].number_format = 'R$ #,##0.00' - worksheet[sub_formula_row_celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + worksheet[sub_formula_row_celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="double") ,bottom=Side(border_style="thin") ) #total1-2 - total12_row = size + 6 - total12_merge_cells = f'A{total12_row}:I{total12_row}' + total12_row = size + 7 + tamanhoestorno + total12_merge_cells = f'A{total12_row}:K{total12_row}' worksheet.merge_cells(total12_merge_cells) top_left_total12_cell_formula = f'A{total12_row}' top_left_total12_cell = worksheet[top_left_total12_cell_formula] @@ -1190,44 +2809,45 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): top_left_total12_cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") top_left_total12_cell.font = Font(name="Arial", size=12, color="000000",bold=True) top_left_total12_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_total12_cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="medium") ,bottom=Side(border_style="medium") ) + top_left_total12_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="hair") ,bottom=Side(border_style="double"),right=Side(border_style="thin") ) #total_formula - total_formula_row = size + 6 - total_formulaa = f'=J{size+2}' - total_formula_row_celula = f'J{total_formula_row}' + total_formula_row = size + 7 + tamanhoestorno + total_formulaa = f'=L{size+2} - L{sub_total2_row }' + total_formula_row_celula = f'L{total_formula_row}' worksheet[total_formula_row_celula].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") worksheet[total_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) worksheet[total_formula_row_celula].number_format = 'R$ #,##0.00' - worksheet[total_formula_row_celula].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="medium"),right=Side(border_style="medium") ) + worksheet[total_formula_row_celula].border = Border(bottom=Side(border_style="double"),right=Side(border_style="double") ) worksheet.row_dimensions[total_formula_row].height = 30 worksheet[total_formula_row_celula] = total_formulaa - + size = size + 1 #brasilia - brasilia_row = size + 7 - brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:J{stringTamanho}" - brasilia_merge_cells = f'A{brasilia_row}:I{brasilia_row}' + brasilia_row = size + 8 +tamanhoestorno + brasilia_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:K{brasilia_row}' worksheet.merge_cells(brasilia_merge_cells) top_left_brasilia_cell_formula = f'A{brasilia_row}' top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] top_left_brasilia_cell.value = brasilia_formula top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_brasilia_cell.font = Font(name="Arial", size=12, color="000000") #DiretorFinanceiro - diretor_row = size + 8 - diretor_cargo_row = size + 9 - diretor_cpf_row = size + 10 + diretor_row = size + 9 + tamanhoestorno + diretor_cargo_row = size + 10 + tamanhoestorno + diretor_cpf_row = size + 11 + tamanhoestorno - diretor_nome_formula = f"='Receita x Despesa'!A{stringTamanho+3}" - diretor_cargo_formula = f"='Receita x Despesa'!A{stringTamanho+4}" - diretor_cpf_formula = f"='Receita x Despesa'!A{stringTamanho+5}" - diretor_merge_cells = f'A{diretor_row}:D{diretor_row}' - diretor_cargo_merge_cells = f'A{diretor_cargo_row}:D{diretor_cargo_row}' - diretor_cpf_merge_cells = f'A{diretor_cpf_row}:D{diretor_cpf_row}' + diretor_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+3}" + diretor_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+4}" + diretor_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+5}" + diretor_merge_cells = f'A{diretor_row}:F{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:F{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:F{diretor_cpf_row}' worksheet.merge_cells(diretor_merge_cells) worksheet.merge_cells(diretor_cargo_merge_cells) worksheet.merge_cells(diretor_cpf_merge_cells) @@ -1245,21 +2865,21 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") #Coordenadora - coordenadora_row = size + 8 - coordenadora_cargo_row = size + 9 - coordenadora_cpf_row = size + 10 - coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" - coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" - coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" - coordenadora_merge_cells = f'F{coordenadora_row}:J{coordenadora_row}' - coordenadora_cargo_merge_cells = f'F{coordenadora_cargo_row}:J{coordenadora_cargo_row}' - coordenadora_cpf_merge_cells = f'F{coordenadora_cpf_row}:J{coordenadora_cpf_row}' + coordenadora_row = size + 9 + tamanhoestorno + coordenadora_cargo_row = size + 10 + tamanhoestorno + coordenadora_cpf_row = size + 11 + tamanhoestorno + coordenadora_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+3}" + coordenadora_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+4}" + coordenadora_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+5}" + coordenadora_merge_cells = f'G{coordenadora_row}:L{coordenadora_row}' + coordenadora_cargo_merge_cells = f'G{coordenadora_cargo_row}:L{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'G{coordenadora_cpf_row}:L{coordenadora_cpf_row}' worksheet.merge_cells(coordenadora_merge_cells) worksheet.merge_cells(coordenadora_cargo_merge_cells) worksheet.merge_cells(coordenadora_cpf_merge_cells) - top_left_coordenadora_cell_formula = f'F{coordenadora_row}' - top_left_coordenadora_cell_cargo_formula = f'F{coordenadora_cargo_row}' - top_left_coordenadora_cell_cpf_formula = f'F{coordenadora_cpf_row}' + top_left_coordenadora_cell_formula = f'G{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'G{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'G{coordenadora_cpf_row}' top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] @@ -1269,28 +2889,50 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") # borda = Border(right=Side(border_style="medium")) # worksheet.sheet_view.showGridLines = False # # - # for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=10): + # for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=9): # for cell in row: # cell.border = borda - + + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=12, max_col=12): + for cell in row: + cell.border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair"), right=Side(border_style="double") ) + cell.fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + + cinzaborda = '9e9e9e' + #borda cabeçario + for row in worksheet.iter_rows(min_row=1, max_row=14,min_col=12,max_col=12): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) - for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=10): + #borda fim pagina + for row in worksheet.iter_rows(min_row=brasilia_row -1, max_row=coordenadora_cpf_row+1,min_col=12,max_col=12): for cell in row: - if cell.column == 10: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + + + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=12): + for cell in row: + if cell.column == 12: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) else: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) workbook.save(tabela) workbook.close() + return size+4 + def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): """Estilo um pouco diferente pois necessita de dois aspectos dinâmicos que é primeiramente a quantidade de entradas de pagamento de tarifas bancárias e por fim a quantidade de estorno. Sabendo esses valores é possivel criar a tabela. @@ -1301,94 +2943,168 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): tamanho2:Corresponde ao tamanho dos estornos. stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referências das formulas. """ - + if tamanho == 0: + tamanho = 1 + #pegar o arquivo e carregar ele um worksheet da pagaina Conciliação Bancária caminho = pegar_caminho(tabela) workbook = openpyxl.load_workbook(caminho) - worksheet = workbook['Conciliação Bancária'] + worksheet = workbook['Conciliação Bancária A.3'] - - size = tamanho + 16 - #worksheet.row_dimensions[27].height = 50 + #size e o tamanho da quantidade de arquivos recebido no argumento tamanho mais o tamanho do cabecario que no caso da fub e de 16 + size = tamanho + 18 cinza = "d9d9d9" cinza_escuro = "bfbfbf" - azul = "336394" - azul_claro = '1c8cbc' + azul_claro = 'ccffff' + + #Borda apenas do lado direito da cedula, uma borda mas larga borda = Border(right=Side(border_style="medium")) worksheet.sheet_view.showGridLines = False # - worksheet.column_dimensions['a'].width = 25 - worksheet.column_dimensions['b'].width = 25 - worksheet.column_dimensions['c'].width = 35 - worksheet.column_dimensions['d'].width = 35 - worksheet.column_dimensions['e'].width = 20 - worksheet.column_dimensions['f'].width = 20 - + worksheet.column_dimensions['a'].width =69 + worksheet.column_dimensions['b'].width = 20 + worksheet.column_dimensions['c'].width = 20 + #cabecario relação de pagamentos - outro servicoes de terceiros - worksheet.merge_cells('A1:F2') - worksheet['A1'] = f'C O N C I L I A Ç Ã O B A N C Á R I A' - worksheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet.merge_cells('A1:C1') + worksheet['A1'] = f'ANEXO 3' + worksheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - worksheet.merge_cells('A3:F3') - worksheet['A3'] = "='Receita x Despesa'!A3:J3" - worksheet['A3'].font = Font(name="Arial", size=12, color="000000") - worksheet['A3'].alignment = Alignment(horizontal="left",vertical="center") - - worksheet.merge_cells('A4:F4') - worksheet['A4'] = "='Receita x Despesa'!A4:J4" + worksheet.merge_cells('A2:C2') + worksheet['A2'] = f'CONCILIAÇÃO BANCÁRIA' + worksheet['A2'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A2'].alignment = Alignment(horizontal="center",vertical="center") + + #cabecario que recebe de referencia as celulas A da planilha DEMOSTR. RECEITA E DESPESA A.2 + + + worksheet['A4'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A4" worksheet['A4'].font = Font(name="Arial", size=12, color="000000") worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A5:F5') - worksheet['A5'] = "='Receita x Despesa'!A5:J5" + worksheet['A5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A5" worksheet['A5'].font = Font(name="Arial", size=12, color="000000") worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") - - worksheet.merge_cells('A6:F6') - worksheet['A6'] = "='Receita x Despesa'!A6:J6" + + worksheet['A6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A6" worksheet['A6'].font = Font(name="Arial", size=12, color="000000") worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A7:F7') - worksheet['A7'] = "='Receita x Despesa'!A7:J7" + worksheet['A7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A7" worksheet['A7'].font = Font(name="Arial", size=12, color="000000") worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A9:F9') - worksheet['A9'] = '1.Saldo conforme extratos bancários na data final do período' - worksheet['A9'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A8" + worksheet['A8'].font = Font(name="Arial", size=12, color="000000") + worksheet['A8'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['A9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A9" + worksheet['A9'].font = Font(name="Arial", size=12, color="000000") worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center") - worksheet['A9'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + + + #cabecario que recebe de referencia as celulas C da planilha DEMOSTR. RECEITA E DESPESA A.2 + + worksheet['B5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C5" + worksheet['B5'].font = Font(name="Arial", size=12, color="000000") + worksheet['B5'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + worksheet.merge_cells('B5:C5') + worksheet['B6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C6" + worksheet['B6'].font = Font(name="Arial", size=12, color="000000") + worksheet['B6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['B7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C7" + worksheet['B7'].font = Font(name="Arial", size=12, color="000000") + worksheet['B7'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['B8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C8" + worksheet['B8'].font = Font(name="Arial", size=12, color="000000") + worksheet['B8'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + + worksheet['B9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C9" + worksheet['B9'].font = Font(name="Arial", size=12, color="000000") + worksheet['B9'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) - worksheet.merge_cells('A10:E10') - worksheet['A10'] = 'Saldo de Conta Corrente(R$)' - worksheet['A10'].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet['A10'].alignment = Alignment(horizontal="right",vertical="center") - worksheet.merge_cells('A11:E11') - worksheet['A11'] = 'Saldo de Aplicações Financeiras(R$)' + + + worksheet['A11'] = 'A. SALDO CONFORME EXTRATOS BANCÁRIOS NA DATA FINAL DO PERÍODO' worksheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet['A11'].alignment = Alignment(horizontal="right",vertical="center") + worksheet['A11'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A11'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet['A11'].border = Border(top=Side(border_style="medium"),bottom=Side(border_style="hair"),right=Side(border_style='medium')) + worksheet.merge_cells('A11:C11') - worksheet.merge_cells('A13:F13') - worksheet['A13'] = '2. Restituições não creditadas pelo banco até a data final do período' - worksheet['A13'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + + worksheet['A12'] = 'DISCRIMINAÇÃO' + worksheet['A12'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A12'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['A12'].border = Border(bottom=Side(border_style="hair"),right=Side(border_style='hair')) + worksheet.merge_cells('A12:B12') + + worksheet['C12'] = 'VALOR' + worksheet['C12'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['C12'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['C12'].border = Border(bottom=Side(border_style="hair"),right=Side(border_style='hair')) + worksheet['C13'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['C13'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['C13'].border = Border(bottom=Side(border_style="hair"),right=Side(border_style='hair')) + worksheet['C14'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['C14'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['C14'].border = Border(bottom=Side(border_style="hair"),right=Side(border_style='hair')) + + + worksheet['A13'] = 'a)Saldo de Conta Corrente(R$)' + worksheet['A13'].font = Font(name="Arial", size=12, color="000000",bold=True) worksheet['A13'].alignment = Alignment(horizontal="left",vertical="center") - worksheet['A13'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet['A13'].border = Border(bottom=Side(border_style="hair"),right=Side(border_style='hair')) + worksheet.merge_cells('A13:B13') + + + worksheet['A14'] = 'b)Saldo de Aplicações Financeiras(R$)' + worksheet['A14'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A14'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A14'].border = Border(bottom=Side(border_style="hair"),right=Side(border_style='hair')) + worksheet.merge_cells('A14:B14') + + + worksheet['A15'] = 'c) TOTAL (a+b)' + worksheet['A15'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A15'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A15'].border = Border(bottom=Side(border_style="medium"),right=Side(border_style='thin'),left=Side(border_style='thin'),top=Side(border_style="thin")) + worksheet['A15'].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + + worksheet.merge_cells('A15:B15') + + worksheet['C15'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['C15'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['C15'].border = Border(bottom=Side(border_style="medium"),right=Side(border_style='medium'),left=Side(border_style='thin'),top=Side(border_style='thin')) + worksheet['C15'].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + + + + + worksheet['A16'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A16'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A16'].border = Border(bottom=Side(border_style="medium"),right=Side(border_style='medium'),top=Side(border_style='medium')) + worksheet.merge_cells('A16:C16') - for i in range(15,size): - sttring = f"D{i}:F{i}" - worksheet.merge_cells(sttring) - - for i in range(size+3,size+4+tamanho2): - sttring = f"D{i}:F{i}" - worksheet.merge_cells(sttring) + + + worksheet['A17'] = 'B. RESTUIÇÕES NÃO CREDITADAS ATÉ A DATA FINAL DESTA PRESTAÇÃO DE CONTAS' + worksheet['A17'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A17'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A17'].border = Border(bottom=Side(border_style="medium"),right=Side(border_style='medium'),left=Side(border_style='thin'),top=Side(border_style='medium')) + worksheet['A17'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet.merge_cells('A17:C17') + + random_number = random.randint(1, 10000) @@ -1401,134 +3117,183 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): custom_number_format_conciliacoes.alignment = Alignment(horizontal="general",vertical="bottom",wrap_text=True) #stylecinza - start_row = 15 - for row in range(start_row,size+1): - cell = worksheet[f'B{row}'] + start_row = 19 + for row in range(start_row,size + tamanho2+ 7): + cell = worksheet[f'C{row}'] cell.style = custom_number_format_conciliacoes - for rows in worksheet.iter_rows(min_row=15, max_row=size, min_col=1, max_col=6): + for rows in worksheet.iter_rows(min_row=18, max_row=size, min_col=1, max_col=3): for cell in rows: - if cell.row % 2: + if not cell.row % 2: cell.fill = PatternFill(start_color=cinza, end_color=cinza, fill_type = "solid") cell.font = Font(name="Arial", size=12, color="000000") cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(bottom=Side(border_style="hair"),right=Side(border_style='hair'),top=Side(border_style='hair'),left=Side(border_style='hair')) - row_number = 15 - values = ["Data","Valor(R$)","Documento",'Descrição'] + row_number = 18 + values = ['Descrição',"Data","Valor"] coluna = 1 for a,b in enumerate(values): worksheet.cell(row=row_number, column=coluna, value=b) coluna = coluna + 1 - + # FORMULATOTAL - formula = f"=SUM(B16:B{size-1})" - celula = f'B{size}' + if size > 18: + formula = f"=SUM(C19:C{size-1})" + else: + formula = f"=SUM(C17:C18)" + size = size +1 + celula = f'C{size}' worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(bottom=Side(border_style="medium"),right=Side(border_style='medium'),top=Side(border_style='medium'),left=Side(border_style='medium')) + #Total + celula_total_merge = f'A{size}:B{size}' celula_total = F'A{size}' - worksheet[celula_total] = f'TOTAL' - worksheet[celula_total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet.row_dimensions[size].height = 38 + worksheet.row_dimensions[size-1].height = 3 + worksheet[celula_total] = f'd)TOTAL' + worksheet[celula_total].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula_total].alignment = Alignment(horizontal="center",vertical="center") + worksheet[celula_total].border = Border(bottom=Side(border_style="medium"),right=Side(border_style='medium'),top=Side(border_style='medium'),left=Side(border_style='medium')) + worksheet.merge_cells(celula_total_merge) #'3. Restituições não creditadas pelo banco até a data final do período' - string_reituicoes_creditadas = f'A{size+2}:F{size+2}' + string_reituicoes_creditadas = f'A{size+2}:C{size+2}' row_creditadas = f'A{size+2}' - worksheet.merge_cells(string_reituicoes_creditadas) - - worksheet[row_creditadas] = '3. Restituições creditadas pelo banco até a data final do período' - worksheet[row_creditadas].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + + worksheet[row_creditadas] = 'C. VALORES NÃO DEBITADOS ATÉ A DATA FINAL DESTA PRESTAÇÃO DE CONTAS' + worksheet[row_creditadas].font = Font(name="Arial", size=12, color="000000",bold=True) worksheet[row_creditadas].alignment = Alignment(horizontal="left",vertical="center") worksheet[row_creditadas].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet[row_creditadas].border = Border(top=Side(border_style='medium')) + worksheet.merge_cells(string_reituicoes_creditadas) #data valor documento descrição row_number = size+3 - values = ["Data","Valor(R$)","Documento",'Descrição'] + values = ['Descrição',"Data","Valor"] coluna = 1 for a,b in enumerate(values): worksheet.cell(row=row_number, column=coluna, value=b) coluna = coluna + 1 - for rows in worksheet.iter_rows(min_row=15, max_row=15, min_col=1, max_col=6): + + + + for rows in worksheet.iter_rows(min_row=18, max_row=18, min_col=1, max_col=3): for cell in rows: cell.font = Font(name="Arial", size=12, color="000000",bold=True) - for rows in worksheet.iter_rows(min_row=row_number, max_row=row_number, min_col=1, max_col=6): + for rows in worksheet.iter_rows(min_row=row_number, max_row=row_number, min_col=1, max_col=3): for cell in rows: cell.font = Font(name="Arial", size=12, color="000000",bold=True) - + for row in range(size+4,size+4+tamanho2): - cell = worksheet[f'B{row}'] + cell = worksheet[f'C{row}'] cell.style = custom_number_format_conciliacoes - for rows in worksheet.iter_rows(min_row=size+3, max_row=size+3+tamanho2, min_col=1, max_col=6): + for rows in worksheet.iter_rows(min_row=size+3, max_row=size+3+tamanho2, min_col=1, max_col=3): for cell in rows: if cell.row % 2: cell.fill = PatternFill(start_color=cinza, end_color=cinza, fill_type = "solid") cell.font = Font(name="Arial", size=12, color="000000") cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - if cell.column == 6: - cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + cell.border = Border(bottom=Side(border_style="hair"),right=Side(border_style='hair'),top=Side(border_style='hair'),left=Side(border_style='hair')) + # FORMULATOTALrestituição - formula = f"=SUM(B{size+4}:B{size+tamanho2+3})" - celula = f'B{size+tamanho2+5}' + formula = f"=SUM(C{size+4}:C{size+tamanho2+3})" + celula = f'C{size+tamanho2+5}' worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(bottom=Side(border_style="medium"),right=Side(border_style='medium'),top=Side(border_style='medium'),left=Side(border_style='medium')) + #Total celula_total = F'A{size+tamanho2+5}' - worksheet[celula_total] = f'TOTAL' - worksheet[celula_total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + string_celula_total= f'A{size+tamanho2+5}:B{size+tamanho2+5}' + worksheet[celula_total].alignment = Alignment(horizontal="center",vertical="center") + worksheet[celula_total] = f'e) TOTAL' + worksheet.row_dimensions[size+tamanho2+5].height = 38 + worksheet.row_dimensions[size+tamanho2+4].height = 3 + worksheet[celula_total].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula_total].border = Border(bottom=Side(border_style="medium"),right=Side(border_style='medium'),top=Side(border_style='medium'),left=Side(border_style='medium')) + worksheet.merge_cells(string_celula_total) + #Saldo disponível p/ período seguinte (1 +2 - 3) - string_saldo_disponivel = f'A{size+3+tamanho2+3}:D{size+3+tamanho2+3}' + string_saldo_disponivel = f'A{size+3+tamanho2+3}:B{size+3+tamanho2+3}' celula_string_saldo = f'A{size+tamanho2+6}' - worksheet[celula_string_saldo].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet.row_dimensions[size+tamanho2+6].height = 30 + worksheet[celula_string_saldo].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet[celula_string_saldo].alignment = Alignment(horizontal="left",vertical="center") + worksheet[celula_string_saldo].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula_string_saldo]= f'D. SALDO CONTÁBIL (c+d-e)' + worksheet[celula_string_saldo].border = Border(bottom=Side(border_style="medium"),right=Side(border_style='medium'),top=Side(border_style='medium'),left=Side(border_style='medium')) worksheet.merge_cells(string_saldo_disponivel) - worksheet[celula_string_saldo]= f'Saldo disponível p/ período seguinte (1 + 2 - 3)' + #total saldo diposnivel - string_merge_saldo_disponivel = f'E{size+3+tamanho2+3}:F{size+3+tamanho2+3}' - celula_string_total = f'E{size+tamanho2+6}' - worksheet.merge_cells(string_merge_saldo_disponivel) + + celula_string_total = f'C{size+tamanho2+6}' saldodiposnivelformat_conciliacoes = NamedStyle(name=f'saldodiposnivelformat_conciliacoes{random_number}') saldodiposnivelformat_conciliacoes.number_format = 'R$ #,##0.00' saldodiposnivelformat_conciliacoes.font = Font(name="Arial", size=12, color="000000") saldodiposnivelformat_conciliacoes.alignment = Alignment(horizontal="general",vertical="bottom",wrap_text=True) - saldodiposnivelformat_conciliacoes.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + saldodiposnivelformat_conciliacoes.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + saldodiposnivelformat_conciliacoes.border = Border(bottom=Side(border_style="medium"),right=Side(border_style='medium'),top=Side(border_style='medium'),left=Side(border_style='medium')) + celular = worksheet[celula_string_total] celular.style = saldodiposnivelformat_conciliacoes - celular.value = f'=F10+F11+B{size} -B{size+tamanho2+5}' + celular.value = f'=C15+C{size} - C{size+tamanho2+5}'#corrigir + # #saldo anterior + # formula = f"Saldo anterior" + # celula = f'A16' + # worksheet[celula] = formula + # worksheet[celula].font = Font(name="Arial", size=12, color="000000") + + # formula = f"Diversos" + # celula = f'C16' + # worksheet[celula] = formula + # worksheet[celula].font = Font(name="Arial", size=12, color="000000") + + # formula = f"Tarifas Prestações Anteriores" + # celula = f'D16' + # worksheet[celula] = formula + # worksheet[celula].font = Font(name="Arial", size=12, color="000000") #brasilia brasilia_row = size + tamanho2+ 8 - brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:J{stringTamanho}" - brasilia_merge_cells = f'A{brasilia_row}:F{brasilia_row}' + brasilia_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:C{brasilia_row}' worksheet.merge_cells(brasilia_merge_cells) top_left_brasilia_cell_formula = f'A{brasilia_row}' top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] top_left_brasilia_cell.value = brasilia_formula top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_brasilia_cell.font = Font(name="Arial", size=12, color="000000") # #DiretorFinanceiro diretor_row = size + 10 + tamanho2 diretor_cargo_row = size + 11 + tamanho2 diretor_cpf_row = size + 12 + tamanho2 - diretor_nome_formula = f"='Receita x Despesa'!A{stringTamanho+3}" - diretor_cargo_formula = f"='Receita x Despesa'!A{stringTamanho+4}" - diretor_cpf_formula = f"='Receita x Despesa'!A{stringTamanho+5}" - diretor_merge_cells = f'A{diretor_row}:B{diretor_row}' - diretor_cargo_merge_cells = f'A{diretor_cargo_row}:B{diretor_cargo_row}' - diretor_cpf_merge_cells = f'A{diretor_cpf_row}:B{diretor_cpf_row}' - worksheet.merge_cells(diretor_merge_cells) - worksheet.merge_cells(diretor_cargo_merge_cells) - worksheet.merge_cells(diretor_cpf_merge_cells) + + diretor_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+3}" + diretor_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+4}" + diretor_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+5}" + # diretor_merge_cells = f'A{diretor_row}:B{diretor_row}' + # diretor_cargo_merge_cells = f'A{diretor_cargo_row}:B{diretor_cargo_row}' + # diretor_cpf_merge_cells = f'A{diretor_cpf_row}:B{diretor_cpf_row}' + # worksheet.merge_cells(diretor_merge_cells) + # worksheet.merge_cells(diretor_cargo_merge_cells) + # worksheet.merge_cells(diretor_cpf_merge_cells) top_left_diretor_cell_formula = f'A{diretor_row}' top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' @@ -1543,49 +3308,69 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") #Coordenadora - coordenadora_row = size + tamanho2 + 10 - coordenadora_cargo_row = size + 11 + tamanho2 - coordenadora_cpf_row = size + 12+ tamanho2 - coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" - coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" - coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" - coordenadora_merge_cells = f'D{coordenadora_row}:F{coordenadora_row}' - coordenadora_cargo_merge_cells = f'D{coordenadora_cargo_row}:F{coordenadora_cargo_row}' - coordenadora_cpf_merge_cells = f'D{coordenadora_cpf_row}:F{coordenadora_cpf_row}' + coordenadora_row = diretor_row + coordenadora_cargo_row = diretor_cargo_row + coordenadora_cpf_row = diretor_cpf_row + coordenadora_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+3}" + coordenadora_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+4}" + coordenadora_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+5}" + coordenadora_merge_cells = f'B{coordenadora_row}:C{coordenadora_row}' + coordenadora_cargo_merge_cells = f'B{coordenadora_cargo_row}:C{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'B{coordenadora_cpf_row}:C{coordenadora_cpf_row}' worksheet.merge_cells(coordenadora_merge_cells) worksheet.merge_cells(coordenadora_cargo_merge_cells) worksheet.merge_cells(coordenadora_cpf_merge_cells) - top_left_coordenadora_cell_formula = f'D{coordenadora_row}' - top_left_coordenadora_cell_cargo_formula = f'D{coordenadora_cargo_row}' - top_left_coordenadora_cell_cpf_formula = f'D{coordenadora_cpf_row}' + top_left_coordenadora_cell_formula = f'B{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'B{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'B{coordenadora_cpf_row}' top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] top_left_coordenadora_cell.value = coordenadora_nome_formula top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula - top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") top_left_coordenadora_cell.border = borda + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") - top_left_coordenadora_cell_cargo_formula.border = borda + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") - top_left_coordenadora_cell_cpf_formula.border = borda + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") + + #borda cabeçario + for row in worksheet.iter_rows(min_row=1, max_row=10,min_col=3,max_col=3): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) - for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=6,max_col=6): + #borda fim pagina + for row in worksheet.iter_rows(min_row=brasilia_row-1, max_row=coordenadora_cpf_row+1,min_col=3,max_col=3): for cell in row: - cell.border = borda + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) - for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=6): + #borda pagina + for row in worksheet.iter_rows(min_row=11, max_row=brasilia_row-2,min_col=4,max_col=4): for cell in row: - if cell.column == 6: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="none") ,left =Side(border_style="medium") ,bottom=Side(border_style="none") ) + + + # + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=3): + for cell in row: + if cell.column == 3: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) else: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) + + for rows in worksheet.iter_rows(min_row=size+3, max_row=size+3, min_col=1, max_col=3): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['B5'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) workbook.save(tabela) workbook.close() + return size +4 + def estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho): """Estilo da rendimento de aplicação, tabela com as colunas periodo, saldo anterior,valor aplicado no período,valor resgatado no período,rendimento bruto,imposto,rendimento luiquido,saldo. @@ -1594,14 +3379,17 @@ def estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho): tamanho:Corresponde ao tamanho das quantidade da tabela de rencimentos. stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referências das formulas. """ + if tamanho == 0: + tamanho = 1 caminho = pegar_caminho(tabela) workbook = openpyxl.load_workbook(caminho) worksheet = workbook['Rendimento de Aplicação'] random_number = random.randint(1, 10000) size = tamanho + 14 - worksheet.row_dimensions[10].height = 2 - worksheet.row_dimensions[9].height = 20 + worksheet.row_dimensions[2].height = 48 + worksheet.row_dimensions[1].height = 48 + testeRow = 15; cinza = "d9d9d9" cinza_escuro = "bfbfbf" @@ -1609,12 +3397,36 @@ def estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho): azul_claro = '1c8cbc' borda = Border(right=Side(border_style="medium")) worksheet.sheet_view.showGridLines = False - # - for row in worksheet.iter_rows(min_row=1, max_row=size+9,min_col=8,max_col=8): - for cell in row: - cell.border = borda - + #imagensfinep + + image_names = [ + 'Finep.png', + + ] + + # Path to the images + path = "/imagemFinep/" + + # List to hold Image objects + images = [] + + nomePasta = "../../imagemFinep" + diretorio = os.path.dirname(__file__) + + # Loop through the list of image names and create Image objects + for i, name in enumerate(image_names): + caminhoImage = os.path.join(diretorio, nomePasta, name) + pil_image = PILImage.open(caminhoImage) + pil_image.save(caminhoImage) + img = Image(caminhoImage) + images.append(img) + + + + worksheet.add_image(images[0], "A1")# FINEP + + worksheet.column_dimensions['a'].width = 20 worksheet.column_dimensions['b'].width = 20 @@ -1628,71 +3440,157 @@ def estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho): #cabecario relação de pagamentos - outro servicoes de terceiros worksheet.merge_cells('A1:H2') - worksheet['A1'] = f'D E M O N S T R A T I V O D E R E N D I M E N T O D E A P L I C A Ç Ã O F I N A N C E I R A' - worksheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A1'] = f'Demonstrativo dos Ganhos Auferidos com Aplicações ' + worksheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - worksheet.merge_cells('A3:H3') - worksheet['A3'] = "='Receita x Despesa'!A3:J3" + + #unidade executora + + worksheet['A3'] = "Unidade Executora:" worksheet['A3'].font = Font(name="Arial", size=12, color="000000") worksheet['A3'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A3'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet['A3'].border = Border(top=Side(border_style="double")) + worksheet.merge_cells('A3:F3') - worksheet.merge_cells('A4:H4') - worksheet['A4'] = "='Receita x Despesa'!A4:J4" - worksheet['A4'].font = Font(name="Arial", size=12, color="000000") + worksheet['A4'] = "FINATEC - Fundação de Empreendimentos Científicos e Tecnológicos" + worksheet['A4'].font = Font(name="Arial", size=12, color="000000",bold=True) worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A4'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + + - worksheet.merge_cells('A5:H5') - worksheet['A5'] = "='Receita x Despesa'!A5:J5" + #convenio + worksheet['G3'] = "Convênio Nº: " + worksheet['G3'].font = Font(name="Arial", size=12, color="000000") + worksheet['G3'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['G3'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet['G3'].border = Border(right=Side(border_style="double"),top=Side(border_style="double")) + worksheet.merge_cells('G3:H3') + #convenio + worksheet['G4'] = "='Capa Finatec'!E17" + worksheet['G4'].font = Font(name="Arial", size=12, color="000000") + worksheet['G4'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['G4'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet['G4'].border = Border(right=Side(border_style="double"),top=Side(border_style="double")) + worksheet.merge_cells('G4:H4') + + #projeto + worksheet['A5'] = "Projeto:" worksheet['A5'].font = Font(name="Arial", size=12, color="000000") worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") - - worksheet.merge_cells('A6:H6') - worksheet['A6'] = "='Receita x Despesa'!A6:J6" + worksheet['A5'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet.merge_cells('A5:F5') + + worksheet['A6'] = "='Capa Finatec'!E9" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + worksheet['A6'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + + #Período de Execução do Convênio: + worksheet['G5'] = "Período de Execução do Convênio:" + worksheet['G5'].font = Font(name="Arial", size=12, color="000000") + worksheet['G5'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['G5'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet['G5'].border = Border(right=Side(border_style="double")) + worksheet.merge_cells('G5:H5') + + worksheet['G6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C6" + worksheet['G6'].font = Font(name="Arial", size=12, color="000000") + worksheet['G6'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['G6'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + + #linha 4 + worksheet['A4'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet.merge_cells('A4:F4') + worksheet['G4'].border = Border(right=Side(border_style="double")) + worksheet['G4'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet.merge_cells('G4:H4') + #linha 6 + worksheet['G6'].border = Border(right=Side(border_style="double")) + worksheet['G6'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet.merge_cells('G6:H6') + + #vaireceberinputnopreencher worksheet['A6'].font = Font(name="Arial", size=12, color="000000") - worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") - - worksheet.merge_cells('A7:H7') - worksheet['A7'] = "='Receita x Despesa'!A7:J7" - worksheet['A7'].font = Font(name="Arial", size=12, color="000000") - worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") - - worksheet.merge_cells('A9:H9') - worksheet['A9'] = 'RF Ref DI Plus Ágil - CNP JRF REF DI PLUS ÁGIL' - worksheet['A9'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + worksheet['A6'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet.merge_cells('A6:F7') + + #Período Abrangido por este Relatório: + worksheet['G7'] = "Período Abrangido por este Relatório:" + worksheet['G7'].font = Font(name="Arial", size=12, color="000000") + worksheet['G7'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + worksheet['G7'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet['G7'].border = Border(right=Side(border_style="double")) + worksheet.merge_cells('G7:H7') + + + #barrvazia + worksheet['A8'].font = Font(name="Arial", size=12, color="000000") + worksheet['A8'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A8'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet['A8'].border = Border(bottom=Side(border_style="double")) + worksheet.merge_cells('A8:F8') + #Período Abrangido por este Relatório: + worksheet['G8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C7" + worksheet['G8'].font = Font(name="Arial", size=12, color="000000") + worksheet['G8'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['G8'].fill = openpyxl.styles.PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type='solid') + worksheet['G8'].border = Border(bottom=Side(border_style="double"),right=Side(border_style="double")) + worksheet.merge_cells('G8:H8') + + + worksheet.row_dimensions[9].height = 20 + worksheet.row_dimensions[10].height = 20 + + worksheet.merge_cells('A9:H10') + worksheet['A9'] = f'APLICAÇÃO FINANCEIRA' + worksheet['A9'].font = Font(name="Arial", size=12, color="000000",bold=True) worksheet['A9'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A9'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - + worksheet.row_dimensions[11].height = 20 + worksheet.row_dimensions[12].height = 20 - #stylecinza + + worksheet['A11'] = f'APLICAÇÃO FINANCEIRA - RF REF DI PLUS ÁGIL' + worksheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A11'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['A11'].border = Border(bottom=Side(border_style="double"),right=Side(border_style="double"),left=Side(border_style="double"),top=Side(border_style="double")) + worksheet.merge_cells('A11:H12') + + + + worksheet.row_dimensions[13].height = 25 + worksheet.row_dimensions[14].height = 25 + + # #stylecinza start_row = 11 - for rows in worksheet.iter_rows(min_row=start_row, max_row=13, min_col=1, max_col=8): + for rows in worksheet.iter_rows(min_row=13, max_row=14, min_col=1, max_col=8): for cell in rows: - if cell.row % 2: + if cell.row % 2 == 0: cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type = "solid") cell.font = Font(name="Arial", size=12, color="000000",bold=True) cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, + fill_type = "solid") - - row_number = 11 + #cabcerario abaixo de aplicação financeira + row_number = 13 values = ["Período","Saldo Anterior","Valor Aplicado no período",'Valor Resgatado no Período','Rendimento Bruto','Imposto de Renda / IOF','Rendimento Líquido','Saldo'] coluna = 1 for a,b in enumerate(values): worksheet.cell(row=row_number, column=coluna, value=b) - coluna = coluna + 1 for i in range(1,9): - worksheet.merge_cells(start_row=11,end_row=13,start_column=i,end_column=i) + worksheet.merge_cells(start_row=13,end_row=14,start_column=i,end_column=i) - #RENDIMENTO LIQUIDO - # print(size) - for row in worksheet.iter_rows(min_row=14, max_row=size, min_col=7, max_col=7): + # #RENDIMENTO LIQUIDO + # # print(size) + for row in worksheet.iter_rows(min_row=testeRow, max_row=size, min_col=7, max_col=7): for cell in row: stringSaldo = f"=E{cell.row} - F{cell.row}" cell.value = stringSaldo @@ -1702,106 +3600,134 @@ def estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho): #BARRAS DE DADOS start_row = 14 - for rows in worksheet.iter_rows(min_row=start_row, max_row=size, min_col=1, max_col=8): + for rows in worksheet.iter_rows(min_row=testeRow, max_row=size, min_col=1, max_col=8): for cell in rows: - if cell.row % 2: + if cell.row % 2==0: cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type = "solid") cell.font = Font(name="Arial", size=12, color="000000") cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) #MASCARA VERMELHO - for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=6, max_col=6): + for rows in worksheet.iter_rows(min_row=testeRow, max_row=size-1, min_col=6, max_col=6): for cell in rows: cell.font = Font(name="Arial", size=12, color="f90000") cell.number_format ='#,##0.00' #MASCARANEGRITO - for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=1, max_col=1): + for rows in worksheet.iter_rows(min_row=testeRow, max_row=size-1, min_col=1, max_col=1): for cell in rows: cell.font = Font(name="Arial", size=12, color="000000",bold=True) - # #MASCARA AZUL - # for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=6, max_col=6): - # for cell in rows: - # cell.font = Font(name="Arial", size=12, color="141fca") - # cell.number_format ='#,##0.00' - - # for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=7, max_col=7): - # for cell in rows: - # cell.font = Font(name="Arial", size=12, color="141fca",bold=True) - # cell.number_format ='#,##0.00' + # # #MASCARA AZUL + # # for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=6, max_col=6): + # # for cell in rows: + # # cell.font = Font(name="Arial", size=12, color="141fca") + # # cell.number_format ='#,##0.00' + + # # for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=7, max_col=7): + # # for cell in rows: + # # cell.font = Font(name="Arial", size=12, color="141fca",bold=True) + # # cell.number_format ='#,##0.00' #barra de totais + formula = f"Saldo anterior" + celula = f'A{testeRow}' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + + + # FORMULATOTAL #B - formula = f"=SUM(B14:B{size-1})" + size = size + 1 + formula = f"=SUM(B{testeRow}:B{size-1})" celula = f'B{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) #C - formula = f"=SUM(C14:C{size-1})" + formula = f"=SUM(C{testeRow}:C{size-1})" celula = f'C{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #D - formula = f"=SUM(D14:D{size-1})" + formula = f"=SUM(D{testeRow}:D{size-1})" celula = f'D{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #E - formula = f"=SUM(E14:E{size-1})" + formula = f"=SUM(E{testeRow}:E{size-1})" celula = f'E{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #F - formula = f"=SUM(F14:F{size-1})" + formula = f"=SUM(F{testeRow}:F{size-1})" celula = f'F{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #G - formula = f"=SUM(G14:G{size-1})" + formula = f"=SUM(G{testeRow}:G{size-1})" celula = f'G{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #H - formula = f"=SUM(H14:H{size-1})" + formula = f"=SUM(H{testeRow}:H{size-1})" celula = f'H{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #Total celula_total = F'A{size}' worksheet[celula_total] = f'TOTAL' worksheet[celula_total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #borda total + + + #brasilia brasilia_row = size + 2 - brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:J{stringTamanho}" - brasilia_merge_cells = f'A{brasilia_row}:F{brasilia_row}' + brasilia_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:H{brasilia_row}' worksheet.merge_cells(brasilia_merge_cells) top_left_brasilia_cell_formula = f'A{brasilia_row}' top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] top_left_brasilia_cell.value = brasilia_formula top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_brasilia_cell.font = Font(name="Arial", size=12, color="000000") # #DiretorFinanceiro diretor_row = size + 6 diretor_cargo_row = size + 7 diretor_cpf_row = size + 8 - diretor_nome_formula = f"='Receita x Despesa'!A{stringTamanho+3}" - diretor_cargo_formula = f"='Receita x Despesa'!A{stringTamanho+4}" - diretor_cpf_formula = f"='Receita x Despesa'!A{stringTamanho+5}" + diretor_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+3}" + diretor_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+4}" + diretor_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+5}" diretor_merge_cells = f'A{diretor_row}:C{diretor_row}' diretor_cargo_merge_cells = f'A{diretor_cargo_row}:C{diretor_cargo_row}' diretor_cpf_merge_cells = f'A{diretor_cpf_row}:C{diretor_cpf_row}' @@ -1825,18 +3751,18 @@ def estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho): coordenadora_row = size + 6 coordenadora_cargo_row = size + 7 coordenadora_cpf_row = size + 8 - coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" - coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" - coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" - coordenadora_merge_cells = f'E{coordenadora_row}:G{coordenadora_row}' - coordenadora_cargo_merge_cells = f'E{coordenadora_cargo_row}:G{coordenadora_cargo_row}' - coordenadora_cpf_merge_cells = f'E{coordenadora_cpf_row}:G{coordenadora_cpf_row}' + coordenadora_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+3}" + coordenadora_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+4}" + coordenadora_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+5}" + coordenadora_merge_cells = f'F{coordenadora_row}:H{coordenadora_row}' + coordenadora_cargo_merge_cells = f'F{coordenadora_cargo_row}:H{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'F{coordenadora_cpf_row}:H{coordenadora_cpf_row}' worksheet.merge_cells(coordenadora_merge_cells) worksheet.merge_cells(coordenadora_cargo_merge_cells) worksheet.merge_cells(coordenadora_cpf_merge_cells) - top_left_coordenadora_cell_formula = f'E{coordenadora_row}' - top_left_coordenadora_cell_cargo_formula = f'E{coordenadora_cargo_row}' - top_left_coordenadora_cell_cpf_formula = f'E{coordenadora_cpf_row}' + top_left_coordenadora_cell_formula = f'F{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'F{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'F{coordenadora_cpf_row}' top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] @@ -1846,21 +3772,46 @@ def estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho): top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") + + for row in worksheet.iter_rows(min_row=15, max_row=brasilia_row-2,min_col=2,max_col=8): + for cell in row: + cell.number_format = 'R$ #,##0.00' + + #borda cabeçario + for row in worksheet.iter_rows(min_row=13, max_row=brasilia_row-2,min_col=8,max_col=8): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="double") ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + #borda fim pagina + for row in worksheet.iter_rows(min_row=brasilia_row-1, max_row=coordenadora_cpf_row+1,min_col=8,max_col=8): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=8): for cell in row: if cell.column == 8: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) else: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) + + + #borda da barra total + for row in worksheet.iter_rows(min_row=size, max_row=size,min_col=1,max_col=8): + for cell in row: + cell.border = Border(top=Side(border_style="double") ,right = Side(border_style="none") ,left =Side(border_style="none") ,bottom=Side(border_style="double") ) + if cell.column == 8: + cell.border = Border(top=Side(border_style="double") ,right = Side(border_style="double") ,left =Side(border_style="none") ,bottom=Side(border_style="double") ) workbook.save(tabela) workbook.close() -def estiloRelacaoBens(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): +def estiloRelacaoBens(tabela,tamanho,stringTamanho): """Estilo da tabela de bens, consulta no banco sap Argumentos: @@ -1868,85 +3819,114 @@ def estiloRelacaoBens(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): tamanho:Corresponde ao tamanho das quantidade de bens. stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referências das formulas. """ + if tamanho == 0: + tamanho = 1 + random_number = random.randint(1, 10000) - + nomeTabela = f'relacaodebens' nomeVariavel = f'material{random_number}' caminho = pegar_caminho(tabela) workbook = openpyxl.load_workbook(caminho) - worksheet = workbook[nomeTabela] + worksheet = workbook['Relação Bens Adquiridos A.5'] size = tamanho + 13 cinza = "d9d9d9" cinza_escuro = "bfbfbf" azul = "336394" - azul_claro = '1c8cbc' + azul_claro = 'ccffff' - borda = Border(right=Side(border_style="medium")) + worksheet.sheet_view.showGridLines = False - # - for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): - for cell in row: - cell.border = borda + - worksheet.column_dimensions['a'].width = 25 - worksheet.column_dimensions['b'].width = 50 + worksheet.column_dimensions['a'].width = 45 + worksheet.column_dimensions['b'].width = 35 worksheet.column_dimensions['c'].width = 35 - worksheet.column_dimensions['d'].width = 35#descrição - worksheet.column_dimensions['e'].width = 40 #n do recibo ou qeuivalente - worksheet.column_dimensions['f'].width = 70 #data de emissão - worksheet.column_dimensions['g'].width = 25 #data de emissão - worksheet.column_dimensions['h'].width = 25 #data de emissão - worksheet.column_dimensions['i'].width = 25 #data de emissão - worksheet.column_dimensions['j'].width = 25 #data de emissão - - - #cabecario relação de pagamentos - outro servicoes de terceiros - worksheet.merge_cells('A1:J2') - worksheet['A1'] = f'RELAÇÃO DE BENS' - worksheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet.column_dimensions['d'].width = 45#descrição + worksheet.column_dimensions['e'].width = 45 #n do recibo ou qeuivalente + worksheet.column_dimensions['f'].width = 35 #data de emissão + worksheet.column_dimensions['g'].width = 35 #data de emissão + worksheet.column_dimensions['h'].width = 35 #data de emissão + worksheet.column_dimensions['i'].width = 35 #data de emissão + worksheet.column_dimensions['j'].width = 35 #data de emissão + worksheet.column_dimensions['k'].width = 35 #data de emissão + + + #cabecario + worksheet.merge_cells('A1:K1') + nomeTabela = nomeTabela.upper() + worksheet['A1'] = f'ANEXO 5' + worksheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - worksheet.merge_cells('A3:J4') - worksheet['A3'] = f'(ADQUIRIDOS, PRODUZIDOS OU CONSTRUÍDOS COM RECURSOS)' - worksheet['A3'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - worksheet['A3'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A3'].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + #RELAÇÃO DE PAGAMENTOS + worksheet.merge_cells('A2:K2') + nomeTabela = nomeTabela.upper() + worksheet['A2'] = f'RELAÇÃO DE BENS ADQUIRIDOS OU PRODUZIDOS' + worksheet['A2'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A2'].alignment = Alignment(horizontal="center",vertical="center") - worksheet.merge_cells('A5:F5') - worksheet['A5'] = "='Receita x Despesa'!A3:J3" + #cabecario que recebe de referencia as celulas A da planilha DEMOSTR. RECEITA E DESPESA A.2 + + worksheet['A4'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A4" + worksheet['A4'].font = Font(name="Arial", size=12, color="000000") + worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + + + worksheet['A5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A5" worksheet['A5'].font = Font(name="Arial", size=12, color="000000") worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A6:F6') - worksheet['A6'] = "='Receita x Despesa'!A4:J4" + worksheet['A6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A6" worksheet['A6'].font = Font(name="Arial", size=12, color="000000") worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A7:F7') - worksheet['A7'] = "='Receita x Despesa'!A5:J5" + worksheet['A7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A7" worksheet['A7'].font = Font(name="Arial", size=12, color="000000") worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A8:F8') - worksheet['A8'] = "='Receita x Despesa'!A6:J6" + worksheet['A8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A8" worksheet['A8'].font = Font(name="Arial", size=12, color="000000") worksheet['A8'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A9:F9') - worksheet['A9'] = "='Receita x Despesa'!A7:J7" + worksheet['A9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!A9" worksheet['A9'].font = Font(name="Arial", size=12, color="000000") worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center") + + + worksheet['C5'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C5" + worksheet['C5'].font = Font(name="Arial", size=12, color="000000") + worksheet['C5'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C6'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C6" + worksheet['C6'].font = Font(name="Arial", size=12, color="000000") + worksheet['C6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C7'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C7" + worksheet['C7'].font = Font(name="Arial", size=12, color="000000") + worksheet['C7'].alignment = Alignment(horizontal="left",vertical="center") - #variavel + worksheet['C8'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C8" + worksheet['C8'].font = Font(name="Arial", size=12, color="000000") + worksheet['C8'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet['C9'] = "='DEMOSTR. RECEITA E DESPESA A.2'!C9" + worksheet['C9'].font = Font(name="Arial", size=12, color="000000") + worksheet['C9'].alignment = Alignment(horizontal="left",vertical="center") + + #declaração + + worksheet['A11'] = f'Declaramos que os bens abaixo especificados, adquiridos ou produzidos com os recursos do concedente, foram inventariados e encontram-se localizados nas instalações do Convenente ou dos Executores conforme relacionado abaixo. Relacionamos, também, os responsáveis pela guarda dos bens.' + worksheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A11'].alignment = Alignment(horizontal="left",vertical="center") + input2=f'rowStyle{nomeVariavel}' borda = Border( - left=Side(border_style='thin', color='FFFFFF'), - right=Side(border_style='thin', color='FFFFFF'), - top=Side(border_style='thin', color='FFFFFF'), - bottom=Side(border_style='thin', color='FFFFFF') + left=Side(border_style='hair'), + right=Side(border_style='hair'), + top=Side(border_style='double'), + bottom=Side(border_style='hair') ) borda2 = Border( left=Side(border_style='hair', color='000000'), @@ -1957,70 +3937,79 @@ def estiloRelacaoBens(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): #colunas azul cabecario locals()[input2] = NamedStyle(name=f'{input2}') - locals()[input2].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input2].font = Font(name="Arial", size=12, color="000000",bold=True) locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - locals()[input2].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="thin") ) + locals()[input2].border = Border(top=Side(border_style="double") ,bottom=Side(border_style="hair") ) locals()[input2].height = 20 - linha_number = 11 - for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=10): + linha_number = 13 + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=11): for cell in row: cell.style = locals()[input2] - if cell.column == 10: - cell.border = Border(left=Side(border_style="thin", color='FFFFFF') ,bottom=Side(border_style="thin", color='FFFFFF'), right=Side(border_style="medium") ) + if cell.column == 11: + cell.border = Border(left=Side(border_style="hair") ,bottom=Side(border_style="hair"), right=Side(border_style="double") ) cell.border = borda ##CABECARIO - worksheet["A11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - worksheet.merge_cells("A11:A12") - worksheet["A11"] ="Nº DO ITEM" + worksheet["A13"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("A13:A14") + worksheet["A13"] ="Nº DO ITEM" - worksheet["B11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - worksheet.merge_cells("B11:B12") - worksheet["B11"] = "DESCRIÇÃO DO BEM" + worksheet["B13"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("B13:B14") + worksheet["B13"] = "DESCRIÇÃO DO BEM" - worksheet["C11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - worksheet.merge_cells("C11:C12") - worksheet["C11"] = "NÚMERO PATRIMONIAL DO BEM" + worksheet["C13"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("C13:C14") + worksheet["C13"] = "NÚMERO PATRIMONIAL DO BEM" - worksheet["D11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - worksheet.merge_cells("D11:E11") - worksheet["D11"] = "DOCUMENTAÇÃO FISCAL" + worksheet["D13"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("D13:E13") + worksheet["D13"] = "DOCUMENTAÇÃO FISCAL" - worksheet["D12"].fill = openpyxl.styles.PatternFill(start_color=cinza, end_color=cinza, fill_type='solid') - worksheet["D12"] = "DATA" - worksheet["D12"].border = borda2 + worksheet["D14"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet["D14"] = "DATA" + worksheet["D14"].border = borda2 - worksheet["E12"].fill = openpyxl.styles.PatternFill(start_color=cinza, end_color=cinza, fill_type='solid') - worksheet["E12"] = "Nº " - worksheet["E12"].border = borda2 + worksheet["E14"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet["E14"] = "Nº " + worksheet["E14"].border = borda2 - worksheet["F11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - worksheet.merge_cells("F11:F12") - worksheet["F11"] = "LOCALIZAÇÃO" + worksheet["F13"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("F13:F14") + worksheet["F13"] = "LOCALIZAÇÃO" - worksheet["G11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - worksheet.merge_cells("G11:G12") - worksheet["G11"] = "QTD." + worksheet["G13"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("G13:G14") + worksheet["G13"] = "Equivalência na Relação de Itens Apoiados" - worksheet["H11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - worksheet.merge_cells("H11:I11") - worksheet["H11"] = "VALOR (R$)" + worksheet["H13"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("H13:H14") + worksheet["H13"] = "QUANTIDADE" - worksheet["H12"].fill = openpyxl.styles.PatternFill(start_color=cinza, end_color=cinza, fill_type='solid') - worksheet["H12"] = "Unitário" - worksheet["H12"].border = borda2 - worksheet["I12"].fill = openpyxl.styles.PatternFill(start_color=cinza, end_color=cinza, fill_type='solid') - worksheet["I12"] = "Total" - worksheet["I12"].border = borda2 + worksheet["I13"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("I13:J13") + worksheet["I13"] = "VALOR (R$)" + + worksheet["I14"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet["I14"] = "Unitário" + worksheet["I14"].border = borda2 + worksheet["J14"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet["J14"] = "Total" + worksheet["J14"].border = borda2 + + worksheet["K13"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet["K13"].border = openpyxl.styles.Border(top=Side(border_style="double") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + worksheet.merge_cells("K13:K14") + worksheet["K13"] = "RESPONSÁVEL PELA GUARDA DO BEM" #Aumentar a altura das celulas - for row in worksheet.iter_rows(min_row=10, max_row=size, min_col=1, max_col=10): - worksheet.row_dimensions[row[0].row].height = 35 + for row in worksheet.iter_rows(min_row=13, max_row=size, min_col=1, max_col=11): + worksheet.row_dimensions[row[0].row].height = 45 input3 = f'customNumber{nomeVariavel}' # MASCARA R$ @@ -2034,74 +4023,89 @@ def estiloRelacaoBens(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): value_to_stop = size start_row = 10 # - for row in range(13,size+1): - cell = worksheet[f'H{row}'] + for row in range(15,size+1): + cell = worksheet[f'I{row}'] cell.style = locals()[input3] - for row in range(13,size+1): - cell = worksheet[f'I{row}'] + for row in range(15,size+1): + cell = worksheet[f'J{row}'] cell.style = locals()[input3] - for rows in worksheet.iter_rows(min_row=13, max_row=size, min_col=1, max_col=10): + for rows in worksheet.iter_rows(min_row=15, max_row=size+1, min_col=1, max_col=11): for cell in rows: if cell.row % 2: cell.fill = PatternFill(start_color=cinza, end_color=cinza, fill_type = "solid") - if cell.column == 10: + + + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + if cell.row == size+1: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="double") ) cell.font = Font(name="Arial", size=12, color="000000") cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) - else: + + if cell.column == 11: cell.font = Font(name="Arial", size=12, color="000000") cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) - - + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="hair") ) + if cell.row == size+1: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="double") ) + + for rows in worksheet.iter_rows(min_row=size+1, max_row=size+1, min_col=1, max_col=11): + for cell in rows: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="double") ) + if cell.column == 11: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="double") ,bottom=Side(border_style="double") ) + #subtotal stringAfinarCelula =size+2 worksheet.row_dimensions[size+2].height = 6 - celulas_mergidas_subtotal = f"A{size+2}:I{size+2}" - worksheet.merge_cells(celulas_mergidas_subtotal) left_celula_cell = f"A{size+2}" top_left_cell = worksheet[left_celula_cell] top_left_cell.value = "TOTAL" - top_left_cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + top_left_cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) top_left_cell.alignment = Alignment(horizontal="center",vertical="center") top_left_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="medium") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + celulas_mergidas_subtotal = f"A{size+2}:I{size+2}" + worksheet.merge_cells(celulas_mergidas_subtotal) worksheet.row_dimensions[size+2].height = 56.25 # FORMULATOTAL - formula = f"=SUM(I13:I{size})" + formula = f"=SUM(J13:J{size+1})" celula = f'J{size+2}' worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + worksheet[celula].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet[celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + worksheet[celula].border = Border( left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) worksheet[celula].number_format = 'R$ #,##0.00' #brasilia brasilia_row = size + 7 - brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:J{stringTamanho}" - brasilia_merge_cells = f'A{brasilia_row}:I{brasilia_row}' + brasilia_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:K{brasilia_row}' worksheet.merge_cells(brasilia_merge_cells) top_left_brasilia_cell_formula = f'A{brasilia_row}' top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] top_left_brasilia_cell.value = brasilia_formula top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_brasilia_cell.font = Font(name="Arial", size=12, color="000000") #DiretorFinanceiro - diretor_row = size + 81 - diretor_cargo_row = size + 91 - diretor_cpf_row = size + 101 - diretor_nome_formula = f"='Receita x Despesa'!A{stringTamanho+3}" - diretor_cargo_formula = f"='Receita x Despesa'!A{stringTamanho+4}" - diretor_cpf_formula = f"='Receita x Despesa'!A{stringTamanho+5}" - diretor_merge_cells = f'A{diretor_row}:D{diretor_row}' - diretor_cargo_merge_cells = f'A{diretor_cargo_row}:D{diretor_cargo_row}' - diretor_cpf_merge_cells = f'A{diretor_cpf_row}:D{diretor_cpf_row}' + diretor_row = size + 8 + diretor_cargo_row = size + 9 + diretor_cpf_row = size + 10 + diretor_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+3}" + diretor_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+4}" + diretor_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!A{stringTamanho+5}" + diretor_merge_cells = f'A{diretor_row}:F{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:F{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:F{diretor_cpf_row}' worksheet.merge_cells(diretor_merge_cells) worksheet.merge_cells(diretor_cargo_merge_cells) worksheet.merge_cells(diretor_cpf_merge_cells) @@ -2119,21 +4123,21 @@ def estiloRelacaoBens(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") #Coordenadora - coordenadora_row = size + 81 - coordenadora_cargo_row = size + 91 - coordenadora_cpf_row = size + 101 - coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" - coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" - coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" - coordenadora_merge_cells = f'F{coordenadora_row}:J{coordenadora_row}' - coordenadora_cargo_merge_cells = f'F{coordenadora_cargo_row}:J{coordenadora_cargo_row}' - coordenadora_cpf_merge_cells = f'F{coordenadora_cpf_row}:J{coordenadora_cpf_row}' + coordenadora_row = size + 8 + coordenadora_cargo_row = size + 9 + coordenadora_cpf_row = size + 10 + coordenadora_nome_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+3}" + coordenadora_cargo_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+4}" + coordenadora_cpf_formula = f"='DEMOSTR. RECEITA E DESPESA A.2'!C{stringTamanho+5}" + coordenadora_merge_cells = f'G{coordenadora_row}:K{coordenadora_row}' + coordenadora_cargo_merge_cells = f'G{coordenadora_cargo_row}:K{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'G{coordenadora_cpf_row}:K{coordenadora_cpf_row}' worksheet.merge_cells(coordenadora_merge_cells) worksheet.merge_cells(coordenadora_cargo_merge_cells) worksheet.merge_cells(coordenadora_cpf_merge_cells) - top_left_coordenadora_cell_formula = f'F{coordenadora_row}' - top_left_coordenadora_cell_cargo_formula = f'F{coordenadora_cargo_row}' - top_left_coordenadora_cell_cpf_formula = f'F{coordenadora_cpf_row}' + top_left_coordenadora_cell_formula = f'G{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'G{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'G{coordenadora_cpf_row}' top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] @@ -2143,32 +4147,37 @@ def estiloRelacaoBens(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") - - # borda = Border(right=Side(border_style="medium")) - # worksheet.sheet_view.showGridLines = False - # # - # for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=10): - # for cell in row: - # cell.border = borda - - - for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=10): + for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row-1,min_col=9,max_col=10): for cell in row: - if cell.column == 10: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + cell.number_format = 'R$ #,##0.00' + + #borda cabeçario + for row in worksheet.iter_rows(min_row=1, max_row=12,min_col=11,max_col=11): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + #borda fim pagina + for row in worksheet.iter_rows(min_row=size+2, max_row=coordenadora_cpf_row+1,min_col=11,max_col=11): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + + + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=11): + for cell in row: + if cell.column == 11: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) else: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) + + + - worksheet["J11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - worksheet.merge_cells("J11:J12") - worksheet["J11"] = "RESPONSÁVEL PELA GUARDA DO BEM" - worksheet["J11"].border = Border(left=Side(border_style="thin", color='FFFFFF') ,bottom=Side(border_style="thin", color='FFFFFF'), right=Side(border_style="medium") ) - worksheet["J11"].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - worksheet["J10"].border = Border(right =Side(border_style="medium")) - worksheet.row_dimensions[10].height = 2 workbook.save(tabela) @@ -2182,8 +4191,12 @@ def estilo_demonstrativoDeReceita(tabela,tamanho,stringTamanho): tamanho:Corresponde ao tamanho das quantidade de bens. stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referências das formulas. """ + + if tamanho == 0: + tamanho = 1 + + caminho = pegar_caminho(tabela) - workbook = openpyxl.load_workbook(caminho) worksheet = workbook['Demonstrativo de Receita'] size = tamanho + 10 @@ -2408,6 +4421,7 @@ def estilo_demonstrativoDeReceita(tabela,tamanho,stringTamanho): top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] top_left_brasilia_cell.value = brasilia_formula top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_brasilia_cell.font = Font(name="Arial", size=12, color="000000") #DiretorFinanceiro diretor_row = size + 8 @@ -2460,9 +4474,11 @@ def estilo_demonstrativoDeReceita(tabela,tamanho,stringTamanho): top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") + - # borda = Border(right=Side(border_style="medium")) # worksheet.sheet_view.showGridLines = False # # @@ -2481,3 +4497,92 @@ def estilo_demonstrativoDeReceita(tabela,tamanho,stringTamanho): workbook.save(tabela) workbook.close() + + + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\ModeloFINEP.xlsx") +# workbook = openpyxl.load_workbook(tabela) +# sheet = workbook.create_sheet(title="DEMOSTR. RECEITA E DESPESA A.2") +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook.close() + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook = openpyxl.load_workbook(tabela) +# sheet = workbook.create_sheet(title="Relatório de Exec Financ A.1") +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook.close() + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook = openpyxl.load_workbook(tabela) +# nomeTabela = "Kek" +# sheet = workbook.create_sheet(title=f"{nomeTabela}") +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook.close() + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook = openpyxl.load_workbook(tabela) +# nomeTabelaa = "Keka" +# sheet = workbook.create_sheet(title=f"{nomeTabelaa}") +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook.close() + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook = openpyxl.load_workbook(tabela) +# nomeTabelaaa = "PAgamentoPEssoal" +# sheet = workbook.create_sheet(title=f"{nomeTabelaaa}") +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook.close() + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook = openpyxl.load_workbook(tabela) +# nomeTabelaaaa = "Elemento1415" +# sheet = workbook.create_sheet(title=f"{nomeTabelaaaa}") +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook.close() + + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook = openpyxl.load_workbook(tabela) +# nomeTabela33 = "Elemento33" +# sheet = workbook.create_sheet(title=f"{nomeTabela33}") +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook.close() + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook = openpyxl.load_workbook(tabela) +# BENS = "Relação Bens Adquiridos A.5" +# sheet = workbook.create_sheet(title=f"{BENS}") +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook.close() + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook = openpyxl.load_workbook(tabela) +# conc = "Conciliação Bancária A.3" +# sheet = workbook.create_sheet(title=f"{conc}") +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook.close() + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook = openpyxl.load_workbook(tabela) +# rend = "Rendimento de Aplicação" +# sheet = workbook.create_sheet(title=f"{rend}") +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelaEstilizada.xlsx") +# workbook.close() + + +# tamanho = 0 +# nomeVariavel = "Quea" + +# tamanhoestorno = 0 + +# tamanhoBrasilia = estiloDEMOSTRRECEITEDESPESAA2(tabela,20) + +# stringTamanho = tamanhoBrasilia +# estiloRelatorioExecFinanceiroA1(tabela,20,tamanhoBrasilia) +# estiloG(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho,tamanhoestorno) +# estiloPagamentoPessoal(tabela,tamanho,nomeTabelaaa,stringTamanho,tamanhoestorno) +# estiloElementoDeDespesa1415Diarias(tabela,tamanho,nomeTabelaaaa,stringTamanho,tamanhoestorno) +# estiloElementoDeDespesa33PassagensEDespesa(tabela,tamanho,nomeTabela33,stringTamanho,tamanhoestorno) +# estiloRelacaoBens(tabela,tamanho,stringTamanho) +# estilo_conciliacoes_bancaria(tabela,tamanho,tamanhoestorno,stringTamanho) +# estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho) \ No newline at end of file diff --git a/project/app/estiloFap.py b/project/app/estiloFap.py new file mode 100644 index 00000000..dc2d210b --- /dev/null +++ b/project/app/estiloFap.py @@ -0,0 +1,1265 @@ +import openpyxl +from openpyxl.styles import Font, PatternFill, Alignment,NamedStyle,Border, Side +from openpyxl.utils import get_column_letter +from openpyxl.drawing.image import Image +from openpyxl.comments import Comment +from PIL import Image as PILImage +from openpyxl.utils import units +import os +import random +from openpyxl.drawing.geometry import GeomRect + +def pegar_caminho(subdiretorio): + + # Obtém o caminho do script atual + arq_atual = os.path.abspath(__file__) + + # Obtém o diretório do script + app = os.path.dirname(arq_atual) + + # Obtém o diretório pai do script + project = os.path.dirname(app) + + # Obtém o diretório pai do projeto + pipeline = os.path.dirname(project) + + # Junta o diretório pai do projeto com o subdiretório desejado + caminho_pipeline = os.path.join(pipeline, subdiretorio) + + return caminho_pipeline + + +def estiloAnexoDois(tabela,tamanho): + '''Esse estilo e considerado geral por que todas as tabelas que compõe utilizam das mesma colunas. + + Argumentos: + tabela: recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo ja foi iniciado e passou pela preencher fub mas ainda esta sem o estilo que sera aplicado nessa função. + tamanho: e o tamanho total de linhas que irao ser geradas dinamicamente correspondente as entradas do respectivo projeto. o valor varia dentre o tamanho das rubricas + + nomeVariavel: variável utilizada para criar o nomes das variaveis dinamicamente para não haver sobreposição de estilos com o mesmo nome. Esses estilos ocorrem nesses codigos: + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid"'.... + nomeTabela: variável utilizada para a criação do nome da tabela.Ela deriva das rubricas que são colocadas no input quando essa função e chamada. + stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referencias das formulas. + + ''' + nomeVariavel = f'Anexo2' + + random_number = random.randint(1, 10000) + nomeVariavel = f'{nomeVariavel}{random_number}' + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + worksheet = workbook['ANEXO II'] + size = tamanho + 10 + cinza = "f3f3f2" + cinza_escuro = "bfbfbf" + azul = "336394" + azul_claro = 'ccffff' + + + # borda = Border(right=Side(border_style="medium")) + worksheet.sheet_view.showGridLines = False + # + # for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda + + + worksheet.column_dimensions['a'].width = 45 + worksheet.column_dimensions['b'].width = 35 + worksheet.column_dimensions['c'].width = 35 + worksheet.column_dimensions['d'].width = 45#descrição + worksheet.column_dimensions['e'].width = 45 #n do recibo ou qeuivalente + worksheet.column_dimensions['f'].width = 35 #data de emissão + worksheet.column_dimensions['g'].width = 35 #data de emissão + worksheet.column_dimensions['h'].width = 35 #data de emissão + worksheet.column_dimensions['i'].width = 35 #data de emissão + worksheet.column_dimensions['j'].width = 35 #data de emissão + worksheet.column_dimensions['k'].width = 35 #data de emissão + + + #ANEXO II + + + worksheet['A1'] = f'ANEXO 2' + worksheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + worksheet.merge_cells('A1:K1') + + #Fapdf + worksheet['A2'] = f'FAPDF' + worksheet['A2'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A2'].alignment = Alignment(horizontal="left",vertical="center") + + #FUNDAÇÃO DE APOIO A PESQUISA DO DISTRITO FEDERAL + worksheet['A3'] = f'FUNDAÇÃO DE APOIO A PESQUISA DO DISTRITO FEDERAL' + worksheet['A3'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A3'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + #RELAÇÃO DE PAGAMENTOS + worksheet['F3'] = f'RELAÇÃO DE PAGAMENTOS' + worksheet['F3'].font = Font(name="Arial", size=12, color="000000",bold=True,italic=True) + worksheet['F3'].alignment = Alignment(horizontal="center",vertical="center") + + + #N TOA/Processo + worksheet['I2'] = f'Nº TOA / Processo' + worksheet['I2'].font = Font(name="Arial", size=12, color="000000",bold=True,italic=True) + worksheet['I2'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['I2'].border = Border(top=Side(border_style="none") ,bottom=Side(border_style="none"), right=Side(border_style="thin"),left=Side(border_style='thin') ) + worksheet.merge_cells('I2:J2') + + worksheet['I3'].border = Border(top=Side(border_style="none") ,bottom=Side(border_style="thin"), right=Side(border_style="thin"),left=Side(border_style='thin') ) + worksheet.merge_cells('I3:J3') + + + #outorgado + + worksheet['A5'] = "Outorgado:" + worksheet['A5'].font = Font(name="Arial", size=12, color="000000") + worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + #Título do Projeto: + worksheet['A6'] = "Título do Projeto:" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000") + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + #Instituição Gestora: + worksheet['A7'] = "Instituição Gestora:Fundação de Empreendimentos Científicos e Tecnológicos - FINATEC" + worksheet['A7'].font = Font(name="Arial", size=12, color="000000") + worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") + #Instituição Executora: + worksheet['A8'] = "Instituição Executora: " + worksheet['A8'].font = Font(name="Arial", size=12, color="000000") + worksheet['A8'].alignment = Alignment(horizontal="left",vertical="center") + + + + + + + + #merges + worksheet.merge_cells('A5:K5') + worksheet.merge_cells('A6:K6') + worksheet.merge_cells('A7:K7') + worksheet.merge_cells('A8:K8') + + + + #variavel + + input2=f'rowStyle{nomeVariavel}' + + + #abecario #Item Rubrica Nº Cheque ou F. de caixa Data Nº Fatura Favorecido Descrição do Bem ou Serviço (nome, marca, tipo, modelo) Qtde. Unitário Custeio Capital + + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="000000",bold=True) + locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input2].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="hair"), right=Side(border_style="hair"),left=Side(border_style='hair') ) + locals()[input2].height = 20 + + linha_number = 10 + + + + + + + valores = ['Item','Rubrica','Nº Cheque ou F. de caixa','Data','Nº Fatura','Favorecido','Descrição do Bem ou Serviço','Qtde','Unitário','Custeio','Capital'] + col = 1 + for a,b in enumerate(valores): + worksheet.cell(row=linha_number, column=col, value=b) + col = col + 1 + + + #Aumentar a altura das celulas + for row in worksheet.iter_rows(min_row=10, max_row=size, min_col=1, max_col=11): + worksheet.row_dimensions[row[0].row].height = 60 + input3 = f'customNumber{nomeVariavel}' + + # MASCARA R$ + + locals()[input3] = NamedStyle(name=f'{input3}') + locals()[input3].number_format = 'R$ #,##0.00' + locals()[input3].font = Font(name="Arial", size=12, color="000000") + locals()[input3].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + value_to_stop = size + start_row = 10 + + #estilo mascara de dinheiro lina I + for row in range(start_row,size+1): + cell = worksheet[f'I{row}'] + cell.style = locals()[input3] + + #estilo mascara de dinheiro lina J + for row in range(start_row,size+1): + cell = worksheet[f'J{row}'] + cell.style = locals()[input3] + + #estilocinzasimcinzanao + for rows in worksheet.iter_rows(min_row=11, max_row=size, min_col=1, max_col=11): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + + + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + if cell.row == size: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + + + + if cell.column == 11: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + if cell.row == size: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + + + #subtotal + #worksheet.row_dimensions[size+1].height = 6 + celulas_mergidas_subtotal = f"A{size+1}:H{size+1}" + + left_celula_cell = f"A{size+1}" + top_left_cell = worksheet[left_celula_cell] + top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + worksheet.merge_cells(celulas_mergidas_subtotal) + worksheet.row_dimensions[size+1].height = 56.25 + + # FORMULASOMATORIOTOTAL + formula = f"=SUM(J11:J{size})" + celula = f'J{size+1}' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(top=Side(border_style="medium") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + worksheet[celula].number_format = 'R$ #,##0.00' + # CEDULATOTAL + celulaTotal = size + 1 + celula_Total=f'I{celulaTotal}' + worksheet[celula_Total].value = "Total" + worksheet[celula_Total].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula_Total].border = Border(top=Side(border_style="medium") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + worksheet.row_dimensions[celulaTotal].height = 30 + + + #capital + formula = f"=SUM(K11:K{size})" + celula = f'K{size+1}' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(top=Side(border_style="medium") ,left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + worksheet[celula].number_format = 'R$ #,##0.00' + + + + + + # #brasilia + brasilia_row = size + 3 + brasilia_formula = f"Brasilia" + brasilia_merge_cells = f'A{brasilia_row}:H{brasilia_row}' + worksheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_brasilia_cell.font = Font(name="Arial", size=12, color="000000",bold = True) + top_left_brasilia_cell.value = brasilia_formula + + + + # #DiretorFinanceiro + diretor_row = size + 5 + diretor_cargo_row = size + 6 + diretor_cpf_row = size + 7 + + diretor_nome_formula = f"Daniel Monteiro Rosa" + diretor_cargo_formula = f"Diretor-Financeiro" + diretor_cpf_formula = f"450.720.272-87" + diretor_merge_cells = f'A{diretor_row}:D{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:D{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:D{diretor_cpf_row}' + worksheet.merge_cells(diretor_merge_cells) + worksheet.merge_cells(diretor_cargo_merge_cells) + worksheet.merge_cells(diretor_cpf_merge_cells) + top_left_diretor_cell_formula = f'A{diretor_row}' + top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' + top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' + top_left_diretor_cell = worksheet[top_left_diretor_cell_formula] + top_left_diretor_cell_cargo_formula = worksheet[top_left_diretor_cell_cargo_formula] + top_left_diretor_cell_cpf_formula = worksheet[top_left_diretor_cell_cpf_formula] + top_left_diretor_cell.value = diretor_nome_formula + top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula + top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula + top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell.font = Font(name="Arial", size=12, color="000000",bold = True) + top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + # #Coordenadora + coordenadora_row = size + 5 + coordenadora_cargo_row = size + 6 + coordenadora_cpf_row = size + 7 + coordenadora_nome_formula = f"nomeFormula" + coordenadora_cargo_formula = f"cargoformula" + coordenadora_cpf_formula = f"cpformula" + coordenadora_merge_cells = f'E{coordenadora_row}:H{coordenadora_row}' + coordenadora_cargo_merge_cells = f'E{coordenadora_cargo_row}:H{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'E{coordenadora_cpf_row}:H{coordenadora_cpf_row}' + worksheet.merge_cells(coordenadora_merge_cells) + worksheet.merge_cells(coordenadora_cargo_merge_cells) + worksheet.merge_cells(coordenadora_cpf_merge_cells) + top_left_coordenadora_cell_formula = f'E{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'E{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'E{coordenadora_cpf_row}' + top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] + top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] + top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] + top_left_coordenadora_cell.value = coordenadora_nome_formula + top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula + top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) + top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") + top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font = Font(name="Arial", size=12, color="000000") + + + + #custeio + # capital + # Bolsa + # total + + + #QUADRADO CINZA + for row in worksheet.iter_rows(min_row=size + 2, max_row=size + 7, min_col=9, max_col=11): + for cell in row: + cell.fill = openpyxl.styles.PatternFill(start_color=cinza, end_color=cinza, fill_type='solid') + cell.font = Font(name="Arial", size=12, color="000000") + cell.number_format = 'R$ #,##0.00' + if cell.column == 9: + cell.border = Border(left=Side(border_style="thin") ) + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + if cell.column == 11: + cell.border = Border(right=Side(border_style="thin") ) + if cell.row == size + 7: + cell.border = Border(bottom=Side(border_style="thin") ) + if cell.row == size + 7 and cell.column == 11: + cell.border = Border(bottom=Side(border_style="thin"), right=Side(border_style="thin") ) + if cell.row == size + 7 and cell.column == 9: + cell.border = Border(bottom=Side(border_style="thin"), left=Side(border_style="thin") ) + + if cell.row == size + 7 and cell.column == 10: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + + + #TOTAL QUADRADO CINZA + #CUSTEIO + custeio_formula = f"CUSTEIO" + top_left_custeio_cell_formula = f'I{size+3}' + top_left_custeio_cell = worksheet[top_left_custeio_cell_formula] + top_left_custeio_cell.value = custeio_formula + top_left_custeio_cell.alignment = Alignment(horizontal="center",vertical="center") + #CAPITAL + custeio_formula = f"CAPITAL" + top_left_custeio_cell_formula = f'I{size+4}' + top_left_custeio_cell = worksheet[top_left_custeio_cell_formula] + top_left_custeio_cell.value = custeio_formula + top_left_custeio_cell.alignment = Alignment(horizontal="center",vertical="center") + #BOLSA + custeio_formula = f"BOLSA" + top_left_custeio_cell_formula = f'I{size+5}' + top_left_custeio_cell = worksheet[top_left_custeio_cell_formula] + top_left_custeio_cell.value = custeio_formula + top_left_custeio_cell.alignment = Alignment(horizontal="center",vertical="center") + #TOTAL + custeio_formula = f"TOTAL" + top_left_custeio_cell_formula = f'I{size+6}' + top_left_custeio_cell = worksheet[top_left_custeio_cell_formula] + top_left_custeio_cell.value = custeio_formula + top_left_custeio_cell.alignment = Alignment(horizontal="center",vertical="center") + #FORMULA TOTAL + custeio_formula = f"=SUM(J{size+3}:J{size+5})" + top_left_custeio_cell_formula = f'J{size+6}' + top_left_custeio_cell = worksheet[top_left_custeio_cell_formula] + top_left_custeio_cell.value = custeio_formula + top_left_custeio_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_custeio_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + + + cinzaborda = '9e9e9e' + + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=11): + for cell in row: + cell.style = locals()[input2] + if cell.column == 11: + cell.border = Border(top=Side(border_style="medium") , right=Side(border_style="medium") ) + + + + #borda cabeçario + for row in worksheet.iter_rows(min_row=1, max_row=9,min_col=11,max_col=11): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + # #borda fim pagina + # for row in worksheet.iter_rows(min_row=size + 3, max_row=coordenadora_cpf_row+1,min_col=11,max_col=11): + # for cell in row: + # cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + + + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row, max_row=coordenadora_cpf_row,min_col=1,max_col=8): + for cell in row: + if cell.column == 11: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) + + workbook.save(tabela) + workbook.close() + + return brasilia_row + +def estiloAnexoTres(tabela,tamanho,stringTamanho): + if tamanho == 0: + tamanho = 1 + + nomeVariavel = f'Anexo3' + nomeTabela = f'ANEXO III' + + random_number = random.randint(1, 10000) + nomeVariavel = f'{nomeVariavel}{random_number}' + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + worksheet = workbook['ANEXO III'] + size = tamanho + 10 + cinza = "f3f3f2" + cinza_escuro = "d9d9d9" + + + # borda = Border(right=Side(border_style="medium")) + worksheet.sheet_view.showGridLines = False + # + # for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda + + + worksheet.column_dimensions['a'].width = 45 + worksheet.column_dimensions['b'].width = 35 + worksheet.column_dimensions['c'].width = 35 + worksheet.column_dimensions['d'].width = 45#descrição + worksheet.column_dimensions['e'].width = 45 #n do recibo ou qeuivalente + worksheet.column_dimensions['f'].width = 35 #data de emissão + worksheet.column_dimensions['g'].width = 35 #data de emissão + worksheet.column_dimensions['h'].width = 35 #data de emissão + worksheet.column_dimensions['i'].width = 35 #data de emissão + worksheet.column_dimensions['j'].width = 35 #data de emissão + worksheet.column_dimensions['k'].width = 35 #data de emissão + worksheet.column_dimensions['l'].width = 35 #data de emissão + + + #ANEXO II + + nomeTabela = nomeTabela.upper() + worksheet['A1'] = f'ANEXO 3' + worksheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + worksheet.merge_cells('A1:L1') + + #Fapdf + worksheet['A2'] = f'FAPDF' + worksheet['A2'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A2'].alignment = Alignment(horizontal="left",vertical="center") + + #FUNDAÇÃO DE APOIO A PESQUISA DO DISTRITO FEDERAL + worksheet['A3'] = f'FUNDAÇÃO DE APOIO A PESQUISA DO DISTRITO FEDERAL' + worksheet['A3'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A3'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + #RELAÇÃO DE PAGAMENTOS + worksheet['F3'] = f'LISTA DE BENS ADQUIRIDOS NO PROJETO' + worksheet['F3'].font = Font(name="Arial", size=12, color="000000",bold=True,italic=True) + worksheet['F3'].alignment = Alignment(horizontal="center",vertical="center") + + + #N TOA/Processo + worksheet['J2'] = f'Nº TOA / Processo' + worksheet['J2'].font = Font(name="Arial", size=12, color="000000",bold=True,italic=True) + worksheet['J2'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['J2'].border = Border(top=Side(border_style="none") ,bottom=Side(border_style="none"), right=Side(border_style="thin"),left=Side(border_style='thin') ) + worksheet.merge_cells('J2:K2') + + worksheet['J3'] = "='ANEXO II'!I3" + worksheet['J3'].font = Font(name="Arial", size=12, color="000000") + worksheet['J3'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['J3'].border = Border(top=Side(border_style="none") ,bottom=Side(border_style="thin"), right=Side(border_style="thin"),left=Side(border_style='thin') ) + worksheet.merge_cells('J3:K3') + + #outorgado + + worksheet['A5'] = "Outorgado:" + worksheet['A5'].font = Font(name="Arial", size=12, color="000000") + worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + #Título do Projeto: + worksheet['A6'] = "='ANEXO II'!A6" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000") + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + #Instituição Gestora: + worksheet['A7'] = "='ANEXO II'!A7" + worksheet['A7'].font = Font(name="Arial", size=12, color="000000") + worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") + #Instituição Executora: + worksheet['A8'] = "='ANEXO II'!A8" + worksheet['A8'].font = Font(name="Arial", size=12, color="000000") + worksheet['A8'].alignment = Alignment(horizontal="left",vertical="center") + + + + + + + + #merges + worksheet.merge_cells('A5:L5') + worksheet.merge_cells('A6:L6') + worksheet.merge_cells('A7:L7') + worksheet.merge_cells('A8:L8') + + + + #variavel + + input2=f'rowStyle{nomeVariavel}' + + + #abecario #Item Rubrica Nº Cheque ou F. de caixa Data Nº Fatura Favorecido Descrição do Bem ou Serviço (nome, marca, tipo, modelo) Qtde. Unitário Custeio Capital + #estilo cabeçario + + + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="000000",bold=True) + locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input2].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="thin"), right=Side(border_style="thin"),left=Side(border_style='thin') ) + locals()[input2].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type = "solid") + locals()[input2].height = 20 + + linha_number = 10 + + + + + + + valores = ['Item','Nº Cheque ou F. de caixa','Data','Nº Fatura','Favorecido','Descrição do Bem ou Serviço','Qtde','Unitário','Capital','Origem / Plaqueta','Localização','Responsável'] + col = 1 + for a,b in enumerate(valores): + worksheet.cell(row=linha_number, column=col, value=b) + col = col + 1 + + + #Aumentar a altura das celulas + for row in worksheet.iter_rows(min_row=10, max_row=size, min_col=1, max_col=12): + worksheet.row_dimensions[row[0].row].height = 60 + input3 = f'customNumber{nomeVariavel}' + + # MASCARA R$ + + locals()[input3] = NamedStyle(name=f'{input3}') + locals()[input3].number_format = 'R$ #,##0.00' + locals()[input3].font = Font(name="Arial", size=12, color="000000") + locals()[input3].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + value_to_stop = size + start_row = 10 + + #estilo mascara de dinheiro lina I + for row in range(start_row,size+1): + cell = worksheet[f'H{row}'] + cell.style = locals()[input3] + + #estilo mascara de dinheiro lina J + for row in range(start_row,size+1): + cell = worksheet[f'I{row}'] + cell.style = locals()[input3] + + #estilocinzasimcinzanao + for rows in worksheet.iter_rows(min_row=11, max_row=size, min_col=1, max_col=12): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + + + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + if cell.row == size: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + + + + if cell.column == 12: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + if cell.row == size: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + + + #subtotal + #worksheet.row_dimensions[size+1].height = 6 + #subtotal barra + celulas_mergidas_subtotal = f"A{size+1}:G{size+1}" + + left_celula_cell = f"A{size+1}" + top_left_cell = worksheet[left_celula_cell] + top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + top_left_cell.value = f'Declaro que as despesas relacionadas acima foram pagas e que os materiais e equipamentos foram recebidos.' + top_left_cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, + fill_type = "solid") + worksheet.merge_cells(celulas_mergidas_subtotal) + worksheet.row_dimensions[size+1].height = 56.25 + #barra 2 + celulas_mergidas_subtotal = f"J{size+1}:L{size+1}" + left_celula_cell = f"J{size+1}" + top_left_cell = worksheet[left_celula_cell] + top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + top_left_cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, + fill_type = "solid") + worksheet.merge_cells(celulas_mergidas_subtotal) + + + + + # FORMULASOMATORIOTOTAL + formula = f"=SUM(I11:I{size})" + celula = f'I{size+1}' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(top=Side(border_style="medium") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + worksheet[celula].number_format = 'R$ #,##0.00' + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, + fill_type = "solid") + # CEDULATOTAL + celulaTotal = size + 1 + celula_Total=f'H{celulaTotal}' + worksheet[celula_Total].value = "Total" + worksheet[celula_Total].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula_Total].border = Border(top=Side(border_style="medium") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + worksheet.row_dimensions[celulaTotal].height = 30 + worksheet[celula_Total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, + fill_type = "solid") + + + + #brasilia + brasilia_row = size + 3 + brasilia_formula = f"='ANEXO II'!A{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:L{brasilia_row}' + worksheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.value = brasilia_formula + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + + # #DiretorFinanceiro + diretor_row = size + 5 + diretor_cargo_row = size + 6 + diretor_cpf_row = size + 7 + + diretor_nome_formula = f"='ANEXO II'!A{stringTamanho+2}:D{stringTamanho+2}" + diretor_cargo_formula = f"='ANEXO II'!A{stringTamanho+3}:D{stringTamanho+3}" + diretor_cpf_formula = f"='ANEXO II'!A{stringTamanho+4}:D{stringTamanho+4}" + diretor_merge_cells = f'A{diretor_row}:F{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:F{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:F{diretor_cpf_row}' + worksheet.merge_cells(diretor_merge_cells) + worksheet.merge_cells(diretor_cargo_merge_cells) + worksheet.merge_cells(diretor_cpf_merge_cells) + top_left_diretor_cell_formula = f'A{diretor_row}' + top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' + top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' + top_left_diretor_cell = worksheet[top_left_diretor_cell_formula] + top_left_diretor_cell_cargo_formula = worksheet[top_left_diretor_cell_cargo_formula] + top_left_diretor_cell_cpf_formula = worksheet[top_left_diretor_cell_cpf_formula] + top_left_diretor_cell.value = diretor_nome_formula + top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula + top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula + top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + # #Coordenadora + coordenadora_row = size + 5 + coordenadora_cargo_row = size + 6 + coordenadora_cpf_row = size + 7 + coordenadora_nome_formula = f"='ANEXO II'!E{stringTamanho+2}" + coordenadora_cargo_formula = f"='ANEXO II'!E{stringTamanho+3}" + coordenadora_cpf_formula = f"='ANEXO II'!E{stringTamanho+4}" + coordenadora_merge_cells = f'G{coordenadora_row}:L{coordenadora_row}' + coordenadora_cargo_merge_cells = f'G{coordenadora_cargo_row}:L{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'G{coordenadora_cpf_row}:L{coordenadora_cpf_row}' + worksheet.merge_cells(coordenadora_merge_cells) + worksheet.merge_cells(coordenadora_cargo_merge_cells) + worksheet.merge_cells(coordenadora_cpf_merge_cells) + top_left_coordenadora_cell_formula = f'G{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'G{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'G{coordenadora_cpf_row}' + top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] + top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] + top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] + top_left_coordenadora_cell.value = coordenadora_nome_formula + top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula + top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) + top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") + top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font = Font(name="Arial", size=12, color="000000") + + + + cinzaborda = '9e9e9e' + + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=12): + for cell in row: + cell.style = locals()[input2] + if cell.column == 12: + cell.border = Border(top=Side(border_style="medium") , right=Side(border_style="medium"),bottom=Side(border_style='thin') ) + + + + #borda cabeçario + for row in worksheet.iter_rows(min_row=1, max_row=9,min_col=12,max_col=12): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + # #borda fim pagina + # for row in worksheet.iter_rows(min_row=size + 3, max_row=coordenadora_cpf_row+1,min_col=11,max_col=11): + # for cell in row: + # cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + for row in worksheet.iter_rows(min_row=size+2, max_row=coordenadora_cpf_row-1,min_col=12,max_col=12): + for cell in row: + if cell.column == 12: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="none") ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,bottom =Side(border_style="none") ,right=Side(border_style="thin",color='9e9e9e') ) + + + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row, max_row=coordenadora_cpf_row,min_col=1,max_col=12): + for cell in row: + if cell.column == 12: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) + + workbook.save(tabela) + workbook.close() + +def estiloAnexoQuatro(tabela,tamanho,stringTamanho): + + if tamanho == 0: + tamanho = 1 + + + nomeVariavel = f'Anexo4' + random_number = random.randint(1, 10000) + nomeVariavel = f'{nomeVariavel}{random_number}' + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + worksheet = workbook['ANEXO IV'] + size = tamanho + 10 + cinza = "f3f3f2" + cinza_escuro = "d9d9d9" + testeRow = 17; + + + # borda = Border(right=Side(border_style="medium")) + worksheet.sheet_view.showGridLines = False + # + + #imagens + + image_names = [ + 'fapdf.png', + + ] + images = [] + + nomePasta = "../../imagemFap" + diretorio = os.path.dirname(__file__) + + # Loop through the list of image names and create Image objects + for i, name in enumerate(image_names): + caminhoImage = os.path.join(diretorio, nomePasta, name) + pil_image = PILImage.open(caminhoImage) + pil_image.save(caminhoImage) + img = Image(caminhoImage) + images.append(img) + + + worksheet.add_image(images[0], "A1")#fap + + + + + + + # for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda + + worksheet.row_dimensions[1].height = 25 + worksheet.row_dimensions[2].height = 25 + worksheet.column_dimensions['a'].width = 45 #Período + worksheet.column_dimensions['b'].width = 35 #Saldo anterior + worksheet.column_dimensions['c'].width = 35 #Valor Aplicado no período + worksheet.column_dimensions['d'].width = 45 #Valor Resgatado no Período + worksheet.column_dimensions['e'].width = 45 #Imposto de Renda / IOF + worksheet.column_dimensions['f'].width = 35 #Rendimento Bruto + worksheet.column_dimensions['g'].width = 35 #Saldo + + + + #ANEXO II + nomeTabela = 'ANEXO IV' + nomeTabela = nomeTabela.upper() + worksheet['A1'] = f'ANEXO IV' + worksheet['A1'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + worksheet.merge_cells('A1:G1') + + #Fapdf + worksheet['A4'] = f'FAPDF' + worksheet['A4'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + worksheet.merge_cells('A4:G4') + + #FUNDAÇÃO DE APOIO A PESQUISA DO DISTRITO FEDERAL + worksheet['A5'] = f'FUNDAÇÃO DE APOIO A PESQUISA DO DISTRITO FEDERAL' + worksheet['A5'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A5'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.merge_cells('A5:G5') + + #Demonstrativo dos Ganhos Auferidos com Aplicações Financeiras + worksheet['A7'] = f'Demonstrativo dos Ganhos Auferidos com Aplicações Financeiras' + worksheet['A7'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A7'].alignment = Alignment(horizontal="center",vertical="center") + worksheet.merge_cells('A7:G7') + + + #N TOA/Processo + worksheet['F9'] = f'Nº TOA / Processo' + worksheet['F9'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['F9'].alignment = Alignment(horizontal="center",vertical="center") + worksheet.merge_cells('F9:G9') + #N TOA/Processo + worksheet['F10'] = f"='ANEXO II'!I3" + worksheet['F10'].font = Font(name="Arial", size=12, color="000000") + worksheet['F10'].alignment = Alignment(horizontal="center",vertical="center") + worksheet.merge_cells('F10:G10') + + + #outorgado + #Unidade Gestora: + worksheet['A9'] = "Unidade Gestora:" + worksheet['A9'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + worksheet.merge_cells('A9:E9') + #Unidade Gestora: + worksheet['A10'] = "FINATEC - Fundação de Empreendimentos Científicos e Tecnológicos" + worksheet['A10'].font = Font(name="Arial", size=12, color="000000") + worksheet['A10'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + worksheet.merge_cells('A10:E10') + #Projeto: + worksheet['A11'] = "Projeto" + worksheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A11'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + worksheet.merge_cells('A11:E11') + #ProjetorEFERENCIA: + worksheet['A12'] = "='ANEXO II'!A6" + worksheet['A12'].font = Font(name="Arial", size=12, color="000000") + worksheet['A12'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + worksheet.merge_cells('A12:E13') + #Período abrangido: + worksheet['F11'] = "Período abrangido:" + worksheet['F11'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['F11'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.merge_cells('F11:G11') + + #APLICAÇÃO FINANCEIRA - CURTO PRAZO + worksheet['A14'] = "APLICAÇÃO FINANCEIRA - " + worksheet['A14'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A14'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet.merge_cells('A14:G14') + + + + + worksheet.row_dimensions[15].height = 20 + worksheet.row_dimensions[16].height = 20 + + # + input2=f'rowStyle{nomeVariavel}' + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="000000",bold=True) + locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input2].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, fill_type = "solid") + locals()[input2].border = Border(top=Side(border_style="medium") ) + locals()[input2].height = 20 + + + linha_number = 15 + + + + + # #stylecinza + start_row = 17 + for rows in worksheet.iter_rows(min_row=15, max_row=16, min_col=1, max_col=7): + for cell in rows: + if cell.row % 2 == 0: + cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, + fill_type = "solid") + + #cabcerario abaixo de aplicação financeira + row_number = 15 + values = ["Período","Saldo Anterior","Valor Aplicado no período",'Valor Resgatado no Período','Imposto de Renda / IOF','Rendimento Bruto','Saldo'] + coluna = 1 + for a,b in enumerate(values): + worksheet.cell(row=row_number, column=coluna, value=b) + coluna = coluna + 1 + + + + + # #RENDIMENTO LIQUIDO + # # # print(size) + # for row in worksheet.iter_rows(min_row=testeRow, max_row=size, min_col=7, max_col=7): + # for cell in row: + # stringSaldo = f"=E{cell.row} - F{cell.row}" + # cell.value = stringSaldo + + + + + #BARRAS DE DADOS + start_row = 14 + for rows in worksheet.iter_rows(min_row=testeRow, max_row=size, min_col=1, max_col=7): + for cell in rows: + if cell.row % 2==0: + cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + # #MASCARA VERMELHO + # for rows in worksheet.iter_rows(min_row=testeRow, max_row=size-1, min_col=6, max_col=6): + # for cell in rows: + # cell.font = Font(name="Arial", size=12, color="f90000") + # cell.number_format ='#,##0.00' + + #MASCARANEGRITO + for rows in worksheet.iter_rows(min_row=testeRow, max_row=size-1, min_col=1, max_col=1): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + + + # # #MASCARA AZUL + # # for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=6, max_col=6): + # # for cell in rows: + # # cell.font = Font(name="Arial", size=12, color="141fca") + # # cell.number_format ='#,##0.00' + + # # for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=7, max_col=7): + # # for cell in rows: + # # cell.font = Font(name="Arial", size=12, color="141fca",bold=True) + # # cell.number_format ='#,##0.00' + + + + #barra de totais + formula = f"Saldo anterior" + celula = f'A{testeRow}' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + + + + + + + # FORMULATOTAL + #B + size = size + 1 + formula = f"=SUM(B{testeRow}:B{size-1})" + celula = f'B{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #C + formula = f"=SUM(C{testeRow}:C{size-1})" + celula = f'C{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #D + formula = f"=SUM(D{testeRow}:D{size-1})" + celula = f'D{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #E + formula = f"=SUM(E{testeRow}:E{size-1})" + celula = f'E{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #F + formula = f"=SUM(F{testeRow}:F{size-1})" + celula = f'F{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #G + formula = f"=SUM(G{testeRow}:G{size-1})" + celula = f'G{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + #Total + celula_total = F'A{size}' + worksheet[celula_total] = f'TOTAL' + worksheet[celula_total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #borda total + + + + #brasilia + brasilia_row = size + 3 + brasilia_formula = f"='ANEXO II'!A{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:G{brasilia_row}' + worksheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.value = brasilia_formula + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + + # #DiretorFinanceiro + diretor_row = size + 5 + diretor_cargo_row = size + 6 + diretor_cpf_row = size + 7 + + diretor_nome_formula = f"='ANEXO II'!A{stringTamanho+2}:C{stringTamanho+2}" + diretor_cargo_formula = f"='ANEXO II'!A{stringTamanho+3}:C{stringTamanho+3}" + diretor_cpf_formula = f"='ANEXO II'!A{stringTamanho+4}:C{stringTamanho+4}" + diretor_merge_cells = f'A{diretor_row}:C{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:C{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:C{diretor_cpf_row}' + worksheet.merge_cells(diretor_merge_cells) + worksheet.merge_cells(diretor_cargo_merge_cells) + worksheet.merge_cells(diretor_cpf_merge_cells) + top_left_diretor_cell_formula = f'A{diretor_row}' + top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' + top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' + top_left_diretor_cell = worksheet[top_left_diretor_cell_formula] + top_left_diretor_cell_cargo_formula = worksheet[top_left_diretor_cell_cargo_formula] + top_left_diretor_cell_cpf_formula = worksheet[top_left_diretor_cell_cpf_formula] + top_left_diretor_cell.value = diretor_nome_formula + top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula + top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula + top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + # #Coordenadora + coordenadora_row = size + 5 + coordenadora_cargo_row = size + 6 + coordenadora_cpf_row = size + 7 + coordenadora_nome_formula = f"='ANEXO II'!E{stringTamanho+2}" + coordenadora_cargo_formula = f"='ANEXO II'!E{stringTamanho+3}" + coordenadora_cpf_formula = f"='ANEXO II'!E{stringTamanho+4}" + coordenadora_merge_cells = f'E{coordenadora_row}:G{coordenadora_row}' + coordenadora_cargo_merge_cells = f'E{coordenadora_cargo_row}:G{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'E{coordenadora_cpf_row}:G{coordenadora_cpf_row}' + worksheet.merge_cells(coordenadora_merge_cells) + worksheet.merge_cells(coordenadora_cargo_merge_cells) + worksheet.merge_cells(coordenadora_cpf_merge_cells) + top_left_coordenadora_cell_formula = f'E{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'E{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'E{coordenadora_cpf_row}' + top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] + top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] + top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] + top_left_coordenadora_cell.value = coordenadora_nome_formula + top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula + top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) + top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.font = Font(name="Arial", size=12, color="000000") + top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.font= Font(name="Arial", size=12, color="000000") + + + + cinzaborda = '9e9e9e' + + #estiloccinza cabeçario + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=7): + for cell in row: + cell.style = locals()[input2] + if cell.column == 7: + cell.border = Border(top=Side(border_style="medium") , right=Side(border_style="medium"),bottom=Side(border_style='thin') ) + + for i in range(1,7): + worksheet.merge_cells(start_row=15,end_row=16,start_column=i,end_column=i) + + #estilo dinheiro tabela toda + for row in worksheet.iter_rows(min_row=17, max_row=size, min_col=2, max_col=7): + for cell in row: + cell.number_format = 'R$ #,##0.00' + + + + + + #borda cabeçario + for row in worksheet.iter_rows(min_row=1, max_row=14,min_col=7,max_col=7): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="thin",color='9e9e9e') ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + + #borda fim pagina + for row in worksheet.iter_rows(min_row=15, max_row=size,min_col=1,max_col=7): + for cell in row: + if cell.column == 7 and cell.row == 15 : + cell.border = Border(top=Side(border_style="medium") ,right = Side(border_style="medium") ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + if cell.column == 7 and cell.row != 15: + cell.border = Border(top=Side(border_style="none") ,right = Side(border_style="medium") ,left =Side(border_style="none") ,bottom=Side(border_style="none") ) + if cell.row == size and cell.column == 7: + cell.border = Border(top=Side(border_style="none") ,bottom = Side(border_style="medium") ,left =Side(border_style="none") ,right=Side(border_style="medium") ) + if cell.row == size and cell.column != 7: + cell.border = Border(top=Side(border_style="none") ,bottom = Side(border_style="medium") ,left =Side(border_style="none") ,right=Side(border_style="none") ) + + + for row in worksheet.iter_rows(min_row=size+1, max_row=coordenadora_cpf_row-1,min_col=7,max_col=7): + for cell in row: + if cell.column == 7: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="none") ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,bottom =Side(border_style="none") ,right=Side(border_style="thin",color='9e9e9e') ) + + + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row, max_row=coordenadora_cpf_row,min_col=1,max_col=7): + for cell in row: + if cell.column == 7: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="thin",color='9e9e9e') ,bottom=Side(border_style="thin",color='9e9e9e') ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="thin",color='9e9e9e') ) + + + + workbook.save(tabela) + workbook.close() + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\modeloFap.xlsx") +# # Load the workbook and create a new sheet +# workbook = openpyxl.load_workbook(tabela) +# sheet = workbook.create_sheet(title="ANEXO II") + +# # Save the workbook +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelafap.xlsx") +# workbook.close() + + + + + + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelafap.xlsx") +# tamanho = 20 +# nomeTabela = "ANEXO II" +# stringTamanho = 0 +# tamanhoestorno = 0 +# rowBrasilia = estiloAnexoDois(tabela,tamanho,nomeTabela,stringTamanho,tamanhoestorno) + + + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelafap.xlsx") +# # Load the workbook and create a new sheet +# workbook = openpyxl.load_workbook(tabela) +# sheet = workbook.create_sheet(title="ANEXO III") + +# # Save the workbook +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelafap.xlsx") +# workbook.close() + + + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelafap.xlsx") +# tamanho = 20 +# nomeTabela = "ANEXO III" +# stringTamanho = 0 +# tamanhoestorno = 0 +# estiloAnexoTres(tabela,tamanho,nomeTabela,rowBrasilia,tamanhoestorno) + +# # anexo4 +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelafap.xlsx") +# # Load the workbook and create a new sheet +# workbook = openpyxl.load_workbook(tabela) +# sheet = workbook.create_sheet(title="ANEXO IV") + +# # Save the workbook +# workbook.save("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelafap.xlsx") +# workbook.close() + + + +# tabela = pegar_caminho("C:\\Users\\hemanoel.brito\\Desktop\\estilos\\tabelafap.xlsx") +# tamanho = 20 +# nomeTabela = "ANEXO IV" +# stringTamanho = 0 +# tamanhoestorno = 0 +# estiloAnexoQuatro(tabela,tamanho,nomeTabela,rowBrasilia,tamanhoestorno) + + + + + diff --git a/project/app/estiloIBICT.py b/project/app/estiloIBICT.py index 53a4b8f6..e5b84bc1 100755 --- a/project/app/estiloIBICT.py +++ b/project/app/estiloIBICT.py @@ -1,328 +1,1445 @@ import openpyxl from openpyxl.styles import Font, PatternFill, Alignment,NamedStyle,Border, Side -from openpyxl.drawing.image import Image -from PIL import Image as PILImage import os +import random +from PIL import Image as PILImage +from openpyxl.drawing.image import Image #pegar o caminho do arquivo -def pegar_caminho(nome_arquivo): +# def pegar_caminho(nome_arquivo): - # Obter o caminho absoluto do arquivo Python em execução - caminho_script = os.path.abspath(__file__) +# # Obter o caminho absoluto do arquivo Python em execução +# caminho_script = os.path.abspath(__file__) - # Obter o diretório da pasta onde o script está localizado - pasta_script = os.path.dirname(caminho_script) +# # Obter o diretório da pasta onde o script está localizado +# pasta_script = os.path.dirname(caminho_script) - # Combinar o caminho da pasta com o nome do arquivo Excel - caminho = os.path.join(pasta_script, nome_arquivo) +# # Combinar o caminho da pasta com o nome do arquivo Excel +# caminho = os.path.join(pasta_script, nome_arquivo) - return caminho +# return caminho + +def pegar_caminho(subdiretorio): + # Obtém o caminho do script atual + arq_atual = os.path.abspath(__file__) + + # Obtém o diretório do script + app = os.path.dirname(arq_atual) + + # Obtém o diretório pai do script + project = os.path.dirname(app) + + # Obtém o diretório pai do projeto + pipeline = os.path.dirname(project) + + # Junta o diretório pai do projeto com o subdiretório desejado + caminho_pipeline = os.path.join(pipeline, subdiretorio) + + return caminho_pipeline +def imagemIbict(tabela,nomeSheet): + '''Estilo da Pagina do Relatorio Execução da Receita e Despesa + + Argumentos: + tabela : recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo ja foi iniciado e passou pela preencher fub mas ainda esta sem o estilo que sera aplicado nessa função. + nomeSheet = recebe o nome da tabela que tem que preencher com as imagens + -def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela): - nomeSheet=nomeVariavel + ''' caminho = pegar_caminho(tabela) workbook = openpyxl.load_workbook(caminho) - worksheet = workbook[nomeTabela] - size = tamanho + 16 - cinza = "d9d9d9" - cinza_escuro = "bfbfbf" - azul = "336394" - azul_claro = '1c8cbc' - - borda = Border(right=Side(border_style="dashed")) - worksheet.sheet_view.showGridLines = False - # - for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): - for cell in row: - cell.border = borda - - - worksheet.column_dimensions['a'].width = 25 - worksheet.column_dimensions['b'].width = 25 - worksheet.column_dimensions['c'].width = 35 - worksheet.column_dimensions['d'].width = 35#descrição - worksheet.column_dimensions['e'].width = 65 #n do recibo ou qeuivalente - worksheet.column_dimensions['f'].width = 25 #data de emissão - worksheet.column_dimensions['g'].width = 25 #data de emissão - worksheet.column_dimensions['h'].width = 25 #data de emissão - worksheet.column_dimensions['i'].width = 25 #data de emissão - worksheet.column_dimensions['j'].width = 25 #data de emissão + sheet = workbook[nomeSheet] - - #cabecario relação de pagamentos - outro servicoes de terceiros - worksheet.merge_cells('A7:J8') - if nomeSheet == "diarias": - worksheet['A7'] = f'R E L A Ç Ã O D E P A G A M E N T O S -DIÁRIAS E PASSAGENS' - elif nomeSheet == "custoOperacional": - worksheet['A7'] = f'R E L A Ç Ã O D E P A G A M E N T O S - CUSTO OPERACIONAL' - elif nomeSheet == "pessoaJuridica": - worksheet['A7'] = f'R E L A Ç Ã O D E P A G A M E N T O S - OUTROS SERVIÇOS DE TERCEIROS - PESSOA JURÍDICA' - elif nomeSheet == "bolsaExtensao": - worksheet['A7'] = f'R E L A Ç Ã O D E P A G A M E N T O S - BOLSA DE PESQUISA' - elif nomeSheet == "materialDeConsumo": - worksheet['A7'] = f'R E L A Ç Ã O D E P A G A M E N T O S - MATERIAL DE CONSUMO' - elif nomeSheet == "evento": - worksheet['A7'] = f'R E L A Ç Ã O D E P A G A M E N T O S - EVENTOS' - - - # List of image names image_names = [ - 'finatec.png', - 'ibict.png' + 'ibict.png', + 'finatec.png' + ] - - # # Path to the images - # path = 'C:\\Users\\Softex\\Desktop\\entrega29\\' - - # # List to hold Image objects - # images = [] - - # # Loop through the list of image names and create Image objects - # for i, name in enumerate(image_names): - # image_path = path + name - # pil_image = PILImage.open(image_path) - # pil_image.save(image_path) - # img = Image(image_path) - # images.append(img) - - # List to hold Image objects images = [] - nomePasta = "imagensIBICIT" + nomePasta = "../../imagensIBICIT" diretorio = os.path.dirname(__file__) # Loop through the list of image names and create Image objects for i, name in enumerate(image_names): - caminhoImage = os.path.join(diretorio, nomePasta, name) - pil_image = PILImage.open(caminhoImage) - pil_image.save(caminhoImage) - img = Image(caminhoImage) - images.append(img) + caminhoImage = os.path.join(diretorio, nomePasta, name) + pil_image = PILImage.open(caminhoImage) + pil_image.save(caminhoImage) + img = Image(caminhoImage) + images.append(img) - worksheet.add_image(images[1], "A1")#ibict - worksheet.add_image(images[0], "H1")#finatec - + sheet.add_image(images[0], "A1")#ibict + sheet.add_image(images[0], "D1")#finatec + + # for row in sheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda + + sheet.row_dimensions[1].height = 25 + sheet.row_dimensions[2].height = 25 + + workbook.save(tabela) + workbook.close() - worksheet['A7'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - worksheet['A7'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A7'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") +def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): + '''Estilo da Pagina do Relatorio Execução da Receita e Despesa + + Argumentos: + tabela : recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo ja foi iniciado e passou pela preencher fub mas ainda esta sem o estilo que sera aplicado nessa função. + tamanho : é o tamanho total de linhas que irão ser geradas dinâmicamente. O valor varia dentre o tamanho da quantidade de rubricas diferente que o projeto possui, excluindo Obras e Instalações + Aplicações Financeira e Equipamento e Material Permanente sendo nacional ou importado. + stringTamanho : refere-se aonde esta localizado a string brasília na pagina Receita e despesa para a referencias das formulas. + + + ''' - worksheet.merge_cells('A9:F9') - worksheet['A9'] = "='Receita x Despesa'!A9:J9" - worksheet['A9'].font = Font(name="Arial", size=12, color="000000") - worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center") + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + sheet = workbook['Exec. Receita e Despesa'] + + size = tamanho + 16; + size2 = size + 1 + cinza = "f1f1f1" + azul_claro = '1c8cbc' + # sheet.row_dimensions[3] = 28 + numRowInicial = 7 + numRowInicialMerge = 8 + variavelA = f'A{numRowInicial}' + + + #cabecario + sheet.merge_cells('A{numRowInicial}:I{numRowInicialMerge}')#7 + sheet['A{numRowInicial}'] = f'E X E C U Ç Ã O D A R E C E I T A E D E S P E S A ' + sheet['A{numRowInicial}'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + sheet['A{numRowInicial}'].alignment = Alignment(horizontal="center",vertical="center") + sheet['A{numRowInicial}'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + numRowInicial = numRowInicial + 1 + + sheet.merge_cells('A{numRowInicial}:I{numRowInicial}')#8 + sheet['A{numRowInicial}'] = "='Receita x Despesa'!A{numRowInicial}:I{numRowInicial}" + sheet['A{numRowInicial}'].font = Font(name="Arial", size=12, color="000000") + sheet['A{numRowInicial}'].alignment = Alignment(horizontal="left",vertical="center") + numRowInicial = numRowInicial + 1 + - worksheet.merge_cells('A10:F10') - worksheet['A10'] = "='Receita x Despesa'!A10:J10" - worksheet['A10'].font = Font(name="Arial", size=12, color="000000") - worksheet['A10'].alignment = Alignment(horizontal="left",vertical="center") + sheet.merge_cells('A{numRowInicial}:I{numRowInicial}')#9 + sheet['A{numRowInicial}'] = "='Receita x Despesa'!A{numRowInicial}:I{numRowInicial}" + sheet['A{numRowInicial}'].font = Font(name="Arial", size=12, color="000000") + sheet['A{numRowInicial}'].alignment = Alignment(horizontal="left",vertical="center") + numRowInicial = numRowInicial + 1 + - worksheet.merge_cells('A11:F11') - worksheet['A11'] = "='Receita x Despesa'!A11:J11" - worksheet['A11'].font = Font(name="Arial", size=12, color="000000") - worksheet['A11'].alignment = Alignment(horizontal="left",vertical="center") + sheet.merge_cells('A{numRowInicial}:I{numRowInicial}')#10 + sheet['A{numRowInicial}'] = "='Receita x Despesa'!A{numRowInicial}:I{numRowInicial}" + sheet['A{numRowInicial}'].font = Font(name="Arial", size=12, color="000000") + sheet['A{numRowInicial}'].alignment = Alignment(horizontal="left",vertical="center") + numRowInicial = numRowInicial + 1 + - worksheet.merge_cells('A12:F12') - worksheet['A12'] = "='Receita x Despesa'!A12:J12" - worksheet['A12'].font = Font(name="Arial", size=12, color="000000") - worksheet['A12'].alignment = Alignment(horizontal="left",vertical="center") + sheet.merge_cells('A{numRowInicial}:I{numRowInicial}')#11 + sheet['A{numRowInicial}'] = "='Receita x Despesa'!A{numRowInicial}:I{numRowInicial}" + sheet['A{numRowInicial}'].font = Font(name="Arial", size=12, color="000000") + sheet['A{numRowInicial}'].alignment = Alignment(horizontal="left",vertical="center") + numRowInicial = numRowInicial + 1 + - worksheet.merge_cells('A13:F13') - worksheet['A13'] = "='Receita x Despesa'!A13:J13" - worksheet['A13'].font = Font(name="Arial", size=12, color="000000") - worksheet['A13'].alignment = Alignment(horizontal="left",vertical="center") + sheet.merge_cells('A{numRowInicial}:I{numRowInicial}')#12 + sheet['A{numRowInicial}'] = "='Receita x Despesa'!A{numRowInicial}:I{numRowInicial}" + sheet['A{numRowInicial}'].font = Font(name="Arial", size=12, color="000000") + sheet['A{numRowInicial}'].alignment = Alignment(horizontal="left",vertical="center") + numRowInicial = numRowInicial + 1 + - #variavel - - input2=f'rowStyle{nomeVariavel}' + sheet.merge_cells('A{numRowInicial}:I{numRowInicial}')#13 + sheet['A{numRowInicial}'] = 'E X E C U Ç Ã O D A R E C E I T A E D E S P E S A' + sheet['A{numRowInicial}'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + sheet['A{numRowInicial}'].alignment = Alignment(horizontal="center",vertical="center") + sheet['A{numRowInicial}'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + numRowInicial = numRowInicial + 1 + + #aumentao altura + for i in range(1,10): + sheet.row_dimensions[i].height = 20 + + sheet.row_dimensions[7].height = 25 + sheet.row_dimensions[9].height = 35 + sheet.row_dimensions[8].height = 25 + sheet.row_dimensions[15].height = 30 + + + + #esticando coluna A e pintando ela + numRowInicial = numRowInicial + 1 #ta na 15 + sheet.merge_cells('A{numRowInicial}:A16') + sheet['A{numRowInicial}'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + sheet.column_dimensions['a'].width = 55 + sheet.column_dimensions['b'].width = 20 + sheet.column_dimensions['c'].width = 20 + sheet.column_dimensions['d'].width = 20 + sheet.column_dimensions['e'].width = 20 + sheet.column_dimensions['f'].width = 20 + sheet.column_dimensions['g'].width = 20 + sheet.column_dimensions['h'].width = 20 + sheet.column_dimensions['i'].width = 20 + sheet.column_dimensions['j'].width = 1 + #resto do cabecario + sheet.merge_cells('B12:E13') + sheet['B12'] = 'EXECUTADO NO PERÍODO\n(Valores em R$)' + sheet['B12'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + sheet['B12'].alignment = Alignment(horizontal="center",vertical="center") + sheet['B12'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + sheet.merge_cells('F12:I13') + sheet['F12'] = 'ACUMULADO ATÉ O PERÍODO\n(Valores em R$)' + sheet['F12'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + sheet['F12'].alignment = Alignment(horizontal="center",vertical="center") + sheet['F12'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - #colunas azul cabecario - locals()[input2] = NamedStyle(name=f'{input2}') - locals()[input2].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - locals()[input2].border = Border(top=Side(border_style="thin") ,bottom=Side(border_style="thin") ) - locals()[input2].height = 20 - linha_number = 15 - for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=10): + + + + + + + #%porcentagem Despesas correntes + #IFERROR (C16/B16;0) + #%porcentagem Despesas de Capital + #IFERROR (C16/B16;0) + percentage_style = NamedStyle(name='percentage', number_format='0%') + #diferença e calculo da porcentagem + for row in sheet.iter_rows(min_row=15, max_row=size2+9, min_col=1, max_col=9): for cell in row: - cell.style = locals()[input2] - if cell.column == 10: - cell.border = Border(top=Side(border_style="thin") ,bottom=Side(border_style="thin"), right=Side(border_style="thin") ) + if cell.column == 4: + stringSaldo = f"=B{cell.row} - C{cell.row}" + cell.value = stringSaldo + if cell.column == 8: + stringSaldo = f"=F{cell.row} - G{cell.row}" + cell.value = stringSaldo + + + if cell.column == 5: + stringPorcentagem = f"=IFERROR(C{cell.row}/B{cell.row}, 0)" + cell.value = stringPorcentagem + cell.style = percentage_style + if cell.column == 9: + stringPorcentagem = f"=IFERROR(G{cell.row}/F{cell.row}, 0)" + cell.value = stringPorcentagem + cell.style = percentage_style + + #adicionara mascara do numero + for row in sheet.iter_rows(min_row=15, max_row=size2+9, min_col=1, max_col=9): + for cell in row: + if cell.column != 5 and cell.column != 9: + cell.number_format ='#,##0.00' + + + - valores = ["ITEM","NOME","CNPJ/CPF",'ESPECIFICAÇÃO DA DESPESA','DESCRIÇÃO',"Nº DO RECIBO OU EQUIVALENTE","DATA DE EMISSÃO",'CHEQUE / ORDEM BANCÁRIA','DATA DE PGTO','Valor'] + + + + + #adicionar borda em tudo + borda = Border(right=Side(border_style="medium")) + sheet.sheet_view.showGridLines = False + for row in sheet.iter_rows(min_row=1, max_row=size2+14,min_col=9,max_col=9): + for cell in row: + cell.border = borda + + font = Font(name='Arial', size=12) + #Colocar tudo arial 12 + for row in sheet.iter_rows(min_row=16): + for cell in row: + cell.font = font + #preenche a coluna A e F com cinza + for row in sheet.iter_rows(min_row=16, max_row=size2+9,min_col=1,max_col=9): + for cell in row: + if cell.column == 1 or cell.column == 6 or cell.column == 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + if cell.column == 6 or cell.column == 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = cell.font = Font(name='Arial', size=12,bold= True) + +###pinta de azul a linha desejada + for row in sheet.iter_rows(min_row=15, max_row=sheet.max_row, min_col=sheet.min_row, max_col= 9): + for cell in row: + if cell.row == 15: + cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro, + fill_type = "solid") + cell.font = Font(name='Arial', size=12,bold= True) + + if cell.row == size2 or cell.row == size2 +5 or cell.row == size2 + 7 or cell.row== size2+9: + cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro, + fill_type = "solid") + cell.font = Font(name='Arial', size=12,bold= True) + + + + + #cabecario negrito sem fundo + + valores = ["RUBRICA","PREVISTO","REALIZADO","SALDO",'(%)\nREALIZADO',"PREVISTO","REALIZADO","SALDO","(%)\nREALIZADO"] col = 1 for a,b in enumerate(valores): - worksheet.cell(row=linha_number, column=col, value=b) + sheet.cell(row=14, column=col, value=b) col = col + 1 + #coloca em negrito + font = Font(name='Arial', size=12,bold=True) + #Colocar tudo arial 12 + for row in sheet.iter_rows(min_row=14,max_row=14): + for cell in row: + cell.font = font - #Aumentar a altura das celulas - for row in worksheet.iter_rows(min_row=16, max_row=size, min_col=1, max_col=10): - worksheet.row_dimensions[row[0].row].height = 60 - input3 = f'customNumber{nomeVariavel}' + #depsesas e capital + despesasDeCapitalString = f"I. DESPESAS CORRENTES" + despesasDeCapitalStringCelula = f'A{15}' + sheet[despesasDeCapitalStringCelula] = despesasDeCapitalString + cell=sheet[despesasDeCapitalStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + + + + + #depsesas e capital + despesasDeCapitalString = f"II. DESPESAS DE CAPITAL" + despesasDeCapitalStringCelula = f'A{size2}' + sheet[despesasDeCapitalStringCelula] = despesasDeCapitalString + cell=sheet[despesasDeCapitalStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + - # MASCARA R$ - - locals()[input3] = NamedStyle(name=f'{input3}') - locals()[input3].number_format = 'R$ #,##0.00' - locals()[input3].font = Font(name="Arial", size=12, color="000000") - locals()[input3].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - #estilocinzasimcinzanao - value_to_stop = size - start_row = 16 -# - for row in range(start_row,size+1): - cell = worksheet[f'J{row}'] - cell.style = locals()[input3] - - for rows in worksheet.iter_rows(min_row=16, max_row=size, min_col=1, max_col=10): - for cell in rows: - if cell.row % 2: - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - if cell.column == 10: - cell.font = Font(name="Arial", size=12, color="000000") - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="dashed") ,bottom=Side(border_style="hair") ) - else: - cell.font = Font(name="Arial", size=12, color="000000") - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) - - - #subtotal - stringAfinarCelula =size+2 - worksheet.row_dimensions[size+2].height = 6 - celulas_mergidas_subtotal = f"A{size+2}:I{size+2}" - worksheet.merge_cells(celulas_mergidas_subtotal) - left_celula_cell = f"A{size+2}" - top_left_cell = worksheet[left_celula_cell] - top_left_cell.value = "Sub Total1" - top_left_cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") - top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) - top_left_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="thin") ) - worksheet.row_dimensions[size+2].height = 56.25 + obrasEInstalacoeslString = f"Obras e Instalações" + obrasEInstalacoeslStringCelula = f'A{size2+1}' + sheet[obrasEInstalacoeslStringCelula] = obrasEInstalacoeslString + + + equipamentoseMaterialPermanenteString = f"Equipamentos e Material Permanente" + equipamentoseMaterialPermanenteStringCelula = f'A{size2+2}' + sheet[equipamentoseMaterialPermanenteStringCelula] = equipamentoseMaterialPermanenteString + cell=sheet[equipamentoseMaterialPermanenteStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell=sheet[f'B{size2+2}'] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + + - # FORMULATOTAL - formula = f"=SUM(J10:J{size})" - celula = f'J{size+2}' - worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") - worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet[celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="dashed") ,bottom=Side(border_style="thin") ) - worksheet[celula].number_format = 'R$ #,##0.00' - #restituições creditadas - restituicoes = size + 3 - celula_restituicoes=f'A{restituicoes}' - worksheet[celula_restituicoes].value = "RESTITUIÇÕES CREDITADAS" - worksheet[celula_restituicoes].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet.row_dimensions[restituicoes].height = 30 + nacionalString = f" a) Nacional" + nacionalStringCelula = f'A{size2+3}' + sheet[nacionalStringCelula] = nacionalString + - input4 = f'row_style_diaria_append{nomeVariavel}' - #estilo colunas restitucoes creditadas - locals()[input4] = NamedStyle(name=f'{input4}') - locals()[input4].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - locals()[input4].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') - locals()[input4].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - locals()[input4].height = 30 - locals()[input4].border = Border(top=Side(border_style="thin") ,bottom=Side(border_style="thin") ) + importadoString = f" b) Importado" + importadoStringCelula = f'A{size2+4}' + sheet[importadoStringCelula] = importadoString + + + #depsesas e capital + utilRendimentosString = f"III.UTILIZAÇÃO DE RENDIMENTOS" + utilRendimentosStringCelula = f'A{size2+7}' + sheet[utilRendimentosStringCelula] = utilRendimentosString + cell=sheet[utilRendimentosStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell=sheet[f'B{size2+1}'] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + - row_number = size + 4 - - for column in range(1, 11): - cell = worksheet.cell(row=row_number, column=column) - cell.style = locals()[input4] - if cell.column == 10: - cell.border = Border(top=Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="thin") ) + + apliFinString = f"Aplicação Financeira" + apliFinStringCelula = f'A{size2+8}' + sheet[apliFinStringCelula] = apliFinString + #barra de total nova 22/02 + totalString = f"TOTAL" + totalStringCelula = f'A{size2+5}' + sheet[totalStringCelula] = totalString + cell=sheet[totalStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.fill = PatternFill(start_color='9c9c9c', end_color='9c9c9c',fill_type = "solid") + cell.alignment = Alignment(horizontal="center",vertical="center") - values = ["Item","Restituidor","CNPJ/CPF",'Descrição',"Cheque equivalente","Data do Cheque",'Nº do Depósito','Data da Devolução','Valor'] - coluna = 1 - for a,b in enumerate(values): - worksheet.cell(row=row_number, column=coluna, value=b) - if coluna == 4: - coluna = coluna + 1 - coluna = coluna + 1 - + + totalString = f"TOTAL" + totalStringCelula = f'A{size2+9}' + sheet[totalStringCelula] = totalString + cell=sheet[totalStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.fill = PatternFill(start_color='9c9c9c', end_color='9c9c9c',fill_type = "solid") + cell.alignment = Alignment(horizontal="center",vertical="center") - merge_formula = f'D{row_number}:E{row_number}' - worksheet.merge_cells(merge_formula) + #barra total nova + + formula = f"=SUM(B{size2}, B15)" + sheet[f'B{size2+5}'] = formula + formula = f"=SUM(C{size2}, C15)" + sheet[f'C{size2+5}'] = formula + + formula = f"=SUM(D{size2}, D15)" + sheet[f'D{size2+5}'] = formula + + formula = f"=SUM(F{size2}, F15)" + sheet[f'F{size2+5}'] = formula + + formula = f"=SUM(G{size2}, G15)" + sheet[f'G{size2+5}'] = formula + + formula = f"=SUM(H{size2},H15)" + sheet[f'H{size2+5}'] = formula + + + #sheet[f'H{size2+5}'] + sheet.row_dimensions[size2 + 6].height = 1 - #subtotal2 - sub_total2_row = size + 5 - subtotal_merge_cells= f'A{sub_total2_row}:I{sub_total2_row}' - worksheet.merge_cells(subtotal_merge_cells) - top_left_subtotal2_cell_formula = f'A{sub_total2_row}' - top_left_subtotal2_cell = worksheet[top_left_subtotal2_cell_formula] - top_left_subtotal2_cell.value = "Sub Total 2" - top_left_subtotal2_cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - top_left_subtotal2_cell.font = Font(name="Arial", size=12, color="000000",bold=True) - top_left_subtotal2_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_subtotal2_cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="thin") ,right =Side(border_style="hair") ,bottom=Side(border_style="thin") ) - sub_formula_row_celula = f'J{sub_total2_row}' - worksheet[sub_formula_row_celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[sub_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet[sub_formula_row_celula].number_format = 'R$ #,##0.00' - worksheet[sub_formula_row_celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="thin") ,bottom=Side(border_style="thin") ) - #total1-2 - total12_row = size + 6 - total12_merge_cells = f'A{total12_row}:I{total12_row}' - worksheet.merge_cells(total12_merge_cells) - top_left_total12_cell_formula = f'A{total12_row}' - top_left_total12_cell = worksheet[top_left_total12_cell_formula] - top_left_total12_cell.value = "Total(1-2)" - top_left_total12_cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - top_left_total12_cell.font = Font(name="Arial", size=12, color="000000",bold=True) - top_left_total12_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_total12_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,bottom=Side(border_style="thin") ) + #3.UTILIZAÇÂO DE RENDIMENTOS + # formula = f"=SUM(A{size2+8})" + # sheet[f'A{size2+7}'] = formula + formula = f"=SUM(B{size2+8})" + sheet[f'B{size2+7}'] = formula - #total_formula - total_formula_row = size + 6 - total_formulaa = f'=J{size}' - total_formula_row_celula = f'J{total_formula_row}' - worksheet[total_formula_row_celula].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - worksheet[total_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet[total_formula_row_celula].number_format = 'R$ #,##0.00' - worksheet[total_formula_row_celula].border = Border(top=Side(border_style="thin") ,bottom=Side(border_style="thin"),right=Side(border_style="thin") ) + formula = f"=SUM(C{size2+8})" + sheet[f'C{size2+7}'] = formula - worksheet.row_dimensions[total_formula_row].height = 30 - worksheet[total_formula_row_celula] = total_formulaa + formula = f"=SUM(D{size2+8})" + sheet[f'D{size2+7}'] = formula + + formula = f"=SUM(F{size2+8})" + sheet[f'F{size2+7}'] = formula + + formula = f"=SUM(G{size2+8})" + sheet[f'G{size2+7}'] = formula + + formula = f"=SUM(H{size2+8})" + sheet[f'H{size2+7}'] = formula + + ##SOMATORIO NEGATIVO C + Formula = f'=SUMIF(D16:D{size}, "<0")' + sheet[f'C{size2+8}']= Formula + ############## + + ##SOMATORIO NEGATIVO G + Formula = f'=SUMIF(H16:H{size}, "<0")' + sheet[f'G{size2+8}'] = Formula + ############## - #valor + + #totais + #total espesas correntes linha 15 - #brasilia - brasilia_row = size + 7 - brasilia_formula = f"='Receita x Despesa'!A44:J44" - brasilia_merge_cells = f'A{brasilia_row}:I{brasilia_row}' - worksheet.merge_cells(brasilia_merge_cells) - top_left_brasilia_cell_formula = f'A{brasilia_row}' - top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] - top_left_brasilia_cell.value = brasilia_formula - top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + formula = f"=SUM(B16:B{size})" + sheet['B15'] = formula + formula = f"=SUM(C16:C{size})" + sheet['C15'] = formula + formula = f'=SUMIF(D16:D{size}, ">0")' + sheet['D15'] = formula - #DiretorFinanceiro - diretor_row = size + 8 - diretor_cargo_row = size + 9 - diretor_cpf_row = size + 10 - diretor_nome_formula = f"='Receita x Despesa'!A48" - diretor_cargo_formula = f"='Receita x Despesa'!A49" - diretor_cpf_formula = f"='Receita x Despesa'!A50" - diretor_merge_cells = f'A{diretor_row}:D{diretor_row}' + formula = f"=SUM(F16:F{size})" + sheet['F15'] = formula + formula = f"=SUM(G16:G{size})" + sheet['G15'] = formula + formula = f'=SUMIF(H16:H{size}, ">0")' + sheet['H15'] = formula + + #Total Despesas de Capital + formula = f"=SUM(B{size2+2}:B{size2+4})" + sheet[f'B{size2}'] = formula + + formula = f"=SUM(C{size2+2}:C{size2+4})" + sheet[f'C{size2}'] = formula + + formula = f"=SUM(D{size2+2}:D{size2+4})" + sheet[f'D{size2}'] = formula + + formula = f"=SUM(F{size2+2}:F{size2+4})" + sheet[f'F{size2}'] = formula + + formula = f"=SUM(G{size2+2}:G{size2+4})" + sheet[f'G{size2}'] = formula + + formula = f"=SUM(H{size2+2}:H{size2+4})" + sheet[f'H{size2}'] = formula + + + #Total abaixo de Utilização de rendimentos + + formula = f"=B{size2+8}" + sheet[f'B{size2+9}'] = formula + + formula = f"=C{size2+8}" + sheet[f'C{size2+9}'] = formula + + formula = f"=D{size2+8}" + sheet[f'D{size2+9}'] = formula + + formula = f"=F{size2+8}" + sheet[f'F{size2+9}'] = formula + + formula = f"=G{size2+8}" + sheet[f'G{size2+9}'] = formula + + formula = f"=H{size2+8}" + sheet[f'H{size2+9}'] = formula + + + + #somasaldo h + stringSaldo = f"=SUM(F{size2+8}+G{size2+8})" + + sheet[f"H{size2+8}"] = stringSaldo + + + #brasilia + brasilia_row = size2 + 11 + brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:I{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:I{brasilia_row}' + sheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = sheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.value = brasilia_formula + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + + #DiretorFinanceiro + diretor_row = size2 + 12 + diretor_cargo_row = size2 + 13 + diretor_cpf_row = size2 + 14 + + diretor_nome_formula = f"Daniel Monteiro Rosa" + diretor_cargo_formula = f"Diretor-Financeiro" + diretor_cpf_formula = f"450.720.272-87" + diretor_merge_cells = f'A{diretor_row}:D{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:D{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:D{diretor_cpf_row}' + sheet.merge_cells(diretor_merge_cells) + sheet.merge_cells(diretor_cargo_merge_cells) + sheet.merge_cells(diretor_cpf_merge_cells) + top_left_diretor_cell_formula = f'A{diretor_row}' + top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' + top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' + top_left_diretor_cell = sheet[top_left_diretor_cell_formula] + top_left_diretor_cell_cargo_formula = sheet[top_left_diretor_cell_cargo_formula] + top_left_diretor_cell_cpf_formula = sheet[top_left_diretor_cell_cpf_formula] + top_left_diretor_cell.value = diretor_nome_formula + top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula + top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula + top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell.font = Font(bold=True) + top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + #Coordenadora + coordenadora_row = size2 + 12 + coordenadora_cargo_row = size2 + 13 + coordenadora_cpf_row = size2 + 14 + coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" + coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" + coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" + coordenadora_merge_cells = f'F{coordenadora_row}:I{coordenadora_row}' + coordenadora_cargo_merge_cells = f'F{coordenadora_cargo_row}:I{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'F{coordenadora_cpf_row}:I{coordenadora_cpf_row}' + sheet.merge_cells(coordenadora_merge_cells) + sheet.merge_cells(coordenadora_cargo_merge_cells) + sheet.merge_cells(coordenadora_cpf_merge_cells) + top_left_coordenadora_cell_formula = f'F{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'F{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'F{coordenadora_cpf_row}' + top_left_coordenadora_cell = sheet[top_left_coordenadora_cell_formula] + top_left_coordenadora_cell_cargo_formula = sheet[top_left_coordenadora_cell_cargo_formula] + top_left_coordenadora_cell_cpf_formula = sheet[top_left_coordenadora_cell_cpf_formula] + top_left_coordenadora_cell.value = coordenadora_nome_formula + top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula + top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) + top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + + + # borda = Border(right=Side(border_style="medium")) + # sheet.sheet_view.showGridLines = False + # # + # for row in sheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda + + + + for row in sheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=9): + for cell in row: + if cell.column == 9: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + + + + #bordinha branca + + for row in sheet.iter_rows(min_row=1,max_row=coordenadora_cpf_row,min_col=1,max_col=10): + for cell in row: + + if cell.row == 15: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.column == 9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='medium', color='000000'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.row == size2: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.column == 9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='medium', color='000000'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + + if cell.row == size2+5: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.column == 9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='medium', color='000000'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.row == size2+7: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.column == 9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='medium', color='000000'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.row == size2+9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.column == 9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='medium', color='000000'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + + for row in sheet.iter_rows(min_row=1,max_row=coordenadora_cpf_row,min_col=10,max_col=10): + cell.border = Border(left=Side(border_style='medium', color='000000')) + + workbook.save(tabela) + workbook.close() + + + + + + + return 0 + +def estiloReceitaXDespesa(tabela,stringTamanho): + '''Estilo da Pagina do Relatorio Receita e Despesa. + + Argumentos: + tabela : recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo ja foi iniciado e passou pela preencher fub mas ainda esta sem o estilo que sera aplicado nessa função. + + stringTamanho : refere-se aonde esta localizado a string Brasilia nessa pagina, ela pega o valor entre o tamanho quantidade de rubricas que o projeto possui salvo algumas exeções + e a entrada de receitas/iss, oque for maior esse ditará tamanho. + ''' + + caminho = pegar_caminho(tabela) + #Plan = planilha + # carrega a planilha de acordo com o caminho + workbook = openpyxl.load_workbook(caminho) + sheet = workbook['Receita x Despesa'] + size = stringTamanho + 16; + size2 = size + 5 + cinza = "d9d9d9" + azul_claro = '1c8cbc' + # sheet.row_dimensions[3] = 28 + + + + #cabecario relação de pagamentos - outro servicoes de terceiros + sheet.merge_cells('A1:J2') + sheet['A1'] = f'D E M O N S T R A T I V O D E R E C E I T A E D E S P E S A' + sheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + sheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + sheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + sheet.merge_cells('A3:J3') + sheet['A3'] = "" + sheet['A3'].font = Font(name="Arial", size=12, color="000000") + sheet['A3'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + + sheet.merge_cells('A4:J4') + sheet['A4'] = "" + sheet['A4'].font = Font(name="Arial", size=12, color="000000") + sheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + + sheet.merge_cells('A5:J5') + sheet['A5'] = "" + sheet['A5'].font = Font(name="Arial", size=12, color="000000") + sheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + + sheet.merge_cells('A6:J6') + sheet['A6'] = "" + sheet['A6'].font = Font(name="Arial", size=12, color="000000") + sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + sheet.merge_cells('A7:J7') + sheet['A7'] = "" + sheet['A7'].font = Font(name="Arial", size=12, color="000000") + sheet['A7'].alignment = Alignment(horizontal="left",vertical="center") + + sheet.merge_cells('A9:J9') + sheet['A9'] = 'R E C E I T A E D E S P E S A' + sheet['A9'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + sheet['A9'].alignment = Alignment(horizontal="center",vertical="center") + sheet['A9'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + for i in range(1,10): + sheet.row_dimensions[i].height = 20 + + sheet.row_dimensions[1].height = 25 + sheet.row_dimensions[3].height = 35 + sheet.row_dimensions[2].height = 25 + sheet.row_dimensions[9].height = 30 + sheet.column_dimensions['b'].width = 40 + sheet.column_dimensions['c'].width = 30 + sheet.column_dimensions['d'].width = 30 + sheet.column_dimensions['e'].width = 30 + sheet.column_dimensions['f'].width = 30 + sheet.column_dimensions['i'].width = 30 + sheet.column_dimensions['j'].width = 30 + #barra cinza + + barrazinzaMerge = f"A{11}:J{11}" + sheet.merge_cells(barrazinzaMerge) + barrazinzaStringCelula = f"A{11}" + cell = sheet[barrazinzaStringCelula] + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + + + #adicionar borda em tudo + borda = Border(right=Side(border_style="medium")) + sheet.sheet_view.showGridLines = False + for row in sheet.iter_rows(min_row=1, max_row=size2+21,min_col=10,max_col=10): + for cell in row: + cell.border = borda + + + + + + #merge das receitas + for i in range(16,size): + sttring = f"C{i}:D{i}" + sheet.merge_cells(sttring) + + + font = Font(name='Arial', size=12) + #Colocar tudo arial 12 + for row in sheet.iter_rows(min_row=16): + for cell in row: + cell.font = font + + #mascara de dinheiro despesas correntes + for row in sheet.iter_rows(min_row=16,max_row=size,min_col=5,max_col=5): + for cell in row: + cell.number_format = 'R$ #,##0.00' + + #mascara de dinehrio despesas realizadas + for row in sheet.iter_rows(min_row=16,max_row=size,min_col=9,max_col=9): + for cell in row: + cell.number_format = 'R$ #,##0.00' + + + #preenche qualquer linha com cinza + for row in sheet.iter_rows(min_row=16, max_row=sheet.max_row, min_col=sheet.min_row, max_col= sheet.max_column): + for cell in row: + if cell.row == size2+2 or cell.row == size2 +12: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + + + + + #Receita + + rendimentoDeAplicacaoFinanceiraMerge = f"A{size2+2}:E{size2+2}" + sheet.merge_cells(rendimentoDeAplicacaoFinanceiraMerge) + rendimentoDeAplicacaoFinanceiraString= f"Rendimento de Aplicação financeira" + rendimentoDeAplicacaoFinanceiraStringCelula = f"A{size2+2}" + sheet[rendimentoDeAplicacaoFinanceiraStringCelula] = rendimentoDeAplicacaoFinanceiraString + cell=sheet[f'A{size2+2}'] + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + + + #Rendimento de aplicação financeira formula + formula = f"=SUM(E{size2+3}:E{size2+6})" + celula = f'F{size2+2}' + sheet[celula] = formula + cell=sheet[f'F{size2+2}'] + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.number_format = 'R$ #,##0.00' + + #soma despesas realizadas + formula = f"=SUM(I{16}:I{size+5})" + celula = f'J13' + sheet[celula] = formula + + #soma saldo conciliado + formula = f'=SUM(I{size2+4}+I{size2+5}+I{size2+6}+I{size2+9})' + celula = f'J{size2+2}' + sheet[celula] = formula + + #valores recebidos no periodo + formula = f"=SUM(E{14}:E{size2+1})" + celula = f'F13' + sheet[celula] = formula + + #SUM total receita + + formula = f'=SUM(F{size2+2}+F13)' + celula = f'F{size2+12}' + sheet[celula] = formula + + #SUM total despesa + formula = f'=SUM(J{size2+2}+J13)' + celula = f'J{size2+12}' + sheet[celula] = formula + + #sum II. DESPESAS DE CAPITAl + formula = f'=SUM(I{size+2}:I{size+5})' + celula = f'I{size+1}' + sheet[celula] = formula + + #Despesas realizadas + #depsesas e capital + despesasDeCapitalString = f"II. DESPESAS DE CAPITAL" + despesasDeCapitalStringCelula = f'H{size+1}' + sheet[despesasDeCapitalStringCelula] = despesasDeCapitalString + cell=sheet[despesasDeCapitalStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell=sheet[f'I{size+1}'] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.number_format = 'R$ #,##0.00' + + + + obrasEInstalacoeslString = f"Obras e Instalações" + obrasEInstalacoeslStringCelula = f'H{size+2}' + sheet[obrasEInstalacoeslStringCelula] = obrasEInstalacoeslString + cell=sheet[f'I{size+2}'] + cell.font = Font(name="Arial", size=12, color="000000") + cell.number_format = 'R$ #,##0.00' + + + equipamentoseMaterialPermanenteString = f"Equipamentos e Material Permanente" + equipamentoseMaterialPermanenteStringCelula = f'H{size+3}' + sheet[equipamentoseMaterialPermanenteStringCelula] = equipamentoseMaterialPermanenteString + cell=sheet[equipamentoseMaterialPermanenteStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell=sheet[f'I{size+3}'] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.number_format = 'R$ #,##0.00' + + + nacionalString = f" a) Nacional" + nacionalStringCelula = f'H{size+4}' + sheet[nacionalStringCelula] = nacionalString + cell=sheet[f'I{size+4}'] + cell.font = Font(name="Arial", size=12, color="000000") + cell.number_format = 'R$ #,##0.00' + + + importadoString = f" b) Importado" + importadoStringCelula = f'H{size+5}' + sheet[importadoStringCelula] = importadoString + cell=sheet[f'I{size+5}'] + cell.font = Font(name="Arial", size=12, color="000000") + cell.number_format = 'R$ #,##0.00' + + #saldo conciliado em: + + saldoConciliadoEmString= f"Saldo Conciliado em: " + saldoConciliadoEmStringCelula = f"H{size2+2}" + sheet[saldoConciliadoEmStringCelula] = saldoConciliadoEmString + cell=sheet[saldoConciliadoEmStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + + ##saldo conciliado formula + cell=sheet[f'J{size2+2}'] + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.number_format = 'R$ #,##0.00' + + #mergecelulasabaixo de Rendimento de Aplicação financeira + for i in range(size2+3,size2+6): + sttring = f"A{i}:D{i}" + sheet.merge_cells(sttring) + + + + contaCorrenteEmString= f"Conta Corrente" + contaCorrenteEmStringCelula = f"H{size2+4}" + sheet[contaCorrenteEmStringCelula] = contaCorrenteEmString + cell=sheet[f'I{size2+4}'] + cell.font = Font(name="Arial", size=12, color="000000") + cell.number_format = 'R$ #,##0.00' + + devolucaoRecursosEmString= f"Devolução de recursos - GRU SIMPLES" + devolucaoRecursosEmStringCelula = f"H{size2+5}" + sheet[devolucaoRecursosEmStringCelula] = devolucaoRecursosEmString + cell=sheet[f'I{size2+5}'] + cell.font = Font(name="Arial", size=12, color="000000") + cell.number_format = 'R$ #,##0.00' + + tarifaBancariaSaldoEmString= f"Tarifa Bancária - Saldo" + tarifaBancariaSaldoEmStringCelula = f"H{size2+6}" + sheet[tarifaBancariaSaldoEmStringCelula] = tarifaBancariaSaldoEmString + cell=sheet[saldoConciliadoEmStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell=sheet[f'I{size2+6}'] + cell.value= f"=I{size2+7}-I{size2+8}" + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.number_format = 'R$ #,##0.00' + + tarifaBancariaDespesaEmString= f"Tarifa Bancária - Despesa (-)" + tarifaBancariaDespesaEmStringCelula = f"H{size2+7}" + sheet[tarifaBancariaDespesaEmStringCelula] = tarifaBancariaDespesaEmString + cell=sheet[f'I{size2+7}'] + cell.font = Font(name="Arial", size=12, color="000000") + cell.number_format = 'R$ #,##0.00' + + TarifaBancariaRestituicaoEmString= f"Tarifa Bancária - Restituição (+)" + TarifaBancariaRestituicaoEmStringCelula = f"H{size2+8}" + sheet[TarifaBancariaRestituicaoEmStringCelula] = TarifaBancariaRestituicaoEmString + cell=sheet[f'I{size2+8}'] + cell.number_format = 'R$ #,##0.00' + + aplicacaoFinanceiraEmString= f"Aplicação Financeira" + aplicacaoFinanceiraEmStringCelula = f"H{size2+9}" + sheet[aplicacaoFinanceiraEmStringCelula] = aplicacaoFinanceiraEmString + cell=sheet[aplicacaoFinanceiraEmStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell=sheet[f'I{size2+9}'] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.number_format = 'R$ #,##0.00' + + rendimentoDeaplicacaoEmString= f"Rendimento de aplicação financeira" + rendimentoDeaplicacaoEmStringCelula = f"H{size2+10}" + sheet[rendimentoDeaplicacaoEmStringCelula] = rendimentoDeaplicacaoEmString + + cell=sheet[f'I{size2+10}'] + cell.number_format = 'R$ #,##0.00' + + #Total Receita + + totalMerge = f"A{size2+12}:E{size2+12}" + sheet.merge_cells(totalMerge) + totalString= f"TOTAL" + totalStringCelula = f"A{size2+12}" + sheet[totalStringCelula] = totalString + + cell = sheet[totalStringCelula] + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #TotalReceitaFormula + cell=sheet[f'F{size2+12}'] + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.number_format = 'R$ #,##0.00' + #Total Despesa + + totalMerge = f"H{size2+12}:I{size2+12}" + sheet.merge_cells(totalMerge) + totalString= f"TOTAL" + totalStringCelula = f"H{size2+12}" + sheet[totalStringCelula] = totalString + cell = sheet[totalStringCelula] + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #Total Despesa Formula + cell=sheet[f'J{size2+12}'] + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.number_format = 'R$ #,##0.00' + + + #Barraazul + + barrazulMerge = f"A{size2+14}:J{size2+14}" + sheet.merge_cells(barrazulMerge) + barrazulStringCelula = f"A{size2+14}" + cell = sheet[barrazulStringCelula] + + cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro, + fill_type = "solid") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + + #brasilia + brasilia_row = size2 + 16 + brasilia_formula = f"" + brasilia_merge_cells = f'A{brasilia_row}:I{brasilia_row}' + sheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = sheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.value = brasilia_formula + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + + #DiretorFinanceiro + diretor_row = size2 + 19 + diretor_cargo_row = size2 + 20 + diretor_cpf_row = size2 + 21 + diretor_nome_formula = f"Daniel Monteiro Rosa" + diretor_cargo_formula = f"Diretor-Financeiro" + diretor_cpf_formula = f"450.720.272-87" + diretor_merge_cells = f'A{diretor_row}:D{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:D{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:D{diretor_cpf_row}' + sheet.merge_cells(diretor_merge_cells) + sheet.merge_cells(diretor_cargo_merge_cells) + sheet.merge_cells(diretor_cpf_merge_cells) + top_left_diretor_cell_formula = f'A{diretor_row}' + top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' + top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' + top_left_diretor_cell = sheet[top_left_diretor_cell_formula] + top_left_diretor_cell_cargo_formula = sheet[top_left_diretor_cell_cargo_formula] + top_left_diretor_cell_cpf_formula = sheet[top_left_diretor_cell_cpf_formula] + top_left_diretor_cell.value = diretor_nome_formula + top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula + top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula + top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell.font = Font(name="Arial", size=12,bold=True) + top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + + #Coordenadora + coordenadora_row = size2 + 19 + coordenadora_cargo_row = size2 + 20 + coordenadora_cpf_row = size2 + 21 + coordenadora_nome_formula = f"teste" + coordenadora_cargo_formula = f"Coordenador(a)" + coordenadora_cpf_formula = f"teste" + coordenadora_merge_cells = f'H{coordenadora_row}:J{coordenadora_row}' + coordenadora_cargo_merge_cells = f'H{coordenadora_cargo_row}:J{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'H{coordenadora_cpf_row}:J{coordenadora_cpf_row}' + sheet.merge_cells(coordenadora_merge_cells) + sheet.merge_cells(coordenadora_cargo_merge_cells) + sheet.merge_cells(coordenadora_cpf_merge_cells) + top_left_coordenadora_cell_formula = f'H{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'H{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'H{coordenadora_cpf_row}' + top_left_coordenadora_cell = sheet[top_left_coordenadora_cell_formula] + top_left_coordenadora_cell_cargo_formula = sheet[top_left_coordenadora_cell_cargo_formula] + top_left_coordenadora_cell_cpf_formula = sheet[top_left_coordenadora_cell_cpf_formula] + top_left_coordenadora_cell.value = coordenadora_nome_formula + top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula + top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) + top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + + + for row in sheet.iter_rows(min_row=1,max_row=coordenadora_cpf_row,min_col=10,max_col=10): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="none") ) + + for row in sheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=10): + for cell in row: + if cell.column == 10: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + + # #deixar azul a letra de receita + # cell=sheet['E16'] + # cell.font = Font(name="Arial", size=12,color="0000FF") + # #deixar VERMELHO a letra de receita + # cell=sheet[f'E{17}'] + # cell.font = Font(name="Arial", size=12,color="FF0000") + + # cell=sheet[f'E{18}'] + # cell.font = Font(name="Arial", size=12,color="FF0000") + + workbook.save(tabela) + workbook.close() + + # print(f'printandosize2') + # print(size2) + #retorna tamanho de brasilia e de equipamentos + return size2 + 16,size+3 + +def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho,tamanhoestorno): + '''Esse estilo e considerado geral por que todas as tabelas que compõe utilizam das mesma colunas. + + Argumentos: + tabela: recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo ja foi iniciado e passou pela preencher fub mas ainda esta sem o estilo que sera aplicado nessa função. + tamanho: e o tamanho total de linhas que irao ser geradas dinamicamente correspondente as entradas do respectivo projeto. o valor varia dentre o tamanho das rubricas + + nomeVariavel: variável utilizada para criar o nomes das variaveis dinamicamente para não haver sobreposição de estilos com o mesmo nome. Esses estilos ocorrem nesses codigos: + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid"'.... + nomeTabela: variável utilizada para a criação do nome da tabela.Ela deriva das rubricas que são colocadas no input quando essa função e chamada. + stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referencias das formulas. + tamanhoEstorno = Correspondente ao tamanho do estrono + ''' + + nomeSheet=nomeVariavel + random_number = random.randint(1, 10000) + nomeVariavel = f'{nomeVariavel}{random_number}' + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + worksheet = workbook[nomeTabela] + size = tamanho + 10 + cinza = "d9d9d9" + cinza_escuro = "bfbfbf" + azul = "336394" + azul_claro = '1c8cbc' + + borda = Border(right=Side(border_style="medium")) + worksheet.sheet_view.showGridLines = False + # + for row in worksheet.iter_rows(min_row=1, max_row=size+12,min_col=10,max_col=10): + for cell in row: + cell.border = borda + + + worksheet.column_dimensions['a'].width = 25 + worksheet.column_dimensions['b'].width = 25 + worksheet.column_dimensions['c'].width = 35 + worksheet.column_dimensions['d'].width = 35#descrição + worksheet.column_dimensions['e'].width = 65 #n do recibo ou qeuivalente + worksheet.column_dimensions['f'].width = 25 #data de emissão + worksheet.column_dimensions['g'].width = 25 #data de emissão + worksheet.column_dimensions['h'].width = 25 #data de emissão + worksheet.column_dimensions['i'].width = 25 #data de emissão + worksheet.column_dimensions['j'].width = 25 #data de emissão + + + #cabecario relação de pagamentos - outro servicoes de terceiros + worksheet.merge_cells('A1:J2') + nomeTabela = nomeTabela.upper() + worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - {nomeTabela}' + + # if nomeSheet == "diarias": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - DIÁRIAS' + # elif nomeSheet == "pessoaFisica": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - OUTROS SERVIÇOS DE TERCEIROS - PF' + # elif nomeSheet == "pessoaJuridica": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - OUTROS SERVIÇOS DE TERCEIROS - PESSOA JURÍDICA' + # elif nomeSheet == "passagenDespLocomo": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - PASSAGENS E DESPESAS COM LOCOMOÇÃO' + # elif nomeSheet == "outrosServiçosTerceiros": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - O U T R O S S E R V I Ç O S D E T E R C E I R O S - C E L E T I S T A S' + # elif nomeSheet == "auxilio": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - AUXÍLIO FINANCEIRO A ESTUDANTE E PESQUISADOR' + # elif nomeSheet == "bolsaExtensao": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - BOLSA DE EXTENSÃO' + # elif nomeSheet == "estagiario": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - ESTAGIÁRIO' + # elif nomeSheet == "custosIndiretos": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - CUSTOS INDIRETOS - FUB' + # elif nomeSheet == "materialDeConsumo": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - MATERIAL DE CONSUMO' + # elif nomeSheet == "equipamentoMaterialPermanente": + # worksheet['A1'] = f'R E L A Ç Ã O D E P A G A M E N T O S - EQUIPAMENTO E MATERIAL PERMANENTE' + # elif nomeSheet == "isss": + # worksheet['A1'] = f'ISS 5% e ISS 2%' + + + + worksheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + worksheet.merge_cells('A3:J3') + worksheet['A3'] = "='Receita x Despesa'!A3:J3" + worksheet['A3'].font = Font(name="Arial", size=12, color="000000") + worksheet['A3'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A4:J4') + worksheet['A4'] = "='Receita x Despesa'!A4:J4" + worksheet['A4'].font = Font(name="Arial", size=12, color="000000") + worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A5:J5') + worksheet['A5'] = "='Receita x Despesa'!A5:J5" + worksheet['A5'].font = Font(name="Arial", size=12, color="000000") + worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A6:J6') + worksheet['A6'] = "='Receita x Despesa'!A6:J6" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000") + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A7:J7') + worksheet['A7'] = "='Receita x Despesa'!A7:J7" + worksheet['A7'].font = Font(name="Arial", size=12, color="000000") + worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") + + #variavel + + input2=f'rowStyle{nomeVariavel}' + + + #colunas azul cabecario + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input2].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="thin") ) + locals()[input2].height = 20 + linha_number = 9 + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=10): + for cell in row: + cell.style = locals()[input2] + if cell.column == 10: + cell.border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="thin"), right=Side(border_style="medium") ) + + valores = ["ITEM","NOME","CNPJ/CPF",'ESPECIFICAÇÃO DA DESPESA','DESCRIÇÃO',"Nº DO RECIBO OU EQUIVALENTE","DATA DE EMISSÃO",'CHEQUE / ORDEM BANCÁRIA','DATA DE PGTO','Valor'] + col = 1 + for a,b in enumerate(valores): + worksheet.cell(row=linha_number, column=col, value=b) + col = col + 1 + + + #Aumentar a altura das celulas + for row in worksheet.iter_rows(min_row=10, max_row=size, min_col=1, max_col=10): + worksheet.row_dimensions[row[0].row].height = 75 + input3 = f'customNumber{nomeVariavel}' + + # MASCARA R$ + + locals()[input3] = NamedStyle(name=f'{input3}') + locals()[input3].number_format = 'R$ #,##0.00' + locals()[input3].font = Font(name="Arial", size=12, color="000000") + locals()[input3].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #estilocinzasimcinzanao + value_to_stop = size + start_row = 10 +# + for row in range(start_row,size+1): + cell = worksheet[f'J{row}'] + cell.style = locals()[input3] + + for rows in worksheet.iter_rows(min_row=10, max_row=size, min_col=1, max_col=10): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + if cell.column == 10: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + else: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + + #subtotal + stringAfinarCelula =size+2 + worksheet.row_dimensions[size+2].height = 6 + celulas_mergidas_subtotal = f"A{size+2}:I{size+2}" + worksheet.merge_cells(celulas_mergidas_subtotal) + left_celula_cell = f"A{size+2}" + top_left_cell = worksheet[left_celula_cell] + top_left_cell.value = "Sub Total1" + top_left_cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="medium") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + + worksheet.row_dimensions[size+2].height = 56.25 + + # FORMULATOTAL + formula = f"=SUM(J10:J{size})" + celula = f'J{size+2}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + worksheet[celula].number_format = 'R$ #,##0.00' + #restituições creditadas + restituicoes = size + 3 + celula_restituicoes=f'A{restituicoes}' + worksheet[celula_restituicoes].value = "RESTITUIÇÕES CREDITADAS" + worksheet[celula_restituicoes].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet.row_dimensions[restituicoes].height = 30 + + + input4 = f'row_style_diaria_append{nomeVariavel}' + #estilo colunas restitucoes creditadas + locals()[input4] = NamedStyle(name=f'{input4}') + locals()[input4].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input4].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + locals()[input4].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input4].height = 30 + locals()[input4].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="medium") ) + + + row_number = size + 4 + + for column in range(1, 11): + cell = worksheet.cell(row=row_number, column=column) + cell.style = locals()[input4] + if cell.column == 10: + cell.border = Border(top=Side(border_style="medium") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + + + + values = ["Item","Restituidor","CNPJ/CPF",'Descrição',"Cheque equivalente","Data do Cheque",'Nº do Depósito','Data da Devolução','Valor'] + coluna = 1 + for a,b in enumerate(values): + worksheet.cell(row=row_number, column=coluna, value=b) + if coluna == 4: + coluna = coluna + 1 + coluna = coluna + 1 + + + merge_formula = f'D{row_number}:E{row_number}' + worksheet.merge_cells(merge_formula) + + #mergecells + for x in range(size+4,size+5+tamanhoestorno): + worksheet.merge_cells(start_row=x ,start_column=4, end_row=x, end_column=5) + + + #estorno + + for rows in worksheet.iter_rows(min_row=size+5, max_row=size+4+tamanhoestorno, min_col=1, max_col=10): + for cell in rows: + if cell.row % 2: + cell.font = Font(name="Arial", size=12, color="000000") + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + if cell.column == 10: + cell.number_format = 'R$ #,##0.00' + cell.font = Font(name="Arial", size=12, color="000000") + + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair")) + cell.font = Font(name="Arial", size=12, color="000000") + + + #bordas,corsimcornao,money + # Set the height of each row to 60 + for row in worksheet.iter_rows(min_row=size+4, max_row=size+4+tamanhoestorno): + worksheet.row_dimensions[row[0].row].height = 75 + + min_row = size + 4 + max_row = size + 4 + tamanhoestorno + + + + #subtotal2 + sub_total2_row = size + 6 +tamanhoestorno + subtotal_merge_cells= f'A{sub_total2_row}:I{sub_total2_row}' + worksheet.merge_cells(subtotal_merge_cells) + top_left_subtotal2_cell_formula = f'A{sub_total2_row}' + top_left_subtotal2_cell = worksheet[top_left_subtotal2_cell_formula] + top_left_subtotal2_cell.value = "Sub Total 2" + top_left_subtotal2_cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + top_left_subtotal2_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_subtotal2_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_subtotal2_cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="medium") ,right =Side(border_style="hair") ,bottom=Side(border_style="medium") ) + + sub_formula_row_celula = f'J{sub_total2_row}' + worksheet[sub_formula_row_celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[sub_formula_row_celula].value = f'=SUM(J{size+5}:J{sub_total2_row-1})' + worksheet[sub_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[sub_formula_row_celula].number_format = 'R$ #,##0.00' + worksheet[sub_formula_row_celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + + #total1-2 + total12_row = size + 7 + tamanhoestorno + total12_merge_cells = f'A{total12_row}:I{total12_row}' + worksheet.merge_cells(total12_merge_cells) + top_left_total12_cell_formula = f'A{total12_row}' + top_left_total12_cell = worksheet[top_left_total12_cell_formula] + top_left_total12_cell.value = "Total(1-2)" + top_left_total12_cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + top_left_total12_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_total12_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_total12_cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="medium") ,bottom=Side(border_style="medium") ) + + + #total_formula + total_formula_row = size + 7 + tamanhoestorno + total_formulaa = f'=J{size+2} - J{sub_total2_row }' + total_formula_row_celula = f'J{total_formula_row}' + worksheet[total_formula_row_celula].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet[total_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[total_formula_row_celula].number_format = 'R$ #,##0.00' + worksheet[total_formula_row_celula].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="medium"),right=Side(border_style="medium") ) + + worksheet.row_dimensions[total_formula_row].height = 30 + worksheet[total_formula_row_celula] = total_formulaa + + + + #brasilia + brasilia_row = size + 8 +tamanhoestorno + brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:J{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:I{brasilia_row}' + worksheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.value = brasilia_formula + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + + #DiretorFinanceiro + diretor_row = size + 9 + tamanhoestorno + diretor_cargo_row = size + 10 + tamanhoestorno + diretor_cpf_row = size + 11 + tamanhoestorno + + diretor_nome_formula = f"='Receita x Despesa'!A{stringTamanho+3}" + diretor_cargo_formula = f"='Receita x Despesa'!A{stringTamanho+4}" + diretor_cpf_formula = f"='Receita x Despesa'!A{stringTamanho+5}" + diretor_merge_cells = f'A{diretor_row}:D{diretor_row}' diretor_cargo_merge_cells = f'A{diretor_cargo_row}:D{diretor_cargo_row}' diretor_cpf_merge_cells = f'A{diretor_cpf_row}:D{diretor_cpf_row}' worksheet.merge_cells(diretor_merge_cells) @@ -342,21 +1459,359 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela): top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") #Coordenadora - coordenadora_row = size + 8 - coordenadora_cargo_row = size + 9 - coordenadora_cpf_row = size + 10 - coordenadora_nome_formula = f"='Receita x Despesa'!G48" - coordenadora_cargo_formula = f"='Receita x Despesa'!G49" - coordenadora_cpf_formula = f"='Receita x Despesa'!G50" - coordenadora_merge_cells = f'F{coordenadora_row}:J{coordenadora_row}' - coordenadora_cargo_merge_cells = f'F{coordenadora_cargo_row}:J{coordenadora_cargo_row}' - coordenadora_cpf_merge_cells = f'F{coordenadora_cpf_row}:J{coordenadora_cpf_row}' + coordenadora_row = size + 9 + tamanhoestorno + coordenadora_cargo_row = size + 10 + tamanhoestorno + coordenadora_cpf_row = diretor_cpf_row + coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" + coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" + coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" + coordenadora_merge_cells = f'F{coordenadora_row}:J{coordenadora_row}' + coordenadora_cargo_merge_cells = f'F{coordenadora_cargo_row}:J{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'F{coordenadora_cpf_row}:J{coordenadora_cpf_row}' + worksheet.merge_cells(coordenadora_merge_cells) + worksheet.merge_cells(coordenadora_cargo_merge_cells) + worksheet.merge_cells(coordenadora_cpf_merge_cells) + top_left_coordenadora_cell_formula = f'F{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'F{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'F{coordenadora_cpf_row}' + top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] + top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] + top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] + top_left_coordenadora_cell.value = coordenadora_nome_formula + top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula + top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) + top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + + + # borda = Border(right=Side(border_style="medium")) + # worksheet.sheet_view.showGridLines = False + # # + # for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda + + for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=11,max_col=11): + for cell in row: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="medium") ,right =Side(border_style="none") ,bottom=Side(border_style="none") ) + + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=10): + for cell in row: + if cell.column == 10: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + + workbook.save(tabela) + workbook.close() + + return size+4 + +def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): + """Estilo um pouco diferente pois necessita de dois aspectos dinâmicos que é primeiramente a quantidade de entradas de pagamento de tarifas bancárias e por fim a quantidade de estorno. Sabendo + esses valores é possivel criar a tabela. + + Argumentos: + tabela: recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo foi iniciado e passou pela preencher fub mas ainda está sem o estilo que será aplicado nessa função. + tamanho:Corresponde ao tamanho das quantidade de transfêrencia bancárias realizada. + tamanho2:Corresponde ao tamanho dos estornos. + stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referências das formulas. + """ + + #pegar o arquivo e carregar ele um worksheet da pagaina Conciliação Bancária + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + worksheet = workbook['Conciliação Bancária'] + + #size e o tamanho da quantidade de arquivos recebido no argumento tamanho mais o tamanho do cabecario que no caso da fub e de 16 + size = tamanho + 17 + cinza = "d9d9d9" + cinza_escuro = "bfbfbf" + azul = "336394" + azul_claro = '1c8cbc' + + #Borda apenas do lado direito da cedula, uma borda mas larga + borda = Border(right=Side(border_style="medium")) + worksheet.sheet_view.showGridLines = False + # + + + + worksheet.column_dimensions['a'].width = 25 + worksheet.column_dimensions['b'].width = 25 + worksheet.column_dimensions['c'].width = 35 + worksheet.column_dimensions['d'].width = 35 + worksheet.column_dimensions['e'].width = 20 + worksheet.column_dimensions['f'].width = 20 + + + #cabecario relação de pagamentos - outro servicoes de terceiros + worksheet.merge_cells('A1:F2') + worksheet['A1'] = f'C O N C I L I A Ç Ã O B A N C Á R I A' + worksheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + worksheet.merge_cells('A3:F3') + worksheet['A3'] = "='Receita x Despesa'!A3:J3" + worksheet['A3'].font = Font(name="Arial", size=12, color="000000") + worksheet['A3'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A4:F4') + worksheet['A4'] = "='Receita x Despesa'!A4:J4" + worksheet['A4'].font = Font(name="Arial", size=12, color="000000") + worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A5:F5') + worksheet['A5'] = "='Receita x Despesa'!A5:J5" + worksheet['A5'].font = Font(name="Arial", size=12, color="000000") + worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A6:F6') + worksheet['A6'] = "='Receita x Despesa'!A6:J6" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000") + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A7:F7') + worksheet['A7'] = "='Receita x Despesa'!A7:J7" + worksheet['A7'].font = Font(name="Arial", size=12, color="000000") + worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A9:F9') + worksheet['A9'] = '1.Saldo conforme extratos bancários na data final do período' + worksheet['A9'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A9'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + worksheet.merge_cells('A10:E10') + worksheet['A10'] = 'Saldo de Conta Corrente(R$)' + worksheet['A10'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A10'].alignment = Alignment(horizontal="right",vertical="center") + + worksheet.merge_cells('A11:E11') + worksheet['A11'] = 'Saldo de Aplicações Financeiras(R$)' + worksheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A11'].alignment = Alignment(horizontal="right",vertical="center") + + worksheet.merge_cells('A13:F13') + worksheet['A13'] = '2. Restituições não creditadas pelo banco até a data final do período' + worksheet['A13'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A13'].alignment = Alignment(horizontal="left",vertical="center") + worksheet['A13'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + for i in range(15,size): + sttring = f"D{i}:F{i}" + worksheet.merge_cells(sttring) + + for i in range(size+3,size+4+tamanho2+1): + sttring = f"D{i}:F{i}" + worksheet.merge_cells(sttring) + + random_number = random.randint(1, 10000) + + custom_number_format_conciliacoes = [] + # MASCARA R$ + if custom_number_format_conciliacoes!= False: + custom_number_format_conciliacoes = NamedStyle(name=f'custom_number_format_conciliacoes{random_number}') + custom_number_format_conciliacoes.number_format = 'R$ #,##0.00' + custom_number_format_conciliacoes.font = Font(name="Arial", size=12, color="000000") + custom_number_format_conciliacoes.alignment = Alignment(horizontal="general",vertical="bottom",wrap_text=True) + + #stylecinza + start_row = 15 + for row in range(start_row,size+1): + cell = worksheet[f'B{row}'] + cell.style = custom_number_format_conciliacoes + + for rows in worksheet.iter_rows(min_row=15, max_row=size, min_col=1, max_col=6): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + row_number = 15 + values = ["Data","Valor(R$)","Documento",'Descrição'] + coluna = 1 + for a,b in enumerate(values): + worksheet.cell(row=row_number, column=coluna, value=b) + + coluna = coluna + 1 + + # FORMULATOTAL + formula = f"=SUM(B16:B{size-1})" + celula = f'B{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + #Total + celula_total = F'A{size}' + worksheet[celula_total] = f'TOTAL' + worksheet[celula_total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) + #'3. Restituições não creditadas pelo banco até a data final do período' + string_reituicoes_creditadas = f'A{size+2}:F{size+2}' + row_creditadas = f'A{size+2}' + worksheet.merge_cells(string_reituicoes_creditadas) + + worksheet[row_creditadas] = '3. Restituições creditadas pelo banco até a data final do período' + worksheet[row_creditadas].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet[row_creditadas].alignment = Alignment(horizontal="left",vertical="center") + worksheet[row_creditadas].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + #data valor documento descrição + row_number = size+3 + values = ["Data","Valor(R$)","Documento",'Descrição'] + coluna = 1 + for a,b in enumerate(values): + worksheet.cell(row=row_number, column=coluna, value=b) + coluna = coluna + 1 + + for rows in worksheet.iter_rows(min_row=15, max_row=15, min_col=1, max_col=6): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + for rows in worksheet.iter_rows(min_row=row_number, max_row=row_number, min_col=1, max_col=6): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.alignment = Alignment(horizontal="center",vertical="center") + + #saldo anterior restituição + row_restituicao = f'A{size+4}' + worksheet[row_restituicao] = 'Saldo anterior' + worksheet[row_restituicao].font = Font(name="Arial", size=12, color="000000") + worksheet[row_restituicao].alignment = Alignment(horizontal="left",vertical="center") + row_restituicao = f'b{size+4}' + worksheet[row_restituicao].font = Font(name="Arial", size=12, color="000000") + worksheet[row_restituicao].alignment = Alignment(horizontal="left",vertical="center") + row_restituicao = f'c{size+4}' + worksheet[row_restituicao] = 'Diversos' + worksheet[row_restituicao].font = Font(name="Arial", size=12, color="000000") + worksheet[row_restituicao].alignment = Alignment(horizontal="left",vertical="center") + row_restituicao = f'd{size+4}' + worksheet[row_restituicao] = 'Restituição Prestações Anteriores' + worksheet[row_restituicao].font = Font(name="Arial", size=12, color="000000") + worksheet[row_restituicao].alignment = Alignment(horizontal="left",vertical="center") + + + + size = size + 1 + + for row in range(size+3,size+4+tamanho2): + cell = worksheet[f'B{row}'] + cell.style = custom_number_format_conciliacoes + + for rows in worksheet.iter_rows(min_row=size+3, max_row=size+3+tamanho2, min_col=1, max_col=6): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + if cell.column == 6: + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + + + # FORMULATOTALrestituição + formula = f"=SUM(B{size+3}:B{size+tamanho2+3})" + celula = f'B{size+tamanho2+5}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + #Total + celula_total = F'A{size+tamanho2+5}' + worksheet[celula_total] = f'TOTAL' + worksheet[celula_total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) + #Saldo disponível p/ período seguinte (1 +2 - 3) + string_saldo_disponivel = f'A{size+3+tamanho2+3}:D{size+3+tamanho2+3}' + celula_string_saldo = f'A{size+tamanho2+6}' + worksheet[celula_string_saldo].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet.merge_cells(string_saldo_disponivel) + worksheet[celula_string_saldo]= f'Saldo disponível p/ período seguinte (1 + 2 - 3)' + #total saldo diposnivel + string_merge_saldo_disponivel = f'E{size+3+tamanho2+3}:F{size+3+tamanho2+3}' + celula_string_total = f'E{size+tamanho2+6}' + worksheet.merge_cells(string_merge_saldo_disponivel) + saldodiposnivelformat_conciliacoes = NamedStyle(name=f'saldodiposnivelformat_conciliacoes{random_number}') + saldodiposnivelformat_conciliacoes.number_format = 'R$ #,##0.00' + saldodiposnivelformat_conciliacoes.font = Font(name="Arial", size=12, color="000000") + saldodiposnivelformat_conciliacoes.alignment = Alignment(horizontal="general",vertical="bottom",wrap_text=True) + saldodiposnivelformat_conciliacoes.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + celular = worksheet[celula_string_total] + celular.style = saldodiposnivelformat_conciliacoes + celular.value = f'=F10+F11+B{size-1} -B{size+tamanho2+5}' + #saldo anterior + formula = f"Saldo anterior" + celula = f'A16' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000") + + formula = f"Diversos" + celula = f'C16' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000") + + formula = f"Tarifas Prestações Anteriores" + celula = f'D16' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000") + + #brasilia + brasilia_row = size + tamanho2+ 8 + brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:J{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:F{brasilia_row}' + worksheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.value = brasilia_formula + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + + # #DiretorFinanceiro + diretor_row = size + 10 + tamanho2 + diretor_cargo_row = size + 11 + tamanho2 + diretor_cpf_row = size + 12 + tamanho2 + diretor_nome_formula = f"='Receita x Despesa'!A{stringTamanho+3}" + diretor_cargo_formula = f"='Receita x Despesa'!A{stringTamanho+4}" + diretor_cpf_formula = f"='Receita x Despesa'!A{stringTamanho+5}" + diretor_merge_cells = f'A{diretor_row}:B{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:B{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:B{diretor_cpf_row}' + worksheet.merge_cells(diretor_merge_cells) + worksheet.merge_cells(diretor_cargo_merge_cells) + worksheet.merge_cells(diretor_cpf_merge_cells) + top_left_diretor_cell_formula = f'A{diretor_row}' + top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' + top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' + top_left_diretor_cell = worksheet[top_left_diretor_cell_formula] + top_left_diretor_cell_cargo_formula = worksheet[top_left_diretor_cell_cargo_formula] + top_left_diretor_cell_cpf_formula = worksheet[top_left_diretor_cell_cpf_formula] + top_left_diretor_cell.value = diretor_nome_formula + top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula + top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula + top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell.font = Font(bold=True) + top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + #Coordenadora + coordenadora_row = diretor_row + coordenadora_cargo_row = diretor_cargo_row + coordenadora_cpf_row = diretor_cpf_row + coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" + coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" + coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" + coordenadora_merge_cells = f'D{coordenadora_row}:F{coordenadora_row}' + coordenadora_cargo_merge_cells = f'D{coordenadora_cargo_row}:F{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'D{coordenadora_cpf_row}:F{coordenadora_cpf_row}' worksheet.merge_cells(coordenadora_merge_cells) worksheet.merge_cells(coordenadora_cargo_merge_cells) worksheet.merge_cells(coordenadora_cpf_merge_cells) - top_left_coordenadora_cell_formula = f'F{coordenadora_row}' - top_left_coordenadora_cell_cargo_formula = f'F{coordenadora_cargo_row}' - top_left_coordenadora_cell_cpf_formula = f'F{coordenadora_cpf_row}' + top_left_coordenadora_cell_formula = f'D{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'D{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'D{coordenadora_cpf_row}' top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] @@ -364,325 +1819,547 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela): top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_coordenadora_cell.font= Font(bold = True) + top_left_coordenadora_cell.border = borda + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cargo_formula.border = borda top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.border = borda + + for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=6,max_col=6): + for cell in row: + cell.border = borda + + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=6): + for cell in row: + if cell.column == 6: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + else: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + + workbook.save(tabela) + workbook.close() +def estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho): + """Estilo da rendimento de aplicação, tabela com as colunas periodo, saldo anterior,valor aplicado no período,valor resgatado no período,rendimento bruto,imposto,rendimento luiquido,saldo. - # borda = Border(right=Side(border_style="thin")) - # worksheet.sheet_view.showGridLines = False - # # - # for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=10): - # for cell in row: - # cell.border = borda - + Argumentos: + tabela: recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo foi iniciado e passou pela preencher fub mas ainda está sem o estilo que será aplicado nessa função. + tamanho:Corresponde ao tamanho das quantidade da tabela de rencimentos. + stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referências das formulas. + """ + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + worksheet = workbook['Rendimento de Aplicação'] + + random_number = random.randint(1, 10000) + size = tamanho + 15 + worksheet.row_dimensions[10].height = 2 + worksheet.row_dimensions[9].height = 20 + + cinza = "d9d9d9" + cinza_escuro = "bfbfbf" + azul = "336394" + azul_claro = '1c8cbc' + borda = Border(right=Side(border_style="medium")) + worksheet.sheet_view.showGridLines = False + # + for row in worksheet.iter_rows(min_row=1, max_row=size+9,min_col=8,max_col=8): + for cell in row: + cell.border = borda + + + + worksheet.column_dimensions['a'].width = 20 + worksheet.column_dimensions['b'].width = 20 + worksheet.column_dimensions['c'].width = 20 + worksheet.column_dimensions['d'].width = 20 + worksheet.column_dimensions['e'].width = 20 + worksheet.column_dimensions['f'].width = 20 + worksheet.column_dimensions['g'].width = 20 + worksheet.column_dimensions['h'].width = 20 + + + #cabecario relação de pagamentos - outro servicoes de terceiros + worksheet.merge_cells('A1:H2') + worksheet['A1'] = f'D E M O N S T R A T I V O D E R E N D I M E N T O D E A P L I C A Ç Ã O F I N A N C E I R A' + worksheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + worksheet.merge_cells('A3:H3') + worksheet['A3'] = "='Receita x Despesa'!A3:J3" + worksheet['A3'].font = Font(name="Arial", size=12, color="000000") + worksheet['A3'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A4:H4') + worksheet['A4'] = "='Receita x Despesa'!A4:J4" + worksheet['A4'].font = Font(name="Arial", size=12, color="000000") + worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A5:H5') + worksheet['A5'] = "='Receita x Despesa'!A5:J5" + worksheet['A5'].font = Font(name="Arial", size=12, color="000000") + worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A6:H6') + worksheet['A6'] = "='Receita x Despesa'!A6:J6" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000") + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A7:H7') + worksheet['A7'] = "='Receita x Despesa'!A7:J7" + worksheet['A7'].font = Font(name="Arial", size=12, color="000000") + worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A9:H9') + worksheet['A9'] = 'RF Ref DI Plus Ágil - CNP JRF REF DI PLUS ÁGIL' + worksheet['A9'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A9'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['A9'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + + + + #stylecinza + start_row = 11 + for rows in worksheet.iter_rows(min_row=start_row, max_row=13, min_col=1, max_col=8): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + row_number = 11 + values = ["Período","Saldo Anterior","Valor Aplicado no período",'Valor Resgatado no Período','Rendimento Bruto','Imposto de Renda / IOF','Rendimento Líquido','Saldo'] + coluna = 1 + for a,b in enumerate(values): + worksheet.cell(row=row_number, column=coluna, value=b) + + coluna = coluna + 1 + + for i in range(1,9): + worksheet.merge_cells(start_row=11,end_row=13,start_column=i,end_column=i) + + + #RENDIMENTO LIQUIDO + # print(size) + for row in worksheet.iter_rows(min_row=14, max_row=size, min_col=7, max_col=7): + for cell in row: + stringSaldo = f"=E{cell.row} - F{cell.row}" + cell.value = stringSaldo + + + + + #BARRAS DE DADOS + start_row = 14 + for rows in worksheet.iter_rows(min_row=start_row, max_row=size, min_col=1, max_col=8): + for cell in rows: + if cell.row % 2: + cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, + fill_type = "solid") + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #MASCARA VERMELHO + for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=6, max_col=6): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="f90000") + cell.number_format ='#,##0.00' + + #MASCARANEGRITO + for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=1, max_col=1): + for cell in rows: + cell.font = Font(name="Arial", size=12, color="000000",bold=True) + + + # #MASCARA AZUL + # for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=6, max_col=6): + # for cell in rows: + # cell.font = Font(name="Arial", size=12, color="141fca") + # cell.number_format ='#,##0.00' + + # for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=7, max_col=7): + # for cell in rows: + # cell.font = Font(name="Arial", size=12, color="141fca",bold=True) + # cell.number_format ='#,##0.00' + + #barra de totais + formula = f"Saldo anterior" + celula = f'A14' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + #barra de totais + # FORMULATOTAL + #B + formula = f"=SUM(B15:B{size-1})" + celula = f'B{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + #C + formula = f"=SUM(C15:C{size-1})" + celula = f'C{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + #D + formula = f"=SUM(D15:D{size-1})" + celula = f'D{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + #E + formula = f"=SUM(E15:E{size-1})" + celula = f'E{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + #F + formula = f"=SUM(F15:F{size-1})" + celula = f'F{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + #G + formula = f"=SUM(G15:G{size-1})" + celula = f'G{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + #H + formula = f"=SUM(H15:H{size-1})" + celula = f'H{size}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + + #Total + celula_total = F'A{size}' + worksheet[celula_total] = f'TOTAL' + worksheet[celula_total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) + + #brasilia + brasilia_row = size + 2 + brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:J{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:F{brasilia_row}' + worksheet.merge_cells(brasilia_merge_cells) + top_left_brasilia_cell_formula = f'A{brasilia_row}' + top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] + top_left_brasilia_cell.value = brasilia_formula + top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") + + # #DiretorFinanceiro + diretor_row = size + 6 + diretor_cargo_row = size + 7 + diretor_cpf_row = size + 8 + diretor_nome_formula = f"='Receita x Despesa'!A{stringTamanho+3}" + diretor_cargo_formula = f"='Receita x Despesa'!A{stringTamanho+4}" + diretor_cpf_formula = f"='Receita x Despesa'!A{stringTamanho+5}" + diretor_merge_cells = f'A{diretor_row}:C{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:C{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:C{diretor_cpf_row}' + worksheet.merge_cells(diretor_merge_cells) + worksheet.merge_cells(diretor_cargo_merge_cells) + worksheet.merge_cells(diretor_cpf_merge_cells) + top_left_diretor_cell_formula = f'A{diretor_row}' + top_left_diretor_cell_cargo_formula = f'A{diretor_cargo_row}' + top_left_diretor_cell_cpf_formula = f'A{diretor_cpf_row}' + top_left_diretor_cell = worksheet[top_left_diretor_cell_formula] + top_left_diretor_cell_cargo_formula = worksheet[top_left_diretor_cell_cargo_formula] + top_left_diretor_cell_cpf_formula = worksheet[top_left_diretor_cell_cpf_formula] + top_left_diretor_cell.value = diretor_nome_formula + top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula + top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula + top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell.font = Font(bold=True) + top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + #Coordenadora + coordenadora_row = size + 6 + coordenadora_cargo_row = size + 7 + coordenadora_cpf_row = size + 8 + coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" + coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" + coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" + coordenadora_merge_cells = f'E{coordenadora_row}:G{coordenadora_row}' + coordenadora_cargo_merge_cells = f'E{coordenadora_cargo_row}:G{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'E{coordenadora_cpf_row}:G{coordenadora_cpf_row}' + worksheet.merge_cells(coordenadora_merge_cells) + worksheet.merge_cells(coordenadora_cargo_merge_cells) + worksheet.merge_cells(coordenadora_cpf_merge_cells) + top_left_coordenadora_cell_formula = f'E{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'E{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'E{coordenadora_cpf_row}' + top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] + top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] + top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] + top_left_coordenadora_cell.value = coordenadora_nome_formula + top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula + top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula + top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) + top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") + top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") - for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=10): + + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=8): for cell in row: - if cell.column == 10: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="dashed") ,bottom=Side(border_style="dashed") ) + if cell.column == 8: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) else: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="dashed") ) + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + - bord = Border(right=Side(border_style="dashed")) - - # - for row in worksheet.iter_rows(min_row=1, max_row=14,min_col=10,max_col=10): - for cell in row: - cell.border = bord - workbook.save(tabela) workbook.close() -def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2): +def estiloRelacaoBens(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): + """Estilo da tabela de bens, consulta no banco sap - + Argumentos: + tabela: recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo foi iniciado e passou pela preencher fub mas ainda está sem o estilo que será aplicado nessa função. + tamanho:Corresponde ao tamanho das quantidade de bens. + stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referências das formulas. + """ + random_number = random.randint(1, 10000) + + nomeVariavel = f'material{random_number}' caminho = pegar_caminho(tabela) workbook = openpyxl.load_workbook(caminho) - worksheet = workbook['Conciliação Bancária'] - - - size = tamanho + 21 - #worksheet.row_dimensions[27].height = 50 + worksheet = workbook[nomeTabela] + size = tamanho + 13 cinza = "d9d9d9" cinza_escuro = "bfbfbf" azul = "336394" azul_claro = '1c8cbc' - - borda = Border(right=Side(border_style="dashed")) + + borda = Border(right=Side(border_style="medium")) worksheet.sheet_view.showGridLines = False # - - - - # List of image names - image_names = [ - 'finatec.png', - 'ibict.png' - ] - - # # Path to the images - # path = 'C:\\Users\\Softex\\Desktop\\entrega29\\' - - # # List to hold Image objects - # images = [] - - # # Loop through the list of image names and create Image objects - # for i, name in enumerate(image_names): - # image_path = path + name - # pil_image = PILImage.open(image_path) - # pil_image.save(image_path) - # img = Image(image_path) - # images.append(img) - - # Path to the images - path = "/imagensIBICIT/" - - # List to hold Image objects - images = [] - - nomePasta = "imagensIBICIT" - diretorio = os.path.dirname(__file__) - - # Loop through the list of image names and create Image objects - for i, name in enumerate(image_names): - caminhoImage = os.path.join(diretorio, nomePasta, name) - pil_image = PILImage.open(caminhoImage) - pil_image.save(caminhoImage) - img = Image(caminhoImage) - images.append(img) - - - worksheet.add_image(images[1], "A1")#ibict - worksheet.add_image(images[0], "E1")#finatec - + for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=10,max_col=10): + for cell in row: + cell.border = borda + worksheet.column_dimensions['a'].width = 25 - worksheet.column_dimensions['b'].width = 25 + worksheet.column_dimensions['b'].width = 50 worksheet.column_dimensions['c'].width = 35 - worksheet.column_dimensions['d'].width = 35 - worksheet.column_dimensions['e'].width = 35 - worksheet.column_dimensions['f'].width = 25 - worksheet.row_dimensions[14].height = 6 - worksheet.row_dimensions[15].height = 29.25 - worksheet.row_dimensions[16].height = 6 - + worksheet.column_dimensions['d'].width = 35#descrição + worksheet.column_dimensions['e'].width = 40 #n do recibo ou qeuivalente + worksheet.column_dimensions['f'].width = 70 #data de emissão + worksheet.column_dimensions['g'].width = 25 #data de emissão + worksheet.column_dimensions['h'].width = 25 #data de emissão + worksheet.column_dimensions['i'].width = 25 #data de emissão + worksheet.column_dimensions['j'].width = 25 #data de emissão + #cabecario relação de pagamentos - outro servicoes de terceiros - worksheet.merge_cells('A7:F8') - worksheet['A7'] = f'C O N C I L I A Ç Ã O B A N C Á R I A' - worksheet['A7'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - worksheet['A7'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A7'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet.merge_cells('A1:J2') + worksheet['A1'] = f'RELAÇÃO DE BENS' + worksheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + + worksheet.merge_cells('A3:J4') + worksheet['A3'] = f'(ADQUIRIDOS, PRODUZIDOS OU CONSTRUÍDOS COM RECURSOS)' + worksheet['A3'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A3'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['A3'].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + + worksheet.merge_cells('A5:F5') + worksheet['A5'] = "='Receita x Despesa'!A3:J3" + worksheet['A5'].font = Font(name="Arial", size=12, color="000000") + worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A6:F6') + worksheet['A6'] = "='Receita x Despesa'!A4:J4" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000") + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A7:F7') + worksheet['A7'] = "='Receita x Despesa'!A5:J5" + worksheet['A7'].font = Font(name="Arial", size=12, color="000000") + worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A8:F8') + worksheet['A8'] = "='Receita x Despesa'!A6:J6" + worksheet['A8'].font = Font(name="Arial", size=12, color="000000") + worksheet['A8'].alignment = Alignment(horizontal="left",vertical="center") worksheet.merge_cells('A9:F9') - worksheet['A9'] = "='Receita x Despesa'!A9:J9" - worksheet['A9'].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet['A9'] = "='Receita x Despesa'!A7:J7" + worksheet['A9'].font = Font(name="Arial", size=12, color="000000") worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center") - - worksheet.merge_cells('A10:F10') - worksheet['A10'] = "='Receita x Despesa'!A10:J10" - worksheet['A10'].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet['A10'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A11:F11') - worksheet['A11'] = "='Receita x Despesa'!A11:J11" - worksheet['A11'].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet['A11'].alignment = Alignment(horizontal="left",vertical="center") + #variavel + + input2=f'rowStyle{nomeVariavel}' + + borda = Border( + left=Side(border_style='thin', color='FFFFFF'), + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF') +) + borda2 = Border( + left=Side(border_style='hair', color='000000'), + right=Side(border_style='hair', color='000000'), + top=Side(border_style='hair', color='000000'), + bottom=Side(border_style='hair', color='000000') +) + + #colunas azul cabecario + locals()[input2] = NamedStyle(name=f'{input2}') + locals()[input2].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + locals()[input2].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + locals()[input2].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + locals()[input2].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="thin") ) + locals()[input2].height = 20 + linha_number = 11 + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=10): + for cell in row: + cell.style = locals()[input2] + if cell.column == 10: + cell.border = Border(left=Side(border_style="thin", color='FFFFFF') ,bottom=Side(border_style="thin", color='FFFFFF'), right=Side(border_style="medium") ) + + + cell.border = borda + +##CABECARIO - worksheet.merge_cells('A12:F12') - worksheet['A12'] = "='Receita x Despesa'!A12:J12" - worksheet['A12'].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet['A12'].alignment = Alignment(horizontal="left",vertical="center") + worksheet["A11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("A11:A12") + worksheet["A11"] ="Nº DO ITEM" - worksheet.merge_cells('A13:F13') - worksheet['A13'] = "='Receita x Despesa'!A13:J13" - worksheet['A13'].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet['A13'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A15:F15') - worksheet['A15'] = "BB RF Simples - CNPJBB RF SIMPLES" - worksheet['A15'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - worksheet['A15'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A15'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - worksheet.merge_cells('A17:F17') - worksheet['A17'] = '1.Saldo conforme extratos bancários na data final do período' - worksheet['A17'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - worksheet['A17'].alignment = Alignment(horizontal="left",vertical="center") - worksheet['A17'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - worksheet.merge_cells('A18:E18') - worksheet['A18'] = 'Saldo de Conta Corrente(R$)' - worksheet['A18'].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet['A18'].alignment = Alignment(horizontal="right",vertical="center") - - worksheet.merge_cells('A19:E19') - worksheet['A19'] = 'Saldo de Aplicações Financeiras(R$)' - worksheet['A19'].font = Font(name="Arial", size=12, color="000000",bold=True) - worksheet['A19'].alignment = Alignment(horizontal="right",vertical="center") - worksheet['A19'].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") - - worksheet['F19'].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") - - worksheet.merge_cells('A21:F21') - worksheet['A21'] = '2. Restituições não creditadas pelo banco até a data final do período' - worksheet['A21'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - worksheet['A21'].alignment = Alignment(horizontal="left",vertical="center") - worksheet['A21'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - - for i in range(21,size): - sttring = f"D{i}:F{i}" - worksheet.merge_cells(sttring) - - for i in range(size+3,size+3+tamanho2): - sttring = f"D{i}:F{i}" - worksheet.merge_cells(sttring) + worksheet["B11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("B11:B12") + worksheet["B11"] = "DESCRIÇÃO DO BEM" - custom_number_format_conciliacoes = [] - # MASCARA R$ - if custom_number_format_conciliacoes!= False: - custom_number_format_conciliacoes = NamedStyle(name='custom_number_format_conciliacoes') - custom_number_format_conciliacoes.number_format = 'R$ #,##0.00' - custom_number_format_conciliacoes.font = Font(name="Arial", size=12, color="000000") - custom_number_format_conciliacoes.alignment = Alignment(horizontal="general",vertical="bottom",wrap_text=True) - - #stylecinza - start_row = 22 - for row in range(start_row,size+2): - cell = worksheet[f'B{row}'] - cell.style = custom_number_format_conciliacoes - - for rows in worksheet.iter_rows(min_row=22, max_row=size, min_col=1, max_col=6): - for cell in rows: - if cell.row % 2: - cell.fill = PatternFill(start_color=cinza, end_color=cinza, - fill_type = "solid") - cell.font = Font(name="Arial", size=12, color="000000") - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + worksheet["C11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("C11:C12") + worksheet["C11"] = "NÚMERO PATRIMONIAL DO BEM" + worksheet["D11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("D11:E11") + worksheet["D11"] = "DOCUMENTAÇÃO FISCAL" - row_number = 22 - values = ["Data","Valor(R$)","Documento",'Descrição'] - coluna = 1 - for a,b in enumerate(values): - worksheet.cell(row=row_number, column=coluna, value=b) - - coluna = coluna + 1 + worksheet["D12"].fill = openpyxl.styles.PatternFill(start_color=cinza, end_color=cinza, fill_type='solid') + worksheet["D12"] = "DATA" + worksheet["D12"].border = borda2 - # FORMULATOTAL - formula = f"=SUM(B16:B{size-1})" - celula = f'B{size}' - worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) - #Total - celula_total = F'A{size}' - worksheet[celula_total] = f'TOTAL' - worksheet[celula_total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) - #rubricado - celulaRubricado = F'C{size}' - stringLozalicaoRubricado = f'C{size}:F{size}' - worksheet.merge_cells(stringLozalicaoRubricado) - worksheet[celulaRubricado].fill = PatternFill(start_color="000000", end_color="FFFFFF",fill_type = "lightUp") + worksheet["E12"].fill = openpyxl.styles.PatternFill(start_color=cinza, end_color=cinza, fill_type='solid') + worksheet["E12"] = "Nº " + worksheet["E12"].border = borda2 - #'3. Restituições não creditadas pelo banco até a data final do período' - string_reituicoes_creditadas = f'A{size+2}:F{size+2}' - row_creditadas = f'A{size+2}' - worksheet.merge_cells(string_reituicoes_creditadas) - worksheet[row_creditadas] = '3. Restituições creditadas pelo banco até a data final do período' - worksheet[row_creditadas].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - worksheet[row_creditadas].alignment = Alignment(horizontal="left",vertical="center") - worksheet[row_creditadas].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet["F11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("F11:F12") + worksheet["F11"] = "LOCALIZAÇÃO" - #data valor documento descrição - row_number = size+3 - values = ["Data","Valor(R$)","Documento",'Descrição'] - coluna = 1 - for a,b in enumerate(values): - worksheet.cell(row=row_number, column=coluna, value=b) - coluna = coluna + 1 + worksheet["G11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("G11:G12") + worksheet["G11"] = "QTD." - for rows in worksheet.iter_rows(min_row=22, max_row=22, min_col=1, max_col=6): - for cell in rows: - cell.font = Font(name="Arial", size=12, color="000000",bold=True) - - + worksheet["H11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("H11:I11") + worksheet["H11"] = "VALOR (R$)" + worksheet["H12"].fill = openpyxl.styles.PatternFill(start_color=cinza, end_color=cinza, fill_type='solid') + worksheet["H12"] = "Unitário" + worksheet["H12"].border = borda2 + worksheet["I12"].fill = openpyxl.styles.PatternFill(start_color=cinza, end_color=cinza, fill_type='solid') + worksheet["I12"] = "Total" + worksheet["I12"].border = borda2 - for row in range(size+4,size+4+tamanho2): - cell = worksheet[f'B{row}'] - cell.style = custom_number_format_conciliacoes + #Aumentar a altura das celulas + for row in worksheet.iter_rows(min_row=10, max_row=size, min_col=1, max_col=10): + worksheet.row_dimensions[row[0].row].height = 35 + input3 = f'customNumber{nomeVariavel}' + + # MASCARA R$ + + locals()[input3] = NamedStyle(name=f'{input3}') + locals()[input3].number_format = 'R$ #,##0.00' + locals()[input3].font = Font(name="Arial", size=12, color="000000") + locals()[input3].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #estilocinzasimcinzanao + value_to_stop = size + start_row = 10 +# + for row in range(13,size+1): + cell = worksheet[f'H{row}'] + cell.style = locals()[input3] + + for row in range(13,size+1): + cell = worksheet[f'I{row}'] + cell.style = locals()[input3] - for rows in worksheet.iter_rows(min_row=size+3, max_row=size+3+tamanho, min_col=1, max_col=6): + for rows in worksheet.iter_rows(min_row=13, max_row=size, min_col=1, max_col=10): for cell in rows: if cell.row % 2: cell.fill = PatternFill(start_color=cinza, end_color=cinza, fill_type = "solid") - cell.font = Font(name="Arial", size=12, color="000000") - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - if cell.column == 6: - cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="dashed") ,bottom=Side(border_style="hair") ) + if cell.column == 10: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + else: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + + #subtotal + stringAfinarCelula =size+2 + worksheet.row_dimensions[size+2].height = 6 + celulas_mergidas_subtotal = f"A{size+2}:I{size+2}" + worksheet.merge_cells(celulas_mergidas_subtotal) + left_celula_cell = f"A{size+2}" + top_left_cell = worksheet[left_celula_cell] + top_left_cell.value = "TOTAL" + top_left_cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="medium") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + worksheet.row_dimensions[size+2].height = 56.25 - # FORMULATOTALrestituição - formula = f"=SUM(B{size+4}:B{size+tamanho2+3})" - celula = f'B{size+tamanho2+4}' + # FORMULATOTAL + formula = f"=SUM(I13:I{size})" + celula = f'J{size+2}' worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) worksheet[celula].number_format = 'R$ #,##0.00' - #Total - celula_total = F'A{size+tamanho2+4}' - worksheet[celula_total] = f'TOTAL' - worksheet[celula_total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) - #rubricado - celulaRubricadoSegundo = F'C{size+tamanho2+4}' - stringLozalicaoRubricadoSegundo = f'C{size+tamanho2+4}:F{size+tamanho2+4}' - worksheet.merge_cells(stringLozalicaoRubricadoSegundo) - worksheet[celulaRubricadoSegundo].fill = PatternFill(start_color="000000", end_color="FFFFFF",fill_type = "lightUp") - #Saldo disponível p/ período seguinte (1 +2 - 3) - string_saldo_disponivel = f'A{size+3+tamanho2+3}:D{size+3+tamanho2+3}' - celula_string_saldo = f'A{size+tamanho2+6}' - worksheet[celula_string_saldo].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet.merge_cells(string_saldo_disponivel) - worksheet[celula_string_saldo]= f'Saldo disponível p/ período seguinte (1 + 2 - 3)' - #total saldo diposnivel - string_merge_saldo_disponivel = f'E{size+3+tamanho2+3}:F{size+3+tamanho2+3}' - celula_string_total = f'E{size+tamanho2+6}' - worksheet.merge_cells(string_merge_saldo_disponivel) - saldodiposnivelformat_conciliacoes = NamedStyle(name='saldodiposnivelformat_conciliacoes') - saldodiposnivelformat_conciliacoes.number_format = 'R$ #,##0.00' - saldodiposnivelformat_conciliacoes.font = Font(name="Arial", size=12, color="000000") - saldodiposnivelformat_conciliacoes.alignment = Alignment(horizontal="general",vertical="bottom",wrap_text=True) - saldodiposnivelformat_conciliacoes.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - celular = worksheet[celula_string_total] - celular.style = saldodiposnivelformat_conciliacoes - celular.value = f'=F10+F11+B{size} -B{size+tamanho2+4}' - #brasilia - brasilia_row = size + tamanho2+ 8 - brasilia_formula = f"='Receita x Despesa'!A44:I44" - brasilia_merge_cells = f'A{brasilia_row}:F{brasilia_row}' + + #brasilia + brasilia_row = size + 7 + brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:J{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:I{brasilia_row}' worksheet.merge_cells(brasilia_merge_cells) top_left_brasilia_cell_formula = f'A{brasilia_row}' top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] top_left_brasilia_cell.value = brasilia_formula top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") - # #DiretorFinanceiro - diretor_row = size + 10 + tamanho2 - diretor_cargo_row = size + 11 + tamanho2 - diretor_cpf_row = size + 12 + tamanho2 - diretor_nome_formula = f"='Receita x Despesa'!A48" - diretor_cargo_formula = f"='Receita x Despesa'!A49" - diretor_cpf_formula = f"='Receita x Despesa'!A50" - diretor_merge_cells = f'A{diretor_row}:B{diretor_row}' - diretor_cargo_merge_cells = f'A{diretor_cargo_row}:B{diretor_cargo_row}' - diretor_cpf_merge_cells = f'A{diretor_cpf_row}:B{diretor_cpf_row}' + #DiretorFinanceiro + diretor_row = size + 8 + diretor_cargo_row = size + 9 + diretor_cpf_row = size + 10 + diretor_nome_formula = f"='Receita x Despesa'!A{stringTamanho+3}" + diretor_cargo_formula = f"='Receita x Despesa'!A{stringTamanho+4}" + diretor_cpf_formula = f"='Receita x Despesa'!A{stringTamanho+5}" + diretor_merge_cells = f'A{diretor_row}:D{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:D{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:D{diretor_cpf_row}' worksheet.merge_cells(diretor_merge_cells) worksheet.merge_cells(diretor_cargo_merge_cells) worksheet.merge_cells(diretor_cpf_merge_cells) @@ -696,25 +2373,25 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2): top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_diretor_cell.font = Font(bold=True) + top_left_diretor_cell.font = Font(name="Arial", size=12, color="000000",bold = True) top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") #Coordenadora - coordenadora_row = size + tamanho2 + 10 - coordenadora_cargo_row = size + 11 + tamanho2 - coordenadora_cpf_row = size + 12+ tamanho2 - coordenadora_nome_formula = f"='Receita x Despesa'!G48" - coordenadora_cargo_formula = f"='Receita x Despesa'!G49" - coordenadora_cpf_formula = f"='Receita x Despesa'!G50" - coordenadora_merge_cells = f'D{coordenadora_row}:F{coordenadora_row}' - coordenadora_cargo_merge_cells = f'D{coordenadora_cargo_row}:F{coordenadora_cargo_row}' - coordenadora_cpf_merge_cells = f'D{coordenadora_cpf_row}:F{coordenadora_cpf_row}' + coordenadora_row = size + 8 + coordenadora_cargo_row = size + 9 + coordenadora_cpf_row = size + 10 + coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" + coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" + coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" + coordenadora_merge_cells = f'F{coordenadora_row}:J{coordenadora_row}' + coordenadora_cargo_merge_cells = f'F{coordenadora_cargo_row}:J{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'F{coordenadora_cpf_row}:J{coordenadora_cpf_row}' worksheet.merge_cells(coordenadora_merge_cells) worksheet.merge_cells(coordenadora_cargo_merge_cells) worksheet.merge_cells(coordenadora_cpf_merge_cells) - top_left_coordenadora_cell_formula = f'D{coordenadora_row}' - top_left_coordenadora_cell_cargo_formula = f'D{coordenadora_cargo_row}' - top_left_coordenadora_cell_cpf_formula = f'D{coordenadora_cpf_row}' + top_left_coordenadora_cell_formula = f'F{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'F{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'F{coordenadora_cpf_row}' top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] @@ -722,260 +2399,284 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2): top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_coordenadora_cell.border = borda - top_left_coordenadora_cell.font= Font(bold = True) + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") - top_left_coordenadora_cell_cargo_formula.border = borda top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") - top_left_coordenadora_cell_cpf_formula.border = borda - for row in worksheet.iter_rows(min_row=1, max_row=size+tamanho2+12,min_col=6,max_col=6): - for cell in row: - cell.border = borda + + # borda = Border(right=Side(border_style="medium")) + # worksheet.sheet_view.showGridLines = False + # # + # for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=10): + # for cell in row: + # cell.border = borda + + - for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=6): + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=10): for cell in row: - if cell.column == 6: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="dashed") ,bottom=Side(border_style="dashed") ) + if cell.column == 10: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) else: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="dashed") ) - - for rows in worksheet.iter_rows(min_row=row_number, max_row=row_number, min_col=1, max_col=6): - for cell in rows: - cell.font = Font(name="Arial", size=12, color="000000",bold=True) + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) + + worksheet["J11"].fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + worksheet.merge_cells("J11:J12") + worksheet["J11"] = "RESPONSÁVEL PELA GUARDA DO BEM" + worksheet["J11"].border = Border(left=Side(border_style="thin", color='FFFFFF') ,bottom=Side(border_style="thin", color='FFFFFF'), right=Side(border_style="medium") ) + worksheet["J11"].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet["J10"].border = Border(right =Side(border_style="medium")) + worksheet.row_dimensions[10].height = 2 + workbook.save(tabela) workbook.close() -def estilo_rendimento_de_aplicacao(tabela,tamanho): +def estilo_demonstrativoDeReceita(tabela,tamanho,stringTamanho): + """Estilo da demonstrativo de receita que inclui entradas de receita ISS 2%, ISS 5%. + + Argumentos: + tabela: recebe o arquivo correspondente a tabela Fub extensão xlsx. Esse arquivo foi iniciado e passou pela preencher fub mas ainda está sem o estilo que será aplicado nessa função. + tamanho:Corresponde ao tamanho das quantidade de bens. + stringTamanho: refere-se aonde esta localizado a string brasilia na pagina Receita e despesa para a referências das formulas. + """ caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) - worksheet = workbook['Rendimento de Aplicação'] - size = tamanho + 16 - worksheet.row_dimensions[10].height = 2 - worksheet.row_dimensions[9].height = 20 - - # List of image names - image_names = [ - 'finatec.png', - 'ibict.png' - ] - - # # Path to the images - # path = 'C:\\Users\\Softex\\Desktop\\entrega29\\' - - # # List to hold Image objects - # images = [] - - # # Loop through the list of image names and create Image objects - # for i, name in enumerate(image_names): - # image_path = path + name - # pil_image = PILImage.open(image_path) - # pil_image.save(image_path) - # img = Image(image_path) - # images.append(img) - - - # Path to the images - path = "/imagensIBICIT/" - - # List to hold Image objects - images = [] - - nomePasta = "imagensIBICIT" - diretorio = os.path.dirname(__file__) - - # Loop through the list of image names and create Image objects - for i, name in enumerate(image_names): - caminhoImage = os.path.join(diretorio, nomePasta, name) - pil_image = PILImage.open(caminhoImage) - pil_image.save(caminhoImage) - img = Image(caminhoImage) - images.append(img) - - - - - - - - worksheet.add_image(images[1], "A1")#ibict - worksheet.add_image(images[0], "E1")#finatec - + worksheet = workbook['Demonstrativo de Receita'] + size = tamanho + 10 cinza = "d9d9d9" cinza_escuro = "bfbfbf" azul = "336394" - azul_claro = '0198cc' - borda = Border(right=Side(border_style="dashed")) + azul_claro = '1c8cbc' + random_number = random.randint(1, 10000) + borda = Border(right=Side(border_style="medium")) worksheet.sheet_view.showGridLines = False # - for row in worksheet.iter_rows(min_row=1, max_row=size+9,min_col=8,max_col=8): + for row in worksheet.iter_rows(min_row=1, max_row=size+11,min_col=5,max_col=5): for cell in row: cell.border = borda + - - - worksheet.column_dimensions['a'].width = 20 - worksheet.column_dimensions['b'].width = 20 - worksheet.column_dimensions['c'].width = 20 - worksheet.column_dimensions['d'].width = 20 - worksheet.column_dimensions['e'].width = 20 - worksheet.column_dimensions['f'].width = 20 - worksheet.column_dimensions['g'].width = 20 - worksheet.column_dimensions['h'].width = 20 - + worksheet.column_dimensions['a'].width = 30 + worksheet.column_dimensions['b'].width = 70 + worksheet.column_dimensions['c'].width = 30 + worksheet.column_dimensions['d'].width = 50#descrição + worksheet.column_dimensions['e'].width = 50#descrição #cabecario relação de pagamentos - outro servicoes de terceiros - worksheet.merge_cells('A7:H8') - worksheet['A7'] = f'Demonstrativo dos Ganhos Auferidos com Aplicações Financeiras' - worksheet['A7'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - worksheet['A7'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A7'].fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") - - worksheet.merge_cells('A9:H9') - worksheet['A9'] = "='Receita x Despesa'!A9:J9" - worksheet['A9'].font = Font(name="Arial", size=12, color="000000") - worksheet['A9'].alignment = Alignment(horizontal="left",vertical="center") - - worksheet.merge_cells('A10:H10') - worksheet['A10'] = "='Receita x Despesa'!A10:J10" - worksheet['A10'].font = Font(name="Arial", size=12, color="000000") - worksheet['A10'].alignment = Alignment(horizontal="left",vertical="center") + worksheet.merge_cells('A1:E2') + worksheet['A1'] = f'D E M O N S T R A T I V O D E R E C E I T A E ISS 5% E ISS 2%' + worksheet['A1'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + worksheet['A1'].alignment = Alignment(horizontal="center",vertical="center") + worksheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - worksheet.merge_cells('A11:H11') - worksheet['A11'] = "='Receita x Despesa'!A11:J11" - worksheet['A11'].font = Font(name="Arial", size=12, color="000000") - worksheet['A11'].alignment = Alignment(horizontal="left",vertical="center") + worksheet.merge_cells('A3:E3') + worksheet['A3'] = "='Receita x Despesa'!A3:J3" + worksheet['A3'].font = Font(name="Arial", size=12, color="000000") + worksheet['A3'].alignment = Alignment(horizontal="left",vertical="center") + + worksheet.merge_cells('A4:E4') + worksheet['A4'] = "='Receita x Despesa'!A4:J4" + worksheet['A4'].font = Font(name="Arial", size=12, color="000000") + worksheet['A4'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A12:H12') - worksheet['A12'] = "='Receita x Despesa'!A12:J12" - worksheet['A12'].font = Font(name="Arial", size=12, color="000000") - worksheet['A12'].alignment = Alignment(horizontal="left",vertical="center") - - worksheet.merge_cells('A13:H13') - worksheet['A13'] = "='Receita x Despesa'!A13:J13" - worksheet['A13'].font = Font(name="Arial", size=12, color="000000") - worksheet['A13'].alignment = Alignment(horizontal="left",vertical="center") + worksheet.merge_cells('A5:E5') + worksheet['A5'] = "='Receita x Despesa'!A5:J5" + worksheet['A5'].font = Font(name="Arial", size=12, color="000000") + worksheet['A5'].alignment = Alignment(horizontal="left",vertical="center") - worksheet.merge_cells('A14:H14') - worksheet['A14'] = 'BB CP Corpor Àgil - CNPJ 11.351.449-0001-10L' - worksheet['A14'].font = Font(name="Arial", size=12, color="FFFFFF",bold=True) - worksheet['A14'].alignment = Alignment(horizontal="center",vertical="center") - worksheet['A14'].fill = PatternFill(start_color=azul, end_color=azul,fill_type = "solid") + worksheet.merge_cells('A6:E6') + worksheet['A6'] = "='Receita x Despesa'!A6:J6" + worksheet['A6'].font = Font(name="Arial", size=12, color="000000") + worksheet['A6'].alignment = Alignment(horizontal="left",vertical="center") + worksheet.merge_cells('A7:E7') + worksheet['A7'] = "='Receita x Despesa'!A7:J7" + worksheet['A7'].font = Font(name="Arial", size=12, color="000000") + worksheet['A7'].alignment = Alignment(horizontal="left",vertical="center") - + #colunas azul cabecario + row_style_demonstrativo = NamedStyle(name=f'row_style_demonstrativo{random_number}') + row_style_demonstrativo.font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + row_style_demonstrativo.fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + row_style_demonstrativo.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + row_style_demonstrativo.border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="thin") ) + row_style_demonstrativo.height = 20 + linha_number = 9 + for row in worksheet.iter_rows(min_row=linha_number, max_row=linha_number, min_col=1, max_col=5): + for cell in row: + cell.style = row_style_demonstrativo + if cell.column == 5: + cell.border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="thin"), right=Side(border_style="medium") ) - #stylecinza - start_row = 18 - for rows in worksheet.iter_rows(min_row=start_row, max_row=13, min_col=1, max_col=8): + valores = ["NomeFavorecido","Histórico","Documento","Data de Entrada",'Valor'] + col = 1 + for a,b in enumerate(valores): + worksheet.cell(row=linha_number, column=col, value=b) + col = col + 1 + + + #Aumentar a altura das celulas + for row in worksheet.iter_rows(min_row=10, max_row=size, min_col=1, max_col=4): + worksheet.row_dimensions[row[0].row].height = 80 + + custom_number_format_demonstrativo = [] + # MASCARA R$ + if custom_number_format_demonstrativo!= False: + custom_number_format_demonstrativo = NamedStyle(name=f'custom_number_format_demonstrativo{random_number}') + custom_number_format_demonstrativo.number_format = 'R$ #,##0.00' + custom_number_format_demonstrativo.font = Font(name="Arial", size=12, color="000000") + custom_number_format_demonstrativo.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + #estilocinzasimcinzanao + value_to_stop = size + start_row = 10 +# + for row in range(start_row,size+1): + cell = worksheet[f'E{row}'] + cell.style = custom_number_format_demonstrativo + + for rows in worksheet.iter_rows(min_row=10, max_row=size, min_col=1, max_col=5): for cell in rows: if cell.row % 2: - cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro, + cell.fill = PatternFill(start_color=cinza, end_color=cinza, fill_type = "solid") - cell.font = Font(name="Arial", size=12, color="000000",bold=True) - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + if cell.column == 5: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="medium") ,bottom=Side(border_style="hair") ) + else: + cell.font = Font(name="Arial", size=12, color="000000") + cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair") ) + + + #subtotal + stringAfinarCelula =size+2 + worksheet.row_dimensions[size+2].height = 6 + celulas_mergidas_subtotal = f"A{size+2}:D{size+2}" + worksheet.merge_cells(celulas_mergidas_subtotal) + left_celula_cell = f"A{size+2}" + top_left_cell = worksheet[left_celula_cell] + top_left_cell.value = "Sub Total1" + top_left_cell.fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + top_left_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_cell.border = Border(top=Side(border_style="thin") ,left = Side(border_style="medium") ,right =Side(border_style="thin") ,bottom=Side(border_style="medium") ) + worksheet.row_dimensions[size+2].height = 56.25 - row_number = 15 - values = ["Período","Saldo Anterior","Valor Aplicado no período",'Valor Resgatado no Período','Rendimento Bruto','Imposto de Renda / IOF','Rendimento Líquido','Saldo'] + # FORMULATOTAL + formula = f"=SUM(E10:E{size})" + celula = f'E{size+2}' + worksheet[celula] = formula + worksheet[celula].fill = PatternFill(start_color=cinza, end_color=cinza,fill_type = "solid") + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + worksheet[celula].number_format = 'R$ #,##0.00' + #restituições creditadas + restituicoes = size + 3 + celula_restituicoes=f'A{restituicoes}' + worksheet[celula_restituicoes].value = "Estorno de Mensalidades" + worksheet[celula_restituicoes].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet.row_dimensions[restituicoes].height = 30 + + #estilo colunas restitucoes creditadas + row_style_demonstrativo_append = NamedStyle(name=f'row_style_demonstrativo_append{random_number}') + row_style_demonstrativo_append.font = Font(name="Arial", size=12, color="FFFFFF",bold=True) + row_style_demonstrativo_append.fill = openpyxl.styles.PatternFill(start_color=azul_claro, end_color=azul_claro, fill_type='solid') + row_style_demonstrativo_append.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + row_style_demonstrativo_append.height = 30 + row_style_demonstrativo_append.border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="medium") ) + + + row_number = size + 4 + + for column in range(1, 6): + cell = worksheet.cell(row=row_number, column=column) + cell.style = row_style_demonstrativo_append + if cell.column == 5: + cell.border = Border(top=Side(border_style="medium") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + + + + values = ["NomeFavorecido","Histórico","Documento","Data de Entrada",'Valor'] coluna = 1 for a,b in enumerate(values): worksheet.cell(row=row_number, column=coluna, value=b) - + if coluna == 5: + coluna = coluna + 1 coluna = coluna + 1 + + - for i in range(1,9): - worksheet.merge_cells(start_row=11,end_row=13,start_column=i,end_column=i) - #BARRAS DE DADOS - start_row = 14 - for rows in worksheet.iter_rows(min_row=start_row, max_row=size, min_col=1, max_col=8): - for cell in rows: - if cell.row % 2: - cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro, - fill_type = "solid") - cell.font = Font(name="Arial", size=12, color="000000") - cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) - #MASCARA VERMELHO - for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=6, max_col=6): - for cell in rows: - cell.font = Font(name="Arial", size=12, color="f90000") - #MASCARANEGRITO - for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=1, max_col=1): - for cell in rows: - cell.font = Font(name="Arial", size=12, color="000000",bold=True) - #MASCARA AZUL - for rows in worksheet.iter_rows(min_row=start_row, max_row=size-1, min_col=7, max_col=7): - for cell in rows: - cell.font = Font(name="Arial", size=12, color="141fca",bold=True) - #barra de totais - # FORMULATOTAL - #C - formula = f"=SUM(C14:C{size-1})" - celula = f'C{size}' - worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) - #D - formula = f"=SUM(D14:D{size-1})" - celula = f'D{size}' - worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) - #E - formula = f"=SUM(E14:E{size-1})" - celula = f'E{size}' - worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) - #F - formula = f"=SUM(F14:F{size-1})" - celula = f'F{size}' - worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) - #G - formula = f"=SUM(G14:G{size-1})" - celula = f'G{size}' - worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) - #H - formula = f"=SUM(H14:H{size-1})" - celula = f'H{size}' - worksheet[celula] = formula - worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) + #subtotal2 + sub_total2_row = size + 5 + subtotal_merge_cells= f'A{sub_total2_row}:D{sub_total2_row}' + worksheet.merge_cells(subtotal_merge_cells) + top_left_subtotal2_cell_formula = f'A{sub_total2_row}' + top_left_subtotal2_cell = worksheet[top_left_subtotal2_cell_formula] + top_left_subtotal2_cell.value = "Sub Total 2" + top_left_subtotal2_cell.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + top_left_subtotal2_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_subtotal2_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_subtotal2_cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="medium") ,right =Side(border_style="hair") ,bottom=Side(border_style="medium") ) + + sub_formula_row_celula = f'E{sub_total2_row}' + worksheet[sub_formula_row_celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") + worksheet[sub_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[sub_formula_row_celula].number_format = 'R$ #,##0.00' + worksheet[sub_formula_row_celula].border = Border(top=Side(border_style="thin") ,left = Side(border_style="thin") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) + + #total1-2 + total12_row = size + 6 + total12_merge_cells = f'A{total12_row}:D{total12_row}' + worksheet.merge_cells(total12_merge_cells) + top_left_total12_cell_formula = f'A{total12_row}' + top_left_total12_cell = worksheet[top_left_total12_cell_formula] + top_left_total12_cell.value = "Total(1-2)" + top_left_total12_cell.fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + top_left_total12_cell.font = Font(name="Arial", size=12, color="000000",bold=True) + top_left_total12_cell.alignment = Alignment(horizontal="center",vertical="center") + top_left_total12_cell.border = Border(top=Side(border_style="medium") ,left = Side(border_style="medium") ,bottom=Side(border_style="medium") ) + + + #total_formula + total_formula_row = size + 6 + total_formulaa = f'=E{size}' + total_formula_row_celula = f'E{total_formula_row}' + worksheet[total_formula_row_celula].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") + worksheet[total_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) + worksheet[total_formula_row_celula].number_format = 'R$ #,##0.00' + worksheet[total_formula_row_celula].border = Border(top=Side(border_style="medium") ,bottom=Side(border_style="medium"),right=Side(border_style="medium") ) + worksheet.row_dimensions[total_formula_row].height = 30 + worksheet[total_formula_row_celula] = total_formulaa - #Total - celula_total = F'A{size}' - worksheet[celula_total] = f'TOTAL' - worksheet[celula_total].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") - worksheet[celula_total].font = Font(name="Arial", size=12, color="000000",bold=True) #brasilia - brasilia_row = size + 2 - brasilia_formula = f"='Receita x Despesa'!A42:F42" - brasilia_merge_cells = f'A{brasilia_row}:F{brasilia_row}' + brasilia_row = size + 7 + brasilia_formula = f"='Receita x Despesa'!A{stringTamanho}:J{stringTamanho}" + brasilia_merge_cells = f'A{brasilia_row}:E{brasilia_row}' worksheet.merge_cells(brasilia_merge_cells) top_left_brasilia_cell_formula = f'A{brasilia_row}' top_left_brasilia_cell = worksheet[top_left_brasilia_cell_formula] top_left_brasilia_cell.value = brasilia_formula top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") - # #DiretorFinanceiro - diretor_row = size + 6 - diretor_cargo_row = size + 7 - diretor_cpf_row = size + 8 - diretor_nome_formula = f"='Receita x Despesa'!A45" - diretor_cargo_formula = f"='Receita x Despesa'!A46" - diretor_cpf_formula = f"='Receita x Despesa'!A47" - diretor_merge_cells = f'A{diretor_row}:C{diretor_row}' - diretor_cargo_merge_cells = f'A{diretor_cargo_row}:C{diretor_cargo_row}' - diretor_cpf_merge_cells = f'A{diretor_cpf_row}:C{diretor_cpf_row}' + #DiretorFinanceiro + diretor_row = size + 8 + diretor_cargo_row = size + 9 + diretor_cpf_row = size + 10 + diretor_nome_formula = f"='Receita x Despesa'!A{stringTamanho+3}" + diretor_cargo_formula = f"='Receita x Despesa'!A{stringTamanho+4}" + diretor_cpf_formula = f"='Receita x Despesa'!A{stringTamanho+5}" + diretor_merge_cells = f'A{diretor_row}:B{diretor_row}' + diretor_cargo_merge_cells = f'A{diretor_cargo_row}:B{diretor_cargo_row}' + diretor_cpf_merge_cells = f'A{diretor_cpf_row}:B{diretor_cpf_row}' worksheet.merge_cells(diretor_merge_cells) worksheet.merge_cells(diretor_cargo_merge_cells) worksheet.merge_cells(diretor_cpf_merge_cells) @@ -989,25 +2690,25 @@ def estilo_rendimento_de_aplicacao(tabela,tamanho): top_left_diretor_cell_cargo_formula.value = diretor_cargo_formula top_left_diretor_cell_cpf_formula.value = diretor_cpf_formula top_left_diretor_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_diretor_cell.font = Font(bold=True) + top_left_diretor_cell.font = Font(name="Arial", size=12, color="000000",bold = True) top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") #Coordenadora - coordenadora_row = size + 6 - coordenadora_cargo_row = size + 7 - coordenadora_cpf_row = size + 8 - coordenadora_nome_formula = f"='Receita x Despesa'!G45" - coordenadora_cargo_formula = f"='Receita x Despesa'!G46" - coordenadora_cpf_formula = f"='Receita x Despesa'!G47" - coordenadora_merge_cells = f'E{coordenadora_row}:G{coordenadora_row}' - coordenadora_cargo_merge_cells = f'E{coordenadora_cargo_row}:G{coordenadora_cargo_row}' - coordenadora_cpf_merge_cells = f'E{coordenadora_cpf_row}:G{coordenadora_cpf_row}' + coordenadora_row = size + 8 + coordenadora_cargo_row = size + 9 + coordenadora_cpf_row = size + 10 + coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" + coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" + coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" + coordenadora_merge_cells = f'C{coordenadora_row}:E{coordenadora_row}' + coordenadora_cargo_merge_cells = f'C{coordenadora_cargo_row}:E{coordenadora_cargo_row}' + coordenadora_cpf_merge_cells = f'C{coordenadora_cpf_row}:E{coordenadora_cpf_row}' worksheet.merge_cells(coordenadora_merge_cells) worksheet.merge_cells(coordenadora_cargo_merge_cells) worksheet.merge_cells(coordenadora_cpf_merge_cells) - top_left_coordenadora_cell_formula = f'E{coordenadora_row}' - top_left_coordenadora_cell_cargo_formula = f'E{coordenadora_cargo_row}' - top_left_coordenadora_cell_cpf_formula = f'E{coordenadora_cpf_row}' + top_left_coordenadora_cell_formula = f'C{coordenadora_row}' + top_left_coordenadora_cell_cargo_formula = f'C{coordenadora_cargo_row}' + top_left_coordenadora_cell_cpf_formula = f'C{coordenadora_cpf_row}' top_left_coordenadora_cell = worksheet[top_left_coordenadora_cell_formula] top_left_coordenadora_cell_cargo_formula = worksheet[top_left_coordenadora_cell_cargo_formula] top_left_coordenadora_cell_cpf_formula = worksheet[top_left_coordenadora_cell_cpf_formula] @@ -1015,41 +2716,26 @@ def estilo_rendimento_de_aplicacao(tabela,tamanho): top_left_coordenadora_cell_cargo_formula.value = coordenadora_cargo_formula top_left_coordenadora_cell_cpf_formula.value = coordenadora_cpf_formula top_left_coordenadora_cell.alignment = Alignment(horizontal="center",vertical="center") - top_left_coordenadora_cell.font= Font(bold = True) + top_left_coordenadora_cell.font= Font(name="Arial", size=12, color="000000",bold = True) top_left_coordenadora_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") top_left_coordenadora_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") + + # borda = Border(right=Side(border_style="medium")) + # worksheet.sheet_view.showGridLines = False + # # + # for row in worksheet.iter_rows(min_row=1, max_row=coordenadora_cpf_row+1,min_col=10,max_col=4): + # for cell in row: + # cell.border = borda + + - for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=8): + for row in worksheet.iter_rows(min_row=coordenadora_cpf_row+1, max_row=coordenadora_cpf_row+1,min_col=1,max_col=5): for cell in row: - if cell.column == 4: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="dashed") ,bottom=Side(border_style="dashed") ) + if cell.column == 5: + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="medium") ,bottom=Side(border_style="medium") ) else: - cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="dashed") ) - + cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) workbook.save(tabela) workbook.close() - - - -tabela = pegar_caminho('IBICT.xlsx') -nomeTabela ="Evento" -tituloStyle = "evento" -workbook = openpyxl.load_workbook(tabela) -sheet2 = workbook.create_sheet(title="Evento") -workbook.save("tabelapreenchida.xlsx") -workbook.close() -tabela = pegar_caminho("tabelapreenchida.xlsx") -workbook = openpyxl.load_workbook(tabela) -sheet2 = workbook.create_sheet(title="Conciliação Bancária") -sheet2 = workbook.create_sheet(title="Rendimento de Aplicação") -workbook.save(tabela) -workbook.close() -maior = 20 -maior2 = 20 -tabela2 = pegar_caminho('tabelapreenchida.xlsx') -print(tabela2) -estiloGeral(tabela2,maior,tituloStyle,nomeTabela) -estilo_conciliacoes_bancaria(tabela2,maior2,maior) -estilo_rendimento_de_aplicacao(tabela2,maior) \ No newline at end of file diff --git a/project/app/estilo_fub.py b/project/app/estilo_fub.py index 653f23a9..bdf7c778 100755 --- a/project/app/estilo_fub.py +++ b/project/app/estilo_fub.py @@ -65,27 +65,27 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): sheet['A1'].alignment = Alignment(horizontal="center",vertical="center") sheet['A1'].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") - sheet.merge_cells('A3:F3') + sheet.merge_cells('A3:I3') sheet['A3'] = "='Receita x Despesa'!A3:I3" sheet['A3'].font = Font(name="Arial", size=12, color="000000") sheet['A3'].alignment = Alignment(horizontal="left",vertical="center") - sheet.merge_cells('A4:F4') + sheet.merge_cells('A4:I4') sheet['A4'] = "='Receita x Despesa'!A4:I4" sheet['A4'].font = Font(name="Arial", size=12, color="000000") sheet['A4'].alignment = Alignment(horizontal="left",vertical="center") - sheet.merge_cells('A5:F5') + sheet.merge_cells('A5:I5') sheet['A5'] = "='Receita x Despesa'!A5:I5" sheet['A5'].font = Font(name="Arial", size=12, color="000000") sheet['A5'].alignment = Alignment(horizontal="left",vertical="center") - sheet.merge_cells('A6:F6') + sheet.merge_cells('A6:I6') sheet['A6'] = "='Receita x Despesa'!A6:I6" sheet['A6'].font = Font(name="Arial", size=12, color="000000") sheet['A6'].alignment = Alignment(horizontal="left",vertical="center") - sheet.merge_cells('A7:F7') + sheet.merge_cells('A7:I7') sheet['A7'] = "='Receita x Despesa'!A7:I7" sheet['A7'].font = Font(name="Arial", size=12, color="000000") sheet['A7'].alignment = Alignment(horizontal="left",vertical="center") @@ -154,6 +154,7 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): if cell.column == 8: stringSaldo = f"=F{cell.row} - G{cell.row}" cell.value = stringSaldo + if cell.column == 5: stringPorcentagem = f"=IFERROR(C{cell.row}/B{cell.row}, 0)" @@ -294,6 +295,7 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): sheet[apliFinStringCelula] = apliFinString + #barra de total nova 22/02 totalString = f"TOTAL" totalStringCelula = f'A{size2+5}' sheet[totalStringCelula] = totalString @@ -302,7 +304,16 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): cell.fill = PatternFill(start_color='9c9c9c', end_color='9c9c9c',fill_type = "solid") cell.alignment = Alignment(horizontal="center",vertical="center") - #total total + + totalString = f"TOTAL" + totalStringCelula = f'A{size2+9}' + sheet[totalStringCelula] = totalString + cell=sheet[totalStringCelula] + cell.font = Font(name="Arial", size=12, color="000000",bold = True) + cell.fill = PatternFill(start_color='9c9c9c', end_color='9c9c9c',fill_type = "solid") + cell.alignment = Alignment(horizontal="center",vertical="center") + + #barra total nova formula = f"=SUM(B{size2}, B15)" sheet[f'B{size2+5}'] = formula @@ -323,38 +334,14 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): sheet[f'H{size2+5}'] = formula - #barra de total nova 22/02 - totalString = f"TOTAL" - totalStringCelula = f'A{size2+9}' - sheet[totalStringCelula] = totalString - cell=sheet[totalStringCelula] - cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell.fill = PatternFill(start_color='9c9c9c', end_color='9c9c9c',fill_type = "solid") - cell.alignment = Alignment(horizontal="center",vertical="center") - - #soma barra total nova - - formula = f"=SUM(B{size2+8})" - sheet[f'B{size2+9}'] = formula - - formula = f"=SUM(C{size2+8})" - sheet[f'C{size2+9}'] = formula - - formula = f"=SUM(D{size2+8})" - sheet[f'D{size2+9}'] = formula - - formula = f"=SUM(F{size2+8})" - sheet[f'F{size2+9}'] = formula + #sheet[f'H{size2+5}'] + sheet.row_dimensions[size2 + 6].height = 1 + - formula = f"=SUM(G{size2+8})" - sheet[f'G{size2+9}'] = formula - - formula = f"=SUM(H{size2+8})" - sheet[f'H{size2+9}'] = formula #3.UTILIZAÇÂO DE RENDIMENTOS - formula = f"=SUM(A{size2+8})" - sheet[f'A{size2+7}'] = formula + # formula = f"=SUM(A{size2+8})" + # sheet[f'A{size2+7}'] = formula formula = f"=SUM(B{size2+8})" sheet[f'B{size2+7}'] = formula @@ -373,6 +360,19 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): formula = f"=SUM(H{size2+8})" sheet[f'H{size2+7}'] = formula + + ##SOMATORIO NEGATIVO C + Formula = f'=SUMIF(D16:D{size}, "<0")' + sheet[f'C{size2+8}']= Formula + ############## + + ##SOMATORIO NEGATIVO G + Formula = f'=SUMIF(H16:H{size}, "<0")' + sheet[f'G{size2+8}'] = Formula + ############## + + + #totais #total espesas correntes linha 15 @@ -411,28 +411,33 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): sheet[f'H{size2}'] = formula - #Total Utilização de rendimentos + #Total abaixo de Utilização de rendimentos formula = f"=B{size2+8}" - sheet[f'B{size2+5}'] = formula + sheet[f'B{size2+9}'] = formula formula = f"=C{size2+8}" - sheet[f'C{size2+5}'] = formula + sheet[f'C{size2+9}'] = formula formula = f"=D{size2+8}" - sheet[f'D{size2+5}'] = formula + sheet[f'D{size2+9}'] = formula formula = f"=F{size2+8}" - sheet[f'F{size2+5}'] = formula + sheet[f'F{size2+9}'] = formula formula = f"=G{size2+8}" - sheet[f'G{size2+5}'] = formula + sheet[f'G{size2+9}'] = formula formula = f"=H{size2+8}" - sheet[f'H{size2+5}'] = formula - + sheet[f'H{size2+9}'] = formula + + #somasaldo h + stringSaldo = f"=SUM(F{size2+8}+G{size2+8})" + + sheet[f"H{size2+8}"] = stringSaldo + #brasilia brasilia_row = size2 + 11 @@ -516,7 +521,66 @@ def estiloExecReceitaDespesa(tabela,tamanho,stringTamanho): cell.border = Border(top=Side(border_style="none") ,left = Side(border_style="none") ,right =Side(border_style="none") ,bottom=Side(border_style="medium") ) - + + #bordinha branca + + for row in sheet.iter_rows(min_row=1,max_row=coordenadora_cpf_row,min_col=1,max_col=10): + for cell in row: + + if cell.row == 15: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.column == 9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='medium', color='000000'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.row == size2: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.column == 9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='medium', color='000000'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + + if cell.row == size2+5: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.column == 9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='medium', color='000000'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.row == size2+7: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.column == 9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='medium', color='000000'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.row == size2+9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='thin', color='FFFFFF'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + if cell.column == 9: + cell.border = Border(left=Side(border_style='thin', color='FFFFFF'), # white + right=Side(border_style='medium', color='000000'), + top=Side(border_style='thin', color='FFFFFF'), + bottom=Side(border_style='thin', color='FFFFFF')) + + for row in sheet.iter_rows(min_row=1,max_row=coordenadora_cpf_row,min_col=10,max_col=10): + cell.border = Border(left=Side(border_style='medium', color='000000')) workbook.save(tabela) workbook.close() @@ -803,7 +867,8 @@ def estiloReceitaXDespesa(tabela,stringTamanho): sheet[tarifaBancariaSaldoEmStringCelula] = tarifaBancariaSaldoEmString cell=sheet[saldoConciliadoEmStringCelula] cell.font = Font(name="Arial", size=12, color="000000",bold = True) - cell=sheet[f'J{size2+6}'] + cell=sheet[f'I{size2+6}'] + cell.value= f"=I{size2+7}-I{size2+8}" cell.font = Font(name="Arial", size=12, color="000000",bold = True) cell.number_format = 'R$ #,##0.00' @@ -876,9 +941,6 @@ def estiloReceitaXDespesa(tabela,stringTamanho): cell.number_format = 'R$ #,##0.00' - - - #Barraazul barrazulMerge = f"A{size2+14}:J{size2+14}" @@ -890,6 +952,7 @@ def estiloReceitaXDespesa(tabela,stringTamanho): fill_type = "solid") cell.alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + #brasilia brasilia_row = size2 + 16 @@ -1122,7 +1185,7 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho,tamanhoesto #Aumentar a altura das celulas for row in worksheet.iter_rows(min_row=10, max_row=size, min_col=1, max_col=10): - worksheet.row_dimensions[row[0].row].height = 60 + worksheet.row_dimensions[row[0].row].height = 75 input3 = f'customNumber{nomeVariavel}' # MASCARA R$ @@ -1228,16 +1291,21 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho,tamanhoesto for rows in worksheet.iter_rows(min_row=size+5, max_row=size+4+tamanhoestorno, min_col=1, max_col=10): for cell in rows: if cell.row % 2: + cell.font = Font(name="Arial", size=12, color="000000") cell.fill = PatternFill(start_color=cinza, end_color=cinza, fill_type = "solid") if cell.column == 10: cell.number_format = 'R$ #,##0.00' + cell.font = Font(name="Arial", size=12, color="000000") + cell.border = Border(top=Side(border_style="hair") ,left = Side(border_style="hair") ,right =Side(border_style="hair") ,bottom=Side(border_style="hair")) - + cell.font = Font(name="Arial", size=12, color="000000") + + #bordas,corsimcornao,money # Set the height of each row to 60 for row in worksheet.iter_rows(min_row=size+4, max_row=size+4+tamanhoestorno): - worksheet.row_dimensions[row[0].row].height = 60 + worksheet.row_dimensions[row[0].row].height = 75 min_row = size + 4 max_row = size + 4 + tamanhoestorno @@ -1278,7 +1346,7 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho,tamanhoesto #total_formula total_formula_row = size + 7 + tamanhoestorno - total_formulaa = f'=J{size+2}' + total_formulaa = f'=J{size+2} - J{sub_total2_row }' total_formula_row_celula = f'J{total_formula_row}' worksheet[total_formula_row_celula].fill = PatternFill(start_color=azul_claro, end_color=azul_claro,fill_type = "solid") worksheet[total_formula_row_celula].font = Font(name="Arial", size=12, color="000000",bold=True) @@ -1328,9 +1396,9 @@ def estiloGeral(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho,tamanhoesto top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") #Coordenadora - coordenadora_row = size + 9 + tamanhoestorno - coordenadora_cargo_row = size + 10 + tamanhoestorno - coordenadora_cpf_row = size + 11 + tamanhoestorno + coordenadora_row = size + 9 + tamanhoestorno + coordenadora_cargo_row = size + 10 + tamanhoestorno + coordenadora_cpf_row = diretor_cpf_row coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" @@ -1395,7 +1463,7 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): worksheet = workbook['Conciliação Bancária'] #size e o tamanho da quantidade de arquivos recebido no argumento tamanho mais o tamanho do cabecario que no caso da fub e de 16 - size = tamanho + 16 + size = tamanho + 17 cinza = "d9d9d9" cinza_escuro = "bfbfbf" azul = "336394" @@ -1474,7 +1542,7 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): sttring = f"D{i}:F{i}" worksheet.merge_cells(sttring) - for i in range(size+3,size+4+tamanho2): + for i in range(size+3,size+4+tamanho2+1): sttring = f"D{i}:F{i}" worksheet.merge_cells(sttring) @@ -1546,10 +1614,30 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): for rows in worksheet.iter_rows(min_row=row_number, max_row=row_number, min_col=1, max_col=6): for cell in rows: cell.font = Font(name="Arial", size=12, color="000000",bold=True) - - - - for row in range(size+4,size+4+tamanho2): + cell.alignment = Alignment(horizontal="center",vertical="center") + + #saldo anterior restituição + row_restituicao = f'A{size+4}' + worksheet[row_restituicao] = 'Saldo anterior' + worksheet[row_restituicao].font = Font(name="Arial", size=12, color="000000") + worksheet[row_restituicao].alignment = Alignment(horizontal="left",vertical="center") + row_restituicao = f'b{size+4}' + worksheet[row_restituicao].font = Font(name="Arial", size=12, color="000000") + worksheet[row_restituicao].alignment = Alignment(horizontal="left",vertical="center") + row_restituicao = f'c{size+4}' + worksheet[row_restituicao] = 'Diversos' + worksheet[row_restituicao].font = Font(name="Arial", size=12, color="000000") + worksheet[row_restituicao].alignment = Alignment(horizontal="left",vertical="center") + row_restituicao = f'd{size+4}' + worksheet[row_restituicao] = 'Restituição Prestações Anteriores' + worksheet[row_restituicao].font = Font(name="Arial", size=12, color="000000") + worksheet[row_restituicao].alignment = Alignment(horizontal="left",vertical="center") + + + + size = size + 1 + + for row in range(size+3,size+4+tamanho2): cell = worksheet[f'B{row}'] cell.style = custom_number_format_conciliacoes @@ -1565,7 +1653,7 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): # FORMULATOTALrestituição - formula = f"=SUM(B{size+4}:B{size+tamanho2+3})" + formula = f"=SUM(B{size+3}:B{size+tamanho2+3})" celula = f'B{size+tamanho2+5}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") @@ -1592,7 +1680,22 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): saldodiposnivelformat_conciliacoes.fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") celular = worksheet[celula_string_total] celular.style = saldodiposnivelformat_conciliacoes - celular.value = f'=F10+F11+B{size} -B{size+tamanho2+5}' + celular.value = f'=F10+F11+B{size-1} -B{size+tamanho2+5}' + #saldo anterior + formula = f"Saldo anterior" + celula = f'A16' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000") + + formula = f"Diversos" + celula = f'C16' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000") + + formula = f"Tarifas Prestações Anteriores" + celula = f'D16' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000") #brasilia brasilia_row = size + tamanho2+ 8 @@ -1631,9 +1734,9 @@ def estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho): top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") #Coordenadora - coordenadora_row = size + tamanho2 + 10 - coordenadora_cargo_row = size + 11 + tamanho2 - coordenadora_cpf_row = size + 12+ tamanho2 + coordenadora_row = diretor_row + coordenadora_cargo_row = diretor_cargo_row + coordenadora_cpf_row = diretor_cpf_row coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" @@ -1687,7 +1790,7 @@ def estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho): worksheet = workbook['Rendimento de Aplicação'] random_number = random.randint(1, 10000) - size = tamanho + 14 + size = tamanho + 15 worksheet.row_dimensions[10].height = 2 worksheet.row_dimensions[9].height = 20 @@ -1820,48 +1923,52 @@ def estilo_rendimento_de_aplicacao(tabela,tamanho,stringTamanho): # cell.font = Font(name="Arial", size=12, color="141fca",bold=True) # cell.number_format ='#,##0.00' - + #barra de totais + formula = f"Saldo anterior" + celula = f'A14' + worksheet[celula] = formula + worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) #barra de totais # FORMULATOTAL #B - formula = f"=SUM(B14:B{size-1})" + formula = f"=SUM(B15:B{size-1})" celula = f'B{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) #C - formula = f"=SUM(C14:C{size-1})" + formula = f"=SUM(C15:C{size-1})" celula = f'C{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) #D - formula = f"=SUM(D14:D{size-1})" + formula = f"=SUM(D15:D{size-1})" celula = f'D{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) #E - formula = f"=SUM(E14:E{size-1})" + formula = f"=SUM(E15:E{size-1})" celula = f'E{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) #F - formula = f"=SUM(F14:F{size-1})" + formula = f"=SUM(F15:F{size-1})" celula = f'F{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) #G - formula = f"=SUM(G14:G{size-1})" + formula = f"=SUM(G15:G{size-1})" celula = f'G{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") worksheet[celula].font = Font(name="Arial", size=12, color="000000",bold=True) #H - formula = f"=SUM(H14:H{size-1})" + formula = f"=SUM(H15:H{size-1})" celula = f'H{size}' worksheet[celula] = formula worksheet[celula].fill = PatternFill(start_color=cinza_escuro, end_color=cinza_escuro,fill_type = "solid") @@ -2181,9 +2288,9 @@ def estiloRelacaoBens(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): top_left_brasilia_cell.alignment = Alignment(horizontal="center",vertical="center") #DiretorFinanceiro - diretor_row = size + 81 - diretor_cargo_row = size + 91 - diretor_cpf_row = size + 101 + diretor_row = size + 8 + diretor_cargo_row = size + 9 + diretor_cpf_row = size + 10 diretor_nome_formula = f"='Receita x Despesa'!A{stringTamanho+3}" diretor_cargo_formula = f"='Receita x Despesa'!A{stringTamanho+4}" diretor_cpf_formula = f"='Receita x Despesa'!A{stringTamanho+5}" @@ -2207,9 +2314,9 @@ def estiloRelacaoBens(tabela,tamanho,nomeVariavel,nomeTabela,stringTamanho): top_left_diretor_cell_cargo_formula.alignment = Alignment(horizontal="center",vertical="center") top_left_diretor_cell_cpf_formula.alignment = Alignment(horizontal="center",vertical="center") #Coordenadora - coordenadora_row = size + 81 - coordenadora_cargo_row = size + 91 - coordenadora_cpf_row = size + 101 + coordenadora_row = size + 8 + coordenadora_cargo_row = size + 9 + coordenadora_cpf_row = size + 10 coordenadora_nome_formula = f"='Receita x Despesa'!H{stringTamanho+3}" coordenadora_cargo_formula = f"='Receita x Despesa'!H{stringTamanho+4}" coordenadora_cpf_formula = f"='Receita x Despesa'!H{stringTamanho+5}" diff --git a/project/app/imagensCapa/agencia.png b/project/app/imagensCapa/agencia.png deleted file mode 100755 index 5594d9f1..00000000 Binary files a/project/app/imagensCapa/agencia.png and /dev/null differ diff --git a/project/app/imagensCapa/agencia_branco.png b/project/app/imagensCapa/agencia_branco.png deleted file mode 100755 index 1966afb6..00000000 Binary files a/project/app/imagensCapa/agencia_branco.png and /dev/null differ diff --git a/project/app/imagensCapa/agente.png b/project/app/imagensCapa/agente.png deleted file mode 100755 index 38f85e28..00000000 Binary files a/project/app/imagensCapa/agente.png and /dev/null differ diff --git a/project/app/imagensCapa/agente_branco.png b/project/app/imagensCapa/agente_branco.png deleted file mode 100755 index 2714e44c..00000000 Binary files a/project/app/imagensCapa/agente_branco.png and /dev/null differ diff --git a/project/app/imagensCapa/analista.png b/project/app/imagensCapa/analista.png deleted file mode 100755 index 2d85ce37..00000000 Binary files a/project/app/imagensCapa/analista.png and /dev/null differ diff --git a/project/app/imagensCapa/analista_branco.png b/project/app/imagensCapa/analista_branco.png deleted file mode 100755 index a3f2c21b..00000000 Binary files a/project/app/imagensCapa/analista_branco.png and /dev/null differ diff --git a/project/app/imagensCapa/assinaturas_responsaveis.png b/project/app/imagensCapa/assinaturas_responsaveis.png deleted file mode 100755 index 7216a55c..00000000 Binary files a/project/app/imagensCapa/assinaturas_responsaveis.png and /dev/null differ diff --git a/project/app/imagensCapa/assistente.png b/project/app/imagensCapa/assistente.png deleted file mode 100755 index 573d4ad4..00000000 Binary files a/project/app/imagensCapa/assistente.png and /dev/null differ diff --git a/project/app/imagensCapa/assistente_branco.png b/project/app/imagensCapa/assistente_branco.png deleted file mode 100755 index 4e87a7ac..00000000 Binary files a/project/app/imagensCapa/assistente_branco.png and /dev/null differ diff --git a/project/app/imagensCapa/banco.png b/project/app/imagensCapa/banco.png deleted file mode 100755 index 5594d9f1..00000000 Binary files a/project/app/imagensCapa/banco.png and /dev/null differ diff --git a/project/app/imagensCapa/banco_branco.png b/project/app/imagensCapa/banco_branco.png deleted file mode 100755 index 1966afb6..00000000 Binary files a/project/app/imagensCapa/banco_branco.png and /dev/null differ diff --git a/project/app/imagensCapa/centrodecusto.png b/project/app/imagensCapa/centrodecusto.png deleted file mode 100755 index 3f027ea6..00000000 Binary files a/project/app/imagensCapa/centrodecusto.png and /dev/null differ diff --git a/project/app/imagensCapa/centrodecusto_branco.png b/project/app/imagensCapa/centrodecusto_branco.png deleted file mode 100755 index 0d53683f..00000000 Binary files a/project/app/imagensCapa/centrodecusto_branco.png and /dev/null differ diff --git a/project/app/imagensCapa/conta_corrente.png b/project/app/imagensCapa/conta_corrente.png deleted file mode 100755 index 0a0513b3..00000000 Binary files a/project/app/imagensCapa/conta_corrente.png and /dev/null differ diff --git a/project/app/imagensCapa/conta_corrente_branco.png b/project/app/imagensCapa/conta_corrente_branco.png deleted file mode 100755 index 1966afb6..00000000 Binary files a/project/app/imagensCapa/conta_corrente_branco.png and /dev/null differ diff --git a/project/app/imagensCapa/coordenador.png b/project/app/imagensCapa/coordenador.png deleted file mode 100755 index 83ef1f41..00000000 Binary files a/project/app/imagensCapa/coordenador.png and /dev/null differ diff --git a/project/app/imagensCapa/coordenador_branco.png b/project/app/imagensCapa/coordenador_branco.png deleted file mode 100755 index ac2b643c..00000000 Binary files a/project/app/imagensCapa/coordenador_branco.png and /dev/null differ diff --git a/project/app/imagensCapa/dadosdoacordo.png b/project/app/imagensCapa/dadosdoacordo.png deleted file mode 100755 index 9a638e47..00000000 Binary files a/project/app/imagensCapa/dadosdoacordo.png and /dev/null differ diff --git a/project/app/imagensCapa/gerente.png b/project/app/imagensCapa/gerente.png deleted file mode 100755 index cbbdafd1..00000000 Binary files a/project/app/imagensCapa/gerente.png and /dev/null differ diff --git a/project/app/imagensCapa/gerente_branco.png b/project/app/imagensCapa/gerente_branco.png deleted file mode 100755 index f9fa8e2e..00000000 Binary files a/project/app/imagensCapa/gerente_branco.png and /dev/null differ diff --git a/project/app/imagensCapa/periodo.png b/project/app/imagensCapa/periodo.png deleted file mode 100755 index cd1af862..00000000 Binary files a/project/app/imagensCapa/periodo.png and /dev/null differ diff --git a/project/app/imagensCapa/periodo_branco.png b/project/app/imagensCapa/periodo_branco.png deleted file mode 100755 index 7c3f0f92..00000000 Binary files a/project/app/imagensCapa/periodo_branco.png and /dev/null differ diff --git "a/project/app/imagensCapa/presta\303\247\303\243odecontasparcial.png" "b/project/app/imagensCapa/presta\303\247\303\243odecontasparcial.png" deleted file mode 100755 index 35f3b358..00000000 Binary files "a/project/app/imagensCapa/presta\303\247\303\243odecontasparcial.png" and /dev/null differ diff --git a/project/app/imagensCapa/processo.png b/project/app/imagensCapa/processo.png deleted file mode 100755 index 3f027ea6..00000000 Binary files a/project/app/imagensCapa/processo.png and /dev/null differ diff --git a/project/app/imagensCapa/processo_branco.png b/project/app/imagensCapa/processo_branco.png deleted file mode 100755 index 3937be94..00000000 Binary files a/project/app/imagensCapa/processo_branco.png and /dev/null differ diff --git a/project/app/imagensCapa/projeto.png b/project/app/imagensCapa/projeto.png deleted file mode 100755 index 99753c53..00000000 Binary files a/project/app/imagensCapa/projeto.png and /dev/null differ diff --git a/project/app/imagensCapa/projeto_branco.png b/project/app/imagensCapa/projeto_branco.png deleted file mode 100755 index b80bd775..00000000 Binary files a/project/app/imagensCapa/projeto_branco.png and /dev/null differ diff --git a/project/app/imagensIBICIT/finatec.png b/project/app/imagensIBICIT/finatec.png deleted file mode 100755 index 88ffdeb0..00000000 Binary files a/project/app/imagensIBICIT/finatec.png and /dev/null differ diff --git a/project/app/imagensIBICIT/ibict.png b/project/app/imagensIBICIT/ibict.png deleted file mode 100755 index 8038a251..00000000 Binary files a/project/app/imagensIBICIT/ibict.png and /dev/null differ diff --git a/project/app/new_dev.py b/project/app/new_dev.py index dc874cd9..08dd8353 100755 --- a/project/app/new_dev.py +++ b/project/app/new_dev.py @@ -82,7 +82,7 @@ def pegar_caminho(subdiretorio): # print(f"arquivo salvo como planilhas_preenchidas/{planilha}") # return caminho_planilha -def preenche_planilha(planilha, dicionario): +def preenche_planilha(planilha, dicionario,codigo,template_id,consultaInicio,consultaFim,stringNomeFinanciador): filename = os.path.basename(planilha) @@ -111,7 +111,8 @@ def preenche_planilha(planilha, dicionario): diretorio_atual = os.path.dirname(os.path.abspath(__file__)) # Combina o diretório atual com o caminho para a pasta "planilhas_preenchidas" e o nome do arquivo - salvar = os.path.join(diretorio_atual, caminho_pasta_planilhas, f"planilhaPreenchida{filename}") + #salvar = os.path.join(diretorio_atual, caminho_pasta_planilhas, f"planilhaPreenchida{filename}") + salvar = os.path.join(diretorio_atual, caminho_pasta_planilhas, f"PC - {stringNomeFinanciador} - {codigo} - {consultaInicio} a {consultaFim}.xlsx") workbook.save(salvar) diff --git a/project/app/planilhas/IBICT.xlsx b/project/app/planilhas/IBICT.xlsx deleted file mode 100755 index 93a0990a..00000000 Binary files a/project/app/planilhas/IBICT.xlsx and /dev/null differ diff --git a/project/app/planilhas/ModeloFAP.xlsx b/project/app/planilhas/ModeloFAP.xlsx deleted file mode 100755 index 1de9600a..00000000 Binary files a/project/app/planilhas/ModeloFAP.xlsx and /dev/null differ diff --git a/project/app/planilhas/ModeloFINEP.xlsx b/project/app/planilhas/ModeloFINEP.xlsx deleted file mode 100644 index 72984cad..00000000 Binary files a/project/app/planilhas/ModeloFINEP.xlsx and /dev/null differ diff --git a/project/app/planilhas/ModeloFUNDEP.xlsx b/project/app/planilhas/ModeloFUNDEP.xlsx deleted file mode 100755 index cb930749..00000000 Binary files a/project/app/planilhas/ModeloFUNDEP.xlsx and /dev/null differ diff --git a/project/app/planilhas/ModeloOPAS.xlsx b/project/app/planilhas/ModeloOPAS.xlsx deleted file mode 100755 index 89b22070..00000000 Binary files a/project/app/planilhas/ModeloOPAS.xlsx and /dev/null differ diff --git a/project/app/planilhas/Modelo_Fub.xlsx b/project/app/planilhas/Modelo_Fub.xlsx deleted file mode 100644 index fa19bf15..00000000 Binary files a/project/app/planilhas/Modelo_Fub.xlsx and /dev/null differ diff --git a/project/app/planilhas_preenchidas/planilhas/test.txt b/project/app/planilhas_preenchidas/planilhas/test.txt deleted file mode 100755 index 78981922..00000000 --- a/project/app/planilhas_preenchidas/planilhas/test.txt +++ /dev/null @@ -1 +0,0 @@ -a diff --git a/project/app/preencheFap.py b/project/app/preencheFap.py new file mode 100644 index 00000000..1d3f2249 --- /dev/null +++ b/project/app/preencheFap.py @@ -0,0 +1,705 @@ +import pyodbc +from datetime import datetime,date +import openpyxl +from openpyxl.styles import Font +import os +from collections import defaultdict +from .estiloFap import * +from .preencheFub import planilhaGeral,consultaID,convert_datetime_to_string,convert_datetime_to_stringdt,formatar_data,formatarDataSemDia,formatar_cpf,check_format,pegar_caminho,pegar_pass +import pandas as pd +from sqlalchemy import create_engine +from sqlalchemy.engine import URL +import numpy as np +import re + +def consultaCabecarioAnexoDois(IDPROJETO,DATA1,DATA2): + """ Informa o titulo do projeto + a instiuição gestora + a instuição executora + NTOA/ e processo + +NomeConvenio Processo SubProcesso ValorAprovado +FAP - FUB/IQ - Edital 05/2016 -Micropoluentes emergentes e o uso da água na Bacia do Paranoá: diagnóstico, identificação de fontes, efeitos tóxicos métodos de remoção e de detecção in situ + +Processo + +0193.000714/2016 + +SubProcesso + +Projeto TOA n° 503/2016 - Edital 05/2016 + +ValorAprovado + +699000.0000 + + """ + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + parametros = [(IDPROJETO,)] + queryNomeCabecario = f"SELECT [LisConvenio].NomeConvenio ,[LisConvenio].Processo,SubProcesso,ValorAprovado,NomePessoa FROM [Conveniar].[dbo].[LisConvenio] WHERE CodConvenio = ? " + dfCabecarios = pd.read_sql(queryNomeCabecario, engine, params=parametros) + + return dfCabecarios + +def consultaID(IDPROJETO): + + #file_path = "/home/ubuntu/Desktop/devfront/devfull/pass.txt" + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + conn = None + + conn = pyodbc.connect(conStr) + cursor = conn.cursor() + + + consulta = {} + + + # SQL querys + + sql = f"SELECT [LisConvenio].* , [LisPessoa].[CPFCNPJ] as 'CPFCoordenador' FROM [Conveniar].[dbo].[LisConvenio] INNER JOIN [Conveniar].[dbo].[LisUsuario] ON [LisConvenio].[CodUsuarioResponsavel] = [LisUsuario].[CodUsuario] INNER JOIN [Conveniar].[dbo].[LisPessoa] ON [LisUsuario].[CodPessoa] = [LisPessoa].[CodPessoa] WHERE CodConvenio = ? " + + # Execute the query + cursor.execute(sql, IDPROJETO) + + + records = cursor.fetchall() + + collums = cursor.description + + + for i in range(len(collums)): + consulta[collums[i][0]] = records[0][i] + + cursor.close() + conn.close() + + + + # return records + return consulta + +def consultaAnexoUm(IDPROJETO): + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + parametros = [(IDPROJETO,)] + queryNomeConvenioProcessoSubProcesso = f"SELECT [LisConvenio].NomeConvenio ,[LisConvenio].Processo,SubProcesso,ValorAprovado,NomePessoaResponsavel FROM [Conveniar].[dbo].[LisConvenio] WHERE CodConvenio = ? " + dfConvenioProcessoSubProcessos = pd.read_sql(queryNomeConvenioProcessoSubProcesso, engine, params=parametros) + + + return dfConvenioProcessoSubProcessos + +def consultaAnexoDois(IDPROJETO,DATA1,DATA2): + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + parametros = [(IDPROJETO,DATA1,DATA2)] + queryAnexoDois = f"""SELECT [NomeRubrica] + ,NumChequeDeposito + ,CONVERT(varchar(10), DataPagamento, 103) AS FormattedDate + ,NumDocPago + ,[NomeFavorecido] + ,HisLancamento + ,CASE WHEN NomeTipoCreditoDebito = 'C' THEN -1 * ValorPago ELSE ValorPago END AS ValorPago, + CASE WHEN NomeTipoCreditoDebito = 'C' THEN -1 * ValorPago ELSE ValorPago END AS ValorPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE [LisLancamentoConvenio].CodConvenio = ? AND [LisLancamentoConvenio].CodStatus = 27 + AND [LisLancamentoConvenio].DataPagamento BETWEEN ? AND ? and [LisLancamentoConvenio].CodRubrica not in (2,3,9,67,88,0) order by DataPagamento""" + dfConvenioAnexoDois = pd.read_sql(queryAnexoDois, engine, params=parametros) + + + + return dfConvenioAnexoDois + +def consultaAnexoTres(IDPROJETO,DATA1,DATA2): + file_path = pegar_pass("passss.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + idprojetoComZero = f"0{IDPROJETO}" + parametros = [(IDPROJETO,idprojetoComZero, DATA1, DATA2)] + + queryConsultaComRubrica = f"""SELECT + CONVERT(varchar, [Data de Aquisição], 103) AS dataAqui, + [Nº Nota][nota], + [Descrição][descri], + [Valor de Aquisição][valorAqui], + [Valor de Aquisição][valorAqui2], + [Patrimônio][patri], + [Localização][localiza], + [Responsável][responsavel] + FROM [SBO_FINATEC].[dbo].[VW_BENS_ADQUIRIDOS] + WHERE ([Cod Projeto] = ? or [Cod Projeto] = ? ) + AND [Status] = 'Imobilizado' + AND [Data de Aquisição] BETWEEN ? AND ? + Order by [Data de Aquisição]""" + dfConsultaBens = pd.read_sql(queryConsultaComRubrica, engine, params=parametros) + + + return dfConsultaBens + return 0 + +def consultaRendimentosIRRFConciliacao(IDPROJETO,DATA1,DATA2): + """consulta fora do comum utilizado para pegar o total de rendimentos para aparecer na pasta conciliação + """ + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + parametros = [(IDPROJETO, DATA1, DATA2)] + + consultaComPeriodo =f"SELECT SUM(ValorPago) AS TotalPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 0 AND DataPagamento BETWEEN ? AND ?" + + consultaRendimentoAplicacao = f""" + SELECT + NomeTipoLancamento, + SUM(CASE WHEN NomeTipoLancamento = 'IRRF Pessoa Jurídica' THEN ValorPago ELSE 0 END) AS IRRF, + SUM(CASE WHEN NomeTipoLancamento = 'Aplicação Financeira' THEN ValorPago ELSE 0 END) AS Aplicação + FROM + [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE + CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 3 + AND DataPagamento BETWEEN ? AND ? + GROUP BY + NomeTipoLancamento; + """ + + + Soma = pd.read_sql(consultaRendimentoAplicacao, engine, params=parametros) + + return Soma + +def consultaDevolucaoRecursosConciliacao(IDPROJETO,DATA1,DATA2): + """Consulta pra informar o total de devolução de recurso dos projetos + """ + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + parametros = [(IDPROJETO, DATA1, DATA2)] + + consultaComPeriodo = f"SELECT SUM(ValorPago) AS TotalPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 0 AND DataPagamento BETWEEN ? AND ?" + + + Soma = pd.read_sql(consultaComPeriodo, engine, params=parametros) + + return Soma + +def consultaRendimentosAplicacao(IDPROJETO,DATA1,DATA2): + """Imprime as colunas de imposto e rendimento bruto. + + Args: + + IDPROJETO: numero do projeto + + DATA1: Data inicio prestação de contas + + DATA2: Data fim prestação de contas + + + Returns: + + Retorna tres dataframes, um contem o imposto o outro contem o rendimento bruto + """ + + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + parametros = [(IDPROJETO, DATA1, DATA2)] + consultaRendimentoAplicacao = f"SELECT DataPagamento,ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 3 and NomeTipoLancamento = 'Aplicação Financeira' AND DataPagamento BETWEEN ? AND ? order by DataPagamento" + dfConsultaRendimentoAplicacao = pd.read_sql(consultaRendimentoAplicacao, engine, params=parametros) + + consultaRendimentoEImposto = f"SELECT DataPagamento,ValorPago,NomeTipoLancamento FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 3 and (NomeTipoLancamento = 'Aplicação Financeira' or NomeTipoLancamento = 'IRRF Pessoa Jurídica') AND DataPagamento BETWEEN ? AND ? order by DataPagamento" + dfConsultaRendimentoEImposto = pd.read_sql(consultaRendimentoEImposto, engine, params=parametros) + + consultaImposto = f"SELECT DataPagamento,ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 3 and NomeTipoLancamento = 'IRRF Pessoa Jurídica' AND DataPagamento BETWEEN ? AND ? order by DataPagamento" + dfConsultaImposto = pd.read_sql(consultaImposto, engine, params=parametros) + + + return dfConsultaRendimentoAplicacao,dfConsultaImposto,dfConsultaRendimentoEImposto + +def consultaConciliacao(IDPROJETO,DATA1,DATA2): + """ Informa o nome do convenio,Processo,SubProcesso e Valor Aprovado do projeto + +NomeConvenio Processo SubProcesso ValorAprovado +FAP - FUB/IQ - Edital 05/2016 -Micropoluentes emergentes e o uso da água na Bacia do Paranoá: diagnóstico, identificação de fontes, efeitos tóxicos métodos de remoção e de detecção in situ + +Processo + +0193.000714/2016 + +SubProcesso + +Projeto TOA n° 503/2016 - Edital 05/2016 + +ValorAprovado + +699000.0000 + + """ + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + parametros = [(IDPROJETO,)] + queryNomeConvenioProcessoSubProcesso = f""" + SELECT [LisConvenio].NomeConvenio , + [LisConvenio].Processo, + SubProcesso, + ValorAprovado,NomePessoaResponsavel + FROM [Conveniar].[dbo].[LisConvenio] WHERE CodConvenio = ? """ + dfConvenioProcessoSubProcessos = pd.read_sql(queryNomeConvenioProcessoSubProcesso, engine, params=parametros) + + return dfConvenioProcessoSubProcessos + + +#preencher + +def anexoUm(tabela,codigo,data1,data2): + dfAnexoUm = consultaAnexoUm(codigo) + dfAnexoRendimento = consultaRendimentosIRRFConciliacao(codigo,data1,data2) + pd.set_option('display.max_colwidth', None) + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + sheet = workbook['ANEXO I'] + # Soma = dfSoma["Aplicação"] + dfSoma["IRRF"] + stringNome = dfAnexoUm['NomeConvenio'] + stringValorAprovado = dfAnexoUm['ValorAprovado'] + stringProcesso = dfAnexoUm['Processo'] + stringSubProcesso = dfAnexoUm['SubProcesso'] + stringCoordenador = dfAnexoUm['NomePessoaResponsavel'] + stringRendApli= dfAnexoRendimento.loc[dfAnexoRendimento['NomeTipoLancamento'] == 'Aplicação Financeira', 'Aplicação'].values[0] + sheet['A20'] = stringNome.to_string(index=False) + sheet['A20'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['A20'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + sheet['A22'] = f'Valor Global R$:{stringValorAprovado.to_string(index=False)}' + sheet['A22'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['A22'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + sheet['E7'] = f'{stringSubProcesso.to_string(index=False)} / {stringProcesso.to_string(index=False)}' + sheet['E7'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['E7'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + sheet['C29'] = stringRendApli + sheet['C29'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['C29'].alignment = Alignment(horizontal="right",vertical="center",wrap_text=True) + sheet['D46'] = stringCoordenador.to_string(index=False) + sheet['D46'].font = Font(name="Arial", size=12, color="000000") + sheet['D46'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + + + input_date = [] + output_date_str = [] + input_date2 = [] + output_date_str2 = [] + if check_format(data1): + input_date = datetime.strptime(data1, "%Y-%m-%d") + # Format the datetime object to a string in dd/mm/yyyy format + output_date_str = input_date.strftime("%d/%m/%Y") + else : + return None + if check_format(data2): + input_date2 = datetime.strptime(data2, "%Y-%m-%d") + # Format the datetime object to a string in dd/mm/yyyy format + output_date_str2 = input_date2.strftime("%d/%m/%Y") + else : + return None + + + #periodo prestação de contas + stringPeriodoAbrangido = f'Período da Prestação de Contas: {output_date_str} a {output_date_str2}' + sheet['C22'] = stringPeriodoAbrangido + sheet['C22'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['C22'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + meses_dict = { + 1: "Janeiro", + 2: "Fevereiro", + 3: "Março", + 4: "Abril", + 5: "Maio", + 6: "Junho", + 7: "Julho", + 8: "Agosto", + 9: "Setembro", + 10: "Outubro", + 11: "Novembro", + 12: "Dezembro" +} + + stringTamanhoBrasilia = f'A{40}' # retorna lugar de brasilia + hoje = date.today() + data_formatada = f"{hoje.day} de {meses_dict[hoje.month]} de {hoje.year}" + sheet[stringTamanhoBrasilia] = f'Brasilia, {data_formatada}' + sheet[stringTamanhoBrasilia].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet[stringTamanhoBrasilia].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + + + + + + + workbook.save(tabela) + workbook.close() + +def anexoDois(tabela,codigo,data1,data2): + consultaAnexoDois(codigo,data1,data2) + df= consultaCabecarioAnexoDois(codigo,data1,data2) + + tabela = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title="ANEXO II") + workbook.save(tabela) + workbook.close() + + + #carregar a tabela + + tamanho = consultaAnexoDois(codigo,data1,data2) + tamanho = len(tamanho) + + brasiliaRow = estiloAnexoDois(tabela,tamanho) + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + sheet = workbook['ANEXO II'] + input_date = [] + output_date_str = [] + input_date2 = [] + output_date_str2 = [] + if check_format(data1): + input_date = datetime.strptime(data1, "%Y-%m-%d") + # Format the datetime object to a string in dd/mm/yyyy format + output_date_str = input_date.strftime("%d/%m/%Y") + else : + return None + if check_format(data2): + input_date2 = datetime.strptime(data2, "%Y-%m-%d") + # Format the datetime object to a string in dd/mm/yyyy format + output_date_str2 = input_date2.strftime("%d/%m/%Y") + else : + return None + + + + + consulta_coordenador = consultaID(codigo) + stringCoordenador= f'E{brasiliaRow+2}' # retorna lugar do coordanor + stringCoordanadorCargo = f'E{brasiliaRow+3}' + sheet[stringCoordanadorCargo] = f"Coordenador(a)" + stringTamanhoCPF = f'E{brasiliaRow+4}' # retorna lugar do coordanor + sheet[stringCoordenador] = consulta_coordenador['NomePessoaResponsavel'] + sheet[stringTamanhoCPF] = formatar_cpf(consulta_coordenador['CPFCoordenador']) + string_titulo = f"Título do Projeto: {consulta_coordenador['NomeConvenio']}" + string_executora = f"Instituição Executora: {consulta_coordenador['NomePessoa']}" + + #string toa + stringTOA = f"{consulta_coordenador['SubProcesso']} / {consulta_coordenador['Processo']}" + + # Convert 'DataAssinatura' to "dd/mm/YYYY" format + datetime_obj1 = consulta_coordenador['DataAssinatura'] + + if datetime_obj1 is not None: + formatted_date1 = datetime_obj1.strftime("%d/%m/%Y") + + # Convert 'DataVigencia' to "dd/mm/YYYY" format + datetime_obj2 = consulta_coordenador['DataVigencia'] + + if datetime_obj2 is not None: + formatted_date2 = datetime_obj2.strftime("%d/%m/%Y") +# # Convert 'DataAssinatura' to "dd/mm/YYYY" format +# datetime_obj1 = consulta_coordenador['DataAssinatura'] + +# if datetime_obj1 is not None: +# formatted_date1 = datetime_obj1.strftime("%d/%m/%Y") + +# # Convert 'DataVigencia' to "dd/mm/YYYY" format +# datetime_obj2 = consulta_coordenador['DataVigencia'] + +# if datetime_obj2 is not None: +# formatted_date2 = datetime_obj2.strftime("%d/%m/%Y") + +# Create the string representing the period of execution + + sheet['A6'] = string_titulo + sheet['A8'] = string_executora + sheet['I3'] = stringTOA + + #dadosquefaltam = getAnalistaDoProjetoECpfCoordenador(codigo) + #sheet['H47'] = formatar_cpf(dadosquefaltam["CPF_COORDENADOR"]) + meses_dict = { + 1: "Janeiro", + 2: "Fevereiro", + 3: "Março", + 4: "Abril", + 5: "Maio", + 6: "Junho", + 7: "Julho", + 8: "Agosto", + 9: "Setembro", + 10: "Outubro", + 11: "Novembro", + 12: "Dezembro" +} + + stringTamanhoBrasilia = f'A{brasiliaRow}' # retorna lugar de brasilia + hoje = date.today() + data_formatada = f"{hoje.day} de {meses_dict[hoje.month]} de {hoje.year}" + sheet[stringTamanhoBrasilia] = f'Brasilia, {data_formatada}' + + dfAnexoDois = consultaAnexoDois(codigo,data1,data2) + + dfAnexoDois.insert(6, "col1", 1) + + + + + for row_num, row_data in enumerate(dfAnexoDois.itertuples(), start=11): #inicio linha + for col_num, value in enumerate(row_data, start=1): #inicio coluna + value = convert_datetime_to_stringdt(value) + sheet.cell(row=row_num, column=col_num, value=value) + + + + + + workbook.save(tabela) + workbook.close() + + + return brasiliaRow + +def anexoTres(tabela,codigo,data1,data2,rowBrasilia): + tabela = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title="ANEXO III") + workbook.save(tabela) + workbook.close() + + dfAnexoTres = consultaAnexoTres(codigo,data1,data2) + tamanho = len(dfAnexoTres) + estiloAnexoTres(tabela,tamanho,rowBrasilia) + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + sheet = workbook['ANEXO III'] + + + + + dfAnexoTres.insert(0, "col1",None) + dfAnexoTres.insert(3, "col2",None) + dfAnexoTres.insert(5, "col3",1) + + + + + + for row_num, row_data in enumerate(dfAnexoTres.itertuples(), start=11): #inicio linha + for col_num, value in enumerate(row_data, start=1): #inicio coluna + value = convert_datetime_to_stringdt(value) + value = re.sub("[^a-zA-ZÀ-ÿ0-9º+-//]", " ", str(value)) + sheet.cell(row=row_num, column=col_num, value=value) + + + + workbook.save(tabela) + workbook.close() + +def anexoQuatro(tabela,codigo,data1,data2,rowBrasilia): + + tabela = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title="ANEXO IV") + workbook.save(tabela) + workbook.close() + + dfConsultaRendimentoAplicacao,dfConsultaImposto,dfImpostoERendimento = consultaRendimentosAplicacao(codigo,data1,data2) + merged_df = pd.merge(dfConsultaRendimentoAplicacao, dfConsultaImposto, on='DataPagamento') + tamanho = 0 + # tamanhoMaior = lambda tamanho: len(dfConsultaRendimentoAplicacao) if len(dfConsultaRendimentoAplicacao) > len(dfConsultaImposto) else len(dfConsultaImposto) + # tamanhoMaiorParaOEstilo = tamanhoMaior(None) + + tamanhoMaiorParaOEstilo = len(merged_df) + # tem q somra oito algum erro do estilo + tamanhoMaiorParaOEstilo = tamanhoMaiorParaOEstilo + 8 + estiloAnexoQuatro(tabela,tamanhoMaiorParaOEstilo,rowBrasilia) + + workbook = openpyxl.load_workbook(tabela) + sheet = workbook['ANEXO IV'] + + merged_df['data_formatada'] = merged_df['DataPagamento'].apply(formatarDataSemDia) + merged_df['DataPagamento'] = merged_df['data_formatada'] + merged_df = merged_df.drop('data_formatada', axis=1) + + + for row_num, row_data in enumerate(merged_df.itertuples(index=False), start=18):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + + if col_num == 2: + col_num = 5 + if col_num == 3: + col_num = 6 + sheet.cell(row=row_num, column=col_num, value=value) + + + #datas + + input_date = [] + output_date_str = [] + input_date2 = [] + output_date_str2 = [] + if check_format(data1): + input_date = datetime.strptime(data1, "%Y-%m-%d") + # Format the datetime object to a string in dd/mm/yyyy format + output_date_str = input_date.strftime("%d/%m/%Y") + else : + return None + if check_format(data2): + input_date2 = datetime.strptime(data2, "%Y-%m-%d") + # Format the datetime object to a string in dd/mm/yyyy format + output_date_str2 = input_date2.strftime("%d/%m/%Y") + else : + return None + + + + stringPeriodoAbrangido = f'{output_date_str} a {output_date_str2}' + + sheet['F12'] = stringPeriodoAbrangido + sheet['F12'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['F12'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + + sheet.merge_cells('F12:G12') + + + + + + + + workbook.save(tabela) + workbook.close() + +def Conciliacao(tabela,codigo,data1,data2): + + caminho = pegar_caminho(tabela) + workbook = openpyxl.load_workbook(caminho) + sheet = workbook['Conciliação '] + dfRendimentoConciliacao = consultaRendimentosIRRFConciliacao(codigo,data1,data2) + dfConciliacao = consultaConciliacao(codigo,data1,data2) + dfDevolucao = consultaDevolucaoRecursosConciliacao(codigo,data1,data2) + stringProcesso = dfConciliacao['Processo'] + stringValorAprovado = dfConciliacao['ValorAprovado'] + stringSubProcesso = dfConciliacao['SubProcesso'] + stringCoordenador = dfConciliacao['NomePessoaResponsavel'] + stringDevolucaoTotal = dfDevolucao['TotalPago'] + stringRendApli= dfRendimentoConciliacao.loc[dfRendimentoConciliacao['NomeTipoLancamento'] == 'Aplicação Financeira', 'Aplicação'].values[0] + + + cell_is_null = dfDevolucao.isnull().iloc[0, 0] + + + + + #toa + sheet['D5'] = f'{stringSubProcesso.to_string(index=False)} / {stringProcesso.to_string(index=False)}' + sheet['D5'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['D5'].alignment = Alignment(horizontal="left",vertical="center",wrap_text=True) + + + #valorparovado + if not stringValorAprovado.empty: + sheet['B15'] = int(stringValorAprovado.iloc[0]) + + else: + sheet['B15'] = 0 + + sheet['B15'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['B15'].alignment = Alignment(horizontal="right",vertical="center",wrap_text=True) + #rendimento + sheet['B21'] = stringRendApli + sheet['B21'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['B21'].alignment = Alignment(horizontal="right",vertical="center",wrap_text=True) + sheet['B21'].number_format = 'R$ #,##0.00' + #devolução + if not cell_is_null: + sheet['D19'] = int(stringDevolucaoTotal.iloc[0]) + + else: + sheet['D19'] = 0 + + sheet['D19'].font = Font(name="Arial", size=12, color="000000",bold=True) + sheet['D19'].alignment = Alignment(horizontal="right",vertical="center",wrap_text=True) + sheet['D19'].number_format = 'R$ #,##0.00' + #COORDENADOR + sheet['C48'] = stringCoordenador.to_string(index=False) + sheet['C48'].font = Font(name="Arial", size=12, color="000000") + sheet['C48'].alignment = Alignment(horizontal="center",vertical="center",wrap_text=True) + sheet['C48'].number_format = 'R$ #,##0.00' + + + for row in sheet.iter_rows(min_row=12, max_row=24, min_col=1, max_col=4): + for cell in row: + cell.number_format = 'R$ #,##0.00' + + workbook.save(tabela) + workbook.close() + +def preencheFap(codigo,data1,data2,tabela): + '''Preenche a planilha fap + + Argumentos: + codigo = CodConvenio na tabela nova, corresponde ao codigo do projeto + DATA1 = Data Inicial Selecinado pelo Usuario + DATA2 = Data Final Selecionado pelo Usuario + tabela = tabela a ser preenchida extensão xlsx + + + ''' + planilhaGeral(tabela,codigo,data1,data2) + rowBrasilia = anexoDois(tabela,codigo,data1,data2) + anexoUm(tabela,codigo,data1,data2) + anexoTres(tabela,codigo,data1,data2,rowBrasilia) + anexoQuatro(tabela,codigo,data1,data2,rowBrasilia) + Conciliacao(tabela,codigo,data1,data2) + + + + diff --git a/project/app/preencheFub.py b/project/app/preencheFub.py index 46f6956e..edb388da 100644 --- a/project/app/preencheFub.py +++ b/project/app/preencheFub.py @@ -8,6 +8,8 @@ import pandas as pd from sqlalchemy import create_engine from sqlalchemy.engine import URL +import numpy as np +import re def convert_datetime_to_string(value): if isinstance(value, datetime): @@ -102,6 +104,7 @@ def pegar_pass(chave): # return records + #todas as consultas em sql def consultaRendimentosTodosAteOPeriodo(IDPROJETO,DATA2): file_path = pegar_pass("passs.txt") @@ -222,6 +225,7 @@ def consultaConciliacaoBancaria(IDPROJETO, DATA1, DATA2): connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) parametros = [(IDPROJETO, DATA1, DATA2)] + parametros2 = [(IDPROJETO, DATA1, DATA2, IDPROJETO, DATA1, DATA2)] #consultaSemEstorno = f"SELECT DISTINCT DataPagamento,ValorPago,NumChequeDeposito,HisLancamento FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 9 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) NOT LIKE '%estorno%' order by DataPagamento" #consultaComEstorno = f"SELECT DISTINCT DataPagamento,ValorPago,NumChequeDeposito,HisLancamento FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 9 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) LIKE '%estorno%' order by DataPagamento" @@ -238,25 +242,104 @@ def consultaConciliacaoBancaria(IDPROJETO, DATA1, DATA2): WHERE [LisLancamentoConvenio].CodConvenio = ? AND [LisLancamentoConvenio].CodStatus = 27 AND [LisLancamentoConvenio].CodRubrica = 9 AND [LisLancamentoConvenio].DataPagamento BETWEEN ? AND ? AND LOWER([LisLancamentoConvenio].HisLancamento) NOT LIKE '%estorno%' order by [LisLancamentoConvenio].DataPagamento""" - consultaComEstorno = f""" - SELECT [LisLancamentoConvenio].DataPagamento, - [LisPagamentoDespesaConvenioAdministrativa].Valor , - [LisLancamentoConvenio].NumChequeDeposito,[LisLancamentoConvenio].HisLancamento - FROM [Conveniar].[dbo].[LisLancamentoConvenio] - INNER JOIN [Conveniar].[dbo].[LisDocumentoConvenio] ON [LisLancamentoConvenio].[CodDocFinConvenio] = [LisDocumentoConvenio].[CodDocFinConvenio] - INNER JOIN [Conveniar].[dbo].[DocFinConvPagDespesa] ON [LisDocumentoConvenio].[CodDocFinConvenio] = [DocFinConvPagDespesa].[CodDocFinConvenio] - INNER JOIN [Conveniar].[dbo].[LisPagamentoDespesaConvenio] ON [DocFinConvPagDespesa].[CodPedido] = [LisPagamentoDespesaConvenio].[CodPedido] - INNER JOIN [Conveniar].[dbo].[LisPagamentoDespesaConvenioAdministrativa] ON [LisPagamentoDespesaConvenio].CodDespesaConvenio = [LisPagamentoDespesaConvenioAdministrativa].CodDespesaConvenio - AND [LisPagamentoDespesaConvenio].CodConvenio = [LisPagamentoDespesaConvenioAdministrativa].CodConvenio - WHERE [LisLancamentoConvenio].CodConvenio = ? AND [LisLancamentoConvenio].CodStatus = 27 AND [LisLancamentoConvenio].CodRubrica = 9 AND [LisLancamentoConvenio].DataPagamento BETWEEN ? AND ? - AND LOWER([LisLancamentoConvenio].HisLancamento) LIKE '%estorno%' order by [LisLancamentoConvenio].DataPagamento""" + consultaComEstorno = f"""SELECT DataPagamento, + ValorPago, + NumChequeDeposito, + HisLancamento + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) LIKE '%estorno%' + OR + CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND NomeTipoCreditoDebito = 'C' + AND DataPagamento BETWEEN ? AND ? + order by DataPagamento""" dfSemEstorno = pd.read_sql(consultaSemEstorno, engine, params=parametros) - dfComEstorno = pd.read_sql(consultaComEstorno, engine, params=parametros) + dfComEstorno = pd.read_sql(consultaComEstorno, engine, params=parametros2) return dfSemEstorno,dfComEstorno +def consultaConciliaoBancarioSaldoTotal(IDPROJETO,DATA1,DATA2): + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + parametrosconsultaSumTotal = [(IDPROJETO, DATA1)] + parametrosConsultaTotalRestituicao = [(IDPROJETO, DATA1,IDPROJETO, DATA1)] + parametrossumPeriodosemEstorno = [(IDPROJETO, DATA1, DATA2, IDPROJETO, DATA1, DATA2)] + parametrossumPeriodoComEstorno = [(IDPROJETO, DATA1, DATA2, IDPROJETO, DATA1, DATA2)] + + SumTotal= f"""SELECT SUM(ValorPago) AS TotalPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND DataPagamento <= ? + AND LOWER(HisLancamento) NOT LIKE '%estorno%' + """ + + SumTotalRestituicao = f"""SELECT SUM(ValorPago) AS TotalPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND DataPagamento <=? + AND LOWER(HisLancamento) LIKE '%estorno%' + OR + CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND NomeTipoCreditoDebito = 'C' + AND DataPagamento <= ? """ + + + sumPeriodoSemEstorno = f"""SELECT SUM(ValorPago) AS TotalPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) NOT LIKE '%estorno%' + OR + CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND NomeTipoCreditoDebito = 'D' + AND DataPagamento BETWEEN ? AND ? """ + + sumPeriodoComEstorno = f"""SELECT SUM(ValorPago) AS TotalPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) LIKE '%estorno%' + OR + CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND NomeTipoCreditoDebito = 'C' + AND DataPagamento BETWEEN ? AND ? """ + + + + consultaSaldoTotal= pd.read_sql(SumTotal, engine, params=parametrosconsultaSumTotal) + consultaSumTotalRestituicao= pd.read_sql(SumTotalRestituicao, engine, params=parametrosConsultaTotalRestituicao) + consultasumPeriodoSemEstorno= pd.read_sql(sumPeriodoSemEstorno, engine, params=parametrossumPeriodosemEstorno) + consultasumPeriodoComEstorno= pd.read_sql(sumPeriodoComEstorno, engine, params=parametrossumPeriodoComEstorno) + + return consultaSaldoTotal,consultaSumTotalRestituicao,consultasumPeriodoSemEstorno,consultasumPeriodoComEstorno + def consultaID(IDPROJETO): #file_path = "/home/ubuntu/Desktop/devfront/devfull/pass.txt" @@ -342,13 +425,106 @@ def consultaProjeto(IDPROJETO, DATA1, DATA2,codigoRubrica): connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) parametros = [(IDPROJETO, DATA1, DATA2,codigoRubrica)] - queryConsultaComRubrica = f"SELECT NomeFavorecido,FavorecidoCPFCNPJ,NomeTipoLancamento,HisLancamento,NumDocPago,DataEmissao,NumChequeDeposito,DataPagamento, ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) NOT LIKE '%estorno%' and CodRubrica = ? " - queryConsultaComRubricaEstorno = f"SELECT NomeFavorecido,FavorecidoCPFCNPJ,NomeTipoLancamento,HisLancamento,NumDocPago,DataEmissao,NumChequeDeposito,DataPagamento, ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) LIKE '%estorno%' and CodRubrica = ? " + parametrosComRubricaEstorno = [(IDPROJETO, DATA1, DATA2,codigoRubrica,IDPROJETO,DATA1, DATA2,codigoRubrica,)] + parametrosPJ=[(IDPROJETO, DATA1, DATA2)] + parametrosPJestorno=[(IDPROJETO, DATA1, DATA2,IDPROJETO, DATA1, DATA2)] + queryConsultaComRubrica = f"""SELECT NomeFavorecido, + CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + [LisConvenioItemAprovado].[DescConvenioItemAprovado], + HisLancamento, + NumDocPago, + DataEmissao, + NumChequeDeposito, + DataPagamento, + ValorPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE [LisLancamentoConvenio].CodConvenio = ? + AND [LisLancamentoConvenio].CodStatus = 27 + AND [LisLancamentoConvenio].DataPagamento BETWEEN ? AND ? + AND LOWER([LisLancamentoConvenio].HisLancamento) NOT LIKE '%estorno%' + and [LisLancamentoConvenio].CodRubrica = ? order by DataPagamento""" + + queryConsultaComRubricaEstorno = f"""SELECT NomeFavorecido + ,CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + HisLancamento, + NumChequeDeposito, + DataPagamento, + ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE + [LisLancamentoConvenio].CodConvenio = ? + AND CodStatus = 27 + AND NomeTipoCreditoDebito = 'C' + AND DataPagamento BETWEEN ? AND ? + and [LisLancamentoConvenio].CodRubrica = ? + OR + CodStatus = 27 + AND [LisLancamentoConvenio].CodConvenio = ? + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) LIKE '%estorno%' + AND [LisLancamentoConvenio].CodRubrica = ? + + order by DataPagamento """ + + queryConsultaPJDOA = f"""SELECT NomeFavorecido, + CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + [LisConvenioItemAprovado].[DescConvenioItemAprovado], + HisLancamento, + NumDocPago, + DataEmissao, + NumChequeDeposito, + DataPagamento, + ValorPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE [LisLancamentoConvenio].CodConvenio = ? + AND CodStatus = 27 + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) NOT LIKE '%estorno%' + AND [LisLancamentoConvenio].CodRubrica IN (57,75,26) + order by DataPagamento """ + + queryConsultaPJDOAEstorno = f""" + SELECT NomeFavorecido, + CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + HisLancamento, + NumChequeDeposito, + DataPagamento, + ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] + + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE + [LisLancamentoConvenio].CodConvenio = ? + AND CodStatus = 27 + AND DataPagamento BETWEEN ? AND ? + AND [LisLancamentoConvenio].CodRubrica IN (57,75,26) + AND NomeTipoCreditoDebito = 'C' + OR CodStatus = 27 + AND [LisLancamentoConvenio].CodConvenio = ? + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) LIKE '%estorno%' + AND [LisLancamentoConvenio].CodRubrica IN (57,75,26) + order by DataPagamento + """ dfconsultaDadosPorRubrica = pd.read_sql(queryConsultaComRubrica, engine, params=parametros) - dfconsultaDadosPorRubricaComEstorno = pd.read_sql(queryConsultaComRubricaEstorno,engine, params=parametros) - - - return dfconsultaDadosPorRubrica,dfconsultaDadosPorRubricaComEstorno + # queryConsultaComRubricaEstorno = f"SELECT NomeFavorecido,CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ,HisLancamento,NumChequeDeposito,DataPagamento, ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) LIKE '%estorno%' and CodRubrica = ? order by DataPagamento " + # queryConsultaPJDOA = f"SELECT NomeFavorecido,CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ,NomeTipoLancamento,HisLancamento,NumDocPago,DataEmissao,NumChequeDeposito,DataPagamento, ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) NOT LIKE '%estorno%' AND CodRubrica IN (57,75,26) order by DataPagamento " + # queryConsultaPJDOAEstorno = f"SELECT NomeFavorecido,CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ,HisLancamento,NumChequeDeposito,DataPagamento, ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) LIKE '%estorno%' AND CodRubrica IN (57,75,26) order by DataPagamento " + # dfconsultaDadosPorRubrica = pd.read_sql(queryConsultaComRubrica, engine, params=parametros) + dfconsultaDadosPorRubricaComEstorno = pd.read_sql(queryConsultaComRubricaEstorno,engine, params=parametrosComRubricaEstorno) + dfPJDOA = pd.read_sql(queryConsultaPJDOA, engine, params=parametrosPJ) + dfPJDOAESTORNO = pd.read_sql(queryConsultaPJDOAEstorno,engine, params=parametrosPJestorno) + + return dfPJDOA,dfPJDOAESTORNO,dfconsultaDadosPorRubrica,dfconsultaDadosPorRubricaComEstorno def consultaEntradaReceitas(IDPROJETO, DATA1, DATA2): @@ -360,16 +536,42 @@ def consultaEntradaReceitas(IDPROJETO, DATA1, DATA2): connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) parametros = [(IDPROJETO, DATA1, DATA2,)] - consultaEntradaReceita = f"SELECT DataPagamento,NumChequeDeposito,NomeFavorecido,ValorPago,CodRubrica FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND (CodRubrica = 2 OR CodRubrica = 67 OR CodRubrica = 88) AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? ORDER BY CodDocFinConvenio,CodRubrica" - consultaDemonstrativoReceita = f"SELECT NomeFavorecido,HisLancamento,NumChequeDeposito,DataPagamento,ValorPago,CodRubrica FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND (CodRubrica = 2 OR CodRubrica = 67 OR CodRubrica = 88) AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? ORDER BY DataPagamento,NumChequeDeposito" + consultaEntradaReceita = f"""SELECT DataPagamento, + NumChequeDeposito + ,NomeFavorecido, + ValorPago, + CodRubrica FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND (CodRubrica = 2 OR CodRubrica = 67 OR CodRubrica = 88) AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? + ORDER BY DataPagamento,CodDocFinConvenio,CodRubrica""" + consultaDemonstrativoReceita = f"""SELECT NomeFavorecido, + HisLancamento, + NumChequeDeposito, + DataPagamento, + ValorPago, + CodRubrica FROM [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE CodConvenio = ? AND (CodRubrica = 2 OR CodRubrica = 67 OR CodRubrica = 88) AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? ORDER BY DataPagamento,NumChequeDeposito""" + consultaSomaTotal2_6788 = f""" + SELECT + SUM(CASE WHEN CodRubrica = 88 THEN ValorPago ELSE 0 END) AS Sum_88, + SUM(CASE WHEN CodRubrica = 67 THEN ValorPago ELSE 0 END) AS Sum_67, + SUM(CASE WHEN CodRubrica = 2 THEN ValorPago ELSE 0 END) AS Sum_2 + FROM + [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE + CodConvenio = ? + AND CodStatus = 27 + AND DataPagamento BETWEEN ? AND ? + """ dfReceitas = pd.read_sql(consultaEntradaReceita, engine, params=parametros) dfDemonstrativoReceitas = pd.read_sql(consultaDemonstrativoReceita, engine, params=parametros) - + dfSomaTotal = pd.read_sql(consultaSomaTotal2_6788, engine, params=parametros)#88% É ISS2% + #88% É ISS2% + #67 É ISS2% + #2 E ENTRADA DE RECEITA - return dfReceitas,dfDemonstrativoReceitas + return dfReceitas,dfDemonstrativoReceitas,dfSomaTotal def consultaReceitaEExecReceita(IDPROJETO, DATA1, DATA2): ''' Função que vai pega os dados da Rubrica 9 Despesas Financeiras e transformalos em dataframe @@ -418,12 +620,51 @@ def consultaBens(IDPROJETO,DATA1,DATA2): idprojetoComZero = f"0{IDPROJETO}" parametros = [(IDPROJETO,idprojetoComZero, DATA1, DATA2)] - queryConsultaComRubrica = f"SELECT [Descrição][descri],[Patrimônio][patri],[Data de Aquisição][dataAqui],[Nº Nota][nota],[Localização][localiza],[telefone],[Valor de Aquisição][valorAqui],[Valor de Aquisição][valorAqui2],[Responsável][responsavel] FROM [SBO_FINATEC].[dbo].[VW_BENS_ADQUIRIDOS] WHERE ([Cod Projeto] = ? or [Cod Projeto] = ? ) AND [Status] = 'Imobilizado' AND [Data de Aquisição] BETWEEN ? AND ? Order by [Data de Aquisição]" + queryConsultaComRubrica = f"SELECT [Descrição][descri],[Patrimônio][patri],CONVERT(varchar, [Data de Aquisição], 103) AS dataAqui,[Nº Nota][nota],[Localização][localiza],[telefone],[Valor de Aquisição][valorAqui],[Valor de Aquisição][valorAqui2],[Responsável][responsavel] FROM [SBO_FINATEC].[dbo].[VW_BENS_ADQUIRIDOS] WHERE ([Cod Projeto] = ? or [Cod Projeto] = ? ) AND [Status] = 'Imobilizado' AND [Data de Aquisição] BETWEEN ? AND ? Order by [Data de Aquisição]" dfConsultaBens = pd.read_sql(queryConsultaComRubrica, engine, params=parametros) return dfConsultaBens - + +def consultaTabelaGigante(IDPROJETO,DATA1,DATA2): + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + parametros = [(IDPROJETO,DATA1,DATA2)] + queryAnexoDois = f""" + SELECT + NumDocFinConvenio, + NomeTipoPedido, + HisLancamento, + NomeRubrica, + ValorLancamento, + NomeTipoCreditoDebito, + DataCriacao, + DataVencimento, + DataPagamento, + ValorPago, + NumChequeDeposito, + NumDocBancario, + DataEmissao, + NumDocPago, + CodConvenio, + NomeConvenio, + AgenciaBancaria, + ContaBancaria, + NomeFavorecido, + FavorecidoCPFCNPJ, + NomePessoaGestor, + NomeTipoPedido, + NomeStatus + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE [LisLancamentoConvenio].CodConvenio = ? AND [LisLancamentoConvenio].CodStatus = 27 + AND [LisLancamentoConvenio].DataPagamento BETWEEN ? AND ? and [LisLancamentoConvenio].CodRubrica not in (2,0) order by DataPagamento""" + dfConvenioAnexoDois = pd.read_sql(queryAnexoDois, engine, params=parametros) + return dfConvenioAnexoDois #preenche planilha def conciliacaoBancaria(codigo,data1,data2,planilha,stringTamanho): @@ -473,20 +714,31 @@ def conciliacaoBancaria(codigo,data1,data2,planilha,stringTamanho): #for row in worksheet333.iter_rows(min_row=16, max_row=tamanho, min_col=1, max_col=4): - # Write data starting from the first row - for row_num, row_data in enumerate(dataframeSemEstorno.itertuples(index=False), start=16):#inicio linha + + for row_num, row_data in enumerate(dataframeSemEstorno.itertuples(index=False), start=17):#inicio linha for col_num, value in enumerate(row_data, start=1):#inicio coluna worksheet333.cell(row=row_num, column=col_num, value=value) - linha2 = 16+4+tamanho + linha2 = 17+4+tamanho+1 for row_num, row_data in enumerate(dataframeComEstorno.itertuples(index=False), start=linha2):#inicio linha for col_num, value in enumerate(row_data, start=1):#inicio coluna worksheet333.cell(row=row_num, column=col_num, value=value) - + #saldo anterior + + consultaSaldoTotal,consultaSumTotalRestituicao,consultasumPeriodoSemEstorno,consultasumPeriodoComEstorno= consultaConciliaoBancarioSaldoTotal(codigo,data1,data2) + + a = consultaSaldoTotal.iloc[0].item() + b = consultaSumTotalRestituicao.iloc[0].item() + + + worksheet333['B16'] = a + worksheet333[f'B{linha2-1}'] = b + + workb.save(tabela) workb.close @@ -540,6 +792,7 @@ def relacaodeBens(codigo,data1,data2,planilha,rowBrasilia): sheet = workbook['Relação de Bens'] for row_num, row_data in enumerate(dfBens.itertuples(), start=13):#inicio linha for col_num, value in enumerate(row_data, start=1):#inicio coluna + value = re.sub("[^a-zA-ZÀ-ÿ0-9º+-//]", " ", str(value)) value = convert_datetime_to_stringdt(value) if col_num == 7: value = 1 @@ -570,8 +823,11 @@ def rendimentoDeAplicacao(codigo,data1,data2,planilha,rowBrasilia): merged_df['data_formatada'] = merged_df['DataPagamento'].apply(formatarDataSemDia) merged_df['DataPagamento'] = merged_df['data_formatada'] merged_df = merged_df.drop('data_formatada', axis=1) + - for row_num, row_data in enumerate(merged_df.itertuples(index=False), start=14):#inicio linha + + + for row_num, row_data in enumerate(merged_df.itertuples(index=False), start=15):#inicio linha for col_num, value in enumerate(row_data, start=1):#inicio coluna if col_num == 2: col_num = 5 @@ -582,20 +838,28 @@ def rendimentoDeAplicacao(codigo,data1,data2,planilha,rowBrasilia): workbook.save(tabela) workbook.close() - return (len(merged_df))+14 + return (len(merged_df))+15 def rubricaGeral(codigo,data1,data2,planilha,rowBrasilia): #consulta todas rubricas tabela = pegar_caminho(planilha) dfNomeRubricaCodigoRubrica = consultaNomeRubricaCodRubrica(codigo, data1, data2) - + + for index, values in dfNomeRubricaCodigoRubrica.iterrows(): + + dfPJDOA,dfPJDOAESTORNO,dfConsultaProjeto ,dfconsultaDadosPorRubricaComEstorno= consultaProjeto(codigo, data1, data2,values['CodRubrica']) - dfConsultaProjeto ,dfconsultaDadosPorRubricaComEstorno= consultaProjeto(codigo, data1, data2,values['CodRubrica']) - + #remove as rubricas nao desejadas + # values_to_remove = ["Receitas", "Rendimentos de Aplicações Financeiras", "Despesas Financeiras",'Devolução de Recursos','Outros Serviços de Terceiros - Pessoa Jurídica ','Despesas Operacionais e Administrativas - Finatec'] + # dfConsultaProjeto = dfConsultaProjeto[~dfConsultaProjeto['NomeRubrica'].isin(values_to_remove)] + # dfconsultaDadosPorRubricaComEstorno = dfconsultaDadosPorRubricaComEstorno[~dfconsultaDadosPorRubricaComEstorno['NomeRubrica'].isin(values_to_remove)] + if values['NomeRubrica'] == "Obrigações Tributárias e contributivas": values['NomeRubrica'] = "Obrigações Tributárias" + if values['NomeRubrica'] == "Material Permanente e Equipamento Nacional": + values['NomeRubrica'] = "Equipamento Material Nacional" if values['NomeRubrica'] == "Serviços de Terceiros Pessoa Física": values['NomeRubrica'] = "Serviços de Terceiros PF" if values['NomeRubrica'] == f"Obrigações Tributárias e Contributivas - 20% de OST " : @@ -616,10 +880,14 @@ def rubricaGeral(codigo,data1,data2,planilha,rowBrasilia): values['NomeRubrica'] = f"AuxFinanceiro Pesquisador" if values['NomeRubrica'] == f"Equipamentos e Material Permanente" : values['NomeRubrica'] = f"Equip e Mat Permanente" - + if values['NomeRubrica'] == f"Material Permanente e Equipamento Importado" : + values['NomeRubrica'] = f"Equipamento Material Importado" - - if values['NomeRubrica'] != "Rendimentos de Aplicações Financeiras" and values['NomeRubrica'] != "Despesas Financeiras" and values['NomeRubrica'] != "Receitas" and ['NomeRubrica'] != "Devolução de Recursos": + + + + if values['NomeRubrica'] == "Outros Serviços Terceiros - PJ" or values['NomeRubrica'] == "Serviços de Terceiros Pessoa Jurídica": + values['NomeRubrica'] = "Outros Serviços Terceiros -PJ" nomeTabela = values['NomeRubrica'] tituloStyle = values['NomeRubrica'] workbook = openpyxl.load_workbook(tabela) @@ -627,28 +895,83 @@ def rubricaGeral(codigo,data1,data2,planilha,rowBrasilia): workbook.save(tabela) workbook.close() - tamanho = len(dfConsultaProjeto) - tamanhoRetorno = len(dfconsultaDadosPorRubricaComEstorno) - # print(f'tamanhoRetorno{tamanhoRetorno}') - rowEstorno = estiloGeral(tabela,tamanho,tituloStyle,nomeTabela,rowBrasilia,tamanhoRetorno) + tamanho = len(dfPJDOA) + tamanhoRetorno = len(dfPJDOAESTORNO) + + rownovo = estiloGeral(tabela,tamanho,tituloStyle,nomeTabela,rowBrasilia,tamanhoRetorno) workbook = openpyxl.load_workbook(tabela) sheet2 = workbook[values['NomeRubrica']] - dfConsultaProjeto.index = dfConsultaProjeto.index + 1 - for row_num, row_data in enumerate(dfConsultaProjeto.itertuples(), start=10):#inicio linha + dfPJDOA.index = dfPJDOA.index + 1 + for row_num, row_data in enumerate(dfPJDOA.itertuples(), start=10):#inicio linha for col_num, value in enumerate(row_data, start=1):#inicio coluna value = convert_datetime_to_stringdt(value) sheet2.cell(row=row_num, column=col_num, value=value) - dfconsultaDadosPorRubricaComEstorno.index = dfconsultaDadosPorRubricaComEstorno.index + 1 - for row_num, rowEstorno in enumerate(dfconsultaDadosPorRubricaComEstorno.itertuples(), start=10): #inicio linha - for col_num, value in enumerate(rowEstorno, start=1): #inicio coluna - if col_num == 4: + + dfPJDOAESTORNO.insert(0, "col1", None) + dfPJDOAESTORNO.insert(4, 'Col2', None) + dfPJDOAESTORNO.insert(4, 'Col3', None) + dfPJDOAESTORNO.insert(5, 'Col4', None) + + + rownovo = rownovo + 1 + for row_num, row_data in enumerate(dfPJDOAESTORNO.itertuples(index=False), start=rownovo): #inicio linha + for col_num, value in enumerate(row_data, start=1): #inicio coluna + if col_num == 5: continue value = convert_datetime_to_stringdt(value) sheet2.cell(row=row_num, column=col_num, value=value) workbook.save(tabela) workbook.close() + + + else: + + if values['NomeRubrica'] != "Rendimentos de Aplicações Financeiras" and values['NomeRubrica'] != "Despesas Financeiras" and values['NomeRubrica'] != "Receitas" and values['NomeRubrica'] != "Devolução de Recursos" and values['NomeRubrica'] != "Outros Serviços Terceiros - PJ"and values['NomeRubrica'] != "Despesas Operacionais": + nomeTabela = values['NomeRubrica'] + tituloStyle = values['NomeRubrica'] + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title=f"{values['NomeRubrica']}") + workbook.save(tabela) + workbook.close() + + tamanho = len(dfConsultaProjeto) + tamanhoRetorno = len(dfconsultaDadosPorRubricaComEstorno) + + + + rowEstorno = estiloGeral(tabela,tamanho,tituloStyle,nomeTabela,rowBrasilia,tamanhoRetorno) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook[values['NomeRubrica']] + dfConsultaProjeto.index = dfConsultaProjeto.index + 1 + for row_num, row_data in enumerate(dfConsultaProjeto.itertuples(), start=10):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + # dfconsultaDadosPorRubricaComEstorno.index = dfconsultaDadosPorRubricaComEstorno.index + 1 + rowEstorno = rowEstorno + 1 + # + tamanhoDf = len(dfconsultaDadosPorRubricaComEstorno) + dfconsultaDadosPorRubricaComEstorno.insert(0, "col1", None) + dfconsultaDadosPorRubricaComEstorno.insert(4, 'Col2', None) + dfconsultaDadosPorRubricaComEstorno.insert(4, 'Col3', None) + dfconsultaDadosPorRubricaComEstorno.insert(5, 'Col4', None) + + + + + for row_num, row_data in enumerate(dfconsultaDadosPorRubricaComEstorno.itertuples(index=False), start=rowEstorno): #inicio linha + for col_num, value in enumerate(row_data, start=1): #inicio coluna + + if col_num == 5: + continue + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + workbook.save(tabela) + workbook.close() @@ -658,9 +981,10 @@ def rubricaGeral(codigo,data1,data2,planilha,rowBrasilia): def Receita(planilha,codigo,data1,data2,tamanhoResumo,dataframe): #dfReceitas,dfDemonstrativoReceitas,dfIss2,dfIss5 = consultaEntradaReceitas(codigo,data1,data2) - dfReceitas,dfDemonstrativoReceitas = consultaEntradaReceitas(codigo,data1,data2) + dfReceitas,dfDemonstrativoReceitas,dfSomaTotal = consultaEntradaReceitas(codigo,data1,data2) - if len(dfReceitas) > tamanhoResumo: + + if len(dfReceitas) > tamanhoResumo and len(dfReceitas) < 15: tamanhoResumo = len(dfReceitas) elif len(dataframe) > tamanhoResumo: tamanhoResumo = len(dataframe) @@ -669,6 +993,8 @@ def Receita(planilha,codigo,data1,data2,tamanhoResumo,dataframe): caminho = pegar_caminho(planilha) #tamanho equipamento ja e valido pois recebeu o tamanho maior e retornou o tamanho equipamentos da string tamanho,tamanhoequipamentos = estiloReceitaXDespesa(caminho,tamanhoResumo) + + #o tamanho na verdade tem que ser do data frame se ele for maior @@ -778,53 +1104,126 @@ def Receita(planilha,codigo,data1,data2,tamanhoResumo,dataframe): sheet[stringObras] = dataframe.loc[dataframe['NomeRubrica'] == 'Material Permanente e Equipamento Importado', 'VALOR_TOTAL_PERIODO'].values[0] - + #remove as rubricas nao desejadas values_to_remove = ["Receitas", "Rendimentos de Aplicações Financeiras", "Despesas Financeiras",'Material Permanente e Equipamento Nacional','Material Permanente e Equipamento Importado','Equipamentos e Material Permanente','Devolução de Recursos','Encargos - ISS 5% '] dataframe = dataframe[~dataframe['NomeRubrica'].isin(values_to_remove)] + + + string_exists = dataframe['NomeRubrica'].isin(["Despesas Operacionais e Administrativas - Finatec"]).any() + if string_exists: + # Extract the value from "Despesas Operacionais e Administrativas - Finatec" + value_to_add = dataframe.loc[dataframe['NomeRubrica'] == 'Despesas Operacionais e Administrativas - Finatec'].iloc[0] + + string_exists = dataframe['NomeRubrica'].isin(["Outros Serviços de Terceiros - Pessoa Jurídica "]).any() + string_exists2 = dataframe['NomeRubrica'].isin(["Serviços de Terceiros Pessoa Jurídica"]).any() + if string_exists or string_exists2: + if string_exists: + # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + index_to_update = dataframe.loc[dataframe['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica '].index[0] + + + # Add the value to "Outros Serviços de Terceiros - Pessoa Jurídica" + dataframe.loc[dataframe['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica '] += value_to_add + + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dataframe = dataframe[dataframe['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + if string_exists2: + # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + index_to_update = dataframe.loc[dataframe['NomeRubrica'] == 'Serviços de Terceiros Pessoa Jurídica'].index[0] + + # Add the value to "Outros Serviços de Terceiros - Pessoa Jurídica" + dataframe.loc[dataframe['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica '] += value_to_add + + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dataframe = dataframe[dataframe['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + + + + + # else: + # string_exists = dataframe['NomeRubrica'].isin(["Outros Serviços de Terceiros - Pessoa Jurídica "]).any() + # string_exists2 = dataframe['NomeRubrica'].isin(["Serviços de Terceiros Pessoa Jurídica"]).any() + # if string_exists or string_exists2: + # if string_exists: + # # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + # index_to_update = dataframe.loc[dataframe['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica '].index[0] + + + # if string_exists2: + # # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + # index_to_update = dataframe.loc[dataframe['NomeRubrica'] == 'Serviços de Terceiros Pessoa Jurídica'].index[0] + + + + + #dataframe.loc[['Outros Serviços de Terceiros - Pessoa Jurídica ']] += dataframe.loc[['Despesas Operacionais e Administrativas - Finatec']] + for row_num, row_data in enumerate(dataframe.itertuples(index = False), start=16):#inicio linha for col_num, value in enumerate(row_data, start=8):#inicio coluna sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) - - #vai preencher o lado esquerdo da tabela a parte de receita - for row_num, row_data in enumerate(dfReceitas.itertuples(index = False), start=16):#inicio linha - for col_num, value in enumerate(row_data, start=1):#inicio coluna - + if len(dfReceitas) < 15: + #vai preencher o lado esquerdo da tabela a parte de receita + for row_num, row_data in enumerate(dfReceitas.itertuples(index = False), start=16):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna - if col_num != 6: - if col_num == 4: - col_num = 5 - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) - cod_rubrica_value = row_data[4] - if col_num ==5: - kek = row_data[3] - if cod_rubrica_value == 88 or cod_rubrica_value == 67: - kek = -row_data[3] - - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(kek)) + + if col_num != 6: + if col_num == 4: + col_num = 5 + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) + cod_rubrica_value = row_data[4] + if col_num ==5: + kek = row_data[3] + if cod_rubrica_value == 88 or cod_rubrica_value == 67: + kek = -row_data[3] + + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(kek)) + + if cod_rubrica_value == 88: + if col_num == 3: + + val = f'ISS 2% {value}' + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(val)) - if cod_rubrica_value == 88: - if col_num == 3: + - val = f'ISS 2% {value}' - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(val)) + sheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='FF0000') - + elif cod_rubrica_value == 67: + if col_num == 3: + + vala = f'ISS 5% {value}' + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(vala)) - sheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='FF0000') + sheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='FF0000') + else: + sheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='0000FF') + else: + - elif cod_rubrica_value == 67: - if col_num == 3: - - vala = f'ISS 5% {value}' - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(vala)) - - sheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='FF0000') - else: - sheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='0000FF') + number_format = 'R$ #,##0.00' + # Set font and value for row 17 + sheet.cell(row=18, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='FF0000') + sheet.cell(row=18, column=5).value = f'ISS 2% R$ {dfSomaTotal["Sum_88"].values[0]}' + sheet.cell(row=18, column=5).alignment = Alignment(horizontal="right",vertical="center") + sheet.cell(row=18, column=5).number_format = number_format + + # Set font and value for row 16 + sheet.cell(row=17, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='FF0000') + sheet.cell(row=17, column=5).value = f'ISS 5% R$ {dfSomaTotal["Sum_67"].values[0]}' + sheet.cell(row=17, column=5).alignment = Alignment(horizontal="right",vertical="center") + sheet.cell(row=17, column=5).number_format = number_format + + # Set font and value for row 15 + sheet.cell(row=16, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='0000FF') + sheet.cell(row=16, column=5).value = dfSomaTotal['Sum_2'].values[0] + + + #rendimentosdeapliacação dfSoma = consultaRendimentosIRRF(codigo,data1,data2) dfcComPeriodo = consultaDevolucaoRecursos(codigo,data1,data2) @@ -842,19 +1241,45 @@ def Receita(planilha,codigo,data1,data2,tamanhoResumo,dataframe): sheet[f'A{tamanhoequipamentos + 6}'] = stringRendimento - + #tarifasbancarias + + consultaSaldoTotal,consultaSumTotalRestituicao,consultasumPeriodoSemEstorno,consultasumPeriodoComEstorno=consultaConciliaoBancarioSaldoTotal(codigo,data1,data2) + + c = consultaSaldoTotal.iloc[0].item() + + d = consultaSumTotalRestituicao.iloc[0].item() + resultEstorno = consultasumPeriodoSemEstorno.iloc[0].item() + resultSemEstorno = consultasumPeriodoComEstorno.iloc[0].item() + #checa soma total ate a data + if c == None: + c = 0 + if d == None: + d = 0 + #checa o total resituição + if resultEstorno == None: + resultEstorno = 0 + if resultSemEstorno == None: + resultSemEstorno = 0 - # # #devoluçãoderecursos - stringRendimentoValor = f'I{tamanhoequipamentos + 7}' - sheet[stringRendimentoValor] = dfcComPeriodo.iloc[0,0] + + #TTarifa Bancária - Despesa (-) + stringRendimentoValor = f'I{tamanhoequipamentos + 9}' + sheet[stringRendimentoValor] = resultEstorno + c + + + #Tarifa Bancária - Restituição (+) + stringRendimentoValor = f'I{tamanhoequipamentos + 10}' + sheet[stringRendimentoValor] = resultSemEstorno + d - - + #devoluçãoderecursos + stringRendimentoValor = f'I{tamanhoequipamentos + 7}' + sheet[stringRendimentoValor] = dfcComPeriodo.iloc[0,0] + workbook.save(planilha) workbook.close() @@ -874,6 +1299,7 @@ def ExeReceitaDespesa(planilha,codigo,data1,data2,stringTamanho): merged_df = pd.merge(dfPrevisto, dfComPeriodo, on='NomeRubrica', how='outer') dfMerged = pd.merge(merged_df,dfAteAData, on = 'NomeRubrica', how = 'outer') tamanho = len(dfMerged)#tamanho para deixar dinamico para imprimir sa rubricas + #tamanho rubrica dinamicas string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Importado"]).any() if string_exists: tamanho = tamanho - 1 @@ -886,8 +1312,16 @@ def ExeReceitaDespesa(planilha,codigo,data1,data2,stringTamanho): string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Nacional"]).any() if string_exists: tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Receitas"]).any() + if string_exists: + tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Rendimentos de Aplicações Financeiras"]).any() + if string_exists: + tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Despesas Financeiras"]).any() + if string_exists: + tamanho = tamanho - 1 - tamanho = tamanho - 3 stringTamanho = tamanho + 16 estiloExecReceitaDespesa(tabela,tamanho,stringTamanho) @@ -994,7 +1428,7 @@ def ExeReceitaDespesa(planilha,codigo,data1,data2,stringTamanho): sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Equipamentos e Material Permanente', 'VALOR_TOTAL_PERIODO'].values[0] #Ate o momento stringObras = f'G{stringTamanho + 3}' - #sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Obras e Instalações', 'VALOR_TOTAL_DATA'].values[0] + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Equipamentos e Material Permanente', 'VALOR_TOTAL_DATA'].values[0] #Materiais Equipamentos e Material nACIONAL string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Nacional"]).any() @@ -1031,8 +1465,7 @@ def ExeReceitaDespesa(planilha,codigo,data1,data2,stringTamanho): all_null = Soma.isnull().all() if all_null != True : - # print(Soma) - # print(len(Soma)) + if len(Soma) == 1: result = Soma.iloc[0] else: @@ -1048,12 +1481,93 @@ def ExeReceitaDespesa(planilha,codigo,data1,data2,stringTamanho): - #remover essas linhas da tabela values_to_remove = ["Receitas", "Rendimentos de Aplicações Financeiras", "Despesas Financeiras",'Material Permanente e Equipamento Nacional','Material Permanente e Equipamento Importado','Devolução de Recursos','Obras e Instalações','Equipamentos e Material Permanente'] + + # Use boolean indexing to drop rows based on the values in the first column dfMerged = dfMerged[~dfMerged['NomeRubrica'].isin(values_to_remove)] + + + + # string_exists = dfMerged['NomeRubrica'].isin(["Despesas Operacionais e Administrativas - Finatec"]).any() + # if string_exists: + # # Extract the row for "Despesas Operacionais e Administrativas - Finatec" + # row_to_add = dfMerged.loc[dfMerged['NomeRubrica'] == 'Despesas Operacionais e Administrativas - Finatec'].iloc[0] + + + # stringDOA_exists = dfMerged['NomeRubrica'].isin(["Despesas Operacionais e Administrativas - Finatec"]).any() + # if stringDOA_exists: + # string_exists = dfMerged['NomeRubrica'].isin(["Outros Serviços de Terceiros - Pessoa Jurídica "]).any() + # string_exists2 = dfMerged['NomeRubrica'].isin(["Serviços de Terceiros Pessoa Jurídica"]).any() + # if string_exists or string_exists2: + # if string_exists: + # # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + # index_to_update = dfMerged.loc[dfMerged['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica '].index[0] + + # # Update the values in "Outros Serviços de Terceiros - Pessoa Jurídica" row with the values from "Despesas Operacionais e Administrativas - Finatec" + # dfMerged.iloc[index_to_update] += row_to_add + + # # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + # dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + # if string_exists2: + # # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + # index_to_update = dfMerged.loc[dfMerged['NomeRubrica'] == "Serviços de Terceiros Pessoa Jurídica"].index[0] + + # # Update the values in "Outros Serviços de Terceiros - Pessoa Jurídica" row with the values from "Despesas Operacionais e Administrativas - Finatec" + # dfMerged.iloc[index_to_update] += row_to_add + + # # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + # dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + + string_exists = dfMerged['NomeRubrica'].isin(["Despesas Operacionais e Administrativas - Finatec"]).any() + if string_exists: + # Extract the value from "Despesas Operacionais e Administrativas - Finatec" + value_to_add = dfMerged.loc[dfMerged['NomeRubrica'] == 'Despesas Operacionais e Administrativas - Finatec'].iloc[0] + + string_exists = dfMerged['NomeRubrica'].isin(["Outros Serviços de Terceiros - Pessoa Jurídica "]).any() + string_exists2 = dfMerged['NomeRubrica'].isin(["Serviços de Terceiros Pessoa Jurídica"]).any() + string_exists3 = dfMerged['NomeRubrica'].isin(["Outros Serviços de Terceiros - Pessoa Jurídica"]).any() + + if string_exists or string_exists2 or string_exists3: + if string_exists: + + # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + + #index_to_update = dfMerged.loc[dfMerged['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica '].index[0] + + # Add the value to "Outros Serviços de Terceiros - Pessoa Jurídica" + + dfMerged.loc[dfMerged['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica '] += value_to_add + + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + + if string_exists2: + + # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + #index_to_update = dfMerged.loc[dfMerged['NomeRubrica'] == 'Serviços de Terceiros Pessoa Jurídica'].index[0] + + # Add the value to "Outros Serviços de Terceiros - Pessoa Jurídica" + dfMerged.loc[dfMerged['NomeRubrica'] == 'Serviços de Terceiros Pessoa Jurídica'] += value_to_add + + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + if string_exists3: + # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + + index_to_update = dfMerged.loc[dfMerged['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica'].index[0] + + # Add the value to "Outros Serviços de Terceiros - Pessoa Jurídica" + dfMerged.iloc[index_to_update] += value_to_add + + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + + + + for row_num, row_data in enumerate(dfMerged.itertuples(index = False), start=16):#inicio linha for col_num, value in enumerate(row_data, start=1):#inicio coluna if col_num == 2: @@ -1075,6 +1589,90 @@ def ExeReceitaDespesa(planilha,codigo,data1,data2,stringTamanho): workbook.close() return tamanho,dfComPeriodo +def planilhaGeral(planilha,codigo,data1,data2): + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title="PlanilhaGeral") + workbook.save(tabela) + workbook.close() + + dfconsultaDadosPorRubrica = consultaTabelaGigante(codigo,data1,data2) + + tamanho = len(dfconsultaDadosPorRubrica) + + + + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook['PlanilhaGeral'] + + #print(dfconsultaDadosPorRubrica.columns.values.tolist()) + + + linha = [ + "Nº Pedido", + "Tipo do Pedido", + "Histórico", + "Rubrica", + "Valor", + "Tipo", + "Data Lançamento", + "Data Vencimento", + "Data Pagamento", + "Valor Pago", + "Nº Autenticação Bancária", + "Nº Documento Bancário", + "Data Emissao NF", + "Doc. Pago", + "Cód. Projeto", + "Projeto", + "Agência", + "Conta", + "Empresa / Pessoa / Projeto", + "CPF/CNPJ", + "Gestor", + "Tipo do Lançamento", + "Situação" + ] + + sheet2.append(linha) + #formatar as linhas + cinza = "f1f1f1" + + for column in range(ord('A'), ord('Z')+1): + column_letter = chr(column) + sheet2.column_dimensions[column_letter].width = 25 + + for row in sheet2.iter_rows(min_row=1, max_row=len(dfconsultaDadosPorRubrica), min_col=1, max_col= 26): + for cell in row: + if cell.row == 1: + cell.fill = PatternFill(start_color=cinza, end_color=cinza, + fill_type = "solid") + 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 + else: + 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 + + #printar resultados + 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) + sheet2.cell(row=row_num, column=col_num, value=value) + + # dfconsultaDadosPorRubricaComEstorno.index = dfconsultaDadosPorRubricaComEstorno.index + 1 + + + + + + + workbook.save(tabela) + workbook.close() + + def preencheFub(codigo,data1,data2,tabela): '''Preencher fub legado dadoRubrica = transforma em dicionario a consulta feita por sql e separa por rubricas. @@ -1102,12 +1700,14 @@ def preencheFub(codigo,data1,data2,tabela): ''' + planilhaGeral(tabela,codigo,data1,data2) tamanho,dataframe = ExeReceitaDespesa(tabela,codigo,data1,data2,15) tamanhoPosicaoBrasilia,dfReceitas,dfDemonstrativoReceitas = Receita(tabela,codigo,data1,data2,tamanho,dataframe) demonstrativo(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia,dfDemonstrativoReceitas,dfReceitas) rubricaGeral(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia) conciliacaoBancaria(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia) rowRendimento= rendimentoDeAplicacao(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia) - relacaodeBens(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia) + + diff --git a/project/app/preenche_fundep.py b/project/app/preencheFundep.py similarity index 97% rename from project/app/preenche_fundep.py rename to project/app/preencheFundep.py index 83b657ae..02af53c4 100755 --- a/project/app/preenche_fundep.py +++ b/project/app/preencheFundep.py @@ -3,6 +3,7 @@ import openpyxl import os from .estilo_fundep import estilo_fundep +from .preencheFub import planilhaGeral from openpyxl.styles import Font,Alignment def check_format(time_data, format='%Y-%m-%d'): try: @@ -98,7 +99,7 @@ def getCollumNames(IDPROJETO, DATA1, DATA2): - sql = f"SELECT * FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? AND CodRubrica NOT LIKE 2 ORDER BY DataPagamento" + sql = f"SELECT * FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? AND CodRubrica NOT IN(2,3,0) ORDER BY DataPagamento" cursor.execute(sql, IDPROJETO, DATA1, DATA2) @@ -134,6 +135,7 @@ def retornavalores(list_of_dicts,keys): def preenche_fundep(codigo,data1,data2,keys,planilha): + planilhaGeral(planilha,codigo,data1,data2) dados_db = get_values_from_dict(codigo,data1,data2) input_date = [] output_date_str = [] diff --git a/project/app/preencheGenerico.py b/project/app/preencheGenerico.py deleted file mode 100644 index e69de29b..00000000 diff --git a/project/app/preencherFinep.py b/project/app/preencherFinep.py index 04d89489..66d7c6f0 100644 --- a/project/app/preencherFinep.py +++ b/project/app/preencherFinep.py @@ -3,107 +3,28 @@ import openpyxl from openpyxl.styles import Font import os -from .estiloFINEP import * from collections import defaultdict +from .estiloFINEP import * +from .preencheFub import planilhaGeral,consultaNomeRubricaCodRubrica,consultaID,convert_datetime_to_string,convert_datetime_to_stringdt,formatar_data,formatarDataSemDia,formatar_cpf,check_format,pegar_caminho,pegar_pass import pandas as pd from sqlalchemy import create_engine from sqlalchemy.engine import URL +import numpy as np +from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE +import re -def convert_datetime_to_string(value): - if isinstance(value, datetime): - return value.strftime('%d/%m/%Y') - return value - -def convert_datetime_to_stringdt(dt): - # Check if the value is a pandas Timestamp - if isinstance(dt, pd.Timestamp): - # Convert the Timestamp to a string using strftime - return dt.strftime('%d/%m/%Y') # You can customize the format as needed - else: - # If it's not a Timestamp, return the original value - return dt - -def formatar_data(row): - """ Formata a data com o mes abreviado transformando 01 em jan por exemplo - """ - dia = row.day - mes = row.month - ano = row.year - - # Mapear o número do mês para o nome abreviado - meses = {1: 'jan', 2: 'fev', 3: 'mar', 4: 'abr', 5: 'mai', 6: 'jun', 7: 'jul', 8: 'ago', 9: 'set', 10: 'out', 11: 'nov', 12: 'dez'} - - # Obter o nome abreviado do mês - mes_abreviado = meses.get(mes, mes) - - # Criar a string formatada - data_formatada = f'{dia}-{mes_abreviado}-{ano}' - - return data_formatada - -def formatarDataSemDia(row): - """ Formata a data com o mes abreviado transformando 01 em jan por exemplo - """ - dia = row.day - mes = row.month - ano = row.year - - # Mapear o número do mês para o nome abreviado - meses = {1: 'jan', 2: 'fev', 3: 'mar', 4: 'abr', 5: 'mai', 6: 'jun', 7: 'jul', 8: 'ago', 9: 'set', 10: 'out', 11: 'nov', 12: 'dez'} - - # Obter o nome abreviado do mês - mes_abreviado = meses.get(mes, mes) - - # Criar a string formatada - data_formatada = f'{mes_abreviado}-{ano}' - - return data_formatada - -def formatar_cpf(cpf): - cpf_formatado = f'{cpf[:3]}.{cpf[3:6]}.{cpf[6:9]}-{cpf[9:]}' - return cpf_formatado - -def check_format(time_data, format='%Y-%m-%d'): - try: - # Try to parse the time_data using the specified format - datetime.strptime(time_data, format) - return True # The time_data matches the format - except ValueError: - return False # The time_data does not match the format - -def pegar_caminho(subdiretorio): - # Obtém o caminho do script atual - arq_atual = os.path.abspath(__file__) - - # Obtém o diretório do script - app = os.path.dirname(arq_atual) - - # Obtém o diretório pai do script - project = os.path.dirname(app) - - # Obtém o diretório pai do projeto - pipeline = os.path.dirname(project) - - # Junta o diretório pai do projeto com o subdiretório desejado - caminho_pipeline = os.path.join(pipeline, subdiretorio) - - return caminho_pipeline - -def pegar_pass(chave): - arq_atual = os.path.abspath(__file__) - app = os.path.dirname(arq_atual) - project = os.path.dirname(app) - pipeline = os.path.dirname(project) - desktop = os.path.dirname(pipeline) - caminho_pipeline = os.path.join(desktop, chave) - - return caminho_pipeline - # return records +#consulta -#todas as consultas em sql -def consultaRendimentosTodosAteOPeriodo(IDPROJETO,DATA2): +#ok +def consultaRelatorioExecFinanceiraA1(IDPROJETO, DATA1, DATA2): + ''' Consulta que busca os valores executado no periodo, e os valores que foram executados até no periodo + Argumentos + IDPROJETO = CodConvenio na tabela nova, corresponde ao codigo do projeto + DATA1 = Data Inicial Selecinado pelo Usuario + DATA2 = Data Final Selecionado pelo Usuario + ''' file_path = pegar_pass("passs.txt") conStr = '' with open(file_path, 'r') as file: @@ -111,31 +32,27 @@ def consultaRendimentosTodosAteOPeriodo(IDPROJETO,DATA2): connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) - parametros = [(IDPROJETO, DATA2)] - - consultaRendimentoAplicacao = f""" - SELECT - NomeTipoLancamento, - SUM(CASE WHEN NomeTipoLancamento = 'IRRF Pessoa Jurídica' THEN ValorPago ELSE 0 END) AS IRRF, - SUM(CASE WHEN NomeTipoLancamento = 'Aplicação Financeira' THEN ValorPago ELSE 0 END) AS Aplicação - FROM - [Conveniar].[dbo].[LisLancamentoConvenio] - WHERE - CodConvenio = ? - AND CodStatus = 27 - AND CodRubrica = 3 - AND DataPagamento <= ? - GROUP BY - NomeTipoLancamento; - """ - - - Soma = pd.read_sql(consultaRendimentoAplicacao, engine, params=parametros) + parametros = [(IDPROJETO, DATA1, DATA2)] + parametros2 = [(IDPROJETO, DATA2)] + parametros3 = IDPROJETO + consultaComPeriodo =f"SELECT NomeRubrica, SUM(ValorPago) AS VALOR_TOTAL_PERIODO FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? GROUP BY NomeRubrica, CodRubrica Order by CodRubrica" + consultaAteAData = f"SELECT NomeRubrica, SUM(ValorPago) AS VALOR_TOTAL_DATA FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento <= ? GROUP BY NomeRubrica, CodRubrica Order by CodRubrica " + #consultaPrevisto = f"SELECT NomeRubrica, SUM(VALOR*Quantidade) AS VALOR_TOTAL_PREVISTO FROM [Conveniar].[dbo].[LisConvenioItemAprovado] WHERE CodConvenio = ? GROUP BY NomeRubrica, CodRubrica Order by CodRubrica" - - return Soma + dfComPeriodo= pd.read_sql(consultaComPeriodo, engine, params=parametros) + dfAteAData = pd.read_sql(consultaAteAData, engine, params=parametros2) + #dfPrevisto = pd.read_sql(consultaPrevisto, engine, params=(IDPROJETO,)) -def consultaRendimentosIRRF(IDPROJETO,DATA1,DATA2): + return dfComPeriodo,dfAteAData +#ok +def consultaDemonstrativoReceitaEDespesaA2(IDPROJETO,DATA1,DATA2): + ''' Função que vai pega os dados da Rubrica 9 Despesas Financeiras e transformalos em dataframe + para poder popular a databela Despesas Financeiras + Argumentos + IDPROJETO = CodConvenio na tabela nova, corresponde ao codigo do projeto + DATA1 = Data Inicial Selecinado pelo Usuario + DATA2 = Data Final Selecionado pelo Usuario + ''' file_path = pegar_pass("passs.txt") conStr = '' with open(file_path, 'r') as file: @@ -144,13 +61,18 @@ def consultaRendimentosIRRF(IDPROJETO,DATA1,DATA2): connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) parametros = [(IDPROJETO, DATA1, DATA2)] + parametros2 = [(IDPROJETO, DATA1)] + parametros4 = [(IDPROJETO, DATA2)] + parametros3 = IDPROJETO + consultaComPeriodo =f"SELECT NomeRubrica, SUM(ValorPago) AS VALOR_TOTAL_PERIODO FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? GROUP BY NomeRubrica, CodRubrica Order by CodRubrica" + consultaAteAData = f"SELECT NomeRubrica, SUM(ValorPago) AS VALOR_TOTAL_DATA FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento <= ? GROUP BY NomeRubrica, CodRubrica Order by CodRubrica " - consultaComPeriodo =f"SELECT SUM(ValorPago) AS TotalPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 0 AND DataPagamento BETWEEN ? AND ?" - + consultaPrevisto = f"SELECT NomeRubrica, SUM(VALOR*Quantidade) AS VALOR_TOTAL_PREVISTO FROM [Conveniar].[dbo].[LisConvenioItemAprovado] WHERE CodConvenio = ? GROUP BY NomeRubrica, CodRubrica Order by CodRubrica" + consultaRubricaRecursoRecebidos = f"SELECT sum(ValorPago) AS VALOR_TOTAL_DATA FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento <= ? " consultaRendimentoAplicacao = f""" SELECT NomeTipoLancamento, - SUM(CASE WHEN NomeTipoLancamento = 'IRRF Pessoa Jurídica' THEN ValorPago ELSE 0 END) AS IRRF, + --SUM(CASE WHEN NomeTipoLancamento = 'IRRF Pessoa Jurídica' THEN ValorPago ELSE 0 END) AS IRRF, SUM(CASE WHEN NomeTipoLancamento = 'Aplicação Financeira' THEN ValorPago ELSE 0 END) AS Aplicação FROM [Conveniar].[dbo].[LisLancamentoConvenio] @@ -162,58 +84,30 @@ def consultaRendimentosIRRF(IDPROJETO,DATA1,DATA2): GROUP BY NomeTipoLancamento; """ - - - Soma = pd.read_sql(consultaRendimentoAplicacao, engine, params=parametros) - return Soma -def consultaDevolucaoRecursos(IDPROJETO,DATA1,DATA2): - file_path = pegar_pass("passs.txt") - conStr = '' - with open(file_path, 'r') as file: - conStr = file.readline().strip() - connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) - engine = create_engine(connection_url) - parametros = [(IDPROJETO, DATA1, DATA2)] - - consultaComPeriodo = f"SELECT SUM(ValorPago) AS TotalPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 0 AND DataPagamento BETWEEN ? AND ?" + Soma = pd.read_sql(consultaRendimentoAplicacao, engine, params=parametros) + dfComPeriodo= pd.read_sql(consultaComPeriodo, engine, params=parametros) + dfAteAData = pd.read_sql(consultaAteAData, engine, params=parametros2) + dfPrevisto = pd.read_sql(consultaPrevisto, engine, params=(IDPROJETO,)) + dfRubricaRecursoRecebidos = pd.read_sql(consultaRubricaRecursoRecebidos, engine, params=parametros4) - Soma = pd.read_sql(consultaComPeriodo, engine, params=parametros) - - return Soma -def consultaRendimentosAplicacao(IDPROJETO,DATA1,DATA2): - file_path = pegar_pass("passs.txt") - conStr = '' - with open(file_path, 'r') as file: - conStr = file.readline().strip() - connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) - engine = create_engine(connection_url) - parametros = [(IDPROJETO, DATA1, DATA2)] - consultaRendimentoAplicacao = f"SELECT DataPagamento,ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 3 and NomeTipoLancamento = 'Aplicação Financeira' AND DataPagamento BETWEEN ? AND ? order by DataPagamento" - dfConsultaRendimentoAplicacao = pd.read_sql(consultaRendimentoAplicacao, engine, params=parametros) - - consultaRendimentoEImposto = f"SELECT DataPagamento,ValorPago,NomeTipoLancamento FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 3 and (NomeTipoLancamento = 'Aplicação Financeira' or NomeTipoLancamento = 'IRRF Pessoa Jurídica') AND DataPagamento BETWEEN ? AND ? order by DataPagamento" - dfConsultaRendimentoEImposto = pd.read_sql(consultaRendimentoEImposto, engine, params=parametros) + return dfComPeriodo,dfAteAData,dfPrevisto,dfRubricaRecursoRecebidos,Soma +#ok +def consultaPagamentoPessoal(IDPROJETO,DATA1,DATA2): - consultaImposto = f"SELECT DataPagamento,ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 3 and NomeTipoLancamento = 'IRRF Pessoa Jurídica' AND DataPagamento BETWEEN ? AND ? order by DataPagamento" - dfConsultaImposto = pd.read_sql(consultaImposto, engine, params=parametros) - - - return dfConsultaRendimentoAplicacao,dfConsultaImposto,dfConsultaRendimentoEImposto - -def consultaConciliacaoBancaria(IDPROJETO, DATA1, DATA2): - ''' Função que vai pega os dados da Rubrica 9 Despesas Financeiras e transformalos em dataframe - para poder popular a databela Despesas Financeiras + ''' Consulta dinamica do SQL relacionado a rubrica correspondente,cada pagina tem sua própria consulta correspondente a rubrica Argumentos IDPROJETO = CodConvenio na tabela nova, corresponde ao codigo do projeto DATA1 = Data Inicial Selecinado pelo Usuario DATA2 = Data Final Selecionado pelo Usuario + codigoRubrica = código da rubrica ''' + codigoRubrica = 87 file_path = pegar_pass("passs.txt") conStr = '' with open(file_path, 'r') as file: @@ -222,62 +116,63 @@ def consultaConciliacaoBancaria(IDPROJETO, DATA1, DATA2): connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) parametros = [(IDPROJETO, DATA1, DATA2)] - consultaSemEstorno = f"SELECT DISTINCT DataPagamento,ValorPago,NumChequeDeposito,HisLancamento FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 9 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) NOT LIKE '%estorno%' order by DataPagamento" - consultaComEstorno = f"SELECT DISTINCT DataPagamento,ValorPago,NumChequeDeposito,HisLancamento FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 9 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) LIKE '%estorno%' order by DataPagamento" - dfSemEstorno = pd.read_sql(consultaSemEstorno, engine, params=parametros) - dfComEstorno = pd.read_sql(consultaComEstorno, engine, params=parametros) - - - return dfSemEstorno,dfComEstorno - -def consultaID(IDPROJETO): - - #file_path = "/home/ubuntu/Desktop/devfront/devfull/pass.txt" - file_path = pegar_pass("passs.txt") - conStr = '' - with open(file_path, 'r') as file: - conStr = file.readline().strip() - - conn = None - - conn = pyodbc.connect(conStr) - cursor = conn.cursor() + parametrosComRubricaEstorno = [(IDPROJETO, DATA1, DATA2,IDPROJETO,DATA1, DATA2)] + parametrosPJ=[(IDPROJETO, DATA1, DATA2)] + parametrosPJestorno=[(IDPROJETO, DATA1, DATA2,IDPROJETO, DATA1, DATA2)] + queryConsultaComRubrica = f"""SELECT NomeFavorecido, + CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + NomeTipoLancamento, + [LisConvenioItemAprovado].[DescConvenioItemAprovado], + NumDocPago, + DataEmissao, + NumChequeDeposito, + DataPagamento, + ValorPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE [LisLancamentoConvenio].CodConvenio = ? + AND [LisLancamentoConvenio].CodStatus = 27 + AND [LisLancamentoConvenio].DataPagamento BETWEEN ? AND ? + AND LOWER([LisLancamentoConvenio].HisLancamento) NOT LIKE '%estorno%' + and [LisLancamentoConvenio].CodRubrica = 87 order by DataPagamento""" - - consulta = {} - - - # SQL querys - - sql = f"SELECT [LisConvenio].* , [LisPessoa].[CPFCNPJ] as 'CPFCoordenador' FROM [Conveniar].[dbo].[LisConvenio] INNER JOIN [Conveniar].[dbo].[LisUsuario] ON [LisConvenio].[CodUsuarioResponsavel] = [LisUsuario].[CodUsuario] INNER JOIN [Conveniar].[dbo].[LisPessoa] ON [LisUsuario].[CodPessoa] = [LisPessoa].[CodPessoa] WHERE CodConvenio = ? " - - # Execute the query - cursor.execute(sql, IDPROJETO) - + #SEMPRE TEM Q ADICIONAR DUAS COLUNAS DEPOIS + queryConsultaComRubricaEstorno = f"""SELECT NomeFavorecido + ,CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + NomeTipoLancamento, + HisLancamento, + NumChequeDeposito, + DataPagamento, + ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE + [LisLancamentoConvenio].CodConvenio = ? + AND CodStatus = 27 + AND NomeTipoCreditoDebito = 'C' + AND DataPagamento BETWEEN ? AND ? + and [LisLancamentoConvenio].CodRubrica = 87 + OR + CodStatus = 27 + AND [LisLancamentoConvenio].CodConvenio = ? + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) LIKE '%estorno%' + AND [LisLancamentoConvenio].CodRubrica = 87 + + order by DataPagamento """ - records = cursor.fetchall() - - collums = cursor.description - - for i in range(len(collums)): - consulta[collums[i][0]] = records[0][i] - - cursor.close() - conn.close() - - - - # return records - return consulta + dfconsultaDadosPorRubrica = pd.read_sql(queryConsultaComRubrica, engine, params=parametros) + dfconsultaDadosPorRubricaComEstorno = pd.read_sql(queryConsultaComRubricaEstorno,engine, params=parametrosComRubricaEstorno) - values = [d.get(key) for d in list_of_dicts for key in keys] - - - return values -def consultaNomeRubricaCodRubrica(IDPROJETO, DATA1, DATA2,): + return dfconsultaDadosPorRubrica,dfconsultaDadosPorRubricaComEstorno +#ok +def consultaestiloElementoDeDespesa1415Diarias(IDPROJETO,DATA1,DATA2): ''' Função que vai pega os dados da Rubrica 9 Despesas Financeiras e transformalos em dataframe para poder popular a databela Despesas Financeiras Argumentos @@ -292,20 +187,126 @@ def consultaNomeRubricaCodRubrica(IDPROJETO, DATA1, DATA2,): connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) - parametros = [(IDPROJETO, DATA1, DATA2)] - queryNomeRubrica = f"SELECT CodRubrica,NomeRubrica FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? GROUP BY NomeRubrica, CodRubrica" - dfNomeRubricaCodRubrica = pd.read_sql(queryNomeRubrica, engine, params=parametros) - - return dfNomeRubricaCodRubrica - -def consultaProjeto(IDPROJETO, DATA1, DATA2,codigoRubrica): - ''' Função que vai pega os dados da Rubrica 9 Despesas Financeiras e transformalos em dataframe - para poder popular a databela Despesas Financeiras + parametros = [(IDPROJETO, DATA1, DATA2)] + parametros2 = [(IDPROJETO, DATA1, DATA2,IDPROJETO, DATA1, DATA2)] + + queryConsultaSemEstorno = f""" + SELECT [LisPessoa].[NomePessoa], + + CASE WHEN LEN([LisPessoa].CPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF([LisPessoa].CPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN([LisPessoa].CPFCNPJ) = 11 THEN STUFF(STUFF(STUFF([LisPessoa].CPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE [LisPessoa].CPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + (SELECT TOP 1 [NomeCidadeOrigem] + FROM [Conveniar].[dbo].[LisPagamentoDiariaTrecho] + WHERE [LisPagamentoDiariaTrecho].CodPedido = [LisPagamentoDiaria].[CodPedido] + AND [NomeTipoDestino] = 'Saída') + ' - ' + + (SELECT TOP 1 [NomeCidadeDestino] + FROM [Conveniar].[dbo].[LisPagamentoDiariaTrecho] + WHERE [LisPagamentoDiariaTrecho].CodPedido = [LisPagamentoDiaria].[CodPedido] + AND [NomeTipoDestino] = 'Saída') + + + ' -> ' + + (SELECT TOP 1 [NomeCidadeOrigem] + FROM [Conveniar].[dbo].[LisPagamentoDiariaTrecho] + WHERE [LisPagamentoDiariaTrecho].CodPedido = [LisPagamentoDiaria].[CodPedido] + AND [NomeTipoDestino] = 'Chegada') + ' - ' + + (SELECT TOP 1 [NomeCidadeDestino] + FROM [Conveniar].[dbo].[LisPagamentoDiariaTrecho] + WHERE [LisPagamentoDiariaTrecho].CodPedido = [LisPagamentoDiaria].[CodPedido] + AND [NomeTipoDestino] = 'Chegada') AS Destino + + + ,[LisPagamentoDiaria].[QuantDiaria] + ,[LisPagamentoDiaria].[ObsPedido] + ,[LisConvenioItemAprovado].[DescConvenioItemAprovado] + ,[LisLancamentoConvenio]. NumDocPago + ,[LisLancamentoConvenio]. DataEmissao + ,[LisLancamentoConvenio].NumChequeDeposito + ,[LisLancamentoConvenio].DataPagamento + ,[LisLancamentoConvenio].ValorPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + INNER JOIN [Conveniar].[dbo].[LisPagamentoDiaria] ON [LisLancamentoConvenio].[NumDocFinConvenio] = [LisPagamentoDiaria].[NumPedido] + INNER JOIN [Conveniar].[dbo].[LisPessoa] ON [LisPagamentoDiaria].[CodPessoaFavorecida] = [LisPessoa].[CodPessoa] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + + + WHERE LisLancamentoConvenio.CodConvenio = ? + AND LisLancamentoConvenio.CodStatus = 27 + AND LisLancamentoConvenio.DataPagamento BETWEEN ? AND ? + """ + + queryConsultaComEstorno = f""" + SELECT + [LisPessoa].[NomePessoa] + , + + CASE WHEN LEN([LisPessoa].CPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF([LisPessoa].CPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN([LisPessoa].CPFCNPJ) = 11 THEN STUFF(STUFF(STUFF([LisPessoa].CPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE [LisPessoa].CPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + (SELECT TOP 1 [NomeCidadeOrigem] + FROM [Conveniar].[dbo].[LisPagamentoDiariaTrecho] + WHERE [LisPagamentoDiariaTrecho].CodPedido = [LisPagamentoDiaria].[CodPedido] + AND [NomeTipoDestino] = 'Saída') + ' - ' + + (SELECT TOP 1 [NomeCidadeDestino] + FROM [Conveniar].[dbo].[LisPagamentoDiariaTrecho] + WHERE [LisPagamentoDiariaTrecho].CodPedido = [LisPagamentoDiaria].[CodPedido] + AND [NomeTipoDestino] = 'Saída') + + + ' -> ' + + (SELECT TOP 1 [NomeCidadeOrigem] + FROM [Conveniar].[dbo].[LisPagamentoDiariaTrecho] + WHERE [LisPagamentoDiariaTrecho].CodPedido = [LisPagamentoDiaria].[CodPedido] + AND [NomeTipoDestino] = 'Chegada') + ' - ' + + (SELECT TOP 1 [NomeCidadeDestino] + FROM [Conveniar].[dbo].[LisPagamentoDiariaTrecho] + WHERE [LisPagamentoDiariaTrecho].CodPedido = [LisPagamentoDiaria].[CodPedido] + AND [NomeTipoDestino] = 'Chegada') AS Destino + + + ,[LisPagamentoDiaria].[QuantDiaria] + ,[LisPagamentoDiaria].[ObsPedido] + ,[LisConvenioItemAprovado].[DescConvenioItemAprovado] + ,[LisLancamentoConvenio].NumChequeDeposito + ,[LisLancamentoConvenio]. NumDocPago + ,[LisLancamentoConvenio]. DataEmissao + ,[LisLancamentoConvenio].NumChequeDeposito + ,[LisLancamentoConvenio].DataPagamento + ,[LisLancamentoConvenio].ValorPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + INNER JOIN [Conveniar].[dbo].[LisPagamentoDiaria] ON [LisLancamentoConvenio].[NumDocFinConvenio] = [LisPagamentoDiaria].[NumPedido] + INNER JOIN [Conveniar].[dbo].[LisPessoa] ON [LisPagamentoDiaria].[CodPessoaFavorecida] = [LisPessoa].[CodPessoa] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + + + WHERE [LisLancamentoConvenio].CodConvenio = ? + AND [LisLancamentoConvenio].[CodStatus] = 27 + AND NomeTipoCreditoDebito = 'C' + AND LisLancamentoConvenio.DataPagamento BETWEEN ? AND ? + or + [LisLancamentoConvenio].CodConvenio = ? + AND [LisLancamentoConvenio].[CodStatus] = 27 + AND LOWER(HisLancamento) LIKE '%estorno%' + AND LisLancamentoConvenio.DataPagamento BETWEEN ? AND ? + + + Order by LisLancamentoConvenio.DataPagamento""" + + + dfConsultaDiaria = pd.read_sql(queryConsultaSemEstorno, engine, params=parametros) + dfConsultaDiariaEstorno = pd.read_sql(queryConsultaComEstorno, engine, params=parametros2) + + + return dfConsultaDiaria ,dfConsultaDiariaEstorno +#ok +def consultaGeral30(IDPROJETO,DATA1,DATA2,codigoRubrica): + + ''' Consulta dinamica do SQL relacionado a rubrica correspondente,cada pagina tem sua própria consulta correspondente a rubrica Argumentos IDPROJETO = CodConvenio na tabela nova, corresponde ao codigo do projeto DATA1 = Data Inicial Selecinado pelo Usuario DATA2 = Data Final Selecionado pelo Usuario + codigoRubrica = código da rubrica ''' file_path = pegar_pass("passs.txt") conStr = '' @@ -315,14 +316,112 @@ def consultaProjeto(IDPROJETO, DATA1, DATA2,codigoRubrica): connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) parametros = [(IDPROJETO, DATA1, DATA2,codigoRubrica)] - queryConsultaComRubrica = f"SELECT NomeFavorecido,FavorecidoCPFCNPJ,NomeTipoLancamento,HisLancamento,NumDocPago,DataEmissao,NumChequeDeposito,DataPagamento, ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? and CodRubrica = ? " - dfconsultaDadosPorRubrica = pd.read_sql(queryConsultaComRubrica, engine, params=parametros) - - - return dfconsultaDadosPorRubrica + parametrosComRubricaEstorno = [(IDPROJETO, DATA1, DATA2,codigoRubrica,IDPROJETO,DATA1, DATA2,codigoRubrica,)] + parametrosPJ=[(IDPROJETO, DATA1, DATA2)] + parametrosPJestorno=[(IDPROJETO, DATA1, DATA2,IDPROJETO, DATA1, DATA2)] + + queryConsultaComRubrica = f"""SELECT NomeFavorecido, + CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + [LisConvenioItemAprovado].[DescConvenioItemAprovado], + + NumDocPago, + DataEmissao, + NumChequeDeposito, + DataPagamento, + ValorPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE [LisLancamentoConvenio].CodConvenio = ? + AND [LisLancamentoConvenio].CodStatus = 27 + AND [LisLancamentoConvenio].DataPagamento BETWEEN ? AND ? + AND LOWER([LisLancamentoConvenio].HisLancamento) NOT LIKE '%estorno%' + and [LisLancamentoConvenio].CodRubrica = ? order by DataPagamento""" + + queryConsultaComRubricaEstorno = f"""SELECT NomeFavorecido + ,CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + HisLancamento, + NumChequeDeposito, + DataPagamento, + ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE + [LisLancamentoConvenio].CodConvenio = ? + AND CodStatus = 27 + AND NomeTipoCreditoDebito = 'C' + AND DataPagamento BETWEEN ? AND ? + and [LisLancamentoConvenio].CodRubrica = ? + OR + CodStatus = 27 + AND [LisLancamentoConvenio].CodConvenio = ? + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) LIKE '%estorno%' + AND [LisLancamentoConvenio].CodRubrica = ? + + order by DataPagamento """ + + queryConsultaPJDOA = f"""SELECT NomeFavorecido, + CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + [LisConvenioItemAprovado].[DescConvenioItemAprovado], + + NumDocPago, + DataEmissao, + NumChequeDeposito, + DataPagamento, + ValorPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE [LisLancamentoConvenio].CodConvenio = ? + AND [LisLancamentoConvenio].CodStatus = 27 + AND [LisLancamentoConvenio].DataPagamento BETWEEN ? AND ? + AND LOWER([LisLancamentoConvenio].HisLancamento) NOT LIKE '%estorno%' + and [LisLancamentoConvenio].CodRubrica IN (57,75,26) order by DataPagamento""" + + queryConsultaPJDOAEstorno = f"""SELECT NomeFavorecido + ,CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + HisLancamento, + NumChequeDeposito, + DataPagamento, + ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE + [LisLancamentoConvenio].CodConvenio = ? + AND CodStatus = 27 + AND NomeTipoCreditoDebito = 'C' + AND DataPagamento BETWEEN ? AND ? + and [LisLancamentoConvenio].CodRubrica IN (57,75,26) + OR + CodStatus = 27 + AND [LisLancamentoConvenio].CodConvenio = ? + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) LIKE '%estorno%' + AND [LisLancamentoConvenio].CodRubrica IN (57,75,26) + + order by DataPagamento """ -def consultaEntradaReceitas(IDPROJETO, DATA1, DATA2): - + dfconsultaDadosPorRubrica = pd.read_sql(queryConsultaComRubrica, engine, params=parametros) + dfconsultaDadosPorRubricaComEstorno = pd.read_sql(queryConsultaComRubricaEstorno,engine, params=parametrosComRubricaEstorno) + dfPJDOA = pd.read_sql(queryConsultaPJDOA, engine, params=parametrosPJ) + dfPJDOAESTORNO = pd.read_sql(queryConsultaPJDOAEstorno,engine, params=parametrosPJestorno) + + return dfPJDOA,dfPJDOAESTORNO,dfconsultaDadosPorRubrica,dfconsultaDadosPorRubricaComEstorno +#ok +def consultaestiloElementoDeDespesa33PassagemEDespesa(IDPROJETO,DATA1,DATA2): + + ''' Consulta dinamica do SQL relacionado a rubrica correspondente,cada pagina tem sua própria consulta correspondente a rubrica + Argumentos + IDPROJETO = CodConvenio na tabela nova, corresponde ao codigo do projeto + DATA1 = Data Inicial Selecinado pelo Usuario + DATA2 = Data Final Selecionado pelo Usuario + codigoRubrica = código da rubrica + ''' file_path = pegar_pass("passs.txt") conStr = '' with open(file_path, 'r') as file: @@ -330,19 +429,60 @@ def consultaEntradaReceitas(IDPROJETO, DATA1, DATA2): connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) - parametros = [(IDPROJETO, DATA1, DATA2,)] - consultaEntradaReceita = f"SELECT DataPagamento,NumChequeDeposito,NomeFavorecido,ValorPago,CodRubrica FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND (CodRubrica = 2 OR CodRubrica = 67 OR CodRubrica = 88) AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? ORDER BY DataPagamento,NumChequeDeposito" - consultaDemonstrativoReceita = f"SELECT NomeFavorecido,HisLancamento,NumChequeDeposito,DataPagamento,ValorPago,CodRubrica FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND (CodRubrica = 2 OR CodRubrica = 67 OR CodRubrica = 88) AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? ORDER BY DataPagamento,NumChequeDeposito" - dfReceitas = pd.read_sql(consultaEntradaReceita, engine, params=parametros) - dfDemonstrativoReceitas = pd.read_sql(consultaDemonstrativoReceita, engine, params=parametros) + parametros = [(IDPROJETO, DATA1, DATA2)] + parametrosComRubricaEstorno = [(IDPROJETO, DATA1, DATA2,IDPROJETO,DATA1, DATA2,)] + queryConsultaComRubrica = f"""SELECT NomeFavorecido, + CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + [LisConvenioItemAprovado].[DescConvenioItemAprovado], + + NumDocPago, + DataEmissao, + NumChequeDeposito, + DataPagamento, + ValorPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE [LisLancamentoConvenio].CodConvenio = ? + AND [LisLancamentoConvenio].CodStatus = 27 + AND [LisLancamentoConvenio].DataPagamento BETWEEN ? AND ? + AND LOWER([LisLancamentoConvenio].HisLancamento) NOT LIKE '%estorno%' + and [LisLancamentoConvenio].CodRubrica in (20,78,52) order by [LisLancamentoConvenio].DataPagamento""" - - - - return dfReceitas,dfDemonstrativoReceitas + queryConsultaComRubricaEstorno = f"""SELECT NomeFavorecido + ,CASE WHEN LEN(FavorecidoCPFCNPJ) > 11 THEN STUFF(STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 3, 0, '.'), 7, 0, '.'), 11, 0, '/'), 16, 0, '-') + WHEN LEN(FavorecidoCPFCNPJ) = 11 THEN STUFF(STUFF(STUFF(FavorecidoCPFCNPJ, 4, 0, '.'), 8, 0, '.'), 12, 0, '-') ELSE FavorecidoCPFCNPJ END AS FormattedFavorecidoCPFCNPJ, + [LisConvenioItemAprovado].[DescConvenioItemAprovado], + NumChequeDeposito, + DataPagamento, + ValorPago + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + LEFT JOIN [Conveniar].[dbo].[PlanoTrabalhoLancamento] ON [LisLancamentoConvenio].[CodLancamento] = [PlanoTrabalhoLancamento].[CodLancamentoGerado] + LEFT JOIN [Conveniar].[dbo].[LisConvenioItemAprovado] ON [PlanoTrabalhoLancamento].[CodConvenioItemAprovado] = [LisConvenioItemAprovado].[CodConvenioItemAprovado] + WHERE + [LisLancamentoConvenio].CodConvenio = ? + AND CodStatus = 27 + AND NomeTipoCreditoDebito = 'C' + AND DataPagamento BETWEEN ? AND ? + and [LisLancamentoConvenio].CodRubrica in (20,78,52) + OR + CodStatus = 27 + AND [LisLancamentoConvenio].CodConvenio = ? + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) LIKE '%estorno%' + AND [LisLancamentoConvenio].CodRubrica in (20,78,52) + + order by [LisLancamentoConvenio].DataPagamento """ -def consultaReceitaEExecReceita(IDPROJETO, DATA1, DATA2): + dfconsultaDadosPorRubrica = pd.read_sql(queryConsultaComRubrica, engine, params=parametros) + dfconsultaDadosPorRubricaComEstorno = pd.read_sql(queryConsultaComRubricaEstorno,engine, params=parametrosComRubricaEstorno) + + + return dfconsultaDadosPorRubrica,dfconsultaDadosPorRubricaComEstorno +#ok +def consultaBens(IDPROJETO,DATA1,DATA2): ''' Função que vai pega os dados da Rubrica 9 Despesas Financeiras e transformalos em dataframe para poder popular a databela Despesas Financeiras Argumentos @@ -350,28 +490,37 @@ def consultaReceitaEExecReceita(IDPROJETO, DATA1, DATA2): DATA1 = Data Inicial Selecinado pelo Usuario DATA2 = Data Final Selecionado pelo Usuario ''' - file_path = pegar_pass("passs.txt") + file_path = pegar_pass("passss.txt") conStr = '' with open(file_path, 'r') as file: conStr = file.readline().strip() connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) - parametros = [(IDPROJETO, DATA1, DATA2)] - parametros2 = [(IDPROJETO, DATA2)] - parametros3 = IDPROJETO - consultaComPeriodo =f"SELECT NomeRubrica, SUM(ValorPago) AS VALOR_TOTAL_PERIODO FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento BETWEEN ? AND ? GROUP BY NomeRubrica, CodRubrica Order by CodRubrica" - consultaAteAData = f"SELECT NomeRubrica, SUM(ValorPago) AS VALOR_TOTAL_DATA FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND DataPagamento <= ? GROUP BY NomeRubrica, CodRubrica Order by CodRubrica " - consultaPrevisto = f"SELECT NomeRubrica, SUM(VALOR*Quantidade) AS VALOR_TOTAL_PREVISTO FROM [Conveniar].[dbo].[LisConvenioItemAprovado] WHERE CodConvenio = ? GROUP BY NomeRubrica, CodRubrica Order by CodRubrica" + idprojetoComZero = f"0{IDPROJETO}" + parametros = [(IDPROJETO,idprojetoComZero, DATA1, DATA2)] - dfComPeriodo= pd.read_sql(consultaComPeriodo, engine, params=parametros) - dfAteAData = pd.read_sql(consultaAteAData, engine, params=parametros2) - dfPrevisto = pd.read_sql(consultaPrevisto, engine, params=(IDPROJETO,)) - - - return dfComPeriodo,dfAteAData,dfPrevisto + queryConsultaComRubrica = f""" + SELECT [Descrição][descri], + [Patrimônio][patri], + CONVERT(varchar, [Data de Aquisição], 103) AS dataAqui, + [Nº Nota][nota], + [Localização][localiza] + ,[Descrição], + [Valor de Aquisição][valorAqui], + [Valor de Aquisição][valorAqui2], + [Responsável][responsavel] + FROM [SBO_FINATEC].[dbo].[VW_BENS_ADQUIRIDOS] + WHERE ([Cod Projeto] = ? or [Cod Projeto] = ? ) + AND [Status] = 'Imobilizado' + AND [Data de Aquisição] BETWEEN ? AND ? + Order by [Data de Aquisição]""" + dfConsultaBens = pd.read_sql(queryConsultaComRubrica, engine, params=parametros) -def consultaBens(IDPROJETO,DATA1,DATA2): + + return dfConsultaBens +#ok +def consultaConciliacaoBancaria(IDPROJETO, DATA1, DATA2): ''' Função que vai pega os dados da Rubrica 9 Despesas Financeiras e transformalos em dataframe para poder popular a databela Despesas Financeiras Argumentos @@ -379,264 +528,130 @@ def consultaBens(IDPROJETO,DATA1,DATA2): DATA1 = Data Inicial Selecinado pelo Usuario DATA2 = Data Final Selecionado pelo Usuario ''' - file_path = pegar_pass("passss.txt") + file_path = pegar_pass("passs.txt") conStr = '' with open(file_path, 'r') as file: conStr = file.readline().strip() connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) engine = create_engine(connection_url) - idprojetoComZero = f"0{IDPROJETO}" - parametros = [(IDPROJETO,idprojetoComZero, DATA1, DATA2)] + parametros = [(IDPROJETO, DATA1, DATA2)] + parametros2 = [(IDPROJETO, DATA1, DATA2, IDPROJETO, DATA1, DATA2)] + #consultaSemEstorno = f"SELECT DISTINCT DataPagamento,ValorPago,NumChequeDeposito,HisLancamento FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 9 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) NOT LIKE '%estorno%' order by DataPagamento" + #consultaComEstorno = f"SELECT DISTINCT DataPagamento,ValorPago,NumChequeDeposito,HisLancamento FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 9 AND DataPagamento BETWEEN ? AND ? AND LOWER(HisLancamento) LIKE '%estorno%' order by DataPagamento" - queryConsultaComRubrica = f"SELECT [Descrição][descri],[Patrimônio][patri],[Data de Aquisição][dataAqui],[Nº Nota][nota],[Localização][localiza],[telefone],[Valor de Aquisição][valorAqui],[Valor de Aquisição][valorAqui2],[Responsável][responsavel] FROM [SBO_FINATEC].[dbo].[VW_BENS_ADQUIRIDOS] WHERE ([Cod Projeto] = ? or [Cod Projeto] = ? ) AND [Status] = 'Imobilizado' AND [Data de Aquisição] BETWEEN ? AND ? Order by [Data de Aquisição]" - dfConsultaBens = pd.read_sql(queryConsultaComRubrica, engine, params=parametros) - - - return dfConsultaBens + #consultaloucona assim por que precisa ser detalhado cada item na tabela + consultaSemEstorno = f""" + SELECT + [LisLancamentoConvenio].HisLancamento, + CONVERT(varchar, CAST([LisLancamentoConvenio].DataPagamento AS datetime), 103) AS FormattedDate, + [LisPagamentoDespesaConvenioAdministrativa].Valor + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + INNER JOIN [Conveniar].[dbo].[LisDocumentoConvenio] ON [LisLancamentoConvenio].[CodDocFinConvenio] = [LisDocumentoConvenio].[CodDocFinConvenio] + INNER JOIN [Conveniar].[dbo].[DocFinConvPagDespesa] ON [LisDocumentoConvenio].[CodDocFinConvenio] = [DocFinConvPagDespesa].[CodDocFinConvenio] + INNER JOIN [Conveniar].[dbo].[LisPagamentoDespesaConvenio] ON [DocFinConvPagDespesa].[CodPedido] = [LisPagamentoDespesaConvenio].[CodPedido] + INNER JOIN [Conveniar].[dbo].[LisPagamentoDespesaConvenioAdministrativa] ON [LisPagamentoDespesaConvenio].CodDespesaConvenio = [LisPagamentoDespesaConvenioAdministrativa].CodDespesaConvenio + AND [LisPagamentoDespesaConvenio].CodConvenio = [LisPagamentoDespesaConvenioAdministrativa].CodConvenio + WHERE [LisLancamentoConvenio].CodConvenio = ? + AND [LisLancamentoConvenio].CodStatus = 27 + AND [LisLancamentoConvenio].CodRubrica = 9 + AND [LisLancamentoConvenio].DataPagamento BETWEEN ? AND ? + AND LOWER([LisLancamentoConvenio].HisLancamento) NOT LIKE '%estorno%' + order by [LisLancamentoConvenio].DataPagamento""" + + consultaComEstorno = f"""SELECT + HisLancamento , + CONVERT(varchar, CAST(DataPagamento AS datetime), 103) AS FormattedDate, + ValorPago -#preenche planilha - -def conciliacaoBancaria(codigo,data1,data2,planilha,stringTamanho): - - tabela = pegar_caminho(planilha) - workbook = openpyxl.load_workbook(tabela) - sheet2 = workbook.create_sheet(title="Conciliação Bancária") - workbook.save(tabela) - workbook.close() - tamanho = [] - # categorized_data= separarporrubrica(codigo,data1,data2) - - dataframeSemEstorno,dataframeComEstorno = consultaConciliacaoBancaria(codigo,data1,data2) - - #####pergar os dados do db e separar por mes e ano###################3 + FROM [Conveniar].[dbo].[LisLancamentoConvenio] + WHERE CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND DataPagamento BETWEEN ? AND ? + AND LOWER(HisLancamento) LIKE '%estorno%' + OR + CodConvenio = ? + AND CodStatus = 27 + AND CodRubrica = 9 + AND NomeTipoCreditoDebito = 'C' + AND DataPagamento BETWEEN ? AND ? + order by DataPagamento""" - grupos_por_ano_mes = defaultdict(list) - if dataframeSemEstorno.empty and dataframeComEstorno.empty: - print("Data not available or empty.") - maior = 5 - maior2= 5 - tabela = pegar_caminho(planilha) - estilo_conciliacoes_bancaria(tabela,maior,maior2,stringTamanho) - return None # or handle the case accordingly - else: - - tamanho = len(dataframeSemEstorno) - tamanho2 = len(dataframeComEstorno) - - tabela = pegar_caminho(planilha) - estilo_conciliacoes_bancaria(tabela,tamanho,tamanho2,stringTamanho) - - - workb = openpyxl.load_workbook(tabela) - worksheet333 = workb["Conciliação Bancária"] - i = 16 - j=0 - estorno_valor = 0 - - dataframeSemEstorno['data_formatada'] = dataframeSemEstorno['DataPagamento'].apply(formatar_data) - dataframeComEstorno['data_formatada'] = dataframeComEstorno['DataPagamento'].apply(formatar_data) - dataframeSemEstorno['DataPagamento'] = dataframeSemEstorno['data_formatada'] - dataframeComEstorno['DataPagamento'] = dataframeComEstorno['data_formatada'] - - dataframeSemEstorno = dataframeSemEstorno.drop('data_formatada', axis=1) - dataframeComEstorno = dataframeComEstorno.drop('data_formatada', axis=1) - - #for row in worksheet333.iter_rows(min_row=16, max_row=tamanho, min_col=1, max_col=4): - - # Write data starting from the first row - for row_num, row_data in enumerate(dataframeSemEstorno.itertuples(index=False), start=16):#inicio linha - for col_num, value in enumerate(row_data, start=1):#inicio coluna - worksheet333.cell(row=row_num, column=col_num, value=value) - - - linha2 = 16+4+tamanho - - - for row_num, row_data in enumerate(dataframeComEstorno.itertuples(index=False), start=linha2):#inicio linha - for col_num, value in enumerate(row_data, start=1):#inicio coluna - worksheet333.cell(row=row_num, column=col_num, value=value) - - - - workb.save(tabela) - workb.close - -def demonstrativo(codigo,data1,data2,planilha,rowBrasilia,dataframeDemonstrativoReceita,dfReceitas): - tabela = pegar_caminho(planilha) - workbook = openpyxl.load_workbook(tabela) - sheet2 = workbook.create_sheet(title="Demonstrativo de Receita") - workbook.save(tabela) - workbook.close() - tamanho = len(dataframeDemonstrativoReceita) - estilo_demonstrativoDeReceita(tabela,tamanho,rowBrasilia) - - workbook = openpyxl.load_workbook(tabela) - worksheet = workbook['Demonstrativo de Receita'] + dfSemEstorno = pd.read_sql(consultaSemEstorno, engine, params=parametros) + dfComEstorno = pd.read_sql(consultaComEstorno, engine, params=parametros2) - for row_num, row_data in enumerate(dataframeDemonstrativoReceita.itertuples(index = False), start=10):#inicio linha - for col_num, value in enumerate(row_data, start=1):#inicio coluna - if col_num != 6: - worksheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) - cod_rubrica_value = row_data[5] - if cod_rubrica_value == 67 or cod_rubrica_value == 88: - worksheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='FF0000') - else: - worksheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='0000FF') - + return dfSemEstorno,dfComEstorno +#ok +def consultaRendimentosAplicacao(IDPROJETO,DATA1,DATA2): + file_path = pegar_pass("passs.txt") + conStr = '' + with open(file_path, 'r') as file: + conStr = file.readline().strip() + connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": conStr}) + engine = create_engine(connection_url) + parametros = [(IDPROJETO, DATA1, DATA2)] + consultaRendimentoAplicacao = f"SELECT DataPagamento,ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 3 and NomeTipoLancamento = 'Aplicação Financeira' AND DataPagamento BETWEEN ? AND ? order by DataPagamento" + dfConsultaRendimentoAplicacao = pd.read_sql(consultaRendimentoAplicacao, engine, params=parametros) + + consultaRendimentoEImposto = f"SELECT DataPagamento,ValorPago,NomeTipoLancamento FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 3 and (NomeTipoLancamento = 'Aplicação Financeira' or NomeTipoLancamento = 'IRRF Pessoa Jurídica') AND DataPagamento BETWEEN ? AND ? order by DataPagamento" + dfConsultaRendimentoEImposto = pd.read_sql(consultaRendimentoEImposto, engine, params=parametros) + + consultaImposto = f"SELECT DataPagamento,ValorPago FROM [Conveniar].[dbo].[LisLancamentoConvenio] WHERE CodConvenio = ? AND CodStatus = 27 AND CodRubrica = 3 and NomeTipoLancamento = 'IRRF Pessoa Jurídica' AND DataPagamento BETWEEN ? AND ? order by DataPagamento" + dfConsultaImposto = pd.read_sql(consultaImposto, engine, params=parametros) + + + return dfConsultaRendimentoAplicacao,dfConsultaImposto,dfConsultaRendimentoEImposto - - workbook.save(tabela) - workbook.close() -def relacaodeBens(codigo,data1,data2,planilha,rowBrasilia): +#preencher +#ok +def demostrativereceitaedepesaA2(codigo,data1,data2,planilha): + #carrega planilha e colocca o estilo e retorna a localização da row brasilia tabela = pegar_caminho(planilha) workbook = openpyxl.load_workbook(tabela) - nomeTabela ="Relação de Bens" - tituloStyle = "relacaoBEns" - sheet2 = workbook.create_sheet(title="Relação de Bens") - workbook.save(tabela) - workbook.close() - dfBens = consultaBens(codigo,data1,data2) - - tamanho = len(dfBens) - - estiloRelacaoBens(tabela,tamanho,tituloStyle,nomeTabela,rowBrasilia) - - workbook = openpyxl.load_workbook(tabela) - sheet = workbook['Relação de Bens'] - for row_num, row_data in enumerate(dfBens.itertuples(), start=13):#inicio linha - for col_num, value in enumerate(row_data, start=1):#inicio coluna - value = convert_datetime_to_stringdt(value) - if col_num == 7: - value = 1 - sheet.cell(row=row_num, column=col_num, value=value) - - + sheet2 = workbook.create_sheet(title="DEMOSTR. RECEITA E DESPESA A.2") workbook.save(tabela) workbook.close() + #pega as 3 tabelas da o merge e retira o tamanho com base nas rubricas chaves que ja possuem um lugar no estilo + dfComPeriodo,dfAteAData,dfPrevisto,dfRubricaRecursoRecebidos,Soma=consultaDemonstrativoReceitaEDespesaA2(codigo,data1,data2) + merged_df = pd.merge(dfPrevisto, dfComPeriodo, on='NomeRubrica', how='outer') + dfMerged = pd.merge(merged_df,dfAteAData, on = 'NomeRubrica', how = 'outer') + tamanho = len(dfMerged)#tamanho para deixar dinamico para imprimir sa rubricas + string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Importado"]).any() + if string_exists: + tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Obras e Instalações"]).any() + if string_exists: + tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Equipamentos e Material Permanente"]).any() + if string_exists: + tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Nacional"]).any() + if string_exists: + tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Receitas"]).any() + if string_exists: + tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Rendimentos de Aplicações Financeiras"]).any() + if string_exists: + tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Despesas Financeiras"]).any() + if string_exists: + tamanho = tamanho - 1 -def rendimentoDeAplicacao(codigo,data1,data2,planilha,rowBrasilia): - tabela = pegar_caminho(planilha) - workbook = openpyxl.load_workbook(tabela) - sheet2 = workbook.create_sheet(title="Rendimento de Aplicação") - workbook.save(tabela) - workbook.close() - dfConsultaRendimentoAplicacao,dfConsultaImposto,dfImpostoERendimento = consultaRendimentosAplicacao(codigo,data1,data2) - merged_df = pd.merge(dfConsultaRendimentoAplicacao, dfConsultaImposto, on='DataPagamento') - tamanho = 0 - # tamanhoMaior = lambda tamanho: len(dfConsultaRendimentoAplicacao) if len(dfConsultaRendimentoAplicacao) > len(dfConsultaImposto) else len(dfConsultaImposto) - # tamanhoMaiorParaOEstilo = tamanhoMaior(None) - tamanhoMaiorParaOEstilo = len(merged_df) - estilo_rendimento_de_aplicacao(tabela,tamanhoMaiorParaOEstilo,rowBrasilia) - - workbook = openpyxl.load_workbook(tabela) - sheet = workbook['Rendimento de Aplicação'] - - merged_df['data_formatada'] = merged_df['DataPagamento'].apply(formatarDataSemDia) - merged_df['DataPagamento'] = merged_df['data_formatada'] - merged_df = merged_df.drop('data_formatada', axis=1) - - for row_num, row_data in enumerate(merged_df.itertuples(index=False), start=14):#inicio linha - for col_num, value in enumerate(row_data, start=1):#inicio coluna - if col_num == 2: - col_num = 5 - if col_num == 3: - col_num = 6 - sheet.cell(row=row_num, column=col_num, value=value) - - workbook.save(tabela) - workbook.close() - return (len(merged_df))+14 - -def rubricaGeral(codigo,data1,data2,planilha,rowBrasilia): - #consulta todas rubricas - tabela = pegar_caminho(planilha) - dfNomeRubricaCodigoRubrica = consultaNomeRubricaCodRubrica(codigo, data1, data2) - - for index, values in dfNomeRubricaCodigoRubrica.iterrows(): - - dfConsultaProjeto = consultaProjeto(codigo, data1, data2,values['CodRubrica']) - - - if values['NomeRubrica'] == "Obrigações Tributárias e contributivas": - values['NomeRubrica'] = "Obrigações Tributárias" - if values['NomeRubrica'] == "Serviços de Terceiros Pessoa Física": - values['NomeRubrica'] = "Serviços de Terceiros PF" - if values['NomeRubrica'] == f"Obrigações Tributárias e Contributivas - 20% de OST " : - values['NomeRubrica'] = f"Obrigações Trib. - Encargos 20%" - if values['NomeRubrica'] == f"Obrigações Tributárias e contributivas " : - values['NomeRubrica'] = f"Obrigações Tributárias" - if values['NomeRubrica'] == f"Outros Serviços de Terceiros - Pessoa Física" : - values['NomeRubrica'] = f"Outros Serviços Terceiros - PF" - if values['NomeRubrica'] == f"Outros Serviços de Terceiros - Pessoa Jurídica " : - values['NomeRubrica'] = f"Outros Serviços Terceiros - PJ" - if values['NomeRubrica'] == f"Passagens e Despesas com Locomoção" : - values['NomeRubrica'] = f"Passagens e Desp. Locomoção" - if values['NomeRubrica'] == f"Despesas Operacionais e Administrativas - Finatec" : - values['NomeRubrica'] = f"Despesas Operacionais" - if values['NomeRubrica'] == f"Despesas Operacionais e Administrativas - Finatec" : - values['NomeRubrica'] = f"Despesas Operacionais" - if values['NomeRubrica'] == f"Auxílio Financeiro a Pesquisador" : - values['NomeRubrica'] = f"AuxFinanceiro Pesquisador" - if values['NomeRubrica'] == f"Equipamentos e Material Permanente" : - values['NomeRubrica'] = f"Equip e Mat Permanente" - - - - if values['NomeRubrica'] != "Rendimentos de Aplicações Financeiras" and values['NomeRubrica'] != "Despesas Financeiras" and values['NomeRubrica'] != "Receitas": - nomeTabela = values['NomeRubrica'] - tituloStyle = values['NomeRubrica'] - workbook = openpyxl.load_workbook(tabela) - sheet2 = workbook.create_sheet(title=f"{values['NomeRubrica']}") - workbook.save(tabela) - workbook.close() - - tamanho = len(dfConsultaProjeto) - estiloGeral(tabela,tamanho,tituloStyle,nomeTabela,rowBrasilia) - workbook = openpyxl.load_workbook(tabela) - sheet2 = workbook[values['NomeRubrica']] - dfConsultaProjeto.index = dfConsultaProjeto.index + 1 - for row_num, row_data in enumerate(dfConsultaProjeto.itertuples(), start=10):#inicio linha - for col_num, value in enumerate(row_data, start=1):#inicio coluna - value = convert_datetime_to_stringdt(value) - sheet2.cell(row=row_num, column=col_num, value=value) - - - workbook.save(tabela) - workbook.close() - - - - #consulta individual - return 0 - -def Receita(planilha,codigo,data1,data2,tamanhoResumo,dataframe): - #dfReceitas,dfDemonstrativoReceitas,dfIss2,dfIss5 = consultaEntradaReceitas(codigo,data1,data2) - dfReceitas,dfDemonstrativoReceitas = consultaEntradaReceitas(codigo,data1,data2) - - if len(dfReceitas) > tamanhoResumo: - tamanhoResumo = len(dfReceitas) - elif len(dataframe) > tamanhoResumo: - tamanhoResumo = len(dataframe) - + rowBrasilia = estiloDEMOSTRRECEITEDESPESAA2(planilha,tamanho) + #carregar planilha para preencher caminho = pegar_caminho(planilha) - #tamanho equipamento ja e valido pois recebeu o tamanho maior e retornou o tamanho equipamentos da string - tamanho,tamanhoequipamentos = estiloReceitaXDespesa(caminho,tamanhoResumo) - - #o tamanho na verdade tem que ser do data frame se ele for maior - - #Plan = planilha - # carrega a planilha de acordo com o caminho workbook = openpyxl.load_workbook(caminho) - sheet = workbook['Receita x Despesa'] + sheet = workbook['DEMOSTR. RECEITA E DESPESA A.2'] input_date = [] output_date_str = [] input_date2 = [] @@ -654,17 +669,23 @@ def Receita(planilha,codigo,data1,data2,tamanhoResumo,dataframe): else : return None - string_periodo = f"Período que abrange esta prestação: {output_date_str} a {output_date_str2}" - sheet['A7'] = string_periodo + string_periodo = f"de {output_date_str} a {output_date_str2}" + consulta_coordenador = consultaID(codigo) - stringCoordenador= f'H{tamanho+3}' # retorna lugar do coordanor - stringTamanhoCPF = f'H{tamanho+5}' # retorna lugar do coordanor + # o quarenta significa pra achar o lugar do coordenador dinamicamente mais o valor do tamanho da quantidade de rubricas + tamanho_row_coordenador = tamanho + 40 + stringCoordenador= f'C{tamanho_row_coordenador}' # retorna lugar do coordanor + stringTamanhoCPF = f'C{tamanho_row_coordenador+2}' # retorna lugar do coordanor sheet[stringCoordenador] = consulta_coordenador['NomePessoaResponsavel'] sheet[stringTamanhoCPF] = formatar_cpf(consulta_coordenador['CPFCoordenador']) - string_titulo = f"Título do Projeto: {consulta_coordenador['NomeConvenio']}" - string_executora = f"Executora: {consulta_coordenador['NomePessoaFinanciador']}" - string_participe = f"Partícipe: Fundação de Empreendimentos Científicos e Tecnológicos - FINATEC" + string_convenio = f"Convênio nº: {consulta_coordenador['SubProcesso']}" + string_convenente= f"Fundação de Empreendimentos Científicos e Tecnológicos - FINATEC" + string_convenente_convenente= f"Convenente: " + string_fonte_recursos = f"Fonte de Recursos:" + string_participe = f"Partícipe (no caso de contrapartida):" + string_periodo_relatorio = f"Período Abrangido por este Relatório: " + stringPeriodoExececucao = f'Período de Execução do Convênio:' # Convert 'DataAssinatura' to "dd/mm/YYYY" format datetime_obj1 = consulta_coordenador['DataAssinatura'] formatted_date1 = datetime_obj1.strftime("%d/%m/%Y") @@ -674,15 +695,22 @@ def Receita(planilha,codigo,data1,data2,tamanhoResumo,dataframe): formatted_date2 = datetime_obj2.strftime("%d/%m/%Y") # Create the string representing the period of execution - string_periodo = f"Período de Execução Físico-Financeiro: {formatted_date1} a {formatted_date2}" - sheet['A3'] = string_titulo - sheet['A4'] = string_executora - sheet['A5'] = string_participe - sheet['A6'] = string_periodo - - #dadosquefaltam = getAnalistaDoProjetoECpfCoordenador(codigo) - #sheet['H47'] = formatar_cpf(dadosquefaltam["CPF_COORDENADOR"]) + string_periodo_convenio = f"de {formatted_date1} a {formatted_date2}" + sheet['A4'] = string_convenio + sheet['A5'] = string_convenente_convenente + sheet['A6'] = stringPeriodoExececucao + sheet['A7'] = string_periodo_relatorio + sheet['A8'] = string_fonte_recursos + sheet['A9'] = string_participe + + sheet['C5'] = string_convenente + sheet['C6'] = string_periodo_convenio + sheet['C7'] = string_periodo + sheet['C8'] = f'RECURSOS FINEP/RECURSOS CONTRAPARTIDA' + sheet['C9'] = F'XXX' + + meses_dict = { 1: "Janeiro", 2: "Fevereiro", @@ -697,139 +725,182 @@ def Receita(planilha,codigo,data1,data2,tamanhoResumo,dataframe): 11: "Novembro", 12: "Dezembro" } - strintT = tamanho - stringTamanho = f'A{tamanho}' # retorna lugar de brasilia + + stringTamanho = f'A{tamanho + 37}' # retorna lugar de brasilia hoje = date.today() data_formatada = f"{hoje.day} de {meses_dict[hoje.month]} de {hoje.year}" sheet[stringTamanho] = f'Brasilia, {data_formatada}' - # tamanhoequipamentos = tamanhoequipamentos + 16 - #Obras e Instalações + + + #começar o preenchimento com o dataframe + + + rowDespesasCapital = tamanho + 13 #vai ser o valro menos 1 para n bugar os codigos de tamanho abaixo + + #TOTAL DAS RECEITAS (B1+B2) + #B.1 + #periodo receitas + if dfMerged['NomeRubrica'].isin(["Receitas"]).any(): + stringReceitas = f'C{rowDespesasCapital + 11}' + sheet[stringReceitas] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Receitas', 'VALOR_TOTAL_PERIODO'].values[0] + #Ate o perido anterior receitas + stringReceitas = f'B{rowDespesasCapital + 11}' + sheet[stringReceitas] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Receitas', 'VALOR_TOTAL_PREVISTO'].values[0] + #B.2 + #periodo Rendimentos de Aplicações Financeiras + if dfMerged['NomeRubrica'].isin(["Rendimentos de Aplicações Financeiras"]).any(): + stringRendimentosdeAplicaçõesFinanceiras = f'C{rowDespesasCapital + 12}' + sheet[stringRendimentosdeAplicaçõesFinanceiras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Rendimentos de Aplicações Financeiras', 'VALOR_TOTAL_PERIODO'].values[0] + #Ate o perido anterior Rendimentos de Aplicações Financeiras + stringRendimentosdeAplicaçõesFinanceiras = f'B{rowDespesasCapital + 12}' + sheet[stringRendimentosdeAplicaçõesFinanceiras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Rendimentos de Aplicações Financeiras', 'VALOR_TOTAL_PREVISTO'].values[0] + + + #Obras e Instalações #previsto - string_exists = dataframe['NomeRubrica'].isin(["Obras e Instalações"]).any() + string_exists = dfMerged['NomeRubrica'].isin(["Obras e Instalações"]).any() if string_exists: + stringObras = f'E{rowDespesasCapital + 2}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Obras e Instalações', 'VALOR_TOTAL_PREVISTO'].values[0] + #periodo - stringObras = f'I{tamanhoequipamentos -1}' - sheet[stringObras] = dataframe.loc[dataframe['NomeRubrica'] == 'Obras e Instalações', 'VALOR_TOTAL_PERIODO'].values[0] - + stringObras = f'C{rowDespesasCapital + 2}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Obras e Instalações', 'VALOR_TOTAL_PERIODO'].values[0] + #Ate o momento + stringObras = f'B{rowDespesasCapital + 2}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Obras e Instalações', 'VALOR_TOTAL_DATA'].values[0] - string_exists = dataframe['NomeRubrica'].isin(["Equipamentos e Material Permanente"]).any() + string_exists = dfMerged['NomeRubrica'].isin(["Equipamentos e Material Permanente"]).any() if string_exists: #Materiais Equipamentos e Material Permanente + stringObras = f'E{rowDespesasCapital + 5}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Equipamentos e Material Permanente', 'VALOR_TOTAL_PREVISTO'].values[0] + #periodo - stringObras = f'I{tamanhoequipamentos}' - sheet[stringObras] = dataframe.loc[dataframe['NomeRubrica'] == 'Equipamentos e Material Permanente', 'VALOR_TOTAL_PERIODO'].values[0] + stringObras = f'C{rowDespesasCapital + 5}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Equipamentos e Material Permanente', 'VALOR_TOTAL_PERIODO'].values[0] + #Ate o momento + stringObras = f'B{rowDespesasCapital + 5}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Equipamentos e Material Permanente', 'VALOR_TOTAL_DATA'].values[0] #Materiais Equipamentos e Material nACIONAL - string_exists = dataframe['NomeRubrica'].isin(["Material Permanente e Equipamento Nacional"]).any() + string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Nacional"]).any() if string_exists: - - #periodo - stringObras = f'I{tamanhoequipamentos +1}' - sheet[stringObras] = dataframe.loc[dataframe['NomeRubrica'] == 'Material Permanente e Equipamento Nacional', 'VALOR_TOTAL_PERIODO'].values[0] + stringObras = f'E{rowDespesasCapital + 6}' + + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Nacional', 'VALOR_TOTAL_PREVISTO'].values[0] + #periodo + stringObras = f'C{rowDespesasCapital + 6}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Nacional', 'VALOR_TOTAL_PERIODO'].values[0] + #Ate o momento + stringObras = f'B{rowDespesasCapital + 6}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Nacional', 'VALOR_TOTAL_DATA'].values[0] #Materiais Equipamentos e Material iMPORTADO - string_exists = dataframe['NomeRubrica'].isin(["Material Permanente e Equipamento Importado"]).any() + string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Importado"]).any() if string_exists: - + stringObras = f'E{rowDespesasCapital + 7}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Importado', 'VALOR_TOTAL_PREVISTO'].values[0] + #periodo - stringObras = f'I{tamanhoequipamentos + 2}' - sheet[stringObras] = dataframe.loc[dataframe['NomeRubrica'] == 'Material Permanente e Equipamento Importado', 'VALOR_TOTAL_PERIODO'].values[0] - - - - values_to_remove = ["Receitas", "Rendimentos de Aplicações Financeiras", "Despesas Financeiras",'Material Permanente e Equipamento Nacional','Material Permanente e Equipamento Importado','Equipamentos e Material Permanente','Devolução de Recursos','Encargos - ISS 5%'] - dataframe = dataframe[~dataframe['NomeRubrica'].isin(values_to_remove)] - for row_num, row_data in enumerate(dataframe.itertuples(index = False), start=16):#inicio linha - for col_num, value in enumerate(row_data, start=8):#inicio coluna - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) + stringObras = f'C{rowDespesasCapital + 7}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Importado', 'VALOR_TOTAL_PERIODO'].values[0] + #Ate o momento + stringObras = f'B{rowDespesasCapital + 7}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Importado', 'VALOR_TOTAL_DATA'].values[0] - #vai preencher o lado esquerdo da tabela a parte de receita - for row_num, row_data in enumerate(dfReceitas.itertuples(index = False), start=16):#inicio linha - for col_num, value in enumerate(row_data, start=1):#inicio coluna - - - if col_num != 6: - if col_num == 4: - col_num = 5 - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) - cod_rubrica_value = row_data[4] - if col_num ==5: - kek = row_data[3] - if cod_rubrica_value == 88 or cod_rubrica_value == 67: - kek = -row_data[3] - - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(kek)) - - - if cod_rubrica_value == 88: - if col_num == 3: - - val = f'ISS 2% {value}' - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(val)) + #remover essas linhas da tabela + values_to_remove = ["Receitas", "Rendimentos de Aplicações Financeiras", "Despesas Financeiras",'Material Permanente e Equipamento Nacional','Material Permanente e Equipamento Importado','Devolução de Recursos','Obras e Instalações','Equipamentos e Material Permanente'] - - - sheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='FF0000') - - elif cod_rubrica_value == 67: - if col_num == 3: - - vala = f'ISS 5% {value}' - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(vala)) - - sheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='FF0000') - else: - sheet.cell(row=row_num, column=5).font = Font(name='Arial', size=12, bold=True, italic=False, color='0000FF') - - #rendimentosdeapliacação - dfSoma = consultaRendimentosIRRF(codigo,data1,data2) - dfcComPeriodo = consultaDevolucaoRecursos(codigo,data1,data2) - Soma = dfSoma["Aplicação"] + dfSoma["IRRF"] - + # Use boolean indexing to drop rows based on the values in the first column + dfMerged = dfMerged[~dfMerged['NomeRubrica'].isin(values_to_remove)] - result = Soma.iloc[0] - Soma.iloc[1] - - stringRendimento = f'Rendimento de Aplicação' - stringRendimentoValor = f'E{tamanhoequipamentos + 6}' - sheet[stringRendimentoValor] = result - sheet[f'A{tamanhoequipamentos + 6}'] = stringRendimento - + string_exists = dfMerged['NomeRubrica'].isin(["Despesas Operacionais e Administrativas - Finatec"]).any() + if string_exists: + # Extract the value from "Despesas Operacionais e Administrativas - Finatec" + value_to_add = dfMerged.loc[dfMerged['NomeRubrica'] == 'Despesas Operacionais e Administrativas - Finatec'].iloc[0] + + string_exists = dfMerged['NomeRubrica'].isin(["Outros Serviços de Terceiros - Pessoa Jurídica "]).any() + string_exists2 = dfMerged['NomeRubrica'].isin(["Serviços de Terceiros Pessoa Jurídica"]).any() + string_exists3 = dfMerged['NomeRubrica'].isin(["Outros Serviços de Terceiros - Pessoa Jurídica"]).any() + + if string_exists or string_exists2 or string_exists3: + if string_exists: + + + dfMerged.loc[dfMerged['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica '] += value_to_add + + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + + if string_exists2: + + # Add the value to "Outros Serviços de Terceiros - Pessoa Jurídica" + dfMerged.loc[dfMerged['NomeRubrica'] == 'Serviços de Terceiros Pessoa Jurídica'] += value_to_add - # # #devoluçãoderecursos + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + + if string_exists3: + # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + + index_to_update = dfMerged.loc[dfMerged['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica'].index[0] + + # Add the value to "Outros Serviços de Terceiros - Pessoa Jurídica" + dfMerged.iloc[index_to_update] += value_to_add + + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + + - stringRendimentoValor = f'I{tamanhoequipamentos + 7}' - sheet[stringRendimentoValor] = dfcComPeriodo.iloc[0,0] + + - - + for row_num, row_data in enumerate(dfMerged.itertuples(index = False), start=14):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + + if col_num == 3: + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)).alignment=Alignment(horizontal="right",vertical="center",wrap_text=True) + if col_num == 1: + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)).alignment=Alignment(horizontal="left",vertical="center",wrap_text=True) + if col_num == 2: + col_num = 5 + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)).alignment=Alignment(horizontal="right",vertical="center",wrap_text=True) + #sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) + + if col_num == 4: + col_num = 2 + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)).alignment=Alignment(horizontal="right",vertical="center",wrap_text=True) + workbook.save(planilha) workbook.close() - return strintT,dfReceitas,dfDemonstrativoReceitas + + -def ExeReceitaDespesa(planilha,codigo,data1,data2,stringTamanho): + return rowBrasilia +#ok +def relatorioExecFinanceiraA1(codigo,data1,data2,planilha,rowBrasilia): tabela = pegar_caminho(planilha) workbook = openpyxl.load_workbook(tabela) - sheet2 = workbook.create_sheet(title="Exec. Receita e Despesa") + sheet2 = workbook.create_sheet(title="Relatório de Exec Financ A.1") workbook.save(tabela) workbook.close() - stringTamanho = 15 #esqueci o pq deve ser =o tamanho na tabela + dfComPeriodo,dfAteAData = consultaRelatorioExecFinanceiraA1(codigo, data1, data2) - #dataframe com os dados - dfComPeriodo,dfAteAData,dfPrevisto = consultaReceitaEExecReceita(codigo,data1,data2) - # Merge with an outer join - merged_df = pd.merge(dfPrevisto, dfComPeriodo, on='NomeRubrica', how='outer') - dfMerged = pd.merge(merged_df,dfAteAData, on = 'NomeRubrica', how = 'outer') + + dfMerged = pd.merge(dfAteAData,dfComPeriodo, on = 'NomeRubrica', how = 'outer') tamanho = len(dfMerged)#tamanho para deixar dinamico para imprimir sa rubricas string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Importado"]).any() if string_exists: @@ -843,160 +914,78 @@ def ExeReceitaDespesa(planilha,codigo,data1,data2,stringTamanho): string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Nacional"]).any() if string_exists: tamanho = tamanho - 1 - - tamanho = tamanho - 3 - - stringTamanho = tamanho + 16 - estiloExecReceitaDespesa(tabela,tamanho,stringTamanho) - #preencher - workbook = openpyxl.load_workbook(planilha) - sheet = workbook['Exec. Receita e Despesa'] - - input_date = [] - output_date_str = [] - input_date2 = [] - output_date_str2 = [] - if check_format(data1): - input_date = datetime.strptime(data1, "%Y-%m-%d") - # Format the datetime object to a string in dd/mm/yyyy format - output_date_str = input_date.strftime("%d/%m/%Y") - else : - return None - if check_format(data2): - input_date2 = datetime.strptime(data2, "%Y-%m-%d") - # Format the datetime object to a string in dd/mm/yyyy format - output_date_str2 = input_date2.strftime("%d/%m/%Y") - else : - return None + string_exists = dfMerged['NomeRubrica'].isin(["Receitas"]).any() + if string_exists: + tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Rendimentos de Aplicações Financeiras"]).any() + if string_exists: + tamanho = tamanho - 1 + string_exists = dfMerged['NomeRubrica'].isin(["Despesas Financeiras"]).any() + if string_exists: + tamanho = tamanho - 1 - string_periodo = f"Período que abrange esta prestação: {output_date_str} a {output_date_str2}" - sheet['A7'] = string_periodo - consulta_coordenador = consultaID(codigo) - stringCoordenador= f'F{stringTamanho+11}' # retorna lugar do coordanor - stringCoordanadorCargo = f'F{stringTamanho+12}' - sheet[stringCoordanadorCargo] = f"Coordenador(a)" - stringTamanhoCPF = f'F{stringTamanho+13}' # retorna lugar do coordanor - sheet[stringCoordenador] = consulta_coordenador['NomePessoaResponsavel'] - sheet[stringTamanhoCPF] = formatar_cpf(consulta_coordenador['CPFCoordenador']) - string_titulo = f"Título do Projeto: {consulta_coordenador['NomeConvenio']}" - string_executora = f"Executora: {consulta_coordenador['NomePessoaFinanciador']}" - string_participe = f"Partícipe: Fundação de Empreendimentos Científicos e Tecnológicos - FINATEC" - # Convert 'DataAssinatura' to "dd/mm/YYYY" format - datetime_obj1 = consulta_coordenador['DataAssinatura'] - formatted_date1 = datetime_obj1.strftime("%d/%m/%Y") - # Convert 'DataVigencia' to "dd/mm/YYYY" format - datetime_obj2 = consulta_coordenador['DataVigencia'] - formatted_date2 = datetime_obj2.strftime("%d/%m/%Y") + + rowDespesasCapital = estiloRelatorioExecFinanceiroA1(tabela,tamanho,rowBrasilia) -# Create the string representing the period of execution - string_periodo = f"Período de Execução Físico-Financeiro: {formatted_date1} a {formatted_date2}" - sheet['A3'] = string_titulo - sheet['A4'] = string_executora - sheet['A5'] = string_participe - sheet['A6'] = string_periodo - - #dadosquefaltam = getAnalistaDoProjetoECpfCoordenador(codigo) - #sheet['H47'] = formatar_cpf(dadosquefaltam["CPF_COORDENADOR"]) - meses_dict = { - 1: "Janeiro", - 2: "Fevereiro", - 3: "Março", - 4: "Abril", - 5: "Maio", - 6: "Junho", - 7: "Julho", - 8: "Agosto", - 9: "Setembro", - 10: "Outubro", - 11: "Novembro", - 12: "Dezembro" -} - stringTamanhoBrasilia = f'A{stringTamanho+10}' # retorna lugar de brasilia - hoje = date.today() - data_formatada = f"{hoje.day} de {meses_dict[hoje.month]} de {hoje.year}" - sheet[stringTamanhoBrasilia] = f'Brasilia, {data_formatada}' - #despesas correntes - imprimirResumoLinha = 16 + caminho = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(caminho) + sheet = workbook['Relatório de Exec Financ A.1'] + + #Obras e Instalações #previsto string_exists = dfMerged['NomeRubrica'].isin(["Obras e Instalações"]).any() if string_exists: - stringObras = f'B{stringTamanho + 2}' - sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Obras e Instalações', 'VALOR_TOTAL_PREVISTO'].values[0] - stringObras = f'F{stringTamanho + 2}' - sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Obras e Instalações', 'VALOR_TOTAL_PREVISTO'].values[0] + #periodo - stringObras = f'C{stringTamanho + 2}' + stringObras = f'F{rowDespesasCapital + 1}' sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Obras e Instalações', 'VALOR_TOTAL_PERIODO'].values[0] #Ate o momento - stringObras = f'G{stringTamanho + 2}' + stringObras = f'B{rowDespesasCapital + 1}' sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Obras e Instalações', 'VALOR_TOTAL_DATA'].values[0] string_exists = dfMerged['NomeRubrica'].isin(["Equipamentos e Material Permanente"]).any() if string_exists: #Materiais Equipamentos e Material Permanente - stringObras = f'B{stringTamanho + 3}' - sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Equipamentos e Material Permanente', 'VALOR_TOTAL_PREVISTO'].values[0] - stringObras = f'F{stringTamanho + 3}' - sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Equipamentos e Material Permanente', 'VALOR_TOTAL_PREVISTO'].values[0] + + #periodo - stringObras = f'C{stringTamanho + 3}' + stringObras = f'F{rowDespesasCapital + 4}' sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Equipamentos e Material Permanente', 'VALOR_TOTAL_PERIODO'].values[0] #Ate o momento - stringObras = f'G{stringTamanho + 3}' - #sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Obras e Instalações', 'VALOR_TOTAL_DATA'].values[0] + stringObras = f'B{rowDespesasCapital + 4}' + sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Equipamentos e Material Permanente', 'VALOR_TOTAL_DATA'].values[0] #Materiais Equipamentos e Material nACIONAL string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Nacional"]).any() if string_exists: - stringObras = f'B{stringTamanho + 4}' - sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Nacional', 'VALOR_TOTAL_PREVISTO'].values[0] - stringObras = f'F{stringTamanho + 4}' - sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Nacional', 'VALOR_TOTAL_PREVISTO'].values[0] + + #periodo - stringObras = f'C{stringTamanho + 4}' + stringObras = f'F{rowDespesasCapital + 5}' sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Nacional', 'VALOR_TOTAL_PERIODO'].values[0] #Ate o momento - stringObras = f'G{stringTamanho + 4}' + stringObras = f'B{rowDespesasCapital + 5}' sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Nacional', 'VALOR_TOTAL_DATA'].values[0] #Materiais Equipamentos e Material iMPORTADO string_exists = dfMerged['NomeRubrica'].isin(["Material Permanente e Equipamento Importado"]).any() if string_exists: - stringObras = f'B{stringTamanho + 5}' - sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Importado', 'VALOR_TOTAL_PREVISTO'].values[0] - stringObras = f'F{stringTamanho + 5}' - sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Importado', 'VALOR_TOTAL_PREVISTO'].values[0] + #periodo - stringObras = f'C{stringTamanho + 5}' + stringObras = f'F{rowDespesasCapital + 6}' sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Importado', 'VALOR_TOTAL_PERIODO'].values[0] #Ate o momento - stringObras = f'G{stringTamanho + 5}' + stringObras = f'B{rowDespesasCapital + 6}' sheet[stringObras] = dfMerged.loc[dfMerged['NomeRubrica'] == 'Material Permanente e Equipamento Importado', 'VALOR_TOTAL_DATA'].values[0] - dfSoma = consultaRendimentosIRRF(codigo,data1,data2) - dfRendimentoAteOPeriodo = consultaRendimentosTodosAteOPeriodo(codigo,data2) - - Soma = dfSoma["Aplicação"] + dfSoma["IRRF"] - - result = Soma.iloc[0] - Soma.iloc[1] - stringObras = f'B{stringTamanho + 7}' - sheet[stringObras] = result - - SomaRendimentoAteoperido = dfRendimentoAteOPeriodo["Aplicação"] + dfRendimentoAteOPeriodo["IRRF"] - resultado = SomaRendimentoAteoperido.iloc[0] - SomaRendimentoAteoperido.iloc[1] - stringObras = f'F{stringTamanho + 7}' - sheet[stringObras] = resultado - - - #remover essas linhas da tabela @@ -1004,62 +993,556 @@ def ExeReceitaDespesa(planilha,codigo,data1,data2,stringTamanho): # Use boolean indexing to drop rows based on the values in the first column dfMerged = dfMerged[~dfMerged['NomeRubrica'].isin(values_to_remove)] - for row_num, row_data in enumerate(dfMerged.itertuples(index = False), start=16):#inicio linha + + + + string_exists = dfMerged['NomeRubrica'].isin(["Despesas Operacionais e Administrativas - Finatec"]).any() + if string_exists: + # Extract the value from "Despesas Operacionais e Administrativas - Finatec" + value_to_add = dfMerged.loc[dfMerged['NomeRubrica'] == 'Despesas Operacionais e Administrativas - Finatec'].iloc[0] + + string_exists = dfMerged['NomeRubrica'].isin(["Outros Serviços de Terceiros - Pessoa Jurídica "]).any() + string_exists2 = dfMerged['NomeRubrica'].isin(["Serviços de Terceiros Pessoa Jurídica"]).any() + string_exists3 = dfMerged['NomeRubrica'].isin(["Outros Serviços de Terceiros - Pessoa Jurídica"]).any() + + if string_exists or string_exists2 or string_exists3: + if string_exists: + + + dfMerged.loc[dfMerged['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica '] += value_to_add + + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + + if string_exists2: + + + # Add the value to "Outros Serviços de Terceiros - Pessoa Jurídica" + dfMerged.loc[dfMerged['NomeRubrica'] == 'Serviços de Terceiros Pessoa Jurídica'] += value_to_add + + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + + if string_exists3: + # Find the index of "Outros Serviços de Terceiros - Pessoa Jurídica" + + index_to_update = dfMerged.loc[dfMerged['NomeRubrica'] == 'Outros Serviços de Terceiros - Pessoa Jurídica'].index[0] + + # Add the value to "Outros Serviços de Terceiros - Pessoa Jurídica" + dfMerged.iloc[index_to_update] += value_to_add + + # Drop the row for "Despesas Operacionais e Administrativas - Finatec" + dfMerged = dfMerged[dfMerged['NomeRubrica'] != 'Despesas Operacionais e Administrativas - Finatec'] + + + + + + for row_num, row_data in enumerate(dfMerged.itertuples(index = False), start=12):#inicio linha for col_num, value in enumerate(row_data, start=1):#inicio coluna + + + if col_num == 1: + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)).alignment=Alignment(horizontal="left",vertical="center",wrap_text=True) if col_num == 2: - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) col_num = 6 - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) - col_num=2 + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)).alignment=Alignment(horizontal="right",vertical="center",wrap_text=True) + #sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) + if col_num == 3: + col_num = 2 + sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)).alignment=Alignment(horizontal="right",vertical="center",wrap_text=True) + - if col_num == 4: - col_num = 7 - sheet.cell(row=row_num, column=col_num, value=convert_datetime_to_string(value)) - + + + #PREENCHER CABECARIO + input_date = [] + output_date_str = [] + input_date2 = [] + output_date_str2 = [] + if check_format(data1): + input_date = datetime.strptime(data1, "%Y-%m-%d") + # Format the datetime object to a string in dd/mm/yyyy format + output_date_str = input_date.strftime("%d/%m/%Y") + else : + return None + if check_format(data2): + input_date2 = datetime.strptime(data2, "%Y-%m-%d") + # Format the datetime object to a string in dd/mm/yyyy format + output_date_str2 = input_date2.strftime("%d/%m/%Y") + else : + return None + + string_periodo = f"de {output_date_str} a {output_date_str2}" + + + consulta_coordenador = consultaID(codigo) + + # o quarenta significa pra achar o lugar do coordenador dinamicamente mais o valor do tamanho da quantidade de rubricas + tamanho_row_coordenador = tamanho + 40 + stringCoordenador= f'C{tamanho_row_coordenador}' # retorna lugar do coordanor + stringTamanhoCPF = f'C{tamanho_row_coordenador+2}' # retorna lugar do coordanor + sheet[stringCoordenador] = consulta_coordenador['NomePessoaResponsavel'] + sheet[stringTamanhoCPF] = formatar_cpf(consulta_coordenador['CPFCoordenador']) + string_convenio = f"Convênio nº: {consulta_coordenador['NomeConvenio']}" + string_convenente= f"Fundação de Empreendimentos Científicos e Tecnológicos - FINATEC" + string_convenente_convenente= f"Convenente: " + string_fonte_recursos = f"Fonte de Recursos:" + string_participe = f"Partícipe (no caso de contrapartida):" + string_periodo_relatorio = f"Período Abrangido por este Relatório: " + stringPeriodoExececucao = f'Período de Execução do Convênio:' + # Convert 'DataAssinatura' to "dd/mm/YYYY" format + datetime_obj1 = consulta_coordenador['DataAssinatura'] + formatted_date1 = datetime_obj1.strftime("%d/%m/%Y") + + # Convert 'DataVigencia' to "dd/mm/YYYY" format + datetime_obj2 = consulta_coordenador['DataVigencia'] + formatted_date2 = datetime_obj2.strftime("%d/%m/%Y") + +# Create the string representing the period of execution + + string_periodo_convenio = f"de {formatted_date1} a {formatted_date2}" + sheet['A4'] = string_convenio + sheet['A5'] = string_convenente_convenente + sheet['A6'] = stringPeriodoExececucao + sheet['A7'] = string_periodo_relatorio + + + sheet['C5'] = string_convenente + sheet['C6'] = string_periodo_convenio + sheet['C7'] = string_periodo + + + + + workbook.save(planilha) + workbook.close() + + + + + return 0 +#ok +def PagamentoDePessoal(codigo,data1,data2,planilha,rowBrasilia): + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title="Pagamento de Pessoal") + sheet2['B11'] = f'Pagamento de Pessoal (Vencimentos e Vantagens Fixas, Obrigações Patronais e Benefícios)' + sheet2['B11'].font = Font(name="Arial", size=12, color="000000",bold=True) + workbook.save(tabela) + workbook.close() + + #recebeOsDataFrames + dfconsultaDadosPorRubrica,dfconsultaDadosPorRubricaComEstorno = consultaPagamentoPessoal(codigo,data1,data2) + + tamanho = len(dfconsultaDadosPorRubrica) + tamanhoestorno = len(dfconsultaDadosPorRubricaComEstorno) + + + rowEstorno = estiloPagamentoPessoal(tabela,tamanho,rowBrasilia,tamanhoestorno) + + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook['Pagamento de Pessoal'] + + dfconsultaDadosPorRubrica.index = dfconsultaDadosPorRubrica.index + 1 + for row_num, row_data in enumerate(dfconsultaDadosPorRubrica.itertuples(), start=16):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + # dfconsultaDadosPorRubricaComEstorno.index = dfconsultaDadosPorRubricaComEstorno.index + 1 + + + + + # + dfconsultaDadosPorRubricaComEstorno.insert(0, "col1", None) + dfconsultaDadosPorRubricaComEstorno.insert(5, 'Col2', None) + dfconsultaDadosPorRubricaComEstorno.insert(6, 'Col3', None) + + + for row_num, row_data in enumerate(dfconsultaDadosPorRubricaComEstorno.itertuples(index=False), start=rowEstorno): #inicio linha + for col_num, value in enumerate(row_data, start=1): #inicio coluna + + + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + workbook.save(tabela) + workbook.close() + + + + return 0 +#ok +def ElementoDeDespesa1415Diarias(codigo,data1,data2,planilha,rowBrasilia): + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title="Elemento de Despesa 14.15") + sheet2['B11'] = f'14/15 - Diárias (Pessoal Civil/Militar)' + sheet2['B11'].font = Font(name="Arial", size=12, color="000000",bold=True) + workbook.save(tabela) + workbook.close() + + dfconsultaDadosPorRubrica,dfconsultaDadosPorRubricaComEstorno = consultaestiloElementoDeDespesa1415Diarias(codigo,data1,data2) + + tamanho = len(dfconsultaDadosPorRubrica) + tamanhoestorno = len(dfconsultaDadosPorRubricaComEstorno) + + + rowEstorno = estiloElementoDeDespesa1415Diarias(tabela,tamanho,rowBrasilia,tamanhoestorno) + + + + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook['Elemento de Despesa 14.15'] + + #print(dfconsultaDadosPorRubrica.columns.values.tolist()) + + dfconsultaDadosPorRubrica.index = dfconsultaDadosPorRubrica.index + 1 + for row_num, row_data in enumerate(dfconsultaDadosPorRubrica.itertuples(), start=16):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + # dfconsultaDadosPorRubricaComEstorno.index = dfconsultaDadosPorRubricaComEstorno.index + 1 + + + + + # + dfconsultaDadosPorRubricaComEstorno.insert(0, "col1", None) + dfconsultaDadosPorRubricaComEstorno.insert(5, 'Col2', None) + dfconsultaDadosPorRubricaComEstorno.insert(6, 'Col3', None) + + + for row_num, row_data in enumerate(dfconsultaDadosPorRubricaComEstorno.itertuples(index=False), start=rowEstorno): #inicio linha + for col_num, value in enumerate(row_data, start=1): #inicio coluna + + + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + workbook.save(tabela) + workbook.close() + + + + + return 0 +#ok +def geral30(codigo,data1,data2,planilha,rowBrasilia): + tabela = pegar_caminho(planilha) + dfNomeRubricaCodigoRubrica = consultaNomeRubricaCodRubrica(codigo, data1, data2) + for index, values in dfNomeRubricaCodigoRubrica.iterrows(): + dfPJDOA,dfPJDOAESTORNO,dfConsultaProjeto ,dfconsultaDadosPorRubricaComEstorno= consultaGeral30(codigo,data1,data2,values['CodRubrica']) + + if values['NomeRubrica'] == "Obrigações Tributárias e contributivas": + values['NomeRubrica'] = "Obrigações Tributárias" + if values['NomeRubrica'] == "Material Permanente e Equipamento Nacional": + values['NomeRubrica'] = "Equipamento Material Nacional" + if values['NomeRubrica'] == "Serviços de Terceiros Pessoa Física": + values['NomeRubrica'] = "Serviços de Terceiros PF" + if values['NomeRubrica'] == f"Obrigações Tributárias e Contributivas - 20% de OST " : + values['NomeRubrica'] = f"Obrigações Trib. - Encargos 20%" + if values['NomeRubrica'] == f"Obrigações Tributárias e contributivas " : + values['NomeRubrica'] = f"Obrigações Tributárias" + if values['NomeRubrica'] == f"Outros Serviços de Terceiros - Pessoa Física" : + values['NomeRubrica'] = f"Outros Serviços Terceiros - PF" + if values['NomeRubrica'] == f"Outros Serviços de Terceiros - Pessoa Jurídica " : + values['NomeRubrica'] = f"Outros Serviços Terceiros - PJ" + if values['NomeRubrica'] == f"Passagens e Despesas com Locomoção" : + values['NomeRubrica'] = f"Passagens e Desp. Locomoção" + if values['NomeRubrica'] == f"Despesas Operacionais e Administrativas - Finatec" : + values['NomeRubrica'] = f"Despesas Operacionais" + if values['NomeRubrica'] == f"Despesas Operacionais e Administrativas - Finatec" : + values['NomeRubrica'] = f"Despesas Operacionais" + if values['NomeRubrica'] == f"Auxílio Financeiro a Pesquisador" : + values['NomeRubrica'] = f"AuxFinanceiro Pesquisador" + if values['NomeRubrica'] == f"Equipamentos e Material Permanente" : + values['NomeRubrica'] = f"Equip e Mat Permanente" + if values['NomeRubrica'] == f"Material Permanente e Equipamento Importado" : + values['NomeRubrica'] = f"Equipamento Material Importado" + + + + + + if values['NomeRubrica'] == "Outros Serviços Terceiros - PJ" or values['NomeRubrica'] == "Serviços de Terceiros Pessoa Jurídica": + values['NomeRubrica'] = "Outros Serviços Terceiros -PJ" + nomeTabela = values['NomeRubrica'] + tituloStyle = values['NomeRubrica'] + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title=f"{values['NomeRubrica']}") + sheet2['B11'] = values['NomeRubrica'] + sheet2['B11'].font = Font(name="Arial", size=12, color="000000",bold=True) + workbook.save(tabela) + workbook.close() + + + tamanho = len(dfPJDOA) + tamanhoRetorno = len(dfPJDOAESTORNO) + + rownovo = estiloG(tabela,tamanho,tituloStyle,nomeTabela,rowBrasilia,tamanhoRetorno) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook[values['NomeRubrica']] + dfPJDOA.index = dfPJDOA.index + 1 + for row_num, row_data in enumerate(dfPJDOA.itertuples(), start=16):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + dfPJDOAESTORNO.insert(0, "col1", None) + dfPJDOAESTORNO.insert(4, 'Col2', None) + dfPJDOAESTORNO.insert(4, 'Col3', None) + rownovo = rownovo + for row_num, row_data in enumerate(dfPJDOAESTORNO.itertuples(index=False), start=rownovo): #inicio linha + for col_num, value in enumerate(row_data, start=1): #inicio coluna + if col_num == 5: + continue + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + workbook.save(tabela) + workbook.close() + + + else: + excluded_values = ["Rendimentos de Aplicações Financeiras", + "Despesas Financeiras", + "Receitas", + "Devolução de Recursos", + "Outros Serviços Terceiros - PJ", + "Despesas Operacionais", + 'Passagens e Despesas com Locomoção', + "Diárias", + "Diárias - Celetistas", + "Diárias - Colaborador Eventual no País", + "Diárias - Pesquisadores", + "Diárias - Servidores Públicos", + "Diárias Internacional", + "Passagens e Desp. Locomoção", + 'Pagamento de Pessoal', + "Diárias Nacionais"] + + if values['NomeRubrica'] not in excluded_values: + + nomeTabela = values['NomeRubrica'] + tituloStyle = values['NomeRubrica'] + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title=f"{values['NomeRubrica']}") + sheet2['B11'] = values['NomeRubrica'] + sheet2['B11'].font = Font(name="Arial", size=12, color="000000",bold=True) + workbook.save(tabela) + workbook.close() + + tamanho = len(dfConsultaProjeto) + tamanhoRetorno = len(dfconsultaDadosPorRubricaComEstorno) + + + + rowEstorno = estiloG(tabela,tamanho,tituloStyle,nomeTabela,rowBrasilia,tamanhoRetorno) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook[values['NomeRubrica']] + dfConsultaProjeto.index = dfConsultaProjeto.index + 1 + for row_num, row_data in enumerate(dfConsultaProjeto.itertuples(), start=16):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + # dfconsultaDadosPorRubricaComEstorno.index = dfconsultaDadosPorRubricaComEstorno.index + 1 + rowEstorno = rowEstorno + # + tamanhoDf = len(dfconsultaDadosPorRubricaComEstorno) + dfconsultaDadosPorRubricaComEstorno.insert(0, "col1", None) + dfconsultaDadosPorRubricaComEstorno.insert(4, 'Col2', None) + dfconsultaDadosPorRubricaComEstorno.insert(4, 'Col3', None) + + + + + + for row_num, row_data in enumerate(dfconsultaDadosPorRubricaComEstorno.itertuples(index=False), start=rowEstorno): #inicio linha + for col_num, value in enumerate(row_data, start=1): #inicio coluna + + if col_num == 5: + continue + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + workbook.save(tabela) + workbook.close() +#ok +def PassagensEDespesa33(codigo,data1,data2,planilha,rowBrasilia): + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title="Elemento de Despesa 33") + sheet2['B11'] = f'33 - Passagens e Despesas com Locomoção' + sheet2['B11'].font = Font(name="Arial", size=12, color="000000",bold=True) + workbook.save(tabela) + workbook.close() + dfconsultaDadosPorRubrica,dfconsultaDadosPorRubricaComEstorno = consultaestiloElementoDeDespesa33PassagemEDespesa(codigo,data1,data2) + tamanho = len(dfconsultaDadosPorRubrica) + tamanhoestorno = len(dfconsultaDadosPorRubricaComEstorno) + rowEstorno = estiloElementoDeDespesa33PassagensEDespesa(tabela,tamanho,rowBrasilia,tamanhoestorno) + + + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook['Elemento de Despesa 33'] + dfconsultaDadosPorRubrica.index = dfconsultaDadosPorRubrica.index + 1 + dfconsultaDadosPorRubrica.insert(2, "col1", None) + dfconsultaDadosPorRubrica.insert(3, 'Col2', None) + dfconsultaDadosPorRubrica.insert(4, 'Col3', None) + for row_num, row_data in enumerate(dfconsultaDadosPorRubrica.itertuples(), start=16):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + # dfconsultaDadosPorRubricaComEstorno.index = dfconsultaDadosPorRubricaComEstorno.index + 1 + + + + + # + dfconsultaDadosPorRubricaComEstorno.insert(0, "col0", None) + dfconsultaDadosPorRubricaComEstorno.insert(3, "col1", None) + dfconsultaDadosPorRubricaComEstorno.insert(4, 'Col2', None) + dfconsultaDadosPorRubricaComEstorno.insert(5, 'Col3', None) + dfconsultaDadosPorRubricaComEstorno.insert(7, 'Col4', None) + dfconsultaDadosPorRubricaComEstorno.insert(8, 'Col5', None) + - workbook.save(planilha) + for row_num, row_data in enumerate(dfconsultaDadosPorRubricaComEstorno.itertuples(index=False), start=rowEstorno): #inicio linha + for col_num, value in enumerate(row_data, start=1): #inicio coluna + + + value = convert_datetime_to_stringdt(value) + sheet2.cell(row=row_num, column=col_num, value=value) + + workbook.save(tabela) workbook.close() - return tamanho,dfComPeriodo -def preencheFinep(codigo,data1,data2,tabela): - '''Preencher fub legado - dadoRubrica = transforma em dicionario a consulta feita por sql e separa por rubricas. - variaveisResumo= preenchimento da tabela Exec, são definidas em tres tipos: - -variavelResumoComPeriodo = consulta no sql com datas1 e data2 - -variavelResumoComPeriodo = consulta no sql ate o periodo da data2 - -variavelResumoComPeriodo = consulta no sql com valor total previsto - execReceitaDespesa = preenche a sheet Exec.Receita e Despesa da planilha, - e retorna 3 argumentos: - -tamanho = o tamanho necessario para fazer o estilo, ele varia de acordo - com a quantidade de rubricas - -dictPraCalcularTamanho = o dicionario utilizado para calcular o tamanho, ele - contem a rubricas utilizadas no projeto para poder preencher a sheet ReceitaxDespesa - -merged_dict = dicionario que contem todas as rubricas inclusive equipamento e - material permanente, utilizado para colocar esses valores na ReceitaxDespesa + + + return 0 +#ok +def relacaoBensAdquiridosA5(codigo,data1,data2,planilha,rowBrasilia): + #consult aprojeto 07318 monte de bens imobilizaos, 6995,7311 + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title="Relação Bens Adquiridos A.5") + workbook.save(tabela) + workbook.close() + dfConsultaBens = consultaBens(codigo,data1,data2) + estiloRelacaoBens(tabela,len(dfConsultaBens),rowBrasilia) + + + + dfConsultaBens.insert(6, "col1", 1) + + + + + + workbook = openpyxl.load_workbook(tabela) + sheet = workbook['Relação Bens Adquiridos A.5'] + for row_num, row_data in enumerate(dfConsultaBens.itertuples(), start=15):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + value = re.sub("[^a-zA-ZÀ-ÿ0-9º+-//]", " ", str(value)) + value = convert_datetime_to_stringdt(value) + + sheet.cell(row=row_num, column=col_num, value=value) + + + + + + workbook.save(tabela) + workbook.close() + + return 0 +#ok +def rendimentoAplicacao(codigo,data1,data2,planilha,rowBrasilia): + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title="Rendimento de Aplicação") + workbook.save(tabela) + workbook.close() + + dfConsultaRendimentoAplicacao,dfConsultaImposto,dfConsultaRendimentoEImposto = consultaRendimentosAplicacao(codigo,data1,data2) + merged_df = pd.merge(dfConsultaRendimentoAplicacao, dfConsultaImposto, on='DataPagamento') + estilo_rendimento_de_aplicacao(tabela,len(merged_df),rowBrasilia) + + workbook = openpyxl.load_workbook(tabela) + sheet = workbook['Rendimento de Aplicação'] + + merged_df['data_formatada'] = merged_df['DataPagamento'].apply(formatarDataSemDia) + merged_df['DataPagamento'] = merged_df['data_formatada'] + merged_df = merged_df.drop('data_formatada', axis=1) + + for row_num, row_data in enumerate(merged_df.itertuples(index=False), start=15):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + if col_num == 2: + col_num = 5 + if col_num == 3: + col_num = 6 + sheet.cell(row=row_num, column=col_num, value=value).number_format = 'R$ #,##0.00' + + + workbook.save(tabela) + workbook.close() + return 0 +#ok +def conciliacaoBancaria(codigo,data1,data2,planilha,rowBrasilia): + tabela = pegar_caminho(planilha) + workbook = openpyxl.load_workbook(tabela) + sheet2 = workbook.create_sheet(title="Conciliação Bancária A.3") + workbook.save(tabela) + workbook.close() + dfSemEstorno,dfComEstorno = consultaConciliacaoBancaria(codigo,data1,data2) + estorno = estilo_conciliacoes_bancaria(tabela,len(dfSemEstorno)+1,len(dfComEstorno),rowBrasilia) + + workb = openpyxl.load_workbook(tabela) + worksheet333 = workb["Conciliação Bancária A.3"] + + for row_num, row_data in enumerate(dfSemEstorno.itertuples(index=False), start=19):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + worksheet333.cell(row=row_num, column=col_num, value=value) + + for row_num, row_data in enumerate(dfComEstorno.itertuples(index=False), start=estorno):#inicio linha + for col_num, value in enumerate(row_data, start=1):#inicio coluna + worksheet333.cell(row=row_num, column=col_num, value=value) + + workb.save(tabela) + workb.close + return 0 +#ok +def preencheFinep(codigo,data1,data2,tabela): + '''Preenche a planilha finep - Argumentos: + Argumentos: codigo = CodConvenio na tabela nova, corresponde ao codigo do projeto DATA1 = Data Inicial Selecinado pelo Usuario DATA2 = Data Final Selecionado pelo Usuario - KEYS = Lista responsavel por filtrar no dicionario quais dados irão ser preenchidos nas - planilhas, exemplo cpf,data etc tabela = tabela a ser preenchida extensão xlsx - - - ''' - tamanho,dataframe = ExeReceitaDespesa(tabela,codigo,data1,data2,15) - tamanhoPosicaoBrasilia,dfReceitas,dfDemonstrativoReceitas = Receita(tabela,codigo,data1,data2,tamanho,dataframe) - demonstrativo(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia,dfDemonstrativoReceitas,dfReceitas) - # tamanhoPosicaoBrasilia,dfReceitas,dfDemonstrativoReceitas,dfIss2,dfIss5 = Receita(tabela,codigo,data1,data2,tamanho,dataframe) - # demonstrativo(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia,dfDemonstrativoReceitas,dfReceitas,dfIss2,dfIss5) - rubricaGeral(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia) - conciliacaoBancaria(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia) - rowRendimento= rendimentoDeAplicacao(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia) - - relacaodeBens(codigo,data1,data2,tabela,tamanhoPosicaoBrasilia) + ''' + planilhaGeral(tabela,codigo,data1,data2) + rowBrasilia = demostrativereceitaedepesaA2(codigo,data1,data2,tabela) + relatorioExecFinanceiraA1(codigo,data1,data2,tabela,rowBrasilia) + PagamentoDePessoal(codigo,data1,data2,tabela,rowBrasilia) + ElementoDeDespesa1415Diarias(codigo,data1,data2,tabela,rowBrasilia) + PassagensEDespesa33(codigo,data1,data2,tabela,rowBrasilia) + geral30(codigo,data1,data2,tabela,rowBrasilia) + relacaoBensAdquiridosA5(codigo,data1,data2,tabela,rowBrasilia) + rendimentoAplicacao(codigo,data1,data2,tabela,rowBrasilia) + conciliacaoBancaria(codigo,data1,data2,tabela,rowBrasilia) + \ No newline at end of file diff --git a/project/app/testeDelete.py b/project/app/testeDelete.py new file mode 100644 index 00000000..dbeac560 --- /dev/null +++ b/project/app/testeDelete.py @@ -0,0 +1,33 @@ +import os + +def deletar_arquivos_em_pasta(caminho_da_pasta): + # Verificar se o caminho é um diretório + if os.path.isdir(caminho_da_pasta): + # Listar todos os arquivos na pasta + arquivos = os.listdir(caminho_da_pasta) + # Imprimir o nome de cada arquivo + for arquivo in arquivos: + # Verificar se o arquivo é um arquivo XLSX + if arquivo.endswith('.xlsx'): + # Construir o caminho completo do arquivo + caminho_arquivo = os.path.join(caminho_da_pasta, arquivo) + # Tentar excluir o arquivo + try: + os.remove(caminho_arquivo) + print(f"Arquivo {arquivo} excluído com sucesso.") + except OSError as e: + print(f"Erro ao excluir o arquivo {arquivo}: {e}") + + else: + print("O caminho especificado não é um diretório.") + +# # Caminho da pasta de planilhas preenchidas +# caminhoPastaPlanilhasPreenchidas = "../../planilhas_preenchidas/" + + +# # +# diretorio_atual = os.path.dirname(os.path.abspath(__file__)) +# testeCaminho = os.path.join(diretorio_atual, caminhoPastaPlanilhasPreenchidas) + +# # Chamar a função para listar e imprimir os arquivos na pasta +# listar_arquivos_em_pasta(testeCaminho) \ No newline at end of file diff --git a/project/app/views.py b/project/app/views.py index 5d76cd77..f7ceda30 100755 --- a/project/app/views.py +++ b/project/app/views.py @@ -1,5 +1,6 @@ import os import datetime + import re from django.shortcuts import render from django.contrib.auth.decorators import user_passes_test @@ -15,14 +16,18 @@ from .models import Template, Employee # from .oracle_cruds import consultaPorID from .new_dev import preenche_planilha,extrair,pegar_caminho -from .preenche_fundep import preenche_fundep -from .preencheFub import consultaID,preencheFub from .preencherFinep import preencheFinep -from .capa import inserir_round_retangulo +from .preencheFundep import preenche_fundep +from .preencheFap import preencheFap +from .preencheFub import consultaID,preencheFub +#from .preencherFinep import preencheFinep +from .capaFub import inserir_round_retangulo +from .capaGeral import inserir_round_retanguloGeral from django.contrib.admin.models import LogEntry from .models import UserActivity from django.core.paginator import Paginator from django.contrib import messages +from .testeDelete import deletar_arquivos_em_pasta # from backend.consultas_oracledb import getlimitedRows,getallRows from backend.consultaSQLServer import consultaCodConvenio, consultaTudo import pandas as pd @@ -34,6 +39,14 @@ def convert_datetime_to_string(value): if isinstance(value, datetime.datetime): return value.strftime('%d/%m/%Y') return value +def convert_datetime_to_string2(value): + # Convert string to datetime object + date_object = datetime.datetime.strptime(value, "%Y-%m-%d") + + # Format the datetime object to the desired format + formatted_date = date_object.strftime("%d.%m.%Y") + + return formatted_date def extract_strings(input_string): # Use regular expressions to find the text before and after '@@' @@ -152,55 +165,64 @@ def projeto_legacy(request): # Obtém o diretório atual do script diretorio_atual = os.path.dirname(os.path.abspath(__file__)) - # Combina o diretório atual com o caminho para a pasta "planilhas_preenchidas" e o nome do arquivo + #deletar planilhas preendhidas + testeCaminho = os.path.join(diretorio_atual, caminhoPastaPlanilhasPreenchidas) + deletar_arquivos_em_pasta(testeCaminho) + + + #corrigindo datas + consultaInicial = convert_datetime_to_string2(consultaInicio) + consultaFinal = convert_datetime_to_string2(consultaFim) + + print(consultaFinal) if nome.nome_template == "fundep": + # Combina o diretório atual com o caminho para a pasta "planilhas_preenchidas" e o nome do arquivo testeCaminhoFundep = os.path.join(diretorio_atual, caminho_pasta_planilhas, f"ModeloFUNDEP.xlsx") - preenche_planilha(testeCaminhoFundep,dict_final) + preenche_planilha(testeCaminhoFundep,dict_final,codigo,template_id,consultaInicial,consultaFinal,stringNomeFinanciador='FUNDEP') if nome.nome_template == "fub": testeCaminhoFub = os.path.join(diretorio_atual, caminho_pasta_planilhas, f"Modelo_Fub.xlsx") - preenche_planilha(testeCaminhoFub,dict_final) - if nome.nome_template == "opas": - opas = os.path.join(caminho_pasta_planilhas, "ModeloOPAS.xlsx") - preenche_planilha(opas,dict_final) + preenche_planilha(testeCaminhoFub,dict_final,codigo,template_id,consultaInicial,consultaFinal,stringNomeFinanciador='FUB') if nome.nome_template == "fap": - fap = os.path.join(caminho_pasta_planilhas, "ModeloFAP.xlsx") - preenche_planilha(fap,dict_final) + testeCaminhoFap = os.path.join(diretorio_atual, caminho_pasta_planilhas, f"modeloFap.xlsx") + preenche_planilha(testeCaminhoFap,dict_final,codigo,template_id,consultaInicial,consultaFinal,stringNomeFinanciador='FAP') + if nome.nome_template == "finep": - print("foi auqi") - finep = os.path.join(diretorio_atual, caminho_pasta_planilhas,"ModeloFINEP.xlsx") - preenche_planilha(finep,dict_final) + testeCaminhoFap = os.path.join(diretorio_atual, caminho_pasta_planilhas, f"modeloFinep.xlsx") + preenche_planilha(testeCaminhoFap,dict_final,codigo,template_id,consultaInicial,consultaFinal,stringNomeFinanciador='FINEP') file_path = None print(f"download{template_id}") if template_id == '1': - keys = ['NomeFavorecido','FavorecidoCPFCNPJ','NomeTipoLancamento', - 'HisLancamento','NumDocPago','DataEmissao','NumChequeDeposito', - 'DataPagamento', 'ValorPago'] - file_path = os.path.join(diretorio_atual, caminhoPastaPlanilhasPreenchidas, f"planilhaPreenchidaModelo_Fub.xlsx") + # keys = ['NomeFavorecido','FavorecidoCPFCNPJ','NomeTipoLancamento', + # 'HisLancamento','NumDocPago','DataEmissao','NumChequeDeposito', + # 'DataPagamento', 'ValorPago'] + file_path = os.path.join(diretorio_atual, caminhoPastaPlanilhasPreenchidas, f"PC - FUB - {codigo} - {consultaInicial} a {consultaFinal}.xlsx") preencheFub(codigo,convert_datetime_to_string(consultaInicio),convert_datetime_to_string(consultaFim),file_path) inserir_round_retangulo(file_path,consultaInicio,consultaFim,db_fin) + elif template_id == '2': keys = ['NomeFavorecido','FavorecidoCPFCNPJ','NomeRubrica','NumDocPago', 'DataEmissao','NumChequeDeposito','DataPagamento', 'ValorPago'] - file_path = os.path.join(diretorio_atual, caminhoPastaPlanilhasPreenchidas, f"planilhaPreenchidaModeloFUNDEP.xlsx") - + file_path = os.path.join(diretorio_atual, caminhoPastaPlanilhasPreenchidas,f"PC - FUNDEP - {codigo} - {consultaInicial} a {consultaFinal}.xlsx") #file_path = pegar_caminho('/home/ubuntu/Desktop/05_PipelineFinatec/planilhas_preenchidas/planilhaPreenchidaModeloFUNDEP.xlsx') preenche_fundep(codigo,convert_datetime_to_string(consultaInicio),convert_datetime_to_string(consultaFim),keys,file_path) - elif template_id == '3': - p_opas = os.path.join(caminhoPastaPlanilhasPreenchidas, "ModeloOPAS.xlsx") - file_path = p_opas - elif template_id == '4': - p_fap = os.path.join(caminhoPastaPlanilhasPreenchidas, "ModeloFAP.xlsx") - file_path = pegar_caminho(p_fap) + elif template_id == '5': - print("ta aqui") - print("TAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") - file_path = os.path.join(diretorio_atual, caminhoPastaPlanilhasPreenchidas, f"planilhaPreenchidaModeloFINEP.xlsx") + + file_path = os.path.join(diretorio_atual, caminhoPastaPlanilhasPreenchidas, f"PC - FINEP - {codigo} - {consultaInicial} a {consultaFinal}.xlsx") + #file_path = os.path.join(diretorio_atual, caminhoPastaPlanilhasPreenchidas, f"PC - FAP - {codigo} - {consultaInicial} a {consultaFinal}.xlsx") preencheFinep(codigo,convert_datetime_to_string(consultaInicio),convert_datetime_to_string(consultaFim),file_path) - inserir_round_retangulo(file_path,consultaInicio,consultaFim,db_fin) + inserir_round_retanguloGeral(file_path,consultaInicio,consultaFim,db_fin) + + elif template_id == '4': + + file_path = os.path.join(diretorio_atual, caminhoPastaPlanilhasPreenchidas, f"PC - FAP - {codigo} - {consultaInicial} a {consultaFinal}.xlsx") + preencheFap(codigo,convert_datetime_to_string(consultaInicio),convert_datetime_to_string(consultaFim),file_path) + inserir_round_retanguloGeral(file_path,consultaInicio,consultaFim,db_fin) + else: # Handle cases where 'download' doesn't match any expected values return HttpResponse("Invalid download request", status=400) @@ -209,7 +231,6 @@ def projeto_legacy(request): if os.path.exists(file_path): with open(file_path, 'rb') as f: response = HttpResponse(f.read(), content_type='application/octet-stream') - #print(f'aaaa{os.path.basename(file_path)}') response['Content-Disposition'] = f'attachment; filename="{os.path.basename(file_path)}"' # adicionando log de consulta @@ -226,6 +247,11 @@ def projeto_legacy(request): # "templates":Template.objects.all(), # }) + #delete the files + + + + def custom_logout(request): logout(request) return redirect('/') diff --git a/project/tabela b/project/tabela deleted file mode 100755 index 618551cd..00000000 Binary files a/project/tabela and /dev/null differ