added invoice and order collection

This commit is contained in:
2023-01-07 23:14:41 +01:00
parent 58fb02875a
commit 573e17161b
6 changed files with 160 additions and 13 deletions

View File

@@ -8,9 +8,12 @@ import javax.crypto.spec.PBEKeySpec;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
public class AccountMgr {
protected static double price = 5.0;
/**
* creates a user with createUser(...) and adds its id to the 'worker' table
* @param userData String[] name, firstname, password, email
@@ -91,7 +94,6 @@ public class AccountMgr {
return workerId > 0;
}
public static boolean isParent(String id){
String[] parentH = {"userid"};
String[] parentD = {id};
@@ -114,4 +116,30 @@ public class AccountMgr {
}
return hashedPw;
}
public static List<String> getInvoice(String date, String childId){
List<String> invoice = new ArrayList<>();
invoice.add("Monatsabrechnung " + date);
List<String> child = Database.getEntryById("child", Long.parseLong(childId));
String[] childParts = child.get(0).split(":");
invoice.add(childParts[1] + ", " + childParts[2]);
String[] food_planH = {"date"};
String[] food_planD = {date+"%"};
List<String> food_plan = Database.select("food_plan",food_planH,food_planD);
for (String day : food_plan) {
String[] food_planParts = day.split(":");
String[] food_selectionH = {"childid","food_planid"};
String[] food_selectionD = {childId,food_planParts[0]};
List<String> food_selection = Database.select("food_selection",food_selectionH,food_selectionD);
for (String food_select : food_selection) {
String[] food_selectParts = food_select.split(":");
List<String> food = Database.getEntryById("food",Long.parseLong(food_selectParts[3]));
String[] foodParts = food.get(0).split(":");
String line = food_planParts[1] + ": " + foodParts[1];
invoice.add(line);
}
}
invoice.add("Total: " + (invoice.size()-2) + " X " + price + "€ = " + ((invoice.size()-2)*price) + "");
return invoice;
}
}