Refactor redundant code with reusable function
[civicrm-core.git] / CRM / Contribute / Form / Task / Invoice.php
index 1fb1874ebf82f34c8346e92e7a25eebd25fa66e6..88c68fa11a8a536451a04f397de46f2ae5a43b9f 100644 (file)
@@ -303,11 +303,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
 
       if ($contribution->contribution_status_id == $refundedStatusId || $contribution->contribution_status_id == $cancelledStatusId) {
         if (is_null($contribution->creditnote_id)) {
-          $query = "select count(creditnote_id) as creditnote_number from civicrm_contribution";
-          $dao = CRM_Core_DAO::executeQuery($query);
-          $dao->fetch();
-          $creditNoteId = CRM_Utils_Array::value('credit_notes_prefix', $prefixValue) . "" . ($dao->creditnote_number + 1);
-          CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'creditnote_id', $creditNoteId);
+          $creditNoteId = CRM_Contribute_BAO_Contribution::createCreditNoteId($contribution->id);
         }
         else {
           $creditNoteId = $contribution->creditnote_id;