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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • PledgePayment API
Pages: 1 [2]

Author Topic: PledgePayment API  (Read 3315 times)

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: PledgePayment API
April 14, 2011, 01:34:36 pm
Yeah, I don't see BAO support for outstanding balance either. It's currently calculated for pledge selector in Pledge/BAO/Query.php select( ).
Protect your investment in CiviCRM by  becoming a Member!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: PledgePayment API
April 14, 2011, 01:44:58 pm
I suspect it would make sense to add it at some point but probably not something I'll look at anytime soon
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: PledgePayment API
April 14, 2011, 04:05:34 pm
@Sarah as you have the code already to calculate the balance, could you add it ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: PledgePayment API
April 20, 2011, 05:13:09 am
Hi,

I have added the param

'option.create_new' - if this is set  & there is no id the pledge won't try to update the oldest existing payment - it will add a new one.

I did think about adding a 3rd variation where it would try to update latest & create new if not but haven't done so.

Note that in general in Civi 'adding' a pledge payment means updating the already created pledge payment to have a contribution id
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: PledgePayment API
April 21, 2011, 10:09:13 pm
The code I wrote to calculate the pledge balance is below:

function get_pledge_balance_remaining($tmp_cur_pledge_id){

$pledge_parms = array();
    $pledge_parms['pledge_id'] = $tmp_cur_pledge_id ;
    $pledge_parms['version'] = 3;
   
    $tmp_pledges =& civicrm_api('Pledge','Get', $pledge_parms ) ;
     
     $tmp_total_amount  = $tmp_pledges['values'][$tmp_cur_pledge_id]['pledge_amount'];
     $tmp_paid_to_date  = $tmp_pledges['values'][$tmp_cur_pledge_id]['pledge_total_paid'] ;
   
    $amount_remaining =  $tmp_total_amount  - $tmp_paid_to_date;
   
    return  $amount_remaining;
   
    }
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: PledgePayment API
May 09, 2011, 06:36:58 pm
Hi,

I recently had to start extending pledges & add new ones. It doesn't provide any default for scheduled date if you leave it blank which is a bit of a pain - here's the code I used - I'm trying to think how to make the scheduled date calculation available to api users - maybe as another function that calls the BAO one - but that's anti CRUD. Or, calculating it in the API if
create_new is set & not scheduled_date

Code: [Select]
$pledgeinst = civicrm_api('PledgePayment','Get', array('version' => 3, 'pledge_id' =>                       $params['pledge_id'],'sequential' => 1 ));
  if($pledgeinst['is_error'] ==0 && $pledgeinst['count'] < $params['installments']){
    $lastPledge = $pledgeinst['values'][$pledgeinst['count'] -1];
    $lastSchedDate  = $lastPledge['scheduled_date'];
    while ($pledgeinst['count'] < $params['installments']) {
    $ppnew = array('version' =>3,
                    'pledge_id' => $params['pledge_id'],
                    'option.create_new' =>1,
                    'status_id' => 2,
        'frequency_unit' => $params['frequency_unit'],
    'frequency_interval' => $params['frequency_interval'],
    'scheduled_amount' => $params['installment_amount'],);

 $lastSchedDate  = $ppnew['scheduled_date'] = CRM_Pledge_BAO_Payment::calculateNextScheduledDate($params,1,$lastSchedDate );   
     
$createpp = civicrm_api('PledgePayment','Create',$ppnew);

$pledgeinst['count']++;
  }

 
}
   
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • PledgePayment API

This forum was archived on 2017-11-26.