Last active
November 3, 2021 22:28
-
-
Save stavxyz/a7af71d175b5aba797c8b8466e7c6a49 to your computer and use it in GitHub Desktop.
calculate session price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math' as math; | |
import 'dart:developer' as developer; | |
void main() { | |
var sessionPrice = "125.00"; | |
print(calculateSessionPriceTotal(sessionPrice)); | |
} | |
////////////////////////////////////////////////////////////////// | |
// N.B. For FlutterFlow, you only need to copy from here down | |
// You must also include all "import" statements from the top | |
////////////////////////////////////////////////////////////////// | |
String calculateSessionPriceTotal(String subTotalString) { | |
const double taxRate = 8.75; | |
const double feeRate = 2.59; | |
const double feeRatePerTransaction = 0.49; | |
void log(String message) { | |
var timestamp = new DateTime.now(); | |
var now = timestamp.toUtc().toIso8601String(); | |
// developer.log("$message\n", time: timestamp); | |
print("$now | $message\n"); | |
} | |
// convert input (string) to math double | |
double subTotal = double.parse(subTotalString); | |
// given a subtotal, calculate taxes and fees for session | |
log("computing total session price where subTotal = \$$subTotal"); | |
log("using taxRate = $taxRate% and feeRate = $feeRate% and feeRatePerTransaction = $feeRatePerTransaction"); | |
var taxes = subTotal * (taxRate * .01); | |
log("taxes computed; taxes = \$$taxes"); | |
var taxedTotal = subTotal + taxes; | |
log("total with taxes; taxedTotal = \$$taxedTotal"); | |
var fees = (taxedTotal * (feeRate * .01)) + feeRatePerTransaction; | |
log("fees computed; fees = \$$fees"); | |
var grandTotal = subTotal + taxes + fees; | |
log("grand total; grandTotal = \$$grandTotal"); | |
// convert back to string and round to 2 decimal places | |
return grandTotal.toStringAsFixed(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment