예제 #1
0
def listCompany():
    file = Global.DATABASE()

    with open(file, 'r') as json_file:
        dados = json.load(json_file)

    count = len(dados)

    listCompany = []

    for index in range(count):
        if 'company' in dados[index]:
            listCompany.append(dados[index]['company']['name'])

    return listCompany
예제 #2
0
    def Start(self, listCompany=[]):

        countList = len(listCompany)

        popup = Popup.Popup()

        if countList == 0:
            popup.alert('INFORME', 'NÃO EXISTE NENHUMA EMPRESA CADASTRADA.')
            return False

        file = Global.DATABASE()

        colTwo = [
            [
                view.Frame('COMPETÊNCIA:', [[view.Input(key='competence')]],
                           background_color='#6272a4')
            ],
            [
                view.Frame('BASE DE CALCULO:',
                           [[view.Input(key="calculateBase")]],
                           background_color='#6272a4')
            ],
            [
                view.Frame('IMPOSTO:', [[
                    view.Radio(
                        'PIS', 'tax', key='pis', background_color='#6272a4'),
                    view.Radio('COFINS',
                               'tax',
                               key='cofins',
                               background_color='#6272a4')
                ]],
                           background_color='#6272a4')
            ]
        ]

        layout = [[view.Text('EMPRESAS', background_color='#6272a4')],
                  [
                      view.Listbox(
                          values=listCompany,
                          size=(20, 9),
                          key='listCompany',
                      ),
                      view.Column(colTwo)
                  ],
                  [
                      view.Button('ADICIONAR',
                                  key='submit',
                                  button_color=['#ffffff', '#3CB371']),
                      view.Button('CANCELAR',
                                  key='cancel',
                                  button_color=['#ffffff', '#ff5555'])
                  ]]

        window = view.Window('ADICIONAR COMPETÊNCIA',
                             layout,
                             icon=Global.ICON(),
                             location=(830, 220),
                             size=(400, 240))

        while True:
            event, values = window.Read()

            if event in (view.WIN_CLOSED, 'cancel'):
                break
            elif event == 'submit':

                countListSelect = len(values['listCompany'])
                listSelect = '' if countListSelect == 0 else values[
                    'listCompany'][0]

                competence = values['competence']
                pis = values['pis']
                cofins = values['cofins']
                calculateBase = values['calculateBase']

                def isFloat(number):
                    try:
                        float(number)
                        return True
                    except:
                        return False

                chews = Chews.Chews()

                if listSelect == '':
                    popup.alert('INFORME', 'POR FAVOR, ESCOLHA UMA EMPRESA.')

                elif competence == '':
                    popup.alert('INFORME',
                                'POR FAVOR, INFORME UMA COMPETÊNCIA.')

                elif not chews.isMonthYear(competence):
                    popup.alert(
                        'INFORME',
                        'POR FAVOR, INFORME UM FORMATO DE COMPÊNCIA VALIDO(00-0000).'
                    )

                elif not isFloat(calculateBase):
                    popup.alert('INFORME',
                                'POR FAVOR, INFORME UM VALOR CONTÁBEL.')

                elif pis == False and cofins == False:
                    popup.alert('INFORME', 'POR FAVOR, SELECIONE UM IMPOSTO.')

                elif calculateBase == '':
                    popup.alert('INFORME',
                                'POR FAVOR, INFORME UM UMA BASE DE CALCULO.')

                else:

                    with open(file, 'r') as json_file:
                        dados = json.load(json_file)

                    count = len(dados)

                    competenceData = dados

                    status = True

                    for index in range(count):
                        if 'competence' in competenceData[index]:
                            competenceIndex = competenceData[index][
                                'competence']

                            if competenceIndex['competence'] == competence:
                                if competenceIndex['foreignKey'] == listSelect:
                                    if competenceIndex['pis'] == True and pis:
                                        popup.alert(
                                            'INFORME',
                                            'A COMPETÊNCIA JÁ EXISTE.')
                                        status = False

                                    if status:
                                        if competenceIndex['cofins'] and cofins:
                                            popup.alert(
                                                'INFORME',
                                                'A COMPETÊNCIA JÁ EXISTE.')
                                            status = False

                    if status:
                        competenceNew = {
                            "competence": {
                                'foreignKey': listSelect,
                                'competence': competence,
                                'pis': pis,
                                'cofins': cofins,
                                'calculateBase': round(float(calculateBase),
                                                       2),
                                'credit': 0,
                                'update': [],
                                'date': '{}'.format(datetime.datetime.now())
                            }
                        }

                        dados.append(competenceNew)

                        with open(file, 'w') as json_file:
                            json.dump(dados, json_file, indent=4)

                        popup.alert('INFORME',
                                    'COMPETÊNCIA ADICIONADA COM SUCESSO.')
                        break
                    else:
                        status = True

        window.close()
