206 lines
5.2 KiB
PHP
206 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Invoice\Actions;
|
|
|
|
use App\Modules\Invoice\Data\InvoiceExcellData;
|
|
use App\Modules\Makeable;
|
|
use Illuminate\Support\Carbon;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\RichText\RichText;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
|
|
class GenerateInvoiceExcell
|
|
{
|
|
use Makeable;
|
|
|
|
/** Template file */
|
|
protected string $templateFile;
|
|
|
|
/** Excell Spreadsheet */
|
|
protected Spreadsheet $spreadsheet;
|
|
|
|
/** Active worksheet */
|
|
protected Worksheet $worksheet;
|
|
|
|
/** Invoice data */
|
|
protected InvoiceExcellData $data;
|
|
|
|
/**
|
|
* Let's generate an invoice excell file...
|
|
*/
|
|
public function __construct()
|
|
{
|
|
// For turkmen date format...
|
|
Carbon::setLocale('tk');
|
|
}
|
|
|
|
/**
|
|
* Run conversion process
|
|
*/
|
|
public function handle(): self
|
|
{
|
|
$this->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;
|
|
}
|
|
}
|