lib/app/filingtype-helpers.go

134 lines
4.2 KiB
Go
Raw Permalink Normal View History

2021-01-14 06:36:35 +00:00
package app
import (
"database/sql"
"time"
"code.tnxs.net/taxnexus/lib/api/regs/regs_models"
"github.com/google/uuid"
)
2021-01-17 21:49:00 +00:00
func UnMarshalFilingType(s *regs_models.FilingType) *FilingType {
2021-01-14 06:36:35 +00:00
if s.ID == "" {
s.ID = uuid.New().String()
}
createdDate, e0 := time.Parse(dateTimeFormat, s.CreatedDate)
lastModfiedDate, e1 := time.Parse(dateTimeFormat, s.LastModifiedDate)
var instances []*FilingTypeInstance
var dueDates []*FilingScheduleItem
if s.Instances != nil {
instances = []*FilingTypeInstance{}
for _, itm := range s.Instances {
instances = append(instances, &FilingTypeInstance{
CountryID: itm.CountryID,
CountyID: itm.CountyID,
FilingTypeID: itm.FilingTypeID,
ObjectType: itm.ObjectType,
PlaceID: itm.PlaceID,
StateID: itm.StateID,
})
}
for _, itm := range s.DueDates {
dueDates = []*FilingScheduleItem{}
dueDate, e0 := time.Parse(dateTimeFormat, itm.DueDate)
if e0 != nil {
dueDate, e0 = time.Parse(dateFormatAlt, itm.DueDate)
}
dueDates = append(dueDates, &FilingScheduleItem{
Description: itm.Description,
DueDate: sql.NullTime{
Time: dueDate,
Valid: e0 == nil,
},
})
}
}
return &FilingType{
AccountID: s.AccountID,
ContactID: s.ContactID,
CreatedByID: s.CreatedByID,
DueDates: dueDates,
FilingCity: s.FilingCity,
FilingCountry: s.FilingCountry,
FilingPostalCode: s.FilingPostalCode,
FilingState: s.FilingState,
FilingStreet: s.FilingStreet,
FormName: s.FormName,
FormVersion: s.FormVersion,
Frequency: s.Frequency,
FullName: s.FullName,
ID: s.ID,
Instances: instances,
LastModifiedByID: s.LastModifiedByID,
Level: s.Level,
Name: s.Name,
OwnerID: s.OwnerID,
SagaType: s.SagaType,
SubmissionMethod: s.SubmissionMethod,
TemplateInstructionsID: s.TemplateInstructionsID,
TemplateReturnID: s.TemplateReturnID,
CreatedDate: sql.NullTime{
Time: createdDate,
Valid: e0 == nil,
},
LastModifiedDate: sql.NullTime{
Time: lastModfiedDate,
Valid: e1 == nil,
},
}
}
2021-01-17 21:49:00 +00:00
func (obj *FilingType) MarshalToSwagger() *regs_models.FilingType {
2021-01-14 06:36:35 +00:00
var instances []*regs_models.FilingTypeInstance
if obj.Instances != nil {
instances = []*regs_models.FilingTypeInstance{}
for _, itm := range obj.Instances {
instances = append(instances, &regs_models.FilingTypeInstance{
CountryID: itm.CountryID,
CountyID: itm.CountyID,
FilingTypeID: itm.FilingTypeID,
ObjectType: itm.ObjectType,
PlaceID: itm.PlaceID,
StateID: itm.StateID,
})
}
}
var dueDates []*regs_models.FilingScheduleItem
if obj.DueDates != nil {
dueDates = []*regs_models.FilingScheduleItem{}
for _, itm := range obj.DueDates {
dueDates = append(dueDates, &regs_models.FilingScheduleItem{
DueDate: itm.DueDate.Time.Format(dateFormat),
Description: itm.Description,
})
}
}
return &regs_models.FilingType{
ID: obj.ID,
AccountID: obj.AccountID,
ContactID: obj.ContactID,
CreatedByID: obj.CreatedByID,
CreatedDate: obj.CreatedDate.Time.Format(dateTimeFormat),
DueDates: dueDates,
FilingCity: obj.FilingCity,
FilingCountry: obj.FilingCountry,
FilingPostalCode: obj.FilingPostalCode,
FilingState: obj.FilingState,
FilingStreet: obj.FilingStreet,
FormName: obj.FormName,
FormVersion: obj.FormVersion,
Frequency: obj.Frequency,
FullName: obj.FullName,
Instances: instances,
LastModifiedByID: obj.LastModifiedByID,
LastModifiedDate: obj.LastModifiedDate.Time.Format(dateTimeFormat),
Level: obj.Level,
Name: obj.Name,
OwnerID: obj.OwnerID,
SagaType: obj.SagaType,
SubmissionMethod: obj.SubmissionMethod,
TemplateInstructionsID: obj.TemplateInstructionsID,
TemplateReturnID: obj.TemplateReturnID,
}
}