diff --git a/app/Http/Controllers/ClientPortal/QuoteController.php b/app/Http/Controllers/ClientPortal/QuoteController.php index c646d41efee9..1b0fa8214428 100644 --- a/app/Http/Controllers/ClientPortal/QuoteController.php +++ b/app/Http/Controllers/ClientPortal/QuoteController.php @@ -31,6 +31,7 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse; use ZipStream\Option\Archive; use ZipStream\ZipStream; use Illuminate\Http\Request; +use Illuminate\Support\Carbon; class QuoteController extends Controller { @@ -54,7 +55,9 @@ class QuoteController extends Controller * @return Factory|View|BinaryFileResponse */ public function show(ShowQuoteRequest $request, Quote $quote) - { + { + /* If the quote is expired, convert the status here */ + $data = [ 'quote' => $quote, ]; diff --git a/app/Http/Livewire/QuotesTable.php b/app/Http/Livewire/QuotesTable.php index e93d24ec6d06..1aa996f089d9 100644 --- a/app/Http/Livewire/QuotesTable.php +++ b/app/Http/Livewire/QuotesTable.php @@ -42,17 +42,45 @@ class QuotesTable extends Component ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc'); if (count($this->status) > 0) { - $query = $query->whereIn('status_id', $this->status); + + /* Special filter for expired*/ + if(in_array("-1", $this->status)){ + // $query->whereDate('due_date', '<=', now()->startOfDay()); + + $query->where(function ($query){ + $query->whereDate('due_date', '<=', now()->startOfDay()) + ->whereNotNull('due_date') + ->where('status_id', '<>', Quote::STATUS_CONVERTED); + }); + + } + + if(in_array("2", $this->status)){ + + $query->where(function ($query){ + $query->whereDate('due_date', '>=', now()->startOfDay()) + ->orWhereNull('due_date'); + })->where('status_id', Quote::STATUS_SENT); + + } + + if(in_array("3", $this->status)){ + $query->whereIn('status_id', [Quote::STATUS_APPROVED, Quote::STATUS_CONVERTED]); + } + + } + + $query = $query ->where('company_id', $this->company->id) ->where('client_id', auth('contact')->user()->client->id) ->where('status_id', '<>', Quote::STATUS_DRAFT) - ->where(function ($query){ - $query->whereDate('due_date', '>=', now()) - ->orWhereNull('due_date'); - }) + // ->where(function ($query){ + // $query->whereDate('due_date', '>=', now()) + // ->orWhereNull('due_date'); + // }) ->where('is_deleted', 0) ->withTrashed() ->paginate($this->per_page); diff --git a/app/Models/Quote.php b/app/Models/Quote.php index b5d105313913..451c73f69d5a 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -87,6 +87,7 @@ class Quote extends BaseModel 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', + 'is_deleted' => 'boolean', ]; protected $dates = []; @@ -117,6 +118,16 @@ class Quote extends BaseModel return $this->dateMutator($value); } + public function getStatusIdAttribute($value) + { + if($this->due_date && !$this->is_deleted && $value == Quote::STATUS_SENT && Carbon::parse($this->due_date)->lte(now()->startOfDay())){ + return Quote::STATUS_EXPIRED; + } + + return $value; + + } + public function company() { return $this->belongsTo(Company::class);