public function execute($params, $btx, CRM_Banking_Matcher_Suggestion $match)
 {
     $contact_id = $match->getParameter('contact_id');
     if ($contact_id) {
         $baid = $btx->party_ba_id;
         $r = civicrm_api3('banking_account', 'create', array('id' => $baid, 'contact_id' => $contact_id));
     }
 }
Пример #2
0
 /** 
  * Generate html code to visualize the given match. The visualization may also provide interactive form elements.
  * 
  * @val $match    match data as previously generated by this plugin instance
  * @val $btx      the bank transaction the match refers to
  * @return html code snippet
  */
 function visualize_match(CRM_Banking_Matcher_Suggestion $match, $btx)
 {
     $html = "<p>" . ts("Because :") . "<ul>";
     $evidence = $match->getEvidence();
     foreach ($evidence as $ev) {
         $html .= '<li>' . $ev . '</li>';
     }
     $html .= '</ul></p>';
     return $html;
 }
 /** 
  * Generate html code to visualize the executed match.
  * 
  * @val $match    match data as previously generated by this plugin instance
  * @val $btx      the bank transaction the match refers to
  * @return html code snippet
  */
 function visualize_execution_info(CRM_Banking_Matcher_Suggestion $match, $btx)
 {
     if ($match->getId() === "manual") {
         $cids = $match->getParameter('contribution_ids');
         $text = "<p>" . ts("This transaction was manually matched to the following contributions:") . "<ul>";
         foreach ($cids as $contribution_id) {
             if ($contribution_id) {
                 $contribution_link = CRM_Utils_System::url("civicrm/contact/view/contribution", "action=view&reset=1&id={$contribution_id}&cid=2&context=home");
                 $text .= "<li><a href=\"{$contribution_link}\">" . ts("Contribution") . " #{$contribution_id}</a>";
             }
         }
         $text .= "</ul>";
         return $text;
     }
 }
 /** 
  * Generate html code to visualize the executed match.
  * 
  * @val $match    match data as previously generated by this plugin instance
  * @val $btx      the bank transaction the match refers to
  * @return html code snippet
  */
 function visualize_execution_info(CRM_Banking_Matcher_Suggestion $match, $btx)
 {
     // just assign to smarty and compile HTML
     $smarty_vars = array();
     $smarty_vars['contribution_id'] = $match->getParameter('contribution_id');
     $smarty_vars['contact_id'] = $match->getParameter('contact_id');
     // assign to smarty and compile HTML
     $smarty = CRM_Banking_Helpers_Smarty::singleton();
     $smarty->pushScope($smarty_vars);
     $html_snippet = $smarty->fetch('CRM/Banking/PluginImpl/Matcher/CreateContribution.execution.tpl');
     $smarty->popScope();
     return $html_snippet;
 }
