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)
|
public function storeTrade($data, ?Tahesab $existing = null)
|
||||||
{
|
{
|
||||||
// if ($input instanceof \Illuminate\Http\Request) {
|
// اگر payload خالی است اما Tahesab موجود و order_id دارد، از Order بازسازی کن
|
||||||
// $data = $input->all();
|
if (empty($data['customer_id']) && $existing && $existing->order_id) {
|
||||||
// } elseif (is_array($input)) {
|
$order = \App\Models\Order::find($existing->order_id);
|
||||||
// $data = $input;
|
if ($order) {
|
||||||
// } else {
|
$data = array_merge($data, [
|
||||||
// $data = request()->all();
|
'customer_id' => $existing->customer_id,
|
||||||
// }
|
'amount' => $existing->amount,
|
||||||
// return ($data);
|
'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'])) {
|
if (!isset($data['customer_id']) || !isset($data['amount'])) {
|
||||||
return request()->expectsJson()
|
return request()->expectsJson()
|
||||||
@@ -125,6 +133,9 @@ class TahesabController extends Controller
|
|||||||
: (int) ($data['total_price'] ?? round((float) $amount * (float) $data['price']));
|
: (int) ($data['total_price'] ?? round((float) $amount * (float) $data['price']));
|
||||||
|
|
||||||
$data['handler'] = 'storeTrade';
|
$data['handler'] = 'storeTrade';
|
||||||
|
if ($existing && empty($existing->data)) {
|
||||||
|
$existing->update(['data' => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]);
|
||||||
|
}
|
||||||
$tahesab = $existing ?? Tahesab::create([
|
$tahesab = $existing ?? Tahesab::create([
|
||||||
"customer_id" => $customer->id,
|
"customer_id" => $customer->id,
|
||||||
"desc" => $data['direction'] == 1 ? "خرید آبشده" : "فروش آبشده",
|
"desc" => $data['direction'] == 1 ? "خرید آبشده" : "فروش آبشده",
|
||||||
|
|||||||
Reference in New Issue
Block a user