Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IIDA-59 [DO NOT MERGE - WIP] Added check for non-exported transactions within closing period #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions CRM/CloseAccountingPeriod/BAO/CloseAccountingPeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,37 @@ public static function setPriorFinancialPeriod($priorFinancialPeriod, $contactID
);
}

/**
* Check if transactions are exported before account period is closed.
*
* @param string $date
* Closing Date.
* @param int $contactId
* Contact ID of organization.
*
*/
public static function checkIfExported($closingDate, $contactId = NULL) {
$priorDate = NULL;
$closingDate = date('Y-m-d', $closingDate);
if ($contactId) {
$priorDate = CRM_CloseAccountingPeriod_BAO_CloseAccountingPeriod::getPriorFinancialPeriod($contactId);
}
if (empty($priorDate)) {
$where = " <= DATE('$closingDate') ";
}
else {
$priorDate = $priorDate['Y'] . '-' . $priorDate['M'] . '-' . $priorDate['d'];
$priorDate = date('Y-m-d', strtotime($priorDate . '+1 Day'));
$where = " BETWEEN DATE('$priorDate') AND DATE('$closingDate') ";
}
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
$sql = "SELECT COUNT(ft.id) FROM civicrm_financial_trxn ft
LEFT JOIN civicrm_entity_batch eb ON eb.entity_id = ft.id AND eb.entity_table = 'civicrm_financial_trxn'
LEFT JOIN civicrm_batch b ON b.id = eb.batch_id
WHERE eb.entity_id IS NULL
AND ft.trxn_date {$where}
AND (b.status_id IS NULL OR b.status_id <> " . array_search('Exported', $batchStatus) . ")";
return $count = CRM_Core_DAO::singleValueQuery($sql);
}

}
3 changes: 3 additions & 0 deletions CRM/CloseAccountingPeriod/Form/CloseAccountingPeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public function setDefaultValues() {
if (count($this->_financialAccountOrg) == 1) {
$defaults['contact_id'] = key($this->_financialAccountOrg);
}
if (CRM_CloseAccountingPeriod_BAO_CloseAccountingPeriod::checkIfExported($date, $defaults['contact_id'])) {
CRM_Core_Session::setStatus(ts('Some transactions in the reporting period have not yet been exported. Please ensure they are exported.'), ts('Warning'), 'warning');
}
return $defaults;
}

Expand Down
3 changes: 3 additions & 0 deletions CRM/CloseAccountingPeriod/Form/Report/TrialBalance.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public function __construct() {
}

public function preProcess() {
if (CRM_CloseAccountingPeriod_BAO_CloseAccountingPeriod::checkIfExported($date)) {
CRM_Core_Session::setStatus(ts('Some transactions in the reporting period have not yet been exported. Please ensure they are exported.'), ts('Warning'), 'warning');
}
parent::preProcess();
}

Expand Down