Exemplo n.º 1
0
def currency_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        currency_id = long(request.matchdict['currency_id'])
        currency = DBSession.query(Currency).filter_by(id=currency_id).first()
        if currency == None:
            return HTTPFound(request.application_url + "/administration/company")

        if request.method == "POST":
            error = False
            name = request.params["name"].lower()
            if name == "usd":
                error = True
            currency_to_usd = float(request.params["currency_to_usd"])
            cur = DBSession.query(Currency).filter_by(account_id=account_id).filter_by(name=name).first()
            if cur is not None and cur.id != currency_id:
                error = True
            if error == False:
                currency.name = name
                currency.currency_to_usd = currency_to_usd
                DBSession.flush()
                return HTTPFound(request.application_url + "/administration/company")

        return dict(logged_in=authenticated_userid(request), header=Header("administration"), currency=currency,
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 2
0
def department_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator is False:
            return HTTPFound(request.application_url)

        department_id = request.matchdict['department_id']

        if request.method == "POST":
            name = request.params["name"].lower()
            dept = DBSession.query(Department).filter_by(account_id=account_id).filter_by(name=name).first()
            if dept is None or dept.id == department_id:
                DBSession.query(Department).filter_by(id=department_id).filter_by(account_id=account_id).update(
                    {'name': name})
                DBSession.flush()
                return HTTPFound(location=request.application_url + "/administration/company")

        department = DBSession.query(Department).filter_by(id=department_id).first()
        return dict(logged_in=authenticated_userid(request), header=Header("administration"), department=department,
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 3
0
def person(request):
    #FIX PERMISSIONS!
    person_id = request.matchdict.get('person_id')
    review_year = request.params.get('year')

    user = DBSession.query(User).filter_by(id=long(request.session['uid'])).first()

    person = DBSession.query(User).filter_by(id=long(person_id)).first()

    account = DBSession.query(Account).filter_by(id=long(request.session['aid'])).first()

    if review_year is None or review_year == "":
        review_year = account.latest_review_year

    review = DBSession.query(Review).filter_by(user_id=person.id).filter_by(review_cycle_year=review_year).first()

    if review is None:
        if review_year == account.latest_review_year:
            review = Review(user, review_year)
            DBSession.add(review)
            DBSession.flush()
        else:
            HTTPFound(location=request.application_url)

    return dict(logged_in=authenticated_userid(request), person=person, user=user, review=review, account=account)
Exemplo n.º 4
0
def account_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        account = DBSession.query(Account).filter_by(id=account_id).first()
        user = DBSession.query(User).filter_by(id=user_id).first()

        if user is None or user.is_administrator == False or account is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"]
            benefits_and_bonus = long(request.params["benefits_and_bonus"])

            acc = DBSession.query(Account).filter_by(name=name).first()
            if acc is None or acc.id == account.id:
                DBSession.query(Account).filter_by(id=account_id).update({
                    'name':
                    name,
                    'benefits_and_bonus':
                    benefits_and_bonus
                })
                DBSession.flush()
                return HTTPFound(request.application_url +
                                 "/administration/company")

        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    account=account,
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 5
0
def account_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        account = DBSession.query(Account).filter_by(id=account_id).first()
        user = DBSession.query(User).filter_by(id=user_id).first()

        if user is None or user.is_administrator == False or account is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"]
            benefits_and_bonus = long(request.params["benefits_and_bonus"])

            acc = DBSession.query(Account).filter_by(name=name).first()
            if acc is None or acc.id == account.id:
                DBSession.query(Account).filter_by(id=account_id).update(
                    {'name': name, 'benefits_and_bonus': benefits_and_bonus})
                DBSession.flush()
                return HTTPFound(request.application_url + "/administration/company")

        return dict(logged_in=authenticated_userid(request), header=Header("administration"), account=account,
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 6
0
def project_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            print("************* no user")
            return HTTPFound(request.application_url)

        project_id = request.matchdict.get('project_id')
        project = DBSession.query(Project).filter_by(id=project_id).filter_by(
            account_id=account_id).first()

        if project is None or user.can_access_client(project.client,
                                                     "financials") == False:
            print("************* no permissions")
            return HTTPFound(request.application_url)

        project.is_active = False
        project.end_date = datetime.datetime.now()
        DBSession.flush()

        return HTTPFound(location=request.application_url + "/client/" +
                         str(project.client_id) + "/projects/" +
                         str(datetime.datetime.now().year))
    except:
        print("*************")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 7
0
def department_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator is False:
            return HTTPFound(request.application_url)

        department_id = request.matchdict['department_id']

        if request.method == "POST":
            name = request.params["name"].lower()
            dept = DBSession.query(Department).filter_by(
                account_id=account_id).filter_by(name=name).first()
            if dept is None or dept.id == department_id:
                DBSession.query(Department).filter_by(
                    id=department_id).filter_by(account_id=account_id).update(
                        {'name': name})
                DBSession.flush()
                return HTTPFound(location=request.application_url +
                                 "/administration/company")

        department = DBSession.query(Department).filter_by(
            id=department_id).first()
        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    department=department,
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 8
0
def office_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        account = DBSession.query(Account).filter_by(id=account_id).first()
        user = DBSession.query(User).filter_by(id=user_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"].lower()
            office = DBSession.query(Office).filter_by(
                account_id=long(request.session['aid'])).filter_by(
                    name=name).first()
            if office is None:
                benefits_and_bonus = long(request.params["benefits_and_bonus"])
                new_office = Office(name, benefits_and_bonus, account)
                DBSession.add(new_office)
                DBSession.flush()

            if request.params.get("add_another") is None:
                return HTTPFound(request.application_url +
                                 "/administration/company")

        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 9
0
def department_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"].lower()
            dept = DBSession.query(Department).filter_by(
                account_id=account_id).filter_by(name=name).first()
            if dept is None:
                new_department = Department(name, account)
                DBSession.add(new_department)
                DBSession.flush()

                if request.params.get("add_another") is None:
                    return HTTPFound(location=request.application_url +
                                     "/administration/company")

        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 10
0
def project_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            print("************* no user")
            return HTTPFound(request.application_url)

        project_id = request.matchdict.get('project_id')
        project = DBSession.query(Project).filter_by(id=project_id).filter_by(account_id=account_id).first()

        if project is None or user.can_access_client(project.client, "financials") == False:
            print("************* no permissions")
            return HTTPFound(request.application_url)

        project.is_active = False
        project.end_date = datetime.datetime.now()
        DBSession.flush()

        return HTTPFound(location=request.application_url + "/client/" + str(project.client_id) + "/projects/" + str(
            datetime.datetime.now().year))
    except:
        print("*************")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 11
0
def currency_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"].lower()
            currency_to_usd = float(request.params["currency_to_usd"])
            error = False
            if name == "usd":
                error = True

            currency = DBSession.query(Currency).filter_by(account_id=account_id).filter_by(name=name).first()
            if currency is not None:
                error = True

            if error == False:
                new_currency = Currency(name, account, currency_to_usd)
                DBSession.add(new_currency)
                DBSession.flush()

                if request.params.get("add_another") is None:
                    return HTTPFound(request.application_url + "/administration/company")

        return dict(logged_in=authenticated_userid(request), header=Header("administration"), user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 12
0
def person_enable_login(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or (user.is_administrator == False and user.is_hr_administrator == False):
            return HTTPFound(request.application_url)

        person_id = request.matchdict.get('person_id')

        if user_id == person_id:
            return HTTPFound(request.application_url + "/administration/employees")

        person = DBSession.query(User).filter_by(id=person_id).filter_by(account_id=account_id).first()
        password = None

        if person is None:
            return HTTPFound(request.application_url + "/administration/employees")

        password = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
        encrypted_password = bcrypt.hashpw(password, bcrypt.gensalt())
        person.password = encrypted_password
        DBSession.flush()

        return dict(logged_in=authenticated_userid(request), header=Header("administration"), person=person, user=user,
                    password=password)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 13
0
def client_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        client_id = request.matchdict.get('client_id')
        client = DBSession.query(Client).filter_by(id=client_id).filter_by(
            account_id=account_id).first()

        if client is None or user.can_access_client(client,
                                                    "financials") == False:
            return HTTPFound(request.application_url)

        client.is_active = False
        DBSession.flush()

        return HTTPFound(request.application_url + "/office/" +
                         str(client.office_id) + "/clients/" +
                         str(datetime.datetime.now().year))
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 14
0
def client_projects_update(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        client_id = long(request.matchdict['client_id'])
        client = DBSession.query(Client).filter_by(id=client_id).filter_by(
            account_id=account_id).first()

        if client is None or user.can_access_client(client,
                                                    "financials") == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            for project in account.projects:
                if project.is_active and project.client.office_id == client.office_id:
                    revenue_local = long(
                        request.params.get(str(project.id) + "-revenue"))
                    if user.currency is None:
                        revenue = revenue_local
                    else:
                        revenue = revenue_local * user.currency.currency_to_usd

                    start_date_text = request.params.get(
                        str(project.id) + "-start_date")
                    start_dateparts = start_date_text.split("/")
                    start_date = datetime.date(long(start_dateparts[2]),
                                               long(start_dateparts[0]),
                                               long(start_dateparts[1]))

                    end_date_text = request.params.get(
                        str(project.id) + "-end_date")
                    end_dateparts = end_date_text.split("/")
                    end_date = datetime.date(long(end_dateparts[2]),
                                             long(end_dateparts[0]),
                                             long(end_dateparts[1]))

                    project.revenue = revenue
                    project.start_date = start_date
                    project.end_date = end_date

            DBSession.flush()
            return HTTPFound(request.application_url + "/client/" +
                             str(client.id) + "/projects/" +
                             str(datetime.datetime.now().year))

        return dict(logged_in=authenticated_userid(request),
                    header=Header("financials"),
                    user=user,
                    account=account,
                    client=client)
    except:
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 15
0
def global_expenses(request):
    try:
        user_id = long(request.session['uid'])
        account_id = long(request.session['aid'])
        year = request.matchdict['year']
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or not (
                user.is_administrator or user.permissions_global_financials):
            return HTTPFound(request.application_url)

        offices = DBSession.query(Office).filter_by(
            account_id=account_id).all()
        if offices is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            for office in offices:
                change = False
                ase = None
                sga = None
                ase_text = request.POST.get("ase_" + str(office.id))

                if ase_text is not None and ase_text != '':
                    ase_local = long(ase_text)
                    if user.currency is None:
                        ase = ase_local
                    else:
                        ase = ase_local * user.currency.currency_to_usd

                    office.allocated_salary_expense = ase

                sga_text = request.POST.get("sga_" + str(office.id))

                if sga_text is not None and sga_text != '':
                    sga_local = long(sga_text)
                    if user.currency is None:
                        sga = sga_local
                    else:
                        sga = sga_local * user.currency.currency_to_usd

                    office.sga_expense = sga

            DBSession.flush()
            # return HTTPFound(request.application_url + "/administration/expenses")

        return dict(logged_in=authenticated_userid(request),
                    header=Header("financials"),
                    offices=offices,
                    year=year,
                    user=user)
    except:
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 16
0
def client_edit(request):
    try:
        user_id = long(request.session['uid'])
        account_id = long(request.session['aid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()
        client_id = long(request.matchdict['client_id'])
        client = DBSession.query(Client).filter_by(account_id=account_id).filter_by(id=client_id).first()

        if user is None or account is None or client is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":

            name = request.params["name"].lower()
            code = request.params["client_code"]
            target_margin = request.params["target_margin"]

            office_id = long(request.params["office_id"])

            office_temp = DBSession.query(Office).filter_by(id=office_id).filter_by(account_id=account_id).first()
            client_temp = DBSession.query(Client).filter_by(account_id=account_id).filter_by(name=name).first()

            if office_temp is None or user.can_access_client(client, "financials") == False or user.can_access_office(
                    office_temp, "financials") == False:
                return HTTPFound(request.application_url)

            if client_temp is not None and client_temp.id != client.id:
                return HTTPFound(request.application_url)

            client.name = name
            client.code = code
            client.office = office_temp
            client.target_margin = target_margin
            DBSession.flush()

            return HTTPFound(
                request.application_url + "/office/" + str(office_id) + "/clients/" + str(datetime.datetime.now().year))

        offices_all = DBSession.query(Office).filter_by(account_id=long(request.session['aid'])).all()
        offices = []
        if user.is_administrator or user.permissions_global_financials:
            offices = offices_all
        else:
            for office in offices_all:
                if user.can_access_office(office, "financials"):
                    offices.append(office)
        if len(offices) == 0:
            return HTTPFound(request.application_url)

        return dict(logged_in=authenticated_userid(request), header=getHeader(client), offices=offices, user=user,
                    client=client, account=account)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 17
0
def role_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        role_id = long(request.matchdict['role_id'])
        role = DBSession.query(Role).filter_by(id=role_id).filter_by(
            account_id=account_id).first()

        if request.method == "POST":
            name = request.params["name"].lower()
            department_id = long(request.params["department_id"])
            salary_low_local = long(request.params["salary_low"])
            salary_high_local = long(request.params["salary_high"])

            if user.currency is None:
                salary_low = salary_low_local
                salary_high = salary_high_local
            else:
                salary_low = salary_low_local * user.currency.currency_to_usd
                salary_high = salary_high_local * user.currency.currency_to_usd

            department = DBSession.query(Department).filter_by(
                id=department_id).filter_by(account_id=account.id).first()

            role_ok = True
            for r in department.roles:
                if r.name == name and r.id != role_id:
                    role_ok = False

            if role_ok:
                role.name = name
                role.department = department
                role.salary_low = salary_low
                role.salary_high = salary_high
                DBSession.flush()
                return HTTPFound(request.application_url +
                                 "/administration/company")

        departments = DBSession.query(Department).filter_by(
            account_id=long(request.session['aid'])).all()
        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    departments=departments,
                    user=user,
                    role=role)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 18
0
def administration_revenue(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        account = DBSession.query(Account).filter_by(id=account_id).first()
        user = DBSession.query(User).filter_by(id=user_id).first()

        if user is None or account is None or not (
                user.is_administrator or user.permissions_global_financials):
            return HTTPFound(request.application_url)

        if request.method == "POST":

            quarter_end_date_text = request.params.get("quarter_end_type")
            quarter_end_year_text = request.params.get("quarter_end_year")
            quarter_end_date_parts = quarter_end_date_text.split("/")
            quarter_end_date = datetime.date(long(quarter_end_year_text),
                                             long(quarter_end_date_parts[0]),
                                             long(quarter_end_date_parts[1]))

            for project in account.projects:
                revenue_local = long(
                    request.params.get(str(project.id) + "-revenue"))

                if user.currency is None:
                    revenue = revenue_local
                else:
                    revenue = revenue_local * user.currency.currency_to_usd

                actual_revenue = DBSession.query(ActualRevenue).filter_by(
                    project_id=project.id).filter_by(
                        quarter_end_date=quarter_end_date).first()

                if actual_revenue is not None:
                    actual_revenue.revenue = revenue
                else:
                    actual_revenue = ActualRevenue(project, revenue,
                                                   quarter_end_date)

                DBSession.flush()

            return HTTPFound(request.application_url +
                             "/administration/company")

        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    account=account,
                    user=user)
    except:
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 19
0
def global_expenses(request):
    try:
        user_id = long(request.session['uid'])
        account_id = long(request.session['aid'])
        year = request.matchdict['year']
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or not (user.is_administrator or user.permissions_global_financials):
            return HTTPFound(request.application_url)

        offices = DBSession.query(Office).filter_by(account_id=account_id).all()
        if offices is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            for office in offices:
                change = False
                ase = None
                sga = None
                ase_text = request.POST.get("ase_" + str(office.id))

                if ase_text is not None and ase_text != '':
                    ase_local = long(ase_text)
                    if user.currency is None:
                        ase = ase_local
                    else:
                        ase = ase_local * user.currency.currency_to_usd

                    office.allocated_salary_expense = ase

                sga_text = request.POST.get("sga_" + str(office.id))

                if sga_text is not None and sga_text != '':
                    sga_local = long(sga_text)
                    if user.currency is None:
                        sga = sga_local
                    else:
                        sga = sga_local * user.currency.currency_to_usd

                    office.sga_expense = sga

            DBSession.flush()
            # return HTTPFound(request.application_url + "/administration/expenses")

        return dict(logged_in=authenticated_userid(request), header=Header("financials"), offices=offices, year=year,
                    user=user)
    except:
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 20
0
def currency_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        currency_id = long(request.matchdict['currency_id'])
        DBSession.query(Currency).filter_by(id=currency_id).filter_by(account_id=account_id).delete()
        DBSession.flush()
        return HTTPFound(request.application_url + "/administration/company")
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 21
0
def role_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        role_id = long(request.matchdict['role_id'])
        role = DBSession.query(Role).filter_by(id=role_id).filter_by(account_id=account_id).first()

        if request.method == "POST":
            name = request.params["name"].lower()
            department_id = long(request.params["department_id"])
            salary_low_local = long(request.params["salary_low"])
            salary_high_local = long(request.params["salary_high"])

            if user.currency is None:
                salary_low = salary_low_local
                salary_high = salary_high_local
            else:
                salary_low = salary_low_local * user.currency.currency_to_usd
                salary_high = salary_high_local * user.currency.currency_to_usd

            department = DBSession.query(Department).filter_by(id=department_id).filter_by(
                account_id=account.id).first()

            role_ok = True
            for r in department.roles:
                if r.name == name and r.id != role_id:
                    role_ok = False

            if role_ok:
                role.name = name
                role.department = department
                role.salary_low = salary_low
                role.salary_high = salary_high
                DBSession.flush()
                return HTTPFound(request.application_url + "/administration/company")

        departments = DBSession.query(Department).filter_by(account_id=long(request.session['aid'])).all()
        return dict(logged_in=authenticated_userid(request), header=Header("administration"), departments=departments,
                    user=user, role=role)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 22
0
def client_projects_update(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        client_id = long(request.matchdict['client_id'])
        client = DBSession.query(Client).filter_by(id=client_id).filter_by(account_id=account_id).first()

        if client is None or user.can_access_client(client, "financials") == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            for project in account.projects:
                if project.is_active and project.client.office_id == client.office_id:
                    revenue_local = long(request.params.get(str(project.id) + "-revenue"))
                    if user.currency is None:
                        revenue = revenue_local
                    else:
                        revenue = revenue_local * user.currency.currency_to_usd

                    start_date_text = request.params.get(str(project.id) + "-start_date")
                    start_dateparts = start_date_text.split("/")
                    start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]),
                                               long(start_dateparts[1]))

                    end_date_text = request.params.get(str(project.id) + "-end_date")
                    end_dateparts = end_date_text.split("/")
                    end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

                    project.revenue = revenue
                    project.start_date = start_date
                    project.end_date = end_date

            DBSession.flush()
            return HTTPFound(request.application_url + "/client/" + str(client.id) + "/projects/" + str(
                datetime.datetime.now().year))

        return dict(logged_in=authenticated_userid(request), header=Header("financials"), user=user, account=account,
                    client=client)
    except:
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 23
0
def role_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        role_id = request.matchdict.get('role_id')
        DBSession.query(Role).filter_by(id=role_id).filter_by(account_id=account_id).update({'is_active': False})
        DBSession.flush()

        return HTTPFound(location=request.application_url + "/administration/company")
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 24
0
def currency_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        currency_id = long(request.matchdict['currency_id'])
        DBSession.query(Currency).filter_by(id=currency_id).filter_by(
            account_id=account_id).delete()
        DBSession.flush()
        return HTTPFound(request.application_url + "/administration/company")
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 25
0
def person_assign_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        person_id = long(request.matchdict.get('person_id'))
        assignment_id = long(request.matchdict.get('assignment_id'))

        person = DBSession.query(User).filter_by(id=person_id).filter_by(account_id=account_id).first()
        if person == None:
            return HTTPFound(request.application_url)

        source_type_text = request.params.get("source_type")
        if source_type_text is None:
            source_type = "office"
        elif source_type_text == "ghost_client":
            source_type = "ghost/client"
        elif source_type_text == "client":
            source_type = source_type_text
        else:
            source_type = "office"
        source_id_text = request.params.get("source_id")
        if source_id_text is None:
            source_id = person.office_id
        else:
            source_id = long(source_id_text)


        user_allocation = DBSession.query(UserAllocation).filter_by(id=assignment_id).first()
        if user_allocation == None or user_allocation.user_id != person.id:
            return HTTPFound(request.application_url)
        DBSession.delete(user_allocation)
        DBSession.flush()

        return HTTPFound(location=request.application_url + "/person/" + str(
            person_id) + "/assign/edit?source_type=" + source_type + "&source_id=" + str(source_id))
    except:
        print("*****")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 26
0
def person_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or (user.is_administrator == False and user.is_hr_administrator == False):
            return HTTPFound(request.application_url)

        person_id = request.matchdict.get('person_id')
        DBSession.query(User).filter_by(id=person_id).filter_by(account_id=account_id).update(
            {'is_active': False, 'end_date': datetime.datetime.now()})
        DBSession.flush()

        return HTTPFound(location=request.application_url + "/administration/employees")
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 27
0
def administration_revenue(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        account = DBSession.query(Account).filter_by(id=account_id).first()
        user = DBSession.query(User).filter_by(id=user_id).first()

        if user is None or account is None or not (user.is_administrator or user.permissions_global_financials):
            return HTTPFound(request.application_url)

        if request.method == "POST":

            quarter_end_date_text = request.params.get("quarter_end_type")
            quarter_end_year_text = request.params.get("quarter_end_year")
            quarter_end_date_parts = quarter_end_date_text.split("/")
            quarter_end_date = datetime.date(long(quarter_end_year_text), long(quarter_end_date_parts[0]),
                                             long(quarter_end_date_parts[1]))

            for project in account.projects:
                revenue_local = long(request.params.get(str(project.id) + "-revenue"))

                if user.currency is None:
                    revenue = revenue_local
                else:
                    revenue = revenue_local * user.currency.currency_to_usd

                actual_revenue = DBSession.query(ActualRevenue).filter_by(project_id=project.id).filter_by(
                    quarter_end_date=quarter_end_date).first()

                if actual_revenue is not None:
                    actual_revenue.revenue = revenue
                else:
                    actual_revenue = ActualRevenue(project, revenue, quarter_end_date)

                DBSession.flush()

            return HTTPFound(request.application_url + "/administration/company")

        return dict(logged_in=authenticated_userid(request), header=Header("administration"), account=account,
                    user=user)
    except:
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 28
0
def office_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        office_id = request.matchdict.get('office_id')
        DBSession.query(Office).filter_by(id=office_id).filter_by(
            account_id=account_id).update({'is_active': False})
        DBSession.flush()

        return HTTPFound(location=request.application_url +
                         "/administration/company")
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 29
0
def role_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"].lower()
            department_id = long(request.params["department_id"])
            salary_low = long(request.params["salary_low"])
            salary_high = long(request.params["salary_high"])
            department = DBSession.query(Department).filter_by(
                id=department_id).filter_by(account_id=account.id).first()

            role_ok = True
            for role in department.roles:
                if role.name == name:
                    role_ok = False
                    break

            if role_ok:
                new_role = Role(account, name, department, salary_high,
                                salary_low)
                DBSession.add(new_role)
                DBSession.flush()

                if request.params.get("add_another") is None:
                    return HTTPFound(request.application_url +
                                     "/administration/company")

        departments = DBSession.query(Department).filter_by(
            account_id=long(request.session['aid'])).all()
        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    departments=departments,
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 30
0
def person_disable_login(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or (user.is_administrator == False and user.is_hr_administrator == False):
            return HTTPFound(request.application_url)

        person_id = request.matchdict.get('person_id')
        person = DBSession.query(User).filter_by(id=person_id).filter_by(account_id=account_id)

        if person is not None:
            password = None
            DBSession.query(User).filter_by(id=person_id).filter_by(account_id=account_id).update(
                {'password': password})
            DBSession.flush()

        return HTTPFound(request.application_url + "/administration/employees")
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 31
0
def currency_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        currency_id = long(request.matchdict['currency_id'])
        currency = DBSession.query(Currency).filter_by(id=currency_id).first()
        if currency == None:
            return HTTPFound(request.application_url +
                             "/administration/company")

        if request.method == "POST":
            error = False
            name = request.params["name"].lower()
            if name == "usd":
                error = True
            currency_to_usd = float(request.params["currency_to_usd"])
            cur = DBSession.query(Currency).filter_by(
                account_id=account_id).filter_by(name=name).first()
            if cur is not None and cur.id != currency_id:
                error = True
            if error == False:
                currency.name = name
                currency.currency_to_usd = currency_to_usd
                DBSession.flush()
                return HTTPFound(request.application_url +
                                 "/administration/company")

        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    currency=currency,
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 32
0
def client_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        client_id = request.matchdict.get('client_id')
        client = DBSession.query(Client).filter_by(id=client_id).filter_by(account_id=account_id).first()

        if client is None or user.can_access_client(client, "financials") == False:
            return HTTPFound(request.application_url)

        client.is_active = False
        DBSession.flush()

        return HTTPFound(request.application_url + "/office/" + str(client.office_id) + "/clients/" + str(
            datetime.datetime.now().year))
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 33
0
def role_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"].lower()
            department_id = long(request.params["department_id"])
            salary_low = long(request.params["salary_low"])
            salary_high = long(request.params["salary_high"])
            department = DBSession.query(Department).filter_by(id=department_id).filter_by(
                account_id=account.id).first()

            role_ok = True
            for role in department.roles:
                if role.name == name:
                    role_ok = False
                    break

            if role_ok:
                new_role = Role(account, name, department, salary_high, salary_low)
                DBSession.add(new_role)
                DBSession.flush()

                if request.params.get("add_another") is None:
                    return HTTPFound(request.application_url + "/administration/company")

        departments = DBSession.query(Department).filter_by(account_id=long(request.session['aid'])).all()
        return dict(logged_in=authenticated_userid(request), header=Header("administration"), departments=departments,
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 34
0
def office_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        account = DBSession.query(Account).filter_by(id=account_id).first()
        user = DBSession.query(User).filter_by(id=user_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        office_id = request.matchdict['office_id']
        if request.method == "POST":
            name = request.params["name"].lower()
            off = DBSession.query(Office).filter_by(
                account_id=long(request.session['aid'])).filter_by(
                    name=name).first()
            if off is None or str(off.id) == office_id:
                benefits_and_bonus = long(request.params["benefits_and_bonus"])
                DBSession.query(Office).filter_by(id=office_id).filter_by(
                    account_id=account_id).update({
                        'name':
                        name,
                        'benefits_and_bonus':
                        benefits_and_bonus
                    })
                DBSession.flush()

            return HTTPFound(request.application_url +
                             "/administration/company")

        office = DBSession.query(Office).filter_by(id=office_id).first()
        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    office=office,
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 35
0
def freelancer_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        freelancer_id = request.matchdict.get('freelancer_id')
        freelancer = DBSession.query(Freelancer).filter_by(id=freelancer_id).filter_by(account_id=account_id).first()

        if freelancer is None:
            return HTTPFound(request.application_url)

        if freelancer.office is None and freelancer.client is None:
            return HTTPFound(request.application_url)

        if freelancer.office is not None and user.can_access_office(freelancer.office, "utilization") == False:
            return HTTPFound(request.application_url)

        if freelancer.client is not None and user.can_access_client(freelancer.client, "utilization") == False:
            return HTTPFound(request.application_url)

        source_id = freelancer.client_id

        DBSession.delete(freelancer)
        DBSession.flush()

        return HTTPFound(
            request.application_url + "/client/" + str(source_id) + "/utilization/" + str(datetime.datetime.now().year))

    except:
        print("*************")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 36
0
def currency_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"].lower()
            currency_to_usd = float(request.params["currency_to_usd"])
            error = False
            if name == "usd":
                error = True

            currency = DBSession.query(Currency).filter_by(
                account_id=account_id).filter_by(name=name).first()
            if currency is not None:
                error = True

            if error == False:
                new_currency = Currency(name, account, currency_to_usd)
                DBSession.add(new_currency)
                DBSession.flush()

                if request.params.get("add_another") is None:
                    return HTTPFound(request.application_url +
                                     "/administration/company")

        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 37
0
def department_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"].lower()
            dept = DBSession.query(Department).filter_by(account_id=account_id).filter_by(name=name).first()
            if dept is None:
                new_department = Department(name, account)
                DBSession.add(new_department)
                DBSession.flush()

                if request.params.get("add_another") is None:
                    return HTTPFound(location=request.application_url + "/administration/company")

        return dict(logged_in=authenticated_userid(request), header=Header("administration"), user=user)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 38
0
def client_assign_resource(request):
    try:
        user_id = long(request.session['uid'])
        account_id = long(request.session['aid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()
        if user is None or account is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":

            client_id = long(request.params['client_id'])
            client = DBSession.query(Client).filter_by(account_id=account_id).filter_by(id=client_id).first()

            person_id = long(request.params["user_id"])
            person = DBSession.query(User).filter_by(id=person_id).filter_by(account_id=account_id).first()

            utilization = long(request.params["utilization"])

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]), long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

            if person is None or client is None or user.can_access_client(client, "utilization") == False:
                return HTTPFound(request.application_url)

            if person.start_date.date() > start_date or start_date > end_date:
                print("*** late start")
                return HTTPFound(request.path)

            ua = UserAllocation(person, client, None, utilization, start_date, end_date)
            DBSession.add(ua)
            DBSession.flush()
            return HTTPFound(request.application_url + "/client/" + str(client_id) + "/utilization/" + str(
                datetime.datetime.now().year))

        clients_all = DBSession.query(Client).filter_by(account_id=account_id).filter_by(is_active=True).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
        if len(clients) == 0:
            return HTTPFound(request.application_url)

        access_administration = user.is_administrator

        # fix this so the filtering is btter instead of doing a big loop
        users_all = DBSession.query(User).filter_by(account_id=account_id).filter_by(is_active=True).all()
        users = []
        for u in users_all:
            if u.is_active and u.percent_billable > 0 and user.can_access_office(u.office, "utilization"):
                users.append(u)
        if len(users) == 0:
            return HTTPFound(request.application_url)

        currentClientId = request.params.get('clientid')
        currentClient = None

        if currentClientId is not None:
            currentClient = DBSession.query(Client).filter_by(id=currentClientId).filter_by(is_active=True).first()

        return dict(logged_in=authenticated_userid(request), header=getHeader(None), clients=clients, users=users,
                    user=user, account=account, access_administration=access_administration,
                    currentClient=currentClient)
    except:
        print("*****")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 39
0
def client_add(request):
    try:
        user_id = long(request.session['uid'])
        account_id = long(request.session['aid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":

            name = request.params["name"].lower()
            code = request.params["client_code"]
            office_id = long(request.params["office_id"])
            project_name = request.params["project_name"]
            project_code = request.params["project_code"]
            target_margin = request.params["target_margin"]
            revenue_local = long(request.params["revenue"])
            if user.currency is None:
                revenue = revenue_local
            else:
                revenue = revenue_local * user.currency.currency_to_usd

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]), long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

            office = DBSession.query(Office).filter_by(id=office_id).filter_by(account_id=account_id).first()
            client = DBSession.query(Client).filter_by(account_id=account_id).filter_by(name=name).first()

            if client is None and office is not None and user.can_access_office(office, "financials"):
                new_client = Client(name, office, code, target_margin)
                DBSession.add(new_client)

                new_project = Project(project_name, project_code, account, new_client, revenue, start_date, end_date)
                DBSession.add(new_project)

                department_matches = []
                for department in account.departments:
                    percent_allocation = request.params.get(str(department.id) + "-allocation")
                    if percent_allocation is not None and percent_allocation != "":
                        department_matches.append(str(department.id) + "-" + str(percent_allocation))

                DBSession.flush()

                for d in department_matches:
                    ds = d.split('-')
                    department = DBSession.query(Department).filter_by(id=int(ds[0])).first()
                    budget_allocation = BudgetAllocation(department, new_project, None, int(ds[1]))
                    DBSession.add(budget_allocation)

                DBSession.flush()

                if request.params.get("add_another") is None:
                    return HTTPFound(request.application_url + "/office/" + str(office_id) + "/clients/" + str(
                        datetime.datetime.now().year))

        officeId = request.params.get('officeid')
        currentOffice = None

        if officeId is not None:
            currentOffice = DBSession.query(Office).filter_by(id=officeId).filter_by(is_active=True).first()

        offices_all = DBSession.query(Office).filter_by(account_id=long(request.session['aid'])).all()
        offices = []
        if user.is_administrator or user.permissions_global_financials:
            offices = offices_all
        else:
            for office in offices_all:
                if user.can_access_office(office, "financials"):
                    offices.append(office)

        return dict(logged_in=authenticated_userid(request), header=getHeader(None), offices=offices, user=user,
                    account=account, currentOffice=currentOffice)
    except:
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 40
0
def person_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or (user.is_administrator == False and user.is_hr_administrator == False):
            return HTTPFound(request.application_url)

        if request.method == "GET":
            source = request.params.get("source")
            if source is None or source == '' or len(source) == 0:
                source = 'financials'

        if request.method == "POST":
            email = request.params["email"]
            person = DBSession.query(User).filter_by(email=email).first()

            if person is not None:
                source = 'financials'
            else:

                account = DBSession.query(Account).filter_by(id=account_id).first()

                name = request.params["name"].lower()
                if request.params.get("employee_number") is None or request.params.get("employee_number") == '':
                    employee_number = 0
                else:
                    employee_number = long(request.params.get("employee_number"))

                source = request.params["source"]

                if request.params.get("salary") is None or request.params.get("salary") == '':
                    salary = 0
                else:
                    salary_local = long(request.params.get("salary"))
                    if user.currency is None:
                        salary = salary_local
                    else:
                        salary = salary_local * user.currency.currency_to_usd

                if request.params.get("office_id") is None or request.params.get("office_id") == '':
                    office_id = None
                    office = None
                else:
                    office_id = long(request.params.get("office_id"))
                    office = DBSession.query(Office).filter_by(id=office_id).filter_by(account_id=account_id).first()

                if request.params.get("role_id") is None or request.params.get("role_id") == '':
                    role_id = None
                    return HTTPFound(request.application_url + "/person/add")
                else:
                    role_id = long(request.params.get("role_id"))
                    role = DBSession.query(Role).filter_by(id=role_id).first()

                if request.params.get("percent_billable") is None or request.params.get("percent_billable") == '':
                    percent_billable = 100
                elif request.params.get("percent_billable") == '0':
                    percent_billable = 0
                else:
                    percent_billable = long(request.params.get("percent_billable"))

                if request.params.get("currency_id") is None or request.params.get("currency_id") == '':
                    currency_id = None
                    currency = None
                else:
                    currency_id = long(request.params.get("currency_id"))
                    currency = DBSession.query(Currency).filter_by(id=currency_id).filter_by(account_id=account_id).first()

                start_date_text = request.params.get("start_date")
                if start_date_text is None or start_date_text == '':
                    start_date = datetime.datetime.now()
                else:
                    start_dateparts = start_date_text.split("/")
                    start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]), long(start_dateparts[1]))

                end_date_text = request.params.get("end_date")
                if end_date_text is None or end_date_text == '':
                    end_date = None
                else:
                    end_dateparts = end_date_text.split("/")
                    end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

                if request.params.get("is_administrator") is None or request.params.get("is_administrator") == '':
                    is_administrator = False
                else:
                    is_administrator = True

                if request.params.get("is_hr_administrator") is None or request.params.get("is_hr_administrator") == '':
                    is_hr_administrator = False
                else:
                    is_hr_administrator = True

                if request.params.get("employee_assignment_access") is None or request.params.get("employee_assignment_access") == '':
                    employee_assignment_access = False
                else:
                    employee_assignment_access = True

                u = DBSession.query(User).filter_by(email=email).first()
                if u is not None:
                    return HTTPFound(request.application_url + "/person/add")

                new_user = User(account, name, email, office, role, salary, start_date)
                new_user.employee_number = employee_number
                new_user.percent_billable = percent_billable
                new_user.end_date = end_date
                new_user.is_administrator = is_administrator
                new_user.is_hr_administrator = is_hr_administrator
                new_user.currency = currency
                new_user.employee_assignment_access = employee_assignment_access

                permissions_office_financials = request.params.getall("permissions_office_financials")
                for office_id in permissions_office_financials:
                    if office_id == "all":
                        new_user.permissions_global_financials = True
                        break
                if new_user.permissions_global_financials == False:
                    for office_id in permissions_office_financials:
                        office = DBSession.query(Office).filter_by(account_id=account_id).filter_by(id=office_id).first()
                        if office is not None:
                            new_user.permissions_office_financials.append(office)

                permissions_office_pipeline = request.params.getall("permissions_office_pipeline")
                for office_id in permissions_office_pipeline:
                    if office_id == "all":
                        new_user.permissions_global_pipeline = True
                        break
                if new_user.permissions_global_pipeline == False:
                    for office_id in permissions_office_pipeline:
                        office = DBSession.query(Office).filter_by(account_id=account_id).filter_by(id=office_id).first()
                        if office is not None:
                            new_user.permissions_office_pipeline.append(office)

                permissions_office_utilization = request.params.getall("permissions_office_utilization")
                for office_id in permissions_office_utilization:
                    if office_id == "all":
                        new_user.permissions_global_utilization = True
                        break
                if new_user.permissions_global_utilization == False:
                    for office_id in permissions_office_utilization:
                        office = DBSession.query(Office).filter_by(account_id=account_id).filter_by(id=office_id).first()
                        if office is not None:
                            new_user.permissions_office_utilization.append(office)

                permissions_client_financials = request.params.getall("permissions_client_financials")
                for client_id in permissions_client_financials:
                    client = DBSession.query(Client).filter_by(account_id=account_id).filter_by(id=client_id).first()
                    if client is not None:
                        new_user.permissions_client_financials.append(client)
                permissions_client_pipeline = request.params.getall("permissions_client_pipeline")
                for client_id in permissions_client_pipeline:
                    client = DBSession.query(Office).filter_by(account_id=account_id).filter_by(id=client_id).first()
                    if client is not None:
                        new_user.permissions_client_pipeline.append(client)
                permissions_client_utilization = request.params.getall("permissions_client_utilization")
                for client_id in permissions_client_utilization:
                    client = DBSession.query(Office).filter_by(account_id=account_id).filter_by(id=client_id).first()
                    if client is not None:
                        new_user.permissions_client_utilization.append(client)
                permissions_department_financials = request.params.getall("permissions_department_financials")
                for department_id in permissions_department_financials:
                    department = DBSession.query(Department).filter_by(account_id=account_id).filter_by(
                        id=department_id).first()
                    if department is not None:
                        new_user.permissions_department_financials.append(department)
                permissions_department_utilization = request.params.getall("permissions_client_utilization")
                for department_id in permissions_client_utilization:
                    department = DBSession.query(Department).filter_by(account_id=account_id).filter_by(
                        id=department_id).first()
                    if department is not None:
                        new_user.permissions_department_utilization.append(department)

                s = Salary(new_user, salary, role.id, start_date)
                new_user.salary_history.append(s)

                DBSession.add(new_user)
                DBSession.flush()

                if request.params.get("add_another") is None:
                    if source == "reviews":
                        return HTTPFound(request.application_url + "/people/all/all/all")
                    else:
                        source = "financials"
                        return HTTPFound(request.application_url + "/administration/employees")

        departments = DBSession.query(Department).filter_by(account_id=account_id).all()
        offices = DBSession.query(Office).filter_by(account_id=account_id).all()
        clients= DBSession.query(Client).filter_by(account_id=account_id).all()
        roles = DBSession.query(Role).filter_by(account_id=account_id).all()
        currencies = DBSession.query(Currency).filter_by(account_id=account_id).all()

        return dict(logged_in=authenticated_userid(request), header=Header(source), offices=offices, roles=roles,
                    clients=clients, currencies=currencies, user=user, departments=departments)
    except:
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 41
0
def project_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":

            name = request.params["name"].lower()
            code = request.params["project_code"]
            client_id = long(request.params["client_id"])
            revenue_local = long(request.params["revenue"])

            if user.currency is None:
                revenue = revenue_local
            else:
                revenue = revenue_local * user.currency.currency_to_usd

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]), long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

            client = DBSession.query(Client).filter_by(account_id=account_id).filter_by(id=client_id).first()

            if client is None or user.can_access_client(client, "financials") == False:
                return HTTPFound(request.application_url)

            for project in client.projects:
                if project.name == name:
                    return HTTPFound(request.application_url)

            new_project = Project(name, code, account, client, revenue, start_date, end_date)
            DBSession.add(new_project)
            DBSession.flush()

            department_matches = []
            for department in account.departments:
                percent_allocation = request.params.get(str(department.id) + "-allocation")
                if percent_allocation is not None and percent_allocation != "":
                    department_matches.append(str(department.id) + "-" + str(percent_allocation))

            for d in department_matches:
                ds = d.split('-')
                department = DBSession.query(Department).filter_by(id=int(ds[0])).first()
                budget_allocation = BudgetAllocation(department, new_project, None, int(ds[1]))
                DBSession.add(budget_allocation)

            DBSession.flush()

            if request.params.get("add_another") is None:
                return HTTPFound(request.application_url + "/client/" + str(client_id) + "/projects/" + str(
                    datetime.datetime.now().year))

        clients_all = DBSession.query(Client).filter_by(account_id=account_id).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
        if len(clients) == 0:
            return HTTPFound(request.application_url)
        return dict(logged_in=authenticated_userid(request), header=Header("financials"), clients=clients, user=user,
                    account=account)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 42
0
def project_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        project_id = long(request.matchdict['project_id'])
        project = DBSession.query(Project).filter_by(id=project_id).filter_by(account_id=account_id).first()

        if project is None or user.can_access_client(project.client, "financials") == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":

            name = request.params["name"].lower()
            code = request.params["project_code"]

            client_id = long(request.params["client_id"])
            revenue_local = long(request.params["revenue"])

            if user.currency is None:
                revenue = revenue_local
            else:
                revenue = revenue_local * user.currency.currency_to_usd

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]), long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

            client = DBSession.query(Client).filter_by(account_id=account_id).filter_by(id=client_id).first()

            if client is None or user.can_access_client(client, "financials") == False:
                return HTTPFound(request.application_url)

            for p in client.projects:
                if p.name == name and p.id != project.id:
                    return HTTPFound(request.application_url)

            matched_departments = []
            for department in account.departments:
                percent_allocation = request.params.get(str(department.id) + "-allocation")
                for budget_allocation in project.budget_allocations:
                    if budget_allocation.department_id == department.id:
                        matched_departments.append(department.id)
                        if percent_allocation is None or percent_allocation == "":
                            DBSession.delete(budget_allocation)
                        else:
                            budget_allocation.percent_allocation = percent_allocation

            for department in account.departments:
                if department.id not in matched_departments:
                    percent_allocation = request.params.get(str(department.id) + "-allocation")
                    if percent_allocation is not None and percent_allocation != "":
                        ba = BudgetAllocation(department, project, None, int(percent_allocation))
                        DBSession.add(ba)

            project.name = name
            project.code = code
            project.client = client
            project.revenue = revenue
            project.start_date = start_date
            project.end_date = end_date
            DBSession.flush()

            return HTTPFound(request.application_url + "/client/" + str(client_id) + "/projects/" + str(
                datetime.datetime.now().year))

        matched_departments = []
        for budget_allocation in project.budget_allocations:
            matched_departments.append(budget_allocation.department_id)

        budgetAllocations = project.budget_allocations

        for department in account.departments:
            if department.id not in matched_departments:
                budgetAllocations.append(BudgetAllocation(department, project, None, 0))

        clients_all = DBSession.query(Client).filter_by(account_id=account_id).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
        if len(clients) == 0:
            return HTTPFound(request.application_url)
        return dict(logged_in=authenticated_userid(request), header=Header("financials"), clients=clients, user=user,
                    account=account, project=project, budgetAllocations=budgetAllocations)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 43
0
def project_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":

            name = request.params["name"].lower()
            code = request.params["project_code"]
            client_id = long(request.params["client_id"])
            revenue_local = long(request.params["revenue"])

            if user.currency is None:
                revenue = revenue_local
            else:
                revenue = revenue_local * user.currency.currency_to_usd

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]),
                                       long(start_dateparts[0]),
                                       long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]),
                                     long(end_dateparts[0]),
                                     long(end_dateparts[1]))

            client = DBSession.query(Client).filter_by(
                account_id=account_id).filter_by(id=client_id).first()

            if client is None or user.can_access_client(client,
                                                        "financials") == False:
                return HTTPFound(request.application_url)

            for project in client.projects:
                if project.name == name:
                    return HTTPFound(request.application_url)

            new_project = Project(name, code, account, client, revenue,
                                  start_date, end_date)
            DBSession.add(new_project)
            DBSession.flush()

            department_matches = []
            for department in account.departments:
                percent_allocation = request.params.get(
                    str(department.id) + "-allocation")
                if percent_allocation is not None and percent_allocation != "":
                    department_matches.append(
                        str(department.id) + "-" + str(percent_allocation))

            for d in department_matches:
                ds = d.split('-')
                department = DBSession.query(Department).filter_by(
                    id=int(ds[0])).first()
                budget_allocation = BudgetAllocation(department, new_project,
                                                     None, int(ds[1]))
                DBSession.add(budget_allocation)

            DBSession.flush()

            if request.params.get("add_another") is None:
                return HTTPFound(request.application_url + "/client/" +
                                 str(client_id) + "/projects/" +
                                 str(datetime.datetime.now().year))

        clients_all = DBSession.query(Client).filter_by(
            account_id=account_id).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
        if len(clients) == 0:
            return HTTPFound(request.application_url)
        return dict(logged_in=authenticated_userid(request),
                    header=Header("financials"),
                    clients=clients,
                    user=user,
                    account=account)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 44
