Example #1
0
    def end(self):
        _product_id = self.textbox_id.GetValue()
        _amount = self.textbox_amount.GetValue()

        if not _product_id or not _amount:
            return dialogs.launch_error(self, u'Dados insuficientes!')

        date, finish_time = core.datetime_today()

        data = data_types.WasteData()
        data.product_ID = int(_product_id)
        data.amount = float(_amount)
        data.record_date = date
        data.record_time = finish_time
        data.ID = self.key

        db = database.TransactionsDB()
        if self.key != -1 or self.data:
            db.edit_waste(data)
            update_inventory(self.data, undo=True)
        else:
            db.insert_waste(data)
        db.close()

        update_inventory(data)

        self.clean()

        dialogs.Confirmation(self, u"Sucesso", 3)
Example #2
0
    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()
Example #3
0
    def notify_delivery(self, data=None):
        """
        Notifica o usuario sobre a existencia de uma entrega a a ser realizada
        :param data: Dados da entrega
        :type data: data_types.DeliveryData
        :return: None
        :rtype: None
        """

        breaks = [60, 30, 15]

        time_now = core.datetime_today()[1][:5]
        time_now_int = core.hour2int(time_now)

        time_delivery_int = core.hour2int(data.hour)

        remaining = time_delivery_int - time_now_int

        for i in breaks:
            if remaining > i:
                timer = threading.Timer(60 * i,
                                        self.notify_delivery,
                                        args=[data])
                self.deliveries_timers.append(timer)
                timer.start()
                break

        wx.CallAfter(dialogs.DeliveryNotification, self, data)
Example #4
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)
Example #5
0
    def end(self):
        description = self.textbox_description.GetValue().capitalize()
        val = core.money2float(self.textbox_value.GetValue())
        if len(description) == 0 or val == 0:
            return dialogs.launch_error(self, u'Dados insulficientes')
        date, finish_time = core.datetime_today()

        wx_date = self.calendar_date.GetDate()
        transaction_date = u'%i-%s-%i' % (
            wx_date.GetYear(), core.good_show(
                'o', str(wx_date.GetMonth() + 1)), wx_date.GetDay())

        data = data_types.TransactionData()
        data.ID = self.key
        data.description = description
        data.category = self.categories_ids[
            self.combobox_category.GetSelection()]
        data.value = val
        data.record_date = date
        data.record_time = finish_time
        data.transaction_date = transaction_date
        data.type = self.transaction_type
        data.payment_pendant = not self.checkbox_payed.GetValue()

        db = database.TransactionsDB()
        if self.key == -1:
            db.insert_transaction(data)
        else:
            db.edit_transaction(data)
        db.close()

        parent = self.GetParent()
        if isinstance(parent, monthly_report.Report):
            funcs = {
                EXPENSE: parent.setup_monthly_expenses,
                INCOME: parent.setup_monthly_incomes
            }
            setup = funcs[self.transaction_type]
            setup(None)

        if self.key == -1:
            self.clean()
            confirmation_option = -1
            if self.transaction_type is EXPENSE:
                confirmation_option = 2
            elif self.transaction_type is INCOME:
                confirmation_option = 7
            dialogs.Confirmation(self, u"Sucesso", confirmation_option)

        else:
            self.exit(None)
Example #6
0
    def delivery_check(self, event=None):
        self.timer_delivery.Stop()

        date_now, time_now = core.datetime_today()

        date_now_int = core.date2int(date_now)
        time_now_int = core.hour2int(time_now[:5])

        deliveries_db = database.DeliveriesDB()
        deliveries = deliveries_db.deliveries_list()

        check_interval = 30
        for _delivery in deliveries:
            date_delivery_int = core.date2int(_delivery.date)

            if date_delivery_int < date_now_int:
                _delivery.active = False
                deliveries_db.delete_delivery(_delivery.ID)

            if _delivery.active is False and _delivery.ID in self.notification_control:
                del self.notification_control[_delivery.ID]

            if date_delivery_int != date_now_int or _delivery.active is False:
                continue

            if _delivery.ID in self.notification_control:
                continue

            time_delivery_int = core.hour2int(_delivery.hour)
            time_remaining = time_delivery_int - time_now_int
            if time_remaining < 60:
                minutes_to_warning = 0
            else:
                minutes_to_warning = time_remaining - 60

            self.notification_control[_delivery.ID] = _delivery

            timer = threading.Timer(60 * minutes_to_warning + 1,
                                    self.notify_delivery,
                                    args=[_delivery])
            self.deliveries_timers.append(timer)
            timer.start()

        deliveries_db.close()

        check_interval *= 60000
        if not check_interval:
            check_interval = 300000
        self.timer_delivery.Start(check_interval)
Example #7
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()
Example #8
0
    def setup_item_color(self, item, data_type):

        lists = {EXPENSE: self.list_expenses, INCOME: self.list_incomes}
        list_ctrl = lists[data_type]

        date = core.datetime_today()[0]
        transaction_date = core.format_date_internal(
            list_ctrl.GetItemText(item, 4))

        date_diference = core.date2int(transaction_date) - core.date2int(date)

        if date_diference < 0:
            color = '#FC1501'
        elif date_diference < 2:
            color = '#FF8600'
        else:
            color = '#1C86EE'
        list_ctrl.SetItemTextColour(item, color)
Example #9
0
    def start(self):
        if self.routine_type == core.ON_TIME:
            time_now = core.hour2int(core.datetime_today()[1][:-3])
            time_objective = core.hour2int(self.time)
            minutes_to_exec = time_objective - time_now

            if minutes_to_exec < 0:
                self.destroy()
                return

            self.timer = threading.Timer(60 * minutes_to_exec, self.execute)
            self.timer.start()

        elif self.routine_type == core.ON_START:
            thread = threading.Timer(3, self.execute)
            thread.start()

        else:
            self.execute()
