複数行グリッド:振替伝票

このサンプルは、MultiRowコントロールで作成された振替伝票を示しています。

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('給料手当,旅費交通費,接待交際費,消耗品費,支払手数料'.split(',')), debtorTypeDataMap = buildDataMap('(指定なし),現金,当座預金'.split(',')), creditorAccDataMap = buildDataMap('普通預金,売上高,現金'.split(',')), creditorTypeDataMap = buildDataMap('雇用保険,住民税,社会保険'.split(',')); return [ { cells: [ { binding: 'debtorAcc', width: 125, header: '借方勘定', dataMap: debtorAccDataMap, align: 'center' }, { binding: 'debtorType', width: 125, header: '借方補助', dataMap: debtorTypeDataMap, align: 'center' } ] }, { cells: [ { binding: 'debtorAmt', width: 125, format: 'c', header: '借方金額', align: 'center' }, { binding: 'debtorTax', width: 125, format: 'c', header: '借方消費税', align: 'center', isReadOnly: true } ] }, { cells: [ { binding: 'creditorAcc', width: 125, header: '貸方勘定', dataMap: creditorAccDataMap, align: 'center' }, { binding: 'creditorType', width: 125, header: '貸方補助', dataMap: creditorTypeDataMap, align: 'center' } ] }, { cells: [ { binding: 'creditorAmt', width: 125, format: 'c', header: '貸方金額', align: 'center' }, { binding: 'creditorTax', width: 125, format: 'c', header: '貸方消費税', align: 'center', isReadOnly: true } ] }, { cells: [ { binding: 'brief', width: 150, header: '摘要', align: 'center' }, { binding: 'note', width: 150, header: '付箋', align: 'center' } ] }, { cells: [ { binding: 'debtorTaxCategrory', width: 150, header: '借方税区分', align: 'center' }, { binding: 'creditorTaxCategory', width: 150, header: '貸方税区分', 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 = '日付'; workbookCell.style = workbookStyle; workbookRow.cells.push(workbookCell); workbookCell = new wjXlsx.WorkbookCell(); workbookCell.value = data.date; let dateCellStyle = new wjXlsx.WorkbookStyle(); dateCellStyle.format = 'd'; workbookCell.style = dateCellStyle; workbookRow.cells.push(workbookCell); workbookCell = new wjXlsx.WorkbookCell(); workbookCell.value = '伝票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 = '決算'; 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 = '貸方合計'; 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 = '借方合計'; 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 = '賃借バランス'; 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: { font: { family: 'ipaexg' }, backgroundColor: '#ffffff', borderColor: '#c6c6c6' }, altCellStyle: { backgroundColor: '#f9f9f9' }, headerCellStyle: { backgroundColor: '#eaeaea' } } }, font, drawTextSetting, thinPen = new wjPdf.PdfPen('#000000', 0.5); doc.registerFont({ source: 'https://demo.mescius.jp/wijmo/sample/fonts/ipaexg.ttf', name: 'ipaexg' }); doc.setFont(new wjPdf.PdfFont('ipaexg')); // 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('日付', 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('伝票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('決算', 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, doc.width, 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('貸方合計', 3.5, 279.5, drawTextSetting); doc.drawText(debtorSum, 63.5, 279.5, drawTextSetting); doc.drawText('借方合計', 123.5, 279.5, drawTextSetting); doc.drawText(creditorSum, 183.5, 279.5, drawTextSetting); doc.drawText('賃借バランス', 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">日付</div> <div class="col-md-2"> <div id="inputDate"></div> </div> <div class="col-md-2 grid-title">伝票No</div> <div class="col-md-2"> <input id="slipNo" type="text" class="form-control" /> </div> <div class="col-md-2 grid-title">決算</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">貸方合計</div> <div style="width:125px;" class="summary-cell"><span id="debtorSum"></span></div> <div style="width:125px;" class="summary-cell">借方合計</div> <div style="width:125px;" class="summary-cell"><span id="creditorSum"></span></div> <div style="width:110px;" class="summary-cell">賃借バランス</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"> Excelにエクスポート </button> <button class="btn btn-default" id="exportPdf"> PDFにエクスポート </button> </div> </div> </body> </html>
export function generateSlipData(count) { let slipData = {}, items = []; for (let i = 0; i < count; i++) { let debtorAcc = 0; let debtorType = Math.floor(3 * Math.random()); let debtorAmt = Math.round(10000 * Math.random()); let creditorAcc = 0; let creditorType = Math.floor(3 * 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: `${i % 12 + 1}月支給分`, note: '', debtorTaxCategrory: '対象外', creditorTaxCategory: '' }); } slipData.items = items; slipData.date = new Date(); slipData.slipNo = '128'; slipData.settlement = '通常'; 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);