振替伝票

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

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjCore from '@grapecity/wijmo'; import * as wjInput from '@grapecity/wijmo.input'; import * as wjGrid from '@grapecity/wijmo.grid'; import * as wjFilter from '@grapecity/wijmo.grid.filter'; import * as wjMultiRow from '@grapecity/wijmo.grid.multirow'; import * as wjGridXlsx from '@grapecity/wijmo.grid.xlsx'; import * as wjXlsx from '@grapecity/wijmo.xlsx'; import * as wjGridPdf from '@grapecity/wijmo.grid.pdf'; import * as wjPdf from '@grapecity/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.grapecity.com/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>GrapeCity Wijmo MultiRow Transfer Slip</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></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-xs-2 grid-title">日付</div> <div class="col-xs-2"> <div id="inputDate"></div> </div> <div class="col-xs-2 grid-title">伝票No</div> <div class="col-xs-2"> <input id="slipNo" type="text" class="form-control" /> </div> <div class="col-xs-2 grid-title">決算</div> <div class="col-xs-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; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wjCore from '@grapecity/wijmo'; import * as wjInput from '@grapecity/wijmo.input'; import * as wjGrid from '@grapecity/wijmo.grid'; import * as wjFilter from '@grapecity/wijmo.grid.filter'; import * as wjPdf from '@grapecity/wijmo.pdf'; import * as wjMultirow from '@grapecity/wijmo.grid.multirow'; import * as wjGridXlsx from '@grapecity/wijmo.grid.xlsx'; import * as wjXlsx from '@grapecity/wijmo.xlsx'; import * as wjGridPdf from '@grapecity/wijmo.grid.pdf'; import { Component, Inject, enableProdMode, NgModule, ViewChild, AfterViewInit } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjGridMultirowModule } from '@grapecity/wijmo.angular2.grid.multirow'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; import { DataService, SlipData, Line } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent implements AfterViewInit { @ViewChild('transferSlip') transferSlip: wjMultirow.MultiRow; data: SlipData; items: wjCore.CollectionView; layoutDefinition: Line[]; cv: wjCore.CollectionView; debtorSum: string; creditorSum: string; balance: string; minDate:Date; maxDate:Date; // currentDescription: string; slipNo: string; settlement: string; // DataSvc will be passed by derived classes constructor(@Inject(DataService) private dataService: DataService) { this.data = this.dataService.generateSlipData(50); this.items = new wjCore.CollectionView(this.data.items); this.layoutDefinition = dataService.generateLayoutDef(); this.minDate = new Date(this.data.date.getFullYear(), 0, 1); this.maxDate = new Date(this.data.date.getFullYear(), 11, 31); } // ngAfterViewInit() { this.items.pageSize = 5; this.slipNo = this.data.slipNo; this.settlement = this.data.settlement; let filter = new wjFilter.FlexGridFilter(this.transferSlip); this.transferSlip.rowHeaders.columns.clear(); this.cv = <wjCore.CollectionView>this.transferSlip.collectionView; this._currentPageChanged(); this._updateSummary(); this.transferSlip.cellEditEnded.addHandler(() => { this._updateSummary(); }); this.cv.pageChanged.addHandler(() => { this._updateSummary(); this._currentPageChanged(); }); this.cv.collectionChanged.addHandler((sender: any, e: wjCore.NotifyCollectionChangedEventArgs) => { let debtorAmt: number, creditorAmt: number; 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; } } }); } // onGotoPageClick(command: string) { let cv = this.cv; if (command === 'first') { cv.moveToFirstPage(); } else if (command === 'previous') { cv.moveToPreviousPage(); } else if (command === 'next') { cv.moveToNextPage(); } else if (command === 'last') { cv.moveToLastPage(); } } // onExportXlsxClick() { let workbook = wjGridXlsx.FlexGridXlsxConverter.save(this.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 = this.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 = this.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 = this.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 = this.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 = this.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 = this.balance; workbookCell.style = workbookStyle; workbookRow.cells.push(workbookCell); workbook.sheets[0].rows.push(workbookRow); workbook.saveAsync('TransferSlip.xlsx'); } // onExportPdfClick() { let doc = new wjPdf.PdfDocument({ header: { declarative: { text: '\t&[Page] / &[Pages]' } }, footer: { declarative: { text: '\t&[Page] / &[Pages]' } }, ended: function (sender: wjPdf.PdfDocument, args: wjPdf.PdfDocumentEndedEventArgs) { 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.grapecity.com/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(this.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(this.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(this.data.settlement, 283.5, 5.5, drawTextSetting); doc.moveDown(); // Draw the body of the transfer slip. wjGridPdf.FlexGridPdfConverter.draw(this.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('貸方合計', 3.5, 279.5, drawTextSetting); doc.drawText(this.debtorSum, 63.5, 279.5, drawTextSetting); doc.drawText('借方合計', 123.5, 279.5, drawTextSetting); doc.drawText(this.creditorSum, 183.5, 279.5, drawTextSetting); doc.drawText('賃借バランス', 243.5, 279.5, drawTextSetting); doc.drawText(this.balance, 323.5, 279.5, drawTextSetting); doc.end(); } // private _updateSummary() { let debtor = wjCore.getAggregate(wjCore.Aggregate.Sum, this.cv.items, 'debtorAmt'), creditor = wjCore.getAggregate(wjCore.Aggregate.Sum, this.cv.items, 'creditorAmt'); this.debtorSum = wjCore.Globalize.format(debtor, 'c'); this.creditorSum = wjCore.Globalize.format(creditor, 'c'); this.balance = wjCore.Globalize.format(debtor - creditor, 'c'); } // private _currentPageChanged() { let curr = wjCore.format('{current:n0} / {count:n0}', { current: this.cv.pageIndex + 1, count: this.cv.pageCount }); this.currentDescription = curr; if (this.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 (this.cv.pageIndex === this.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'); } } } //\\ @NgModule({ imports: [WjGridMultirowModule, WjInputModule, BrowserModule], declarations: [AppComponent], providers: [DataService], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo MultiRow Transfer Slip</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <div class="row show-grid"> <div class="col-xs-2 grid-title">日付</div> <div class="col-xs-2"> <wj-input-date [format]="'d'" [value]="data.date" [min]="minDate" [max]="maxDate"></wj-input-date> </div> <div class="col-xs-2 grid-title">伝票No </div> <div class="col-xs-2"> <input (value)="slipNo" type="text" class="form-control" /> </div> <div class="col-xs-2 grid-title">決算</div> <div class="col-xs-2"> <input (value)="settlement" type="text" class="form-control" /> </div> </div> <wj-multi-row #transferSlip [itemsSource]="items" [layoutDefinition]="layoutDefinition"></wj-multi-row> <div class="row show-grid"> <div style="width:125px;" class="summary-cell">貸方合計</div> <div style="width:125px;" class="summary-cell"><span [innerHTML]="debtorSum"></span></div> <div style="width:125px;" class="summary-cell">借方合計</div> <div style="width:125px;" class="summary-cell"><span [innerHTML]="creditorSum"></span></div> <div style="width:110px;" class="summary-cell">賃借バランス</div> <div style="width:100px;" class="summary-cell"><span [innerHTML]="balance"></span></div> </div> <div class="pull-right btn-group"> <button class="btn btn-default" (click)="onGotoPageClick('first')" id="first"> <span class="glyphicon glyphicon-fast-backward"></span> </button> <button class="btn btn-default" (click)="onGotoPageClick('previous')" id="previous"> <span class="glyphicon glyphicon-backward"></span> </button> <button id="current" type="button" class="btn" disabled style="width:100px" [innerHTML]="currentDescription"> </button> <button class="btn btn-default" (click)="onGotoPageClick('next')" id="next"> <span class="glyphicon glyphicon-forward"></span> </button> <button class="btn btn-default" (click)="onGotoPageClick('last')" id="last"> <span class="glyphicon glyphicon-fast-forward"></span> </button> </div> <div class="btn-group"> <button class="btn btn-default" (click)="onExportXlsxClick()"> Excelにエクスポート </button> <button class="btn btn-default" (click)="onExportPdfClick()"> PDFにエクスポート </button> </div> </div> import { Injectable } from '@angular/core'; import * as wjGrid from '@grapecity/wijmo.grid'; export interface SlipData { items: SlipDataItem[]; date: Date; slipNo: string; settlement: string; } export interface SlipDataItem { debtorAcc: number; debtorType: number; debtorAmt: number; debtorTax: number; creditorAcc: number; creditorType: number; creditorAmt: number; creditorTax: number; brief: string; note: string; debtorTaxCategrory: string; creditorTaxCategory: string; } export interface Cell { binding: string; header: string; cssClass?: string; format?: string; isReadOnly?: boolean; wordWrap?: boolean; width?: number; colspan?: number; align?: string; dataMap?: wjGrid.DataMap; } export interface Line { cells: Cell[]; } @Injectable() export class DataService { generateSlipData(count: number): SlipData { let slipData: any = {}, 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; } generateLayoutDef(): Line[] { 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: string[]) { let map = []; for (let i = 0; i < items.length; i++) { map.push({ key: i, value: items[i] }); } return new wjGrid.DataMap(map, 'key', 'value'); } .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; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wjGrid from '@grapecity/wijmo.react.grid.multirow'; import * as wjInput from '@grapecity/wijmo.react.input'; import * as wjCore from '@grapecity/wijmo'; import * as wjFilter from '@grapecity/wijmo.grid.filter'; import * as wjPdf from '@grapecity/wijmo.pdf'; import * as wjGridXlsx from '@grapecity/wijmo.grid.xlsx'; import * as wjXlsx from '@grapecity/wijmo.xlsx'; import * as wjGridPdf from '@grapecity/wijmo.grid.pdf'; import { generateSlipData, generateLayoutDef } from './data'; class App extends React.Component { constructor(props) { super(props); this.initSlip = (slip) => { this.setState({ transferSlip: slip, cv: slip.collectionView }, () => { let filter = new wjFilter.FlexGridFilter(this.state.transferSlip); this.state.transferSlip.rowHeaders.columns.clear(); this.setState({ cv: this.state.transferSlip.collectionView }); this._currentPageChanged(); this._updateSummary(); let cv = this.state.cv, transferSlip = this.state.transferSlip; transferSlip.cellEditEnded.addHandler(() => { this._updateSummary(); }); cv.pageChanged.addHandler(() => { this._updateSummary(); this._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; } } }); this.setState({ cv: cv, transferSlip: transferSlip }); }); }; this.onGotoPageClick = (command) => { let cv = this.state.cv; if (command === 'first') { cv.moveToFirstPage(); } else if (command === 'previous') { cv.moveToPreviousPage(); } else if (command === 'next') { cv.moveToNextPage(); } else if (command === 'last') { cv.moveToLastPage(); } }; this.onExportXlsxClick = () => { let workbook = wjGridXlsx.FlexGridXlsxConverter.save(this.state.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 = this.state.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 = this.state.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 = this.state.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 = this.state.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 = this.state.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 = this.state.balance; workbookCell.style = workbookStyle; workbookRow.cells.push(workbookCell); workbook.sheets[0].rows.push(workbookRow); workbook.saveAsync('TransferSlip.xlsx'); }; this.onExportPdfClick = () => { 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.grapecity.com/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(this.state.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(this.state.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(this.state.data.settlement, 283.5, 5.5, drawTextSetting); doc.moveDown(); // Draw the body of the transfer slip. wjGridPdf.FlexGridPdfConverter.draw(this.state.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('貸方合計', 3.5, 279.5, drawTextSetting); doc.drawText(this.state.debtorSum, 63.5, 279.5, drawTextSetting); doc.drawText('借方合計', 123.5, 279.5, drawTextSetting); doc.drawText(this.state.creditorSum, 183.5, 279.5, drawTextSetting); doc.drawText('賃借バランス', 243.5, 279.5, drawTextSetting); doc.drawText(this.state.balance, 323.5, 279.5, drawTextSetting); doc.end(); }; this._updateSummary = () => { let debtor = wjCore.getAggregate(wjCore.Aggregate.Sum, this.state.cv.items, 'debtorAmt'), creditor = wjCore.getAggregate(wjCore.Aggregate.Sum, this.state.cv.items, 'creditorAmt'); this.setState({ debtorSum: wjCore.Globalize.format(debtor, 'c'), creditorSum: wjCore.Globalize.format(creditor, 'c'), balance: wjCore.Globalize.format(debtor - creditor, 'c') }); }; this._currentPageChanged = () => { let curr = wjCore.format('{current:n0} / {count:n0}', { current: this.state.cv.pageIndex + 1, count: this.state.cv.pageCount }); this.setState({ currentDescription: curr }); if (this.state.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 (this.state.cv.pageIndex === this.state.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'); } }; let data = generateSlipData(50); this.state = { data: data, items: new wjCore.CollectionView(data.items), layoutDefinition: generateLayoutDef(), minDate: new Date(data.date.getFullYear(), 0, 1), maxDate: new Date(data.date.getFullYear(), 11, 31), transferSlip: { rowHeaders: {} }, cv: {}, slipNo: '', settlement: '', debtorSum: '', creditorSum: '', balance: '', currentDescription: '' }; } render() { return <div className="container-fluid"> <div className="row show-grid"> <div className="col-xs-2 grid-title">日付</div> <div className="col-xs-2"> <wjInput.InputDate format="d" value={this.state.data.date} min={this.state.minDate} max={this.state.maxDate}> </wjInput.InputDate> </div> <div className="col-xs-2 grid-title">伝票No </div> <div className="col-xs-2"> <input value={this.state.slipNo} type="text" className="form-control"/> </div> <div className="col-xs-2 grid-title">決算</div> <div className="col-xs-2"> <input value={this.state.settlement} type="text" className="form-control"/> </div> </div> <wjGrid.MultiRow itemsSource={this.state.items} layoutDefinition={this.state.layoutDefinition} initialized={this.initSlip}></wjGrid.MultiRow> <div className="row show-grid"> <div style={{ width: "125px" }} className="summary-cell">貸方合計</div> <div style={{ width: "125px" }} className="summary-cell"> <span dangerouslySetInnerHTML={{ __html: this.state.debtorSum }}></span> </div> <div style={{ width: "125px" }} className="summary-cell">借方合計</div> <div style={{ width: "125px" }} className="summary-cell"> <span dangerouslySetInnerHTML={{ __html: this.state.creditorSum }}></span> </div> <div style={{ width: "110px" }} className="summary-cell">賃借バランス</div> <div style={{ width: "100px" }} className="summary-cell"> <span dangerouslySetInnerHTML={{ __html: this.state.balance }}></span> </div> </div> <div className="pull-right btn-group"> <button className="btn btn-default" onClick={e => this.onGotoPageClick('first')} id="first"> <span className="glyphicon glyphicon-fast-backward"></span> </button> <button className="btn btn-default" onClick={e => this.onGotoPageClick('previous')} id="previous"> <span className="glyphicon glyphicon-backward"></span> </button> <button id="current" type="button" className="btn" disabled style={{ width: "100px" }} dangerouslySetInnerHTML={{ __html: this.state.currentDescription }}> </button> <button className="btn btn-default" onClick={e => this.onGotoPageClick('next')} id="next"> <span className="glyphicon glyphicon-forward"></span> </button> <button className="btn btn-default" onClick={e => this.onGotoPageClick('last')} id="last"> <span className="glyphicon glyphicon-fast-forward"></span> </button> </div> <div className="btn-group"> <button className="btn btn-default" onClick={this.onExportXlsxClick}> Excelにエクスポート </button> <button className="btn btn-default" onClick={this.onExportPdfClick}> PDFにエクスポート </button> </div> </div>; } componentDidMount() { let items = this.state.items; items.pageSize = 5; this.setState({ items: items, slipNo: this.state.data.slipNo, settlement: this.state.data.settlement }); } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/jszip/dist/jszip.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .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; } import * as wjGrid from '@grapecity/wijmo.grid'; 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: `${i % 12 + 1}月支給分`, note: '', debtorTaxCategrory: '対象外', creditorTaxCategory: '' }); } slipData.items = items; slipData.date = new Date(); slipData.slipNo = '128'; slipData.settlement = '通常'; return slipData; } export 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'); } <template> <div class="container-fluid"> <div class="row show-grid"> <div class="col-xs-2 grid-title">日付</div> <div class="col-xs-2"> <wj-input-date :format="'d'" :value="data.date" :min="minDate" :max="maxDate"></wj-input-date> </div> <div class="col-xs-2 grid-title">伝票No </div> <div class="col-xs-2"> <input :value="slipNo" type="text" class="form-control" /> </div> <div class="col-xs-2 grid-title">決算</div> <div class="col-xs-2"> <input :value="settlement" type="text" class="form-control" /> </div> </div> <wj-multi-row :initialized="initSlip" :itemsSource="items" :layoutDefinition="layoutDefinition"></wj-multi-row> <div class="row show-grid"> <div style="width:125px;" class="summary-cell">貸方合計</div> <div style="width:125px;" class="summary-cell"><span v-html="debtorSum"></span></div> <div style="width:125px;" class="summary-cell">借方合計</div> <div style="width:125px;" class="summary-cell"><span v-html="creditorSum"></span></div> <div style="width:110px;" class="summary-cell">賃借バランス</div> <div style="width:100px;" class="summary-cell"><span v-html="balance"></span></div> </div> <div class="pull-right btn-group"> <button class="btn btn-default" @click="onGotoPageClick('first')" id="first"> <span class="glyphicon glyphicon-fast-backward"></span> </button> <button class="btn btn-default" @click="onGotoPageClick('previous')" id="previous"> <span class="glyphicon glyphicon-backward"></span> </button> <button id="current" type="button" class="btn" disabled style="width:100px" v-html="currentDescription"> </button> <button class="btn btn-default" @click="onGotoPageClick('next')" id="next"> <span class="glyphicon glyphicon-forward"></span> </button> <button class="btn btn-default" @click="onGotoPageClick('last')" id="last"> <span class="glyphicon glyphicon-fast-forward"></span> </button> </div> <div class="btn-group"> <button class="btn btn-default" @click="onExportXlsxClick"> Excelにエクスポート </button> <button class="btn btn-default" @click="onExportPdfClick"> PDFにエクスポート </button> </div> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import 'bootstrap.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.core'; import '@grapecity/wijmo.vue2.input'; import '@grapecity/wijmo.vue2.grid.multirow'; import * as wjCore from '@grapecity/wijmo'; import * as wjFilter from '@grapecity/wijmo.grid.filter'; import * as wjPdf from '@grapecity/wijmo.pdf'; import * as wjGridXlsx from '@grapecity/wijmo.grid.xlsx'; import * as wjXlsx from '@grapecity/wijmo.xlsx'; import * as wjGridPdf from '@grapecity/wijmo.grid.pdf'; import { generateSlipData, generateLayoutDef } from './data'; let App = Vue.extend({ name: 'app', data: function(){ let data = generateSlipData(50); return { data: data, items: new wjCore.CollectionView(data.items), layoutDefinition: generateLayoutDef(), minDate: new Date(data.date.getFullYear(), 0, 1), maxDate: new Date(data.date.getFullYear(), 11, 31), transferSlip: null, cv: null, slipNo: '', settlement: '', debtorSum: '', creditorSum: '', balance: '', currentDescription : '' } }, methods: { initSlip: function(slip){ this.transferSlip = slip; }, onGotoPageClick: function(command) { let cv = this.cv; if (command === 'first') { cv.moveToFirstPage(); } else if (command === 'previous') { cv.moveToPreviousPage(); } else if (command === 'next') { cv.moveToNextPage(); } else if (command === 'last') { cv.moveToLastPage(); } }, onExportXlsxClick: function() { let workbook = wjGridXlsx.FlexGridXlsxConverter.save(this.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 = this.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 = this.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 = this.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 = this.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 = this.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 = this.balance; workbookCell.style = workbookStyle; workbookRow.cells.push(workbookCell); workbook.sheets[0].rows.push(workbookRow); workbook.saveAsync('TransferSlip.xlsx'); }, onExportPdfClick: function() { 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.grapecity.com/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(this.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(this.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(this.data.settlement, 283.5, 5.5, drawTextSetting); doc.moveDown(); // Draw the body of the transfer slip. wjGridPdf.FlexGridPdfConverter.draw(this.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('貸方合計', 3.5, 279.5, drawTextSetting); doc.drawText(this.debtorSum, 63.5, 279.5, drawTextSetting); doc.drawText('借方合計', 123.5, 279.5, drawTextSetting); doc.drawText(this.creditorSum, 183.5, 279.5, drawTextSetting); doc.drawText('賃借バランス', 243.5, 279.5, drawTextSetting); doc.drawText(this.balance, 323.5, 279.5, drawTextSetting); doc.end(); }, _updateSummary: function() { let debtor = wjCore.getAggregate(wjCore.Aggregate.Sum, this.cv.items, 'debtorAmt'), creditor = wjCore.getAggregate(wjCore.Aggregate.Sum, this.cv.items, 'creditorAmt'); this.debtorSum = wjCore.Globalize.format(debtor, 'c'); this.creditorSum = wjCore.Globalize.format(creditor, 'c'); this.balance = wjCore.Globalize.format(debtor - creditor, 'c'); }, _currentPageChanged: function() { let curr = wjCore.format('{current:n0} / {count:n0}', { current: this.cv.pageIndex + 1, count: this.cv.pageCount }); this.currentDescription = curr; if (this.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 (this.cv.pageIndex === this.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'); } } }, mounted: function(){ this.items.pageSize = 5; this.slipNo = this.data.slipNo; this.settlement = this.data.settlement; // console.log(this.transferSlip); let filter = new wjFilter.FlexGridFilter(this.transferSlip); this.transferSlip.rowHeaders.columns.clear(); this.cv = this.transferSlip.collectionView; this._currentPageChanged(); this._updateSummary(); this.transferSlip.cellEditEnded.addHandler(() => { this._updateSummary(); }); this.cv.pageChanged.addHandler(() => { this._updateSummary(); this._currentPageChanged(); }); this.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; } } }); } }); new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> .container-fluid .wj-multirow { max-height: 400px; margin: 6px 0; } .container-fluid .show-grid { margin-left: 6px; margin-top: 5px; margin-bottom: 5px; border-radius: 4px; } .container-fluid .show-grid [class^=col-] { padding-top: 5px; padding-bottom: 5px; border-style: solid solid solid none; border-width: 1px; border-color: #000000; height: 44px; } .container-fluid .show-grid > .grid-title { background-color: #8080ff; font-size: 18px; font-weight: bold; } .container-fluid .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; } .container-fluid .show-grid > div:first-child { border-left-style: solid; border-radius: 4px 0px 0px 4px; } .container-fluid .show-grid > div:last-child { border-radius: 0px 4px 4px 0px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/jszip/dist/jszip.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"> </div> </body> </html> import * as wjGrid from '@grapecity/wijmo.grid'; 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; } export 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'); }