From df911026cf9911d4f7a8a840f2cd43c343b1b728 Mon Sep 17 00:00:00 2001 From: Nadim Salloum Date: Fri, 18 Jun 2021 13:16:41 +0300 Subject: [PATCH] remove profit --- app/Http/Controllers/CarController.php | 16 ---------------- app/Models/Car.php | 9 --------- public/js/app.js | 8 -------- resources/js/Pages/Cars/Index.vue | 1 - resources/js/Pages/Cars/Sold.vue | 1 - 5 files changed, 35 deletions(-) diff --git a/app/Http/Controllers/CarController.php b/app/Http/Controllers/CarController.php index 1b46904..ae1ddb2 100644 --- a/app/Http/Controllers/CarController.php +++ b/app/Http/Controllers/CarController.php @@ -51,7 +51,6 @@ class CarController extends Controller 'Käufer', 'Verkaufsdatum', 'Verkaufspreis', - 'Profit', ]; $direction = $this->getDirection($request, 'desc'); @@ -79,7 +78,6 @@ class CarController extends Controller 'buyer' => $scontract ? $scontract->contact->full_title : null, 'sell_date' => $scontract ? $scontract->date_formatted : null, 'sell_price' => $scontract ? $scontract->price : null, - 'profit' => $car->latestProfit(), ]; }); @@ -150,7 +148,6 @@ class CarController extends Controller 'Käufer', 'Verkaufsdatum', 'Verkaufspreis', - 'Profit', ]; $direction = $this->getDirection($request, 'desc'); @@ -178,7 +175,6 @@ class CarController extends Controller 'buyer' => $scontract ? $scontract->contact->full_title : null, 'sell_date' => $scontract ? $scontract->date_formatted : null, 'sell_price' => $scontract ? $scontract->price : null, - 'profit' => $car->latestProfit(), ]; }); @@ -205,7 +201,6 @@ class CarController extends Controller 'vin' => $car->vin, 'buy_contract' => $this->getContractFields($car->latestBuyContract()), 'sell_contract' => $car->isSold() ? $this->getContractFields($car->latestSellContract()) : null, - 'profit' => $car->latestProfit(), 'car_model' => $car->carModel->only('name'), 'name' => $car->name, 'initial_date' => $car->initial_date_formatted, @@ -290,17 +285,6 @@ class CarController extends Controller ->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '1' order by date desc limit 1)")); }) ->orderBy('contracts.price', $direction); - case 'profit': - return $cars - ->leftJoin('contracts as buy_contracts', function($join) { - $join->on('buy_contracts.car_id', '=', 'cars.id') - ->on('buy_contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '0' order by date desc limit 1)")); - }) - ->leftJoin('contracts as sell_contracts', function($join) { - $join->on('sell_contracts.car_id', '=', 'cars.id') - ->on('sell_contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '1' order by date desc limit 1)")); - }) - ->orderByRaw('(sell_contracts.price - buy_contracts.price) ' . $direction); default: return $cars->orderBy('initial_date', $direction); } diff --git a/app/Models/Car.php b/app/Models/Car.php index cfb7f9d..836b398 100644 --- a/app/Models/Car.php +++ b/app/Models/Car.php @@ -81,15 +81,6 @@ class Car extends Model return $this->buyContracts()->count() >= 1 && $this->buyContracts()->count() <= $this->sellContracts()->count(); } - public function latestProfit() - { - if (!$this->isSold()) { - return null; - } - - return $this->latestSellContract()->price->subtract($this->latestBuyContract()->price)->format(); - } - public function contracts() { return $this->hasMany(Contract::class); diff --git a/public/js/app.js b/public/js/app.js index 0d8aad6..ee4852c 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -20392,10 +20392,6 @@ __webpack_require__.r(__webpack_exports__); key: 'sell_contract.price', value: 'Verkaufspreis', sortable: true - }, { - key: 'profit', - value: 'Profit', - sortable: true }] }; } @@ -20508,10 +20504,6 @@ __webpack_require__.r(__webpack_exports__); key: 'sell_contract.price', value: 'Verkaufspreis', sortable: true - }, { - key: 'profit', - value: 'Profit', - sortable: true }] }; } diff --git a/resources/js/Pages/Cars/Index.vue b/resources/js/Pages/Cars/Index.vue index 95cf282..8e1fb67 100644 --- a/resources/js/Pages/Cars/Index.vue +++ b/resources/js/Pages/Cars/Index.vue @@ -38,7 +38,6 @@ export default { { key: 'buy_contract.price', value: 'Einkaufspreis', sortable: true }, { key: 'sell_contract.date', value: 'Verkaufssdatum', sortable: true }, { key: 'sell_contract.price', value: 'Verkaufspreis', sortable: true }, - { key: 'profit', value: 'Profit', sortable: true }, ], }; }, diff --git a/resources/js/Pages/Cars/Sold.vue b/resources/js/Pages/Cars/Sold.vue index b3b99e5..84ff141 100644 --- a/resources/js/Pages/Cars/Sold.vue +++ b/resources/js/Pages/Cars/Sold.vue @@ -38,7 +38,6 @@ export default { { key: 'buy_contract.price', value: 'Einkaufspreis', sortable: true }, { key: 'sell_contract.date', value: 'Verkaufssdatum', sortable: true }, { key: 'sell_contract.price', value: 'Verkaufspreis', sortable: true }, - { key: 'profit', value: 'Profit', sortable: true }, ], }; },