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:
@@ -1394,29 +1394,49 @@ class ZarinController 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->createCustomerInZarin($customer->id);
|
||||
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||
if (! $isColleagueLeg) {
|
||||
if ($customer && ($customer->moshtari_code === null)) {
|
||||
$this->createCustomerInZarin($customer->id);
|
||||
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||
}
|
||||
|
||||
if (!$customer || empty($customer->moshtari_code)) {
|
||||
return false;
|
||||
}
|
||||
} elseif (! $customer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$customer || empty($customer->moshtari_code)) {
|
||||
return false;
|
||||
$accountCustomer = $customer;
|
||||
if ($isColleagueLeg) {
|
||||
$accountCustomer = clone $customer;
|
||||
$accountCustomer->moshtari_code = $accountOverride;
|
||||
}
|
||||
|
||||
$rawAmount = (float) $data['amount'];
|
||||
$count = $mapper->accountingQty($product, $rawAmount, $data);
|
||||
$vazn = $mapper->accountingWeight($product, $rawAmount, $data);
|
||||
$isBuy = (int) ($data['direction'] ?? 0) === 1;
|
||||
$orderId = $data['order']['id'] ?? ($existing->order_id ?? null);
|
||||
$orderId = is_object($data['order'] ?? null)
|
||||
? ($data['order']->id ?? null)
|
||||
: ($data['order']['id'] ?? ($existing->order_id ?? null));
|
||||
$title = $mapper->productTitle($product);
|
||||
$action = $isBuy ? 'خرید' : 'فروش';
|
||||
$sharh = trim($title !== '' ? "{$action} {$title}" : "{$action} {$mapper->kindLabel($mapper->resolveKind($product))}");
|
||||
$sharh = trim((string) ($data['sharh_override'] ?? ''));
|
||||
if ($sharh === '') {
|
||||
$sharh = trim($title !== '' ? "{$action} {$title}" : "{$action} {$mapper->kindLabel($mapper->resolveKind($product))}");
|
||||
}
|
||||
$syncAmount = $mapper->isCountDoc($product) ? $count : $vazn;
|
||||
$uidSource = $orderId ?? null;
|
||||
if (!empty($data['line'])) {
|
||||
$uidSource = ($orderId ?? '0') . 'L' . (int) $data['line'];
|
||||
}
|
||||
if ($isColleagueLeg) {
|
||||
$uidSource = ($uidSource ?? '0') . 'C';
|
||||
}
|
||||
|
||||
$data['handler'] = 'storeTrade';
|
||||
if ($existing && empty($existing->data)) {
|
||||
@@ -1440,6 +1460,8 @@ class ZarinController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
$uidKind = $isColleagueLeg ? '11' : '10';
|
||||
|
||||
try {
|
||||
if ($mapper->isCountDoc($product)) {
|
||||
$fi = (float) ($data['price'] ?? 0);
|
||||
@@ -1453,25 +1475,25 @@ class ZarinController extends Controller
|
||||
$result = $this->postZarinCountDoc(
|
||||
$zarin,
|
||||
$data,
|
||||
$customer,
|
||||
$accountCustomer,
|
||||
$product,
|
||||
$count,
|
||||
$isBuy ? -1 : 1,
|
||||
$fi,
|
||||
$sharh,
|
||||
$this->zarinUid('10', $uidSource ?? $zarin->id)
|
||||
$this->zarinUid($uidKind, $uidSource ?? $zarin->id)
|
||||
);
|
||||
} else {
|
||||
$result = $this->postZarinWeightDoc(
|
||||
$zarin,
|
||||
$data,
|
||||
$customer,
|
||||
$accountCustomer,
|
||||
$vazn,
|
||||
$isBuy ? 'f' : 'k',
|
||||
(float) ($data['price'] ?? 0),
|
||||
$sharh,
|
||||
$mapper->jensFelez($product) ?? 0,
|
||||
$this->zarinUid('10', $uidSource ?? $zarin->id)
|
||||
$this->zarinUid($uidKind, $uidSource ?? $zarin->id)
|
||||
);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user