1、修改库存调拨入库编号生成规则;
2、采购入库的计划单价和执行单价保留3位小数,方便采购处理除不尽的情况; 3、修改商品资料前端入参分页错误时,接口报错的缺陷;
This commit is contained in:
parent
2a4f28f9a8
commit
d6472c05b4
|
@ -285,6 +285,7 @@ func ErpPurchaseDetail(c *gin.Context) {
|
|||
v.EffectiveCount = nCount // 有效数量
|
||||
v.ErpCategoryID = erpCommodity.ErpCategoryId
|
||||
v.ErpCategoryName = erpCommodity.ErpCategoryName
|
||||
v.Price = math.Round(v.Price*1000) / 1000
|
||||
|
||||
commodityList = append(commodityList, v)
|
||||
}
|
||||
|
|
|
@ -509,6 +509,10 @@ func (m *ErpCommodityListReq) List() (*ErpCommodityListResp, error) {
|
|||
|
||||
// 计算分页所需的切片索引
|
||||
startIndex := page * m.PageSize
|
||||
if (len(commodities)/m.PageSize + 1) < startIndex {
|
||||
startIndex = 0
|
||||
page = 0
|
||||
}
|
||||
endIndex := (page + 1) * m.PageSize
|
||||
if endIndex > len(commodities) {
|
||||
endIndex = len(commodities)
|
||||
|
|
|
@ -782,29 +782,63 @@ func (m *ErpPurchaseOrder) IdInit() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetPurchaseInventorySn 生成入库编号
|
||||
//// GetPurchaseInventorySn 生成入库编号 有重复的情况
|
||||
//func GetPurchaseInventorySn() string {
|
||||
// count := 0
|
||||
// for {
|
||||
// if count > 5 {
|
||||
// return ""
|
||||
// }
|
||||
// nowTime := time.Now()
|
||||
// sn := nowTime.Format("060102")
|
||||
// sn += fmt.Sprintf("%d", nowTime.Unix()%100)
|
||||
// rand.Seed(nowTime.UnixNano())
|
||||
// sn += fmt.Sprintf("%d", rand.Int31n(100))
|
||||
// exist, err := QueryRecordExist(fmt.Sprintf("SELECT * FROM erp_purchase_inventory WHERE serial_number='%s'", sn))
|
||||
// if err != nil {
|
||||
// logger.Error("sn err:", logger.Field("err", err))
|
||||
// count++
|
||||
// continue
|
||||
// }
|
||||
// if err == nil && !exist {
|
||||
// return sn
|
||||
// }
|
||||
// return ""
|
||||
// }
|
||||
//}
|
||||
|
||||
var mu sync.Mutex
|
||||
|
||||
// GetPurchaseInventorySn generates a unique inventory serial number
|
||||
func GetPurchaseInventorySn() string {
|
||||
count := 0
|
||||
for {
|
||||
if count > 5 {
|
||||
return ""
|
||||
}
|
||||
const maxRetries = 5
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
for retryCount := 0; retryCount < maxRetries; retryCount++ {
|
||||
nowTime := time.Now()
|
||||
sn := nowTime.Format("060102")
|
||||
sn += fmt.Sprintf("%d", nowTime.Unix()%100)
|
||||
rand.Seed(nowTime.UnixNano())
|
||||
sn += fmt.Sprintf("%d", rand.Int31n(100))
|
||||
// 使用日期格式精确到天
|
||||
datePart := nowTime.Format("060102") // 格式为 YYMMDD
|
||||
// 生成10位随机数
|
||||
rand.Seed(nowTime.UnixNano() + int64(retryCount)) // 为了确保每次生成不同的随机数
|
||||
randomNum := rand.Int63n(1e10) // 10位随机数,范围从0到9999999999
|
||||
randomPart := fmt.Sprintf("%010d", randomNum) // 确保随机数是10位的,前面补零
|
||||
|
||||
// 拼接日期部分和随机数部分
|
||||
sn := fmt.Sprintf("%s%s", datePart, randomPart)
|
||||
|
||||
exist, err := QueryRecordExist(fmt.Sprintf("SELECT * FROM erp_purchase_inventory WHERE serial_number='%s'", sn))
|
||||
if err != nil {
|
||||
logger.Error("sn err:", logger.Field("err", err))
|
||||
count++
|
||||
continue
|
||||
}
|
||||
if err == nil && !exist {
|
||||
if !exist {
|
||||
return sn
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
return "" // 返回空字符串,如果在最大重试次数后仍未找到唯一编号
|
||||
}
|
||||
|
||||
// CheckCreateErpPurchaseOrderParam 新增采购订单-检查参数
|
||||
|
@ -1296,8 +1330,8 @@ func InventoryErpPurchaseUpdateStock(gdb *gorm.DB, list []ErpPurchaseInventory,
|
|||
ErpCategoryName: commodityInfo.ErpCategoryName,
|
||||
ErpSupplierId: purchaseOrder.ErpSupplierId,
|
||||
ErpSupplierName: purchaseOrder.ErpSupplierName,
|
||||
StaffCostPrice: tools.RoundToTwoDecimalPlaces(v.EmployeePrice - v.ImplementationPrice),
|
||||
WholesalePrice: tools.RoundToTwoDecimalPlaces(v.ImplementationPrice),
|
||||
StaffCostPrice: tools.RoundToThreeDecimalPlaces(v.EmployeePrice - v.ImplementationPrice),
|
||||
WholesalePrice: tools.RoundToThreeDecimalPlaces(v.ImplementationPrice),
|
||||
State: InStock,
|
||||
StorageType: PurchaseInventory, // 采购入库
|
||||
FirstStockTime: nowTime,
|
||||
|
@ -5740,6 +5774,9 @@ func CancelAuditUpdateStock(begin *gorm.DB, req ErpPurchaseOrder) error {
|
|||
// Inventories: inventoryList,
|
||||
//}
|
||||
|
||||
// 赋值采购退货单号
|
||||
purchaseOrder.RejectedSerialNumber = purchaseOrder.SerialNumber
|
||||
|
||||
// 按照采购退货更新库存
|
||||
err = InventoryErpPurchaseUpdateRejectStock(begin, inventoryList, purchaseOrder)
|
||||
if err != nil {
|
||||
|
|
|
@ -116,6 +116,11 @@ func RoundToTwoDecimalPlaces(num float64) float64 {
|
|||
return math.Round(num*100) / 100
|
||||
}
|
||||
|
||||
// RoundToThreeDecimalPlaces 将float64类型四舍五入保留3位小数
|
||||
func RoundToThreeDecimalPlaces(num float64) float64 {
|
||||
return math.Round(num*1000) / 1000
|
||||
}
|
||||
|
||||
// Uint32SliceContains 检查 uint32 切片中是否包含特定的值
|
||||
func Uint32SliceContains(slice []uint32, val uint32) bool {
|
||||
for _, item := range slice {
|
||||
|
|
Loading…
Reference in New Issue
Block a user