示例#1
0
    def add_expense(self):
        item_name = self.item_name.text
        value = self.value.text
        exp_date = self.datelabel.text

        if item_name is None or item_name == '' or \
                value is None or value == '' or \
                exp_date is None or exp_date == '':
            self.lbl_message.text = 'Required input missing.'
            self.lbl_message.theme_text_color = 'Error'
            return

        item_id = Items.get_item(item_name=item_name, item_link=None)
        if item_id is None or item_id == 0:
            self.lbl_message.text = 'No Category/Sub-Category by this name. ' \
                                    'Please create if required from Items screen.'
            self.lbl_message.theme_text_color = 'Error'
            return

        if value == '0':
            self.lbl_message.text = 'Enter an amount not equal to 0'
            self.lbl_message.theme_text_color = 'Error'
            return

        expense_id = Expenses.get_next_exp_id()

        kwargs = {'expense_id': expense_id,
                  'item_id': item_id,
                  'value': float(value),
                  'date': exp_date}

        Expenses.add_expense(**kwargs)

        toast('Expense Added')
        self.leave_screen()
示例#2
0
    def add_expense(self):
        item_name = self.item_name.text
        value = self.value.text
        exp_date = self.datelabel.text

        if (item_name is None or item_name == "" or value is None
                or value == "" or exp_date is None or exp_date == ""):
            self.lbl_message.text = "Required input missing."
            self.lbl_message.theme_text_color = "Error"
            return

        item_id = Items.get_item(item_name=item_name, item_link=None)
        if item_id is None or item_id == 0:
            self.lbl_message.text = (
                "No Category/Sub-Category by this name. "
                "Please create if required from Items screen.")
            self.lbl_message.theme_text_color = "Error"
            return

        if value == "0":
            self.lbl_message.text = "Enter an amount not equal to 0"
            self.lbl_message.theme_text_color = "Error"
            return

        expense_id = Expenses.get_next_exp_id()

        kwargs = {
            "expense_id": expense_id,
            "item_id": item_id,
            "value": float(value),
            "date": exp_date,
        }

        Expenses.add_expense(**kwargs)

        toast("Expense Added")
        self.leave_screen()
示例#3
0
    def update_totals(self):
        currency = self.app.config.get("CustSettings", "Currency")
        totals = Expenses.get_totals(self.current_date)
        self.ids.lbl_day_total.text = "{} {}".format(currency,
                                                     str(totals["day"]))
        self.ids.lbl_month_total.text = "{} {}".format(currency,
                                                       str(totals["month"]))
        self.ids.lbl_year_total.text = "{} {}".format(currency,
                                                      str(totals["year"]))

        day_limit = float(self.app.config.get("CustSettings", "DayLimitAmt"))
        day_limit_flg = self.app.config.get("CustSettings", "DayLimitFlg")
        if totals["day"] > day_limit and day_limit_flg == "True":
            self.app.theme_cls.primary_palette = "Red"
        else:
            self.app.theme_cls.primary_palette = "Teal"
示例#4
0
    def update_totals(self):
        currency = app_scr.config.get('CustSettings', 'Currency')
        totals = Expenses.get_totals(self.current_date)
        self.ids.lbl_day_total.text = '{} {}'.format(currency,
                                                     str(totals['day']))
        self.ids.lbl_month_total.text = '{} {}'.format(currency,
                                                       str(totals['month']))
        self.ids.lbl_year_total.text = '{} {}'.format(currency,
                                                      str(totals['year']))

        day_limit = float(app_scr.config.get('CustSettings', 'DayLimitAmt'))
        day_limit_flg = app_scr.config.get('CustSettings', 'DayLimitFlg')
        if totals['day'] > day_limit and day_limit_flg == 'True':
            app_scr.theme_cls.primary_palette = 'Red'
        else:
            app_scr.theme_cls.primary_palette = 'Teal'
