def loadInfo(self): brokers = DATABASE.getBrokers() self.viewTreasure.clear() self.viewTreasure.setHeaderLabels(COLUMNSTREASURE) self.viewStocks.clear() self.viewStocks.setHeaderLabels(COLUMNSSTOCK) for broker in brokers: treasureItem = TreeItem(self.viewTreasure, broker) treasureItem.setFont(0, BOLD) treasureItem.setText( 1, "R$ %.2f" % DATABASE.getBalanceFromBroker(broker, TREASURE)) treasureItem.setTextAlignment(1, Qt.AlignRight) stockItem = TreeItem(self.viewStocks, broker) stockItem.setFont(0, BOLD) stockItem.setText( 3, "R$ %.2f" % DATABASE.getBalanceFromBroker(broker, STOCK)) stockItem.setTextAlignment(3, Qt.AlignRight) investiments = DATABASE.getInvestiments(broker) for investiment in investiments: if investiment[2] == TREASURE: item = TreeItem(treasureItem, investiment[0]) item.setCheckState(0, Qt.Unchecked) item.setText(1, "R$ %.2f" % investiment[3]) item.setTextAlignment(1, Qt.AlignRight) elif investiment[2] == STOCK: item = TreeItem(stockItem, investiment[0]) item.setCheckState(0, Qt.Unchecked) item.setText(1, "%d" % investiment[1]) item.setTextAlignment(1, Qt.AlignCenter) item.setText(2, "R$ %.2f" % investiment[3]) item.setTextAlignment(2, Qt.AlignRight) item.setText(3, "R$ %.2f" % (investiment[1] * investiment[3])) item.setTextAlignment(3, Qt.AlignRight) self.viewTreasure.expandAll() self.viewTreasure.resizeColumnToContents(0) self.viewTreasure.sortItems(0, Qt.AscendingOrder) self.viewStocks.expandAll() self.viewStocks.resizeColumnToContents(0) self.viewStocks.sortItems(0, Qt.AscendingOrder)
def loadInfo(self): self.view.clear() self.view.setHeaderLabels(COLUMNS) banks = TreeItem(self.view, "Bancos") banks.setFont(1, BOLD) banks.setTextAlignment(1, Qt.AlignRight) banks.setFont(2, BOLD) banks.setTextAlignment(2, Qt.AlignRight) cards = TreeItem(self.view, u"Cartões de Crédito") cards.setFont(1, BOLD) cards.setTextAlignment(1, Qt.AlignRight) cards.setFont(2, BOLD) cards.setTextAlignment(2, Qt.AlignRight) brokers = TreeItem(self.view, "Corretoras") brokers.setFont(1, BOLD) brokers.setTextAlignment(1, Qt.AlignRight) accounts = DATABASE.getAccounts(info=True) for account in accounts: balance = DATABASE.getBalance(account[0]) if account[1] == BANK: item = TreeItem(banks, account[0]) if balance >= 0: item.setText(2, "R$ %.2f" % account[2]) else: item.setText(2, "R$ %.2f" % (account[2] + balance)) item.setText(1, "R$ %.2f" % balance) defineColor(item, balance, 1) elif account[1] == CARD: item = TreeItem(cards, account[0]) item.setText(2, "R$ %.2f" % (account[2] + balance)) item.setText(1, "R$ %.2f" % balance) defineColor(item, balance, 1) else: item = TreeItem(brokers, account[0]) item.setText( 1, "R$ %.2f" % (balance + DATABASE.getBalanceFromBroker(account[0]))) defineColor( item, balance + DATABASE.getBalanceFromBroker(account[0]), 1) item.setTextAlignment(1, Qt.AlignRight) item.setTextAlignment(2, Qt.AlignRight) value = DATABASE.getBalance(_type=BANK) banks.setText(1, "R$ %.2f" % value) defineColor(banks, value, 1) accounts = DATABASE.getAccounts(info=True) limitDisp = 0 for account in accounts: balance = DATABASE.getBalance(account[0]) if account[1] == BANK and balance < 0: limitDisp += account[2] + balance elif account[1] == BANK: limitDisp += account[2] banks.setText(2, "R$ %.2f" % limitDisp) value = DATABASE.getBalance(_type=CARD) cards.setText(1, "R$ %.2f" % value) defineColor(cards, value, 1) limitDisp = 0 for account in accounts: balance = DATABASE.getBalance(account[0]) if account[1] == CARD: limitDisp += account[2] + balance cards.setText(2, "R$ %.2f" % limitDisp) brokers.setText( 1, "R$ %.2f" % (DATABASE.getBalance(_type=BROKER) + DATABASE.getBalanceFromBroker())) defineColor( brokers, DATABASE.getBalance(_type=BROKER) + DATABASE.getBalanceFromBroker(), 1) balance = DATABASE.getBalance() + DATABASE.getBalanceFromBroker() self.balance.setText("Balanço Total: R$ %.2f" % balance) if balance > 0: self.balance.setStyleSheet("QLabel {color:#007E00}") elif balance == 0: self.balance.setStyleSheet("QLabel {color:#000000}") else: self.balance.setStyleSheet("QLabel {color:#7E0000}") self.view.expandAll() self.view.resizeColumnToContents(0) self.view.sortItems(0, Qt.AscendingOrder)