@extends('front.layouts.master-auth') @section('meta') @if(isset($chat)) @endif @endsection @section('content')
@php $is_parts_offer= $item->installments()->count() > 0 ? true : false; $all_parts_completed = false; $partToComplete = null; $partToDelivery = null; $lastPart = $item->installments()->orderBy('id', 'desc')->first(); // تعريف أسماء المراحل بالعربية $stageNumbers = [ 1 => 'الأولى', 2 => 'الثانية', 3 => 'الثالثة', 4 => 'الرابعة', 5 => 'الخامسة', 6 => 'السادسة', 7 => 'السابعة', 8 => 'الثامنة', 9 => 'التاسعة', 10 => 'العاشرة' ]; if ($is_parts_offer){ $all_parts_completed = $item->installments()->where('status',\App\Models\OfferInstallment::STATUS_COMPLETED)->count() == $item->installments()->count(); $partToComplete = $item->installments()->where('status', \App\Models\OfferInstallment::STATUS_PENDING_COMPLETED)->first(); $partToDelivery = $item->installments()->whereIn('status', [\App\Models\OfferInstallment::STATUS_RUNNING, \App\Models\OfferInstallment::STATUS_PENDING])->first(); } $pendingModRequest = $item->pendingModificationRequest(); $runningInstallment = $is_parts_offer ? $item->installments()->where('status', \App\Models\OfferInstallment::STATUS_RUNNING)->first() : null; $canRequestModification = $item->status == \App\Models\Offer::STATUS_RUNNING && $project->status != \App\Models\Project::CANCELLED && !$item->delivery_requested && !$pendingModRequest && getCurrentUser()->isFreelancer(); @endphp

@lang('Offer Details')

