invoice items so far getting better

This commit is contained in:
2024-11-10 15:32:54 +05:00
parent c1af5e1b39
commit 607a916cff
7 changed files with 115 additions and 10 deletions

View File

@@ -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++;
});
}
/**