Beispiel #1
0
    def clean(self):
        db = database.InventoryDB()

        if self.editable:
            self.update_categories()

        if self.data:
            self.product_id = self.data.ID
        elif self.product_id != -1:
            self.data = db.inventory_search_id(self.product_id)
        else:
            db.close()

            self.textbox_description.SetValue('')
            self.textbox_price.SetValue('R$ 0,00')
            self.textbox_amount.SetValue('')
            self.textbox_supplier.SetValue('')
            self.textbox_observation.SetValue('')
            self.update_categories()

            return
        category = db.categories_search_id(self.data.category_ID)

        self.textbox_description.SetValue(self.data.description)
        self.textbox_barcode.SetValue(self.data.barcode)
        self.textbox_price.SetValue(
            core.format_cash_user(self.data.price, currency=True))
        self.textbox_amount.SetValue(
            core.format_amount_user(self.data.amount, unit=category.unit))
        self.textbox_supplier.SetValue(self.data.supplier)
        self.textbox_observation.SetValue(self.data.obs)

        self.combobox_category.SetValue(category.category)

        db.close()
Beispiel #2
0
    def __init__(self, parent, title=u'Desperdícios', key=-1, data=None):
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          title,
                          size=(630, 280),
                          style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION
                          | wx.CLOSE_BOX | wx.CLIP_CHILDREN)

        self.key = key
        self.data = data

        self.setup_gui()

        self.database_inventory = database.InventoryDB(':memory:')

        if self.key != -1 or data:
            if not data:
                db = database.TransactionsDB()
                self.data = db.wastes_search_id(self.key)
                db.close()
                self.key = self.data.ID
            self.recover_waste()

        self.database_search(None)

        self.Show()
Beispiel #3
0
    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)
Beispiel #4
0
 def data_delete(self, event):
     it = self.list_products.GetFocusedItem()
     if it == -1:
         return
     e_id = self.list_products.GetItem(it, 1).GetText()
     db = database.InventoryDB()
     db.delete_product(int(e_id))
     db.close()
     self.setup(None)
Beispiel #5
0
def imposto_122741(category_id=None, data=None, origin=None):
    """
    coleta os dados de imposto de um determinado produto
    :param category_id: id do produto
    :param data: Produto a ter o imposto coletado
    :param origin: Frame de origem
    :type category_id: int
    :type data: data_types.ProductCategoryData
    :type origin: wx.Window
    :return: produto
    :rtype: data_types.ProductData
    """
    import ibptws.provisoes
    import ibptws.excecoes
    import database
    from ibptws import conf

    import requests

    conf.token = '797XZCfo2HY0TtThIPLPiMds9JzUrCDvUVhiPaJ_Jq7OFawH1OdSq3kJkOSsxPpI'
    conf.cnpj = '16678899000136'
    conf.estado = 'SP'

    if not data and not category_id:
        return False

    db = database.InventoryDB()

    if not data:
        data = db.categories_search_id(category_id)

    calc = ibptws.provisoes.SemProvisao()
    try:
        p = calc.get_produto(data.ncm, 0)
        data.imposto_federal = float(p.aliquota_nacional +
                                     p.aliquota_importado)
        data.imposto_estadual = float(p.aliquota_estadual)

        data.imposto_total = data.imposto_federal + data.imposto_estadual

    except ibptws.excecoes.ErroProdutoNaoEncontrado:
        import dialogs
        import categories
        dialogs.launch_error(
            origin, u'O NCM da categoria "%s" é inválido!' % data.category)
        if not isinstance(origin, categories.ProductCategoryData):
            categories.ProductCategoryData(origin,
                                           title=data.category,
                                           category_id=category_id,
                                           data=data)
        raise exception.ExceptionNCM

    except requests.ConnectionError:
        db.insert_category_fila(data.ID)
        raise exception.ExceptionInternet

    return data
Beispiel #6
0
 def update_categories(self):
     db = database.InventoryDB()
     category_list = db.categories_list()
     category_options = [u'Selecione']
     for category in category_list:
         category_options.append(category.category)
     self.combobox_category.SetItems(category_options)
     self.combobox_category.SetSelection(0)
     db.close()
