public void deleteTransaction(Transaction transaction) {
    int transactionId = transaction.getTransactionId();
    int foodId = transaction.getFoodId();
    String deletedTime = transaction.getStrTimeStamp();

    SQLiteDatabase db_write = this.getWritableDatabase();
    db_write.delete(
        TABLE_TRANSACTION, TRANSACTION_ID + "=" + Integer.toString(transactionId), null);
    Log.d("deleteTransaction", "id=" + Integer.toString(transactionId));
    db_write.close();

    SQLiteDatabase db_read = this.getReadableDatabase();
    Cursor cursor =
        db_read.rawQuery(
            GET_LATEST_TRANSACTION_TIME_FOR_FOOD, new String[] {Integer.toString(foodId)});
    String lastTransactionTime;
    if (cursor.getCount() > 0) {
      cursor.moveToFirst();
      lastTransactionTime = cursor.getString(0);
    } else {
      lastTransactionTime = "";
    }
    db_read.close();

    Food food = getFood(foodId);
    food.setFrequency(food.getFrequency() - 1);
    food.setStrLastTransaction(lastTransactionTime);
    Log.d("INFO", food.toString());
    updateFood(foodId, food);
  }
 public Food getFoodFromCursor(Cursor cursor) {
   Food food = new Food();
   food.setFood_name(cursor.getString(1));
   food.setProtein(Double.parseDouble(cursor.getString(2)));
   food.setCarbo_hydr(Double.parseDouble(cursor.getString(3)));
   food.setFat(Double.parseDouble(cursor.getString(4)));
   food.setKcal(Double.parseDouble(cursor.getString(5)));
   food.setType(FoodType.getType(Integer.parseInt(cursor.getString(6))), 0);
   food.setType(FoodType.getType(Integer.parseInt(cursor.getString(7))), 1);
   food.setType(FoodType.getType(Integer.parseInt(cursor.getString(8))), 2);
   food.setCategory(FoodCategory.getCategory(Integer.parseInt(cursor.getString(9))));
   food.setFrequency(cursor.getInt(10));
   if (cursor.isNull(11) || cursor.getString(11) == "null") {
     food.setStrLastTransaction("");
   } else {
     food.setStrLastTransaction(cursor.getString(11));
   }
   cursor.close();
   return food;
 }
  public void addTransaction(int foodId, double proportion) {
    String currentTime = getCurrentTime();
    Log.d("addTransaction", Integer.toString(foodId));
    SQLiteDatabase db = this.getWritableDatabase();

    // add new food transaction
    ContentValues values = new ContentValues();
    values.put(FOOD_ID, foodId);
    values.put(COL_PROPORTION, proportion);
    values.put(COL_TIME, currentTime);
    db.insert(TABLE_TRANSACTION, null, values);
    db.close();

    // update food
    Food food = getFood(foodId);
    food.setFrequency(food.getFrequency() + 1);
    food.setStrLastTransaction(currentTime);
    Log.d(currentTime, food.toString());
    updateFood(foodId, food);
  }