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 CiviMember (Moderator: Deepak Srivastava) »
  • automated way of moving new memberships from the individual to the organization
Pages: [1]

Author Topic: automated way of moving new memberships from the individual to the organization  (Read 1269 times)

tmcnulty1982

  • Guest
automated way of moving new memberships from the individual to the organization
September 26, 2008, 02:06:59 pm
Our client has some online applications setup through contribution pages.  They have a "corporate" membership that users can sign up for.  The application works great, but the membership ends up on the individual contact instead of the organization.  I created some SQL that moves the membership from the individual to the organization contact, if it would be useful to anyone else (comments also welcome).  This has been tested (a little) with CiviCRM 2.0.6.

Code: [Select]
CREATE VIEW civicrm_membership_mismatches AS
SELECT DISTINCT
  m.id AS membership_id,
  t.name AS membership_type,
  indivc.id AS indiv_id,
  indivc.contact_type AS indiv_type,
  indivc.display_name AS indiv_name,
  corpc.id AS corp_id,
  corpc.contact_type AS corp_type,
  corpc.display_name AS corp_name
FROM civicrm_membership m
JOIN civicrm_contact indivc
  ON (indivc.id = m.contact_id)
JOIN civicrm_membership_type t
  ON (t.id = m.membership_type_id)
JOIN civicrm_relationship r
  ON (r.contact_id_a = m.contact_id)
JOIN civicrm_contact corpc
  ON (corpc.id = r.contact_id_b)
WHERE t.name IN ('Corporate', 'Silver Exemplary Corporate')
ORDER BY indiv_id;

UPDATE civicrm_membership m, civicrm_membership_mismatches ms SET m.contact_id=ms.corp_id WHERE m.id = ms.membership_id;

I also created a little drupal module to run the UPDATE statement when cron.php is loaded, but you could run it from anywhere.  This isn't heavily tested so I don't want to make it TOO easy for everyone to try this.  :)
« Last Edit: September 26, 2008, 02:43:29 pm by tmcnulty1982 »

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: automated way of moving new memberships from the individual to the organization
September 26, 2008, 02:14:02 pm
Tobias - Thx for sharing this.

On a related note, you might want to check out the new 2.1 feature of allowing individuals to signup for membership "on behalf of an organization" - this might work nicely for the client going forward.

http://issues.civicrm.org/jira/browse/CRM-2964
Protect your investment in CiviCRM by  becoming a Member!

tmcnulty1982

  • Guest
Re: automated way of moving new memberships from the individual to the organization
September 26, 2008, 02:42:34 pm
Looks cool, but we have too many Drupal 5 dependent modules to upgrade to 6 just yet!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • automated way of moving new memberships from the individual to the organization

This forum was archived on 2017-11-26.