Beispiel #7
0
    def end(self):

        if not self.textbox_description.GetValue():
            return dialogs.launch_error(self, u'É necessária uma descrição!')
        if self.combobox_category.GetSelection() == 0:
            return dialogs.launch_error(self, u'Selecione uma categoria!')

        amount_str = self.textbox_amount.GetValue()

        try:
            amount = core.amount2float(amount_str)
        except ValueError:
            self.textbox_amount.Clear()
            return dialogs.launch_error(self, u'Quantidade inválida!')

        rdate, rtime = core.datetime_today()
        names = strip(self.textbox_description.GetValue()).split()
        for i in range(0, len(names)):
            names[i] = names[i].capitalize()
        namef = ' '.join(names)
        db = database.InventoryDB()
        category = db.category_search_name(self.combobox_category.GetValue())
        barcode = self.textbox_barcode.GetValue()

        s = data_types.ProductData()
        if barcode:
            s.barcode = barcode

        s.ID = self.product_id
        s.description = namef
        s.price = core.money2float(self.textbox_price.GetValue())
        s.amount = int(amount)
        s.category_ID = category.ID
        s.supplier = self.textbox_supplier.GetValue()
        s.obs = self.textbox_observation.GetValue()
        s.record_time = rtime
        s.record_date = rdate

        if self.data:
            db.edit_product(s)
        else:
            db.insert_product(s)
        db.close()

        if isinstance(self.parent, sale.Sale):
            self.parent.database_inventory.insert_product(s)
            self.parent.database_search(None)

        if self.data:
            if isinstance(self.parent, InventoryManager):
                self.parent.setup(None)

            return self.exit(None)

        self.clean()
        dialogs.Confirmation(self, u'Sucesso', 5)
Beispiel #8
0
 def database_search(self, event):
     self.list_products.DeleteAllItems()
     db = database.InventoryDB()
     info = self.textbox_filter.GetValue()
     inventory = db.inventory_search(info)
     for product in inventory:
         category = db.categories_search_id(product.category_ID)
         self.list_products.Append(
             (product.description, product.ID, category.category,
              core.format_cash_user(product.price, currency=True),
              core.format_amount_user(product.amount, unit=category.unit),
              core.format_amount_user(product.sold, unit=category.unit)))
     db.close()
Beispiel #9
0
def __fila_imposto_122741():
    import database
    db = database.InventoryDB()
    line = db.fila_list()
    for category_id in line:
        try:
            data = db.categories_search_id(category_id)
            imposto_122741(data=data)
            db.edit_category_impostos(data)
        except exception.ExceptionNCM:
            continue
        except exception.ExceptionInternet:
            continue

    db.close()
Beispiel #10
0
    def __init__(self, parent, title=u'Entrada de Produtos'):
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          title,
                          size=(470, 675),
                          style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION
                          | wx.CLOSE_BOX | wx.CLIP_CHILDREN | wx.TAB_TRAVERSAL)

        self.parent = parent
        self.setup_gui()

        self.database_inventory = database.InventoryDB(':memory:')
        self.database_search(None)

        self.Show()
Beispiel #11
0
def update_inventory(data, undo=False):
    """
    Atualiza o estoque de acordo com um registro de desperdicio
    :type data: data_types.WasteData
    :type undo: bool
    :param data: dados do desperdicio
    :param undo: Caso True desfaz as mudanças causadas no BD pelo registro da perda
    :return: None
    :rtype: None
    """
    db = database.InventoryDB()

    prduct_id = data.product_ID
    amount = data.amount if undo else -data.amount

    db.update_product_stock(prduct_id, amount, sold=False)
    db.close()
Beispiel #12
0
def __atualiza_imposto_122741():
    import database
    import core
    db = database.InventoryDB()
    line = db.categories_list()
    for data in line:
        try:
            imposto_122741(data=data)
            db.edit_category_impostos(data)
        except exception.ExceptionNCM:
            continue
        except exception.ExceptionInternet:
            continue
    settings.CONFIG.set(settings.CONFIG_SECTION_SAT,
                        settings.CONFIG_FIELD_LAST_UPDATE_IMPOSTO,
                        core.datetime_today()[0])

    settings.save_config()
