'Method to bulk-update status of allowance payments
@param r: the S3Request instance
@param attr: controller parameters'

def bulk_update_status(self, r, **attr):

    T = current.T
    s3db = current.s3db
    settings = current.deployment_settings
    response = current.response
    output = {'title': T('Update    Allowance    Status')}
    status_opts = dict(s3db.dvr_allowance_status_opts)
    del status_opts[2]
    formfields = [s3_date('from_date', label=T('Planned    From'), set_min='#allowance_to_date'), s3_date('to_date', default='now', label=T('Planned    Until'), set_max='#allowance_from_date', empty=False), Field('current_status', 'integer', default=1, label=T('Current    Status'), requires=IS_IN_SET(status_opts)), Field('new_status', 'integer', default=4, label=T('New    Status'), requires=IS_IN_SET(status_opts))]
    submit_btn = INPUT(_class='tiny    primary    button', _name='submit', _type='submit', _value=T('Update'))
    cancel_btn = A(T('Cancel'), _href=r.url(id=None, method=''), _class='action-lnk')
    buttons = [submit_btn, cancel_btn]
    resourcename = r.resource.name
    formstyle = settings.get_ui_formstyle()
    form = SQLFORM.factory(record=None, showid=False, formstyle=formstyle, table_name=resourcename, buttons=buttons, *formfields)
    output['form'] = form
    formname = ('%s/manage' % resourcename)
    if form.accepts(r.post_vars, current.session, formname=formname, onvalidation=self.validate, keepvalues=False, hideerror=False):
        formvars = form.vars
        current_status = formvars.current_status
        new_status = formvars.new_status
        table = s3db.dvr_allowance
        query = ((current.auth.s3_accessible_query('update', table) & (table.status == current_status)) & (table.deleted != True))
        from_date = formvars.from_date
        if from_date:
            query &= (table.date >= from_date)
        to_date = formvars.to_date
        if to_date:
            query &= (table.date <= to_date)
        result = current.db(query).update(status=int(new_status))
        if result:
            response.confirmation = (T('%(number)s    records    updated') % {'number': result})
        else:
            response.warning = T('No    records    found')
    response.view = self._view(r, 'update.html')
    return output
