fixed empty page

This commit is contained in:
Denis Duliçi 2023-10-03 18:06:15 +03:00
parent a3027f0c2e
commit 6256f381c0
6 changed files with 40 additions and 7 deletions

View File

@ -26,6 +26,8 @@ abstract class Index extends Component
public $documents;
public $totalDocuments;
/** @var string */
public $group;
@ -223,7 +225,7 @@ abstract class Index extends Component
* @return void
*/
public function __construct(
string $type, string $alias = '', $documents = [], string $group = '', string $page = '', string $textTabDocument = '', string $textPage = '',
string $type, string $alias = '', $documents = [], int $totalDocuments = null, string $group = '', string $page = '', string $textTabDocument = '', string $textPage = '',
string $routeTabDocument = '', string $routeTabRecurring = '', string $routeParamsTabUnpaid = '', string $routeParamsTabDraft = '',
string $permissionCreate = '', string $permissionUpdate = '', string $permissionDelete = '',
bool $hideAcceptPayment = false, bool $checkPermissionCreate = true,
@ -246,6 +248,7 @@ abstract class Index extends Component
$this->type = $type;
$this->alias = $this->getAlias($type, $alias);
$this->documents = ($documents) ? $documents : collect();
$this->totalDocuments = $this->getTotalDocuments($totalDocuments);
$this->group = $this->getGroup($type, $group);
$this->page = $this->getPage($type, $page);
$this->textTabDocument = $this->getTextTabDocument($type, $textTabDocument);
@ -278,7 +281,7 @@ abstract class Index extends Component
/* -- Content Start -- */
/* -- Empty Page Start -- */
$this->hideEmptyPage = $hideEmptyPage;
$this->hideEmptyPage = $this->getHideEmptyPage($hideEmptyPage);
$this->emptyPageButtons = $this->getEmptyPageButtons($type, $emptyPageButtons);
$this->imageEmptyPage = $this->getImageEmptyPage($type, $imageEmptyPage);
@ -351,6 +354,32 @@ abstract class Index extends Component
$this->setParentData();
}
protected function getTotalDocuments($totalDocuments)
{
if (! is_null($totalDocuments)) {
return $totalDocuments;
}
return $this->documents->count();
}
protected function getHideEmptyPage($hideEmptyPage): bool
{
if ($hideEmptyPage) {
return $hideEmptyPage;
}
if ($this->totalDocuments > 0) {
return true;
}
if (request()->has('search') && ($this->totalDocuments > 0)) {
return true;
}
return false;
}
protected function getEmptyPageButtons($type, $emptyPageButtons)
{
if (! empty($emptyPageButtons)) {

View File

@ -31,7 +31,9 @@ class Bills extends Controller
$bills = Document::bill()->with('contact', 'items', 'item_taxes', 'last_history', 'transactions', 'totals', 'histories', 'media')->collect(['issued_at' => 'desc']);
return $this->response('purchases.bills.index', compact('bills'));
$total_bills = Document::bill()->count();
return $this->response('purchases.bills.index', compact('bills', 'total_bills'));
}
/**

View File

@ -32,7 +32,9 @@ class Invoices extends Controller
$invoices = Document::invoice()->with('contact', 'items', 'item_taxes', 'last_history', 'transactions', 'totals', 'histories', 'media')->collect(['document_number'=> 'desc']);
return $this->response('sales.invoices.index', compact('invoices'));
$total_invoices = Document::invoice()->count();
return $this->response('sales.invoices.index', compact('invoices', 'total_invoices'));
}
/**

View File

@ -1,4 +1,4 @@
@if ($hideEmptyPage || ($documents->count() || (request()->has('search') && ! request()->has('programmatic'))))
@if ($hideEmptyPage)
@if (! $hideSummary)
<x-index.summary :items="$summaryItems" />
@endif

View File

@ -18,7 +18,7 @@
</x-slot>
<x-slot name="content">
<x-documents.index.content type="bill" :documents="$bills" />
<x-documents.index.content type="bill" :documents="$bills" :total-documents="$total_bills" />
</x-slot>
<x-documents.script type="bill" />

View File

@ -18,7 +18,7 @@
</x-slot>
<x-slot name="content">
<x-documents.index.content type="invoice" :documents="$invoices" />
<x-documents.index.content type="invoice" :documents="$invoices" :total-documents="$total_invoices" />
</x-slot>
<x-documents.script type="invoice" />