#P1632
GET /v2/redis-accounting/documents/account
Get Documents by Account
این اندپوینت لیست اسناد حسابداری مربوط به یک کد معین را از Redis بازیابی میکند. خروجی شامل اسناد، مانده فعلی، تعداد اسناد، و در صورت فعال بودن، ماندهٔ تجمیعی از ابتدای سال است. عملیات بر اساس ایندکس Redis accounting:docs:account:{code} انجام میشود.
Request Overview
URL:
/v2/redis-accounting/documents/accountMethod: GET
Auth: Bearer Token (Required)
Content-Type: application/json
Query Parameters Schema
| Field | Type | Required | Description |
|---|---|---|---|
code |
integer | yes | کد معین که اسناد براساس آن فیلتر میشوند |
from_year_start |
boolean | optional | اگر true باشد، مانده تجمیعی از ابتدای سال شمسی محاسبه میشود |
to_date |
string (YYYY-MM-DD) | optional | تاریخ پایانی برای محاسبه year_start_balance (پیشفرض: تاریخ امروز) |
Request Example
GET /v2/redis-accounting/documents/account?code=1011&from_year_start=true
Response (Success)
ساختار خروجی:
| Field | Type | Description |
|---|---|---|
success |
boolean | وضعیت نهایی |
data.documents |
array | خروجی دقیقاً شامل [diffProcess, docs] است diffProcess آرایهای از timestamps docs آرایه سندها |
data.balance |
object | مانده فعلی Redis برای حساب معین |
data.total_documents |
integer | توجه: در سیستم فعلی مقدار آن ۲ است چون count روی آرایه دوبخشی [diffProcess, docs] اعمال شده (این یک نقص منطقی در پیادهسازی است) |
data.year_start_balance |
object | فقط اگر from_year_start=true ارسال میشود |
{
"success": true,
"data": {
"documents": [
[
[1733301120.101, 1733301120.103, ...],
[
{
"id": "2210",
"date": "1403-05-01",
"debit": "500000",
"credit": "0",
"group": "10",
"general": "101",
"account": "1011",
"subsidiary": "1011001"
}
]
],
"balance": {
"debit": 500000,
"credit": 0,
"remaining": 500000
},
"total_documents": 2,
"year_start_balance": {
"debit": 500000,
"credit": 0,
"remaining": 500000,
"year_start": "1403-01-01",
"to_date": "1403-09-15"
}
}
}
}
Response (Validation Error)
{
"success": false,
"message": "خطا در اعتبارسنجی",
"errors": {
"code": [
"The code field is required."
]
}
}
Response (Server Error)
{
"success": false,
"message": "خطا در دریافت اسناد: Internal server error..."
}
Internal Redis Architecture
| Key | Type | Description |
|---|---|---|
accounting:docs:account:{code} |
Set | لیست شناسه اسناد مربوط به این معین |
accounting:doc:{id} |
Hash | اطلاعات کامل سند |
balance:account:{code} |
Hash | مانده حساب در Redis |
accounting:docs:by_date |
SortedSet | ایندکس سراسری تمام اسناد بر اساس تاریخ برای year_start_balance |
Process Flow
Receive Request + Validate Inputs
↓
Load Document IDs (accounting:docs:account:{code})
↓
Fetch Every Document Hash (accounting:doc:{id})
↓
Sort Documents by Date
↓
Read Current Balance (balance:account:{code})
↓
If from_year_start=true → compute getBalanceFromYearStart()
↓
Return Final JSON Response