-
app/Models/Company/Expense.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Expense extends Model { // const CREATED = 'created'; const AWAITING_MANAGER_APPROVAL = 'manager_approval'; const AWAITING_ACCOUTING_APPROVAL = 'accounting_approval'; const REJECTED_BY_MANAGER = 'rejected_by_manager'; const REJECTED_BY_ACCOUNTING = 'rejected_by_accounting'; const ACCEPTED = 'accepted'; // }
-
app/Jobs/CheckIfPendingExpenseShouldBeMovedToAccountingWhenManagerChanges.php
Open in GitHubuse App\Models\Company\Company; use App\Models\Company\Expense; use App\Models\Company\Employee; class CheckIfPendingExpenseShouldBeMovedToAccountingWhenManagerChanges { public Company $company; public function __construct(Company $company) { $this->company = $company; } public function handle(): void { $expenses = $this->company->expenses() ->with('employee') ->with('employee.managers') ->where('company_id', $this->company->id) ->where('status', Expense::AWAITING_MANAGER_APPROVAL) ->where('employee_id', '!=', null) ->get(); foreach ($expenses as $expense) { $employee = $expense->employee; if ($employee->managers->count() == 0) { Expense::where('id', $expense->id)->update([ 'status' => Expense::AWAITING_ACCOUTING_APPROVAL, ]); } } } }