fix some bugs from accounting

This commit is contained in:
2026-07-28 17:44:24 +03:30
parent 91f6b24da4
commit d81cea3d4f
7 changed files with 995 additions and 247 deletions
@@ -315,6 +315,18 @@ class WalletController extends Controller
try {
$data['direction'] = $deposit ? 1 : 0;
$data['withdraw_id'] = $Withdraw->id;
if ($representative) {
$data['product_id'] = $representative->id;
$data['product'] = [
'id' => $representative->id,
'title' => $representative->title,
'group_type' => $representative->group_type,
'metal_id' => $representative->metal_id,
'amount' => $representative->amount,
'unit' => $representative->unit,
'trade_by_quantity' => $representative->trade_by_quantity,
];
}
app(TahesabController::class)->walletGold($data);
} catch (\Exception $e) {
report($e);
@@ -325,6 +337,18 @@ class WalletController extends Controller
try {
$data['direction'] = $deposit ? 1 : 0;
$data['withdraw_id'] = $Withdraw->id;
if ($representative) {
$data['product_id'] = $representative->id;
$data['product'] = [
'id' => $representative->id,
'title' => $representative->title,
'group_type' => $representative->group_type,
'metal_id' => $representative->metal_id,
'amount' => $representative->amount,
'unit' => $representative->unit,
'trade_by_quantity' => $representative->trade_by_quantity,
];
}
app(\App\Http\Controllers\Admin\ZarinController::class)->walletGold($data);
} catch (\Exception $e) {
report($e);
@@ -415,6 +439,9 @@ class WalletController extends Controller
$label .= ' (غیرفعال)';
}
$payload = Controller::productUnitPayload($product);
$isCountBased = Controller::isCountBasedProduct($payload);
$targets[] = [
'key' => 'product:' . $product->id,
'kind' => 'metal',
@@ -424,6 +451,7 @@ class WalletController extends Controller
'metal_id' => max(1, (int) ($product->metal_id ?? 1)),
'uses_main_wallet' => $usesMainWallet,
'trade_by_quantity' => (bool) $product->trade_by_quantity,
'allows_decimal' => !$isCountBased,
'group_type' => (string) ($product->group_type ?? ''),
'active' => (bool) $product->active,
];
@@ -453,7 +481,13 @@ class WalletController extends Controller
$data = $request->all();
$product = Product::findOrFail($productId);
$customer = Customer::findOrFail($data['customer_id']);
$deposit = ((float) ($data['value'] ?? 0)) > 0;
$value = (float) ($data['value'] ?? 0);
$deposit = $value > 0;
$payload = Controller::productUnitPayload($product);
if (Controller::isCountBasedProduct($payload) && abs($value - round($value)) > 0.000001) {
throw new UnprocessableEntityHttpException('برای محصول تعدادی فقط عدد صحیح مجاز است');
}
$effectiveProductId = Controller::effectiveProductWalletId($productId);
$wallet_interface = new WalletInterface(
@@ -504,6 +538,16 @@ class WalletController extends Controller
try {
$data['direction'] = $deposit ? 1 : 0;
$data['withdraw_id'] = $Withdraw->id;
$data['product_id'] = $productId;
$data['product'] = [
'id' => $product->id,
'title' => $product->title,
'group_type' => $product->group_type,
'metal_id' => $product->metal_id,
'amount' => $product->amount,
'unit' => $product->unit,
'trade_by_quantity' => $product->trade_by_quantity,
];
app(TahesabController::class)->walletGold($data);
} catch (\Exception $e) {
report($e);
@@ -514,6 +558,16 @@ class WalletController extends Controller
try {
$data['direction'] = $deposit ? 1 : 0;
$data['withdraw_id'] = $Withdraw->id;
$data['product_id'] = $productId;
$data['product'] = [
'id' => $product->id,
'title' => $product->title,
'group_type' => $product->group_type,
'metal_id' => $product->metal_id,
'amount' => $product->amount,
'unit' => $product->unit,
'trade_by_quantity' => $product->trade_by_quantity,
];
app(\App\Http\Controllers\Admin\ZarinController::class)->walletGold($data);
} catch (\Exception $e) {
report($e);
@@ -576,19 +630,20 @@ class WalletController extends Controller
{
$payload = Controller::productUnitPayload($product);
if (
Controller::usesQuantityTrade($payload)
&& !Controller::isWeightBasedProductUnit($payload['unit'] ?? null)
) {
$unit = trim((string) ($payload['unit'] ?? ''));
return $unit !== '' ? $unit : 'عدد';
// تعدادی: همیشه «عدد» — حتی اگر unit محصول وزن هر قطعه (گرم) باشد
if (Controller::isCountBasedProduct($payload)) {
return 'عدد';
}
if (Controller::isWeightBasedProductUnit($payload['unit'] ?? null)) {
return trim((string) $payload['unit']);
}
$unit = trim((string) ($payload['unit'] ?? ''));
if ($unit !== '') {
return $unit;
}
return Controller::productStorageWeightUnit($product);
}
@@ -1102,6 +1157,26 @@ class WalletController extends Controller
return $withdraw;
});
foreach ($data['wallets'] as $walletRow) {
$wallet = Wallet::with('product')->find($walletRow['wallet_id'] ?? 0);
$product = $wallet?->product;
if (!$product) {
continue;
}
try {
app(\App\Services\AccountingWalletPush::class)->pushProductWalletGold(
$customer,
$product,
(float) $walletRow['value'],
false,
(int) $withdraw->id,
'برداشت فیزیکی ' . $product->title
);
} catch (\Throwable $e) {
report($e);
}
}
$this->broadcastCustomerWalletAssets($customer);
return response()->json(['id' => $withdraw->id]);