From 19bbf202e4f38f067db9c2800e764512ad67dcd9 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 27 六月 2024 22:34:32 +0800
Subject: [PATCH] 当月的统计报表(未至库存结算时间点)支持实时查询入库数量出库数量期末数量

---
 utils/util.go |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/utils/util.go b/utils/util.go
index 61c9c1c..c1b4d52 100644
--- a/utils/util.go
+++ b/utils/util.go
@@ -3,9 +3,31 @@
 import (
 	"github.com/google/uuid"
 	"strings"
+	"time"
 )
 
 func GetUUID() string {
 	s := uuid.New().String()
 	return strings.ReplaceAll(s, "-", "")
 }
+
+// GetLastMonthPeriod 杩斿洖涓婁釜鏈堢殑鏈堝垵鏃堕棿鍜屾湀鏈椂闂�
+func GetLastMonthPeriod() (time.Time, time.Time) {
+	// 鑾峰彇褰撳墠鏃堕棿
+	now := time.Now()
+
+	// 璁$畻涓婁釜鏈堢殑骞翠唤鍜屾湀浠�
+	lastMonth := now.AddDate(0, -1, 0)
+	lastYear, lastMonthNum, _ := lastMonth.Date()
+
+	// 鑾峰彇涓婁釜鏈堢殑绗竴澶╃殑鏃ユ湡锛堝嵆涓婁釜鏈堟湀鍒濓級
+	firstDayOfLastMonth := time.Date(lastYear, lastMonthNum, 1, 0, 0, 0, 0, now.Location())
+
+	// 鑾峰彇鏈湀绗竴澶╃殑鏃ユ湡锛堝嵆鏈湀鏈堝垵锛�
+	firstDayOfThisMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
+
+	// 涓婁釜鏈堟湀鏈椂闂村嵆涓烘湰鏈堟湀鍒濆噺鍘讳竴绉�
+	lastDayOfLastMonth := firstDayOfThisMonth.Add(-time.Second)
+
+	return firstDayOfLastMonth, lastDayOfLastMonth
+}

--
Gitblit v1.8.0