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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Insert Multiple Records on One Contribution
Pages: [1]

Author Topic: Insert Multiple Records on One Contribution  (Read 3979 times)

rs3515

  • I’m new here
  • *
  • Posts: 29
  • Karma: 1
Insert Multiple Records on One Contribution
June 01, 2008, 02:52:24 am
CiviContribute allows one contribution page for each program, campaign, etc.  We are attempting to do something slightly different -- we need a user to be able to make multiple contributions on one contribution page.

We have successfully modified the Main, Confirm and ThankYou templates to show multiple items on a single page.  However we now need to handle the DB insert. 

CiviCRM takes the total of the line-item contributions and places it in the civicrm_contributions table.  We need to insert the line-item contributions into the table, not the total.  Any suggestions on the best way to do this without completely hacking the code?  :)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Insert Multiple Records on One Contribution
June 01, 2008, 11:33:40 am

I suspect you will need to hack the code at this stage :(.

all the contribution records are created here:

CRM_Contribute_Form_Contribution_Confirm::processContribution

which in turn calls

CRM_Contribute_BAO_Contribution::add( $contribParams, $ids );

You'll need to be a bit careful since we expect unique transaction ids / contribution etc. Can you give us an idea of your use case so we have a better idea of what you are trying to accomplish etc

thanx

lobo


lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

rs3515

  • I’m new here
  • *
  • Posts: 29
  • Karma: 1
Re: Insert Multiple Records on One Contribution
June 01, 2008, 02:52:11 pm
Hey Lobo, thanks for the reply.  Sorry about not placing the question in the right area.  Let me offer more explanation to see if there is a way to handle this with minimal hacking.  :)

Based on our modifications, here is how the code currently works:

  • 1) User enters billing information and multiple amounts for donation.  Values stored in session.  (Main.tpl/Main.php)
  • 2) User confirms billing information and contribution amounts.  (Confirm.tpl/Confirm.php)
  • 3) Total amount stored in civicrm_contribution table, and detail line-item amounts stored in a Drupal table called donations.  We place the same invoice_id and trxn_id in Drupal as cross-reference.  Thank You page presented to the user.  (ThankYou.tpl/ThankYou.php)

All of the above works fine.  The issue we have is with administration.  When an admin visits CiviContribute, we would like him/her to be able to (a) see detailed-line item donations in the Recent Contributions list and (b) download them using the Find Contributions functionality. 

Admins can deliver line-item amounts to the right groups only if they have a way to see them.  Of course we could have created a separate donation page for each group, but the current site bundles together multiple donation opportunities on one page.  (Note: when we first started working on this, we considered creating separate contribution pages in CiviContribute and then finding a way to merge them on the front-end.  However we ran into similar problems with the donation process rather than the admin process.)

Within CiviContribute code we can write queries to get the detailed line-items from Drupal:
Code: [Select]
SELECT * FROM drupal.donations
LEFT OUTER JOIN civicrm.civicrm_contribution ON (donations.tid = civicrm_contribution.invoice_id)
WHERE donations.status = '1'

However not entirely sure how this would integrate with the Recent Contributions and Find Contributions lists, or if there is an easy way to do so.  That's why we were wondering if the better approach was to just insert contribution records at the time of donation.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Insert Multiple Records on One Contribution
June 02, 2008, 01:50:00 am

Both recent contributions and find contributions use civicrm search, and that code is a wee bit complex. You can hack the code and integrate your changes out there, the file to modify would be:

