calculationlibrary 0.2.1
calculationlibrary: ^0.2.1 copied to clipboard
Financial Calculation Library
example/main.dart
import '../lib/Calculator.dart';
// Exemplo de funcionamento
// argument = {
// method
// params
// }
void main() {
List<String> tests = ["addItem", "getAcc","removeItem","addAccountDiscount","addItemDiscount"];
String aux = "";
String item = "";
String acc = "";
String argument= "";
for(var method in tests){
switch(method){
case "addItem":
item = '{"idItem": "123", "idEntry": "abc","description": "Product A", "quantity": 1, "value":60.0}';
acc = '{"sum": 8.55, "amount": 3, "discount": 0.45, "servicecharge": 0.0, "task": [{"name": "addItem", "aparam": {"idItem": 789, "idEntry": "ghi", "description": "Product C", "quantity": 3, "value": 3.0, "discount": {"type": 1, "value": 5.0}}}], "result": {"idItem": 789, "idEntry": "ghi", "description": "Product C", "quantity": 3, "value": 3.0, "discount": {"type": 1, "value": 5.0}}}';
argument = '{"method": "$method", "item": $item}';
aux = Calculator.run(argument);
argument = '{"method": "$method", "item": $item, "acc": $acc}';
aux = Calculator.run(argument);
break;
case "getAcc":
acc = '{"sum": 8.55, "amount": 3, "discount": 0.45, "servicecharge": 0.0, "task": [{"name": "addItem", "aparam": {"idItem": 789, "idEntry": "ghi", "description": "Product C", "quantity": 3, "value": 3.0, "discount": {"type": 1, "value": 5.0}}}], "result": {"idItem": 789, "idEntry": "ghi", "description": "Product C", "quantity": 3, "value": 3.0, "discount": {"type": 1, "value": 5.0}}}';
argument = '{"method": "$method", "acc": $acc}';
aux = Calculator.run(argument);
break;
case "removeItem":
item = '{"idItem": "789", "idEntry": "ghi","description": "Product C", "quantity": 3, "value":3.0, "discount": {"type": 1, "value": 5.0}}';
acc = '{"sum": 8.55, "amount": 3, "discount": 0.45, "servicecharge": 0.0, "task": [{"name": "addItem", "aparam": {"idItem": 789, "idEntry": "ghi", "description": "Product C", "quantity": 3, "value": 3.0, "discount": {"type": 1, "value": 5.0}}}], "result": {"idItem": 789, "idEntry": "ghi", "description": "Product C", "quantity": 3, "value": 3.0, "discount": {"type": 1, "value": 5.0}}}';
argument = '{"method": "$method", "acc": $acc, "item": $item}';
aux = Calculator.run(argument);
break;
case "addAccountDiscount":
var discount = '{"type": 1, "value": 5.0}';
acc = '{"sum": 8.55, "amount": 3, "discount": 0.45, "servicecharge": 0.0, "task": [{"name": "addItem", "aparam": {"idItem": 789, "idEntry": "ghi", "description": "Product C", "quantity": 3, "value": 3.0, "discount": {"type": 1, "value": 5.0}}}], "result": {"idItem": 789, "idEntry": "ghi", "description": "Product C", "quantity": 3, "value": 3.0, "discount": {"type": 1, "value": 5.0}}}';
argument = '{"method": "$method", "acc": $acc, "discount": $discount}';
aux = Calculator.run(argument);
break;
case "addItemDiscount":
item = '{"idItem": "789", "idEntry": "ghi","description": "Product C", "quantity": 3, "value":3.0, "discount": {"type": 1, "value": 5.0}}';
acc = '{"sum": 8.55, "amount": 3, "discount": 0.45, "servicecharge": 0.0, "task": [{"name": "addItem", "aparam": {"idItem": 789, "idEntry": "ghi", "description": "Product C", "quantity": 3, "value": 3.0, "discount": {"type": 1, "value": 5.0}}}], "result": {"idItem": 789, "idEntry": "ghi", "description": "Product C", "quantity": 3, "value": 3.0, "discount": {"type": 1, "value": 5.0}}}';
var discount = '{"type": 1, "value": 5.0}';
var argument = '{"method": "$method", "acc": $acc, "discount": $discount, "item": $item}';
aux = Calculator.run(argument);
break;
default:
aux = "{'error': 'Método não reconhecido'}";
}
print(aux);
}
}