Fix total amount of extra hours in report
This commit is contained in:
parent
56fe23f8bc
commit
036551ba39
3 changed files with 9 additions and 7 deletions
|
|
@ -32,7 +32,6 @@ pub trait ExtraHoursDao {
|
||||||
&self,
|
&self,
|
||||||
sales_person_id: Uuid,
|
sales_person_id: Uuid,
|
||||||
year: u32,
|
year: u32,
|
||||||
until_week: u8,
|
|
||||||
) -> Result<Arc<[ExtraHoursEntity]>, crate::DaoError>;
|
) -> Result<Arc<[ExtraHoursEntity]>, crate::DaoError>;
|
||||||
async fn create(&self, entity: &ExtraHoursEntity, process: &str)
|
async fn create(&self, entity: &ExtraHoursEntity, process: &str)
|
||||||
-> Result<(), crate::DaoError>;
|
-> Result<(), crate::DaoError>;
|
||||||
|
|
|
||||||
|
|
@ -73,15 +73,13 @@ impl ExtraHoursDao for ExtraHoursDaoImpl {
|
||||||
&self,
|
&self,
|
||||||
sales_person_id: Uuid,
|
sales_person_id: Uuid,
|
||||||
year: u32,
|
year: u32,
|
||||||
until_week: u8,
|
|
||||||
) -> Result<Arc<[ExtraHoursEntity]>, crate::DaoError> {
|
) -> Result<Arc<[ExtraHoursEntity]>, crate::DaoError> {
|
||||||
let id_vec = sales_person_id.as_bytes().to_vec();
|
let id_vec = sales_person_id.as_bytes().to_vec();
|
||||||
Ok(query_as!(
|
Ok(query_as!(
|
||||||
ExtraHoursDb,
|
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,
|
id_vec,
|
||||||
year,
|
year,
|
||||||
until_week,
|
|
||||||
).fetch_all(self.pool.as_ref())
|
).fetch_all(self.pool.as_ref())
|
||||||
.await
|
.await
|
||||||
.map_db_error()?
|
.map_db_error()?
|
||||||
|
|
|
||||||
|
|
@ -178,9 +178,10 @@ where
|
||||||
.sum();
|
.sum();
|
||||||
let extra_hours = self
|
let extra_hours = self
|
||||||
.extra_hours_dao
|
.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?
|
.await?
|
||||||
.iter()
|
.iter()
|
||||||
|
.filter(|eh| eh.date_time.iso_week() <= until_week)
|
||||||
.map(|eh| eh.amount)
|
.map(|eh| eh.amount)
|
||||||
.sum::<f32>();
|
.sum::<f32>();
|
||||||
let balance_hours = shiftplan_hours + extra_hours - planned_hours;
|
let balance_hours = shiftplan_hours + extra_hours - planned_hours;
|
||||||
|
|
@ -221,7 +222,7 @@ where
|
||||||
.await?;
|
.await?;
|
||||||
let extra_hours = self
|
let extra_hours = self
|
||||||
.extra_hours_dao
|
.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?;
|
.await?;
|
||||||
|
|
||||||
let planned_hours: f32 = (1..=until_week)
|
let planned_hours: f32 = (1..=until_week)
|
||||||
|
|
@ -232,7 +233,11 @@ where
|
||||||
})
|
})
|
||||||
.sum();
|
.sum();
|
||||||
let shiftplan_hours = shiftplan_report.iter().map(|r| r.hours).sum::<f32>() as f32;
|
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 {
|
let employee_report = EmployeeReport {
|
||||||
sales_person: Arc::new(sales_person),
|
sales_person: Arc::new(sales_person),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue