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

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

    if request.form['year']:

        if page == 1:
            offset = 0
        else:
            pages = page
            pages -= 1
            offset = pages * 10

        clients = Client.query().fetch(limit=10, offset=offset)

        for client in clients:
            budget = ClientBudget.query(
                ClientBudget.client_id == client.key,
                ClientBudget.date_app == function.date_convert(datetime.date(int(request.form['year']), 1, 1))
            ).get()

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

            if budget:
                if float(request.form[clef]) > 0:
                    budget.montant = float(request.form[clef])
                    budget.put()
                else:
                    budget.key.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.date_convert(datetime.date(int(request.form['year']), 1, 1))
                budget_new.client_id = client.key
                budget_new.put()

        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.query()
    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)

    datas = Client.query(
        Client.prospect == False
    )

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

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

        charg = ClientBudget.query(
            ClientBudget.date_app == datetime.date(current_year, 1, 1),
            ClientBudget.client_id == client.key
        ).get()

        data['montant'] = 0

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

        list_charge.append(data)


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

    return render_template('budget/client.html', **locals())
Пример #3
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())