Add Expiring Soon
This commit is contained in:
parent
c1ae2fd14a
commit
2e1b62e33a
@ -34,6 +34,7 @@ type LicenseGetAll struct {
|
|||||||
PartnerName string `gorm:"type:varchar(255);not null"`
|
PartnerName string `gorm:"type:varchar(255);not null"`
|
||||||
LicenseStatus string `gorm:"type:string(255);not null"`
|
LicenseStatus string `gorm:"type:string(255);not null"`
|
||||||
CreatedByName string `gorm:"type:string(255);not null"`
|
CreatedByName string `gorm:"type:string(255);not null"`
|
||||||
|
DaysToExpire int64 `gorm:"type:bigint"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (License) TableName() string {
|
func (License) TableName() string {
|
||||||
|
|||||||
@ -16,6 +16,7 @@ type License struct {
|
|||||||
UpdatedBy int64 `json:"updated_by"`
|
UpdatedBy int64 `json:"updated_by"`
|
||||||
PartnerName string `json:"partner_name"`
|
PartnerName string `json:"partner_name"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
DaysToExpire int64 `json:"days_to_expire"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LicenseList struct {
|
type LicenseList struct {
|
||||||
@ -67,4 +68,5 @@ func (r *License) FromEntityGetAll(e *entity.LicenseGetAll) {
|
|||||||
r.UpdatedBy = e.UpdatedBy
|
r.UpdatedBy = e.UpdatedBy
|
||||||
r.PartnerName = e.PartnerName
|
r.PartnerName = e.PartnerName
|
||||||
r.Status = e.LicenseStatus
|
r.Status = e.LicenseStatus
|
||||||
|
r.DaysToExpire = e.DaysToExpire
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,10 +58,11 @@ func (r *LicenseRepository) GetAll(ctx context.Context, limit, offset int, statu
|
|||||||
Table("licenses").
|
Table("licenses").
|
||||||
Select(`licenses.*, partners.name as partner_name,
|
Select(`licenses.*, partners.name as partner_name,
|
||||||
CASE
|
CASE
|
||||||
WHEN licenses.end_date < CURRENT_DATE THEN 'Expired'
|
WHEN licenses.end_date < CURRENT_DATE THEN 'EXPIRED'
|
||||||
WHEN licenses.end_date < CURRENT_DATE + INTERVAL '30 days' THEN '< 30 days'
|
WHEN licenses.end_date < CURRENT_DATE + INTERVAL '30 days' THEN 'EXPIRING_SOON'
|
||||||
ELSE 'Active'
|
ELSE 'ACTIVE'
|
||||||
END as license_status,
|
END as license_status,
|
||||||
|
(GREATEST(licenses.end_date - CURRENT_DATE, 0)) as days_to_expire,
|
||||||
users.name as created_by_name`).
|
users.name as created_by_name`).
|
||||||
Joins("LEFT JOIN partners ON licenses.partner_id = partners.id").
|
Joins("LEFT JOIN partners ON licenses.partner_id = partners.id").
|
||||||
Joins("LEFT JOIN users ON licenses.created_by = users.id").
|
Joins("LEFT JOIN users ON licenses.created_by = users.id").
|
||||||
@ -87,7 +88,7 @@ func (r *LicenseRepository) GetAll(ctx context.Context, limit, offset int, statu
|
|||||||
|
|
||||||
func (r *LicenseRepository) FindByPartnerIDMaxEndDate(ctx context.Context, partnerID *int64) (*entity.LicenseDB, error) {
|
func (r *LicenseRepository) FindByPartnerIDMaxEndDate(ctx context.Context, partnerID *int64) (*entity.LicenseDB, error) {
|
||||||
var licenseDB entity.LicenseDB
|
var licenseDB entity.LicenseDB
|
||||||
if err := r.db.WithContext(ctx).
|
if err := r.db.Debug().WithContext(ctx).
|
||||||
Where("partner_id = ?", partnerID).
|
Where("partner_id = ?", partnerID).
|
||||||
Order("end_date DESC").
|
Order("end_date DESC").
|
||||||
First(&licenseDB).Error; err != nil {
|
First(&licenseDB).Error; err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user