package app import ( "database/sql" "fmt" "time" "code.tnxs.net/taxnexus/lib/api/geo/geo_models" "github.com/google/uuid" ) // UnMarshalTaxType decodes swagger to a first class object func UnMarshalTaxType(s *geo_models.TaxType) *TaxType { createdDate, e0 := time.Parse(dateTimeFormat, s.CreatedDate) lastModifiedDate, e1 := time.Parse(dateTimeFormat, s.LastModifiedDate) effectiveDate, e2 := time.Parse(dateFormat, s.EffectiveDate) endDate, e3 := time.Parse(dateFormat, s.EndDate) formatted := TaxTypeFormatted{ CreatedDate: createdDate.Format(dateTimeFormat), EffectiveDate: effectiveDate.Format(dateFormat), EndDate: endDate.Format(dateFormat), Fractional: fmt.Sprintf("%v", s.Fractional), InterestRate: RenderFloat(rPattern, s.InterestRate*percentFactor) + "%", IsMedicinal: fmt.Sprintf("%v", s.IsMedicinal), IsRecreational: fmt.Sprintf("%v", s.IsRecreational), LastModifiedDate: lastModifiedDate.Format(dateTimeFormat), MarkupRate: RenderFloat(rPattern, (s.MarkupRate-1)*percentFactor) + "%", PassThrough: fmt.Sprintf("%v", s.PassThrough), PenaltyDays: fmt.Sprintf("%v", s.PenaltyDays), PenaltyRate: RenderFloat(rPattern, s.PenaltyRate*percentFactor) + "%", Rate: RenderFloat(rPattern, s.Rate*percentFactor) + "%", } switch { case s.Category == "cannabis-ag": formatted.Rate = "$" + RenderFloat(rPattern, s.Rate) + " / " + s.Units } if s.ID == "" { s.ID = uuid.New().String() } return &TaxType{ ID: s.ID, AccountID: s.AccountID, AccountingRuleCode: s.AccountingRuleCode, Active: s.Active, AgencyType: s.AgencyType, AgentID: s.AgentID, Amount: s.Amount, Category: s.Category, ChainType: s.ChainType, CollectorDomainID: s.CollectorDomainID, CompanyID: s.CompanyID, ContactID: s.ContactID, CreatedByID: s.CreatedByID, Description: s.Description, EnrollmentStatus: s.EnrollmentStatus, FilingCity: s.FilingCity, FilingCountry: s.FilingCountry, FilingEmail: s.FilingEmail, FilingMethod: s.FilingMethod, FilingPostalcode: s.FilingPostalCode, FilingState: s.FilingState, FilingStreet: s.FilingStreet, Formatted: formatted, Fractional: s.Fractional, Frequency: s.Frequency, GeocodeString: s.GeocodeString, InterestRate: s.InterestRate, IsMedicinal: s.IsMedicinal, IsRecreational: s.IsRecreational, LastModifiedByID: s.LastModifiedByID, MarkupRate: s.MarkupRate, Name: s.Name, OwnerID: s.OwnerID, Passthrough: s.PassThrough, PenaltyDays: s.PenaltyDays, PenaltyRate: s.PenaltyRate, Rate: s.Rate, Reference: s.Reference, RevenueBase: s.RevenueBase, RevenueNet: s.RevenueNet, RevenueNotTaxable: s.RevenueNotTaxable, SalesRegulation: s.SalesRegulation, Status: s.Status, TaxnexusCodeID: s.TaxnexusCodeID, TaxnexusNumber: s.TaxnexusNumber, TemplateID: s.TemplateID, UnitBase: s.UnitBase, Units: s.Units, CreatedDate: sql.NullTime{ Time: createdDate, Valid: e0 == nil && !createdDate.IsZero(), }, LastModifiedDate: sql.NullTime{ Time: lastModifiedDate, Valid: e1 == nil && !lastModifiedDate.IsZero(), }, EffectiveDate: sql.NullTime{ Time: effectiveDate, Valid: e2 == nil && !effectiveDate.IsZero(), }, EndDate: sql.NullTime{ Time: endDate, Valid: e3 == nil && !endDate.IsZero(), }, } } // MarshalToSwagger encodes a first class object to swagger func (obj *TaxType) MarshalToSwagger() *geo_models.TaxType { var createdDate string if obj.CreatedDate.Valid { createdDate = obj.CreatedDate.Time.Format(dateTimeFormat) } var lastModifiedDate string if obj.LastModifiedDate.Valid { lastModifiedDate = obj.LastModifiedDate.Time.Format(dateTimeFormat) } var effectiveDate string if obj.EffectiveDate.Valid { effectiveDate = obj.EffectiveDate.Time.Format(dateFormat) } var endDate string if obj.EndDate.Valid { endDate = obj.EndDate.Time.Format(dateFormat) } return &geo_models.TaxType{ ID: obj.ID, AccountID: obj.AccountID, AccountingRuleCode: obj.AccountingRuleCode, Active: obj.Active, AgencyType: obj.AgencyType, AgentID: obj.AgentID, Amount: obj.Amount, Category: obj.Category, ChainType: obj.ChainType, CollectorDomainID: obj.CollectorDomainID, CompanyID: obj.CompanyID, ContactID: obj.ContactID, CreatedByID: obj.CreatedByID, CreatedDate: createdDate, Description: obj.Description, EffectiveDate: effectiveDate, EndDate: endDate, EnrollmentStatus: obj.EnrollmentStatus, FilingCity: obj.FilingCity, FilingCountry: obj.FilingCountry, FilingEmail: obj.FilingEmail, FilingMethod: obj.FilingMethod, FilingPostalCode: obj.FilingPostalcode, FilingState: obj.FilingState, FilingStreet: obj.FilingStreet, Fractional: obj.Fractional, Frequency: obj.Frequency, GeocodeString: obj.GeocodeString, InterestRate: obj.InterestRate, IsMedicinal: obj.IsMedicinal, IsRecreational: obj.IsRecreational, LastModifiedByID: obj.LastModifiedByID, LastModifiedDate: lastModifiedDate, MarkupRate: obj.MarkupRate, Name: obj.Name, OwnerID: obj.OwnerID, PassThrough: obj.Passthrough, PenaltyDays: obj.PenaltyDays, PenaltyRate: obj.PenaltyRate, Rate: obj.Rate, Reference: obj.Reference, RevenueBase: obj.RevenueBase, RevenueNet: obj.RevenueNet, RevenueNotTaxable: obj.RevenueNotTaxable, SalesRegulation: obj.SalesRegulation, Status: obj.Status, TaxnexusCodeID: obj.TaxnexusCodeID, TaxnexusNumber: obj.TaxnexusNumber, TemplateID: obj.TemplateID, UnitBase: obj.UnitBase, Units: obj.Units, } }