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) »
  • Need help pulling related data to a detailed report (dao + overriding templates)
Pages: [1]

Author Topic: Need help pulling related data to a detailed report (dao + overriding templates)  (Read 870 times)

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Need help pulling related data to a detailed report (dao + overriding templates)
March 06, 2014, 06:16:53 pm
Hello all,

I'm putting the final touches on an extension used to define and apply taxes to contributions (events, memberships, pledges, donations) and the last piece of the puzzle is pulling the tax information into my detailed reports. Whenever a taxable transaction is completed, the tax is charged and the tax details are logged in a table that my extension created called "civi_tax_invoicing". The key that relates this information to the transaction is the invoice number. Now what I have to do is bring my tax information into the reports page but I've been spinning my wheels for a couple of days and can't seem to bring the info over to the reports.

Here's what I need to do:
  • Add fields to my Report Criteria panel with pre_tax amount and then fields for the applicable taxes.
  • Bind these fields in the report to the rows/columns that are reported.
  • Rearrange the columns so that I show before tax, tax amounts, total including tax.

Here's what I've done so far:
  • In my extension I have a modified version of Detail.php which usually resides in civicrm/CRM/Report/Form/Contribute/. I've modified this file to add my fields for the transaction (pre_tax, tax_amount). I've set up the array like so:

    'civi_tax_invoicing' => array(
          'dao' => 'CRM_Core_DAO_CiviTaxInvoicing',
          'fields' => array(),
          'grouping' => 'contact-fields',
       ),
    The names and number of taxes is dynamic so I'm pushing them into the array via a select statement from the database. The upside is now, I have new checkbox fields in my report criteria.
     
  • The next thing I need to do is get the related data attached to the report.

    As I understand it, my array of fields should now be bound to a data access object that I created called CRM_Core_DAO_CiviTaxInvoicing. This is defined in a file called CiviTaxInvoicing.php that lives in CRM/Core/DAO/. I modeled it after Contact.php which defines the CRM_Contact_DAO_Contact data access object. The problem is, I don't know how to test it and when I try to use it as I expect it should work, I get errors that really don't tell me anything of use. 

So, does anyone have some tips or direction I can follow to bind my info to the transactions so I can produce the detailed transaction report with tax info in it?

Thanks,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Need help pulling related data to a detailed report (dao + overriding templates)
March 06, 2014, 06:20:55 pm
Not helping with your question, but could I recommend that you rename the table to start with civicrm_ - there is a hard-coded expectation in many places that tables start with that string.
Try asking your question on the new CiviCRM help site.

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Need help pulling related data to a detailed report (dao + overriding templates)
March 06, 2014, 07:01:29 pm
Thanks Coleman for the reply but you can't name tables in an extension with civicrm_ MySQL will try to run a routine that checks log tables for every table with the prefix "civicrm_" and it will error out. More about that here: http://forum.civicrm.org/index.php/topic,27095.msg115325.html#msg115325
My CiviCRM Extension Workshop: https://github.com/awasson

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Need help pulling related data to a detailed report (dao + overriding templates)
March 07, 2014, 06:53:38 pm
Ok, I've been trying all sorts of things with no real progress but I'm beginning to think that there is something wrong with my data access object (CRM_Core_DAO_CiviTaxInvoicing) that's defined in my extension module at CRM/Core/DAO/CiviTaxInvoicing.php

Parts of it seem to be working. For instance I can return an array of fields that are defined in the class by calling: CRM_Core_DAO_TaxInvoicing::fields();

What isn't working however is the more dynamic part of the object. For example from within my report, I'll be adding a left join on custom_table where custom_table.invoice_id = civicrm_contribution.invoice_id. As I understand it my custom DAO should automatically create an alias which should look like civi_tax_invoicing_civireport or something similar but if I dump it to the screen print_r($this->_aliases['civi_tax_invoicing']); I get returned: _invoicing_civireport.

You can see my DAO declaration here: https://github.com/awasson/civiTAX/blob/civitax_4.4.x/CRM/Core/DAO/TaxInvoicing.php

Furthermore if I dump the sql query and insert it into my database (mysql workbench), it will work for all of the existing report aliases but I can't get it to recognize an alias for my custom dao described alias

Any direction would be great.

Thanks,
Andrew
« Last Edit: March 07, 2014, 10:59:43 pm by awasson »
My CiviCRM Extension Workshop: https://github.com/awasson

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Need help pulling related data to a detailed report (dao + overriding templates)
March 08, 2014, 12:20:16 am
Ok, low and behold, I'm making some progress here  :o

My DAO is working although I'd be a heck of a lot happier if I could figure out why the alias is _invoicing_civireport instead of something with a little more of the name; ie: civi_tax_invoicing_civireport but never the less I can work with it because I now have $this->_aliases['civi_tax_invoicing'] working in my query.

So the big blockade was that there was a conflict between the character sets that my custom database tables had taken and the ones that CiviCRM created. My tables were utf8_general_ci and CiviCRM tables were utf8_unicode_ci. The fix for now is to amend my LEFT join as follows:

Code: [Select]

$this->_from .= "
    LEFT JOIN civi_tax_invoicing {$this->_aliases['civi_tax_invoicing']}
    ON {$this->_aliases['civicrm_contribution']}.invoice_id = {$this->_aliases['civi_tax_invoicing']}.invoice_id COLLATE utf8_unicode_ci";
   

   

The real fix will be to make sure that my tables share the same character set as the main tables.

So the beautiful thing about this is that because my custom data access object is indeed working as soon as I bring in one of the fields that I added to the fields array into the report via the checkbox, it pops up in my report. Prior to this breakthrough I was getting blank errors with no descriptions. I am super psyched about this! Woo Hoo!

I still have some tricky bits to work through to get my dynamic taxes to pop into the picture but we're looking good!
« Last Edit: March 08, 2014, 12:22:20 am by awasson »
My CiviCRM Extension Workshop: https://github.com/awasson

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Need help pulling related data to a detailed report (dao + overriding templates)

This forum was archived on 2017-11-26.