Exemple #1
0
def GetAllCostByDateOfPaymentFromDB(dateOfPayment):
    """Based on the payment date of the Cost objects we get back
    all Cost objects from database.

    Parameters
    ----------
    dateOfPayment : date
        Payment date of Cost object.

    Returns
    -------
    List
        List of Cost objects.
    """

    logs.logger.debug(
        "Start to get back all Cost object from database "
        "based on payment date.")
    try:
        searchedCostByDateOfPaymentFromDB = session.query(
            Cost.Cost).filter(Cost.Cost.dateOfPayment == dateOfPayment).all()
        logs.logger.info(
            "Get back all Cost object from database based on payment date.")
        return [item for item in searchedCostByDateOfPaymentFromDB]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #2
0
def GetAllCostByDescriptionFromDB(description):
    """Based on the description of the Cost objects we get back
    all Cost objects from database.

    Parameters
    ----------
    description : string
        Description of Cost object.

    Returns
    -------
    List
        List of Cost objects.
    """

    logs.logger.debug(
        "Start to get back all Cost object from database "
        "based on description.")
    try:
        searchedCostByDescriptionFromDB = session.query(
            Cost.Cost).filter(Cost.Cost.description == description).all()
        logs.logger.info(
            "Get back all Cost object from database based on description.")
        return [item for item in searchedCostByDescriptionFromDB]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #3
0
def GetAllCostByAmountFromDB(amount):
    """Based on the amount of the Cost objects we get back
    all Cost objects from database.

    Parameters
    ----------
    amount : integer
        Amount of Cost object.

    Returns
    -------
    List
        List of Cost objects.
    """

    logs.logger.debug(
        "Start to get back all Cost object from database based on amount.")
    try:
        searchedCostByAmountFromDB = session.query(
            Cost.Cost).filter(Cost.Cost.amount == amount).all()
        logs.logger.info(
            "Get back all Cost object from database based on amount.")
        return [item for item in searchedCostByAmountFromDB]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #4
0
def GetAllCostByAmountBandFromDB(lowerLimit, upperLimit):
    """Based on an amount band of the Cost objects we get back
    all Cost objects from database.

    Parameters
    ----------
    lowerLimit : integer
        Lower limit amount of Cost objects.
    upperLimit : integer
        Upper limit amount of Cost objects.

    Returns
    -------
    List
        List of Cost objects.
    """

    logs.logger.debug("Start to get back all Cost object from database\
        based on amount band.")
    try:
        searchedCostByAmountBandFromDB = session.query(
            Cost.Cost).filter(Cost.Cost.amount >= lowerLimit, Cost.Cost.amount <= upperLimit).all()
        logs.logger.info(
            "Get back all Cost object from database based on amount band.")
        return [item for item in searchedCostByAmountBandFromDB]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #5
0
def GetAllCostByCategoryFromDB(category):
    """Based on the category of the Cost objects we get back
    all Cost objects from database.

    Parameters
    ----------
    category : enum
        Category of Cost object.

    Returns
    -------
    List
        List of Cost objects.
    """

    logs.logger.debug(
        "Start to get back all Cost object from database based on category.")
    try:
        searchedCostByCategoryFromDB = session.query(
            Cost.Cost).filter(Cost.Cost.category == category).all()
        logs.logger.info(
            "Get back all Cost object from database based on category.")
        return [item for item in searchedCostByCategoryFromDB]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #6
0
def GetAllIncomeByDateOfPaymentBandFromDB(startDate, endDate):
    """Based on payment date band of the Income objects we get back
    all Income objects from database.

    Parameters
    ----------
    startDate : date
        Start date of payment.
    endDate : date
        Start date of payment.

    Returns
    -------
    List
        List of Income objects.
    """

    logs.logger.debug("Start to get back all Income object from database "
                      "based on payment date band (%s < < %s)." %
                      (startDate, endDate))
    try:
        searchedIncomeByDateOfPaymentBandFromDB = session.query(
            Income.Income).filter(
                Income.Income.dateOfPayment >= startDate,
                Income.Income.dateOfPayment <= endDate).all()
        logs.logger.info("Get back all Income object from database "
                         "based on payment date band (%s < < %s)." %
                         (startDate, endDate))
        return [item for item in searchedIncomeByDateOfPaymentBandFromDB]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #7
