This commit is contained in:
Jagad R R
2025-03-06 16:24:55 +07:00
parent c3a488b143
commit d2ff42f58b
4 changed files with 53 additions and 29 deletions
@@ -124,8 +124,8 @@
<tfoot>
<tr>
<td colspan="3" class="text-right"><strong>Total</strong></td>
<td>{{ number_format($totalDr, 0, ',', ',') }}</td>
<td>{{ number_format($totalCr, 0, ',', ',') }}</td>
<td>{{ number_format($totalDr, 0, ',', '.') }}</td>
<td>{{ number_format($totalCr, 0, ',', '.') }}</td>
</tr>
</tfoot>
</table>
@@ -151,12 +151,24 @@
text: 'Export Excel',
customize: function (xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
var styles = xlsx.xl['styles.xml'];
var cellXfs = $(styles).find('cellXfs');
// Add a blank row for spacing
var blankRow = `<row><c t="inlineStr"><is><t></t></is></c></row>`;
// Add number format style for thousands separator
var numFmtId = 3; // Built-in ID for thousands separator
var xfCount = cellXfs.children().length;
cellXfs.append(`
<xf numFmtId="${numFmtId}" xfId="0" applyNumberFormat="1">
<alignment horizontal="right"/>
</xf>
`);
var xfIndex = xfCount; // Index of the new style
// Bold text using Excel XML structure
var additionalInfo = `
// Add additional info and blank row
var sheetData = $(sheet).find('sheetData');
var existingRows = sheetData.children();
existingRows.last().after(`
<row><c t="inlineStr"><is><t></t></is></c></row>
<row>
<c t="inlineStr" s="2"><is><t>Cabang: {{ $cabang->name }}</t></is></c>
</row>
@@ -166,29 +178,24 @@
<row>
<c t="inlineStr" s="2"><is><t>Cost Centre: {{ $cabang->cost->code }}</t></is></c>
</row>
`;
// Locate the sheet data and append the blank row and additional information
var sheetData = $(sheet).find('sheetData');
var existingRows = sheetData.children();
existingRows.last().after(blankRow + additionalInfo);
// Add bold style to the sheet
var styles = xlsx.xl['styles.xml'];
var cellXfs = $(styles).find('cellXfs');
cellXfs.append(`
<xf xfId="0" applyFont="1">
<alignment horizontal="left"/>
<font>
<b/>
<sz val="11"/>
<name val="Calibri"/>
<family val="2"/>
</font>
</xf>
`);
}
},
// Update total row with number formatting
var totalRow = sheetData.find("row:last");
var totalDr = {{ $totalDr }};
var totalCr = {{ $totalCr }};
totalRow.find("c:nth-child(4)").attr({
't': 'n', // Set type to number
's': xfIndex // Apply the thousands separator style
}).html('<v>' + totalDr + '</v>');
totalRow.find("c:nth-child(5)").attr({
't': 'n',
's': xfIndex
}).html('<v>' + totalCr + '</v>');
},
},
{
extend: 'csv',
text: 'Export CSV',