diff --git a/app/Modules/Excell/Excell.php b/app/Modules/Excell/Excell.php new file mode 100644 index 0000000..9c7bae3 --- /dev/null +++ b/app/Modules/Excell/Excell.php @@ -0,0 +1,16 @@ +defaultFontName = $fontname; + + return $this; + } + + /** + * Default font size + */ + public function setDefaultSize(int $size): self + { + $this->defaultSize = $size; + + return $this; + } + + /** + * Add or attach text + * + * @param array $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; + } +} diff --git a/app/Modules/Excell/Types/iRichText/Traits/HasExcellRichTextWrappers.php b/app/Modules/Excell/Types/iRichText/Traits/HasExcellRichTextWrappers.php new file mode 100644 index 0000000..891572e --- /dev/null +++ b/app/Modules/Excell/Types/iRichText/Traits/HasExcellRichTextWrappers.php @@ -0,0 +1,5 @@ +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 */ @@ -244,7 +230,7 @@ class GenerateInvoiceExcell ); $this->worksheet->getStyle('A'.$itemCellNumber)->applyFromArray([ '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 { - $richText = new RichText; - $satyjy_salgyt_belgi = $this->addToRichText( - richText: $richText, - text: 'Satyjynyň şahsy salgyt belgisi: ' - ); - - return $this->addToRichText( - richText: $satyjy_salgyt_belgi, - text: $this->data->seller_ssb, - isBold: true - ); + return Excell::richText() + ->setDefaultFont(FONTS::TIMES_NEW_ROMAN) + ->setDefaultSize(10) + ->add('Satyjynyň şahsy salgyt belgisi: ') + ->add($this->data->seller_ssb, bold: true) + ->toRichText(); } /** @@ -322,17 +303,12 @@ class GenerateInvoiceExcell */ public function satyjyBanky(): RichText { - $richText = new RichText; - $satyjy_banky = $this->addToRichText( - richText: $richText, - text: sprintf('Satyjynyň bankynyň ady %s, hasap № ', $this->data->seller_bank_name) - ); - - return $this->addToRichText( - richText: $satyjy_banky, - text: $this->data->seller_bank_hb_1, - isBold: true - ); + return Excell::richText() + ->setDefaultFont(FONTS::TIMES_NEW_ROMAN) + ->setDefaultSize(10) + ->add(sprintf('Satyjynyň bankynyň ady %s, hasap № ', $this->data->seller_bank_name)) + ->add($this->data->seller_bank_hb_1, bold: true) + ->toRichText(); } /** @@ -340,16 +316,16 @@ class GenerateInvoiceExcell */ public function satyjyBankyMaglumatlary(): RichText { - $richText = new RichText; - $city_label = $this->addToRichText($richText, 'şäherde (etrapda) '); - $city = $this->addToRichText($city_label, $this->data->seller_bank_city, isBold: true); - - $bab_label = $this->addToRichText($city, ' BAB '); - $bab = $this->addToRichText($bab_label, $this->data->seller_bank_bab, isBold: true); - - $hb_2_label = $this->addToRichText($bab, ' bankyň kor.hasap '); - - return $this->addToRichText($hb_2_label, $this->data->seller_bank_hb_2, isBold: true); + return Excell::richText() + ->setDefaultFont(FONTS::TIMES_NEW_ROMAN) + ->setDefaultSize(10) + ->add('şäherde (etrapda) ') + ->add($this->data->seller_bank_city, bold: true) + ->add(' BAB ') + ->add($this->data->seller_bank_bab, bold: true) + ->add(' bankyň kor.hasap ') + ->add($this->data->seller_bank_hb_2, bold: true) + ->toRichText(); } /** diff --git a/app/Modules/Invoice/Resources/.DS_Store b/app/Modules/Invoice/Resources/.DS_Store index 3043b7b..88b7b97 100644 Binary files a/app/Modules/Invoice/Resources/.DS_Store and b/app/Modules/Invoice/Resources/.DS_Store differ diff --git a/app/Modules/Invoice/Resources/Docs/invoice-original.xls b/app/Modules/Invoice/Resources/Docs/invoice-original.xls index fd920b6..e5b4bff 100755 Binary files a/app/Modules/Invoice/Resources/Docs/invoice-original.xls and b/app/Modules/Invoice/Resources/Docs/invoice-original.xls differ diff --git a/app/Modules/PHPExcell/.DS_Store b/app/Modules/PHPExcell/.DS_Store deleted file mode 100644 index 5008ddf..0000000 Binary files a/app/Modules/PHPExcell/.DS_Store and /dev/null differ diff --git a/public/write.xls b/public/write.xls index 92110ef..346ea3c 100644 Binary files a/public/write.xls and b/public/write.xls differ