def __init__(self, codiEmp, finalDate, payments=[]): self._codiEmp = codiEmp self._finalDate = funcoesUteis.retornaCampoComoData(finalDate) self._payments = payments self._providers = readJson( os.path.join( fileDir, f'{folderExtractDatabaseAccount}/fornecedores/{self._codiEmp}-effornece.json' )) self._installments = readJson( os.path.join( fileDir, f'{folderExtractDatabaseAccount}/entradas_parcelas/{self._codiEmp}-efentradaspar.json' )) self._paymentsFinal = [] self._listWordsNotConsiderInTheName = ['LTDA', 'LTDA.', '-', 'ME', 'ME.', 'EPP', 'EPP.', 'EIRELI', 'EIRELI.', \ 'MEI', 'MEI.', 'EI', 'EI.', 'S.A.', 'SA', 'S.A', 'S/A'] self._listWordsAbbreviatedToChange = { "COM.": "COMERCIO", "PROD.": "PRODUCAO", "IND.": "INDUSTRIA", "IMP.": "IMPORTACAO", "EXP.": "EXPORTACAO", "MAT.": "MATERIAIS", "LIMP.": "LIMPEZA", "SERV.": "SERVICO", "EQUIP.": "EQUIPAMENTOS", "P/": "PARA", "ARTIG.": "ARTIGOS", "DIST.": "DISTRIBUIDORA", "CONST.": "CONSTRUCAO" }
def __init__(self): self._payments = [] self._paymentsDates = [] self._proofsOfPayments = [] self._extracts = [] self._codiEmp = int( input( f'\n - Digite o código da empresa dentro da Domínio que será realizada a integração: ' )) self._inicialDate = input( f'\n - Informe a data inicial (dd/mm/aaaa): ') self._finalDate = input(f' - Informe a data final (dd/mm/aaaa): ') # self._codiEmp = 118 # self._inicialDate = '01/07/2020' # self._finalDate = '31/07/2020' self._lenghtLayoutsAccountPaid = 0 self._waySettings = os.path.join( fileDir, f'backend/accounting_integration/data/settings/company{self._codiEmp}.json' ) if os.path.exists(self._waySettings) is False: getSettingsCompany = GetSettingsCompany(self._codiEmp) self._settings = getSettingsCompany.getSettingsFinancy() self._lenghtLayoutsAccountPaid = len( self._settings['settingsLayouts']) self._banksToProof = funcoesUteis.returnDataFieldInDict( self._settings, ["proofPayment"], [{ "value": 0, "label": "" }]) else: self._settings = leArquivos.readJson(self._waySettings) self._banksToProof = funcoesUteis.returnDataFieldInDict( self._settings, ["banks", "listNumbers"], [{ "value": 0, "label": "" }]) self._wayFilesToRead = os.path.join( folderToSaveFilesAccountIntegration, f'{self._codiEmp}/arquivos_originais') self._wayFilesTemp = os.path.join( fileDir, f'backend/accounting_integration/data/temp/{self._codiEmp}') if os.path.exists(self._wayFilesTemp) is False: os.makedirs(self._wayFilesTemp) try: shutil.rmtree(self._wayFilesTemp) except OSError as e: print(f"Error: {e.filename}, {e.strerror}") if os.path.exists(self._wayFilesTemp) is False: os.makedirs(self._wayFilesTemp) self._wayReadFiles = os.path.join(self._wayFilesTemp, 'FilesReads.json') if os.path.exists(self._wayReadFiles) is False: with open(self._wayReadFiles, 'w') as fileRead: json.dump({}, fileRead)
def returnDataOutputNoteDominio(self, codi_emp, month, year, keyNF): try: dataNfs = readJson(os.path.join(wayToSaveFile, 'saidas', str(codi_emp), f'{str(year)}{month:0>2}.json')) for nf in dataNfs: if nf['chave_nfe_sai'] == keyNF: return nf except Exception: pass
def __init__(self, wayToRead, filterDate="01/01/2019"): self._wayToRead = wayToRead self._filterDate = funcoesUteis.retornaCampoComoData(filterDate) self._companies = readJson(os.path.join(wayToSaveFile, 'empresas.json')) self._hourProcessing = datetime.datetime.now() self._client = MongoClient() # conecta num cliente do MongoDB rodando na sua máquina self._db = self._client.baymax self._collection = self._db[f'MeshNote']
def __init__(self, codiEmp, wayOriginal, wayTemp): self._extracts = [] self._codiEmp = codiEmp self._wayOriginal = wayOriginal self._wayTemp = wayTemp self._banks = readJson(os.path.join(fileDir, f'backend/accounting_integration/data/banks.json')) # print(self._banks["BanksNamePerNumber"]) sanitizeOFX = SanitizeOFX(self._codiEmp, self._wayOriginal, self._wayTemp) sanitizeOFX.processAll()
def __init__(self, codiEmp, wayTemp): self._codiEmp = codiEmp self._wayTemp = wayTemp self._wayTempFilesRead = os.path.join(wayTemp, 'FilesReads.json') self._filesRead = readJson(self._wayTempFilesRead) self._wayBaseToSaveFiles = os.path.join( folderToSaveFilesAccountIntegration, f'{self._codiEmp}/arquivos_processados/docs_nao_lidos') if os.path.exists(self._wayBaseToSaveFiles) is False: os.makedirs(self._wayBaseToSaveFiles)
def __init__(self, system, codiEmp, wayOriginalToRead, wayTemp): self._payments = [] self._system = system self._codiEmp = codiEmp self._wayOriginalToRead = wayOriginalToRead self._wayTemp = wayTemp self._waySettings = os.path.join( fileDir, f'backend/accounting_integration/data/settings/company{self._codiEmp}.json' ) self._settings = leArquivos.readJson(self._waySettings)
def __init__(self): self._wayToRead = input( '- Informe o caminho onde estão os XMLs que deseja organizar: ') self._wayToSave = input( '- Agora informe o caminho onde deseja salvar os XMLs organizados: ' ) self._filterDate = input( '- A partir de qual data deseja organizar estes XMLs (dd/mm/aaaa): ' ) self._filterDate = funcoesUteis.retornaCampoComoData(self._filterDate) self._companies = readJson(os.path.join(wayToSaveFile, 'empresas.json'))
def __init__(self): self._DB = DB() self._connection = self._DB.getConnection() self._cursor = None self._wayCompanies = os.path.join(wayDefaultToSave, 'empresas.json') self._dataCompanies = readJson(self._wayCompanies) self._baseWayToSave = os.path.join(wayDefaultToSave, 'entradas') if os.path.exists(self._baseWayToSave) is False: os.makedirs(self._baseWayToSave) self._today = datetime.date.today() self._currentMonth = self._today.month self._currentYear = self._today.year
def __init__(self, filterDate="01/01/2019"): self._wayToReadXMLs = input( '- Informe a pasta onde estão os XMLs que servirão como base na comparação: ' ) self._wayToRead = [ os.path.join(wayToSaveFile, 'entradas_produtos'), os.path.join(wayToSaveFile, 'saidas_produtos') ] self._filterDate = funcoesUteis.retornaCampoComoData(filterDate) self._companies = readJson(os.path.join(wayToSaveFile, 'empresas.json')) self._hourProcessing = datetime.datetime.now() self._client = MongoClient( ) # conecta num cliente do MongoDB rodando na sua máquina self._db = self._client.baymax self._collection = self._db[ f'ProductComparationBetweenAccountSystemAndXML']
import sys import os absPath = os.path.dirname(os.path.abspath(__file__)) fileDir = absPath[:absPath.find('backend')] sys.path.append(os.path.join(fileDir, 'backend')) sys.path.append(os.path.join(fileDir, 'backend/accounting_integration/src')) import tools.leArquivos as leArquivos from services.rules.ReadExcelToUpdateOrExportData import ReadExcelToUpdateOrExportData from services.rules.GenerateExcel import GenerateExcel from services.rules.GenerateExportDominio import GenerateExportDominio from services.rules.CompareWithSettings import CompareWithSettings envData = leArquivos.readJson(os.path.join(fileDir, 'backend/env.json')) folderToSaveFilesAccountIntegration = envData['folderToSaveFilesAccountIntegration'] class UpdateOrExportData(object): def __init__(self): self._UpdateOrExport = int(input(f'\n - Para exportar os dados no Leiaute Domínio digite 1, já se quiser atualizar a planilha Financeiro e Extratos pra conferência digite 2: ')) self._codiEmp = input(f'\n - Digite o código da empresa dentro da Domínio: ') self._wayFilesToRead = os.path.join(folderToSaveFilesAccountIntegration, f'{self._codiEmp}/arquivos_processados') def process(self): for root, dirs, files in os.walk(self._wayFilesToRead): if root == self._wayFilesToRead: for file in files: print(f'\n - Atualizando o arquivo "{file}"') wayFile = os.path.join(root, file)
from pymongo import MongoClient import json import os import sys absPath = os.path.dirname(os.path.abspath(__file__)) fileDir = absPath[:absPath.find('backend')] sys.path.append(os.path.join(fileDir, 'backend')) from tools.leArquivos import readJson envData = readJson(os.path.join(fileDir, 'backend/env.json')) hostDatabase = envData['hostDatabase'] class ConnectMongo(object): def __init__(self, nameDB='baymax'): self._connection = None self._selectDB = None self._nameDB = nameDB def getConnetion(self): if self._connection is None: try: self._connection = MongoClient(f'mongodb://{hostDatabase}:27017/') # conecta num cliente do MongoDB rodando na sua máquina self._selectDB = self._connection[self._nameDB] except Exception as e: print(f"** Não foi possível realizar a conexão. O erro é: {e}") return self._selectDB def closeConnection(self):
absPath = os.path.dirname(os.path.abspath(__file__)) fileDir = absPath[:absPath.find('backend')] sys.path.append(os.path.join(fileDir, 'backend')) import datetime import json import codecs from pymongo import MongoClient from fiscal.src.services.read_files.CallReadXmls import CallReadXmls from tools.leArquivos import readXml, readJson import tools.funcoesUteis as funcoesUteis # from zipfile import ZipFile # from rarfile import RarFile # from py7zr import SevenZipFile wayDefault = readJson(os.path.join(fileDir, 'backend/extract/src/WayToSaveFiles.json') ) wayToSaveFile = wayDefault['wayDefaultToSaveFiles'] class MeshNote(object): def __init__(self, wayToRead, filterDate="01/01/2019"): self._wayToRead = wayToRead self._filterDate = funcoesUteis.retornaCampoComoData(filterDate) self._companies = readJson(os.path.join(wayToSaveFile, 'empresas.json')) self._hourProcessing = datetime.datetime.now() self._client = MongoClient() # conecta num cliente do MongoDB rodando na sua máquina self._db = self._client.baymax self._collection = self._db[f'MeshNote'] def returnDataEmp(self, cgce): for companie in self._companies:
def process(self, jsonNF): nf = '' productsXML = [] typeNF = '' noteHasProducts = False products = readJson(jsonNF) if len(products) == 0: return "" for key, product in enumerate(products): codi_emp = product['codi_emp'] cgce_emp = self.returnDataEmp(codi_emp) # ignora empresas inativas if cgce_emp is None: continue keyNF = product['chave_nfe'] # ignora notas que não são NF-e if keyNF == "" or keyNF is None: continue emissao = product['emissao'] emissao = funcoesUteis.retornaCampoComoData(emissao, 2) month = emissao.month year = emissao.year previousProduct = funcoesUteis.analyzeIfFieldIsValidMatrix( products, key - 1) previousKeyNF = funcoesUteis.analyzeIfFieldIsValid( previousProduct, 'chave_nfe') # busca os dados das notas de entradas if jsonNF.find('entradas_produtos') >= 0: typeNF = 'Entradas' if jsonNF.find('saidas_produtos') >= 0: typeNF = 'Saidas' if keyNF != previousKeyNF or len(products) == 1: wayXml = os.path.join(self._wayToReadXMLs, f'{codi_emp} -', f'{str(year)}-{month:0>2}', f'{typeNF}', f'{keyNF}.xml') callReadXmls = CallReadXmls(wayXml) nf = callReadXmls.process() productsXML = funcoesUteis.analyzeIfFieldIsValid( nf, 'produtos') noteHasProducts = False if len(productsXML) == 0 else True # quando existe apenas um produto no XML ele não cria um array de produtos, e sim apenas um objeto. Todavia, pra função de # comparação funcionar preciso que seja um array. As linhas abaixo fazem esta análise e cria o array quando necessário productsWhenExistOneProductXML = [] onlyProductInXML = funcoesUteis.analyzeIfFieldIsValid( productsXML, 'prod', False) if onlyProductInXML is not False: productsWhenExistOneProductXML.append(productsXML) productsXML = productsWhenExistOneProductXML productXML = self.returnProductComparation(product, productsXML) if productXML is not None: valueComparationBetweenAccountSystemAndXML = productXML[ 'valueComparationBetweenAccountSystemAndXML'] # deleta o campo pois pra remover o productXML do arrays de products as informações tem que ser idênticas del productXML['valueComparationBetweenAccountSystemAndXML'] # remove o produto pra ele não processar 2 vezes dizendo como seria de outro produto productsXML.remove(productXML) else: valueComparationBetweenAccountSystemAndXML = 0 if valueComparationBetweenAccountSystemAndXML <= 0.3 and noteHasProducts is True: dataProcess = { "codiEmp": codi_emp, "keyNF": keyNF, "typeNF": typeNF[:3].upper(), "productDominio": product, "productXML": productXML, "valueComparationBetweenAccountSystemAndXML": valueComparationBetweenAccountSystemAndXML } self.saveResultProcess(dataProcess)
def returnDataEntryNote(self, note=0, cgceProvider=None, ddoc_ent=None, dent_ent=None, amountPayment=0.0, nameProvider=None, dueDate=None, amountOriginal=0.0): if note == "" or note is None: note = 0 if cgceProvider == "": cgceProvider = None if ddoc_ent == "": ddoc_ent = None if dent_ent == "": dent_ent = None if dueDate == "": dueDate = None if nameProvider == "": nameProvider = None note = funcoesUteis.treatNumberField(note, True) if note == 0 and ddoc_ent is None and dent_ent is None and cgceProvider is None and nameProvider is None: return None wayFiles = os.path.join(fileDir, f'{folderExtractDatabaseAccount}/entradas/', str(self._codiEmp)) for root, dirs, files in os.walk(wayFiles): for file in sorted(files, reverse=True): if file.lower().endswith(('.json')): competenceFile = funcoesUteis.retornaCampoComoData( f'{file[0:4]}-{file[4:6]}-01', 2) if competenceFile > self._finalDate: continue wayFile = os.path.join(root, file) entryNotes = readJson(wayFile) for entryNote in entryNotes: provider = self.returnDataProvider( entryNote["codi_for"]) cgceProviderEntryNote = funcoesUteis.analyzeIfFieldIsValid( provider, "cgce_for", None) nameProviderEntryNote = funcoesUteis.analyzeIfFieldIsValid( provider, "nome_for", None) noteEntryNote = int( funcoesUteis.analyzeIfFieldIsValid( entryNote, "nume_ent", 0)) issueEntryNote = funcoesUteis.transformaCampoDataParaFormatoBrasileiro( \ funcoesUteis.retornaCampoComoData(funcoesUteis.analyzeIfFieldIsValid(entryNote, "ddoc_ent"), 2) ) entryEntryNote = funcoesUteis.transformaCampoDataParaFormatoBrasileiro( \ funcoesUteis.retornaCampoComoData(funcoesUteis.analyzeIfFieldIsValid(entryNote, "dent_ent"), 2) ) amountAccountEntryNote = float( funcoesUteis.analyzeIfFieldIsValid( entryNote, "vcon_ent", 0.0)) if note != 0: # se a nota for válida compara os dados com ela, uma comparação no mínimo tem que ser igual, pq a se a nota tá preenchida ela tem que existir na domínio (mesmo número) if noteEntryNote == note and cgceProviderEntryNote == cgceProvider: return entryNote if noteEntryNote == note and issueEntryNote == ddoc_ent and ddoc_ent is not None: return entryNote if noteEntryNote == note and entryEntryNote == dent_ent and dent_ent is not None: return entryNote if noteEntryNote == note and issueEntryNote == dueDate and dueDate is not None: # a comparação por vencimento e emissão é pq algumas vezes a data de vencimento é a própria emissão return entryNote if noteEntryNote == note and amountAccountEntryNote == amountOriginal and amountOriginal > 0: return entryNote if noteEntryNote == note and amountAccountEntryNote == amountPayment and amountPayment > 0: return entryNote else: # se não tiver a nota olha outros pontos de apoios que não são tão confiáveis if issueEntryNote == ddoc_ent and cgceProviderEntryNote == cgceProvider and ddoc_ent is not None: return entryNote if entryEntryNote == dent_ent and cgceProviderEntryNote == cgceProvider and dent_ent is not None: return entryNote if issueEntryNote == dueDate and cgceProviderEntryNote == cgceProvider and dueDate is not None: return entryNote if amountAccountEntryNote == amountOriginal and cgceProviderEntryNote == cgceProvider and amountOriginal > 0: return entryNote if amountAccountEntryNote == amountPayment and cgceProviderEntryNote == cgceProvider and amountPayment > 0: return entryNote # comparação pelo nome, caso as hipóteses acima não retorne nada compareTwoWords = self.compareTwoNames( nameProviderEntryNote, nameProvider) if compareTwoWords[ "first7LettersEquals"] is True or compareTwoWords[ "percentWordsEqualsAboutNameTwo"] >= 0.25: if note != 0: # se a nota for válida compara os dados com ela, uma comparação no mínimo tem que ser igual, pq a se a nota tá preenchida ela tem que existir na domínio (mesmo número) if noteEntryNote == note: return entryNote else: if issueEntryNote == ddoc_ent and ddoc_ent is not None: return entryNote if entryEntryNote == dent_ent and dent_ent is not None: return entryNote if issueEntryNote == dueDate and dueDate is not None: return entryNote if amountAccountEntryNote == amountOriginal and amountOriginal > 0: return entryNote if amountAccountEntryNote == amountPayment and amountPayment > 0: return entryNote