Example #1
0
def paypal_cross_ref(item, days_before):
    item = item.lower()
    Desc, Bal, In, Out, Date = item.split(';')
    Out = tc.str2float(Out)
    if 'payp' in Desc:
        date1 = tc.str2date(Date) - dt.timedelta(days_before)
        date2 = tc.str2date(Date) + dt.timedelta(1)
        possible_paypal_data = dataframe_date_splice(paypal_data, date1, date2)
        possible_paypal_data[' Amount'] = possible_paypal_data[
            ' Amount'].apply(tc.str2float)
        if Out:
            possible_paypal_item = possible_paypal_data.loc[
                possible_paypal_data[' Amount'] == -tc.str2float(Out)]
            unique_entries = possible_paypal_item[' Name'].unique()
            if len(unique_entries) > 1:
                unique_entries = [
                    i for i in unique_entries
                    if all(j not in i.lower() for j in ['payp', 'credit card'])
                ]
                if len(unique_entries) > 1:
                    print("\n\nDescription = ", Desc, "\nDate = ", Date,
                          "\nIn = ", In, "\nOut = ", Out,
                          "\nPossible Paypal Item:\n", unique_entries)
                else:
                    if len(unique_entries):
                        return unique_entries[0] + ' (payp)'
            else:
                if len(unique_entries):
                    return unique_entries[0] + ' (payp)'
                else:
                    new_poss_paypal_item = possible_paypal_data.loc[
                        possible_paypal_data[' Amount'] == Out]
                    if len(new_poss_paypal_item):
                        if new_poss_paypal_item[' Name'].values[0].replace(
                                ' ', '').lower() == 'bankaccount':
                            balance = tc.str2float(
                                new_poss_paypal_item[' Balance'].values[0])
                            possible_paypal_data[
                                ' Amount'] = possible_paypal_data[
                                    ' Amount'].apply(tc.str2float)
                            possible_items = possible_paypal_data.loc[
                                possible_paypal_data[' Amount'] ==
                                -balance][' Name'].unique()
                            if len(possible_items) == 1:
                                return possible_items[0]
                            else:
                                return paypal_cross_ref(item, 21)
                                print("\n\nDescription = ", Desc, "\nDate = ",
                                      Date, "\nIn = ", In, "\nOut = ", Out,
                                      "\nPossible Paypal Data:\n",
                                      possible_paypal_data)
                                return "Non"
                    return Desc
        else:
            return "Paypal Transfer"
    else:
        return Desc
Example #2
0
 def setData(self, index, value, role=Qt.EditRole):
     if role == Qt.EditRole:
         row = index.row()
         col = index.column()
         if type(value) == str:
             self._data[row, col] = tc.tablePrep(
                 value)  # Set the data to the newly typed value
             return True
         return False
Example #3
0
    def data(self, index, role):  #Controls how the data looks in the table
        global Editted_Items
        if index.isValid():
            rowI, colI = index.row(), index.column()
            if role == Qt.EditRole:
                if (rowI, colI) not in Editted_Items:
                    Editted_Items.append((rowI, colI))
                return tc.tablePrep(self._data[rowI, colI])

            if role == Qt.DisplayRole:  # Displays the data
                if type(tc.tablePrep(self._data[rowI, colI])) != str:
                    print(type(tc.tablePrep(self._data[rowI, colI])))
                return tc.tablePrep(self._data[rowI, colI])

            if role == Qt.TextColorRole:
                col = self._cols[colI]
                row = rowI
                if col == 'Balance' and float(self._data[row, colI]) < 0:
                    return QVariant(QColor('#ff0000'))

        return None
Example #4
0
    def data(self, index, role):
        if index.isValid():
            if role == Qt.DisplayRole:  # Displays the data
                return tc.tablePrep(self._data[index.row(), index.column()])

            if role == Qt.TextAlignmentRole:
                return Qt.AlignCenter

            if role == Qt.TextColorRole:
                col = index.column()
                if col == 0:
                    return QVariant(QColor('#228B22'))
                if col == 1:
                    return QVariant(QColor('#65000B'))
        return None
Example #5
0
def Data_Read(filepath, paypal=False):
    if os.path.isdir(filepath):
        if paypal == False:
            datafilepaths = find_files(filepath)
        else:
            datafilepaths = find_paypal_files(filepath)
        data_clean(
            datafilepaths
        )  # Permanently removes sensitive/useless data from bank statements
        DATA = data_read_and_concat(
            datafilepaths
        )  # Reads the statement files and collates them into 1 dataframe
    else:
        DATA = data_read_and_concat('./')

    if len(DATA):
        names = dict_parser(col_head_filepath, 'c')  #Grabbing the data headers

        ### Changing the names of the statement columns
        cols = DATA.columns
        new_cols = dict_value_search(names, list(cols))
        DATA.columns = new_cols
        DATA = drop_nan_cols(DATA, 0.8)

        DATA = split_in_out_col(DATA, names)
        DATA.index = range(len(DATA))
        ###
    else:
        print(
            "\n\n\nSorry there are no '.csv' files could be found in the directory '"
            + filepath +
            "'\nAre you sure this is where you want me to look?\n\n\n\n")
        raise OSError(' '.join(["No files found in ", filepath]))

    ### Converting the type from string to something more useful
    for i in DATA.columns:
        DATA[i] = DATA[i].apply(tc.str2num)
        if DATA[i].dtype == object:
            DATA[i] = tc.str2date(DATA[i])
    ###
    if len(datafilepaths):
        dict_DATA, act_nums = Initial_Prep(DATA)
        ###
        cols_ordered = [
            'Description', 'Category', 'In', 'Out', 'Date', 'Balance', 'Type'
        ]
        Plottable_cols = []
        for i in dict_DATA:
            if paypal:
                for col in ['Balance', 'In', 'Out', 'Date']:
                    dict_DATA[i]['Description'] = dict_DATA[i][
                        'Description'] + ';' + dict_DATA[i][col].apply(
                            tc.string)
                dict_DATA[i]['Description'] = dict_DATA[i][
                    'Description'].apply(paypal_cross_ref, args=(7, ))
            dict_DATA[i]['Category'] = dict_DATA[i]['Type']
            for col in ['Description', 'Balance', 'In', 'Out', 'Date']:
                dict_DATA[i]['Category'] = dict_DATA[i][
                    'Category'] + ';' + dict_DATA[i][col].apply(tc.string)
            dict_DATA[i].index = range(len(
                dict_DATA[i]))  # Resorting the index
            dict_DATA[i]['Category'] = dict_DATA[i]['Category'].apply(
                categoriser)
            dict_DATA[i] = dict_DATA[i].sort_values(by='Date', ascending=False)
            dict_DATA[i] = dict_DATA[i][
                cols_ordered]  # Re-Ordering the Columns
            dict_DATA[i]['Description'] = dict_DATA[i]['Description'].apply(
                st.capital)

        for col in dict_DATA[act_nums[0]].columns:
            if dict_DATA[act_nums[0]][col].apply(tc.dataPrep).dtype != object:
                Plottable_cols.append(col)

    return dict_DATA, Plottable_cols
Example #6
0
 def calbut2change(self, date):
     strdate2 = tc.date2str(date)
     self.ButtonFrame.Date2Button.setText(strdate2)
Example #7
0
 def calbut1change(self, date):
     strdate1 = tc.date2str(date)
     self.ButtonFrame.Date1Button.setText(strdate1)