CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • Donation Amount doubled in recent imports
Pages: [1]

Author Topic: Donation Amount doubled in recent imports  (Read 813 times)

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Donation Amount doubled in recent imports
January 06, 2012, 07:14:07 am
I'm using API v3 to import donations and the reports (like "Donor Report (Detail)") are showing these imported donations as double their actual value (e.g, $100 when the donation was $50).  Clicking on the amount (to open the actual contribution record) shows the correct amount (a $50 contribution).  Also, if I add a "Net Amount" column, the net amount displays the correct amount ($50).

Comparing with older civicrm_contribution table records (that don't display a doubled value) they look the same (e.g, total_amount = net_amount = 50.00).

From what I can see, CRM/Report/Form/Contribute/Detail.php gets total_amount from CRM_Contribute_DAO_Contribution which gets it from cicirm_contribution.total_amount (as I would expect).  But it is appearing in the report as double the value recorded in the table - and only in more recent records.  (I know I'm repeating myself, but this is driving me nuts.)

Any ideas of where else I should be looking will be gratefully accepted.

Oh, and Happy New Year!

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: Donation Amount doubled in recent imports
January 09, 2012, 07:57:46 am
smartyDebug=1 is showing me for a recent record (where total_amount = net_amount = 50.00):
Code: [Select]
civicrm_contribution_net_amount => "50.00"
 civicrm_contribution_total_amount_sum => "100.00"
...but for an older record (again, where total_amount = net_amount = 50.00):
Code: [Select]
civicrm_contribution_net_amount => "50.00"
 civicrm_contribution_total_amount_sum => "50.00"
...so where is this 'civicrm_contribution_total_amount_sum' is being computed (and why is it working differently on newly imported records than on older records)?

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: Donation Amount doubled in recent imports
January 09, 2012, 06:21:07 pm
OK, figured it out: on import using API v3 where $params does not contain the key 'is_primary':
Code: [Select]
$result = civicrm_api("Address","create", $address_params);creates an address with 'is_primary' set *even* if there is already an address with is_primary set.  (I am using CiviCRM v3.4.8 on Drupal 6.22)  Once I discovered this I found a slew of related posts and tickets:

The multiple is_primary issue is discussed in http://issues.civicrm.org/jira/browse/CRM-8689 and http://forum.civicrm.org/index.php/topic,11659.msg50019.html (http://forum.civicrm.org/index.php/topic,21238.0.html and http://issues.civicrm.org/jira/browse/CRM-8740 appear to be related, too).

I'm not quite sure what the answer should be to this.  I can use the SQL in the forum post above (also referenced in http://forum.civicrm.org/index.php/topic,21238.0.html) to clean up the database (yea!) but how should I handle creating new addresses in the future?  If an imported contact matches an existing contact that already has (say) a home address set, and if the imported contact has a different home address, should I update the old home address with the new one?  This makes sense except for those wealthy enough to have more than one home address, in which case multiple home addresses make sense, but only one would have 'is_primary' set.

So I'm going to go with that concept: for each location type, there can be only one (exactly one?) 'is_primary'

Update: There can be multiple address records of a particular location type, but only one is_primary address record

And it appears this concept should hold for email and phone, too.

So after running the SQL to set exactly one is_primary for every address, phone and email, my API v3-based import script will need to be updated to:
  • check for an existing address (phone, email) of that location type
  • if one exists, check for a match (if match, done; else...)
  • update "Other" address (phone, email) from the found address (saveing last replaced location data)
  • create new primary address (phone, email) location

I guess I could delete the old Other address if it exists and change the old Home address type to Other.  (I am only importing Home and Shipping addresses, so Other will be available.)

But this whole process seems messy. Is there a better way?

Update: see http://forum.civicrm.org/index.php/topic,22366.msg96323.html#msg96323
« Last Edit: January 09, 2012, 10:03:40 pm by fen »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • Donation Amount doubled in recent imports

This forum was archived on 2017-11-26.