Exemplo n.º 1
0
 /**
  * Function to delete financial Types
  *
  * @param int $contributionTypeId
  * @static
  */
 static function del($financialTypeId)
 {
     $financialType = new CRM_Financial_DAO_FinancialType();
     $financialType->id = $financialTypeId;
     $financialType->find(true);
     // tables to ingore checks for financial_type_id
     $ignoreTables = array('CRM_Financial_DAO_EntityFinancialAccount');
     //TODO: if (!$financialType->find(true)) {
     // ensure that we have no objects that have an FK to this financial type id TODO: that cannot be null
     $occurrences = $financialType->findReferences();
     if ($occurrences) {
         $tables = array();
         foreach ($occurrences as $occurence) {
             $className = get_class($occurence);
             if (!in_array($className, $ignoreTables)) {
                 $tables[] = $className;
             }
         }
         if (!empty($tables)) {
             $message = ts('The following tables have an entry for this financial type: %1', array('%1' => implode(', ', $tables)));
             $errors = array();
             $errors['is_error'] = 1;
             $errors['error_message'] = $message;
             return $errors;
         }
     }
     //delete from financial Type table
     $financialType->delete();
     $entityFinancialType = new CRM_Financial_DAO_EntityFinancialAccount();
     $entityFinancialType->entity_id = $financialTypeId;
     $entityFinancialType->entity_table = 'civicrm_financial_type';
     $entityFinancialType->delete();
     return FALSE;
 }
 /**
  * Delete financial Types.
  *
  * @param int $financialTypeAccountId
  * @param int $accountId
  *
  */
 public static function del($financialTypeAccountId, $accountId = NULL)
 {
     // check if financial type is present
     $check = FALSE;
     $relationValues = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
     $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'entity_id');
     // check dependencies
     // FIXME more table containing financial_type_id to come
     $dependency = array(array('Contribute', 'Contribution'), array('Contribute', 'ContributionPage'), array('Member', 'MembershipType'), array('Price', 'PriceFieldValue'), array('Grant', 'Grant'), array('Contribute', 'PremiumsProduct'), array('Contribute', 'Product'), array('Price', 'LineItem'));
     foreach ($dependency as $name) {
         $daoString = 'CRM_' . $name[0] . '_DAO_' . $name[1];
         $dao = new $daoString();
         $dao->financial_type_id = $financialTypeId;
         if ($dao->find(TRUE)) {
             $check = TRUE;
             break;
         }
     }
     if ($check) {
         if ($name[1] == 'PremiumsProduct' || $name[1] == 'Product') {
             CRM_Core_Session::setStatus(ts('You cannot remove an account with a %1 relationship while the Financial Type is used for a Premium.', array(1 => $relationValues[$financialTypeAccountId])));
         } else {
             $accountRelationShipId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'account_relationship');
             CRM_Core_Session::setStatus(ts('You cannot remove an account with a %1 relationship because it is being referenced by one or more of the following types of records: Contributions, Contribution Pages, or Membership Types. Consider disabling this type instead if you no longer want it used.', array(1 => $relationValues[$accountRelationShipId])), NULL, 'error');
         }
         return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', "reset=1&action=browse&aid={$accountId}"));
     }
     // delete from financial Type table
     $financialType = new CRM_Financial_DAO_EntityFinancialAccount();
     $financialType->id = $financialTypeAccountId;
     $financialType->find(TRUE);
     $financialType->delete();
     CRM_Core_Session::setStatus(ts('Unbalanced transactions may be created if you delete the account of type: %1.', array(1 => $relationValues[$financialType->account_relationship])));
 }
Exemplo n.º 3
0
 /**
  * @param string $name
  */
 public function financialAccountDelete($name)
 {
     $financialAccount = new CRM_Financial_DAO_FinancialAccount();
     $financialAccount->name = $name;
     if ($financialAccount->find(TRUE)) {
         $entityFinancialType = new CRM_Financial_DAO_EntityFinancialAccount();
         $entityFinancialType->financial_account_id = $financialAccount->id;
         $entityFinancialType->delete();
         $financialAccount->delete();
     }
 }