lib/app/taxtype-helpers.go

172 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-01-28 01:58:08 +00:00
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
}
2021-01-14 06:36:35 +00:00
if s.ID == "" {
s.ID = uuid.New().String()
}
dateTime, dateErr := time.Parse(dateTimeFormat, s.CreatedDate)
2021-01-28 01:58:08 +00:00
createdDateSQL := sql.NullTime{
2021-01-14 06:36:35 +00:00
Time: dateTime,
Valid: dateErr == nil,
}
dateTime, dateErr = time.Parse(dateTimeFormat, s.LastModifiedDate)
2021-01-28 01:58:08 +00:00
modifiedDateSQL := sql.NullTime{
2021-01-14 06:36:35 +00:00
Time: dateTime,
Valid: dateErr == nil,
}
date, dateErr := time.Parse(dateFormat, s.EffectiveDate)
2021-01-28 01:58:08 +00:00
effectiveDateSQL := sql.NullTime{
2021-01-14 06:36:35 +00:00
Time: date,
Valid: dateErr == nil,
}
date, dateErr = time.Parse(dateFormat, s.EndDate)
2021-01-28 01:58:08 +00:00
endDateSQL := sql.NullTime{
2021-01-14 06:36:35 +00:00
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,
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,
2021-01-28 01:58:08 +00:00
CreatedDate: createdDateSQL,
2021-01-14 06:36:35 +00:00
Description: s.Description,
2021-01-28 01:58:08 +00:00
EffectiveDate: effectiveDateSQL,
EndDate: endDateSQL,
2021-01-14 06:36:35 +00:00
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,
2021-01-28 01:58:08 +00:00
LastModifiedDate: modifiedDateSQL,
2021-01-14 06:36:35 +00:00
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,
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,
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,
}
}