def charge_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 charges = Charge.query().fetch(limit=10, offset=offset) for char in charges: budget = ChargeBudget.query( ChargeBudget.charge_id == char.key, ChargeBudget.date_app == function.date_convert(datetime.date(int(request.form['year']), 1, 1)) ).get() clef = 'name['+str(char.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 = ChargeBudget() 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.charge_id = char.key budget_new.put() flash('Enregistrement effectue avec succes', 'success') return redirect(url_for('budget.charge', page=page, year=str(request.form['year'])))
def charge(): menu = 'societe' submenu = 'budget' context = 'charge' title_page = 'Parametre - Budget Charge/Impot' 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 = ChargeBudget.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 = Charge.query() # Traitement du tableau des charges a afficher list_charge = [] 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) for charge in data_fecth: data = {} data['id'] = charge.key.id() data['name'] = charge.libelle charg = ChargeBudget.query( ChargeBudget.date_app == datetime.date(current_year, 1, 1), ChargeBudget.charge_id == charge.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='Charges') return render_template('budget/charge.html', **locals())
def charge(): menu = 'societe' submenu = 'budget' context = 'charge' title_page = 'Parametre - Budget Charge/Impot' 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 = ChargeBudget.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 = 10 offset = ((page - 1) * 10) #liste des budgets collaborateurs datas = Charge.objects().skip(offset).limit(limit) count = Charge.objects().count() # Traitement du tableau des charges a afficher list_charge = [] data_fecth = datas for charge in data_fecth: data = {} data['id'] = charge.id data['name'] = charge.libelle charg = ChargeBudget.objects( Q(date_app=datetime.date(current_year, 1, 1)) & Q(charge_id=charge.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='Charges') return render_template('budget/charge.html', **locals())