CRM-20387 - Add invoice_number field for human readable contribution invoice
authorColeman Watts <coleman@civicrm.org>
Wed, 3 May 2017 21:15:28 +0000 (17:15 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 23 Jun 2017 12:40:07 +0000 (08:40 -0400)
13 files changed:
CRM/Contribute/BAO/Query.php
CRM/Contribute/DAO/Contribution.php
CRM/Contribute/Form/Task/Invoice.php
CRM/Upgrade/4.7.22.msg_template/civicrm_msg_template.tpl [new file with mode: 0644]
CRM/Upgrade/4.7.22.msg_template/message_templates/contribution_invoice_receipt_html.tpl [new file with mode: 0644]
CRM/Upgrade/Incremental/php/FourSeven.php
CRM/Upgrade/Incremental/sql/4.7.22.mysql.tpl
api/v3/examples/Contribution/Create.php
templates/CRM/Contribute/Form/ContributionView.tpl
templates/CRM/Contribute/Form/Search/Common.tpl
tests/phpunit/api/v3/ContributionTest.php
xml/schema/Contribute/Contribution.xml
xml/templates/message_templates/contribution_invoice_receipt_html.tpl

index 185f38cfe75324c93d46ff137b5de06fc2a0fc3c..e402e7c213e2d263ff0d4e9ff70713f1e6a41cd3 100644 (file)
@@ -232,6 +232,7 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query {
         CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
         $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.$name", 'IN', array_keys($financialTypes), 'String');
       case 'invoice_id':
+      case 'invoice_number':
       case 'payment_instrument_id':
       case 'contribution_payment_instrument_id':
       case 'contribution_page_id':
@@ -943,7 +944,7 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query {
 
     // Add field for transaction ID search
     $form->addElement('text', 'contribution_trxn_id', ts("Transaction ID"));
-    $form->addElement('text', 'invoice_id', ts("Invoice ID"));
+    $form->addElement('text', 'invoice_number', ts("Invoice Number"));
     $form->addElement('text', 'contribution_check_number', ts('Check Number'));
 
     // Add field for pcp display in roll search
index e0285ac385e66aeaf9bbaf4658817ee070ac16d3..6744a69fa949a4eef644b9c6dfcbda23c77158da 100644 (file)
@@ -30,7 +30,7 @@
  *
  * Generated from xml/schema/CRM/Contribute/Contribution.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:59c3615cae90b0580f7d77aa8343b21f)
+ * (GenCodeChecksum:45a20d00d01766a61687cbac5cef1482)
  */
 require_once 'CRM/Core/DAO.php';
 require_once 'CRM/Utils/Type.php';
@@ -122,6 +122,12 @@ class CRM_Contribute_DAO_Contribution extends CRM_Core_DAO {
    * @var string
    */
   public $invoice_id;
+  /**
+   * Human readable invoice number
+   *
+   * @var string
+   */
+  public $invoice_number;
   /**
    * 3 character string, value from config setting or input via user.
    *
@@ -487,7 +493,7 @@ class CRM_Contribute_DAO_Contribution extends CRM_Core_DAO {
         'invoice_id' => array(
           'name' => 'invoice_id',
           'type' => CRM_Utils_Type::T_STRING,
-          'title' => ts('Invoice ID') ,
+          'title' => ts('Invoice Reference') ,
           'description' => 'unique invoice id, system generated or passed in',
           'maxlength' => 255,
           'size' => CRM_Utils_Type::HUGE,
@@ -504,6 +510,26 @@ class CRM_Contribute_DAO_Contribution extends CRM_Core_DAO {
             'type' => 'Text',
           ) ,
         ) ,
+        'invoice_number' => array(
+          'name' => 'invoice_number',
+          'type' => CRM_Utils_Type::T_STRING,
+          'title' => ts('Invoice Number') ,
+          'description' => 'Human readable invoice number',
+          'maxlength' => 255,
+          'size' => CRM_Utils_Type::HUGE,
+          'import' => true,
+          'where' => 'civicrm_contribution.invoice_number',
+          'headerPattern' => '/invoice(.?number)?/i',
+          'dataPattern' => '',
+          'export' => true,
+          'table_name' => 'civicrm_contribution',
+          'entity' => 'Contribution',
+          'bao' => 'CRM_Contribute_BAO_Contribution',
+          'localizable' => 0,
+          'html' => array(
+            'type' => 'Text',
+          ) ,
+        ) ,
         'currency' => array(
           'name' => 'currency',
           'type' => CRM_Utils_Type::T_STRING,
index 5500804b719ce71eaa3b2c8366aa7083cb2e9f30..121bf65ec0fcac78f12f51aca6bae58307c82b7c 100644 (file)
@@ -312,7 +312,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
           $creditNoteId = $contribution->creditnote_id;
         }
       }
-      $invoiceId = CRM_Utils_Array::value('invoice_prefix', $prefixValue) . "" . $contribution->id;
+      $invoiceNumber = CRM_Utils_Array::value('invoice_prefix', $prefixValue) . "" . $contribution->id;
 
       //to obtain due date for PDF invoice
       $contributionReceiveDate = date('F j,Y', strtotime(date($input['receive_date'])));
@@ -425,7 +425,8 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
         'component' => $input['component'],
         'id' => $contribution->id,
         'source' => $source,
-        'invoice_id' => $invoiceId,
+        'invoice_number' => $invoiceNumber,
+        'invoice_id' => $contribution->invoice_id,
         'resourceBase' => $config->userFrameworkResourceURL,
         'defaultCurrency' => $config->defaultCurrency,
         'amount' => $contribution->total_amount,
@@ -468,7 +469,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
         $tplParams['creditnote_id'] = $creditNoteId;
       }
 
-      $pdfFileName = "{$invoiceId}.pdf";
+      $pdfFileName = "{$invoiceNumber}.pdf";
       $sendTemplateParams = array(
         'groupName' => 'msg_tpl_workflow_contribution',
         'valueName' => 'contribution_invoice_receipt',
@@ -536,7 +537,7 @@ 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
-        $pdfFileName = "{$invoiceId}.pdf";
+        $pdfFileName = "{$invoiceNumber}.pdf";
         $fileName = self::putFile($html, $pdfFileName);
         self::addActivities($subject, $contribution->contact_id, $fileName, $params);
       }
@@ -551,12 +552,12 @@ 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
-        $pdfFileName = "{$invoiceId}.pdf";
+        $pdfFileName = "{$invoiceNumber}.pdf";
         $fileName = self::putFile($html, $pdfFileName);
         self::addActivities($subject, $contribution->contact_id, $fileName, $params);
       }
 
-      CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'invoice_id', $invoiceId);
+      CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'invoice_number', $invoiceNumber);
       $invoiceTemplate->clearTemplateVars();
     }
 
@@ -565,7 +566,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
         return $html;
       }
       else {
-        $pdfFileName = "{$invoiceId}.pdf";
+        $pdfFileName = "{$invoiceNumber}.pdf";
         CRM_Utils_PDF_Utils::html2pdf($messageInvoice, $pdfFileName, FALSE, array(
           'margin_top' => 10,
           'margin_left' => 65,
diff --git a/CRM/Upgrade/4.7.22.msg_template/civicrm_msg_template.tpl b/CRM/Upgrade/4.7.22.msg_template/civicrm_msg_template.tpl
new file mode 100644 (file)
index 0000000..60cb7df
--- /dev/null
@@ -0,0 +1,16 @@
+{php}
+  $dir = SMARTY_DIR . '/../../CRM/Upgrade/4.7.22.msg_template/message_templates';
+  $templates = array();
+  foreach (preg_grep('/\.tpl$/', scandir($dir)) as $filename) {
+    $parts = explode('_', basename($filename, '.tpl'));
+    $templates[] = array('type' => array_pop($parts), 'name' => implode('_', $parts), 'filename' => "$dir/$filename");
+  }
+  $this->assign('templates', $templates);
+{/php}
+
+{foreach from=$templates item=tpl}
+  {fetch assign=content file=$tpl.filename}
+  SELECT @workflow_id := MAX(id) FROM civicrm_option_value WHERE name = '{$tpl.name}';
+  SELECT @content := msg_{$tpl.type} FROM civicrm_msg_template WHERE workflow_id = @workflow_id AND is_reserved = 1 LIMIT 1;
+  UPDATE civicrm_msg_template SET msg_{$tpl.type} = '{$content|escape:"quotes"}' WHERE workflow_id = @workflow_id AND (is_reserved = 1 OR (is_default = 1 AND msg_{$tpl.type} = @content));
+{/foreach}
diff --git a/CRM/Upgrade/4.7.22.msg_template/message_templates/contribution_invoice_receipt_html.tpl b/CRM/Upgrade/4.7.22.msg_template/message_templates/contribution_invoice_receipt_html.tpl
new file mode 100644 (file)
index 0000000..75d7bf0
--- /dev/null
@@ -0,0 +1,458 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns = "http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv = "Content-Type" content="text/html; charset=UTF-8" />
+      <title></title>
+  </head>
+  <body>
+    <table style = "margin-top:2px;padding-left:7px;">
+      <tr>
+        <td><img src = "{$resourceBase}/i/civi99.png" height = "34px" width = "99px"></td>
+      </tr>
+    </table>
+    <center>
+      <table style = "padding-right:19px;font-family: Arial, Verdana, sans-serif;" width = "500" height = "100" border = "0" cellpadding = "2" cellspacing = "1">
+        <tr>
+          <td style = "padding-left:15px;" ><b><font size = "4" align = "center">{ts}INVOICE{/ts}</font></b></td>
+          <td colspan = "1"></td>
+          <td style = "padding-left:70px;"><b><font size = "1" align = "center" >{ts}Invoice Date:{/ts}</font></b></td>
+          <td><font size = "1" align = "right">{$domain_organization}</font></td>
+        </tr>
+        <tr>
+          {if $organization_name}
+            <td style = "padding-left:17px;"><font size = "1" align = "center" >{$display_name}  ({$organization_name})</font></td>
+          {else}
+            <td style = "padding-left:15px;"><font size = "1" align = "center" >{$display_name}</font></td>
+          {/if}
+          <td colspan = "1"></td>
+          <td style = "padding-left:70px;"><font size = "1" align = "right">{$invoice_date}</font></td>
+          <td>
+            <font size = "1" align = "right">
+              {if $domain_street_address }{$domain_street_address}{/if}
+              {if $domain_supplemental_address_1 }{$domain_supplemental_address_1}{/if}
+            </font>
+          </td>
+        </tr>
+        <tr>
+          <td style = "padding-left:17px;"><font size = "1" align = "center">{$street_address}   {$supplemental_address_1}</font></td>
+          <td colspan = "1"></td>
+          <td style = "padding-left:70px;"><b><font size = "1" align = "right">{ts}Invoice Number:{/ts}</font></b></td>
+          <td>
+            <font size = "1" align = "right">
+              {if $domain_supplemental_address_2 }{$domain_supplemental_address_2}{/if}
+              {if $domain_state }{$domain_state}{/if}
+            </font>
+          </td>
+        </tr>
+        <tr>
+          <td style = "padding-left:17px;"><font size = "1" align = "center">{$supplemental_address_2}  {$stateProvinceAbbreviation}</font></td>
+          <td colspan="1"></td>
+          <td style = "padding-left:70px;"><font size = "1" align = "right">{$invoice_number}</font></td>
+          <td>
+            <font size = "1" align = "right">
+              {if $domain_city}{$domain_city}{/if}
+              {if $domain_postal_code }{$domain_postal_code}{/if}
+            </font>
+          </td>
+        </tr>
+        <tr>
+          <td style = "padding-left:17px;"><font size = "1" align = "right">{$city}  {$postal_code}</font></td>
+          <td colspan="1"></td>
+          <td height = "10" style = "padding-left:70px;"><b><font size = "1"align = "right">{ts}Reference:{/ts}</font></b></td>
+          <td><font size = "1" align = "right"> {if $domain_country}{$domain_country}{/if}</font></td>
+        </tr>
+        <tr>
+          <td></td>
+          <td></td>
+          <td style = "padding-left:70px;"><font size = "1"align = "right">{$source}</font></td>
+          <td><font size = "1" align = "right"> {if $domain_phone}{$domain_phone}{/if}</font> </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td></td>
+          <td></td>
+          <td><font size = "1" align = "right"> {if $domain_email}{$domain_email}{/if}</font> </td>
+        </tr>
+      </table>
+      <table style = "margin-top:75px;font-family: Arial, Verdana, sans-serif" width = "590" border = "0"cellpadding = "-5" cellspacing = "19" id = "desc">
+        <tr>
+          <td colspan = "2" {$valueStyle}>
+            <table> {* FIXME: style this table so that it looks like the text version (justification, etc.) *}
+              <tr>
+                <th style = "padding-right:34px;text-align:left;font-weight:bold;width:200px;"><font size = "1">{ts}Description{/ts}</font></th>
+                <th style = "padding-left:34px;text-align:right;font-weight:bold;" ><font size = "1">{ts}Quantity{/ts}</font></th>
+                <th style = "padding-left:34px;text-align:right;font-weight:bold;"><font size = "1">{ts}Unit Price{/ts}</font></th>
+                <th style = "padding-left:34px;text-align:right;font-weight:bold;width:20px;"><font size = "1">{$taxTerm} </font></th>
+                <th style = "padding-left:34px;text-align:right;font-weight:bold;"><font size = "1">{ts 1=$defaultCurrency}Amount %1{/ts}</font></th>
+              </tr>
+              {foreach from=$lineItem item=value key=priceset name=taxpricevalue}
+                {if $smarty.foreach.taxpricevalue.index eq 0}
+                  <tr>
+                    <td colspan = "5" ><hr size="3" style = "color:#000;"></hr></td>
+                  </tr>
+                {else}
+                  <tr>
+                    <td  colspan = "5" style = "color:#F5F5F5;"><hr></hr></td>
+                  </tr>
+                {/if}
+                <tr>
+                  <td style="text-align:left;" ><font size = "1">
+                    {if $value.html_type eq 'Text'}
+                      {$value.label}
+                    {else}
+                      {$value.field_title} - {$value.label}
+                    {/if}
+                    {if $value.description}
+                      <div>{$value.description|truncate:30:"..."}</div>
+                    {/if}
+                    </font>
+                  </td>
+                  <td style = "padding-left:34px;text-align:right;"><font size = "1"> {$value.qty}</font></td>
+                  <td style = "padding-left:34px;text-align:right;"><font size = "1"> {$value.unit_price|crmMoney:$currency}</font></td>
+                  {if $value.tax_amount != ''}
+                    <td style = "padding-left:34px;text-align:right;width:20px;"><font size = "1"> {$value.tax_rate}%</font></td>
+                  {else}
+                    <td style = "padding-left:34px;text-align:right;width:20px;"><font size = "1">{ts 1=$taxTerm}No %1{/ts}</font></td>
+                  {/if}
+                  <td style = "padding-left:34px;text-align:right;"><font size = "1">{$value.subTotal|crmMoney:$currency}</font></td>
+                </tr>
+              {/foreach}
+              <tr><td  colspan = "5" style = "color:#F5F5F5;"><hr></hr></td></tr>
+              <tr>
+                <td colspan = "3"></td>
+                <td style = "padding-left:20px;text-align:right;"><font size = "1">{ts}Sub Total{/ts}</font></td>
+                <td style = "padding-left:34px;text-align:right;"><font size = "1"> {$subTotal|crmMoney:$currency}</font></td>
+              </tr>
+              {foreach from = $dataArray item = value key = priceset}
+                <tr>
+                  <td colspan = "3"></td>
+                    {if $priceset}
+                      <td style = "padding-left:20px;text-align:right;"><font size = "1"> {ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}</font></td>
+                      <td style = "padding-left:34px;text-align:right"><font size = "1" align = "right">{$value|crmMoney:$currency}</font> </td>
+                    {elseif $priceset == 0}
+                      <td style = "padding-left:20px;text-align:right;"><font size = "1">{ts 1=$taxTerm}TOTAL NO %1{/ts}</font></td>
+                      <td style = "padding-left:34px;text-align:right"><font size = "1" align = "right">{$value|crmMoney:$currency}</font> </td>
+                </tr>
+              {/if}
+              {/foreach}
+              <tr>
+                <td colspan = "3"></td>
+                <td colspan = "2"><hr></hr></td>
+              </tr>
+              <tr>
+                <td colspan = "3"></td>
+                <td style = "padding-left:20px;text-align:right;"><b><font size = "1">{ts 1=$defaultCurrency}TOTAL %1{/ts}</font></b></td>
+                <td style = "padding-left:34px;text-align:right;"><font size = "1">{$amount|crmMoney:$currency}</font></td>
+                <td style = "padding-left:34px;"><font size = "1" align = "right"></font></td>
+              </tr>
+              {if $is_pay_later == 0}
+                <tr>
+                  <td colspan = "3"></td>
+                  <td style = "padding-left:20px;text-align:right;"><font size = "1">
+                    {if $contribution_status_id == $refundedStatusId}
+                      {ts}LESS Amount Credited{/ts}
+                    {else}
+                      {ts}LESS Amount Paid{/ts}
+                    {/if}
+                    </font>
+                  </td>
+                  <td style = "padding-left:34px;text-align:right;"><font size = "1">{$amountPaid|crmMoney:$currency}</font></td>
+                </tr>
+                <tr>
+                  <td colspan = "3"></td>
+                  <td colspan = "2" ><hr></hr></td>
+                </tr>
+                <tr>
+                  <td colspan = "3"></td>
+                  <td style = "padding-left:20px;text-align:right;"><b><font size = "1">{ts}AMOUNT DUE:{/ts} </font></b></td>
+                  <td style = "padding-left:34px;text-align:right;"><b><font size = "1">{$amountDue|crmMoney:$currency}</font></b></td>
+                  <td style = "padding-left:34px;"><font size = "1" align = "right"></font></td>
+                </tr>
+              {/if}
+              <br/><br/><br/>
+              <tr>
+                <td colspan = "3"></td>
+              </tr>
+              {if $contribution_status_id == $pendingStatusId && $is_pay_later == 1}
+                <tr>
+                  <td><b><font size = "1" align = "center">{ts 1=$dueDate}DUE DATE: %1{/ts}</font></b></td>
+                  <td colspan = "3"></td>
+                </tr>
+              {/if}
+            </table>
+          </td>
+        </tr>
+      </table>
+      {if $contribution_status_id == $pendingStatusId && $is_pay_later == 1}
+        <table style = "margin-top:5px;padding-right:45px;">
+          <tr>
+            <td><img src = "{$resourceBase}/i/contribute/cut_line.png" height = "15" width = "630"></td>
+          </tr>
+        </table>
+        <table style = "margin-top:6px;padding-right:20px;font-family: Arial, Verdana, sans-serif" width = "480" border = "0"cellpadding = "-5" cellspacing="19" id = "desc">
+          <tr>
+            <td width="60%"><b><font size = "4" align = "right">{ts}PAYMENT ADVICE{/ts}</font></b> <br/><br/> <font size = "1" align = "right"><b>{ts}To: {/ts}</b><div style="width:17em;word-wrap:break-word;">
+              {$domain_organization} <br />
+              {$domain_street_address} {$domain_supplemental_address_1} <br />
+              {$domain_supplemental_address_2} {$domain_state} <br />
+              {$domain_city} {$domain_postal_code} <br />
+              {$domain_country} <br />
+              {$domain_phone} <br />
+              {$domain_email}</div>
+              </font><br/><br/><font size="1" align="right">{$notes}</font>
+            </td>
+            <td width="40%">
+              <table  cellpadding = "-10" cellspacing = "22"  align="right" >
+                <tr>
+                  <td colspan = "2"></td>
+                  <td><font size = "1" align = "right" style="font-weight:bold;">{ts}Customer: {/ts}</font></td>
+                  <td ><font size = "1" align = "right">{$display_name}</font></td>
+                </tr>
+                <tr>
+                  <td colspan = "2"></td>
+                  <td><font size = "1" align = "right" style="font-weight:bold;">{ts}Invoice Number: {/ts}</font></td>
+                  <td><font size = "1" align = "right">{$invoice_id}</font></td>
+                </tr>
+                <tr><td colspan = "5"style = "color:#F5F5F5;"><hr></hr></td></tr>
+                {if $is_pay_later == 1}
+                  <tr>
+                    <td colspan = "2"></td>
+                    <td><font size = "1" align = "right" style="font-weight:bold;">{ts}Amount Due:{/ts}</font></td>
+                    <td><font size = "1" align = "right" style="font-weight:bold;">{$amount|crmMoney:$currency}</font></td>
+                  </tr>
+                {else}
+                  <tr>
+                    <td colspan = "2"></td>
+                    <td><font size = "1" align = "right" style="font-weight:bold;">{ts}Amount Due: {/ts}</font></td>
+                    <td><font size = "1" align = "right" style="font-weight:bold;">{$amountDue|crmMoney:$currency}</font></td>
+                  </tr>
+                {/if}
+                <tr>
+                  <td colspan = "2"></td>
+                  <td><font size = "1" align = "right" style="font-weight:bold;">{ts}Due Date:  {/ts}</font></td>
+                  <td><font size = "1" align = "right">{$dueDate}</font></td>
+                </tr>
+                <tr>
+                  <td colspan = "5" style = "color:#F5F5F5;"><hr></hr></td>
+                </tr>
+              </table>
+            </td>
+          </tr>
+        </table>
+      {/if}
+
+      {if $contribution_status_id == $refundedStatusId || $contribution_status_id == $cancelledStatusId}
+        <table style = "margin-top:2px;padding-left:7px;page-break-before: always;">
+          <tr>
+            <td><img src = "{$resourceBase}/i/civi99.png" height = "34px" width = "99px"></td>
+          </tr>
+        </table>
+    <center>
+
+      <table style = "padding-right:19px;font-family: Arial, Verdana, sans-serif" width = "500" height = "100" border = "0" cellpadding = "2" cellspacing = "1">
+        <tr>
+          <td style = "padding-left:15px;" ><b><font size = "4" align = "center">{ts}CREDIT NOTE{/ts}</font></b></td>
+          <td colspan = "1"></td>
+          <td style = "padding-left:70px;"><b><font size = "1" align = "right">{ts}Date:{/ts}</font></b></td>
+          <td><font size = "1" align = "right">{$domain_organization}</font></td>
+        </tr>
+        <tr>
+          {if $organization_name}
+            <td style = "padding-left:17px;"><font size = "1" align = "center">{$display_name}  ({$organization_name})</font></td>
+          {else}
+            <td style = "padding-left:17px;"><font size = "1" align = "center">{$display_name}</font></td>
+          {/if}
+          <td colspan = "1"></td>
+          <td style = "padding-left:70px;"><font size = "1" align = "right">{$invoice_date}</font></td>
+          <td>
+            <font size = "1" align = "right">
+              {if $domain_street_address }{$domain_street_address}{/if}
+              {if $domain_supplemental_address_1 }{$domain_supplemental_address_1}{/if}
+            </font>
+          </td>
+        </tr>
+        <tr>
+          <td style = "padding-left:17px;"><font size = "1" align = "center">{$street_address}   {$supplemental_address_1}</font></td>
+          <td colspan = "1"></td>
+          <td style = "padding-left:70px;"><b><font size = "1" align = "right">{ts}Credit Note Number:{/ts}</font></b></td>
+          <td>
+            <font size = "1" align = "right">
+              {if $domain_supplemental_address_2 }{$domain_supplemental_address_2}{/if}
+              {if $domain_state }{$domain_state}{/if}
+            </font>
+          </td>
+        </tr>
+        <tr>
+          <td style = "padding-left:17px;"><font size = "1" align = "center">{$supplemental_address_2}  {$stateProvinceAbbreviation}</font></td>
+          <td colspan="1"></td>
+          <td style = "padding-left:70px;"><font size = "1" align = "right">{$creditnote_id}</font></td>
+          <td>
+            <font size = "1" align = "right">
+              {if $domain_city}{$domain_city}{/if}
+              {if $domain_postal_code }{$domain_postal_code}{/if}
+            </font>
+          </td>
+        </tr>
+        <tr>
+          <td style = "padding-left:17px;"><font size = "1" align = "right">{$city}  {$postal_code}</font></td>
+          <td colspan="1"></td>
+          <td height = "10" style = "padding-left:70px;"><b><font size = "1"align = "right">{ts}Reference:{/ts}</font></b></td>
+          <td>
+            <font size = "1" align = "right">
+              {if $domain_country}{$domain_country}{/if}
+            </font>
+          </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td></td>
+          <td style = "padding-left:70px;"><font size = "1"align = "right">{$source}</font></td>
+          <td>
+            <font size = "1" align = "right">
+              {if $domain_phone}{$domain_phone}{/if}
+            </font>
+          </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td></td>
+          <td></td>
+          <td>
+            <font size = "1" align = "right">
+              {if $domain_email}{$domain_email}{/if}
+            </font>
+          </td>
+        </tr>
+      </table>
+
+      <table style = "margin-top:75px;font-family: Arial, Verdana, sans-serif" width = "590" border = "0"cellpadding = "-5" cellspacing = "19" id = "desc">
+        <tr>
+          <td colspan = "2" {$valueStyle}>
+            <table> {* FIXME: style this table so that it looks like the text version (justification, etc.) *}
+              <tr>
+                <th style = "padding-right:28px;text-align:left;font-weight:bold;width:200px;"><font size = "1">{ts}Description{/ts}</font></th>
+                <th style = "padding-left:28px;text-align:right;font-weight:bold;"><font size = "1">{ts}Quantity{/ts}</font></th>
+                <th style = "padding-left:28px;text-align:right;font-weight:bold;"><font size = "1">{ts}Unit Price{/ts}</font></th>
+                <th style = "padding-left:28px;text-align:right;font-weight:bold;"><font size = "1">{$taxTerm} </font></th>
+                <th style = "padding-left:28px;text-align:right;font-weight:bold;"><font size = "1">{ts 1=$defaultCurrency}Amount %1{/ts}</font></th>
+              </tr>
+              {foreach from=$lineItem item=value key=priceset name=pricevalue}
+                {if $smarty.foreach.pricevalue.index eq 0}
+                  <tr><td  colspan = "5" ><hr size="3" style = "color:#000;"></hr></td></tr>
+                {else}
+                  <tr><td  colspan = "5" style = "color:#F5F5F5;"><hr></hr></td></tr>
+                {/if}
+                <tr>
+                  <td style ="text-align:left;"  >
+                    <font size = "1">
+                      {if $value.html_type eq 'Text'}
+                        {$value.label}
+                      {else}
+                        {$value.field_title} - {$value.label}
+                      {/if}
+                      {if $value.description}
+                        <div>{$value.description|truncate:30:"..."}</div>
+                      {/if}
+                    </font>
+                  </td>
+                  <td style = "padding-left:28px;text-align:right;"><font size = "1"> {$value.qty}</font></td>
+                  <td style = "padding-left:28px;text-align:right;"><font size = "1"> {$value.unit_price|crmMoney:$currency}</font></td>
+                  {if $value.tax_amount != ''}
+                    <td style = "padding-left:28px;text-align:right;"><font size = "1"> {$value.tax_rate}%</font></td>
+                  {else}
+                    <td style = "padding-left:28px;text-align:right"><font size = "1" >{ts 1=$taxTerm}No %1{/ts}</font></td>
+                  {/if}
+                  <td style = "padding-left:28px;text-align:right;"><font size = "1" >{$value.subTotal|crmMoney:$currency}</font></td>
+                </tr>
+              {/foreach}
+              <tr><td  colspan = "5" style = "color:#F5F5F5;"><hr></hr></td></tr>
+              <tr>
+                <td colspan = "3"></td>
+                <td style = "padding-left:28px;text-align:right;"><font size = "1">{ts}Sub Total{/ts}</font></td>
+                <td style = "padding-left:28px;text-align:right;"><font size = "1"> {$subTotal|crmMoney:$currency}</font></td>
+              </tr>
+              {foreach from = $dataArray item = value key = priceset}
+                <tr>
+                  <td colspan = "3"></td>
+                  {if $priceset}
+                    <td style = "padding-left:28px;text-align:right;"><font size = "1"> {ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}</font></td>
+                    <td style = "padding-left:28px;text-align:right;"><font size = "1" align = "right">{$value|crmMoney:$currency}</font> </td>
+                  {elseif $priceset == 0}
+                    <td style = "padding-left:28px;text-align:right;"><font size = "1">{ts 1=$taxTerm}TOTAL NO %1{/ts}</font></td>
+                    <td style = "padding-left:28px;text-align:right;"><font size = "1" align = "right">{$value|crmMoney:$currency}</font> </td>
+                </tr>
+                {/if}
+              {/foreach}
+              <tr>
+                <td colspan = "3"></td>
+                <td colspan = "2"><hr></hr></td>
+              </tr>
+              <tr>
+                <td colspan = "3"></td>
+                <td style = "padding-left:28px;text-align:right;"><b><font size = "1">{ts 1=$defaultCurrency}TOTAL %1{/ts}</font></b></td>
+                <td style = "padding-left:28px;text-align:right;"><font size = "1">{$amount|crmMoney:$currency}</font></td>
+              </tr>
+              {if $is_pay_later == 0}
+                <tr>
+                  <td colspan = "3"></td>
+                  <td style = "padding-left:28px;text-align:right;"><font size = "1" >{ts}LESS Credit to invoice(s){/ts}</font></td>
+                  <td style = "padding-left:28px;text-align:right;"><font size = "1">{$amount|crmMoney:$currency}</font></td>
+                </tr>
+                <tr>
+                  <td colspan = "3"></td>
+                  <td colspan = "2" ><hr></hr></td>
+                </tr>
+                <tr>
+                  <td colspan = "3"></td>
+                  <td style = "padding-left:28px;text-align:right;"><b><font size = "1">{ts}REMAINING CREDIT{/ts}</font></b></td>
+                  <td style = "padding-left:28px;text-align:right;"><b><font size = "1">{$amountDue|crmMoney:$currency}</font></b></td>
+                  <td style = "padding-left:28px;"><font size = "1" align = "right"></font></td>
+                </tr>
+              {/if}
+              <br/><br/><br/>
+              <tr>
+                <td colspan = "3"></td>
+              </tr>
+              <tr>
+                <td></td>
+                <td colspan = "3"></td>
+              </tr>
+            </table>
+          </td>
+        </tr>
+      </table>
+      <table style = "margin-top:5px;padding-right:45px;">
+        <tr>
+          <td><img src = "{$resourceBase}/i/contribute/cut_line.png" height = "15" width = "630"></td>
+        </tr>
+      </table>
+
+      <table style = "margin-top:6px;padding-right:20px;font-family: Arial, Verdana, sans-serif" width = "507" border = "0"cellpadding = "-5" cellspacing="19" id = "desc">
+        <tr>
+          <td width="60%"><font size = "4" align = "right"><b>{ts}CREDIT ADVICE{/ts}</b><br/><br /><div  style="font-size:10px;max-width:300px;">{ts}Please do not pay on this advice. Deduct the amount of this Credit Note from your next payment to us{/ts}</div><br/></font></td>
+          <td width="40%">
+            <table    align="right" >
+              <tr>
+                <td colspan = "2"></td>
+                <td><font size = "1" align = "right" style="font-weight:bold;">{ts}Customer:{/ts} </font></td>
+                <td><font size = "1" align = "right" >{$display_name}</font></td>
+              </tr>
+              <tr>
+                <td colspan = "2"></td>
+                <td><font size = "1" align = "right" style="font-weight:bold;">{ts}Credit Note#:{/ts} </font></td>
+                <td><font size = "1" align = "right">{$creditnote_id}</font></td>
+              </tr>
+              <tr><td  colspan = "5"style = "color:#F5F5F5;"><hr></hr></td></tr>
+              <tr>
+                <td colspan = "2"></td>
+                <td><font size = "1" align = "right" style="font-weight:bold;">{ts}Credit Amount:{/ts}</font></td>
+                <td width='50px'><font size = "1" align = "right" style="font-weight:bold;">{$amount|crmMoney:$currency}</font></td>
+              </tr>
+            </table>
+          </td>
+        </tr>
+      </table>
+    {/if}
+    </center>
+  </body>
+</html>
index aea404fd539b5609555a47507f863a78c0dcd2dc..f0e601ae777326e4fda6a4e3546693137cc5e7f3 100644 (file)
@@ -122,6 +122,9 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base
         $postUpgradeMessage .= '<p>civicrm_sms_provider ' . ts('has now had a domain id column added. As there is more than 1 domains in this install you need to manually set the domain id for the providers in this install') . '</p>';
       }
     }
+    if ($rev == '4.7.22') {
+      $postUpgradeMessage .= '<br /><br />' . ts('Default version of the following System Workflow Message Templates have been modified: <ul><li>Contribution Invoice</li></ul> If you have modified these templates, please review the new default versions and implement updates as needed to your copies (Administer > Communications > Message Templates > System Workflow Messages).');
+    }
   }
 
   /**
@@ -360,6 +363,17 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base
       'civicrm_mail_settings', 'activity_status', "varchar (255) DEFAULT NULL COMMENT 'Name of status to use when creating email to activity.'");
   }
 
+  /**
+   * Upgrade function.
+   *
+   * @param string $rev
+   */
+  public function upgrade_4_7_22($rev) {
+    $this->addTask('CRM-20387 - Add invoice_number column to civicrm_contribution', 'addColumn',
+      'civicrm_contribution', 'invoice_number', "varchar(255) COMMENT 'Human readable invoice number' DEFAULT NULL");
+    $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
+  }
+
   /*
    * Important! All upgrade functions MUST add a 'runSql' task.
    * Uncomment and use the following template for a new upgrade version
index c4fca4dc84d75f08f854dec96167f4f26d324a3b..071a9a6430fe2e5e3f7d03a12a9221f8647a2ef1 100644 (file)
@@ -1 +1,6 @@
 {* file to handle db changes in 4.7.22 during upgrade *}
+
+{include file='../CRM/Upgrade/4.7.22.msg_template/civicrm_msg_template.tpl'}
+
+-- CRM-20387
+UPDATE `civicrm_contribution` SET `invoice_number` = `invoice_id` WHERE `invoice_id` LIKE CONCAT('%', `id`);
index 9b4997039319cd65ec4e8eadd6a731a094b87a64..a1ffbf661bfc0ef6b1d98afdc6217310479ad6e3 100644 (file)
@@ -83,6 +83,7 @@ function contribution_create_expectedresult() {
         'tax_amount' => '',
         'revenue_recognition_date' => '',
         'contribution_type_id' => '1',
+        'invoice_number' => '',
       ),
     ),
   );
index 4252279c832e870109029c65ca34ca120856771e..33eee999e2637feb20d3572d66305373d47f8475 100644 (file)
     </tr>
   {/if}
 
+  {if $invoice_number}
+    <tr>
+      <td class="label">{ts}Invoice Number{/ts}</td>
+      <td>{$invoice_number}&nbsp;</td>
+    </tr>
+  {/if}
+
   {if $invoice_id}
     <tr>
-      <td class="label">{ts}Invoice ID{/ts}</td>
+      <td class="label">{ts}Invoice Reference{/ts}</td>
       <td>{$invoice_id}&nbsp;</td>
     </tr>
   {/if}
index 2e601e47a0b4bc9028bdc4ecf2416e75442c4989..9b94d9df5491b1a6bf9af9f2c7c1ba3d11778166 100644 (file)
@@ -71,8 +71,8 @@
     </div>
   </td>
   <td>
-    {$form.invoice_id.label} <br />
-    {$form.invoice_id.html}
+    {$form.invoice_number.label} <br />
+    {$form.invoice_number.html}
   </td>
 </tr>
 <tr>
index 9dc657d2df5d9a2a34e1cad65da85dcc88685ddb..3317805d1813978518f5eb2e1567b2ac900b9783 100644 (file)
@@ -247,6 +247,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     $params['campaign_id'] = $this->campaignCreate();
 
     $contributionID = $this->contributionCreate($params);
+
+    // update contribution with invoice number
+    $params = array_merge($params, array(
+      'id' => $contributionID,
+      'invoice_number' => CRM_Utils_Array::value('invoice_prefix', Civi::settings()->get('contribution_invoice_settings')) . "" . $contributionID,
+    ));
+    $contributionID = $this->contributionCreate($params);
+
     $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contributionID));
     $this->assertEquals('bouncer', $contribution['check_number']);
     $this->assertEquals('bouncer', $contribution['contribution_check_number']);
index ad9260293beb107ad0103c49201bbe4485a1ef0e..edcb3befa4114113cf03630ef1f12b4830c9bf6c 100644 (file)
   </field>
   <field>
     <name>invoice_id</name>
-    <title>Invoice ID</title>
+    <title>Invoice Reference</title>
     <type>varchar</type>
     <length>255</length>
     <import>true</import>
       <type>Text</type>
     </html>
     <add>1.3</add>
-    </field>
+  </field>
+  <field>
+    <name>invoice_number</name>
+    <title>Invoice Number</title>
+    <type>varchar</type>
+    <length>255</length>
+    <import>true</import>
+    <headerPattern>/invoice(.?number)?/i</headerPattern>
+    <comment>Human readable invoice number</comment>
+    <html>
+      <type>Text</type>
+    </html>
+    <add>4.7</add>
+  </field>
   <field>
     <name>currency</name>
     <type>varchar</type>
index 0b5633f53bc7d14535509cc52cf4e52c0929d36c..75d7bf006c457ba98d6123280fcc32a428dd9fcb 100644 (file)
@@ -47,7 +47,7 @@
         <tr>
           <td style = "padding-left:17px;"><font size = "1" align = "center">{$supplemental_address_2}  {$stateProvinceAbbreviation}</font></td>
           <td colspan="1"></td>
-          <td style = "padding-left:70px;"><font size = "1" align = "right">{$invoice_id}</font></td>
+          <td style = "padding-left:70px;"><font size = "1" align = "right">{$invoice_number}</font></td>
           <td>
             <font size = "1" align = "right">
               {if $domain_city}{$domain_city}{/if}