#P1627
POST /v2/redis-accounting/save-document
Save Document
این اندپوینت یک سند حسابداری را در هسته حسابداری Redis ذخیره میکند. عملیات شامل ایجاد Hash سند، ساخت ایندکسهای زمانی و حسابداری، و بهروزرسانی ماندهها در سه سطح گروه/کل/حساب است. این متد ستون فقرات سیستم حسابداری Redis محسوب میشود.
Request Overview
URL:
/v2/redis-accounting/save-documentMethod: POST
Auth: Bearer Token (Required)
Content-Type: application/json
Request Body Schema
| Field | Type | Required | Description |
|---|---|---|---|
serial |
integer | optional | شماره سریال سند. اگر ارسال نشود، سیستم خودش تولید میکند. |
description |
string | yes | شرح سند |
jalaliDate |
string | yes | تاریخ شمسی با فرمت YYYY-MM-DD (الزامی) |
debtor |
number | optional | مبلغ بدهکار (پیشفرض: 0) |
creditor |
number | optional | مبلغ بستانکار (پیشفرض: 0) |
group |
integer | yes | شناسه گروه حسابداری |
general |
integer | yes | شناسه کل |
account |
integer | yes | شناسه معین |
subsidiary |
integer | yes | شناسه تفضیلی |
datetime |
string | optional | تاریخزمان میلادی (اگر ارسال نشود، now() استفاده میشود) |
Request Example
{
"serial": 120,
"description": "خرید قطعات",
"jalaliDate": "1403-09-01",
"debtor": 250000,
"creditor": 0,
"group": 10,
"general": 101,
"account": 1011,
"subsidiary": 1011003
}
Response (Success)
| Field | Type | Description |
|---|---|---|
status |
boolean | وضعیت نهایی ذخیره سند |
id |
integer | شناسه سند ایجادشده در Redis |
serial |
integer | سریال اختصاص دادهشده |
time |
float | مدت زمان اجرای عملیات (ms) |
{
"status": true,
"serial": 120,
"id": 934221,
"time": 1.78
}
Response (Validation Error)
{
"status": false,
"message": "خطا در اعتبارسنجی",
"errors": {
"jalaliDate": [
"The jalaliDate must match YYYY-MM-DD"
]
}
}
Response (Server Error)
{
"status": false,
"message": "خطا در ذخیره سند",
"trace": [...]
}
Internal Redis Architecture
| Key | Type | Description |
|---|---|---|
accounting:doc:{id} |
Hash | اطلاعات کامل سند ذخیرهشده |
accounting:docs:by_datetime |
SortedSet | مرتبسازی تمام اسناد بر اساس timestamp |
accounting:docs:group:{groupId} |
Set | ایندکس اسناد گروه |
accounting:docs:general:{generalId} |
Set | ایندکس سطح کل |
accounting:docs:account:{accountId} |
Set | ایندکس سطح معین |
accounting:docs:subsidiary:{subsidiaryId} |
Set | ایندکس سطح تفضیلی |
Process Flow
Receive Request
↓
Validate Input
↓
Convert Jalali → Gregorian
↓
Normalize Debtor/Creditor
↓
Generate Serial (if needed)
↓
Create Hash & Indexes in Redis
↓
Update Balances
↓
Return Final Response