added some feature for accounting

This commit is contained in:
2026-08-30 20:47:26 +03:30
parent 283f17561c
commit c27cfabd22
3 changed files with 128 additions and 0 deletions
@@ -234,6 +234,84 @@ class TahesabInboundWalletService
return $this->parseMandeRow($row);
}
/**
* مقایسهٔ کیف اپ با ماندهٔ ته‌حساب برای لیست ادمین — بدون نوشتن.
*
* @param iterable<Customer> $customers
* @return list<array<string, mixed>>
*/
public function compareCustomers(iterable $customers): array
{
$list = [];
foreach ($customers as $customer) {
if ($customer instanceof Customer) {
$list[] = $customer;
}
}
if ($list === []) {
return [];
}
$codes = [];
foreach ($list as $customer) {
$code = (int) ($customer->moshtari_code ?? 0);
if ($code > 0) {
$codes[] = $code;
}
}
$mandes = $this->fetchMandeByCodes($codes);
$rows = [];
foreach ($list as $customer) {
$code = (int) ($customer->moshtari_code ?? 0);
$mande = $code > 0 ? ($mandes[(string) $code] ?? null) : null;
$base = [
'id' => (int) $customer->id,
'name' => (string) ($customer->name ?? ''),
'mobile' => (string) ($customer->mobile ?? ''),
'moshtari_code' => $code > 0 ? $code : null,
];
if ($mande === null) {
$ownerType = (int) ($customer->type ?? 2);
$wallet = (new WalletInterface((int) $customer->id, $ownerType))->wallet;
$appGold = $this->walletBalance
->accountingVisibleMainWalletGold((int) $customer->id, $ownerType);
$appCash = (float) ($wallet->cash ?? 0);
$rows[] = array_merge($base, [
'app_gold' => $appGold,
'app_cash' => $appCash,
'tahesab_gold' => null,
'tahesab_cash' => null,
'gold_delta' => null,
'rial_delta' => null,
'status' => 'missing',
'message' => 'مانده از ته‌حساب دریافت نشد',
]);
continue;
}
$compared = $this->compareWithWallet($customer, $mande);
$same = $compared['gold_same'] && $compared['rial_same'];
$status = 'conflict';
if ($same) {
$status = 'same';
} elseif (! $compared['app_has_balance']) {
$status = 'ready';
}
$rows[] = array_merge($base, $compared['comparison'], [
'status' => $status,
'message' => $same
? 'مانده با ته‌حساب یکسان است'
: ($status === 'ready'
? 'کیف خالی است؛ همگام‌سازی مانده ته‌حساب را می‌نشاند'
: 'موجودی اپ با ته‌حساب فرق دارد'),
]);
}
return $rows;
}
/**
* @param array{gold?: float, cash?: float} $mande
* @return array{