Пример #5
0
 public function match(CRM_Banking_BAO_BankTransaction $btx, CRM_Banking_Matcher_Context $context)
 {
     $suggestion = new CRM_Banking_Matcher_Suggestion($this, $btx);
     $suggestion->addEvidence(1.0, "Yes we can");
     return array($suggestion);
 }
 /**
  * create suggestions for matching recurring contributions
  */
 function createRecurringContributionSuggestions($query, $probability, $btx, $context)
 {
     $config = $this->_plugin_config;
     $threshold = $this->getThreshold();
     $data_parsed = $btx->getDataParsed();
     $suggestions = array();
     // don't waste your time contacts below the threshold...
     if ($probability < $threshold) {
         return $suggestions;
     }
     $rcur_result = civicrm_api3('ContributionRecur', 'get', $query);
     foreach ($rcur_result['values'] as $rcur_id => $rcur) {
         // find the next expected date for the recurring contribution
         $expected_date = self::getExpectedDate($rcur, $btx, $config->recurring_mode);
         if ($expected_date == NULL) {
             continue;
         }
         // create a suggestion
         $suggestion = new CRM_Banking_Matcher_Suggestion($this, $btx);
         $suggestion->setId("recurring-{$rcur_id}");
         $suggestion->setParameter('recurring_contribution_id', $rcur_id);
         $suggestion->setParameter('contact_id', $rcur['contact_id']);
         $suggestion->setParameter('expected_date', date('Y-m-d', $expected_date));
         $suggestion->setParameter('expected_amount', $rcur['amount']);
         if (!empty($config->suggestion_title)) {
             $suggestion->setTitle($config->suggestion_title);
         }
         if ($probability < 1.0) {
             $suggestion->addEvidence(1.0 - $probability, ts("The contact could not be uniquely identified."));
         }
         // CHECK AMOUNT
         if ($config->amount_check) {
             // calculate the amount penalties (equivalent to CRM_Banking_PluginImpl_Matcher_ExistingContribution)
             $transaction_amount = $btx->amount;
             $expected_amount = $rcur['amount'];
             $amount_delta = $transaction_amount - $expected_amount;
             if ($transaction_amount < $expected_amount * $config->amount_relative_minimum && $amount_delta < $config->amount_absolute_minimum) {
                 continue;
             }
             if ($transaction_amount > $expected_amount * $config->amount_relative_maximum && $amount_delta > $config->amount_absolute_maximum) {
                 continue;
             }
             $amount_range_rel = $transaction_amount * ($config->amount_relative_maximum - $config->amount_relative_minimum);
             $amount_range_abs = $config->amount_absolute_maximum - $config->amount_absolute_minimum;
             $amount_range = max($amount_range_rel, $amount_range_abs);
             if ($amount_range) {
                 $penalty = $config->amount_penalty * (abs($amount_delta) / $amount_range);
                 if ($penalty) {
                     $suggestion->addEvidence($penalty, ts("The amount of the transaction differs from the expected amount."));
                     $probability -= $penalty;
                 }
             }
         }
         // CHECK CURRENCY
         if ($context->btx->currency != $rcur['currency']) {
             $suggestion->addEvidence($config->currency_penalty, ts("The currency of the transaction is not as expected."));
             $probability -= $config->currency_penalty;
         }
         // CHECK EXPECTED DATE
         if ($config->received_date_check) {
             // use date only
             $transaction_date = strtotime(date('Y-m-d', strtotime($context->btx->value_date)));
             // only apply penalties, if the offset is outside the accepted range
             $date_offset = $transaction_date - $expected_date;
             if ($date_offset < strtotime($config->acceptable_date_offset_from, 0) || $date_offset > strtotime($config->acceptable_date_offset_to, 0)) {
                 // check if the payment is completely out of bounds
                 if ($date_offset < strtotime($config->date_offset_minimum, 0)) {
                     continue;
                 }
                 if ($date_offset > strtotime($config->date_offset_maximum, 0)) {
                     continue;
                 }
                 // calculate the date penalties
                 $date_range = strtotime($config->date_offset_maximum) - strtotime($config->date_offset_minimum) - (strtotime($config->acceptable_date_offset_to) - strtotime($config->acceptable_date_offset_from));
                 if ($date_offset < 0) {
                     $date_delta = abs($date_offset - strtotime($config->acceptable_date_offset_from, 0));
                 } else {
                     $date_delta = abs($date_offset - strtotime($config->acceptable_date_offset_to, 0));
                 }
                 if ($date_range) {
                     $penalty = $config->date_penalty * ($date_delta / $date_range);
                     if ($penalty) {
                         $suggestion->addEvidence($penalty, ts("The date of the transaction deviates too much from the expected date."));
                         $probability -= $penalty;
                     }
                 }
             }
         }
         // CHECK FOR OTHER PAYMENTS
         if ($config->existing_check) {
             $other_contributions_id_list = array();
             $expected_date_string = date('Y-m-d', $expected_date);
             if (empty($config->existing_status_list)) {
                 $config->existing_status_list = array(1, 2);
             }
             $existing_status_list = implode(',', $config->existing_status_list);
             // determine date range
             // TODO: use date_offset_minimum/maximum
             if (preg_match("/[0-9]+%/", $config->existing_precision)) {
                 $cycle_length_seconds = strtotime("+{$rcur['frequency_interval']} {$rcur['frequency_unit']}", 0);
                 $date_range = (int) ((100.0 - (double) $config->existing_precision) / 100.0 * ((double) $cycle_length_seconds / (double) (60 * 60 * 24)));
             } else {
                 $date_range = (int) $config->existing_precision;
             }
             $sql = "\n        SELECT id AS contribution_id\n        FROM civicrm_contribution \n        WHERE contribution_recur_id = {$rcur_id}\n          AND contribution_status_id IN ({$existing_status_list})\n          AND (receive_date BETWEEN ('{$expected_date_string}' - INTERVAL {$date_range} DAY)\n                                AND ('{$expected_date_string}' + INTERVAL {$date_range} DAY) );";
             $sql_query = CRM_Core_DAO::executeQuery($sql);
             while ($sql_query->fetch()) {
                 $other_contributions_id_list[] = $sql_query->contribution_id;
             }
             if (!empty($other_contributions_id_list)) {
                 $links = array();
                 if (count($other_contributions_id_list) == 1) {
                     $message = ts("There is already another contribution recorded for this interval: ");
                 } else {
                     $message = ts("There are already multiple contributions recorded for this interval: ");
                 }
                 foreach ($other_contributions_id_list as $other_contributions_id) {
                     $links[] = "<a href='" . CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&id={$other_contributions_id}&cid={$rcur['contact_id']}&action=view") . "'>[{$other_contributions_id}]</a>";
                 }
                 $message .= implode(', ', $links);
                 $suggestion->addEvidence($config->existing_penalty, $message);
                 $probability -= $config->existing_penalty;
             }
         }
         $suggestion->setProbability($probability);
         $suggestions[] = $suggestion;
     }
     return $suggestions;
 }
