fix some bugs 3

This commit is contained in:
2026-07-21 21:38:48 +03:30
parent 356471c9f3
commit 80a2eb207a
2 changed files with 80 additions and 238 deletions
@@ -274,20 +274,22 @@ class PargarController extends Controller
$force = $request->boolean('force');
$result = app(PargarInboundWalletService::class)->syncWalletFromPargar($customer, $force);
$appliedDocs = (int) ($result['documents']['applied'] ?? 0);
$acknowledged = (int) ($result['documents']['acknowledged'] ?? 0);
$skippedDocs = (int) ($result['documents']['skipped'] ?? 0);
$batches = (int) ($result['documents']['batches'] ?? 0);
$appliedMande = (bool) ($result['mande']['applied'] ?? false);
$mandeMessage = (string) ($result['mande']['message'] ?? '');
$ok = $appliedDocs > 0 || $appliedMande;
$docErrors = $result['documents']['errors'] ?? [];
$ok = $appliedMande || $acknowledged > 0;
if ($appliedDocs > 0 && $appliedMande) {
$message = "{$appliedDocs} سند اعمال شد و مانده هم‌تراز شد";
} elseif ($appliedDocs > 0) {
$message = "{$appliedDocs} سند اعمال شد"
.($mandeMessage !== '' ? " — {$mandeMessage}" : '');
if ($appliedMande && $acknowledged > 0) {
$message = "مانده هم‌تراز شد ({$acknowledged} دسته سند مصرف شد)";
} elseif ($appliedMande) {
$message = 'مانده با پرگار هم‌تراز شد';
} elseif ($acknowledged > 0) {
$message = $mandeMessage !== ''
? "{$acknowledged} دسته سند مصرف شد — {$mandeMessage}"
: "{$acknowledged} دسته سند مصرف شد";
} elseif ($batches > 0 && $skippedDocs > 0) {
$message = $mandeMessage !== ''
? $mandeMessage
@@ -298,6 +300,10 @@ class PargarController extends Controller
: 'سند یا ماندهٔ جدیدی برای اعمال نبود';
}
if (is_array($docErrors) && $docErrors !== []) {
$message .= ' — '.implode('؛ ', array_slice($docErrors, 0, 2));
}
return response()->json([
'ok' => $ok,
'message' => $message,