<?php

namespace App\Classes\General\Eloquent\Filters;

use Illuminate\Database\Eloquent\Builder;

class IsPartialRefund implements Filter
{

    /**
     * @param Builder $builder
     * @param $value
     * @return Builder|mixed
     */
    public static function apply(Builder $builder, $value)
    {
        return $builder->whereHas('owner', function ($q) use ($value) {
            if ($value) {
                $q->whereRaw('original_amount != transactions.original_amount');
            } else {
                $q->whereRaw('original_amount = transactions.original_amount');
            }
        });
    }
}