Beispiel #13
0
    def end(self):

        w = self.list_update.GetItemCount()
        if w == 0:
            return dialogs.launch_error(self,
                                        u'Você não adicionou nenhum produto!')

        update = self.radio_update.GetValue()
        entry = self.radio_entry.GetValue()
        db = database.InventoryDB()
        for i in range(w):
            products_id = self.list_update.GetItemData(i)
            amount = core.amount2float(self.list_update.GetItemText(i, 2))
            if update:
                db.update_product_amount(products_id, amount)
            elif entry:
                db.update_product_stock(products_id, amount)

        db.close()

        self.clean()
        dialogs.Confirmation(self, u'Sucesso', 6)
Beispiel #14
0
    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()
Beispiel #15
0
    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)
Beispiel #16
0
    def __setup__(self):
        self.clean()

        month = core.format_date_internal(
            self.combobox_month_displayed.GetValue())

        db = database.TransactionsDB()
        sales = db.monthly_sales_list(month)
        expenses = db.monthly_expenses_list(month)
        wastes = db.monthly_wastes_list(month)
        transactions = db.monthly_transactions_list(month)
        db.close()

        inventory_db = database.InventoryDB()

        total_expense = 0.0
        total_income = 0.0
        total_waste = 0.0
        total_card_income = 0.0
        total_money_income = 0.0
        dict_products = {}
        week_sold = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
        days = []
        pendant_income = 0.0
        pendant_expense = 0.0
        pendant_income_count = 0
        pendant_expense_count = 0

        for sale_ in sales:
            date_ = sale_.record_date.split('-')
            week_day = calendar.weekday(int(date_[0]), int(date_[1]),
                                        int(date_[2]))
            if date_[2] not in days:
                days.append(date_[2])
            if not sale_.payment_pendant:
                total_income += sale_.value
                if sale_.payment == u'Dinheiro':
                    total_money_income += sale_.value
                elif sale_.payment.split()[0] == u'Cartão':
                    total_card_income += sale_.value
                week_sold[week_day] += sale_.value
            else:
                pendant_income += sale_.value
                pendant_income_count += 1
            for i in range(len(sale_.products_IDs)):
                product_id = sale_.products_IDs[i]
                if product_id not in dict_products:
                    dict_products[product_id] = [0, 0.0]
                dict_products[product_id][0] += sale_.amounts[i]
                dict_products[product_id][1] += sale_.prices[i]

        for expense_ in expenses:
            total_expense += expense_.value

        for waste_ in wastes:
            product = inventory_db.inventory_search_id(waste_.product_ID)
            total_waste += product.price * waste_.amount

        for transaction_ in transactions:
            if not transaction_.payment_pendant:
                if transaction_.type is transaction.INCOME:
                    total_income += transaction_.value
                elif transaction_.type is transaction.EXPENSE:
                    total_expense += transaction_.value
            else:
                if transaction_.type is transaction.INCOME:
                    pendant_income += transaction_.value
                    pendant_income_count += 1
                elif transaction_.type is transaction.EXPENSE:
                    pendant_expense += transaction_.value
                    pendant_expense_count += 1

        lp1 = []
        lp2 = []

        for item in range(0, 11):

            product_item_left = [u'', 0, 0.0, -1]
            for product_id in dict_products:
                if dict_products[product_id][1] > product_item_left[2]:
                    product_item_left = [
                        inventory_db.inventory_search_id(
                            product_id).description,
                        dict_products[product_id][0],
                        dict_products[product_id][1], product_id
                    ]

            product_item_right = [u'', 0, 0.0, -1]
            for product_id in dict_products:
                if dict_products[product_id][0] > product_item_right[1]:
                    product_item_right = [
                        inventory_db.inventory_search_id(
                            product_id).description,
                        dict_products[product_id][0],
                        dict_products[product_id][1], product_id
                    ]
            if product_item_left[2] and product_item_left not in lp1:
                lp1.append(product_item_left)
            if product_item_right[1] and product_item_right not in lp2:
                lp2.append(product_item_right)

        inventory_db.close()

        for item in lp1:
            item_id = self.list_left.Append(
                (item[0], item[1], core.format_cash_user(item[2],
                                                         currency=True)))
            self.list_left.SetItemData(item_id, item[3])
        for item in lp2:
            item_id = self.list_right.Append(
                (item[0], item[1], core.format_cash_user(item[2],
                                                         currency=True)))
            self.list_right.SetItemData(item_id, item[3])

        total_balance = (total_income - total_expense)

        try:
            average_daily_balance = (total_income - total_expense) / len(days)
        except ZeroDivisionError:
            average_daily_balance = 0.0

        if max(week_sold):
            weekday_best = core.week_days[week_sold.index(max(week_sold))]
        else:
            weekday_best = '-------'

        if min(week_sold):
            weekday_worse = core.week_days[week_sold.index(min(week_sold))]
        else:
            try:
                while not min(week_sold):
                    week_sold.remove(0.0)
                weekday_worse = core.week_days[week_sold.index(min(week_sold))]
                if weekday_best == weekday_worse:
                    weekday_worse = '-------'
            except ValueError:
                weekday_worse = '-------'

        self.text_profit.SetValue(
            core.format_cash_user(total_balance, currency=True))
        self.text_spent.SetValue(
            core.format_cash_user(total_expense, currency=True))
        self.text_income.SetValue(
            core.format_cash_user(total_income, currency=True))
        self.text_wasted.SetValue(
            core.format_cash_user(total_waste, currency=True))
        self.text_income_pendant.SetValue(
            core.format_cash_user(pendant_income, currency=True))
        self.text_expense_pendant.SetValue(
            core.format_cash_user(pendant_expense, currency=True))
        self.text_income_pendant_amount.SetValue(str(pendant_income_count))
        self.text_expense_pendant_amount.SetValue(str(pendant_expense_count))
        self.text_daily_income.SetValue(
            core.format_cash_user(average_daily_balance, currency=True))
        self.text_credit_card_income.SetValue(
            core.format_cash_user(total_card_income, currency=True))
        self.text_money_income.SetValue(
            core.format_cash_user(total_money_income, currency=True))
        self.text_worst_week_day.SetValue(weekday_best)
        self.text_better_week_day.SetValue(weekday_worse)
        self.setup_monthly_incomes(None)
        self.setup_monthly_expenses(None)
    def setup_selection_1(self):
        main_root = self.list_edited_data.AddRoot(u"---------")
        self.list_edited_data.SetItemText(main_root, u"Registros Apagados", 2)

        db = database.InventoryDB()
        products = db.product_list(deleted=True)
        categories = db.categories_list(deleted=True)
        db.close()

        db = database.ClientsDB()
        clients = db.clients_list(deleted=True)
        db.close()

        clients_counter = len(clients)
        products_counter = len(products)
        categories_counter = len(categories)

        clients_root = self.list_edited_data.AppendItem(
            main_root, u"---------")
        self.list_edited_data.SetItemText(clients_root, u"Clientes", 2)
        self.list_edited_data.SetItemText(clients_root, str(clients_counter),
                                          3)
        self.list_edited_data.SetItemFont(
            clients_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in clients:

            item = self.list_edited_data.AppendItem(clients_root, u"---------")
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(item, data.name, 2)

            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))

        products_root = self.list_edited_data.AppendItem(
            main_root, u"---------")
        self.list_edited_data.SetItemText(products_root, u"Produtos", 2)
        self.list_edited_data.SetItemText(products_root, str(products_counter),
                                          3)
        self.list_edited_data.SetItemFont(
            products_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in products:

            item = self.list_edited_data.AppendItem(products_root,
                                                    u"---------")
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(item, data.description, 2)
            self.list_edited_data.SetItemText(
                item, core.format_amount_user(data.amount), 3)
            self.list_edited_data.SetItemText(
                item, core.format_cash_user(data.price, currency=True), 4)

            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))

        categories_root = self.list_edited_data.AppendItem(
            main_root, u"---------")
        self.list_edited_data.SetItemText(categories_root, u"Categorias", 2)
        self.list_edited_data.SetItemText(categories_root,
                                          str(categories_counter), 3)
        self.list_edited_data.SetItemFont(
            categories_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in categories:

            item = self.list_edited_data.AppendItem(categories_root,
                                                    u"---------")
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(item, data.category, 2)

            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))

        self.list_edited_data.SetItemFont(
            main_root, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
        self.list_edited_data.SetItemText(
            main_root,
            str(categories_counter + products_counter + clients_counter), 3)
        self.list_edited_data.Expand(main_root)