Beispiel #1
0
def monthCalc(request):
    req = request.REQUEST
    if param_exist("date",req):
        date = DateService.parse(req['date'])
    else:
        date = DateService.today()

    fromDate = DateService.firstDateOfMonth(date)
    toDate = DateService.lastDateOfMonth(date)
    
    q = Expense.objects.extra(select={'sum': 'sum(amount)'}).values('sum','date')
    #q = Expense.objects.filter(date__gte=fromDate, date__lte=toDate)
    q = q.filter(date__gte=fromDate, date__lte=toDate).order_by('date')
    if param_exist("subC",req):
        q = q.filter(subCategory=req['subC'])
    elif param_exist("cat",req):
        c = SubCategory.objects.filter(category=req['cat'])
        q = q.filter(subCategory__in=c)
    if param_exist("payT",req):
        q = q.filter(paymentType=req['payT'])
    q.query.group_by = ['date']
    
    list = []
    for exp in q:
        list.append('[%d,%s]' % (int(DateService.toLong(exp['date'])),exp['sum']))
    
    data = "[" + ",".join(list) + "]"
    return data
Beispiel #2
0
def stats(request):
    req = request.REQUEST
    toDate = DateService.today()
    fromDate = datetime.date(toDate.tm_year, toDate.tm_mon, 1)
    fromDate = DateService.addMonth(fromDate,-12)
    toDate = datetime.date(toDate.tm_year, toDate.tm_mon, 1)
    
    q = Income.objects.values('period').annotate(sum=Sum('amount'))
    q = q.filter(period__gte=fromDate, period__lte=toDate).order_by('period')
    
#    q = Income.objects.extra(select={'sum': 'sum(amount)'}).values('sum','period')
#    q = q.filter(period__gte=fromDate, period__lte=toDate).order_by('period')
#    q.query.group_by = ['period']
        
    #q = Income.objects.filter(period__gte=fromDate, period__lte=toDate).order_by('period')
    
    list = []
    for exp in q:
        #list.append('[%d,%s]' % (int(DateService.toLong(exp.period)),exp.amount))
        list.append('[%d,%s]' % (int(DateService.toLong(exp['period'])),exp['sum']))
        
    data = "[" + ",".join(list) + "]"
    return data