0
def freelancer_add(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"].lower()
            role_id = long(request.params["role_id"])
            client_id = request.params.get('client_id')
            office_id = request.params.get('office_id')

            client = None
            if client_id is not None and client_id != '' and len(client_id) > 0:
                client = DBSession.query(Client).filter_by(account_id=account_id).filter_by(id=long(client_id)).first()

            office = None
            if office_id is not None and office_id != '' and len(office_id) > 0:
                office = DBSession.query(Office).filter_by(account_id=account_id).filter_by(id=long(office_id)).first()

            if client is None and office is None:
                return HTTPFound(request.application_url)

            utilization = long(request.params["utilization"])
            hourly_rate_local = long(request.params["hourly_rate"])
            if user.currency is None:
                hourly_rate = hourly_rate_local
            else:
                hourly_rate = hourly_rate_local * user.currency.currency_to_usd

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]), long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

            role = DBSession.query(Role).filter_by(id=role_id).filter_by(account_id=account_id).first()

            if office is not None and user.can_access_office(office, "utilization") == False:
                return HTTPFound(request.application_url)

            if client is not None and user.can_access_client(client, "utilization") == False:
                return HTTPFound(request.application_url)

            freelancer = Freelancer(account, name, role, start_date, end_date, hourly_rate, utilization, client, office)
            DBSession.add(freelancer)
            DBSession.flush()

            if request.params.get("add_another") is None:
                if client is not None:
                    return HTTPFound(request.application_url + "/client/" + str(client_id) + "/utilization/" + str(
                        datetime.datetime.now().year))

                if office is not None:
                    return HTTPFound(request.application_url + "/office/" + str(office_id) + "/utilization/" + str(
                        datetime.datetime.now().year))

        currentClientId = request.params.get('clientid')
        currentClient = None

        if currentClientId is not None:
            currentClient = DBSession.query(Client).filter_by(id=currentClientId).filter_by(is_active=True).first()

        clients_all = DBSession.query(Client).filter_by(account_id=account_id).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
        if len(clients) == 0:
            return HTTPFound(request.application_url)

        offices_all = DBSession.query(Office).filter_by(account_id=account_id).all()
        offices = []
        if user.is_administrator or user.permissions_global_utilization:
            offices = offices_all
        else:
            for office in offices_all:
                if user.can_access_office(office, "utilization"):
                    offices.append(office)
        if len(offices) == 0:
            return HTTPFound(request.application_url)

        roles = DBSession.query(Role).filter_by(account_id=account_id).all()

        return dict(logged_in=authenticated_userid(request), header=Header('financials'), clients=clients,
                    offices=offices, roles=roles, user=user, account=account, currentClient=currentClient)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 45
