#P1627
POST /v2/redis-accounting/save-document
Save
1. Overview
Document
1. Overview
Documentاین روت مسئول ثبتاندپوینت یک سند حسابداری را در هسته حسابداری Redis ذخیره میکند. عملیات شامل ایجاد Hash سند، ساخت ایندکسهای زمانی و حسابداری، و بهروزرسانی ماندهها در سه سطح گروه/کل/حساب است. سند شامل مبالغ بدهکار/بستانکار، تاریخ شمسی، تاریخ میلادی، گروه/کل/معین/تفضیلی، و توضیحات است.
این Endpointمتد هستهٔستون فقرات سیستم حسابداری است.Redis تمام ماندههای حسابها از همین مسیر بهروزمحسوب میشوند.شود.
2. Request SchemaOverview
POSTURL:/v2/redis-accounting/save-documentMethod: POSTAuth: Bearer Token (Required)Content-Type: application/jsonRequest Body Schema
Field Type Required Description serialinteger optional شماره سریال سند. اگر ارسال نشود، سیستم خودش تولید میکند. descriptionstring yes شرح سند jalaliDatestring yes تاریخ شمسی با فرمت YYYY-MM-DD (الزامی) debtornumber optional مبلغ بدهکار (پیشفرض: 0) creditornumber optional مبلغ بستانکار (پیشفرض: 0) groupinteger yes شناسه گروه حسابداری generalinteger yes شناسه کل accountinteger yes شناسه معین subsidiaryinteger yes شناسه تفضیلی datetimestring optional تاریخزمان میلادی (اگر ارسال نشود، now() استفاده میشود) Request Example
{ "serial":number,120, "description":string,"خرید قطعات", "jalaliDate": "YYYY-MM-DD"1403-09-01", "debtor":number,250000, "creditor":number,0, "group":number,10, "general":number,101, "account":number,1011, "subsidiary":number, "datetime": "YYYY-MM-DD HH:MM:SS" (optional)1011003 }
3.ResponseValidation Rules(Success)
Field Type Description statusboolean وضعیت نهایی ذخیره سند idinteger شناسه سند ایجادشده در Redis serial→integer required,سریال integerاختصاصdescriptionدادهشده→required,stringtimejalaliDatefloat →مدت required,زمانformatاجرای/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/عملیاتdebtor/creditor(ms)→numeric,max9999999999999group/general/account/subsidiary → required, integerdatetime → optional → converted to Carbonورودی validate میشود.jalaliDate → تبدیل به میلادی با Jalalian::fromFormatاگر debtor یا creditor وجود نداشته باشد → 0datetime اگر وجود نداشت → now()صدا زدن RedisAccountingService::saveDocument()برگشت خروجی با:
4. Controller Flow
{
"status": true,
"serial": {computed_serial},120,
"id": {doc_id},934221,
"time": {execution_time_ms}1.78
}
Response (Validation Error)
Error)
{
"status": false,
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