return FALSE;
}
+ /**
+ * Check if financial type has Deferred Revenue Account is relationship
+ * with Financial Account.
+ *
+ * @param int $financialTypeId
+ *
+ * @return bool
+ *
+ */
+ public static function validateFinancialType($financialTypeId, $entityID = NULL, $entity = NULL) {
+ if (!CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
+ return FALSE;
+ }
+ if ($entityID) {
+ $query = ' SELECT ps.extends FROM civicrm_price_set ps %3 WHERE %1.id = %2';
+ $params = array(
+ 1 => array('ps', 'Text'),
+ 2 => array($entityID, 'Integer'),
+ );
+ if ($entity == 'PriceField') {
+ $params[1] = array('pf', 'Text');
+ $params[3] = array(
+ ' INNER JOIN civicrm_price_field pf ON pf.price_set_id = ps.id ',
+ 'Text',
+ );
+ }
+ $extends = CRM_Core_DAO::singleValueQuery($query, $params);
+ $extends = explode('\ 1', $extends);
+ if (!(in_array(CRM_Core_Component::getComponentID('CiviEvent'), $extends)
+ || in_array(CRM_Core_Component::getComponentID('CiviMember'), $extends))
+ ) {
+ return FALSE;
+ }
+ }
+ $deferredFinancialType = self::getDeferredFinancialType();
+ if (!array_key_exists($financialTypeId, $deferredFinancialType)) {
+ return TRUE;
+ }
+ return FALSE;
+ }
+
}
$this->assertEquals($valid, $message, "The messages do not match");
}
+ /**
+ * Test if financial type has Deferred Revenue Account is relationship with Financial Account.
+ *
+ */
+ public function testValidateFinancialType() {
+ Civi::settings()->set('contribution_invoice_settings', array('deferred_revenue_enabled' => '1'));
+ $deferred = CRM_Financial_BAO_FinancialAccount::getDeferredFinancialType();
+ $financialTypes = CRM_Contribute_PseudoConstant::financialType();
+ foreach ($financialTypes as $key => $value) {
+ $validate = CRM_Financial_BAO_FinancialAccount::validateFinancialType($key);
+ if (array_key_exists($key, $deferred)) {
+ $this->assertFalse($validate, "This should not have thrown an error.");
+ }
+ else {
+ $this->assertEquals($validate, TRUE);
+ }
+ }
+ }
+
}