def add_ledger_manually(self): input = self.uns.get_add_ledger_manually_input() trans_id = str(uuid.uuid4()) # Add transaction for reference transaction = dsvct.enter_if_not_exists(transaction_category=input['transaction_category'] , transaction_id=trans_id , description=input['description'] , debit=input['debit'] , credit=input['credit'] , source=TransactionSource.MANUALENTRY , date_stamp=input['date_stamp'] , payment_type=input['payment_type'] , handled=TransactionStatus.HANDLED) ledger = dsvcl.enter_if_not_exists(transaction_id=trans_id , description=input['description'] , transaction_category=input['transaction_category'] , debit=input['debit'] , credit=input['credit'] , from_account=input['from_account'].account_name , from_bucket=input['from_bucket'].name , to_account=input['to_account'].account_name , to_bucket=input['to_bucket'].name , source=TransactionSource.MANUALENTRY , spend_category=input['spend_category'] , payment_type=input['payment_type'] , date_stamp=input['date_stamp'] , notes=input['notes']) if ledger is None: self.uns.notify_user("Ledger item already exists") return self.uns.notify_user("Ledger Entry added successfully")
def _record_expense(self): trans_id = str(uuid.uuid4()) input = self.uns.get_record_expense_input(self) if input is None: return from_account = input['from_account'] from_bucket = input['from_bucket'] transaction = dsvct.enter_if_not_exists( transaction_id=trans_id, description=input["description"], transaction_category=TransactionTypes.RECORD_EXPENSE, debit=input['debit'], credit=0, source=TransactionSource.MANUALENTRY, payment_type=input['payment_type'], date_stamp=input['date_stamp'], handled=TransactionStatus.UNHANDLED ) ledger = ledgerManager.approve_transaction(transaction, self) dsvca.update_bucket_saved_amount(account=from_account, bucketName=ledger.from_bucket, newAmount=from_bucket.saved_amount - input['debit']) # Need to add an open balance if the payment type was Bank if input['payment_type'] == PaymentType.BANK: dsvca.add_open_balance_to_account(from_account, input['description'], input['debit'])
def read_in_barclay_transactions(filepath: str): # Read in the BarclayCardUs data from csv barclay_data = pd.read_csv(filepath, skiprows=[0, 1, 2, 3], ) # Transalate BarclayCardUs transactions to standard transaction format barclay_transactions = [] for transaction in barclay_data.to_dict('rows'): if transaction['Category'] == 'DEBIT': debit = -transaction["Amount"] credit = 0 transaction_category = TransactionTypes.RECORD_EXPENSE elif transaction['Category'] == 'CREDIT' and transaction['Description'] == 'PaymentReceived': debit = 0 credit = transaction['Amount'] transaction_category = TransactionTypes.APPLY_PAYMENT elif transaction['Category'] == 'CREDIT' and transaction['Description'] != 'PaymentReceived': debit = 0 credit = transaction['Amount'] transaction_category = TransactionTypes.RECEIVE_REFUND else: raise Exception(f"Unhandled transaction category for BarclaycardUS: {transaction['Category']}") new = dsvct.enter_if_not_exists(transaction_category=transaction_category , transaction_id=str(uuid.uuid4()) , description=transaction['Description'] , debit=debit , credit=credit , source=TransactionSource.BARCLAYCARDUS , payment_type=PaymentType.CREDIT , date_stamp=parser.parse(transaction['Transaction Date'])) if new is not None: barclay_transactions.append(new) return barclay_transactions
def split_transaction(self, transaction: Transaction): if transaction.credit > 0 and transaction.debit == 0: currentAmount = transaction.credit elif transaction.debit > 0 and transaction.credit == 0: currentAmount = transaction.debit else: raise NotImplementedError("Unable to handle transactions with both credit and debit values") amt = self.uns.get_split_transaction_input(currentAmount) if transaction.credit > 0: newdeb1 = 0.0 newdeb2 = 0.0 newcred1 = amt newcred2 = transaction.credit - amt elif transaction.debit > 0: newdeb1 = amt newdeb2 = transaction.debit - amt newcred1 = 0.0 newcred2 = 0.0 else: raise NotImplementedError("Unknown Scenario for splits") newTransaction1 = dsvct.enter_if_not_exists(transaction_category=transaction.category , transaction_id=str(uuid.uuid4()) , description=transaction.description , debit=newdeb1 , credit=newcred1 , source=transaction.source , payment_type=transaction.payment_type , date_stamp=transaction.date_stamp) newTransaction2 = dsvct.enter_if_not_exists(transaction_category=transaction.category , transaction_id=str(uuid.uuid4()) , description=transaction.description , debit=newdeb2 , credit=newcred2 , payment_type=transaction.payment_type , source=transaction.source , date_stamp=transaction.date_stamp) dsvct.mark_transaction_handled(transaction, TransactionStatus.SPLIT) self.uns.notify_user(f"Transaction Split into {newTransaction1.id} and {newTransaction2.id}")
def read_in_pnc_transactions(filepath: str): # Read in the PNC data from csv pnc_data = pd.read_csv(filepath).fillna(0.0) #Translate PNC transactions to standard transaction format pnc_transactions = [] for transaction in pnc_data.to_dict('rows'): if type(transaction['Credit']) != float: credit = _float_from_dollar_string(transaction["Credit"]) else: credit = transaction["Credit"] if type(transaction['Debit']) != float: debit = _float_from_dollar_string(transaction["Debit"]) else: debit = transaction["Debit"] if credit > 0: transaction_category = TransactionTypes.APPLY_INCOME else: transaction_category = TransactionTypes.RECORD_EXPENSE new = dsvct.enter_if_not_exists(transaction_category=transaction_category , transaction_id=str(uuid.uuid4()) , description=transaction['Transaction'] , debit=debit , credit=credit , payment_type=PaymentType.BANK , source=TransactionSource.PNC , date_stamp=parser.parse(transaction['Date'])) if new is not None: pnc_transactions.append(new) return pnc_transactions
def read_in_old_ledgers(filepath: str, account: Account): # Read in the old ledger data from csv old_data = pd.read_csv(filepath, encoding='ISO-8859-1').fillna("") # Transalate old ledger data into standard ledger format old_ledgers = [] for ledger in old_data.to_dict('rows'): if ledger['Trans_Type'] == 'APPLY PMNT': debit = _float_from_dollar_string(ledger['Amount']) credit = 0.0 transaction_category = TransactionTypes.RECORD_EXPENSE from_account = account.account_name to_account = 'External' elif ledger['Trans_Type'] == 'MOVING FUNDS': debit = _float_from_dollar_string(ledger['Amount']) credit = _float_from_dollar_string(ledger['Amount']) transaction_category = TransactionTypes.MOVE_FUNDS from_account = account.account_name to_account = account.account_name elif ledger['Trans_Type'] == 'ADD INCOME': debit = 0.0 credit = _float_from_dollar_string(ledger['Amount']) transaction_category = TransactionTypes.APPLY_INCOME from_account = 'External' to_account = account.account_name elif ledger['Trans_Type'] == 'BALANCE BANK': debit = 0.0 credit = _float_from_dollar_string(ledger['Amount']) transaction_category = TransactionTypes.BALANCE_BANK from_account = account.account_name to_account = account.account_name elif ledger['Trans_Type'] == "CHANGE MONTH": continue else: raise Exception(f"Unhandled transaction category for Archive: {ledger['Trans_Type']}") from_bucket = ledger['From'] to_bucket = ledger['To'] amount_covered = 0 if ledger['Validated'] == 1 or ledger['Trans_Type'] != "APPLY PMNT": amount_covered = debit if ledger['Spend_Cat'] == 'Car' and ledger['From'] == "Car (AUTO_PNC)": spend_category = SpendCategory.CAR_PAYMENT elif ledger['Spend_Cat'] == 'Car': spend_category = SpendCategory.CAR_MAINT else: spend_category = old_spend_category_switch(ledger['Spend_Cat']) trans_id = str(uuid.uuid4()) if ledger['Trans_Type'] == 'APPLY PMNT' and ledger['To'] == "PAYMENT - Credit": payment_type = PaymentType.CREDIT elif ledger['Trans_Type'] == 'APPLY PMNT' and ledger['To'] == "PAYMENT - Bank-PNC": payment_type = PaymentType.BANK elif ledger['Trans_Type'] == 'APPLY PMNT' and ledger['To'] == "PAYMENT - Cash": payment_type = PaymentType.CASH else: payment_type = PaymentType.NOTAPPLICABLE # Add transaction fro reference transaction = dsvct.enter_if_not_exists(transaction_category=transaction_category , transaction_id=trans_id , description=ledger['Comment'] , debit=debit , credit=credit , source=TransactionSource.ARCHIVE , date_stamp=parser.parse(ledger['Date']) , payment_type=payment_type , handled=TransactionStatus.HANDLED) # Unsure about format, but confident no duplicates, therefore dont check for dups before entering new = dsvcl.enter_ledger_entry( transaction_id=trans_id , transaction_category=transaction_category , description=ledger['Comment'] , debit=debit , credit=credit , source=TransactionSource.ARCHIVE , from_account=from_account , from_bucket=from_bucket , to_bucket=to_bucket , to_account=to_account , spend_category=spend_category , payment_type=payment_type , date_stamp=parser.parse(ledger['Date']) , notes=ledger['Comment'] , amount_covered=amount_covered) if new is not None: old_ledgers.append(new) return old_ledgers