Example #10
0
def notify_pendant_transactions(transaction_type, parent=None):
    import database
    import dialogs

    today = core.datetime_today()[0]
    advance = st.config2type(
        st.CONFIG.get(st.CONFIG_SECTION_NOTIFICATIONS,
                      st.CONFIG_FIELD_TRANSACTION_ADVANCE), int)
    limit_day = core.int2date(core.date2int(today) + advance)

    db = database.TransactionsDB()
    transactions = db.pendant_transactions_list(up_to=limit_day)
    db.close()

    for exchange in transactions:
        if exchange.type == transaction_type:
            gui_line.open(dialogs.TransactionNotification,
                          parent,
                          exchange,
                          title=exchange.description)
Example #11
0
def atualizar_imposto_122741():
    import threading
    import core

    last_update = settings.CONFIG.get(
        settings.CONFIG_SECTION_SAT, settings.CONFIG_FIELD_LAST_UPDATE_IMPOSTO)
    interval = int(
        settings.CONFIG.get(settings.CONFIG_SECTION_SAT,
                            settings.CONFIG_FIELD_UPDATE_IMPOSTO_INTERVAL))

    now_date = core.date2int(core.datetime_today()[0])
    last_date = core.date2int(last_update)

    if now_date >= last_date + interval:
        thread = threading.Thread(target=__atualiza_imposto_122741)
    else:
        thread = threading.Thread(target=__fila_imposto_122741)

    thread.setDaemon(True)
    thread.start()
Example #12
0
    def end(self):
        if not self.textbox_client_name.GetValue():
            return dialogs.launch_error(self, u'É necessário o nome, para o cadastro')
        rdate = core.datetime_today()[0]

        xname = self.textbox_client_name.GetValue()
        names = xname.strip().split()
        for i in range(0, len(names)):
            names[i] = names[i].capitalize()
        namef = ' '.join(names)

        data = data_types.ClientData()
        data.name = namef
        data.sex = self.textbox_client_sex.GetValue()
        data.birth = core.format_date_internal(self.textbox_client_birth.GetValue())
        data.email = self.textbox_client_email.GetValue()
        data.cpf = self.textbox_client_cpf.GetValue().replace('-', '').replace('.', '')
        data.telephone = self.textbox_client_telephone.GetValue().replace('-', '').replace('(', '').replace(')', '')
        data.cep = self.textbox_client_cep.GetValue().replace('-', '')
        data.state = self.textbox_client_state.GetValue()
        data.city = self.textbox_client_city.GetValue()
        data.district = self.textbox_client_district.GetValue()
        data.address = self.textbox_client_address.GetValue()
        data.obs = self.textbox_client_observations.GetValue()
        data.record_date = rdate

        db = database.ClientsDB()
        db.insert_client(data)
        db.close()

        self.clean()
        parent = self.GetParent()
        if isinstance(parent, sale.Sale):
            parent.textbox_client_name.SetValue(data.name)
            parent.textbox_client_cpf.SetValue(core.format_cpf(data.cpf))
            self.exit(None)
            return
        dialogs.Confirmation(self, u'Sucesso', 4)
Example #13
0
    def setup(self, event=None):
        date_today = core.datetime_today()[0]

        show_all = True if self.combobox_show_option.GetSelection() else False

        deliveries_db = database.DeliveriesDB()
        database_deliveries = deliveries_db.deliveries_list(show_all=show_all)
        deliveries_dates = dict()

        date_today_int = core.date2int(date_today)
        for delivery in database_deliveries:
            date_delivery_int = core.date2int(delivery.date)

            if date_delivery_int < date_today_int:
                delivery.active = False
                deliveries_db.delete_delivery(delivery.ID)
                continue
            if delivery.date not in deliveries_dates:
                deliveries_dates[delivery.date] = []
            deliveries_dates[delivery.date].append(delivery)

        deliveries_db.close()

        self.list_deliveries.DeleteAllItems()

        root = self.list_deliveries.AddRoot(u"--------")
        self.list_deliveries.SetItemFont(root, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
        amount = 0

        for date in deliveries_dates:
            date_item = self.list_deliveries.AppendItem(root, date)
            self.list_deliveries.SetItemFont(date_item, wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
            counter = 0
            active = False
            for delivery in deliveries_dates[date]:
                counter += 1

                a = self.list_deliveries.AppendItem(date_item, delivery.date)
                self.list_deliveries.SetItemText(a, delivery.hour, 1)
                self.list_deliveries.SetItemText(a, delivery.city + ', ' + delivery.address, 2)
                self.list_deliveries.SetItemText(a, delivery.receiver, 3)

                self.list_deliveries.SetItemData(a, wx.TreeItemData(delivery))
                if not delivery.active:
                    self.list_deliveries.SetItemTextColour(a, '#ADADAD')
                else:
                    active = True

            text = u' Entrega'
            text = text + u's' if counter > 1 else text
            self.list_deliveries.SetItemText(date_item, str(counter) + text, 2)
            if not active:
                self.list_deliveries.SetItemTextColour(date_item, '#ADADAD')
            amount += counter
        if not show_all:
            text = u' ENTREGA PROGRAMADA'
        else:
            text = u' ENTREGA REGISTRADA'
        text = text[:8] + u'S' + text[8:] + u'S' if amount > 1 else text
        amount_str = str(amount) if amount > 0 else u'NENHUMA'
        self.list_deliveries.SetItemText(root, amount_str + text, 2)
        self.list_deliveries.ExpandAll(root)