feat(tahesab): pump pending documents slowly from admin, not schedule

Send leftover orders and charges one-by-one with a gap so Tahesab is not rate-limited, skip already-synced rows, and expose start/stop plus progress on existing status APIs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-02 20:48:14 +03:30
co-authored by Cursor
parent 92d8f2e9b3
commit c5fd3b45fe
5 changed files with 531 additions and 23 deletions
@@ -12,6 +12,7 @@ use App\Models\Tahesab;
use App\Models\Customer;
use App\Services\AccountingProductDocMapper;
use App\Services\ConfigService;
use App\Services\TahesabDocSyncService;
use App\Services\TahesabInboundWalletService;
use App\Services\TahesabSyncService;
use Morilog\Jalali\Jalalian;
@@ -214,6 +215,7 @@ class TahesabController extends Controller
'phone_conflicts' => $phoneConflicts,
'panel_only_list' => $panelOnlyList,
'tahesab_only_list' => $tahesabOnlyResult,
'doc_sync' => app(TahesabDocSyncService::class)->snapshot(),
];
// برای تشخیص نام دقیق فیلدها: ?include_tahesab=1&raw=1
@@ -672,11 +674,27 @@ class TahesabController extends Controller
public function pendingSummary(Request $request)
{
$docs = app(TahesabDocSyncService::class);
$docs->tickIfStale();
$customerId = $request->filled('customer_id') ? (int) $request->input('customer_id') : null;
return response()->json($this->sync()->pendingSummary($customerId));
}
public function startDocSync()
{
$result = app(TahesabDocSyncService::class)->start();
return response()->json($result, ($result['ok'] ?? false) ? 200 : 422);
}
public function stopDocSync()
{
$result = app(TahesabDocSyncService::class)->stop();
return response()->json($result);
}
public function pendingDocs(Request $request)
{
$customerId = $request->filled('customer_id') ? (int) $request->input('customer_id') : null;