Commit d9da7aa0 authored by jaapjansma's avatar jaapjansma
Browse files

added correction job

parent 104ff37c
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
/**
* Bkfbanking.Correctbankaccount API method.
* Lookup the bank account of every contribution in civi banking and set the bank account
* in the custom field.
*
* @param array $params Parameters
*
* @return array API result descriptor
* @throws API_Exception
* @see civicrm_api3_create_error
* @see civicrm_api3_create_success
*/
function civicrm_api3_bkfbanking_correctbankaccount($params) {
$options = _civicrm_api3_get_options_from_params($params);
$sql = "SELECT id FROM civicrm_contribution WHERE id NOT IN (SELECT entity_id FROM civicrm_value_contribution_bankkonto) and YEAR(receive_date) >= 2020 and payment_instrument_id = 4 and contribution_status_id = 1 LIMIT %1, %2";
$sqlParams[1] = [$options['offset'], 'Integer'];
$sqlParams[2] = [$options['limit'], 'Integer'];
$dao = CRM_Core_DAO::executeQuery($sql, $sqlParams);
$insertSql = "INSERT INTO civicrm_value_contribution_bankkonto (entity_id, bankkonto) VALUES ";
$insertValues = [];
while ($dao->fetch()) {
$findBankTxSql = "SELECT id FROM `civicrm_bank_tx` WHERE `suggestions` REGEXP '(.*,\"contribution_ids\":\\\\[\"\",\"({$dao->id})\"],\"executed\".*|.*,\"contribution_id\":({$dao->id}).*)'";
$btx = CRM_Core_DAO::executeQuery($findBankTxSql, [], TRUE, 'CRM_Banking_BAO_BankTransaction');
while ($btx->fetch()) {
$btx_bao = new CRM_Banking_BAO_BankTransaction();
$btx_bao->get('id', $btx->id);
$suggestion_objects = $btx_bao->getSuggestionList();
foreach ($suggestion_objects as $suggestion) {
if ($suggestion->isExecuted()) {
$dataParsed = $btx_bao->getDataParsed();
if (isset($dataParsed['_NBAN_NO'])) {
$contribution_ids = array();
if ($suggestion->getParameter('contribution_id')) {
$contribution_ids[] = $suggestion->getParameter('contribution_id');
} elseif ($suggestion->getParameter('contribution_ids')) {
$contribution_ids = $suggestion->getParameter('contribution_ids');
}
foreach($contribution_ids as $contrib_id) {
if ($contrib_id && $contrib_id == $dao->id) {
$insertValues[$dao->id] = "(".$dao->id.",'".$dataParsed['_NBAN_NO']."')";
}
}
}
}
}
}
}
if (count($insertValues)) {
$insertSql = $insertSql . implode(", ", $insertValues).";";
CRM_Core_DAO::executeQuery($insertSql);
}
$returnMessages[] = ts("Updated contributions with bank account: %1", [
1 => count($insertValues),
]) ;
return $returnMessages;
}
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
<url desc="Documentation">https://lab.civicrm.org/partners/civicoop/barnekreftforeningen/barnekreftbanking/blob/master/README.md</url> <url desc="Documentation">https://lab.civicrm.org/partners/civicoop/barnekreftforeningen/barnekreftbanking/blob/master/README.md</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url> <url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls> </urls>
<releaseDate>2019-12-18</releaseDate> <releaseDate>2020-02-25</releaseDate>
<version>1.2</version> <version>1.3</version>
<develStage>stable</develStage> <develStage>stable</develStage>
<compatibility> <compatibility>
<ver>5.13</ver> <ver>5.13</ver>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment