printTable method
dynamic
printTable(
- dynamic param,
- dynamic context
Implementation
printTable(param, context) async {
dynamic param0 = param[0];
dynamic tableid = param0[gTableID] ?? '';
if (isNull(tableid)) {
return;
}
//List rows = getTableData(tableid, context);
dynamic tableInfo = _tableList[tableid];
var where = tableInfo[gWhere] ?? '';
List rows = getTableDataFromWhere(tableid, where, context, false, -1);
if (rows.isEmpty) {
return;
}
List colList = tableInfo![gColumns];
List cols = [];
List widthList = [];
List alignList = [];
for (int i = 0; i < colList.length; i++) {
if (isHiddenColumn(colList, i)) {
continue;
}
dynamic col = colList[i];
if (!isNull(col[gShowrange]) && col[gShowrange] != gTable) {
continue;
}
dynamic colID = col[gId];
dynamic colLabel = getSCurrent(col[gLabel]);
Map mapCol = {gId: colID, gLabel: colLabel, gCol: col};
cols.add(mapCol);
int align = 0;
/*if (col[gType] == gMoney) {
align = 2;
}*/
double charLength = getCharLength(colLabel.toString());
widthList.add(charLength);
alignList.add(align);
//widths[colID] = getCharLength(colLabel.toString());
//aligns[colID] = align;
}
for (int i = 0; i < rows.length; i++) {
dynamic row = rows[i];
for (int j = 0; j < cols.length; j++) {
dynamic acol = cols[j];
var showTxt = getValueGUI(row[acol[gId]] ?? '', acol[gCol]);
dynamic length = getCharLength(showTxt.toString());
if (length > widthList[j]) {
widthList[j] = length;
}
}
}
List list = [];
for (int i = 0; i < widthList.length; i++) {
widthList[i] = getInt(widthList[i]);
}
{
// header
List headers = [];
for (int i = 0; i < cols.length; i++) {
headers.add((cols[i][gLabel] ?? '').toString());
}
list.add({
'msg': {
'str': headers,
'widths': widthList,
'aligns': alignList,
gType: 'big'
},
'type': 'cols'
});
list.add({'msg': '', 'type': 'line'});
for (int i = 0; i < rows.length; i++) {
dynamic row = rows[i];
dynamic strs = [];
for (int j = 0; j < cols.length; j++) {
dynamic acol = cols[j];
var showTxt = getValueGUI(row[acol[gId]] ?? '', acol[gCol]);
strs.add(showTxt ?? '');
}
list.add({
'msg': {'str': strs, 'widths': widthList, 'aligns': alignList},
'type': 'cols'
});
}
list.add({'msg': '', 'type': 'line'});
}
//add subtype
List sumList = getTableHeaderValueBasic(tableid, context);
if (!isNull(sumList)) {
for (int i = 0; i < sumList.length; i++) {
dynamic si = sumList[i];
dynamic sLabel = getSCurrent(si[gCol][gLabel]);
list.add({'msg': '$sLabel: ${si[gValue]}', 'type': 'big'});
}
}
await _methodChannel.invokeMethod<String>('internalRequest', list);
/*printReceiptTransaction([
{gData: dataRow, gIsselected: true}
], context);*/
}