lib/app/country-helpers.go

103 lines
3.3 KiB
Go
Raw Normal View History

2021-01-14 06:36:35 +00:00
package app
import (
"database/sql"
"time"
"code.tnxs.net/taxnexus/lib/api/geo/geo_models"
"github.com/google/uuid"
)
2021-01-18 03:13:54 +00:00
// UnMarshalCountry decodes swagger to first class object
2021-01-17 21:49:00 +00:00
func UnMarshalCountry(s *geo_models.Country) *Country {
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)
theInstances := []*TaxInstance{}
for _, itm := range s.TaxInstances {
2021-01-17 21:49:00 +00:00
theInstances = append(theInstances, UnMarshalTaxInstance(itm))
2021-01-14 06:36:35 +00:00
}
return &Country{
ID: s.ID,
AccountID: s.AccountID,
Amount: s.Amount,
Code: s.Code,
ContactID: s.ContactID,
CreatedByID: s.CreatedByID,
EnrollmentStatus: s.EnrollmentStatus,
Interest: s.Interest,
LastModifiedByID: s.LastModifiedByID,
Latitude: s.Latitude,
Longitude: s.Longitude,
Name: s.Name,
OwnerID: s.OwnerID,
Penalty: s.Penalty,
Ref: s.Ref,
ReportedAdjustments: s.ReportedAdjustments,
ReportedDeductions: s.ReportedDeductions,
ReportedNetRevenue: s.ReportedNetRevenue,
ReportedRate: s.ReportedRate,
ReportedRevenue: s.ReportedRevenue,
RevenueBase: s.RevenueBase,
RevenueNet: s.RevenueNet,
RevenueNotTaxable: s.RevenueNotTaxable,
Status: s.Status,
Subtotal: s.Subtotal,
TaxInstances: theInstances,
TemplateID: s.TemplateID,
TotalAmount: s.TotalAmount,
UnitBase: s.UnitBase,
CreatedDate: sql.NullTime{
Time: createdDate,
Valid: e0 == nil,
},
LastModifiedDate: sql.NullTime{
Time: lastModfiedDate,
Valid: e1 == nil,
},
}
}
2021-01-18 03:13:54 +00:00
// MarshalToSwagger encodes first class object
2021-01-17 21:49:00 +00:00
func (obj *Country) MarshalToSwagger() *geo_models.Country {
2021-01-14 06:36:35 +00:00
taxInstances := []*geo_models.TaxInstance{}
for _, itm := range obj.TaxInstances {
2021-01-17 21:49:00 +00:00
taxInstances = append(taxInstances, itm.MarshalToSwagger())
2021-01-14 06:36:35 +00:00
}
return &geo_models.Country{
ID: obj.ID,
AccountID: obj.AccountID,
Amount: obj.Amount,
Code: obj.Code,
ContactID: obj.ContactID,
CreatedByID: obj.CreatedByID,
CreatedDate: obj.CreatedDate.Time.Format(dateTimeFormat),
EnrollmentStatus: obj.EnrollmentStatus,
Interest: obj.Interest,
LastModifiedByID: obj.LastModifiedByID,
LastModifiedDate: obj.LastModifiedDate.Time.Format(dateTimeFormat),
Latitude: obj.Latitude,
Longitude: obj.Longitude,
Name: obj.Name,
OwnerID: obj.OwnerID,
Penalty: obj.Penalty,
Ref: obj.Ref,
ReportedAdjustments: obj.ReportedAdjustments,
ReportedDeductions: obj.ReportedDeductions,
ReportedNetRevenue: obj.ReportedNetRevenue,
ReportedRate: obj.ReportedRate,
ReportedRevenue: obj.ReportedRevenue,
RevenueBase: obj.RevenueBase,
RevenueNet: obj.RevenueNet,
RevenueNotTaxable: obj.RevenueNotTaxable,
Status: obj.Status,
Subtotal: obj.Subtotal,
TaxInstances: taxInstances,
TemplateID: obj.TemplateID,
TotalAmount: obj.TotalAmount,
UnitBase: obj.UnitBase,
}
}