Merge pull request #3926 from beganovich/v2-2207-hide-drafts-from-clients

Fixes for invoices & drafts
This commit is contained in:
David Bomba 2020-07-23 20:56:50 +10:00 committed by GitHub
commit 6ca56d3cb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 30 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Livewire;
use App\Models\Invoice; use App\Models\Invoice;
use App\Utils\Traits\WithSorting; use App\Utils\Traits\WithSorting;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Livewire\Component; use Livewire\Component;
use Livewire\WithPagination; use Livewire\WithPagination;
@ -30,6 +31,7 @@ class InvoicesTable extends Component
public function render() public function render()
{ {
DB::enableQueryLog();
$query = Invoice::query() $query = Invoice::query()
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc'); ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc');
@ -44,12 +46,16 @@ class InvoicesTable extends Component
if (in_array('overdue', $this->status)) { if (in_array('overdue', $this->status)) {
$query = $query->orWhereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) $query = $query->orWhereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('due_date', '<', Carbon::now()) ->where(function ($query) {
->orWhere('partial_due_date', '<', Carbon::now()); $query
->orWhere('due_date', '<', Carbon::now())
->orWhere('partial_due_date', '<', Carbon::now());
});
} }
$query = $query $query = $query
->where('client_id', auth('contact')->user()->client->id) ->where('client_id', auth('contact')->user()->client->id)
->where('status_id', '<>', Invoice::STATUS_DRAFT)
->paginate($this->per_page); ->paginate($this->per_page);
return render('components.livewire.invoices-table', [ return render('components.livewire.invoices-table', [

View File

@ -218,7 +218,7 @@ class Quote extends BaseModel
return '<h5><span class="badge badge-light">' . ctrans('texts.draft') . '</span></h5>'; return '<h5><span class="badge badge-light">' . ctrans('texts.draft') . '</span></h5>';
break; break;
case Quote::STATUS_SENT: case Quote::STATUS_SENT:
return '<h5><span class="badge badge-primary">' . ctrans('texts.sent') . '</span></h5>'; return '<h5><span class="badge badge-primary">' . ctrans('texts.pending') . '</span></h5>';
break; break;
case Quote::STATUS_APPROVED: case Quote::STATUS_APPROVED:
return '<h5><span class="badge badge-success">' . ctrans('texts.approved') . '</span></h5>'; return '<h5><span class="badge badge-success">' . ctrans('texts.approved') . '</span></h5>';

View File

@ -1,8 +1,8 @@
<div> <div>
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<div class="flex items-center"> <div class="flex items-center">
<span class="mr-2 text-sm hidden md:block">{{ ctrans('texts.per_page') }}</span> <span class="hidden mr-2 text-sm md:block">{{ ctrans('texts.per_page') }}</span>
<select wire:model="per_page" class="form-select py-1 text-sm"> <select wire:model="per_page" class="py-1 text-sm form-select">
<option>5</option> <option>5</option>
<option selected>10</option> <option selected>10</option>
<option>15</option> <option>15</option>
@ -11,54 +11,54 @@
</div> </div>
<div class="flex items-center"> <div class="flex items-center">
<div class="mr-3"> <div class="mr-3">
<input wire:click="statusChange('draft')" type="checkbox" class="form-checkbox cursor-pointer" id="draft-checkbox"> <input wire:click="statusChange('draft')" type="checkbox" class="cursor-pointer form-checkbox" id="draft-checkbox">
<label for="draft-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_draft') }}</label> <label for="draft-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_draft') }}</label>
</div> </div>
<div class="mr-3"> <div class="mr-3">
<input wire:click="statusChange('sent')" value="sent" type="checkbox" class="form-checkbox cursor-pointer" id="sent-checkbox"> <input wire:click="statusChange('sent')" value="sent" type="checkbox" class="cursor-pointer form-checkbox" id="sent-checkbox">
<label for="sent-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_sent') }}</label> <label for="sent-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_pending') }}</label>
</div> </div>
<div class="mr-3"> <div class="mr-3">
<input wire:click="statusChange('approved')" value="approved" type="checkbox" class="form-checkbox cursor-pointer" id="approved-checkbox"> <input wire:click="statusChange('approved')" value="approved" type="checkbox" class="cursor-pointer form-checkbox" id="approved-checkbox">
<label for="approved-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.approved') }}</label> <label for="approved-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.approved') }}</label>
</div> </div>
<div class="mr-3"> <div class="mr-3">
<input wire:click="statusChange('expired')" value="expired" type="checkbox" class="form-checkbox cursor-pointer" id="expired-checkbox"> <input wire:click="statusChange('expired')" value="expired" type="checkbox" class="cursor-pointer form-checkbox" id="expired-checkbox">
<label for="expired-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.expired') }}</label> <label for="expired-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.expired') }}</label>
</div> </div>
</div> </div>
</div> </div>
<div class="-my-2 py-2 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8"> <div class="py-2 -my-2 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
<div class="align-middle inline-block min-w-full overflow-hidden rounded"> <div class="inline-block min-w-full overflow-hidden align-middle rounded">
<table class="min-w-full shadow rounded border border-gray-200 mt-4 quotes-table"> <table class="min-w-full mt-4 border border-gray-200 rounded shadow quotes-table">
<thead> <thead>
<tr> <tr>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider"> <th class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50">
<label> <label>
<input type="checkbox" class="form-check form-check-parent"> <input type="checkbox" class="form-check form-check-parent">
</label> </label>
</th> </th>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider"> <th class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50">
<span role="button" wire:click="sortBy('number')" class="cursor-pointer"> <span role="button" wire:click="sortBy('number')" class="cursor-pointer">
{{ ctrans('texts.quote_number') }} {{ ctrans('texts.quote_number') }}
</span> </span>
</th> </th>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider"> <th class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50">
<span role="button" wire:click="sortBy('date')" class="cursor-pointer"> <span role="button" wire:click="sortBy('date')" class="cursor-pointer">
{{ ctrans('texts.quote_date') }} {{ ctrans('texts.quote_date') }}
</span> </span>
</th> </th>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider"> <th class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50">
<span role="button" wire:click="sortBy('balance')" class="cursor-pointer"> <span role="button" wire:click="sortBy('balance')" class="cursor-pointer">
{{ ctrans('texts.balance') }} {{ ctrans('texts.balance') }}
</span> </span>
</th> </th>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider"> <th class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50">
<span role="button" wire:click="sortBy('date')" class="cursor-pointer"> <span role="button" wire:click="sortBy('date')" class="cursor-pointer">
{{ ctrans('texts.valid_until') }} {{ ctrans('texts.valid_until') }}
</span> </span>
</th> </th>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider"> <th class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50">
<span role="button" wire:click="sortBy('status_id')" class="cursor-pointer"> <span role="button" wire:click="sortBy('status_id')" class="cursor-pointer">
{{ ctrans('texts.quote_status') }} {{ ctrans('texts.quote_status') }}
</span> </span>
@ -69,27 +69,27 @@
<tbody> <tbody>
@forelse($quotes as $quote) @forelse($quotes as $quote)
<tr class="bg-white group hover:bg-gray-100"> <tr class="bg-white group hover:bg-gray-100">
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 font-medium text-gray-900"> <td class="px-6 py-4 text-sm font-medium leading-5 text-gray-900 whitespace-no-wrap">
<label> <label>
<input type="checkbox" class="form-check form-check-child" data-value="{{ $quote->hashed_id }}"> <input type="checkbox" class="form-check form-check-child" data-value="{{ $quote->hashed_id }}">
</label> </label>
</td> </td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500"> <td class="px-6 py-4 text-sm leading-5 text-gray-500 whitespace-no-wrap">
{{ $quote->number }} {{ $quote->number }}
</td> </td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500"> <td class="px-6 py-4 text-sm leading-5 text-gray-500 whitespace-no-wrap">
{{ $quote->formatDate($quote->date, $quote->client->date_format()) }} {{ $quote->formatDate($quote->date, $quote->client->date_format()) }}
</td> </td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500"> <td class="px-6 py-4 text-sm leading-5 text-gray-500 whitespace-no-wrap">
{{ App\Utils\Number::formatMoney($quote->balance, $quote->client) }} {{ App\Utils\Number::formatMoney($quote->balance, $quote->client) }}
</td> </td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500"> <td class="px-6 py-4 text-sm leading-5 text-gray-500 whitespace-no-wrap">
{{ $quote->formatDate($quote->date, $quote->client->date_format()) }} <!-- Fix valid until --> {{ $quote->formatDate($quote->due_date, $quote->client->date_format()) }}
</td> </td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500"> <td class="px-6 py-4 text-sm leading-5 text-gray-500 whitespace-no-wrap">
{!! App\Models\Quote::badgeForStatus($quote->status_id) !!} {!! App\Models\Quote::badgeForStatus($quote->status_id) !!}
</td> </td>
<td class="px-6 py-4 whitespace-no-wrap flex items-center justify-end text-sm leading-5 font-medium"> <td class="flex items-center justify-end px-6 py-4 text-sm font-medium leading-5 whitespace-no-wrap">
<a href="{{ route('client.quote.show', $quote->hashed_id) }}" class="button-link"> <a href="{{ route('client.quote.show', $quote->hashed_id) }}" class="button-link">
@lang('texts.view') @lang('texts.view')
</a> </a>
@ -97,7 +97,7 @@
</tr> </tr>
@empty @empty
<tr class="bg-white group hover:bg-gray-100"> <tr class="bg-white group hover:bg-gray-100">
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500" colspan="100%"> <td class="px-6 py-4 text-sm leading-5 text-gray-500 whitespace-no-wrap" colspan="100%">
{{ ctrans('texts.no_results') }} {{ ctrans('texts.no_results') }}
</td> </td>
</tr> </tr>
@ -106,9 +106,9 @@
</table> </table>
</div> </div>
</div> </div>
<div class="flex justify-center md:justify-between mt-6 mb-6"> <div class="flex justify-center mt-6 mb-6 md:justify-between">
@if($quotes->total() > 0) @if($quotes->total() > 0)
<span class="text-gray-700 text-sm hidden md:block"> <span class="hidden text-sm text-gray-700 md:block">
{{ ctrans('texts.showing_x_of', ['first' => $quotes->firstItem(), 'last' => $quotes->lastItem(), 'total' => $quotes->total()]) }} {{ ctrans('texts.showing_x_of', ['first' => $quotes->firstItem(), 'last' => $quotes->lastItem(), 'total' => $quotes->total()]) }}
</span> </span>
@endif @endif