CRM/Contribute/BAO/Query.php
CRM/Contribute/Form/Search.php
CRM/Contribute/Form/Search.tpl
CRM/Contribute/Form/Search/*

Another alternative approach might be to build a custom search that is aware of the "drupal_donations" table and includes that in the results. So your admin folks use this set of custom search(es) rather than recent contribution/find contributions. This is probably the easiest, non hackish way of doing things

lobo



lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

rs3515

  • I’m new here
  • *
  • Posts: 29
  • Karma: 1
Re: Insert Multiple Records on One Contribution
June 02, 2008, 11:47:35 pm
Hmmm ... I've been looking at the code more closely, and I'm wondering if there might be a way to accomplish this without too much hacking.  Let me explain my proposed solution and tell me if there are any risks I should consider.

To clarify, I'm not interested in creating unique invoice_id's and trxn_id's for each line-item of the transaction.  In fact, I want each line to have the same IDs so we can see they are part of the same contribution.

What I'm thinking is a for loop around the entire code in processContribution.  To ensure we can use processContribution for other contribution types, we will pass a session variable identifying if a transaction has multiple line-items.  If multiple records, all the $params['amount'] values will be set to the line-item amount, and $params['source'] will be set to the unique information that identifies the line-item record.  Otherwise, process as normal.

I would think this approach would make all the line-items show up as individual records in Recent/Find Contributions.  Am I correct to assume this?  As for building a custom search, probably the easier approach is to have "donations" be a content type in Drupal, so each contribution is a new node.  Using the Views module would allow for an easy way to build a powerful search tool.  However, I'd rather avoid hijacking content nodes for the purpose of donations.  There's really no need to do so.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Insert Multiple Records on One Contribution
June 03, 2008, 02:43:14 am

1. both invoice_id and trxn_id have unique indexes on them. so it wont work unless you drop those indexes from the schema. you could also prefix / suffix the line item id to make those id's unique and keep the constraint

2. Your proposed solution should work with a few tweaks. some of the code needs one contribution id (the function that sends the mail), so u'll need to check / fix that

building a custom search is not too hard. its basically exposing the sql queries. check the wiki for docs on doing it

lobo


A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

rs3515

  • I’m new here
  • *
  • Posts: 29
  • Karma: 1
Re: Insert Multiple Records on One Contribution
June 03, 2008, 08:26:50 am
Ahhh there always has to be a wrench to mess things up.  :) 

I'll take a look at the custom search and compare to the tweaks necessary for the proposed solution.  When you say contribution id for the mail, is it the function needs a specific id to send the mail?  Or are you just referring to what information is displayed on the message?

So I'm curious to know, any chance CiviCRM will in the future move to a more traditional/flexible data schema of a contribution_header table with line-items stored in a contribution_detail table?   ;)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Insert Multiple Records on One Contribution
June 03, 2008, 02:10:16 pm

1. The function takes the contribution id to determine the values for the tokens it needs to replace in the email sent (CRM/Contribute/BAO/ContributionPage.php, function sendMail)

2. We will revisit the price set / line item scheme and implementation in a future 2.x release. The line items are currently stored in a different table and associated with the contribution, we do have the information now, but we dont export/display it in a nice manner. Note that the price set code was community contributed (thanx to ideal solutions), so any improvements to the display/listings/export will be gladly accepted :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

rs3515

  • I’m new here
  • *
  • Posts: 29
  • Karma: 1
Re: Insert Multiple Records on One Contribution
June 03, 2008, 07:15:07 pm
After reviewing the wiki, am I correct to assume the custom search capability is part of 2.x and not in 1.9?    Guessing in 1.9 I would need to edit/hack the files you mentioned in CRM/Contribute/BAO and CRM/Contribute/Form/Search.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Insert Multiple Records on One Contribution
June 03, 2008, 07:42:53 pm

yes, custom search is part of 2.x only. You definitely should consider upgrading and doing your stuff in 2.x release. its significantly better than 1.9 :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

rs3515

  • I’m new here
  • *
  • Posts: 29
  • Karma: 1
Re: Insert Multiple Records on One Contribution
June 03, 2008, 11:06:05 pm
I've avoided upgrading to 2.x because of concerns about compatibility.  I decided to give it a try this evening, and sure enough, my concerns have been confirmed.  When I attempt to run the upgrade, I receive the following error:

Code: [Select]
Fatal error: Call to undefined function crm_uf_get_match_id()
in /htdocs/sites/all/modules/civinode/civinode_utils.inc on line 593

If I remove the CiviNode module from Drupal, of course it makes it through the rest of the upgrade successfully.  We're using CiviNode 5.x-1.2 (http://drupal.org/project/civinode) to expose contact records to the user so they can update personal information from their user profile.

Unless there is some other way to allow this to happen in Drupal with CiviCRM 2.x, I just don't see how we can upgrade at this point.  Also here is an on-going thread discussing some of the issues:  http://drupal.org/node/230103  Any thoughts?
« Last Edit: June 03, 2008, 11:10:48 pm by rs3515 »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Insert Multiple Records on One Contribution
June 04, 2008, 12:07:02 am

Not sure why you are not using CiviCRM profiles to expose contact data to the user. seems a much easier route than civinode (for this specific case)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

rs3515

  • I’m new here
  • *
  • Posts: 29
  • Karma: 1
Re: Insert Multiple Records on One Contribution
June 07, 2008, 01:46:03 am
Ah you know what?  You are absolutely right.  I'm not sure why I was thinking that our exposing of contact records is being done via CiviNode.  In fact we are using CiviCRM profiles.  It is still a bit of an issue, since we are exposing CiviCRM fields through CCK in a couple of places.  In the interim we may be able to work around this by just putting the data in Drupal, then eventually migrating it back to CiviCRM.

I did work for a bit on attempting to create a custom search per the wiki.  Very slick and this does seem like it could solve our issues.  I was able to merge together CiviCRM and Drupal data into a single result set, and export the data.  The functions to select data columns for export doesn't seem to work, but I'm ok with just dumping all the data to the screen and doing one large export of all columns for now.

I'm not sure what the long-term plans are for the custom search capabilities, but if it was eventually integrated into a query-building front-end (a la Drupal Views), it could be a very powerful data mining solution.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Insert Multiple Records on One Contribution

This forum was archived on 2017-11-26.