{{-- Combinations: target_type(room/bill), target_method (new/occupied) 1 = Room Qty, New Room (1,1) 2 = Room Qty, Occupied (1,2) 3 = Bill, New Room (2,1) 4 = Bill, Occupied (2,2) --}} @php $combination = $setups->first()->target_type.'_'.$setups->first()->target_method; $total_commission = 0; @endphp @php $sl = 0; @endphp @foreach ($period as $p) @php $new_room_qty = $room_details->where('is_new_room', 1)->where('start_date_time', date('Y-m-d 00:00:00',strtotime($p)))->count(); $occupied_room_qty_checkin = $room_details->where('check_out_time', null)->where('start_date_time', '<=', date('Y-m-d 00:00:00',strtotime($p)))->count(); $occupied_room_qty_checkout = $room_details->where('check_out_time', '!=', null)->where('start_date_time', '<=', date('Y-m-d 00:00:00',strtotime($p)))->where('start_date_time', '>=', date('Y-m-d 00:00:00',strtotime($p)))->count(); $occupied_room_qty = $occupied_room_qty_checkin + $occupied_room_qty_checkout; $new_room_bill_amount = $room_details->where('is_new_room', 1)->where('start_date_time', date('Y-m-d 00:00:00',strtotime($p)))->sum('rent'); $new_room_bill_vat = $room_details->where('is_new_room', 1)->where('start_date_time', date('Y-m-d 00:00:00',strtotime($p)))->sum('vat'); $new_room_bill = $new_room_bill_amount + $new_room_bill_vat; $occupied_room_bill_checkin_amount = $room_details->where('check_out_time', null)->where('start_date_time', '<=', date('Y-m-d 00:00:00',strtotime($p)))->sum('rent'); $occupied_room_bill_checkin_vat = $room_details->where('check_out_time', null)->where('start_date_time', '<=', date('Y-m-d 00:00:00',strtotime($p)))->sum('vat'); $occupied_room_bill_checkout_amount = $room_details->where('check_out_time', '!=', null)->where('start_date_time', '<=', date('Y-m-d 00:00:00',strtotime($p)))->where('start_date_time', '>=', date('Y-m-d 00:00:00',strtotime($p)))->sum('rent'); $occupied_room_bill_checkout_vat = $room_details->where('check_out_time', '!=', null)->where('start_date_time', '<=', date('Y-m-d 00:00:00',strtotime($p)))->where('start_date_time', '>=', date('Y-m-d 00:00:00',strtotime($p)))->sum('vat'); $occupied_room_bill = $occupied_room_bill_checkin_amount + $occupied_room_bill_checkin_vat + $occupied_room_bill_checkout_amount + $occupied_room_bill_checkout_vat; $calculation_arr = [ '1_1' => $new_room_qty, '1_2' => $occupied_room_qty, '2_1' => $new_room_bill, '2_2' => $occupied_room_bill ]; $commission = $setups->where('target_value', '<=', $calculation_arr[$combination])->sortByDesc('target_value')->first()->commission_percent ?? 0; if(in_array($combination, ['2_1','2_2'])){ $target_value = $setups->where('target_value', '<=', $calculation_arr[$combination])->sortByDesc('target_value')->first()->target_value ?? 0; $commission = $target_value > 0 ? ($commission*($calculation_arr[$combination]/$target_value)) : 0; } else{ // Room qty $commission = $commission*$calculation_arr[$combination]; } $commission = round($commission, 2); $total_commission += $commission; @endphp @endforeach
{{ __('obs.sl') }} {{ __('obs.date') }} {{ __('obs.new_room') }} {{ __('obs.occupied_room') }} {{ __('obs.new_room_bill') }} {{ __('obs.occupied_room_bill') }} {{ __('obs.commission') }}
{{ ++$sl }} {{ date('d-m-Y', strtotime($p)) }}{{ $new_room_qty }} {{ $occupied_room_qty }} {{ $new_room_bill }} {{ $occupied_room_bill }} {{ $commission }}
{{ __('obs.total') }} {{ $total_commission }}