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

Add contribution id as activity source record when downloading or emailing invoice #17165

Merged
merged 2 commits into from
Apr 25, 2020
Merged
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
27 changes: 12 additions & 15 deletions CRM/Contribute/Form/Task/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
// functions call for adding activity with attachment
$fileName = self::putFile($html, $pdfFileName);
self::addActivities($subject, $contribution->contact_id, $fileName, $params);
self::addActivities($subject, $contribution->contact_id, $fileName, $params, $contribution->id);
}
elseif ($contribution->_component == 'event') {
$email = CRM_Contact_BAO_Contact::getPrimaryEmail($contribution->contact_id);
Expand All @@ -462,7 +462,7 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
// functions call for adding activity with attachment
$fileName = self::putFile($html, $pdfFileName);
self::addActivities($subject, $contribution->contact_id, $fileName, $params);
self::addActivities($subject, $contribution->contact_id, $fileName, $params, $contribution->id);
}
$invoiceTemplate->clearTemplateVars();
}
Expand Down Expand Up @@ -510,34 +510,28 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
* Gives the location with name of the file.
* @param array $params
* For invoices.
* @param int $contributionId
* Contribution Id.
*
*/
public static function addActivities($subject, $contactIds, $fileName, $params) {
public static function addActivities($subject, $contactIds, $fileName, $params, $contributionId = NULL) {
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
$config = CRM_Core_Config::singleton();
$config->doNotAttachPDFReceipt = 1;

if (!empty($params['output']) && $params['output'] == 'pdf_invoice') {
$activityTypeID = CRM_Core_PseudoConstant::getKey(
'CRM_Activity_DAO_Activity',
'activity_type_id',
'Downloaded Invoice'
);
$activityType = 'Downloaded Invoice';
}
else {
$activityTypeID = CRM_Core_PseudoConstant::getKey(
'CRM_Activity_DAO_Activity',
'activity_type_id',
'Emailed Invoice'
);
$activityType = 'Emailed Invoice';
}

$activityParams = [
'subject' => $subject,
'source_contact_id' => $userID,
'target_contact_id' => $contactIds,
'activity_type_id' => $activityTypeID,
'activity_type_id' => $activityType,
'activity_date_time' => date('YmdHis'),
'attachFile_1' => [
'uri' => $fileName,
Expand All @@ -546,7 +540,10 @@ public static function addActivities($subject, $contactIds, $fileName, $params)
'upload_date' => date('YmdHis'),
],
];
CRM_Activity_BAO_Activity::create($activityParams);
if ($contributionId) {
$activityParams['source_record_id'] = $contributionId;
}
civicrm_api3('Activity', 'create', $activityParams);
}

/**
Expand Down