lib/app/country-helpers.go

100 lines
3.2 KiB
Go
Raw Permalink 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"
)
func unMarshalCountry(s *geo_models.Country) *Country {
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 {
theInstances = append(theInstances, unMarshalTaxInstance(itm))
}
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,
},
}
}
func (obj *Country) marshalToSwagger() *geo_models.Country {
taxInstances := []*geo_models.TaxInstance{}
for _, itm := range obj.TaxInstances {
taxInstances = append(taxInstances, itm.marshalToSwagger())
}
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,
}
}