Browse Source

Initial commit

Dmitry Yu Okunev 5 years ago
commit
8780214818
3 changed files with 185 additions and 0 deletions
  1. 97 0
      formular.go
  2. 44 0
      person.go
  3. 44 0
      unit.go

+ 97 - 0
formular.go

@@ -0,0 +1,97 @@
+package asuModels
+
+//go:generate reform --gofmt=false
+
+import (
+	"fmt"
+	"github.com/revel/revel"
+	"github.com/xaionaro-go/extime"
+	"html/template"
+)
+
+//reform:formular
+type Formular struct {
+	EmpGUID              int          `reform:"EmpGUID"        view:"readonly"`
+	StfCardId            int          `reform:"StfCardId"      view:"readonly"`
+	PersonnelNumber      int          `reform:"TabN"           view:"readonly"`
+	FormularType         string       `reform:"Tip_formular"   view:"readonly"`
+	StartDate            *extime.Date `reform:"StartDate"      view:"readonly"`
+	EndDate              *extime.Date `reform:"EndDate"        view:"readonly"`
+	AppointmentName      string       `reform:"Name"           view:"readonly"`
+	AppointmentShortName *string      `reform:"Prof_BriefName" view:"readonly"`
+	WorkStart            *extime.Date `reform:"Start_work"     view:"readonly"`
+	Category             string       `reform:"Category"       view:"readonly"`
+	UnitName             string       `reform:"Name_podr"      view:"readonly"`
+	UnitShortName        *string      `reform:"Podr_BriefName" view:"readonly"`
+	UnitCode             string       `reform:"Code"           view:"readonly"`
+	ChiefName            *string      `reform:"ChiefName"      view:"readonly"`
+	Rate                 *float64     `reform:"RateAmount"     view:"readonly"`
+	IsHead               *bool        `reform:"IsHead"         view:"readonly"`
+	UnitId               int          `reform:"OrgDiv"         view:"readonly"`
+
+	Unit   Unit   `reform:"-"`
+	Person Person `reform:"-"`
+
+	//PersNumber           *int         `reform:"PersNumber"`
+	//FormularTypeCode   int     `reform:"Cod_Tip_formular"`
+	//CategoryCode       int     `reform:"Cod_Catgory"`
+	//WorkEnd           *string  `reform:"End_work"`
+	//Profession         int     `reform:"Profession"`
+	//Lastname           string  `reform:"SurName"`
+	//Firstname          string  `reform:"FirstName"`
+	//Patronymic         string  `reform:"MiddleName"`
+	//OrgInn             string  `reform:"OrgInn"`
+	//DivInn             string  `reform:"DivInn"`
+	//Sex                int     `reform:"Sex"`
+	//WorkState          int     `reform:"WorkState"`
+	//ProfKvalLevel      string  `reform:"ProfKvalLevel"`
+	//ProfKvalGroup      int     `reform:"ProfKvalGroup"`
+	//EmpCardId          string  `reform:"EmpCardId"`
+	//VacDays            *int    `reform:"VacDays"`
+	//ExtraVacDays       *int    `reform:"ExtraVacDays"`
+}
+
+func (f Formular) View_readTag(fieldName string, parent interface{}, args []interface{}) template.HTML {
+	unitName := f.UnitName
+	if f.UnitShortName != nil {
+		unitName = *f.UnitShortName + " (" + unitName + ")"
+	}
+	return template.HTML(fmt.Sprintf(`<a href="/asu/formulars/%v?fullscreen=true">%v — %v: [%v] %v — %v</a>`, f.StfCardId, f.StartDate, f.EndDate, f.UnitCode, f.AppointmentName, unitName))
+}
+
+func (f *Formular) PrepareUnit() *Formular {
+	var err error
+	f.Unit, err = UnitSQL.First(Unit{Id: f.UnitId})
+	if err != nil {
+		revel.ERROR.Printf("Got error: %v", err.Error())
+	}
+	return f
+}
+
+func (f *Formular) PreparePerson() *Formular {
+	var err error
+	f.Person, err = PersonSQL.First(Person{EmpGUID: f.EmpGUID})
+	if err != nil {
+		revel.ERROR.Printf("Got error: %v", err.Error())
+	}
+	return f
+}
+
+func (f Formular) IsActive() bool {
+	now := extime.Now()
+
+	startIsGood := false
+	endIsGood := false
+
+	if f.StartDate != nil {
+		startIsGood = f.StartDate.UnixNano() <= now.UnixNano()
+	}
+
+	if f.EndDate == nil {
+		endIsGood = true
+	} else {
+		endIsGood = f.EndDate.UnixNano() + 3600 * 24 >= now.UnixNano()
+	}
+
+	return startIsGood && endIsGood
+}

