beautify code
This commit is contained in:
16
app/Modules/Excell/Excell.php
Normal file
16
app/Modules/Excell/Excell.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Excell;
|
||||||
|
|
||||||
|
use App\Modules\Excell\Types\iRichText\RichTextWrapper;
|
||||||
|
|
||||||
|
class Excell
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* RichText wrapper
|
||||||
|
*/
|
||||||
|
public static function richText(): RichTextWrapper
|
||||||
|
{
|
||||||
|
return new RichTextWrapper;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Modules\PHPExcell;
|
namespace App\Modules\Excell;
|
||||||
|
|
||||||
use App\Modules\Makeable;
|
use App\Modules\Makeable;
|
||||||
use App\Modules\ModuleContract;
|
use App\Modules\ModuleContract;
|
||||||
|
|
||||||
class PHPExcellModule implements ModuleContract
|
class ExcellModule implements ModuleContract
|
||||||
{
|
{
|
||||||
use Makeable;
|
use Makeable;
|
||||||
|
|
||||||
8
app/Modules/Excell/Fonts/Fonts.php
Normal file
8
app/Modules/Excell/Fonts/Fonts.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Excell\Fonts;
|
||||||
|
|
||||||
|
class FONTS
|
||||||
|
{
|
||||||
|
public const TIMES_NEW_ROMAN = 'Times New Roman';
|
||||||
|
}
|
||||||
67
app/Modules/Excell/Types/iRichText/RichTextWrapper.php
Normal file
67
app/Modules/Excell/Types/iRichText/RichTextWrapper.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Excell\Types\iRichText;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\RichText\RichText;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Font;
|
||||||
|
|
||||||
|
class RichTextWrapper
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected RichText $richText = new RichText,
|
||||||
|
protected string $defaultFontName = 'Calibri',
|
||||||
|
protected int $defaultSize = 12,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default font name
|
||||||
|
*/
|
||||||
|
public function setDefaultFont(string $fontname): self
|
||||||
|
{
|
||||||
|
$this->defaultFontName = $fontname;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default font size
|
||||||
|
*/
|
||||||
|
public function setDefaultSize(int $size): self
|
||||||
|
{
|
||||||
|
$this->defaultSize = $size;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add or attach text
|
||||||
|
*
|
||||||
|
* @param array<int, string> $styles
|
||||||
|
*/
|
||||||
|
public function add(?string $text, array $styles = [], bool $bold = false): self
|
||||||
|
{
|
||||||
|
if (! $text) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
$textRun = $this->richText->createTextRun($text);
|
||||||
|
|
||||||
|
$font = $textRun->getFont() ?: new Font;
|
||||||
|
$font->setName($this->defaultFontName)
|
||||||
|
->setSize($this->defaultSize);
|
||||||
|
|
||||||
|
if ($bold) {
|
||||||
|
$font->setBold(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return RichText
|
||||||
|
*/
|
||||||
|
public function toRichText(): RichText
|
||||||
|
{
|
||||||
|
return $this->richText;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Excell\Types\RichText\Traits;
|
||||||
|
|
||||||
|
trait HasExcellRichTextWrappers {}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Modules\Invoice\Actions;
|
namespace App\Modules\Invoice\Actions;
|
||||||
|
|
||||||
|
use App\Modules\Excell\Excell;
|
||||||
|
use App\Modules\Excell\Fonts\FONTS;
|
||||||
use App\Modules\Invoice\Data\InvoiceExcellData;
|
use App\Modules\Invoice\Data\InvoiceExcellData;
|
||||||
use App\Modules\Invoice\Data\InvoiceItem;
|
use App\Modules\Invoice\Data\InvoiceItem;
|
||||||
use App\Modules\Makeable;
|
use App\Modules\Makeable;
|
||||||
@@ -99,22 +101,6 @@ 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
|
||||||
*/
|
*/
|
||||||
@@ -244,7 +230,7 @@ class GenerateInvoiceExcell
|
|||||||
);
|
);
|
||||||
$this->worksheet->getStyle('A'.$itemCellNumber)->applyFromArray([
|
$this->worksheet->getStyle('A'.$itemCellNumber)->applyFromArray([
|
||||||
'font' => ['bold' => false, 'size' => 8, 'name' => 'Times New Roman'],
|
'font' => ['bold' => false, 'size' => 8, 'name' => 'Times New Roman'],
|
||||||
'alignment' => ['vertical' => Alignment::VERTICAL_TOP]
|
'alignment' => ['vertical' => Alignment::VERTICAL_TOP],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,17 +290,12 @@ class GenerateInvoiceExcell
|
|||||||
*/
|
*/
|
||||||
public function satyjySalgytBelgi(): RichText
|
public function satyjySalgytBelgi(): RichText
|
||||||
{
|
{
|
||||||
$richText = new RichText;
|
return Excell::richText()
|
||||||
$satyjy_salgyt_belgi = $this->addToRichText(
|
->setDefaultFont(FONTS::TIMES_NEW_ROMAN)
|
||||||
richText: $richText,
|
->setDefaultSize(10)
|
||||||
text: 'Satyjynyň şahsy salgyt belgisi: '
|
->add('Satyjynyň şahsy salgyt belgisi: ')
|
||||||
);
|
->add($this->data->seller_ssb, bold: true)
|
||||||
|
->toRichText();
|
||||||
return $this->addToRichText(
|
|
||||||
richText: $satyjy_salgyt_belgi,
|
|
||||||
text: $this->data->seller_ssb,
|
|
||||||
isBold: true
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -322,17 +303,12 @@ class GenerateInvoiceExcell
|
|||||||
*/
|
*/
|
||||||
public function satyjyBanky(): RichText
|
public function satyjyBanky(): RichText
|
||||||
{
|
{
|
||||||
$richText = new RichText;
|
return Excell::richText()
|
||||||
$satyjy_banky = $this->addToRichText(
|
->setDefaultFont(FONTS::TIMES_NEW_ROMAN)
|
||||||
richText: $richText,
|
->setDefaultSize(10)
|
||||||
text: sprintf('Satyjynyň bankynyň ady %s, hasap № ', $this->data->seller_bank_name)
|
->add(sprintf('Satyjynyň bankynyň ady %s, hasap № ', $this->data->seller_bank_name))
|
||||||
);
|
->add($this->data->seller_bank_hb_1, bold: true)
|
||||||
|
->toRichText();
|
||||||
return $this->addToRichText(
|
|
||||||
richText: $satyjy_banky,
|
|
||||||
text: $this->data->seller_bank_hb_1,
|
|
||||||
isBold: true
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -340,16 +316,16 @@ class GenerateInvoiceExcell
|
|||||||
*/
|
*/
|
||||||
public function satyjyBankyMaglumatlary(): RichText
|
public function satyjyBankyMaglumatlary(): RichText
|
||||||
{
|
{
|
||||||
$richText = new RichText;
|
return Excell::richText()
|
||||||
$city_label = $this->addToRichText($richText, 'şäherde (etrapda) ');
|
->setDefaultFont(FONTS::TIMES_NEW_ROMAN)
|
||||||
$city = $this->addToRichText($city_label, $this->data->seller_bank_city, isBold: true);
|
->setDefaultSize(10)
|
||||||
|
->add('şäherde (etrapda) ')
|
||||||
$bab_label = $this->addToRichText($city, ' BAB ');
|
->add($this->data->seller_bank_city, bold: true)
|
||||||
$bab = $this->addToRichText($bab_label, $this->data->seller_bank_bab, isBold: true);
|
->add(' BAB ')
|
||||||
|
->add($this->data->seller_bank_bab, bold: true)
|
||||||
$hb_2_label = $this->addToRichText($bab, ' bankyň kor.hasap ');
|
->add(' bankyň kor.hasap ')
|
||||||
|
->add($this->data->seller_bank_hb_2, bold: true)
|
||||||
return $this->addToRichText($hb_2_label, $this->data->seller_bank_hb_2, isBold: true);
|
->toRichText();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
BIN
app/Modules/Invoice/Resources/.DS_Store
vendored
BIN
app/Modules/Invoice/Resources/.DS_Store
vendored
Binary file not shown.
Binary file not shown.
BIN
app/Modules/PHPExcell/.DS_Store
vendored
BIN
app/Modules/PHPExcell/.DS_Store
vendored
Binary file not shown.
BIN
public/write.xls
BIN
public/write.xls
Binary file not shown.
Reference in New Issue
Block a user