0
def freelancer_convert(request):
    try:
        freelancer_id = long(request.matchdict['freelancer_id'])

        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        freelancer = DBSession.query(Freelancer).filter_by(account_id=account_id).filter_by(id=freelancer_id).first()
        if freelancer is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            email = request.params["email"]
            person = DBSession.query(User).filter_by(email=email).first()

            if person is not None:
                source = 'financials'
            else:

                account = DBSession.query(Account).filter_by(id=account_id).first()

                name = request.params["name"].lower()
                if request.params.get("employee_number") is None or request.params.get("employee_number") == '':
                    employee_number = 0
                else:
                    employee_number = long(request.params.get("employee_number"))

                if request.params.get("salary") is None or request.params.get("salary") == '':
                    salary = 0
                else:
                    salary_local = long(request.params.get("salary"))
                    if user.currency is None:
                        salary = salary_local
                    else:
                        salary = salary_local * user.currency.currency_to_usd

                if request.params.get("office_id") is None or request.params.get("office_id") == '':
                    office_id = None
                    office = None
                else:
                    office_id = long(request.params.get("office_id"))
                    office = DBSession.query(Office).filter_by(id=office_id).filter_by(account_id=account_id).first()

                if request.params.get("role_id") is None or request.params.get("role_id") == '':
                    role_id = None
                    return HTTPFound(request.application_url + "/person/add")
                else:
                    role_id = long(request.params.get("role_id"))
                    role = DBSession.query(Role).filter_by(id=role_id).first()

                if request.params.get("percent_billable") is None or request.params.get("percent_billable") == '':
                    percent_billable = 100
                elif request.params.get("percent_billable") == '0':
                    percent_billable = 0
                else:
                    percent_billable = long(request.params.get("percent_billable"))

                if request.params.get("currency_id") is None or request.params.get("currency_id") == '':
                    currency_id = None
                    currency = None
                else:
                    currency_id = long(request.params.get("currency_id"))
                    currency = DBSession.query(Currency).filter_by(id=currency_id).filter_by(
                        account_id=account_id).first()

                start_date_text = request.params.get("start_date")
                if start_date_text is None or start_date_text == '':
                    start_date = datetime.datetime.now()
                else:
                    start_dateparts = start_date_text.split("/")
                    start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]),
                                               long(start_dateparts[1]))

                end_date_text = request.params.get("end_date")
                if end_date_text is None or end_date_text == '':
                    end_date = None
                else:
                    end_dateparts = end_date_text.split("/")
                    end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

                is_administrator = False

                is_hr_administrator = False

                u = DBSession.query(User).filter_by(email=email).first()
                if u is not None:
                    return HTTPFound(request.application_url + "/person/add")

                new_user = User(account, name, email, office, role, salary, start_date)
                new_user.employee_number = employee_number
                new_user.percent_billable = percent_billable
                new_user.end_date = end_date
                new_user.is_administrator = is_administrator
                new_user.is_hr_administrator = is_hr_administrator
                new_user.currency = currency

                s = Salary(new_user, salary, role.id, start_date)
                new_user.salary_history.append(s)

                DBSession.add(new_user)

                freelancer.converted_fulltime = True

                expected_freelancer_end_date = start_date - timedelta(days=1)
                if freelancer.end_date.date() > expected_freelancer_end_date:
                    freelancer.end_date = expected_freelancer_end_date

                DBSession.flush()
                return HTTPFound(request.application_url + "/client/" + str(freelancer.client.id) + "/utilization/" + str(datetime.datetime.now().year))

        departments = DBSession.query(Department).filter_by(account_id=account_id).all()
        offices = DBSession.query(Office).filter_by(account_id=account_id).all()
        roles = DBSession.query(Role).filter_by(account_id=account_id).all()
        currencies = DBSession.query(Currency).filter_by(account_id=account_id).all()

        return dict(logged_in=authenticated_userid(request), header=Header('financials'),
                    offices=offices, roles=roles, freelancer=freelancer, currencies=currencies, user=user,
                    account=account, departments=departments)
    except:
        print("*************")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 46
