110 lines
3.6 KiB
PHP
110 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace paygw_moneta\local;
|
|
|
|
use html_writer;
|
|
use moodle_url;
|
|
use paygw_moneta\local\order\TransactionRepository;
|
|
use paygw_moneta\local\order\TransactionStatus;
|
|
use stdClass;
|
|
use table_sql;
|
|
|
|
/**
|
|
* Таблица заказов для администратора (Администрирование → Платежи → Заказы Монета).
|
|
* Показывает статусы и коды последних отказов — первое, о чём спрашивает мерчант.
|
|
*
|
|
* @package paygw_moneta
|
|
* @copyright 2026 Moneta Labs {@link https://moneta.ru/}
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class ReportTable extends table_sql
|
|
{
|
|
public function __construct(string $uniqueId, moodle_url $baseUrl)
|
|
{
|
|
parent::__construct($uniqueId);
|
|
|
|
$this->define_columns(
|
|
[
|
|
'timecreated',
|
|
'user',
|
|
'description',
|
|
'amount',
|
|
'status',
|
|
'providertransactionid',
|
|
'lasterror',
|
|
],
|
|
);
|
|
|
|
$this->define_headers([
|
|
get_string('report:time', 'paygw_moneta'),
|
|
get_string('report:user', 'paygw_moneta'),
|
|
get_string('report:description', 'paygw_moneta'),
|
|
get_string('report:amount', 'paygw_moneta'),
|
|
get_string('report:status', 'paygw_moneta'),
|
|
get_string('report:operation', 'paygw_moneta'),
|
|
get_string('report:lasterror', 'paygw_moneta'),
|
|
]);
|
|
$this->define_baseurl($baseUrl);
|
|
$this->sortable(true, 'timecreated', SORT_DESC);
|
|
$this->no_sorting('description');
|
|
$this->no_sorting('lasterror');
|
|
$this->collapsible(false);
|
|
$this->pageable(true);
|
|
|
|
$userFields = \core_user\fields::for_name()->get_sql('u')->selects;
|
|
$this->set_sql(
|
|
't.*' . $userFields,
|
|
'{' . TransactionRepository::TABLE . '} t JOIN {user} u ON u.id = t.userid',
|
|
'1 = 1',
|
|
);
|
|
}
|
|
|
|
public function col_timecreated(stdClass $row): string
|
|
{
|
|
return userdate((int) $row->timecreated, get_string('strftimedatetimeshort', 'langconfig'));
|
|
}
|
|
|
|
public function col_user(stdClass $row): string
|
|
{
|
|
return html_writer::link(new moodle_url('/user/profile.php', ['id' => $row->userid]), fullname($row));
|
|
}
|
|
|
|
public function col_description(stdClass $row): string
|
|
{
|
|
$snapshot = json_decode((string) $row->snapshot, true);
|
|
|
|
return s((string) ($snapshot['description'] ?? ''));
|
|
}
|
|
|
|
public function col_amount(stdClass $row): string
|
|
{
|
|
return Money::fromFloat((float) $row->amount)->toDecimal() . ' ' . s(CurrencySymbol::of((string) $row->currency));
|
|
}
|
|
|
|
public function col_status(stdClass $row): string
|
|
{
|
|
$status = TransactionStatus::tryFrom((string) $row->status);
|
|
$label = $status === null ? s((string) $row->status) : get_string('status:' . $status->value, 'paygw_moneta');
|
|
$class = match ($status) {
|
|
TransactionStatus::Paid => 'badge bg-success text-white',
|
|
TransactionStatus::Failed => 'badge bg-danger text-white',
|
|
TransactionStatus::Canceled => 'badge bg-secondary text-white',
|
|
default => 'badge bg-info text-white',
|
|
};
|
|
|
|
return html_writer::span($label, $class);
|
|
}
|
|
|
|
public function col_providertransactionid(stdClass $row): string
|
|
{
|
|
return s((string) ($row->providertransactionid ?? ''));
|
|
}
|
|
|
|
public function col_lasterror(stdClass $row): string
|
|
{
|
|
return s((string) ($row->lasterror ?? ''));
|
|
}
|
|
}
|