예제 #1
0
def edit(user_id, page, current_year, budget_id=None):

    user = Users.get_by_id(user_id)

    if budget_id:
        budget = Budget.get_by_id(budget_id)

        disponible = budget.heure

        prest1 = BudgetPrestation.query(
            BudgetPrestation.budget_id == budget.key
        )

        for pres in prest1:

            if pres.prestation_id.get().sigle == 'FOR':
                formation = pres.heure
            if pres.prestation_id.get().sigle == 'DEV':
                developpement = pres.heure
            if pres.prestation_id.get().sigle == 'ADM':
                administration = pres.heure
            if pres.prestation_id.get().sigle == 'PRO':
                production = pres.heure
    else:
        budget = Budget()

    success = False
    dispo = 0.0
    dispo2 = 0.0

    if request.method == 'POST':

        disponible = request.form['disponible']
        production = request.form['production']
        formation = request.form['formation']
        developpement = request.form['developpement']
        administration = request.form['administration']

        dispo = float(request.form['disponible']) - float(request.form['administration'])
        dispo -= float(request.form['production'])
        dispo -= float(request.form['formation'])
        dispo -= float(request.form['developpement'])
        dispo = round(dispo,1)

        error = False
        if dispo > 0.0:
            error = True
            message = 'La somme des heures de prestation n\'est pas egale aux heures disponibles'
        if dispo < 0.0:
            error = True
            message = 'La somme des heures de prestation est superieure aux heures disponibles '+str(dispo)

        if not error:
            if not budget_id:
                budget.date_start = datetime.date(current_year, 1, 1)
                budget.user_id = user.key

            budget.heure = float(request.form['disponible'])
            bud_id = budget.put()

            prest = Prestation.query(
                Prestation.sigle != None
            )

            for pres in prest:

                presti = BudgetPrestation.query(
                    BudgetPrestation.prestation_id == pres.key,
                    BudgetPrestation.budget_id == bud_id
                ).get()

                if presti:

                    if pres.sigle == 'FOR':
                        presti.heure = float(request.form['formation'])
                    if pres.sigle == 'DEV':
                        presti.heure = float(request.form['developpement'])
                    if pres.sigle == 'ADM':
                        presti.heure = float(request.form['administration'])
                    if pres.sigle == 'PRO':
                        presti.heure = float(request.form['production'])

                    presti.budget_id = bud_id
                    presti.prestation_id = pres.key
                    presti.put()

                else:

                    prestis = BudgetPrestation()

                    if pres.sigle == 'FOR':
                        prestis.heure = float(request.form['formation'])
                    if pres.sigle == 'DEV':
                        prestis.heure = float(request.form['developpement'])
                    if pres.sigle == 'ADM':
                        prestis.heure = float(request.form['administration'])
                    if pres.sigle == 'PRO':
                        prestis.heure = float(request.form['production'])

                    prestis.budget_id = bud_id
                    prestis.prestation_id = pres.key
                    prestis.put()

            flash('Enregistement effectue avec succes', 'success')
            success = True

    return render_template('budget/edit.html', **locals())
예제 #2
0
def edit(user_id, page, current_year, budget_id=None):

    user = Users.objects.get(id=user_id)

    if budget_id:
        budget = Budget.objects.get(id=budget_id)

        disponible = budget.heure

        prest1 = BudgetPrestation.objects(budget_id=budget.id)

        for pres in prest1:

            if pres.prestation_id.sigle == 'FOR':
                formation = pres.heure
            if pres.prestation_id.sigle == 'DEV':
                developpement = pres.heure
            if pres.prestation_id.sigle == 'ADM':
                administration = pres.heure
            if pres.prestation_id.sigle == 'PRO':
                production = pres.heure
    else:
        budget = Budget()

    success = False
    dispo = 0.0
    dispo2 = 0.0

    if request.method == 'POST':

        disponible = request.form['disponible']
        production = request.form['production']
        formation = request.form['formation']
        developpement = request.form['developpement']
        administration = request.form['administration']

        dispo = float(request.form['disponible']) - float(
            request.form['administration'])
        dispo -= float(request.form['production'])
        dispo -= float(request.form['formation'])
        dispo -= float(request.form['developpement'])
        dispo = round(dispo, 1)

        error = False
        if dispo > 0.0:
            error = True
            message = 'La somme des heures de prestation n\'est pas egale aux heures disponibles'
        if dispo < 0.0:
            error = True
            message = 'La somme des heures de prestation est superieure aux heures disponibles ' + str(
                dispo)

        if not error:
            if not budget_id:
                budget.date_start = datetime.date(current_year, 1, 1)
                budget.user_id = user

            budget.heure = float(request.form['disponible'])
            bud_id = budget.save()

            prest = Prestation.objects(sigle__ne=None)

            for pres in prest:

                presti = BudgetPrestation.objects(
                    Q(prestation_id=pres.id) & Q(budget_id=bud_id)).first()

                if presti:

                    if pres.sigle == 'FOR':
                        presti.heure = float(request.form['formation'])
                    if pres.sigle == 'DEV':
                        presti.heure = float(request.form['developpement'])
                    if pres.sigle == 'ADM':
                        presti.heure = float(request.form['administration'])
                    if pres.sigle == 'PRO':
                        presti.heure = float(request.form['production'])

                    presti.budget_id = bud_id
                    presti.prestation_id = pres
                    presti.save()

                else:

                    prestis = BudgetPrestation()

                    if pres.sigle == 'FOR':
                        prestis.heure = float(request.form['formation'])
                    if pres.sigle == 'DEV':
                        prestis.heure = float(request.form['developpement'])
                    if pres.sigle == 'ADM':
                        prestis.heure = float(request.form['administration'])
                    if pres.sigle == 'PRO':
                        prestis.heure = float(request.form['production'])

                    prestis.budget_id = bud_id
                    prestis.prestation_id = pres
                    prestis.save()

            flash('Enregistement effectue avec succes', 'success')
            success = True

    return render_template('budget/edit.html', **locals())
