diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index eb51776..914663d 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -33,16 +33,49 @@ class HomeController extends Controller items: [ new InvoiceItem( - name: 'Programma üpjünçiligini işläp taýýarlamak barada', + name: 'Programma üpjünçiligini hyzmat etmek barada', unit: 'ay', - quantity: 1, - unit_price: 25000, + quantity: 2, + unit_price: 100000, vat: null, - excludingVat: null, + vat_excluded: null, vat_percentage: null, vat_tmt: null, - total: 25000, + total: 200000, ), + new InvoiceItem( + name: 'Programma üpjünçiligini hyzmat etmek barada', + unit: 'ay', + quantity: 2, + unit_price: 100000, + vat: null, + vat_excluded: null, + vat_percentage: null, + vat_tmt: null, + total: 200000, + ), + new InvoiceItem( + name: 'Programma üpjünçiligini hyzmat etmek barada', + unit: 'ay', + quantity: 2, + unit_price: 100000, + vat: null, + vat_excluded: null, + vat_percentage: null, + vat_tmt: null, + total: 200000, + ), + new InvoiceItem( + name: 'Programma üpjünçiligini işäň taýýarlamak barada', + unit: 'ay', + quantity: 2, + unit_price: 100000, + vat: null, + vat_excluded: null, + vat_percentage: null, + vat_tmt: null, + total: 200000, + ) ] )) ->handle() diff --git a/app/Modules/Invoice/.DS_Store b/app/Modules/Invoice/.DS_Store index 352e2a8..3f56ecd 100644 Binary files a/app/Modules/Invoice/.DS_Store and b/app/Modules/Invoice/.DS_Store differ diff --git a/app/Modules/Invoice/Actions/GenerateInvoiceExcell.php b/app/Modules/Invoice/Actions/GenerateInvoiceExcell.php index 259a616..cb05627 100644 --- a/app/Modules/Invoice/Actions/GenerateInvoiceExcell.php +++ b/app/Modules/Invoice/Actions/GenerateInvoiceExcell.php @@ -3,11 +3,14 @@ namespace App\Modules\Invoice\Actions; use App\Modules\Invoice\Data\InvoiceExcellData; +use App\Modules\Invoice\Data\InvoiceItem; use App\Modules\Makeable; use Illuminate\Support\Carbon; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Font; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; @@ -120,6 +123,72 @@ class GenerateInvoiceExcell foreach ($data as $cell => $value) { $this->worksheet->getCell($cell)->setValue($value); } + + $items = collect($this->data->items); + + $itemCellNumber = 25; + $numberFormat = $this->worksheet->getStyle('E' . 25)->getNumberFormat()->getFormatCode(); + $items->each(function (InvoiceItem $item, int $index) use (&$itemCellNumber, $numberFormat) { + $this->worksheet->getCell('A' . $itemCellNumber)->setValue($index + 1); + $this->worksheet->getCell('B' . $itemCellNumber)->setValue($item->name); + $this->worksheet->getCell('C' . $itemCellNumber)->setValue($item->unit); + $this->worksheet->getCell('D' . $itemCellNumber)->setValue($item->quantity); + $this->worksheet->getCell('E' . $itemCellNumber)->setValue($item->unit_price); + $this->worksheet->getCell('F' . $itemCellNumber)->setValue($item->vat); + $this->worksheet->getCell('G' . $itemCellNumber)->setValue($item->vat_excluded); + $this->worksheet->getCell('H' . $itemCellNumber)->setValue($item->vat_percentage); + $this->worksheet->getCell('I' . $itemCellNumber)->setValue($item->vat_tmt); + $this->worksheet->getCell('J' . $itemCellNumber)->setValue($item->total); + + // Set font-family, alingment, and borders for all of them... + $this->worksheet->getStyle('A' . $itemCellNumber . ':J' . $itemCellNumber)->applyFromArray([ + 'font' => [ + 'bold' => false, + 'size' => 10, + 'name' => 'Times New Roman' + ], + 'alignment' => [ + 'horizontal' => Alignment::HORIZONTAL_CENTER, + 'vertical' => Alignment::VERTICAL_CENTER, + ], + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => Border::BORDER_THIN, + ], + ], + ]); + + // Invoice Name... + $this->worksheet->getCell('B' . $itemCellNumber)->getStyle()->applyFromArray([ + 'alignment' => [ + 'horizontal' => Alignment::HORIZONTAL_LEFT, + 'vertical' => Alignment::VERTICAL_CENTER, + ] + ]); + + $this->worksheet->getCell('D' . $itemCellNumber)->getStyle()->applyFromArray([ + 'font' => [ + 'bold' => true, + ], + ]); + + $this->worksheet->getCell('E' . $itemCellNumber)->getStyle()->applyFromArray([ + 'font' => [ + 'bold' => true, + ], + ]); + $this->worksheet->getCell('J' . $itemCellNumber)->getStyle()->applyFromArray([ + 'font' => [ + 'bold' => true, + ], + ]); + + // Invoice number format... + $this->worksheet->getStyle('E' . $itemCellNumber)->getNumberFormat()->setFormatCode($numberFormat); + $this->worksheet->getStyle('J' . $itemCellNumber)->getNumberFormat()->setFormatCode($numberFormat); + + $itemCellNumber++; + }); } /** diff --git a/app/Modules/Invoice/Data/InvoiceItem.php b/app/Modules/Invoice/Data/InvoiceItem.php index 22037c8..1a629a6 100644 --- a/app/Modules/Invoice/Data/InvoiceItem.php +++ b/app/Modules/Invoice/Data/InvoiceItem.php @@ -9,12 +9,15 @@ class InvoiceItem public int|string $unit, public int $quantity, public int|float $unit_price, - public null|int|float $vat, - public null|int|float $excludingVat, - public null|int|float $vat_percentage, - public null|int|float $vat_tmt, + public null|int|float|string $vat, + public null|int|float|string $vat_excluded, + public null|int|float|string $vat_percentage, + public null|int|float|string $vat_tmt, public int|float|string $total, ) { - // ... + $this->vat = $vat ?: 'x'; + $this->vat_excluded = $vat_excluded ?: 'x'; + $this->vat_percentage = $vat_percentage ?: 'x'; + $this->vat_tmt = $vat_tmt ?: 'x'; } } diff --git a/app/Modules/Invoice/Resources/Docs/invoice-original.xls b/app/Modules/Invoice/Resources/Docs/invoice-original.xls new file mode 100755 index 0000000..139ae31 Binary files /dev/null and b/app/Modules/Invoice/Resources/Docs/invoice-original.xls differ diff --git a/app/Modules/Invoice/Resources/Docs/invoice.xls b/app/Modules/Invoice/Resources/Docs/invoice.xls index b0de7a5..793ae7e 100755 Binary files a/app/Modules/Invoice/Resources/Docs/invoice.xls and b/app/Modules/Invoice/Resources/Docs/invoice.xls differ diff --git a/public/write.xls b/public/write.xls index e9899d0..217308c 100644 Binary files a/public/write.xls and b/public/write.xls differ