+ 44 - 0
person.go

@@ -0,0 +1,44 @@
+//go:generate reform --gofmt=false
+package asuModels
+
+import (
+	"fmt"
+	"html/template"
+)
+
+//reform:face
+type Person struct {
+	EmpGUID     int     `reform:"EmpGUID"     view:"readonly"`
+	Lastname    string  `reform:"SurName"     view:"readonly"`
+	Firstname   string  `reform:"FirstName"   view:"readonly"`
+	Patronymic  *string `reform:"MiddleName"  view:"readonly"`
+	Sex         *int    `reform:"Sex"         view:"readonly"`
+	Id          int     `reform:"_Id"         view:"readonly"`
+	BirthDay    *string `reform:"BirthDay"    view:"readonly"`
+	Citizenship *int    `reform:"Citizenship" view:"readonly"`
+	CitizenType *string `reform:"CitizenType" view:"readonly"`
+	Phone       *string `reform:"Phone"       view:"readonly"`
+	Phone2      *string `reform:"Phone2"      view:"readonly"`
+	Phone3      *string `reform:"Phone3"      view:"readonly"`
+
+	// for rendering:
+	Formulars []Formular
+}
+
+func (u Person) View_readTag(fieldName string, parent interface{}, args []interface{}) template.HTML {
+	if u.EmpGUID == 0 {
+		return template.HTML(fmt.Sprintf(`Не назначено`))
+	}
+
+	description := u.Lastname + " " + u.Firstname
+	if u.Patronymic != nil {
+		description += " " + *u.Patronymic
+	}
+	if u.BirthDay != nil {
+		if len(*u.BirthDay) > len("1988-03-06") {
+			description += " (" + (*u.BirthDay)[:len("1988-03-06")] + ")"
+		}
+	}
+
+	return template.HTML(fmt.Sprintf(`<a href="/asu/people/%v?fullscreen=true">%v</a>`, u.EmpGUID, description))
+}

+ 44 - 0
unit.go

@@ -0,0 +1,44 @@
+//go:generate reform --gofmt=false
+package asuModels
+
+import (
+	"fmt"
+	"html/template"
+)
+
+//reform:unit
+type Unit struct {
+	Id              int     `reform:"id"              view:"readonly"`
+	OrgInn          string  `reform:"OrgInn"          view:"readonly"`
+	Name            *string `reform:"Name"            view:"readonly"`
+	ParentId        *int    `reform:"ParentId"        view:"readonly"`
+	LevelIdx        int     `reform:"LevelIdx"        view:"readonly"`
+	IsHidden        int     `reform:"IsHidden"        view:"readonly"`
+	OKVED           *string `reform:"OKVED"           view:"readonly"`
+	BriefName       *string `reform:"BriefName"       view:"readonly"`
+	CreateOrderNo   *string `reform:"CreateOrderNo"   view:"readonly"`
+	CreateOrderDate *string `reform:"CreateOrderDate" view:"readonly"`
+	CloseOrderNo    *string `reform:"CloseOrderNo"    view:"readonly"`
+	CloseOrderDate  *string `reform:"CloseOrderDate"  view:"readonly"`
+	ChiefName       *string `reform:"ChiefName"       view:"readonly"`
+	PersNumber      *int    `reform:"PersNumber"      view:"readonly"`
+	Code            string  `reform:"Code"            view:"readonly"`
+	SortNumber      *string `reform:"SortNumber"      view:"readonly"`
+	ChiefTabN       *string `reform:"ChiefTabN"       view:"readonly"`
+}
+
+func (u Unit) View_readTag(fieldName string, parent interface{}, args []interface{}) template.HTML {
+	if u.Id == 0 {
+		return template.HTML(fmt.Sprintf(`Не назначено`))
+	}
+
+	name := ""
+	if u.BriefName != nil {
+		name = *u.BriefName
+	}
+	if u.Name != nil {
+		name += " (" + *u.Name + ")"
+	}
+
+	return template.HTML(fmt.Sprintf(`<a href="/asu/unitsByID/%v?fullscreen=true">%v — %v</a>`, u.Id, u.Code, name))
+}