示例#5
0
 def refresh_list(self):
     self.ids.yearlist.clear_widgets()
     currency = app_scr.config.get('CustSettings', 'Currency')
     expense_dict = Expenses.get_expenses(date=self.current_date,
                                          date_type='year')
     if expense_dict == {}:
         self.ids.yearlist.add_widget(
             MDLabel(text='No expenses to show',
                     halign='center',
                     theme_text_color='Hint'))
     total = 0.0
     for key, value in expense_dict.items():
         self.ids.yearlist.add_widget(
             CustomListItem(text=key,
                            right_text='{} {}'.format(currency,
                                                      str(value))))
         total = total + float(value)
     self.ids.total.text = '{} {}'.format(currency, total)
示例#6
0
 def refresh_list(self):
     self.ids.monthlist.clear_widgets()
     currency = app_scr.config.get('CustSettings', 'Currency')
     expense_dict = Expenses.get_expenses(date=self.current_date,
                                          date_type='month')
     if expense_dict == {}:
         self.ids.monthlist.add_widget(
             MDLabel(text='No expenses to show',
                     halign='center',
                     theme_text_color='Hint'))
     total = 0.0
     for key, value in expense_dict.items():
         exp_date = datetime.strptime(key, '%Y-%m-%d')
         self.ids.monthlist.add_widget(
             CustomListItem(text=exp_date.strftime('%d %b %Y'),
                            right_text='{} {}'.format(currency,
                                                      str(value))))
         total = total + value
     self.ids.total.text = '{} {}'.format(currency, total)
示例#7
0
 def refresh_list(self):
     self.ids.list.clear_widgets()
     currency = app_scr.config.get('CustSettings', 'Currency')
     expense_dict = Expenses.get_expenses(
         date=self.current_date.strftime('%Y-%m-%d'), date_type='day')
     if expense_dict == {}:
         self.ids.list.add_widget(
             MDLabel(text='No expenses to show',
                     halign='center',
                     theme_text_color='Hint'))
     total = 0.0
     for key, value in expense_dict.items():
         self.ids.list.add_widget(
             CustomDayItem(text=value['item_name'],
                           right_text='{} {}'.format(
                               currency, str(value['value'])),
                           expense_id=key))
         total = total + value['value']
     self.ids.total.text = '{} {}'.format(currency, total)
示例#8
0
 def on_release(self, *args):
     Expenses.del_expense(expense_id=self.expense_id)
     expdetail_obj.daytab.refresh_list()
     expdetail_obj.yeartab.refresh_list()
     expdetail_obj.monthtab.refresh_list()
     Toast(opacity=0.5).toast('Expense Deleted')
