added some feature for accounting and price 5
This commit is contained in:
@@ -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 ? "خرید آبشده" : "فروش آبشده",
|
||||
|
||||
Reference in New Issue
Block a user