{{-- Action Buttons --}}
@if($item->status == \App\Models\Offer::STATUS_PENDING && getCurrentUser()->isProjectOwner()) @lang('Accept Offer') @elseif($item->status == \App\Models\Offer::STATUS_PENDING && getCurrentUser()->isFreelancer()) @if($item->canBeEdited()) @lang('Edit Offer') @endif @elseif($item->status == \App\Models\Offer::STATUS_RUNNING && $project->status != \App\Models\Project::CANCELLED && getCurrentUser()->isProjectOwner() && !$is_parts_offer) @if($item->delivery_requested) @else @lang('End Project') @endif @elseif($item->status == \App\Models\Offer::STATUS_RUNNING && !$is_parts_offer && !$item->delivery_requested && getCurrentUser()->isFreelancer() && $project->status != \App\Models\Project::CANCELLED) @if(!$pendingModRequest) @else @lang('Complete Project Request') @endif @elseif($item->status == \App\Models\Offer::STATUS_RUNNING && $is_parts_offer && !$all_parts_completed && getCurrentUser()->isFreelancer() && $project->status != \App\Models\Project::CANCELLED) @if($partToComplete)
@lang('Part Delivery Request Sent')
@if($runningInstallment && !$pendingModRequest) @php $modPartIndex = $item->installments->search(function($inst) use ($runningInstallment) { return $inst->id == $runningInstallment->id; }) + 1; $modStageName = $stageNumbers[$modPartIndex] ?? 'رقم ' . $modPartIndex; @endphp طلب تعديل المرحلة {{ $modStageName }} @endif @elseif($partToDelivery && $partToDelivery->status == \App\Models\OfferInstallment::STATUS_PENDING) @php $partIndex = $item->installments->search(function($inst) use ($partToDelivery) { return $inst->id == $partToDelivery->id; }) + 1; $stageName = $stageNumbers[$partIndex] ?? 'رقم ' . $partIndex; @endphp
بإنتظار سداد المرحلة {{ $stageName }}
@if($runningInstallment && !$pendingModRequest) @php $modPartIndex = $item->installments->search(function($inst) use ($runningInstallment) { return $inst->id == $runningInstallment->id; }) + 1; $modStageName = $stageNumbers[$modPartIndex] ?? 'رقم ' . $modPartIndex; @endphp طلب تعديل المرحلة {{ $modStageName }} @endif @else @php $partIndex = $item->installments->search(function($inst) use ($partToDelivery) { return $inst->id == $partToDelivery->id; }) + 1; $stageName = $stageNumbers[$partIndex] ?? 'رقم ' . $partIndex; @endphp @if($runningInstallment && !$pendingModRequest) @php $modPartIndex = $item->installments->search(function($inst) use ($runningInstallment) { return $inst->id == $runningInstallment->id; }) + 1; $modStageName = $stageNumbers[$modPartIndex] ?? 'رقم ' . $modPartIndex; @endphp @else طلب تسليم المرحلة {{ $stageName }} @endif @endif @elseif($item->status == \App\Models\Offer::STATUS_RUNNING && $is_parts_offer && !$all_parts_completed && getCurrentUser()->isProjectOwner() && $project->status != \App\Models\Project::CANCELLED) @if($partToComplete) @else @if($partToDelivery && $partToDelivery->status == \App\Models\OfferInstallment::STATUS_PENDING) @php $payPartIndex = $item->installments->search(function($inst) use ($partToDelivery) { return $inst->id == $partToDelivery->id; }) + 1; $payStageName = $stageNumbers[$payPartIndex] ?? 'رقم ' . $payPartIndex; @endphp سداد المرحلة {{ $payStageName }} والبدأ فيها @else @php $partIndex = $item->installments->search(function($inst) use ($partToDelivery) { return $inst->id == $partToDelivery->id; }) + 1; $stageName = $stageNumbers[$partIndex] ?? 'رقم ' . $partIndex; @endphp تسليم المرحلة {{ $stageName }} @endif @endif @elseif($item->status == \App\Models\Offer::STATUS_COMPLETED && getCurrentUser()->isFreelancer()) @php // التحقق من تقييم المستقل لصاحب المشروع $rating = \App\Models\Rating::where('rated_by', auth()->user()->id) ->where('project_id', $item->project_id) ->where('rating_type', \App\Models\Rating::TYPE_FREELANCER_TO_OWNER) ->first(); @endphp @if(!$rating) @lang('Project Owner Rate') @endif @elseif($item->status == \App\Models\Offer::STATUS_COMPLETED && getCurrentUser()->isProjectOwner()) @php // التحقق من تقييم صاحب المشروع للمستقل $rating = \App\Models\Rating::where('rated_by', auth()->user()->id) ->where('project_id', $item->project_id) ->where('rating_type', \App\Models\Rating::TYPE_OWNER_TO_FREELANCER) ->first(); @endphp @if(!$rating) @lang('Freelancer Rate') @endif @endif
{{-- Pending Modification Request Alert --}} @if($pendingModRequest)

طلب تعديل معلّق من المستقل {{ $pendingModRequest->user->first_name }} {{ $pendingModRequest->user->last_name }}

@if($pendingModRequest->isForInstallment()) @php $modInstIndex = $item->installments->search(function($inst) use ($pendingModRequest) { return $inst->id == $pendingModRequest->offer_installment_id; }) + 1; $modInstName = $stageNumbers[$modInstIndex] ?? 'رقم ' . $modInstIndex; @endphp نوع التعديل

تعديل المرحلة {{ $modInstName }}

@endif
السعر الحالي

${{ number_format($pendingModRequest->current_total, 2) }}

السعر المطلوب

${{ number_format($pendingModRequest->requested_total, 2) }}

@if($pendingModRequest->current_delivery_days)
المدة الحالية

{{ $pendingModRequest->current_delivery_days }} يوم

@endif @if($pendingModRequest->requested_delivery_days)
المدة المطلوبة

{{ $pendingModRequest->requested_delivery_days }} يوم

@endif
السبب

{{ $pendingModRequest->reason }}

