Пример #1
0
def client_edit():

    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1

    if request.form['year']:

        clients = Client.objects.paginate(page=page, per_page=10)

        for client in clients:
            budget = ClientBudget.objects(
                Q(client_id=client.id) & Q(date_app=function.datetime_convert(
                    datetime.date(int(request.form['year']), 1, 1)))).first()

            clef = 'name[' + str(client.id) + ']'

            if budget:
                if float(request.form[clef]) > 0:
                    budget.montant = float(request.form[clef])
                    budget.save()
                else:
                    budget.delete()
            else:
                budget_new = ClientBudget()
                if float(request.form[clef]) > 0:
                    budget_new.montant = float(request.form[clef])
                else:
                    budget_new.montant = float(0)
                budget_new.date_app = function.datetime_convert(
                    datetime.date(int(request.form['year']), 1, 1))
                budget_new.client_id = client.id
                budget_new.save()

        flash('Enregistrement effectue avec succes', 'success')

    return redirect(
        url_for('budget.client', page=page, year=request.form['year']))
Пример #2
0
def client():
    menu = 'societe'
    submenu = 'budget'
    context = 'client'
    title_page = 'Parametre - Budget Previsionnel Client'

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

    time_zones = pytz.timezone('Africa/Douala')
    current_year = datetime.datetime.now(time_zones).year
    now_year = datetime.datetime.now(time_zones).year

    if 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 = []
    charge_year = ClientBudget.objects()
    for bud in charge_year:
        year = {}
        year['date'] = bud.date_app.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)

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

    datas = Client.objects(prospect=False).skip(offset).limit(limit)
    count = Client.objects(prospect=False).count()

    data_fecth = datas

    # Traitement du tableau des charges a afficher
    list_charge = []
    for client in data_fecth:
        data = {}
        data['id'] = client.id
        data['name'] = client.name

        charg = ClientBudget.objects(
            Q(date_app=datetime.date(current_year, 1, 1))
            & Q(client_id=client.id)).first()

        data['montant'] = 0

        if charg:
            data['montant'] = charg.montant

        list_charge.append(data)

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

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