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 CiviContribute (Moderator: Donald Lobo) »
  • Allowing trxn_id dups
Pages: [1]

Author Topic: Allowing trxn_id dups  (Read 3663 times)

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Allowing trxn_id dups
June 23, 2008, 05:53:32 pm
Currently, you're not able to have duplicate values for the trxn_id field. We have a lot of people who pay by check, and run into duplicate check numbers, which we enter into this field. What's the best way to remove the duplicate check, and if I do so, will it break other things? I'm looking CRM/Contribute/Form/Contribution.php, around  line 452. I tried just commenting out the addrule function, but it breaks the form.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

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: Allowing trxn_id dups
June 23, 2008, 06:34:55 pm

You will also need to drop the unique index from the db

I think we use and check for uniqueness in a couple of places. You might want to search the code for trxn_id and fix it as needed

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

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Allowing trxn_id dups
June 24, 2008, 10:13:38 am
I had to remove the addrule form validation check from Contribute/Form/Contribution.php, remove the unique index, and also modify CRM/Contribute/BAO/Contribution.php --- I removed trxn_id from the checkDuplicate function.

Question: I'm concerned that removing trxn_id from the checkDuplicate function may have negative repercussions for the use of that field for front end transactions, where the value is prepopulated. Do you know offhand if that's a valid concern?
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Allowing trxn_id dups
June 24, 2008, 11:09:38 am
Brian - I'm not sure if your change will affect online transactions, altho i doubt it.

However, from a overall data design perspective - the "intent" for folks entering check payment transaction id's was that the "acct # + chk #" would provide a unique key for the transaction. Perhaps this is not a "realistic" approach to how folks enter this data and we should consider providing a different field for this or removing the uniqueness constraint in general ??

Would be great to hear thoughts from others on this.
Protect your investment in CiviCRM by  becoming a Member!

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Allowing trxn_id dups
June 24, 2008, 11:29:37 am
This particular client is using that field for check numbers and PO numbers. PO numbers were actually the greater issue. The bookkeeper who handles data entry wants consistent formatting (e.g. "PO #345") for the data, and because that field data is exported and used for invoicing back to the member, they'd rather not require "creative" workarounds. And when using checks, yes, I doubt most people want to enter an account number + check number, both because of the time required and because they may feel uncomfortable putting bank account numbers in the system for security reasons.

There are two fields in CiviContribute (that I can think of) that mix auto-generated values and manually entered values -- the Source field and Transaction ID. I steer people away from using the Source field for anything because it's not always clear when the system will auto fill a value, and what will happen if data is manually entered into that field (will auto-data be appended; will manual data be overwritten). Seems to me it may make better sense to separate fields that have system generated data from those available for manual input. Personally, I don't think a unique value is important when entering manual data (check numbers, PO numbers), but do think it is for the auto generated content.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

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: Allowing trxn_id dups
June 24, 2008, 02:25:51 pm