@if(getCurrentUser()->isProjectOwner()) @else
بانتظار رد صاحب المشروع
@endif
@endif
@if($is_parts_offer && in_array($item->status, [\App\Models\Offer::STATUS_RUNNING, \App\Models\Offer::STATUS_CANCELLED]))
@foreach($item->installments as $part)
@if($part->status == \App\Models\OfferInstallment::STATUS_COMPLETED) @elseif(in_array($part->status ,[ \App\Models\OfferInstallment::STATUS_RUNNING, \App\Models\OfferInstallment::STATUS_PENDING_COMPLETED])) @endif @php $stageNumber = $stageNumbers[$loop->iteration] ?? 'رقم ' . $loop->iteration; @endphp المرحلة {{ $stageNumber }}
@endforeach
@endif

تفاصيل المشروع

@lang('View Project')
{{$project->title}}
@php $description = format_text($project->description); $shortDescription = mb_substr($project->description ?? '', 0, 100); $isLong = mb_strlen($project->description ?? '') > 100; @endphp
@if($isLong) {!! e($shortDescription) !!}... @else {!! $description !!} @endif
{{-- Ratings Box - Show when project is completed --}} @if($item->status == \App\Models\Offer::STATUS_COMPLETED) @include('front.project._ratings_box', ['offer' => $item]) @endif

@lang('Offer Details')

نوع العرض

{{ $item->payment_type == 'full' ? 'دفعة واحدة' : 'دفعات مرحلية (' . $item->installments->count() . ' مراحل)' }}

@lang('Duration')

@if($item->delivery_days) {{ $item->delivery_days }} @lang('Day') @elseif($item->time) {{ getTrans($item->time->display_name,lang()) }} @else {{ trans('N/A') }} @endif

{!! $item->notes ? format_text($item->notes) : trans('N/A') !!}
@php $attachments = $item->getMedia('attachments'); @endphp @if(count($attachments) > 0)

@lang('Attachments')

@foreach($attachments as $attachment) @php // Check if it's a PDF based on mime type $isPdf = str_contains($attachment->mime_type, 'pdf'); $isImage = str_contains($attachment->mime_type, 'image'); @endphp @if($isPdf) {{-- PDF File --}}
PDF
{{ $attachment->file_name }}
@elseif($isImage) {{-- Image File --}} Offer attachment @else {{-- Other File Types --}}
{{ strtoupper(pathinfo($attachment->file_name, PATHINFO_EXTENSION)) }}
{{ $attachment->file_name }}
@endif @endforeach
@endif

تفاصيل الدفع

@if($is_parts_offer) {{-- Display installments details --}}
@php $totalDays = 0; @endphp @foreach($item->installments as $index => $installment) @php if($installment->delivery_days) { $totalDays += $installment->delivery_days; } @endphp
المرحلة {{ $index + 1 }}: {{ $installment->description }}
المدة

@if($installment->delivery_days) {{ $installment->delivery_days }} @lang('Day') @elseif($installment->due_date) {{ $installment->due_date }} @else {{ trans('N/A') }} @endif

التكلفة

{{ $installment->amount }} $

@if(auth()->user()->isFreelancer()) {{--
صافي الربح

{{ $installment->amount - ($installment->service_fees ?? 0) }} $

--}} @endif @if($item->status == \App\Models\Offer::STATUS_RUNNING)
تاريخ التسليم

@if($installment->due_date) {{ $installment->due_date }} @elseif($item->approved_at && $installment->delivery_days) {{ \Carbon\Carbon::parse($item->approved_at)->addDays($totalDays)->format('Y-m-d') }} @else {{ trans('N/A') }} @endif

@endif
الحالة

@if($installment->status == \App\Models\OfferInstallment::STATUS_COMPLETED) مكتملة @elseif($installment->status == \App\Models\OfferInstallment::STATUS_RUNNING) قيد التنفيذ @elseif($installment->status == \App\Models\OfferInstallment::STATUS_PENDING_COMPLETED) بانتظار التسليم @elseif($installment->status == \App\Models\OfferInstallment::STATUS_CANCELLED) ملغية @else لم تبدأ بعد @endif

