Skip to content

Instantly share code, notes, and snippets.

@ANNASBlackHat
Created January 29, 2024 08:49
Show Gist options
  • Save ANNASBlackHat/66fd1a4fc06ce3606dccb1d0264769bf to your computer and use it in GitHub Desktop.
Save ANNASBlackHat/66fd1a4fc06ce3606dccb1d0264769bf to your computer and use it in GitHub Desktop.
Generate Display Nota

Generate Display Nota

Created with <3 with dartpad.dev.

import 'dart:math';
String generateDisplayNota(int? adminId, int? outletId, int salesCount) {
var nota = StringBuffer();
try {
var id = (outletId ?? 0) + (adminId ?? 1);
var words = [
"A",
"P",
"L",
"I",
"K",
"U",
"N",
"Q",
"D",
"E"
];
id.toString().split("").forEach((element) {
if (isNumeric(element)) {
nota.write(words[int.parse(element)]);
}
});
var now = DateTime.now();
nota.write(now.year);
nota.write(now.month.toString().padLeft(2, '0'));
nota.write(now.day.toString().padLeft(2, '0'));
nota.write(salesCount + 1);
} catch (e) {
print('Generate Display Nota error: $e');
}
return nota.toString();
}
bool isNumeric(String str) {
if(int.tryParse(str) != null || double.tryParse(str) != null) {
return true;
}
return false;
}
void main() {
print('Display Nota: ${generateDisplayNota(1, 10, 45)}');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment