Implementation
@override
String normativeJsonDanfe(Danfe? danfe, {bool mostrarMoeda = true}) {
String moeda = (mostrarMoeda == true) ? r'R$' : '';
List<Map> danfeJson = [];
danfeJson.add(_prepareLine(aligment: 1, bold: true, fontSize: 18, italic: false, content: danfe?.dados?.emit?.xFant ?? (danfe?.dados?.emit?.xNome ?? '')));
danfeJson.add(_prepareLine(aligment: 1, bold: false, fontSize: 10, italic: false, content: danfe?.dados?.emit?.cnpj ?? ''));
danfeJson.add(_prepareLine(aligment: 1, bold: false, fontSize: 10, italic: false, content: '${danfe?.dados?.emit?.enderEmit?.xLgr ?? ''}, ${danfe?.dados?.emit?.enderEmit?.nro ?? ''}'));
danfeJson.add(_divider());
if ((danfe?.tipo ?? 'CFe') == 'CFe') {
danfeJson.add(_prepareLine(aligment: 1, bold: true, fontSize: 10, italic: false, content: ('Nota Fiscal Eletronica - SAT ')));
} else {
danfeJson.add(_prepareLine(aligment: 1, bold: true, fontSize: 10, italic: false, content: ('Nota Fiscal Eletronica - NFC-E ')));
}
danfeJson.add(_prepareLine(aligment: 0, bold: false, fontSize: 10, italic: false, content: "CPF/CNPJ do consumidor: ${danfe?.dados?.dest?.cpf ?? danfe?.dados?.dest?.cnpj ?? ''}"));
if (danfe?.dados?.dest?.xNome != '' && danfe?.dados?.dest?.xNome != null) {
danfeJson.add(_prepareLine(aligment: 0, bold: false, fontSize: 10, italic: false, content: "Nome: ${danfe?.dados?.dest?.xNome ?? ''}"));
}
danfeJson.add(_prepareLine(aligment: 0, bold: false, fontSize: 10, italic: false, content: ("Nota: ${danfe?.dados?.ide?.nNF ?? ''}")));
danfeJson.add(_prepareLine(aligment: 0, bold: false, fontSize: 10, italic: false, content: ('Data: ${DanfeUtils.formatDate(danfe?.dados?.ide?.dataEmissao ?? '')}')));
danfeJson.add(_divider());
danfeJson.add(_createColumnItems(paperSize: paperSize, det: danfe?.dados?.det));
danfeJson.add(_divider());
danfeJson.add(
_createColumn(
paperSize: paperSize,
rows: [
_createRow(row: {
'text': 'QTD de itens',
'alignment': 0,
}, paperSize: paperSize),
_createRow(
row: {
'text': DanfeUtils.formatNumber(danfe?.dados?.det?.length.toString() ?? ''),
'alignment': 2,
},
paperSize: paperSize,
)
],
),
);
danfeJson.add(
_createColumn(
paperSize: paperSize,
rows: [
_createRow(row: {
'text': 'SUBTOTAL',
'alignment': 0,
}, paperSize: paperSize),
_createRow(
row: {
'text': DanfeUtils.formatMoneyMilhar(danfe?.dados?.total?.valorTotal ?? '', modeda: 'pt_BR', simbolo: moeda),
'alignment': 2,
},
paperSize: paperSize,
)
],
),
);
if ((danfe?.dados?.total?.desconto ?? '0.00') != '0.00') {
danfeJson.add(
_createColumn(
paperSize: paperSize,
rows: [
_createRow(row: {
'text': 'Desconto',
'alignment': 0,
}, paperSize: paperSize),
_createRow(
row: {
'text': DanfeUtils.formatMoneyMilhar(danfe?.dados?.total?.desconto ?? '', modeda: 'pt_BR', simbolo: moeda),
'alignment': 2,
},
paperSize: paperSize,
)
],
),
);
}
if ((danfe?.dados?.total?.acrescimo ?? '0.00') != '0.00') {
danfeJson.add(
_createColumn(
paperSize: paperSize,
rows: [
_createRow(row: {
'text': 'Acréscimo',
'alignment': 0,
}, paperSize: paperSize),
_createRow(
row: {
'text': DanfeUtils.formatMoneyMilhar(danfe?.dados?.total?.acrescimo ?? '', modeda: 'pt_BR', simbolo: moeda),
'alignment': 2,
},
paperSize: paperSize,
)
],
),
);
}
if ((danfe?.dados?.pgto?.vTroco ?? '0.00') != '0.00') {
danfeJson.add(
_createColumn(
paperSize: paperSize,
rows: [
_createRow(row: {
'text': 'Troco',
'alignment': 0,
}, paperSize: paperSize),
_createRow(
row: {
'text': DanfeUtils.formatMoneyMilhar(danfe?.dados?.pgto?.vTroco ?? '', modeda: 'pt_BR', simbolo: moeda),
'alignment': 2,
},
paperSize: paperSize,
)
],
),
);
}
danfeJson.add(
_createColumn(
paperSize: paperSize,
rows: [
_createRow(row: {
'text': 'Total',
'alignment': 0,
}, paperSize: paperSize),
_createRow(
row: {
'text': DanfeUtils.formatMoneyMilhar(danfe?.dados?.total?.valorPago ?? '0.00', modeda: 'pt_BR', simbolo: moeda),
'alignment': 2,
},
paperSize: paperSize,
)
],
),
);
if (danfe?.dados?.pgto != null) {
danfeJson.add(_divider());
danfeJson.add(
_createColumn(
paperSize: paperSize,
rows: [
_createRow(row: {'text': 'Formas de pagamento', 'alignment': 0, 'bold': true}, paperSize: paperSize),
_createRow(
row: {'text': 'Valor pago', 'alignment': 2, 'bold': true},
paperSize: paperSize,
)
],
),
);
for (MP pagamento in danfe!.dados!.pgto!.formas!) {
danfeJson.add(
_createColumn(
paperSize: paperSize,
rows: [
_createRow(row: {
'text': pagamento.cMP ?? '',
'alignment': 0,
}, paperSize: paperSize),
_createRow(
row: {
'text': DanfeUtils.formatMoneyMilhar(pagamento.vMP ?? '', modeda: 'pt_BR', simbolo: moeda),
'alignment': 2,
},
paperSize: paperSize,
)
],
),
);
}
}
danfeJson.add(_divider());
danfeJson.add(_prepareLine(content: 'CHAVE DE ACESSO DA NOTA FISCAL'));
danfeJson.add(
_prepareLine(
fontSize: 10,
bold: true,
content: DanfeUtils.splitByLength(
danfe?.dados?.chaveNota ?? '',
4,
' ',
),
),
);
danfeJson.add(_prepareQrcode(content: danfe?.qrcodePrinter ?? '', size: 120, level: 'L'));
if (danfe?.dados?.ide?.serie != null) {
final serie = (danfe?.dados?.ide?.serie ?? '0').padLeft(3, '0');
final nnf = (danfe?.dados?.ide?.nNF ?? '0').padLeft(9, '0');
danfeJson.add(_prepareLine(content: 'Nota $nnf Serie $serie '));
}
if (danfe?.dados?.ide?.nserieSAT != null) {
final serie = (danfe?.dados?.ide?.nserieSAT ?? '0').padLeft(3, '0');
final nnf = (danfe?.dados?.ide?.nNF ?? '0').padLeft(9, '0');
danfeJson.add(_prepareLine(content: 'Nota $nnf Serie $serie '));
}
if (danfe?.protNFe != null) {
danfeJson.add(_prepareLine(content: 'Protocolo: ${danfe?.protNFe?.infProt?.nProt ?? ''} '));
DateTime dateTime = DateTime.parse(danfe?.protNFe?.infProt?.dhRecbto ?? DateTime.now().toIso8601String());
String formattedDate = "${dateTime.day.toString().padLeft(2, '0')}/${dateTime.month.toString().padLeft(2, '0')}/${dateTime.year} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}:${dateTime.second.toString().padLeft(2, '0')}";
danfeJson.add(_prepareLine(content: 'Data: $formattedDate '));
}
if (danfe?.dados?.infAdic?.infCpl != null) {
danfeJson.add(_prepareLine(content: danfe!.dados!.infAdic!.infCpl ?? '', fontSize: 10));
}
return json.encode(danfeJson);
}