Skip to content

Commit

Permalink
fixed empty page
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Oct 3, 2023
1 parent a3027f0 commit 6256f38
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
33 changes: 31 additions & 2 deletions app/Abstracts/View/Components/Documents/Index.php
Expand Up @@ -26,6 +26,8 @@ abstract class Index extends Component

public $documents;

public $totalDocuments;

/** @var string */
public $group;

Expand Down Expand Up @@ -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,
Expand All @@ -246,6 +248,7 @@ public function __construct(
$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);
Expand Down Expand Up @@ -278,7 +281,7 @@ public function __construct(

/* -- 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);
Expand Down Expand Up @@ -351,6 +354,32 @@ public function __construct(
$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)) {
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Purchases/Bills.php
Expand Up @@ -31,7 +31,9 @@ public function index()

$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'));
}

/**
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Sales/Invoices.php
Expand Up @@ -32,7 +32,9 @@ public function index()

$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'));
}

/**
Expand Down
@@ -1,4 +1,4 @@
@if ($hideEmptyPage || ($documents->count() || (request()->has('search') && ! request()->has('programmatic'))))
@if ($hideEmptyPage)
@if (! $hideSummary)
<x-index.summary :items="$summaryItems" />
@endif
Expand Down
2 changes: 1 addition & 1 deletion resources/views/purchases/bills/index.blade.php
Expand Up @@ -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" />
Expand Down
2 changes: 1 addition & 1 deletion resources/views/sales/invoices/index.blade.php
Expand Up @@ -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" />
Expand Down

0 comments on commit 6256f38

Please sign in to comment.