0
def GetAllCostByDateOfPaymentBandFromDB(startDate, endDate):
    """Based on payment date band of the Cost objects we get back
    all Cost objects from database.

    Parameters
    ----------
    startDate : date
        Start date of payment.
    endDate : date
        Start date of payment.

    Returns
    -------
    List
        List of Cost objects.
    """

    logs.logger.debug(
        "Start to get back all Cost object from database "
        "based on payment date band.")
    try:
        searchedCostByDateOfPaymentBandFromDB = session.query(
            Cost.Cost).filter(Cost.Cost.dateOfPayment >= startDate, Cost.Cost.dateOfPayment <= endDate).all()
        logs.logger.info(
            "Get back all Cost object from database "
            "based on payment date band.")
        return [item for item in searchedCostByDateOfPaymentBandFromDB]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #8
0
def GetIncomeByIDFromDB(idOfIncome):
    """Based on the ID of the Income object we get back
    the Income object from database.

    Parameters
    ----------
    idOfIncome : integer
        Id of Income object.

    Returns
    -------
    Income Object
        Income
    """

    logs.logger.debug("Start to get back the Income object from database "
                      "based on ID (%s)." % idOfIncome)
    try:
        searchedIncometByIDFromDB = session.query(
            Income.Income).filter(Income.Income.id == idOfIncome).one()
        logs.logger.info(
            "Get back the Income object from database based on ID (%s)." %
            idOfIncome)
        return searchedIncometByIDFromDB
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #9
0
def GetAllIncomeByAmountBandFromDB(lowerLimit, upperLimit):
    """Based on an amount band of the Income objects we get back
    all Income objects from database.

    Parameters
    ----------
    lowerLimit : integer
        Lower limit amount of Income objects.
    upperLimit : integer
        Upper limit amount of Income objects.

    Returns
    -------
    List
        List of Income objects.
    """

    logs.logger.debug("Start to get back all Income object from database "
                      "based on amount band (%s < < %s)." %
                      (lowerLimit, upperLimit))
    try:
        searchedIncomeByAmountBandFromDB = session.query(Income.Income).filter(
            Income.Income.amount >= lowerLimit,
            Income.Income.amount <= upperLimit).all()
        logs.logger.info("Get back all Income object from database based on\
                 amount band (%s < < %s)." % (lowerLimit, upperLimit))
        return [item for item in searchedIncomeByAmountBandFromDB]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #10
