2021-01-14 06:36:35 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.tnxs.net/taxnexus/lib/api/ledger/ledger_models"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
2021-01-18 03:13:54 +00:00
|
|
|
// UnMarshalAccountingRuleset decodes swagger to first class object
|
2021-01-14 06:36:35 +00:00
|
|
|
func UnMarshalAccountingRuleset(s *ledger_models.AccountingRuleset) *AccountingRuleset {
|
|
|
|
if s.ID == "" {
|
|
|
|
s.ID = uuid.New().String()
|
|
|
|
}
|
|
|
|
createdDate, e0 := time.Parse(dateTimeFormat, s.CreatedDate)
|
|
|
|
lastModfiedDate, e1 := time.Parse(dateTimeFormat, s.LastModifiedDate)
|
|
|
|
theItems := []*AccountingRulesetItem{}
|
|
|
|
for _, itm := range s.Items {
|
|
|
|
theItems = append(theItems, &AccountingRulesetItem{
|
|
|
|
ID: itm.ID,
|
|
|
|
AccountingRuleCode: itm.AccountingRuleCode,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return &AccountingRuleset{
|
|
|
|
ID: s.ID,
|
|
|
|
AccountID: s.AccountID,
|
|
|
|
Code: s.Code,
|
|
|
|
Description: s.Description,
|
|
|
|
Items: theItems,
|
|
|
|
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 *AccountingRuleset) MarshalToSwagger() *ledger_models.AccountingRuleset {
|
2021-01-14 06:36:35 +00:00
|
|
|
theItems := []*ledger_models.AccountingRulesetItem{}
|
|
|
|
for _, itm := range obj.Items {
|
|
|
|
theItems = append(theItems,
|
|
|
|
&ledger_models.AccountingRulesetItem{
|
|
|
|
ID: itm.ID,
|
|
|
|
AccountingRuleCode: itm.AccountingRuleCode,
|
|
|
|
TenantID: itm.TenantID,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return &ledger_models.AccountingRuleset{
|
|
|
|
ID: obj.ID,
|
|
|
|
AccountID: obj.AccountID,
|
|
|
|
Code: obj.Code,
|
|
|
|
CreatedByID: obj.CreatedByID,
|
|
|
|
CreatedDate: obj.CreatedDate.Time.Format(dateTimeFormat),
|
|
|
|
Description: obj.Description,
|
|
|
|
Items: theItems,
|
|
|
|
LastModifiedByID: obj.LastModifiedByID,
|
|
|
|
LastModifiedDate: obj.LastModifiedDate.Time.Format(dateTimeFormat),
|
|
|
|
TenantID: obj.TenantID,
|
|
|
|
}
|
|
|
|
}
|