Class: Osm::GiftAid::Data
Constant Summary collapse
- SORT_BY =
[:section_id, :grouping_id, :last_name, :first_name]
Instance Attribute Summary collapse
-
#donations ⇒ DirtyHashy
The data for each payment - keys are the date, values are the value of the payment.
-
#first_name ⇒ String
The member’s first name.
-
#grouping_id ⇒ Fixnum
The OSM ID for the member’s grouping.
-
#last_name ⇒ String
The member’s last name.
-
#member_id ⇒ Fixnum
The OSM ID for the member.
-
#section_id ⇒ Fixnum
The OSM ID for the member’s section.
-
#tax_payer_address ⇒ String
The tax payer’s street address.
-
#tax_payer_name ⇒ String
The tax payer’s name.
-
#tax_payer_postcode ⇒ String
The tax payer’s postcode.
-
#total ⇒ String
Total.
Instance Method Summary collapse
-
#update(api) ⇒ Boolean
Update data in OSM.
Methods inherited from Model
#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Instance Attribute Details
#donations ⇒ DirtyHashy
Returns The data for each payment - keys are the date, values are the value of the payment.
183 |
# File 'lib/osm/giftaid.rb', line 183 attribute :member_id, :type => Integer |
#first_name ⇒ String
Returns The member’s first name.
183 |
# File 'lib/osm/giftaid.rb', line 183 attribute :member_id, :type => Integer |
#grouping_id ⇒ Fixnum
Returns The OSM ID for the member’s grouping.
183 |
# File 'lib/osm/giftaid.rb', line 183 attribute :member_id, :type => Integer |
#last_name ⇒ String
Returns The member’s last name.
183 |
# File 'lib/osm/giftaid.rb', line 183 attribute :member_id, :type => Integer |
#member_id ⇒ Fixnum
Returns The OSM ID for the member.
183 |
# File 'lib/osm/giftaid.rb', line 183 attribute :member_id, :type => Integer |
#section_id ⇒ Fixnum
Returns The OSM ID for the member’s section.
183 |
# File 'lib/osm/giftaid.rb', line 183 attribute :member_id, :type => Integer |
#tax_payer_address ⇒ String
Returns The tax payer’s street address.
183 |
# File 'lib/osm/giftaid.rb', line 183 attribute :member_id, :type => Integer |
#tax_payer_name ⇒ String
Returns The tax payer’s name.
183 |
# File 'lib/osm/giftaid.rb', line 183 attribute :member_id, :type => Integer |
#tax_payer_postcode ⇒ String
Returns The tax payer’s postcode.
183 |
# File 'lib/osm/giftaid.rb', line 183 attribute :member_id, :type => Integer |
#total ⇒ String
Returns Total.
183 |
# File 'lib/osm/giftaid.rb', line 183 attribute :member_id, :type => Integer |
Instance Method Details
#update(api) ⇒ Boolean
Update data in OSM
224 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 |
# File 'lib/osm/giftaid.rb', line 224 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 |