comment fixes
[civicrm-core.git] / CRM / Contribute / Form / Task / Invoice.php
index 999a5724523637436b6ea4119df998ce5d38ec48..2baabaebb0d70b39a44a4f94e8f5c4cbe9d2fdf4 100644 (file)
@@ -66,8 +66,6 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
 
   /**
    * Build all the data structures needed to build the form.
-   *
-   * @return void
    */
   public function preProcess() {
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
@@ -138,9 +136,6 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
 
   /**
    * Build the form object.
-   *
-   *
-   * @return void
    */
   public function buildQuickForm() {
     $session = CRM_Core_Session::singleton();
@@ -222,9 +217,6 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
 
   /**
    * Process the form after the input has been submitted and validated.
-   *
-   *
-   * @return void
    */
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);
@@ -232,8 +224,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
   }
 
   /**
-   * Process the PDf and email with activity and attachment.
-   * on click of Print Invoices
+   * Process the PDf and email with activity and attachment on click of Print Invoices.
    *
    * @param array $contribIDs
    *   Contribution Id.
@@ -456,12 +447,13 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
         $tplParams['creditnote_id'] = $creditNoteId;
       }
 
+      $pdfFileName = "{$invoiceId}.pdf";
       $sendTemplateParams = array(
         'groupName' => 'msg_tpl_workflow_contribution',
         'valueName' => 'contribution_invoice_receipt',
         'contactId' => $contribution->contact_id,
         'tplParams' => $tplParams,
-        'PDFFilename' => 'Invoice.pdf',
+        'PDFFilename' => $pdfFileName,
       );
       $session = CRM_Core_Session::singleton();
       $contactID = $session->get('userID');
@@ -519,7 +511,8 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
 
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
         // functions call for adding activity with attachment
-        $fileName = self::putFile($html);
+        $pdfFileName = "{$invoiceId}.pdf";
+        $fileName = self::putFile($html, $pdfFileName);
         self::addActivities($subject, $contribution->contact_id, $fileName, $params);
       }
       elseif ($contribution->_component == 'event') {
@@ -533,7 +526,8 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
 
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
         // functions call for adding activity with attachment
-        $fileName = self::putFile($html);
+        $pdfFileName = "{$invoiceId}.pdf";
+        $fileName = self::putFile($html, $pdfFileName);
         self::addActivities($subject, $contribution->contact_id, $fileName, $params);
       }
 
@@ -549,13 +543,14 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
         return $html;
       }
       else {
-        CRM_Utils_PDF_Utils::html2pdf($messageInvoice, 'Invoice.pdf', FALSE, array(
+        $pdfFileName = "{$invoiceId}.pdf";
+        CRM_Utils_PDF_Utils::html2pdf($messageInvoice, $pdfFileName, FALSE, array(
           'margin_top' => 10,
           'margin_left' => 65,
           'metric' => 'px',
         ));
         // functions call for adding activity with attachment
-        $fileName = self::putFile($html);
+        $fileName = self::putFile($html, $pdfFileName);
         self::addActivities($subject, $contactIds, $fileName, $params);
 
         CRM_Utils_System::civiExit();
@@ -633,14 +628,14 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
    * @return string
    *   Name of file which is in pdf format
    */
-  static public function putFile($html) {
+  static public function putFile($html, $name = 'Invoice.pdf') {
     require_once "vendor/dompdf/dompdf/dompdf_config.inc.php";
     $doc = new DOMPDF();
     $doc->load_html($html);
     $doc->render();
     $html = $doc->output();
     $config = CRM_Core_Config::singleton();
-    $fileName = $config->uploadDir . 'Invoice.pdf';
+    $fileName = $config->uploadDir . $name;
     file_put_contents($fileName, $html);
     return $fileName;
   }