diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 185f38cfe753..e402e7c213e2 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -232,6 +232,7 @@ public static function whereClauseSingle(&$values, &$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 @@ public static function buildSearchForm(&$form) { // 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 diff --git a/CRM/Contribute/DAO/Contribution.php b/CRM/Contribute/DAO/Contribution.php index e0285ac385e6..2d1e9d94e76d 100644 --- a/CRM/Contribute/DAO/Contribution.php +++ b/CRM/Contribute/DAO/Contribution.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Contribute/Contribution.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:59c3615cae90b0580f7d77aa8343b21f) + * (GenCodeChecksum:ef92bd39734f5967f59e4cdb08fc0ba8) */ 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 @@ static function &fields() { 'invoice_id' => array( 'name' => 'invoice_id', 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('Invoice ID') , + 'title' => ts('Invoice Hash') , 'description' => 'unique invoice id, system generated or passed in', 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, @@ -504,6 +510,26 @@ static function &fields() { '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, diff --git a/CRM/Contribute/Form/Task/Invoice.php b/CRM/Contribute/Form/Task/Invoice.php index 5500804b719c..121bf65ec0fc 100644 --- a/CRM/Contribute/Form/Task/Invoice.php +++ b/CRM/Contribute/Form/Task/Invoice.php @@ -312,7 +312,7 @@ public static function printPDF($contribIDs, &$params, $contactIds) { $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 @@ public static function printPDF($contribIDs, &$params, $contactIds) { '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 @@ public static function printPDF($contribIDs, &$params, $contactIds) { $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 @@ public static function printPDF($contribIDs, &$params, $contactIds) { 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 @@ public static function printPDF($contribIDs, &$params, $contactIds) { 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 @@ public static function printPDF($contribIDs, &$params, $contactIds) { 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.20.msg_template/civicrm_msg_template.tpl b/CRM/Upgrade/4.7.20.msg_template/civicrm_msg_template.tpl new file mode 100644 index 000000000000..7ba1f4f1bff2 --- /dev/null +++ b/CRM/Upgrade/4.7.20.msg_template/civicrm_msg_template.tpl @@ -0,0 +1,16 @@ +{php} + $dir = SMARTY_DIR . '/../../CRM/Upgrade/4.7.20.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.20.msg_template/message_templates/contribution_invoice_receipt_html.tpl b/CRM/Upgrade/4.7.20.msg_template/message_templates/contribution_invoice_receipt_html.tpl new file mode 100644 index 000000000000..75d7bf006c45 --- /dev/null +++ b/CRM/Upgrade/4.7.20.msg_template/message_templates/contribution_invoice_receipt_html.tpl @@ -0,0 +1,458 @@ + + + + + + + + + + + +
+
+ + + + + + + + + {if $organization_name} + + {else} + + {/if} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{ts}INVOICE{/ts}{ts}Invoice Date:{/ts}{$domain_organization}
{$display_name} ({$organization_name}){$display_name}{$invoice_date} + + {if $domain_street_address }{$domain_street_address}{/if} + {if $domain_supplemental_address_1 }{$domain_supplemental_address_1}{/if} + +
{$street_address} {$supplemental_address_1}{ts}Invoice Number:{/ts} + + {if $domain_supplemental_address_2 }{$domain_supplemental_address_2}{/if} + {if $domain_state }{$domain_state}{/if} + +
{$supplemental_address_2} {$stateProvinceAbbreviation}{$invoice_number} + + {if $domain_city}{$domain_city}{/if} + {if $domain_postal_code }{$domain_postal_code}{/if} + +
{$city} {$postal_code}{ts}Reference:{/ts} {if $domain_country}{$domain_country}{/if}
{$source} {if $domain_phone}{$domain_phone}{/if}
{if $domain_email}{$domain_email}{/if}
+ + + + +
+ {* FIXME: style this table so that it looks like the text version (justification, etc.) *} + + + + + + + + {foreach from=$lineItem item=value key=priceset name=taxpricevalue} + {if $smarty.foreach.taxpricevalue.index eq 0} + + + + {else} + + + + {/if} + + + + + {if $value.tax_amount != ''} + + {else} + + {/if} + + + {/foreach} + + + + + + + {foreach from = $dataArray item = value key = priceset} + + + {if $priceset} + + + {elseif $priceset == 0} + + + + {/if} + {/foreach} + + + + + + + + + + + {if $is_pay_later == 0} + + + + + + + + + + + + + + + + {/if} +


+ + + + {if $contribution_status_id == $pendingStatusId && $is_pay_later == 1} + + + + + {/if} +
{ts}Description{/ts}{ts}Quantity{/ts}{ts}Unit Price{/ts}{$taxTerm} {ts 1=$defaultCurrency}Amount %1{/ts}


+ {if $value.html_type eq 'Text'} + {$value.label} + {else} + {$value.field_title} - {$value.label} + {/if} + {if $value.description} +
{$value.description|truncate:30:"..."}
+ {/if} +
+
{$value.qty} {$value.unit_price|crmMoney:$currency} {$value.tax_rate}%{ts 1=$taxTerm}No %1{/ts}{$value.subTotal|crmMoney:$currency}

{ts}Sub Total{/ts} {$subTotal|crmMoney:$currency}
{ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}{$value|crmMoney:$currency} {ts 1=$taxTerm}TOTAL NO %1{/ts}{$value|crmMoney:$currency}

{ts 1=$defaultCurrency}TOTAL %1{/ts}{$amount|crmMoney:$currency}
+ {if $contribution_status_id == $refundedStatusId} + {ts}LESS Amount Credited{/ts} + {else} + {ts}LESS Amount Paid{/ts} + {/if} + + {$amountPaid|crmMoney:$currency}

{ts}AMOUNT DUE:{/ts} {$amountDue|crmMoney:$currency}
{ts 1=$dueDate}DUE DATE: %1{/ts}
+
+ {if $contribution_status_id == $pendingStatusId && $is_pay_later == 1} + + + + +
+ + + + + +
{ts}PAYMENT ADVICE{/ts}

{ts}To: {/ts}
+ {$domain_organization}
+ {$domain_street_address} {$domain_supplemental_address_1}
+ {$domain_supplemental_address_2} {$domain_state}
+ {$domain_city} {$domain_postal_code}
+ {$domain_country}
+ {$domain_phone}
+ {$domain_email}
+


{$notes} +
+ + + + + + + + + + + + + {if $is_pay_later == 1} + + + + + + {else} + + + + + + {/if} + + + + + + + + +
{ts}Customer: {/ts}{$display_name}
{ts}Invoice Number: {/ts}{$invoice_id}

{ts}Amount Due:{/ts}{$amount|crmMoney:$currency}
{ts}Amount Due: {/ts}{$amountDue|crmMoney:$currency}
{ts}Due Date: {/ts}{$dueDate}

+
+ {/if} + + {if $contribution_status_id == $refundedStatusId || $contribution_status_id == $cancelledStatusId} + + + + +
+
+ + + + + + + + + + {if $organization_name} + + {else} + + {/if} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{ts}CREDIT NOTE{/ts}{ts}Date:{/ts}{$domain_organization}
{$display_name} ({$organization_name}){$display_name}{$invoice_date} + + {if $domain_street_address }{$domain_street_address}{/if} + {if $domain_supplemental_address_1 }{$domain_supplemental_address_1}{/if} + +
{$street_address} {$supplemental_address_1}{ts}Credit Note Number:{/ts} + + {if $domain_supplemental_address_2 }{$domain_supplemental_address_2}{/if} + {if $domain_state }{$domain_state}{/if} + +
{$supplemental_address_2} {$stateProvinceAbbreviation}{$creditnote_id} + + {if $domain_city}{$domain_city}{/if} + {if $domain_postal_code }{$domain_postal_code}{/if} + +
{$city} {$postal_code}{ts}Reference:{/ts} + + {if $domain_country}{$domain_country}{/if} + +
{$source} + + {if $domain_phone}{$domain_phone}{/if} + +
+ + {if $domain_email}{$domain_email}{/if} + +
+ + + + + +
+ {* FIXME: style this table so that it looks like the text version (justification, etc.) *} + + + + + + + + {foreach from=$lineItem item=value key=priceset name=pricevalue} + {if $smarty.foreach.pricevalue.index eq 0} + + {else} + + {/if} + + + + + {if $value.tax_amount != ''} + + {else} + + {/if} + + + {/foreach} + + + + + + + {foreach from = $dataArray item = value key = priceset} + + + {if $priceset} + + + {elseif $priceset == 0} + + + + {/if} + {/foreach} + + + + + + + + + + {if $is_pay_later == 0} + + + + + + + + + + + + + + + + {/if} +


+ + + + + + + +
{ts}Description{/ts}{ts}Quantity{/ts}{ts}Unit Price{/ts}{$taxTerm} {ts 1=$defaultCurrency}Amount %1{/ts}


+ + {if $value.html_type eq 'Text'} + {$value.label} + {else} + {$value.field_title} - {$value.label} + {/if} + {if $value.description} +
{$value.description|truncate:30:"..."}
+ {/if} +
+
{$value.qty} {$value.unit_price|crmMoney:$currency} {$value.tax_rate}%{ts 1=$taxTerm}No %1{/ts}{$value.subTotal|crmMoney:$currency}

{ts}Sub Total{/ts} {$subTotal|crmMoney:$currency}
{ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}{$value|crmMoney:$currency} {ts 1=$taxTerm}TOTAL NO %1{/ts}{$value|crmMoney:$currency}

{ts 1=$defaultCurrency}TOTAL %1{/ts}{$amount|crmMoney:$currency}
{ts}LESS Credit to invoice(s){/ts}{$amount|crmMoney:$currency}

{ts}REMAINING CREDIT{/ts}{$amountDue|crmMoney:$currency}
+
+ + + + +
+ + + + + + +
{ts}CREDIT ADVICE{/ts}

{ts}Please do not pay on this advice. Deduct the amount of this Credit Note from your next payment to us{/ts}

+ + + + + + + + + + + + + + + + + +
{ts}Customer:{/ts} {$display_name}
{ts}Credit Note#:{/ts} {$creditnote_id}

{ts}Credit Amount:{/ts}{$amount|crmMoney:$currency}
+
+ {/if} +
+ + diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index cbfbc839a773..fd02201867a6 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -122,6 +122,9 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { $postUpgradeMessage .= '

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') . '

'; } } + if ($rev == '4.7.20') { + $postUpgradeMessage .= '

' . ts('Default version of the following System Workflow Message Templates have been modified: 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).'); + } } /** @@ -352,6 +355,8 @@ public function upgrade_4_7_19($rev) { * @param string $rev */ public function upgrade_4_7_20($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('Fix Schema on civicrm_action_schedule', 'fixSchemaOnCiviCRMActionSchedule'); $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); } diff --git a/CRM/Upgrade/Incremental/sql/4.7.20.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.20.mysql.tpl index 307ad1b882a3..857ca781c409 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.20.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.20.mysql.tpl @@ -1 +1,6 @@ {* file to handle db changes in 4.7.20 during upgrade *} + +{include file='../CRM/Upgrade/4.7.20.msg_template/civicrm_msg_template.tpl'} + +-- CRM-20387 +UPDATE `civicrm_contribution` SET `invoice_number` = `invoice_id` WHERE `invoice_id` LIKE CONCAT('%', `id`); diff --git a/api/v3/examples/Contribution/Create.php b/api/v3/examples/Contribution/Create.php index 9b4997039319..a1ffbf661bfc 100644 --- a/api/v3/examples/Contribution/Create.php +++ b/api/v3/examples/Contribution/Create.php @@ -83,6 +83,7 @@ function contribution_create_expectedresult() { 'tax_amount' => '', 'revenue_recognition_date' => '', 'contribution_type_id' => '1', + 'invoice_number' => '', ), ), ); diff --git a/templates/CRM/Contribute/Form/ContributionView.tpl b/templates/CRM/Contribute/Form/ContributionView.tpl index 4252279c832e..8a7b48f5e255 100644 --- a/templates/CRM/Contribute/Form/ContributionView.tpl +++ b/templates/CRM/Contribute/Form/ContributionView.tpl @@ -217,9 +217,16 @@ {/if} + {if $invoice_number} + + {ts}Invoice Number{/ts} + {$invoice_number}  + + {/if} + {if $invoice_id} - {ts}Invoice ID{/ts} + {ts}Invoice Hash{/ts} {$invoice_id}  {/if} diff --git a/templates/CRM/Contribute/Form/Search/Common.tpl b/templates/CRM/Contribute/Form/Search/Common.tpl index 2e601e47a0b4..9b94d9df5491 100644 --- a/templates/CRM/Contribute/Form/Search/Common.tpl +++ b/templates/CRM/Contribute/Form/Search/Common.tpl @@ -71,8 +71,8 @@ - {$form.invoice_id.label}
- {$form.invoice_id.html} + {$form.invoice_number.label}
+ {$form.invoice_number.html} diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index fe48f7e36928..f30fa33b5616 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -260,7 +260,7 @@ public function testGetContributionReturnFunctionality() { $fieldsLockedIn = array( 'contribution_id', 'contribution_contact_id', 'financial_type_id', 'contribution_page_id', 'payment_instrument_id', 'receive_date', 'non_deductible_amount', 'total_amount', - 'fee_amount', 'net_amount', 'trxn_id', 'invoice_id', 'currency', 'cancel_date', 'cancel_reason', + 'fee_amount', 'net_amount', 'trxn_id', 'invoice_id', 'invoice_number', 'currency', 'cancel_date', 'cancel_reason', 'receipt_date', 'thankyou_date', 'contribution_source', 'amount_level', 'contribution_recur_id', 'is_test', 'is_pay_later', 'contribution_status_id', 'address_id', 'check_number', 'contribution_campaign_id', 'creditnote_id', 'tax_amount', 'revenue_recognition_date', 'decoy', diff --git a/xml/schema/Contribute/Contribution.xml b/xml/schema/Contribute/Contribution.xml index ad9260293beb..323eb1e8b6ab 100644 --- a/xml/schema/Contribute/Contribution.xml +++ b/xml/schema/Contribute/Contribution.xml @@ -226,7 +226,7 @@ invoice_id - Invoice ID + Invoice Hash varchar 255 true @@ -236,7 +236,20 @@ Text 1.3 - + + + invoice_number + Invoice Number + varchar + 255 + true + /invoice(.?number)?/i + Human readable invoice number + + Text + + 4.7 + currency varchar diff --git a/xml/templates/message_templates/contribution_invoice_receipt_html.tpl b/xml/templates/message_templates/contribution_invoice_receipt_html.tpl index 0b5633f53bc7..75d7bf006c45 100644 --- a/xml/templates/message_templates/contribution_invoice_receipt_html.tpl +++ b/xml/templates/message_templates/contribution_invoice_receipt_html.tpl @@ -47,7 +47,7 @@ {$supplemental_address_2} {$stateProvinceAbbreviation} - {$invoice_id} + {$invoice_number} {if $domain_city}{$domain_city}{/if}