mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-01 21:02:54 +09:00
Refactor dashboard and enhance charts with transaction support (#3581)
* Support optional `transaction.ipn_hash` with repair * Refactor dashboard tables and product sales card * Refactor dashboard client/avatar and activity tables * Replace ApexCharts with Chart.js sparklines * Preserve decimal income and enhance chart tooltips * Normalize admin navigation URIs * Fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * refactor(Stats): split _genFlotArray into typed _genFlotArrayInt and _genFlotArrayFloat helpers Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/fb8520de-2038-4e33-af3e-3520d999c939 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * fix(Invoice): use processTransaction return value in markAsPaidByAdmin instead of returning true unconditionally Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/fc7131ac-81aa-416b-af57-7d65d9bd20c3 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * fix(Invoice): remove runtime DDL migration from ServiceTransaction; simplify supportsTransactionIpnHash to schema-check only Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/e4b07e3f-7660-4fba-84c0-0105d6b2a318 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>
This commit is contained in:
16 files changed
+799
-128
No files matched your search
Generated
+19
-7
@@ -1403,6 +1403,12 @@
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@kurkle/color": {
|
||||
"version": "0.3.4",
|
||||
"resolved": "https://registry.npmjs.org/@kurkle/color/-/color-0.3.4.tgz",
|
||||
"integrity": "sha512-M5UknZPHRu3DEDWoipU6sE8PdkZ6Z/S+v4dD+Ke8IaNlpdSQah50lz1KtcFBa2vsdOnwbbnxJwVM4wty6udA5w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@melloware/coloris": {
|
||||
"version": "0.25.0",
|
||||
"resolved": "https://registry.npmjs.org/@melloware/coloris/-/coloris-0.25.0.tgz",
|
||||
@@ -2223,12 +2229,6 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/apexcharts": {
|
||||
"version": "5.12.0",
|
||||
"resolved": "https://registry.npmjs.org/apexcharts/-/apexcharts-5.12.0.tgz",
|
||||
"integrity": "sha512-vNCw62M5rhVg09FHFCL/ztpH7VlTOF8/+lWLUVjBdQffIAgQaxtyDGfojCyYoZHM3Hh17srWwz6rrD/XzblRSw==",
|
||||
"license": "SEE LICENSE IN LICENSE"
|
||||
},
|
||||
"node_modules/argparse": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||
@@ -2467,6 +2467,18 @@
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/chart.js": {
|
||||
"version": "4.5.1",
|
||||
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.5.1.tgz",
|
||||
"integrity": "sha512-GIjfiT9dbmHRiYi6Nl2yFCq7kkwdkp1W/lp2J99rX0yo9tgJGn3lKQATztIjb5tVtevcBtIdICNWqlq5+E8/Pw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@kurkle/color": "^0.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"pnpm": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/chokidar": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz",
|
||||
@@ -5622,7 +5634,7 @@
|
||||
"@dicebear/identicon": "^9.0.0",
|
||||
"@melloware/coloris": "^0.25.0",
|
||||
"@tabler/core": "^1.2.0",
|
||||
"apexcharts": "^5.0.0",
|
||||
"chart.js": "^4.5.1",
|
||||
"flag-icons": "^7.2.3",
|
||||
"litepicker": "^2.0.12",
|
||||
"sortable-tablesort": "^4.1.7",
|
||||
|
||||
@@ -279,8 +279,6 @@ class Service implements InjectionAwareInterface
|
||||
public function getAdminNavigation($admin, $url = null)
|
||||
{
|
||||
$staff_service = $this->di['mod_service']('staff');
|
||||
$current_mod = null;
|
||||
$current_url = null;
|
||||
$nav = [];
|
||||
$subpages = [];
|
||||
|
||||
@@ -301,6 +299,7 @@ class Service implements InjectionAwareInterface
|
||||
$l = $n['group']['location'];
|
||||
unset($n['group']['location']);
|
||||
$n['group']['active'] = false;
|
||||
$n['group']['uri'] = $this->normalizeNavigationUri($n['group']['uri'] ?? null);
|
||||
$nav[$l] = $n['group'];
|
||||
}
|
||||
|
||||
@@ -331,17 +330,54 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$l = $page['location'];
|
||||
unset($page['location']);
|
||||
$page['uri'] = $this->normalizeNavigationUri($page['uri'] ?? null);
|
||||
$nav[$l]['subpages'][] = $page;
|
||||
}
|
||||
|
||||
// submenu sorting
|
||||
foreach ($nav as &$group) {
|
||||
$group['subpages'] = $this->di['tools']->sortByOneKey($group['subpages'], 'index');
|
||||
$group['uri'] = $this->resolveNavigationGroupUri($group);
|
||||
}
|
||||
|
||||
return $nav;
|
||||
}
|
||||
|
||||
private function resolveNavigationGroupUri(array $group): ?string
|
||||
{
|
||||
$groupUri = $this->normalizeNavigationUri($group['uri'] ?? null);
|
||||
if (!empty($groupUri)) {
|
||||
return $groupUri;
|
||||
}
|
||||
|
||||
foreach ($group['subpages'] ?? [] as $subpage) {
|
||||
$subpageUri = $this->normalizeNavigationUri($subpage['uri'] ?? null);
|
||||
if (!empty($subpageUri)) {
|
||||
return $subpageUri;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function normalizeNavigationUri(?string $uri): ?string
|
||||
{
|
||||
if (is_null($uri)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uri = trim($uri);
|
||||
if ($uri === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match('/^(?:[a-z][a-z0-9+.-]*:|\/|#|\?)/i', $uri) === 1) {
|
||||
return $uri;
|
||||
}
|
||||
|
||||
return $this->di['url']->adminLink(ltrim($uri, '/'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Model_Extension
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@ class Admin implements \FOSSBilling\InjectionAwareInterface
|
||||
'index' => 400,
|
||||
'location' => 'invoice',
|
||||
'label' => __trans('Invoices'),
|
||||
'uri' => 'invoice',
|
||||
'uri' => $this->di['url']->adminLink('invoice'),
|
||||
'class' => 'invoices',
|
||||
],
|
||||
'subpages' => [
|
||||
|
||||
@@ -528,7 +528,9 @@ class Service implements InjectionAwareInterface
|
||||
'txn_id' => $transactionId,
|
||||
]);
|
||||
|
||||
return $transactionService->processTransaction($newtx);
|
||||
$result = $transactionService->processTransaction($newtx);
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
return $this->markAsPaid($invoice, false, $execute);
|
||||
|
||||
@@ -21,6 +21,7 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
private const int PROCESSING_RECOVERY_TIMEOUT = 300;
|
||||
|
||||
protected ?\Pimple\Container $di = null;
|
||||
private ?bool $transactionIpnHashColumnExists = null;
|
||||
|
||||
public function setDi(\Pimple\Container $di): void
|
||||
{
|
||||
@@ -139,7 +140,8 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
// Fallback dedupe: compute a canonical hash of the IPN payload and
|
||||
// look up an existing transaction by (gateway_id, ipn_hash).
|
||||
$ipn_hash = $this->ipnHash($ipn);
|
||||
if (!empty($data['gateway_id']) && !empty($ipn_hash)) {
|
||||
$supportsIpnHash = $this->supportsTransactionIpnHash();
|
||||
if ($supportsIpnHash && !empty($data['gateway_id']) && !empty($ipn_hash)) {
|
||||
$existingByHash = $this->di['db']->findOne('Transaction', 'gateway_id = ? AND ipn_hash = ?', [$data['gateway_id'], $ipn_hash]);
|
||||
if ($existingByHash instanceof \Model_Transaction) {
|
||||
$this->di['logger']->info('Duplicate transaction detected by IPN hash, returning existing transaction #%s', $existingByHash->id);
|
||||
@@ -152,7 +154,9 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
$transaction->gateway_id = $data['gateway_id'] ?? null;
|
||||
$transaction->invoice_id = $data['invoice_id'] ?? null;
|
||||
$transaction->txn_id = $data['txn_id'] ?? null;
|
||||
$transaction->ipn_hash = $ipn_hash ?? null;
|
||||
if ($supportsIpnHash) {
|
||||
$transaction->ipn_hash = $ipn_hash ?? null;
|
||||
}
|
||||
$transaction->status = 'received';
|
||||
$transaction->ip = $this->di['request']->getClientIp();
|
||||
$transaction->ipn = json_encode($ipn);
|
||||
@@ -168,6 +172,31 @@ class ServiceTransaction implements InjectionAwareInterface
|
||||
return $newId;
|
||||
}
|
||||
|
||||
private function supportsTransactionIpnHash(): bool
|
||||
{
|
||||
if ($this->transactionIpnHashColumnExists !== null) {
|
||||
return $this->transactionIpnHashColumnExists;
|
||||
}
|
||||
|
||||
try {
|
||||
$schemaManager = $this->di['dbal']->createSchemaManager();
|
||||
$columns = array_map(static fn ($column) => $column->getName(), $schemaManager->listTableColumns('transaction'));
|
||||
$indexes = array_map(static fn ($index) => $index->getName(), $schemaManager->listTableIndexes('transaction'));
|
||||
|
||||
$supported = in_array('ipn_hash', $columns, true) && in_array('transaction_ipn_hash_idx', $indexes, true);
|
||||
} catch (\Throwable $e) {
|
||||
if (isset($this->di['logger'])) {
|
||||
$this->di['logger']->warn('Could not determine whether transaction.ipn_hash exists; disabling IPN hash dedupe: %s', $e->getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->transactionIpnHashColumnExists = $supported;
|
||||
|
||||
return $this->transactionIpnHashColumnExists;
|
||||
}
|
||||
|
||||
public function delete(\Model_Transaction $model): bool
|
||||
{
|
||||
$id = $model->id;
|
||||
|
||||
@@ -239,7 +239,7 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$results = $result->fetchAllKeyValue();
|
||||
|
||||
return $this->_genFlotArray($results, $time_from, $time_to);
|
||||
return $this->_genFlotArrayFloat($results, $time_from, $time_to);
|
||||
}
|
||||
|
||||
public function getIncome($data)
|
||||
@@ -272,7 +272,7 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$results = $result->fetchAllKeyValue();
|
||||
|
||||
return $this->_genFlotArray($results, $time_from, $time_to);
|
||||
return $this->_genFlotArrayFloat($results, $time_from, $time_to);
|
||||
}
|
||||
|
||||
public function getClientCountries($data)
|
||||
@@ -355,24 +355,41 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
$results = $result->fetchAllKeyValue();
|
||||
|
||||
return $this->_genFlotArray($results, $time_from, $time_to);
|
||||
return $this->_genFlotArrayInt($results, $time_from, $time_to);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $time_from
|
||||
* @param int $time_to
|
||||
*
|
||||
* @return int[][]
|
||||
* @return array<int, array{0:int, 1:int}>
|
||||
*/
|
||||
private function _genFlotArray($results, $time_from, $time_to): array
|
||||
private function _genFlotArrayInt(array $results, int $time_from, int $time_to): array
|
||||
{
|
||||
$data = [];
|
||||
// Loop between timestamps, 1 day at a time
|
||||
do {
|
||||
$time_from = strtotime('+1 day', $time_from);
|
||||
$dom = date('Y-m-d', $time_from);
|
||||
$c = $results[$dom] ?? 0;
|
||||
$data[] = [$time_from * 1000, (int) $c];
|
||||
$data[] = [$time_from * 1000, (int) ($results[$dom] ?? 0)];
|
||||
} while ($time_to > $time_from);
|
||||
array_pop($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $time_from
|
||||
* @param int $time_to
|
||||
*
|
||||
* @return array<int, array{0:int, 1:float}>
|
||||
*/
|
||||
private function _genFlotArrayFloat(array $results, int $time_from, int $time_to): array
|
||||
{
|
||||
$data = [];
|
||||
do {
|
||||
$time_from = strtotime('+1 day', $time_from);
|
||||
$dom = date('Y-m-d', $time_from);
|
||||
$data[] = [$time_from * 1000, round((float) ($results[$dom] ?? 0), 2)];
|
||||
} while ($time_to > $time_from);
|
||||
array_pop($data);
|
||||
|
||||
|
||||
@@ -4,12 +4,10 @@ import { coloris, init } from '@melloware/coloris';
|
||||
import * as tabler from '@tabler/core/js/tabler.js';
|
||||
import './js/tomselect';
|
||||
import './js/datepicker';
|
||||
import ApexCharts from 'apexcharts';
|
||||
import './js/ui/theme_settings';
|
||||
import './js/fossbilling';
|
||||
import 'sortable-tablesort/dist/sortable.min.js';
|
||||
|
||||
globalThis.ApexCharts = ApexCharts;
|
||||
globalThis.bootstrap = tabler.bootstrap;
|
||||
|
||||
init();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import backToTop from "./ui/backToTop";
|
||||
import { renderTimeSeriesSparkline } from "./ui/charts";
|
||||
|
||||
globalThis.FOSSBilling = {
|
||||
message: (message, type = "info") => {
|
||||
@@ -87,6 +88,10 @@ globalThis.FOSSBilling = {
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
charts: {
|
||||
renderTimeSeriesSparkline,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
import Chart from 'chart.js/auto';
|
||||
|
||||
const chartInstances = new WeakMap();
|
||||
|
||||
function getChartElement(target) {
|
||||
if (typeof target === 'string') {
|
||||
return document.getElementById(target) || document.querySelector(target);
|
||||
}
|
||||
|
||||
return target instanceof HTMLElement ? target : null;
|
||||
}
|
||||
|
||||
function getThemeMode() {
|
||||
const rootTheme = document.documentElement.getAttribute('data-bs-theme');
|
||||
const storedTheme = localStorage.getItem('theme');
|
||||
|
||||
return rootTheme || storedTheme || 'light';
|
||||
}
|
||||
|
||||
function getThemeColors() {
|
||||
if (getThemeMode() === 'dark') {
|
||||
return {
|
||||
border: '#91bbed',
|
||||
fill: 'rgba(145, 187, 237, 0.16)',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
border: '#206bc4',
|
||||
fill: 'rgba(32, 107, 196, 0.16)',
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeTimeSeriesData(data) {
|
||||
if (!Array.isArray(data)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return data
|
||||
.filter(point => Array.isArray(point) && point.length >= 2)
|
||||
.map(point => ({
|
||||
x: Number(point[0]),
|
||||
y: Number(point[1]),
|
||||
}))
|
||||
.filter(point => Number.isFinite(point.x) && Number.isFinite(point.y));
|
||||
}
|
||||
|
||||
function formatTooltipDate(timestamp) {
|
||||
return new Intl.DateTimeFormat(undefined, {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
}).format(new Date(timestamp));
|
||||
}
|
||||
|
||||
function formatTooltipValue(value, options) {
|
||||
const numericValue = Number(value);
|
||||
if (!Number.isFinite(numericValue)) {
|
||||
return String(value);
|
||||
}
|
||||
|
||||
if (options.valueFormat === 'currency' && options.currency) {
|
||||
try {
|
||||
return new Intl.NumberFormat(undefined, {
|
||||
style: 'currency',
|
||||
currency: options.currency,
|
||||
currencyDisplay: 'narrowSymbol',
|
||||
}).format(numericValue);
|
||||
} catch (error) {
|
||||
// Ignore invalid currency codes and fall back to numeric formatting.
|
||||
}
|
||||
}
|
||||
|
||||
return new Intl.NumberFormat(undefined, {
|
||||
maximumFractionDigits: 0,
|
||||
}).format(numericValue);
|
||||
}
|
||||
|
||||
export function renderTimeSeriesSparkline(target, data, options = {}) {
|
||||
const container = getChartElement(target);
|
||||
if (!container) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const existingChart = chartInstances.get(container);
|
||||
if (existingChart) {
|
||||
existingChart.destroy();
|
||||
chartInstances.delete(container);
|
||||
}
|
||||
|
||||
const series = normalizeTimeSeriesData(data);
|
||||
const label = options.label || 'Series';
|
||||
const height = Number.isFinite(options.height) ? options.height : 140;
|
||||
const { border, fill } = getThemeColors();
|
||||
const firstPoint = series[0] || null;
|
||||
const lastPoint = series[series.length - 1] || null;
|
||||
|
||||
container.replaceChildren();
|
||||
container.style.width = '100%';
|
||||
container.style.height = `${height}px`;
|
||||
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.setAttribute('aria-label', label);
|
||||
canvas.setAttribute('role', 'img');
|
||||
container.appendChild(canvas);
|
||||
|
||||
const chart = new Chart(canvas, {
|
||||
type: 'line',
|
||||
data: {
|
||||
datasets: [{
|
||||
label,
|
||||
data: series,
|
||||
parsing: false,
|
||||
borderColor: border,
|
||||
backgroundColor: fill,
|
||||
borderWidth: 2,
|
||||
tension: 0.4,
|
||||
cubicInterpolationMode: 'monotone',
|
||||
fill: true,
|
||||
pointRadius: 0,
|
||||
pointHoverRadius: options.showTooltip ? 3 : 0,
|
||||
pointHitRadius: options.showTooltip ? 16 : 8,
|
||||
borderCapStyle: 'round',
|
||||
}],
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
animation: false,
|
||||
normalized: true,
|
||||
interaction: {
|
||||
mode: 'nearest',
|
||||
axis: 'x',
|
||||
intersect: false,
|
||||
},
|
||||
layout: {
|
||||
padding: 0,
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false,
|
||||
},
|
||||
tooltip: {
|
||||
enabled: Boolean(options.showTooltip),
|
||||
displayColors: false,
|
||||
callbacks: {
|
||||
title(items) {
|
||||
const timestamp = items[0]?.raw?.x;
|
||||
return Number.isFinite(timestamp) ? formatTooltipDate(timestamp) : '';
|
||||
},
|
||||
label(context) {
|
||||
const formattedValue = formatTooltipValue(context.raw?.y, options);
|
||||
return `${label}: ${formattedValue}`;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
type: 'linear',
|
||||
bounds: 'data',
|
||||
display: false,
|
||||
min: firstPoint ? firstPoint.x : undefined,
|
||||
max: lastPoint ? lastPoint.x : undefined,
|
||||
offset: false,
|
||||
grid: {
|
||||
display: false,
|
||||
drawBorder: false,
|
||||
},
|
||||
border: {
|
||||
display: false,
|
||||
},
|
||||
},
|
||||
y: {
|
||||
display: false,
|
||||
beginAtZero: true,
|
||||
grace: 0,
|
||||
grid: {
|
||||
display: false,
|
||||
drawBorder: false,
|
||||
},
|
||||
border: {
|
||||
display: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
elements: {
|
||||
line: {
|
||||
capBezierPoints: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
chartInstances.set(container, chart);
|
||||
|
||||
return chart;
|
||||
}
|
||||
@@ -150,13 +150,13 @@
|
||||
{% for location, group in navigation %}
|
||||
{% if group.subpages %}
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#navbar-base" data-bs-toggle="dropdown" data-bs-auto-close="outside" role="button" aria-expanded="false" >
|
||||
<a class="nav-link dropdown-toggle" href="{{ group.uri ?: '#' }}" data-bs-toggle="dropdown" data-bs-auto-close="outside" role="button" aria-expanded="false" >
|
||||
<svg class="icon icon-tabler icon-tabler-arrow-back-up d-none d-xxl-block me-1">
|
||||
<use xlink:href="#{{ group.class }}" />
|
||||
</svg>
|
||||
<span class="nav-link-title">{{ group.label|trans }}</span>
|
||||
</a>
|
||||
<div class="dropdown-menu">
|
||||
</a>
|
||||
<div class="dropdown-menu">
|
||||
<div class="dropdown-menu-columns">
|
||||
<div class="dropdown-menu-column">
|
||||
{% for subpage in group.subpages %}
|
||||
|
||||
@@ -256,18 +256,25 @@
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table card-table table-vcenter table-striped text-nowrap">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ 'Invoice #'|trans }}</th>
|
||||
<th>{{ 'Client'|trans }}</th>
|
||||
<th class="text-center">{{ 'Amount'|trans }}</th>
|
||||
<th class="text-center">{{ 'Created At'|trans }}</th>
|
||||
<th>{{ 'Status'|trans }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for invoice in invoicesUnpaid.list %}
|
||||
<tr>
|
||||
<td class="w-1">
|
||||
<a href='{{ "invoice/manage/#{invoice.id}"|url }}'>{{ invoice.serie_nr }}</a>
|
||||
</td>
|
||||
<td class="w-1">
|
||||
<td>
|
||||
<a href='{{ "client/manage/#{invoice.client.id}"|url }}'>
|
||||
{{ mf.avatar(invoice.buyer.email, 24, 'db-avatar avatar avatar-xs') }}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
</a>
|
||||
<a href='{{ "client/manage/#{invoice.client.id}"|url }}'>{{ invoice.buyer.first_name }} {{ invoice.buyer.last_name }}</a>
|
||||
</td>
|
||||
<td class="text-center">{{ invoice.total|format_currency(invoice.currency ?? default_currency) }}</td>
|
||||
@@ -316,10 +323,19 @@
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table card-table table-vcenter table-striped text-nowrap">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ 'Client'|trans }}</th>
|
||||
<th>{{ 'Order Title'|trans }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for order in orders.list %}
|
||||
<tr title="{{ order.created_at|timeago }} {{ 'ago'|trans }}">
|
||||
<td>
|
||||
<a href='{{ "client/manage/#{order.client.id}"|url }}'>
|
||||
{{ mf.avatar(order.client.email, 24, 'db-avatar avatar avatar-xs') }}
|
||||
</a>
|
||||
<a href='{{ "client/manage/#{order.client_id}"|url }}'>{{ order.client.first_name }} {{ order.client.last_name }}</a>
|
||||
</td>
|
||||
<td>
|
||||
@@ -337,37 +353,37 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# <div class="col-lg-6">
|
||||
<div class="widget card">
|
||||
<div class="head">
|
||||
<h5 class="iGraph">{{ 'Product sales'|trans }}</h5>
|
||||
{% if admin.system_is_allowed({ 'mod': 'stats' }) %}
|
||||
<div class="col-lg-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">{{ 'Product Sales'|trans }}</h3>
|
||||
</div>
|
||||
<div>
|
||||
<table class="tableStatic wide">
|
||||
<div class="table-responsive">
|
||||
<table class="table card-table table-vcenter table-striped text-nowrap">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{{ 'Product/Service'|trans }}</td>
|
||||
<td>{{ 'Orders'|trans }}</td>
|
||||
<th>{{ 'Product/Service'|trans }}</th>
|
||||
<th>{{ 'Orders'|trans }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for p in admin.stats_get_product_summary %}
|
||||
<tr>
|
||||
<td><a href='{{ "product/manage/#{p.id}"|url }}' title="{{ p.title }}">{{ p.title|truncate(35) }}</a></td>
|
||||
<td>
|
||||
<a href='{{ "product/manage/#{p.id}"|url }}' title="{{ p.title }}">{{ p.title|truncate(35) }}</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href='{{ 'order'|url(query: { 'product_id': p.id }) }}' class="webStatsLink">{{ p.orders }}</a>
|
||||
<a href='{{ 'order'|url(query: { 'product_id': p.id }) }}'>{{ p.orders }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="2" align="center">{{ 'No active orders available'|trans }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div> #}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if admin.system_is_allowed({ 'mod': 'stats' }) %}
|
||||
@@ -452,21 +468,25 @@
|
||||
<div class="tab-content" id="tabs">
|
||||
<div class="tab-pane fade show active" id="tab-index" role="tabpanel">
|
||||
<table class="table table-vcenter card-table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ 'Client'|trans }}</th>
|
||||
<th>{{ 'Message'|trans }}</th>
|
||||
<th class="text-center">{{ 'Date/Time'|trans }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% set events = admin.activity_log_get_list({ 'per_page': 10, 'user_filter': 'only_clients' }) %}
|
||||
{% for i, event in events.list %}
|
||||
<tr>
|
||||
<td class="w-1">
|
||||
<td>
|
||||
<a href='{{ "client/manage/#{event.client.id}"|url }}'>
|
||||
{{ mf.avatar(event.client.email, 24, 'db-avatar avatar avatar-xs') }}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
</a>
|
||||
<a href='{{ "client/manage/#{event.client.id}"|url }}'>{{ event.client.name|truncate(40) }}</a>
|
||||
</td>
|
||||
<td>{{ event.message|truncate(50) }}</td>
|
||||
<td>{{ event.created_at|format_datetime }}</td>
|
||||
<td>{{ event.created_at|timeago }} {{ 'ago'|trans }}</td>
|
||||
<td class="text-center">{{ event.created_at|format_datetime }} ({{ event.created_at|timeago }} {{ 'ago'|trans }})</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
@@ -479,21 +499,25 @@
|
||||
|
||||
<div class="tab-pane fade" id="tab-staff" role="tabpanel">
|
||||
<table class="table table-vcenter card-table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ 'Staff Member'|trans }}</th>
|
||||
<th>{{ 'Message'|trans }}</th>
|
||||
<th class="text-center">{{ 'Date/Time'|trans }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% set events = admin.activity_log_get_list({ 'per_page': 10, 'user_filter': 'only_staff' }) %}
|
||||
{% for i, event in events.list %}
|
||||
<tr>
|
||||
<td class="w-1">
|
||||
<td>
|
||||
<a href='{{ "staff/manage/#{event.staff.id}"|url }}'>
|
||||
{{ mf.avatar(event.staff.email, 24, 'db-avatar avatar avatar-xs') }}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
</a>
|
||||
<a href='{{ "staff/manage/#{event.staff.id}"|url }}'>{{ event.staff.name }}</a>
|
||||
</td>
|
||||
<td>{{ event.message|truncate(50) }}</td>
|
||||
<td>{{ event.created_at|format_datetime }}</td>
|
||||
<td>{{ event.created_at|timeago }} {{ 'ago'|trans }}</td>
|
||||
<td class="text-center">{{ event.created_at|format_datetime }} ({{ event.created_at|timeago }} {{ 'ago'|trans }})</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
@@ -514,75 +538,34 @@
|
||||
{% if admin.system_is_allowed({ 'mod': 'stats' }) %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
setPlotDataData('chart-income', {{ admin.stats_get_income({ 'date_from': request.date_from, 'date_to': request.date_to })|json_encode }}, "{{ 'Income'|trans }}" );
|
||||
setPlotDataData('chart-orders', {{ admin.stats_get_orders({ 'date_from': request.date_from, 'date_to': request.date_to })|json_encode }}, "{{ 'Orders'|trans }}" );
|
||||
setPlotDataData('chart-invoices', {{ admin.stats_get_invoices({ 'date_from': request.date_from, 'date_to': request.date_to })|json_encode }},"{{ 'Invoices'|trans }}" );
|
||||
setPlotDataData('chart-clients', {{ admin.stats_get_clients({ 'date_from': request.date_from, 'date_to': request.date_to })|json_encode }}, "{{ 'Clients'|trans }}" );
|
||||
setPlotDataData('chart-tickets', {{ admin.stats_get_tickets({ 'date_from': request.date_from, 'date_to': request.date_to })|json_encode }}, "{{ 'Tickets'|trans }}");
|
||||
});
|
||||
|
||||
function setPlotDataData(elementId, data, displayName="Name Placeholder") {
|
||||
new ApexCharts(document.getElementById(elementId), {
|
||||
chart: {
|
||||
type: 'area',
|
||||
fontFamily: 'inherit',
|
||||
height: 140,
|
||||
parentHeightOffset: 0,
|
||||
toolbar: {
|
||||
show: false,
|
||||
},
|
||||
animations: {
|
||||
enabled: false
|
||||
},
|
||||
},
|
||||
dataLabels: {
|
||||
enabled: false,
|
||||
},
|
||||
fill: {
|
||||
opacity: .16,
|
||||
type: 'solid'
|
||||
},
|
||||
stroke: {
|
||||
width: 2,
|
||||
lineCap: "round",
|
||||
curve: "smooth",
|
||||
},
|
||||
series: [{
|
||||
name: displayName,
|
||||
data: data
|
||||
const charts = [
|
||||
['chart-income', {{ admin.stats_get_income({ 'date_from': request.date_from, 'date_to': request.date_to })|json_encode }}, {
|
||||
label: "{{ 'Income'|trans }}",
|
||||
valueFormat: 'currency',
|
||||
currency: "{{ currency.code ?: default_currency }}",
|
||||
}],
|
||||
grid: {
|
||||
padding: {
|
||||
top: -20,
|
||||
right: 0,
|
||||
left: -4,
|
||||
bottom: -4
|
||||
},
|
||||
strokeDashArray: 4,
|
||||
},
|
||||
xaxis: {
|
||||
labels: {
|
||||
show: false
|
||||
},
|
||||
type: 'datetime',
|
||||
},
|
||||
yaxis: {
|
||||
labels: {
|
||||
show: false
|
||||
},
|
||||
},
|
||||
labels: {
|
||||
show: false,
|
||||
},
|
||||
colors: (localStorage.getItem('theme') === 'dark') ? ["#91bbed"] : ["#206bc4"],
|
||||
theme : {
|
||||
mode: (localStorage.getItem('theme') === 'dark') ? 'dark' : 'light',
|
||||
monochrome: {
|
||||
enabled: false,
|
||||
}
|
||||
}
|
||||
}).render();
|
||||
}
|
||||
['chart-orders', {{ admin.stats_get_orders({ 'date_from': request.date_from, 'date_to': request.date_to })|json_encode }}, {
|
||||
label: "{{ 'Orders'|trans }}",
|
||||
}],
|
||||
['chart-invoices', {{ admin.stats_get_invoices({ 'date_from': request.date_from, 'date_to': request.date_to })|json_encode }}, {
|
||||
label: "{{ 'Invoices'|trans }}",
|
||||
}],
|
||||
['chart-clients', {{ admin.stats_get_clients({ 'date_from': request.date_from, 'date_to': request.date_to })|json_encode }}, {
|
||||
label: "{{ 'Clients'|trans }}",
|
||||
}],
|
||||
['chart-tickets', {{ admin.stats_get_tickets({ 'date_from': request.date_from, 'date_to': request.date_to })|json_encode }}, {
|
||||
label: "{{ 'Tickets'|trans }}",
|
||||
}],
|
||||
];
|
||||
|
||||
charts.forEach(function([elementId, data, chartOptions]) {
|
||||
FOSSBilling.charts.renderTimeSeriesSparkline(elementId, data, {
|
||||
height: 140,
|
||||
showTooltip: true,
|
||||
...chartOptions,
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -9,7 +9,7 @@
|
||||
"@dicebear/identicon": "^9.0.0",
|
||||
"@melloware/coloris": "^0.25.0",
|
||||
"@tabler/core": "^1.2.0",
|
||||
"apexcharts": "^5.0.0",
|
||||
"chart.js": "^4.5.1",
|
||||
"flag-icons": "^7.2.3",
|
||||
"litepicker": "^2.0.12",
|
||||
"sortable-tablesort": "^4.1.7",
|
||||
|
||||
@@ -271,11 +271,17 @@ final class ServiceTest extends \BBTestCase
|
||||
};
|
||||
|
||||
$link = 'extension';
|
||||
|
||||
$urlMock = $this->createMock('Box_Url');
|
||||
$urlMock->expects($this->atLeastOnce())
|
||||
->method('adminLink')
|
||||
->willReturn('http://fossbilling.org/index.php?_url=/' . $link);
|
||||
->willReturnCallback(static function (string $path, array $query = []): string {
|
||||
$url = 'http://fossbilling.org/index.php?_url=/' . ltrim($path, '/');
|
||||
if (!empty($query)) {
|
||||
$url .= '&' . http_build_query($query);
|
||||
}
|
||||
|
||||
return $url;
|
||||
});
|
||||
|
||||
$di = $this->getDi();
|
||||
$di['mod'] = $di->protect(function ($name) use ($di) {
|
||||
@@ -298,6 +304,9 @@ final class ServiceTest extends \BBTestCase
|
||||
$this->service->setDi($di);
|
||||
$result = $this->service->getAdminNavigation(new \Model_Admin());
|
||||
$this->assertIsArray($result);
|
||||
$this->assertSame('http://fossbilling.org/index.php?_url=/' . $link, $result['extensions']['uri']);
|
||||
$this->assertSame('http://fossbilling.org/index.php?_url=/system', $result['system']['uri']);
|
||||
$this->assertSame('http://fossbilling.org/index.php?_url=/invoice', $result['invoice']['uri']);
|
||||
}
|
||||
|
||||
public function testFindExtension(): void
|
||||
|
||||
@@ -712,6 +712,56 @@ final class ServiceTest extends \BBTestCase
|
||||
$this->assertSame(5, $invoiceModel->gateway_id);
|
||||
}
|
||||
|
||||
public function testMarkAsPaidByAdminReturnsBoolWhenCustomGatewayProcessingReturnsNonBool(): void
|
||||
{
|
||||
$invoiceModel = new \Model_Invoice();
|
||||
$invoiceModel->loadBean(new \DummyBean());
|
||||
$invoiceModel->id = 42;
|
||||
$invoiceModel->gateway_id = 5;
|
||||
$invoiceModel->currency = 'USD';
|
||||
|
||||
$gatewayModel = new \Model_PayGateway();
|
||||
$gatewayModel->loadBean(new \DummyBean());
|
||||
$gatewayModel->id = 5;
|
||||
$gatewayModel->gateway = 'Custom';
|
||||
$gatewayModel->enabled = 1;
|
||||
|
||||
$transactionServiceMock = $this->createMock(ServiceTransaction::class);
|
||||
$transactionServiceMock->expects($this->once())
|
||||
->method('create')
|
||||
->willReturn(99);
|
||||
$transactionServiceMock->expects($this->once())
|
||||
->method('processTransaction')
|
||||
->with(99)
|
||||
->willReturn(99);
|
||||
|
||||
$serviceMock = $this->getMockBuilder(Service::class)
|
||||
->onlyMethods(['markAsPaid'])
|
||||
->getMock();
|
||||
$serviceMock->expects($this->never())
|
||||
->method('markAsPaid');
|
||||
|
||||
$dbMock = $this->createMock('\Box_Database');
|
||||
$dbMock->expects($this->once())
|
||||
->method('getExistingModelById')
|
||||
->with('PayGateway', 5, 'Payment gateway not found')
|
||||
->willReturn($gatewayModel);
|
||||
|
||||
$di = $this->getDi();
|
||||
$di['db'] = $dbMock;
|
||||
$di['logger'] = new \Box_Log();
|
||||
$di['mod_service'] = $di->protect(fn (string $serviceName, string $sub = ''): \PHPUnit\Framework\MockObject\MockObject => match ([$serviceName, $sub]) {
|
||||
['Invoice', 'Transaction'] => $transactionServiceMock,
|
||||
default => throw new \RuntimeException('Unexpected service request'),
|
||||
});
|
||||
|
||||
$serviceMock->setDi($di);
|
||||
|
||||
$this->assertTrue($serviceMock->markAsPaidByAdmin($invoiceModel, [
|
||||
'transactionId' => 'manual-txn-2',
|
||||
]));
|
||||
}
|
||||
|
||||
public function testMarkAsPaidByAdminRequiresTransactionIdForCustomGateway(): void
|
||||
{
|
||||
$invoiceModel = new \Model_Invoice();
|
||||
|
||||
@@ -621,10 +621,58 @@ final class ServiceTransactionTest extends \BBTestCase
|
||||
$existing->id = 123;
|
||||
$existing->status = \Model_Transaction::STATUS_PROCESSED;
|
||||
|
||||
$schemaManager = new class()
|
||||
{
|
||||
public function listTableColumns(string $table): array
|
||||
{
|
||||
return [
|
||||
new class()
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'ipn_hash';
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function listTableIndexes(string $table): array
|
||||
{
|
||||
return [
|
||||
new class()
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'transaction_ipn_hash_idx';
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
$dbal = new class($schemaManager)
|
||||
{
|
||||
public function __construct(private object $schemaManager)
|
||||
{
|
||||
}
|
||||
|
||||
public function createSchemaManager(): object
|
||||
{
|
||||
return $this->schemaManager;
|
||||
}
|
||||
|
||||
public function executeStatement(string $sql): void
|
||||
{
|
||||
throw new \RuntimeException('Unexpected schema repair query: ' . $sql);
|
||||
}
|
||||
};
|
||||
|
||||
$dbMock = $this->createMock('\Box_Database');
|
||||
$dbMock->expects($this->atLeastOnce())
|
||||
->method('findOne')
|
||||
->willReturn($existing);
|
||||
$dbMock->expects($this->never())
|
||||
->method('dispense');
|
||||
|
||||
$eventsMock = $this->createMock('\Box_EventManager');
|
||||
$eventsMock->expects($this->atLeastOnce())
|
||||
@@ -632,6 +680,7 @@ final class ServiceTransactionTest extends \BBTestCase
|
||||
|
||||
$di = $this->getDi();
|
||||
$di['db'] = $dbMock;
|
||||
$di['dbal'] = $dbal;
|
||||
$di['events_manager'] = $eventsMock;
|
||||
$di['logger'] = new \Box_Log();
|
||||
|
||||
@@ -649,4 +698,225 @@ final class ServiceTransactionTest extends \BBTestCase
|
||||
$resultId = $this->service->create($data);
|
||||
$this->assertEquals(123, $resultId);
|
||||
}
|
||||
|
||||
public function testCreateSkipsIpnHashLookupWhenSchemaDoesNotHaveColumn(): void
|
||||
{
|
||||
$transactionModel = new \Model_Transaction();
|
||||
$transactionModel->loadBean(new \DummyBean());
|
||||
$payGatewayModel = new \Model_PayGateway();
|
||||
$payGatewayModel->loadBean(new \DummyBean());
|
||||
$invoiceModel = new \Model_Invoice();
|
||||
$invoiceModel->loadBean(new \DummyBean());
|
||||
|
||||
$schemaManager = new class()
|
||||
{
|
||||
public function listTableColumns(string $table): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function listTableIndexes(string $table): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
$dbal = new class($schemaManager)
|
||||
{
|
||||
public function __construct(private object $schemaManager)
|
||||
{
|
||||
}
|
||||
|
||||
public function createSchemaManager(): object
|
||||
{
|
||||
return $this->schemaManager;
|
||||
}
|
||||
|
||||
public function executeStatement(string $sql): void
|
||||
{
|
||||
throw new \RuntimeException('No SQL statements should be executed during transaction creation: ' . $sql);
|
||||
}
|
||||
};
|
||||
|
||||
$dbMock = $this->createMock('\Box_Database');
|
||||
$dbMock->expects($this->once())
|
||||
->method('findOne')
|
||||
->willReturnCallback(function (string $model, string $sql, array $bindings) {
|
||||
$this->assertSame('Transaction', $model);
|
||||
$this->assertSame('txn_id = ? AND gateway_id = ?', $sql);
|
||||
$this->assertSame(['manual-txn-1', 5], $bindings);
|
||||
|
||||
return null;
|
||||
});
|
||||
$dbMock->expects($this->once())
|
||||
->method('dispense')
|
||||
->with('Transaction')
|
||||
->willReturn($transactionModel);
|
||||
$dbMock->expects($this->once())
|
||||
->method('store')
|
||||
->with($this->callback(function (\Model_Transaction $transaction): bool {
|
||||
$this->assertSame(5, $transaction->gateway_id);
|
||||
$this->assertSame(42, $transaction->invoice_id);
|
||||
$this->assertSame('manual-txn-1', $transaction->txn_id);
|
||||
$this->assertNull($transaction->ipn_hash);
|
||||
|
||||
return true;
|
||||
}))
|
||||
->willReturn(99);
|
||||
$dbMock->expects($this->exactly(3))
|
||||
->method('getExistingModelById')
|
||||
->willReturnCallback(function (string $modelName, int $id, string $message) use ($payGatewayModel, $invoiceModel) {
|
||||
static $calls = 0;
|
||||
$calls++;
|
||||
|
||||
if ($calls === 1) {
|
||||
$this->assertSame('PayGateway', $modelName);
|
||||
$this->assertSame(5, $id);
|
||||
$this->assertSame('Gateway was not found', $message);
|
||||
|
||||
return $payGatewayModel;
|
||||
}
|
||||
|
||||
if ($calls === 2) {
|
||||
$this->assertSame('Invoice', $modelName);
|
||||
$this->assertSame(42, $id);
|
||||
$this->assertSame('Invoice was not found', $message);
|
||||
|
||||
return $invoiceModel;
|
||||
}
|
||||
|
||||
if ($calls === 3) {
|
||||
$this->assertSame('PayGateway', $modelName);
|
||||
$this->assertSame(5, $id);
|
||||
$this->assertSame('Gateway was not found', $message);
|
||||
|
||||
return $payGatewayModel;
|
||||
}
|
||||
|
||||
$this->fail('Unexpected getExistingModelById call');
|
||||
});
|
||||
|
||||
$requestMock = new class()
|
||||
{
|
||||
public function getClientIp(): string
|
||||
{
|
||||
return '127.0.0.1';
|
||||
}
|
||||
};
|
||||
|
||||
$eventsMock = $this->createMock('\Box_EventManager');
|
||||
$eventsMock->expects($this->exactly(2))
|
||||
->method('fire');
|
||||
|
||||
$di = $this->getDi();
|
||||
$di['db'] = $dbMock;
|
||||
$di['dbal'] = $dbal;
|
||||
$di['request'] = $requestMock;
|
||||
$di['events_manager'] = $eventsMock;
|
||||
$di['logger'] = new \Box_Log();
|
||||
|
||||
$this->service->setDi($di);
|
||||
|
||||
$resultId = $this->service->create([
|
||||
'invoice_id' => 42,
|
||||
'gateway_id' => 5,
|
||||
'txn_id' => 'manual-txn-1',
|
||||
'source' => 'admin',
|
||||
]);
|
||||
|
||||
$this->assertSame(99, $resultId);
|
||||
}
|
||||
|
||||
public function testCreateUsesIpnHashLookupWhenSchemaSupportsColumn(): void
|
||||
{
|
||||
$existing = new \Model_Transaction();
|
||||
$existing->loadBean(new \DummyBean());
|
||||
$existing->id = 321;
|
||||
|
||||
$schemaManager = new class()
|
||||
{
|
||||
public function listTableColumns(string $table): array
|
||||
{
|
||||
return [
|
||||
new class()
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'ipn_hash';
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function listTableIndexes(string $table): array
|
||||
{
|
||||
return [
|
||||
new class()
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'transaction_ipn_hash_idx';
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
$dbal = new class($schemaManager)
|
||||
{
|
||||
public function __construct(private object $schemaManager)
|
||||
{
|
||||
}
|
||||
|
||||
public function createSchemaManager(): object
|
||||
{
|
||||
return $this->schemaManager;
|
||||
}
|
||||
|
||||
public function executeStatement(string $sql): void
|
||||
{
|
||||
throw new \RuntimeException('Unexpected schema repair query: ' . $sql);
|
||||
}
|
||||
};
|
||||
|
||||
$dbMock = $this->createMock('\Box_Database');
|
||||
$dbMock->expects($this->exactly(2))
|
||||
->method('findOne')
|
||||
->willReturnCallback(function (string $model, string $sql, array $bindings) use ($existing) {
|
||||
if ($sql === 'txn_id = ? AND gateway_id = ?') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($sql === 'gateway_id = ? AND ipn_hash = ?') {
|
||||
$this->assertSame('Transaction', $model);
|
||||
$this->assertSame(5, $bindings[0]);
|
||||
$this->assertMatchesRegularExpression('/^[a-f0-9]{64}$/', $bindings[1]);
|
||||
|
||||
return $existing;
|
||||
}
|
||||
|
||||
$this->fail('Unexpected findOne lookup: ' . $sql);
|
||||
});
|
||||
|
||||
$eventsMock = $this->createMock('\Box_EventManager');
|
||||
$eventsMock->expects($this->once())
|
||||
->method('fire');
|
||||
|
||||
$di = $this->getDi();
|
||||
$di['db'] = $dbMock;
|
||||
$di['dbal'] = $dbal;
|
||||
$di['events_manager'] = $eventsMock;
|
||||
$di['logger'] = new \Box_Log();
|
||||
|
||||
$this->service->setDi($di);
|
||||
|
||||
$resultId = $this->service->create([
|
||||
'skip_validation' => true,
|
||||
'gateway_id' => 5,
|
||||
'txn_id' => 'manual-txn-2',
|
||||
'source' => 'admin',
|
||||
]);
|
||||
|
||||
$this->assertSame(321, $resultId);
|
||||
}
|
||||
}
|
||||
@@ -232,6 +232,37 @@ final class ServiceTest extends \BBTestCase
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
|
||||
public function testGetIncomePreservesDecimals(): void
|
||||
{
|
||||
$resultMock = $this->createMock(\Doctrine\DBAL\Result::class);
|
||||
$resultMock->expects($this->once())
|
||||
->method('fetchAllKeyValue')
|
||||
->willReturn([
|
||||
'2026-05-14' => '11.99',
|
||||
'2026-05-15' => '0.50',
|
||||
]);
|
||||
|
||||
$dbalMock = $this->createMock(\Doctrine\DBAL\Connection::class);
|
||||
$dbalMock->expects($this->once())
|
||||
->method('executeQuery')
|
||||
->willReturn($resultMock);
|
||||
|
||||
$di = $this->getDi();
|
||||
$di['dbal'] = $dbalMock;
|
||||
|
||||
$this->service->setDi($di);
|
||||
|
||||
$result = $this->service->getIncome([
|
||||
'date_from' => '2026-05-13',
|
||||
'date_to' => '2026-05-16',
|
||||
]);
|
||||
|
||||
$this->assertSame([
|
||||
[strtotime('2026-05-14') * 1000, 11.99],
|
||||
[strtotime('2026-05-15') * 1000, 0.5],
|
||||
], $result);
|
||||
}
|
||||
|
||||
public function testGetClientCountries(): void
|
||||
{
|
||||
$resultMock = $this->createMock(\Doctrine\DBAL\Result::class);
|
||||
@@ -274,6 +305,37 @@ final class ServiceTest extends \BBTestCase
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
|
||||
public function testGetTableStatsKeepsCountsAsIntegers(): void
|
||||
{
|
||||
$resultMock = $this->createMock(\Doctrine\DBAL\Result::class);
|
||||
$resultMock->expects($this->once())
|
||||
->method('fetchAllKeyValue')
|
||||
->willReturn([
|
||||
'2026-05-14' => '3',
|
||||
'2026-05-15' => '1',
|
||||
]);
|
||||
|
||||
$dbalMock = $this->createMock(\Doctrine\DBAL\Connection::class);
|
||||
$dbalMock->expects($this->once())
|
||||
->method('executeQuery')
|
||||
->willReturn($resultMock);
|
||||
|
||||
$di = $this->getDi();
|
||||
$di['dbal'] = $dbalMock;
|
||||
|
||||
$this->service->setDi($di);
|
||||
|
||||
$result = $this->service->getTableStats('invoice', [
|
||||
'date_from' => '2026-05-13',
|
||||
'date_to' => '2026-05-16',
|
||||
]);
|
||||
|
||||
$this->assertSame([
|
||||
[strtotime('2026-05-14') * 1000, 3],
|
||||
[strtotime('2026-05-15') * 1000, 1],
|
||||
], $result);
|
||||
}
|
||||
|
||||
public function testGetTableStats(): void
|
||||
{
|
||||
$resultMock = $this->createMock(\Doctrine\DBAL\Result::class);
|
||||
|
||||
Reference in new issue
Block a user