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 Collection<array-key, mixed>|array<string, string>
* @return Collection<int|string, string>|array<string, string>
*/
public function options(): Collection|array
{
return CacheRepository::make(
/** @var Collection<int|string, string> */
$options = CacheRepository::make(
name: static::$cacheName.'_options',
value: fn () => $this->query->get(['id', 'name', 'bab'])->mapWithKeys(fn ($item) => [
$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\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Font;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class GenerateInvoiceExcell
@@ -93,40 +94,53 @@ class GenerateInvoiceExcell
$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
*/
protected function fillTheCells(): void
{
// Hasap faktura nomeri...
$this->worksheet->getCell('C6')->setValue($this->hasapFakturaNomeri());
$data = $this->getTemplateValues();
// Sene...
$this->worksheet->getCell('C7')->setValue($this->sene());
foreach ($data as $cell => $value) {
$this->worksheet->getCell($cell)->setValue($value);
}
}
// Satyjy...
$this->worksheet->getCell('A9')->setValue($this->satyjy());
// Satyjy şahsy salgyt belgi...
$this->worksheet->getCell('A11')->setValue($this->satyjySalgytBelgi());
// Satyjy banky...
$this->worksheet->getCell('A12')->setValue($this->satyjyBanky());
// Satyjy bank maglumatlary...
$this->worksheet->getCell('A13')->setValue(sprintf('şäherde (etrapda) %s BAB %s bankyň kor.hasap %s', 'Aşgabat', '390101601', '21101934110100700005000'));
// Satyn alyjy...
$this->worksheet->getCell('A16')->setValue(sprintf('Satyn alyjy: %s', 'Türkmenistanyň „Türkmenbaşy“ paýdarlar täjirçilik banky'));
// Satyn alyjy salgy...
$this->worksheet->getCell('A18')->setValue(sprintf('744000 Aşgabat ş., Çandebil şaýoly köç., 121,'));
// 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'));
/**
* Get template cells and values
*
* @return array<string, mixed>
*/
protected function getTemplateValues(): array
{
return [
'C6' => $this->hasapFakturaNomeri(),
'C7' => $this->sene(),
'A9' => $this->satyjy(),
'A11' => $this->satyjySalgytBelgi(),
'A12' => $this->satyjyBanky(),
'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',
'A18' => '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'),
];
}
/**
@@ -164,21 +178,17 @@ class GenerateInvoiceExcell
*/
public function satyjySalgytBelgi(): RichText
{
$satyjy_salgyt_belgi = new RichText;
$satyjy_salgyt_belgi
->createTextRun('Satyjynyň şahsy salgyt belgisi: ')
->getFont()
->setName('Times New Roman')
->setSize(10);
$richText = new RichText;
$satyjy_salgyt_belgi = $this->addToRichText(
richText: $richText,
text: 'Satyjynyň şahsy salgyt belgisi: '
);
$satyjy_salgyt_belgi
->createTextRun($this->data->seller_ssb)
->getFont()
->setBold(true)
->setName('Times New Roman')
->setSize(10);
return $satyjy_salgyt_belgi;
return $this->addToRichText(
richText: $satyjy_salgyt_belgi,
text: $this->data->seller_ssb,
isBold: true
);
}
/**
@@ -186,20 +196,16 @@ class GenerateInvoiceExcell
*/
public function satyjyBanky(): RichText
{
$satyjy_banky = new RichText;
$satyjy_banky
->createTextRun(sprintf('Satyjynyň bankynyň ady %s, hasap № ', $this->data->seller_bank_name))
->getFont()
->setName('Times New Roman')
->setSize(10);
$richText = new RichText;
$satyjy_banky = $this->addToRichText(
richText: $richText,
text: sprintf('Satyjynyň bankynyň ady %s, hasap № ', $this->data->seller_bank_name)
);
$satyjy_banky
->createTextRun($this->data->seller_bank_number)
->getFont()
->setBold(true)
->setName('Times New Roman')
->setSize(10);
return $satyjy_banky;
return $this->addToRichText(
richText: $satyjy_banky,
text: $this->data->seller_bank_number,
isBold: true
);
}
}

Binary file not shown.