From: Jon Goldberg Date: Fri, 21 May 2021 15:10:47 +0000 (-0400) Subject: Show 'Pay Now' on user dashboard for partially paid contributions X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=dbfe939a1cc37facb9e1c55403cdc6ff322365f5;p=civicrm-core.git Show 'Pay Now' on user dashboard for partially paid contributions --- diff --git a/CRM/Contribute/Page/UserDashboard.php b/CRM/Contribute/Page/UserDashboard.php index 11adcd89e3..0a4c9f0fe1 100644 --- a/CRM/Contribute/Page/UserDashboard.php +++ b/CRM/Contribute/Page/UserDashboard.php @@ -48,7 +48,10 @@ class CRM_Contribute_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBo // This is required for tpl logic. We should move away from hard-code this to adding an array of actions to the row // which the tpl can iterate through - this should allow us to cope with competing attempts to add new buttons // and allow extensions to assign new ones through the pageRun hook - if ('Pending' === CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id'])) { + $row['balance_amount'] = CRM_Contribute_BAO_Contribution::getContributionBalance($row['contribution_id']); + $contributionStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id']); + + if (in_array($contributionStatus, ['Pending', 'Partially paid'])) { $row['buttons']['pay'] = [ 'class' => 'button', 'label' => ts('Pay Now'), diff --git a/templates/CRM/Contribute/Page/UserDashboard.tpl b/templates/CRM/Contribute/Page/UserDashboard.tpl index 0520ebc1a3..d856cf4d98 100644 --- a/templates/CRM/Contribute/Page/UserDashboard.tpl +++ b/templates/CRM/Contribute/Page/UserDashboard.tpl @@ -18,13 +18,12 @@ {ts}Financial Type{/ts} {ts}Received date{/ts} {ts}Receipt Sent{/ts} + {ts}Balance{/ts} {ts}Status{/ts} {if $isIncludeInvoiceLinks} {/if} - {foreach from=$row.buttons item=button} - - {/foreach} + {foreach from=$contribute_rows item=row} @@ -39,6 +38,7 @@ {$row.financial_type} {$row.receive_date|truncate:10:''|crmDate} {$row.receipt_date|truncate:10:''|crmDate} + {$row.balance_amount|crmMoney:$row.currency} {$row.contribution_status} {if $isIncludeInvoiceLinks} @@ -59,9 +59,11 @@ {/if} {/if} + {foreach from=$row.buttons item=button} - {$button.label} + {$button.label} {/foreach} + {/foreach} diff --git a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php index 9d0abd2433..9ae687e1a5 100644 --- a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php +++ b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php @@ -113,8 +113,8 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase { $this->runUserDashboard(); $expectedStrings = [ 'Your Contribution(s)', - '', - '', + 'runUserDashboard(); $expectedStrings = [ 'Your Contribution(s)', - '
Total AmountFinancial TypeReceived dateReceipt SentStatusCompletedPrint Invoice
Total AmountFinancial TypeReceived dateReceipt SentBalanceStatusCompletedPrint Invoice
', + '
Total AmountFinancial TypeReceived dateReceipt SentStatus
', '', '', ]; $this->assertPageContains($expectedStrings); } + /** + * Test the presence of a "Pay Now" button on partial payments + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + */ + public function testDashboardPartialPayments() { + $contributionId = $this->contributionCreate([ + 'contact_id' => $this->contactID, + 'contribution_status_id' => 'Pending', + 'total_amount' => 25, + ]); + $result = civicrm_api3('Payment', 'create', [ + 'contribution_id' => $contributionId, + 'total_amount' => 11, + 'trxn_date' => "2021-05-11", + ]); + $this->contributions[] = civicrm_api3('Contribution', 'get', [ + 'contact_id' => $this->contactID, + 'options' => ['limit' => 12, 'sort' => 'receive_date DESC'], + 'sequential' => 1, + ])['values']; + $this->runUserDashboard(); + $expectedStrings = [ + 'Your Contribution(s)', + '
Total AmountFinancial TypeReceived dateReceipt SentBalanceStatus$ 100.00 DonationCompleted
', + '', + '', + 'Pay Now', + ]; + $this->assertPageContains($expectedStrings); + } + /** * Run the user dashboard. */
Total AmountFinancial TypeReceived dateReceipt SentBalanceStatus$ 25.00 Donation$ 14.00Partially paid