'Helper function to register payments
@param person_id: the person record ID
@param payments: the payments as sent from form
@param date: the payment date (default utcnow)
@param comments: comments for the payments
@return: tuple (updated, failed), number of records'

def register_payments(self, person_id, payments, date=None, comments=None):

    if isinstance(payments, basestring):
        try:
            payments = json.loads(payments)
        except (ValueError, TypeError):
            payments = []
    if (not date):
        date = current.request.utcnow
    data = {'status': 2, 'paid_on': date}
    if comments:
        data['comments'] = comments
    atable = current.s3db.dvr_allowance
    updated = 0
    failed = 0
    r = S3Request('dvr', 'allowance', current.request, args=[], get_vars={})
    r.customise_resource('dvr_allowance')
    onaccept = current.s3db.onaccept
    db = current.db
    accessible = current.auth.s3_accessible_query('update', atable)
    for payment in payments:
        record_id = payment.get('r')
        query = ((((accessible & (atable.id == record_id)) & (atable.person_id == person_id)) & (atable.status != 2)) & (atable.deleted != True))
        success = db(query).update(**data)
        if success:
            record = {'id': record_id, 'person_id': person_id}
            record.update(data)
            onaccept(atable, record, method='update')
            updated += 1
        else:
            failed += 1
    return (updated, failed)