0
def freelancer_edit(request):
    try:
        freelancer_id = long(request.matchdict['freelancer_id'])

        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        freelancer = DBSession.query(Freelancer).filter_by(account_id=account_id).filter_by(id=freelancer_id).first()
        if freelancer is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            name = request.params["name"].lower()
            role_id = long(request.params["role_id"])
            client_id = request.params.get('client_id')
            office_id = request.params.get('office_id')

            client = None
            if client_id is not None and client_id != '' and len(client_id) > 0:
                client = DBSession.query(Client).filter_by(account_id=account_id).filter_by(id=long(client_id)).first()

            office = None
            if office_id is not None and office_id != '' and len(office_id) > 0:
                office = DBSession.query(Office).filter_by(account_id=account_id).filter_by(id=long(office_id)).first()

            if client is None and office is None:
                return HTTPFound(request.application_url)

            utilization = long(request.params["utilization"])
            hourly_rate_local = long(request.params["hourly_rate"])
            if user.currency is None:
                hourly_rate = hourly_rate_local
            else:
                hourly_rate = hourly_rate_local * user.currency.currency_to_usd

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]), long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

            role = DBSession.query(Role).filter_by(id=role_id).filter_by(account_id=account_id).first()

            if role is None or office is not None and user.can_access_office(office, "utilization") == False:
                return HTTPFound(request.application_url)

            if client is not None and user.can_access_client(client, "utilization") == False:
                return HTTPFound(request.application_url)

            parsed_name = HumanName(name)
            freelancer.first_name = parsed_name.first
            freelancer.middle_name = parsed_name.middle
            freelancer.last_name = parsed_name.last
            freelancer.office = office
            freelancer.client = client
            freelancer.start_date = start_date
            freelancer.end_date = end_date
            freelancer.utilization = utilization
            freelancer.hourly_rate = hourly_rate
            DBSession.flush()

            if client is not None:
                return HTTPFound(request.application_url + "/client/" + str(client_id) + "/utilization/" + str(
                    datetime.datetime.now().year))

            if office is not None:
                return HTTPFound(request.application_url + "/office/" + str(office_id) + "/utilization/" + str(
                    datetime.datetime.now().year))

        clients_all = DBSession.query(Client).filter_by(account_id=account_id).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
            if len(clients) == 0:
                print("************* no c")
                return HTTPFound(request.application_url)

        offices_all = DBSession.query(Office).filter_by(account_id=account_id).all()
        offices = []
        if user.is_administrator or user.permissions_global_utilization:
            offices = offices_all
        else:
            for office in offices_all:
                if user.can_access_office(office, "utilization"):
                    offices.append(office)
            if len(offices) == 0:
                print("************* no o")
                return HTTPFound(request.application_url)

        roles = DBSession.query(Role).filter_by(account_id=long(request.session['aid'])).all()

        return dict(logged_in=authenticated_userid(request), header=Header('financials'), clients=clients,
                    offices=offices, roles=roles, freelancer=freelancer, user=user, account=account)
    except:
        print("*************")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 47
