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, _ := time.Parse(dateTimeFormat, s.CreatedDate) lastModifiedDate, _ := time.Parse(dateTimeFormat, s.LastModifiedDate) effectiveDate, _ := time.Parse(dateFormatDB, s.EffectiveDate) endDate, _ := time.Parse(dateFormatDB, 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() } dateTime, dateErr := time.Parse(dateTimeFormat, s.CreatedDate) createdDateSQL := sql.NullTime{ Time: dateTime, Valid: dateErr == nil, } dateTime, dateErr = time.Parse(dateTimeFormat, s.LastModifiedDate) modifiedDateSQL := sql.NullTime{ Time: dateTime, Valid: dateErr == nil, } date, dateErr := time.Parse(dateFormat, s.EffectiveDate) effectiveDateSQL := sql.NullTime{ Time: date, Valid: dateErr == nil, } date, dateErr = time.Parse(dateFormat, s.EndDate) endDateSQL := sql.NullTime{ Time: date, Valid: dateErr == nil, } 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, CollectorDomainID: s.CollectorDomainID, CompanyID: s.CompanyID, ContactID: s.ContactID, CreatedByID: s.CreatedByID, CreatedDate: createdDateSQL, Description: s.Description, EffectiveDate: effectiveDateSQL, EndDate: endDateSQL, 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, LastModifiedDate: modifiedDateSQL, 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, } } // MarshalToSwagger encodes a first class object to swagger func (obj *TaxType) MarshalToSwagger() *geo_models.TaxType { 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, CollectorDomainID: obj.CollectorDomainID, CompanyID: obj.CompanyID, ContactID: obj.ContactID, CreatedByID: obj.CreatedByID, CreatedDate: obj.CreatedDate.Time.Format(dateTimeFormatAlt), Description: obj.Description, EffectiveDate: obj.EffectiveDate.Time.Format(dateFormat), EndDate: obj.EndDate.Time.Format(dateFormat), 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: obj.LastModifiedDate.Time.Format(dateTimeFormatAlt), 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, } }