feat(accounting): document colleague trades on configured accounts
Post Montzar-covered buy/sell to Zarin/Tahesab/Pargar using montzar_account_* settings, and harden public storage URL/MIME handling for uploads. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -453,10 +453,25 @@ class TahesabController extends Controller
|
||||
}
|
||||
|
||||
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||
$accountOverride = trim((string) ($data['accounting_account_code'] ?? ''));
|
||||
$isColleagueLeg = ! empty($data['colleague_leg']) && $accountOverride !== '';
|
||||
|
||||
if ($customer && ($customer->moshtari_code === null)) {
|
||||
$this->createCustomerInTahesab($customer->id);
|
||||
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||
if (! $isColleagueLeg) {
|
||||
if ($customer && ($customer->moshtari_code === null)) {
|
||||
$this->createCustomerInTahesab($customer->id);
|
||||
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||
}
|
||||
}
|
||||
|
||||
if (! $customer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hesabCode = $isColleagueLeg
|
||||
? (int) $accountOverride
|
||||
: (int) ($customer->moshtari_code ?? 0);
|
||||
if ($hesabCode <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$kind = $mapper->resolveKind($product);
|
||||
@@ -490,7 +505,14 @@ class TahesabController extends Controller
|
||||
|
||||
$action = $isBuy ? 'خرید' : 'فروش';
|
||||
$kindFa = $mapper->kindLabel($kind);
|
||||
$sharh = trim($title !== '' ? "{$action} {$title}" : "{$action} {$kindFa}");
|
||||
$sharh = trim((string) ($data['sharh_override'] ?? ''));
|
||||
if ($sharh === '') {
|
||||
$sharh = trim($title !== '' ? "{$action} {$title}" : "{$action} {$kindFa}");
|
||||
}
|
||||
|
||||
$orderId = is_object($data['order'] ?? null)
|
||||
? ($data['order']->id ?? null)
|
||||
: ($data['order']['id'] ?? null);
|
||||
|
||||
$data['handler'] = 'storeTrade';
|
||||
if ($existing && empty($existing->data)) {
|
||||
@@ -500,21 +522,21 @@ class TahesabController extends Controller
|
||||
'customer_id' => $customer->id,
|
||||
'desc' => $sharh,
|
||||
'amount' => $mapper->isCountDoc($product) ? $count : $vazn,
|
||||
'order_id' => $data['order']['id'] ?? null,
|
||||
'order_id' => $orderId,
|
||||
'date' => $data['pay_at'] ?? Carbon::now(),
|
||||
'type' => $mapper->syncTypeLabel($product),
|
||||
'created_at' => Carbon::now(),
|
||||
'data' => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||
]);
|
||||
|
||||
if ($mapper->isCountDoc($product) && $title === '') {
|
||||
if ($mapper->isCountDoc($product) && $title === '' && ! $isColleagueLeg) {
|
||||
$this->sync()->markFailed($tahesab, null, 'نام محصول برای سند تعدادی تهحساب خالی است');
|
||||
return false;
|
||||
}
|
||||
|
||||
$body = $this->buildBuySaleBody(
|
||||
$kind,
|
||||
(int) $customer->moshtari_code,
|
||||
$hesabCode,
|
||||
(int) $year,
|
||||
(int) $month,
|
||||
(int) $day,
|
||||
|
||||
Reference in New Issue
Block a user