#P1633
GET /v2/redis-accounting/documents/general
Get Documents by General
این اندپوینت اسناد حسابداری مرتبط با یک کد کل (General Code) را از Redis بازیابی میکند. خروجی شامل: لیست اسناد، مانده فعلی، تعداد اسناد، و اگر درخواست شده باشد، مانده تجمیعی از ابتدای سال است. دادهها از ایندکس Redis با الگو accounting:docs:general:{code} استخراج میشوند.
Request Overview
URL:
/v2/redis-accounting/documents/generalMethod: GET
Auth: Bearer Token (Required)
Middleware: shamsiDate
Query Parameters
| 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/general?code=101&from_year_start=true
Response (Success)
ساختار خروجی:
| Field | Type | Description |
|---|---|---|
success |
boolean | وضعیت نهایی |
data.documents |
array | مقدار برگشتی دقیقاً بهصورت زیر است: [ diffProcess[], documents[] ] diffProcess شامل timestamps مراحل عملکرد Redis است. documents آرایه کامل اسناد میباشد. |
data.balance |
object | مانده فعلی کل در Redis |
data.total_documents |
integer | توجه: مقدار فعلی همیشه ۲ است چون count روی آرایه دوبخشی اعمال میشود (این یک ایراد منطقی در پیادهسازی فعلی API است) |
data.year_start_balance |
object | در صورت درخواست (from_year_start = true) |
{
"success": true,
"data": {
"documents": [
[
[1733301120.201, 1733301120.203, ...],
[
{
"id": "88401",
"date": "1403-03-15",
"debit": "150000",
"credit": "0",
"group": "10",
"general": "101",
"account": "1011",
"subsidiary": "1011001"
}
]
],
"balance": {
"debit": 150000,
"credit": 0,
"remaining": 150000
},
"total_documents": 2,
"year_start_balance": {
"debit": 150000,
"credit": 0,
"remaining": 150000,
"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 Pattern | Type | Description |
|---|---|---|
accounting:docs:general:{code} |
Set | لیست ID اسناد مرتبط با کد کل |
accounting:doc:{id} |
Hash | اطلاعات کامل سند |
balance:general:{code} |
Hash | مانده فعلی Redis برای کل |
accounting:docs:by_date |
SortedSet | ایندکس سراسری برای year_start_balance |
Process Flow
Validate Inputs
↓
Load IDs (accounting:docs:general:{code})
↓
Fetch Documents (accounting:doc:{id})
↓
Sort by Document Date
↓
Get Balance (balance:general:{code})
↓
If from_year_start=true → Compute Year-Start Balance
↓
Return JSON Response