Example #1
0
def balance_graph():
    balance_x = [(op.date_op.strftime(_(u"%d/%b")).decode('utf-8'))
                 for op in Operation.select().filter(type_="balance").order_by(("date_op"))]
    balance_y = [(op.balance) for op in Operation.select()\
                                                 .order_by(("date_op"))\
                                                 .filter(type_="balance")]
    return balance_x, balance_y
Example #2
0
def balance_graph():
    balance_x = [(op.date_op.strftime(_(u"%d/%b")).decode('utf-8'))
                 for op in Operation.select().filter(
                     type_="balance").order_by(("date_op"))]
    balance_y = [(op.balance) for op in Operation.select()\
                                                 .order_by(("date_op"))\
                                                 .filter(type_="balance")]
    return balance_x, balance_y
Example #3
0
def last_operation(type_op=""):
    """ last operation """
    if type_op != "":
        try:
            return Operation.select().filter(Operation.type == type_op)\
                                               .order_by(("date_op", "desc")).get()

        except:
            raise
            return 0
    else:
        try:
            return Operation.select().\
                             order_by(("date_op", "desc")).get().date_op
        except:
            raise
            pass
Example #4
0
def last_operation(type_op=""):
    """ last operation """
    if type_op != "":
        try:
            return Operation.select().filter(Operation.type == type_op)\
                                               .order_by(("date_op", "desc")).get()

        except:
            raise
            return 0
    else:
        try:
            return Operation.select().\
                             order_by(("date_op", "desc")).get().date_op
        except:
            raise
            pass
Example #5
0
def last_balance():
    """ last balance """
    try:
        last_balance = Operation.select().order_by(("date_op", "desc")).get()
        return last_balance.balance

    except AttributeError:
        raise
        pass
Example #6
0
def last_balance():
    """ last balance """
    try:
        last_balance = Operation.select().order_by(("date_op", "desc")).get()
        return last_balance.balance

    except AttributeError:
        raise
        pass
Example #7
0
def handle_message(message):
    check = Qiwi(token_qiwi)
    elements_to_check = check.find_pay(str(message.from_user.id),
                                       check.get_history())
    # print(elements_to_check)
    if elements_to_check['total']['amount'] == 10 and elements_to_check[
            'total']['currency'] == 643:
        my_database = Operation()
        if my_database.select(str(message.from_user.id),
                              elements_to_check['date']):
            bot.send_message(message.chat.id,
                             f'Новых платежей от вас не поступало')
        else:
            my_database.commit(str(message.from_user.id),
                               elements_to_check['date'])
            bot.send_message(message.chat.id, f'Логин:{12}\nПароль:{1}')
    else:
        bot.send_message(message.chat.id, 'Ожидаются данный')
Example #8
0
def consumption():
    """ Calculation of consumption per day. """
    list_consump = []
    data_balance = [(op.balance, op.date_op, op.type_) for op in Operation.select().order_by(("date_op"))]

    for i in range(len(data_balance) -1):
        if data_balance[i + 1][2] == "balance":
            list_consump.append((data_balance[i][1], abs(int(data_balance[i][0])
                                 - int(data_balance[i + 1][0]))))
    return list_consump
Example #9
0
def consumption():
    """ Calculation of consumption per day. """
    list_consump = []
    data_balance = [(op.balance, op.date_op, op.type_)
                    for op in Operation.select().order_by(("date_op"))]

    for i in range(len(data_balance) - 1):
        if data_balance[i + 1][2] == "balance":
            list_consump.append(
                (data_balance[i][1],
                 abs(int(data_balance[i][0]) - int(data_balance[i + 1][0]))))
    return list_consump
Example #10
0
    def add_operation(self):
        ''' add operation '''
        year, month, day = self.invoice_date.text().split('-')
        invoice_date = date(int(year), int(month), int(day))
        period = period_for(invoice_date)

        try:
            amount = int(self.amount.text())
        except ValueError:
            amount = 0

        if self.order_number.text() and self.invoice_number.text() and \
            invoice_date and self.provider.text() and self.amount.text()\
            and invoice_date >= self.main_period.start_on and invoice_date <= \
            self.main_period.end_on and amount < self.balance:
            operation = Operation(unicode(self.order_number.text()),
                        unicode(self.invoice_number.text()), invoice_date, \
                        unicode(self.provider.text()), amount)
            operation.account = self.account
            operation.period = period
            session.add(operation)
            session.commit()
            raise_success(_(u'Confirmation'), _(u'Registered opération'))
            self.order_number.clear()
            self.invoice_number.clear()
            self.provider.clear()
            self.amount.clear()
            self.adjust_balance(period)
            self.refresh()
        elif invoice_date > self.main_period.end_on or\
             invoice_date < self.main_period.start_on:
            raise_error(_(u'Error date'), \
            _(u'The date is not included in the current quarter.'))
        elif amount >= self.balance:
            raise_error(_(u'Error money'),\
             _(u"There is not enough money for this operation."))
        else:
            raise_error(_(u'Error field'), _(u'You must fill in all fields.'))