0
def ModifyDescriptionOfIncome(idOfIncome, description):
    """Based on the ID of the Income object the description
    is modified in database.

    Parameters
    ----------
    idOfIncome : integer
        Id of Income object.
    description : string
        Description of Income object.

    """

    logs.logger.debug(
        "Start to modify description of Income based on the ID (%s)." %
        idOfIncome)
    try:
        modifiedIncome = session.query(
            Income.Income).filter(Income.Income.id == idOfIncome).one()
        modifiedIncome.description = description
        session.commit()
        logs.logger.info("Modify description of Income based on the ID (%s)." %
                         idOfIncome)
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #11
0
def ModifyCategoryOfIncome(idOfIncome, category):
    """Based on the ID of the Income object the category
    is modified in database.

    Parameters
    ----------
    idOfIncome : integer
        Id of Income object.
    category : enum
        Category of Income object.

    """

    logs.logger.debug(
        "Start to modify category of Income based on the ID (%s)." %
        idOfIncome)
    try:
        modifiedIncome = session.query(
            Income.Income).filter(Income.Income.id == idOfIncome).one()
        modifiedIncome.category = category
        session.commit()
        logs.logger.info("Modify category of Income based on the ID (%s)." %
                         idOfIncome)
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #12
0
def ModifyRegistrationDateOfIncome(idOfIncome, registrationDate):
    """Based on the ID of the Income object the registration date
    is modified in database.

    Parameters
    ----------
    idOfIncome : integer
        Id of Income object.
    registrationDate : date
        Registration date of Income object.

    """

    logs.logger.debug("Start to modify registration date of Income based\
             on the ID (%s)." % idOfIncome)
    try:
        modifiedIncome = session.query(
            Income.Income).filter(Income.Income.id == idOfIncome).one()
        modifiedIncome.registrationDate = registrationDate
        session.commit()
        logs.logger.info(
            "Modify registration date of Income based on the ID (%s)." %
            idOfIncome)
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #13
0
def GetAllCostByRegistrationDateFromDB(registrationDate):
    """Based on the registration date of the Cost objects we get back
    all Cost objects from database.

    Parameters
    ----------
    registrationDate : date
        Registration date of Cost object.

    Returns
    -------
    List
        List of Cost objects.
    """

    logs.logger.debug("Start to get back all Cost object from database "
                      "based on registration date.")
    try:
        searchedCostByRegDateFromDB = session.query(Cost.Cost).filter(
            Cost.Cost.registrationDate == registrationDate).all()
        logs.logger.info(
            "Get back all Cost object from database "
            "based on registration date.")
        return [item for item in searchedCostByRegDateFromDB]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #14
0
def SumCostByDayPerCategory(day, category):
    """Based on the payment date and on the category adds all amount of
    Cost objects.

    Parameters
    ----------
    day : date
        Payment date of Cost objects.
    category : string
        Category of Cost object.

    Returns
    -------
    Integer
        Summarize amount of all Cost objects with the same payment date
        and category from database.
    """

    logs.logger.debug(
        "Start to adds all amount of Cost objects based on the payment date and on the category")
    try:
        searchedCostByDayPerCategoryFromDB = session.query(
            Cost.Cost).filter(Cost.Cost.dateOfPayment == day).filter(
                Cost.Cost.category == category).all()
        sumTotal = 0
        for item in searchedCostByDayPerCategoryFromDB:
            sumTotal += item.amount
        logs.logger.info(
            "Based on the payment date and on the category adds all amount of Cost objects.")
        return sumTotal
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #15
0
def GetTheHashListOfFiles():
    """Get the hash list of the files from DB.

    Returns
    -------
    list
        Hash list of the files from DB.
    """

    logs.logger.debug("Get the hash list of the files from DB.")
    try:
        Files = session.query(File.File).all()
        return [File.Hash for File in Files]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #16
0
def GetAllCostsFromDB():
    """All Cost objects is got back from database.

    Returns
    -------
    List
        List of Cost objects.
    """

    logs.logger.debug("Start to get back all Cost objects from database.")
    try:
        ListOfAllCost = session.query(Cost.Cost).all()
        logs.logger.info("Get back all Cost objects from database.")
        return [item for item in ListOfAllCost]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #17
0
def NewFilesInDB():
    """Get the list of new files from DB.

    Returns
    -------
    list
        List of new files from DB.
    """

    logs.logger.debug("Get the list of new files from DB.")
    try:
        ListOfNewFiles = []
        ListOfNewFiles = session.query(
            File.File).filter(File.File.Status == 1).all()
        return ListOfNewFiles
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #18
0
def GetAllAmountOfCost():
    """All amounts of Cost objects is got back from database.

    Returns
    -------
    List
        List of Amounts of Cost objects.
    """

    logs.logger.debug("Start to get back all amounts of\
        Cost objects from database.")
    try:
        searchedCostsItems = session.query(Cost.Cost).all()
        logs.logger.info("Get back all amounts of Cost objects from database.")
        return [CostItems.amount for CostItems in searchedCostsItems]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #19