0
def administration_expenses_clients(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        account = DBSession.query(Account).filter_by(id=account_id).first()
        user = DBSession.query(User).filter_by(id=user_id).first()
        year = str(datetime.datetime.now().year)
        quarter_end_year_text = None
        if user is None or account is None or not (
                user.is_administrator or user.permissions_global_financials):
            return HTTPFound(request.application_url)

        if request.method == "POST":

            quarter_end_date_text = request.params.get("quarter_end_type")
            quarter_end_year_text = request.params.get("quarter_end_year")
            quarter_end_date_parts = quarter_end_date_text.split("/")
            quarter_end_date = datetime.date(long(quarter_end_year_text),
                                             long(quarter_end_date_parts[0]),
                                             long(quarter_end_date_parts[1]))

            for client in account.clients:
                if request.params.get(str(client.id) + "-expense"
                                      ) is not None and request.params.get(
                                          str(client.id) + "-expense") != "":
                    expense_lc = long(
                        request.params.get(str(client.id) + "-expense"))
                else:
                    expense_lc = 0

                if user.currency is None:
                    expense_local = expense_lc
                else:
                    expense_local = expense_lc * user.currency.currency_to_usd

                actual_expense = DBSession.query(ActualExpense).filter_by(
                    client_id=client.id).filter_by(
                        quarter_end_date=quarter_end_date).first()

                if actual_expense is not None:
                    actual_expense.expense_local += expense_local
                else:
                    actual_expense = ActualExpense(None, client, expense_local,
                                                   None, quarter_end_date)
                    DBSession.add(actual_expense)

            DBSession.flush()

        usd_to_local = 1
        if user.currency is not None:
            usd_to_local = user.currency.usd_to_currency

        if quarter_end_year_text is not None:
            expense_year = int(quarter_end_year_text)
        else:
            expense_year = int(year)

        all_client_expense_sga = []
        for client in account.clients:
            client_expense_sga = [0, 0, 0, 0]

            for actual_expense in client.actual_expenses:
                if actual_expense.quarter_end_date.year == expense_year:

                    if actual_expense.quarter_end_date.month == 3:
                        if actual_expense.expense_local is not None:
                            client_expense_sga[
                                0] = actual_expense.expense_local * usd_to_local

                    elif actual_expense.quarter_end_date.month == 6:
                        if actual_expense.expense_local is not None:
                            client_expense_sga[
                                1] = actual_expense.expense_local * usd_to_local

                    elif actual_expense.quarter_end_date.month == 9:
                        if actual_expense.expense_local is not None:
                            client_expense_sga[
                                2] = actual_expense.expense_local * usd_to_local

                    elif actual_expense.quarter_end_date.month == 12:
                        if actual_expense.expense_local is not None:
                            client_expense_sga[
                                3] = actual_expense.expense_local * usd_to_local

            all_client_expense_sga.append(client_expense_sga)
        return dict(logged_in=authenticated_userid(request),
                    header=Header("administration"),
                    account=account,
                    user=user,
                    year=year,
                    all_client_expense_sga=all_client_expense_sga,
                    expense_year=expense_year)
    except:
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 48
0
def person_assign_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            print("*** no user")
            return HTTPFound(request.application_url)

        person_id = long(request.matchdict['person_id'])
        person = DBSession.query(User).filter_by(id=person_id).first()

        if person is None or user.can_access_office(person.office, "utilization") == False:
            print("*** no person")
            return HTTPFound(request.application_url)

        source_type_text = request.params.get("source_type")

        if source_type_text is None:
            source_type = "office"
        elif source_type_text == "ghost_client":
            source_type = "ghost/client"
        elif source_type_text == "client":
            source_type = source_type_text
        elif source_type_text == "administration":
            source_type = source_type_text
        else:
            source_type = "office"
        source_id_text = request.params.get("source_id")
        if source_id_text is None:
            source_id = person.office_id
        else:
            source_id = long(source_id_text)

        if request.method == "POST":
            for assignment in person.allocations:
                client_id = None
                ghost_client_id = None
                client_id = request.params.get(str(assignment.id) + "-client_id")
                ghost_client_id = request.params.get(str(assignment.id) + "-ghost_client_id")
                client = None
                ghost_client = None

                if client_id is not None and client_id != '' and len(client_id) > 0:
                    client = DBSession.query(Client).filter_by(id=client_id).filter_by(account_id=account_id).first()

                if ghost_client_id is not None and ghost_client_id != '' and len(ghost_client_id) > 0:
                    ghost_client = DBSession.query(GhostClient).filter_by(id=ghost_client_id).filter_by(
                        account_id=account_id).first()

                if client is None and ghost_client is None:
                    return HTTPFound(request.application_url)

                if client is not None and user.can_access_client(client, "utilization") == False:
                    return HTTPFound(request.application_url)

                if ghost_client is not None and user.can_access_office(ghost_client, "utilization") == False:
                    return HTTPFound(request.application_url)

                utilization = long(request.params[str(assignment.id) + "-utilization"])

                start_date_text = request.params[str(assignment.id) + "-start_date"]
                start_dateparts = start_date_text.split("/")
                start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]), long(start_dateparts[1]))

                end_date_text = request.params[str(assignment.id) + "-end_date"]
                end_dateparts = end_date_text.split("/")
                end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

                if person.start_date.date() > start_date or start_date > end_date:
                    print("*** late start")
                    return HTTPFound(request.path)

                assignment.client = client
                assignment.ghost_client = ghost_client
                assignment.utilization = utilization
                assignment.start_date = start_date
                assignment.end_date = end_date
                DBSession.flush()

            return HTTPFound(request.application_url + "/" + source_type + "/" + str(source_id) + "/utilization/" + str(
                datetime.datetime.now().year))

        assignments_all = DBSession.query(UserAllocation).filter_by(user_id=person_id).all()
        assignments = []
        if user.is_administrator or user.permissions_global_utilization:
            assignments = assignments_all
        else:
            for assignment in assignments_all:
                if assignment.client_id is not None:
                    if user.can_access_client(assignment.client, "utilization"):
                        assignments.append(assignment)
                elif assignment.ghost_client_id is not None:
                    if user.can_access_office(assignment.ghost_client.office, "utilization"):
                        assignments.append(assignment)

        # Commented for now.
        # if len(assignments) == 0:
        #     return HTTPFound(request.application_url + "/" + source_type + "/" + str(source_id) + "/utilization/" + str(
        #         datetime.datetime.now().year))

        clients_all = DBSession.query(Client).filter_by(account_id=account_id).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
        ghost_clients_all = DBSession.query(GhostClient).filter_by(account_id=account_id).all()
        ghost_clients = []
        if user.is_administrator or user.permissions_global_utilization:
            ghost_clients = ghost_clients_all
        else:
            for ghost_client in ghost_clients_all:
                if user.can_access_office(ghost_client.office, "utilization"):
                    ghost_clients.append(ghost_client)
        if len(clients) == 0 and len(ghost_clients):
            return HTTPFound(request.application_url)

        return dict(logged_in=authenticated_userid(request), header=Header("financials"), clients=clients,
                    ghost_clients=ghost_clients, person=person, user=user, account=account, assignments=assignments,
                    source_id=source_id, source_type=source_type, year=str(datetime.datetime.now().year))
    except:
        print("*****")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 49
