Exemplo n.º 1
0
 /** 
  * Generate a set of suggestions for the given bank transaction
  * 
  * @return array(match structures)
  */
 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;
     $threshold = $this->getThreshold();
     $penalty = $this->getPenalty($btx);
     if (isset($config->ignore)) {
         // iterate through the ignore list
         foreach ($config->ignore as $ignore_record) {
             if ($this->matches_pattern($ignore_record, $btx, $context)) {
                 $ignore_this = TRUE;
                 // this $btx is to be ignored, but check if it happens to be on the "don't ignore" list
                 foreach ($config->dont_ignore as $dont_ignore_record) {
                     if ($this->matches_pattern($dont_ignore_record, $btx, $context)) {
                         // ok, this should not be ignored after all...
                         $ignore_this = FALSE;
                         break;
                         // doesn't matter why it should not be ignored
                     }
                 }
                 if ($ignore_this) {
                     if (isset($ignore_record->precision)) {
                         $probability = $ignore_record->precision;
                     } else {
                         $probability = 1.0;
                     }
                     $probability -= $penalty;
                     $suggestion->addEvidence($probability, $ignore_record->message);
                 }
             }
         }
     }
     if ($suggestion->getProbability() >= $threshold) {
         $btx->addSuggestion($suggestion);
     }
     // that's it...
     return empty($this->_suggestions) ? null : $this->_suggestions;
 }
Exemplo n.º 2
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;
 }