def budget_weekly_planner(caption,period, plan, clasfctn2, fact,budget): mtitle="{0} {1}".format(period.start.strftime("%B"),period.start.year) table=Table(mtitle) #self._normal_magn=0 table[0,0]=mtitle #название месяца для которого делается отчет table._normal_magn=100 table.define_style("totals", foreground_color=Color.Red) table.define_style("weekcaptions", bold=True, font_size=10) table.define_style("categoryline", bold=True, background_color=Color.LightGreen) table.define_style("categoryline_totals", italic=True,background_color=Color.LightGreen, formatting_style=Style.Money) table.define_style("item_plan",background_color=Color.LightGray, formatting_style=Style.Money) table.define_style("item_plan_overdue",background_color=Color.Red,foreground_color=Color.White, formatting_style=Style.Money) table.define_style("percent_green",foreground_color=Color.Green, formatting_style=Style.Percent) table.define_style("percent_red",foreground_color=Color.Red, formatting_style=Style.Percent) table.define_style("accum",bold=True, formatting_style=Style.Money) table.define_style("item_fact", formatting_style=Style.Money) clasfctn=copy.deepcopy(clasfctn2) t=period.start weeks=[] w=WeekDef(t) weeks.append(w) #находим первый и последний день недели while t<period.end: w.lastday=t if t.weekday()==6: #это воскресенье #ечли это последний день месяца, то не создаем новую неделю firstDayOfNextWeek=t+timedelta(days=1) if firstDayOfNextWeek<period.end: i=w.windex w=WeekDef(firstDayOfNextWeek) w.windex=i+1 weeks.append(w) t+=timedelta(days=1) #заголовки колонок недель rowi=1 coli=3 now=datetime.now() for w in weeks: w.coli=coli spast="[p]" if w.startday<now: spast="" if now>=w.startday and now<=w.lastday:spast="[c]" sdays="{0}-{1}".format(w.startday.day,w.lastday.day) table[rowi,coli]=u"{0}{1}".format(sdays,spast), "weekcaptions" coli+=2 budget_weekly_planner_preprocessrows(plan,clasfctn,period,weeks,False) budget_weekly_planner_preprocessrows(fact,clasfctn,period,weeks, True) now=datetime.now() duedate=now if now>period.end: duedate=period.end if now<period.start: duedate=period.start #вывод массива данных overspendingReport={} lastrowi,outputedrecords=budget_weekly_planner_cat(table,clasfctn._root,7, period,plan,weeks,budget,duedate,overspendingReport) plan_total=0 fact_total=0 prediction_total=0 for w in weeks: table[3,w.coli]=u"План" table[3,w.coli+1]=w.plan_total, Style.Money table[4,w.coli]=u"Факт" table[4,w.coli+1]=w.fact_total, Style.Money plan_total+=w.plan_total fact_total+=w.fact_total prediction_total+=w.predict_total table.set_column_width(w.coli, 10) table.set_column_width(w.coli+1, 5) table.set_column_width(w.coli+2, 10) table.set_column_width(w.coli+3, 5) coli=0 table[3,coli]=u"План" table[3,coli+1]=u"Факт" table[3,coli+2]=u"Предикт" table[4,coli]=plan_total, Style.Money table[4,coli+1]=fact_total, Style.Money table[4,coli+2]=prediction_total, Style.Money over=prediction_total/plan_total if over>1: table[5,coli+2]=over,"percent_red" else: table[5,coli+2]=over, "percent_green" table.set_column_width(0, 6) table.set_column_width(1, 6) table.set_column_width(2, 6) todorow=lastrowi+0-5 table[todorow,0]=u"Просроченные бюджетные цели","weekcaptions" bt_row=1 sum=0 for budget_item in budget.get_buying_targets(): is_overdue, is_executed, is_todo=budget.check_item_execution(budget_item,duedate) if is_overdue: table[todorow+bt_row,1]="", Style.Month descr=budget_item.description if hasattr(budget_item,"_description"): descr= budget_item._description table[todorow+bt_row,3]=u"{0}".format(descr) table[todorow+bt_row,6]=budget_item.debit, Style.Money sum+=budget_item.debit bt_row+=1 table[todorow,6]=sum, Style.Money lastrowi=todorow bt_row=1 sum=0 table[lastrowi,7]=u"Бюджетные цели в ближайшие 30 дней","weekcaptions" for budget_item in budget.get_buying_targets(): is_overdue, is_executed, is_todo=budget.check_item_execution(budget_item,duedate) if is_todo: if budget_item.exactdate<period.end: table[lastrowi+bt_row,8]=budget_item.exactdate, Style.Month table[lastrowi+bt_row,9]=u"{0}".format(budget_item.description) table[lastrowi+bt_row,12]=budget_item.debit, Style.Money sum+=budget_item.debit bt_row+=1 #table[lastrowi,7]=u"Бюджетные цели ({0})".format(sum) table[lastrowi,12]=sum, Style.Money bt_row=lastrowi+3 table[bt_row,0]=u"Отчет по перерасходу","weekcaptions" overspending_sum=0 #overspendingReport=OrderedDict(overspendingReport) overspendingReport=OrderedDict(sorted(overspendingReport.items(), key=lambda t: t[1], reverse=True)) for k, v in overspendingReport.items(): if v>0: bt_row+=1 table[bt_row,3]=k table[bt_row,6]=v, Style.Money overspending_sum+=v table[bt_row+2,3]=u"Итого:" table[bt_row+2,6]=overspending_sum, Style.Money return table