本文整理汇总了PHP中CRM_Utils_Date::intervalAdd方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Date::intervalAdd方法的具体用法?PHP CRM_Utils_Date::intervalAdd怎么用?PHP CRM_Utils_Date::intervalAdd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Date
的用法示例。
在下文中一共展示了CRM_Utils_Date::intervalAdd方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: adjustPledgePayment
/**
* @param int $pledgeID
* @param $actualAmount
* @param $pledgeScheduledAmount
* @param int $paymentContributionId
* @param int $pPaymentId
* @param int $paymentStatusID
*/
public static function adjustPledgePayment($pledgeID, $actualAmount, $pledgeScheduledAmount, $paymentContributionId = NULL, $pPaymentId = NULL, $paymentStatusID = NULL)
{
$allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if ($paymentStatusID == array_search('Cancelled', $allStatus) || $paymentStatusID == array_search('Refunded', $allStatus)) {
$query = "\nSELECT civicrm_pledge_payment.id id\nFROM civicrm_pledge_payment\nWHERE civicrm_pledge_payment.contribution_id = {$paymentContributionId}\n";
$paymentsAffected = CRM_Core_DAO::executeQuery($query);
$paymentIDs = array();
while ($paymentsAffected->fetch()) {
$paymentIDs[] = $paymentsAffected->id;
}
// Reset the affected values by the amount paid more than the scheduled amount
foreach ($paymentIDs as $key => $value) {
$payment = new CRM_Pledge_DAO_PledgePayment();
$payment->id = $value;
if ($payment->find(TRUE)) {
$payment->contribution_id = 'null';
$payment->status_id = array_search('Pending', $allStatus);
$payment->scheduled_date = NULL;
$payment->reminder_date = NULL;
$payment->scheduled_amount = $pledgeScheduledAmount;
$payment->actual_amount = 'null';
$payment->save();
}
}
// Cancel the initial paid amount
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', reset($paymentIDs), 'status_id', $paymentStatusID, 'id');
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', reset($paymentIDs), 'actual_amount', $actualAmount, 'id');
// Add new payment after the last payment for the pledge
$allPayments = self::getPledgePayments($pledgeID);
$lastPayment = array_pop($allPayments);
$pledgeFrequencyUnit = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeID, 'frequency_unit', 'id');
$pledgeFrequencyInterval = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeID, 'frequency_interval', 'id');
$pledgeScheduledDate = $lastPayment['scheduled_date'];
$scheduled_date = CRM_Utils_Date::processDate($pledgeScheduledDate);
$date['year'] = (int) substr($scheduled_date, 0, 4);
$date['month'] = (int) substr($scheduled_date, 4, 2);
$date['day'] = (int) substr($scheduled_date, 6, 2);
$newDate = date('YmdHis', mktime(0, 0, 0, $date['month'], $date['day'], $date['year']));
$ScheduledDate = CRM_Utils_Date::format(CRM_Utils_Date::intervalAdd($pledgeFrequencyUnit, $pledgeFrequencyInterval, $newDate));
$pledgeParams = array('status_id' => array_search('Pending', $allStatus), 'pledge_id' => $pledgeID, 'scheduled_amount' => $pledgeScheduledAmount, 'scheduled_date' => $ScheduledDate);
$payment = self::add($pledgeParams);
} else {
$oldestPayment = self::getOldestPledgePayment($pledgeID);
if (!$paymentContributionId) {
// means we are editing payment scheduled payment, so get the second pending to update.
$oldestPayment = self::getOldestPledgePayment($pledgeID, 2);
if ($oldestPayment['count'] != 1 && $oldestPayment['id'] == $pPaymentId) {
$oldestPayment = self::getOldestPledgePayment($pledgeID);
}
}
if ($oldestPayment) {
// not the last scheduled payment and the actual amount is less than the expected , add it to oldest pending.
if ($actualAmount != $pledgeScheduledAmount && ($actualAmount < $pledgeScheduledAmount || $actualAmount - $pledgeScheduledAmount < $oldestPayment['amount'])) {
$oldScheduledAmount = $oldestPayment['amount'];
$newScheduledAmount = $oldScheduledAmount + ($pledgeScheduledAmount - $actualAmount);
// store new amount in oldest pending payment record.
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $oldestPayment['id'], 'scheduled_amount', $newScheduledAmount);
if (CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $oldestPayment['id'], 'contribution_id', 'id')) {
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $oldestPayment['id'], 'contribution_id', $paymentContributionId);
}
} elseif ($actualAmount > $pledgeScheduledAmount && $actualAmount - $pledgeScheduledAmount >= $oldestPayment['amount']) {
// here the actual amount is greater than expected and also greater than the next installment amount, so update the next installment as complete and again add it to next subsequent pending payment
// set the actual amount of the next pending to '0', set contribution Id to current contribution Id and status as completed
$paymentId = array($oldestPayment['id']);
self::updatePledgePayments($pledgeID, array_search('Completed', $allStatus), $paymentId, 0, $paymentContributionId);
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $oldestPayment['id'], 'scheduled_amount', 0, 'id');
$oldestPayment = self::getOldestPledgePayment($pledgeID);
if (!$paymentContributionId) {
// means we are editing payment scheduled payment.
$oldestPaymentAmount = self::getOldestPledgePayment($pledgeID, 2);
}
$newActualAmount = $actualAmount - $pledgeScheduledAmount;
$newPledgeScheduledAmount = $oldestPayment['amount'];
if (!$paymentContributionId) {
$newActualAmount = $actualAmount - $pledgeScheduledAmount;
$newPledgeScheduledAmount = $oldestPaymentAmount['amount'];
// means we are editing payment scheduled payment, so update scheduled amount.
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $oldestPaymentAmount['id'], 'scheduled_amount', $newActualAmount);
}
if ($newActualAmount > 0) {
self::adjustPledgePayment($pledgeID, $newActualAmount, $newPledgeScheduledAmount, $paymentContributionId);
}
}
}
}
}
示例2: createActivity
/**
* @param $activityTypeXML
* @param array $params
*
* @return bool
* @throws CRM_Core_Exception
* @throws Exception
*/
public function createActivity($activityTypeXML, &$params)
{
$activityTypeName = (string) $activityTypeXML->name;
$activityTypes =& $this->allActivityTypes(TRUE, TRUE);
$activityTypeInfo = CRM_Utils_Array::value($activityTypeName, $activityTypes);
if (!$activityTypeInfo) {
$docLink = CRM_Utils_System::docURL2("user/case-management/setup");
CRM_Core_Error::fatal(ts('Activity type %1, found in case configuration file, is not present in the database %2', array(1 => $activityTypeName, 2 => $docLink)));
return FALSE;
}
$activityTypeID = $activityTypeInfo['id'];
if (isset($activityTypeXML->status)) {
$statusName = (string) $activityTypeXML->status;
} else {
$statusName = 'Scheduled';
}
if ($this->_isMultiClient) {
$client = $params['clientID'];
} else {
$client = array(1 => $params['clientID']);
}
//set order
$orderVal = '';
if (isset($activityTypeXML->order)) {
$orderVal = (string) $activityTypeXML->order;
}
if ($activityTypeName == 'Open Case') {
$activityParams = array('activity_type_id' => $activityTypeID, 'source_contact_id' => $params['creatorID'], 'is_auto' => FALSE, 'is_current_revision' => 1, 'subject' => CRM_Utils_Array::value('subject', $params) ? $params['subject'] : $activityTypeName, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', $statusName, 'name'), 'target_contact_id' => $client, 'medium_id' => CRM_Utils_Array::value('medium_id', $params), 'location' => CRM_Utils_Array::value('location', $params), 'details' => CRM_Utils_Array::value('details', $params), 'duration' => CRM_Utils_Array::value('duration', $params), 'weight' => $orderVal);
} else {
$activityParams = array('activity_type_id' => $activityTypeID, 'source_contact_id' => $params['creatorID'], 'is_auto' => TRUE, 'is_current_revision' => 1, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', $statusName, 'name'), 'target_contact_id' => $client, 'weight' => $orderVal);
}
//parsing date to default preference format
$params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time']);
if ($activityTypeName == 'Open Case') {
// we don't set activity_date_time for auto generated
// activities, but we want it to be set for open case.
$activityParams['activity_date_time'] = $params['activity_date_time'];
if (array_key_exists('custom', $params) && is_array($params['custom'])) {
$activityParams['custom'] = $params['custom'];
}
// Add parameters for attachments
$numAttachments = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'max_attachments');
for ($i = 1; $i <= $numAttachments; $i++) {
$attachName = "attachFile_{$i}";
if (isset($params[$attachName]) && !empty($params[$attachName])) {
$activityParams[$attachName] = $params[$attachName];
}
}
} else {
$activityDate = NULL;
//get date of reference activity if set.
if ($referenceActivityName = (string) $activityTypeXML->reference_activity) {
//we skip open case as reference activity.CRM-4374.
if (!empty($params['resetTimeline']) && $referenceActivityName == 'Open Case') {
$activityDate = $params['activity_date_time'];
} else {
$referenceActivityInfo = CRM_Utils_Array::value($referenceActivityName, $activityTypes);
if ($referenceActivityInfo['id']) {
$caseActivityParams = array('activity_type_id' => $referenceActivityInfo['id']);
//if reference_select is set take according activity.
if ($referenceSelect = (string) $activityTypeXML->reference_select) {
$caseActivityParams[$referenceSelect] = 1;
}
$referenceActivity = CRM_Case_BAO_Case::getCaseActivityDates($params['caseID'], $caseActivityParams, TRUE);
if (is_array($referenceActivity)) {
foreach ($referenceActivity as $aId => $details) {
$activityDate = CRM_Utils_Array::value('activity_date', $details);
break;
}
}
}
}
}
if (!$activityDate) {
$activityDate = $params['activity_date_time'];
}
list($activity_date, $activity_time) = CRM_Utils_Date::setDateDefaults($activityDate);
$activityDateTime = CRM_Utils_Date::processDate($activity_date, $activity_time);
//add reference offset to date.
if ((int) $activityTypeXML->reference_offset) {
$activityDateTime = CRM_Utils_Date::intervalAdd('day', (int) $activityTypeXML->reference_offset, $activityDateTime);
}
$activityParams['activity_date_time'] = CRM_Utils_Date::format($activityDateTime);
}
// if same activity is already there, skip and dont touch
$params['activityTypeID'] = $activityTypeID;
$params['activityTypeName'] = $activityTypeName;
if ($this->isActivityPresent($params)) {
return TRUE;
}
$activityParams['case_id'] = $params['caseID'];
if (!empty($activityParams['is_auto'])) {
//.........这里部分代码省略.........
示例3: testCreatePledge
public function testCreatePledge()
{
$result = $this->callAPIAndDocument('pledge', 'create', $this->_params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values'][0]['amount'], 100.0);
$this->assertEquals($result['values'][0]['installments'], 5);
$this->assertEquals($result['values'][0]['frequency_unit'], 'year');
$this->assertEquals($result['values'][0]['frequency_interval'], 5);
$this->assertEquals($result['values'][0]['frequency_day'], 15);
$this->assertEquals($result['values'][0]['original_installment_amount'], 20);
$this->assertEquals($result['values'][0]['status_id'], 2);
$this->assertEquals($result['values'][0]['create_date'], date('Ymd') . '000000');
$this->assertEquals($result['values'][0]['start_date'], date('Ymd') . '000000');
$this->assertAPISuccess($result);
$payments = $this->callAPISuccess('PledgePayment', 'Get', array('pledge_id' => $result['id'], 'sequential' => 1));
$this->assertAPISuccess($payments);
$this->assertEquals($payments['count'], 5);
$shouldBeDate = CRM_Utils_Date::format(CRM_Utils_Date::intervalAdd('year', 5 * 4, $this->scheduled_date), "-");
$this->assertEquals(substr($shouldBeDate, 0, 10), substr($payments['values'][4]['scheduled_date'], 0, 10));
$pledgeID = array('id' => $result['id']);
$pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID);
}
示例4: create
static function create($params)
{
require_once 'CRM/Contribute/PseudoConstant.php';
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$date = array();
$scheduled_date = CRM_Utils_Date::processDate($params['scheduled_date']);
$date['year'] = (int) substr($scheduled_date, 0, 4);
$date['month'] = (int) substr($scheduled_date, 4, 2);
$date['day'] = (int) substr($scheduled_date, 6, 2);
$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
//calculation of schedule date according to frequency day of period
//frequency day is not applicable for daily installments
if ($params['frequency_unit'] != 'day') {
if ($params['frequency_unit'] != 'week') {
//for month use day of next month & for year use day of month Jan of next year as next payment date
$date['day'] = $params['frequency_day'];
if ($params['frequency_unit'] == 'year') {
$date['month'] = '1';
}
} else {
if ($params['frequency_unit'] == 'week') {
//for week calculate day of week ie. Sunday,Monday etc. as next payment date
$dayOfWeek = date('w', mktime(0, 0, 0, $date['month'], $date['day'], $date['year']));
$frequencyDay = $params['frequency_day'] - $dayOfWeek;
$scheduleDate = explode("-", date('n-j-Y', mktime(0, 0, 0, $date['month'], $date['day'] + $frequencyDay, $date['year'])));
$date['month'] = $scheduleDate[0];
$date['day'] = $scheduleDate[1];
$date['year'] = $scheduleDate[2];
}
}
}
//calculate the scheduled date for every installment
$now = date('Ymd') . '000000';
$statues = $prevScheduledDate = array();
$prevScheduledDate[1] = $scheduled_date;
if (CRM_Utils_Date::overdue($prevScheduledDate[1], $now)) {
$statues[1] = array_search('Overdue', $contributionStatus);
} else {
$statues[1] = array_search('Pending', $contributionStatus);
}
$newDate = date('YmdHis', mktime(0, 0, 0, $date['month'], $date['day'], $date['year']));
for ($i = 1; $i < $params['installments']; $i++) {
$prevScheduledDate[$i + 1] = CRM_Utils_Date::format(CRM_Utils_Date::intervalAdd($params['frequency_unit'], $i * $params['frequency_interval'], $newDate));
if (CRM_Utils_Date::overdue($prevScheduledDate[$i + 1], $now)) {
$statues[$i + 1] = array_search('Overdue', $contributionStatus);
} else {
$statues[$i + 1] = array_search('Pending', $contributionStatus);
}
}
if ($params['installment_amount']) {
$params['scheduled_amount'] = $params['installment_amount'];
} else {
$params['scheduled_amount'] = round($params['amount'] / $params['installments'], 2);
}
for ($i = 1; $i <= $params['installments']; $i++) {
//calculate the scheduled amount for every installment.
if ($i == $params['installments']) {
$params['scheduled_amount'] = $params['amount'] - ($i - 1) * $params['scheduled_amount'];
}
if (!isset($params['contribution_id']) && $params['installments'] > 1) {
$params['status_id'] = $statues[$i];
}
$params['scheduled_date'] = $prevScheduledDate[$i];
$payment = self::add($params);
if (is_a($payment, 'CRM_Core_Error')) {
$transaction->rollback();
return $payment;
}
// we should add contribution id to only first payment record
if (isset($params['contribution_id'])) {
unset($params['contribution_id']);
}
}
//update pledge status
self::updatePledgePaymentStatus($params['pledge_id']);
$transaction->commit();
return $payment;
}
示例5: createFollowupActivity
/**
* Function to create a follow up a given activity
*
* @activityId int activity id of parent activity
* @param array $activity details
*
* @access public
*/
static function createFollowupActivity($activityId, $params)
{
if (!$activityId) {
return;
}
$session =& CRM_Core_Session::singleton();
$followupParams = array();
$followupParams['parent_id'] = $activityId;
$followupParams['source_contact_id'] = $session->get('userID');
$followupParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name');
$followupParams['activity_type_id'] = $params['followup_activity_type_id'];
// Get Subject of Follow-up Activiity, CRM-4491
$followupParams['subject'] = CRM_Utils_Array::value('followup_activity_subject', $params);
//create target contact for followup
if (CRM_Utils_Array::value('target_contact_id', $params)) {
$followupParams['target_contact_id'] = $params['target_contact_id'];
}
$currentDate = implode(' ', CRM_Utils_Date::setDateDefaults());
$followupDate = CRM_Utils_Date::intervalAdd($params['interval_unit'], $params['interval'], $currentDate);
$followupParams['activity_date_time'] = CRM_Utils_Date::format($followupDate);
$followupActivity = self::create($followupParams);
return $followupActivity;
}
示例6: updatePledgePaymentStatus
/**
* update Pledge Payment Status
*
* @param int $pledgeID, id of pledge
* @param array $paymentIDs, ids of pledge payment
* @param int $paymentStatus, payment status
* @param int $pledgeStatus, pledge status
*
* @return int $newStatus, updated status id (or 0)
*/
function updatePledgePaymentStatus($pledgeID, $paymentIDs = null, $paymentStatusID = null, $pledgeStatusID = null, $actualAmount = 0, $adjustTotalAmount = false, $isScriptUpdate = false)
{
//get all status
require_once 'CRM/Contribute/PseudoConstant.php';
$allStatus = CRM_Contribute_PseudoConstant::contributionStatus(null, 'name');
// if we get do not get contribution id means we are editing the scheduled payment.
if (!empty($paymentIDs)) {
$payments = implode(',', $paymentIDs);
$paymentContributionId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Payment', $payments, 'contribution_id', 'id');
if (!$paymentContributionId) {
$editScheduled = true;
}
}
// if payment ids are passed, we update payment table first, since payments statuses are not dependent on pledge status
if ((!empty($paymentIDs) || $pledgeStatusID == array_search('Cancelled', $allStatus)) && !$editScheduled) {
if ($pledgeStatusID == array_search('Cancelled', $allStatus)) {
$paymentStatusID = $pledgeStatusID;
}
self::updatePledgePayments($pledgeID, $paymentStatusID, $paymentIDs, $actualAmount, $paymentContributionId, $isScriptUpdate);
}
if (!empty($paymentIDs) && $actualAmount) {
$payments = implode(',', $paymentIDs);
$pledgeScheduledAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Payment', $payments, 'scheduled_amount', 'id');
$pledgeStatusId = self::calculatePledgeStatus($pledgeID);
// Actual Pledge Amount
$actualPledgeAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeID, 'amount', 'id');
// while editing scheduled we need to check if we are editing last pending
if (!$paymentContributionId) {
$checkPendingCount = self::getOldestPledgePayment($pledgeID, 2);
if ($checkPendingCount['count'] == 1) {
$lastPending = true;
}
}
// check if this is the last payment and adjust the actual amount.
if ($pledgeStatusId && $pledgeStatusId == array_search('Completed', $allStatus) || $lastPending) {
// last scheduled payment
if ($actualAmount < $pledgeScheduledAmount) {
// actual amount is less than the scheduled amount, so enter new pledge payment record
$pledgeFrequencyUnit = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeID, 'frequency_unit', 'id');
$pledgeFrequencyInterval = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeID, 'frequency_interval', 'id');
$pledgeScheduledDate = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Payment', $payments, 'scheduled_date', 'id');
$scheduled_date = CRM_Utils_Date::processDate($pledgeScheduledDate);
$date['year'] = (int) substr($scheduled_date, 0, 4);
$date['month'] = (int) substr($scheduled_date, 4, 2);
$date['day'] = (int) substr($scheduled_date, 6, 2);
$newDate = date('YmdHis', mktime(0, 0, 0, $date['month'], $date['day'], $date['year']));
$ScheduledDate = CRM_Utils_Date::format(CRM_Utils_Date::intervalAdd($pledgeFrequencyUnit, $pledgeFrequencyInterval, $newDate));
$pledgeParams = array('status_id' => array_search('Pending', $allStatus), 'pledge_id' => $pledgeID, 'scheduled_amount' => $pledgeScheduledAmount - $actualAmount, 'scheduled_date' => $ScheduledDate);
$payment = self::add($pledgeParams);
// while editing schedule, after adding a new pledge payemnt update the scheduled amount of the current payment
if (!$paymentContributionId) {
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_Payment', $payments, 'scheduled_amount', $actualAmount);
}
} else {
$adjustTotalAmount = true;
}
} elseif (!$adjustTotalAmount) {
// not last schedule amount and also not selected to adjust Total
$paymentContributionId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Payment', $payments, 'contribution_id', 'id');
self::adjustPledgePayment($pledgeID, $actualAmount, $pledgeScheduledAmount, $paymentContributionId, $payments);
// while editing schedule, after adding a new pledge payemnt update the scheduled amount of the current payment
if (!$paymentContributionId) {
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_Payment', $payments, 'scheduled_amount', $actualAmount);
}
// after adjusting all payments check if the actual amount was greater than the actual remaining amount , if so then update the total pledge amount.
$pledgeStatusId = self::calculatePledgeStatus($pledgeID);
$balanceQuery = "\n SELECT sum( civicrm_pledge_payment.actual_amount )\n FROM civicrm_pledge_payment\n WHERE civicrm_pledge_payment.pledge_id = %1\n AND civicrm_pledge_payment.status_id = 1\n ";
$totalPaidParams = array(1 => array($pledgeID, 'Integer'));
$totalPaidAmount = CRM_Core_DAO::singleValueQuery($balanceQuery, $totalPaidParams);
$remainingTotalAmount = $actualPledgeAmount - $totalPaidAmount;
if ($pledgeStatusId && $pledgeStatusId == array_search('Completed', $allStatus) && ($actualAmount > $remainingTotalAmount || $actualAmount >= $actualPledgeAmount)) {
$totalAmountClause = ", civicrm_pledge.amount = {$totalPaidAmount}";
}
}
if ($adjustTotalAmount) {
$newTotalAmount = $actualPledgeAmount + ($actualAmount - $pledgeScheduledAmount);
$totalAmountClause = ", civicrm_pledge.amount = {$newTotalAmount}";
if (!$paymentContributionId) {
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_Payment', $payments, 'scheduled_amount', $actualAmount);
}
}
}
$cancelDateClause = $endDateClause = null;
//update pledge and payment status if status is Completed/Cancelled.
if ($pledgeStatusID && $pledgeStatusID == array_search('Cancelled', $allStatus)) {
$paymentStatusID = $pledgeStatusID;
$cancelDateClause = ", civicrm_pledge.cancel_date = CURRENT_TIMESTAMP ";
} else {
// get pledge status
$pledgeStatusID = self::calculatePledgeStatus($pledgeID);
//.........这里部分代码省略.........
示例7: createActivity
function createActivity($activityTypeXML, &$params)
{
$activityTypeName = (string) $activityTypeXML->name;
$activityTypes =& $this->allActivityTypes();
$activityTypeInfo = CRM_Utils_Array::value($activityTypeName, $activityTypes);
if (!$activityTypeInfo) {
require_once 'CRM/Utils/System.php';
$docLink = CRM_Utils_System::docURL2("CiviCase Configuration");
CRM_Core_Error::fatal(ts('Activity type %1, found in case configuration file, is not present in the database %2', array(1 => $activityTypeName, 2 => $docLink)));
return false;
}
$activityTypeID = $activityTypeInfo['id'];
if (isset($activityTypeXML->status)) {
$statusName = (string) $activityTypeXML->status;
} else {
$statusName = 'Scheduled';
}
require_once 'CRM/Core/OptionGroup.php';
if ($activityTypeName == 'Open Case') {
$activityParams = array('activity_type_id' => $activityTypeID, 'source_contact_id' => $params['creatorID'], 'is_auto' => false, 'is_current_revision' => 1, 'subject' => CRM_Utils_Array::value('subject', $params) ? $params['subject'] : $activityTypeName, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', $statusName, 'name'), 'target_contact_id' => $params['clientID'], 'medium_id' => CRM_Utils_Array::value('medium_id', $params), 'location' => CRM_Utils_Array::value('location', $params), 'details' => CRM_Utils_Array::value('details', $params), 'duration' => CRM_Utils_Array::value('duration', $params));
} else {
$activityParams = array('activity_type_id' => $activityTypeID, 'source_contact_id' => $params['creatorID'], 'is_auto' => true, 'is_current_revision' => 1, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', $statusName, 'name'), 'target_contact_id' => $params['clientID']);
}
if ($activityTypeName == 'Open Case') {
// we don't set activity_date_time for auto generated
// activities, but we want it to be set for open case.
$activityParams['activity_date_time'] = $params['activity_date_time'];
if (array_key_exists('custom', $params) && is_array($params['custom'])) {
$activityParams['custom'] = $params['custom'];
}
} else {
$activityDate = null;
//get date of reference activity if set.
if ($referenceActivityName = (string) $activityTypeXML->reference_activity) {
//we skip open case as reference activity.CRM-4374.
if (CRM_Utils_Array::value('resetTimeline', $params) && $referenceActivityName == 'Open Case') {
$activityDate = $params['activity_date_time'];
} else {
$referenceActivityInfo = CRM_Utils_Array::value($referenceActivityName, $activityTypes);
if ($referenceActivityInfo['id']) {
$caseActivityParams = array('activity_type_id' => $referenceActivityInfo['id']);
//if reference_select is set take according activity.
if ($referenceSelect = (string) $activityTypeXML->reference_select) {
$caseActivityParams[$referenceSelect] = 1;
}
require_once 'CRM/Case/BAO/Case.php';
$referenceActivity = CRM_Case_BAO_Case::getCaseActivityDates($params['caseID'], $caseActivityParams, true);
if (is_array($referenceActivity)) {
foreach ($referenceActivity as $aId => $details) {
$activityDate = CRM_Utils_Array::value('activity_date', $details);
break;
}
}
}
}
}
if (!$activityDate) {
$activityDate = $params['activity_date_time'];
}
$datetime = new DateTime($activityDate);
$activityDateTime = CRM_Utils_Date::unformat($datetime->format('Y:m:d:H:i:s'), ':');
//add reference offset to date.
if ((int) $activityTypeXML->reference_offset) {
$activityDateTime = CRM_Utils_Date::intervalAdd('day', (int) $activityTypeXML->reference_offset, $activityDateTime);
}
$activityParams['activity_date_time'] = CRM_Utils_Date::format($activityDateTime);
}
// if same activity is already there, skip and dont touch
$params['activityTypeID'] = $activityTypeID;
$params['activityTypeName'] = $activityTypeName;
if ($this->isActivityPresent($params)) {
return true;
}
$activityParams['case_id'] = $params['caseID'];
if (CRM_Utils_Array::value('is_auto', $activityParams)) {
$activityParams['skipRecentView'] = true;
}
require_once 'CRM/Activity/BAO/Activity.php';
$activity = CRM_Activity_BAO_Activity::create($activityParams);
if (!$activity) {
CRM_Core_Error::fatal();
return false;
}
// create case activity record
$caseParams = array('activity_id' => $activity->id, 'case_id' => $params['caseID']);
require_once 'CRM/Case/BAO/Case.php';
CRM_Case_BAO_Case::processCaseActivity($caseParams);
return true;
}
示例8: calculateNextScheduledDate
/**
* Calculate next scheduled pledge payment date. Function calculates next pledge payment date.
*
* @param array params - must include frequency unit & frequency interval
* @param int paymentNo number of payment in sequence (e.g. 1 for first calculated payment (treat initial payment as 0)
* @param datestring basePaymentDate - date to calculate payments from. This would normally be the
* first day of the pledge (default) & is calculated off the 'scheduled date' param. Returned date will
* be equal to basePaymentDate normalised to fit the 'pledge pattern' + number of installments
*
* @return formatted date
*
*/
static function calculateNextScheduledDate(&$params, $paymentNo, $basePaymentDate = NULL)
{
if (!$basePaymentDate) {
$basePaymentDate = self::calculateBaseScheduleDate($params);
}
return CRM_Utils_Date::format(CRM_Utils_Date::intervalAdd($params['frequency_unit'], $paymentNo * $params['frequency_interval'], $basePaymentDate));
}