Skip to content

Instantly share code, notes, and snippets.

@ANNASBlackHat
Created January 29, 2024 08:41
Show Gist options
  • Save ANNASBlackHat/f090c555b616e01c94c926d205646fc9 to your computer and use it in GitHub Desktop.
Save ANNASBlackHat/f090c555b616e01c94c926d205646fc9 to your computer and use it in GitHub Desktop.
Generate Payment Options

Generate Payment Options

Created with <3 with dartpad.dev.

List<int> generatePaymentOptions(int grandTotal, bool isPiutang) {
final options = <int>[];
options.add(grandTotal);
//for piutang, the options would be less than grand total
if (isPiutang) {
[0.75, 0.50, 0.25].forEach((divider) {
final option = (grandTotal * divider).round();
if (option <= 0) {
return;
}
if (option % 10000 > 0) {
final newOption = option - option %10000 +
(option % 10000 < 5000 ? 5000 : 10000);
if (!options.contains(newOption)) {
options.add(newOption);
}
}
options.add(option);
});
} else {
if (grandTotal % 10000 > 5000) {
options.add(grandTotal - grandTotal % 10000 + 10000);
} else if (grandTotal % 5000 < 5000) {
options.add(grandTotal - grandTotal % 5000 + 5000);
}
[10000, 20000, 50000, 100000].forEach((amt) {
if (amt > options.last % 100000) {
options.add(amt + options.last - options.last % 100000);
}
});
}
return options;
}
void main() {
final grandTotal = 43000;
print('Grand Total ${grandTotal}, payment options:');
print(generatePaymentOptions(grandTotal, false));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment