#P1634
GET /v2/redis-accounting/documents/group
Get Documents by Group
این اندپوینت وظیفه دارد تمام اسناد حسابداری مرتبط با یک کد گروه (Group Code) را از Redis بازیابی کند. دادهها شامل اسناد، مانده فعلی، تعداد اسناد، و در صورت درخواست، مانده تجمیعی از ابتدای سال شمسی است. استخراج داده از Redis بر اساس الگوی زیر انجام میشود: accounting:docs:group:{code}.
Request Overview
URL:
/v2/redis-accounting/documents/groupMethod: GET
Middleware: authWithJwt, 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/group?code=10&from_year_start=true
Response (Success)
ساختار خروجی دقیقاً مطابق پیادهسازی فعلی RedisAccountingService است.
| Field | Type | Description |
|---|---|---|
success |
boolean | True در صورت موفقیت عملیات |
data.documents |
array | آرایه دوبخشی: [ diffProcess[], docs[] ] diffProcess شامل timestamps اجرای مراحل Redis است. docs شامل اطلاعات کامل هر سند است. |
data.balance |
object | ماندهٔ فعلی گروه در Redis |
data.total_documents |
integer | مقدار همیشه ۲ است چون count روی آرایه دوبخشی اعمال شده (نقص منطقی در سیستم فعلی) |
data.year_start_balance |
object | فقط اگر from_year_start=true ارسال میشود |
{
"success": true,
"data": {
"documents": [
[
[1733301001.102, 1733301001.105, ...],
[
{
"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:group:{code} |
Set | شناسه اسناد مرتبط با این گروه |
accounting:doc:{id} |
Hash | اطلاعات کامل هر سند |
balance:group:{code} |
Hash | مانده فعلی گروه در Redis |
accounting:docs:by_date |
SortedSet | برای year_start_balance استفاده میشود |
Process Flow
Validate Inputs
↓
Fetch IDs (accounting:docs:group:{code})
↓
Load Each Document (accounting:doc:{id})
↓
Sort by Date Field
↓
Get Redis Balance (balance:group:{code})
↓
If requested → Calculate Year-Start Balance
↓
Return Final JSON Payload