// 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'),
<th>{ts}Financial Type{/ts}</th>
<th>{ts}Received date{/ts}</th>
<th>{ts}Receipt Sent{/ts}</th>
+ <th>{ts}Balance{/ts}</th>
<th>{ts}Status{/ts}</th>
{if $isIncludeInvoiceLinks}
<th></th>
{/if}
- {foreach from=$row.buttons item=button}
- <th></th>
- {/foreach}
+ <th></th>
</tr>
{foreach from=$contribute_rows item=row}
<td>{$row.financial_type}</td>
<td>{$row.receive_date|truncate:10:''|crmDate}</td>
<td>{$row.receipt_date|truncate:10:''|crmDate}</td>
+ <td>{$row.balance_amount|crmMoney:$row.currency}</td>
<td>{$row.contribution_status}</td>
{if $isIncludeInvoiceLinks}
<td>
{/if}
</td>
{/if}
+ <td>
{foreach from=$row.buttons item=button}
- <td><a class="{$button.class}" href="{$button.url}"><span class='nowrap'>{$button.label}</span></a></td>
+ <a class="{$button.class}" href="{$button.url}"><span class='nowrap'>{$button.label}</span></a>
{/foreach}
+ </td>
</tr>
{/foreach}
</table>
$this->runUserDashboard();
$expectedStrings = [
'Your Contribution(s)',
- '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Status</th><th></th>',
- '<td>Completed</td><td><a class="button no-popup nowrap"href="/index.php?q=civicrm/contribute/invoice&reset=1&id=1&cid=' . $this->contactID . '"><i class="crm-i fa-print" aria-hidden="true"></i><span>Print Invoice</span></a></td></tr><tr id=\'rowid2\'',
+ '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th><th></th>',
+ '<td>Completed</td><td><a class="button no-popup nowrap"href="/index.php?q=civicrm/contribute/invoice&reset=1&id=1&cid=' . $this->contactID . '"><i class="crm-i fa-print" aria-hidden="true"></i><span>Print Invoice</span></a></td><td></td></tr><tr id=\'rowid2\'',
'Pay Now',
];
$this->runUserDashboard();
$expectedStrings = [
'Your Contribution(s)',
- '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Status</th>',
+ '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th>',
'<td>$ 100.00 </td><td>Donation</td>',
'<td>Completed</td>',
];
$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)',
+ '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th>',
+ '<td>$ 25.00 </td><td>Donation</td>',
+ '<td>$ 14.00</td><td>Partially paid</td>',
+ 'Pay Now',
+ ];
+ $this->assertPageContains($expectedStrings);
+ }
+
/**
* Run the user dashboard.
*/