Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Export pdf #410

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions app/Exports/Pdf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace App\Exports;

use App\Models\Beneficiary;
use App\Services\Reports\BeneficiariesV2;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Maatwebsite\Excel\Concerns\FromView;

class Pdf implements FromView
{
public static function getModel(): Model
{
return Beneficiary::make();
}

public static function getOptionsFormComponents()
{
return [];
}

public static function getColumns()
{
return [];
}
public function view(): View
{
// $verticalSubHeader = $this->reportService->getVerticalSubHeader();
// $horizontalSubHeader = $this->reportService->getHorizontalSubHeader();
// $firstHeaderElementColSpan = $verticalSubHeader ? 2 : 1;
// $firstHeaderElementRowSpan = $horizontalSubHeader ? 2 : 1;

return view('exports.export_pdf', [
// 'reportData' => $this->reportService->getReportData(),
// 'header' => $this->reportService->getHorizontalHeader(),
// 'subHeader' => $horizontalSubHeader,
// 'subHeaderKey' => $this->reportService->getSubHeaderKey(),
// 'verticalHeader' => $this->reportService->getVerticalHeader(),
// 'verticalHeaderKey' => $this->reportService->getVerticalHeaderKey(),
// 'verticalSubHeader' => $verticalSubHeader,
// 'verticalSubHeaderKey' => $this->reportService->getVerticalSubHeaderKey(),
// 'firstHeaderElementColSpan' => $firstHeaderElementColSpan,
// 'firstHeaderElementRowSpan' => $firstHeaderElementRowSpan,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace App\Filament\Organizations\Resources\BeneficiaryResource\Actions;

use Filament\Actions\Action;
use Filament\Infolists\Infolist;
use Illuminate\Support\Facades\Blade;
use Spatie\LaravelPdf\Facades\Pdf;

class ExportPdf extends Action
{
protected array | \Closure | null $schema = null;

protected function setUp(): void
{
parent::setUp();

$this->action(function () {
$infolist = Infolist::make()
->record($this->getRecord())
->schema($this->schema);

$html = view('exports.pdf-page', ['infolist' => $infolist])->render();
// dd($html);

return response()->streamDownload(function () use ($infolist) {
echo \Barryvdh\DomPDF\Facade\Pdf::loadHtml(
Blade::render('exports.pdf-page', ['infolist' => $infolist])
)
// ->setOptions(['defaultFont' => filament()->getFontFamily()], true)
// ->setOptions(['defaultFont' => 'identity'], true)
->stream();
}, 'test' . '.pdf');

// return \Barryvdh\DomPDF\Facade\Pdf::loadView('exports.pdf-page', ['infolist' => $infolist])
// ->download('dasda.pdf')
// ->save(storage_path('app/public/exports.pdf'))
// ;
// ->download();
// return Pdf::html($html)->download('close_file.pdf');
// Pdf::view('exports.pdf-page', ['infolist' => $infolist])
// ->name('close_file.pdf')
// ->download();
// ->save(storage_path('app/public/exports.pdf'));
// return dd();
// ->download();

});
}

public function schema(array|\Closure|null $schema): self
{
$this->schema = $schema;

return $this;
}

public function getName(): ?string
{
return 'export_pdf';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace App\Filament\Organizations\Resources\BeneficiaryResource\Actions;

use Filament\Actions\Action;
use Filament\Actions\ExportAction;
use Filament\Infolists\Infolist;
use Spatie\LaravelPdf\Facades\Pdf;

class ExportPdf2 extends ExportAction
{
protected array | \Closure | null $schema = null;

protected function setUp(): void
{
$this->exporter(\App\Exports\Pdf::class);
parent::setUp();

// $this->action(function () {
// $infolist = Infolist::make()
// ->record($this->getRecord())
// ->schema($this->schema);
//
// dd(Pdf::view('exports.pdf-page', ['infolist' => $infolist]));
//// ->save(storage_path('app/public/exports.pdf'));
// return dd();
//// ->download();
//
// });
}

public function schema(array|\Closure|null $schema): self
{
$this->schema = $schema;

return $this;
}

public function getName(): ?string
{
return 'export_pdf_2';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,48 @@ public function getBreadcrumbs(): array
->getBreadcrumbs('view_close_file');
}

/**
* @return array
*/
public function getFileDetailsSchema(): array
{
return [
TextEntry::make('date')
->label(__('beneficiary.section.close_file.labels.date')),

TextEntry::make('number')
->label(__('beneficiary.section.close_file.labels.number')),

TextEntry::make('admittance_date')
->label(__('beneficiary.section.close_file.labels.admittance_date')),

TextEntry::make('exit_date')
->label(__('beneficiary.section.close_file.labels.exit_date')),

TextEntry::make('caseManager.name_role')
->label(__('beneficiary.section.close_file.labels.case_manager')),

];
}

protected function getHeaderActions(): array
{
return [
BeneficiaryResource\Actions\ExportPdf::make()
->schema([
TextEntry::make('status')
->badge(),

Section::make('asdasdasd')
->columns()
->relationship('closeFile')
->schema($this->getFileDetailsSchema()),
]),

BeneficiaryResource\Actions\ExportPdf2::make()
->exporter(\App\Exports\Pdf::class)
->schema($this->getFileDetailsSchema()),

DeleteAction::make()
->label(__('beneficiary.section.close_file.actions.delete'))
->outlined()
Expand Down Expand Up @@ -70,23 +109,7 @@ public function infolist(Infolist $infolist): Infolist
Edit::make('edit_details')
->url(self::getResource()::getUrl('edit_close_file_details', ['record' => $this->getRecord()])),
])
->schema([
TextEntry::make('date')
->label(__('beneficiary.section.close_file.labels.date')),

TextEntry::make('number')
->label(__('beneficiary.section.close_file.labels.number')),

TextEntry::make('admittance_date')
->label(__('beneficiary.section.close_file.labels.admittance_date')),

TextEntry::make('exit_date')
->label(__('beneficiary.section.close_file.labels.exit_date')),

TextEntry::make('caseManager.name_role')
->label(__('beneficiary.section.close_file.labels.case_manager')),

]),
->schema($this->getFileDetailsSchema()),
]),
Tabs\Tab::make(__('beneficiary.section.identity.tab.beneficiary'))
->maxWidth('3xl')
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"php": "^8.2",
"alcea/cnp": "^3.0",
"awcodes/filament-table-repeater": "^2.0",
"barryvdh/laravel-dompdf": "^3.0",
"blade-ui-kit/blade-icons": "^1.6",
"filament/filament": "^3.2",
"filament/spatie-laravel-media-library-plugin": "^3.2",
Expand All @@ -29,6 +30,7 @@
"pxlrbt/filament-excel": "^2.3",
"sentry/sentry-laravel": "^4.7",
"spatie/laravel-activitylog": "^4.8",
"spatie/laravel-pdf": "^1.5",
"staudenmeir/belongs-to-through": "^2.5",
"staudenmeir/eloquent-has-many-deep": "^1.7",
"stevegrunwell/time-constants": "^1.2",
Expand Down
Loading
Loading