Skip to content

Commit 2f6bcf0

Browse files
Merge pull request #5 from subhashladumor1/dev
item table html
2 parents 9ec5e73 + aa2c14a commit 2f6bcf0

File tree

7 files changed

+35
-25
lines changed

7 files changed

+35
-25
lines changed

β€Žcomposer.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "πŸ’Ό Laravel InvoiceLite β€” Multi-language, multi-country, professional invoice generator with PDF/Image export, templates, taxes & sharing πŸš€",
44
"type": "library",
55
"license": "MIT",
6-
"version": "1.0.3",
6+
"version": "1.0.4",
77
"keywords": [
88
"laravel invoice",
99
"invoice generator",

β€Žsrc/Services/TemplateManager.phpβ€Ž

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TemplateManager
1313
public function render(string $template, array $data, string $language = 'en'): string
1414
{
1515
// Set the application locale
16-
App::setLocale($language);
16+
app()->setLocale($language);
1717

1818
// Ensure required data is present
1919
$data = array_merge([
@@ -64,6 +64,9 @@ public function render(string $template, array $data, string $language = 'en'):
6464
$data['qr_code'] = ''; // QR code package not available
6565
}
6666

67+
// Generate items table HTML for both View system and fallback
68+
$data['itemsHtml'] = $this->generateItemsHtml($data['items'] ?? []);
69+
6770
// Try to render using Laravel's view system
6871
try {
6972
// Check if custom template exists
@@ -81,6 +84,30 @@ public function render(string $template, array $data, string $language = 'en'):
8184
}
8285
}
8386

87+
/**
88+
* Generate HTML for items table
89+
*/
90+
protected function generateItemsHtml(array $items): string
91+
{
92+
$itemsHtml = '';
93+
if (isset($items) && is_array($items)) {
94+
foreach ($items as $item) {
95+
$itemName = $item['name'] ?? '';
96+
$itemQty = $item['qty'] ?? 0;
97+
$itemPrice = $item['price'] ?? 0;
98+
$itemTotal = (($item['price'] ?? 0) * ($item['qty'] ?? 1));
99+
100+
$itemsHtml .= "<tr>";
101+
$itemsHtml .= "<td>{$itemName}</td>";
102+
$itemsHtml .= "<td>{$itemQty}</td>";
103+
$itemsHtml .= "<td>" . number_format($itemPrice, 2) . "</td>";
104+
$itemsHtml .= "<td>" . number_format($itemTotal, 2) . "</td>";
105+
$itemsHtml .= "</tr>";
106+
}
107+
}
108+
return $itemsHtml;
109+
}
110+
84111
/**
85112
* Fallback rendering method using file content
86113
*/
@@ -122,24 +149,7 @@ protected function renderFromFile(string $template, array $data): string
122149
$content = str_replace('{{ $tax }}', $data['tax'] ?? 0, $content);
123150

124151
// Add items table
125-
$itemsHtml = '';
126-
if (isset($data['items']) && is_array($data['items'])) {
127-
foreach ($data['items'] as $item) {
128-
$itemName = $item['name'] ?? '';
129-
$itemQty = $item['qty'] ?? 0;
130-
$itemPrice = $item['price'] ?? 0;
131-
$itemTotal = (($item['price'] ?? 0) * ($item['qty'] ?? 1));
132-
133-
$itemsHtml .= "<tr>";
134-
$itemsHtml .= "<td>{$itemName}</td>";
135-
$itemsHtml .= "<td>{$itemQty}</td>";
136-
$itemsHtml .= "<td>" . number_format($itemPrice, 2) . "</td>";
137-
$itemsHtml .= "<td>" . number_format($itemTotal, 2) . "</td>";
138-
$itemsHtml .= "</tr>";
139-
}
140-
}
141-
142-
$content = str_replace('@itemsTable', $itemsHtml, $content);
152+
$content = str_replace('@itemsTable', $data['itemsHtml'] ?? '', $content);
143153

144154
// Replace totals with proper formatting
145155
$content = str_replace('{{ $subtotal }}', number_format($data['subtotal'] ?? 0, 2), $content);

β€Žsrc/Templates/business.blade.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
</tr>
285285
</thead>
286286
<tbody>
287-
@itemsTable
287+
{!! $itemsHtml !!}
288288
</tbody>
289289
</table>
290290

β€Žsrc/Templates/classic.blade.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
</tr>
194194
</thead>
195195
<tbody>
196-
@itemsTable
196+
{!! $itemsHtml !!}
197197
</tbody>
198198
</table>
199199

β€Žsrc/Templates/corporate.blade.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@
301301
</tr>
302302
</thead>
303303
<tbody>
304-
@itemsTable
304+
{!! $itemsHtml !!}
305305
</tbody>
306306
</table>
307307

β€Žsrc/Templates/minimal.blade.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
</tr>
211211
</thead>
212212
<tbody>
213-
@itemsTable
213+
{!! $itemsHtml !!}
214214
</tbody>
215215
</table>
216216

β€Žsrc/Templates/modern.blade.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
</tr>
219219
</thead>
220220
<tbody>
221-
@itemsTable
221+
{!! $itemsHtml !!}
222222
</tbody>
223223
</table>
224224

0 commit comments

Comments
Β (0)