class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
/**
- * static field for all the pledge information that we can potentially export
+ * Static field for all the pledge information that we can potentially export
*
* @var array
* @static
static $_exportableFields = NULL;
/**
- * class constructor
+ * Class constructor
*/
function __construct() {
parent::__construct();
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $defaults (reference ) an assoc array to hold the flattened values
*
- * @return object CRM_Pledge_BAO_Pledge object
+ * @return CRM_Pledge_BAO_Pledge object
* @access public
* @static
*/
}
/**
- * function to add pledge
+ * Add pledge
*
* @param array $params reference array contains the values submitted by the form
*
}
/**
- * takes an associative array and creates a pledge object
+ * Takes an associative array and creates a pledge object
*
* @param array $params (reference ) an assoc array of name/value pairs
*
- * @return object CRM_Pledge_BAO_Pledge object
+ * @return CRM_Pledge_BAO_Pledge object
* @access public
* @static
*/
}
/**
- * Function to delete the pledge
+ * Delete the pledge
*
* @param int $id pledge id
*
}
/**
- * function to get the amount details date wise.
+ * Get the amount details date wise.
+ *
+ * @param string $status
+ * @param string $startDate
+ * @param string $endDate
+ *
+ * @return array|null
*/
static function getTotalAmountAndCount($status = NULL, $startDate = NULL, $endDate = NULL) {
$where = array();
GROUP BY cp.currency
";
if ($select) {
- // CRM_Core_Error::debug($status . ' start:' . $startDate . '- end:' . $endDate, $query);
$dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
$amount = array();
$count = 0;
}
/**
- * Function to get list of pledges In Honor of contact Ids
+ * Get list of pledges In Honor of contact Ids
*
* @param int $honorId In Honor of Contact ID
*
- * @return return the list of pledge fields
+ * @return array return the list of pledge fields
*
* @access public
* @static
}
/**
- * Function to send Acknowledgment and create activity.
+ * Send Acknowledgment and create activity.
*
- * @param object $form form object.
- * @param array $params (reference ) an assoc array of name/value pairs.
+ * @param CRM_Core_Form $form form object.
+ * @param array $params an assoc array of name/value pairs.
* @access public
*
* @return void.
}
}
}
- //end
//assign pledge fields value to template.
$pledgeFields = array(
$receiptFrom = $params['from_email_id'];
}
elseif ($userID = $session->get('userID')) {
- //check for loged in user.
+ //check for logged in user.
list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
}
else {
);
$config = CRM_Core_Config::singleton();
+ // FIXME: Translate
$details = 'Total Amount ' . CRM_Utils_Money::format($params['total_pledge_amount'], CRM_Utils_Array::value('currency', $params)) . ' To be paid in ' . $params['installments'] . ' installments of ' . CRM_Utils_Money::format($params['scheduled_amount'], CRM_Utils_Array::value('currency', $params)) . ' every ' . $params['frequency_interval'] . ' ' . $params['frequency_unit'] . '(s)';
if (!$activity->find()) {
}
/**
- * combine all the exportable fields from the lower levels object
+ * Combine all the exportable fields from the lower levels object
*
* @return array array of exportable Fields
* @access public
}
/**
- * Function to get pending or in progress pledges
+ * Get pending or in progress pledges
*
* @param int $contactID contact id
*
}
/**
- * Function to get pledge record count for a Contact
+ * Get pledge record count for a Contact
*
- * @param $contactID
- *
- * @internal param int $contactId Contact ID
+ * @param int $contactID
*
* @return int count of pledge records
* @access public
}
/**
- * @param $params
+ * @param array $params
*
* @return array
*/
}
return $paymentIDs;
}
+
+ /**
+ * Is this pledge free from financial transactions (this is important to know as we allow editing
+ * when no transactions have taken place - the editing process currently involves deleting all pledge payments & contributions
+ * & recreating so we want to block that if appropriate
+ *
+ * @param integer $pledgeID
+ * @param integer $pledgeStatusID
+ * @return bool do financial transactions exist for this pledge?
+ */
+ static function pledgeHasFinancialTransactions($pledgeID, $pledgeStatusID) {
+ if (empty($pledgeStatusID)) {
+ //why would this happen? If we can see where it does then we can see if we should look it up
+ //but assuming from form code it CAN be empty
+ return TRUE;
+ }
+ if (self::isTransactedStatus($pledgeStatusID)) {
+ return TRUE;
+ }
+
+ return civicrm_api3('pledge_payment', 'getcount', array('pledge_id' => $pledgeID, 'status_id' => array('IN' => self::getTransactionalStatus())));
+ }
+
+ /**
+ * Does this pledge / pledge payment status mean that a financial transaction has taken place?
+ * @param int $statusID pledge status id
+ *
+ * @return bool is it a transactional status?
+ */
+ protected static function isTransactedStatus($statusID) {
+ if (!in_array($statusID, self::getNonTransactionalStatus())) {
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ /**
+ * Get array of non transactional statuses
+ * @return array non transactional status ids
+ */
+ protected static function getNonTransactionalStatus() {
+ $paymentStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
+ return array_flip(array_intersect($paymentStatus, array('Overdue', 'Pending')));
+ }
+
+ /**
+ * Get array of non transactional statuses
+ * @return array non transactional status ids
+ */
+ protected static function getTransactionalStatus() {
+ $paymentStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
+ return array_diff(array_flip($paymentStatus), self::getNonTransactionalStatus());
+ }
}