import 'bootstrap.css';
import '@mescius/wijmo.styles/wijmo.css';
import './styles.css';
import * as wjCore from '@mescius/wijmo';
import * as wjInput from '@mescius/wijmo.input';
import * as wjGrid from '@mescius/wijmo.grid';
import * as wjFilter from '@mescius/wijmo.grid.filter';
import * as wjMultiRow from '@mescius/wijmo.grid.multirow';
import * as wjGridXlsx from '@mescius/wijmo.grid.xlsx';
import * as wjXlsx from '@mescius/wijmo.xlsx';
import * as wjGridPdf from '@mescius/wijmo.grid.pdf';
import * as wjPdf from '@mescius/wijmo.pdf';
import { generateSlipData } from './data';
//
document.readyState === 'complete' ? init() : window.onload = init;
//
function init() {
let data = generateSlipData(50);
let debtorSum;
let creditorSum;
let balance;
let items = new wjCore.CollectionView(data.items);
items.pageSize = 5;
document.querySelector('#slipNo').value = data.slipNo;
document.querySelector('#settlement').value = data.settlement;
let inputDate = new wjInput.InputDate('#inputDate');
inputDate.format = 'd';
inputDate.value = data.date;
inputDate.min = new Date(data.date.getFullYear(), 0, 1);
inputDate.max = new Date(data.date.getFullYear(), 11, 31);
let transferSlip = new wjMultiRow.MultiRow('#transferSlip', {
itemsSource: items,
layoutDefinition: generateLayoutDef()
});
let filter = new wjFilter.FlexGridFilter(transferSlip);
transferSlip.rowHeaders.columns.clear();
let cv = transferSlip.collectionView;
currentPageChanged();
updateSummary(cv);
transferSlip.cellEditEnded.addHandler(() => {
updateSummary(cv);
});
cv.pageChanged.addHandler(() => {
updateSummary(cv);
currentPageChanged();
});
cv.collectionChanged.addHandler((sender, e) => {
let debtorAmt, creditorAmt;
if (e.action === wjCore.NotifyCollectionChangedAction.Change && !!e.item) {
debtorAmt = +e.item.debtorAmt;
creditorAmt = +e.item.creditorAmt;
if (!isNaN(debtorAmt)) {
e.item.debtorTax = e.item.debtorAmt * 0.09;
}
if (!isNaN(creditorAmt)) {
e.item.creditorTax = e.item.creditorAmt * 0.09;
}
}
});
document.querySelector('#first').addEventListener('click', () => {
cv.moveToFirstPage();
});
document.querySelector('#previous').addEventListener('click', () => {
cv.moveToPreviousPage();
});
document.querySelector('#next').addEventListener('click', () => {
cv.moveToNextPage();
});
document.querySelector('#last').addEventListener('click', () => {
cv.moveToLastPage();
});
// Generate the layout definition for the MultiRow control.
function generateLayoutDef() {
let debtorAccDataMap = buildDataMap('Saralies,Transport,Entertainment,Supplies,Fees'.split(',')), debtorTypeDataMap = buildDataMap(['(none)']), creditorAccDataMap = buildDataMap('Ordinary deposit,Deposits payable,Advance money,Accounts payable'.split(',')), creditorTypeDataMap = buildDataMap('Grape bank,Orange bank,Apple bank,Grape card'.split(','));
return [
{
cells: [
{ binding: 'debtorAcc', width: 125, header: 'Debtor Account', dataMap: debtorAccDataMap, align: 'center' },
{ binding: 'debtorType', width: 125, header: 'Debtor Type', dataMap: debtorTypeDataMap, align: 'center' }
]
},
{
cells: [
{ binding: 'debtorAmt', width: 125, format: 'c2', header: 'Debtor Amount', align: 'center' },
{ binding: 'debtorTax', width: 125, format: 'c2', header: 'Debtor Tax', align: 'center', isReadOnly: true }
]
},
{
cells: [
{ binding: 'creditorAcc', width: 125, header: 'Creditor Account', dataMap: creditorAccDataMap, align: 'center' },
{ binding: 'creditorType', width: 125, header: 'Creditor Type', dataMap: creditorTypeDataMap, align: 'center' }
]
},
{
cells: [
{ binding: 'creditorAmt', width: 125, format: 'c2', header: 'Creditor Amount', align: 'center' },
{ binding: 'creditorTax', width: 125, format: 'c2', header: 'Creditor Tax', align: 'center', isReadOnly: true }
]
},
{
cells: [
{ binding: 'brief', width: 210, header: 'Brief', align: 'center' },
{ binding: 'note', width: 210, header: 'Note', align: 'center' }
]
},
{
cells: [
{ binding: 'debtorTaxCategrory', width: 230, header: 'Debtor Tax Category', align: 'center' },
{ binding: 'creditorTaxCategory', width: 230, header: 'Creditor Tax Categoty', align: 'center' }
]
}
];
}
function buildDataMap(items) {
let map = [];
for (let i = 0; i < items.length; i++) {
map.push({ key: i, value: items[i] });
}
return new wjGrid.DataMap(map, 'key', 'value');
}
// Update summary info for the footer of the multirow control.
function updateSummary(cv) {
let debtor = wjCore.getAggregate(wjCore.Aggregate.Sum, cv.items, 'debtorAmt'), creditor = wjCore.getAggregate(wjCore.Aggregate.Sum, cv.items, 'creditorAmt');
debtorSum = wjCore.Globalize.format(debtor, 'c');
creditorSum = wjCore.Globalize.format(creditor, 'c');
balance = wjCore.Globalize.format(debtor - creditor, 'c');
document.querySelector('#debtorSum').innerHTML = debtorSum;
document.querySelector('#creditorSum').innerHTML = creditorSum;
document.querySelector('#balance').innerHTML = balance;
}
function currentPageChanged() {
let cv = transferSlip.collectionView, curr = wjCore.format('{current:n0} / {count:n0}', {
current: cv.pageIndex + 1,
count: cv.pageCount
});
document.querySelector('#current').innerHTML = curr;
if (cv.pageIndex === 0) {
document.querySelector('#first').setAttribute('disabled', 'true');
document.querySelector('#previous').setAttribute('disabled', 'true');
}
else {
document.querySelector('#first').removeAttribute('disabled');
document.querySelector('#previous').removeAttribute('disabled');
}
if (cv.pageIndex === cv.pageCount - 1) {
document.querySelector('#last').setAttribute('disabled', 'true');
document.querySelector('#next').setAttribute('disabled', 'true');
}
else {
document.querySelector('#last').removeAttribute('disabled');
document.querySelector('#next').removeAttribute('disabled');
}
}
document.querySelector('#exportXlsx').addEventListener('click', () => {
exportToExcel();
});
document.querySelector('#exportPdf').addEventListener('click', () => {
exportToPDF();
});
// Export the records of current page to xlsx file.
function exportToExcel() {
let workbook = wjGridXlsx.FlexGridXlsxConverter.save(transferSlip);
let workbookRow = new wjXlsx.WorkbookRow();
let workbookFill = new wjXlsx.WorkbookFill();
workbookFill.color = '#8080FF';
let workbookFont = new wjXlsx.WorkbookFont();
workbookFont.bold = true;
let workbookStyle = new wjXlsx.WorkbookStyle();
workbookStyle.fill = workbookFill;
workbookStyle.font = workbookFont;
workbookStyle.hAlign = wjXlsx.HAlign.Center;
let workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = 'Date';
workbookCell.style = workbookStyle;
workbookRow.cells.push(workbookCell);
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = data.date;
let dateCellStyle = new wjXlsx.WorkbookStyle();
dateCellStyle.format = 'MM/dd/yyyy';
workbookCell.style = dateCellStyle;
workbookRow.cells.push(workbookCell);
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = 'Slip No';
workbookCell.style = workbookStyle;
workbookRow.cells.push(workbookCell);
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = data.slipNo;
workbookRow.cells.push(workbookCell);
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = 'Settlement';
workbookCell.style = workbookStyle;
workbookRow.cells.push(workbookCell);
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = data.settlement;
workbookRow.cells.push(workbookCell);
workbook.sheets[0].rows.splice(0, 0, workbookRow);
workbook.sheets[0].frozenPane.rows = 3;
workbookRow = new wjXlsx.WorkbookRow();
workbookFill = new wjXlsx.WorkbookFill();
workbookFill.color = '#99B4D1';
workbookStyle = new wjXlsx.WorkbookStyle();
workbookStyle.fill = workbookFill;
workbookStyle.hAlign = wjXlsx.HAlign.Center;
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = 'Debtor Sum';
workbookCell.style = workbookStyle;
workbookRow.cells.push(workbookCell);
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = debtorSum;
workbookCell.style = workbookStyle;
workbookRow.cells.push(workbookCell);
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = 'Creditor Sum';
workbookCell.style = workbookStyle;
workbookRow.cells.push(workbookCell);
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = creditorSum;
workbookCell.style = workbookStyle;
workbookRow.cells.push(workbookCell);
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = 'Balance';
workbookCell.style = workbookStyle;
workbookRow.cells.push(workbookCell);
workbookCell = new wjXlsx.WorkbookCell();
workbookCell.value = balance;
workbookCell.style = workbookStyle;
workbookRow.cells.push(workbookCell);
workbook.sheets[0].rows.push(workbookRow);
workbook.saveAsync('TransferSlip.xlsx');
}
// Save the records of current page to PDF file.
function exportToPDF() {
let doc = new wjPdf.PdfDocument({
header: {
declarative: {
text: '\t&[Page]\\&[Pages]'
}
},
footer: {
declarative: {
text: '\t&[Page]\\&[Pages]'
}
},
ended: function (sender, args) {
wjPdf.saveBlob(args.blob, 'TransferSlip.pdf');
}
}), settings = {
styles: {
cellStyle: {
backgroundColor: '#ffffff',
borderColor: '#c6c6c6'
},
altCellStyle: {
backgroundColor: '#f9f9f9'
},
headerCellStyle: {
backgroundColor: '#eaeaea'
}
}
}, font, drawTextSetting, thinPen = new wjPdf.PdfPen('#000000', 0.5);
// Draw header of the transfer slip.
doc.paths
.rect(0.5, 0.5, 50, 21)
.fill('#8080FF')
.moveTo(0, 0).lineTo(334, 0)
.moveTo(334, 0).lineTo(334, 22)
.moveTo(0, 22).lineTo(334, 22)
.moveTo(0, 0).lineTo(0, 22).stroke(thinPen);
doc.drawText('Date', 3.5, 5.5, drawTextSetting);
doc.drawText(wjCore.Globalize.format(data.date, 'd'), 53.5, 5.5, drawTextSetting);
doc.paths
.rect(130.5, 0.5, 50, 21)
.fill('#8080FF');
doc.drawText('Slip No', 133.5, 5.5, drawTextSetting);
doc.drawText(data.slipNo, 183.5, 5.5, drawTextSetting);
doc.paths
.rect(230.5, 0.5, 50, 21)
.fill('#8080FF');
doc.drawText('Settlement', 233.5, 5.5, drawTextSetting);
doc.drawText(data.settlement, 283.5, 5.5, drawTextSetting);
doc.moveDown();
// Draw the body of the transfer slip.
wjGridPdf.FlexGridPdfConverter.draw(transferSlip, doc, null, null, settings);
// Draw the footer of the transfer slip.
doc.paths
.rect(0.5, 274.5, 380, 21)
.fill('#99B4D1')
.moveTo(0, 274).lineTo(381, 274)
.moveTo(381, 274).lineTo(381, 296)
.moveTo(0, 296).lineTo(381, 296)
.moveTo(0, 274).lineTo(0, 296)
.moveTo(60, 274).lineTo(60, 296)
.moveTo(120, 274).lineTo(120, 296)
.moveTo(180, 274).lineTo(180, 296)
.moveTo(240, 274).lineTo(240, 296)
.moveTo(320, 274).lineTo(320, 296).stroke(thinPen);
doc.drawText('Debtor Sum', 3.5, 279.5, drawTextSetting);
doc.drawText(debtorSum, 63.5, 279.5, drawTextSetting);
doc.drawText('Creditor Sum', 123.5, 279.5, drawTextSetting);
doc.drawText(creditorSum, 183.5, 279.5, drawTextSetting);
doc.drawText('Balance', 243.5, 279.5, drawTextSetting);
doc.drawText(balance, 323.5, 279.5, drawTextSetting);
doc.end();
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MESCIUS Wijmo MultiRow Transfer Slip</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- SystemJS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.21.5/system.src.js" integrity="sha512-skZbMyvYdNoZfLmiGn5ii6KmklM82rYX2uWctBhzaXPxJgiv4XBwJnFGr5k8s+6tE1pcR1nuTKghozJHyzMcoA==" crossorigin="anonymous"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('./src/app');
</script>
</head>
<body>
<div class="container-fluid">
<div class="row show-grid">
<div class="col-md-1 grid-title">Date</div>
<div class="col-md-2">
<div id="inputDate"></div>
</div>
<div class="col-md-2 grid-title">Slip No</div>
<div class="col-md-2">
<input id="slipNo" type="text" class="form-control" />
</div>
<div class="col-md-2 grid-title">Settlement</div>
<div class="col-md-2">
<input id="settlement" type="text" class="form-control" />
</div>
</div>
<div id="transferSlip"></div>
<div class="row show-grid">
<div style="width:125px;" class="summary-cell">Debtor Sum</div>
<div style="width:125px;" class="summary-cell"><span id="debtorSum"></span></div>
<div style="width:125px;" class="summary-cell">Creditor Sum</div>
<div style="width:125px;" class="summary-cell"><span id="creditorSum"></span></div>
<div style="width:110px;" class="summary-cell">Balance</div>
<div style="width:100px;" class="summary-cell"><span id="balance"></span></div>
</div>
<div class="pull-right btn-group">
<button class="btn btn-default" id="first">
<span class="glyphicon glyphicon-fast-backward"></span>
</button>
<button class="btn btn-default" id="previous">
<span class="glyphicon glyphicon-backward"></span>
</button>
<button id="current" type="button" class="btn" disabled style="width:100px">
</button>
<button class="btn btn-default" id="next">
<span class="glyphicon glyphicon-forward"></span>
</button>
<button class="btn btn-default" id="last">
<span class="glyphicon glyphicon-fast-forward"></span>
</button>
</div>
<div class="btn-group">
<button class="btn btn-default" id="exportXlsx">
Export to Excel
</button>
<button class="btn btn-default" id="exportPdf">
Export to PDF
</button>
</div>
</div>
</body>
</html>
export function generateSlipData(count) {
let slipData = {}, items = [];
for (let i = 0; i < count; i++) {
let debtorAcc = Math.floor(5 * Math.random());
let debtorType = 0;
let debtorAmt = Math.round(10000 * Math.random());
let creditorAcc = Math.floor(4 * Math.random());
let creditorType = Math.floor(4 * Math.random());
let creditorAmt = Math.round(10000 * Math.random());
items.push({
debtorAcc: debtorAcc,
debtorType: debtorType,
debtorAmt: debtorAmt,
debtorTax: debtorAmt * 0.09,
creditorAcc: creditorAcc,
creditorType: creditorType,
creditorAmt: creditorAmt,
creditorTax: creditorAmt * 0.09,
brief: '',
note: '',
debtorTaxCategrory: '',
creditorTaxCategory: ''
});
}
slipData.items = items;
slipData.date = new Date();
slipData.slipNo = 's128';
slipData.settlement = 'Normal';
return slipData;
}
.wj-multirow {
max-height: 400px;
margin: 6px 0;
}
.show-grid {
margin-left: 6px;
margin-top: 5px;
margin-bottom: 5px;
border-radius: 4px;
}
.show-grid [class^=col-] {
padding-top: 5px;
padding-bottom: 5px;
border-style: solid solid solid none;
border-width: 1px;
border-color: #000000;
height: 44px;
}
.show-grid > .grid-title {
background-color: #8080ff;
font-size: 18px;
font-weight: bold;
}
.show-grid > .summary-cell {
padding: 5px;
border-style: solid solid solid none;
border-width: 1px;
border-color: #000000;
background-color: #99B4D1;
font-weight: bold;
text-align: center;
float: left;
}
.show-grid > div:first-child {
border-left-style: solid;
border-radius: 4px 0px 0px 4px;
}
.show-grid > div:last-child {
border-radius: 0px 4px 4px 0px;
}
(function (global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'jszip': 'npm:jszip/dist/jszip.js',
'@mescius/wijmo': 'npm:@mescius/wijmo/index.js',
'@mescius/wijmo.input': 'npm:@mescius/wijmo.input/index.js',
'@mescius/wijmo.styles': 'npm:@mescius/wijmo.styles',
'@mescius/wijmo.cultures': 'npm:@mescius/wijmo.cultures',
'@mescius/wijmo.chart': 'npm:@mescius/wijmo.chart/index.js',
'@mescius/wijmo.chart.analytics': 'npm:@mescius/wijmo.chart.analytics/index.js',
'@mescius/wijmo.chart.animation': 'npm:@mescius/wijmo.chart.animation/index.js',
'@mescius/wijmo.chart.annotation': 'npm:@mescius/wijmo.chart.annotation/index.js',
'@mescius/wijmo.chart.finance': 'npm:@mescius/wijmo.chart.finance/index.js',
'@mescius/wijmo.chart.finance.analytics': 'npm:@mescius/wijmo.chart.finance.analytics/index.js',
'@mescius/wijmo.chart.hierarchical': 'npm:@mescius/wijmo.chart.hierarchical/index.js',
'@mescius/wijmo.chart.interaction': 'npm:@mescius/wijmo.chart.interaction/index.js',
'@mescius/wijmo.chart.radar': 'npm:@mescius/wijmo.chart.radar/index.js',
'@mescius/wijmo.chart.render': 'npm:@mescius/wijmo.chart.render/index.js',
'@mescius/wijmo.chart.webgl': 'npm:@mescius/wijmo.chart.webgl/index.js',
'@mescius/wijmo.chart.map': 'npm:@mescius/wijmo.chart.map/index.js',
'@mescius/wijmo.gauge': 'npm:@mescius/wijmo.gauge/index.js',
'@mescius/wijmo.grid': 'npm:@mescius/wijmo.grid/index.js',
'@mescius/wijmo.grid.detail': 'npm:@mescius/wijmo.grid.detail/index.js',
'@mescius/wijmo.grid.filter': 'npm:@mescius/wijmo.grid.filter/index.js',
'@mescius/wijmo.grid.search': 'npm:@mescius/wijmo.grid.search/index.js',
'@mescius/wijmo.grid.grouppanel': 'npm:@mescius/wijmo.grid.grouppanel/index.js',
'@mescius/wijmo.grid.multirow': 'npm:@mescius/wijmo.grid.multirow/index.js',
'@mescius/wijmo.grid.transposed': 'npm:@mescius/wijmo.grid.transposed/index.js',
'@mescius/wijmo.grid.transposedmultirow': 'npm:@mescius/wijmo.grid.transposedmultirow/index.js',
'@mescius/wijmo.grid.pdf': 'npm:@mescius/wijmo.grid.pdf/index.js',
'@mescius/wijmo.grid.sheet': 'npm:@mescius/wijmo.grid.sheet/index.js',
'@mescius/wijmo.grid.xlsx': 'npm:@mescius/wijmo.grid.xlsx/index.js',
'@mescius/wijmo.grid.selector': 'npm:@mescius/wijmo.grid.selector/index.js',
'@mescius/wijmo.grid.cellmaker': 'npm:@mescius/wijmo.grid.cellmaker/index.js',
'@mescius/wijmo.nav': 'npm:@mescius/wijmo.nav/index.js',
'@mescius/wijmo.odata': 'npm:@mescius/wijmo.odata/index.js',
'@mescius/wijmo.olap': 'npm:@mescius/wijmo.olap/index.js',
'@mescius/wijmo.rest': 'npm:@mescius/wijmo.rest/index.js',
'@mescius/wijmo.pdf': 'npm:@mescius/wijmo.pdf/index.js',
'@mescius/wijmo.pdf.security': 'npm:@mescius/wijmo.pdf.security/index.js',
'@mescius/wijmo.viewer': 'npm:@mescius/wijmo.viewer/index.js',
'@mescius/wijmo.xlsx': 'npm:@mescius/wijmo.xlsx/index.js',
'@mescius/wijmo.undo': 'npm:@mescius/wijmo.undo/index.js',
'@mescius/wijmo.interop.grid': 'npm:@mescius/wijmo.interop.grid/index.js',
'@mescius/wijmo.touch': 'npm:@mescius/wijmo.touch/index.js',
'@mescius/wijmo.cloud': 'npm:@mescius/wijmo.cloud/index.js',
'@mescius/wijmo.barcode': 'npm:@mescius/wijmo.barcode/index.js',
'@mescius/wijmo.barcode.common': 'npm:@mescius/wijmo.barcode.common/index.js',
'@mescius/wijmo.barcode.composite': 'npm:@mescius/wijmo.barcode.composite/index.js',
'@mescius/wijmo.barcode.specialized': 'npm:@mescius/wijmo.barcode.specialized/index.js',
'jszip': 'npm:jszip/dist/jszip.js',
'bootstrap.css': 'npm:bootstrap/dist/css/bootstrap.min.css',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);