0
def client_assign_ghost(request):
    try:
        user_id = long(request.session['uid'])
        account_id = long(request.session['aid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        if request.method == "POST":
            ghost_user_id = request.params.get('ghost_user_id')
            if ghost_user_id is None or len(ghost_user_id) == 0 or ghost_user_id == '':
                return HTTPFound(request.application_url)
            ghost_user = DBSession.query(GhostUser).filter_by(id=ghost_user_id).filter_by(account_id=account_id).first()

            client_id = request.params.get('client_id')
            client = None
            if client_id is not None and len(client_id) > 0 and client_id != '':
                client = DBSession.query(Client).filter_by(account_id=account_id).filter_by(id=long(client_id)).first()

            ghost_client_id = request.params.get('ghost_client_id')
            ghost_client = None
            if ghost_client_id is not None and len(ghost_client_id) > 0 and ghost_client_id != '':
                ghost_client = DBSession.query(GhostClient).filter_by(account_id=account_id).filter_by(
                    id=long(ghost_client_id)).first()

            if client is None and ghost_client is None:
                return HTTPFound(request.application_url)

            if client is not None and user.can_access_client(client, "utilization") == False:
                return HTTPFound(request.application_url)

            if ghost_client is not None and user.can_access_office(ghost_client.office, "utilization") == False:
                return HTTPFound(request.application_url)

            utilization = long(request.params["utilization"])

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]), long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

            if ghost_user.start_date.date() > start_date or start_date > end_date:
                print('**** late start')
                return HTTPFound(request.path)

            gua = GhostAllocation(ghost_user, client, ghost_client, utilization, start_date, end_date)
            DBSession.add(gua)

            if ghost_user.start_date.date() > start_date:
                ghost_user.start_date = datetime.datetime.combine(start_date, datetime.time())

            DBSession.flush()
            if client is not None:
                return HTTPFound(request.application_url + "/client/" + str(client_id) + "/utilization/" + str(
                    datetime.datetime.now().year))
            if ghost_client is not None:
                return HTTPFound(
                    request.application_url + "/ghost/client/" + str(ghost_client_id) + "/utilization/" + str(
                        datetime.datetime.now().year))

        currentClientId = request.params.get('clientid')
        currentClient = None

        if currentClientId is not None:
            currentClient = DBSession.query(Client).filter_by(id=currentClientId).filter_by(is_active=True).first()

        currentGhostClientId = request.params.get('ghostclientid')
        currentGhostClient = None

        if currentGhostClientId is not None:
            currentGhostClient = DBSession.query(GhostClient).filter_by(id=currentGhostClientId).filter_by(
                is_active=True).first()

        clients_all = DBSession.query(Client).filter_by(account_id=account_id).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
        if len(clients) == 0:
            return HTTPFound(request.application_url)

        #fix to handle disabled
        ghost_users_all = DBSession.query(GhostUser).filter_by(account_id=account_id).all()
        ghost_users = []
        if user.is_administrator or user.permissions_global_utilization:
            ghost_users = ghost_users_all
        else:
            for ghost_user in ghost_users:
                if user.can_access_office(ghost_user.office, "utilization"):
                    ghost_users.append(ghost_user)

        ghost_clients = []
        ghost_clients_all = DBSession.query(GhostClient).filter_by(account_id=account_id).all()
        if user.is_administrator or user.permissions_global_utilization:
            ghost_clients = ghost_clients_all
        else:
            for ghost_client in ghost_clients_all:
                if user.can_access_office(ghost_client.office, "utilization"):
                    ghost_clients.append(ghost_client)

        return dict(logged_in=authenticated_userid(request), header=getHeader(None), clients=clients,
                    ghost_users=ghost_users, user=user, account=account, ghost_clients=ghost_clients,
                    currentClient=currentClient, currentGhostClient=currentGhostClient)
    except:
        print("*****")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Exemplo n.º 50
