Dmitry Yu Okunev лет назад: 6
Родитель
Сommit
795a8254d7
4 измененных файлов с 161 добавлено и 7 удалено
  1. 1 0
      .gitignore
  2. 0 2
      person.go
  3. 150 0
      timesheet_row.go
  4. 10 5
      unit.go

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 *_reform.go
+*_easyjson.go

+ 0 - 2
person.go

@@ -129,5 +129,3 @@ func (people People) PrepareFormulars() People {
 
 	return people
 }
-
-

+ 150 - 0
timesheet_row.go

@@ -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
+}

+ 10 - 5
unit.go

@@ -6,8 +6,8 @@ import (
 	"fmt"
 	"github.com/xaionaro-go/extime"
 	"html/template"
-	"strings"
 	"reflect"
+	"strings"
 )
 
 //reform:unit
@@ -56,7 +56,7 @@ func (sql Unit) ActiveOnly() *UnitScope {
 func (sql *UnitScope) ActiveOnly() *UnitScope {
 	cond := "((CreateOrderDate IS NULL OR CreateOrderDate < NOW()) AND (CloseOrderDate IS NULL OR CloseOrderDate+24*3600 > NOW()))"
 
-	return sql.Where(cond+" OR (Id IN (SELECT ParentId FROM unit WHERE "+cond+"))")
+	return sql.Where(cond + " OR (Id IN (SELECT ParentId FROM unit WHERE " + cond + "))")
 }
 
 func (sql Unit) RealOnly() *UnitScope {
@@ -199,10 +199,16 @@ func (u Unit) GetFormulars() Formulars {
 	return u.formulars
 }
 
-func (units Units) PrepareFormulars() Units {
+func (units Units) PrepareFormulars(activeOnly bool) Units {
 	ids := units.GetUnitIds()
 
-	formulars, err := FormularSQL.Select("OrgDiv IN (?)", ids)
+	scope := FormularSQL.Scope()
+
+	if activeOnly {
+		scope = scope.ActiveOnly()
+	}
+
+	formulars, err := scope.Select("OrgDiv IN (?)", ids)
 	if err != nil && err != sql.ErrNoRows {
 		panic(err)
 	}
@@ -349,4 +355,3 @@ func (unit Unit) IsEqualsTo(compareTo Unit) bool {
 	compareTo.Flush()
 	return reflect.DeepEqual(unit, compareTo)
 }
-