File: D:/HostingSpaces/MdnDirecteur/hours.komma.cloud/app/Komma/Expenses/ExpenseService.php
<?php
namespace App\Komma\Expenses;
use Carbon\Carbon;
use Illuminate\Http\Request;
class ExpenseService{
/**
* @param $date
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function getExpense($date, $user)
{
return Expense::with([
'ExpenseType.ExpenseUnit',
'Subproject.Project',
])->where('user_id', $user)
->where('date','>=', Carbon::parse($date)->toDateString())
->where('date','<', Carbon::parse($date)->addDay()->toDateString())
->get();
}
public function checkIfExists(Request $request, $user) {
$foundExpenseWithinSeconds = Expense::where('user_id', $user)
->where('subproject_id', $request->subproject)
->where('expense_type_id', $request->expense)
->where('value', $request->hours)
->where('date', Carbon::parse($request->date)->toDateString())
->where('created_at', '>', Carbon::now()->subSecond(10)->format(Carbon::DEFAULT_TO_STRING_FORMAT))
->first();
return !empty($foundExpenseWithinSeconds);
}
public function getExpenseByID($id) {
return Expense::with([
'ExpenseType',
'ExpenseType.ExpenseUnit'
])->where('id', '=', $id)->first();
}
}