Example #1
0
 def month_balance(self, id):                
     orders = meta.Session.query(func.month(Order.created_at).label('month'), 
                                 func.day(Order.created_at).label('day'), 
                                 func.sum(Order.real_value - TransportOrder.real_value).label('value')) \
                  .join(Order.transport_order) \
                  .group_by( func.month(Order.created_at), func.day(Order.created_at)) \
                  .filter(and_(Order.idCreator == id, Order.created_at.between(h.today(31), h.today()))) \
                  .all()
     
     chart = open_flash_chart()
     t = title(text='Zestawienie')
     
     b = bar()        
     b.values = [order.value for order in orders]               
     
     lbl = labels(labels = [str(order.month) + ' ' + str(order.day) for order in orders])
     
     x = x_axis()
     x.labels = lbl
     
     y = y_axis()        
     y.min, y.max= 0, max(b.values or [0])         
     
     chart.title = t        
     chart.y_axis = y
     chart.x_axis = x
     chart.add_element(b)        
     
     return chart.render()
Example #2
0
 def company_balance(self, id):
     orders = meta.Session.query(func.year(Order.created_at).label('year'), 
                                 func.month(Order.created_at).label('month'), 
                                 func.sum(Order.real_value).label('value')) \
                  .join(Order.transport_order) \
                  .filter(and_(Order.idCompany == id, Order.created_at.between(h.today(365), h.today()))) \
                  .group_by( func.year(Order.created_at), func.month(Order.created_at)) \
                  .all()
     
     profits = meta.Session.query(func.year(Order.created_at).label('year'), 
                                 func.month(Order.created_at).label('month'), 
                                 func.sum(Order.real_value - TransportOrder.real_value).label('value')) \
                  .join(Order.transport_order) \
                  .filter(and_(Order.idCompany == id, Order.created_at.between(h.today(365), h.today()))) \
                  .group_by( func.year(Order.created_at), func.month(Order.created_at)) \
                  .all()
     
     chart = open_flash_chart()
     t = title(text='Zestawienie')
     
     b = bar()        
     b.values = [order.value for order in orders]               
     
     b2 = bar()        
     b2.values = [order.value for order in profits]
     b2.colour = '#56acde'
     
     lbl = labels(labels = [str(order.year) + ' ' + str(order.month) for order in orders])
     
     x = x_axis()
     x.labels = lbl
     
     y = y_axis()
     y.min, y.max= 0, max(b.values or [0])
     y.labels = None
     y.offset = False
     
     chart.title = t        
     chart.y_axis = y
     chart.x_axis = x
     chart.add_element(b)
     chart.add_element(b2)         
     
     return chart.render()