123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- //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"`
- PersonId int `reform:"person_id"`
- StfCardId int `reform:"StaffCardId"`
- TimeUseCode string `reform:"TimeUseCode"`
- Days float32 `reform:"Days"`
- Hours *float32 `reform:"Hours"`
- Author *int `reform:"Author"`
- ParentId *int `reform:"ParentId"`
- TableId *int `reform:"TableId"`
- TableState int `reform:"TableState"`
- State int `reform:"State"`
- AstDate *extime.Date `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
- }
- func (timesheetRows TimesheetRows) GetStfCardIds() (stfCardIds []int) {
- for _, timesheetRow := range timesheetRows {
- stfCardIds = append(stfCardIds, timesheetRow.StfCardId)
- }
- return
- }
|