0
def project_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        project_id = long(request.matchdict['project_id'])
        project = DBSession.query(Project).filter_by(id=project_id).filter_by(
            account_id=account_id).first()

        if project is None or user.can_access_client(project.client,
                                                     "financials") == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":

            name = request.params["name"].lower()
            code = request.params["project_code"]

            client_id = long(request.params["client_id"])
            revenue_local = long(request.params["revenue"])

            if user.currency is None:
                revenue = revenue_local
            else:
                revenue = revenue_local * user.currency.currency_to_usd

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]),
                                       long(start_dateparts[0]),
                                       long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]),
                                     long(end_dateparts[0]),
                                     long(end_dateparts[1]))

            client = DBSession.query(Client).filter_by(
                account_id=account_id).filter_by(id=client_id).first()

            if client is None or user.can_access_client(client,
                                                        "financials") == False:
                return HTTPFound(request.application_url)

            for p in client.projects:
                if p.name == name and p.id != project.id:
                    return HTTPFound(request.application_url)

            matched_departments = []
            for department in account.departments:
                percent_allocation = request.params.get(
                    str(department.id) + "-allocation")
                for budget_allocation in project.budget_allocations:
                    if budget_allocation.department_id == department.id:
                        matched_departments.append(department.id)
                        if percent_allocation is None or percent_allocation == "":
                            DBSession.delete(budget_allocation)
                        else:
                            budget_allocation.percent_allocation = percent_allocation

            for department in account.departments:
                if department.id not in matched_departments:
                    percent_allocation = request.params.get(
                        str(department.id) + "-allocation")
                    if percent_allocation is not None and percent_allocation != "":
                        ba = BudgetAllocation(department, project, None,
                                              int(percent_allocation))
                        DBSession.add(ba)

            project.name = name
            project.code = code
            project.client = client
            project.revenue = revenue
            project.start_date = start_date
            project.end_date = end_date
            DBSession.flush()

            return HTTPFound(request.application_url + "/client/" +
                             str(client_id) + "/projects/" +
                             str(datetime.datetime.now().year))

        matched_departments = []
        for budget_allocation in project.budget_allocations:
            matched_departments.append(budget_allocation.department_id)

        budgetAllocations = project.budget_allocations

        for department in account.departments:
            if department.id not in matched_departments:
                budgetAllocations.append(
                    BudgetAllocation(department, project, None, 0))

        clients_all = DBSession.query(Client).filter_by(
            account_id=account_id).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
        if len(clients) == 0:
            return HTTPFound(request.application_url)
        return dict(logged_in=authenticated_userid(request),
                    header=Header("financials"),
                    clients=clients,
                    user=user,
                    account=account,
                    project=project,
                    budgetAllocations=budgetAllocations)
    except:
        return HTTPFound(request.application_url)
