def __init__(self, parent, title=u'Transaçoes'): wx.Frame.__init__(self, parent, -1, title, style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN) self.setup_gui() db = database.TransactionsDB() dates = db.list_transactions_dates() db.close() months = list() for date in dates: month = core.format_date_user(date[:-3]) if month not in months: months.append(month) if months: self.combobox_month_displayed.SetItems(months) self.combobox_month_displayed.SetSelection(0) self.setup(None) self.Show()
def setup_monthly_expenses(self, event): self.list_expenses.DeleteAllItems() month = core.format_date_internal( self.combobox_month_displayed.GetValue()) db = database.TransactionsDB() expenses = db.monthly_transactions_list(month, transaction.EXPENSE) db.close() root = self.list_expenses.AddRoot( self.combobox_month_displayed.GetValue() or u'-----') self.list_expenses.SetItemText(root, u'Gastos Mensais', 1) self.list_expenses.SetItemFont( root, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) total = 0.0 for expense_ in expenses: x = self.list_expenses.AppendItem( root, core.format_date_user(expense_.transaction_date)) self.list_expenses.SetItemText(x, expense_.description, 1) self.list_expenses.SetItemText( x, core.format_cash_user(expense_.value, currency=True), 2) self.list_expenses.SetItemData(x, wx.TreeItemData(expense_)) total += expense_.value self.list_expenses.SetItemText( root, core.format_cash_user(total, currency=True), 2) self.list_expenses.ExpandAll(root)
def setup_monthly_list(self, data_type): month = core.format_date_internal( self.combobox_month_displayed.GetValue()) date = core.datetime_today()[0] lists = {EXPENSE: self.list_expenses, INCOME: self.list_incomes} list_ctrl = lists[data_type] list_ctrl.DeleteAllItems() db = database.TransactionsDB() transaction_registered = db.monthly_transactions_list(month, data_type) for _transaction in transaction_registered: category = db.categories_search_id(_transaction.category) item = list_ctrl.Append( (_transaction.description, core.format_id_user( _transaction.ID), category.category if category else u'', core.format_cash_user(_transaction.value, currency=True), core.format_date_user(_transaction.transaction_date), u'OK' if not _transaction.payment_pendant else u'Pendente')) # Atribui uma cor ao item caso o pagamento ainda não tenha sido realizado if _transaction.payment_pendant: self.setup_item_color(item, data_type) db.close()
def setup_wastes(self): inventory_db = database.InventoryDB() wastes_db = database.TransactionsDB() waste_list = wastes_db.monthly_wastes_list(self.month) wastes_db.close() walist = {} for waste_ in waste_list: if waste_.product_ID in walist: walist[waste_.product_ID][0] += waste_.amount walist[waste_.product_ID][1] += 1 else: product = inventory_db.inventory_search_id(waste_.product_ID) walist[waste_.product_ID] = [ waste_.amount, 1, product.description, product.price, waste_ ] self.AddColumn(u'ID', 100) self.AddColumn(u'Descrição', 300) self.AddColumn(u'Preço Unitário', 100) self.AddColumn(u'Quantidade', 100) self.AddColumn(u'Quantidade de vezes', 150) self.AddColumn(u'Valor', 200) root = self.AddRoot(u'------') self.SetItemText( root, u'Desperdícios de %s' % core.format_date_user(self.month), 1) self.SetItemFont(root, wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) a = 0.0 b = 0.0 counter = 0 for product_id in walist: value = walist[product_id][3] * walist[product_id][0] item = self.AppendItem(root, str(product_id)) self.SetItemText(item, walist[product_id][2], 1) self.SetItemText( item, core.format_cash_user(walist[product_id][3], currency=True), 2) self.SetItemText(item, core.format_amount_user(walist[product_id][0]), 3) self.SetItemText(item, str(walist[product_id][1]), 4) self.SetItemText(item, core.format_cash_user(value, currency=True), 5) self.SetItemData(item, wx.TreeItemData(walist[product_id][4])) a += value b += walist[product_id][0] counter += 1 self.SetItemText(root, core.format_amount_user(b), 3) self.SetItemText(root, str(counter), 4) self.SetItemText(root, core.format_cash_user(a, currency=True), 5) self.Expand(root) self.SortChildren(root)
def get_message(self): blur = u'Atenção' what = u'recebimento' if self.data.type is transaction.INCOME else u'pagamento' args = (blur, what, self.data.description, core.format_cash_user(self.data.value, currency=True), core.format_date_user(self.data.transaction_date)) message = u'%s! O %s da conta "%s" no valor de %s, ' \ u'a qual está programada para %s ainda está pendente' % args return message
def sales_list(self): self.list_bought.DeleteAllItems() db = database.ClientsDB() sales = db.sales_search_client(self.client_id) db.close() sales_db = database.TransactionsDB() value = 0.0 value_money = 0.0 value_card = 0.0 amount = 0 amount_money = 0 amount_card = 0 for sale_ in sales: data = sales_db.sales_search_id(sale_.sale) if not data.active: disconnect_sale(sale_.ID, data.ID) continue payed = u'Sim' if not data.payment_pendant else u'Não' item = self.list_bought.Append((data.record_date, data.record_time, core.format_cash_user(data.value, currency=True), payed)) self.list_bought.SetItemData(item, data.ID) value += data.value amount += 1 if data.payment == u'Dinheiro': amount_money += 1 value_money += data.value elif data.payment.split()[0] == u'Cartão': amount_card += 1 value_card += data.value if self.data.last_sale: last_sale = u'Última compra registrada em %s \n' \ u'Já gastou R$ %s na Canela Santa através de %i compras, das quais %i, no valor de R$ %s,' \ u'foram pagas em dinheiro e %i, no valor de R$ %s, foram pagas no cartão.' % \ (core.format_date_user(self.data.last_sale), core.format_cash_user(value), amount, amount_money, core.format_cash_user(value_money), amount_card, core.format_cash_user(value_card)) else: last_sale = u'Não há nenhuma compra registrada em seu nome' self.textbox_client_intel.SetValue( u'Cliente desde %s \n%s' % (core.format_date_user(self.data.record_date), last_sale))
def clean(self): self.textbox_client_name.SetValue(self.data.name) self.textbox_client_sex.SetValue(self.data.sex) self.textbox_client_birth.SetValue(core.format_date_user(self.data.birth)) self.textbox_client_telephone.SetValue(self.data.telephone) self.textbox_client_email.SetValue(self.data.email) self.textbox_client_cpf.SetValue(self.data.cpf) self.textbox_client_cep.SetValue(self.data.cep) self.textbox_client_state.SetValue(self.data.state) self.textbox_client_city.SetValue(self.data.city) self.textbox_client_district.SetValue(self.data.district) self.textbox_client_address.SetValue(self.data.address) self.textbox_client_observations.SetValue(self.data.obs) self.sales_list()
def setup_options(self): db = database.TransactionsDB() month_options = list() for date in db.list_record_dates(): month_options.append(core.format_date_user(date)) db.close() self.combobox_day_option = wx.ComboBox(self.panel_top, -1, choices=month_options, size=(130, -1), pos=(420, 12), style=wx.CB_READONLY) self.combobox_day_option.Bind(wx.EVT_COMBOBOX, self.setup) if len(month_options) != 0: self.combobox_day_option.SetSelection(0)
def setup_options(self): db = database.TransactionsDB() record_dates = db.list_record_dates(transactions=True, deleted=True) transactions_dates = db.list_transactions_record_dates(deleted=True) db.close() day_options = core.convert_list(record_dates, core.format_date_user) month_options = list() for date in transactions_dates: month = core.format_date_user(date[:-3]) if month not in month_options: month_options.append(month) entry_types = [ u'Gastos, Vendas e Desperdícios', u'Clientes, Produtos e Categorias', u'Transações e Categorias' ] self.combobox_entry_type = wx.ComboBox(self.panel_control, choices=entry_types, size=(230, -1), pos=(5, 30), style=wx.CB_READONLY | wx.TE_MULTILINE) self.combobox_entry_type.Bind(wx.EVT_COMBOBOX, self.data_update) self.combobox_month_option = wx.ComboBox(self.panel_control, -1, choices=month_options, size=(130, -1), pos=(5, 100), style=wx.CB_READONLY) self.combobox_month_option.Bind(wx.EVT_COMBOBOX, self.setup) self.combobox_day_option = wx.ComboBox(self.panel_control, -1, choices=day_options, size=(130, -1), pos=(5, 100), style=wx.CB_READONLY) self.combobox_day_option.Bind(wx.EVT_COMBOBOX, self.setup) self.combobox_entry_type.SetSelection(1) if len(month_options): self.combobox_month_option.SetSelection(0) if len(day_options): self.combobox_day_option.SetSelection(0) self.combobox_entry_type.SetSelection(0)
def setup_incomes(self): sales_db = database.TransactionsDB() sales = sales_db.monthly_sales_list(self.month) incomes = sales_db.monthly_transactions_list(self.month, transaction.INCOME) sales_db.close() self.AddColumn(u'Data/Horário', 250) self.AddColumn(u'Pagamento', 150) self.AddColumn(u'Descrição', 250) self.AddColumn(u'Quantidade', 100) self.AddColumn(u'Valor', 150) root = self.AddRoot(u'Ganhos de %s' % core.date_reverse(self.month).replace('-', '/')) self.SetItemFont(root, wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) a = 0.0 b = 0 days = {} saturdays = core.week_end(self.month) weeks = {} for sale_ in sales: for day in saturdays: if day >= int(sale_.record_date.split('-')[2]): week = saturdays.index(day) + 1 break if week not in weeks: we = self.AppendItem(root, u'%iª Semana' % week) self.SetItemFont(we, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) weeks[week] = [we, 0.0, 0] if sale_.record_date not in days: item = self.AppendItem( weeks[week][0], core.format_date_user(sale_.record_date)) self.SetItemFont(item, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD)) days[sale_.record_date] = [item, 0.0, 0] b += 1 a += sale_.value weeks[week][1] += sale_.value weeks[week][2] += 1 days[sale_.record_date][1] += sale_.value days[sale_.record_date][2] += 1 father = self.AppendItem(days[sale_.record_date][0], sale_.record_time) self.SetItemFont(father, wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) self.SetItemText(father, sale_.payment, 1) self.SetItemText(father, u'-----------', 2) self.SetItemText(father, str(len(sale_.products_IDs)), 3) self.SetItemText(father, core.format_cash_user(sale_.value, currency=True), 4) self.SetItemData(father, wx.TreeItemData(sale_)) for i in range(len(sale_.products_IDs)): kid = self.AppendItem(father, u'-----------') self.SetItemText(kid, u'-----------', 1) self.SetItemText(kid, core.format_id_user(sale_.products_IDs[i]), 2) self.SetItemText(kid, core.format_amount_user(sale_.amounts[i]), 3) self.SetItemText( kid, core.format_cash_user(sale_.prices[i], currency=True), 4) self.SetItemData(kid, wx.TreeItemData(str(sale_.products_IDs[i]))) for j in weeks: self.SetItemText(weeks[j][0], str(weeks[j][2]), 3) self.SetItemText(weeks[j][0], core.format_cash_user(weeks[j][1], currency=True), 4) for j in days: self.SetItemText(days[j][0], str(days[j][2]), 3) self.SetItemText(days[j][0], core.format_cash_user(days[j][1], currency=True), 4) self.SortChildren(days[j][0]) if len(incomes): parent = self.AppendItem(root, u'Outras entradas de dinheiro') self.SetItemFont(parent, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) for income in incomes: b += 1 a += income.value payment = u'RECEBIDO' payment = payment if not income.payment_pendant else u'AINDA NÃO ' + payment father = self.AppendItem( parent, core.format_date_user(income.transaction_date)) self.SetItemFont(father, wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) self.SetItemText(father, payment, 1) self.SetItemText(father, income.description, 2) self.SetItemText( father, core.format_cash_user(income.value, currency=True), 4) self.SetItemData(father, wx.TreeItemData(income)) self.SetItemText(root, str(b), 3) self.SetItemText(root, core.format_cash_user(a, currency=True), 4) self.Expand(root) self.SortChildren(root)
def setup_products(self): inventory_db = database.InventoryDB() sales_db = database.TransactionsDB() sale_list = sales_db.monthly_sales_list(self.month) sales_db.close() plist = {} categories_dict = {} for sale_ in sale_list: for i in range(len(sale_.products_IDs)): key = sale_.products_IDs[i] if key in plist: plist[key][0] += sale_.amounts[i] plist[key][1] += sale_.prices[i] plist[key][2] += 1 else: product = inventory_db.inventory_search_id(key) plist[key] = [ sale_.amounts[i], sale_.prices[i], 1, product.description, product.price, product ] category_id = plist[key][5].category_ID if category_id in categories_dict: categories_dict[category_id][0] += sale_.amounts[i] categories_dict[category_id][1] += sale_.prices[i] categories_dict[category_id][2] += 1 else: category = inventory_db.categories_search_id(category_id) categories_dict[category_id] = [ sale_.amounts[i], sale_.prices[i], 1, category.category, category, None ] inventory_db.close() self.AddColumn(u'ID', 100) self.AddColumn(u'Descrição', 300) self.AddColumn(u'Preço Unitário', 100) self.AddColumn(u'Quantidade vendida', 135) self.AddColumn(u'Quantidade de vezes vendido', 180) self.AddColumn(u'Valor', 115) root = self.AddRoot(u'------') self.SetItemText( root, u'Produtos Vendidos em %s' % core.format_date_user(self.month), 1) self.SetItemFont(root, wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) a = 0.0 b = 0.0 counter = 0 for product_id in plist: data = plist[product_id] category_id = data[5].category_ID data_category = categories_dict[category_id] if not data_category[5]: aux = self.AppendItem(root, core.format_id_user(category_id)) self.SetItemText(aux, data_category[3], 1) self.SetItemText( aux, core.format_amount_user(data[0], unit=data_category[4].unit), 3) self.SetItemText(aux, str(data_category[2]), 4) self.SetItemText( aux, core.format_cash_user(data_category[1], currency=True), 5) self.SetItemData(aux, wx.TreeItemData(data_category[4])) self.SetItemFont(aux, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD)) data_category[5] = aux parent = data_category[5] item = self.AppendItem(parent, core.format_id_user(product_id)) self.SetItemText(item, data[3], 1) self.SetItemText(item, core.format_cash_user(data[4], currency=True), 2) self.SetItemText( item, core.format_amount_user(data[0], unit=data_category[4].unit), 3) self.SetItemText(item, str(data[2]), 4) self.SetItemText(item, core.format_cash_user(data[1], currency=True), 5) self.SetItemData(item, wx.TreeItemData(data[5])) a += plist[product_id][1] b += plist[product_id][0] counter += 1 self.SetItemText(root, core.format_amount_user(b), 3) self.SetItemText(root, str(counter), 4) self.SetItemText(root, core.format_cash_user(a, currency=True), 5) self.Expand(root) self.SortChildren(root)
def setup_gui(self): self.SetBackgroundColour(core.COLOR_DEFAULT_BACKGROUND) self.Centre() self.SetIcon(wx.Icon(core.ICON_MAIN, wx.BITMAP_TYPE_ICO)) part1 = wx.Panel(self, -1, pos=(10, 10), size=(1180, 290), style=wx.SUNKEN_BORDER | wx.TAB_TRAVERSAL) self.text_profit = wx.TextCtrl(part1, -1, pos=(200, 50), size=(100, 30), style=wx.TE_READONLY) self.text_income = wx.TextCtrl(part1, -1, pos=(200, 90), size=(100, 30), style=wx.TE_READONLY) self.text_spent = wx.TextCtrl(part1, -1, pos=(200, 130), size=(100, 30), style=wx.TE_READONLY) self.text_wasted = wx.TextCtrl(part1, -1, pos=(200, 170), size=(100, 30), style=wx.TE_READONLY) self.text_income_pendant = wx.TextCtrl(part1, -1, pos=(200, 210), size=(100, 30), style=wx.TE_READONLY) self.text_expense_pendant = wx.TextCtrl(part1, -1, pos=(200, 250), size=(100, 30), style=wx.TE_READONLY) self.text_daily_income = wx.TextCtrl(part1, -1, pos=(500, 10), size=(100, 30), style=wx.TE_READONLY) self.text_credit_card_income = wx.TextCtrl(part1, -1, pos=(500, 50), size=(100, 30), style=wx.TE_READONLY) self.text_money_income = wx.TextCtrl(part1, -1, pos=(500, 90), size=(100, 30), style=wx.TE_READONLY) self.text_worst_week_day = wx.TextCtrl(part1, -1, pos=(500, 130), size=(100, 30), style=wx.TE_READONLY) self.text_better_week_day = wx.TextCtrl(part1, -1, pos=(500, 170), size=(100, 30), style=wx.TE_READONLY) self.text_income_pendant_amount = wx.TextCtrl(part1, -1, pos=(500, 210), size=(100, 30), style=wx.TE_READONLY) self.text_expense_pendant_amount = wx.TextCtrl(part1, -1, pos=(500, 250), size=(100, 30), style=wx.TE_READONLY) self.list_left = wx.ListCtrl(part1, -1, pos=(625, 30), size=(250, 240), style=wx.SIMPLE_BORDER | wx.LC_REPORT | wx.LC_HRULES | wx.LC_VRULES) self.list_right = wx.ListCtrl(part1, -1, pos=(900, 30), size=(250, 240), style=wx.SIMPLE_BORDER | wx.LC_REPORT | wx.LC_HRULES | wx.LC_VRULES) self.list_left.InsertColumn(0, u'Descrição') self.list_left.InsertColumn(1, u'Quantidade') self.list_left.InsertColumn(2, u'Valor') self.list_right.InsertColumn(3, u'Descrição') self.list_right.InsertColumn(4, u'Quantidade') self.list_right.InsertColumn(5, u'Valor') wx.StaticText(part1, -1, u'Mês/Ano', pos=(10, 17)) wx.StaticText(part1, -1, u'Lucro', pos=(10, 57)) wx.StaticText(part1, -1, u'Receita', pos=(10, 97)) wx.StaticText(part1, -1, u'Custos', pos=(10, 137)) wx.StaticText(part1, -1, u'Total Perdido', pos=(10, 177)) wx.StaticText(part1, -1, u'Entradas Pendentes de Pagamento', pos=(10, 217)) wx.StaticText(part1, -1, u'Gastos Pendentes de Pagamento', pos=(10, 257)) wx.StaticText(part1, -1, u'Rendimento Médio por dia', pos=(310, 17)) wx.StaticText(part1, -1, u'Total Vendido no Cartão', pos=(310, 57)) wx.StaticText(part1, -1, u'Total Vendido em Dinheiro', pos=(310, 97)) wx.StaticText(part1, -1, u'Dia da Semana menos Rentável', pos=(310, 137)) wx.StaticText(part1, -1, u'Dia da Semana mais Rentável', pos=(310, 177)) wx.StaticText(part1, -1, u'Quantidade de Entradas Pendentes', pos=(310, 217)) wx.StaticText(part1, -1, u'Quantidade de Gastos Pendentes', pos=(310, 257)) wx.StaticText(part1, -1, u'Produtos de Maior Redimento', pos=(625, 10)).SetFont( wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) wx.StaticText(part1, -1, u'Produtos Mais Vendidos', pos=(900, 10)).SetFont( wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) part2 = wx.Panel(self, -1, pos=(10, 305), size=(1180, 50), style=wx.TAB_TRAVERSAL) part21 = wx.Panel(part2, -1, pos=(10, 0), size=(620, 50), style=wx.SIMPLE_BORDER) part22 = wx.Panel(part2, -1, pos=(790, 0), size=(380, 50), style=wx.SIMPLE_BORDER) button1 = GenBitmapTextButton( part21, -1, wx.Bitmap(core.directory_paths['icons'] + 'Report.png', wx.BITMAP_TYPE_PNG), u'Tabela de Vendas', pos=(0, 0), size=(150, 50)) button2 = GenBitmapTextButton( part21, -1, wx.Bitmap(core.directory_paths['icons'] + 'Report.png', wx.BITMAP_TYPE_PNG), u'Tabela de Gastos', pos=(150, 0), size=(150, 50)) button3 = GenBitmapTextButton( part21, -1, wx.Bitmap(core.directory_paths['icons'] + 'Report.png', wx.BITMAP_TYPE_PNG), u'Tabela de Produtos', pos=(300, 0), size=(150, 50)) button7 = GenBitmapTextButton( part21, -1, wx.Bitmap(core.directory_paths['icons'] + 'Report.png', wx.BITMAP_TYPE_PNG), u'Tabela de Desperdícios', pos=(450, 0), size=(170, 50)) button8 = GenBitmapTextButton( part2, -1, wx.Bitmap(core.directory_paths['icons'] + 'Reset.png', wx.BITMAP_TYPE_PNG), u'Recalcular', pos=(645, 0), size=(130, 50), style=wx.SIMPLE_BORDER) button4 = GenBitmapTextButton( part22, -1, wx.Bitmap(core.directory_paths['icons'] + 'system-users.png', wx.BITMAP_TYPE_PNG), u'Registar Gasto', pos=(0, 0), size=(130, 50)) button5 = GenBitmapTextButton( part22, -1, wx.Bitmap(core.directory_paths['icons'] + 'system-users.png', wx.BITMAP_TYPE_PNG), u'Registrar Ganho', pos=(130, 0), size=(130, 50)) button6 = GenBitmapTextButton( part22, -1, wx.Bitmap(core.directory_paths['icons'] + 'system-users.png', wx.BITMAP_TYPE_PNG), u'Observações', pos=(260, 0), size=(120, 50)) button1.Bind(wx.EVT_BUTTON, self.open_sheets_sales) button2.Bind(wx.EVT_BUTTON, self.open_sheets_expenses) button3.Bind(wx.EVT_BUTTON, self.open_sheets_products) button7.Bind(wx.EVT_BUTTON, self.open_sheets_wastes) button8.Bind(wx.EVT_BUTTON, self.setup) button4.Bind(wx.EVT_BUTTON, self.open_new_monthly_expense) button5.Bind(wx.EVT_BUTTON, self.open_new_monthly_income) button6.Bind(wx.EVT_BUTTON, self.open_text_box) button1.SetBackgroundColour(core.COLOR_LIGHT_YELLOW) button2.SetBackgroundColour(core.COLOR_LIGHT_YELLOW) button3.SetBackgroundColour(core.COLOR_LIGHT_YELLOW) button7.SetBackgroundColour(core.COLOR_LIGHT_YELLOW) button4.SetBackgroundColour(core.COLOR_LIGHT_BLUE) button5.SetBackgroundColour(core.COLOR_LIGHT_BLUE) button6.SetBackgroundColour(core.COLOR_LIGHT_BLUE) part3 = wx.Panel(self, pos=(10, 360), size=(1180, 280), style=wx.SIMPLE_BORDER) part31 = wx.Panel(part3, 56, pos=(10, 5), size=(575, 260), style=wx.SUNKEN_BORDER) part31.SetBackgroundColour(core.COLOR_DEFAULT_BACKGROUND) self.list_incomes = wx.gizmos.TreeListCtrl(part31, -1, pos=(10, 10), size=(400, 240), style=wx.SIMPLE_BORDER | wx.TR_DEFAULT_STYLE | wx.TR_FULL_ROW_HIGHLIGHT) self.list_incomes.AddColumn(u"Data", width=110) self.list_incomes.AddColumn(u"Descrição", width=180) self.list_incomes.AddColumn(u"Valor", width=100) self.list_incomes.SetMainColumn(0) dr = wx.StaticText(part31, -1, u'Ganhos\nMensais', pos=(420, 10)) dr.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) last_panel = wx.Panel(part31, pos=(420, 80), size=(145, 160), style=wx.SIMPLE_BORDER) button31 = GenBitmapTextButton( last_panel, -1, wx.Bitmap(core.directory_paths['icons'] + 'Add.png', wx.BITMAP_TYPE_PNG), u'Adicionar', pos=(0, 0), size=(145, 40)) button32 = GenBitmapTextButton( last_panel, -1, wx.Bitmap(core.directory_paths['icons'] + 'Edit.png', wx.BITMAP_TYPE_PNG), u'Editar', pos=(0, 40), size=(145, 40)) button33 = GenBitmapTextButton( last_panel, -1, wx.Bitmap(core.directory_paths['icons'] + 'Trash.png', wx.BITMAP_TYPE_PNG), u'Apagar', pos=(0, 80), size=(145, 40)) button34 = GenBitmapTextButton( last_panel, -1, wx.Bitmap(core.directory_paths['icons'] + 'Reset.png', wx.BITMAP_TYPE_PNG), u'Atualizar', pos=(0, 120), size=(145, 40)) button31.Bind(wx.EVT_BUTTON, self.open_new_monthly_income) button32.Bind(wx.EVT_BUTTON, self.open_edit_monthly_income) button33.Bind(wx.EVT_BUTTON, self.ask_delete_income) button34.Bind(wx.EVT_BUTTON, self.setup_monthly_incomes) part32 = wx.Panel(part3, 56, pos=(590, 5), size=(575, 260), style=wx.SUNKEN_BORDER) part32.SetBackgroundColour(core.COLOR_DEFAULT_BACKGROUND) self.list_expenses = wx.gizmos.TreeListCtrl(part32, -1, pos=(10, 10), size=(400, 240), style=wx.SIMPLE_BORDER | wx.TR_DEFAULT_STYLE | wx.TR_FULL_ROW_HIGHLIGHT) self.list_expenses.AddColumn(u"Data", width=110) self.list_expenses.AddColumn(u"Descrição", width=180) self.list_expenses.AddColumn(u"Valor", width=100) self.list_expenses.SetMainColumn(0) dr = wx.StaticText(part32, -1, u'Gastos\nMensais', pos=(420, 10)) dr.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) last_buttons = wx.Panel(part32, pos=(420, 80), size=(145, 160), style=wx.SIMPLE_BORDER) button41 = GenBitmapTextButton( last_buttons, -1, wx.Bitmap(core.directory_paths['icons'] + 'Add.png', wx.BITMAP_TYPE_PNG), u'Adicionar', pos=(0, 0), size=(145, 40)) button42 = GenBitmapTextButton( last_buttons, -1, wx.Bitmap(core.directory_paths['icons'] + 'Edit.png', wx.BITMAP_TYPE_PNG), u'Editar', pos=(0, 40), size=(145, 40)) button43 = GenBitmapTextButton( last_buttons, -1, wx.Bitmap(core.directory_paths['icons'] + 'Trash.png', wx.BITMAP_TYPE_PNG), u'Apagar', pos=(0, 80), size=(145, 40)) button44 = GenBitmapTextButton( last_buttons, -1, wx.Bitmap(core.directory_paths['icons'] + 'Reset.png', wx.BITMAP_TYPE_PNG), u'Atualizar', pos=(0, 120), size=(145, 40)) button41.Bind(wx.EVT_BUTTON, self.open_new_monthly_expense) button42.Bind(wx.EVT_BUTTON, self.open_edit_monthly_expense) button43.Bind(wx.EVT_BUTTON, self.ask_delete_expense) button44.Bind(wx.EVT_BUTTON, self.setup_monthly_expenses) db = database.TransactionsDB() dates = db.list_record_dates(transactions=True) db.close() month_options = list() for date in dates: date_ = core.format_date_user(date[:7]) if date_ not in month_options: month_options.append(date_) self.combobox_month_displayed = wx.ComboBox(part1, -1, choices=month_options, size=(100, 30), pos=(200, 15), style=wx.CB_READONLY) self.combobox_month_displayed.Bind(wx.EVT_COMBOBOX, self.setup) if len(month_options) != 0: self.combobox_month_displayed.SetValue(month_options[0])
def setup_expenses(self): expenses_db = database.TransactionsDB() expenses = expenses_db.monthly_expenses_list(self.month) money_exits = expenses_db.monthly_transactions_list( self.month, transaction.EXPENSE) expenses_db.close() self.AddColumn(u'Data/Horário', 250) self.AddColumn(u'Pagamento', 150) self.AddColumn(u'Descrição', 250) self.AddColumn(u'Quantidade', 100) self.AddColumn(u'Valor', 150) root = self.AddRoot(u'Gastos de %s' % core.date_reverse(self.month).replace('-', '/')) self.SetItemFont(root, wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) a = 0.0 b = 0 days = {} saturdays = core.week_end(self.month) weeks = {} for expense_ in expenses: for day in saturdays: if day >= int(expense_.record_date.split('-')[2]): week = saturdays.index(day) + 1 break if week not in weeks: we = self.AppendItem(root, u'%iª Semana' % week) self.SetItemFont(we, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) weeks[week] = [we, 0.0, 0] if expense_.record_date not in days: item = self.AppendItem( weeks[week][0], core.format_date_user(expense_.record_date)) self.SetItemFont(item, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD)) days[expense_.record_date] = [item, 0.0, 0] b += 1 a += expense_.value weeks[week][1] += expense_.value weeks[week][2] += 1 days[expense_.record_date][1] += expense_.value days[expense_.record_date][2] += 1 father = self.AppendItem(days[expense_.record_date][0], expense_.record_time) self.SetItemFont(father, wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) self.SetItemText(father, expense_.description, 2) self.SetItemText( father, core.format_cash_user(expense_.value, currency=True), 4) self.SetItemData(father, wx.TreeItemData(expense_)) for j in weeks: self.SetItemText(weeks[j][0], str(weeks[j][2]), 3) self.SetItemText(weeks[j][0], core.format_cash_user(weeks[j][1], currency=True), 4) for j in days: self.SetItemText(days[j][0], str(days[j][2]), 3) self.SetItemText(days[j][0], core.format_cash_user(days[j][1], currency=True), 4) self.SortChildren(days[j][0]) if len(money_exits): parent = self.AppendItem(root, u'Outros Gastos') self.SetItemFont(parent, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) for money_exit in money_exits: b += 1 a += money_exit.value payment = u'RECEBIDO' payment = payment if not money_exit.payment_pendant else u'AINDA NÃO ' + payment father = self.AppendItem( parent, core.format_date_user(money_exit.transaction_date)) self.SetItemFont(father, wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) self.SetItemText(father, payment, 1) self.SetItemText(father, money_exit.description, 2) self.SetItemText( father, core.format_cash_user(money_exit.value, currency=True), 4) self.SetItemData(father, wx.TreeItemData(money_exit)) self.SetItemText(root, str(b), 3) self.SetItemText(root, core.format_cash_user(a, currency=True), 4) self.Expand(root) self.SortChildren(root)
def __setup__(self): if self.combobox_day_option.GetValue() != u'': self.clean() transactions_db = database.TransactionsDB() inventory_db = database.InventoryDB() day = core.format_date_internal(self.combobox_day_option.GetValue()) root = self.list_sales.AddRoot(u"Vendas de " + self.combobox_day_option.GetValue()) self.list_sales.SetItemFont(root, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) sales_value = 0.0 sales_amount = 0 money_value = 0.00 money_amount = 0 card_value = 0.00 card_amount = 0 day_sales = transactions_db.daily_sales_list(day) for sale_item in day_sales: sales_value += sale_item.value sold = self.list_sales.AppendItem(root, sale_item.record_time) self.list_sales.SetItemText(sold, sale_item.payment, 2) self.list_sales.SetItemText(sold, core.format_cash_user(sale_item.value, currency=True), 3) self.list_sales.SetItemFont(sold, wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) self.list_sales.SetItemData(sold, wx.TreeItemData(sale_item)) for i in range(len(sale_item.products_IDs)): product_id = sale_item.products_IDs[i] product = inventory_db.inventory_search_id(int(product_id)) a = self.list_sales.AppendItem(sold, product.description) self.list_sales.SetItemText(a, core.format_amount_user(sale_item.amounts[i]), 1) self.list_sales.SetItemText(a, core.format_cash_user(sale_item.prices[i], currency=True), 3) self.list_sales.SetItemData(a, wx.TreeItemData(product)) if sale_item.discount: web = self.list_sales.AppendItem(sold, u"Desconto") self.list_sales.SetItemText(web, core.format_cash_user(sale_item.discount, currency=True), 3) if sale_item.taxes: bew = self.list_sales.AppendItem(sold, u"Taxas adicionais") self.list_sales.SetItemText(bew, core.format_cash_user(sale_item.taxes, currency=True), 3) sales_amount += 1 if sale_item.payment == u"Dinheiro": money_amount += 1 money_value += sale_item.value elif sale_item.payment.split()[0] == u"Cartão": card_amount += 1 card_value += sale_item.value self.list_sales.SetItemText(root, str(sales_amount), 1) self.list_sales.SetItemText(root, core.format_cash_user(sales_value, currency=True), 3) self.list_sales.Expand(root) raz = self.list_expenses.AddRoot(self.combobox_day_option.GetValue()) expenses_value = 0.0 expenses_amount = 0 self.list_expenses.SetItemFont(raz, wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) day_expenses = transactions_db.daily_expenses_list(day) for expense_item in day_expenses: value = expense_item.value description = expense_item.description expenses_amount += 1 expenses_value += value golf = self.list_expenses.AppendItem(raz, core.format_date_user(expense_item.record_time)) self.list_expenses.SetItemText(golf, description, 1) self.list_expenses.SetItemText(golf, core.format_cash_user(value, currency=True), 3) self.list_expenses.SetItemData(golf, wx.TreeItemData(expense_item)) self.list_expenses.SetItemText(raz, u"Gastos", 1) self.list_expenses.SetItemText(raz, str(expenses_amount), 2) self.list_expenses.SetItemText(raz, core.format_cash_user(expenses_value, currency=True), 3) self.list_expenses.Expand(raz) pain = self.list_wastes.AddRoot(u"Desperdícios de " + self.combobox_day_option.GetValue()) wastes_value = 0.0 wastes_amount = 0 self.list_wastes.SetItemFont(pain, wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) day_wastes = transactions_db.daily_wastes_list(day) for wasted in day_wastes: amount = wasted.amount product = inventory_db.inventory_search_id(wasted.product_ID) value = product.price * amount wastes_amount += 1 wastes_value += value king = self.list_wastes.AppendItem(pain, product.description) self.list_wastes.SetItemText(king, core.format_amount_user(amount), 1) self.list_wastes.SetItemText(king, core.format_cash_user(value, currency=True), 2) self.list_wastes.SetItemData(king, wx.TreeItemData(wasted)) self.list_wastes.SetItemText(pain, str(wastes_amount), 1) self.list_wastes.SetItemText(pain, core.format_cash_user(wastes_value, currency=True), 2) self.list_wastes.Expand(pain) self.textbox_day_total.SetValue(core.format_cash_user(sales_value - expenses_value, currency=True)) self.textbox_sales_value.SetValue(core.format_cash_user(sales_value, currency=True)) self.textbox_sales_amount.SetValue(str(sales_amount)) self.textbox_money_value.SetValue(core.format_cash_user(money_value, currency=True)) self.textbox_money_amount.SetValue(str(money_amount)) self.textbox_card_value.SetValue(core.format_cash_user(card_value, currency=True)) self.textbox_card_amount.SetValue(str(card_amount)) self.textbox_spent_value.SetValue(core.format_cash_user(expenses_value, currency=True)) self.textbox_spent_amount.SetValue(str(expenses_amount)) self.cash_register = transactions_db.cash_search_date(day) if self.cash_register: self.textbox_cash_previous.SetValue(core.format_cash_user(self.cash_register.fund)) self.textbox_cash_real.SetValue(core.format_cash_user(self.cash_register.cash)) self.textbox_cash_removed.SetValue(core.format_cash_user(self.cash_register.withdrawal)) else: months = self.combobox_day_option.GetItems() last_movement = months[self.combobox_day_option.GetSelection()-1] cash_register = transactions_db.cash_search_date(core.format_date_internal(last_movement)) if cash_register: self.textbox_cash_previous.SetValue(core.format_cash_user(cash_register.cash)) else: self.textbox_cash_previous.SetValue('0,00') self.textbox_cash_real.SetValue('0,00') self.textbox_cash_removed.SetValue('0,00') self.update_cash(None) transactions_db.close() inventory_db.close() self.save(None) self.combobox_day_option.Enable()