*/
public $_invoiceTemplate;
+ /**
+ * selected output
+ */
+ public $_selectedOutput;
+
/**
* build all the data structures needed to build the form
*
$this->_componentClause = " civicrm_contribution.id IN ( $id ) ";
$this->_single = TRUE;
$this->assign('totalSelectedContributions', 1);
+
+ // set the redirection after actions
+ $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
+ $url = CRM_Utils_System::url('civicrm/contact/view/contribution',
+ "action=view&reset=1&id={$id}&cid={$contactId}&context=contribution&selectedChild=contribute"
+ );
+
+ CRM_Core_Session::singleton()->pushUserContext($url);
}
else {
parent::preProcess();
);
CRM_Utils_System::appendBreadCrumb($breadCrumb);
- if (in_array("email", $this->urlPath)) {
+
+ $this->_selectedOutput = CRM_Utils_Request::retrieve('select', 'String', $this);
+ $this->assign('selectedOutput', $this->_selectedOutput);
+
+ if ($this->_selectedOutput == 'email') {
CRM_Utils_System::setTitle(ts('Email Invoice'));
}
else {
$fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]);
}
$fromEmail = CRM_Utils_Array::crmArrayMerge($emails, $fromEmailAddress);
-
- $this->addElement('radio', 'output', NULL, ts('Email Invoice'), 'email_invoice');
- $this->addElement('radio', 'output', NULL, ts('PDF Invoice'), 'pdf_invoice');
$this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') + $fromEmail);
- $this->addFormRule(array('CRM_Contribute_Form_Task_Invoice', 'formRule'));
+ if ($this->_selectedOutput != 'email') {
+ $this->addElement('radio', 'output', NULL, ts('Email Invoice'), 'email_invoice');
+ $this->addElement('radio', 'output', NULL, ts('PDF Invoice'), 'pdf_invoice');
+ $this->addRule('output', ts('Selection required'), 'required');
+ $this->addFormRule(array('CRM_Contribute_Form_Task_Invoice', 'formRule'));
+ }
+ else {
+ $this->addRule('from_email_address', ts('From Email Address is required'), 'required');
+ }
+
$this->addWysiwyg('email_comment', ts('If you would like to add personal message to email please add it here. (If sending to more then one receipient the same message will be sent to each contact.)'), array(
'rows' => 2,
'cols' => 40
));
- if (in_array("email", $this->urlPath)) {
+ if ($this->_selectedOutput == 'email') {
$this->addButtons(array(
array(
- 'type' => 'next',
+ 'type' => 'upload',
'name' => ts('Email Invoice'),
'isDefault' => TRUE,
),
array(
- 'type' => 'back',
+ 'type' => 'cancel',
'name' => ts('Cancel'),
),
)
else {
$this->addButtons(array(
array(
- 'type' => 'next',
+ 'type' => 'upload',
'name' => ts('Process Invoice(s)'),
'isDefault' => TRUE,
),
array(
- 'type' => 'back',
+ 'type' => 'cancel',
'name' => ts('Cancel'),
),
)
*/
static function formRule($values) {
$errors = array();
- if (!$values['from_email_address']) {
- if (in_array("Email Invoice", $values)) {
- $errors['from_email_address'] = ts("From Email Address is required");
- }
- else {
- if (in_array("email_invoice", $values)) {
- $errors['from_email_address'] = ts("From Email Address is required");
- }
- else {
- $errors['output'] = ts("Selection required");
- }
- }
+
+ if ($values['output'] == 'email_invoice' && empty($values['from_email_address'])) {
+ $errors['from_email_address'] = ts("From Email Address is required");
}
+
return $errors;
}
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
- $this->printPDF($this->_contributionIds, $params, $this->_contactIds);
+ $this->printPDF($this->_contributionIds, $params, $this->_contactIds, $this);
}
/**
* on click of Print Invoices
*
* @param array $contribIDs Contribution Id
- * @param array $params for pdf or email invoices
+ * @param array $params associated array of submitted values
* @param array $contactIds Contact Id
+ * @param object $form form object
* @static
*
*/
- static function printPDF($contribIDs, $params, $contactIds) {
+ static function printPDF($contribIDs, &$params, $contactIds, &$form) {
// get all the details needed to generate a invoice
$messageInvoice = array();
$invoiceTemplate = CRM_Core_Smarty::singleton();
$addressParams = array('contact_id' => $contribution->contact_id);
$addressDetails = CRM_Core_BAO_Address::getValues($addressParams);
- // to get billing address if present
+ // to get billing address if present
$billingAddress = array();
foreach ($addressDetails as $key => $address) {
if ((isset($address['is_billing']) && $address['is_billing'] == 1) && (isset($address['is_primary']) && $address['is_primary'] == 1) && $address['contact_id'] == $contribution->contact_id) {
if ($input['component'] == 'contribute') {
$eid = $contribID;
$etable = 'contribution';
+ $lineItem = CRM_Price_BAO_LineItem::getLineItems($eid, $etable, NULL, TRUE, TRUE);
}
else {
$eid = $contribution->_relatedObjects['participant']->id;
$etable = 'participant';
+ $lineItem = CRM_Price_BAO_LineItem::getLineItems($eid, $etable);
}
- //TO DO: Need to do changes for partially paid to display amount due on PDF invoice
+ //TO DO: Need to do changes for partially paid to display amount due on PDF invoice
$amountDue = ($input['amount'] - $input['amount']);
- // retreiving the subtotal and sum of same tax_rate
- $lineItem = CRM_Price_BAO_LineItem::getLineItems($eid, $etable);
+ // retreiving the subtotal and sum of same tax_rate
$dataArray = array();
$subTotal = 0;
foreach ($lineItem as $entity_id => $taxRate) {
'id' => $contribution->id,
'source' => $source,
'invoice_id' => $invoiceId,
- 'imageUploadURL' => $config->imageUploadURL,
+ 'resourceBase' => $config->userFrameworkResourceURL,
'defaultCurrency' => $config->defaultCurrency,
'amount' => $contribution->total_amount,
'amountDue' => $amountDue,
'domain_email' => CRM_Utils_Array::value('email', CRM_Utils_Array::value('1', $locationDefaults['email'])),
'domain_phone' => CRM_Utils_Array::value('phone', CRM_Utils_Array::value('1', $locationDefaults['phone'])),
);
+
if (isset($creditNoteId)) {
$tplParams['creditnote_id'] = $creditNoteId;
}
+
$sendTemplateParams = array(
'groupName' => 'msg_tpl_workflow_contribution',
'valueName' => 'contribution_invoice_receipt',
));
// functions call for adding activity with attachment
$fileName = self::putFile($html);
- self::addActivities($subject, $contactIds, $fileName, $params['output']);
+ self::addActivities($subject, $contactIds, $fileName, $params);
CRM_Utils_System::civiExit();
}
* @param string $subject Activity subject
* @param array $contactIds Contact Id
* @param string $fileName gives the location with name of the file
- * @param array $output for invoices
+ * @param array $params for invoices
*
* @access public
* @static
*/
- static public function addActivities($subject, $contactIds, $fileName, $output) {
+ static public function addActivities($subject, $contactIds, $fileName, $params) {
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
$config = CRM_Core_Config::singleton();
$config->doNotAttachPDFReceipt = 1;
- if ($output['output'] == 'email_invoice' || (is_array($output) && array_key_exists("from_email_address", $output))) {
+
+ if (!empty($params['output']) && $params['output'] == 'pdf_invoice') {
$activityTypeID = CRM_Core_OptionGroup::getValue('activity_type',
- 'Emailed Invoice',
+ 'Downloaded Invoice',
'name'
);
}
- else {
+ else{
$activityTypeID = CRM_Core_OptionGroup::getValue('activity_type',
- 'Downloaded Invoice',
+ 'Emailed Invoice',
'name'
);
}
+
$activityParams = array(
'subject' => $subject,
'source_contact_id' => $userID,
file_put_contents($fileName, $html);
return $fileName;
}
+
+ /**
+ * Callback to perform action on Print Invoice button.
+ */
+ static function getPrintPDF() {
+ $contributionId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject, FALSE);
+ $contributionIDs = array($contributionId);
+ $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE);
+ $params = array('output' => 'pdf_invoice');
+ CRM_Contribute_Form_Task_Invoice::printPDF($contributionIDs, $params, $contactId, CRM_Core_DAO::$_nullObject);
+ }
}