lib/app/taxtype-helpers.go

176 lines
6.1 KiB
Go
Raw Normal View History

2021-01-14 06:36:35 +00:00
package app
import (
"database/sql"
2021-01-28 01:58:08 +00:00
"fmt"
2021-01-14 06:36:35 +00:00
"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 {
2021-02-06 15:59:05 +00:00
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)
2021-01-28 01:58:08 +00:00
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
}
2021-01-14 06:36:35 +00:00
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,
2021-02-05 22:04:17 +00:00
ChainType: s.ChainType,
2021-01-14 06:36:35 +00:00
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,
2021-01-28 01:58:08 +00:00
Formatted: formatted,
2021-01-14 06:36:35 +00:00
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,
2021-02-06 15:59:05 +00:00
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(),
},
2021-01-14 06:36:35 +00:00
}
}
// MarshalToSwagger encodes a first class object to swagger
func (obj *TaxType) MarshalToSwagger() *geo_models.TaxType {
2021-02-06 15:59:05 +00:00
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)
}
2021-01-14 06:36:35 +00:00
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,
2021-02-05 22:04:17 +00:00
ChainType: obj.ChainType,
2021-01-14 06:36:35 +00:00
CollectorDomainID: obj.CollectorDomainID,
CompanyID: obj.CompanyID,
ContactID: obj.ContactID,
CreatedByID: obj.CreatedByID,
2021-02-06 15:59:05 +00:00
CreatedDate: createdDate,
2021-01-14 06:36:35 +00:00
Description: obj.Description,
2021-02-06 15:59:05 +00:00
EffectiveDate: effectiveDate,
EndDate: endDate,
2021-01-14 06:36:35 +00:00
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,
2021-02-06 15:59:05 +00:00
LastModifiedDate: lastModifiedDate,
2021-01-14 06:36:35 +00:00
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,
}
}