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
@@ -874,6 +874,55 @@ class TahesabController extends Controller
]);
}
/**
* لیست مشتریان لینک‌شده با مقایسهٔ کیف و ماندهٔ ته‌حساب.
*/
public function walletLinkedList(Request $request): \Illuminate\Http\JsonResponse
{
if (! app(ConfigService::class)->isTahesabAccounting()) {
return response()->json([
'ok' => false,
'message' => 'حسابداری ته‌حساب فعال نیست',
], 422);
}
$search = trim((string) $request->input('search', ''));
$page = max(1, (int) $request->input('page', 1));
$perPage = max(1, min(50, (int) $request->input('per_page', 20)));
$base = Customer::query()
->whereNull('deleted_at')
->whereNotNull('moshtari_code')
->where('moshtari_code', '!=', '')
->where('moshtari_code', '!=', '0');
if ($search !== '') {
$base->where(function ($q) use ($search) {
$q->where('name', 'like', '%'.$search.'%')
->orWhere('mobile', 'like', '%'.$search.'%')
->orWhere('moshtari_code', 'like', '%'.$search.'%');
});
}
$total = (clone $base)->count();
$customers = (clone $base)
->orderBy('id')
->offset(($page - 1) * $perPage)
->limit($perPage)
->get(['id', 'name', 'mobile', 'moshtari_code', 'type']);
$rows = app(TahesabInboundWalletService::class)->compareCustomers($customers);
return response()->json([
'ok' => true,
'total' => $total,
'page' => $page,
'per_page' => $perPage,
'last_page' => max(1, (int) ceil($total / max(1, $perPage))),
'rows' => $rows,
]);
}
private function tahesabApiUrl(): string
{
$host = trim((string) $this->Config('tahesab_host'));