Пример #7
0
 public function match(CRM_Banking_BAO_BankTransaction $btx, CRM_Banking_Matcher_Context $context)
 {
     // this section will be refactored to use different conditions, but for now, this is hardcoded
     $suggestion = new CRM_Banking_Matcher_Suggestion($this, $btx);
     $config = $this->_plugin_config;
     // amount range
     if (isset($config->amount)) {
         $camount = $config->amount;
         $low = $camount->low;
         $high = $camount->high;
         $factor = $camount->prob or 1;
         $amount = $btx->amount;
         if ($low == null || $amount >= $low) {
             if ($high == null || $amount <= $high) {
                 $message = ts('the transaction amount is in the range [ ');
                 if ($low) {
                     $message .= number_format($low, 2);
                 }
                 $message .= ' - ';
                 if ($high) {
                     $message .= number_format($high, 2);
                 }
                 $message .= ' ]';
                 $suggestion->addEvidence($factor, $message);
             }
         }
     }
     // date range
     if (isset($config->value_date)) {
         $cvdate = $config->value_date;
         $early = $cvdate->early;
         $late = $cvdate->late;
         $factor = $cvdate->prob or 1;
         $value_date = strtotime($btx->value_date);
         if ($early != '' && $value_date >= strtotime($early)) {
             if ($late != '' && $value_date <= strtotime($late)) {
                 $message = ts('the transaction value date is in the range [ ');
                 if ($early) {
                     $message .= $early;
                 }
                 $message .= ' - ';
                 if ($late) {
                     $message .= $late;
                 }
                 $message .= ' ]';
                 $suggestion->addEvidence($factor, $message);
             }
         }
     }
     // regex
     if (isset($config->purpose)) {
         $cpurp = $config->purpose;
         $regex = $cpurp->regex;
         $factor = $cpurp->prob or 1;
         $parsed = json_decode($btx->data_parsed, true);
         $purpose = $parsed['purpose'];
         if ($regex != '' && preg_match("/{$regex}/", $purpose)) {
             $message = sprintf(ts('the transaction purpose matches the expression "%s"'), htmlentities($regex));
             $suggestion->addEvidence($factor, $message);
         }
     }
     if ($suggestion->getProbability() > 0) {
         $btx->addSuggestion($suggestion);
     }
     // close up
     return empty($this->_suggestions) ? null : $this->_suggestions;
 }
