From 7755188e3a360951061711820a5f428b1bbb1d63 Mon Sep 17 00:00:00 2001 From: adonis Date: Sun, 28 Jun 2026 17:05:33 +0330 Subject: [PATCH] added some feature for accounting and price 5 --- .../Controllers/Admin/TahesabController.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Admin/TahesabController.php b/app/Http/Controllers/Admin/TahesabController.php index 44a1cd7..2eb458f 100644 --- a/app/Http/Controllers/Admin/TahesabController.php +++ b/app/Http/Controllers/Admin/TahesabController.php @@ -90,14 +90,22 @@ class TahesabController extends Controller public function storeTrade($data, ?Tahesab $existing = null) { -// if ($input instanceof \Illuminate\Http\Request) { -// $data = $input->all(); -// } elseif (is_array($input)) { -// $data = $input; -// } else { -// $data = request()->all(); -// } -// return ($data); + // اگر payload خالی است اما Tahesab موجود و order_id دارد، از Order بازسازی کن + if (empty($data['customer_id']) && $existing && $existing->order_id) { + $order = \App\Models\Order::find($existing->order_id); + if ($order) { + $data = array_merge($data, [ + 'customer_id' => $existing->customer_id, + 'amount' => $existing->amount, + 'direction' => $order->direction, + 'price' => $order->price, + 'total_price' => $order->total_price, + 'pay_at' => $existing->date, + 'product' => ['metal_id' => $existing->type === 'طلا' ? 1 : 2], + 'order' => ['id' => $existing->order_id], + ]); + } + } if (!isset($data['customer_id']) || !isset($data['amount'])) { return request()->expectsJson() @@ -125,6 +133,9 @@ class TahesabController extends Controller : (int) ($data['total_price'] ?? round((float) $amount * (float) $data['price'])); $data['handler'] = 'storeTrade'; + if ($existing && empty($existing->data)) { + $existing->update(['data' => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]); + } $tahesab = $existing ?? Tahesab::create([ "customer_id" => $customer->id, "desc" => $data['direction'] == 1 ? "خرید آبشده" : "فروش آبشده",