예제 #3
0
    def select(self, listCompany=[]):

        countList = len(listCompany)

        popup = Popup.Popup()

        if countList == 0:
            popup.alert('INFORME', 'NÃO EXISTE NENHUMA EMPRESA CADASTRADA.')
            return False

        file = Global.DATABASE()

        def index(name='', tax=''):
            with open(file, 'r') as json_file:
                datas = json.load(json_file)

            count = len(datas)

            listSelect = []

            for index in range(count):
                if 'competence' in datas[index]:
                    if datas[index]['competence']['foreignKey'] == name:
                        if tax == 'pis':
                            if datas[index]['competence']['pis'] == True:
                                listSelect.append(datas[index]['competence'])
                        elif tax == 'cofins':
                            if datas[index]['competence']['cofins'] == True:
                                listSelect.append(datas[index]['competence'])

            if listSelect == []:
                return False

            return listSelect

        colOne = [[view.Text('EMPRESAS:', background_color='#6272a4')],
                  [
                      view.Listbox(values=listCompany,
                                   size=(15, 7),
                                   key='company')
                  ]]

        colTwo = [[
            view.Frame('IMPOSTO', [[
                view.Radio('PIS', 'tax', key='pis',
                           background_color='#6272a4'),
                view.Radio(
                    'COFINS', 'tax', key='cofins', background_color='#6272a4')
            ]],
                       background_color='#6272a4')
        ],
                  [
                      view.Button('CONSULTAR',
                                  key='submit',
                                  button_color=['#ffffff', '#3CB371'],
                                  size=(17, 1))
                  ],
                  [
                      view.Button('CANCELAR',
                                  key='cancel',
                                  button_color=['#ffffff', '#ff5555'],
                                  size=(17, 1))
                  ]]

        layout = [[
            view.Column(colOne),
            view.Column(colTwo, element_justification='center')
        ]]

        window = view.Window('CONSULTAR CRÉDITO',
                             layout,
                             location=(830, 220),
                             icon=Global.ICON())

        while True:

            event, values = window.read()

            if event in (view.WIN_CLOSED, 'cancel'):
                break

            elif event == 'submit':
                popup = Popup.Popup()

                companySelect = '' if values['company'] == [] else values[
                    'company'][0]

                if companySelect == '':
                    popup.alert('INFORME', 'POR FAVOR, SELECIONE UMA EMPRESA.')
                elif not values['pis'] and not values['cofins']:
                    popup.alert('INFORME', 'POR FAVOR, SELECIONE UM IMPOSTO.')
                else:
                    tax = 'pis' if values['pis'] == True else 'cofins'

                    listCosultCompany = index(companySelect, tax)

                    if listCosultCompany:
                        list_ = List.windowListCredit()
                        list_.index(listCosultCompany)
                    else:
                        popup.alert(
                            'INFORME',
                            'NÃO EXISTE COMPETÊNCIA RELACIONADA A ESSE IMPOSTO.'
                        )

        window.close()
