utils

package
v1.0.66 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AmountRound

func AmountRound(x float64, decimalPlace int) float64

func CalculateDistance

func CalculateDistance(lat1, lng1, lat2, lng2 float64) float64

func CalculateExcludeTax

func CalculateExcludeTax(subtotalExclTax float64, taxRate float64) float64

func CalculateIncludeTax

func CalculateIncludeTax(subtotalInclTax float64, taxRate float64) float64

func ContainsString

func ContainsString(arr []string, str string) bool

func CreateSlugFromTitle

func CreateSlugFromTitle(title string) string

func CreateUsernameFromFullName

func CreateUsernameFromFullName(fullName string) string

CreateUsernameFromFullName creates a username from a full name

func FileHeaderToBytes

func FileHeaderToBytes(fileHeader *multipart.FileHeader) ([]byte, error)

func FilenameTrimSpace

func FilenameTrimSpace(filename string) string

func FixRequest

func FixRequest(request *http.Request)

func FormatCurrency

func FormatCurrency(amount float64) string

func FormatDateIndonesian

func FormatDateIndonesian(date time.Time) string

func FormatFloatWithThousandSeparator

func FormatFloatWithThousandSeparator(number float64) string

func FormatRupiah

func FormatRupiah(amount float64) string

func GenTemplate

func GenTemplate(layout, body string, data any) (string, error)

func GenerateHTMLPDF

func GenerateHTMLPDF(dataHtml string, footer string) ([]byte, error)

func GenerateInvoicePDF

func GenerateInvoicePDF(data InvoicePDF, templatePath string, footer string) ([]byte, error)

func GenerateJWT

func GenerateJWT(userID string, expiredAt int64, secretKey string) (string, error)

func GenerateOrderReceipt

func GenerateOrderReceipt(data ReceiptData, templatePath string) ([]byte, error)

func GeneratePDF

func GeneratePDF(wkhtmltopdfPath, footer, html string) ([]byte, error)

GeneratePDF generates a PDF file from an HTML string.

Parameters:

  • wkhtmltopdfPath: The file path for the wkhtmltopdf binary. If not empty, it sets the path to the wkhtmltopdf executable.
  • footer: The footer text to be added to each page of the PDF. If empty, no footer is added.
  • html: The HTML content to be converted into a PDF.

Returns:

  • A byte slice containing the generated PDF.
  • An error if there is an issue during PDF generation.

This function sets various options for the PDF, such as enabling local file access, setting page margins to zero, and disabling smart shrinking. It also configures footer settings if a footer is provided. It supports customization of the PDF size, DPI, and orientation.

func GenerateRandomNumber

func GenerateRandomNumber(length int) string

func GenerateRandomString

func GenerateRandomString(length int) string

func GetCurrentMachineID added in v1.0.64

func GetCurrentMachineID() string

func GetMimeType

func GetMimeType(url string) string

func HandleDBError

func HandleDBError(err error) error

func InitLog added in v1.0.66

func InitLog()

func IntegerToRoman

func IntegerToRoman(number int) string

func IsValidEmail

func IsValidEmail(email string) bool

func LogJson

func LogJson(data interface{})

func LogPrint

func LogPrint(v ...any)

LogPrint print error message with RFC3339 timestamp. This function is used to log error message from goroutine.

func LogPrintf

func LogPrintf(format string, v ...any)

func NumToAlphabet

func NumToAlphabet(num int) string

func ParseDate

func ParseDate(dateStr string) (time.Time, error)

func ParsePhoneNumber

func ParsePhoneNumber(value string, country string) string

func ParseTime

func ParseTime(hm string) time.Time

func PtrFloat64

func PtrFloat64(value float64) *float64

Helper function to return pointer to a float64

func PtrInt

func PtrInt(value int) *int

func RandString

func RandString(n int, uppercase bool) string

RandString generates a random string of length n

func RandomStringNumber

func RandomStringNumber(n int, uppercase bool) string

RandomStringNumber generates a random string of length n including numbers

func ReduceMap

func ReduceMap(data map[string]interface{}, keys []string) map[string]interface{}

func RenderFromDBTemplate

func RenderFromDBTemplate(tmplString string, data any) (string, error)

func SaveJson

func SaveJson(data interface{})

func StringOrEmpty

func StringOrEmpty(s *string) string

func ToJsonString added in v1.0.56

func ToJsonString(data interface{}) string

func URLify

func URLify(str string) string

func Uuid

func Uuid() string

func ValidateEmail

func ValidateEmail(email string) bool

Types

type Contact added in v1.0.64

type Contact struct {
	Name      string
	FirstName string
	LastName  string
	Phone     string
	Email     string
}

func ParseVCardString added in v1.0.64

func ParseVCardString(vcardString string) (*Contact, error)

type InvoicePDF

type InvoicePDF struct {
	Company         InvoicePDFContact
	Number          string
	Date            string
	DueDate         string
	Items           []InvoicePDFItem
	SubTotal        string
	TotalDiscount   string
	AfterDiscount   string
	TotalTax        string
	GrandTotal      string
	InvoicePayments []InvoicePDFPayment
	Balance         string
	Paid            string
	BilledTo        InvoicePDFContact
	ShippedTo       InvoicePDFContact
	TermCondition   string
	PaymentTerms    string
	ShowCompany     bool
	ShowShipped     bool
}

type InvoicePDFContact

type InvoicePDFContact struct {
	Name    string
	Address string
	Phone   string
	Email   string
}

type InvoicePDFItem

type InvoicePDFItem struct {
	No                 int
	Description        string
	Notes              string
	Quantity           string
	UnitPrice          string
	UnitName           string
	Total              string
	SubTotal           string
	SubtotalBeforeDisc string
	TotalDiscount      string
	DiscountPercent    string
	TaxAmount          string
	TaxPercent         string
	TaxName            string
}

type InvoicePDFPayment

type InvoicePDFPayment struct {
	Date               string
	Description        string
	PaymentMethod      string
	Amount             string
	PaymentDiscount    string
	PaymentMethodNotes string
}

type ReceiptData

type ReceiptData struct {
	Items           []ReceiptItem `json:"items"`
	SubTotalPrice   string        `json:"sub_total_price"`
	DiscountAmount  string        `json:"discount_amount"`
	TotalPrice      string        `json:"total_price"`
	CashierName     string        `json:"cashier_name"`
	Code            string        `json:"code"`
	Date            string        `json:"date"`
	CustomerName    string        `json:"customer_name"`
	MerchantName    string        `json:"merchant_name"`
	MerchantAddress string        `json:"merchant_address"`
}

type ReceiptItem

type ReceiptItem struct {
	Description     string `json:"description"`
	Quantity        string `json:"quantity"`
	Price           string `json:"price"`
	Total           string `json:"total"`
	DiscountPercent string `json:"discount_percent"`
	Notes           string `json:"notes"`
}

Directories

Path Synopsis
Package fin is a library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds and depreciation calculations.
Package fin is a library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds and depreciation calculations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL