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