Skip to content

Commit

Permalink
fixed download PDF issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Jun 27, 2021
1 parent 71394f8 commit 116562e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/Http/Controllers/Purchases/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
use App\Models\Setting\Currency;
use App\Traits\Currencies;
use App\Traits\DateTime;
use App\Traits\Transactions;
use App\Utilities\Modules;

class Payments extends Controller
{
use Currencies, DateTime;
use Currencies, DateTime, Transactions;

/**
* Display a listing of the resource.
Expand Down Expand Up @@ -318,7 +319,7 @@ public function pdfPayment(Transaction $payment)

//$pdf->setPaper('A4', 'portrait');

$file_name = $this->getDocumentFileName($payment);
$file_name = $this->getTransactionFileName($payment);

return $pdf->download($file_name);
}
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Sales/Revenues.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
use App\Notifications\Sale\Revenue as Notification;
use App\Traits\Currencies;
use App\Traits\DateTime;
use App\Traits\Transactions;
use App\Utilities\Modules;

class Revenues extends Controller
{
use Currencies, DateTime;
use Currencies, DateTime, Transactions;

/**
* Display a listing of the resource.
Expand Down Expand Up @@ -319,7 +320,7 @@ public function pdfRevenue(Transaction $revenue)

//$pdf->setPaper('A4', 'portrait');

$file_name = $this->getDocumentFileName($revenue);
$file_name = $this->getTransactionFileName($revenue);

return $pdf->download($file_name);
}
Expand Down
13 changes: 13 additions & 0 deletions app/Traits/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Traits;

use App\Models\Banking\Transaction;
use Illuminate\Support\Str;

trait Transactions
{
public function isIncome()
Expand Down Expand Up @@ -60,6 +63,16 @@ public function addTransactionType($new_type, $index)
])->save();
}

public function getTransactionFileName(Transaction $transaction, string $separator = '-', string $extension = 'pdf'): string
{
return $this->getSafeTransactionNumber($transaction, $separator) . $separator . time() . '.' . $extension;
}

public function getSafeTransactionNumber(Transaction $transaction, string $separator = '-'): string
{
return Str::slug($transaction->id, $separator, language()->getShortCode());
}

protected function getSettingKey($type, $setting_key)
{
$key = '';
Expand Down

0 comments on commit 116562e

Please sign in to comment.