0
def GetAllCategoryOfIncome():
    """All categories of Income objects is got back from database.

    Returns
    -------
    List
        List of Categories of Income objects.
    """

    logs.logger.debug(
        "Start to get back all categories of Income objects from database.")
    try:
        searchedIncomeItems = session.query(Income.Income).all()
        logs.logger.info(
            "Get back all categories of Income objects from database.")
        return [IncomeItems.category for IncomeItems in searchedIncomeItems]
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #20
0
def PrintAllCosts():
    """After queries of all costs from database this method print the details
    (id, reg.date, date of payment, amount, description, category)
    of the costs to the consol.

    """

    logs.logger.debug("After queries of all costs from database start to print"
                      " the details (id, reg.date, date of payment, amount,"
                      " description, category) of the costs to the consol.")
    try:
        printedCosts = session.query(Cost.Cost).all()
        for cost in printedCosts:
            print(
                f'{cost.id}\t{cost.registrationDate}\t{cost.dateOfPayment} \
                    \t{cost.amount}\t{cost.description}\t{cost.category.value}')
        logs.logger.info("After queries of all costs from database print"
                         " the details (id, reg.date, date of payment, amount,"
                         " description, category) of the costs to the consol.")
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #21
0
def ModifyAmountOfCost(idOfCost, amount):
    """Based on the ID of the Cost object the amount
    is modified in database.

    Parameters
    ----------
    idOfCost : integer
        Id of Cost object.
    amount : integer
        Amount of Cost object.

    """

    logs.logger.debug("Start to modify amount of Cost based on the ID.")
    try:
        modifiedCost = session.query(Cost.Cost).filter(
            Cost.Cost.id == idOfCost).one()
        modifiedCost.amount = amount
        session.commit()
        logs.logger.info("Modify amount of Cost based on the ID.")
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #22
0
def DeleteIncome(idOfIncome):
    """Based on Id parameter of the Income object this method deletes the Income
    object from database.

    Parameters
    ----------
    idOfIncome : integer
        Id of the Income object.

    """

    logs.logger.debug("Start to deletes the Income object from database "
                      "based on Id parameter (%s)." % idOfIncome)
    try:
        deletedIncome = session.query(
            Income.Income).filter(Income.Income.id == idOfIncome).one()
        session.delete(deletedIncome)
        session.commit()
        logs.logger.info("Deletes the Income object from database "
                         "based on Id parameter (%s)." % idOfIncome)
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #23
0
def ModifyTheFullRowOfCost(idOfCost, registrationDate, dateOfPayment,
                           amount, description, category):
    """Based on the all given properties of Cost as parameters this method
    modifys the properties of Cost object in database.

    Parameters
    ----------
    idOfCost : integer
        Id of Cost object.
    registrationDate : date
        Registration date of Cost object.
    dateOfPayment : date
        Payment date of Cost object.
    amount : integer
        Amount of Cost object.
    description : string
        Description of Cost object.
    category : enum
        Category of Cost object.

    """

    logs.logger.debug(
        "Start to modify the properties of Cost object in database "
        "based on the all given properties of Cost.")
    try:
        modifiedCost = session.query(Cost.Cost).filter(
            Cost.Cost.id == idOfCost).one()
        modifiedCost.registrationDate = registrationDate
        modifiedCost.dateOfPayment = dateOfPayment
        modifiedCost.amount = amount
        modifiedCost.description = description
        modifiedCost.category = category
        session.commit()
        logs.logger.info(
            "Modify the properties of Cost object in database "
            "based on the all given properties of Cost.")
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #24
0
def ModifyDescriptionOfCost(idOfCost, description):
    """Based on the ID of the Cost object the description
    is modified in database.

    Parameters
    ----------
    idOfCost : integer
        Id of Cost object.
    description : string
        Description of Cost object.

    """

    logs.logger.debug("Start to modify description of Cost based on the ID.")
    try:
        modifiedCost = session.query(Cost.Cost).filter(
            Cost.Cost.id == idOfCost).one()
        modifiedCost.description = description
        session.commit()
        logs.logger.info("Modify description of Cost based on the ID.")
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #25
0
def ModifyCategoryOfCost(idOfCost, category):
    """Based on the ID of the Cost object the category
    is modified in database.

    Parameters
    ----------
    idOfCost : integer
        Id of Cost object.
    category : enum
        Category of Cost object.

    """

    logs.logger.debug("Start to modify category of Cost based on the ID.")
    try:
        modifiedCost = session.query(Cost.Cost).filter(
            Cost.Cost.id == idOfCost).one()
        modifiedCost.category = category
        session.commit()
        logs.logger.info("Modify category of Cost based on the ID.")
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #26
0
def DeleteCost(idOfCost):
    """Based on Id parameter of the Cost object this method deletes the Cost
    object from database.

    Parameters
    ----------
    idOfCost : integer
        Id of the Cost object.

    """

    logs.logger.debug(
        "Start to deletes the Cost object from database "
        "based on Id parameter.")
    try:
        deletedCost = session.query(Cost.Cost).filter(
            Cost.Cost.id == idOfCost).one()
        session.delete(deletedCost)
        session.commit()
        logs.logger.info("Deletes the Cost object from database "
                         "based on Id parameter.")
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #27
0
def ModifyRegistrationDateOfCost(idOfCost, registrationDate):
    """Based on the ID of the Cost object the registration date
    is modified in database.

    Parameters
    ----------
    idOfCost : integer
        Id of Cost object.
    registrationDate : date
        Registration date of Cost object.

    """

    logs.logger.debug(
        "Start to modify registration date of Cost based on the ID.")
    try:
        modifiedCost = session.query(Cost.Cost).filter(
            Cost.Cost.id == idOfCost).one()
        modifiedCost.registrationDate = registrationDate
        session.commit()
        logs.logger.info("Modify registration date of Cost based on the ID.")
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #28
0
def GetTheLastFile():
    """Get the last file from the database.

    Parameters
    ----------
    session : session
        Manages persistence operations for ORM-mapped objects.

   path : string
        the path of the file

    Returns
    -------
    ORM-mapped object
        trigger file
    """

    logs.logger.debug("Get the last file from the database.")
    try:
        LastFile = session.query(File.File).order_by('ModificationDate')[-1]
        return LastFile
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #29
0
def ModifyAmountOfIncome(idOfIncome, amount):
    """Based on the ID of the Income object the amount
    is modified in database.

    Parameters
    ----------
    idOfIncome : integer
        Id of Income object.
    amount : integer
        Amount of Income object.

    """

    logs.logger.debug(
        "Start to modify amount of Income based on the ID (%s)." % idOfIncome)
    try:
        modifiedIncome = session.query(
            Income.Income).filter(Income.Income.id == idOfIncome).one()
        modifiedIncome.amount = amount
        session.commit()
        logs.logger.info("Modify amount of Income based on the ID (%s)." %
                         idOfIncome)
    except Exception as e:
        logs.logger.error(e, exc_info=True)
Exemple #30
0
def GetCostByIDFromDB(idOfCost):
    """Based on the ID of the Cost object we get back
    the Cost object from database.

    Parameters
    ----------
    idOfCost : integer
        Id of Cost object.

    Returns
    -------
    Cost Object
        Cost
    """

    logs.logger.debug("Start to get back the Cost object from database "
                      "based on ID.")
    try:
        searchedCostByIDFromDB = session.query(
            Cost.Cost).filter(Cost.Cost.id == idOfCost).one()
        logs.logger.info("Get back the Cost object from database based on ID.")
        return searchedCostByIDFromDB
    except Exception as e:
        logs.logger.error(e, exc_info=True)