Exemplo n.º 51
0
def administration_expenses_clients(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        account = DBSession.query(Account).filter_by(id=account_id).first()
        user = DBSession.query(User).filter_by(id=user_id).first()
        year = str(datetime.datetime.now().year)
        quarter_end_year_text = None
        if user is None or account is None or not (user.is_administrator or user.permissions_global_financials):
            return HTTPFound(request.application_url)

        if request.method == "POST":

            quarter_end_date_text = request.params.get("quarter_end_type")
            quarter_end_year_text = request.params.get("quarter_end_year")
            quarter_end_date_parts = quarter_end_date_text.split("/")
            quarter_end_date = datetime.date(long(quarter_end_year_text), long(quarter_end_date_parts[0]),
                                             long(quarter_end_date_parts[1]))

            for client in account.clients:
                if request.params.get(str(client.id) + "-expense") is not None and request.params.get(
                                str(client.id) + "-expense") != "":
                    expense_lc = long(request.params.get(str(client.id) + "-expense"))
                else:
                    expense_lc = 0

                if user.currency is None:
                    expense_local = expense_lc
                else:
                    expense_local = expense_lc * user.currency.currency_to_usd

                actual_expense = DBSession.query(ActualExpense).filter_by(client_id=client.id).filter_by(
                    quarter_end_date=quarter_end_date).first()

                if actual_expense is not None:
                    actual_expense.expense_local += expense_local
                else:
                    actual_expense = ActualExpense(None, client, expense_local, None, quarter_end_date)
                    DBSession.add(actual_expense)

            DBSession.flush()

        usd_to_local = 1
        if user.currency is not None:
            usd_to_local = user.currency.usd_to_currency

        if quarter_end_year_text is not None:
            expense_year = int(quarter_end_year_text)
        else:
            expense_year = int(year)

        all_client_expense_sga = []
        for client in account.clients:
            client_expense_sga = [0, 0, 0, 0]

            for actual_expense in client.actual_expenses:
                if actual_expense.quarter_end_date.year == expense_year:

                    if actual_expense.quarter_end_date.month == 3:
                        if actual_expense.expense_local is not None:
                            client_expense_sga[0] = actual_expense.expense_local * usd_to_local

                    elif actual_expense.quarter_end_date.month == 6:
                        if actual_expense.expense_local is not None:
                            client_expense_sga[1] = actual_expense.expense_local * usd_to_local

                    elif actual_expense.quarter_end_date.month == 9:
                        if actual_expense.expense_local is not None:
                            client_expense_sga[2] = actual_expense.expense_local * usd_to_local

                    elif actual_expense.quarter_end_date.month == 12:
                        if actual_expense.expense_local is not None:
                            client_expense_sga[3] = actual_expense.expense_local * usd_to_local

            all_client_expense_sga.append(client_expense_sga)
        return dict(logged_in=authenticated_userid(request), header=Header("administration"), account=account,
                    user=user, year=year, all_client_expense_sga=all_client_expense_sga, expense_year=expense_year)
    except:
        traceback.print_exc()
        return HTTPFound(request.application_url)