Merge remote-tracking branch 'rajgo94/mailingui-new' into master-abtest
[civicrm-core.git] / CRM / Contribute / Form / Task / Invoice.php
index bed09c42aa3acda4da798504ab8c3857d204cb46..e0a413841f99008072549905d4e32c77036d4af7 100644 (file)
@@ -84,6 +84,14 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
       $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();
@@ -188,15 +196,15 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
       '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'),
           ),
         )
@@ -205,12 +213,12 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
     else {
       $this->addButtons(array(
           array(
-            'type' => 'next',
+            'type' => 'upload',
             'name' => ts('Process Invoice(s)'),
             'isDefault' => TRUE,
           ),
           array(
-            'type' => 'back',
+            'type' => 'cancel',
             'name' => ts('Cancel'),
           ),
         )
@@ -248,7 +256,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
    */
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);
-    $this->printPDF($this->_contributionIds, $params, $this->_contactIds);
+    $this->printPDF($this->_contributionIds, $params, $this->_contactIds, $this);
   }
 
   /**
@@ -257,12 +265,13 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
    * 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();
@@ -308,7 +317,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
       $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) {
@@ -348,10 +357,10 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
         $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 
+      // retreiving the subtotal and sum of same tax_rate
       $dataArray = array();
       $subTotal = 0;
       foreach ($lineItem as $entity_id => $taxRate) {
@@ -473,7 +482,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
       if (isset($creditNoteId)) {
         $tplParams['creditnote_id'] = $creditNoteId;
       }
-      
+
       $sendTemplateParams = array(
         'groupName' => 'msg_tpl_workflow_contribution',
         'valueName' => 'contribution_invoice_receipt',
@@ -659,5 +668,16 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
     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);
+  }
 }