Beispiel #1
0
def list(request):
    req = request.REQUEST
    
    # find close date
    
    dateQuery = CardDates.objects.filter(closeDate__gt=DateService.todayDate())
    dateQuery = dateQuery.order_by('closeDate')
    if dateQuery.count()>0:
        dt = dateQuery[:1][0]
    else:
        dt = CardDates(closeDate=DateService.todayDate(), expireDate=DateService.todayDate())
    
    q = CardData.objects.extra(where=["ADDDATE(date, INTERVAL ((instalments+1) * 30) DAY) > '%s'" % DateService.invert(dt.closeDate)])
    if param_exist("sort",req):
        q = q.order_by(sortMethod(req))
    if param_exist("limit",req):
        start = req['start']
        limit = req['limit']
        list = q[start:start+limit]
    else:
        list = q

    res = []
    for exp in list:
        rem = FinancialService.remainInstalments(exp.date, dt.closeDate, exp.instalments)
        if rem >= 0:
            res.append({'id': exp.id, 'date': exp.date,
                            'shop': exp.shop, 'instalments': exp.instalments,
                            'card_id': exp.card.id, 'card_name': exp.card.name,
                            'total': exp.total, 'own': exp.own,
                            'partial': exp.total / exp.instalments,
                            'remain': rem })
    
    data = '{"total": %s,"close": "%s", "expire": "%s", "rows": %s}' % (CardData.objects.count(), DateService.format(dt.closeDate),DateService.format(dt.expireDate), JsonParser.parse(res))
    return data
Beispiel #2
0
def pay(request):
    req = request.REQUEST
    e = Tax.objects.get(pk=req['id'])
    if e:
        if param_exist("nextExpire",req):
            e.expire = DateService.invert(req['nextExpire'])
        else:
            e.expire = e.nextExpire
        if param_exist("nextExpire2",req):
            e.nextExpire = DateService.invert(req['nextExpire2'])
        else:
            e.nextExpire = None
        e.amount = req['amount']
        e.lastPay = DateService.todayDate()
        if e.account=="":
            service = e.service
        else:
            service = "%s (%s)" % (e.service, e.account)
        expense = Expense(date=DateService.todayDate(), text=service, amount=e.amount, subCategory=e.subCategory, paymentType=e.paymentType)
        
        data = '{"success":true}'
        
        safe = True
        try:
            e.save()
        except _mysql_exceptions.Warning:
            pass
        except Exception, e1:
            safe = False
            transaction.rollback()
            data = '{"success":false, "msg": "%s"}' % (e1.args)
        
        if safe:
            try:
                expense.save()
                transaction.commit()
            except _mysql_exceptions.Warning:
                transaction.commit()
            except Exception, e2:
                safe = False
                transaction.rollback()
                data = '{"success":false, "msg": "%s"}' % (e2.args)