예제 #4
0
    def calculate(self, listCompany=[]):

        countList = len(listCompany)

        popup = Popup.Popup()

        if countList == 0:
            popup.alert('INFORME', 'NÃO EXISTE NENHUMA EMPRESA CADASTRADA.')
            return False

        file = Global.DATABASE()

        def index(name='', tax=''):
            with open(file, 'r') as json_file:
                datas = json.load(json_file)

            count = len(datas)

            listCompetence = []

            for index in range(count):
                if 'competence' in datas[index]:
                    if datas[index]['competence']['foreignKey'] == name:
                        if tax == 'pis':
                            if datas[index]['competence']['pis'] == True:
                                listCompetence.append(
                                    datas[index]['competence']['competence'])
                        elif tax == 'cofins':
                            if datas[index]['competence']['cofins'] == True:
                                listCompetence.append(
                                    datas[index]['competence']['competence'])

            if listCompetence == []:
                return False

            return listCompetence

        def update(name='', competenceSelect='', tax='', valueUsed=''):
            with open(file, 'r') as json_file:
                datas = json.load(json_file)

            count = len(datas)

            datasUp = {
                'valueUsed': round(float(valueUsed), 2),
                'date': '{}'.format(datetime.datetime.now()),
            }

            for index in range(count):
                if 'competence' in datas[index]:
                    competence = datas[index]['competence']

                    if competence['foreignKey'] == name:
                        if competence['competence'] == competenceSelect:

                            valueUsed = float(valueUsed)
                            calculateBase = float(competence['calculateBase'])
                            credit = float(competence['credit'])

                            if competence['update'] == []:
                                if valueUsed > calculateBase:
                                    popup.alert(
                                        'ERRO',
                                        'O VALOR USUADO É MAIOR QUE O CRÉDITO DISPONÍVEL.'
                                    )
                                    return False
                            else:
                                if valueUsed > credit:
                                    popup.alert(
                                        'ERRO',
                                        'O VALOR USUADO É MAIOR QUE O CRÉDITO DISPONÍVEL.'
                                    )
                                    return False

                            if tax == 'pis':
                                if competence['pis'] == True:
                                    if competence['credit'] == 0:
                                        competence['credit'] = round(
                                            calculateBase - valueUsed, 2)

                                    else:
                                        competence['credit'] = round(
                                            credit - valueUsed, 2)

                            elif tax == 'cofins':
                                if competence['cofins'] == True:
                                    if competence['credit'] == 0:
                                        competence['credit'] = round(
                                            calculateBase - valueUsed, 2)

                                    else:
                                        competence['credit'] = round(
                                            credit - valueUsed, 2)

                            competence['update'].append(datasUp)
                            datas[index] = {"competence": competence}

                            with open(file, 'w') as json_file:
                                json.dump(datas, json_file, indent=4)

                            message = 'O VALOR DE CRÉDITO RESTANTE É DE: R$ {:.2f}'.format(
                                competence['credit'])
                            popup.alert('INFORME', message)
                            return True

            popup.alert('ERRO', 'COMPETÊNCIA NÃO ENCONTRADA.')
            return False

        colOne = [[view.Text('EMPRESAS:', background_color='#6272a4')],
                  [
                      view.Listbox(values=listCompany,
                                   size=(15, 7),
                                   key='company')
                  ]]

        colTwo = [[
            view.Frame('IMPOSTO', [[
                view.Radio('PIS', 'tax', key='pis',
                           background_color='#6272a4'),
                view.Radio(
                    'COFINS', 'tax', key='cofins', background_color='#6272a4')
            ]],
                       background_color='#6272a4')
        ],
                  [
                      view.Frame('VALOR USADO',
                                 [[view.Input(size=(18, 1), key='calculate')]],
                                 background_color='#6272a4')
                  ],
                  [
                      view.Button('LISTAR',
                                  size=(17, 1),
                                  key='list',
                                  button_color=['#ffffff', '#282a36'])
                  ]]

        colThree = [[view.Text('COMPETÊNCIAS:', background_color='#6272a4')],
                    [view.Listbox(values=[], size=(15, 7), key='competence')]]

        layout = [[
            view.Column(colOne),
            view.Column(colTwo, element_justification='center'),
            view.Column(colThree)
        ],
                  [
                      view.Button('ATUALIZAR',
                                  key="submit",
                                  button_color=['#ffffff', '#3CB371']),
                      view.Button('CANCELAR',
                                  key="cancel",
                                  button_color=['#ffffff', '#ff5555'])
                  ]]

        window = view.Window(
            'ATUALIZAÇÃO DE CRÉDITOS',
            layout,
            icon=Global.ICON(),
            location=(830, 220),
        )

        while True:

            event, values = window.Read()

            if event in (view.WIN_CLOSED, 'cancel'):
                break

            if event == 'list' or event == 'submit':

                companySelect = '' if values['company'] == [] else values[
                    'company'][0]

                if companySelect == '':
                    popup.alert('INFORME', 'POR FAVOR, SELECIONE UMA EMPRESA.')

                elif not values['pis'] and not values['cofins']:
                    popup.alert('INFORME', 'POR FAVOR, SELECIONE UM IMPOSTO.')

                elif event == 'list':
                    tax = 'pis' if values['pis'] == True else 'cofins'

                    listCompetence = index(companySelect, tax)

                    if listCompetence:
                        window['competence'].update(listCompetence)
                    else:
                        popup.alert(
                            'INFORME',
                            'NÃO EXISTE COMPETÊNCIA RELACIONADA A ESSE IMPOSTO.'
                        )

                elif event == 'submit':
                    if values['competence'] == []:
                        popup.alert('INFORME',
                                    'POR FAVOR, SELECIONE UMA COMPETÊNCIA.')
                    elif values['calculate'] == '' or values[
                            'calculate'] == None:
                        popup.alert(
                            'INFORME',
                            'POR FAVOR, INFORME UM VALOR A SER DESCONTADO.')
                    else:
                        name = values['company'][0]
                        competence = values['competence'][0]
                        discount = values['calculate']
                        tax = 'pis' if values['pis'] == True else 'cofins'

                        try:
                            float(discount)
                            update(name, competence, tax, discount)
                            window['calculate'].update('')
                        except:
                            popup.alert(
                                'ERRO',
                                'POR FAVOR, INFORME UM VALOR CONTÁBEL.')
            else:
                break

        window.close()