Пример #8
0
 /**
  * Examine this particular condition. Use $ctx to retrieve and store context items.
  * 
  * @param CRM_Banking_BAO_BankTransaction $btx
  * @param CRM_Banking_Matcher_Context $ctx
  * @param CRM_Banking_Matcher_Suggestion $suggestion
  */
 public function match(CRM_Banking_BAO_BankTransaction $btx, CRM_Banking_Matcher_Context $ctx, CRM_Banking_Matcher_Suggestion $suggestion)
 {
     $suggestion->addEvidence($this->prob, 'GENERIC REASON');
     return true;
 }
 /** 
  * Generate html code to visualize the executed match.
  * 
  * @val $match    match data as previously generated by this plugin instance
  * @val $btx      the bank transaction the match refers to
  * @return html code snippet
  */
 function visualize_execution_info(CRM_Banking_Matcher_Suggestion $match, $btx)
 {
     // just assign to smarty and compile HTML
     $smarty_vars = array();
     $smarty_vars['contribution_id'] = $match->getParameter('contribution_id');
     $contact_id = $match->getParameter('contact_id');
     if (empty($contact_id)) {
         // this information has not been stored (old matcher version)
         $result = civicrm_api('Contribution', 'get', array('version' => 3, 'id' => $match->getParameter('contribution_id')));
         if (isset($result['id'])) {
             $contribution = $result['values'][$result['id']];
             $contact_id = $contribution['contact_id'];
             $smarty_vars['contact_id'] = $contact_id;
         } else {
             // TODO: error handling?
             $smarty_vars['contact_id'] = 0;
         }
     } else {
         $smarty_vars['contact_id'] = $contact_id;
     }
     $smarty_vars['cancellation_mode'] = $match->getParameter('cancellation_mode');
     $smarty_vars['cancel_fee'] = $match->getParameter('cancel_fee');
     $smarty_vars['cancel_reason'] = $match->getParameter('cancel_reason');
     $smarty = CRM_Banking_Helpers_Smarty::singleton();
     $smarty->pushScope($smarty_vars);
     $html_snippet = $smarty->fetch('CRM/Banking/PluginImpl/Matcher/SepaMandate.execution.tpl');
     $smarty->popScope();
     return $html_snippet;
 }
Пример #10
0
 function visualize_match(CRM_Banking_Matcher_Suggestion $match, $btx)
 {
     $s = '<ul>' . ts("Because :");
     $evidence = $match->getEvidence();
     foreach ($evidence as $ev) {
         $s .= '<li>' . $ev . '</li>';
     }
     $s .= '</ul>';
     return $s;
 }
Пример #11
0
 /** 
  * Generate html code to visualize the executed match.
  * 
  * @val $match    match data as previously generated by this plugin instance
  * @val $btx      the bank transaction the match refers to
  * @return html code snippet
  */
 function visualize_execution_info(CRM_Banking_Matcher_Suggestion $match, $btx)
 {
     $batch_id = $match->getParameter('batch_id');
     $batch_link = CRM_Utils_System::url("civicrm/batchtransaction", "reset=1&bid={$batch_id}");
     return "<p>" . sprintf(ts("This transaction was associated with <a href=\"%s\">payment batch #%s</a>."), $batch_link, $batch_id) . "</p>";
 }