@endforeach {{-- Total summary --}} {{--
@if($item->delivery_days)
المدة الإجمالية

{{ $item->delivery_days }} @lang('Day')

@endif
التكلفة الإجمالية

{{$item->total}} $

@if(auth()->user()->isFreelancer())
إجمالي الربح

{{$item->total - $item->service_fees}} $

@endif
--}}
@else {{-- Display regular payment details --}}
@lang('Total Cost')

{{$item->total}} $

@if(isset($item->hour_cost))
@lang('Hour Cost')

{{$item->hour_cost}} $

@endif @if(isset($item->hours_number))
@lang('Hours Number')

{{$item->hours_number}} @lang('Hour')

@endif @if(auth()->user()->isFreelancer()) {{--
@lang('Service Cost')

{{$item->service_fees}} $

@lang('The Profit')

{{$item->total - $item->service_fees}} $

--}} @endif
@endif
@if(count($project->questions) > 0)

@lang('Questions')

@if(isset($project) && count($project->questions) > 0 && isset($item->answers)) @foreach($project->questions as $question) @php $qText = $question->question; $answer = $item->answers[$qText] ?? null; @endphp {{$qText}}

{{$answer}}

@endforeach @elseif(count($item->answers) > 0) @foreach($item->answers as $q => $answer) {{$q}}

{{$answer}}

@endforeach @endif
@endif
@if((getCurrentUser()->isFreelancer() && !in_array($item->status,[ \App\Models\Offer::STATUS_PENDING, \App\Models\Offer::STATUS_REJECTED, \App\Models\Offer::STATUS_COMPLETED])) || (getCurrentUser()->isProjectOwner()) || isset($chat) && $chat->messages->count() > 0) @php $current = auth()->user(); $other = getCurrentUser()->isFreelancer() ? $project->user : $item->user; @endphp @include('front.partials._chat_block', [ 'chat' => $chat, 'current' => $current, 'other' => $other, 'projectId' => $project?->id ]) @endif
@if(auth()->check()) @endif
{{-- Project Details Box --}} @include('front.project._project_details_box') @if($item->status == \App\Models\Offer::STATUS_RUNNING)

تفاصيل التنفيذ

{{-- --}}
تاريخ بداية التنفيذ {{$item->approved_at ? date('Y-m-d', strtotime($item->approved_at)) : trans('N/A')}}
تاريخ نهاية التنفيذ @if($item->approved_at) @if($project->delivery_days) @php $endDate = \Carbon\Carbon::parse($item->approved_at)->addDays($project->delivery_days); @endphp @elseif($project->time && $project->time->value) @php $endDate = \Carbon\Carbon::parse($item->approved_at)->addDays($project->time->value); @endphp @endif @endif @if($item->completed_at) @php $endDate = $item->completed_at; @endphp @endif {{isset($endDate) && $endDate ? date('Y-m-d', strtotime($endDate)) : trans('N/A')}}
مدة التنفيذ @if($project->delivery_days) {{ $project->delivery_days }} @lang('Day') @elseif($project->time) {{ getTrans($project->time->display_name, lang()) }} @endif
@endif {{-- User Information Box (Project Owner or Freelancer) --}} @include('front.project._project_owner_box', [ 'user' => $user, ])
@if(isset($is_parts_offer)) {{-- @if(isset($partToDelivery) && isset($lastPart) && $lastPart->id == $partToDelivery->id)--}} {{-- @endif--}} @endif {{-- Modification Request Modal (Freelancer) --}} @if($canRequestModification) @endif {{-- Reject Modification Modal (Project Owner) --}} @if($pendingModRequest && getCurrentUser()->isProjectOwner()) @endif @endsection @section('js-body') @endsection