示例#9
0
    def cre_list(self):
        self.ids.insight_list.clear_widgets()
        # Get maximum and minimum info.
        currency = app_scr.config.get('CustSettings', 'Currency')

        layout_box = FloatLayout()
        card_ = MDCard(orientation='vertical',
                       border_radius=10,
                       border_color_a=0.2,
                       elevation=10,
                       size_hint=(.95, .95),
                       pos_hint={
                           'x': .025,
                           'y': .025
                       })
        layout_box.add_widget(card_)

        max_dict = Expenses.get_borders()

        # Get the most expensive day.
        disp_data = max_dict['MEDay']
        card_.add_widget(
            MDLabel(text='Most Expensive Day',
                    halign='center',
                    bold=True,
                    font_style='Subtitle1',
                    theme_text_color='Primary'))
        box_meday = BoxLayout()
        box_meday.add_widget(
            MDLabel(text='    {}'.format(
                datetime.strptime(disp_data['date'],
                                  '%Y-%m-%d').strftime('%d %b %Y')),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        box_meday.add_widget(
            MDLabel(text='{} {}'.format(currency, disp_data['value']),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        card_.add_widget(box_meday)

        # Get the least expensive day.
        disp_data = max_dict['LEDay']
        card_.add_widget(
            MDLabel(text='Least Expensive Day',
                    halign='center',
                    bold=True,
                    font_style='Subtitle1',
                    theme_text_color='Primary'))
        box_leday = BoxLayout()
        box_leday.add_widget(
            MDLabel(text='    {}'.format(
                datetime.strptime(disp_data['date'],
                                  '%Y-%m-%d').strftime('%d %b %Y')),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        box_leday.add_widget(
            MDLabel(text='{} {}'.format(currency, disp_data['value']),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        card_.add_widget(box_leday)

        # Get the most expensive month.
        disp_data = max_dict['MEMonth']
        card_.add_widget(
            MDLabel(text='Most Expensive Month',
                    halign='center',
                    bold=True,
                    font_style='Subtitle1',
                    theme_text_color='Primary'))
        box_memonth = BoxLayout()
        box_memonth.add_widget(
            MDLabel(text='    {}'.format(
                datetime.strptime(disp_data['date'],
                                  '%Y-%m').strftime('%b %Y')),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        box_memonth.add_widget(
            MDLabel(text='{} {}'.format(currency, disp_data['value']),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        card_.add_widget(box_memonth)

        # Get the least expensive month.
        disp_data = max_dict['LEMonth']
        card_.add_widget(
            MDLabel(text='Least Expensive Month',
                    halign='center',
                    bold=True,
                    font_style='Subtitle1',
                    theme_text_color='Primary'))
        box_lemonth = BoxLayout()
        box_lemonth.add_widget(
            MDLabel(text='    {}'.format(
                datetime.strptime(disp_data['date'],
                                  '%Y-%m').strftime('%b %Y')),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        box_lemonth.add_widget(
            MDLabel(text='{} {}'.format(currency, disp_data['value']),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        card_.add_widget(box_lemonth)

        card_.add_widget(BoxLayout())
        # Add the box to accorion list item
        acc_im = MDAccordionItem2(title='Max-Mins')
        acc_im.add_widget(layout_box)
        self.ids.insight_list.add_widget(acc_im)

        # Averages
        layout_boxa = FloatLayout()
        card_a = MDCard(orientation='vertical',
                        border_radius=10,
                        border_color_a=0.2,
                        elevation=10,
                        size_hint=(.95, .5),
                        pos_hint={
                            'x': .025,
                            'y': .475
                        })
        layout_boxa.add_widget(card_a)

        avg_dict = Expenses.get_avgs()

        # Get the average daily expense.
        disp_data = avg_dict['day_avg']
        box_avgday = BoxLayout()
        box_avgday.add_widget(
            MDLabel(text='    {}'.format('Average Daily Expense'),
                    halign='center',
                    bold=True,
                    theme_text_color='Primary',
                    size_hint_x=.5))
        box_avgday.add_widget(
            MDLabel(text='{} {}'.format(currency, disp_data),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        card_a.add_widget(box_avgday)

        # Get the average monthly expense.
        disp_data = avg_dict['month_avg']
        box_avgmonth = BoxLayout()
        box_avgmonth.add_widget(
            MDLabel(text='    {}'.format('Average Monthly Expense'),
                    halign='center',
                    bold=True,
                    theme_text_color='Primary',
                    size_hint_x=.5))
        box_avgmonth.add_widget(
            MDLabel(text='{} {}'.format(currency, disp_data),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        card_a.add_widget(box_avgmonth)

        # Get the average daily expense.
        disp_data = avg_dict['year_avg']
        box_avgyear = BoxLayout()
        box_avgyear.add_widget(
            MDLabel(text='    {}'.format('Average Yearly Expense'),
                    halign='center',
                    bold=True,
                    theme_text_color='Primary',
                    size_hint_x=.5))
        box_avgyear.add_widget(
            MDLabel(text='{} {}'.format(currency, disp_data),
                    halign='center',
                    theme_text_color='Primary',
                    size_hint_x=.5))
        card_a.add_widget(box_avgyear)

        acc_ia = MDAccordionItem2(title='Averages')
        acc_ia.add_widget(layout_boxa)
        self.ids.insight_list.add_widget(acc_ia)