Project60 / org.project60.sepa

SEPA direct debit integration with civicrm
19 stars 46 forks source link

Erroneous annual amount #682

Closed bastienho closed 9 months ago

bastienho commented 10 months ago

Annuel amount seems erroneous when the installments attribute of the contribution_recur is set.

For example, a contribution of 4,5€ with 10 instalments should have a total amount of 45€ instead of 54€

image

bjendres commented 10 months ago

That's weird, CiviSEPA usually doesn't work with installments. How was that mandate created?

bastienho commented 10 months ago

This example has instalments thanks to a hook from another extension. I have another hook which interrupts debits in the summer.

I just wondered how to customize the "annual amount". Maybe am I on the wrong way.

bastienho commented 9 months ago

I'll manage the display with another hook.

If someone is interested:

function someextension_civicrm_pageRun(  &$page ) {
    if($page instanceof CRM_Sepa_Page_MandateTab){
        $rcur_list =  $page->get_template_vars('rcurs');

        foreach($rcur_list as $rcur_id=>$rcur){
            $sepa_mandates = civicrm_api4('SepaMandate', 'get', [
                'where' => [
                    ['id', '=', $rcur['mandate_id']],
                ],
                'limit' => 1,
                'checkPermissions' => false,
            ]);
            if(isset($sepa_mandates[0]) && ($sepa_mandate = $sepa_mandates[0]) && $sepa_mandate['entity_table'] === 'civicrm_contribution_recur'){
                $contribution_recur_id = $sepa_mandate['entity_id'];
                // Maybe usefull data
                $contributions_recur = civicrm_api4('ContributionRecur', 'get', [
                    'where' => [
                        ['id', '=', $contribution_recur_id],
                    ],
                    'limit' => 1,
                    'checkPermissions' => false,
                ]);
                $memberships = civicrm_api4('Membership', 'get', [
                    'where' => [
                        ['contribution_recur_id', '=', $contribution_recur_id],
                    ],
                    'limit' => 1,
                    'checkPermissions' => false,
                ]);

                // if some conditions{
                        $amount = (float) $rcur['amount'];
                        $prorata = 10;
                        // Alter the total amount
                        $new_total_amount = $amount * $prorata
                        $rcur_list[$rcur_id]['total_amount'] = $new_total_amount;
                        $rcur_list[$rcur_id]['frequency'] .= '  '.sprintf(E::ts('(prorata %d months)'), $prorata);
                 //}

        }
        $page->assign('rcurs', $rcur_list);
    }
}
bjendres commented 9 months ago

Thanks for sharing!