Implement compact PayPal refund summary feature in registration management
This commit introduces a new function, `renderPayPalRefundSummaryHtml`, to provide a concise overview of PayPal refunds within the registration management interface. The summary displays essential information such as status, captured amount, total refunded, and remaining balance, enhancing the user experience by presenting key details in a more accessible format. Additionally, the existing code is updated to utilize this new summary function, improving the overall clarity and usability of transaction information.
This commit is contained in:
@ -180,15 +180,15 @@ switch ($strAction) {
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/inc_fx_panier.php';
|
||||
$strResume = fxShowPanier($strNoPanier, 0, 'web', 1, $strLangue);
|
||||
|
||||
// Detail des remboursements PayPal (meme rendu que Super Admin). N'apparait que
|
||||
// s'il existe une capture PayPal exploitable ; sinon rien (les cas gratuits/non-PayPal
|
||||
// sont deja couverts par la facture ci-dessus).
|
||||
// Sommaire des remboursements PayPal (vue compacte, pas la grande table Super Admin).
|
||||
// N'apparait que s'il existe une capture PayPal exploitable ; sinon rien (les cas
|
||||
// gratuits/non-PayPal sont deja couverts par la facture ci-dessus).
|
||||
$strRefunds = '';
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/superadm/php/inc_fx_paypal.php';
|
||||
$arrRefundCtx = fxRefundComputeContext($recCommandes);
|
||||
if (!empty($arrRefundCtx['ok'])) {
|
||||
$strRefunds = '<div style="margin-top:14px;border-top:1px solid #cfe0ff;padding-top:12px;">'
|
||||
. renderPayPalCaptureHtml($arrRefundCtx['paypaldetails'])
|
||||
. renderPayPalRefundSummaryHtml($arrRefundCtx['paypaldetails'])
|
||||
. '</div>';
|
||||
}
|
||||
|
||||
|
||||
@ -289,6 +289,125 @@ $html .= '<div style="font-family:sans-serif;font-size:14px;color:#555;margin:4p
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sommaire compact d'une capture PayPal + remboursements (vue promoteur/gestion).
|
||||
* Contrairement a renderPayPalCaptureHtml(), n'affiche que l'essentiel :
|
||||
* statut, montant capture, total rembourse, solde restant et une ligne par remboursement.
|
||||
* - $capOrBundle : meme entree que renderPayPalCaptureHtml() (bundle 'delails'/'details' + 'refunds')
|
||||
* - $tz : fuseau pour afficher les dates
|
||||
*/
|
||||
function renderPayPalRefundSummaryHtml($capOrBundle, string $tz = 'America/Toronto'): string
|
||||
{
|
||||
$h = static function ($v): string {
|
||||
return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
|
||||
};
|
||||
$get = static function ($a, array $path, $default = '') {
|
||||
if (!is_array($a)) return $default;
|
||||
foreach ($path as $k) {
|
||||
if (!is_array($a) || !array_key_exists($k, $a)) return $default;
|
||||
$a = $a[$k];
|
||||
}
|
||||
return $a;
|
||||
};
|
||||
$moneyVal = static function ($amt): float {
|
||||
if (is_array($amt) && isset($amt['value'])) return (float)$amt['value'];
|
||||
if (is_numeric($amt)) return (float)$amt;
|
||||
return 0.0;
|
||||
};
|
||||
$fmtDate = static function ($iso, string $tz): string {
|
||||
if (!$iso) return '';
|
||||
try {
|
||||
$dt = new DateTime($iso);
|
||||
$dt->setTimezone(new DateTimeZone($tz));
|
||||
return $dt->format('Y-m-d H:i');
|
||||
} catch (Throwable $e) {
|
||||
return (string)$iso;
|
||||
}
|
||||
};
|
||||
|
||||
// --- Detecte le bundle vs capture brute ---
|
||||
$isBundle = is_array($capOrBundle) && (array_key_exists('delails', $capOrBundle) || array_key_exists('details', $capOrBundle));
|
||||
if ($isBundle) {
|
||||
$cap = $capOrBundle['delails'] ?? $capOrBundle['details'];
|
||||
$refBloc = $capOrBundle['refunds'] ?? [];
|
||||
$refundItems = $refBloc['refunds'] ?? [];
|
||||
$totals = $refBloc['totals'] ?? [];
|
||||
} else {
|
||||
$cap = $capOrBundle;
|
||||
$refundItems = [];
|
||||
$totals = [];
|
||||
}
|
||||
|
||||
// --- Statut traduit ---
|
||||
$statusMapCap = [
|
||||
'COMPLETED' => 'Complété',
|
||||
'PARTIALLY_REFUNDED' => 'Partiellement remboursé',
|
||||
'REFUNDED' => 'Remboursé',
|
||||
'PENDING' => 'En attente',
|
||||
'DECLINED' => 'Refusé',
|
||||
'NON_DISPONIBLE' => 'Non disponible',
|
||||
];
|
||||
$statRaw = (string)$get($cap, ['status'], '');
|
||||
$statNice = $statusMapCap[$statRaw] ?? $statRaw;
|
||||
|
||||
// --- Montants ---
|
||||
$currency = $totals['currency'] ?? (string)$get($cap, ['amount','currency_code'], '');
|
||||
$capTotal = $moneyVal($get($cap, ['amount'], []));
|
||||
$refTotal = isset($totals['refunded_total']) ? (float)$totals['refunded_total'] : 0.0;
|
||||
if ($refTotal <= 0 && !empty($refundItems)) {
|
||||
foreach ($refundItems as $rf) {
|
||||
$refTotal += $moneyVal(['value' => $get($rf, ['amount'], 0)]);
|
||||
}
|
||||
}
|
||||
$remaining = isset($totals['remaining']) ? (float)$totals['remaining'] : max(0.0, $capTotal - $refTotal);
|
||||
$fmtMoney = static function (float $v) use ($currency): string {
|
||||
return number_format($v, 2, '.', '') . ($currency ? ' ' . $currency : '');
|
||||
};
|
||||
|
||||
// --- Sommaire (cartes inline, pas de grande table) ---
|
||||
$html = '<div style="font-family:sans-serif;font-size:13px;">';
|
||||
$html .= '<div style="font-weight:700;margin-bottom:6px;">Remboursements</div>';
|
||||
$html .= '<div style="display:flex;flex-wrap:wrap;gap:8px;margin-bottom:6px;">';
|
||||
$cell = static function (string $label, string $value, string $color) use ($h): string {
|
||||
return '<div style="flex:1 1 120px;min-width:110px;background:#fff;border:1px solid #dbe7ff;border-radius:8px;padding:6px 10px;">'
|
||||
. '<div style="font-size:11px;color:#666;">' . $h($label) . '</div>'
|
||||
. '<div style="font-weight:700;color:' . $color . ';">' . $h($value) . '</div>'
|
||||
. '</div>';
|
||||
};
|
||||
$html .= $cell('Statut', $statNice ?: '—', '#2d6cdf');
|
||||
$html .= $cell('Capturé', $fmtMoney($capTotal), '#333');
|
||||
$html .= $cell('Remboursé', $fmtMoney($refTotal), '#c0392b');
|
||||
$html .= $cell('Solde', $fmtMoney($remaining), '#1e7e34');
|
||||
$html .= '</div>';
|
||||
|
||||
// --- Lignes de remboursements (compactes) ---
|
||||
$statusMapRef = [
|
||||
'S' => 'Effectué', 'COMPLETED' => 'Effectué',
|
||||
'P' => 'En attente', 'PENDING' => 'En attente',
|
||||
'D' => 'Refusé', 'DENIED' => 'Refusé', 'FAILED' => 'Échoué',
|
||||
'V' => 'Annulé', 'VOIDED' => 'Annulé',
|
||||
'R' => 'Reversé', 'REVERSED' => 'Reversé',
|
||||
];
|
||||
if (!empty($refundItems)) {
|
||||
foreach ($refundItems as $rf) {
|
||||
$rid = $get($rf, ['refund_id']) ?: $get($rf, ['id']);
|
||||
$amt = $moneyVal(['value' => $get($rf, ['amount'], 0)]);
|
||||
$cur = $get($rf, ['currency'], $currency);
|
||||
$srfRaw = (string)$get($rf, ['status'], '');
|
||||
$srf = $statusMapRef[$srfRaw] ?? $srfRaw;
|
||||
$time = $get($rf, ['create_time']) ?: $get($rf, ['time']);
|
||||
$html .= '<div style="display:flex;justify-content:space-between;gap:8px;border-top:1px solid #eee;padding:4px 0;color:#444;">'
|
||||
. '<span>' . $h($fmtDate($time, $tz)) . '</span>'
|
||||
. '<span style="font-weight:600;">' . $h(number_format($amt, 2, '.', '') . ($cur ? ' ' . $cur : '')) . '</span>'
|
||||
. '<span style="color:#666;">' . $h($srf) . '</span>'
|
||||
. '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
function money2($v) {
|
||||
return number_format((float)$v, 2, '.', '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user