Class: Osm::GiftAid::Data

Inherits:
Model
  • Object
show all
Defined in:
lib/osm/giftaid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i

Instance Attribute Details

#donationsDirtyHashy

Returns The data for each payment - keys are the date, values are the value of the payment.

Returns:

  • (DirtyHashy)

    The data for each payment - keys are the date, values are the value of the payment


184
# File 'lib/osm/giftaid.rb', line 184

attribute :member_id, :type => Integer

#first_nameString

Returns The member's first name.

Returns:

  • (String)

    The member's first name


184
# File 'lib/osm/giftaid.rb', line 184

attribute :member_id, :type => Integer

#grouping_idFixnum

Returns The OSM ID for the member's grouping.

Returns:

  • (Fixnum)

    The OSM ID for the member's grouping


184
# File 'lib/osm/giftaid.rb', line 184

attribute :member_id, :type => Integer

#last_nameString

Returns The member's last name.

Returns:

  • (String)

    The member's last name


184
# File 'lib/osm/giftaid.rb', line 184

attribute :member_id, :type => Integer

#member_idFixnum

Returns The OSM ID for the member.

Returns:

  • (Fixnum)

    The OSM ID for the member


184
# File 'lib/osm/giftaid.rb', line 184

attribute :member_id, :type => Integer

#section_idFixnum

Returns The OSM ID for the member's section.

Returns:

  • (Fixnum)

    The OSM ID for the member's section


184
# File 'lib/osm/giftaid.rb', line 184

attribute :member_id, :type => Integer

#tax_payer_addressString

Returns The tax payer's street address.

Returns:

  • (String)

    The tax payer's street address


184
# File 'lib/osm/giftaid.rb', line 184

attribute :member_id, :type => Integer

#tax_payer_nameString

Returns The tax payer's name.

Returns:

  • (String)

    The tax payer's name


184
# File 'lib/osm/giftaid.rb', line 184

attribute :member_id, :type => Integer

#tax_payer_postcodeString

Returns The tax payer's postcode.

Returns:

  • (String)

    The tax payer's postcode


184
# File 'lib/osm/giftaid.rb', line 184

attribute :member_id, :type => Integer

#totalString

Returns Total.

Returns:

  • (String)

    Total


184
# File 'lib/osm/giftaid.rb', line 184

attribute :member_id, :type => Integer

Instance Method Details

#<=>(another) ⇒ Object

Compare Data based on section_id, grouping_id, last_name then first_name


284
285
286
287
288
289
290
# File 'lib/osm/giftaid.rb', line 284

def <=>(another)
  result = self.section_id <=> another.try(:section_id)
  result = self.grouping_id <=> another.try(:grouping_id) if result == 0
  result = self.last_name <=> another.try(:last_name) if result == 0
  result = self.first_name <=> another.try(:last_name) if result == 0
  return result
end

#update(api) ⇒ Boolean

Update data in OSM

Parameters:

  • api (Osm::Api)

    The api to use to make the request

Returns:

  • (Boolean)

    whether the data was updated in OSM

Raises:


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/osm/giftaid.rb', line 225

def update(api)
  raise Osm::ObjectIsInvalid, 'data is invalid' unless valid?
  require_ability_to(api, :write, :finance, section_id)
  term_id = Osm::Term.get_current_term_for_section(api, section_id).id

  updated = true
  fields = [
    ['tax_payer_name', 'parentname', tax_payer_name],
    ['tax_payer_address', 'address', tax_payer_address],
    ['tax_payer_postcode', 'postcode', tax_payer_postcode],
  ]
  fields.each do |field|
    if changed_attributes.include?(field[0])
      result = api.perform_query("giftaid.php?action=updateScout", {
        'scoutid' => member_id,
        'termid' => term_id,
        'column' => field[1],
        'value' => field[2],
        'sectionid' => section_id,
        'row' => 0,
      })
      if result.is_a?(Hash)
        (result['items'] || []).each do |i|
          if i['scoutid'] == member_id.to_s
            updated = false unless i[field[1]] == field[2]
          end
        end
      end
    end
  end
  reset_changed_attributes if updated

  donations.changes.each do |date, (was,now)|
    date = date.strftime(Osm::OSM_DATE_FORMAT)
    result = api.perform_query("giftaid.php?action=updateScout", {
      'scoutid' => member_id,
      'termid' => term_id,
      'column' => date,
      'value' => now,
      'sectionid' => section_id,
      'row' => 0,
    })
    if result.is_a?(Hash)
      (result['items'] || []).each do |i|
        if i['scoutid'] == member_id.to_s
          updated = false unless i[date] == now
        end
      end
    end
  end
  donations.clean_up! if updated

  Osm::Model.cache_delete(api, ['gift_aid_data', section_id, term_id]) if updated

  return updated
end