remove profit

shift-build-2464
Nadim Salloum 2021-06-18 13:16:41 +03:00
parent 1f43411eab
commit df911026cf
5 changed files with 0 additions and 35 deletions

View File

@ -51,7 +51,6 @@ class CarController extends Controller
'Käufer', 'Käufer',
'Verkaufsdatum', 'Verkaufsdatum',
'Verkaufspreis', 'Verkaufspreis',
'Profit',
]; ];
$direction = $this->getDirection($request, 'desc'); $direction = $this->getDirection($request, 'desc');
@ -79,7 +78,6 @@ class CarController extends Controller
'buyer' => $scontract ? $scontract->contact->full_title : null, 'buyer' => $scontract ? $scontract->contact->full_title : null,
'sell_date' => $scontract ? $scontract->date_formatted : null, 'sell_date' => $scontract ? $scontract->date_formatted : null,
'sell_price' => $scontract ? $scontract->price : null, 'sell_price' => $scontract ? $scontract->price : null,
'profit' => $car->latestProfit(),
]; ];
}); });
@ -150,7 +148,6 @@ class CarController extends Controller
'Käufer', 'Käufer',
'Verkaufsdatum', 'Verkaufsdatum',
'Verkaufspreis', 'Verkaufspreis',
'Profit',
]; ];
$direction = $this->getDirection($request, 'desc'); $direction = $this->getDirection($request, 'desc');
@ -178,7 +175,6 @@ class CarController extends Controller
'buyer' => $scontract ? $scontract->contact->full_title : null, 'buyer' => $scontract ? $scontract->contact->full_title : null,
'sell_date' => $scontract ? $scontract->date_formatted : null, 'sell_date' => $scontract ? $scontract->date_formatted : null,
'sell_price' => $scontract ? $scontract->price : null, 'sell_price' => $scontract ? $scontract->price : null,
'profit' => $car->latestProfit(),
]; ];
}); });
@ -205,7 +201,6 @@ class CarController extends Controller
'vin' => $car->vin, 'vin' => $car->vin,
'buy_contract' => $this->getContractFields($car->latestBuyContract()), 'buy_contract' => $this->getContractFields($car->latestBuyContract()),
'sell_contract' => $car->isSold() ? $this->getContractFields($car->latestSellContract()) : null, 'sell_contract' => $car->isSold() ? $this->getContractFields($car->latestSellContract()) : null,
'profit' => $car->latestProfit(),
'car_model' => $car->carModel->only('name'), 'car_model' => $car->carModel->only('name'),
'name' => $car->name, 'name' => $car->name,
'initial_date' => $car->initial_date_formatted, '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)")); ->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); ->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: default:
return $cars->orderBy('initial_date', $direction); return $cars->orderBy('initial_date', $direction);
} }

View File

@ -81,15 +81,6 @@ class Car extends Model
return $this->buyContracts()->count() >= 1 && $this->buyContracts()->count() <= $this->sellContracts()->count(); 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() public function contracts()
{ {
return $this->hasMany(Contract::class); return $this->hasMany(Contract::class);

8
public/js/app.js vendored
View File

@ -20392,10 +20392,6 @@ __webpack_require__.r(__webpack_exports__);
key: 'sell_contract.price', key: 'sell_contract.price',
value: 'Verkaufspreis', value: 'Verkaufspreis',
sortable: true sortable: true
}, {
key: 'profit',
value: 'Profit',
sortable: true
}] }]
}; };
} }
@ -20508,10 +20504,6 @@ __webpack_require__.r(__webpack_exports__);
key: 'sell_contract.price', key: 'sell_contract.price',
value: 'Verkaufspreis', value: 'Verkaufspreis',
sortable: true sortable: true
}, {
key: 'profit',
value: 'Profit',
sortable: true
}] }]
}; };
} }

View File

@ -38,7 +38,6 @@ export default {
{ key: 'buy_contract.price', value: 'Einkaufspreis', sortable: true }, { key: 'buy_contract.price', value: 'Einkaufspreis', sortable: true },
{ key: 'sell_contract.date', value: 'Verkaufssdatum', sortable: true }, { key: 'sell_contract.date', value: 'Verkaufssdatum', sortable: true },
{ key: 'sell_contract.price', value: 'Verkaufspreis', sortable: true }, { key: 'sell_contract.price', value: 'Verkaufspreis', sortable: true },
{ key: 'profit', value: 'Profit', sortable: true },
], ],
}; };
}, },

View File

@ -38,7 +38,6 @@ export default {
{ key: 'buy_contract.price', value: 'Einkaufspreis', sortable: true }, { key: 'buy_contract.price', value: 'Einkaufspreis', sortable: true },
{ key: 'sell_contract.date', value: 'Verkaufssdatum', sortable: true }, { key: 'sell_contract.date', value: 'Verkaufssdatum', sortable: true },
{ key: 'sell_contract.price', value: 'Verkaufspreis', sortable: true }, { key: 'sell_contract.price', value: 'Verkaufspreis', sortable: true },
{ key: 'profit', value: 'Profit', sortable: true },
], ],
}; };
}, },