|
@@ -6124,11 +6124,32 @@ func UpdateGoodWarehouseOutById(id int64, warehouse_info_id int64, org_id int64,
|
6124
|
6124
|
return err
|
6125
|
6125
|
}
|
6126
|
6126
|
|
|
6127
|
+func UpdateNewGoodWarehouseOutById(id int64, warehouse_info_id int64, org_id int64, over_count int64, tx *gorm.DB) error {
|
|
6128
|
+
|
|
6129
|
+ err := tx.Model(models.WarehouseOutInfo{}).Where("id = ? and org_id = ? and status = 1", id, org_id).Update(map[string]interface{}{"warehouse_info_id": warehouse_info_id, "over_count": over_count}).Error
|
|
6130
|
+ if err != nil {
|
|
6131
|
+ tx.Rollback()
|
|
6132
|
+ return err
|
|
6133
|
+ }
|
|
6134
|
+ return err
|
|
6135
|
+}
|
|
6136
|
+
|
6127
|
6137
|
func ChangeMaxNumber(id int64, count int64) error {
|
6128
|
6138
|
|
6129
|
6139
|
err = XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
|
6130
|
6140
|
return err
|
6131
|
6141
|
|
|
6142
|
+}
|
|
6143
|
+
|
|
6144
|
+func ChangeNewMaxNumber(id int64, count int64, tx *gorm.DB) error {
|
|
6145
|
+
|
|
6146
|
+ err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
|
|
6147
|
+ if err != nil {
|
|
6148
|
+ tx.Rollback()
|
|
6149
|
+ return err
|
|
6150
|
+ }
|
|
6151
|
+ return err
|
|
6152
|
+
|
6132
|
6153
|
}
|
6133
|
6154
|
func ChangeMaxNumberOne(id int64, count int64) error {
|
6134
|
6155
|
|
|
@@ -6137,24 +6158,68 @@ func ChangeMaxNumberOne(id int64, count int64) error {
|
6137
|
6158
|
|
6138
|
6159
|
}
|
6139
|
6160
|
|
|
6161
|
+func ChangeNewMaxNumberOne(id int64, count int64, tx *gorm.DB) error {
|
|
6162
|
+
|
|
6163
|
+ err = XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).Updates(map[string]interface{}{"stock_max_number": count, "stock_min_number": 0}).Error
|
|
6164
|
+ if err != nil {
|
|
6165
|
+ tx.Rollback()
|
|
6166
|
+ return err
|
|
6167
|
+ }
|
|
6168
|
+ return err
|
|
6169
|
+
|
|
6170
|
+}
|
|
6171
|
+
|
6140
|
6172
|
func UpdateMinNumber(id int64, count int64) error {
|
6141
|
6173
|
|
6142
|
6174
|
err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).Update(map[string]interface{}{"stock_min_number": count}).Error
|
6143
|
6175
|
return err
|
6144
|
6176
|
}
|
6145
|
6177
|
|
|
6178
|
+func UpdateNewMinNumber(id int64, count int64, tx *gorm.DB) error {
|
|
6179
|
+
|
|
6180
|
+ err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).Update(map[string]interface{}{"stock_min_number": count}).Error
|
|
6181
|
+ if err != nil {
|
|
6182
|
+ tx.Rollback()
|
|
6183
|
+ return err
|
|
6184
|
+ }
|
|
6185
|
+ return err
|
|
6186
|
+}
|
|
6187
|
+
|
6146
|
6188
|
func FindLastDrugWarehouseOutInfo(orgid int64) (models.DrugWarehouseOutInfo, error) {
|
6147
|
6189
|
info := models.DrugWarehouseOutInfo{}
|
6148
|
6190
|
err := XTReadDB().Where("org_id = ? and status = 1", orgid).Last(&info).Error
|
6149
|
6191
|
return info, err
|
6150
|
6192
|
}
|
6151
|
6193
|
|
|
6194
|
+func FindNewLastDrugWarehouseOutInfo(orgid int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
|
|
6195
|
+ info := models.DrugWarehouseOutInfo{}
|
|
6196
|
+ err := tx.Where("org_id = ? and status = 1", orgid).Last(&info).Error
|
|
6197
|
+ if err != nil {
|
|
6198
|
+ tx.Rollback()
|
|
6199
|
+ return info, err
|
|
6200
|
+ }
|
|
6201
|
+ tx.Rollback()
|
|
6202
|
+ return info, err
|
|
6203
|
+}
|
|
6204
|
+
|
6152
|
6205
|
func GetAllGoodSumCount(goodid int64, orgid int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
|
6153
|
6206
|
|
6154
|
6207
|
err = XTReadDB().Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0 and storehouse_id = ?", goodid, orgid, storehouse_id).Find(&info).Error
|
6155
|
6208
|
return info, err
|
6156
|
6209
|
}
|
6157
|
6210
|
|
|
6211
|
+func GetNewAllGoodSumCount(goodid int64, orgid int64, storehouse_id int64, tx *gorm.DB) (info []*models.WarehousingInfo, err error) {
|
|
6212
|
+
|
|
6213
|
+ err = tx.Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0 and storehouse_id = ?", goodid, orgid, storehouse_id).Find(&info).Error
|
|
6214
|
+ if err != gorm.ErrRecordNotFound {
|
|
6215
|
+ if err != nil {
|
|
6216
|
+ tx.Rollback()
|
|
6217
|
+ return info, err
|
|
6218
|
+ }
|
|
6219
|
+ }
|
|
6220
|
+ return info, err
|
|
6221
|
+}
|
|
6222
|
+
|
6158
|
6223
|
func CreatedFlushInfo(info models.XtWarehouseFlushInfo) error {
|
6159
|
6224
|
ut := writeDb.Begin()
|
6160
|
6225
|
err := ut.Create(&info).Error
|
|
@@ -6333,6 +6398,23 @@ func ModifyGoodSumCount(storehouse_id int64, count int64, user_org_id int64, goo
|
6333
|
6398
|
return err
|
6334
|
6399
|
}
|
6335
|
6400
|
|
|
6401
|
+func ModifyNewGoodSumCount(storehouse_id int64, count int64, user_org_id int64, good_id int64, tx *gorm.DB) error {
|
|
6402
|
+
|
|
6403
|
+ err = tx.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count + ?", count)).Error
|
|
6404
|
+ if err != nil {
|
|
6405
|
+ tx.Rollback()
|
|
6406
|
+ return err
|
|
6407
|
+ }
|
|
6408
|
+
|
|
6409
|
+ err = tx.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count + ?", count)).Error
|
|
6410
|
+ if err != nil {
|
|
6411
|
+ tx.Rollback()
|
|
6412
|
+ return err
|
|
6413
|
+ }
|
|
6414
|
+
|
|
6415
|
+ return err
|
|
6416
|
+}
|
|
6417
|
+
|
6336
|
6418
|
func ModifyReduceGoodSumCount(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
|
6337
|
6419
|
|
6338
|
6420
|
ut := XTWriteDB().Begin()
|
|
@@ -6378,6 +6460,17 @@ func ModifyAddGoodSumCount(storehouse_id int64, count int64, user_org_id int64,
|
6378
|
6460
|
return err
|
6379
|
6461
|
}
|
6380
|
6462
|
|
|
6463
|
+func ModifyNewAddGoodSumCount(storehouse_id int64, count int64, user_org_id int64, good_id int64, tx *gorm.DB) error {
|
|
6464
|
+
|
|
6465
|
+ err = tx.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", count)).Error
|
|
6466
|
+ if err != nil {
|
|
6467
|
+ tx.Rollback()
|
|
6468
|
+ return err
|
|
6469
|
+ }
|
|
6470
|
+
|
|
6471
|
+ return err
|
|
6472
|
+}
|
|
6473
|
+
|
6381
|
6474
|
func UpdateSumAddCancelCount(user_org_id int64, good_id int64, storehouse_id int64, count int64) error {
|
6382
|
6475
|
|
6383
|
6476
|
ut := XTWriteDB().Begin()
|
|
@@ -6390,6 +6483,16 @@ func UpdateSumAddCancelCount(user_org_id int64, good_id int64, storehouse_id int
|
6390
|
6483
|
return err
|
6391
|
6484
|
}
|
6392
|
6485
|
|
|
6486
|
+func UpdateNewSumAddCancelCount(user_org_id int64, good_id int64, storehouse_id int64, count int64, tx *gorm.DB) error {
|
|
6487
|
+
|
|
6488
|
+ err := tx.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id = ?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_cancel_count", gorm.Expr("stock_cancel_count + ?", count)).Error
|
|
6489
|
+ if err != nil {
|
|
6490
|
+ tx.Rollback()
|
|
6491
|
+ return err
|
|
6492
|
+ }
|
|
6493
|
+ return err
|
|
6494
|
+}
|
|
6495
|
+
|
6393
|
6496
|
func UpdateSumReduceCancelCount(user_org_id int64, good_id int64, storehouse_id int64, count int64) error {
|
6394
|
6497
|
|
6395
|
6498
|
ut := XTWriteDB().Begin()
|
|
@@ -7673,12 +7776,32 @@ func CreateAutoDetail(detail models.AutomaticReduceDetail) error {
|
7673
|
7776
|
return err
|
7674
|
7777
|
}
|
7675
|
7778
|
|
|
7779
|
+func CreateNewAutoDetail(detail models.AutomaticReduceDetail, tx *gorm.DB) error {
|
|
7780
|
+
|
|
7781
|
+ err := tx.Create(&detail).Error
|
|
7782
|
+ if err != nil {
|
|
7783
|
+ tx.Rollback()
|
|
7784
|
+ return err
|
|
7785
|
+ }
|
|
7786
|
+ return err
|
|
7787
|
+}
|
|
7788
|
+
|
7676
|
7789
|
func UpdateAutomaticReduce(patient_id int64, record_date int64, good_id int64, project_id int64) error {
|
7677
|
7790
|
|
7678
|
7791
|
err := XTWriteDB().Model(&models.AutomaticReduceDetail{}).Where("patient_id = ? and record_time =? and good_id = ? and project_id = ? and status = 1", patient_id, record_date, good_id, project_id).Update(map[string]interface{}{"status": 0}).Error
|
7679
|
7792
|
return err
|
7680
|
7793
|
}
|
7681
|
7794
|
|
|
7795
|
+func UpdateNewAutomaticReduce(patient_id int64, record_date int64, good_id int64, project_id int64, tx *gorm.DB) error {
|
|
7796
|
+
|
|
7797
|
+ err := tx.Model(&models.AutomaticReduceDetail{}).Where("patient_id = ? and record_time =? and good_id = ? and project_id = ? and status = 1", patient_id, record_date, good_id, project_id).Update(map[string]interface{}{"status": 0}).Error
|
|
7798
|
+ if err != nil {
|
|
7799
|
+ tx.Rollback()
|
|
7800
|
+ return err
|
|
7801
|
+ }
|
|
7802
|
+ return err
|
|
7803
|
+}
|
|
7804
|
+
|
7682
|
7805
|
func GetDrugFLowByAdviceById(drug_id int64, patient_id int64, user_org_id int64, advice_date int64) (outInfo []*models.DrugWarehouseOutInfo, err error) {
|
7683
|
7806
|
|
7684
|
7807
|
err = XTReadDB().Where("drug_id = ? and patient_id = ? and org_id = ? and sys_record_time = ? and status= 1", drug_id, patient_id, user_org_id, advice_date).Find(&outInfo).Error
|
|
@@ -7717,7 +7840,7 @@ func NewHisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdv
|
7717
|
7840
|
if isHasWay {
|
7718
|
7841
|
//判断当天当前机构有没有创建出库单,没有则创建
|
7719
|
7842
|
out, err := FindNewDrugStockOutByIsSys(orgID, 1, record_time, tx)
|
7720
|
|
-
|
|
7843
|
+ fmt.Println(out)
|
7721
|
7844
|
houseConfig, _ := GetAllStoreHouseConfig(orgID)
|
7722
|
7845
|
if err == gorm.ErrRecordNotFound {
|
7723
|
7846
|
timeStr := time.Now().Format("2006-01-02")
|
|
@@ -7753,13 +7876,13 @@ func NewHisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdv
|
7753
|
7876
|
}
|
7754
|
7877
|
}
|
7755
|
7878
|
|
7756
|
|
- // 出库流程
|
7757
|
|
- // 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
|
|
7879
|
+ //出库流程
|
|
7880
|
+ //1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
|
7758
|
7881
|
drup, _ := FindNewBaseDrugLibRecord(orgID, advice.DrugId, tx)
|
7759
|
7882
|
if drup.ID > 0 {
|
7760
|
7883
|
prescribingNumber := advice.PrescribingNumber
|
7761
|
7884
|
|
7762
|
|
- BloodHisDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber, advice.PrescribingNumberUnit)
|
|
7885
|
+ NewBloodHisDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber, advice.PrescribingNumberUnit, tx)
|
7763
|
7886
|
|
7764
|
7887
|
} else {
|
7765
|
7888
|
return errors.New("药品信息不存在")
|
|
@@ -7769,3 +7892,704 @@ func NewHisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdv
|
7769
|
7892
|
|
7770
|
7893
|
return
|
7771
|
7894
|
}
|
|
7895
|
+
|
|
7896
|
+// 保存处方出库
|
|
7897
|
+func ConsumableNewPrescriptionDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, creator int64, count int64, tx *gorm.DB) (err error) {
|
|
7898
|
+
|
|
7899
|
+ var deliver_number int64 = 0
|
|
7900
|
+ var stock_number int64 = 0
|
|
7901
|
+ var maxNumber int64 = 0
|
|
7902
|
+
|
|
7903
|
+ deliver_number = goods.Count
|
|
7904
|
+
|
|
7905
|
+ // 根据先进先出原则,查询最先入库的批次,进行出库
|
|
7906
|
+
|
|
7907
|
+ // 如果没有对应的库存,则报错
|
|
7908
|
+ warehouse, err := FindNewFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId, tx)
|
|
7909
|
+ if err != nil {
|
|
7910
|
+ goodErrcode := models.XtGoodErrcode{
|
|
7911
|
+ UserOrgId: goods.UserOrgId,
|
|
7912
|
+ Errcode: "查询库存信息报错",
|
|
7913
|
+ GoodId: goods.GoodId,
|
|
7914
|
+ Status: 1,
|
|
7915
|
+ Ctime: time.Now().Unix(),
|
|
7916
|
+ Mtime: 0,
|
|
7917
|
+ Count: 0,
|
|
7918
|
+ StockCount: 0,
|
|
7919
|
+ Creater: creator,
|
|
7920
|
+ BatchNumberId: warehouse.ID,
|
|
7921
|
+ WarehouseOutId: 0,
|
|
7922
|
+ }
|
|
7923
|
+ CreateGoodErrcode(goodErrcode)
|
|
7924
|
+ return err
|
|
7925
|
+ }
|
|
7926
|
+
|
|
7927
|
+ stock_number = warehouse.StockCount
|
|
7928
|
+
|
|
7929
|
+ // 当库存数量大于或等于出库数量的话,则正常出库该批次
|
|
7930
|
+ if stock_number >= deliver_number {
|
|
7931
|
+ maxNumber = goods.Count
|
|
7932
|
+ warehouse.StockCount = warehouse.StockCount - maxNumber
|
|
7933
|
+ warehouse.Mtime = time.Now().Unix()
|
|
7934
|
+
|
|
7935
|
+ //扣减库存
|
|
7936
|
+ errThree := UpDateNewWarehouseInfoByStock(&warehouse, tx)
|
|
7937
|
+ if errThree != nil {
|
|
7938
|
+ goodErrcode := models.XtGoodErrcode{
|
|
7939
|
+ UserOrgId: goods.UserOrgId,
|
|
7940
|
+ Errcode: "扣减库存失败",
|
|
7941
|
+ GoodId: goods.GoodId,
|
|
7942
|
+ Status: 1,
|
|
7943
|
+ Ctime: time.Now().Unix(),
|
|
7944
|
+ Mtime: 0,
|
|
7945
|
+ Count: 0,
|
|
7946
|
+ StockCount: 0,
|
|
7947
|
+ Creater: creator,
|
|
7948
|
+ BatchNumberId: warehouse.ID,
|
|
7949
|
+ WarehouseOutId: 0,
|
|
7950
|
+ }
|
|
7951
|
+ CreateGoodErrcode(goodErrcode)
|
|
7952
|
+ return errThree
|
|
7953
|
+ }
|
|
7954
|
+
|
|
7955
|
+ //查询剩余库存
|
|
7956
|
+ goodList, _ := GetNewAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId, tx)
|
|
7957
|
+ var sum_count int64
|
|
7958
|
+ for _, item := range goodList {
|
|
7959
|
+ sum_count += item.StockCount
|
|
7960
|
+ }
|
|
7961
|
+
|
|
7962
|
+ //查询已经出库的数据
|
|
7963
|
+ flowGood, _ := GetNewStockFlowIsBatchNumberSix(patient_id, record_time, goods.GoodId, goods.ProjectId, tx)
|
|
7964
|
+ var out_count int64
|
|
7965
|
+ var out_count_one int64
|
|
7966
|
+ for _, item := range flowGood {
|
|
7967
|
+ out_count += item.Count
|
|
7968
|
+ }
|
|
7969
|
+
|
|
7970
|
+ //查询退库数据
|
|
7971
|
+ flowGoodTwo, _ := GetNewStockFlowIsBatchNumberFour(patient_id, record_time, goods.GoodId, goods.ProjectId, tx)
|
|
7972
|
+ for _, item := range flowGoodTwo {
|
|
7973
|
+ out_count_one += item.Count
|
|
7974
|
+ }
|
|
7975
|
+
|
|
7976
|
+ var out_count_two int64
|
|
7977
|
+
|
|
7978
|
+ wareOutList, _ := GetNewStockFlowIsBatchNumberSixty(patient_id, record_time, goods.GoodId, goods.ProjectId, tx)
|
|
7979
|
+ for _, item := range wareOutList {
|
|
7980
|
+ out_count_two += item.Count
|
|
7981
|
+ }
|
|
7982
|
+
|
|
7983
|
+ OutInfo := &models.WarehouseOutInfo{
|
|
7984
|
+ WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
|
|
7985
|
+ WarehouseOutId: warehouseOut.ID,
|
|
7986
|
+ WarehouseInfotId: warehouse.ID,
|
|
7987
|
+ Status: 1,
|
|
7988
|
+ Ctime: time.Now().Unix(),
|
|
7989
|
+ Remark: warehouse.Remark,
|
|
7990
|
+ OrgId: orgID,
|
|
7991
|
+ Type: 1,
|
|
7992
|
+ Manufacturer: warehouse.Manufacturer,
|
|
7993
|
+ Dealer: warehouse.Dealer,
|
|
7994
|
+ IsSys: 1,
|
|
7995
|
+ SysRecordTime: record_time,
|
|
7996
|
+ GoodTypeId: goods.GoodTypeId,
|
|
7997
|
+ GoodId: goods.GoodId,
|
|
7998
|
+ PatientId: patient_id,
|
|
7999
|
+ Number: warehouse.Number,
|
|
8000
|
+ LicenseNumber: warehouse.LicenseNumber,
|
|
8001
|
+ Price: warehouse.PackingPrice,
|
|
8002
|
+ ExpiryDate: warehouse.ExpiryDate,
|
|
8003
|
+ ProductDate: warehouse.ProductDate,
|
|
8004
|
+ ProjectId: goods.ProjectId,
|
|
8005
|
+ SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
|
8006
|
+ StorehouseId: goods.StorehouseId,
|
|
8007
|
+ IsCheck: 1,
|
|
8008
|
+ OverCount: sum_count,
|
|
8009
|
+ RegisterNumber: warehouse.RegisterNumber,
|
|
8010
|
+ }
|
|
8011
|
+ OutInfo.Count = count - out_count_two + out_count_one
|
|
8012
|
+
|
|
8013
|
+ _, errcodes := GetNewNewWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId, warehouse.ID, tx)
|
|
8014
|
+ fmt.Println("errcodes-------------------------------------------", errcodes)
|
|
8015
|
+ if errcodes == gorm.ErrRecordNotFound {
|
|
8016
|
+ errOne := AddNewSigleWarehouseOutInfo(OutInfo, tx)
|
|
8017
|
+ if errOne != nil {
|
|
8018
|
+ return errOne
|
|
8019
|
+ }
|
|
8020
|
+ } else if errcodes == nil {
|
|
8021
|
+ outInfoOne, _ := GetNewWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId, tx)
|
|
8022
|
+ if count != outInfoOne.Count {
|
|
8023
|
+ UpdatedNewWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId, tx)
|
|
8024
|
+ }
|
|
8025
|
+
|
|
8026
|
+ }
|
|
8027
|
+
|
|
8028
|
+ lastOut, _ := FindNewWarehouseOutInfoByPatientIdTwo(patient_id, record_time, goods.GoodId, orgID, goods.ProjectId, tx)
|
|
8029
|
+
|
|
8030
|
+ //如果本次出库数据大于历史出库数据 新增1条流水
|
|
8031
|
+ fmt.Println("本次出库数据", count)
|
|
8032
|
+ fmt.Println("历史出库数据", out_count)
|
|
8033
|
+ fmt.Println("退库数据", out_count_one)
|
|
8034
|
+ if count > (out_count - out_count_one) {
|
|
8035
|
+
|
|
8036
|
+ stockFlow := models.VmStockFlow{
|
|
8037
|
+ WarehousingId: warehouse.ID,
|
|
8038
|
+ GoodId: goods.GoodId,
|
|
8039
|
+ Number: warehouse.Number,
|
|
8040
|
+ LicenseNumber: warehouse.LicenseNumber,
|
|
8041
|
+ Count: count - out_count + out_count_one,
|
|
8042
|
+ UserOrgId: orgID,
|
|
8043
|
+ PatientId: goods.PatientId,
|
|
8044
|
+ SystemTime: record_time,
|
|
8045
|
+ ConsumableType: 3,
|
|
8046
|
+ IsSys: 1,
|
|
8047
|
+ WarehousingOrder: warehouse.WarehousingOrder,
|
|
8048
|
+ WarehouseOutId: warehouseOut.ID,
|
|
8049
|
+ WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
|
|
8050
|
+ IsEdit: 1,
|
|
8051
|
+ CancelStockId: 0,
|
|
8052
|
+ CancelOrderNumber: "",
|
|
8053
|
+ Manufacturer: warehouse.Manufacturer,
|
|
8054
|
+ Dealer: warehouse.Dealer,
|
|
8055
|
+ Creator: creator,
|
|
8056
|
+ UpdateCreator: 0,
|
|
8057
|
+ Status: 1,
|
|
8058
|
+ Ctime: time.Now().Unix(),
|
|
8059
|
+ Mtime: 0,
|
|
8060
|
+ Price: warehouse.PackingPrice, //零售价
|
|
8061
|
+ WarehousingDetailId: warehouse.ID,
|
|
8062
|
+ WarehouseOutDetailId: goods.ID,
|
|
8063
|
+ CancelOutDetailId: 0,
|
|
8064
|
+ ProductDate: warehouse.ProductDate,
|
|
8065
|
+ ExpireDate: warehouse.ExpiryDate,
|
|
8066
|
+ SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
|
8067
|
+ StorehouseId: warehouse.StorehouseId,
|
|
8068
|
+ AdminUserId: creator,
|
|
8069
|
+ BuyPrice: warehouse.Price, //进货价
|
|
8070
|
+ StockCount: "",
|
|
8071
|
+ BatchNumberCount: warehouse.StockCount - goods.Count,
|
|
8072
|
+ IsCheck: 1,
|
|
8073
|
+ OverCount: sum_count,
|
|
8074
|
+ RegisterNumber: warehouse.RegisterNumber,
|
|
8075
|
+ ProjectId: goods.ProjectId,
|
|
8076
|
+ }
|
|
8077
|
+ //创建出库流水
|
|
8078
|
+ errflow := CreateNewStockFlowOne(stockFlow, tx)
|
|
8079
|
+ if errflow != nil {
|
|
8080
|
+ goodErrcode := models.XtGoodErrcode{
|
|
8081
|
+ UserOrgId: orgID,
|
|
8082
|
+ Errcode: "创建流水报错",
|
|
8083
|
+ GoodId: goods.GoodId,
|
|
8084
|
+ Status: 1,
|
|
8085
|
+ Ctime: time.Now().Unix(),
|
|
8086
|
+ Mtime: 0,
|
|
8087
|
+ Count: 0,
|
|
8088
|
+ StockCount: 0,
|
|
8089
|
+ Creater: creator,
|
|
8090
|
+ BatchNumberId: warehouse.ID,
|
|
8091
|
+ WarehouseOutId: 0,
|
|
8092
|
+ }
|
|
8093
|
+ CreateGoodErrcode(goodErrcode)
|
|
8094
|
+ }
|
|
8095
|
+
|
|
8096
|
+ //更新出库数量
|
|
8097
|
+ errsumcode := ModifyNewGoodSumCount(goods.StorehouseId, stockFlow.Count, orgID, goods.GoodId, tx)
|
|
8098
|
+ if errsumcode != nil {
|
|
8099
|
+ goodErrcode := models.XtGoodErrcode{
|
|
8100
|
+ UserOrgId: orgID,
|
|
8101
|
+ Errcode: "更新出库数量报错",
|
|
8102
|
+ GoodId: goods.GoodId,
|
|
8103
|
+ Status: 1,
|
|
8104
|
+ Ctime: time.Now().Unix(),
|
|
8105
|
+ Mtime: 0,
|
|
8106
|
+ Count: 0,
|
|
8107
|
+ StockCount: 0,
|
|
8108
|
+ Creater: creator,
|
|
8109
|
+ BatchNumberId: warehouse.ID,
|
|
8110
|
+ WarehouseOutId: 0,
|
|
8111
|
+ }
|
|
8112
|
+ CreateGoodErrcode(goodErrcode)
|
|
8113
|
+ }
|
|
8114
|
+ }
|
|
8115
|
+
|
|
8116
|
+ //如果本次出库数据小于历史出库数据 新增1条退库流水
|
|
8117
|
+
|
|
8118
|
+ if count < (out_count - out_count_one) {
|
|
8119
|
+
|
|
8120
|
+ operation_time := time.Now().Unix()
|
|
8121
|
+
|
|
8122
|
+ //创建退库单
|
|
8123
|
+ timeStr := time.Now().Format("2006-01-02")
|
|
8124
|
+ timeArr := strings.Split(timeStr, "-")
|
|
8125
|
+ total, _ := FindNewAllCancelStockTotal(orgID, tx)
|
|
8126
|
+ total = total + 1
|
|
8127
|
+ orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
|
|
8128
|
+
|
|
8129
|
+ cancelStock := models.CancelStock{
|
|
8130
|
+ OrderNumber: orderNumber,
|
|
8131
|
+ OperaTime: operation_time,
|
|
8132
|
+ OrgId: orgID,
|
|
8133
|
+ Creater: warehouseOut.Creater,
|
|
8134
|
+ Ctime: time.Now().Unix(),
|
|
8135
|
+ Status: 1,
|
|
8136
|
+ ReturnTime: record_time,
|
|
8137
|
+ Type: 1,
|
|
8138
|
+ StorehouseId: goods.StorehouseId,
|
|
8139
|
+ IsCheck: 1,
|
|
8140
|
+ }
|
|
8141
|
+ _, msgerrkonde := GetNewCancelStockDetailByOrderNumberOne(record_time, orgID, tx)
|
|
8142
|
+ if msgerrkonde == gorm.ErrRecordNotFound {
|
|
8143
|
+ AddNewSigleCancelStock(&cancelStock, tx)
|
|
8144
|
+ }
|
|
8145
|
+
|
|
8146
|
+ cancel, _ := GetNewLastCancelStockById(orgID, tx)
|
|
8147
|
+
|
|
8148
|
+ manufacturer, _ := GetNewManufactureById(warehouse.Manufacturer, tx)
|
|
8149
|
+ deaerler, _ := GetNewDealerById(warehouse.Dealer, tx)
|
|
8150
|
+ cancelStockInfo := models.CancelStockInfo{
|
|
8151
|
+ GoodId: goods.GoodId,
|
|
8152
|
+ CancelStockId: cancel.ID,
|
|
8153
|
+ GoodTypeId: goods.GoodTypeId,
|
|
8154
|
+ Count: out_count - out_count_one - count,
|
|
8155
|
+ Price: warehouse.PackingPrice,
|
|
8156
|
+ Total: 0,
|
|
8157
|
+ ProductDate: warehouse.ProductDate,
|
|
8158
|
+ ExpiryDate: warehouse.ExpiryDate,
|
|
8159
|
+ Ctime: time.Now().Unix(),
|
|
8160
|
+ Status: 1,
|
|
8161
|
+ OrgId: orgID,
|
|
8162
|
+ OrderNumber: cancel.OrderNumber,
|
|
8163
|
+ Type: 0,
|
|
8164
|
+ Dealer: deaerler.DealerName,
|
|
8165
|
+ Manufacturer: manufacturer.ManufacturerName,
|
|
8166
|
+ Number: warehouse.Number,
|
|
8167
|
+ RegisterAccount: "",
|
|
8168
|
+ Remark: "",
|
|
8169
|
+ WarehouseInfoId: warehouse.ID,
|
|
8170
|
+ PatientId: patient_id,
|
|
8171
|
+ RecordDate: record_time,
|
|
8172
|
+ StorehouseId: goods.StorehouseId,
|
|
8173
|
+ IsCheck: 1,
|
|
8174
|
+ }
|
|
8175
|
+ if orgID == 9671 || orgID == 10265 {
|
|
8176
|
+ goodsInfo, _ := FindeNewGoodInfo(orgID, goods.ProjectId, tx)
|
|
8177
|
+ cancelStockInfo.Price = goodsInfo.PackingPrice
|
|
8178
|
+ }
|
|
8179
|
+ CreateNewCancelStockInfoOne(&cancelStockInfo, tx)
|
|
8180
|
+
|
|
8181
|
+ cancelInfo, _ := GetLastNewCancelStockInfoByGoodId(goods.GoodId, tx)
|
|
8182
|
+
|
|
8183
|
+ flow := models.VmStockFlow{
|
|
8184
|
+ WarehousingId: warehouse.ID,
|
|
8185
|
+ GoodId: goods.GoodId,
|
|
8186
|
+ Number: warehouse.Number,
|
|
8187
|
+ LicenseNumber: warehouse.LicenseNumber,
|
|
8188
|
+ Count: out_count - out_count_one - count,
|
|
8189
|
+ UserOrgId: orgID,
|
|
8190
|
+ PatientId: patient_id,
|
|
8191
|
+ SystemTime: record_time,
|
|
8192
|
+ ConsumableType: 7,
|
|
8193
|
+ IsSys: 1,
|
|
8194
|
+ WarehousingOrder: "",
|
|
8195
|
+ WarehouseOutId: lastOut.WarehouseOutId,
|
|
8196
|
+ WarehouseOutOrderNumber: lastOut.WarehouseOutOrderNumber,
|
|
8197
|
+ IsEdit: 0,
|
|
8198
|
+ CancelStockId: cancel.ID,
|
|
8199
|
+ CancelOrderNumber: cancel.OrderNumber,
|
|
8200
|
+ Manufacturer: manufacturer.ID,
|
|
8201
|
+ Dealer: 0,
|
|
8202
|
+ Creator: warehouseOut.Creater,
|
|
8203
|
+ UpdateCreator: 0,
|
|
8204
|
+ Status: 1,
|
|
8205
|
+ Ctime: time.Now().Unix(),
|
|
8206
|
+ Mtime: 0,
|
|
8207
|
+ Price: warehouse.PackingPrice,
|
|
8208
|
+ WarehousingDetailId: warehouse.ID,
|
|
8209
|
+ WarehouseOutDetailId: lastOut.ID,
|
|
8210
|
+ CancelOutDetailId: cancelInfo.ID,
|
|
8211
|
+ ProductDate: warehouse.ProductDate,
|
|
8212
|
+ ExpireDate: warehouse.ExpiryDate,
|
|
8213
|
+ StorehouseId: goods.StorehouseId,
|
|
8214
|
+ BuyPrice: warehouse.Price,
|
|
8215
|
+ ProjectId: goods.ProjectId,
|
|
8216
|
+ OverCount: sum_count,
|
|
8217
|
+ RegisterNumber: warehouse.RegisterNumber,
|
|
8218
|
+ }
|
|
8219
|
+ if orgID == 9671 || orgID == 10265 {
|
|
8220
|
+ goodsInfo, _ := FindeNewGoodInfo(orgID, goods.ProjectId, tx)
|
|
8221
|
+ flow.Price = goodsInfo.PackingPrice
|
|
8222
|
+ flow.BuyPrice = goodsInfo.BuyPrice
|
|
8223
|
+ }
|
|
8224
|
+ CreateNewStockFlowOne(flow, tx)
|
|
8225
|
+
|
|
8226
|
+ //退库数量增加
|
|
8227
|
+ UpdateNewSumAddCancelCount(orgID, goods.GoodId, goods.StorehouseId, flow.Count, tx)
|
|
8228
|
+ ModifyNewAddGoodSumCount(goods.StorehouseId, flow.Count, orgID, goods.GoodId, tx)
|
|
8229
|
+ }
|
|
8230
|
+
|
|
8231
|
+ //添加入库ID
|
|
8232
|
+ errWarehouse := UpdateNewGoodWarehouseOutById(goods.ID, warehouse.ID, orgID, sum_count, tx)
|
|
8233
|
+ if errWarehouse != nil {
|
|
8234
|
+ goodErrcode := models.XtGoodErrcode{
|
|
8235
|
+ UserOrgId: orgID,
|
|
8236
|
+ Errcode: "添加入库ID报错",
|
|
8237
|
+ GoodId: goods.GoodId,
|
|
8238
|
+ Status: 1,
|
|
8239
|
+ Ctime: time.Now().Unix(),
|
|
8240
|
+ Mtime: 0,
|
|
8241
|
+ Count: 0,
|
|
8242
|
+ StockCount: 0,
|
|
8243
|
+ Creater: creator,
|
|
8244
|
+ BatchNumberId: warehouse.ID,
|
|
8245
|
+ WarehouseOutId: 0,
|
|
8246
|
+ }
|
|
8247
|
+ CreateGoodErrcode(goodErrcode)
|
|
8248
|
+ }
|
|
8249
|
+
|
|
8250
|
+ if warehouse.StockCount < maxNumber {
|
|
8251
|
+ goodErrcode := models.XtGoodErrcode{
|
|
8252
|
+ UserOrgId: orgID,
|
|
8253
|
+ Errcode: "出库接口库存数量不足",
|
|
8254
|
+ GoodId: goods.GoodId,
|
|
8255
|
+ Status: 1,
|
|
8256
|
+ Ctime: time.Now().Unix(),
|
|
8257
|
+ Mtime: 0,
|
|
8258
|
+ Count: 0,
|
|
8259
|
+ StockCount: 0,
|
|
8260
|
+ Creater: creator,
|
|
8261
|
+ BatchNumberId: warehouse.ID,
|
|
8262
|
+ WarehouseOutId: 0,
|
|
8263
|
+ }
|
|
8264
|
+ CreateGoodErrcode(goodErrcode)
|
|
8265
|
+ return errors.New("库存数量不足")
|
|
8266
|
+
|
|
8267
|
+ }
|
|
8268
|
+
|
|
8269
|
+ return nil
|
|
8270
|
+ } else {
|
|
8271
|
+ // 出库完成后,要将该批次库存清零
|
|
8272
|
+ warehouse.StockCount = 0
|
|
8273
|
+ warehouse.Mtime = time.Now().Unix()
|
|
8274
|
+
|
|
8275
|
+ errThree := UpDateNewWarehouseInfoByStock(&warehouse, tx)
|
|
8276
|
+ if errThree != nil {
|
|
8277
|
+ goodErrcode := models.XtGoodErrcode{
|
|
8278
|
+ UserOrgId: orgID,
|
|
8279
|
+ Errcode: "扣减库存报错",
|
|
8280
|
+ GoodId: goods.GoodId,
|
|
8281
|
+ Status: 1,
|
|
8282
|
+ Ctime: time.Now().Unix(),
|
|
8283
|
+ Mtime: 0,
|
|
8284
|
+ Count: 0,
|
|
8285
|
+ StockCount: 0,
|
|
8286
|
+ Creater: creator,
|
|
8287
|
+ BatchNumberId: warehouse.ID,
|
|
8288
|
+ WarehouseOutId: 0,
|
|
8289
|
+ }
|
|
8290
|
+ CreateGoodErrcode(goodErrcode)
|
|
8291
|
+ return errThree
|
|
8292
|
+ }
|
|
8293
|
+
|
|
8294
|
+ //查询剩余库存
|
|
8295
|
+ goodList, _ := GetNewAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId, tx)
|
|
8296
|
+ var sum_count int64
|
|
8297
|
+ for _, item := range goodList {
|
|
8298
|
+ sum_count += item.StockCount
|
|
8299
|
+ }
|
|
8300
|
+ fmt.Println("剩余库存", sum_count)
|
|
8301
|
+
|
|
8302
|
+ OutInfo := &models.WarehouseOutInfo{
|
|
8303
|
+ WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
|
|
8304
|
+ WarehouseOutId: warehouseOut.ID,
|
|
8305
|
+ WarehouseInfotId: warehouse.ID,
|
|
8306
|
+ Status: 1,
|
|
8307
|
+ Ctime: time.Now().Unix(),
|
|
8308
|
+ Remark: warehouse.Remark,
|
|
8309
|
+ OrgId: orgID,
|
|
8310
|
+ Type: 1,
|
|
8311
|
+ Manufacturer: warehouse.Manufacturer,
|
|
8312
|
+ Dealer: warehouse.Dealer,
|
|
8313
|
+ IsSys: 1,
|
|
8314
|
+ SysRecordTime: record_time,
|
|
8315
|
+ GoodTypeId: goods.GoodTypeId,
|
|
8316
|
+ GoodId: goods.GoodId,
|
|
8317
|
+ PatientId: patient_id,
|
|
8318
|
+ Number: warehouse.Number,
|
|
8319
|
+ LicenseNumber: warehouse.LicenseNumber,
|
|
8320
|
+ Price: warehouse.PackingPrice,
|
|
8321
|
+ ExpiryDate: warehouse.ExpiryDate,
|
|
8322
|
+ ProductDate: warehouse.ProductDate,
|
|
8323
|
+ ProjectId: goods.ProjectId,
|
|
8324
|
+ SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
|
8325
|
+ StorehouseId: goods.StorehouseId,
|
|
8326
|
+ IsCheck: 1,
|
|
8327
|
+ OverCount: sum_count,
|
|
8328
|
+ RegisterNumber: warehouse.RegisterNumber,
|
|
8329
|
+ }
|
|
8330
|
+ OutInfo.Count = stock_number
|
|
8331
|
+
|
|
8332
|
+ _, errcodes := GetNewNewWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId, warehouse.ID, tx)
|
|
8333
|
+ if errcodes == gorm.ErrRecordNotFound {
|
|
8334
|
+ errOne := AddNewSigleWarehouseOutInfo(OutInfo, tx)
|
|
8335
|
+ if errOne != nil {
|
|
8336
|
+ return errOne
|
|
8337
|
+ }
|
|
8338
|
+ } else if errcodes == nil {
|
|
8339
|
+
|
|
8340
|
+ outInfoOne, _ := GetNewWarehouseOutInfoIsExistTen(goods.GoodId, patient_id, record_time, goods.ProjectId, warehouse.ID, tx)
|
|
8341
|
+ if count != outInfoOne.Count {
|
|
8342
|
+ UpdatedNewWarehouseOutInfoSix(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId, warehouse.ID, tx)
|
|
8343
|
+ }
|
|
8344
|
+
|
|
8345
|
+ }
|
|
8346
|
+
|
|
8347
|
+ lastOut, _ := FindNewWarehouseOutInfoByPatientIdTwo(patient_id, record_time, goods.GoodId, orgID, goods.ProjectId, tx)
|
|
8348
|
+
|
|
8349
|
+ //查询该该批次已经出库的数据
|
|
8350
|
+ flowGood, _ := GetNewStockFlowIsBatchNumberSix(patient_id, record_time, goods.GoodId, goods.ProjectId, tx)
|
|
8351
|
+ var out_count int64
|
|
8352
|
+ var out_count_one int64
|
|
8353
|
+ for _, item := range flowGood {
|
|
8354
|
+ out_count += item.Count
|
|
8355
|
+ }
|
|
8356
|
+ flowGoodTwo, _ := GetNewStockFlowIsBatchNumberFour(patient_id, record_time, goods.GoodId, goods.ProjectId, tx)
|
|
8357
|
+ for _, item := range flowGoodTwo {
|
|
8358
|
+ out_count_one += item.Count
|
|
8359
|
+ }
|
|
8360
|
+ //如果出库数量 大于 历史出库数据 新增1条流水
|
|
8361
|
+ if count > out_count-out_count_one {
|
|
8362
|
+ stockFlow := models.VmStockFlow{
|
|
8363
|
+ WarehousingId: warehouse.ID,
|
|
8364
|
+ GoodId: goods.GoodId,
|
|
8365
|
+ Number: warehouse.Number,
|
|
8366
|
+ LicenseNumber: warehouse.LicenseNumber,
|
|
8367
|
+ Count: stock_number,
|
|
8368
|
+ UserOrgId: orgID,
|
|
8369
|
+ PatientId: goods.PatientId,
|
|
8370
|
+ SystemTime: record_time,
|
|
8371
|
+ ConsumableType: 3,
|
|
8372
|
+ IsSys: 1,
|
|
8373
|
+ WarehousingOrder: warehouse.WarehousingOrder,
|
|
8374
|
+ WarehouseOutId: warehouseOut.ID,
|
|
8375
|
+ WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
|
|
8376
|
+ IsEdit: 1,
|
|
8377
|
+ CancelStockId: 0,
|
|
8378
|
+ CancelOrderNumber: "",
|
|
8379
|
+ Manufacturer: warehouse.Manufacturer,
|
|
8380
|
+ Dealer: warehouse.Dealer,
|
|
8381
|
+ Creator: creator,
|
|
8382
|
+ UpdateCreator: 0,
|
|
8383
|
+ Status: 1,
|
|
8384
|
+ Ctime: time.Now().Unix(),
|
|
8385
|
+ Mtime: 0,
|
|
8386
|
+ Price: warehouse.PackingPrice, //零售价
|
|
8387
|
+ WarehousingDetailId: warehouse.ID,
|
|
8388
|
+ WarehouseOutDetailId: goods.ID,
|
|
8389
|
+ CancelOutDetailId: 0,
|
|
8390
|
+ ProductDate: warehouse.ProductDate,
|
|
8391
|
+ ExpireDate: warehouse.ExpiryDate,
|
|
8392
|
+ SupplyWarehouseId: warehouse.SupplyWarehouseId,
|
|
8393
|
+ StorehouseId: warehouse.StorehouseId,
|
|
8394
|
+ AdminUserId: creator,
|
|
8395
|
+ BuyPrice: warehouse.Price, //进货价
|
|
8396
|
+ StockCount: "",
|
|
8397
|
+ BatchNumberCount: 0,
|
|
8398
|
+ IsCheck: 1,
|
|
8399
|
+ OverCount: sum_count,
|
|
8400
|
+ RegisterNumber: warehouse.RegisterNumber,
|
|
8401
|
+ ProjectId: goods.ProjectId,
|
|
8402
|
+ }
|
|
8403
|
+ //创建出库流水
|
|
8404
|
+ errflow := CreateNewStockFlowOne(stockFlow, tx)
|
|
8405
|
+ if errflow != nil {
|
|
8406
|
+ goodErrcode := models.XtGoodErrcode{
|
|
8407
|
+ UserOrgId: orgID,
|
|
8408
|
+ Errcode: "创建出库流水报错",
|
|
8409
|
+ GoodId: goods.GoodId,
|
|
8410
|
+ Status: 1,
|
|
8411
|
+ Ctime: time.Now().Unix(),
|
|
8412
|
+ Mtime: 0,
|
|
8413
|
+ Count: 0,
|
|
8414
|
+ StockCount: 0,
|
|
8415
|
+ Creater: creator,
|
|
8416
|
+ BatchNumberId: warehouse.ID,
|
|
8417
|
+ WarehouseOutId: 0,
|
|
8418
|
+ }
|
|
8419
|
+ CreateGoodErrcode(goodErrcode)
|
|
8420
|
+ }
|
|
8421
|
+
|
|
8422
|
+ //更新出库数量
|
|
8423
|
+ errcodecout := ModifyNewGoodSumCount(goods.StorehouseId, stock_number, orgID, goods.GoodId, tx)
|
|
8424
|
+
|
|
8425
|
+ if errcodecout != nil {
|
|
8426
|
+ goodErrcode := models.XtGoodErrcode{
|
|
8427
|
+ UserOrgId: orgID,
|
|
8428
|
+ Errcode: "更新出库数量报错",
|
|
8429
|
+ GoodId: goods.GoodId,
|
|
8430
|
+ Status: 1,
|
|
8431
|
+ Ctime: time.Now().Unix(),
|
|
8432
|
+ Mtime: 0,
|
|
8433
|
+ Count: 0,
|
|
8434
|
+ StockCount: 0,
|
|
8435
|
+ Creater: creator,
|
|
8436
|
+ BatchNumberId: warehouse.ID,
|
|
8437
|
+ WarehouseOutId: 0,
|
|
8438
|
+ }
|
|
8439
|
+ CreateGoodErrcode(goodErrcode)
|
|
8440
|
+ }
|
|
8441
|
+ }
|
|
8442
|
+
|
|
8443
|
+ //退库
|
|
8444
|
+ if count < out_count-out_count_one {
|
|
8445
|
+
|
|
8446
|
+ operation_time := time.Now().Unix()
|
|
8447
|
+
|
|
8448
|
+ //创建退库单
|
|
8449
|
+ timeStr := time.Now().Format("2006-01-02")
|
|
8450
|
+ timeArr := strings.Split(timeStr, "-")
|
|
8451
|
+ total, _ := FindNewAllCancelStockTotal(orgID, tx)
|
|
8452
|
+ total = total + 1
|
|
8453
|
+ orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
|
|
8454
|
+
|
|
8455
|
+ cancelStock := models.CancelStock{
|
|
8456
|
+ OrderNumber: orderNumber,
|
|
8457
|
+ OperaTime: operation_time,
|
|
8458
|
+ OrgId: orgID,
|
|
8459
|
+ Creater: warehouseOut.Creater,
|
|
8460
|
+ Ctime: time.Now().Unix(),
|
|
8461
|
+ Status: 1,
|
|
8462
|
+ ReturnTime: record_time,
|
|
8463
|
+ Type: 1,
|
|
8464
|
+ StorehouseId: goods.StorehouseId,
|
|
8465
|
+ IsCheck: 1,
|
|
8466
|
+ }
|
|
8467
|
+ _, msgerrkonde := GetNewCancelStockDetailByOrderNumberOne(record_time, orgID, tx)
|
|
8468
|
+ if msgerrkonde == gorm.ErrRecordNotFound {
|
|
8469
|
+ AddNewSigleCancelStock(&cancelStock, tx)
|
|
8470
|
+ }
|
|
8471
|
+
|
|
8472
|
+ cancel, _ := GetNewLastCancelStockById(orgID, tx)
|
|
8473
|
+
|
|
8474
|
+ manufacturer, _ := GetNewManufactureById(warehouse.Manufacturer, tx)
|
|
8475
|
+ deaerler, _ := GetNewDealerById(warehouse.Dealer, tx)
|
|
8476
|
+ cancelStockInfo := models.CancelStockInfo{
|
|
8477
|
+ GoodId: goods.GoodId,
|
|
8478
|
+ CancelStockId: cancel.ID,
|
|
8479
|
+ GoodTypeId: goods.GoodTypeId,
|
|
8480
|
+ Count: out_count - out_count_one - count,
|
|
8481
|
+ Price: warehouse.PackingPrice,
|
|
8482
|
+ Total: 0,
|
|
8483
|
+ ProductDate: warehouse.ProductDate,
|
|
8484
|
+ ExpiryDate: warehouse.ExpiryDate,
|
|
8485
|
+ Ctime: time.Now().Unix(),
|
|
8486
|
+ Status: 1,
|
|
8487
|
+ OrgId: orgID,
|
|
8488
|
+ OrderNumber: cancel.OrderNumber,
|
|
8489
|
+ Type: 0,
|
|
8490
|
+ Dealer: deaerler.DealerName,
|
|
8491
|
+ Manufacturer: manufacturer.ManufacturerName,
|
|
8492
|
+ Number: warehouse.Number,
|
|
8493
|
+ RegisterAccount: "",
|
|
8494
|
+ Remark: "",
|
|
8495
|
+ WarehouseInfoId: warehouse.ID,
|
|
8496
|
+ PatientId: patient_id,
|
|
8497
|
+ RecordDate: record_time,
|
|
8498
|
+ StorehouseId: goods.StorehouseId,
|
|
8499
|
+ IsCheck: 1,
|
|
8500
|
+ }
|
|
8501
|
+ if orgID == 9671 || orgID == 10265 {
|
|
8502
|
+ goodsInfo, _ := FindeNewGoodInfo(orgID, goods.ProjectId, tx)
|
|
8503
|
+ cancelStockInfo.Price = goodsInfo.PackingPrice
|
|
8504
|
+ }
|
|
8505
|
+ CreateNewCancelStockInfoOne(&cancelStockInfo, tx)
|
|
8506
|
+
|
|
8507
|
+ cancelInfo, _ := GetLastNewCancelStockInfoByGoodId(goods.GoodId, tx)
|
|
8508
|
+
|
|
8509
|
+ flow := models.VmStockFlow{
|
|
8510
|
+ WarehousingId: warehouse.ID,
|
|
8511
|
+ GoodId: goods.GoodId,
|
|
8512
|
+ Number: warehouse.Number,
|
|
8513
|
+ LicenseNumber: warehouse.LicenseNumber,
|
|
8514
|
+ Count: out_count - count,
|
|
8515
|
+ UserOrgId: orgID,
|
|
8516
|
+ PatientId: patient_id,
|
|
8517
|
+ SystemTime: record_time,
|
|
8518
|
+ ConsumableType: 7,
|
|
8519
|
+ IsSys: 1,
|
|
8520
|
+ WarehousingOrder: "",
|
|
8521
|
+ WarehouseOutId: lastOut.WarehouseOutId,
|
|
8522
|
+ WarehouseOutOrderNumber: lastOut.WarehouseOutOrderNumber,
|
|
8523
|
+ IsEdit: 0,
|
|
8524
|
+ CancelStockId: cancel.ID,
|
|
8525
|
+ CancelOrderNumber: cancel.OrderNumber,
|
|
8526
|
+ Manufacturer: manufacturer.ID,
|
|
8527
|
+ Dealer: 0,
|
|
8528
|
+ Creator: warehouseOut.Creater,
|
|
8529
|
+ UpdateCreator: 0,
|
|
8530
|
+ Status: 1,
|
|
8531
|
+ Ctime: time.Now().Unix(),
|
|
8532
|
+ Mtime: 0,
|
|
8533
|
+ Price: warehouse.Price,
|
|
8534
|
+ WarehousingDetailId: warehouse.ID,
|
|
8535
|
+ WarehouseOutDetailId: lastOut.ID,
|
|
8536
|
+ CancelOutDetailId: cancelInfo.ID,
|
|
8537
|
+ ProductDate: warehouse.ProductDate,
|
|
8538
|
+ ExpireDate: warehouse.ExpiryDate,
|
|
8539
|
+ StorehouseId: goods.StorehouseId,
|
|
8540
|
+ BuyPrice: warehouse.Price,
|
|
8541
|
+ ProjectId: goods.ProjectId,
|
|
8542
|
+ OverCount: sum_count,
|
|
8543
|
+ RegisterNumber: warehouse.RegisterNumber,
|
|
8544
|
+ }
|
|
8545
|
+ if orgID == 9671 || orgID == 10265 {
|
|
8546
|
+ goodsInfo, _ := FindeNewGoodInfo(orgID, goods.ProjectId, tx)
|
|
8547
|
+ flow.Price = goodsInfo.PackingPrice
|
|
8548
|
+ flow.BuyPrice = goodsInfo.BuyPrice
|
|
8549
|
+ }
|
|
8550
|
+ CreateNewStockFlowOne(flow, tx)
|
|
8551
|
+
|
|
8552
|
+ //退库数量增加
|
|
8553
|
+ UpdateNewSumAddCancelCount(orgID, goods.GoodId, goods.StorehouseId, flow.Count, tx)
|
|
8554
|
+ //实际出库减少
|
|
8555
|
+ ModifyNewAddGoodSumCount(goods.StorehouseId, flow.Count, orgID, goods.GoodId, tx)
|
|
8556
|
+ }
|
|
8557
|
+
|
|
8558
|
+ errWarehouse := UpdateNewGoodWarehouseOutById(goods.ID, warehouse.ID, orgID, sum_count, tx)
|
|
8559
|
+ if errWarehouse != nil {
|
|
8560
|
+ goodErrcode := models.XtGoodErrcode{
|
|
8561
|
+ UserOrgId: orgID,
|
|
8562
|
+ Errcode: "添加入库ID报错",
|
|
8563
|
+ GoodId: goods.GoodId,
|
|
8564
|
+ Status: 1,
|
|
8565
|
+ Ctime: time.Now().Unix(),
|
|
8566
|
+ Mtime: 0,
|
|
8567
|
+ Count: 0,
|
|
8568
|
+ StockCount: 0,
|
|
8569
|
+ Creater: creator,
|
|
8570
|
+ BatchNumberId: warehouse.ID,
|
|
8571
|
+ WarehouseOutId: 0,
|
|
8572
|
+ }
|
|
8573
|
+ CreateGoodErrcode(goodErrcode)
|
|
8574
|
+ }
|
|
8575
|
+
|
|
8576
|
+ }
|
|
8577
|
+
|
|
8578
|
+ goods.Count = deliver_number - stock_number
|
|
8579
|
+ prepare := &models.DialysisBeforePrepare{
|
|
8580
|
+ Count: deliver_number - stock_number,
|
|
8581
|
+ GoodTypeId: goods.GoodTypeId,
|
|
8582
|
+ GoodId: goods.GoodId,
|
|
8583
|
+ PatientId: goods.PatientId,
|
|
8584
|
+ RecordDate: goods.RecordDate,
|
|
8585
|
+ UserOrgId: orgID,
|
|
8586
|
+ Ctime: time.Now().Unix(),
|
|
8587
|
+ Creater: creator,
|
|
8588
|
+ Status: 1,
|
|
8589
|
+ StorehouseId: goods.StorehouseId,
|
|
8590
|
+ ProjectId: goods.ProjectId,
|
|
8591
|
+ }
|
|
8592
|
+ ConsumableNewPrescriptionDelivery(orgID, patient_id, record_time, prepare, warehouseOut, creator, count, tx)
|
|
8593
|
+
|
|
8594
|
+ return nil
|
|
8595
|
+}
|