Would it make sense to create a custom field (called check #) and use that to record check numbers, and avoid using trxn_id?

will make maintainance a lot easier

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

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Allowing trxn_id dups
June 24, 2008, 02:52:50 pm
We could do that. Built-in fields integrate more cleanly, so it's a bit more preferable. Also, I've included the trxn_id field in the member/event record forms. Might be a little more difficult to include custom fields in those forms.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

peta

  • Guest
Re: Allowing trxn_id dups
July 08, 2008, 08:04:11 pm
Hi. Hope this is a good place to put this.

I am testing and documenting the best way for administrators to enter payments received from those who elect to "pay later" on the contribution form.  Using Joomla 1.5 and CiviCRM 2.0.4.

Following instructions in CiviCRM,  I use "Update Pending Contribution Status" for this, which works fine, updates membership status as well as contribution status.  On one occasion, however I forgot to enter the amount in the "Fee Amount" field on the "Update Contribution Status" screen. I did enter a unique Transaction Id and accepted the default Transaction date. After updating I realised my mistake.  It made me start to test possible procedures for correcting such errors.

I went into Edit for the particular record and reset the contribution status to "pending" which allowed me to once again go into "Update Pending Contribution Status".  This time I entered the Fee Amount, left the Transaction Id and Transaction Date as they were.  On update, I received a database error - see below. 

I know the transaction id is supposed to be unique and that would be fine - if the system was doing a database UPDATE. But according to the error it is trying to do an INSERT and of course, failing. 

Why is it doing an INSERT here?

I agree with others who posted here that it would be good to have transaction id or cheque id field that is not unique nor potentially a mix of autogenerated and manually entered data.

Peta




 Sorry. A non-recoverable error has occurred.

    DB Error: already exists

    Database Error Code: Duplicate entry '9723-1' for key 2, 1062

    Return to home page.

Error Details:

Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
Code: [Select]
=> -5
    [message] => DB Error: already exists
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_financial_trxn (domain_id , contribution_id , trxn_date , trxn_type , total_amount , fee_amount , net_amount , currency , payment_processor , trxn_id ) VALUES ( 1 ,  24 ,  20080709 , 'Debit' ,  0.05 ,  0.05 ,  0 , 'AUD' , 'PayPal_Standard' , '9723' )  [nativecode=1062 ** Duplicate entry '9723-1' for key 2]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_financial_trxn (domain_id , contribution_id , trxn_date , trxn_type , total_amount , fee_amount , net_amount , currency , payment_processor , trxn_id ) VALUES ( 1 ,  24 ,  20080709 , 'Debit' ,  0.05 ,  0.05 ,  0 , 'AUD' , 'PayPal_Standard' , '9723' )  [nativecode=1062 ** Duplicate entry '9723-1' for key 2]
    [to_string] => [db_error: message="DB Error: already exists" code=-5 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_financial_trxn (domain_id , contribution_id , trxn_date , trxn_type , total_amount , fee_amount , net_amount , currency , payment_processor , trxn_id ) VALUES ( 1 ,  24 ,  20080709 , 'Debit' ,  0.05 ,  0.05 ,  0 , 'AUD' , 'PayPal_Standard' , '9723' )  [nativecode=1062 ** Duplicate entry '9723-1' for key 2]"]
)

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: Allowing trxn_id dups
July 09, 2008, 03:13:53 am

It is inserting into the financial transaction table. the record in the contribution table is being updated.

when u change a contribution to pending, you should also delete the associated financial trxn record with it

We'll consider introducing a check # in v2.x. In the meantime you can use a custom field

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

peta

  • Guest
Re: Allowing trxn_id dups
July 11, 2008, 12:28:02 am
Hi

Thank you for your reply.

So, the first time I did the "Update Pending Contribution Status",  the contribution record was UPDATED and a record was INSERTED into the financial transaction table with a Fee Amount of $0.

The second time I am trying to correct that error using "Update Pending Contribution Status".
If I change the transaction id which will allow the INSERT into the financial transaction table I will have two financial records against this contribution, one with a fee amount of $0 and one with the correct amount. Is that correct?

I wonder if it would be possible to allow edit of the financial transaction table entry, by checking for its existence by contributionid, before determining whether an INSERT or UPDATE is required?  I am sure my client will make the same mistake I did, or put the wrong date or transaction id.

Related to this: today I applied the code changes in CRM-3177 to my J1.5.3/Civi2.0.4 - as I need to have a "pay later" without a payment processor.  This worked beautifully for the contribution form and process.

But good old "Update Pending Contribution Status" failed with an error "Could not find payment processor for contribution record:".  I have tracked this (I think) to

administration/components/civicrm/CRM/Contribute/Form/Task/Status.php about row 239

    if ( ! baseIPN -->validateData.... etc etc

and it fails in  administration/components/civicrm/CRM/Core/Payment/BaseIPN.php in the function loadObjects around row 199 where it requires a 'payment processor'!

Is there another CRM number for this fix?  If not I can restore my system to remove the CRM-3177.  I think it's a bit beyond me to work out how to fix this one!

Peta



« Last Edit: July 11, 2008, 12:29:41 am by peta »

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: Allowing trxn_id dups
July 11, 2008, 12:28:27 pm

I reread your original post and realized i had misinterpreted it. I filed and fixed the insert/update issue here:

http://issues.civicrm.org/jira/browse/CRM-3317

No idea with regard to the latter issue since the amount of code changes between two releases is quite a lot. We try to group all commits together with an issue, but sometimes fail to do so completely :(

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

peta

  • Guest
Re: Allowing trxn_id dups
July 19, 2008, 04:12:44 pm
Hi

Thank you so much for this! I was able to apply it as a patch - (I needed to put a comma after 'id', though) - now it is working fine.

Peta

// if a transaction already exists for a contribution id, lets get the id
        66   +           $id = CRM_Core_DAO::getFieldValue( 'CRM_Contribute_DAO_FinancialTrxn',
        67   +                                              $trxn->contribution_id,
        68   +                                              'id'
        69   +                                              'contribution_id' );
        70   +           if ( $id ) {
        71   +               $trxn->id = $id;
        72   +           }

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Allowing trxn_id dups

This forum was archived on 2017-11-26.