Word to export working properly

This commit is contained in:
2024-11-04 13:15:52 +05:00
parent 0a860b3259
commit 54043d42aa
7 changed files with 133 additions and 25953 deletions

View File

@@ -3,13 +3,10 @@
namespace App\Filament\Resources\PaymentOrder\PaymentOrderResource\Pages;
use App\Filament\Resources\PaymentOrder\PaymentOrderResource;
use Carbon\Carbon;
use App\Filament\Resources\PaymentOrder\PaymentOrderResource\Actions\ExportToWord;
use Filament\Actions;
use Filament\Actions\Action;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use PhpOffice\PhpWord\TemplateProcessor;
class EditPaymentOrder extends EditRecord
{
@@ -18,54 +15,12 @@ class EditPaymentOrder extends EditRecord
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Action::make('sendEmail')
->action(function (array $data) {
/** @var \App\Modules\PaymentOrder\Models\PaymentOrder $paymentOrder */
$paymentOrder = $this->getRecord();
Actions\DeleteAction::make()
->icon('heroicon-m-trash'),
Carbon::setLocale('tk');
$orderNumber = 1;
$date_written_turkmen = sprintf(
'%s -nji(y) ýylyň %s aýynyň %s',
$paymentOrder->created_at->year,
Str::lower($paymentOrder->created_at->translatedFormat('F')),
$paymentOrder->created_at->format('d')
);
$templateProcessor = new TemplateProcessor(modules_path('PaymentOrder/Resources/Docs/orders.docx'));
$templateProcessor->setValues([
'n' => $paymentOrder->number,
'date_written_turkmen' => $date_written_turkmen,
'p_date' => $paymentOrder->created_at->format('Y-m-d'),
'money_amount' => $paymentOrder->money_amount,
// Bank topary
'b_nm' => $paymentOrder->bank_code,
't_name' => $paymentOrder->t_name,
't_ssb' => $paymentOrder->t_ssb,
't_bab' => $paymentOrder->t_bab,
't_bank' => $paymentOrder->t_bank,
't_hb_1' => $paymentOrder->t_hb_1,
't_hb_2' => $paymentOrder->t_hb_2,
'a_name' => $paymentOrder->a_name,
'a_ssb' => $paymentOrder->a_ssb,
'a_bab' => $paymentOrder->a_bab,
'a_bank' => $paymentOrder->a_bank,
'a_hb_1' => $paymentOrder->a_hb_1,
'a_hb_2' => $paymentOrder->a_hb_2,
]);
$pathToSave = storage_path('app/private/ok.docx');
$templateProcessor->saveAs($pathToSave);
return Storage::disk('private')->download('ok.docx');
}),
Action::make('ExportToWord')
->icon('heroicon-m-document-arrow-down')
->action(fn () => ExportToWord::make($this->getRecord())->handle()->download()),
];
}
}