0 ) { // Record the destination it was actually sent to before confirming. $this->payments->updateEtransferEmail( $paymentId, '' !== $email ? $email : null ); $this->service->markPaid( $paymentId ); } } } $groups = $this->groupPending( $this->payments->findPending() ); include USC_PLUGIN_DIR . 'templates/admin/payments.php'; } /** * Group pending payments by their shared notice batch, so payments the daily * scan emailed a student together (and which a single lump-sum e-transfer * covers) are shown as one group with a combined total. Payments with no batch * — legacy at-registration e-transfers — are each their own single-item group. * * @param list $pending * @return list}> */ private function groupPending( array $pending ): array { $groups = []; foreach ( $pending as $payment ) { $batch = (string) $payment->noticeBatch; $key = '' !== $batch ? 'b:' . $batch : 's:' . (string) $payment->id; if ( ! isset( $groups[ $key ] ) ) { $groups[ $key ] = [ 'reference' => $batch, 'currency' => $payment->currency, 'total_raw' => 0.0, 'rows' => [], ]; } $student = get_userdata( $payment->studentId ); // Show what the student still owes — the amount less any account credit // already applied to this payment. $groups[ $key ]['total_raw'] += $payment->netDue(); $groups[ $key ]['rows'][] = [ 'id' => (int) $payment->id, 'student' => $student ? $student->display_name : (string) $payment->studentId, 'amount' => number_format( $payment->netDue(), 2 ) . ' ' . $payment->currency, 'method' => $payment->method, 'for' => $payment->registrationType . ' #' . $payment->registrationId, 'etransfer_email' => (string) $payment->etransferEmail, ]; } return array_values( array_map( static fn( array $group ): array => [ 'reference' => $group['reference'], 'is_group' => count( $group['rows'] ) > 1, 'total' => number_format( $group['total_raw'], 2 ) . ' ' . $group['currency'], 'rows' => $group['rows'], ], $groups ) ); } }