浏览代码

add:拆零入库

zoie 1 年之前
父节点
当前提交
01f7d2c60b
共有 3 个文件被更改,包括 88 次插入3 次删除
  1. 4 3
      controllers/stock_template.go
  2. 34 0
      models/medicine_template.go
  3. 50 0
      services/stock_template.go

+ 4 - 3
controllers/stock_template.go

@@ -22,6 +22,7 @@ import (
 	"github.com/xuri/excelize/v2"
 	"gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
 	"image/jpeg"
+	"log"
 	"path"
 	"strings"
 
@@ -1767,7 +1768,7 @@ func (c StockTemplateController) TransportRecordPdf(reqData models.TransportReco
 		// 获取药品信息图片
 		img, err := imgSvc.Get(deptId, rootId, product, enterprise, spec, batchNumber)
 		if err == nil && img.Img != "" {
-			fmt.Println("==============", img.Img)
+			log.Println("==============", img.Img)
 			imgList = append(imgList, img.Img)
 		}
 	}
@@ -1993,7 +1994,7 @@ func (c StockTemplateController) TransportRecordPdf(reqData models.TransportReco
 	pdf.Text("收货单位:")
 	txtWd, _ = pdf.MeasureTextWidth("收货单位:")
 	pdf.SetXY(curx+txtWd, y)
-	pdf.Text(beegouser.GetDeptName(c.Ctx))
+	pdf.Text(reqData.ReceivingUnit)
 	pdf.Line(57, y+3, 207, y+3)
 
 	pdf.SetXY(300, y)
@@ -2393,7 +2394,7 @@ func (c StockTemplateController) GetBarCodeInfo() {
 		return
 	}
 
-	list, err := s.StockTemplateTransportRecordWord(&code.Data, code.Data.DeptID)
+	list, err := s.StockTemplateTransportRecordWord2(&code.Data, code.Data.DeptID)
 	if err != nil {
 		c.Error(500, err, err.Error())
 		return

+ 34 - 0
models/medicine_template.go

@@ -84,6 +84,40 @@ func GetInitMedicineTemplateSql(deptId int) string {
 	return sqlStmt
 }
 
+// 获取系统初始化字段
+func GetMedicineInfoFieldIsSysInit(field string) bool {
+	switch field {
+	case "product_id":
+		return true
+	case "enterprise_id":
+		return true
+	case "spec_id":
+		return true
+	case "unit_id":
+		return true
+	case "dosage_form_id":
+		return true
+	case "batch_number":
+		return true
+	case "expiry_date":
+		return true
+	case "produced_date":
+		return true
+	case "approval_number":
+		return true
+	case "qualification_number":
+		return true
+	//case "unit_price":
+	//	return true
+	//case "qrcode":
+	//	return true
+	default:
+		return false
+
+	}
+
+}
+
 //purchase_unit_price DECIMAL(10,2) comment '购进单价',
 //sales_unit_price DECIMAL(10,2) comment '销售单价'
 

+ 50 - 0
services/stock_template.go

@@ -439,7 +439,15 @@ func (e *StockTemplate) StockTemplateInScanCode(req *dto.BatchStockTemplateInIns
 		if medicineInfo == nil {
 			sql := "INSERT INTO " + models.GetMedicineInfoTableName(req.DeptId) + " SET "
 			for k, v := range c.MedicineInfo {
+				// 不是系统初始化字段
+				if !models.GetMedicineInfoFieldIsSysInit(k) {
+					continue
+				}
+				if v == nil {
+					continue
+				}
 				sql += fmt.Sprintf("`%s`='%v',", k, v)
+
 			}
 			sql += fmt.Sprintf("`%s`='%v',", "unit_price", c.UnitPrice)
 			sql += fmt.Sprintf("`%s`='%v',", "qrcode", c.Qrcode)
@@ -1494,6 +1502,7 @@ func (e *StockTemplate) StockTemplateInList(c *dto.StockTemplateInPageReq, deptI
 		).
 		Joins("left join " + mtable + " on stock_in.medicine_id = " + mtable + ".id").
 		Where(whereSql).
+		Order("stock_in.date desc,stock_in.id desc").
 		Scan(&list).Limit(-1).Offset(-1).
 		Count(&count).Error
 	if err != nil {
@@ -1561,6 +1570,7 @@ func (e *StockTemplate) StockTemplateOutList(c *dto.StockTemplateOutPageReq, dep
 		).
 		Joins("left join " + mtable + " on stock_out.medicine_id = " + mtable + ".id").
 		Where(whereSql).
+		Order("stock_out.date desc,stock_out.id desc").
 		Scan(&list).Limit(-1).Offset(-1).
 		Count(&count).Error
 	if err != nil {
@@ -2097,3 +2107,43 @@ func (e *StockTemplate) StockTemplateTransportRecordWord(c *models.TransportReco
 	return list, nil
 
 }
+func (e *StockTemplate) StockTemplateTransportRecordWord2(c *models.TransportRecord, deptId int) (list []map[string]interface{}, err error) {
+
+	mtable := models.GetMedicineInfoTableName(deptId)
+	whereSql := "stock_out.dept_id = " + strconv.Itoa(deptId) + " AND stock_out.deleted_at is null"
+	if c.ProductID > 0 {
+		whereSql += " AND " + mtable + ".product_id = " + strconv.Itoa(c.ProductID)
+	}
+	if len(c.Date) > 0 {
+		whereSql += " AND stock_out.date = '" + c.Date + "'"
+	}
+	if len(c.ReceivingUnit) > 0 {
+		whereSql += " AND stock_out.receiving_unit like '%" + c.ReceivingUnit + "%'"
+	}
+	err = db.DB.Table("stock_out").
+		Select(mtable + ".*,stock_out.quantity as quantity").
+		Joins("left join " + mtable + " on stock_out.medicine_id = " + mtable + ".id").
+		Where(whereSql).
+		Scan(&list).Error
+	if err != nil {
+		logs.Error("db error: %s ", err)
+		return list, global.GetFailedErr
+	}
+	models.InitBasicData(deptId)
+	for i := 0; i < len(list); i++ {
+		if id, ok := list[i][models.FieldProductID]; ok {
+			list[i][models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
+		}
+		if id, ok := list[i][models.FieldEnterpriseID]; ok {
+			list[i][models.FieldEnterpriseName] = models.Read_Enterprise_Get(utils.ToInt(id))
+		}
+		if id, ok := list[i][models.FieldSpecID]; ok {
+			list[i][models.FieldSpecName] = models.Read_Spec_Get(utils.ToInt(id))
+		}
+		if id, ok := list[i][models.FieldUnitID]; ok {
+			list[i][models.FieldUnitName] = models.Read_Unit_Get(utils.ToInt(id))
+		}
+	}
+	return list, nil
+
+}