Example #11
0
def build_balance_report(filename=None, format='pdf'):
    ''' PDF: List of balances '''
    if not filename:
        filename = get_temp_filename('pdf')

    doc = Document(title=_(u"List of balances"))

    table = Table(4)
    table.add_header_row([
        Text(_(u"Date")),
        Text(_(u"Type")),
        Text(_(u"Value")),
        Text(_(u"Balance"))
    ])

    # column widths
    table.set_column_width(20, 0)
    table.set_column_width(10, 2)
    table.set_column_width(15, 3)

    # column alignments
    table.set_alignment(Table.ALIGN_LEFT, column=0)
    table.set_alignment(Table.ALIGN_LEFT, column=1)
    table.set_alignment(Table.ALIGN_RIGHT, column=2)
    table.set_alignment(Table.ALIGN_RIGHT, column=3)

    operations = [(op.date_op, op.type_, op.value, op.balance) \
                    for op in Operation.select().order_by(("date_op"))
                    .filter(type_="balance")]

    for operation in operations:
        table.add_row([
            Text(unicode(operation[0])),
            Text(unicode(operation[1])),
            Text(formatted_number(operation[2])),
            Text(formatted_number(operation[3]))
        ])

    doc.add_element(table)

    gen = PDFGenerator(doc, filename)
    gen.render_document()

    return gen.get_filename()
Example #12
0
    def add_statement(self):
        ''' add statement '''
        types = {0: "balance", 1: "added", 2: "cut", 3: "recovery"}
        commit = False
        for data in self.list_data:
            date_op = data[0].text()
            time_op = data[1].text()
            type_op = types[data[2].currentIndex()]
            value_op = data[3].text()

            day, month, year = date_op.split('/')
            hour, minute = time_op.split(':')
            datetime_ = datetime(int(year), int(month), int(day), int(hour),
                                 int(minute))
            flag = False
            last_b = last_balance()
            if value_op:
                flag = True
            if type_op == "recovery" or type_op == "cut":
                flag = True
            if flag:
                if type_op == "added":
                    if last_b == None:
                        balance = int(value_op)
                    else:
                        balance = int(last_b) + int(value_op)
                if type_op == "balance":
                    balance = unicode(value_op)
                if type_op == "recovery" or type_op == "cut":
                    balance = unicode(last_b)

                try:
                    operation = Operation.create(date_op=datetime_,
                                                 type_=unicode(type_op),
                                                 value=unicode(value_op),
                                                 balance=balance)
                    raise_success(_(u"Confirmation"),
                                  _(u"Registered opération"))
                except:
                    raise
                    raise_error(_(u"Confirmation"),
                                _(u"There is no valid operation"))
        self.change_main_context(DashbordViewWidget)
Example #13
0
def build_balance_report(filename=None, format='pdf'):
    ''' PDF: List of balances '''
    if not filename:
        filename = get_temp_filename('pdf')

    doc = Document(title=_(u"List of balances"))

    table = Table(4)
    table.add_header_row([
            Text(_(u"Date")),
            Text(_(u"Type")),
            Text(_(u"Value")),
            Text(_(u"Balance"))])

    # column widths
    table.set_column_width(20, 0)
    table.set_column_width(10, 2)
    table.set_column_width(15, 3)

    # column alignments
    table.set_alignment(Table.ALIGN_LEFT, column=0)
    table.set_alignment(Table.ALIGN_LEFT, column=1)
    table.set_alignment(Table.ALIGN_RIGHT, column=2)
    table.set_alignment(Table.ALIGN_RIGHT, column=3)

    operations = [(op.date_op, op.type_, op.value, op.balance) \
                    for op in Operation.select().order_by(("date_op"))
                    .filter(type_="balance")]

    for operation in operations:
        table.add_row([
            Text(unicode(operation[0])),
            Text(unicode(operation[1])),
            Text(formatted_number(operation[2])),
            Text(formatted_number(operation[3]))])

    doc.add_element(table)

    gen = PDFGenerator(doc, filename)
    gen.render_document()

    return gen.get_filename()
