def search_extract(*args): layout_extract.label_of_client.text = f'Cliente: {layout_extract.search.text.title()}' global widget_for_scroll_extract widget_for_scroll_extract.clear_widgets() with open(file) as archive: cont = 0 total_debts = 0 list_with_payments = [] for c in range(0, lines_in_archive(file)): line = archive.readline().replace('\n', '').split('/') if line[0] == layout_extract.search.text.title(): total_debts += float(line[2]) if line[1] != '**pagamento**': widget_for_scroll_extract.add_widget(DefaultLabel(text=f'Compra: {line[1]}\nPreço: {line[2]}', size_hint=(1, None), height=size_screen[1] / 10)) cont += 1 else: list_with_payments.append(f'{line[2]}') layout_extract.total_debts.text = f'Total: R${total_debts:.2f}' for items in list_with_payments: widget_for_scroll_extract.add_widget(DefaultLabel(text=f'PAGAMENTO\nPreço: {items.replace("-", "")}', size_hint=(1, None), height=size_screen[1] / 10)) cont += 1 widget_for_scroll_extract.height = (size_screen[1] / 10) * cont
def search_all_debts(*args): total = 0 with open(file) as archive: for c in range(0, lines_in_archive(file)): line = archive.readline().replace('\n', '').split('/') total += float(line[2]) total_real = float(f'{total:.2f}') layout_all_debts.infos.text = f'O valor total da dívida é: {total_real}'
def search_all_debtors(*args): scroll_layout_all_debtors.clear_widgets() widget_for_scroll_all_debtors.clear_widgets() list_with_debtors = [] cont = 0 with open(file) as archive: for c in range(0, lines_in_archive(file)): line = archive.readline().replace('\n', '').split('/') if line[0] not in list_with_debtors: widget_for_scroll_all_debtors.add_widget(DefaultLabel(text=f'{cont + 1} - {line[0]}', size_hint=(1, None), height=size_screen[1] / 13)) cont += 1 list_with_debtors.append(line[0]) if not list_with_debtors: widget_for_scroll_all_debtors.add_widget(DefaultLabel(text='Não existe devedores cadastrados!', size_hint=(1, None), height=size_screen[1] / 13)) cont = 1 widget_for_scroll_all_debtors.height = (size_screen[1] / 13) * cont scroll_layout_all_debtors.add_widget(widget_for_scroll_all_debtors)
def search(*args): search = layout_total_debts.search.text.title() total_debt = 0 total_purchase = 0 exist_client = False with open(file) as archive: for c in range(0, lines_in_archive(file)): line = archive.readline().replace('\n', '').split('/') if line[0] == search: total_debt += float(line[2]) if line[1] != '**pagamento**': total_purchase += 1 exist_client = True if exist_client: if total_purchase != 1: s = 'compras' else: s = 'compra' layout_total_debts.infos.text = f'{total_purchase} {s} do cliente encontada!\n' \ f'Total: R${total_debt}' else: layout_total_debts.infos.text = 'Cliente não encontrado!'
def confirmation(self, *args): global payment name = layout_payment.input_name.text.title().strip() total_debt = 0 exist_client = False with open(file) as archive: for c in range(0, lines_in_archive(file)): line = archive.readline().replace('\n', '').split('/') if line[0] == name: total_debt += float(line[2]) exist_client = True if not exist_client: layout_payment.label.text = f'Não existe um cliente {name} registrado!' if name \ else f'Não foi escrito o nome do pagador!' else: total_debt_real = float(f'{total_debt:.2f}') if total_debt_real > 0: product = '**pagamento**' try: payment = float(layout_payment.input_payment.text.replace(',', '.')) except: layout_payment.label.text = 'Valor de pagamento inválido!' else: if total_debt_real - payment < 0: layout_payment.label.text = f'{name} tem divida de {total_debt_real} reais.\n' \ f'É impossível reduzir {payment} de {total_debt_real}!' else: # OPEN POP UP def exit_popup(*args): popup.dismiss() def confirm_popup(*args): append_in_data(file, f'{name}/{product}/{payment * -1}') popup.dismiss() self.manager.current = 'menu' layout_payment.input_name.text = '' layout_payment.input_payment.text = '' layout_payment.label.text = '' content = BoxLayout() content.orientation = 'vertical' content.add_widget(Label(text=f'Você realmente deseja quitar a dívida:\n' f'Comprador: {name}\n' f'Preço: {payment}\n', halign='center')) content.add_widget(DefaultButtonForPopup(size_screen, text='Voltar', on_release=exit_popup)) content.add_widget(DefaultButtonForPopup(size_screen, text='Confirmar', on_release=confirm_popup)) popup = DefaultPopup(size_screen, title='Confirmação', content=content) popup.open() # END POP UP else: layout_payment.label.text = f'O cliente {name} não possui dívidas.'