<?php

namespace App\Classes\Modules\Bookings\Services;


use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Booking;
use Carbon\Carbon;

class CalculatesBookingTransferredAmount
{

    public function execute(Booking $booking){
        return $booking->transactions()->payments()->complete()->whereHas('transactions', function($query){
            return $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->where('type', TransactionType::BILL);
        })->sum('original_amount');
    }

}