Exemplo n.º 1
0
def update_transaction(id):
    amount = request.form['amount']
    category = category_repository.select(request.form['category_id'])
    date = request.form['date']
    merchant = merchant_repository.select(request.form['merchant_id'])
    user = user_repository.select(request.form['user_id'])
    transaction = Transaction(amount, category, date, merchant, user, id)
    transaction_repository.update(transaction)
    return redirect("/transactions")
def update_company(id):
  name = request.form["name"]
  amount = request.form["amount"]
  category = category_repository.select(request.form['category_id'])
  account = account_repository.select(request.form['account_id'])
  update_company = Company(name, amount, category, account, id)
  company_repository.update(update_company)
  account.amount += float(amount)
  account_repository.update(account)
  return redirect("/") 
def create_company():
  name = request.form['name']
  amount = request.form['amount']
  category = category_repository.select(request.form['category_id'])
  account = account_repository.select(request.form['account_id'])
  add_company = Company(name, amount, category, account)
  company_repository.save(add_company)
  account.amount -= float(amount)
  account_repository.update(account)
  return redirect('/')
Exemplo n.º 4
0
def select(id):
    company = None
    sql = "SELECT * FROM companys WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        category = category_repository.select(result['category_id'])
        account = account_repository.select(result['account_id'])
        company = Company(result['name'], result['amount'], category, account,
                          result['id'])
    return company
Exemplo n.º 5
0
def select_all():
    companys = []

    sql = "SELECT * FROM companys"
    results = run_sql(sql)
    for row in results:
        category = category_repository.select(row['category_id'])
        account = account_repository.select(row['account_id'])
        company = Company(row['name'], row['amount'], category, account,
                          row['id'])
        companys.append(company)
    return companys
def sort_transactions(transactions):
    transactions = []
    sql = "SELECT * FROM transactions ORDER BY date ASC"
    results = run_sql(sql)

    for row in results:
        merchant = merchant_repository.select(row['merchant_id'])
        category = category_repository.select(row['category_id'])
        user = user_repository.select(row['user_id'])
        transaction = Transaction(row['amount'], category, row['date'],
                                  merchant, user, row['id'])
        transactions.append(transaction)
    return transactions
def select(id):
    transaction = None
    sql = "SELECT * FROM transactions WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        merchant = merchant_repository.select(result['merchant_id'])
        category = category_repository.select(result['category_id'])
        user = user_repository.select(result['user_id'])
        transaction = Transaction(result['amount'], category, result['date'],
                                  merchant, user, result['id'])
    return transaction
def filter_by_month(month):
    transactions = []
    sql = "SELECT * FROM transactions WHERE EXTRACT (MONTH from date) = %s "
    values = [month]
    results = run_sql(sql, values)

    for row in results:
        merchant = merchant_repository.select(row['merchant_id'])
        category = category_repository.select(row['category_id'])
        user = user_repository.select(row['user_id'])
        transaction = Transaction(row['amount'], category, row['date'],
                                  merchant, user, row['id'])
        transactions.append(transaction)
    return transactions
Exemplo n.º 9
0
def edit_category(id):
    category = category_repository.select(id)
    return render_template("categorys/edit.html", category=category)
Exemplo n.º 10
0
def show_category(id):
    category = category_repository.select(id)
    return render_template("categorys/show.html", category=category)