if checkPayment(l,amount,prevAmount):
        if prevAmount:
            diff = float(prevAmount) - float(amount)
            l.remain = unicode(float(l.remain) + diff)
        else:
            l.remain = unicode(float(l.remain) - float(amount))

        p.amount=amount
        p.date=DateService.parseDate(req['date'])
        
        try:
            l.save()
        except _mysql_exceptions.Warning:
            pass        
        try:
            p.save()
        except _mysql_exceptions.Warning:
            pass        
        except Exception, e1:
            data = '{"success":false, "msg": "%s"}' % (e1.args)
    else:
        data = '{"success":false, "msg": "%s"}' % (_('The entered amount is greater than the amount owed.'))
    return data
        
def getPaymentRemain(loan):
# cursors are not supported in appengine 
#    cursor = connection.cursor()
#    cursor.execute("SELECT sum(amount) as sum FROM payment WHERE loan_id = %s", [loan.pk])
#    row = cursor.fetchone()
#    resto = float(loan.amount)
#    if row[0]!=None: