|
@@ -284,18 +284,27 @@ func (e *StockTemplate) StockTemplateInEdit(c *dto.StockTemplateInEditReq) error
|
|
|
}
|
|
|
|
|
|
// 修改入库信息
|
|
|
- stockInRecord := models.StockIn{
|
|
|
- MedicineID: medicineInfoId,
|
|
|
- Quantity: c.Quantity,
|
|
|
- UnitPrice: c.UnitPrice,
|
|
|
- Operator: c.Operator,
|
|
|
- ForwardingUnit: c.ForwardingUnit,
|
|
|
- Date: c.Date,
|
|
|
- ControlBy: model2.ControlBy{
|
|
|
- UpdateBy: c.UpdateBy,
|
|
|
- },
|
|
|
- }
|
|
|
- err = tx.Where("id = ?", c.Id).Updates(&stockInRecord).Error
|
|
|
+ //stockInRecord := models.StockIn{
|
|
|
+ // MedicineID: medicineInfoId,
|
|
|
+ // Quantity: c.Quantity,
|
|
|
+ // UnitPrice: c.UnitPrice,
|
|
|
+ // Operator: c.Operator,
|
|
|
+ // ForwardingUnit: c.ForwardingUnit,
|
|
|
+ // Date: c.Date,
|
|
|
+ // ControlBy: model2.ControlBy{
|
|
|
+ // UpdateBy: c.UpdateBy,
|
|
|
+ // },
|
|
|
+ //}
|
|
|
+ stockInRecordMap := map[string]interface{}{
|
|
|
+ "medicine_id": medicineInfoId,
|
|
|
+ "quantity": c.Quantity,
|
|
|
+ "unit_price": c.UnitPrice,
|
|
|
+ "operator": c.Operator,
|
|
|
+ "forwarding_unit": c.ForwardingUnit,
|
|
|
+ "date": c.Date,
|
|
|
+ "update_by": c.UpdateBy,
|
|
|
+ }
|
|
|
+ err = tx.Model(models.StockIn{}).Where("id = ?", c.Id).Updates(stockInRecordMap).Error
|
|
|
if err != nil {
|
|
|
tx.Rollback()
|
|
|
logs.Error("db error: %s", err)
|
|
@@ -606,18 +615,30 @@ func (e *StockTemplate) StockTemplateOutEdit(c *dto.StockTemplateOutEditReq) err
|
|
|
}
|
|
|
|
|
|
// 修改入库信息
|
|
|
- stockOutRecord := models.StockOut{
|
|
|
- MedicineID: medicineInfoId,
|
|
|
- Quantity: c.Quantity,
|
|
|
- UnitPrice: c.UnitPrice,
|
|
|
- Operator: c.Operator,
|
|
|
- ReceivingUnit: c.ReceivingUnit,
|
|
|
- Date: c.Date,
|
|
|
- ControlBy: model2.ControlBy{
|
|
|
- UpdateBy: c.UpdateBy,
|
|
|
- },
|
|
|
+ //stockOutRecord := models.StockOut{
|
|
|
+ // MedicineID: medicineInfoId,
|
|
|
+ // Quantity: c.Quantity,
|
|
|
+ // UnitPrice: c.UnitPrice,
|
|
|
+ // Operator: c.Operator,
|
|
|
+ // ReceivingUnit: c.ReceivingUnit,
|
|
|
+ // Date: c.Date,
|
|
|
+ // ControlBy: model2.ControlBy{
|
|
|
+ // UpdateBy: c.UpdateBy,
|
|
|
+ // },
|
|
|
+ //}
|
|
|
+ //err = tx.Where("id = ?", c.Id).Updates(&stockOutRecord).Error
|
|
|
+
|
|
|
+ stockOutRecordMap := map[string]interface{}{
|
|
|
+ "medicine_id": medicineInfoId,
|
|
|
+ "quantity": c.Quantity,
|
|
|
+ "unit_price": c.UnitPrice,
|
|
|
+ "operator": c.Operator,
|
|
|
+ "receiving_unit": c.ReceivingUnit,
|
|
|
+ "date": c.Date,
|
|
|
+ "update_by": c.UpdateBy,
|
|
|
}
|
|
|
- err = tx.Where("id = ?", c.Id).Updates(&stockOutRecord).Error
|
|
|
+ err = tx.Model(models.StockOut{}).Where("id = ?", c.Id).Updates(stockOutRecordMap).Error
|
|
|
+
|
|
|
if err != nil {
|
|
|
tx.Rollback()
|
|
|
logs.Error("db error: %s", err)
|
|
@@ -832,6 +853,7 @@ func (e *StockTemplate) BatchStockTemplateOut(req *dto.BatchStockTemplateOutInse
|
|
|
return global.CreateFailedErr
|
|
|
}
|
|
|
if mi.Balance < c.Quantity {
|
|
|
+ tx.Rollback()
|
|
|
return errors.New(fmt.Sprintf("库存量【%d】小于出库库存量【%d】,出库失败", mi.Balance, c.Quantity))
|
|
|
}
|
|
|
|
|
@@ -946,10 +968,18 @@ func (e *StockTemplate) StockTemplateInList(c *dto.StockTemplateInPageReq, deptI
|
|
|
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))
|
|
|
+ if utils.ToInt(id) == 0 {
|
|
|
+ list[i][models.FieldUnitID] = nil
|
|
|
+ } else {
|
|
|
+ list[i][models.FieldUnitName] = models.Read_Unit_Get(utils.ToInt(id))
|
|
|
+ }
|
|
|
}
|
|
|
if id, ok := list[i][models.FieldDosageFormID]; ok {
|
|
|
- list[i][models.FieldDosageFormName] = models.Read_DosageForm_Get(utils.ToInt(id))
|
|
|
+ if utils.ToInt(id) == 0 {
|
|
|
+ list[i][models.FieldDosageFormID] = nil
|
|
|
+ } else {
|
|
|
+ list[i][models.FieldDosageFormName] = models.Read_DosageForm_Get(utils.ToInt(id))
|
|
|
+ }
|
|
|
}
|
|
|
if date, ok := list[i][models.FieldExpiryDate]; ok && date != nil {
|
|
|
list[i][models.FieldExpiryDate] = date.(time.Time).Format("2006-01-02")
|
|
@@ -1006,11 +1036,20 @@ func (e *StockTemplate) StockTemplateOutList(c *dto.StockTemplateOutPageReq, dep
|
|
|
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))
|
|
|
+ if utils.ToInt(id) == 0 {
|
|
|
+ list[i][models.FieldUnitID] = nil
|
|
|
+ } else {
|
|
|
+ list[i][models.FieldUnitName] = models.Read_Unit_Get(utils.ToInt(id))
|
|
|
+ }
|
|
|
}
|
|
|
if id, ok := list[i][models.FieldDosageFormID]; ok {
|
|
|
- list[i][models.FieldDosageFormName] = models.Read_DosageForm_Get(utils.ToInt(id))
|
|
|
+ if utils.ToInt(id) == 0 {
|
|
|
+ list[i][models.FieldDosageFormID] = nil
|
|
|
+ } else {
|
|
|
+ list[i][models.FieldDosageFormName] = models.Read_DosageForm_Get(utils.ToInt(id))
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if date, ok := list[i][models.FieldExpiryDate]; ok && date != nil {
|
|
|
list[i][models.FieldExpiryDate] = date.(time.Time).Format("2006-01-02")
|
|
|
}
|
|
@@ -1136,7 +1175,7 @@ func (e *StockTemplate) StockUnitList(c *dto.StockUnitListReq, deptId int) (list
|
|
|
if len(c.Name) > 0 {
|
|
|
whereSql += " AND forwarding_unit like '%" + c.Name + "%'"
|
|
|
}
|
|
|
- whereSql += " AND forwarding_unit is not null"
|
|
|
+ whereSql += " AND forwarding_unit is not null AND forwarding_unit != ''"
|
|
|
err = db.DB.Table("stock_in").
|
|
|
Distinct("forwarding_unit").
|
|
|
Where(whereSql).
|
|
@@ -1150,7 +1189,7 @@ func (e *StockTemplate) StockUnitList(c *dto.StockUnitListReq, deptId int) (list
|
|
|
if len(c.Name) > 0 {
|
|
|
whereSql += " AND receiving_unit like '%" + c.Name + "%'"
|
|
|
}
|
|
|
- whereSql += " AND receiving_unit is not null"
|
|
|
+ whereSql += " AND receiving_unit is not null AND receiving_unit != ''"
|
|
|
|
|
|
err = db.DB.Table("stock_out").
|
|
|
Distinct("receiving_unit").
|
|
@@ -1169,7 +1208,7 @@ func (e *StockTemplate) StockUnitList(c *dto.StockUnitListReq, deptId int) (list
|
|
|
forwarding_unit, receiving_unit := []string{}, []string{}
|
|
|
err = db.DB.Table("medicine_inventory").
|
|
|
Distinct("forwarding_unit").
|
|
|
- Where(whereSql + " AND forwarding_unit is not null").
|
|
|
+ Where(whereSql + " AND forwarding_unit is not null AND forwarding_unit != ''").
|
|
|
Scan(&forwarding_unit).Error
|
|
|
if err != nil {
|
|
|
logs.Error("db error: %s ", err)
|
|
@@ -1177,7 +1216,7 @@ func (e *StockTemplate) StockUnitList(c *dto.StockUnitListReq, deptId int) (list
|
|
|
}
|
|
|
err = db.DB.Table("medicine_inventory").
|
|
|
Distinct("receiving_unit").
|
|
|
- Where(whereSql + " AND receiving_unit is not null").
|
|
|
+ Where(whereSql + " AND receiving_unit is not null AND receiving_unit != ''").
|
|
|
Scan(&receiving_unit).Error
|
|
|
if err != nil {
|
|
|
logs.Error("db error: %s ", err)
|
|
@@ -1211,7 +1250,7 @@ func (e *StockTemplate) StockOperatorList(c *dto.StockOperatorListReq, deptId in
|
|
|
func (e *StockTemplate) StockInquiryList(c *dto.StockStatListReq, deptId int) (list []map[string]interface{}, count int64, err error) {
|
|
|
|
|
|
mtable := models.GetMedicineInfoTableName(deptId)
|
|
|
- whereSql := " WHERE mi.dept_id = " + strconv.Itoa(deptId) + " AND deleted_at is null"
|
|
|
+ whereSql := " WHERE mi.dept_id = " + strconv.Itoa(deptId)
|
|
|
if c.ProductID > 0 {
|
|
|
whereSql += " AND m_info.product_id = " + strconv.Itoa(c.ProductID)
|
|
|
}
|
|
@@ -1232,11 +1271,11 @@ func (e *StockTemplate) StockInquiryList(c *dto.StockStatListReq, deptId int) (l
|
|
|
//sql := "SELECT * FROM (SELECT a.* FROM (SELECT * FROM medicine_inventory ORDER BY id DESC LIMIT 100) a GROUP BY a.medicine_id) b " +
|
|
|
// "LEFT JOIN " + mtable + " ON b.medicine_id=" + mtable + ".id WHERE " + whereSql
|
|
|
|
|
|
- sql := "SELECT mi.*,m_info.* FROM (SELECT medicine_id,MAX(id) AS latest_id FROM medicine_inventory GROUP BY medicine_id) AS mi_latest " +
|
|
|
+ sql := "SELECT mi.*,m_info.* FROM (SELECT medicine_id,MAX(id) AS latest_id FROM medicine_inventory WHERE 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 limit ? offset ?;"
|
|
|
|
|
|
- sqlWhereCount := "SELECT COUNT(1) FROM (SELECT medicine_id,MAX(id) AS latest_id FROM medicine_inventory GROUP BY medicine_id) AS mi_latest " +
|
|
|
+ sqlWhereCount := "SELECT COUNT(1) FROM (SELECT medicine_id,MAX(id) AS latest_id FROM medicine_inventory WHERE 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
|
|
|
|