|
@@ -1,9 +1,11 @@
|
|
|
package controllers
|
|
|
|
|
|
import (
|
|
|
+ "database/sql"
|
|
|
renderModels "devel.mephi.ru/dyokunev/cps-models/for_render"
|
|
|
asuModels "devel.mephi.ru/dyokunev/go-asu-models"
|
|
|
"github.com/revel/revel"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
type Units struct {
|
|
@@ -32,7 +34,7 @@ func (c Units) scope(unit asuModels.Unit, activeOnly bool, unhiddenOnly bool, re
|
|
|
return scope
|
|
|
}
|
|
|
|
|
|
-func (c Units) Index(unit asuModels.Unit, activeOnly, unhiddenOnly, realOnly, notEmptyOnly, setIfHasFormularsRecursive, prepareFormulars, showChildren, forceRecursiveChildren, preparePeople bool) revel.Result {
|
|
|
+func (c Units) Index(unit asuModels.Unit, activeOnly, unhiddenOnly, realOnly, notEmptyOnly, setIfHasFormularsRecursive, prepareFormulars, showChildren, forceRecursiveChildren, preparePeople bool, startDate, endDate time.Time) revel.Result {
|
|
|
if r := c.Init(); r != nil {
|
|
|
return r
|
|
|
}
|
|
@@ -50,8 +52,33 @@ func (c Units) Index(unit asuModels.Unit, activeOnly, unhiddenOnly, realOnly, no
|
|
|
return r
|
|
|
}
|
|
|
|
|
|
+ timesheetRowScope := c.TimesheetRowSQL.Scope().SetQueryFieldsByNames("StfCardId").SetTableQuery("`table` JOIN formular on StaffCardId = formular.StfCardId").Group("StaffCardId")
|
|
|
+
|
|
|
+ timesheetRowScope = timesheetRowScope.Where("PersNumber IN (?)", asuModels.Units(units).GetPersNumbers())
|
|
|
+
|
|
|
+ if (time.Time{}) != startDate {
|
|
|
+ timesheetRowScope = timesheetRowScope.Where("ADate > ?", startDate)
|
|
|
+ }
|
|
|
+ if (time.Time{}) != endDate {
|
|
|
+ timesheetRowScope = timesheetRowScope.Where("ADate < ?", endDate)
|
|
|
+ }
|
|
|
+
|
|
|
+ staffCardIdRows, err := timesheetRowScope.Select()
|
|
|
+ if err == sql.ErrNoRows {
|
|
|
+ return c.Render(renderModels.NewUnits(units))
|
|
|
+ }
|
|
|
+ if r := c.ConsiderErr(err); r != nil {
|
|
|
+ return r
|
|
|
+ }
|
|
|
+
|
|
|
if prepareFormulars {
|
|
|
- asuModels.Units(units).PrepareFormulars(true)
|
|
|
+ stfCardIds := asuModels.TimesheetRows(staffCardIdRows).GetStfCardIds()
|
|
|
+ if len(stfCardIds) > 0 {
|
|
|
+ asuModels.Units(units).PrepareFormulars(false, "StfCardId IN (?)", asuModels.TimesheetRows(staffCardIdRows).GetStfCardIds())
|
|
|
+ } else {
|
|
|
+ // Just to set formularsReady to true:
|
|
|
+ asuModels.Units(units).PrepareFormulars(false, "0=1")
|
|
|
+ }
|
|
|
}
|
|
|
if preparePeople {
|
|
|
for idx, _ := range units {
|