account for power_sense and divider

This commit is contained in:
Christoph Beckmann 2025-03-21 20:09:07 +01:00
parent cd23f8ef19
commit c7718b6378

View File

@ -21,7 +21,7 @@ pub struct UserData {
pub struct MachineData { pub struct MachineData {
id: Option<i32>, id: Option<i32>,
to_be_used: bool, to_be_used: bool,
power_sense: bool, power_sense: bool, //1 = runtime, 0 = booked time
divider: i32 divider: i32
} }
@ -84,16 +84,33 @@ pub fn billinglog(machine: &str, booking: &Booking) -> io::Result<()> {
booking.user.to_string() booking.user.to_string()
}; };
let artikel_id = let machine_data = &DATA_MACHINES
if let Some(machine_data) = &DATA_MACHINES.get(&machine.to_string()) { .get(&machine.to_string())
if !machine_data.to_be_used { return Ok(()); } .unwrap_or(&MachineData {
machine_data id: None,
.id to_be_used: true,
.map(|i| i.to_string()) power_sense: true,
.unwrap_or(machine.to_string()) divider: 1
});
if !machine_data.to_be_used { return Ok(()); }
let artikel_id = machine_data
.id
.map(|i| i.to_string())
.unwrap_or(machine.to_string());
let anzahl =
if machine_data.power_sense {
booking.total_runtime()
} else { } else {
machine.to_string() booking.creation_instant.elapsed()
}; }
.as_secs_f32()
.div(60.0)
.div(machine_data.divider as f32)
.ceil()
as _;
let bill = BillingRecord { let bill = BillingRecord {
user_id, user_id,
@ -103,12 +120,7 @@ pub fn billinglog(machine: &str, booking: &Booking) -> io::Result<()> {
positionsdetails: Local::now() positionsdetails: Local::now()
.format("%Y-%m-%d") .format("%Y-%m-%d")
.to_string(), .to_string(),
anzahl: booking anzahl,
.total_runtime()
.as_secs_f32()
.div(60.0)
.ceil()
as _,
rechnungstyp: 0, rechnungstyp: 0,
}; };