|
@@ -1989,7 +1989,7 @@ func (e *StockTemplate) StockInquiryList(c *dto.StockStatListReq, deptId int) (l
|
|
|
whereSql += " AND m_info.enterprise_id = " + strconv.Itoa(c.EnterpriseID)
|
|
|
}
|
|
|
if len(c.BatchNumber) > 0 {
|
|
|
- whereSql += " AND m_info.batch_number = " + c.BatchNumber
|
|
|
+ whereSql += " AND m_info.batch_number = '" + c.BatchNumber+ "'"
|
|
|
}
|
|
|
if len(c.StartDate) > 0 {
|
|
|
whereSql += " AND m_info.expiry_date >= '" + c.StartDate + "'"
|
|
@@ -2049,6 +2049,64 @@ func (e *StockTemplate) StockInquiryList(c *dto.StockStatListReq, deptId int) (l
|
|
|
return list, count, nil
|
|
|
|
|
|
}
|
|
|
+func (e *StockTemplate) GetStockInquiry(c *dto.GetStockStatReq, deptId int) (res map[string]interface{}, err error) {
|
|
|
+
|
|
|
+ mtable := models.GetMedicineInfoTableName(deptId)
|
|
|
+ whereSql := ""
|
|
|
+ if c.ProductID > 0 {
|
|
|
+ whereSql += " AND m_info.product_id = " + strconv.Itoa(c.ProductID)
|
|
|
+ }
|
|
|
+ if c.EnterpriseID > 0 {
|
|
|
+ whereSql += " AND m_info.enterprise_id = " + strconv.Itoa(c.EnterpriseID)
|
|
|
+ }
|
|
|
+ if c.SpecID > 0 {
|
|
|
+ whereSql += " AND m_info.spec_id = '" + strconv.Itoa(c.SpecID)
|
|
|
+ }
|
|
|
+ if len(c.BatchNumber) > 0 {
|
|
|
+ whereSql += " AND m_info.batch_number = '" + c.BatchNumber+ "'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(whereSql) > 0 {
|
|
|
+ whereSql = " WHERE " + strings.TrimLeft(whereSql, " AND ")
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ sql := "SELECT mi.* FROM (SELECT medicine_id,MAX(id) AS latest_id FROM medicine_inventory WHERE dept_id = " + strconv.Itoa(deptId) + " AND deleted_at is null GROUP BY medicine_id) AS mi_latest " +
|
|
|
+ "JOIN medicine_inventory AS mi ON mi.medicine_id=mi_latest.medicine_id AND mi.id=mi_latest.latest_id " +
|
|
|
+ "LEFT JOIN " + mtable + " AS m_info ON mi.medicine_id=m_info.id" + whereSql + " order by m_info.expiry_date ;"
|
|
|
+
|
|
|
+ err = db.DB.Raw(sql).Last(&res).Error
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("db error: %s ", err)
|
|
|
+ return res, err
|
|
|
+ }
|
|
|
+
|
|
|
+ //models.InitBasicData(deptId)
|
|
|
+ //if id, ok := res[models.FieldProductID]; ok {
|
|
|
+ // res[models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
|
|
|
+ //}
|
|
|
+ //if id, ok := res[models.FieldEnterpriseID]; ok {
|
|
|
+ // res[models.FieldEnterpriseName] = models.Read_Enterprise_Get(utils.ToInt(id))
|
|
|
+ //}
|
|
|
+ //if id, ok := res[models.FieldSpecID]; ok {
|
|
|
+ // res[models.FieldSpecName] = models.Read_Spec_Get(utils.ToInt(id))
|
|
|
+ //}
|
|
|
+ //if id, ok := res[models.FieldUnitID]; ok {
|
|
|
+ // res[models.FieldUnitName] = models.Read_Unit_Get(utils.ToInt(id))
|
|
|
+ //}
|
|
|
+ //if id, ok := res[models.FieldDosageFormID]; ok {
|
|
|
+ // if utils.ToInt(id) == 0 {
|
|
|
+ // res[models.FieldDosageFormID] = nil
|
|
|
+ // } else {
|
|
|
+ // res[models.FieldDosageFormName] = models.Read_DosageForm_Get(utils.ToInt(id))
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //res[models.FieldExpiryDate] = utils.ToDate(res[models.FieldExpiryDate])
|
|
|
+ //res[models.FieldProducedDate] = utils.ToDate(res[models.FieldProducedDate])
|
|
|
+
|
|
|
+ return res, nil
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
// 库存查询excel
|
|
|
func (e *StockTemplate) StockInquiryExcel(c *dto.StockStatListReq, deptId int) (list []map[string]interface{}, err error) {
|