Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CRM/Admin/Form/Setting/BankingSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ function buildQuickForm() {
'positiveInteger'
);

$this->addTransactionDomainElements();

$this->addButtons(array(
array(
'type' => 'submit',
Expand Down Expand Up @@ -179,6 +181,8 @@ function setDefaultValues() {
$defaults['lenient_dedupe'] = Civi::settings()->get('lenient_dedupe');
$defaults[CRM_Banking_Config::SETTING_TRANSACTION_LIST_CUTOFF]
= Civi::settings()->get(CRM_Banking_Config::SETTING_TRANSACTION_LIST_CUTOFF);
$defaults[CRM_Banking_Config::SETTING_FORCE_TRANSACTION_DOMAIN]
= Civi::settings()->get(CRM_Banking_Config::SETTING_FORCE_TRANSACTION_DOMAIN);

if ($defaults['reference_matching_probability'] === null) {
$defaults['reference_matching_probability'] = '1.0';
Expand Down Expand Up @@ -226,10 +230,24 @@ function postProcess() {
Civi::settings()->set(CRM_Banking_Config::SETTING_TRANSACTION_LIST_CUTOFF,
$values[CRM_Banking_Config::SETTING_TRANSACTION_LIST_CUTOFF]);

Civi::settings()->set(
CRM_Banking_Config::SETTING_FORCE_TRANSACTION_DOMAIN,
(bool) $values[CRM_Banking_Config::SETTING_FORCE_TRANSACTION_DOMAIN]
);

// log results
$logger = CRM_Banking_Helpers_Logger::getLogger();
$logger->logDebug("Log level changed to '{$values['banking_log_level']}', file is: {$values['banking_log_file']}");

parent::postProcess();
}

private function addTransactionDomainElements(): void {
$this->add(
'checkbox',
CRM_Banking_Config::SETTING_FORCE_TRANSACTION_DOMAIN,
E::ts('Force transaction domain on import')
);
}

}
7 changes: 5 additions & 2 deletions CRM/Banking/BAO/BankTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
| written permission from the original author(s). |
+--------------------------------------------------------*/

use Civi\Banking\Permissions\AllowedDomainsSqlGenerator;

/**
* Class contains functions for CiviBanking bank transactions
Expand Down Expand Up @@ -272,12 +273,14 @@ public static function findUnprocessedIDs($max_count) {
$results = array();
$maxcount = (int) $max_count;
$status_id_new = (int) banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'new');
$sql_query = "SELECT `id` AS txid FROM `civicrm_bank_tx` WHERE `status_id` = '$status_id_new' ORDER BY `value_date` ASC, `id` ASC LIMIT $maxcount";
/** @var \Civi\Banking\Permissions\AllowedDomainsSqlGenerator $allowedDomainsSqlGenerator */
$allowedDomainsSqlGenerator = \Civi::service(AllowedDomainsSqlGenerator::class);
$allowedDomainsClause = $allowedDomainsSqlGenerator->generateWhereClause();
$sql_query = "SELECT `id` AS txid FROM `civicrm_bank_tx` WHERE `status_id` = '$status_id_new' AND $allowedDomainsClause ORDER BY `value_date` ASC, `id` ASC LIMIT $maxcount";
$query_results = CRM_Core_DAO::executeQuery($sql_query);
while ($query_results->fetch()) {
$results[] = $query_results->txid;
}
return $results;
}
}

15 changes: 8 additions & 7 deletions CRM/Banking/BAO/BankTransactionBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
| written permission from the original author(s). |
+--------------------------------------------------------*/

use Civi\Api4\BankTransaction;

/**
* Class contains functions for CiviBanking bank transactions
*/
Expand Down Expand Up @@ -52,14 +54,13 @@ static function add(&$params) {
/**
* Get the list of transactions
*
* @return array of CRM_Banking_BAO_BankTransaction
* @return list<array<string, mixed>>
*/
public function getTransactions()
{
$search = new CRM_Banking_BAO_BankTransaction();
$search->tx_batch_id = $this->id;
$search->find();
return $search->fetchAll();
public function getTransactions(): array {
return BankTransaction::get()
->addWhere('tx_batch_id', '=', $this->id)
->execute()
->getArrayCopy();
}

}
7 changes: 3 additions & 4 deletions CRM/Banking/BAO/PluginInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ static function add(&$params) {
*
* If $enabled_only is set to true (default), only enabled plugins will be delivered.
*
* @return array CRM_Banking_BAO_PluginInstances
* @phpstan-return list<\CRM_Banking_BAO_PluginInstance>
*/
static function listInstances($type_name, $enabled_only=TRUE) {
static function listInstances($type_name, $enabled_only = TRUE): array {
// find the correct plugin type
$import_plugin_type = civicrm_api3('OptionValue', 'get', array(
'name' => $type_name,
Expand Down Expand Up @@ -100,7 +100,7 @@ function getClass() {
/**
* getInstance returns an instance of the class implementing this plugin's functionality
*/
function getInstance() {
public function getInstance(): \CRM_Banking_PluginModel_Base {
$class = $this->getClass();
return new $class( $this );
}
Expand Down Expand Up @@ -179,4 +179,3 @@ public function updateWithSerialisedData($serialised_data, $skip_fields = [], $v
}
}
}

4 changes: 3 additions & 1 deletion CRM/Banking/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class CRM_Banking_Config {
/**
* Setting for the transaction list cutoff
*/
const SETTING_TRANSACTION_LIST_CUTOFF = 'transaction_list_cutoff';
public const SETTING_TRANSACTION_LIST_CUTOFF = 'transaction_list_cutoff';

public const SETTING_FORCE_TRANSACTION_DOMAIN = 'force_transaction_domain';

/**
* Should the bank account dedupe be done in a lenient way?
Expand Down
41 changes: 40 additions & 1 deletion CRM/Banking/DAO/BankTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from org.project60.banking/xml/schema/CRM/Banking/BankTransaction.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:2ec2bcde06e6f6d87f384622825cf4ce)
* (GenCodeChecksum:ff5b0671cddb9376c39713b0af213118)
*/
use CRM_Banking_ExtensionUtil as E;

Expand Down Expand Up @@ -67,6 +67,13 @@ class CRM_Banking_DAO_BankTransaction extends CRM_Core_DAO {
*/
public $booking_date;

/**
* @var string|null
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
public $domain;

/**
* Transaction amount (positive or negative)
*
Expand Down Expand Up @@ -290,6 +297,30 @@ public static function &fields() {
'localizable' => 0,
'add' => '4.3',
],
'domain' => [
'name' => 'domain',
'type' => CRM_Utils_Type::T_STRING,
'title' => E::ts('Domain'),
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'usage' => [
'import' => FALSE,
'export' => FALSE,
'duplicate_matching' => FALSE,
'token' => FALSE,
],
'where' => 'civicrm_bank_tx.domain',
'default' => 'null',
'table_name' => 'civicrm_bank_tx',
'entity' => 'BankTransaction',
'bao' => 'CRM_Banking_DAO_BankTransaction',
'localizable' => 0,
'pseudoconstant' => [
'optionGroupName' => 'banking_transaction_domain',
'optionEditPath' => 'civicrm/admin/options/banking_transaction_domain',
],
'add' => NULL,
],
'amount' => [
'name' => 'amount',
'type' => CRM_Utils_Type::T_MONEY,
Expand Down Expand Up @@ -585,6 +616,14 @@ public static function indices($localize = TRUE) {
'unique' => TRUE,
'sig' => 'civicrm_bank_tx::1::bank_reference',
],
'index_domain' => [
'name' => 'index_domain',
'field' => [
0 => 'domain',
],
'localizable' => FALSE,
'sig' => 'civicrm_bank_tx::0::domain',
],
];
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
Expand Down
41 changes: 40 additions & 1 deletion CRM/Banking/DAO/BankTransactionBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from org.project60.banking/xml/schema/CRM/Banking/BankTransactionBatch.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:0bbb3196810c4399aaec4a31ab6c3b0d)
* (GenCodeChecksum:0bc441ded5ae936cfda329c566363802)
*/
use CRM_Banking_ExtensionUtil as E;

Expand Down Expand Up @@ -67,6 +67,13 @@ class CRM_Banking_DAO_BankTransactionBatch extends CRM_Core_DAO {
*/
public $sequence;

/**
* @var string|null
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
public $domain;

/**
* @var float|string|null
* (SQL type: decimal(20,2))
Expand Down Expand Up @@ -222,6 +229,30 @@ public static function &fields() {
'localizable' => 0,
'add' => '4.3',
],
'domain' => [
'name' => 'domain',
'type' => CRM_Utils_Type::T_STRING,
'title' => E::ts('Domain'),
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'usage' => [
'import' => FALSE,
'export' => FALSE,
'duplicate_matching' => FALSE,
'token' => FALSE,
],
'where' => 'civicrm_bank_tx_batch.domain',
'default' => 'null',
'table_name' => 'civicrm_bank_tx_batch',
'entity' => 'BankTransactionBatch',
'bao' => 'CRM_Banking_DAO_BankTransactionBatch',
'localizable' => 0,
'pseudoconstant' => [
'optionGroupName' => 'banking_transaction_domain',
'optionEditPath' => 'civicrm/admin/options/banking_transaction_domain',
],
'add' => NULL,
],
'starting_balance' => [
'name' => 'starting_balance',
'type' => CRM_Utils_Type::T_MONEY,
Expand Down Expand Up @@ -418,6 +449,14 @@ public static function indices($localize = TRUE) {
'unique' => TRUE,
'sig' => 'civicrm_bank_tx_batch::1::reference',
],
'index_domain' => [
'name' => 'index_domain',
'field' => [
0 => 'domain',
],
'localizable' => FALSE,
'sig' => 'civicrm_bank_tx_batch::0::domain',
],
];
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
Expand Down
6 changes: 6 additions & 0 deletions CRM/Banking/Form/Report/BankingTransactions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use Civi\Banking\Permissions\AllowedDomainsSqlGenerator;
use CRM_Banking_ExtensionUtil as E;

class CRM_Banking_Form_Report_BankingTransactions extends CRM_Report_Form {
Expand All @@ -20,6 +22,10 @@ function __construct() {
$this->bankingStatuses[$status['id']] = $status['label'];
}

/** @var \Civi\Banking\Permissions\AllowedDomainsSqlGenerator $allowedDomainsSqlGenerator */
$allowedDomainsSqlGenerator = \Civi::service(AllowedDomainsSqlGenerator::class);
$this->_whereClauses[] = $allowedDomainsSqlGenerator->generateWhereClause();

$this->_columns = array(
'civicrm_bank_tx' => array(
'fields' => array(),
Expand Down
5 changes: 5 additions & 0 deletions CRM/Banking/Form/StatementSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
| written permission from the original author(s). |
+--------------------------------------------------------*/

use Civi\Banking\Permissions\AllowedDomainsSqlGenerator;
use CRM_Banking_ExtensionUtil as E;

/**
Expand Down Expand Up @@ -286,6 +287,10 @@ public static function getTransactionsAjax()
];
$whereClauses = [];

/** @var \Civi\Banking\Permissions\AllowedDomainsSqlGenerator $allowedDomainsSqlGenerator */
$allowedDomainsSqlGenerator = \Civi::service(AllowedDomainsSqlGenerator::class);
$whereClauses[] = $allowedDomainsSqlGenerator->generateWhereClause('tx');

if (!empty($ajaxParameters[self::VALUE_DATE_START_ELEMENT])) {
$parameterCount = count($queryParameters) + 1;

Expand Down
29 changes: 10 additions & 19 deletions CRM/Banking/Helpers/ContributionLinkMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
| written permission from the original author(s). |
+--------------------------------------------------------*/

use Civi\Api4\BankTransaction;
use CRM_Banking_ExtensionUtil as E;


Expand Down Expand Up @@ -51,28 +52,18 @@ public function run($context)
}

// run a query to the the suggestion strings
$batch = CRM_Core_DAO::executeQuery(
"
SELECT
id AS tx_id,
suggestions AS suggestions
FROM civicrm_bank_tx bank_tx
WHERE bank_tx.id >= %1
AND bank_tx.id <= %2
AND bank_tx.status_id IN (%3)
",
[
1 => [(int) $this->from_tx_id, 'Integer'],
2 => [(int) $this->to_tx_id, 'Integer'],
3 => [$this->status_ids, 'CommaSeparatedIntegers'],
]
);
$transactions = BankTransaction::get()
->addSelect('id', 'suggestions')
->addWhere('id', '>=', (int) $this->from_tx_id)
->addWhere('id', '<=', (int) $this->to_tx_id)
->addWhere('status_id', 'IN', explode(',', $this->status_ids))
->execute();

// migrate all of them. We have to use a heuristic to extract the linked
// contributions, because each matcher could do their own thing...
$contribution_id_parameters = ['contribution_id', 'contribution_ids'];
while ($batch->fetch()) {
$suggestions = json_decode($batch->suggestions, true);
foreach ($transactions as $transaction) {
$suggestions = json_decode($transaction['suggestions'], true);
Comment thread
jensschuppe marked this conversation as resolved.
foreach ($suggestions as $suggestion) {
if (!empty($suggestion['executed'])) {
// this suggestion has been executed -> find contribution_ids
Expand All @@ -85,7 +76,7 @@ public function run($context)
foreach ($contribution_ids as $contribution_id) {
$contribution_id = (int) $contribution_id;
if ($contribution_id) {
CRM_Banking_BAO_BankTransactionContribution::linkContribution($batch->tx_id, $contribution_id);
CRM_Banking_BAO_BankTransactionContribution::linkContribution($transaction['id'], $contribution_id);
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions CRM/Banking/Page/AccountDedupe.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
| written permission from the original author(s). |
+--------------------------------------------------------*/


use Civi\Api4\BankTransaction;
use CRM_Banking_ExtensionUtil as E;

require_once 'CRM/Core/Page.php';
Expand Down Expand Up @@ -314,8 +314,14 @@ function executeRequests($duplicates) {
unset($bank_account_ids[0]);
$delete_ids = implode(',', $bank_account_ids);
CRM_Core_DAO::singleValueQuery("UPDATE civicrm_bank_account_reference SET ba_id=$target_id WHERE ba_id IN ($delete_ids);");
CRM_Core_DAO::singleValueQuery("UPDATE civicrm_bank_tx SET ba_id=$target_id WHERE ba_id IN ($delete_ids);");
CRM_Core_DAO::singleValueQuery("UPDATE civicrm_bank_tx SET party_ba_id=$target_id WHERE party_ba_id IN ($delete_ids);");
BankTransaction::update()
->addValue('ba_id', $target_id)
->addWhere('ba_id', 'IN', $bank_account_ids)
->execute();
BankTransaction::update()
->addValue('party_ba_id', $target_id)
->addWhere('party_ba_id', 'IN', $bank_account_ids)
->execute();
CRM_Core_DAO::singleValueQuery("DELETE FROM civicrm_bank_account WHERE id IN ($delete_ids);");
$accounts_fixed += 1;

Expand Down
Loading