Example #14
0
    def add_statement(self):
        """ add statement """
        types = {0: "balance", 1: "added", 2: "cut", 3: "recovery"}
        commit = False
        for data in self.list_data:
            date_op = data[0].text()
            time_op = data[1].text()
            type_op = types[data[2].currentIndex()]
            value_op = data[3].text()

            day, month, year = date_op.split("/")
            hour, minute = time_op.split(":")
            datetime_ = datetime(int(year), int(month), int(day), int(hour), int(minute))
            flag = False
            last_b = last_balance()
            if value_op:
                flag = True
            if type_op == "recovery" or type_op == "cut":
                flag = True
            if flag:
                if type_op == "added":
                    if last_b == None:
                        balance = int(value_op)
                    else:
                        balance = int(last_b) + int(value_op)
                if type_op == "balance":
                    balance = unicode(value_op)
                if type_op == "recovery" or type_op == "cut":
                    balance = unicode(last_b)

                try:
                    operation = Operation.create(
                        date_op=datetime_, type_=unicode(type_op), value=unicode(value_op), balance=balance
                    )
                    raise_success(_(u"Confirmation"), _(u"Registered opération"))
                except:
                    raise
                    raise_error(_(u"Confirmation"), _(u"There is no valid operation"))
        self.change_main_context(DashbordViewWidget)
Example #15
0
    def set_data_for(self):

        self.data = [(op.date_op.strftime(_(u'%x %Hh:%Mmn')), op.type_,
                      formatted_number(op.value), formatted_number(op.balance))
                     for op in Operation.select().order_by(('date_op', 'asc'))]
Example #16
0
    def set_data_for(self):

        self.data = [(op.date_op.strftime(_(u'%x %Hh:%Mmn')), op.type_,
                     formatted_number(op.value), formatted_number(op.balance))
                     for op in Operation.select().order_by(('date_op', 'asc'))]
Example #17
0
    def __init__(self, parent, *args, **kwargs):
        QtGui.QDialog.__init__(self, parent, *args, **kwargs)

        self.data = Operation.select().order_by("date_op")

        title = QtGui.QLabel()
        self.setWindowTitle(_(u"Delete an operation"))
        if self.data == []:
            title.setText(_(u"There is no operation removed for this account"))
            ok_butt = QtGui.QPushButton(_(u"OK"))
            ok_butt.clicked.connect(self.close)

            vbox = QtGui.QVBoxLayout()
            vbox.addWidget(title)
            vbox.addWidget(ok_butt)
            self.setLayout(vbox)
        else:
            title.setText(_(u"Select a statement has deleted"))
            title.setAlignment(QtCore.Qt.AlignHCenter)
            title_hbox = QtGui.QHBoxLayout()
            title_hbox.addWidget(title)

            #Combobox widget
            # self.box = QtGui.QComboBox()
            # for index in xrange(0, self.data.count()):
            #     op = self.data[index]
            #     sentence = _(u"%(date_op)s - %(type)s - " \
            #                  u"%(value)s/%(balance)s ")\
            #                  % {'date_op': op.date_op, \
            #                     'type': op.type, \
            #                     'value': op.value, \
            #                     'balance': formatted_number(op.balance)}
            #     self.box.addItem(sentence, QtCore.QVariant(op.id))
            self.box = QtGui.QComboBox()
            for index in self.data:
                op = index
                sentence = _(u"%(date_op)s - %(type)s - " \
                             u"%(value)s/%(balance)s ")\
                             % {'date_op': op.date_op, \
                                'type': op.type_, \
                                'value': op.value, \
                                'balance': formatted_number(op.balance)}
                self.box.addItem(sentence, QtCore.QVariant(op.id))

            combo_hbox = QtGui.QHBoxLayout()
            combo_hbox.addWidget(self.box)

            #delete and cancel hbox
            button_hbox = QtGui.QHBoxLayout()

            #Delete Button widget.
            delete_but = QtGui.QPushButton(_(u"Delete"))
            delete_but.clicked.connect(self.delete)
            #Cancel Button widget.
            cancel_but = QtGui.QPushButton(_(u"Cancel"))
            cancel_but.clicked.connect(self.cancel)

            button_hbox.addWidget(cancel_but)
            button_hbox.addWidget(delete_but)
            #Create the QVBoxLayout contenaire.
            vbox = QtGui.QVBoxLayout()
            vbox.addLayout(title_hbox)
            vbox.addLayout(combo_hbox)
            vbox.addLayout(button_hbox)
            self.setLayout(vbox)