Fix total amount of extra hours in report

This commit is contained in:
Simon Goller 2024-06-26 20:44:20 +02:00
parent 56fe23f8bc
commit 036551ba39
3 changed files with 9 additions and 7 deletions

View file

@ -32,7 +32,6 @@ pub trait ExtraHoursDao {
&self,
sales_person_id: Uuid,
year: u32,
until_week: u8,
) -> Result<Arc<[ExtraHoursEntity]>, crate::DaoError>;
async fn create(&self, entity: &ExtraHoursEntity, process: &str)
-> Result<(), crate::DaoError>;

View file

@ -73,15 +73,13 @@ impl ExtraHoursDao for ExtraHoursDaoImpl {
&self,
sales_person_id: Uuid,
year: u32,
until_week: u8,
) -> Result<Arc<[ExtraHoursEntity]>, crate::DaoError> {
let id_vec = sales_person_id.as_bytes().to_vec();
Ok(query_as!(
ExtraHoursDb,
"SELECT id, sales_person_id, amount, category, description, date_time, created, deleted, update_version FROM extra_hours WHERE sales_person_id = ? AND CAST(strftime('%Y', date_time) AS INTEGER) = ? AND CAST(strftime('%m', date_time) AS INTEGER) <= ?",
"SELECT id, sales_person_id, amount, category, description, date_time, created, deleted, update_version FROM extra_hours WHERE sales_person_id = ? AND CAST(strftime('%Y', date_time) AS INTEGER) = ?",
id_vec,
year,
until_week,
).fetch_all(self.pool.as_ref())
.await
.map_db_error()?

View file

@ -178,9 +178,10 @@ where
.sum();
let extra_hours = self
.extra_hours_dao
.find_by_sales_person_id_and_year(paid_employee.id, year, until_week)
.find_by_sales_person_id_and_year(paid_employee.id, year)
.await?
.iter()
.filter(|eh| eh.date_time.iso_week() <= until_week)
.map(|eh| eh.amount)
.sum::<f32>();
let balance_hours = shiftplan_hours + extra_hours - planned_hours;
@ -221,7 +222,7 @@ where
.await?;
let extra_hours = self
.extra_hours_dao
.find_by_sales_person_id_and_year(*sales_person_id, year, until_week)
.find_by_sales_person_id_and_year(*sales_person_id, year)
.await?;
let planned_hours: f32 = (1..=until_week)
@ -232,7 +233,11 @@ where
})
.sum();
let shiftplan_hours = shiftplan_report.iter().map(|r| r.hours).sum::<f32>() as f32;
let overall_extra_hours = extra_hours.iter().map(|eh| eh.amount).sum::<f32>();
let overall_extra_hours = extra_hours
.iter()
.filter(|eh| eh.date_time.iso_week() <= until_week)
.map(|eh| eh.amount)
.sum::<f32>();
let employee_report = EmployeeReport {
sales_person: Arc::new(sales_person),