Fixes for client portal quote tables

This commit is contained in:
David Bomba 2022-01-07 15:03:42 +11:00
parent addc10ef4e
commit 959d45f081
3 changed files with 48 additions and 6 deletions

View File

@ -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
{
@ -55,6 +56,8 @@ class QuoteController extends Controller
*/
public function show(ShowQuoteRequest $request, Quote $quote)
{
/* If the quote is expired, convert the status here */
$data = [
'quote' => $quote,
];

View File

@ -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);

View File

@ -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);