lib/app/glaccount-helpers.go

75 lines
2.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/ledger/ledger_models"
"github.com/google/uuid"
)
2021-01-17 21:49:00 +00:00
func UnMarshalGlAccount(s *ledger_models.GlAccount) *GlAccount {
2021-01-14 06:36:35 +00:00
if s.ID == "" {
s.ID = uuid.New().String()
}
createdDate, err1 := time.Parse(dateTimeFormat, s.CreatedDate)
lastModifiedDate, err2 := time.Parse(dateTimeFormat, s.LastModifiedDate)
return &GlAccount{
ID: s.ID,
AccountID: s.AccountID,
AccountLevel: s.AccountLevel,
AccountName: s.AccountName,
AccountNumber: s.AccountNumber,
AccountSign: s.AccountSign,
AccountType: s.AccountType,
CreatedByID: s.CreatedByID,
Description: s.Description,
IsActive: s.IsActive,
IsBankAccount: s.IsBankAccount,
IsSummary: s.IsSummary,
LastModifiedByID: s.LastModifiedByID,
Name: s.Name,
ParentFK: s.ParentFK,
ParentGlAccountID: s.ParentGLAccountID,
Ref: s.Ref,
Status: s.Status,
TenantID: s.TenantID,
CreatedDate: sql.NullTime{
Time: createdDate,
Valid: err1 == nil,
},
LastModifiedDate: sql.NullTime{
Time: lastModifiedDate,
Valid: err2 == nil,
},
}
}
2021-01-18 03:13:54 +00:00
// MarshalToSwagger encodes first class object
2021-01-14 06:36:35 +00:00
func (obj *GlAccount) MarshalToSwagger() *ledger_models.GlAccount {
return &ledger_models.GlAccount{
ID: obj.ID,
AccountID: obj.AccountID,
AccountLevel: obj.AccountLevel,
AccountName: obj.AccountName,
AccountNumber: obj.AccountNumber,
AccountSign: obj.AccountSign,
AccountType: obj.AccountType,
Balances: []*ledger_models.GlBalance{},
CreatedByID: obj.CreatedByID,
CreatedDate: obj.CreatedDate.Time.Format(dateTimeFormat),
Description: obj.Description,
IsActive: obj.IsActive,
IsBankAccount: obj.IsBankAccount,
IsSummary: obj.IsSummary,
LastModifiedByID: obj.LastModifiedByID,
LastModifiedDate: obj.LastModifiedDate.Time.Format(dateTimeFormat),
Name: obj.Name,
ParentFK: obj.ParentFK,
ParentGLAccountID: obj.ParentGlAccountID,
Ref: obj.Ref,
Status: obj.Status,
TenantID: obj.TenantID,
}
}