Word to export working properly
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PaymentOrder\PaymentOrderResource\Actions;
|
||||
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\PaymentOrder\Models\PaymentOrder;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use PhpOffice\PhpWord\TemplateProcessor;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class ExportToWord
|
||||
{
|
||||
use Makeable;
|
||||
|
||||
/**
|
||||
* Export to ms-word
|
||||
*/
|
||||
public function __construct(protected PaymentOrder $record, protected string $filepath = '')
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Export to ms-word
|
||||
*/
|
||||
public function handle(): self
|
||||
{
|
||||
Carbon::setLocale('tk');
|
||||
|
||||
$date_written_turkmen = sprintf(
|
||||
'%s -nji(y) ýylyň %s aýynyň %s',
|
||||
$this->record->created_at->year,
|
||||
Str::lower($this->record->created_at->translatedFormat('F')),
|
||||
$this->record->created_at->format('d')
|
||||
);
|
||||
|
||||
$templateProcessor = new TemplateProcessor(modules_path('PaymentOrder/Resources/Docs/orders.docx'));
|
||||
$templateProcessor->setValues([
|
||||
'n' => $this->record->number,
|
||||
|
||||
// Dates...
|
||||
'date_written_turkmen' => $date_written_turkmen,
|
||||
'p_date' => $this->record->created_at->format('Y-m-d'),
|
||||
|
||||
// Money...
|
||||
'money_amount' => number_format(floatval($this->record->money_amount), 2, '-', ''),
|
||||
'money_in_letter' => ucfirst(moneyFormatInTurkmenLetter($this->record->money_amount)),
|
||||
|
||||
// Bank topary...
|
||||
'b_nm' => $this->record->bank_code,
|
||||
|
||||
// Sebäbi...
|
||||
'p_reason_n' => $this->record->payment_reason_number,
|
||||
'p_reason' => $this->record->payment_reason_description,
|
||||
|
||||
// Töleýji...
|
||||
't_name' => $this->record->t_name,
|
||||
't_ssb' => $this->record->t_ssb,
|
||||
't_bab' => $this->record->t_bab,
|
||||
't_bank' => $this->record->t_bank,
|
||||
't_hb_1' => $this->record->t_hb_1,
|
||||
't_hb_2' => $this->record->t_hb_2,
|
||||
|
||||
// Alyjy...
|
||||
'a_name' => $this->record->a_name,
|
||||
'a_ssb' => $this->record->a_ssb,
|
||||
'a_bab' => $this->record->a_bab,
|
||||
'a_bank' => $this->record->a_bank,
|
||||
'a_hb_1' => $this->record->a_hb_1,
|
||||
'a_hb_2' => $this->record->a_hb_2,
|
||||
]);
|
||||
|
||||
$this->filepath = storage_path('app/private/payment-order.docx');
|
||||
$templateProcessor->saveAs($this->filepath);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file path
|
||||
*/
|
||||
public function filePath(): string
|
||||
{
|
||||
return $this->filepath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force browser to download file
|
||||
*/
|
||||
public function download(): StreamedResponse
|
||||
{
|
||||
/** @var Storage $storage */
|
||||
$storage = Storage::disk('private');
|
||||
|
||||
return $storage->download('payment-order.docx');
|
||||
}
|
||||
}
|
||||
@@ -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()),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use App\Modules\EmptyModule;
|
||||
use App\Modules\ModuleContract;
|
||||
use App\Modules\TurkmenNumberFormatter\Repositories\TurkmenNumberFormatter;
|
||||
use Illuminate\Contracts\Cache\Repository as CacheRepository;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -132,3 +133,13 @@ function getLatestNumber(string $tableName = 'incoming_letters', string $column
|
||||
|
||||
return $data ? intval($data->max_number) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Written format of money in turkmen
|
||||
*
|
||||
* @param string $money
|
||||
*/
|
||||
function moneyFormatInTurkmenLetter(string $money): string
|
||||
{
|
||||
return TurkmenNumberFormatter::format(floatval($money));
|
||||
}
|
||||
|
||||
@@ -6,23 +6,23 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property ?string $number
|
||||
* @property ?string $money_amount
|
||||
* @property ?string $payment_reason_number
|
||||
* @property ?string $payment_reason_description
|
||||
* @property ?string $bank_code
|
||||
* @property ?string $t_name
|
||||
* @property ?string $t_ssb
|
||||
* @property ?string $t_bab
|
||||
* @property ?string $t_bank
|
||||
* @property ?string $t_hb_1
|
||||
* @property ?string $t_hb_2
|
||||
* @property ?string $a_name
|
||||
* @property ?string $a_ssb
|
||||
* @property ?string $a_bab
|
||||
* @property ?string $a_bank
|
||||
* @property ?string $a_hb_1
|
||||
* @property ?string $a_hb_2
|
||||
* @property string $number
|
||||
* @property string $money_amount
|
||||
* @property string $payment_reason_number
|
||||
* @property string $payment_reason_description
|
||||
* @property string $bank_code
|
||||
* @property string $t_name
|
||||
* @property string $t_ssb
|
||||
* @property string $t_bab
|
||||
* @property string $t_bank
|
||||
* @property string $t_hb_1
|
||||
* @property string $t_hb_2
|
||||
* @property string $a_name
|
||||
* @property string $a_ssb
|
||||
* @property string $a_bab
|
||||
* @property string $a_bank
|
||||
* @property string $a_hb_1
|
||||
* @property string $a_hb_2
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $deleted_at
|
||||
*/
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user