예제 #3
0
def index():
    menu = 'societe'
    submenu = 'budget'
    context = 'collaborateur'
    title_page = 'Parametre - Budget Collaborateur'

    search = False
    q = request.args.get('q')
    if q:
        search = True
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1

    #liste des budgets collaborateurs
    users = Users.query(
        Users.email != '*****@*****.**'
    )

    time_zones = pytz.timezone('Africa/Douala')
    current_year = datetime.datetime.now(time_zones).year
    now_year = datetime.datetime.now(time_zones).year
    # date = datetime.date(date_auto_nows, 1, 1)

    if request.args.get('year') and request.args.get('year') is not None:
        current_year = int(request.args.get('year'))

    #Traitement du formulaire d'affichage de la liste des annees
    years = []
    budget_year = Budget.query()
    for bud in budget_year:
        year = {}
        year['date'] = bud.date_start.year
        years.append(year)

    list_year = []
    for key, group in groupby(years, lambda item: item["date"]):
        if key != now_year:
            list_year.append(key)

    for i in range(now_year, now_year+2):
        if i not in list_year:
            list_year.append(i)

    datas = users
    if users.count() > 10:
        if page == 1:
            offset = 0
        else:
            pages = page
            pages -= 1
            offset = pages * 10
        datas = users.fetch(limit=10, offset=offset)

    # Traitement du tableau des budgets a afficher
    list_budget = []
    for user in datas:
        data = {}
        data['id'] = user.key.id()
        data['full_name'] = user.first_name+" "+user.last_name
        data['taux'] = user.tauxH

        budget = Budget.query(
            Budget.date_start == datetime.date(current_year, 1, 1),
            Budget.user_id == user.key
        ).get()

        data['disponible'] = 0
        data['budget_id'] = None

        data['budget_prestation'] = []

        if budget:
            data['disponible'] = budget.heure
            data['budget_id'] = budget.key.id()

            budget_prest = BudgetPrestation.query(
                BudgetPrestation.budget_id == budget.key
            )

            for prestation in budget_prest:
                data2 = {}
                data2['id'] = prestation.prestation_id.get().key.id()
                data2['prestation'] = prestation.prestation_id.get().libelle
                data2['sigle'] = prestation.prestation_id.get().sigle
                data2['time'] = prestation.heure

                data['budget_prestation'].append(data2)

        list_budget.append(data)

    pagination = Pagination(css_framework='bootstrap3', page=page, total=users.count(), search=search, record_name='Budget')

    return render_template('budget/index.html', **locals())
예제 #4
0
def index():
    menu = 'societe'
    submenu = 'budget'
    context = 'collaborateur'
    title_page = 'Parametre - Budget Collaborateur'

    search = False
    q = request.args.get('q')
    if q:
        search = True
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1

    limit = 10
    offset = ((page - 1) * 10)

    #liste des budgets collaborateurs
    users = Users.objects(
        email__ne='*****@*****.**').skip(offset).limit(limit)
    count = Users.objects(email__ne='*****@*****.**').count()

    time_zones = pytz.timezone('Africa/Douala')
    current_year = datetime.datetime.now(time_zones).year
    now_year = datetime.datetime.now(time_zones).year
    # date = datetime.date(date_auto_nows, 1, 1)

    if request.args.get('year') and request.args.get('year') is not None:
        current_year = int(request.args.get('year'))

    #Traitement du formulaire d'affichage de la liste des annees
    years = []
    budget_year = Budget.objects()
    for bud in budget_year:
        year = {}
        year['date'] = bud.date_start.year
        years.append(year)

    list_year = []
    for key, group in groupby(years, lambda item: item["date"]):
        if key != now_year:
            list_year.append(key)

    for i in range(now_year, now_year + 2):
        if i not in list_year:
            list_year.append(i)

    datas = users

    # Traitement du tableau des budgets a afficher
    list_budget = []
    for user in datas:
        data = {}
        data['id'] = user.id
        data['full_name'] = user.first_name + " " + user.last_name
        data['taux'] = user.tauxH

        budget = Budget.objects(
            Q(date_start=datetime.date(current_year, 1, 1), )
            & Q(user_id=user.id)).first()

        data['disponible'] = 0
        data['budget_id'] = None

        data['budget_prestation'] = []

        if budget:
            data['disponible'] = budget.heure
            data['budget_id'] = budget.id

            budget_prest = BudgetPrestation.objects(budget_id=budget.id)

            for prestation in budget_prest:
                data2 = {}
                data2['id'] = prestation.prestation_id.id
                data2['prestation'] = prestation.prestation_id.libelle
                data2['sigle'] = prestation.prestation_id.sigle
                data2['time'] = prestation.heure

                data['budget_prestation'].append(data2)

        list_budget.append(data)

    pagination = Pagination(css_framework='bootstrap3',
                            page=page,
                            total=count,
                            search=search,
                            record_name='Budget')

    return render_template('budget/index.html', **locals())