diff --git a/app/Modules/Invoice/Actions/GenerateInvoiceExcell.php b/app/Modules/Invoice/Actions/GenerateInvoiceExcell.php new file mode 100644 index 0000000..d08fa13 --- /dev/null +++ b/app/Modules/Invoice/Actions/GenerateInvoiceExcell.php @@ -0,0 +1,205 @@ +setSpreadsheetFile(); + $this->setWorksheetFile(); + $this->fillTheCells(); + + return $this; + } + + /** + * Save the invoice + */ + public function save(): void + { + $writer = IOFactory::createWriter($this->spreadsheet, 'Xls'); + + $writer->save('write.xls'); + } + + /** + * Set template file path + */ + public function setTemplateFile(string $file): self + { + $this->templateFile = $file; + + return $this; + } + + /** + * Set data + */ + public function setData(InvoiceExcellData $data): self + { + $this->data = $data; + + return $this; + } + + /** + * Load template to a new spreadsheet + */ + protected function setSpreadsheetFile(): void + { + $this->spreadsheet = IOFactory::load($this->templateFile); + } + + /** + * Set working spreadsheet + */ + protected function setWorksheetFile(): void + { + $this->worksheet = $this->spreadsheet->getActiveSheet(); + } + + /** + * Fill the cells + */ + protected function fillTheCells(): void + { + // Hasap faktura nomeri... + $this->worksheet->getCell('C6')->setValue($this->hasapFakturaNomeri()); + + // Sene... + $this->worksheet->getCell('C7')->setValue($this->sene()); + + // 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')); + } + + /** + * Hasap faktura nomeri + */ + public function hasapFakturaNomeri(): string + { + return 'Hasap-faktura № '.$this->data->number; + } + + /** + * Sene + */ + public function sene(): string + { + $date = $this->data->date; + + $year = $date->year; + $day = $date->format('d'); + $month_as_string = $date->translatedFormat('F'); + + return sprintf('%s ýylyň «%s» %s', $year, $day, $month_as_string); + } + + /** + * Satyjy + */ + public function satyjy(): string + { + return sprintf('Satyjy: %s %s', $this->data->seller_firm_type, $this->data->seller_firm_name); + } + + /** + * Satyjy salgyt belgisi + */ + public function satyjySalgytBelgi(): RichText + { + $satyjy_salgyt_belgi = new RichText; + $satyjy_salgyt_belgi + ->createTextRun('Satyjynyň şahsy salgyt belgisi: ') + ->getFont() + ->setName('Times New Roman') + ->setSize(10); + + $satyjy_salgyt_belgi + ->createTextRun($this->data->seller_ssb) + ->getFont() + ->setBold(true) + ->setName('Times New Roman') + ->setSize(10); + + return $satyjy_salgyt_belgi; + } + + /** + * Satyjy bank maglumatlary + */ + 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); + + $satyjy_banky + ->createTextRun($this->data->seller_bank_number) + ->getFont() + ->setBold(true) + ->setName('Times New Roman') + ->setSize(10); + + return $satyjy_banky; + } +} diff --git a/app/Modules/Invoice/Data/InvoiceExcellData.php b/app/Modules/Invoice/Data/InvoiceExcellData.php new file mode 100644 index 0000000..f30dcc7 --- /dev/null +++ b/app/Modules/Invoice/Data/InvoiceExcellData.php @@ -0,0 +1,18 @@ +enabled = false; + $this->enabled = false; } /** @@ -35,7 +35,7 @@ class InvoiceModule implements ModuleContract */ public function enable(): void { - $this->enabled = true; + $this->enabled = true; } /** diff --git a/app/Modules/Invoice/Models/Invoice.php b/app/Modules/Invoice/Models/Invoice.php index 4741484..c9f824e 100644 --- a/app/Modules/Invoice/Models/Invoice.php +++ b/app/Modules/Invoice/Models/Invoice.php @@ -2,10 +2,6 @@ namespace App\Modules\Invoice\Models; -use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Model; -class Invoice extends Model -{ - -} +class Invoice extends Model {} diff --git a/app/Modules/Invoice/Repositories/InvoiceRepository.php b/app/Modules/Invoice/Repositories/InvoiceRepository.php index 6d9959a..b2dafa3 100644 --- a/app/Modules/Invoice/Repositories/InvoiceRepository.php +++ b/app/Modules/Invoice/Repositories/InvoiceRepository.php @@ -2,9 +2,4 @@ namespace App\Modules\Invoice\Repositories; -use App\Modules\Invoice\Models\Invoice; - -class InvoiceRepository -{ - -} +class InvoiceRepository {} diff --git a/app/Modules/PHPExcell/PHPExcellModule.php b/app/Modules/PHPExcell/PHPExcellModule.php index 8915b0b..8bf6af8 100644 --- a/app/Modules/PHPExcell/PHPExcellModule.php +++ b/app/Modules/PHPExcell/PHPExcellModule.php @@ -27,7 +27,7 @@ class PHPExcellModule implements ModuleContract */ public function disable(): void { - $this->enabled = false; + $this->enabled = false; } /** @@ -35,7 +35,7 @@ class PHPExcellModule implements ModuleContract */ public function enable(): void { - $this->enabled = true; + $this->enabled = true; } /** diff --git a/public/.DS_Store b/public/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/public/.DS_Store differ diff --git a/public/write.xls b/public/write.xls index 36331f7..cc9cd51 100644 Binary files a/public/write.xls and b/public/write.xls differ diff --git a/routes/web.php b/routes/web.php index eec769a..1559845 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,85 +1,26 @@ getActiveSheet(); - - Carbon::setLocale('tk'); - - // Define vars... - $number = random_int(1, 99); - $date = new Carbon('2024-11-08'); - $year = $date->year; - $day = $date->format('d'); - $month_as_string = $date->translatedFormat('F'); - $seller_firm_type = 'Telekeçi'; - $seller_firm_name = 'Nurmuhammet Allanov Parahatowiç'; - $seller_ssb = '201126532321'; - $seller_bank_name = 'Türkmenistanyň „Halkbank“ paýdarlar täjirçilik banky'; - $seller_bank_number = "23206934160169902250000"; - - // Cell vars... - $hasap_faktura = 'Hasap-faktura № ' . $number; - $sene = sprintf('%s ýylyň «%s» %s', $year, $day, $month_as_string); - $satyjy = sprintf('Satyjy: %s %s', $seller_firm_type, $seller_firm_name); - - $satyjy_salgyt_belgi = new RichText(); - $satyjy_salgyt_belgi - ->createTextRun('Satyjynyň şahsy salgyt belgisi: ') - ->getFont() - ->setName('Times New Roman') - ->setSize(10); - - $satyjy_salgyt_belgi - ->createTextRun($seller_ssb) - ->getFont() - ->setBold(true) - ->setName('Times New Roman') - ->setSize(10); - - $satyjy_bank_maglumatlary = new RichText(); - $satyjy_bank_maglumatlary - ->createTextRun(sprintf('Satyjynyň bankynyň ady %s, hasap № ', $seller_bank_name)) - ->getFont() - ->setName('Times New Roman') - ->setSize(10); - - $satyjy_bank_maglumatlary - ->createTextRun($seller_bank_number) - ->getFont() - ->setBold(true) - ->setName('Times New Roman') - ->setSize(10); - - // Set cell vars... - $worksheet->getCell('C6')->setValue($hasap_faktura); - $worksheet->getCell('C7')->setValue($sene); - $worksheet->getCell('A9')->setValue($satyjy); - $worksheet->getCell('A11')->setValue($satyjy_salgyt_belgi); - $worksheet->getCell('A12')->setValue($satyjy_bank_maglumatlary); - - $worksheet->getCell('A13')->setValue(sprintf('şäherde (etrapda) %s BAB %s bankyň kor.hasap %s', 'Aşgabat', '390101601', '21101934110100700005000')); - - $worksheet->getCell('A16')->setValue(sprintf('Satyn alyjy: %s', 'Türkmenistanyň „Türkmenbaşy“ paýdarlar täjirçilik banky')); - - $worksheet->getCell('A18')->setValue(sprintf('744000 Aşgabat ş., Çandebil şaýoly köç., 121,')); - - $worksheet->getCell('A19')->setValue(sprintf('Alyjynyň bankynyň ady %s %s', 'Türkmenistanyň Merkezi Banky', 'Aşgabat ş.')); - - $worksheet->getCell('A20')->setValue(sprintf('Satyn alyjynyň şahsy salgyt belgisi %s, MFO %s, Hasap № %s', '101301000408', '390101304', '21101934110100300007000')); - - $writer = IOFactory::createWriter($spreadsheet, 'Xls'); - $writer->save('write.xls'); + GenerateInvoiceExcell::make() + ->setTemplateFile(app_path('Modules/Invoice/Resources/Docs/invoice.xls')) + ->setData(new InvoiceExcellData( + number: random_int(1, 99), + date: new Carbon('2024-11-08'), + seller_firm_type: 'Telekeçi', + seller_firm_name: 'Nurmuhammet Allanov Parahatowiç', + seller_ssb: '201126532321', + seller_bank_name: 'Türkmenistanyň „Halkbank“ paýdarlar täjirçilik banky', + seller_bank_number: '23206934160169902250000' + )) + ->handle() + ->save(); return 'F'; });