<?php

namespace App\Classes\General\Eloquent\Filters;


use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Booking;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;

class WithBookingMarkingLike implements Filter
{

    /**
     * @param Builder $builder
     * @param $value
     * @return mixed
     */
    public static function apply(Builder $builder, $value)
    {
        return $builder->join('transactions as t2', 't2.payment_reference', '=', 'transactions.bill_no')
            ->join('bookings', function ($join) use ($value) {
                $join->on('bookings.id', '=', 't2.owner_id')
                    ->where('bookings.marking', 'LIKE', '%'.$value.'%');
            })
            ->addSelect(['transactions.*','t2.owner_id as bookingId', 'bookings.marking as bookingMarking']);
    }
}