예제 #5
0
    def Start(self):

        layout = [
                
                    [
                        view.Text('CNPJ', background_color="#6272a4"),
                        view.Input(key='cnpj')
                    ],
                    [
                        view.Text('RAZÃO SOCIAL', background_color="#6272a4"),
                        view.Input(key='name')
                    ],
                    [
                        view.Button('CADASTRAR', 
                                        key='submit',
                                        button_color=['#ffffff','#3CB371']
                                    ),
                        view.Button('CANCELAR', 
                                        key='cancel',
                                        button_color=['#ffffff','#ff5555']
                                    )
                    ] 
                 ]


        window = view.Window('CADASTRAR EMPRESA',
                                 layout,
                                 location=(830, 220),
                                 icon=Global.ICON(),
                                 size=(300, 100)
                            )
        

        file = Global.DATABASE()
       

        while True:

            event, values = window.read()

            with open(file, 'r') as json_file:
                dados = json.load(json_file)

            count = len(dados)
            company = values

            if event in (view.WIN_CLOSED, 'cancel'):
                break

            elif event == 'submit':
                popup = Popup.Popup()

                if not validate.validar_cnpj(company['cnpj']):
                    popup.alert('ERRO', 'O CNPJ NÃO É VALIDO.')
                    
                elif company['cnpj'] == '' or company['name'] == '' :
                     popup.alert('ERRO', 'POR FAVOR, PREENCHA TODOS OS CAMPOS.') 

                else: 
                    status = True

                    for index in range(count):
                        if 'company' in dados[index]:
                            if dados[index]['company']['cnpj'] == company['cnpj']:
                                popup.alert('INFORME', 'A EMPRESA JÁ FOI CADASTRADA.')
                                status = False
                            if status:
                                if dados[index]['company']['name'] == company['name']:
                                    popup.alert('INFORME', 'A RAZÃO SOCIAL JÁ ESTÁ VINCULADA A UM CNPJ.')
                                    status = False

                    if status :
                        
                        company = {
                            "company": {
                                'cnpj': company['cnpj'],
                                'name': company['name'],
                                'date': '{}'.format(datetime.datetime.now()),
                            } 
                        }

                        dados.append(company)

                        with open(file, 'w') as json_file:
                            json.dump(dados, json_file, indent=4)

                        popup.alert('INFORME', 'EMPRESA CADASTRADA COM SUCESSO.')
                        break
                    else:
                        status = True

        window.close()