clean code

This commit is contained in:
2024-11-10 00:50:07 +05:00
parent c0a94da482
commit 3f4c00f970
4 changed files with 66 additions and 57 deletions

View File

@@ -31,15 +31,18 @@ class BankRepository
/** /**
* Return available options * Return available options
* *
* @return Collection<array-key, mixed>|array<string, string> * @return Collection<int|string, string>|array<string, string>
*/ */
public function options(): Collection|array public function options(): Collection|array
{ {
return CacheRepository::make( /** @var Collection<int|string, string> */
$options = CacheRepository::make(
name: static::$cacheName.'_options', name: static::$cacheName.'_options',
value: fn () => $this->query->get(['id', 'name', 'bab'])->mapWithKeys(fn ($item) => [ value: fn () => $this->query->get(['id', 'name', 'bab'])->mapWithKeys(fn ($item) => [
$item->id => $item->name.' - '.$item->bab, $item->id => $item->name.' - '.$item->bab,
]), ]),
); );
return $options;
} }
} }

View File

@@ -8,6 +8,7 @@ use Illuminate\Support\Carbon;
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Font;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class GenerateInvoiceExcell class GenerateInvoiceExcell
@@ -93,40 +94,53 @@ class GenerateInvoiceExcell
$this->worksheet = $this->spreadsheet->getActiveSheet(); $this->worksheet = $this->spreadsheet->getActiveSheet();
} }
/**
* Create a RichText object with specified text and font settings.
*/
protected function addToRichText(RichText $richText, string $text, bool $isBold = false): RichText
{
$textRun = $richText->createTextRun($text);
$font = $textRun->getFont() ?: new Font;
$font->setName('Times New Roman')->setSize(10);
if ($isBold) {
$font->setBold(true);
}
return $richText;
}
/** /**
* Fill the cells * Fill the cells
*/ */
protected function fillTheCells(): void protected function fillTheCells(): void
{ {
// Hasap faktura nomeri... $data = $this->getTemplateValues();
$this->worksheet->getCell('C6')->setValue($this->hasapFakturaNomeri());
// Sene... foreach ($data as $cell => $value) {
$this->worksheet->getCell('C7')->setValue($this->sene()); $this->worksheet->getCell($cell)->setValue($value);
}
}
// Satyjy... /**
$this->worksheet->getCell('A9')->setValue($this->satyjy()); * Get template cells and values
*
// Satyjy şahsy salgyt belgi... * @return array<string, mixed>
$this->worksheet->getCell('A11')->setValue($this->satyjySalgytBelgi()); */
protected function getTemplateValues(): array
// Satyjy banky... {
$this->worksheet->getCell('A12')->setValue($this->satyjyBanky()); return [
'C6' => $this->hasapFakturaNomeri(),
// Satyjy bank maglumatlary... 'C7' => $this->sene(),
$this->worksheet->getCell('A13')->setValue(sprintf('şäherde (etrapda) %s BAB %s bankyň kor.hasap %s', 'Aşgabat', '390101601', '21101934110100700005000')); 'A9' => $this->satyjy(),
'A11' => $this->satyjySalgytBelgi(),
// Satyn alyjy... 'A12' => $this->satyjyBanky(),
$this->worksheet->getCell('A16')->setValue(sprintf('Satyn alyjy: %s', 'Türkmenistanyň „Türkmenbaşy“ paýdarlar täjirçilik banky')); 'A13' => sprintf('şäherde (etrapda) %s BAB %s bankyň kor.hasap %s', 'Aşgabat', '390101601', '21101934110100700005000'),
'A16' => 'Satyn alyjy: Türkmenistanyň „Türkmenbaşy“ paýdarlar täjirçilik banky',
// Satyn alyjy salgy... 'A18' => '744000 Aşgabat ş., Çandebil şaýoly köç., 121,',
$this->worksheet->getCell('A18')->setValue(sprintf('744000 Aşgabat ş., Çandebil şaýoly köç., 121,')); 'A19' => sprintf('Alyjynyň bankynyň ady %s %s', 'Türkmenistanyň Merkezi Banky', 'Aşgabat ş.'),
'A20' => sprintf('Satyn alyjynyň şahsy salgyt belgisi %s, MFO %s, Hasap № %s', '101301000408', '390101304', '21101934110100300007000'),
// Satyn alyjy banky... ];
$this->worksheet->getCell('A19')->setValue(sprintf('Alyjynyň bankynyň ady %s %s', 'Türkmenistanyň Merkezi Banky', 'Aşgabat ş.'));
// Satyn alyjy banky maglumatlary...
$this->worksheet->getCell('A20')->setValue(sprintf('Satyn alyjynyň şahsy salgyt belgisi %s, MFO %s, Hasap № %s', '101301000408', '390101304', '21101934110100300007000'));
} }
/** /**
@@ -164,21 +178,17 @@ class GenerateInvoiceExcell
*/ */
public function satyjySalgytBelgi(): RichText public function satyjySalgytBelgi(): RichText
{ {
$satyjy_salgyt_belgi = new RichText; $richText = new RichText;
$satyjy_salgyt_belgi $satyjy_salgyt_belgi = $this->addToRichText(
->createTextRun('Satyjynyň şahsy salgyt belgisi: ') richText: $richText,
->getFont() text: 'Satyjynyň şahsy salgyt belgisi: '
->setName('Times New Roman') );
->setSize(10);
$satyjy_salgyt_belgi return $this->addToRichText(
->createTextRun($this->data->seller_ssb) richText: $satyjy_salgyt_belgi,
->getFont() text: $this->data->seller_ssb,
->setBold(true) isBold: true
->setName('Times New Roman') );
->setSize(10);
return $satyjy_salgyt_belgi;
} }
/** /**
@@ -186,20 +196,16 @@ class GenerateInvoiceExcell
*/ */
public function satyjyBanky(): RichText public function satyjyBanky(): RichText
{ {
$satyjy_banky = new RichText; $richText = new RichText;
$satyjy_banky $satyjy_banky = $this->addToRichText(
->createTextRun(sprintf('Satyjynyň bankynyň ady %s, hasap № ', $this->data->seller_bank_name)) richText: $richText,
->getFont() text: sprintf('Satyjynyň bankynyň ady %s, hasap № ', $this->data->seller_bank_name)
->setName('Times New Roman') );
->setSize(10);
$satyjy_banky return $this->addToRichText(
->createTextRun($this->data->seller_bank_number) richText: $satyjy_banky,
->getFont() text: $this->data->seller_bank_number,
->setBold(true) isBold: true
->setName('Times New Roman') );
->setSize(10);
return $satyjy_banky;
} }
} }

Binary file not shown.