|
@@ -0,0 +1,150 @@
|
|
|
+//go:generate reform --gofmt=false
|
|
|
+//go:generate easyjson -all timesheet_row.go
|
|
|
+package asuModels
|
|
|
+
|
|
|
+import (
|
|
|
+ "database/sql"
|
|
|
+ "github.com/xaionaro-go/extime"
|
|
|
+ "reflect"
|
|
|
+)
|
|
|
+
|
|
|
+//reform:table_view
|
|
|
+type TimesheetRow struct {
|
|
|
+ Id int `reform:"Id"`
|
|
|
+ ADate extime.Date `reform:"ADate"`
|
|
|
+ ODate extime.Date `reform:"ODate"`
|
|
|
+ MonthYear extime.Date `reform:"MonthYear"`
|
|
|
+ EmpGUID int `reform:"EmpGuid"`
|
|
|
+ StfCardId int `reform:"StaffCardId"`
|
|
|
+ TimeUseCode string `reform:"TimeUseCode"`
|
|
|
+ Days int `reform:"Days"`
|
|
|
+ Hours *int `reform:"Hours"`
|
|
|
+ Author int `reform:"Author"`
|
|
|
+ ParentId int `reform:"ParentId"`
|
|
|
+ TableId int `reform:"TableId"`
|
|
|
+ TableState int `reform:"TableState"`
|
|
|
+ State int `reform:"State"`
|
|
|
+ AstDate int `reform:"AstDate"`
|
|
|
+ SID int `reform:"SID"`
|
|
|
+ Nullified *int `reform:"Nullified"`
|
|
|
+ ParentState int `reform:"ParentState"`
|
|
|
+ BlockerId *int `reform:"BlockerId"`
|
|
|
+ OrgInn *string `reform:"OrgInn"`
|
|
|
+ DivInn *string `reform:"DivInn"`
|
|
|
+ TabN *int `reform:"TabN"`
|
|
|
+ ScGUID *int `reform:"scGUID"`
|
|
|
+ Description string `reform:"Description"`
|
|
|
+ TimeUseClass int `reform:"TimeUseClass"`
|
|
|
+ RequiredHours int `reform:"RequiredHours"`
|
|
|
+
|
|
|
+ person Person `reform:"-"`
|
|
|
+ personReady bool `reform:"-"`
|
|
|
+
|
|
|
+ formular Formular `reform:"-"`
|
|
|
+ formularReady bool `reform:"-"`
|
|
|
+}
|
|
|
+
|
|
|
+func (t *TimesheetRow) PreparePerson() *TimesheetRow {
|
|
|
+ var err error
|
|
|
+ t.person, err = PersonSQL.First(Person{EmpGUID: t.EmpGUID})
|
|
|
+ if err != nil && err != sql.ErrNoRows {
|
|
|
+ panic(err)
|
|
|
+ return t
|
|
|
+ }
|
|
|
+ t.personReady = true
|
|
|
+ return t
|
|
|
+}
|
|
|
+
|
|
|
+func (t TimesheetRow) IsPersonReady() bool {
|
|
|
+ return t.personReady
|
|
|
+}
|
|
|
+
|
|
|
+func (t TimesheetRow) GetPerson() Person {
|
|
|
+ if !t.personReady {
|
|
|
+ panic("formular is not ready for method GetPerson: it's required to call PreparePerson method, first")
|
|
|
+ }
|
|
|
+ return t.person
|
|
|
+}
|
|
|
+
|
|
|
+func (t *TimesheetRow) PrepareFormular() *TimesheetRow {
|
|
|
+ var err error
|
|
|
+ t.formular, err = FormularSQL.First(Formular{StfCardId: t.StfCardId})
|
|
|
+ if err != nil && err != sql.ErrNoRows {
|
|
|
+ panic(err)
|
|
|
+ return t
|
|
|
+ }
|
|
|
+ t.formularReady = true
|
|
|
+ return t
|
|
|
+}
|
|
|
+
|
|
|
+func (t TimesheetRow) IsFormularReady() bool {
|
|
|
+ return t.formularReady
|
|
|
+}
|
|
|
+
|
|
|
+func (t TimesheetRow) GetFormular() Formular {
|
|
|
+ if !t.formularReady {
|
|
|
+ panic("formular is not ready for method GetFormular: it's required to call PrepareFormular method, first")
|
|
|
+ }
|
|
|
+ return t.formular
|
|
|
+}
|
|
|
+
|
|
|
+func (timesheetRow TimesheetRow) Flush() {
|
|
|
+ timesheetRow.formular = Formular{}
|
|
|
+ timesheetRow.formularReady = false
|
|
|
+ timesheetRow.person = Person{}
|
|
|
+ timesheetRow.personReady = false
|
|
|
+}
|
|
|
+
|
|
|
+func (timesheetRow TimesheetRow) IsEqualsTo(compareTo TimesheetRow) bool {
|
|
|
+ timesheetRow.Flush()
|
|
|
+ compareTo.Flush()
|
|
|
+ return reflect.DeepEqual(timesheetRow, compareTo)
|
|
|
+}
|
|
|
+
|
|
|
+type TimesheetRows []TimesheetRow
|
|
|
+
|
|
|
+func (timesheetRows TimesheetRows) GetEmpGUIDs() (empGUIDs []int) {
|
|
|
+ empGUIDMap := map[int]bool{}
|
|
|
+
|
|
|
+ for _, timesheetRow := range timesheetRows {
|
|
|
+ empGUIDMap[timesheetRow.EmpGUID] = true
|
|
|
+ }
|
|
|
+ for empGUID, _ := range empGUIDMap {
|
|
|
+ empGUIDs = append(empGUIDs, empGUID)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (timesheetRows TimesheetRows) PrepareFormulars(activeOnly bool) TimesheetRows {
|
|
|
+ ids := timesheetRows.GetEmpGUIDs()
|
|
|
+
|
|
|
+ scope := FormularSQL.Scope()
|
|
|
+
|
|
|
+ if activeOnly {
|
|
|
+ scope = scope.ActiveOnly()
|
|
|
+ }
|
|
|
+
|
|
|
+ formulars, err := scope.Select("EmpGUID IN (?)", ids)
|
|
|
+ if err != nil && err != sql.ErrNoRows {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ for range formulars {
|
|
|
+ panic("Not implemented, yet")
|
|
|
+ }
|
|
|
+
|
|
|
+ for idx, _ := range timesheetRows {
|
|
|
+ timesheetRows[idx].formularReady = true
|
|
|
+ }
|
|
|
+
|
|
|
+ return timesheetRows
|
|
|
+}
|
|
|
+
|
|
|
+func (timesheetRows TimesheetRows) GetFormulars() (formulars Formulars) {
|
|
|
+ for _, timesheetRow := range timesheetRows {
|
|
|
+ formulars = append(formulars, timesheetRow.GetFormular())
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|